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