blob: 4f9ed2fccde8c169723e1c17a8dcc246f134afc7 [file] [log] [blame]
Sergey Kubushync74b2102007-08-10 20:26:18 +02001/*
2 * Ethernet driver for TI TMS320DM644x (DaVinci) chips.
3 *
4 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
5 *
6 * Parts shamelessly stolen from TI's dm644x_emac.c. Original copyright
7 * follows:
8 *
9 * ----------------------------------------------------------------------------
10 *
11 * dm644x_emac.c
12 *
13 * TI DaVinci (DM644X) EMAC peripheral driver source for DV-EVM
14 *
15 * Copyright (C) 2005 Texas Instruments.
16 *
17 * ----------------------------------------------------------------------------
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 * ----------------------------------------------------------------------------
33
34 * Modifications:
35 * ver. 1.0: Sep 2005, Anant Gole - Created EMAC version for uBoot.
36 * ver 1.1: Nov 2005, Anant Gole - Extended the RX logic for multiple descriptors
37 *
38 */
39#include <common.h>
40#include <command.h>
41#include <net.h>
42#include <miiphy.h>
Ben Warren84535872009-05-26 00:34:07 -070043#include <malloc.h>
Sergey Kubushync74b2102007-08-10 20:26:18 +020044#include <asm/arch/emac_defs.h>
Nick Thompsond7e35432009-12-18 13:33:07 +000045#include <asm/io.h>
Ilya Yanok7c587d32011-11-28 06:37:29 +000046#include "davinci_emac.h"
Sergey Kubushync74b2102007-08-10 20:26:18 +020047
Sergey Kubushync74b2102007-08-10 20:26:18 +020048unsigned int emac_dbg = 0;
49#define debug_emac(fmt,args...) if (emac_dbg) printf(fmt,##args)
50
Ilya Yanok82b77212011-11-28 06:37:30 +000051#ifdef EMAC_HW_RAM_ADDR
52static inline unsigned long BD_TO_HW(unsigned long x)
53{
54 if (x == 0)
55 return 0;
56
57 return x - EMAC_WRAPPER_RAM_ADDR + EMAC_HW_RAM_ADDR;
58}
59
60static inline unsigned long HW_TO_BD(unsigned long x)
61{
62 if (x == 0)
63 return 0;
64
65 return x - EMAC_HW_RAM_ADDR + EMAC_WRAPPER_RAM_ADDR;
66}
67#else
68#define BD_TO_HW(x) (x)
69#define HW_TO_BD(x) (x)
70#endif
71
Nick Thompsond7e35432009-12-18 13:33:07 +000072#ifdef DAVINCI_EMAC_GIG_ENABLE
Manjunath Hadlifb1d6332011-10-13 03:40:55 +000073#define emac_gigabit_enable(phy_addr) davinci_eth_gigabit_enable(phy_addr)
Nick Thompsond7e35432009-12-18 13:33:07 +000074#else
Manjunath Hadlifb1d6332011-10-13 03:40:55 +000075#define emac_gigabit_enable(phy_addr) /* no gigabit to enable */
Nick Thompsond7e35432009-12-18 13:33:07 +000076#endif
77
Heiko Schocher882ecfa2011-11-01 20:00:27 +000078#if !defined(CONFIG_SYS_EMAC_TI_CLKDIV)
79#define CONFIG_SYS_EMAC_TI_CLKDIV ((EMAC_MDIO_BUS_FREQ / \
80 EMAC_MDIO_CLOCK_FREQ) - 1)
81#endif
82
Sandeep Paulrajfcaac582008-08-31 00:39:46 +020083static void davinci_eth_mdio_enable(void);
Sergey Kubushync74b2102007-08-10 20:26:18 +020084
85static int gen_init_phy(int phy_addr);
86static int gen_is_phy_connected(int phy_addr);
87static int gen_get_link_speed(int phy_addr);
88static int gen_auto_negotiate(int phy_addr);
89
Sergey Kubushync74b2102007-08-10 20:26:18 +020090void eth_mdio_enable(void)
91{
Sandeep Paulrajfcaac582008-08-31 00:39:46 +020092 davinci_eth_mdio_enable();
Sergey Kubushync74b2102007-08-10 20:26:18 +020093}
Sergey Kubushync74b2102007-08-10 20:26:18 +020094
Sergey Kubushync74b2102007-08-10 20:26:18 +020095/* EMAC Addresses */
96static volatile emac_regs *adap_emac = (emac_regs *)EMAC_BASE_ADDR;
97static volatile ewrap_regs *adap_ewrap = (ewrap_regs *)EMAC_WRAPPER_BASE_ADDR;
98static volatile mdio_regs *adap_mdio = (mdio_regs *)EMAC_MDIO_BASE_ADDR;
99
100/* EMAC descriptors */
101static volatile emac_desc *emac_rx_desc = (emac_desc *)(EMAC_WRAPPER_RAM_ADDR + EMAC_RX_DESC_BASE);
102static volatile emac_desc *emac_tx_desc = (emac_desc *)(EMAC_WRAPPER_RAM_ADDR + EMAC_TX_DESC_BASE);
103static volatile emac_desc *emac_rx_active_head = 0;
104static volatile emac_desc *emac_rx_active_tail = 0;
105static int emac_rx_queue_active = 0;
106
107/* Receive packet buffers */
108static unsigned char emac_rx_buffers[EMAC_MAX_RX_BUFFERS * (EMAC_MAX_ETHERNET_PKT_SIZE + EMAC_PKT_ALIGN)];
109
Heiko Schocherdc02bad2011-11-15 10:00:04 -0500110#ifndef CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT
111#define CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT 3
112#endif
Sergey Kubushync74b2102007-08-10 20:26:18 +0200113
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000114/* PHY address for a discovered PHY (0xff - not found) */
Heiko Schocherdc02bad2011-11-15 10:00:04 -0500115static u_int8_t active_phy_addr[CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT];
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000116
117/* number of PHY found active */
118static u_int8_t num_phy;
119
Heiko Schocherdc02bad2011-11-15 10:00:04 -0500120phy_t phy[CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT];
Sergey Kubushync74b2102007-08-10 20:26:18 +0200121
Ben Gardiner7b37a272010-09-23 09:58:43 -0400122static int davinci_eth_set_mac_addr(struct eth_device *dev)
123{
124 unsigned long mac_hi;
125 unsigned long mac_lo;
126
127 /*
128 * Set MAC Addresses & Init multicast Hash to 0 (disable any multicast
129 * receive)
130 * Using channel 0 only - other channels are disabled
131 * */
132 writel(0, &adap_emac->MACINDEX);
133 mac_hi = (dev->enetaddr[3] << 24) |
134 (dev->enetaddr[2] << 16) |
135 (dev->enetaddr[1] << 8) |
136 (dev->enetaddr[0]);
137 mac_lo = (dev->enetaddr[5] << 8) |
138 (dev->enetaddr[4]);
139
140 writel(mac_hi, &adap_emac->MACADDRHI);
141#if defined(DAVINCI_EMAC_VERSION2)
142 writel(mac_lo | EMAC_MAC_ADDR_IS_VALID | EMAC_MAC_ADDR_MATCH,
143 &adap_emac->MACADDRLO);
144#else
145 writel(mac_lo, &adap_emac->MACADDRLO);
146#endif
147
148 writel(0, &adap_emac->MACHASH1);
149 writel(0, &adap_emac->MACHASH2);
150
151 /* Set source MAC address - REQUIRED */
152 writel(mac_hi, &adap_emac->MACSRCADDRHI);
153 writel(mac_lo, &adap_emac->MACSRCADDRLO);
154
155
156 return 0;
157}
158
Sandeep Paulrajfcaac582008-08-31 00:39:46 +0200159static void davinci_eth_mdio_enable(void)
Sergey Kubushync74b2102007-08-10 20:26:18 +0200160{
161 u_int32_t clkdiv;
162
Heiko Schocher882ecfa2011-11-01 20:00:27 +0000163 clkdiv = CONFIG_SYS_EMAC_TI_CLKDIV;
Sergey Kubushync74b2102007-08-10 20:26:18 +0200164
Nick Thompsond7e35432009-12-18 13:33:07 +0000165 writel((clkdiv & 0xff) |
166 MDIO_CONTROL_ENABLE |
167 MDIO_CONTROL_FAULT |
168 MDIO_CONTROL_FAULT_ENABLE,
169 &adap_mdio->CONTROL);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200170
Nick Thompsond7e35432009-12-18 13:33:07 +0000171 while (readl(&adap_mdio->CONTROL) & MDIO_CONTROL_IDLE)
172 ;
Sergey Kubushync74b2102007-08-10 20:26:18 +0200173}
174
175/*
176 * Tries to find an active connected PHY. Returns 1 if address if found.
177 * If no active PHY (or more than one PHY) found returns 0.
178 * Sets active_phy_addr variable.
179 */
Sandeep Paulrajfcaac582008-08-31 00:39:46 +0200180static int davinci_eth_phy_detect(void)
Sergey Kubushync74b2102007-08-10 20:26:18 +0200181{
182 u_int32_t phy_act_state;
183 int i;
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000184 int j;
185 unsigned int count = 0;
Sergey Kubushync74b2102007-08-10 20:26:18 +0200186
Heiko Schocherdc02bad2011-11-15 10:00:04 -0500187 for (i = 0; i < CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT; i++)
188 active_phy_addr[i] = 0xff;
Sergey Kubushync74b2102007-08-10 20:26:18 +0200189
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000190 udelay(1000);
191 phy_act_state = readl(&adap_mdio->ALIVE);
192
Nick Thompsond7e35432009-12-18 13:33:07 +0000193 if (phy_act_state == 0)
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000194 return 0; /* No active PHYs */
Sergey Kubushync74b2102007-08-10 20:26:18 +0200195
Sandeep Paulrajfcaac582008-08-31 00:39:46 +0200196 debug_emac("davinci_eth_phy_detect(), ALIVE = 0x%08x\n", phy_act_state);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200197
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000198 for (i = 0, j = 0; i < 32; i++)
Sergey Kubushync74b2102007-08-10 20:26:18 +0200199 if (phy_act_state & (1 << i)) {
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000200 count++;
Heiko Schocherdc02bad2011-11-15 10:00:04 -0500201 if (count < CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT) {
202 active_phy_addr[j++] = i;
203 } else {
204 printf("%s: to many PHYs detected.\n",
205 __func__);
206 count = 0;
207 break;
208 }
Sergey Kubushync74b2102007-08-10 20:26:18 +0200209 }
Sergey Kubushync74b2102007-08-10 20:26:18 +0200210
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000211 num_phy = count;
212
213 return count;
Sergey Kubushync74b2102007-08-10 20:26:18 +0200214}
215
216
217/* Read a PHY register via MDIO inteface. Returns 1 on success, 0 otherwise */
Sandeep Paulrajfcaac582008-08-31 00:39:46 +0200218int davinci_eth_phy_read(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t *data)
Sergey Kubushync74b2102007-08-10 20:26:18 +0200219{
220 int tmp;
221
Nick Thompsond7e35432009-12-18 13:33:07 +0000222 while (readl(&adap_mdio->USERACCESS0) & MDIO_USERACCESS0_GO)
223 ;
Sergey Kubushync74b2102007-08-10 20:26:18 +0200224
Nick Thompsond7e35432009-12-18 13:33:07 +0000225 writel(MDIO_USERACCESS0_GO |
226 MDIO_USERACCESS0_WRITE_READ |
227 ((reg_num & 0x1f) << 21) |
228 ((phy_addr & 0x1f) << 16),
229 &adap_mdio->USERACCESS0);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200230
231 /* Wait for command to complete */
Nick Thompsond7e35432009-12-18 13:33:07 +0000232 while ((tmp = readl(&adap_mdio->USERACCESS0)) & MDIO_USERACCESS0_GO)
233 ;
Sergey Kubushync74b2102007-08-10 20:26:18 +0200234
235 if (tmp & MDIO_USERACCESS0_ACK) {
236 *data = tmp & 0xffff;
237 return(1);
238 }
239
240 *data = -1;
241 return(0);
242}
243
244/* Write to a PHY register via MDIO inteface. Blocks until operation is complete. */
Sandeep Paulrajfcaac582008-08-31 00:39:46 +0200245int davinci_eth_phy_write(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t data)
Sergey Kubushync74b2102007-08-10 20:26:18 +0200246{
247
Nick Thompsond7e35432009-12-18 13:33:07 +0000248 while (readl(&adap_mdio->USERACCESS0) & MDIO_USERACCESS0_GO)
249 ;
Sergey Kubushync74b2102007-08-10 20:26:18 +0200250
Nick Thompsond7e35432009-12-18 13:33:07 +0000251 writel(MDIO_USERACCESS0_GO |
252 MDIO_USERACCESS0_WRITE_WRITE |
253 ((reg_num & 0x1f) << 21) |
254 ((phy_addr & 0x1f) << 16) |
255 (data & 0xffff),
256 &adap_mdio->USERACCESS0);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200257
258 /* Wait for command to complete */
Nick Thompsond7e35432009-12-18 13:33:07 +0000259 while (readl(&adap_mdio->USERACCESS0) & MDIO_USERACCESS0_GO)
260 ;
Sergey Kubushync74b2102007-08-10 20:26:18 +0200261
262 return(1);
263}
264
265/* PHY functions for a generic PHY */
266static int gen_init_phy(int phy_addr)
267{
268 int ret = 1;
269
270 if (gen_get_link_speed(phy_addr)) {
271 /* Try another time */
272 ret = gen_get_link_speed(phy_addr);
273 }
274
275 return(ret);
276}
277
278static int gen_is_phy_connected(int phy_addr)
279{
280 u_int16_t dummy;
281
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000282 return davinci_eth_phy_read(phy_addr, MII_PHYSID1, &dummy);
283}
284
285static int get_active_phy(void)
286{
287 int i;
288
289 for (i = 0; i < num_phy; i++)
290 if (phy[i].get_link_speed(active_phy_addr[i]))
291 return i;
292
293 return -1; /* Return error if no link */
Sergey Kubushync74b2102007-08-10 20:26:18 +0200294}
295
296static int gen_get_link_speed(int phy_addr)
297{
298 u_int16_t tmp;
299
Sudhakar Rajashekharad2607402010-11-18 09:59:37 -0500300 if (davinci_eth_phy_read(phy_addr, MII_STATUS_REG, &tmp) &&
301 (tmp & 0x04)) {
302#if defined(CONFIG_DRIVER_TI_EMAC_USE_RMII) && \
303 defined(CONFIG_MACH_DAVINCI_DA850_EVM)
Ben Gardiner7d2fade2011-01-11 14:48:17 -0500304 davinci_eth_phy_read(phy_addr, MII_LPA, &tmp);
Sudhakar Rajashekharad2607402010-11-18 09:59:37 -0500305
306 /* Speed doesn't matter, there is no setting for it in EMAC. */
Ben Gardiner7d2fade2011-01-11 14:48:17 -0500307 if (tmp & (LPA_100FULL | LPA_10FULL)) {
Sudhakar Rajashekharad2607402010-11-18 09:59:37 -0500308 /* set EMAC for Full Duplex */
309 writel(EMAC_MACCONTROL_MIIEN_ENABLE |
310 EMAC_MACCONTROL_FULLDUPLEX_ENABLE,
311 &adap_emac->MACCONTROL);
312 } else {
313 /*set EMAC for Half Duplex */
314 writel(EMAC_MACCONTROL_MIIEN_ENABLE,
315 &adap_emac->MACCONTROL);
316 }
317
Ben Gardiner7d2fade2011-01-11 14:48:17 -0500318 if (tmp & (LPA_100FULL | LPA_100HALF))
Sudhakar Rajashekharad2607402010-11-18 09:59:37 -0500319 writel(readl(&adap_emac->MACCONTROL) |
320 EMAC_MACCONTROL_RMIISPEED_100,
321 &adap_emac->MACCONTROL);
322 else
323 writel(readl(&adap_emac->MACCONTROL) &
324 ~EMAC_MACCONTROL_RMIISPEED_100,
325 &adap_emac->MACCONTROL);
326#endif
Sergey Kubushync74b2102007-08-10 20:26:18 +0200327 return(1);
Sudhakar Rajashekharad2607402010-11-18 09:59:37 -0500328 }
Sergey Kubushync74b2102007-08-10 20:26:18 +0200329
330 return(0);
331}
332
333static int gen_auto_negotiate(int phy_addr)
334{
335 u_int16_t tmp;
Manjunath Hadlicc4bd472011-10-13 03:40:53 +0000336 u_int16_t val;
337 unsigned long cntr = 0;
338
339 if (!davinci_eth_phy_read(phy_addr, MII_BMCR, &tmp))
340 return 0;
341
342 val = tmp | BMCR_FULLDPLX | BMCR_ANENABLE |
343 BMCR_SPEED100;
344 davinci_eth_phy_write(phy_addr, MII_BMCR, val);
345
346 if (!davinci_eth_phy_read(phy_addr, MII_ADVERTISE, &val))
347 return 0;
348
349 val |= (ADVERTISE_100FULL | ADVERTISE_100HALF | ADVERTISE_10FULL |
350 ADVERTISE_10HALF);
351 davinci_eth_phy_write(phy_addr, MII_ADVERTISE, val);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200352
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500353 if (!davinci_eth_phy_read(phy_addr, MII_BMCR, &tmp))
Sergey Kubushync74b2102007-08-10 20:26:18 +0200354 return(0);
355
356 /* Restart Auto_negotiation */
Manjunath Hadlicc4bd472011-10-13 03:40:53 +0000357 tmp |= BMCR_ANRESTART;
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500358 davinci_eth_phy_write(phy_addr, MII_BMCR, tmp);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200359
360 /*check AutoNegotiate complete */
Manjunath Hadlicc4bd472011-10-13 03:40:53 +0000361 do {
362 udelay(40000);
363 if (!davinci_eth_phy_read(phy_addr, MII_BMSR, &tmp))
364 return 0;
365
366 if (tmp & BMSR_ANEGCOMPLETE)
367 break;
368
369 cntr++;
370 } while (cntr < 200);
371
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500372 if (!davinci_eth_phy_read(phy_addr, MII_BMSR, &tmp))
Sergey Kubushync74b2102007-08-10 20:26:18 +0200373 return(0);
374
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500375 if (!(tmp & BMSR_ANEGCOMPLETE))
Sergey Kubushync74b2102007-08-10 20:26:18 +0200376 return(0);
377
378 return(gen_get_link_speed(phy_addr));
379}
380/* End of generic PHY functions */
381
382
Wolfgang Denkafaac862007-08-12 14:27:39 +0200383#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Mike Frysinger5700bb62010-07-27 18:35:08 -0400384static int davinci_mii_phy_read(const char *devname, unsigned char addr, unsigned char reg, unsigned short *value)
Sergey Kubushync74b2102007-08-10 20:26:18 +0200385{
Sandeep Paulrajfcaac582008-08-31 00:39:46 +0200386 return(davinci_eth_phy_read(addr, reg, value) ? 0 : 1);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200387}
388
Mike Frysinger5700bb62010-07-27 18:35:08 -0400389static int davinci_mii_phy_write(const char *devname, unsigned char addr, unsigned char reg, unsigned short value)
Sergey Kubushync74b2102007-08-10 20:26:18 +0200390{
Sandeep Paulrajfcaac582008-08-31 00:39:46 +0200391 return(davinci_eth_phy_write(addr, reg, value) ? 0 : 1);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200392}
Sergey Kubushync74b2102007-08-10 20:26:18 +0200393#endif
394
Manjunath Hadlifb1d6332011-10-13 03:40:55 +0000395static void __attribute__((unused)) davinci_eth_gigabit_enable(int phy_addr)
Nick Thompsond7e35432009-12-18 13:33:07 +0000396{
397 u_int16_t data;
398
Manjunath Hadlifb1d6332011-10-13 03:40:55 +0000399 if (davinci_eth_phy_read(phy_addr, 0, &data)) {
Nick Thompsond7e35432009-12-18 13:33:07 +0000400 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 Paulraj4b9b9e72010-12-28 14:37:33 -0500405 writel(readl(&adap_emac->MACCONTROL) |
406 EMAC_MACCONTROL_GIGFORCE |
407 EMAC_MACCONTROL_GIGABIT_ENABLE,
408 &adap_emac->MACCONTROL);
Nick Thompsond7e35432009-12-18 13:33:07 +0000409 }
410 }
411}
Sergey Kubushync74b2102007-08-10 20:26:18 +0200412
413/* Eth device open */
Ben Warren84535872009-05-26 00:34:07 -0700414static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
Sergey Kubushync74b2102007-08-10 20:26:18 +0200415{
416 dv_reg_p addr;
417 u_int32_t clkdiv, cnt;
418 volatile emac_desc *rx_desc;
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000419 int index;
Sergey Kubushync74b2102007-08-10 20:26:18 +0200420
421 debug_emac("+ emac_open\n");
422
423 /* Reset EMAC module and disable interrupts in wrapper */
Nick Thompsond7e35432009-12-18 13:33:07 +0000424 writel(1, &adap_emac->SOFTRESET);
425 while (readl(&adap_emac->SOFTRESET) != 0)
426 ;
427#if defined(DAVINCI_EMAC_VERSION2)
428 writel(1, &adap_ewrap->softrst);
429 while (readl(&adap_ewrap->softrst) != 0)
430 ;
431#else
432 writel(0, &adap_ewrap->EWCTL);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200433 for (cnt = 0; cnt < 5; cnt++) {
Nick Thompsond7e35432009-12-18 13:33:07 +0000434 clkdiv = readl(&adap_ewrap->EWCTL);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200435 }
Nick Thompsond7e35432009-12-18 13:33:07 +0000436#endif
Sergey Kubushync74b2102007-08-10 20:26:18 +0200437
Sudhakar Rajashekharad2607402010-11-18 09:59:37 -0500438#if defined(CONFIG_DRIVER_TI_EMAC_USE_RMII) && \
439 defined(CONFIG_MACH_DAVINCI_DA850_EVM)
440 adap_ewrap->c0rxen = adap_ewrap->c1rxen = adap_ewrap->c2rxen = 0;
441 adap_ewrap->c0txen = adap_ewrap->c1txen = adap_ewrap->c2txen = 0;
442 adap_ewrap->c0miscen = adap_ewrap->c1miscen = adap_ewrap->c2miscen = 0;
443#endif
Sergey Kubushync74b2102007-08-10 20:26:18 +0200444 rx_desc = emac_rx_desc;
445
Nick Thompsond7e35432009-12-18 13:33:07 +0000446 writel(1, &adap_emac->TXCONTROL);
447 writel(1, &adap_emac->RXCONTROL);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200448
Ben Gardiner7b37a272010-09-23 09:58:43 -0400449 davinci_eth_set_mac_addr(dev);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200450
451 /* Set DMA 8 TX / 8 RX Head pointers to 0 */
452 addr = &adap_emac->TX0HDP;
453 for(cnt = 0; cnt < 16; cnt++)
Nick Thompsond7e35432009-12-18 13:33:07 +0000454 writel(0, addr++);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200455
456 addr = &adap_emac->RX0HDP;
457 for(cnt = 0; cnt < 16; cnt++)
Nick Thompsond7e35432009-12-18 13:33:07 +0000458 writel(0, addr++);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200459
460 /* Clear Statistics (do this before setting MacControl register) */
461 addr = &adap_emac->RXGOODFRAMES;
462 for(cnt = 0; cnt < EMAC_NUM_STATS; cnt++)
Nick Thompsond7e35432009-12-18 13:33:07 +0000463 writel(0, addr++);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200464
465 /* No multicast addressing */
Nick Thompsond7e35432009-12-18 13:33:07 +0000466 writel(0, &adap_emac->MACHASH1);
467 writel(0, &adap_emac->MACHASH2);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200468
469 /* Create RX queue and set receive process in place */
470 emac_rx_active_head = emac_rx_desc;
471 for (cnt = 0; cnt < EMAC_MAX_RX_BUFFERS; cnt++) {
Ilya Yanok82b77212011-11-28 06:37:30 +0000472 rx_desc->next = BD_TO_HW((u_int32_t)(rx_desc + 1));
Sergey Kubushync74b2102007-08-10 20:26:18 +0200473 rx_desc->buffer = &emac_rx_buffers[cnt * (EMAC_MAX_ETHERNET_PKT_SIZE + EMAC_PKT_ALIGN)];
474 rx_desc->buff_off_len = EMAC_MAX_ETHERNET_PKT_SIZE;
475 rx_desc->pkt_flag_len = EMAC_CPPI_OWNERSHIP_BIT;
476 rx_desc++;
477 }
478
Nick Thompsond7e35432009-12-18 13:33:07 +0000479 /* Finalize the rx desc list */
Sergey Kubushync74b2102007-08-10 20:26:18 +0200480 rx_desc--;
481 rx_desc->next = 0;
482 emac_rx_active_tail = rx_desc;
483 emac_rx_queue_active = 1;
484
485 /* Enable TX/RX */
Nick Thompsond7e35432009-12-18 13:33:07 +0000486 writel(EMAC_MAX_ETHERNET_PKT_SIZE, &adap_emac->RXMAXLEN);
487 writel(0, &adap_emac->RXBUFFEROFFSET);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200488
Nick Thompsond7e35432009-12-18 13:33:07 +0000489 /*
490 * No fancy configs - Use this for promiscous debug
491 * - EMAC_RXMBPENABLE_RXCAFEN_ENABLE
492 */
493 writel(EMAC_RXMBPENABLE_RXBROADEN, &adap_emac->RXMBPENABLE);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200494
495 /* Enable ch 0 only */
Nick Thompsond7e35432009-12-18 13:33:07 +0000496 writel(1, &adap_emac->RXUNICASTSET);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200497
498 /* Enable MII interface and Full duplex mode */
Nick Thompsond7e35432009-12-18 13:33:07 +0000499#ifdef CONFIG_SOC_DA8XX
500 writel((EMAC_MACCONTROL_MIIEN_ENABLE |
501 EMAC_MACCONTROL_FULLDUPLEX_ENABLE |
502 EMAC_MACCONTROL_RMIISPEED_100),
503 &adap_emac->MACCONTROL);
504#else
505 writel((EMAC_MACCONTROL_MIIEN_ENABLE |
506 EMAC_MACCONTROL_FULLDUPLEX_ENABLE),
507 &adap_emac->MACCONTROL);
508#endif
Sergey Kubushync74b2102007-08-10 20:26:18 +0200509
510 /* Init MDIO & get link state */
Heiko Schocher882ecfa2011-11-01 20:00:27 +0000511 clkdiv = CONFIG_SYS_EMAC_TI_CLKDIV;
Nick Thompsond7e35432009-12-18 13:33:07 +0000512 writel((clkdiv & 0xff) | MDIO_CONTROL_ENABLE | MDIO_CONTROL_FAULT,
513 &adap_mdio->CONTROL);
514
515 /* We need to wait for MDIO to start */
516 udelay(1000);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200517
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000518 index = get_active_phy();
519 if (index == -1)
Sergey Kubushync74b2102007-08-10 20:26:18 +0200520 return(0);
521
Manjunath Hadlifb1d6332011-10-13 03:40:55 +0000522 emac_gigabit_enable(active_phy_addr[index]);
Nick Thompsond7e35432009-12-18 13:33:07 +0000523
Sergey Kubushync74b2102007-08-10 20:26:18 +0200524 /* Start receive process */
Ilya Yanok82b77212011-11-28 06:37:30 +0000525 writel(BD_TO_HW((u_int32_t)emac_rx_desc), &adap_emac->RX0HDP);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200526
527 debug_emac("- emac_open\n");
528
529 return(1);
530}
531
532/* EMAC Channel Teardown */
Sandeep Paulrajfcaac582008-08-31 00:39:46 +0200533static void davinci_eth_ch_teardown(int ch)
Sergey Kubushync74b2102007-08-10 20:26:18 +0200534{
535 dv_reg dly = 0xff;
536 dv_reg cnt;
537
538 debug_emac("+ emac_ch_teardown\n");
539
540 if (ch == EMAC_CH_TX) {
541 /* Init TX channel teardown */
Nagabhushana Netagunteba511f72011-09-03 22:20:33 -0400542 writel(0, &adap_emac->TXTEARDOWN);
Nick Thompsond7e35432009-12-18 13:33:07 +0000543 do {
544 /*
545 * Wait here for Tx teardown completion interrupt to
546 * occur. Note: A task delay can be called here to pend
547 * rather than occupying CPU cycles - anyway it has
548 * been found that teardown takes very few cpu cycles
549 * and does not affect functionality
550 */
551 dly--;
552 udelay(1);
553 if (dly == 0)
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200554 break;
Nick Thompsond7e35432009-12-18 13:33:07 +0000555 cnt = readl(&adap_emac->TX0CP);
556 } while (cnt != 0xfffffffc);
557 writel(cnt, &adap_emac->TX0CP);
558 writel(0, &adap_emac->TX0HDP);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200559 } else {
560 /* Init RX channel teardown */
Nagabhushana Netagunteba511f72011-09-03 22:20:33 -0400561 writel(0, &adap_emac->RXTEARDOWN);
Nick Thompsond7e35432009-12-18 13:33:07 +0000562 do {
563 /*
564 * Wait here for Rx teardown completion interrupt to
565 * occur. Note: A task delay can be called here to pend
566 * rather than occupying CPU cycles - anyway it has
567 * been found that teardown takes very few cpu cycles
568 * and does not affect functionality
569 */
570 dly--;
571 udelay(1);
572 if (dly == 0)
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200573 break;
Nick Thompsond7e35432009-12-18 13:33:07 +0000574 cnt = readl(&adap_emac->RX0CP);
575 } while (cnt != 0xfffffffc);
576 writel(cnt, &adap_emac->RX0CP);
577 writel(0, &adap_emac->RX0HDP);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200578 }
579
580 debug_emac("- emac_ch_teardown\n");
581}
582
583/* Eth device close */
Ben Warren84535872009-05-26 00:34:07 -0700584static void davinci_eth_close(struct eth_device *dev)
Sergey Kubushync74b2102007-08-10 20:26:18 +0200585{
586 debug_emac("+ emac_close\n");
587
Sandeep Paulrajfcaac582008-08-31 00:39:46 +0200588 davinci_eth_ch_teardown(EMAC_CH_TX); /* TX Channel teardown */
589 davinci_eth_ch_teardown(EMAC_CH_RX); /* RX Channel teardown */
Sergey Kubushync74b2102007-08-10 20:26:18 +0200590
591 /* Reset EMAC module and disable interrupts in wrapper */
Nick Thompsond7e35432009-12-18 13:33:07 +0000592 writel(1, &adap_emac->SOFTRESET);
593#if defined(DAVINCI_EMAC_VERSION2)
594 writel(1, &adap_ewrap->softrst);
595#else
596 writel(0, &adap_ewrap->EWCTL);
597#endif
Sergey Kubushync74b2102007-08-10 20:26:18 +0200598
Sudhakar Rajashekharad2607402010-11-18 09:59:37 -0500599#if defined(CONFIG_DRIVER_TI_EMAC_USE_RMII) && \
600 defined(CONFIG_MACH_DAVINCI_DA850_EVM)
601 adap_ewrap->c0rxen = adap_ewrap->c1rxen = adap_ewrap->c2rxen = 0;
602 adap_ewrap->c0txen = adap_ewrap->c1txen = adap_ewrap->c2txen = 0;
603 adap_ewrap->c0miscen = adap_ewrap->c1miscen = adap_ewrap->c2miscen = 0;
604#endif
Sergey Kubushync74b2102007-08-10 20:26:18 +0200605 debug_emac("- emac_close\n");
Sergey Kubushync74b2102007-08-10 20:26:18 +0200606}
607
608static int tx_send_loop = 0;
609
610/*
611 * This function sends a single packet on the network and returns
612 * positive number (number of bytes transmitted) or negative for error
613 */
Ben Warren84535872009-05-26 00:34:07 -0700614static int davinci_eth_send_packet (struct eth_device *dev,
615 volatile void *packet, int length)
Sergey Kubushync74b2102007-08-10 20:26:18 +0200616{
617 int ret_status = -1;
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000618 int index;
Sergey Kubushync74b2102007-08-10 20:26:18 +0200619 tx_send_loop = 0;
620
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000621 index = get_active_phy();
622 if (index == -1) {
623 printf(" WARN: emac_send_packet: No link\n");
Sergey Kubushync74b2102007-08-10 20:26:18 +0200624 return (ret_status);
625 }
626
Manjunath Hadlifb1d6332011-10-13 03:40:55 +0000627 emac_gigabit_enable(active_phy_addr[index]);
Nick Thompsond7e35432009-12-18 13:33:07 +0000628
Sergey Kubushync74b2102007-08-10 20:26:18 +0200629 /* Check packet size and if < EMAC_MIN_ETHERNET_PKT_SIZE, pad it up */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200630 if (length < EMAC_MIN_ETHERNET_PKT_SIZE) {
Sergey Kubushync74b2102007-08-10 20:26:18 +0200631 length = EMAC_MIN_ETHERNET_PKT_SIZE;
632 }
633
634 /* Populate the TX descriptor */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200635 emac_tx_desc->next = 0;
636 emac_tx_desc->buffer = (u_int8_t *) packet;
Sergey Kubushync74b2102007-08-10 20:26:18 +0200637 emac_tx_desc->buff_off_len = (length & 0xffff);
638 emac_tx_desc->pkt_flag_len = ((length & 0xffff) |
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200639 EMAC_CPPI_SOP_BIT |
640 EMAC_CPPI_OWNERSHIP_BIT |
641 EMAC_CPPI_EOP_BIT);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200642 /* Send the packet */
Ilya Yanok82b77212011-11-28 06:37:30 +0000643 writel(BD_TO_HW((unsigned long)emac_tx_desc), &adap_emac->TX0HDP);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200644
645 /* Wait for packet to complete or link down */
646 while (1) {
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000647 if (!phy[index].get_link_speed(active_phy_addr[index])) {
Sandeep Paulrajfcaac582008-08-31 00:39:46 +0200648 davinci_eth_ch_teardown (EMAC_CH_TX);
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200649 return (ret_status);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200650 }
Nick Thompsond7e35432009-12-18 13:33:07 +0000651
Manjunath Hadlifb1d6332011-10-13 03:40:55 +0000652 emac_gigabit_enable(active_phy_addr[index]);
Nick Thompsond7e35432009-12-18 13:33:07 +0000653
654 if (readl(&adap_emac->TXINTSTATRAW) & 0x01) {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200655 ret_status = length;
656 break;
657 }
658 tx_send_loop++;
Sergey Kubushync74b2102007-08-10 20:26:18 +0200659 }
660
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200661 return (ret_status);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200662}
663
664/*
665 * This function handles receipt of a packet from the network
666 */
Ben Warren84535872009-05-26 00:34:07 -0700667static int davinci_eth_rcv_packet (struct eth_device *dev)
Sergey Kubushync74b2102007-08-10 20:26:18 +0200668{
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200669 volatile emac_desc *rx_curr_desc;
670 volatile emac_desc *curr_desc;
671 volatile emac_desc *tail_desc;
672 int status, ret = -1;
Sergey Kubushync74b2102007-08-10 20:26:18 +0200673
674 rx_curr_desc = emac_rx_active_head;
675 status = rx_curr_desc->pkt_flag_len;
676 if ((rx_curr_desc) && ((status & EMAC_CPPI_OWNERSHIP_BIT) == 0)) {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200677 if (status & EMAC_CPPI_RX_ERROR_FRAME) {
678 /* Error in packet - discard it and requeue desc */
679 printf ("WARN: emac_rcv_pkt: Error in packet\n");
Sergey Kubushync74b2102007-08-10 20:26:18 +0200680 } else {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200681 NetReceive (rx_curr_desc->buffer,
682 (rx_curr_desc->buff_off_len & 0xffff));
Sergey Kubushync74b2102007-08-10 20:26:18 +0200683 ret = rx_curr_desc->buff_off_len & 0xffff;
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200684 }
Sergey Kubushync74b2102007-08-10 20:26:18 +0200685
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200686 /* Ack received packet descriptor */
Ilya Yanok82b77212011-11-28 06:37:30 +0000687 writel(BD_TO_HW((ulong)rx_curr_desc), &adap_emac->RX0CP);
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200688 curr_desc = rx_curr_desc;
689 emac_rx_active_head =
Ilya Yanok82b77212011-11-28 06:37:30 +0000690 (volatile emac_desc *) (HW_TO_BD(rx_curr_desc->next));
Sergey Kubushync74b2102007-08-10 20:26:18 +0200691
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200692 if (status & EMAC_CPPI_EOQ_BIT) {
693 if (emac_rx_active_head) {
Ilya Yanok82b77212011-11-28 06:37:30 +0000694 writel(BD_TO_HW((ulong)emac_rx_active_head),
Nick Thompsond7e35432009-12-18 13:33:07 +0000695 &adap_emac->RX0HDP);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200696 } else {
697 emac_rx_queue_active = 0;
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200698 printf ("INFO:emac_rcv_packet: RX Queue not active\n");
Sergey Kubushync74b2102007-08-10 20:26:18 +0200699 }
700 }
701
702 /* Recycle RX descriptor */
703 rx_curr_desc->buff_off_len = EMAC_MAX_ETHERNET_PKT_SIZE;
704 rx_curr_desc->pkt_flag_len = EMAC_CPPI_OWNERSHIP_BIT;
705 rx_curr_desc->next = 0;
706
707 if (emac_rx_active_head == 0) {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200708 printf ("INFO: emac_rcv_pkt: active queue head = 0\n");
Sergey Kubushync74b2102007-08-10 20:26:18 +0200709 emac_rx_active_head = curr_desc;
710 emac_rx_active_tail = curr_desc;
711 if (emac_rx_queue_active != 0) {
Ilya Yanok82b77212011-11-28 06:37:30 +0000712 writel(BD_TO_HW((ulong)emac_rx_active_head),
Nick Thompsond7e35432009-12-18 13:33:07 +0000713 &adap_emac->RX0HDP);
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200714 printf ("INFO: emac_rcv_pkt: active queue head = 0, HDP fired\n");
Sergey Kubushync74b2102007-08-10 20:26:18 +0200715 emac_rx_queue_active = 1;
716 }
717 } else {
718 tail_desc = emac_rx_active_tail;
719 emac_rx_active_tail = curr_desc;
Ilya Yanok82b77212011-11-28 06:37:30 +0000720 tail_desc->next = BD_TO_HW((ulong) curr_desc);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200721 status = tail_desc->pkt_flag_len;
722 if (status & EMAC_CPPI_EOQ_BIT) {
Ilya Yanok82b77212011-11-28 06:37:30 +0000723 writel(BD_TO_HW((ulong)curr_desc),
Nick Thompsond7e35432009-12-18 13:33:07 +0000724 &adap_emac->RX0HDP);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200725 status &= ~EMAC_CPPI_EOQ_BIT;
726 tail_desc->pkt_flag_len = status;
727 }
728 }
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200729 return (ret);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200730 }
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200731 return (0);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200732}
733
Ben Warren8cc13c12009-04-27 23:19:10 -0700734/*
735 * This function initializes the emac hardware. It does NOT initialize
736 * EMAC modules power or pin multiplexors, that is done by board_init()
737 * much earlier in bootup process. Returns 1 on success, 0 otherwise.
738 */
Ben Warren84535872009-05-26 00:34:07 -0700739int davinci_emac_initialize(void)
Ben Warren8cc13c12009-04-27 23:19:10 -0700740{
741 u_int32_t phy_id;
742 u_int16_t tmp;
743 int i;
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000744 int ret;
Ben Warren84535872009-05-26 00:34:07 -0700745 struct eth_device *dev;
746
747 dev = malloc(sizeof *dev);
748
749 if (dev == NULL)
750 return -1;
751
752 memset(dev, 0, sizeof *dev);
Sandeep Paulraj2a7d6032010-12-28 14:42:27 -0500753 sprintf(dev->name, "DaVinci-EMAC");
Ben Warren84535872009-05-26 00:34:07 -0700754
755 dev->iobase = 0;
756 dev->init = davinci_eth_open;
757 dev->halt = davinci_eth_close;
758 dev->send = davinci_eth_send_packet;
759 dev->recv = davinci_eth_rcv_packet;
Ben Gardiner7b37a272010-09-23 09:58:43 -0400760 dev->write_hwaddr = davinci_eth_set_mac_addr;
Ben Warren84535872009-05-26 00:34:07 -0700761
762 eth_register(dev);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200763
Ben Warren8cc13c12009-04-27 23:19:10 -0700764 davinci_eth_mdio_enable();
765
Heiko Schocher19fdf9a2011-09-14 19:37:42 +0000766 /* let the EMAC detect the PHYs */
767 udelay(5000);
768
Ben Warren8cc13c12009-04-27 23:19:10 -0700769 for (i = 0; i < 256; i++) {
Nick Thompsond7e35432009-12-18 13:33:07 +0000770 if (readl(&adap_mdio->ALIVE))
Ben Warren8cc13c12009-04-27 23:19:10 -0700771 break;
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000772 udelay(1000);
Ben Warren8cc13c12009-04-27 23:19:10 -0700773 }
774
775 if (i >= 256) {
776 printf("No ETH PHY detected!!!\n");
777 return(0);
778 }
779
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000780 /* Find if PHY(s) is/are connected */
781 ret = davinci_eth_phy_detect();
782 if (!ret)
Ben Warren8cc13c12009-04-27 23:19:10 -0700783 return(0);
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000784 else
Heiko Schocherdc02bad2011-11-15 10:00:04 -0500785 debug_emac(" %d ETH PHY detected\n", ret);
Ben Warren8cc13c12009-04-27 23:19:10 -0700786
787 /* Get PHY ID and initialize phy_ops for a detected PHY */
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000788 for (i = 0; i < num_phy; i++) {
789 if (!davinci_eth_phy_read(active_phy_addr[i], MII_PHYSID1,
790 &tmp)) {
791 active_phy_addr[i] = 0xff;
792 continue;
793 }
Ben Warren8cc13c12009-04-27 23:19:10 -0700794
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000795 phy_id = (tmp << 16) & 0xffff0000;
Ben Warren8cc13c12009-04-27 23:19:10 -0700796
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000797 if (!davinci_eth_phy_read(active_phy_addr[i], MII_PHYSID2,
798 &tmp)) {
799 active_phy_addr[i] = 0xff;
800 continue;
801 }
Ben Warren8cc13c12009-04-27 23:19:10 -0700802
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000803 phy_id |= tmp & 0x0000ffff;
Ben Warren8cc13c12009-04-27 23:19:10 -0700804
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000805 switch (phy_id) {
Ilya Yanok918588c2011-11-28 06:37:31 +0000806#ifdef PHY_KSZ8873
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000807 case PHY_KSZ8873:
808 sprintf(phy[i].name, "KSZ8873 @ 0x%02x",
809 active_phy_addr[i]);
810 phy[i].init = ksz8873_init_phy;
811 phy[i].is_phy_connected = ksz8873_is_phy_connected;
812 phy[i].get_link_speed = ksz8873_get_link_speed;
813 phy[i].auto_negotiate = ksz8873_auto_negotiate;
814 break;
Ilya Yanok918588c2011-11-28 06:37:31 +0000815#endif
816#ifdef PHY_LXT972
Ben Warren8cc13c12009-04-27 23:19:10 -0700817 case PHY_LXT972:
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000818 sprintf(phy[i].name, "LXT972 @ 0x%02x",
819 active_phy_addr[i]);
820 phy[i].init = lxt972_init_phy;
821 phy[i].is_phy_connected = lxt972_is_phy_connected;
822 phy[i].get_link_speed = lxt972_get_link_speed;
823 phy[i].auto_negotiate = lxt972_auto_negotiate;
Ben Warren8cc13c12009-04-27 23:19:10 -0700824 break;
Ilya Yanok918588c2011-11-28 06:37:31 +0000825#endif
826#ifdef PHY_DP83848
Ben Warren8cc13c12009-04-27 23:19:10 -0700827 case PHY_DP83848:
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000828 sprintf(phy[i].name, "DP83848 @ 0x%02x",
829 active_phy_addr[i]);
830 phy[i].init = dp83848_init_phy;
831 phy[i].is_phy_connected = dp83848_is_phy_connected;
832 phy[i].get_link_speed = dp83848_get_link_speed;
833 phy[i].auto_negotiate = dp83848_auto_negotiate;
Ben Warren8cc13c12009-04-27 23:19:10 -0700834 break;
Ilya Yanok918588c2011-11-28 06:37:31 +0000835#endif
836#ifdef PHY_ET1011C
Sandeep Paulraj840f8922010-12-28 15:43:16 -0500837 case PHY_ET1011C:
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000838 sprintf(phy[i].name, "ET1011C @ 0x%02x",
839 active_phy_addr[i]);
840 phy[i].init = gen_init_phy;
841 phy[i].is_phy_connected = gen_is_phy_connected;
842 phy[i].get_link_speed = et1011c_get_link_speed;
843 phy[i].auto_negotiate = gen_auto_negotiate;
Sandeep Paulraj840f8922010-12-28 15:43:16 -0500844 break;
Ilya Yanok918588c2011-11-28 06:37:31 +0000845#endif
Ben Warren8cc13c12009-04-27 23:19:10 -0700846 default:
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000847 sprintf(phy[i].name, "GENERIC @ 0x%02x",
848 active_phy_addr[i]);
849 phy[i].init = gen_init_phy;
850 phy[i].is_phy_connected = gen_is_phy_connected;
851 phy[i].get_link_speed = gen_get_link_speed;
852 phy[i].auto_negotiate = gen_auto_negotiate;
853 }
854
Ilya Yanoke0297a52011-11-01 13:15:55 +0000855 debug("Ethernet PHY: %s\n", phy[i].name);
Manjunath Hadli062fe7d2011-10-13 03:40:54 +0000856
857 miiphy_register(phy[i].name, davinci_mii_phy_read,
858 davinci_mii_phy_write);
Ben Warren8cc13c12009-04-27 23:19:10 -0700859 }
Ben Warren8cc13c12009-04-27 23:19:10 -0700860 return(1);
861}