blob: 9ebecfdbf581a6b259b01d52bc586099039e1287 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Steve Sakoman6b810ff2010-06-11 20:35:26 -07002/*
3 * (C) Copyright 2010
4 * Texas Instruments Incorporated, <www.ti.com>
5 * Steve Sakoman <steve@sakoman.com>
Steve Sakoman6b810ff2010-06-11 20:35:26 -07006 */
7#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060010#include <net.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060011#include <asm/mach-types.h>
Steve Sakoman6b810ff2010-06-11 20:35:26 -070012#include <asm/arch/sys_proto.h>
Sukumar Ghoraie9edff82010-09-18 20:56:18 -070013#include <asm/arch/mmc_host_def.h>
Lokesh Vutla61c517f2013-05-30 02:54:32 +000014#include <asm/arch/clock.h>
Chris Lalancette5008c132011-12-13 09:41:12 +000015#include <asm/arch/gpio.h>
Govindraj.Redc16a02012-02-06 03:55:34 +000016#include <asm/gpio.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060017#include <env.h>
Paul Kocialkowski4bbf2b32016-02-27 19:18:52 +010018#include <twl6030.h>
Steve Sakoman6b810ff2010-06-11 20:35:26 -070019
Aneesh Vf908b632011-07-21 09:10:01 -040020#include "panda_mux_data.h"
Steve Sakoman9bb65b52010-07-15 13:43:10 -070021
Tom Riniceed5d22017-05-12 22:33:27 -040022#ifdef CONFIG_USB_EHCI_HCD
Govindraj.Redc16a02012-02-06 03:55:34 +000023#include <usb.h>
24#include <asm/arch/ehci.h>
25#include <asm/ehci-omap.h>
26#endif
27
Chris Lalancette5008c132011-12-13 09:41:12 +000028#define PANDA_ULPI_PHY_TYPE_GPIO 182
Dan Murphye56459e2013-06-13 11:21:13 -050029#define PANDA_BOARD_ID_1_GPIO 101
30#define PANDA_ES_BOARD_ID_1_GPIO 48
31#define PANDA_BOARD_ID_2_GPIO 171
32#define PANDA_ES_BOARD_ID_3_GPIO 3
33#define PANDA_ES_BOARD_ID_4_GPIO 2
Chris Lalancette5008c132011-12-13 09:41:12 +000034
Steve Sakoman6b810ff2010-06-11 20:35:26 -070035DECLARE_GLOBAL_DATA_PTR;
36
37const struct omap_sysinfo sysinfo = {
38 "Board: OMAP4 Panda\n"
39};
40
Chris Lalancette5008c132011-12-13 09:41:12 +000041struct omap4_scrm_regs *const scrm = (struct omap4_scrm_regs *)0x4a30a000;
42
Steve Sakoman6b810ff2010-06-11 20:35:26 -070043/**
44 * @brief board_init
45 *
46 * @return 0
47 */
48int board_init(void)
49{
Steve Sakoman9b8ea4e2010-07-15 16:19:16 -040050 gpmc_init();
51
Steve Sakoman6b810ff2010-06-11 20:35:26 -070052 gd->bd->bi_arch_number = MACH_TYPE_OMAP4_PANDA;
53 gd->bd->bi_boot_params = (0x80000000 + 0x100); /* boot param addr */
54
55 return 0;
56}
57
58int board_eth_init(bd_t *bis)
59{
60 return 0;
61}
62
Dan Murphye56459e2013-06-13 11:21:13 -050063/*
64* Routine: get_board_revision
65* Description: Detect if we are running on a panda revision A1-A6,
66* or an ES panda board. This can be done by reading
67* the level of GPIOs and checking the processor revisions.
68* This should result in:
69* Panda 4430:
70* GPIO171, GPIO101, GPIO182: 0 1 1 => A1-A5
71* GPIO171, GPIO101, GPIO182: 1 0 1 => A6
72* Panda ES:
73* GPIO2, GPIO3, GPIO171, GPIO48, GPIO182: 0 0 0 1 1 => B1/B2
74* GPIO2, GPIO3, GPIO171, GPIO48, GPIO182: 0 0 1 1 1 => B3
75*/
76int get_board_revision(void)
77{
78 int board_id0, board_id1, board_id2;
79 int board_id3, board_id4;
80 int board_id;
81
82 int processor_rev = omap_revision();
83
84 /* Setup the mux for the common board ID pins (gpio 171 and 182) */
85 writew((IEN | M3), (*ctrl)->control_padconf_core_base + UNIPRO_TX0);
86 writew((IEN | M3), (*ctrl)->control_padconf_core_base + FREF_CLK2_OUT);
87
88 board_id0 = gpio_get_value(PANDA_ULPI_PHY_TYPE_GPIO);
89 board_id2 = gpio_get_value(PANDA_BOARD_ID_2_GPIO);
90
91 if ((processor_rev >= OMAP4460_ES1_0 &&
92 processor_rev <= OMAP4460_ES1_1)) {
93 /*
94 * Setup the mux for the ES specific board ID pins (gpio 101,
95 * 2 and 3.
96 */
97 writew((IEN | M3), (*ctrl)->control_padconf_core_base +
98 GPMC_A24);
99 writew((IEN | M3), (*ctrl)->control_padconf_core_base +
100 UNIPRO_RY0);
101 writew((IEN | M3), (*ctrl)->control_padconf_core_base +
102 UNIPRO_RX1);
103
104 board_id1 = gpio_get_value(PANDA_ES_BOARD_ID_1_GPIO);
105 board_id3 = gpio_get_value(PANDA_ES_BOARD_ID_3_GPIO);
106 board_id4 = gpio_get_value(PANDA_ES_BOARD_ID_4_GPIO);
107
108#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Simon Glass6a38e412017-08-03 12:22:09 -0600109 env_set("board_name", "panda-es");
Dan Murphye56459e2013-06-13 11:21:13 -0500110#endif
111 board_id = ((board_id4 << 4) | (board_id3 << 3) |
112 (board_id2 << 2) | (board_id1 << 1) | (board_id0));
113 } else {
114 /* Setup the mux for the Ax specific board ID pins (gpio 101) */
115 writew((IEN | M3), (*ctrl)->control_padconf_core_base +
116 FREF_CLK2_OUT);
117
118 board_id1 = gpio_get_value(PANDA_BOARD_ID_1_GPIO);
119 board_id = ((board_id2 << 2) | (board_id1 << 1) | (board_id0));
120
121#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
122 if ((board_id >= 0x3) && (processor_rev == OMAP4430_ES2_3))
Simon Glass6a38e412017-08-03 12:22:09 -0600123 env_set("board_name", "panda-a4");
Dan Murphye56459e2013-06-13 11:21:13 -0500124#endif
125 }
126
127 return board_id;
128}
129
Steve Sakoman6b810ff2010-06-11 20:35:26 -0700130/**
Hardik Patel8662fc62013-11-27 21:16:21 +0530131 * is_panda_es_rev_b3() - Detect if we are running on rev B3 of panda board ES
132 *
133 *
134 * Detect if we are running on B3 version of ES panda board,
135 * This can be done by reading the level of GPIO 171 and checking the
136 * processor revisions.
137 * GPIO171: 1 => Panda ES Rev B3
138 *
139 * Return : return 1 if Panda ES Rev B3 , else return 0
140 */
141u8 is_panda_es_rev_b3(void)
142{
143 int processor_rev = omap_revision();
144 int ret = 0;
145
146 if ((processor_rev >= OMAP4460_ES1_0 &&
147 processor_rev <= OMAP4460_ES1_1)) {
148
149 /* Setup the mux for the common board ID pins (gpio 171) */
150 writew((IEN | M3),
151 (*ctrl)->control_padconf_core_base + UNIPRO_TX0);
152
153 /* if processor_rev is panda ES and GPIO171 is 1,it is rev b3 */
154 ret = gpio_get_value(PANDA_BOARD_ID_2_GPIO);
155 }
156 return ret;
157}
158
159#ifdef CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS
160/*
161 * emif_get_reg_dump() - emif_get_reg_dump strong function
162 *
163 * @emif_nr - emif base
164 * @regs - reg dump of timing values
165 *
166 * Strong function to override emif_get_reg_dump weak function in sdram_elpida.c
167 */
168void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
169{
170 u32 omap4_rev = omap_revision();
171
172 /* Same devices and geometry on both EMIFs */
173 if (omap4_rev == OMAP4430_ES1_0)
174 *regs = &emif_regs_elpida_380_mhz_1cs;
175 else if (omap4_rev == OMAP4430_ES2_0)
176 *regs = &emif_regs_elpida_200_mhz_2cs;
177 else if (omap4_rev == OMAP4430_ES2_3)
178 *regs = &emif_regs_elpida_400_mhz_1cs;
179 else if (omap4_rev < OMAP4470_ES1_0) {
180 if(is_panda_es_rev_b3())
181 *regs = &emif_regs_elpida_400_mhz_1cs;
182 else
183 *regs = &emif_regs_elpida_400_mhz_2cs;
184 }
185 else
186 *regs = &emif_regs_elpida_400_mhz_1cs;
187}
Nishanth Menonc22ced32014-12-18 15:28:35 -0600188
189void emif_get_dmm_regs(const struct dmm_lisa_map_regs
190 **dmm_lisa_regs)
191{
192 u32 omap_rev = omap_revision();
193
194 if (omap_rev == OMAP4430_ES1_0)
195 *dmm_lisa_regs = &lisa_map_2G_x_1_x_2;
196 else if (omap_rev == OMAP4430_ES2_3)
197 *dmm_lisa_regs = &lisa_map_2G_x_2_x_2;
198 else if (omap_rev < OMAP4460_ES1_0)
199 *dmm_lisa_regs = &lisa_map_2G_x_2_x_2;
200 else
201 *dmm_lisa_regs = &ma_lisa_map_2G_x_2_x_2;
202}
203
Hardik Patel8662fc62013-11-27 21:16:21 +0530204#endif
205
206/**
Steve Sakoman6b810ff2010-06-11 20:35:26 -0700207 * @brief misc_init_r - Configure Panda board specific configurations
208 * such as power configurations, ethernet initialization as phase2 of
209 * boot sequence
210 *
211 * @return 0
212 */
213int misc_init_r(void)
214{
Chris Lalancette5008c132011-12-13 09:41:12 +0000215 int phy_type;
216 u32 auxclk, altclksrc;
217
218 /* EHCI is not supported on ES1.0 */
219 if (omap_revision() == OMAP4430_ES1_0)
220 return 0;
221
Dan Murphye56459e2013-06-13 11:21:13 -0500222 get_board_revision();
Dan Murphye44c6d72013-04-18 06:29:53 +0000223
Chris Lalancette5008c132011-12-13 09:41:12 +0000224 gpio_direction_input(PANDA_ULPI_PHY_TYPE_GPIO);
225 phy_type = gpio_get_value(PANDA_ULPI_PHY_TYPE_GPIO);
226
227 if (phy_type == 1) {
228 /* ULPI PHY supplied by auxclk3 derived from sys_clk */
229 debug("ULPI PHY supplied by auxclk3\n");
230
231 auxclk = readl(&scrm->auxclk3);
232 /* Select sys_clk */
233 auxclk &= ~AUXCLK_SRCSELECT_MASK;
234 auxclk |= AUXCLK_SRCSELECT_SYS_CLK << AUXCLK_SRCSELECT_SHIFT;
235 /* Set the divisor to 2 */
236 auxclk &= ~AUXCLK_CLKDIV_MASK;
237 auxclk |= AUXCLK_CLKDIV_2 << AUXCLK_CLKDIV_SHIFT;
238 /* Request auxilary clock #3 */
239 auxclk |= AUXCLK_ENABLE_MASK;
240
241 writel(auxclk, &scrm->auxclk3);
Dan Murphy9793ba82013-06-13 11:21:26 -0500242 } else {
Chris Lalancette5008c132011-12-13 09:41:12 +0000243 /* ULPI PHY supplied by auxclk1 derived from PER dpll */
244 debug("ULPI PHY supplied by auxclk1\n");
245
246 auxclk = readl(&scrm->auxclk1);
247 /* Select per DPLL */
248 auxclk &= ~AUXCLK_SRCSELECT_MASK;
249 auxclk |= AUXCLK_SRCSELECT_PER_DPLL << AUXCLK_SRCSELECT_SHIFT;
250 /* Set the divisor to 16 */
251 auxclk &= ~AUXCLK_CLKDIV_MASK;
252 auxclk |= AUXCLK_CLKDIV_16 << AUXCLK_CLKDIV_SHIFT;
253 /* Request auxilary clock #3 */
254 auxclk |= AUXCLK_ENABLE_MASK;
255
256 writel(auxclk, &scrm->auxclk1);
257 }
258
259 altclksrc = readl(&scrm->altclksrc);
260
261 /* Activate alternate system clock supplier */
262 altclksrc &= ~ALTCLKSRC_MODE_MASK;
263 altclksrc |= ALTCLKSRC_MODE_ACTIVE;
264
265 /* enable clocks */
266 altclksrc |= ALTCLKSRC_ENABLE_INT_MASK | ALTCLKSRC_ENABLE_EXT_MASK;
267
268 writel(altclksrc, &scrm->altclksrc);
269
Paul Kocialkowski2edadee2015-08-27 19:37:12 +0200270 omap_die_id_usbethaddr();
Dan Murphy50663272013-10-10 08:54:23 -0500271
Steve Sakoman6b810ff2010-06-11 20:35:26 -0700272 return 0;
273}
Steve Sakoman9bb65b52010-07-15 13:43:10 -0700274
Paul Kocialkowskia00b1e52016-02-27 19:18:56 +0100275void set_muxconf_regs(void)
Sricharan9310ff72011-11-15 09:49:55 -0500276{
Lokesh Vutla37bce592013-05-30 02:54:30 +0000277 do_set_mux((*ctrl)->control_padconf_core_base,
278 core_padconf_array_essential,
Sricharan9310ff72011-11-15 09:49:55 -0500279 sizeof(core_padconf_array_essential) /
280 sizeof(struct pad_conf_entry));
281
Lokesh Vutla37bce592013-05-30 02:54:30 +0000282 do_set_mux((*ctrl)->control_padconf_wkup_base,
283 wkup_padconf_array_essential,
Sricharan9310ff72011-11-15 09:49:55 -0500284 sizeof(wkup_padconf_array_essential) /
285 sizeof(struct pad_conf_entry));
286
287 if (omap_revision() >= OMAP4460_ES1_0)
Lokesh Vutla37bce592013-05-30 02:54:30 +0000288 do_set_mux((*ctrl)->control_padconf_wkup_base,
Dan Murphy9793ba82013-06-13 11:21:26 -0500289 wkup_padconf_array_essential_4460,
290 sizeof(wkup_padconf_array_essential_4460) /
291 sizeof(struct pad_conf_entry));
Sricharan9310ff72011-11-15 09:49:55 -0500292}
293
Masahiro Yamada0a780172017-05-09 20:31:39 +0900294#if defined(CONFIG_MMC)
Sukumar Ghoraie9edff82010-09-18 20:56:18 -0700295int board_mmc_init(bd_t *bis)
296{
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +0000297 return omap_mmc_init(0, 0, 0, -1, -1);
Sukumar Ghoraie9edff82010-09-18 20:56:18 -0700298}
Paul Kocialkowski4bbf2b32016-02-27 19:18:52 +0100299
Jean-Jacques Hiblote0e319a2017-02-01 11:39:14 +0100300#if !defined(CONFIG_SPL_BUILD)
Paul Kocialkowski4bbf2b32016-02-27 19:18:52 +0100301void board_mmc_power_init(void)
302{
303 twl6030_power_mmc_init(0);
304}
Govindraj.Redc16a02012-02-06 03:55:34 +0000305#endif
Jean-Jacques Hiblote0e319a2017-02-01 11:39:14 +0100306#endif
Govindraj.Redc16a02012-02-06 03:55:34 +0000307
Tom Riniceed5d22017-05-12 22:33:27 -0400308#ifdef CONFIG_USB_EHCI_HCD
Govindraj.Redc16a02012-02-06 03:55:34 +0000309
310static struct omap_usbhs_board_data usbhs_bdata = {
311 .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
312 .port_mode[1] = OMAP_USBHS_PORT_MODE_UNUSED,
313 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
314};
315
Troy Kisky7d6bbb92013-10-10 15:27:57 -0700316int ehci_hcd_init(int index, enum usb_init_type init,
317 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Govindraj.Redc16a02012-02-06 03:55:34 +0000318{
319 int ret;
320 unsigned int utmi_clk;
321
322 /* Now we can enable our port clocks */
323 utmi_clk = readl((void *)CM_L3INIT_HSUSBHOST_CLKCTRL);
324 utmi_clk |= HSUSBHOST_CLKCTRL_CLKSEL_UTMI_P1_MASK;
Wolfgang Denk42b97cb2014-03-25 14:49:48 +0100325 setbits_le32((void *)CM_L3INIT_HSUSBHOST_CLKCTRL, utmi_clk);
Govindraj.Redc16a02012-02-06 03:55:34 +0000326
Mateusz Zalegad862f892013-10-04 19:22:26 +0200327 ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
Govindraj.Redc16a02012-02-06 03:55:34 +0000328 if (ret < 0)
329 return ret;
330
331 return 0;
332}
333
Lucas Stach3494a4c2012-09-26 00:14:35 +0200334int ehci_hcd_stop(int index)
Govindraj.Redc16a02012-02-06 03:55:34 +0000335{
336 return omap_ehci_hcd_stop();
337}
Sukumar Ghoraie9edff82010-09-18 20:56:18 -0700338#endif
Sricharan9310ff72011-11-15 09:49:55 -0500339
340/*
341 * get_board_rev() - get board revision
342 */
343u32 get_board_rev(void)
344{
345 return 0x20;
346}