blob: d11630b95433901e8859b5d6421f9cc1f39a2ddc [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Paul Kocialkowski02579302015-07-20 15:17:11 +02002/*
Paul Kocialkowski39af3d82016-02-07 16:50:50 +01003 * LG Optimus Black codename sniper board
Paul Kocialkowski02579302015-07-20 15:17:11 +02004 *
5 * Copyright (C) 2015 Paul Kocialkowski <contact@paulk.fr>
Paul Kocialkowski02579302015-07-20 15:17:11 +02006 */
7
8#include <config.h>
9#include <common.h>
10#include <dm.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060011#include <env.h>
Roman Kovalivskyi851737a2020-07-28 23:35:32 +030012#include <fastboot.h>
Simon Glass691d7192020-05-10 11:40:02 -060013#include <init.h>
Paul Kocialkowski957efd42015-07-20 15:17:12 +020014#include <linux/ctype.h>
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +020015#include <linux/usb/musb.h>
16#include <asm/omap_musb.h>
Paul Kocialkowski02579302015-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 Kocialkowski23a004a2016-02-26 13:18:47 +010029 .board_string = "sniper",
Paul Kocialkowski02579302015-07-20 15:17:11 +020030 .nand_string = "MMC"
31};
32
Simon Glass8a8d24b2020-12-03 16:55:23 -070033static const struct ns16550_plat serial_omap_plat = {
Paul Kocialkowski02579302015-07-20 15:17:11 +020034 .base = OMAP34XX_UART3,
35 .reg_shift = 2,
Heiko Schocher17fa0322017-01-18 08:05:49 +010036 .clock = V_NS16550_CLK,
37 .fcr = UART_FCR_DEFVAL,
Paul Kocialkowski02579302015-07-20 15:17:11 +020038};
39
40U_BOOT_DEVICE(sniper_serial) = {
Thomas Chouc7b96862015-11-19 21:48:12 +080041 .name = "ns16550_serial",
Simon Glass8a8d24b2020-12-03 16:55:23 -070042 .plat = &serial_omap_plat
Paul Kocialkowski02579302015-07-20 15:17:11 +020043};
44
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +020045static struct musb_hdrc_config musb_config = {
46 .multipoint = 1,
47 .dyn_fifo = 1,
48 .num_eps = 16,
49 .ram_bits = 12
50};
51
52static struct omap_musb_board_data musb_board_data = {
53 .interface_type = MUSB_INTERFACE_ULPI,
54};
55
56static 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 Kocialkowski23a004a2016-02-26 13:18:47 +010064void set_muxconf_regs(void)
65{
66 MUX_SNIPER();
67}
68
Paul Kocialkowski02579302015-07-20 15:17:11 +020069#ifdef CONFIG_SPL_BUILD
70void 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 Kocialkowski02579302015-07-20 15:17:11 +020080int 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 Kocialkowski957efd42015-07-20 15:17:12 +020094int misc_init_r(void)
95{
Paul Kocialkowski5c2cff82015-07-20 15:17:18 +020096 unsigned char keypad_matrix[64] = { 0 };
Paul Kocialkowski957efd42015-07-20 15:17:12 +020097 char reboot_mode[2] = { 0 };
Paul Kocialkowski5c2cff82015-07-20 15:17:18 +020098 unsigned char keys[3];
Paul Kocialkowski0e14f882015-07-20 15:17:17 +020099 unsigned char data = 0;
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +0200100 int rc;
Paul Kocialkowski957efd42015-07-20 15:17:12 +0200101
Paul Kocialkowski69f25412015-07-20 15:17:16 +0200102 /* Power button reset init */
103
104 twl4030_power_reset_init();
105
Paul Kocialkowski5c2cff82015-07-20 15:17:18 +0200106 /* 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 Kocialkowski957efd42015-07-20 15:17:12 +0200114 /* Reboot mode */
115
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +0200116 rc = omap_reboot_mode(reboot_mode, sizeof(reboot_mode));
Paul Kocialkowski5c2cff82015-07-20 15:17:18 +0200117
118 if (keys[0])
119 reboot_mode[0] = 'r';
120 else if (keys[1])
121 reboot_mode[0] = 'b';
122
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +0200123 if (rc < 0 || reboot_mode[0] == 'o') {
Paul Kocialkowski0e14f882015-07-20 15:17:17 +0200124 /*
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 Kocialkowski957efd42015-07-20 15:17:12 +0200135 }
136
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +0200137 if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
Simon Glass00caae62017-08-03 12:22:12 -0600138 if (!env_get("reboot-mode"))
Simon Glass382bee52017-08-03 12:22:09 -0600139 env_set("reboot-mode", (char *)reboot_mode);
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +0200140 }
141
142 omap_reboot_mode_clear();
143
Paul Kocialkowski169ecb42015-07-20 15:17:13 +0200144 /* Serial number */
145
Paul Kocialkowski07815eb2015-08-27 19:37:12 +0200146 omap_die_id_serial();
Paul Kocialkowski169ecb42015-07-20 15:17:13 +0200147
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +0200148 /* MUSB */
149
150 musb_register(&musb_platform_data, &musb_board_data, (void *)MUSB_BASE);
151
Paul Kocialkowski957efd42015-07-20 15:17:12 +0200152 return 0;
153}
154
Paul Kocialkowski23a004a2016-02-26 13:18:47 +0100155u32 get_board_rev(void)
156{
157 /* Sold devices are expected to be at least revision F. */
158 return 6;
159}
160
Paul Kocialkowski9f4e1e92015-07-20 15:17:14 +0200161void get_board_serial(struct tag_serialnr *serialnr)
162{
Paul Kocialkowski2da87ab2015-08-27 19:37:14 +0200163 omap_die_id_get_board_serial(serialnr);
Paul Kocialkowski9f4e1e92015-07-20 15:17:14 +0200164}
165
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +0200166void 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 Kovalivskyi851737a2020-07-28 23:35:32 +0300179int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +0200180{
Roman Kovalivskyi851737a2020-07-28 23:35:32 +0300181 if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER)
182 return -ENOTSUPP;
183
Paul Kocialkowskic5412b02016-02-27 19:26:41 +0100184 return omap_reboot_mode_store("b");
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +0200185}
186
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900187int board_mmc_init(struct bd_info *bis)
Paul Kocialkowski02579302015-07-20 15:17:11 +0200188{
189 return omap_mmc_init(1, 0, 0, -1, -1);
190}
Paul Kocialkowski02579302015-07-20 15:17:11 +0200191
192void board_mmc_power_init(void)
193{
194 twl4030_power_mmc_init(1);
195}