blob: d4db32ee69b035e07779a791ab36ecae88ef02bc [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>
Paul Kocialkowski02579302015-07-20 15:17:11 +02009#include <dm.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060010#include <env.h>
Roman Kovalivskyi851737a2020-07-28 23:35:32 +030011#include <fastboot.h>
Simon Glass691d7192020-05-10 11:40:02 -060012#include <init.h>
Simon Glass401d1c42020-10-30 21:38:53 -060013#include <asm/global_data.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/sys_proto.h>
18#include <asm/arch/mem.h>
19#include <asm/io.h>
Paul Kocialkowski02579302015-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 Kocialkowski23a004a2016-02-26 13:18:47 +010027 .board_string = "sniper",
Paul Kocialkowski02579302015-07-20 15:17:11 +020028 .nand_string = "MMC"
29};
30
Tom Rini7d055992021-05-22 08:47:15 -040031#if defined(CONFIG_USB_MUSB_HOST) || defined(CONFIG_USB_MUSB_GADGET)
Paul Kocialkowskifbdd3292015-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 Rini7d055992021-05-22 08:47:15 -040050#endif
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +020051
Paul Kocialkowski23a004a2016-02-26 13:18:47 +010052void set_muxconf_regs(void)
53{
54 MUX_SNIPER();
55}
56
Simon Glassdac3ce92024-09-29 19:49:47 -060057#ifdef CONFIG_XPL_BUILD
Paul Kocialkowski02579302015-07-20 15:17:11 +020058void 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 Kocialkowski54920df2024-07-29 22:44:39 +020066
67void spl_board_init(void)
68{
69 twl4030_power_mmc_init(1);
70}
Paul Kocialkowski02579302015-07-20 15:17:11 +020071#endif
72
Paul Kocialkowski02579302015-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 Kocialkowski957efd42015-07-20 15:17:12 +020087int misc_init_r(void)
88{
Paul Kocialkowski5c2cff82015-07-20 15:17:18 +020089 unsigned char keypad_matrix[64] = { 0 };
Paul Kocialkowski957efd42015-07-20 15:17:12 +020090 char reboot_mode[2] = { 0 };
Paul Kocialkowski5c2cff82015-07-20 15:17:18 +020091 unsigned char keys[3];
Paul Kocialkowski0e14f882015-07-20 15:17:17 +020092 unsigned char data = 0;
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +020093 int rc;
Paul Kocialkowski957efd42015-07-20 15:17:12 +020094
Paul Kocialkowski69f25412015-07-20 15:17:16 +020095 /* Power button reset init */
96
97 twl4030_power_reset_init();
98
Paul Kocialkowski5c2cff82015-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 Kocialkowski957efd42015-07-20 15:17:12 +0200107 /* Reboot mode */
108
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +0200109 rc = omap_reboot_mode(reboot_mode, sizeof(reboot_mode));
Paul Kocialkowski5c2cff82015-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 Kocialkowskic15ab5b2016-03-29 14:16:25 +0200116 if (rc < 0 || reboot_mode[0] == 'o') {
Paul Kocialkowski0e14f882015-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 Kocialkowski957efd42015-07-20 15:17:12 +0200128 }
129
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +0200130 if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
Simon Glass00caae62017-08-03 12:22:12 -0600131 if (!env_get("reboot-mode"))
Simon Glass382bee52017-08-03 12:22:09 -0600132 env_set("reboot-mode", (char *)reboot_mode);
Paul Kocialkowskic15ab5b2016-03-29 14:16:25 +0200133 }
134
135 omap_reboot_mode_clear();
136
Paul Kocialkowski169ecb42015-07-20 15:17:13 +0200137 /* Serial number */
138
Paul Kocialkowski07815eb2015-08-27 19:37:12 +0200139 omap_die_id_serial();
Paul Kocialkowski169ecb42015-07-20 15:17:13 +0200140
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +0200141 /* MUSB */
Tom Rini7d055992021-05-22 08:47:15 -0400142#if defined(CONFIG_USB_MUSB_HOST) || defined(CONFIG_USB_MUSB_GADGET)
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +0200143 musb_register(&musb_platform_data, &musb_board_data, (void *)MUSB_BASE);
Tom Rini7d055992021-05-22 08:47:15 -0400144#endif
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +0200145
Paul Kocialkowski957efd42015-07-20 15:17:12 +0200146 return 0;
147}
148
Tom Rini97744622021-08-30 09:16:30 -0400149#ifdef CONFIG_REVISION_TAG
Paul Kocialkowski23a004a2016-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 Rini97744622021-08-30 09:16:30 -0400155#endif
Paul Kocialkowski23a004a2016-02-26 13:18:47 +0100156
Paul Kocialkowski9f4e1e92015-07-20 15:17:14 +0200157void get_board_serial(struct tag_serialnr *serialnr)
158{
Paul Kocialkowski2da87ab2015-08-27 19:37:14 +0200159 omap_die_id_get_board_serial(serialnr);
Paul Kocialkowski9f4e1e92015-07-20 15:17:14 +0200160}
161
Paul Kocialkowskic15ab5b2016-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 Kovalivskyi851737a2020-07-28 23:35:32 +0300175int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +0200176{
Roman Kovalivskyi851737a2020-07-28 23:35:32 +0300177 if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER)
178 return -ENOTSUPP;
179
Paul Kocialkowskic5412b02016-02-27 19:26:41 +0100180 return omap_reboot_mode_store("b");
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +0200181}