Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 2 | /* |
| 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 Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
Adam Ford | b85781c | 2017-09-19 20:32:11 -0500 | [diff] [blame] | 14 | #include <dm.h> |
| 15 | #include <ns16550.h> |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 16 | #include <asm/io.h> |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 17 | #include <asm/omap_musb.h> |
| 18 | #include <asm/arch/am35x_def.h> |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 19 | #include <asm/arch/mem.h> |
| 20 | #include <asm/arch/mux.h> |
| 21 | #include <asm/arch/sys_proto.h> |
Vaibhav Hiremath | 122e6e0 | 2011-09-03 21:47:44 -0400 | [diff] [blame] | 22 | #include <asm/arch/mmc_host_def.h> |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 23 | #include <asm/arch/musb.h> |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 24 | #include <asm/mach-types.h> |
Masahiro Yamada | 1221ce4 | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 25 | #include <linux/errno.h> |
Yegor Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 26 | #include <asm/gpio.h> |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 27 | #include <linux/usb/ch9.h> |
| 28 | #include <linux/usb/gadget.h> |
| 29 | #include <linux/usb/musb.h> |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 30 | #include <i2c.h> |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 31 | #include <netdev.h> |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 32 | #include "am3517evm.h" |
| 33 | |
| 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
Yegor Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 36 | #define AM3517_IP_SW_RESET 0x48002598 |
| 37 | #define CPGMACSS_SW_RST (1 << 1) |
Adam Ford | b85781c | 2017-09-19 20:32:11 -0500 | [diff] [blame] | 38 | #define PHY_GPIO 30 |
| 39 | |
Adam Ford | 86034a9 | 2019-03-31 09:18:29 -0500 | [diff] [blame^] | 40 | #if defined(CONFIG_SPL_BUILD) |
| 41 | #if defined(CONFIG_SPL_OS_BOOT) |
| 42 | int 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 Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 49 | |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 50 | /* |
| 51 | * Routine: board_init |
| 52 | * Description: Early hardware init. |
| 53 | */ |
| 54 | int 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 Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 65 | #ifdef CONFIG_USB_MUSB_AM35X |
| 66 | static struct musb_hdrc_config musb_config = { |
| 67 | .multipoint = 1, |
| 68 | .dyn_fifo = 1, |
| 69 | .num_eps = 16, |
| 70 | .ram_bits = 12, |
| 71 | }; |
| 72 | |
| 73 | static 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 | |
| 79 | static struct musb_hdrc_platform_data musb_plat = { |
Paul Kocialkowski | 95de1e2 | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 80 | #if defined(CONFIG_USB_MUSB_HOST) |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 81 | .mode = MUSB_HOST, |
Paul Kocialkowski | 95de1e2 | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 82 | #elif defined(CONFIG_USB_MUSB_GADGET) |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 83 | .mode = MUSB_PERIPHERAL, |
| 84 | #else |
Paul Kocialkowski | 95de1e2 | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 85 | #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] | 86 | #endif |
| 87 | .config = &musb_config, |
| 88 | .power = 250, |
| 89 | .platform_ops = &am35x_ops, |
| 90 | .board_data = &musb_board_data, |
| 91 | }; |
| 92 | |
| 93 | static 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 Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 111 | /* |
| 112 | * Routine: misc_init_r |
| 113 | * Description: Init i2c, ethernet, etc... (done here so udelay works) |
| 114 | */ |
| 115 | int misc_init_r(void) |
| 116 | { |
Yegor Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 117 | volatile unsigned int ctr; |
| 118 | u32 reset; |
| 119 | |
Adam Ford | 819ad5f | 2018-08-19 11:11:03 -0500 | [diff] [blame] | 120 | #if !defined(CONFIG_DM_I2C) |
Adam Ford | 94d50be | 2017-08-07 13:11:19 -0500 | [diff] [blame] | 121 | #ifdef CONFIG_SYS_I2C_OMAP24XX |
Heiko Schocher | 6789e84 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 122 | i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE); |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 123 | #endif |
Adam Ford | 819ad5f | 2018-08-19 11:11:03 -0500 | [diff] [blame] | 124 | #endif |
Paul Kocialkowski | 679f82c | 2015-08-27 19:37:13 +0200 | [diff] [blame] | 125 | omap_die_id_display(); |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 126 | |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 127 | am3517_evm_musb_init(); |
| 128 | |
Adam Ford | b85781c | 2017-09-19 20:32:11 -0500 | [diff] [blame] | 129 | 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 Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 133 | |
Adam Ford | b85781c | 2017-09-19 20:32:11 -0500 | [diff] [blame] | 134 | ctr = 0; |
| 135 | do { |
| 136 | udelay(1000); |
| 137 | ctr++; |
| 138 | } while (ctr < 300); |
Yegor Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 139 | |
Adam Ford | b85781c | 2017-09-19 20:32:11 -0500 | [diff] [blame] | 140 | /* deactivate PHY reset */ |
| 141 | gpio_set_value(PHY_GPIO, 1); |
Yegor Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 142 | |
Adam Ford | b85781c | 2017-09-19 20:32:11 -0500 | [diff] [blame] | 143 | /* allow the PHY to stabilize and settle down */ |
| 144 | ctr = 0; |
| 145 | do { |
| 146 | udelay(1000); |
| 147 | ctr++; |
| 148 | } while (ctr < 300); |
Yegor Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 149 | |
Adam Ford | b85781c | 2017-09-19 20:32:11 -0500 | [diff] [blame] | 150 | /* 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 Yefremov | 6a1df37 | 2013-12-11 15:41:11 +0100 | [diff] [blame] | 158 | |
Vaibhav Hiremath | ed01e45 | 2010-06-07 15:20:43 -0400 | [diff] [blame] | 159 | 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 | */ |
| 168 | void set_muxconf_regs(void) |
| 169 | { |
| 170 | MUX_AM3517EVM(); |
| 171 | } |
Vaibhav Hiremath | 122e6e0 | 2011-09-03 21:47:44 -0400 | [diff] [blame] | 172 | |
Masahiro Yamada | 4aa2ba3 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 173 | #if defined(CONFIG_MMC) |
Vaibhav Hiremath | 122e6e0 | 2011-09-03 21:47:44 -0400 | [diff] [blame] | 174 | int board_mmc_init(bd_t *bis) |
| 175 | { |
Nikita Kiryanov | e3913f5 | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 176 | return omap_mmc_init(0, 0, 0, -1, -1); |
Vaibhav Hiremath | 122e6e0 | 2011-09-03 21:47:44 -0400 | [diff] [blame] | 177 | } |
| 178 | #endif |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 179 | |
Paul Kocialkowski | 95de1e2 | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 180 | #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET) |
Ilya Yanok | 88919ff | 2012-11-06 13:48:28 +0000 | [diff] [blame] | 181 | int 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 |