1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Amazon Kindle Fire (first generation) codename kc1 config
4 *
5 * Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
6 */
7
8 #include <config.h>
9 #include <common.h>
10 #include <env.h>
11 #include <fastboot.h>
12 #include <init.h>
13 #include <asm/global_data.h>
14 #include <linux/ctype.h>
15 #include <linux/usb/musb.h>
16 #include <asm/omap_musb.h>
17 #include <asm/arch/sys_proto.h>
18 #include <asm/arch/mmc_host_def.h>
19 #include <asm/gpio.h>
20 #include <asm/emif.h>
21 #include <twl6030.h>
22 #include "kc1.h"
23 #include <asm/mach-types.h>
24
25 DECLARE_GLOBAL_DATA_PTR;
26
27 const struct omap_sysinfo sysinfo = {
28 .board_string = "kc1"
29 };
30
31 static struct musb_hdrc_config musb_config = {
32 .multipoint = 1,
33 .dyn_fifo = 1,
34 .num_eps = 16,
35 .ram_bits = 12
36 };
37
38 static struct omap_musb_board_data musb_board_data = {
39 .interface_type = MUSB_INTERFACE_UTMI,
40 };
41
42 static struct musb_hdrc_platform_data musb_platform_data = {
43 .mode = MUSB_PERIPHERAL,
44 .config = &musb_config,
45 .power = 100,
46 .platform_ops = &omap2430_ops,
47 .board_data = &musb_board_data,
48 };
49
50
set_muxconf_regs(void)51 void set_muxconf_regs(void)
52 {
53 do_set_mux((*ctrl)->control_padconf_core_base, core_padconf_array,
54 sizeof(core_padconf_array) / sizeof(struct pad_conf_entry));
55 }
56
emif_get_device_details(u32 emif_nr,u8 cs,struct lpddr2_device_details * lpddr2_dev_details)57 struct lpddr2_device_details *emif_get_device_details(u32 emif_nr, u8 cs,
58 struct lpddr2_device_details *lpddr2_dev_details)
59 {
60 if (cs == CS1)
61 return NULL;
62
63 *lpddr2_dev_details = elpida_2G_S4_details;
64
65 return lpddr2_dev_details;
66 }
67
emif_get_device_timings(u32 emif_nr,const struct lpddr2_device_timings ** cs0_device_timings,const struct lpddr2_device_timings ** cs1_device_timings)68 void emif_get_device_timings(u32 emif_nr,
69 const struct lpddr2_device_timings **cs0_device_timings,
70 const struct lpddr2_device_timings **cs1_device_timings)
71 {
72 *cs0_device_timings = &elpida_2G_S4_timings;
73 *cs1_device_timings = NULL;
74 }
75
board_init(void)76 int board_init(void)
77 {
78 /* GPMC init */
79 gpmc_init();
80
81 /* MACH number */
82 gd->bd->bi_arch_number = MACH_TYPE_OMAP_4430SDP;
83
84 /* ATAGs location */
85 gd->bd->bi_boot_params = OMAP44XX_DRAM_ADDR_SPACE_START + 0x100;
86
87 return 0;
88 }
89
misc_init_r(void)90 int misc_init_r(void)
91 {
92 char reboot_mode[2] = { 0 };
93 u32 data = 0;
94 u32 value;
95 int rc;
96
97 /* Reboot mode */
98
99 rc = omap_reboot_mode(reboot_mode, sizeof(reboot_mode));
100
101 /* USB ID pin pull-up indicates factory (fastboot) cable detection. */
102 gpio_request(KC1_GPIO_USB_ID, "USB_ID");
103 gpio_direction_input(KC1_GPIO_USB_ID);
104 value = gpio_get_value(KC1_GPIO_USB_ID);
105
106 if (value)
107 reboot_mode[0] = 'b';
108
109 if (rc < 0 || reboot_mode[0] == 'o') {
110 /*
111 * When not rebooting, valid power on reasons are either the
112 * power button, charger plug or USB plug.
113 */
114
115 data |= twl6030_input_power_button();
116 data |= twl6030_input_charger();
117 data |= twl6030_input_usb();
118
119 if (!data)
120 twl6030_power_off();
121 }
122
123 if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
124 if (!env_get("reboot-mode"))
125 env_set("reboot-mode", (char *)reboot_mode);
126 }
127
128 omap_reboot_mode_clear();
129
130 /* Serial number */
131
132 omap_die_id_serial();
133
134 /* MUSB */
135
136 musb_register(&musb_platform_data, &musb_board_data, (void *)MUSB_BASE);
137
138 return 0;
139 }
140
get_board_rev(void)141 u32 get_board_rev(void)
142 {
143 u32 value = 0;
144
145 gpio_request(KC1_GPIO_MBID0, "MBID0");
146 gpio_request(KC1_GPIO_MBID1, "MBID1");
147 gpio_request(KC1_GPIO_MBID2, "MBID2");
148 gpio_request(KC1_GPIO_MBID3, "MBID3");
149
150 gpio_direction_input(KC1_GPIO_MBID0);
151 gpio_direction_input(KC1_GPIO_MBID1);
152 gpio_direction_input(KC1_GPIO_MBID2);
153 gpio_direction_input(KC1_GPIO_MBID3);
154
155 value |= (gpio_get_value(KC1_GPIO_MBID0) << 0);
156 value |= (gpio_get_value(KC1_GPIO_MBID1) << 1);
157 value |= (gpio_get_value(KC1_GPIO_MBID2) << 2);
158 value |= (gpio_get_value(KC1_GPIO_MBID3) << 3);
159
160 return value;
161 }
162
get_board_serial(struct tag_serialnr * serialnr)163 void get_board_serial(struct tag_serialnr *serialnr)
164 {
165 omap_die_id_get_board_serial(serialnr);
166 }
167
fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)168 int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
169 {
170 if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER)
171 return -ENOTSUPP;
172
173 return omap_reboot_mode_store("b");
174 }
175
board_mmc_init(struct bd_info * bis)176 int board_mmc_init(struct bd_info *bis)
177 {
178 return omap_mmc_init(1, 0, 0, -1, -1);
179 }
180
board_mmc_power_init(void)181 void board_mmc_power_init(void)
182 {
183 twl6030_power_mmc_init(1);
184 }
185