blob: 3065461be5b7eeb8efbeb86bf27c92e604c7dc99 [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>
Simon Glass401d1c42020-10-30 21:38:53 -060014#include <asm/global_data.h>
Paul Kocialkowski957efd42015-07-20 15:17:12 +020015#include <linux/ctype.h>
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +020016#include <linux/usb/musb.h>
17#include <asm/omap_musb.h>
Paul Kocialkowski02579302015-07-20 15:17:11 +020018#include <asm/arch/mmc_host_def.h>
19#include <asm/arch/sys_proto.h>
20#include <asm/arch/mem.h>
21#include <asm/io.h>
22#include <ns16550.h>
23#include <twl4030.h>
24#include "sniper.h"
25
26DECLARE_GLOBAL_DATA_PTR;
27
28const omap3_sysinfo sysinfo = {
29 .mtype = DDR_STACKED,
Paul Kocialkowski23a004a2016-02-26 13:18:47 +010030 .board_string = "sniper",
Paul Kocialkowski02579302015-07-20 15:17:11 +020031 .nand_string = "MMC"
32};
33
Simon Glass8a8d24b2020-12-03 16:55:23 -070034static const struct ns16550_plat serial_omap_plat = {
Paul Kocialkowski02579302015-07-20 15:17:11 +020035 .base = OMAP34XX_UART3,
36 .reg_shift = 2,
Heiko Schocher17fa0322017-01-18 08:05:49 +010037 .clock = V_NS16550_CLK,
38 .fcr = UART_FCR_DEFVAL,
Paul Kocialkowski02579302015-07-20 15:17:11 +020039};
40
Simon Glass20e442a2020-12-28 20:34:54 -070041U_BOOT_DRVINFO(sniper_serial) = {
Thomas Chouc7b96862015-11-19 21:48:12 +080042 .name = "ns16550_serial",
Simon Glass8a8d24b2020-12-03 16:55:23 -070043 .plat = &serial_omap_plat
Paul Kocialkowski02579302015-07-20 15:17:11 +020044};
45
Paul Kocialkowskifbdd3292015-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};
64
Paul Kocialkowski23a004a2016-02-26 13:18:47 +010065void set_muxconf_regs(void)
66{
67 MUX_SNIPER();
68}
69
Paul Kocialkowski02579302015-07-20 15:17:11 +020070#ifdef CONFIG_SPL_BUILD
71void get_board_mem_timings(struct board_sdrc_timings *timings)
72{
73 timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
74 timings->ctrla = HYNIX_V_ACTIMA_200;
75 timings->ctrlb = HYNIX_V_ACTIMB_200;
76 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
77 timings->mr = MICRON_V_MR_165;
78}
79#endif
80
Paul Kocialkowski02579302015-07-20 15:17:11 +020081int board_init(void)
82{
83 /* GPMC init */
84 gpmc_init();
85
86 /* MACH number */
87 gd->bd->bi_arch_number = 3000;
88
89 /* ATAGs location */
90 gd->bd->bi_boot_params = OMAP34XX_SDRC_CS0 + 0x100;
91
92 return 0;
93}
94
Paul Kocialkowski957efd42015-07-20 15:17:12 +020095int misc_init_r(void)
96{
Paul Kocialkowski5c2cff82015-07-20 15:17:18 +020097 unsigned char keypad_matrix[64] = { 0 };
Paul Kocialkowski957efd42015-07-20 15:17:12 +020098 char reboot_mode[2] = { 0 };
Paul Kocialkowski5c2cff82015-07-20 15:17:18 +020099 unsigned char keys[3];
Paul Kocialkowski0e14f882015-07-20 15:17:17 +0200100 unsigned char data = 0;
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +0200101 int rc;
Paul Kocialkowski957efd42015-07-20 15:17:12 +0200102
Paul Kocialkowski69f25412015-07-20 15:17:16 +0200103 /* Power button reset init */
104
105 twl4030_power_reset_init();
106
Paul Kocialkowski5c2cff82015-07-20 15:17:18 +0200107 /* Keypad */
108
109 twl4030_keypad_scan((unsigned char *)&keypad_matrix);
110
111 keys[0] = twl4030_keypad_key((unsigned char *)&keypad_matrix, 0, 0);
112 keys[1] = twl4030_keypad_key((unsigned char *)&keypad_matrix, 0, 1);
113 keys[2] = twl4030_keypad_key((unsigned char *)&keypad_matrix, 0, 2);
114
Paul Kocialkowski957efd42015-07-20 15:17:12 +0200115 /* Reboot mode */
116
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +0200117 rc = omap_reboot_mode(reboot_mode, sizeof(reboot_mode));
Paul Kocialkowski5c2cff82015-07-20 15:17:18 +0200118
119 if (keys[0])
120 reboot_mode[0] = 'r';
121 else if (keys[1])
122 reboot_mode[0] = 'b';
123
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +0200124 if (rc < 0 || reboot_mode[0] == 'o') {
Paul Kocialkowski0e14f882015-07-20 15:17:17 +0200125 /*
126 * When not rebooting, valid power on reasons are either the
127 * power button, charger plug or USB plug.
128 */
129
130 data |= twl4030_input_power_button();
131 data |= twl4030_input_charger();
132 data |= twl4030_input_usb();
133
134 if (!data)
135 twl4030_power_off();
Paul Kocialkowski957efd42015-07-20 15:17:12 +0200136 }
137
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +0200138 if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
Simon Glass00caae62017-08-03 12:22:12 -0600139 if (!env_get("reboot-mode"))
Simon Glass382bee52017-08-03 12:22:09 -0600140 env_set("reboot-mode", (char *)reboot_mode);
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +0200141 }
142
143 omap_reboot_mode_clear();
144
Paul Kocialkowski169ecb42015-07-20 15:17:13 +0200145 /* Serial number */
146
Paul Kocialkowski07815eb2015-08-27 19:37:12 +0200147 omap_die_id_serial();
Paul Kocialkowski169ecb42015-07-20 15:17:13 +0200148
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +0200149 /* MUSB */
150
151 musb_register(&musb_platform_data, &musb_board_data, (void *)MUSB_BASE);
152
Paul Kocialkowski957efd42015-07-20 15:17:12 +0200153 return 0;
154}
155
Paul Kocialkowski23a004a2016-02-26 13:18:47 +0100156u32 get_board_rev(void)
157{
158 /* Sold devices are expected to be at least revision F. */
159 return 6;
160}
161
Paul Kocialkowski9f4e1e92015-07-20 15:17:14 +0200162void get_board_serial(struct tag_serialnr *serialnr)
163{
Paul Kocialkowski2da87ab2015-08-27 19:37:14 +0200164 omap_die_id_get_board_serial(serialnr);
Paul Kocialkowski9f4e1e92015-07-20 15:17:14 +0200165}
166
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +0200167void reset_misc(void)
168{
169 char reboot_mode[2] = { 0 };
170
171 /*
172 * Valid resets must contain the reboot mode magic, but we must not
173 * override it when set previously (e.g. reboot to bootloader).
174 */
175
176 omap_reboot_mode(reboot_mode, sizeof(reboot_mode));
177 omap_reboot_mode_store(reboot_mode);
178}
179
Roman Kovalivskyi851737a2020-07-28 23:35:32 +0300180int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +0200181{
Roman Kovalivskyi851737a2020-07-28 23:35:32 +0300182 if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER)
183 return -ENOTSUPP;
184
Paul Kocialkowskic5412b02016-02-27 19:26:41 +0100185 return omap_reboot_mode_store("b");
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +0200186}
187
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900188int board_mmc_init(struct bd_info *bis)
Paul Kocialkowski02579302015-07-20 15:17:11 +0200189{
190 return omap_mmc_init(1, 0, 0, -1, -1);
191}
Paul Kocialkowski02579302015-07-20 15:17:11 +0200192
193void board_mmc_power_init(void)
194{
195 twl4030_power_mmc_init(1);
196}