blob: 9d0959f294e83f2aca5a81347c5171eeca588e9a [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/sys_proto.h>
18#include <asm/arch/mem.h>
19#include <asm/io.h>
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020020#include <twl4030.h>
21#include "sniper.h"
22
23DECLARE_GLOBAL_DATA_PTR;
24
25const omap3_sysinfo sysinfo = {
26 .mtype = DDR_STACKED,
Paul Kocialkowskid90f8832016-02-26 13:18:47 +010027 .board_string = "sniper",
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020028 .nand_string = "MMC"
29};
30
Tom Rini490599d2021-05-22 08:47:15 -040031#if defined(CONFIG_USB_MUSB_HOST) || defined(CONFIG_USB_MUSB_GADGET)
Paul Kocialkowski46f99102015-07-20 15:17:15 +020032static struct musb_hdrc_config musb_config = {
33 .multipoint = 1,
34 .dyn_fifo = 1,
35 .num_eps = 16,
36 .ram_bits = 12
37};
38
39static struct omap_musb_board_data musb_board_data = {
40 .interface_type = MUSB_INTERFACE_ULPI,
41};
42
43static 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 Rini490599d2021-05-22 08:47:15 -040050#endif
Paul Kocialkowski46f99102015-07-20 15:17:15 +020051
Paul Kocialkowskid90f8832016-02-26 13:18:47 +010052void set_muxconf_regs(void)
53{
54 MUX_SNIPER();
55}
56
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020057#ifdef CONFIG_SPL_BUILD
58void 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 Kocialkowski32c9f4b2024-07-29 22:44:39 +020066
67void spl_board_init(void)
68{
69 twl4030_power_mmc_init(1);
70}
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020071#endif
72
Paul Kocialkowski3dee0002015-07-20 15:17:11 +020073int 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 Kocialkowski248b7912015-07-20 15:17:12 +020087int misc_init_r(void)
88{
Paul Kocialkowski76844b92015-07-20 15:17:18 +020089 unsigned char keypad_matrix[64] = { 0 };
Paul Kocialkowski248b7912015-07-20 15:17:12 +020090 char reboot_mode[2] = { 0 };
Paul Kocialkowski76844b92015-07-20 15:17:18 +020091 unsigned char keys[3];
Paul Kocialkowski361b98b2015-07-20 15:17:17 +020092 unsigned char data = 0;
Paul Kocialkowski3b78da22016-03-29 14:16:25 +020093 int rc;
Paul Kocialkowski248b7912015-07-20 15:17:12 +020094
Paul Kocialkowskie3ff29e2015-07-20 15:17:16 +020095 /* Power button reset init */
96
97 twl4030_power_reset_init();
98
Paul Kocialkowski76844b92015-07-20 15:17:18 +020099 /* 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 Kocialkowski248b7912015-07-20 15:17:12 +0200107 /* Reboot mode */
108
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200109 rc = omap_reboot_mode(reboot_mode, sizeof(reboot_mode));
Paul Kocialkowski76844b92015-07-20 15:17:18 +0200110
111 if (keys[0])
112 reboot_mode[0] = 'r';
113 else if (keys[1])
114 reboot_mode[0] = 'b';
115
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200116 if (rc < 0 || reboot_mode[0] == 'o') {
Paul Kocialkowski361b98b2015-07-20 15:17:17 +0200117 /*
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 Kocialkowski248b7912015-07-20 15:17:12 +0200128 }
129
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200130 if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
Simon Glass64b723f2017-08-03 12:22:12 -0600131 if (!env_get("reboot-mode"))
Simon Glass6a38e412017-08-03 12:22:09 -0600132 env_set("reboot-mode", (char *)reboot_mode);
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200133 }
134
135 omap_reboot_mode_clear();
136
Paul Kocialkowskie3820442015-07-20 15:17:13 +0200137 /* Serial number */
138
Paul Kocialkowski2edadee2015-08-27 19:37:12 +0200139 omap_die_id_serial();
Paul Kocialkowskie3820442015-07-20 15:17:13 +0200140
Paul Kocialkowski46f99102015-07-20 15:17:15 +0200141 /* MUSB */
Tom Rini490599d2021-05-22 08:47:15 -0400142#if defined(CONFIG_USB_MUSB_HOST) || defined(CONFIG_USB_MUSB_GADGET)
Paul Kocialkowski46f99102015-07-20 15:17:15 +0200143 musb_register(&musb_platform_data, &musb_board_data, (void *)MUSB_BASE);
Tom Rini490599d2021-05-22 08:47:15 -0400144#endif
Paul Kocialkowski46f99102015-07-20 15:17:15 +0200145
Paul Kocialkowski248b7912015-07-20 15:17:12 +0200146 return 0;
147}
148
Tom Rini4cc38852021-08-30 09:16:30 -0400149#ifdef CONFIG_REVISION_TAG
Paul Kocialkowskid90f8832016-02-26 13:18:47 +0100150u32 get_board_rev(void)
151{
152 /* Sold devices are expected to be at least revision F. */
153 return 6;
154}
Tom Rini4cc38852021-08-30 09:16:30 -0400155#endif
Paul Kocialkowskid90f8832016-02-26 13:18:47 +0100156
Paul Kocialkowskic29a72f2015-07-20 15:17:14 +0200157void get_board_serial(struct tag_serialnr *serialnr)
158{
Paul Kocialkowskia7267d22015-08-27 19:37:14 +0200159 omap_die_id_get_board_serial(serialnr);
Paul Kocialkowskic29a72f2015-07-20 15:17:14 +0200160}
161
Paul Kocialkowski3b78da22016-03-29 14:16:25 +0200162void 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 Kovalivskyi1bb13422020-07-28 23:35:32 +0300175int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
Paul Kocialkowski46f99102015-07-20 15:17:15 +0200176{
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +0300177 if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER)
178 return -ENOTSUPP;
179
Paul Kocialkowskibb0ac142016-02-27 19:26:41 +0100180 return omap_reboot_mode_store("b");
Paul Kocialkowski46f99102015-07-20 15:17:15 +0200181}