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