blob: a43f640ecfc594c835788aa6a82b774058ebc1a8 [file] [log] [blame]
Paul Kocialkowski02579302015-07-20 15:17:11 +02001/*
2 * LG Optimus Black (P970) codename sniper board
3 *
4 * Copyright (C) 2015 Paul Kocialkowski <contact@paulk.fr>
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <config.h>
10#include <common.h>
11#include <dm.h>
Paul Kocialkowski957efd42015-07-20 15:17:12 +020012#include <linux/ctype.h>
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +020013#include <linux/usb/musb.h>
14#include <asm/omap_musb.h>
Paul Kocialkowski02579302015-07-20 15:17:11 +020015#include <asm/arch/mmc_host_def.h>
16#include <asm/arch/sys_proto.h>
17#include <asm/arch/mem.h>
18#include <asm/io.h>
19#include <ns16550.h>
20#include <twl4030.h>
21#include "sniper.h"
22
23DECLARE_GLOBAL_DATA_PTR;
24
25const omap3_sysinfo sysinfo = {
26 .mtype = DDR_STACKED,
27 .board_string = "Sniper",
28 .nand_string = "MMC"
29};
30
31static const struct ns16550_platdata serial_omap_platdata = {
32 .base = OMAP34XX_UART3,
33 .reg_shift = 2,
34 .clock = V_NS16550_CLK
35};
36
37U_BOOT_DEVICE(sniper_serial) = {
38 .name = "serial_omap",
39 .platdata = &serial_omap_platdata
40};
41
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +020042static struct musb_hdrc_config musb_config = {
43 .multipoint = 1,
44 .dyn_fifo = 1,
45 .num_eps = 16,
46 .ram_bits = 12
47};
48
49static struct omap_musb_board_data musb_board_data = {
50 .interface_type = MUSB_INTERFACE_ULPI,
51};
52
53static struct musb_hdrc_platform_data musb_platform_data = {
54 .mode = MUSB_PERIPHERAL,
55 .config = &musb_config,
56 .power = 100,
57 .platform_ops = &omap2430_ops,
58 .board_data = &musb_board_data,
59};
60
Paul Kocialkowski02579302015-07-20 15:17:11 +020061#ifdef CONFIG_SPL_BUILD
62void get_board_mem_timings(struct board_sdrc_timings *timings)
63{
64 timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
65 timings->ctrla = HYNIX_V_ACTIMA_200;
66 timings->ctrlb = HYNIX_V_ACTIMB_200;
67 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
68 timings->mr = MICRON_V_MR_165;
69}
70#endif
71
72u32 get_board_rev(void)
73{
74 /* Sold devices are expected to be at least revision F. */
75 return 6;
76}
77
78int board_init(void)
79{
80 /* GPMC init */
81 gpmc_init();
82
83 /* MACH number */
84 gd->bd->bi_arch_number = 3000;
85
86 /* ATAGs location */
87 gd->bd->bi_boot_params = OMAP34XX_SDRC_CS0 + 0x100;
88
89 return 0;
90}
91
Paul Kocialkowski957efd42015-07-20 15:17:12 +020092int misc_init_r(void)
93{
Paul Kocialkowski5c2cff82015-07-20 15:17:18 +020094 unsigned char keypad_matrix[64] = { 0 };
Paul Kocialkowski169ecb42015-07-20 15:17:13 +020095 char serial_string[17] = { 0 };
Paul Kocialkowski957efd42015-07-20 15:17:12 +020096 char reboot_mode[2] = { 0 };
Paul Kocialkowski169ecb42015-07-20 15:17:13 +020097 u32 dieid[4] = { 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 Kocialkowski957efd42015-07-20 15:17:12 +0200100
Paul Kocialkowski69f25412015-07-20 15:17:16 +0200101 /* Power button reset init */
102
103 twl4030_power_reset_init();
104
Paul Kocialkowski5c2cff82015-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 Kocialkowski957efd42015-07-20 15:17:12 +0200113 /* Reboot mode */
114
115 reboot_mode[0] = omap_reboot_mode();
Paul Kocialkowski5c2cff82015-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 Kocialkowski957efd42015-07-20 15:17:12 +0200122 if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
123 if (!getenv("reboot-mode"))
124 setenv("reboot-mode", (char *)reboot_mode);
125
126 omap_reboot_mode_clear();
Paul Kocialkowski0e14f882015-07-20 15:17:17 +0200127 } else {
128 /*
129 * When not rebooting, valid power on reasons are either the
130 * power button, charger plug or USB plug.
131 */
132
133 data |= twl4030_input_power_button();
134 data |= twl4030_input_charger();
135 data |= twl4030_input_usb();
136
137 if (!data)
138 twl4030_power_off();
Paul Kocialkowski957efd42015-07-20 15:17:12 +0200139 }
140
Paul Kocialkowski169ecb42015-07-20 15:17:13 +0200141 /* Serial number */
142
143 get_dieid((u32 *)&dieid);
144
145 if (!getenv("serial#")) {
146 snprintf(serial_string, sizeof(serial_string),
147 "%08x%08x", dieid[0], dieid[3]);
148
149 setenv("serial#", serial_string);
150 }
151
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +0200152 /* MUSB */
153
154 musb_register(&musb_platform_data, &musb_board_data, (void *)MUSB_BASE);
155
Paul Kocialkowski957efd42015-07-20 15:17:12 +0200156 return 0;
157}
158
Paul Kocialkowski9f4e1e92015-07-20 15:17:14 +0200159void get_board_serial(struct tag_serialnr *serialnr)
160{
161 char *serial_string;
162 unsigned long long serial;
163
164 serial_string = getenv("serial#");
165
166 if (serial_string) {
167 serial = simple_strtoull(serial_string, NULL, 16);
168
169 serialnr->high = (unsigned int) (serial >> 32);
170 serialnr->low = (unsigned int) (serial & 0xffffffff);
171 } else {
172 serialnr->high = 0;
173 serialnr->low = 0;
174 }
175}
176
Paul Kocialkowski0e14f882015-07-20 15:17:17 +0200177void reset_misc(void)
178{
179 omap_reboot_mode_store('u');
180}
181
Paul Kocialkowskifbdd3292015-07-20 15:17:15 +0200182int fb_set_reboot_flag(void)
183{
184 return omap_reboot_mode_store('b');
185}
186
Paul Kocialkowski02579302015-07-20 15:17:11 +0200187void set_muxconf_regs(void)
188{
189 MUX_SNIPER();
190}
191
192#ifndef CONFIG_SPL_BUILD
193int board_mmc_init(bd_t *bis)
194{
195 return omap_mmc_init(1, 0, 0, -1, -1);
196}
197#endif
198
199void board_mmc_power_init(void)
200{
201 twl4030_power_mmc_init(1);
202}