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