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