blob: 10031a48018fc9b13960fe0094756a0ee6b2ac78 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vaibhav Hiremathed01e452010-06-07 15:20:43 -04002/*
3 * am3517evm.c - board file for TI's AM3517 family of devices.
4 *
5 * Author: Vaibhav Hiremath <hvaibhav@ti.com>
6 *
7 * Based on ti/evm/evm.c
8 *
9 * Copyright (C) 2010
10 * Texas Instruments Incorporated - http://www.ti.com/
Vaibhav Hiremathed01e452010-06-07 15:20:43 -040011 */
12
13#include <common.h>
Adam Fordb85781c2017-09-19 20:32:11 -050014#include <dm.h>
15#include <ns16550.h>
Vaibhav Hiremathed01e452010-06-07 15:20:43 -040016#include <asm/io.h>
Ilya Yanok88919ff2012-11-06 13:48:28 +000017#include <asm/omap_musb.h>
18#include <asm/arch/am35x_def.h>
Vaibhav Hiremathed01e452010-06-07 15:20:43 -040019#include <asm/arch/mem.h>
20#include <asm/arch/mux.h>
21#include <asm/arch/sys_proto.h>
Vaibhav Hiremath122e6e02011-09-03 21:47:44 -040022#include <asm/arch/mmc_host_def.h>
Ilya Yanok88919ff2012-11-06 13:48:28 +000023#include <asm/arch/musb.h>
Vaibhav Hiremathed01e452010-06-07 15:20:43 -040024#include <asm/mach-types.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090025#include <linux/errno.h>
Yegor Yefremov6a1df372013-12-11 15:41:11 +010026#include <asm/gpio.h>
Ilya Yanok88919ff2012-11-06 13:48:28 +000027#include <linux/usb/ch9.h>
28#include <linux/usb/gadget.h>
29#include <linux/usb/musb.h>
Vaibhav Hiremathed01e452010-06-07 15:20:43 -040030#include <i2c.h>
Ilya Yanok88919ff2012-11-06 13:48:28 +000031#include <netdev.h>
Vaibhav Hiremathed01e452010-06-07 15:20:43 -040032#include "am3517evm.h"
33
34DECLARE_GLOBAL_DATA_PTR;
35
Yegor Yefremov6a1df372013-12-11 15:41:11 +010036#define AM3517_IP_SW_RESET 0x48002598
37#define CPGMACSS_SW_RST (1 << 1)
Adam Fordb85781c2017-09-19 20:32:11 -050038#define PHY_GPIO 30
39
Adam Ford86034a92019-03-31 09:18:29 -050040#if defined(CONFIG_SPL_BUILD)
41#if defined(CONFIG_SPL_OS_BOOT)
42int spl_start_uboot(void)
43{
44 /* break into full u-boot on 'c' */
45 return serial_tstc() && serial_getc() == 'c';
46}
47#endif
48#endif
Yegor Yefremov6a1df372013-12-11 15:41:11 +010049
Vaibhav Hiremathed01e452010-06-07 15:20:43 -040050/*
51 * Routine: board_init
52 * Description: Early hardware init.
53 */
54int board_init(void)
55{
56 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
57 /* board id for Linux */
58 gd->bd->bi_arch_number = MACH_TYPE_OMAP3517EVM;
59 /* boot param addr */
60 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
61
62 return 0;
63}
64
Ilya Yanok88919ff2012-11-06 13:48:28 +000065#ifdef CONFIG_USB_MUSB_AM35X
66static struct musb_hdrc_config musb_config = {
67 .multipoint = 1,
68 .dyn_fifo = 1,
69 .num_eps = 16,
70 .ram_bits = 12,
71};
72
73static struct omap_musb_board_data musb_board_data = {
74 .set_phy_power = am35x_musb_phy_power,
75 .clear_irq = am35x_musb_clear_irq,
76 .reset = am35x_musb_reset,
77};
78
79static struct musb_hdrc_platform_data musb_plat = {
Paul Kocialkowski95de1e22015-08-04 17:04:06 +020080#if defined(CONFIG_USB_MUSB_HOST)
Ilya Yanok88919ff2012-11-06 13:48:28 +000081 .mode = MUSB_HOST,
Paul Kocialkowski95de1e22015-08-04 17:04:06 +020082#elif defined(CONFIG_USB_MUSB_GADGET)
Ilya Yanok88919ff2012-11-06 13:48:28 +000083 .mode = MUSB_PERIPHERAL,
84#else
Paul Kocialkowski95de1e22015-08-04 17:04:06 +020085#error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
Ilya Yanok88919ff2012-11-06 13:48:28 +000086#endif
87 .config = &musb_config,
88 .power = 250,
89 .platform_ops = &am35x_ops,
90 .board_data = &musb_board_data,
91};
92
93static void am3517_evm_musb_init(void)
94{
95 /*
96 * Set up USB clock/mode in the DEVCONF2 register.
97 * USB2.0 PHY reference clock is 13 MHz
98 */
99 clrsetbits_le32(&am35x_scm_general_regs->devconf2,
100 CONF2_REFFREQ | CONF2_OTGMODE | CONF2_PHY_GPIOMODE,
101 CONF2_REFFREQ_13MHZ | CONF2_SESENDEN |
102 CONF2_VBDTCTEN | CONF2_DATPOL);
103
104 musb_register(&musb_plat, &musb_board_data,
105 (void *)AM35XX_IPSS_USBOTGSS_BASE);
106}
107#else
108#define am3517_evm_musb_init() do {} while (0)
109#endif
110
Vaibhav Hiremathed01e452010-06-07 15:20:43 -0400111/*
112 * Routine: misc_init_r
113 * Description: Init i2c, ethernet, etc... (done here so udelay works)
114 */
115int misc_init_r(void)
116{
Yegor Yefremov6a1df372013-12-11 15:41:11 +0100117 volatile unsigned int ctr;
118 u32 reset;
119
Adam Ford819ad5f2018-08-19 11:11:03 -0500120#if !defined(CONFIG_DM_I2C)
Adam Ford94d50be2017-08-07 13:11:19 -0500121#ifdef CONFIG_SYS_I2C_OMAP24XX
Heiko Schocher6789e842013-10-22 11:03:18 +0200122 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Vaibhav Hiremathed01e452010-06-07 15:20:43 -0400123#endif
Adam Ford819ad5f2018-08-19 11:11:03 -0500124#endif
Paul Kocialkowski679f82c2015-08-27 19:37:13 +0200125 omap_die_id_display();
Vaibhav Hiremathed01e452010-06-07 15:20:43 -0400126
Ilya Yanok88919ff2012-11-06 13:48:28 +0000127 am3517_evm_musb_init();
128
Adam Fordb85781c2017-09-19 20:32:11 -0500129 if (gpio_request(PHY_GPIO, "gpio_30") == 0) {
130 /* activate PHY reset */
131 gpio_direction_output(PHY_GPIO, 0);
132 gpio_set_value(PHY_GPIO, 0);
Yegor Yefremov6a1df372013-12-11 15:41:11 +0100133
Adam Fordb85781c2017-09-19 20:32:11 -0500134 ctr = 0;
135 do {
136 udelay(1000);
137 ctr++;
138 } while (ctr < 300);
Yegor Yefremov6a1df372013-12-11 15:41:11 +0100139
Adam Fordb85781c2017-09-19 20:32:11 -0500140 /* deactivate PHY reset */
141 gpio_set_value(PHY_GPIO, 1);
Yegor Yefremov6a1df372013-12-11 15:41:11 +0100142
Adam Fordb85781c2017-09-19 20:32:11 -0500143 /* allow the PHY to stabilize and settle down */
144 ctr = 0;
145 do {
146 udelay(1000);
147 ctr++;
148 } while (ctr < 300);
Yegor Yefremov6a1df372013-12-11 15:41:11 +0100149
Adam Fordb85781c2017-09-19 20:32:11 -0500150 /* ensure that the module is out of reset */
151 reset = readl(AM3517_IP_SW_RESET);
152 reset &= (~CPGMACSS_SW_RST);
153 writel(reset, AM3517_IP_SW_RESET);
154
155 /* Free requested GPIO */
156 gpio_free(PHY_GPIO);
157 }
Yegor Yefremov6a1df372013-12-11 15:41:11 +0100158
Vaibhav Hiremathed01e452010-06-07 15:20:43 -0400159 return 0;
160}
161
162/*
163 * Routine: set_muxconf_regs
164 * Description: Setting up the configuration Mux registers specific to the
165 * hardware. Many pins need to be moved from protect to primary
166 * mode.
167 */
168void set_muxconf_regs(void)
169{
170 MUX_AM3517EVM();
171}
Vaibhav Hiremath122e6e02011-09-03 21:47:44 -0400172
Masahiro Yamada4aa2ba32017-05-09 20:31:39 +0900173#if defined(CONFIG_MMC)
Vaibhav Hiremath122e6e02011-09-03 21:47:44 -0400174int board_mmc_init(bd_t *bis)
175{
Nikita Kiryanove3913f52012-12-03 02:19:47 +0000176 return omap_mmc_init(0, 0, 0, -1, -1);
Vaibhav Hiremath122e6e02011-09-03 21:47:44 -0400177}
178#endif
Ilya Yanok88919ff2012-11-06 13:48:28 +0000179
Paul Kocialkowski95de1e22015-08-04 17:04:06 +0200180#if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)
Ilya Yanok88919ff2012-11-06 13:48:28 +0000181int board_eth_init(bd_t *bis)
182{
183 int rv, n = 0;
184
185 rv = cpu_eth_init(bis);
186 if (rv > 0)
187 n += rv;
188
189 rv = usb_eth_initialize(bis);
190 if (rv > 0)
191 n += rv;
192
193 return n;
194}
195#endif