blob: 7b6fd5c737a1094f198b12bb3b8ec0531eb6b45c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ash Charles48971ac2014-05-14 08:34:34 -07002/*
3 * (C) Copyright 2013
4 * Gumstix Inc. <www.gumstix.com>
5 * Maintainer: Ash Charles <ash@gumstix.com>
Ash Charles48971ac2014-05-14 08:34:34 -07006 */
7#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -06009#include <net.h>
Ash Charles48971ac2014-05-14 08:34:34 -070010#include <netdev.h>
11#include <asm/arch/sys_proto.h>
12#include <asm/arch/mmc_host_def.h>
13#include <twl6030.h>
14#include <asm/emif.h>
15#include <asm/arch/clock.h>
16#include <asm/arch/gpio.h>
17#include <asm/gpio.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060018#include <asm/mach-types.h>
Ash Charles48971ac2014-05-14 08:34:34 -070019
20#include "duovero_mux_data.h"
21
22#define WIFI_EN 43
23
24#if defined(CONFIG_CMD_NET)
25#define SMSC_NRESET 45
26static void setup_net_chip(void);
27#endif
28
Tom Riniceed5d22017-05-12 22:33:27 -040029#ifdef CONFIG_USB_EHCI_HCD
Ash Charles48971ac2014-05-14 08:34:34 -070030#include <usb.h>
31#include <asm/arch/ehci.h>
32#include <asm/ehci-omap.h>
33#endif
34
35DECLARE_GLOBAL_DATA_PTR;
36
37const struct omap_sysinfo sysinfo = {
38 "Board: duovero\n"
39};
40
41struct omap4_scrm_regs *const scrm = (struct omap4_scrm_regs *)0x4a30a000;
42
43/**
44 * @brief board_init
45 *
46 * @return 0
47 */
48int board_init(void)
49{
50 gpmc_init();
51
Tom Rinid997f7c2017-01-25 20:42:36 -050052 gd->bd->bi_arch_number = MACH_TYPE_DUOVERO;
Ash Charles48971ac2014-05-14 08:34:34 -070053 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
54
55 return 0;
56}
57
58/**
59 * @brief misc_init_r - Configure board specific configurations
60 * such as power configurations, ethernet initialization as phase2 of
61 * boot sequence
62 *
63 * @return 0
64 */
65int misc_init_r(void)
66{
67 int ret = 0;
68 u8 val;
69
70 /* wifi setup: first enable 32Khz clock from 6030 pmic */
71 val = 0xe1;
72 ret = i2c_write(TWL6030_CHIP_PM, 0xbe, 1, &val, 1);
73 if (ret)
74 printf("Failed to enable 32Khz clock to wifi module\n");
75
76 /* then setup WIFI_EN as an output pin and send reset pulse */
77 if (!gpio_request(WIFI_EN, "")) {
78 gpio_direction_output(WIFI_EN, 0);
79 gpio_set_value(WIFI_EN, 1);
80 udelay(1);
81 gpio_set_value(WIFI_EN, 0);
82 udelay(1);
83 gpio_set_value(WIFI_EN, 1);
84 }
85
86#if defined(CONFIG_CMD_NET)
87 setup_net_chip();
88#endif
89 return 0;
90}
91
Paul Kocialkowskia00b1e52016-02-27 19:18:56 +010092void set_muxconf_regs(void)
Ash Charles48971ac2014-05-14 08:34:34 -070093{
94 do_set_mux((*ctrl)->control_padconf_core_base,
95 core_padconf_array_essential,
96 sizeof(core_padconf_array_essential) /
97 sizeof(struct pad_conf_entry));
98
99 do_set_mux((*ctrl)->control_padconf_wkup_base,
100 wkup_padconf_array_essential,
101 sizeof(wkup_padconf_array_essential) /
102 sizeof(struct pad_conf_entry));
103
104 do_set_mux((*ctrl)->control_padconf_core_base,
105 core_padconf_array_non_essential,
106 sizeof(core_padconf_array_non_essential) /
107 sizeof(struct pad_conf_entry));
108
109 do_set_mux((*ctrl)->control_padconf_wkup_base,
110 wkup_padconf_array_non_essential,
111 sizeof(wkup_padconf_array_non_essential) /
112 sizeof(struct pad_conf_entry));
113}
114
Masahiro Yamada0a780172017-05-09 20:31:39 +0900115#if defined(CONFIG_MMC)
Ash Charles48971ac2014-05-14 08:34:34 -0700116int board_mmc_init(bd_t *bis)
117{
118 return omap_mmc_init(0, 0, 0, -1, -1);
119}
Ash Charles48971ac2014-05-14 08:34:34 -0700120
Jean-Jacques Hiblote0e319a2017-02-01 11:39:14 +0100121#if !defined(CONFIG_SPL_BUILD)
Paul Kocialkowski4bbf2b32016-02-27 19:18:52 +0100122void board_mmc_power_init(void)
123{
124 twl6030_power_mmc_init(0);
125}
126#endif
Jean-Jacques Hiblote0e319a2017-02-01 11:39:14 +0100127#endif
Ash Charles48971ac2014-05-14 08:34:34 -0700128
129#if defined(CONFIG_CMD_NET)
130
131#define GPMC_SIZE_16M 0xF
132#define GPMC_BASEADDR_MASK 0x3F
133#define GPMC_CS_ENABLE 0x1
134
Ladislav Michld5b1c272016-07-12 20:28:16 +0200135static void enable_gpmc_net_config(const u32 *gpmc_config, const struct gpmc_cs *cs,
Ash Charles48971ac2014-05-14 08:34:34 -0700136 u32 base, u32 size)
137{
138 writel(0, &cs->config7);
139 sdelay(1000);
140 /* Delay for settling */
141 writel(gpmc_config[0], &cs->config1);
142 writel(gpmc_config[1], &cs->config2);
143 writel(gpmc_config[2], &cs->config3);
144 writel(gpmc_config[3], &cs->config4);
145 writel(gpmc_config[4], &cs->config5);
146 writel(gpmc_config[5], &cs->config6);
147
148 /*
149 * Enable the config. size is the CS size and goes in
150 * bits 11:8. We set bit 6 to enable this CS and the base
151 * address goes into bits 5:0.
152 */
153 writel((size << 8) | (GPMC_CS_ENABLE << 6) |
154 ((base >> 24) & GPMC_BASEADDR_MASK),
155 &cs->config7);
156
157 sdelay(2000);
158}
159
160/* GPMC CS configuration for an SMSC LAN9221 ethernet controller */
161#define NET_LAN9221_GPMC_CONFIG1 0x2a001203
162#define NET_LAN9221_GPMC_CONFIG2 0x000a0a02
163#define NET_LAN9221_GPMC_CONFIG3 0x00020200
164#define NET_LAN9221_GPMC_CONFIG4 0x0a030a03
165#define NET_LAN9221_GPMC_CONFIG5 0x000a0a0a
166#define NET_LAN9221_GPMC_CONFIG6 0x8a070707
167#define NET_LAN9221_GPMC_CONFIG7 0x00000f6c
168
169/* GPMC definitions for LAN9221 chips on expansion boards */
170static const u32 gpmc_lan_config[] = {
171 NET_LAN9221_GPMC_CONFIG1,
172 NET_LAN9221_GPMC_CONFIG2,
173 NET_LAN9221_GPMC_CONFIG3,
174 NET_LAN9221_GPMC_CONFIG4,
175 NET_LAN9221_GPMC_CONFIG5,
176 NET_LAN9221_GPMC_CONFIG6,
177 /*CONFIG7- computed as params */
178};
179
180/*
181 * Routine: setup_net_chip
182 * Description: Setting up the configuration GPMC registers specific to the
183 * Ethernet hardware.
184 */
185static void setup_net_chip(void)
186{
187 enable_gpmc_net_config(gpmc_lan_config, &gpmc_cfg->cs[5], 0x2C000000,
188 GPMC_SIZE_16M);
189
190 /* Make GPIO SMSC_NRESET as output pin and send reset pulse */
191 if (!gpio_request(SMSC_NRESET, "")) {
192 gpio_direction_output(SMSC_NRESET, 0);
193 gpio_set_value(SMSC_NRESET, 1);
194 udelay(1);
195 gpio_set_value(SMSC_NRESET, 0);
196 udelay(1);
197 gpio_set_value(SMSC_NRESET, 1);
198 }
199}
200#endif
201
202int board_eth_init(bd_t *bis)
203{
204 int rc = 0;
205#ifdef CONFIG_SMC911X
206 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
207#endif
208 return rc;
209}
210
Tom Riniceed5d22017-05-12 22:33:27 -0400211#ifdef CONFIG_USB_EHCI_HCD
Ash Charles48971ac2014-05-14 08:34:34 -0700212
213static struct omap_usbhs_board_data usbhs_bdata = {
214 .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
215 .port_mode[1] = OMAP_USBHS_PORT_MODE_UNUSED,
216 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
217};
218
219int ehci_hcd_init(int index, enum usb_init_type init,
220 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
221{
222 int ret;
223 unsigned int utmi_clk;
224 u32 auxclk, altclksrc;
225
226 /* Now we can enable our port clocks */
227 utmi_clk = readl((void *)CM_L3INIT_HSUSBHOST_CLKCTRL);
228 utmi_clk |= HSUSBHOST_CLKCTRL_CLKSEL_UTMI_P1_MASK;
229 setbits_le32((void *)CM_L3INIT_HSUSBHOST_CLKCTRL, utmi_clk);
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 writel(auxclk, &scrm->auxclk3);
241
242 altclksrc = readl(&scrm->altclksrc);
243
244 /* Activate alternate system clock supplier */
245 altclksrc &= ~ALTCLKSRC_MODE_MASK;
246 altclksrc |= ALTCLKSRC_MODE_ACTIVE;
247
248 /* enable clocks */
249 altclksrc |= ALTCLKSRC_ENABLE_INT_MASK | ALTCLKSRC_ENABLE_EXT_MASK;
250
251 writel(altclksrc, &scrm->altclksrc);
252
253 ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
254 if (ret < 0)
255 return ret;
256
257 return 0;
258}
259
260int ehci_hcd_stop(int index)
261{
262 return omap_ehci_hcd_stop();
263}
264#endif
265
266/*
267 * get_board_rev() - get board revision
268 */
269u32 get_board_rev(void)
270{
271 return 0x20;
272}