Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Ethernet driver for TI TMS320DM644x (DaVinci) chips. |
| 4 | * |
| 5 | * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net> |
| 6 | * |
| 7 | * Parts shamelessly stolen from TI's dm644x_emac.c. Original copyright |
| 8 | * follows: |
| 9 | * |
| 10 | * ---------------------------------------------------------------------------- |
| 11 | * |
| 12 | * dm644x_emac.c |
| 13 | * |
| 14 | * TI DaVinci (DM644X) EMAC peripheral driver source for DV-EVM |
| 15 | * |
| 16 | * Copyright (C) 2005 Texas Instruments. |
| 17 | * |
| 18 | * ---------------------------------------------------------------------------- |
| 19 | * |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 20 | * Modifications: |
| 21 | * ver. 1.0: Sep 2005, Anant Gole - Created EMAC version for uBoot. |
| 22 | * ver 1.1: Nov 2005, Anant Gole - Extended the RX logic for multiple descriptors |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 23 | */ |
| 24 | #include <common.h> |
| 25 | #include <command.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 26 | #include <cpu_func.h> |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 27 | #include <net.h> |
| 28 | #include <miiphy.h> |
Ben Warren | 5301bbf | 2009-05-26 00:34:07 -0700 | [diff] [blame] | 29 | #include <malloc.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame^] | 30 | #include <asm/cache.h> |
Ilya Yanok | ff67276 | 2011-11-28 06:37:33 +0000 | [diff] [blame] | 31 | #include <linux/compiler.h> |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 32 | #include <asm/arch/emac_defs.h> |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 33 | #include <asm/io.h> |
Ilya Yanok | 5f732f7 | 2011-11-28 06:37:29 +0000 | [diff] [blame] | 34 | #include "davinci_emac.h" |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 35 | |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 36 | unsigned int emac_dbg = 0; |
| 37 | #define debug_emac(fmt,args...) if (emac_dbg) printf(fmt,##args) |
| 38 | |
Ilya Yanok | 518036e | 2011-11-28 06:37:30 +0000 | [diff] [blame] | 39 | #ifdef EMAC_HW_RAM_ADDR |
| 40 | static inline unsigned long BD_TO_HW(unsigned long x) |
| 41 | { |
| 42 | if (x == 0) |
| 43 | return 0; |
| 44 | |
| 45 | return x - EMAC_WRAPPER_RAM_ADDR + EMAC_HW_RAM_ADDR; |
| 46 | } |
| 47 | |
| 48 | static inline unsigned long HW_TO_BD(unsigned long x) |
| 49 | { |
| 50 | if (x == 0) |
| 51 | return 0; |
| 52 | |
| 53 | return x - EMAC_HW_RAM_ADDR + EMAC_WRAPPER_RAM_ADDR; |
| 54 | } |
| 55 | #else |
| 56 | #define BD_TO_HW(x) (x) |
| 57 | #define HW_TO_BD(x) (x) |
| 58 | #endif |
| 59 | |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 60 | #ifdef DAVINCI_EMAC_GIG_ENABLE |
Manjunath Hadli | 5b5260e | 2011-10-13 03:40:55 +0000 | [diff] [blame] | 61 | #define emac_gigabit_enable(phy_addr) davinci_eth_gigabit_enable(phy_addr) |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 62 | #else |
Manjunath Hadli | 5b5260e | 2011-10-13 03:40:55 +0000 | [diff] [blame] | 63 | #define emac_gigabit_enable(phy_addr) /* no gigabit to enable */ |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 64 | #endif |
| 65 | |
Heiko Schocher | 3e80613 | 2011-11-01 20:00:27 +0000 | [diff] [blame] | 66 | #if !defined(CONFIG_SYS_EMAC_TI_CLKDIV) |
| 67 | #define CONFIG_SYS_EMAC_TI_CLKDIV ((EMAC_MDIO_BUS_FREQ / \ |
| 68 | EMAC_MDIO_CLOCK_FREQ) - 1) |
| 69 | #endif |
| 70 | |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 71 | static void davinci_eth_mdio_enable(void); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 72 | |
| 73 | static int gen_init_phy(int phy_addr); |
| 74 | static int gen_is_phy_connected(int phy_addr); |
| 75 | static int gen_get_link_speed(int phy_addr); |
| 76 | static int gen_auto_negotiate(int phy_addr); |
| 77 | |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 78 | void eth_mdio_enable(void) |
| 79 | { |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 80 | davinci_eth_mdio_enable(); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 81 | } |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 82 | |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 83 | /* EMAC Addresses */ |
| 84 | static volatile emac_regs *adap_emac = (emac_regs *)EMAC_BASE_ADDR; |
| 85 | static volatile ewrap_regs *adap_ewrap = (ewrap_regs *)EMAC_WRAPPER_BASE_ADDR; |
| 86 | static volatile mdio_regs *adap_mdio = (mdio_regs *)EMAC_MDIO_BASE_ADDR; |
| 87 | |
| 88 | /* EMAC descriptors */ |
| 89 | static volatile emac_desc *emac_rx_desc = (emac_desc *)(EMAC_WRAPPER_RAM_ADDR + EMAC_RX_DESC_BASE); |
| 90 | static volatile emac_desc *emac_tx_desc = (emac_desc *)(EMAC_WRAPPER_RAM_ADDR + EMAC_TX_DESC_BASE); |
| 91 | static volatile emac_desc *emac_rx_active_head = 0; |
| 92 | static volatile emac_desc *emac_rx_active_tail = 0; |
| 93 | static int emac_rx_queue_active = 0; |
| 94 | |
| 95 | /* Receive packet buffers */ |
Ilya Yanok | ff67276 | 2011-11-28 06:37:33 +0000 | [diff] [blame] | 96 | static unsigned char emac_rx_buffers[EMAC_MAX_RX_BUFFERS * EMAC_RXBUF_SIZE] |
| 97 | __aligned(ARCH_DMA_MINALIGN); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 98 | |
Heiko Schocher | 7d037f7 | 2011-11-15 10:00:04 -0500 | [diff] [blame] | 99 | #ifndef CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT |
| 100 | #define CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT 3 |
| 101 | #endif |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 102 | |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 103 | /* PHY address for a discovered PHY (0xff - not found) */ |
Heiko Schocher | 7d037f7 | 2011-11-15 10:00:04 -0500 | [diff] [blame] | 104 | static u_int8_t active_phy_addr[CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT]; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 105 | |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 106 | /* number of PHY found active */ |
| 107 | static u_int8_t num_phy; |
| 108 | |
Heiko Schocher | 7d037f7 | 2011-11-15 10:00:04 -0500 | [diff] [blame] | 109 | phy_t phy[CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT]; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 110 | |
Bartosz Golaszewski | 2cedf75 | 2019-07-24 10:12:07 +0200 | [diff] [blame] | 111 | static int davinci_emac_write_hwaddr(struct udevice *dev) |
Ben Gardiner | 1fb49e3 | 2010-09-23 09:58:43 -0400 | [diff] [blame] | 112 | { |
Bartosz Golaszewski | 2cedf75 | 2019-07-24 10:12:07 +0200 | [diff] [blame] | 113 | struct eth_pdata *pdata = dev_get_platdata(dev); |
Ben Gardiner | 1fb49e3 | 2010-09-23 09:58:43 -0400 | [diff] [blame] | 114 | unsigned long mac_hi; |
| 115 | unsigned long mac_lo; |
| 116 | |
| 117 | /* |
| 118 | * Set MAC Addresses & Init multicast Hash to 0 (disable any multicast |
| 119 | * receive) |
| 120 | * Using channel 0 only - other channels are disabled |
| 121 | * */ |
| 122 | writel(0, &adap_emac->MACINDEX); |
Bartosz Golaszewski | 2cedf75 | 2019-07-24 10:12:07 +0200 | [diff] [blame] | 123 | mac_hi = (pdata->enetaddr[3] << 24) | |
| 124 | (pdata->enetaddr[2] << 16) | |
| 125 | (pdata->enetaddr[1] << 8) | |
| 126 | (pdata->enetaddr[0]); |
| 127 | mac_lo = (pdata->enetaddr[5] << 8) | |
| 128 | (pdata->enetaddr[4]); |
Ben Gardiner | 1fb49e3 | 2010-09-23 09:58:43 -0400 | [diff] [blame] | 129 | |
| 130 | writel(mac_hi, &adap_emac->MACADDRHI); |
| 131 | #if defined(DAVINCI_EMAC_VERSION2) |
| 132 | writel(mac_lo | EMAC_MAC_ADDR_IS_VALID | EMAC_MAC_ADDR_MATCH, |
| 133 | &adap_emac->MACADDRLO); |
| 134 | #else |
| 135 | writel(mac_lo, &adap_emac->MACADDRLO); |
| 136 | #endif |
| 137 | |
| 138 | writel(0, &adap_emac->MACHASH1); |
| 139 | writel(0, &adap_emac->MACHASH2); |
| 140 | |
| 141 | /* Set source MAC address - REQUIRED */ |
| 142 | writel(mac_hi, &adap_emac->MACSRCADDRHI); |
| 143 | writel(mac_lo, &adap_emac->MACSRCADDRLO); |
| 144 | |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 149 | static void davinci_eth_mdio_enable(void) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 150 | { |
| 151 | u_int32_t clkdiv; |
| 152 | |
Heiko Schocher | 3e80613 | 2011-11-01 20:00:27 +0000 | [diff] [blame] | 153 | clkdiv = CONFIG_SYS_EMAC_TI_CLKDIV; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 154 | |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 155 | writel((clkdiv & 0xff) | |
| 156 | MDIO_CONTROL_ENABLE | |
| 157 | MDIO_CONTROL_FAULT | |
| 158 | MDIO_CONTROL_FAULT_ENABLE, |
| 159 | &adap_mdio->CONTROL); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 160 | |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 161 | while (readl(&adap_mdio->CONTROL) & MDIO_CONTROL_IDLE) |
| 162 | ; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /* |
| 166 | * Tries to find an active connected PHY. Returns 1 if address if found. |
| 167 | * If no active PHY (or more than one PHY) found returns 0. |
| 168 | * Sets active_phy_addr variable. |
| 169 | */ |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 170 | static int davinci_eth_phy_detect(void) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 171 | { |
| 172 | u_int32_t phy_act_state; |
| 173 | int i; |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 174 | int j; |
| 175 | unsigned int count = 0; |
| 176 | |
Heiko Schocher | 7d037f7 | 2011-11-15 10:00:04 -0500 | [diff] [blame] | 177 | for (i = 0; i < CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT; i++) |
| 178 | active_phy_addr[i] = 0xff; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 179 | |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 180 | udelay(1000); |
| 181 | phy_act_state = readl(&adap_mdio->ALIVE); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 182 | |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 183 | if (phy_act_state == 0) |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 184 | return 0; /* No active PHYs */ |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 185 | |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 186 | debug_emac("davinci_eth_phy_detect(), ALIVE = 0x%08x\n", phy_act_state); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 187 | |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 188 | for (i = 0, j = 0; i < 32; i++) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 189 | if (phy_act_state & (1 << i)) { |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 190 | count++; |
Prabhakar Lad | 60289fe | 2011-11-17 02:53:23 +0000 | [diff] [blame] | 191 | if (count <= CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT) { |
Heiko Schocher | 7d037f7 | 2011-11-15 10:00:04 -0500 | [diff] [blame] | 192 | active_phy_addr[j++] = i; |
| 193 | } else { |
| 194 | printf("%s: to many PHYs detected.\n", |
| 195 | __func__); |
| 196 | count = 0; |
| 197 | break; |
| 198 | } |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 199 | } |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 200 | |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 201 | num_phy = count; |
| 202 | |
| 203 | return count; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | |
| 207 | /* Read a PHY register via MDIO inteface. Returns 1 on success, 0 otherwise */ |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 208 | int davinci_eth_phy_read(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t *data) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 209 | { |
| 210 | int tmp; |
| 211 | |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 212 | while (readl(&adap_mdio->USERACCESS0) & MDIO_USERACCESS0_GO) |
| 213 | ; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 214 | |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 215 | writel(MDIO_USERACCESS0_GO | |
| 216 | MDIO_USERACCESS0_WRITE_READ | |
| 217 | ((reg_num & 0x1f) << 21) | |
| 218 | ((phy_addr & 0x1f) << 16), |
| 219 | &adap_mdio->USERACCESS0); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 220 | |
| 221 | /* Wait for command to complete */ |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 222 | while ((tmp = readl(&adap_mdio->USERACCESS0)) & MDIO_USERACCESS0_GO) |
| 223 | ; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 224 | |
| 225 | if (tmp & MDIO_USERACCESS0_ACK) { |
| 226 | *data = tmp & 0xffff; |
karl beldan | 05d0698 | 2016-08-20 08:56:53 +0000 | [diff] [blame] | 227 | return 1; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 228 | } |
| 229 | |
karl beldan | 05d0698 | 2016-08-20 08:56:53 +0000 | [diff] [blame] | 230 | return 0; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /* Write to a PHY register via MDIO inteface. Blocks until operation is complete. */ |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 234 | int davinci_eth_phy_write(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t data) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 235 | { |
| 236 | |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 237 | while (readl(&adap_mdio->USERACCESS0) & MDIO_USERACCESS0_GO) |
| 238 | ; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 239 | |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 240 | writel(MDIO_USERACCESS0_GO | |
| 241 | MDIO_USERACCESS0_WRITE_WRITE | |
| 242 | ((reg_num & 0x1f) << 21) | |
| 243 | ((phy_addr & 0x1f) << 16) | |
| 244 | (data & 0xffff), |
| 245 | &adap_mdio->USERACCESS0); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 246 | |
| 247 | /* Wait for command to complete */ |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 248 | while (readl(&adap_mdio->USERACCESS0) & MDIO_USERACCESS0_GO) |
| 249 | ; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 250 | |
karl beldan | 05d0698 | 2016-08-20 08:56:53 +0000 | [diff] [blame] | 251 | return 1; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /* PHY functions for a generic PHY */ |
| 255 | static int gen_init_phy(int phy_addr) |
| 256 | { |
| 257 | int ret = 1; |
| 258 | |
| 259 | if (gen_get_link_speed(phy_addr)) { |
| 260 | /* Try another time */ |
| 261 | ret = gen_get_link_speed(phy_addr); |
| 262 | } |
| 263 | |
| 264 | return(ret); |
| 265 | } |
| 266 | |
| 267 | static int gen_is_phy_connected(int phy_addr) |
| 268 | { |
| 269 | u_int16_t dummy; |
| 270 | |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 271 | return davinci_eth_phy_read(phy_addr, MII_PHYSID1, &dummy); |
| 272 | } |
| 273 | |
| 274 | static int get_active_phy(void) |
| 275 | { |
| 276 | int i; |
| 277 | |
| 278 | for (i = 0; i < num_phy; i++) |
| 279 | if (phy[i].get_link_speed(active_phy_addr[i])) |
| 280 | return i; |
| 281 | |
| 282 | return -1; /* Return error if no link */ |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | static int gen_get_link_speed(int phy_addr) |
| 286 | { |
| 287 | u_int16_t tmp; |
| 288 | |
Sudhakar Rajashekhara | 5851e12 | 2010-11-18 09:59:37 -0500 | [diff] [blame] | 289 | if (davinci_eth_phy_read(phy_addr, MII_STATUS_REG, &tmp) && |
| 290 | (tmp & 0x04)) { |
| 291 | #if defined(CONFIG_DRIVER_TI_EMAC_USE_RMII) && \ |
| 292 | defined(CONFIG_MACH_DAVINCI_DA850_EVM) |
Ben Gardiner | b936eaa | 2011-01-11 14:48:17 -0500 | [diff] [blame] | 293 | davinci_eth_phy_read(phy_addr, MII_LPA, &tmp); |
Sudhakar Rajashekhara | 5851e12 | 2010-11-18 09:59:37 -0500 | [diff] [blame] | 294 | |
| 295 | /* Speed doesn't matter, there is no setting for it in EMAC. */ |
Ben Gardiner | b936eaa | 2011-01-11 14:48:17 -0500 | [diff] [blame] | 296 | if (tmp & (LPA_100FULL | LPA_10FULL)) { |
Sudhakar Rajashekhara | 5851e12 | 2010-11-18 09:59:37 -0500 | [diff] [blame] | 297 | /* set EMAC for Full Duplex */ |
| 298 | writel(EMAC_MACCONTROL_MIIEN_ENABLE | |
| 299 | EMAC_MACCONTROL_FULLDUPLEX_ENABLE, |
| 300 | &adap_emac->MACCONTROL); |
| 301 | } else { |
| 302 | /*set EMAC for Half Duplex */ |
| 303 | writel(EMAC_MACCONTROL_MIIEN_ENABLE, |
| 304 | &adap_emac->MACCONTROL); |
| 305 | } |
| 306 | |
Ben Gardiner | b936eaa | 2011-01-11 14:48:17 -0500 | [diff] [blame] | 307 | if (tmp & (LPA_100FULL | LPA_100HALF)) |
Sudhakar Rajashekhara | 5851e12 | 2010-11-18 09:59:37 -0500 | [diff] [blame] | 308 | writel(readl(&adap_emac->MACCONTROL) | |
| 309 | EMAC_MACCONTROL_RMIISPEED_100, |
| 310 | &adap_emac->MACCONTROL); |
| 311 | else |
| 312 | writel(readl(&adap_emac->MACCONTROL) & |
| 313 | ~EMAC_MACCONTROL_RMIISPEED_100, |
| 314 | &adap_emac->MACCONTROL); |
| 315 | #endif |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 316 | return(1); |
Sudhakar Rajashekhara | 5851e12 | 2010-11-18 09:59:37 -0500 | [diff] [blame] | 317 | } |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 318 | |
| 319 | return(0); |
| 320 | } |
| 321 | |
| 322 | static int gen_auto_negotiate(int phy_addr) |
| 323 | { |
| 324 | u_int16_t tmp; |
Manjunath Hadli | 4141ad4 | 2011-10-13 03:40:53 +0000 | [diff] [blame] | 325 | u_int16_t val; |
| 326 | unsigned long cntr = 0; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 327 | |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 328 | if (!davinci_eth_phy_read(phy_addr, MII_BMCR, &tmp)) |
Manjunath Hadli | 4141ad4 | 2011-10-13 03:40:53 +0000 | [diff] [blame] | 329 | return 0; |
| 330 | |
| 331 | val = tmp | BMCR_FULLDPLX | BMCR_ANENABLE | |
| 332 | BMCR_SPEED100; |
| 333 | davinci_eth_phy_write(phy_addr, MII_BMCR, val); |
| 334 | |
| 335 | if (!davinci_eth_phy_read(phy_addr, MII_ADVERTISE, &val)) |
| 336 | return 0; |
| 337 | |
| 338 | val |= (ADVERTISE_100FULL | ADVERTISE_100HALF | ADVERTISE_10FULL | |
| 339 | ADVERTISE_10HALF); |
| 340 | davinci_eth_phy_write(phy_addr, MII_ADVERTISE, val); |
| 341 | |
| 342 | if (!davinci_eth_phy_read(phy_addr, MII_BMCR, &tmp)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 343 | return(0); |
| 344 | |
Tom Rini | c3cf899 | 2017-05-10 12:01:02 -0400 | [diff] [blame] | 345 | #ifdef DAVINCI_EMAC_GIG_ENABLE |
| 346 | davinci_eth_phy_read(phy_addr, MII_CTRL1000, &val); |
| 347 | val |= PHY_1000BTCR_1000FD; |
| 348 | val &= ~PHY_1000BTCR_1000HD; |
| 349 | davinci_eth_phy_write(phy_addr, MII_CTRL1000, val); |
| 350 | davinci_eth_phy_read(phy_addr, MII_CTRL1000, &val); |
| 351 | #endif |
| 352 | |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 353 | /* Restart Auto_negotiation */ |
Manjunath Hadli | 4141ad4 | 2011-10-13 03:40:53 +0000 | [diff] [blame] | 354 | tmp |= BMCR_ANRESTART; |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 355 | davinci_eth_phy_write(phy_addr, MII_BMCR, tmp); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 356 | |
| 357 | /*check AutoNegotiate complete */ |
Manjunath Hadli | 4141ad4 | 2011-10-13 03:40:53 +0000 | [diff] [blame] | 358 | do { |
| 359 | udelay(40000); |
| 360 | if (!davinci_eth_phy_read(phy_addr, MII_BMSR, &tmp)) |
| 361 | return 0; |
| 362 | |
| 363 | if (tmp & BMSR_ANEGCOMPLETE) |
| 364 | break; |
| 365 | |
| 366 | cntr++; |
| 367 | } while (cntr < 200); |
| 368 | |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 369 | if (!davinci_eth_phy_read(phy_addr, MII_BMSR, &tmp)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 370 | return(0); |
| 371 | |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 372 | if (!(tmp & BMSR_ANEGCOMPLETE)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 373 | return(0); |
| 374 | |
| 375 | return(gen_get_link_speed(phy_addr)); |
| 376 | } |
| 377 | /* End of generic PHY functions */ |
| 378 | |
| 379 | |
Wolfgang Denk | 56cbd02 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 380 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 381 | static int davinci_mii_phy_read(struct mii_dev *bus, int addr, int devad, |
| 382 | int reg) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 383 | { |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 384 | unsigned short value = 0; |
Joe Hershberger | ece1aa6 | 2016-08-08 11:28:40 -0500 | [diff] [blame] | 385 | int retval = davinci_eth_phy_read(addr, reg, &value); |
karl beldan | 05d0698 | 2016-08-20 08:56:53 +0000 | [diff] [blame] | 386 | |
| 387 | return retval ? value : -EIO; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 388 | } |
| 389 | |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 390 | static int davinci_mii_phy_write(struct mii_dev *bus, int addr, int devad, |
| 391 | int reg, u16 value) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 392 | { |
karl beldan | 05d0698 | 2016-08-20 08:56:53 +0000 | [diff] [blame] | 393 | return davinci_eth_phy_write(addr, reg, value) ? 0 : 1; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 394 | } |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 395 | #endif |
| 396 | |
Manjunath Hadli | 5b5260e | 2011-10-13 03:40:55 +0000 | [diff] [blame] | 397 | static void __attribute__((unused)) davinci_eth_gigabit_enable(int phy_addr) |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 398 | { |
| 399 | u_int16_t data; |
| 400 | |
Manjunath Hadli | 5b5260e | 2011-10-13 03:40:55 +0000 | [diff] [blame] | 401 | if (davinci_eth_phy_read(phy_addr, 0, &data)) { |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 402 | if (data & (1 << 6)) { /* speed selection MSB */ |
| 403 | /* |
| 404 | * Check if link detected is giga-bit |
| 405 | * If Gigabit mode detected, enable gigbit in MAC |
| 406 | */ |
Sandeep Paulraj | 9da994b | 2010-12-28 14:37:33 -0500 | [diff] [blame] | 407 | writel(readl(&adap_emac->MACCONTROL) | |
| 408 | EMAC_MACCONTROL_GIGFORCE | |
| 409 | EMAC_MACCONTROL_GIGABIT_ENABLE, |
| 410 | &adap_emac->MACCONTROL); |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | } |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 414 | |
| 415 | /* Eth device open */ |
Bartosz Golaszewski | 2cedf75 | 2019-07-24 10:12:07 +0200 | [diff] [blame] | 416 | static int davinci_emac_start(struct udevice *dev) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 417 | { |
| 418 | dv_reg_p addr; |
Tom Rini | c3cf899 | 2017-05-10 12:01:02 -0400 | [diff] [blame] | 419 | u_int32_t clkdiv, cnt, mac_control; |
| 420 | uint16_t __maybe_unused lpa_val; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 421 | volatile emac_desc *rx_desc; |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 422 | int index; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 423 | |
| 424 | debug_emac("+ emac_open\n"); |
| 425 | |
| 426 | /* Reset EMAC module and disable interrupts in wrapper */ |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 427 | writel(1, &adap_emac->SOFTRESET); |
| 428 | while (readl(&adap_emac->SOFTRESET) != 0) |
| 429 | ; |
| 430 | #if defined(DAVINCI_EMAC_VERSION2) |
| 431 | writel(1, &adap_ewrap->softrst); |
| 432 | while (readl(&adap_ewrap->softrst) != 0) |
| 433 | ; |
| 434 | #else |
| 435 | writel(0, &adap_ewrap->EWCTL); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 436 | for (cnt = 0; cnt < 5; cnt++) { |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 437 | clkdiv = readl(&adap_ewrap->EWCTL); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 438 | } |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 439 | #endif |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 440 | |
Sudhakar Rajashekhara | 5851e12 | 2010-11-18 09:59:37 -0500 | [diff] [blame] | 441 | #if defined(CONFIG_DRIVER_TI_EMAC_USE_RMII) && \ |
| 442 | defined(CONFIG_MACH_DAVINCI_DA850_EVM) |
| 443 | adap_ewrap->c0rxen = adap_ewrap->c1rxen = adap_ewrap->c2rxen = 0; |
| 444 | adap_ewrap->c0txen = adap_ewrap->c1txen = adap_ewrap->c2txen = 0; |
| 445 | adap_ewrap->c0miscen = adap_ewrap->c1miscen = adap_ewrap->c2miscen = 0; |
| 446 | #endif |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 447 | rx_desc = emac_rx_desc; |
| 448 | |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 449 | writel(1, &adap_emac->TXCONTROL); |
| 450 | writel(1, &adap_emac->RXCONTROL); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 451 | |
Bartosz Golaszewski | 2cedf75 | 2019-07-24 10:12:07 +0200 | [diff] [blame] | 452 | davinci_emac_write_hwaddr(dev); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 453 | |
| 454 | /* Set DMA 8 TX / 8 RX Head pointers to 0 */ |
| 455 | addr = &adap_emac->TX0HDP; |
Vishwas Srivastava | 8aaeb1f | 2016-01-25 21:28:17 +0530 | [diff] [blame] | 456 | for (cnt = 0; cnt < 8; cnt++) |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 457 | writel(0, addr++); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 458 | |
| 459 | addr = &adap_emac->RX0HDP; |
Vishwas Srivastava | 8aaeb1f | 2016-01-25 21:28:17 +0530 | [diff] [blame] | 460 | for (cnt = 0; cnt < 8; cnt++) |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 461 | writel(0, addr++); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 462 | |
| 463 | /* Clear Statistics (do this before setting MacControl register) */ |
| 464 | addr = &adap_emac->RXGOODFRAMES; |
| 465 | for(cnt = 0; cnt < EMAC_NUM_STATS; cnt++) |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 466 | writel(0, addr++); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 467 | |
| 468 | /* No multicast addressing */ |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 469 | writel(0, &adap_emac->MACHASH1); |
| 470 | writel(0, &adap_emac->MACHASH2); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 471 | |
| 472 | /* Create RX queue and set receive process in place */ |
| 473 | emac_rx_active_head = emac_rx_desc; |
| 474 | for (cnt = 0; cnt < EMAC_MAX_RX_BUFFERS; cnt++) { |
Ilya Yanok | 518036e | 2011-11-28 06:37:30 +0000 | [diff] [blame] | 475 | rx_desc->next = BD_TO_HW((u_int32_t)(rx_desc + 1)); |
Ilya Yanok | ff67276 | 2011-11-28 06:37:33 +0000 | [diff] [blame] | 476 | rx_desc->buffer = &emac_rx_buffers[cnt * EMAC_RXBUF_SIZE]; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 477 | rx_desc->buff_off_len = EMAC_MAX_ETHERNET_PKT_SIZE; |
| 478 | rx_desc->pkt_flag_len = EMAC_CPPI_OWNERSHIP_BIT; |
| 479 | rx_desc++; |
| 480 | } |
| 481 | |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 482 | /* Finalize the rx desc list */ |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 483 | rx_desc--; |
| 484 | rx_desc->next = 0; |
| 485 | emac_rx_active_tail = rx_desc; |
| 486 | emac_rx_queue_active = 1; |
| 487 | |
| 488 | /* Enable TX/RX */ |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 489 | writel(EMAC_MAX_ETHERNET_PKT_SIZE, &adap_emac->RXMAXLEN); |
| 490 | writel(0, &adap_emac->RXBUFFEROFFSET); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 491 | |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 492 | /* |
| 493 | * No fancy configs - Use this for promiscous debug |
| 494 | * - EMAC_RXMBPENABLE_RXCAFEN_ENABLE |
| 495 | */ |
| 496 | writel(EMAC_RXMBPENABLE_RXBROADEN, &adap_emac->RXMBPENABLE); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 497 | |
| 498 | /* Enable ch 0 only */ |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 499 | writel(1, &adap_emac->RXUNICASTSET); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 500 | |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 501 | /* Init MDIO & get link state */ |
Heiko Schocher | 3e80613 | 2011-11-01 20:00:27 +0000 | [diff] [blame] | 502 | clkdiv = CONFIG_SYS_EMAC_TI_CLKDIV; |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 503 | writel((clkdiv & 0xff) | MDIO_CONTROL_ENABLE | MDIO_CONTROL_FAULT, |
| 504 | &adap_mdio->CONTROL); |
| 505 | |
| 506 | /* We need to wait for MDIO to start */ |
| 507 | udelay(1000); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 508 | |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 509 | index = get_active_phy(); |
| 510 | if (index == -1) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 511 | return(0); |
| 512 | |
Tom Rini | c3cf899 | 2017-05-10 12:01:02 -0400 | [diff] [blame] | 513 | /* Enable MII interface */ |
| 514 | mac_control = EMAC_MACCONTROL_MIIEN_ENABLE; |
| 515 | #ifdef DAVINCI_EMAC_GIG_ENABLE |
| 516 | davinci_eth_phy_read(active_phy_addr[index], MII_STAT1000, &lpa_val); |
| 517 | if (lpa_val & PHY_1000BTSR_1000FD) { |
| 518 | debug_emac("eth_open : gigabit negotiated\n"); |
| 519 | mac_control |= EMAC_MACCONTROL_FULLDUPLEX_ENABLE; |
| 520 | mac_control |= EMAC_MACCONTROL_GIGABIT_ENABLE; |
| 521 | } |
| 522 | #endif |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 523 | |
Tom Rini | c3cf899 | 2017-05-10 12:01:02 -0400 | [diff] [blame] | 524 | davinci_eth_phy_read(active_phy_addr[index], MII_LPA, &lpa_val); |
| 525 | if (lpa_val & (LPA_100FULL | LPA_10FULL)) |
| 526 | /* set EMAC for Full Duplex */ |
| 527 | mac_control |= EMAC_MACCONTROL_FULLDUPLEX_ENABLE; |
| 528 | #if defined(CONFIG_SOC_DA8XX) || \ |
| 529 | (defined(CONFIG_OMAP34XX) && defined(CONFIG_DRIVER_TI_EMAC_USE_RMII)) |
| 530 | mac_control |= EMAC_MACCONTROL_RMIISPEED_100; |
| 531 | #endif |
| 532 | writel(mac_control, &adap_emac->MACCONTROL); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 533 | /* Start receive process */ |
Ilya Yanok | 518036e | 2011-11-28 06:37:30 +0000 | [diff] [blame] | 534 | writel(BD_TO_HW((u_int32_t)emac_rx_desc), &adap_emac->RX0HDP); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 535 | |
| 536 | debug_emac("- emac_open\n"); |
| 537 | |
| 538 | return(1); |
| 539 | } |
| 540 | |
| 541 | /* EMAC Channel Teardown */ |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 542 | static void davinci_eth_ch_teardown(int ch) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 543 | { |
| 544 | dv_reg dly = 0xff; |
| 545 | dv_reg cnt; |
| 546 | |
| 547 | debug_emac("+ emac_ch_teardown\n"); |
| 548 | |
| 549 | if (ch == EMAC_CH_TX) { |
| 550 | /* Init TX channel teardown */ |
Nagabhushana Netagunte | a33bc4b | 2011-09-03 22:20:33 -0400 | [diff] [blame] | 551 | writel(0, &adap_emac->TXTEARDOWN); |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 552 | do { |
| 553 | /* |
| 554 | * Wait here for Tx teardown completion interrupt to |
| 555 | * occur. Note: A task delay can be called here to pend |
| 556 | * rather than occupying CPU cycles - anyway it has |
| 557 | * been found that teardown takes very few cpu cycles |
| 558 | * and does not affect functionality |
| 559 | */ |
| 560 | dly--; |
| 561 | udelay(1); |
| 562 | if (dly == 0) |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 563 | break; |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 564 | cnt = readl(&adap_emac->TX0CP); |
| 565 | } while (cnt != 0xfffffffc); |
| 566 | writel(cnt, &adap_emac->TX0CP); |
| 567 | writel(0, &adap_emac->TX0HDP); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 568 | } else { |
| 569 | /* Init RX channel teardown */ |
Nagabhushana Netagunte | a33bc4b | 2011-09-03 22:20:33 -0400 | [diff] [blame] | 570 | writel(0, &adap_emac->RXTEARDOWN); |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 571 | do { |
| 572 | /* |
| 573 | * Wait here for Rx teardown completion interrupt to |
| 574 | * occur. Note: A task delay can be called here to pend |
| 575 | * rather than occupying CPU cycles - anyway it has |
| 576 | * been found that teardown takes very few cpu cycles |
| 577 | * and does not affect functionality |
| 578 | */ |
| 579 | dly--; |
| 580 | udelay(1); |
| 581 | if (dly == 0) |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 582 | break; |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 583 | cnt = readl(&adap_emac->RX0CP); |
| 584 | } while (cnt != 0xfffffffc); |
| 585 | writel(cnt, &adap_emac->RX0CP); |
| 586 | writel(0, &adap_emac->RX0HDP); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | debug_emac("- emac_ch_teardown\n"); |
| 590 | } |
| 591 | |
| 592 | /* Eth device close */ |
Bartosz Golaszewski | 2cedf75 | 2019-07-24 10:12:07 +0200 | [diff] [blame] | 593 | static void davinci_emac_stop(struct udevice *dev) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 594 | { |
| 595 | debug_emac("+ emac_close\n"); |
| 596 | |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 597 | davinci_eth_ch_teardown(EMAC_CH_TX); /* TX Channel teardown */ |
Jeroen Hofstee | 8938b5b | 2015-06-07 17:30:38 +0200 | [diff] [blame] | 598 | if (readl(&adap_emac->RXCONTROL) & 1) |
| 599 | davinci_eth_ch_teardown(EMAC_CH_RX); /* RX Channel teardown */ |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 600 | |
| 601 | /* Reset EMAC module and disable interrupts in wrapper */ |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 602 | writel(1, &adap_emac->SOFTRESET); |
| 603 | #if defined(DAVINCI_EMAC_VERSION2) |
| 604 | writel(1, &adap_ewrap->softrst); |
| 605 | #else |
| 606 | writel(0, &adap_ewrap->EWCTL); |
| 607 | #endif |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 608 | |
Sudhakar Rajashekhara | 5851e12 | 2010-11-18 09:59:37 -0500 | [diff] [blame] | 609 | #if defined(CONFIG_DRIVER_TI_EMAC_USE_RMII) && \ |
| 610 | defined(CONFIG_MACH_DAVINCI_DA850_EVM) |
| 611 | adap_ewrap->c0rxen = adap_ewrap->c1rxen = adap_ewrap->c2rxen = 0; |
| 612 | adap_ewrap->c0txen = adap_ewrap->c1txen = adap_ewrap->c2txen = 0; |
| 613 | adap_ewrap->c0miscen = adap_ewrap->c1miscen = adap_ewrap->c2miscen = 0; |
| 614 | #endif |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 615 | debug_emac("- emac_close\n"); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | static int tx_send_loop = 0; |
| 619 | |
| 620 | /* |
| 621 | * This function sends a single packet on the network and returns |
| 622 | * positive number (number of bytes transmitted) or negative for error |
| 623 | */ |
Bartosz Golaszewski | 2cedf75 | 2019-07-24 10:12:07 +0200 | [diff] [blame] | 624 | static int davinci_emac_send(struct udevice *dev, |
| 625 | void *packet, int length) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 626 | { |
| 627 | int ret_status = -1; |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 628 | int index; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 629 | tx_send_loop = 0; |
| 630 | |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 631 | index = get_active_phy(); |
| 632 | if (index == -1) { |
| 633 | printf(" WARN: emac_send_packet: No link\n"); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 634 | return (ret_status); |
| 635 | } |
| 636 | |
| 637 | /* Check packet size and if < EMAC_MIN_ETHERNET_PKT_SIZE, pad it up */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 638 | if (length < EMAC_MIN_ETHERNET_PKT_SIZE) { |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 639 | length = EMAC_MIN_ETHERNET_PKT_SIZE; |
| 640 | } |
| 641 | |
| 642 | /* Populate the TX descriptor */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 643 | emac_tx_desc->next = 0; |
| 644 | emac_tx_desc->buffer = (u_int8_t *) packet; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 645 | emac_tx_desc->buff_off_len = (length & 0xffff); |
| 646 | emac_tx_desc->pkt_flag_len = ((length & 0xffff) | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 647 | EMAC_CPPI_SOP_BIT | |
| 648 | EMAC_CPPI_OWNERSHIP_BIT | |
| 649 | EMAC_CPPI_EOP_BIT); |
Ilya Yanok | ff67276 | 2011-11-28 06:37:33 +0000 | [diff] [blame] | 650 | |
| 651 | flush_dcache_range((unsigned long)packet, |
karl beldan | e24ce8b | 2016-08-15 17:23:00 +0000 | [diff] [blame] | 652 | (unsigned long)packet + ALIGN(length, PKTALIGN)); |
Ilya Yanok | ff67276 | 2011-11-28 06:37:33 +0000 | [diff] [blame] | 653 | |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 654 | /* Send the packet */ |
Ilya Yanok | 518036e | 2011-11-28 06:37:30 +0000 | [diff] [blame] | 655 | writel(BD_TO_HW((unsigned long)emac_tx_desc), &adap_emac->TX0HDP); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 656 | |
| 657 | /* Wait for packet to complete or link down */ |
| 658 | while (1) { |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 659 | if (!phy[index].get_link_speed(active_phy_addr[index])) { |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 660 | davinci_eth_ch_teardown (EMAC_CH_TX); |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 661 | return (ret_status); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 662 | } |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 663 | |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 664 | if (readl(&adap_emac->TXINTSTATRAW) & 0x01) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 665 | ret_status = length; |
| 666 | break; |
| 667 | } |
| 668 | tx_send_loop++; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 669 | } |
| 670 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 671 | return (ret_status); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | /* |
| 675 | * This function handles receipt of a packet from the network |
| 676 | */ |
Bartosz Golaszewski | 2cedf75 | 2019-07-24 10:12:07 +0200 | [diff] [blame] | 677 | static int davinci_emac_recv(struct udevice *dev, int flags, uchar **packetp) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 678 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 679 | volatile emac_desc *rx_curr_desc; |
| 680 | volatile emac_desc *curr_desc; |
| 681 | volatile emac_desc *tail_desc; |
| 682 | int status, ret = -1; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 683 | |
| 684 | rx_curr_desc = emac_rx_active_head; |
Vishwas Srivastava | c994c9c | 2016-01-26 12:46:42 +0530 | [diff] [blame] | 685 | if (!rx_curr_desc) |
| 686 | return 0; |
Bartosz Golaszewski | 2cedf75 | 2019-07-24 10:12:07 +0200 | [diff] [blame] | 687 | *packetp = rx_curr_desc->buffer; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 688 | status = rx_curr_desc->pkt_flag_len; |
Vishwas Srivastava | c994c9c | 2016-01-26 12:46:42 +0530 | [diff] [blame] | 689 | if ((status & EMAC_CPPI_OWNERSHIP_BIT) == 0) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 690 | if (status & EMAC_CPPI_RX_ERROR_FRAME) { |
| 691 | /* Error in packet - discard it and requeue desc */ |
| 692 | printf ("WARN: emac_rcv_pkt: Error in packet\n"); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 693 | } else { |
Ilya Yanok | ff67276 | 2011-11-28 06:37:33 +0000 | [diff] [blame] | 694 | unsigned long tmp = (unsigned long)rx_curr_desc->buffer; |
karl beldan | 12e4987 | 2016-08-15 17:23:01 +0000 | [diff] [blame] | 695 | unsigned short len = |
| 696 | rx_curr_desc->buff_off_len & 0xffff; |
Ilya Yanok | ff67276 | 2011-11-28 06:37:33 +0000 | [diff] [blame] | 697 | |
karl beldan | 12e4987 | 2016-08-15 17:23:01 +0000 | [diff] [blame] | 698 | invalidate_dcache_range(tmp, tmp + ALIGN(len, PKTALIGN)); |
karl beldan | 12e4987 | 2016-08-15 17:23:01 +0000 | [diff] [blame] | 699 | ret = len; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 700 | } |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 701 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 702 | /* Ack received packet descriptor */ |
Ilya Yanok | 518036e | 2011-11-28 06:37:30 +0000 | [diff] [blame] | 703 | writel(BD_TO_HW((ulong)rx_curr_desc), &adap_emac->RX0CP); |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 704 | curr_desc = rx_curr_desc; |
| 705 | emac_rx_active_head = |
Ilya Yanok | 518036e | 2011-11-28 06:37:30 +0000 | [diff] [blame] | 706 | (volatile emac_desc *) (HW_TO_BD(rx_curr_desc->next)); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 707 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 708 | if (status & EMAC_CPPI_EOQ_BIT) { |
| 709 | if (emac_rx_active_head) { |
Ilya Yanok | 518036e | 2011-11-28 06:37:30 +0000 | [diff] [blame] | 710 | writel(BD_TO_HW((ulong)emac_rx_active_head), |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 711 | &adap_emac->RX0HDP); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 712 | } else { |
| 713 | emac_rx_queue_active = 0; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 714 | printf ("INFO:emac_rcv_packet: RX Queue not active\n"); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | |
| 718 | /* Recycle RX descriptor */ |
| 719 | rx_curr_desc->buff_off_len = EMAC_MAX_ETHERNET_PKT_SIZE; |
| 720 | rx_curr_desc->pkt_flag_len = EMAC_CPPI_OWNERSHIP_BIT; |
| 721 | rx_curr_desc->next = 0; |
| 722 | |
| 723 | if (emac_rx_active_head == 0) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 724 | printf ("INFO: emac_rcv_pkt: active queue head = 0\n"); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 725 | emac_rx_active_head = curr_desc; |
| 726 | emac_rx_active_tail = curr_desc; |
| 727 | if (emac_rx_queue_active != 0) { |
Ilya Yanok | 518036e | 2011-11-28 06:37:30 +0000 | [diff] [blame] | 728 | writel(BD_TO_HW((ulong)emac_rx_active_head), |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 729 | &adap_emac->RX0HDP); |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 730 | printf ("INFO: emac_rcv_pkt: active queue head = 0, HDP fired\n"); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 731 | emac_rx_queue_active = 1; |
| 732 | } |
| 733 | } else { |
| 734 | tail_desc = emac_rx_active_tail; |
| 735 | emac_rx_active_tail = curr_desc; |
Ilya Yanok | 518036e | 2011-11-28 06:37:30 +0000 | [diff] [blame] | 736 | tail_desc->next = BD_TO_HW((ulong) curr_desc); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 737 | status = tail_desc->pkt_flag_len; |
| 738 | if (status & EMAC_CPPI_EOQ_BIT) { |
Ilya Yanok | 518036e | 2011-11-28 06:37:30 +0000 | [diff] [blame] | 739 | writel(BD_TO_HW((ulong)curr_desc), |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 740 | &adap_emac->RX0HDP); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 741 | status &= ~EMAC_CPPI_EOQ_BIT; |
| 742 | tail_desc->pkt_flag_len = status; |
| 743 | } |
| 744 | } |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 745 | return (ret); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 746 | } |
Bartosz Golaszewski | 2cedf75 | 2019-07-24 10:12:07 +0200 | [diff] [blame] | 747 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 748 | return (0); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 749 | } |
| 750 | |
Ben Warren | 4c28e27 | 2009-04-27 23:19:10 -0700 | [diff] [blame] | 751 | /* |
| 752 | * This function initializes the emac hardware. It does NOT initialize |
| 753 | * EMAC modules power or pin multiplexors, that is done by board_init() |
| 754 | * much earlier in bootup process. Returns 1 on success, 0 otherwise. |
| 755 | */ |
Bartosz Golaszewski | 2cedf75 | 2019-07-24 10:12:07 +0200 | [diff] [blame] | 756 | static int davinci_emac_probe(struct udevice *dev) |
Ben Warren | 4c28e27 | 2009-04-27 23:19:10 -0700 | [diff] [blame] | 757 | { |
| 758 | u_int32_t phy_id; |
| 759 | u_int16_t tmp; |
| 760 | int i; |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 761 | int ret; |
Ben Warren | 4c28e27 | 2009-04-27 23:19:10 -0700 | [diff] [blame] | 762 | |
| 763 | davinci_eth_mdio_enable(); |
| 764 | |
Heiko Schocher | 70fa966 | 2011-09-14 19:37:42 +0000 | [diff] [blame] | 765 | /* let the EMAC detect the PHYs */ |
| 766 | udelay(5000); |
| 767 | |
Ben Warren | 4c28e27 | 2009-04-27 23:19:10 -0700 | [diff] [blame] | 768 | for (i = 0; i < 256; i++) { |
Nick Thompson | d5ee6f6 | 2009-12-18 13:33:07 +0000 | [diff] [blame] | 769 | if (readl(&adap_mdio->ALIVE)) |
Ben Warren | 4c28e27 | 2009-04-27 23:19:10 -0700 | [diff] [blame] | 770 | break; |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 771 | udelay(1000); |
Ben Warren | 4c28e27 | 2009-04-27 23:19:10 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | if (i >= 256) { |
| 775 | printf("No ETH PHY detected!!!\n"); |
| 776 | return(0); |
| 777 | } |
| 778 | |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 779 | /* Find if PHY(s) is/are connected */ |
| 780 | ret = davinci_eth_phy_detect(); |
| 781 | if (!ret) |
Ben Warren | 4c28e27 | 2009-04-27 23:19:10 -0700 | [diff] [blame] | 782 | return(0); |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 783 | else |
Heiko Schocher | 7d037f7 | 2011-11-15 10:00:04 -0500 | [diff] [blame] | 784 | debug_emac(" %d ETH PHY detected\n", ret); |
Ben Warren | 4c28e27 | 2009-04-27 23:19:10 -0700 | [diff] [blame] | 785 | |
| 786 | /* Get PHY ID and initialize phy_ops for a detected PHY */ |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 787 | for (i = 0; i < num_phy; i++) { |
| 788 | if (!davinci_eth_phy_read(active_phy_addr[i], MII_PHYSID1, |
| 789 | &tmp)) { |
| 790 | active_phy_addr[i] = 0xff; |
| 791 | continue; |
| 792 | } |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 793 | |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 794 | phy_id = (tmp << 16) & 0xffff0000; |
Ben Warren | 4c28e27 | 2009-04-27 23:19:10 -0700 | [diff] [blame] | 795 | |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 796 | if (!davinci_eth_phy_read(active_phy_addr[i], MII_PHYSID2, |
| 797 | &tmp)) { |
| 798 | active_phy_addr[i] = 0xff; |
| 799 | continue; |
| 800 | } |
Ben Warren | 4c28e27 | 2009-04-27 23:19:10 -0700 | [diff] [blame] | 801 | |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 802 | phy_id |= tmp & 0x0000ffff; |
Ben Warren | 4c28e27 | 2009-04-27 23:19:10 -0700 | [diff] [blame] | 803 | |
Bartosz Golaszewski | 101c5ba | 2019-04-29 18:37:08 +0200 | [diff] [blame] | 804 | sprintf(phy[i].name, "GENERIC @ 0x%02x", |
| 805 | active_phy_addr[i]); |
| 806 | phy[i].init = gen_init_phy; |
| 807 | phy[i].is_phy_connected = gen_is_phy_connected; |
| 808 | phy[i].get_link_speed = gen_get_link_speed; |
| 809 | phy[i].auto_negotiate = gen_auto_negotiate; |
Ben Warren | 4c28e27 | 2009-04-27 23:19:10 -0700 | [diff] [blame] | 810 | |
Ilya Yanok | 57c449d | 2011-11-01 13:15:55 +0000 | [diff] [blame] | 811 | debug("Ethernet PHY: %s\n", phy[i].name); |
Ben Warren | 4c28e27 | 2009-04-27 23:19:10 -0700 | [diff] [blame] | 812 | |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 813 | int retval; |
| 814 | struct mii_dev *mdiodev = mdio_alloc(); |
| 815 | if (!mdiodev) |
| 816 | return -ENOMEM; |
| 817 | strncpy(mdiodev->name, phy[i].name, MDIO_NAME_LEN); |
| 818 | mdiodev->read = davinci_mii_phy_read; |
| 819 | mdiodev->write = davinci_mii_phy_write; |
| 820 | |
| 821 | retval = mdio_register(mdiodev); |
| 822 | if (retval < 0) |
| 823 | return retval; |
Tom Rini | c3cf899 | 2017-05-10 12:01:02 -0400 | [diff] [blame] | 824 | #ifdef DAVINCI_EMAC_GIG_ENABLE |
| 825 | #define PHY_CONF_REG 22 |
| 826 | /* Enable PHY to clock out TX_CLK */ |
| 827 | davinci_eth_phy_read(active_phy_addr[i], PHY_CONF_REG, &tmp); |
| 828 | tmp |= PHY_CONF_TXCLKEN; |
| 829 | davinci_eth_phy_write(active_phy_addr[i], PHY_CONF_REG, tmp); |
| 830 | davinci_eth_phy_read(active_phy_addr[i], PHY_CONF_REG, &tmp); |
| 831 | #endif |
Manjunath Hadli | 444d8c1 | 2011-10-13 03:40:54 +0000 | [diff] [blame] | 832 | } |
Rajashekhara, Sudhakar | fe3a0d6 | 2012-06-07 00:27:44 +0000 | [diff] [blame] | 833 | |
Tom Rini | c3cf899 | 2017-05-10 12:01:02 -0400 | [diff] [blame] | 834 | #if defined(CONFIG_TI816X) || (defined(CONFIG_DRIVER_TI_EMAC_USE_RMII) && \ |
Bastian Ruppert | ef2746a | 2012-09-13 22:29:03 +0000 | [diff] [blame] | 835 | defined(CONFIG_MACH_DAVINCI_DA850_EVM) && \ |
Tom Rini | c3cf899 | 2017-05-10 12:01:02 -0400 | [diff] [blame] | 836 | !defined(CONFIG_DRIVER_TI_EMAC_RMII_NO_NEGOTIATE)) |
Rajashekhara, Sudhakar | fe3a0d6 | 2012-06-07 00:27:44 +0000 | [diff] [blame] | 837 | for (i = 0; i < num_phy; i++) { |
| 838 | if (phy[i].is_phy_connected(i)) |
| 839 | phy[i].auto_negotiate(i); |
| 840 | } |
| 841 | #endif |
Bartosz Golaszewski | 2cedf75 | 2019-07-24 10:12:07 +0200 | [diff] [blame] | 842 | return 0; |
Ben Warren | 4c28e27 | 2009-04-27 23:19:10 -0700 | [diff] [blame] | 843 | } |
Bartosz Golaszewski | 2cedf75 | 2019-07-24 10:12:07 +0200 | [diff] [blame] | 844 | |
| 845 | static const struct eth_ops davinci_emac_ops = { |
| 846 | .start = davinci_emac_start, |
| 847 | .send = davinci_emac_send, |
| 848 | .recv = davinci_emac_recv, |
| 849 | .stop = davinci_emac_stop, |
| 850 | .write_hwaddr = davinci_emac_write_hwaddr, |
| 851 | }; |
| 852 | |
| 853 | static const struct udevice_id davinci_emac_ids[] = { |
| 854 | { .compatible = "ti,davinci-dm6467-emac" }, |
| 855 | { .compatible = "ti,am3517-emac", }, |
| 856 | { .compatible = "ti,dm816-emac", }, |
| 857 | { } |
| 858 | }; |
| 859 | |
| 860 | U_BOOT_DRIVER(davinci_emac) = { |
| 861 | .name = "davinci_emac", |
| 862 | .id = UCLASS_ETH, |
| 863 | .of_match = davinci_emac_ids, |
| 864 | .probe = davinci_emac_probe, |
| 865 | .ops = &davinci_emac_ops, |
| 866 | .platdata_auto_alloc_size = sizeof(struct eth_pdata), |
| 867 | }; |