Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 1 | /* |
| 2 | * am3517evm.c - board file for TI's AM3517 family of devices. |
| 3 | * |
| 4 | * Author: Vaibhav Hiremath <hvaibhav@ti.com> |
| 5 | * |
| 6 | * Based on ti/evm/evm.c |
| 7 | * |
| 8 | * Copyright (C) 2010 |
| 9 | * Texas Instruments Incorporated - http://www.ti.com/ |
| 10 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 11 | * SPDX-License-Identifier: GPL-2.0+ |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <common.h> |
Adam Ford | b85781c | 2017-09-19 20:32:11 -0500 | [diff] [blame^] | 15 | #include <dm.h> |
| 16 | #include <ns16550.h> |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 17 | #include <asm/io.h> |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 18 | #include <asm/omap_musb.h> |
| 19 | #include <asm/arch/am35x_def.h> |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 20 | #include <asm/arch/mem.h> |
| 21 | #include <asm/arch/mux.h> |
| 22 | #include <asm/arch/sys_proto.h> |
Vaibhav Hiremath | 122e6e0 | 2011-09-03 21:47:44 -0400 | [diff] [blame] | 23 | #include <asm/arch/mmc_host_def.h> |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 24 | #include <asm/arch/musb.h> |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 25 | #include <asm/mach-types.h> |
Masahiro Yamada | 1221ce4 | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 26 | #include <linux/errno.h> |
Yegor Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 27 | #include <asm/gpio.h> |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 28 | #include <linux/usb/ch9.h> |
| 29 | #include <linux/usb/gadget.h> |
| 30 | #include <linux/usb/musb.h> |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 31 | #include <i2c.h> |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 32 | #include <netdev.h> |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 33 | #include "am3517evm.h" |
| 34 | |
| 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
Yegor Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 37 | #define AM3517_IP_SW_RESET 0x48002598 |
| 38 | #define CPGMACSS_SW_RST (1 << 1) |
Adam Ford | b85781c | 2017-09-19 20:32:11 -0500 | [diff] [blame^] | 39 | #define PHY_GPIO 30 |
| 40 | |
| 41 | /* This is only needed until SPL gets OF support */ |
| 42 | #ifdef CONFIG_SPL_BUILD |
| 43 | static const struct ns16550_platdata am3517_serial = { |
| 44 | .base = OMAP34XX_UART3, |
| 45 | .reg_shift = 2, |
| 46 | .clock = V_NS16550_CLK, |
| 47 | .fcr = UART_FCR_DEFVAL, |
| 48 | }; |
| 49 | |
| 50 | U_BOOT_DEVICE(am3517_uart) = { |
| 51 | "ns16550_serial", |
| 52 | &am3517_serial |
| 53 | }; |
| 54 | #endif |
Yegor Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 55 | |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 56 | /* |
| 57 | * Routine: board_init |
| 58 | * Description: Early hardware init. |
| 59 | */ |
| 60 | int board_init(void) |
| 61 | { |
| 62 | gpmc_init(); /* in SRAM or SDRAM, finish GPMC */ |
| 63 | /* board id for Linux */ |
| 64 | gd->bd->bi_arch_number = MACH_TYPE_OMAP3517EVM; |
| 65 | /* boot param addr */ |
| 66 | gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100); |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 71 | #ifdef CONFIG_USB_MUSB_AM35X |
| 72 | static struct musb_hdrc_config musb_config = { |
| 73 | .multipoint = 1, |
| 74 | .dyn_fifo = 1, |
| 75 | .num_eps = 16, |
| 76 | .ram_bits = 12, |
| 77 | }; |
| 78 | |
| 79 | static struct omap_musb_board_data musb_board_data = { |
| 80 | .set_phy_power = am35x_musb_phy_power, |
| 81 | .clear_irq = am35x_musb_clear_irq, |
| 82 | .reset = am35x_musb_reset, |
| 83 | }; |
| 84 | |
| 85 | static struct musb_hdrc_platform_data musb_plat = { |
Paul Kocialkowski | 95de1e2 | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 86 | #if defined(CONFIG_USB_MUSB_HOST) |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 87 | .mode = MUSB_HOST, |
Paul Kocialkowski | 95de1e2 | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 88 | #elif defined(CONFIG_USB_MUSB_GADGET) |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 89 | .mode = MUSB_PERIPHERAL, |
| 90 | #else |
Paul Kocialkowski | 95de1e2 | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 91 | #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET" |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 92 | #endif |
| 93 | .config = &musb_config, |
| 94 | .power = 250, |
| 95 | .platform_ops = &am35x_ops, |
| 96 | .board_data = &musb_board_data, |
| 97 | }; |
| 98 | |
| 99 | static void am3517_evm_musb_init(void) |
| 100 | { |
| 101 | /* |
| 102 | * Set up USB clock/mode in the DEVCONF2 register. |
| 103 | * USB2.0 PHY reference clock is 13 MHz |
| 104 | */ |
| 105 | clrsetbits_le32(&am35x_scm_general_regs->devconf2, |
| 106 | CONF2_REFFREQ | CONF2_OTGMODE | CONF2_PHY_GPIOMODE, |
| 107 | CONF2_REFFREQ_13MHZ | CONF2_SESENDEN | |
| 108 | CONF2_VBDTCTEN | CONF2_DATPOL); |
| 109 | |
| 110 | musb_register(&musb_plat, &musb_board_data, |
| 111 | (void *)AM35XX_IPSS_USBOTGSS_BASE); |
| 112 | } |
| 113 | #else |
| 114 | #define am3517_evm_musb_init() do {} while (0) |
| 115 | #endif |
| 116 | |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 117 | /* |
| 118 | * Routine: misc_init_r |
| 119 | * Description: Init i2c, ethernet, etc... (done here so udelay works) |
| 120 | */ |
| 121 | int misc_init_r(void) |
| 122 | { |
Yegor Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 123 | volatile unsigned int ctr; |
| 124 | u32 reset; |
| 125 | |
Adam Ford | 94d50be | 2017-08-07 13:11:19 -0500 | [diff] [blame] | 126 | #ifdef CONFIG_SYS_I2C_OMAP24XX |
Heiko Schocher | 6789e84 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 127 | i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE); |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 128 | #endif |
| 129 | |
Paul Kocialkowski | 679f82c | 2015-08-27 19:37:13 +0200 | [diff] [blame] | 130 | omap_die_id_display(); |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 131 | |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 132 | am3517_evm_musb_init(); |
| 133 | |
Adam Ford | b85781c | 2017-09-19 20:32:11 -0500 | [diff] [blame^] | 134 | if (gpio_request(PHY_GPIO, "gpio_30") == 0) { |
| 135 | /* activate PHY reset */ |
| 136 | gpio_direction_output(PHY_GPIO, 0); |
| 137 | gpio_set_value(PHY_GPIO, 0); |
Yegor Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 138 | |
Adam Ford | b85781c | 2017-09-19 20:32:11 -0500 | [diff] [blame^] | 139 | ctr = 0; |
| 140 | do { |
| 141 | udelay(1000); |
| 142 | ctr++; |
| 143 | } while (ctr < 300); |
Yegor Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 144 | |
Adam Ford | b85781c | 2017-09-19 20:32:11 -0500 | [diff] [blame^] | 145 | /* deactivate PHY reset */ |
| 146 | gpio_set_value(PHY_GPIO, 1); |
Yegor Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 147 | |
Adam Ford | b85781c | 2017-09-19 20:32:11 -0500 | [diff] [blame^] | 148 | /* allow the PHY to stabilize and settle down */ |
| 149 | ctr = 0; |
| 150 | do { |
| 151 | udelay(1000); |
| 152 | ctr++; |
| 153 | } while (ctr < 300); |
Yegor Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 154 | |
Adam Ford | b85781c | 2017-09-19 20:32:11 -0500 | [diff] [blame^] | 155 | /* ensure that the module is out of reset */ |
| 156 | reset = readl(AM3517_IP_SW_RESET); |
| 157 | reset &= (~CPGMACSS_SW_RST); |
| 158 | writel(reset, AM3517_IP_SW_RESET); |
| 159 | |
| 160 | /* Free requested GPIO */ |
| 161 | gpio_free(PHY_GPIO); |
| 162 | } |
Yegor Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 163 | |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | /* |
| 168 | * Routine: set_muxconf_regs |
| 169 | * Description: Setting up the configuration Mux registers specific to the |
| 170 | * hardware. Many pins need to be moved from protect to primary |
| 171 | * mode. |
| 172 | */ |
| 173 | void set_muxconf_regs(void) |
| 174 | { |
| 175 | MUX_AM3517EVM(); |
| 176 | } |
Vaibhav Hiremath | 122e6e0 | 2011-09-03 21:47:44 -0400 | [diff] [blame] | 177 | |
Masahiro Yamada | 4aa2ba3 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 178 | #if defined(CONFIG_MMC) |
Vaibhav Hiremath | 122e6e0 | 2011-09-03 21:47:44 -0400 | [diff] [blame] | 179 | int board_mmc_init(bd_t *bis) |
| 180 | { |
Nikita Kiryanov | e3913f5 | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 181 | return omap_mmc_init(0, 0, 0, -1, -1); |
Vaibhav Hiremath | 122e6e0 | 2011-09-03 21:47:44 -0400 | [diff] [blame] | 182 | } |
| 183 | #endif |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 184 | |
Paul Kocialkowski | 95de1e2 | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 185 | #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET) |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 186 | int board_eth_init(bd_t *bis) |
| 187 | { |
| 188 | int rv, n = 0; |
| 189 | |
| 190 | rv = cpu_eth_init(bis); |
| 191 | if (rv > 0) |
| 192 | n += rv; |
| 193 | |
| 194 | rv = usb_eth_initialize(bis); |
| 195 | if (rv > 0) |
| 196 | n += rv; |
| 197 | |
| 198 | return n; |
| 199 | } |
| 200 | #endif |