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