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