blob: c9413af350124d6e91365215332828784e9cb4a0 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Steve Sakomanc57cca22010-06-11 20:35:26 -07002/*
3 * (C) Copyright 2010
4 * Texas Instruments Incorporated, <www.ti.com>
5 * Steve Sakoman <steve@sakoman.com>
Steve Sakomanc57cca22010-06-11 20:35:26 -07006 */
7#include <common.h>
Simon Glass691d7192020-05-10 11:40:02 -06008#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -06009#include <net.h>
Simon Glassc62db352017-05-31 19:47:48 -060010#include <asm/mach-types.h>
Steve Sakomanc57cca22010-06-11 20:35:26 -070011#include <asm/arch/sys_proto.h>
Sukumar Ghorai7e982c92010-09-18 20:56:18 -070012#include <asm/arch/mmc_host_def.h>
Lokesh Vutlaaf1d0022013-05-30 02:54:32 +000013#include <asm/arch/clock.h>
Chris Lalancettedf65a3f2011-12-13 09:41:12 +000014#include <asm/arch/gpio.h>
Govindraj.R43b62392012-02-06 03:55:34 +000015#include <asm/gpio.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060016#include <env.h>
Paul Kocialkowskifbf1b082016-02-27 19:18:52 +010017#include <twl6030.h>
Steve Sakomanc57cca22010-06-11 20:35:26 -070018
Aneesh V469ec1e2011-07-21 09:10:01 -040019#include "panda_mux_data.h"
Steve Sakoman2ad853c2010-07-15 13:43:10 -070020
Tom Rini8850c5d2017-05-12 22:33:27 -040021#ifdef CONFIG_USB_EHCI_HCD
Govindraj.R43b62392012-02-06 03:55:34 +000022#include <usb.h>
23#include <asm/arch/ehci.h>
24#include <asm/ehci-omap.h>
25#endif
26
Chris Lalancettedf65a3f2011-12-13 09:41:12 +000027#define PANDA_ULPI_PHY_TYPE_GPIO 182
Dan Murphy7d47d1c2013-06-13 11:21:13 -050028#define PANDA_BOARD_ID_1_GPIO 101
29#define PANDA_ES_BOARD_ID_1_GPIO 48
30#define PANDA_BOARD_ID_2_GPIO 171
31#define PANDA_ES_BOARD_ID_3_GPIO 3
32#define PANDA_ES_BOARD_ID_4_GPIO 2
Chris Lalancettedf65a3f2011-12-13 09:41:12 +000033
Steve Sakomanc57cca22010-06-11 20:35:26 -070034DECLARE_GLOBAL_DATA_PTR;
35
36const struct omap_sysinfo sysinfo = {
37 "Board: OMAP4 Panda\n"
38};
39
Chris Lalancettedf65a3f2011-12-13 09:41:12 +000040struct omap4_scrm_regs *const scrm = (struct omap4_scrm_regs *)0x4a30a000;
41
Steve Sakomanc57cca22010-06-11 20:35:26 -070042/**
43 * @brief board_init
44 *
45 * @return 0
46 */
47int board_init(void)
48{
Steve Sakoman27952012010-07-15 16:19:16 -040049 gpmc_init();
50
Steve Sakomanc57cca22010-06-11 20:35:26 -070051 gd->bd->bi_arch_number = MACH_TYPE_OMAP4_PANDA;
52 gd->bd->bi_boot_params = (0x80000000 + 0x100); /* boot param addr */
53
54 return 0;
55}
56
57int board_eth_init(bd_t *bis)
58{
59 return 0;
60}
61
Dan Murphy7d47d1c2013-06-13 11:21:13 -050062/*
63* Routine: get_board_revision
64* Description: Detect if we are running on a panda revision A1-A6,
65* or an ES panda board. This can be done by reading
66* the level of GPIOs and checking the processor revisions.
67* This should result in:
68* Panda 4430:
69* GPIO171, GPIO101, GPIO182: 0 1 1 => A1-A5
70* GPIO171, GPIO101, GPIO182: 1 0 1 => A6
71* Panda ES:
72* GPIO2, GPIO3, GPIO171, GPIO48, GPIO182: 0 0 0 1 1 => B1/B2
73* GPIO2, GPIO3, GPIO171, GPIO48, GPIO182: 0 0 1 1 1 => B3
74*/
75int get_board_revision(void)
76{
77 int board_id0, board_id1, board_id2;
78 int board_id3, board_id4;
79 int board_id;
80
81 int processor_rev = omap_revision();
82
83 /* Setup the mux for the common board ID pins (gpio 171 and 182) */
84 writew((IEN | M3), (*ctrl)->control_padconf_core_base + UNIPRO_TX0);
85 writew((IEN | M3), (*ctrl)->control_padconf_core_base + FREF_CLK2_OUT);
86
87 board_id0 = gpio_get_value(PANDA_ULPI_PHY_TYPE_GPIO);
88 board_id2 = gpio_get_value(PANDA_BOARD_ID_2_GPIO);
89
90 if ((processor_rev >= OMAP4460_ES1_0 &&
91 processor_rev <= OMAP4460_ES1_1)) {
92 /*
93 * Setup the mux for the ES specific board ID pins (gpio 101,
94 * 2 and 3.
95 */
96 writew((IEN | M3), (*ctrl)->control_padconf_core_base +
97 GPMC_A24);
98 writew((IEN | M3), (*ctrl)->control_padconf_core_base +
99 UNIPRO_RY0);
100 writew((IEN | M3), (*ctrl)->control_padconf_core_base +
101 UNIPRO_RX1);
102
103 board_id1 = gpio_get_value(PANDA_ES_BOARD_ID_1_GPIO);
104 board_id3 = gpio_get_value(PANDA_ES_BOARD_ID_3_GPIO);
105 board_id4 = gpio_get_value(PANDA_ES_BOARD_ID_4_GPIO);
106
107#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Simon Glass382bee52017-08-03 12:22:09 -0600108 env_set("board_name", "panda-es");
Dan Murphy7d47d1c2013-06-13 11:21:13 -0500109#endif
110 board_id = ((board_id4 << 4) | (board_id3 << 3) |
111 (board_id2 << 2) | (board_id1 << 1) | (board_id0));
112 } else {
113 /* Setup the mux for the Ax specific board ID pins (gpio 101) */
114 writew((IEN | M3), (*ctrl)->control_padconf_core_base +
115 FREF_CLK2_OUT);
116
117 board_id1 = gpio_get_value(PANDA_BOARD_ID_1_GPIO);
118 board_id = ((board_id2 << 2) | (board_id1 << 1) | (board_id0));
119
120#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
121 if ((board_id >= 0x3) && (processor_rev == OMAP4430_ES2_3))
Simon Glass382bee52017-08-03 12:22:09 -0600122 env_set("board_name", "panda-a4");
Dan Murphy7d47d1c2013-06-13 11:21:13 -0500123#endif
124 }
125
126 return board_id;
127}
128
Steve Sakomanc57cca22010-06-11 20:35:26 -0700129/**
Hardik Patel675cc772013-11-27 21:16:21 +0530130 * is_panda_es_rev_b3() - Detect if we are running on rev B3 of panda board ES
131 *
132 *
133 * Detect if we are running on B3 version of ES panda board,
134 * This can be done by reading the level of GPIO 171 and checking the
135 * processor revisions.
136 * GPIO171: 1 => Panda ES Rev B3
137 *
138 * Return : return 1 if Panda ES Rev B3 , else return 0
139 */
140u8 is_panda_es_rev_b3(void)
141{
142 int processor_rev = omap_revision();
143 int ret = 0;
144
145 if ((processor_rev >= OMAP4460_ES1_0 &&
146 processor_rev <= OMAP4460_ES1_1)) {
147
148 /* Setup the mux for the common board ID pins (gpio 171) */
149 writew((IEN | M3),
150 (*ctrl)->control_padconf_core_base + UNIPRO_TX0);
151
152 /* if processor_rev is panda ES and GPIO171 is 1,it is rev b3 */
153 ret = gpio_get_value(PANDA_BOARD_ID_2_GPIO);
154 }
155 return ret;
156}
157
158#ifdef CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS
159/*
160 * emif_get_reg_dump() - emif_get_reg_dump strong function
161 *
162 * @emif_nr - emif base
163 * @regs - reg dump of timing values
164 *
165 * Strong function to override emif_get_reg_dump weak function in sdram_elpida.c
166 */
167void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
168{
169 u32 omap4_rev = omap_revision();
170
171 /* Same devices and geometry on both EMIFs */
172 if (omap4_rev == OMAP4430_ES1_0)
173 *regs = &emif_regs_elpida_380_mhz_1cs;
174 else if (omap4_rev == OMAP4430_ES2_0)
175 *regs = &emif_regs_elpida_200_mhz_2cs;
176 else if (omap4_rev == OMAP4430_ES2_3)
177 *regs = &emif_regs_elpida_400_mhz_1cs;
178 else if (omap4_rev < OMAP4470_ES1_0) {
179 if(is_panda_es_rev_b3())
180 *regs = &emif_regs_elpida_400_mhz_1cs;
181 else
182 *regs = &emif_regs_elpida_400_mhz_2cs;
183 }
184 else
185 *regs = &emif_regs_elpida_400_mhz_1cs;
186}
Nishanth Menon38e5a5a2014-12-18 15:28:35 -0600187
188void emif_get_dmm_regs(const struct dmm_lisa_map_regs
189 **dmm_lisa_regs)
190{
191 u32 omap_rev = omap_revision();
192
193 if (omap_rev == OMAP4430_ES1_0)
194 *dmm_lisa_regs = &lisa_map_2G_x_1_x_2;
195 else if (omap_rev == OMAP4430_ES2_3)
196 *dmm_lisa_regs = &lisa_map_2G_x_2_x_2;
197 else if (omap_rev < OMAP4460_ES1_0)
198 *dmm_lisa_regs = &lisa_map_2G_x_2_x_2;
199 else
200 *dmm_lisa_regs = &ma_lisa_map_2G_x_2_x_2;
201}
202
Hardik Patel675cc772013-11-27 21:16:21 +0530203#endif
204
205/**
Steve Sakomanc57cca22010-06-11 20:35:26 -0700206 * @brief misc_init_r - Configure Panda board specific configurations
207 * such as power configurations, ethernet initialization as phase2 of
208 * boot sequence
209 *
210 * @return 0
211 */
212int misc_init_r(void)
213{
Chris Lalancettedf65a3f2011-12-13 09:41:12 +0000214 int phy_type;
215 u32 auxclk, altclksrc;
216
217 /* EHCI is not supported on ES1.0 */
218 if (omap_revision() == OMAP4430_ES1_0)
219 return 0;
220
Dan Murphy7d47d1c2013-06-13 11:21:13 -0500221 get_board_revision();
Dan Murphy34f667b2013-04-18 06:29:53 +0000222
Chris Lalancettedf65a3f2011-12-13 09:41:12 +0000223 gpio_direction_input(PANDA_ULPI_PHY_TYPE_GPIO);
224 phy_type = gpio_get_value(PANDA_ULPI_PHY_TYPE_GPIO);
225
226 if (phy_type == 1) {
227 /* ULPI PHY supplied by auxclk3 derived from sys_clk */
228 debug("ULPI PHY supplied by auxclk3\n");
229
230 auxclk = readl(&scrm->auxclk3);
231 /* Select sys_clk */
232 auxclk &= ~AUXCLK_SRCSELECT_MASK;
233 auxclk |= AUXCLK_SRCSELECT_SYS_CLK << AUXCLK_SRCSELECT_SHIFT;
234 /* Set the divisor to 2 */
235 auxclk &= ~AUXCLK_CLKDIV_MASK;
236 auxclk |= AUXCLK_CLKDIV_2 << AUXCLK_CLKDIV_SHIFT;
237 /* Request auxilary clock #3 */
238 auxclk |= AUXCLK_ENABLE_MASK;
239
240 writel(auxclk, &scrm->auxclk3);
Dan Murphybf3b98a2013-06-13 11:21:26 -0500241 } else {
Chris Lalancettedf65a3f2011-12-13 09:41:12 +0000242 /* ULPI PHY supplied by auxclk1 derived from PER dpll */
243 debug("ULPI PHY supplied by auxclk1\n");
244
245 auxclk = readl(&scrm->auxclk1);
246 /* Select per DPLL */
247 auxclk &= ~AUXCLK_SRCSELECT_MASK;
248 auxclk |= AUXCLK_SRCSELECT_PER_DPLL << AUXCLK_SRCSELECT_SHIFT;
249 /* Set the divisor to 16 */
250 auxclk &= ~AUXCLK_CLKDIV_MASK;
251 auxclk |= AUXCLK_CLKDIV_16 << AUXCLK_CLKDIV_SHIFT;
252 /* Request auxilary clock #3 */
253 auxclk |= AUXCLK_ENABLE_MASK;
254
255 writel(auxclk, &scrm->auxclk1);
256 }
257
258 altclksrc = readl(&scrm->altclksrc);
259
260 /* Activate alternate system clock supplier */
261 altclksrc &= ~ALTCLKSRC_MODE_MASK;
262 altclksrc |= ALTCLKSRC_MODE_ACTIVE;
263
264 /* enable clocks */
265 altclksrc |= ALTCLKSRC_ENABLE_INT_MASK | ALTCLKSRC_ENABLE_EXT_MASK;
266
267 writel(altclksrc, &scrm->altclksrc);
268
Paul Kocialkowski07815eb2015-08-27 19:37:12 +0200269 omap_die_id_usbethaddr();
Dan Murphye84b8f62013-10-10 08:54:23 -0500270
Steve Sakomanc57cca22010-06-11 20:35:26 -0700271 return 0;
272}
Steve Sakoman2ad853c2010-07-15 13:43:10 -0700273
Paul Kocialkowski3ef56e62016-02-27 19:18:56 +0100274void set_muxconf_regs(void)
Sricharan508a58f2011-11-15 09:49:55 -0500275{
Lokesh Vutla9239f5b2013-05-30 02:54:30 +0000276 do_set_mux((*ctrl)->control_padconf_core_base,
277 core_padconf_array_essential,
Sricharan508a58f2011-11-15 09:49:55 -0500278 sizeof(core_padconf_array_essential) /
279 sizeof(struct pad_conf_entry));
280
Lokesh Vutla9239f5b2013-05-30 02:54:30 +0000281 do_set_mux((*ctrl)->control_padconf_wkup_base,
282 wkup_padconf_array_essential,
Sricharan508a58f2011-11-15 09:49:55 -0500283 sizeof(wkup_padconf_array_essential) /
284 sizeof(struct pad_conf_entry));
285
286 if (omap_revision() >= OMAP4460_ES1_0)
Lokesh Vutla9239f5b2013-05-30 02:54:30 +0000287 do_set_mux((*ctrl)->control_padconf_wkup_base,
Dan Murphybf3b98a2013-06-13 11:21:26 -0500288 wkup_padconf_array_essential_4460,
289 sizeof(wkup_padconf_array_essential_4460) /
290 sizeof(struct pad_conf_entry));
Sricharan508a58f2011-11-15 09:49:55 -0500291}
292
Masahiro Yamada4aa2ba32017-05-09 20:31:39 +0900293#if defined(CONFIG_MMC)
Sukumar Ghorai7e982c92010-09-18 20:56:18 -0700294int board_mmc_init(bd_t *bis)
295{
Nikita Kiryanove3913f52012-12-03 02:19:47 +0000296 return omap_mmc_init(0, 0, 0, -1, -1);
Sukumar Ghorai7e982c92010-09-18 20:56:18 -0700297}
Paul Kocialkowskifbf1b082016-02-27 19:18:52 +0100298
Jean-Jacques Hiblotd5abcf92017-02-01 11:39:14 +0100299#if !defined(CONFIG_SPL_BUILD)
Paul Kocialkowskifbf1b082016-02-27 19:18:52 +0100300void board_mmc_power_init(void)
301{
302 twl6030_power_mmc_init(0);
303}
Sukumar Ghorai7e982c92010-09-18 20:56:18 -0700304#endif
Jean-Jacques Hiblotd5abcf92017-02-01 11:39:14 +0100305#endif
Sricharan508a58f2011-11-15 09:49:55 -0500306
Tom Rini8850c5d2017-05-12 22:33:27 -0400307#ifdef CONFIG_USB_EHCI_HCD
Govindraj.R43b62392012-02-06 03:55:34 +0000308
309static struct omap_usbhs_board_data usbhs_bdata = {
310 .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
311 .port_mode[1] = OMAP_USBHS_PORT_MODE_UNUSED,
312 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
313};
314
Troy Kisky127efc42013-10-10 15:27:57 -0700315int ehci_hcd_init(int index, enum usb_init_type init,
316 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Govindraj.R43b62392012-02-06 03:55:34 +0000317{
318 int ret;
319 unsigned int utmi_clk;
320
321 /* Now we can enable our port clocks */
322 utmi_clk = readl((void *)CM_L3INIT_HSUSBHOST_CLKCTRL);
323 utmi_clk |= HSUSBHOST_CLKCTRL_CLKSEL_UTMI_P1_MASK;
Wolfgang Denke7300f42014-03-25 14:49:48 +0100324 setbits_le32((void *)CM_L3INIT_HSUSBHOST_CLKCTRL, utmi_clk);
Govindraj.R43b62392012-02-06 03:55:34 +0000325
Mateusz Zalega16297cf2013-10-04 19:22:26 +0200326 ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
Govindraj.R43b62392012-02-06 03:55:34 +0000327 if (ret < 0)
328 return ret;
329
330 return 0;
331}
332
Lucas Stach676ae062012-09-26 00:14:35 +0200333int ehci_hcd_stop(int index)
Govindraj.R43b62392012-02-06 03:55:34 +0000334{
335 return omap_ehci_hcd_stop();
336}
337#endif
338
Sricharan508a58f2011-11-15 09:49:55 -0500339/*
340 * get_board_rev() - get board revision
341 */
342u32 get_board_rev(void)
343{
344 return 0x20;
345}