Paul Kocialkowski | 0257930 | 2015-07-20 15:17:11 +0200 | [diff] [blame] | 1 | /* |
Paul Kocialkowski | 39af3d8 | 2016-02-07 16:50:50 +0100 | [diff] [blame] | 2 | * LG Optimus Black codename sniper board |
Paul Kocialkowski | 0257930 | 2015-07-20 15:17:11 +0200 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2015 Paul Kocialkowski <contact@paulk.fr> |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0+ |
| 7 | */ |
| 8 | |
| 9 | #include <config.h> |
| 10 | #include <common.h> |
| 11 | #include <dm.h> |
Paul Kocialkowski | 957efd4 | 2015-07-20 15:17:12 +0200 | [diff] [blame] | 12 | #include <linux/ctype.h> |
Paul Kocialkowski | fbdd329 | 2015-07-20 15:17:15 +0200 | [diff] [blame] | 13 | #include <linux/usb/musb.h> |
| 14 | #include <asm/omap_musb.h> |
Paul Kocialkowski | 0257930 | 2015-07-20 15:17:11 +0200 | [diff] [blame] | 15 | #include <asm/arch/mmc_host_def.h> |
| 16 | #include <asm/arch/sys_proto.h> |
| 17 | #include <asm/arch/mem.h> |
| 18 | #include <asm/io.h> |
| 19 | #include <ns16550.h> |
| 20 | #include <twl4030.h> |
| 21 | #include "sniper.h" |
| 22 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
| 25 | const omap3_sysinfo sysinfo = { |
| 26 | .mtype = DDR_STACKED, |
Paul Kocialkowski | 23a004a | 2016-02-26 13:18:47 +0100 | [diff] [blame] | 27 | .board_string = "sniper", |
Paul Kocialkowski | 0257930 | 2015-07-20 15:17:11 +0200 | [diff] [blame] | 28 | .nand_string = "MMC" |
| 29 | }; |
| 30 | |
| 31 | static const struct ns16550_platdata serial_omap_platdata = { |
| 32 | .base = OMAP34XX_UART3, |
| 33 | .reg_shift = 2, |
Heiko Schocher | 17fa032 | 2017-01-18 08:05:49 +0100 | [diff] [blame] | 34 | .clock = V_NS16550_CLK, |
| 35 | .fcr = UART_FCR_DEFVAL, |
Paul Kocialkowski | 0257930 | 2015-07-20 15:17:11 +0200 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | U_BOOT_DEVICE(sniper_serial) = { |
Thomas Chou | c7b9686 | 2015-11-19 21:48:12 +0800 | [diff] [blame] | 39 | .name = "ns16550_serial", |
Paul Kocialkowski | 0257930 | 2015-07-20 15:17:11 +0200 | [diff] [blame] | 40 | .platdata = &serial_omap_platdata |
| 41 | }; |
| 42 | |
Paul Kocialkowski | fbdd329 | 2015-07-20 15:17:15 +0200 | [diff] [blame] | 43 | static struct musb_hdrc_config musb_config = { |
| 44 | .multipoint = 1, |
| 45 | .dyn_fifo = 1, |
| 46 | .num_eps = 16, |
| 47 | .ram_bits = 12 |
| 48 | }; |
| 49 | |
| 50 | static struct omap_musb_board_data musb_board_data = { |
| 51 | .interface_type = MUSB_INTERFACE_ULPI, |
| 52 | }; |
| 53 | |
| 54 | static struct musb_hdrc_platform_data musb_platform_data = { |
| 55 | .mode = MUSB_PERIPHERAL, |
| 56 | .config = &musb_config, |
| 57 | .power = 100, |
| 58 | .platform_ops = &omap2430_ops, |
| 59 | .board_data = &musb_board_data, |
| 60 | }; |
| 61 | |
Paul Kocialkowski | 23a004a | 2016-02-26 13:18:47 +0100 | [diff] [blame] | 62 | void set_muxconf_regs(void) |
| 63 | { |
| 64 | MUX_SNIPER(); |
| 65 | } |
| 66 | |
Paul Kocialkowski | 0257930 | 2015-07-20 15:17:11 +0200 | [diff] [blame] | 67 | #ifdef CONFIG_SPL_BUILD |
| 68 | void get_board_mem_timings(struct board_sdrc_timings *timings) |
| 69 | { |
| 70 | timings->mcfg = HYNIX_V_MCFG_200(256 << 20); |
| 71 | timings->ctrla = HYNIX_V_ACTIMA_200; |
| 72 | timings->ctrlb = HYNIX_V_ACTIMB_200; |
| 73 | timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz; |
| 74 | timings->mr = MICRON_V_MR_165; |
| 75 | } |
| 76 | #endif |
| 77 | |
Paul Kocialkowski | 0257930 | 2015-07-20 15:17:11 +0200 | [diff] [blame] | 78 | int board_init(void) |
| 79 | { |
| 80 | /* GPMC init */ |
| 81 | gpmc_init(); |
| 82 | |
| 83 | /* MACH number */ |
| 84 | gd->bd->bi_arch_number = 3000; |
| 85 | |
| 86 | /* ATAGs location */ |
| 87 | gd->bd->bi_boot_params = OMAP34XX_SDRC_CS0 + 0x100; |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
Paul Kocialkowski | 957efd4 | 2015-07-20 15:17:12 +0200 | [diff] [blame] | 92 | int misc_init_r(void) |
| 93 | { |
Paul Kocialkowski | 5c2cff8 | 2015-07-20 15:17:18 +0200 | [diff] [blame] | 94 | unsigned char keypad_matrix[64] = { 0 }; |
Paul Kocialkowski | 957efd4 | 2015-07-20 15:17:12 +0200 | [diff] [blame] | 95 | char reboot_mode[2] = { 0 }; |
Paul Kocialkowski | 5c2cff8 | 2015-07-20 15:17:18 +0200 | [diff] [blame] | 96 | unsigned char keys[3]; |
Paul Kocialkowski | 0e14f88 | 2015-07-20 15:17:17 +0200 | [diff] [blame] | 97 | unsigned char data = 0; |
Paul Kocialkowski | c15ab5b | 2016-03-29 14:16:25 +0200 | [diff] [blame] | 98 | int rc; |
Paul Kocialkowski | 957efd4 | 2015-07-20 15:17:12 +0200 | [diff] [blame] | 99 | |
Paul Kocialkowski | 69f2541 | 2015-07-20 15:17:16 +0200 | [diff] [blame] | 100 | /* Power button reset init */ |
| 101 | |
| 102 | twl4030_power_reset_init(); |
| 103 | |
Paul Kocialkowski | 5c2cff8 | 2015-07-20 15:17:18 +0200 | [diff] [blame] | 104 | /* Keypad */ |
| 105 | |
| 106 | twl4030_keypad_scan((unsigned char *)&keypad_matrix); |
| 107 | |
| 108 | keys[0] = twl4030_keypad_key((unsigned char *)&keypad_matrix, 0, 0); |
| 109 | keys[1] = twl4030_keypad_key((unsigned char *)&keypad_matrix, 0, 1); |
| 110 | keys[2] = twl4030_keypad_key((unsigned char *)&keypad_matrix, 0, 2); |
| 111 | |
Paul Kocialkowski | 957efd4 | 2015-07-20 15:17:12 +0200 | [diff] [blame] | 112 | /* Reboot mode */ |
| 113 | |
Paul Kocialkowski | c15ab5b | 2016-03-29 14:16:25 +0200 | [diff] [blame] | 114 | rc = omap_reboot_mode(reboot_mode, sizeof(reboot_mode)); |
Paul Kocialkowski | 5c2cff8 | 2015-07-20 15:17:18 +0200 | [diff] [blame] | 115 | |
| 116 | if (keys[0]) |
| 117 | reboot_mode[0] = 'r'; |
| 118 | else if (keys[1]) |
| 119 | reboot_mode[0] = 'b'; |
| 120 | |
Paul Kocialkowski | c15ab5b | 2016-03-29 14:16:25 +0200 | [diff] [blame] | 121 | if (rc < 0 || reboot_mode[0] == 'o') { |
Paul Kocialkowski | 0e14f88 | 2015-07-20 15:17:17 +0200 | [diff] [blame] | 122 | /* |
| 123 | * When not rebooting, valid power on reasons are either the |
| 124 | * power button, charger plug or USB plug. |
| 125 | */ |
| 126 | |
| 127 | data |= twl4030_input_power_button(); |
| 128 | data |= twl4030_input_charger(); |
| 129 | data |= twl4030_input_usb(); |
| 130 | |
| 131 | if (!data) |
| 132 | twl4030_power_off(); |
Paul Kocialkowski | 957efd4 | 2015-07-20 15:17:12 +0200 | [diff] [blame] | 133 | } |
| 134 | |
Paul Kocialkowski | c15ab5b | 2016-03-29 14:16:25 +0200 | [diff] [blame] | 135 | if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) { |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 136 | if (!env_get("reboot-mode")) |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 137 | env_set("reboot-mode", (char *)reboot_mode); |
Paul Kocialkowski | c15ab5b | 2016-03-29 14:16:25 +0200 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | omap_reboot_mode_clear(); |
| 141 | |
Paul Kocialkowski | 169ecb4 | 2015-07-20 15:17:13 +0200 | [diff] [blame] | 142 | /* Serial number */ |
| 143 | |
Paul Kocialkowski | 07815eb | 2015-08-27 19:37:12 +0200 | [diff] [blame] | 144 | omap_die_id_serial(); |
Paul Kocialkowski | 169ecb4 | 2015-07-20 15:17:13 +0200 | [diff] [blame] | 145 | |
Paul Kocialkowski | fbdd329 | 2015-07-20 15:17:15 +0200 | [diff] [blame] | 146 | /* MUSB */ |
| 147 | |
| 148 | musb_register(&musb_platform_data, &musb_board_data, (void *)MUSB_BASE); |
| 149 | |
Paul Kocialkowski | 957efd4 | 2015-07-20 15:17:12 +0200 | [diff] [blame] | 150 | return 0; |
| 151 | } |
| 152 | |
Paul Kocialkowski | 23a004a | 2016-02-26 13:18:47 +0100 | [diff] [blame] | 153 | u32 get_board_rev(void) |
| 154 | { |
| 155 | /* Sold devices are expected to be at least revision F. */ |
| 156 | return 6; |
| 157 | } |
| 158 | |
Paul Kocialkowski | 9f4e1e9 | 2015-07-20 15:17:14 +0200 | [diff] [blame] | 159 | void get_board_serial(struct tag_serialnr *serialnr) |
| 160 | { |
Paul Kocialkowski | 2da87ab | 2015-08-27 19:37:14 +0200 | [diff] [blame] | 161 | omap_die_id_get_board_serial(serialnr); |
Paul Kocialkowski | 9f4e1e9 | 2015-07-20 15:17:14 +0200 | [diff] [blame] | 162 | } |
| 163 | |
Paul Kocialkowski | c15ab5b | 2016-03-29 14:16:25 +0200 | [diff] [blame] | 164 | void reset_misc(void) |
| 165 | { |
| 166 | char reboot_mode[2] = { 0 }; |
| 167 | |
| 168 | /* |
| 169 | * Valid resets must contain the reboot mode magic, but we must not |
| 170 | * override it when set previously (e.g. reboot to bootloader). |
| 171 | */ |
| 172 | |
| 173 | omap_reboot_mode(reboot_mode, sizeof(reboot_mode)); |
| 174 | omap_reboot_mode_store(reboot_mode); |
| 175 | } |
| 176 | |
Paul Kocialkowski | fbdd329 | 2015-07-20 15:17:15 +0200 | [diff] [blame] | 177 | int fb_set_reboot_flag(void) |
| 178 | { |
Paul Kocialkowski | c5412b0 | 2016-02-27 19:26:41 +0100 | [diff] [blame] | 179 | return omap_reboot_mode_store("b"); |
Paul Kocialkowski | fbdd329 | 2015-07-20 15:17:15 +0200 | [diff] [blame] | 180 | } |
| 181 | |
Paul Kocialkowski | 0257930 | 2015-07-20 15:17:11 +0200 | [diff] [blame] | 182 | int board_mmc_init(bd_t *bis) |
| 183 | { |
| 184 | return omap_mmc_init(1, 0, 0, -1, -1); |
| 185 | } |
Paul Kocialkowski | 0257930 | 2015-07-20 15:17:11 +0200 | [diff] [blame] | 186 | |
| 187 | void board_mmc_power_init(void) |
| 188 | { |
| 189 | twl4030_power_mmc_init(1); |
| 190 | } |