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> |
Paul Kocialkowski | 0257930 | 2015-07-20 15:17:11 +0200 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 10 | #include <env.h> |
Roman Kovalivskyi | 851737a | 2020-07-28 23:35:32 +0300 | [diff] [blame] | 11 | #include <fastboot.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.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/sys_proto.h> |
| 18 | #include <asm/arch/mem.h> |
| 19 | #include <asm/io.h> |
Paul Kocialkowski | 0257930 | 2015-07-20 15:17:11 +0200 | [diff] [blame] | 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 | |
Tom Rini | 7d05599 | 2021-05-22 08:47:15 -0400 | [diff] [blame] | 31 | #if defined(CONFIG_USB_MUSB_HOST) || defined(CONFIG_USB_MUSB_GADGET) |
Paul Kocialkowski | fbdd329 | 2015-07-20 15:17:15 +0200 | [diff] [blame] | 32 | static struct musb_hdrc_config musb_config = { |
| 33 | .multipoint = 1, |
| 34 | .dyn_fifo = 1, |
| 35 | .num_eps = 16, |
| 36 | .ram_bits = 12 |
| 37 | }; |
| 38 | |
| 39 | static struct omap_musb_board_data musb_board_data = { |
| 40 | .interface_type = MUSB_INTERFACE_ULPI, |
| 41 | }; |
| 42 | |
| 43 | static struct musb_hdrc_platform_data musb_platform_data = { |
| 44 | .mode = MUSB_PERIPHERAL, |
| 45 | .config = &musb_config, |
| 46 | .power = 100, |
| 47 | .platform_ops = &omap2430_ops, |
| 48 | .board_data = &musb_board_data, |
| 49 | }; |
Tom Rini | 7d05599 | 2021-05-22 08:47:15 -0400 | [diff] [blame] | 50 | #endif |
Paul Kocialkowski | fbdd329 | 2015-07-20 15:17:15 +0200 | [diff] [blame] | 51 | |
Paul Kocialkowski | 23a004a | 2016-02-26 13:18:47 +0100 | [diff] [blame] | 52 | void set_muxconf_regs(void) |
| 53 | { |
| 54 | MUX_SNIPER(); |
| 55 | } |
| 56 | |
Simon Glass | dac3ce9 | 2024-09-29 19:49:47 -0600 | [diff] [blame] | 57 | #ifdef CONFIG_XPL_BUILD |
Paul Kocialkowski | 0257930 | 2015-07-20 15:17:11 +0200 | [diff] [blame] | 58 | void get_board_mem_timings(struct board_sdrc_timings *timings) |
| 59 | { |
| 60 | timings->mcfg = HYNIX_V_MCFG_200(256 << 20); |
| 61 | timings->ctrla = HYNIX_V_ACTIMA_200; |
| 62 | timings->ctrlb = HYNIX_V_ACTIMB_200; |
| 63 | timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz; |
| 64 | timings->mr = MICRON_V_MR_165; |
| 65 | } |
Paul Kocialkowski | 54920df | 2024-07-29 22:44:39 +0200 | [diff] [blame] | 66 | |
| 67 | void spl_board_init(void) |
| 68 | { |
| 69 | twl4030_power_mmc_init(1); |
| 70 | } |
Paul Kocialkowski | 0257930 | 2015-07-20 15:17:11 +0200 | [diff] [blame] | 71 | #endif |
| 72 | |
Paul Kocialkowski | 0257930 | 2015-07-20 15:17:11 +0200 | [diff] [blame] | 73 | int board_init(void) |
| 74 | { |
| 75 | /* GPMC init */ |
| 76 | gpmc_init(); |
| 77 | |
| 78 | /* MACH number */ |
| 79 | gd->bd->bi_arch_number = 3000; |
| 80 | |
| 81 | /* ATAGs location */ |
| 82 | gd->bd->bi_boot_params = OMAP34XX_SDRC_CS0 + 0x100; |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
Paul Kocialkowski | 957efd4 | 2015-07-20 15:17:12 +0200 | [diff] [blame] | 87 | int misc_init_r(void) |
| 88 | { |
Paul Kocialkowski | 5c2cff8 | 2015-07-20 15:17:18 +0200 | [diff] [blame] | 89 | unsigned char keypad_matrix[64] = { 0 }; |
Paul Kocialkowski | 957efd4 | 2015-07-20 15:17:12 +0200 | [diff] [blame] | 90 | char reboot_mode[2] = { 0 }; |
Paul Kocialkowski | 5c2cff8 | 2015-07-20 15:17:18 +0200 | [diff] [blame] | 91 | unsigned char keys[3]; |
Paul Kocialkowski | 0e14f88 | 2015-07-20 15:17:17 +0200 | [diff] [blame] | 92 | unsigned char data = 0; |
Paul Kocialkowski | c15ab5b | 2016-03-29 14:16:25 +0200 | [diff] [blame] | 93 | int rc; |
Paul Kocialkowski | 957efd4 | 2015-07-20 15:17:12 +0200 | [diff] [blame] | 94 | |
Paul Kocialkowski | 69f2541 | 2015-07-20 15:17:16 +0200 | [diff] [blame] | 95 | /* Power button reset init */ |
| 96 | |
| 97 | twl4030_power_reset_init(); |
| 98 | |
Paul Kocialkowski | 5c2cff8 | 2015-07-20 15:17:18 +0200 | [diff] [blame] | 99 | /* Keypad */ |
| 100 | |
| 101 | twl4030_keypad_scan((unsigned char *)&keypad_matrix); |
| 102 | |
| 103 | keys[0] = twl4030_keypad_key((unsigned char *)&keypad_matrix, 0, 0); |
| 104 | keys[1] = twl4030_keypad_key((unsigned char *)&keypad_matrix, 0, 1); |
| 105 | keys[2] = twl4030_keypad_key((unsigned char *)&keypad_matrix, 0, 2); |
| 106 | |
Paul Kocialkowski | 957efd4 | 2015-07-20 15:17:12 +0200 | [diff] [blame] | 107 | /* Reboot mode */ |
| 108 | |
Paul Kocialkowski | c15ab5b | 2016-03-29 14:16:25 +0200 | [diff] [blame] | 109 | rc = omap_reboot_mode(reboot_mode, sizeof(reboot_mode)); |
Paul Kocialkowski | 5c2cff8 | 2015-07-20 15:17:18 +0200 | [diff] [blame] | 110 | |
| 111 | if (keys[0]) |
| 112 | reboot_mode[0] = 'r'; |
| 113 | else if (keys[1]) |
| 114 | reboot_mode[0] = 'b'; |
| 115 | |
Paul Kocialkowski | c15ab5b | 2016-03-29 14:16:25 +0200 | [diff] [blame] | 116 | if (rc < 0 || reboot_mode[0] == 'o') { |
Paul Kocialkowski | 0e14f88 | 2015-07-20 15:17:17 +0200 | [diff] [blame] | 117 | /* |
| 118 | * When not rebooting, valid power on reasons are either the |
| 119 | * power button, charger plug or USB plug. |
| 120 | */ |
| 121 | |
| 122 | data |= twl4030_input_power_button(); |
| 123 | data |= twl4030_input_charger(); |
| 124 | data |= twl4030_input_usb(); |
| 125 | |
| 126 | if (!data) |
| 127 | twl4030_power_off(); |
Paul Kocialkowski | 957efd4 | 2015-07-20 15:17:12 +0200 | [diff] [blame] | 128 | } |
| 129 | |
Paul Kocialkowski | c15ab5b | 2016-03-29 14:16:25 +0200 | [diff] [blame] | 130 | if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) { |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 131 | if (!env_get("reboot-mode")) |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 132 | env_set("reboot-mode", (char *)reboot_mode); |
Paul Kocialkowski | c15ab5b | 2016-03-29 14:16:25 +0200 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | omap_reboot_mode_clear(); |
| 136 | |
Paul Kocialkowski | 169ecb4 | 2015-07-20 15:17:13 +0200 | [diff] [blame] | 137 | /* Serial number */ |
| 138 | |
Paul Kocialkowski | 07815eb | 2015-08-27 19:37:12 +0200 | [diff] [blame] | 139 | omap_die_id_serial(); |
Paul Kocialkowski | 169ecb4 | 2015-07-20 15:17:13 +0200 | [diff] [blame] | 140 | |
Paul Kocialkowski | fbdd329 | 2015-07-20 15:17:15 +0200 | [diff] [blame] | 141 | /* MUSB */ |
Tom Rini | 7d05599 | 2021-05-22 08:47:15 -0400 | [diff] [blame] | 142 | #if defined(CONFIG_USB_MUSB_HOST) || defined(CONFIG_USB_MUSB_GADGET) |
Paul Kocialkowski | fbdd329 | 2015-07-20 15:17:15 +0200 | [diff] [blame] | 143 | musb_register(&musb_platform_data, &musb_board_data, (void *)MUSB_BASE); |
Tom Rini | 7d05599 | 2021-05-22 08:47:15 -0400 | [diff] [blame] | 144 | #endif |
Paul Kocialkowski | fbdd329 | 2015-07-20 15:17:15 +0200 | [diff] [blame] | 145 | |
Paul Kocialkowski | 957efd4 | 2015-07-20 15:17:12 +0200 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
Tom Rini | 9774462 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 149 | #ifdef CONFIG_REVISION_TAG |
Paul Kocialkowski | 23a004a | 2016-02-26 13:18:47 +0100 | [diff] [blame] | 150 | u32 get_board_rev(void) |
| 151 | { |
| 152 | /* Sold devices are expected to be at least revision F. */ |
| 153 | return 6; |
| 154 | } |
Tom Rini | 9774462 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 155 | #endif |
Paul Kocialkowski | 23a004a | 2016-02-26 13:18:47 +0100 | [diff] [blame] | 156 | |
Paul Kocialkowski | 9f4e1e9 | 2015-07-20 15:17:14 +0200 | [diff] [blame] | 157 | void get_board_serial(struct tag_serialnr *serialnr) |
| 158 | { |
Paul Kocialkowski | 2da87ab | 2015-08-27 19:37:14 +0200 | [diff] [blame] | 159 | omap_die_id_get_board_serial(serialnr); |
Paul Kocialkowski | 9f4e1e9 | 2015-07-20 15:17:14 +0200 | [diff] [blame] | 160 | } |
| 161 | |
Paul Kocialkowski | c15ab5b | 2016-03-29 14:16:25 +0200 | [diff] [blame] | 162 | void reset_misc(void) |
| 163 | { |
| 164 | char reboot_mode[2] = { 0 }; |
| 165 | |
| 166 | /* |
| 167 | * Valid resets must contain the reboot mode magic, but we must not |
| 168 | * override it when set previously (e.g. reboot to bootloader). |
| 169 | */ |
| 170 | |
| 171 | omap_reboot_mode(reboot_mode, sizeof(reboot_mode)); |
| 172 | omap_reboot_mode_store(reboot_mode); |
| 173 | } |
| 174 | |
Roman Kovalivskyi | 851737a | 2020-07-28 23:35:32 +0300 | [diff] [blame] | 175 | int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) |
Paul Kocialkowski | fbdd329 | 2015-07-20 15:17:15 +0200 | [diff] [blame] | 176 | { |
Roman Kovalivskyi | 851737a | 2020-07-28 23:35:32 +0300 | [diff] [blame] | 177 | if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER) |
| 178 | return -ENOTSUPP; |
| 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 | } |