blob: 2825eccc035a2ff3d376ba705250709bd6ca3c85 [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>
9#include <common.h>
10#include <dm.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060011#include <env.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Paul Kocialkowski248b7912015-07-20 15:17:12 +020013#include <linux/ctype.h>
Paul Kocialkowski46f99102015-07-20 15:17:15 +020014#include <linux/usb/musb.h>
15#include <asm/omap_musb.h>
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020016#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
24DECLARE_GLOBAL_DATA_PTR;
25
26const omap3_sysinfo sysinfo = {
27 .mtype = DDR_STACKED,
Paul Kocialkowskid90f8832016-02-26 13:18:47 +010028 .board_string = "sniper",
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020029 .nand_string = "MMC"
30};
31
32static const struct ns16550_platdata serial_omap_platdata = {
33 .base = OMAP34XX_UART3,
34 .reg_shift = 2,
Heiko Schocher06f108e2017-01-18 08:05:49 +010035 .clock = V_NS16550_CLK,
36 .fcr = UART_FCR_DEFVAL,
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020037};
38
39U_BOOT_DEVICE(sniper_serial) = {
Thomas Chou52ac4432015-11-19 21:48:12 +080040 .name = "ns16550_serial",
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020041 .platdata = &serial_omap_platdata
42};
43
Paul Kocialkowski46f99102015-07-20 15:17:15 +020044static struct musb_hdrc_config musb_config = {
45 .multipoint = 1,
46 .dyn_fifo = 1,
47 .num_eps = 16,
48 .ram_bits = 12
49};
50
51static struct omap_musb_board_data musb_board_data = {
52 .interface_type = MUSB_INTERFACE_ULPI,
53};
54
55static 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 Kocialkowskid90f8832016-02-26 13:18:47 +010063void set_muxconf_regs(void)
64{
65 MUX_SNIPER();
66}
67
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020068#ifdef CONFIG_SPL_BUILD
69void 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 Kocialkowski3dee0002015-07-20 15:17:11 +020079int 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 Kocialkowski248b7912015-07-20 15:17:12 +020093int misc_init_r(void)
94{
Paul Kocialkowski76844b92015-07-20 15:17:18 +020095 unsigned char keypad_matrix[64] = { 0 };
Paul Kocialkowski248b7912015-07-20 15:17:12 +020096 char reboot_mode[2] = { 0 };
Paul Kocialkowski76844b92015-07-20 15:17:18 +020097 unsigned char keys[3];
Paul Kocialkowski361b98b2015-07-20 15:17:17 +020098 unsigned char data = 0;
Paul Kocialkowski3b78da22016-03-29 14:16:25 +020099 int rc;
Paul Kocialkowski248b7912015-07-20 15:17:12 +0200100
Paul Kocialkowskie3ff29e2015-07-20 15:17:16 +0200101 /* Power button reset init */
102
103 twl4030_power_reset_init();
104
Paul Kocialkowski76844b92015-07-20 15:17:18 +0200105 /* 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 Kocialkowski248b7912015-07-20 15:17:12 +0200113 /* Reboot mode */
114
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200115 rc = omap_reboot_mode(reboot_mode, sizeof(reboot_mode));
Paul Kocialkowski76844b92015-07-20 15:17:18 +0200116
117 if (keys[0])
118 reboot_mode[0] = 'r';
119 else if (keys[1])
120 reboot_mode[0] = 'b';
121
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200122 if (rc < 0 || reboot_mode[0] == 'o') {
Paul Kocialkowski361b98b2015-07-20 15:17:17 +0200123 /*
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 Kocialkowski248b7912015-07-20 15:17:12 +0200134 }
135
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200136 if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
Simon Glass64b723f2017-08-03 12:22:12 -0600137 if (!env_get("reboot-mode"))
Simon Glass6a38e412017-08-03 12:22:09 -0600138 env_set("reboot-mode", (char *)reboot_mode);
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200139 }
140
141 omap_reboot_mode_clear();
142
Paul Kocialkowskie3820442015-07-20 15:17:13 +0200143 /* Serial number */
144
Paul Kocialkowski2edadee2015-08-27 19:37:12 +0200145 omap_die_id_serial();
Paul Kocialkowskie3820442015-07-20 15:17:13 +0200146
Paul Kocialkowski46f99102015-07-20 15:17:15 +0200147 /* MUSB */
148
149 musb_register(&musb_platform_data, &musb_board_data, (void *)MUSB_BASE);
150
Paul Kocialkowski248b7912015-07-20 15:17:12 +0200151 return 0;
152}
153
Paul Kocialkowskid90f8832016-02-26 13:18:47 +0100154u32 get_board_rev(void)
155{
156 /* Sold devices are expected to be at least revision F. */
157 return 6;
158}
159
Paul Kocialkowskic29a72f2015-07-20 15:17:14 +0200160void get_board_serial(struct tag_serialnr *serialnr)
161{
Paul Kocialkowskia7267d22015-08-27 19:37:14 +0200162 omap_die_id_get_board_serial(serialnr);
Paul Kocialkowskic29a72f2015-07-20 15:17:14 +0200163}
164
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200165void 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 Kiernan5512c432018-05-29 15:30:46 +0000178int fastboot_set_reboot_flag(void)
Paul Kocialkowski46f99102015-07-20 15:17:15 +0200179{
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +0100180 return omap_reboot_mode_store("b");
Paul Kocialkowski46f99102015-07-20 15:17:15 +0200181}
182
Paul Kocialkowski3dee0002015-07-20 15:17:11 +0200183int board_mmc_init(bd_t *bis)
184{
185 return omap_mmc_init(1, 0, 0, -1, -1);
186}
Paul Kocialkowski3dee0002015-07-20 15:17:11 +0200187
188void board_mmc_power_init(void)
189{
190 twl4030_power_mmc_init(1);
191}