blob: 88d5d08814335a1b86809f99d187bf032daaeee8 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Paul Kocialkowski3dee0002015-07-20 15:17:11 +02002/*
Paul Kocialkowski4db92762016-02-07 16:50:50 +01003 * LG Optimus Black codename sniper board
Paul Kocialkowski3dee0002015-07-20 15:17:11 +02004 *
5 * Copyright (C) 2015 Paul Kocialkowski <contact@paulk.fr>
Paul Kocialkowski3dee0002015-07-20 15:17:11 +02006 */
7
8#include <config.h>
Paul Kocialkowski3dee0002015-07-20 15:17:11 +02009#include <dm.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060010#include <env.h>
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +030011#include <fastboot.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Paul Kocialkowski248b7912015-07-20 15:17:12 +020014#include <linux/ctype.h>
Paul Kocialkowski46f99102015-07-20 15:17:15 +020015#include <linux/usb/musb.h>
16#include <asm/omap_musb.h>
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020017#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
25DECLARE_GLOBAL_DATA_PTR;
26
27const omap3_sysinfo sysinfo = {
28 .mtype = DDR_STACKED,
Paul Kocialkowskid90f8832016-02-26 13:18:47 +010029 .board_string = "sniper",
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020030 .nand_string = "MMC"
31};
32
Simon Glassb75b15b2020-12-03 16:55:23 -070033static const struct ns16550_plat serial_omap_plat = {
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020034 .base = OMAP34XX_UART3,
35 .reg_shift = 2,
Heiko Schocher06f108e2017-01-18 08:05:49 +010036 .clock = V_NS16550_CLK,
37 .fcr = UART_FCR_DEFVAL,
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020038};
39
Simon Glass1d8364a2020-12-28 20:34:54 -070040U_BOOT_DRVINFO(sniper_serial) = {
Thomas Chou52ac4432015-11-19 21:48:12 +080041 .name = "ns16550_serial",
Simon Glassb75b15b2020-12-03 16:55:23 -070042 .plat = &serial_omap_plat
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020043};
44
Tom Rini490599d2021-05-22 08:47:15 -040045#if defined(CONFIG_USB_MUSB_HOST) || defined(CONFIG_USB_MUSB_GADGET)
Paul Kocialkowski46f99102015-07-20 15:17:15 +020046static struct musb_hdrc_config musb_config = {
47 .multipoint = 1,
48 .dyn_fifo = 1,
49 .num_eps = 16,
50 .ram_bits = 12
51};
52
53static struct omap_musb_board_data musb_board_data = {
54 .interface_type = MUSB_INTERFACE_ULPI,
55};
56
57static struct musb_hdrc_platform_data musb_platform_data = {
58 .mode = MUSB_PERIPHERAL,
59 .config = &musb_config,
60 .power = 100,
61 .platform_ops = &omap2430_ops,
62 .board_data = &musb_board_data,
63};
Tom Rini490599d2021-05-22 08:47:15 -040064#endif
Paul Kocialkowski46f99102015-07-20 15:17:15 +020065
Paul Kocialkowskid90f8832016-02-26 13:18:47 +010066void set_muxconf_regs(void)
67{
68 MUX_SNIPER();
69}
70
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020071#ifdef CONFIG_SPL_BUILD
72void get_board_mem_timings(struct board_sdrc_timings *timings)
73{
74 timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
75 timings->ctrla = HYNIX_V_ACTIMA_200;
76 timings->ctrlb = HYNIX_V_ACTIMB_200;
77 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
78 timings->mr = MICRON_V_MR_165;
79}
80#endif
81
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020082int board_init(void)
83{
84 /* GPMC init */
85 gpmc_init();
86
87 /* MACH number */
88 gd->bd->bi_arch_number = 3000;
89
90 /* ATAGs location */
91 gd->bd->bi_boot_params = OMAP34XX_SDRC_CS0 + 0x100;
92
93 return 0;
94}
95
Paul Kocialkowski248b7912015-07-20 15:17:12 +020096int misc_init_r(void)
97{
Paul Kocialkowski76844b92015-07-20 15:17:18 +020098 unsigned char keypad_matrix[64] = { 0 };
Paul Kocialkowski248b7912015-07-20 15:17:12 +020099 char reboot_mode[2] = { 0 };
Paul Kocialkowski76844b92015-07-20 15:17:18 +0200100 unsigned char keys[3];
Paul Kocialkowski361b98b2015-07-20 15:17:17 +0200101 unsigned char data = 0;
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200102 int rc;
Paul Kocialkowski248b7912015-07-20 15:17:12 +0200103
Paul Kocialkowskie3ff29e2015-07-20 15:17:16 +0200104 /* Power button reset init */
105
106 twl4030_power_reset_init();
107
Paul Kocialkowski76844b92015-07-20 15:17:18 +0200108 /* Keypad */
109
110 twl4030_keypad_scan((unsigned char *)&keypad_matrix);
111
112 keys[0] = twl4030_keypad_key((unsigned char *)&keypad_matrix, 0, 0);
113 keys[1] = twl4030_keypad_key((unsigned char *)&keypad_matrix, 0, 1);
114 keys[2] = twl4030_keypad_key((unsigned char *)&keypad_matrix, 0, 2);
115
Paul Kocialkowski248b7912015-07-20 15:17:12 +0200116 /* Reboot mode */
117
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200118 rc = omap_reboot_mode(reboot_mode, sizeof(reboot_mode));
Paul Kocialkowski76844b92015-07-20 15:17:18 +0200119
120 if (keys[0])
121 reboot_mode[0] = 'r';
122 else if (keys[1])
123 reboot_mode[0] = 'b';
124
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200125 if (rc < 0 || reboot_mode[0] == 'o') {
Paul Kocialkowski361b98b2015-07-20 15:17:17 +0200126 /*
127 * When not rebooting, valid power on reasons are either the
128 * power button, charger plug or USB plug.
129 */
130
131 data |= twl4030_input_power_button();
132 data |= twl4030_input_charger();
133 data |= twl4030_input_usb();
134
135 if (!data)
136 twl4030_power_off();
Paul Kocialkowski248b7912015-07-20 15:17:12 +0200137 }
138
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200139 if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
Simon Glass64b723f2017-08-03 12:22:12 -0600140 if (!env_get("reboot-mode"))
Simon Glass6a38e412017-08-03 12:22:09 -0600141 env_set("reboot-mode", (char *)reboot_mode);
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200142 }
143
144 omap_reboot_mode_clear();
145
Paul Kocialkowskie3820442015-07-20 15:17:13 +0200146 /* Serial number */
147
Paul Kocialkowski2edadee2015-08-27 19:37:12 +0200148 omap_die_id_serial();
Paul Kocialkowskie3820442015-07-20 15:17:13 +0200149
Paul Kocialkowski46f99102015-07-20 15:17:15 +0200150 /* MUSB */
Tom Rini490599d2021-05-22 08:47:15 -0400151#if defined(CONFIG_USB_MUSB_HOST) || defined(CONFIG_USB_MUSB_GADGET)
Paul Kocialkowski46f99102015-07-20 15:17:15 +0200152 musb_register(&musb_platform_data, &musb_board_data, (void *)MUSB_BASE);
Tom Rini490599d2021-05-22 08:47:15 -0400153#endif
Paul Kocialkowski46f99102015-07-20 15:17:15 +0200154
Paul Kocialkowski248b7912015-07-20 15:17:12 +0200155 return 0;
156}
157
Tom Rini4cc38852021-08-30 09:16:30 -0400158#ifdef CONFIG_REVISION_TAG
Paul Kocialkowskid90f8832016-02-26 13:18:47 +0100159u32 get_board_rev(void)
160{
161 /* Sold devices are expected to be at least revision F. */
162 return 6;
163}
Tom Rini4cc38852021-08-30 09:16:30 -0400164#endif
Paul Kocialkowskid90f8832016-02-26 13:18:47 +0100165
Paul Kocialkowskic29a72f2015-07-20 15:17:14 +0200166void get_board_serial(struct tag_serialnr *serialnr)
167{
Paul Kocialkowskia7267d22015-08-27 19:37:14 +0200168 omap_die_id_get_board_serial(serialnr);
Paul Kocialkowskic29a72f2015-07-20 15:17:14 +0200169}
170
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200171void reset_misc(void)
172{
173 char reboot_mode[2] = { 0 };
174
175 /*
176 * Valid resets must contain the reboot mode magic, but we must not
177 * override it when set previously (e.g. reboot to bootloader).
178 */
179
180 omap_reboot_mode(reboot_mode, sizeof(reboot_mode));
181 omap_reboot_mode_store(reboot_mode);
182}
183
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +0300184int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
Paul Kocialkowski46f99102015-07-20 15:17:15 +0200185{
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +0300186 if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER)
187 return -ENOTSUPP;
188
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +0100189 return omap_reboot_mode_store("b");
Paul Kocialkowski46f99102015-07-20 15:17:15 +0200190}
191
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900192int board_mmc_init(struct bd_info *bis)
Paul Kocialkowski3dee0002015-07-20 15:17:11 +0200193{
194 return omap_mmc_init(1, 0, 0, -1, -1);
195}
Paul Kocialkowski3dee0002015-07-20 15:17:11 +0200196
197void board_mmc_power_init(void)
198{
199 twl4030_power_mmc_init(1);
200}