Merge tag 'efi-2020-07-rc6' of https://gitlab.denx.de/u-boot/custodians/u-boot-efi
[oweals/u-boot.git] / board / lg / sniper / sniper.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * LG Optimus Black codename sniper board
4  *
5  * Copyright (C) 2015 Paul Kocialkowski <contact@paulk.fr>
6  */
7
8 #include <config.h>
9 #include <common.h>
10 #include <dm.h>
11 #include <env.h>
12 #include <init.h>
13 #include <linux/ctype.h>
14 #include <linux/usb/musb.h>
15 #include <asm/omap_musb.h>
16 #include <asm/arch/mmc_host_def.h>
17 #include <asm/arch/sys_proto.h>
18 #include <asm/arch/mem.h>
19 #include <asm/io.h>
20 #include <ns16550.h>
21 #include <twl4030.h>
22 #include "sniper.h"
23
24 DECLARE_GLOBAL_DATA_PTR;
25
26 const omap3_sysinfo sysinfo = {
27         .mtype = DDR_STACKED,
28         .board_string = "sniper",
29         .nand_string = "MMC"
30 };
31
32 static const struct ns16550_platdata serial_omap_platdata = {
33         .base = OMAP34XX_UART3,
34         .reg_shift = 2,
35         .clock = V_NS16550_CLK,
36         .fcr = UART_FCR_DEFVAL,
37 };
38
39 U_BOOT_DEVICE(sniper_serial) = {
40         .name = "ns16550_serial",
41         .platdata = &serial_omap_platdata
42 };
43
44 static struct musb_hdrc_config musb_config = {
45         .multipoint = 1,
46         .dyn_fifo = 1,
47         .num_eps = 16,
48         .ram_bits = 12
49 };
50
51 static struct omap_musb_board_data musb_board_data = {
52         .interface_type = MUSB_INTERFACE_ULPI,
53 };
54
55 static struct musb_hdrc_platform_data musb_platform_data = {
56         .mode = MUSB_PERIPHERAL,
57         .config = &musb_config,
58         .power = 100,
59         .platform_ops = &omap2430_ops,
60         .board_data = &musb_board_data,
61 };
62
63 void set_muxconf_regs(void)
64 {
65         MUX_SNIPER();
66 }
67
68 #ifdef CONFIG_SPL_BUILD
69 void get_board_mem_timings(struct board_sdrc_timings *timings)
70 {
71         timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
72         timings->ctrla = HYNIX_V_ACTIMA_200;
73         timings->ctrlb = HYNIX_V_ACTIMB_200;
74         timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
75         timings->mr = MICRON_V_MR_165;
76 }
77 #endif
78
79 int board_init(void)
80 {
81         /* GPMC init */
82         gpmc_init();
83
84         /* MACH number */
85         gd->bd->bi_arch_number = 3000;
86
87         /* ATAGs location */
88         gd->bd->bi_boot_params = OMAP34XX_SDRC_CS0 + 0x100;
89
90         return 0;
91 }
92
93 int misc_init_r(void)
94 {
95         unsigned char keypad_matrix[64] = { 0 };
96         char reboot_mode[2] = { 0 };
97         unsigned char keys[3];
98         unsigned char data = 0;
99         int rc;
100
101         /* Power button reset init */
102
103         twl4030_power_reset_init();
104
105         /* 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
113         /* Reboot mode */
114
115         rc = omap_reboot_mode(reboot_mode, sizeof(reboot_mode));
116
117         if (keys[0])
118                 reboot_mode[0] = 'r';
119         else if (keys[1])
120                 reboot_mode[0] = 'b';
121
122         if (rc < 0 || reboot_mode[0] == 'o') {
123                 /*
124                  * When not rebooting, valid power on reasons are either the
125                  * power button, charger plug or USB plug.
126                  */
127
128                 data |= twl4030_input_power_button();
129                 data |= twl4030_input_charger();
130                 data |= twl4030_input_usb();
131
132                 if (!data)
133                         twl4030_power_off();
134         }
135
136         if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
137                 if (!env_get("reboot-mode"))
138                         env_set("reboot-mode", (char *)reboot_mode);
139         }
140
141         omap_reboot_mode_clear();
142
143         /* Serial number */
144
145         omap_die_id_serial();
146
147         /* MUSB */
148
149         musb_register(&musb_platform_data, &musb_board_data, (void *)MUSB_BASE);
150
151         return 0;
152 }
153
154 u32 get_board_rev(void)
155 {
156         /* Sold devices are expected to be at least revision F. */
157         return 6;
158 }
159
160 void get_board_serial(struct tag_serialnr *serialnr)
161 {
162         omap_die_id_get_board_serial(serialnr);
163 }
164
165 void reset_misc(void)
166 {
167         char reboot_mode[2] = { 0 };
168
169         /*
170          * Valid resets must contain the reboot mode magic, but we must not
171          * override it when set previously (e.g. reboot to bootloader).
172          */
173
174         omap_reboot_mode(reboot_mode, sizeof(reboot_mode));
175         omap_reboot_mode_store(reboot_mode);
176 }
177
178 int fastboot_set_reboot_flag(void)
179 {
180         return omap_reboot_mode_store("b");
181 }
182
183 int board_mmc_init(bd_t *bis)
184 {
185         return omap_mmc_init(1, 0, 0, -1, -1);
186 }
187
188 void board_mmc_power_init(void)
189 {
190         twl4030_power_mmc_init(1);
191 }