blob: 5ac6334322ec2299e5bf27d951aec9296b410c36 [file] [log] [blame]
wdenk9c53f402003-10-15 23:53:47 +00001/*
2 * tsec.c
wdenka445ddf2004-06-09 00:34:46 +00003 * Freescale Three Speed Ethernet Controller driver
wdenk9c53f402003-10-15 23:53:47 +00004 *
5 * This software may be used and distributed according to the
6 * terms of the GNU Public License, Version 2, incorporated
7 * herein by reference.
8 *
wdenka445ddf2004-06-09 00:34:46 +00009 * Copyright 2004 Freescale Semiconductor.
wdenk9c53f402003-10-15 23:53:47 +000010 * (C) Copyright 2003, Motorola, Inc.
wdenka445ddf2004-06-09 00:34:46 +000011 * maintained by Jon Loeliger (loeliger@freescale.com)
wdenk9c53f402003-10-15 23:53:47 +000012 * author Andy Fleming
13 *
14 */
15
16#include <config.h>
17#include <mpc85xx.h>
18#include <common.h>
19#include <malloc.h>
20#include <net.h>
21#include <command.h>
22
23#if defined(CONFIG_TSEC_ENET)
24#include "tsec.h"
25
26#define TX_BUF_CNT 2
27
wdenk9c53f402003-10-15 23:53:47 +000028static uint rxIdx; /* index of the current RX buffer */
29static uint txIdx; /* index of the current TX buffer */
30
31typedef volatile struct rtxbd {
32 txbd8_t txbd[TX_BUF_CNT];
33 rxbd8_t rxbd[PKTBUFSRX];
34} RTXBD;
35
wdenka445ddf2004-06-09 00:34:46 +000036struct tsec_info_struct {
37 unsigned int phyaddr;
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050038 u32 flags;
wdenka445ddf2004-06-09 00:34:46 +000039 unsigned int phyregidx;
40};
41
42
43/* The tsec_info structure contains 3 values which the
44 * driver uses to determine how to operate a given ethernet
45 * device. For now, the structure is initialized with the
46 * knowledge that all current implementations have 2 TSEC
47 * devices, and one FEC. The information needed is:
48 * phyaddr - The address of the PHY which is attached to
wdenkbfad55d2005-03-14 23:56:42 +000049 * the given device.
wdenka445ddf2004-06-09 00:34:46 +000050 *
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050051 * flags - This variable indicates whether the device
52 * supports gigabit speed ethernet, and whether it should be
53 * in reduced mode.
wdenka445ddf2004-06-09 00:34:46 +000054 *
55 * phyregidx - This variable specifies which ethernet device
wdenkbfad55d2005-03-14 23:56:42 +000056 * controls the MII Management registers which are connected
57 * to the PHY. For 8540/8560, only TSEC1 (index 0) has
58 * access to the PHYs, so all of the entries have "0".
wdenka445ddf2004-06-09 00:34:46 +000059 *
60 * The values specified in the table are taken from the board's
61 * config file in include/configs/. When implementing a new
62 * board with ethernet capability, it is necessary to define:
63 * TSEC1_PHY_ADDR
64 * TSEC1_PHYIDX
65 * TSEC2_PHY_ADDR
66 * TSEC2_PHYIDX
67 *
68 * and for 8560:
69 * FEC_PHY_ADDR
70 * FEC_PHYIDX
71 */
72static struct tsec_info_struct tsec_info[] = {
73#ifdef CONFIG_MPC85XX_TSEC1
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050074 {TSEC1_PHY_ADDR, TSEC_GIGABIT, TSEC1_PHYIDX},
wdenkbfad55d2005-03-14 23:56:42 +000075#else
76 { 0, 0, 0},
wdenka445ddf2004-06-09 00:34:46 +000077#endif
78#ifdef CONFIG_MPC85XX_TSEC2
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050079 {TSEC2_PHY_ADDR, TSEC_GIGABIT, TSEC2_PHYIDX},
wdenkbfad55d2005-03-14 23:56:42 +000080#else
81 { 0, 0, 0},
wdenka445ddf2004-06-09 00:34:46 +000082#endif
83#ifdef CONFIG_MPC85XX_FEC
84 {FEC_PHY_ADDR, 0, FEC_PHYIDX},
wdenkbfad55d2005-03-14 23:56:42 +000085#else
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050086# ifdef CONFIG_MPC85XX_TSEC3
87 {TSEC3_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC3_PHYIDX},
88# else
wdenkbfad55d2005-03-14 23:56:42 +000089 { 0, 0, 0},
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050090# endif
91# ifdef CONFIG_MPC85XX_TSEC4
92 {TSEC4_PHY_ADDR, TSEC_REDUCED, TSEC4_PHYIDX},
93# else
94 { 0, 0, 0},
95# endif
wdenka445ddf2004-06-09 00:34:46 +000096#endif
97};
98
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050099#define MAXCONTROLLERS (4)
wdenka445ddf2004-06-09 00:34:46 +0000100
101static int relocated = 0;
102
103static struct tsec_private *privlist[MAXCONTROLLERS];
104
wdenk9c53f402003-10-15 23:53:47 +0000105#ifdef __GNUC__
106static RTXBD rtx __attribute__ ((aligned(8)));
107#else
108#error "rtx must be 64-bit aligned"
109#endif
110
111static int tsec_send(struct eth_device* dev, volatile void *packet, int length);
112static int tsec_recv(struct eth_device* dev);
113static int tsec_init(struct eth_device* dev, bd_t * bd);
114static void tsec_halt(struct eth_device* dev);
wdenka445ddf2004-06-09 00:34:46 +0000115static void init_registers(volatile tsec_t *regs);
116static void startup_tsec(struct eth_device *dev);
117static int init_phy(struct eth_device *dev);
118void write_phy_reg(struct tsec_private *priv, uint regnum, uint value);
119uint read_phy_reg(struct tsec_private *priv, uint regnum);
120struct phy_info * get_phy_info(struct eth_device *dev);
121void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd);
122static void adjust_link(struct eth_device *dev);
123static void relocate_cmds(void);
wdenk78924a72004-04-18 21:45:42 +0000124
wdenka445ddf2004-06-09 00:34:46 +0000125/* Initialize device structure. Returns success if PHY
126 * initialization succeeded (i.e. if it recognizes the PHY)
127 */
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500128int tsec_initialize(bd_t *bis, int index, char *devname)
wdenk9c53f402003-10-15 23:53:47 +0000129{
130 struct eth_device* dev;
131 int i;
wdenka445ddf2004-06-09 00:34:46 +0000132 struct tsec_private *priv;
wdenk9c53f402003-10-15 23:53:47 +0000133
134 dev = (struct eth_device*) malloc(sizeof *dev);
135
wdenka445ddf2004-06-09 00:34:46 +0000136 if(NULL == dev)
wdenk9c53f402003-10-15 23:53:47 +0000137 return 0;
138
139 memset(dev, 0, sizeof *dev);
140
wdenka445ddf2004-06-09 00:34:46 +0000141 priv = (struct tsec_private *) malloc(sizeof(*priv));
142
143 if(NULL == priv)
144 return 0;
145
146 privlist[index] = priv;
147 priv->regs = (volatile tsec_t *)(TSEC_BASE_ADDR + index*TSEC_SIZE);
148 priv->phyregs = (volatile tsec_t *)(TSEC_BASE_ADDR +
149 tsec_info[index].phyregidx*TSEC_SIZE);
150
151 priv->phyaddr = tsec_info[index].phyaddr;
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500152 priv->flags = tsec_info[index].flags;
wdenka445ddf2004-06-09 00:34:46 +0000153
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500154 sprintf(dev->name, devname);
wdenk9c53f402003-10-15 23:53:47 +0000155 dev->iobase = 0;
wdenka445ddf2004-06-09 00:34:46 +0000156 dev->priv = priv;
wdenk9c53f402003-10-15 23:53:47 +0000157 dev->init = tsec_init;
158 dev->halt = tsec_halt;
159 dev->send = tsec_send;
160 dev->recv = tsec_recv;
161
162 /* Tell u-boot to get the addr from the env */
163 for(i=0;i<6;i++)
164 dev->enetaddr[i] = 0;
165
166 eth_register(dev);
167
wdenk78924a72004-04-18 21:45:42 +0000168
wdenka445ddf2004-06-09 00:34:46 +0000169 /* Reset the MAC */
170 priv->regs->maccfg1 |= MACCFG1_SOFT_RESET;
171 priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET);
wdenk78924a72004-04-18 21:45:42 +0000172
wdenka445ddf2004-06-09 00:34:46 +0000173 /* Try to initialize PHY here, and return */
174 return init_phy(dev);
wdenk9c53f402003-10-15 23:53:47 +0000175}
176
177
178/* Initializes data structures and registers for the controller,
wdenkbfad55d2005-03-14 23:56:42 +0000179 * and brings the interface up. Returns the link status, meaning
wdenka445ddf2004-06-09 00:34:46 +0000180 * that it returns success if the link is up, failure otherwise.
181 * This allows u-boot to find the first active controller. */
wdenk9c53f402003-10-15 23:53:47 +0000182int tsec_init(struct eth_device* dev, bd_t * bd)
183{
wdenk9c53f402003-10-15 23:53:47 +0000184 uint tempval;
185 char tmpbuf[MAC_ADDR_LEN];
186 int i;
wdenka445ddf2004-06-09 00:34:46 +0000187 struct tsec_private *priv = (struct tsec_private *)dev->priv;
188 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000189
190 /* Make sure the controller is stopped */
191 tsec_halt(dev);
192
wdenka445ddf2004-06-09 00:34:46 +0000193 /* Init MACCFG2. Defaults to GMII */
wdenk9c53f402003-10-15 23:53:47 +0000194 regs->maccfg2 = MACCFG2_INIT_SETTINGS;
195
196 /* Init ECNTRL */
197 regs->ecntrl = ECNTRL_INIT_SETTINGS;
198
199 /* Copy the station address into the address registers.
200 * Backwards, because little endian MACS are dumb */
201 for(i=0;i<MAC_ADDR_LEN;i++) {
wdenka445ddf2004-06-09 00:34:46 +0000202 tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i];
wdenk9c53f402003-10-15 23:53:47 +0000203 }
204 (uint)(regs->macstnaddr1) = *((uint *)(tmpbuf));
205
206 tempval = *((uint *)(tmpbuf +4));
207
208 (uint)(regs->macstnaddr2) = tempval;
209
wdenk9c53f402003-10-15 23:53:47 +0000210 /* reset the indices to zero */
211 rxIdx = 0;
212 txIdx = 0;
213
214 /* Clear out (for the most part) the other registers */
215 init_registers(regs);
216
217 /* Ready the device for tx/rx */
wdenka445ddf2004-06-09 00:34:46 +0000218 startup_tsec(dev);
wdenk9c53f402003-10-15 23:53:47 +0000219
wdenka445ddf2004-06-09 00:34:46 +0000220 /* If there's no link, fail */
221 return priv->link;
222
223}
wdenk9c53f402003-10-15 23:53:47 +0000224
wdenka445ddf2004-06-09 00:34:46 +0000225
226/* Write value to the device's PHY through the registers
227 * specified in priv, modifying the register specified in regnum.
228 * It will wait for the write to be done (or for a timeout to
229 * expire) before exiting
230 */
231void write_phy_reg(struct tsec_private *priv, uint regnum, uint value)
232{
233 volatile tsec_t *regbase = priv->phyregs;
234 uint phyid = priv->phyaddr;
235 int timeout=1000000;
236
237 regbase->miimadd = (phyid << 8) | regnum;
238 regbase->miimcon = value;
239 asm("msync");
240
241 timeout=1000000;
242 while((regbase->miimind & MIIMIND_BUSY) && timeout--);
wdenk9c53f402003-10-15 23:53:47 +0000243}
244
245
wdenka445ddf2004-06-09 00:34:46 +0000246/* Reads register regnum on the device's PHY through the
wdenkbfad55d2005-03-14 23:56:42 +0000247 * registers specified in priv. It lowers and raises the read
wdenka445ddf2004-06-09 00:34:46 +0000248 * command, and waits for the data to become valid (miimind
249 * notvalid bit cleared), and the bus to cease activity (miimind
250 * busy bit cleared), and then returns the value
251 */
252uint read_phy_reg(struct tsec_private *priv, uint regnum)
wdenk9c53f402003-10-15 23:53:47 +0000253{
254 uint value;
wdenka445ddf2004-06-09 00:34:46 +0000255 volatile tsec_t *regbase = priv->phyregs;
256 uint phyid = priv->phyaddr;
wdenk9c53f402003-10-15 23:53:47 +0000257
wdenka445ddf2004-06-09 00:34:46 +0000258 /* Put the address of the phy, and the register
259 * number into MIIMADD */
260 regbase->miimadd = (phyid << 8) | regnum;
wdenk9c53f402003-10-15 23:53:47 +0000261
262 /* Clear the command register, and wait */
263 regbase->miimcom = 0;
264 asm("msync");
265
266 /* Initiate a read command, and wait */
267 regbase->miimcom = MIIM_READ_COMMAND;
268 asm("msync");
269
270 /* Wait for the the indication that the read is done */
271 while((regbase->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY)));
272
273 /* Grab the value read from the PHY */
274 value = regbase->miimstat;
275
276 return value;
277}
278
wdenka445ddf2004-06-09 00:34:46 +0000279
280/* Discover which PHY is attached to the device, and configure it
281 * properly. If the PHY is not recognized, then return 0
282 * (failure). Otherwise, return 1
283 */
284static int init_phy(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000285{
wdenka445ddf2004-06-09 00:34:46 +0000286 struct tsec_private *priv = (struct tsec_private *)dev->priv;
287 struct phy_info *curphy;
wdenk9c53f402003-10-15 23:53:47 +0000288
289 /* Assign a Physical address to the TBI */
wdenke085e5b2005-04-05 23:32:21 +0000290
wdenkf41ff3b2005-04-04 23:43:44 +0000291 {
292 volatile tsec_t *regs = (volatile tsec_t *)(TSEC_BASE_ADDR);
293 regs->tbipa = TBIPA_VALUE;
294 regs = (volatile tsec_t *)(TSEC_BASE_ADDR + TSEC_SIZE);
295 regs->tbipa = TBIPA_VALUE;
296 asm("msync");
297 }
298
299 /* Reset MII (due to new addresses) */
300 priv->phyregs->miimcfg = MIIMCFG_RESET;
301 asm("msync");
302 priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
303 asm("msync");
304 while(priv->phyregs->miimind & MIIMIND_BUSY);
wdenk9c53f402003-10-15 23:53:47 +0000305
wdenka445ddf2004-06-09 00:34:46 +0000306 if(0 == relocated)
307 relocate_cmds();
wdenk9c53f402003-10-15 23:53:47 +0000308
wdenka445ddf2004-06-09 00:34:46 +0000309 /* Get the cmd structure corresponding to the attached
310 * PHY */
311 curphy = get_phy_info(dev);
wdenk9c53f402003-10-15 23:53:47 +0000312
wdenka445ddf2004-06-09 00:34:46 +0000313 if(NULL == curphy) {
314 printf("%s: No PHY found\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +0000315
wdenka445ddf2004-06-09 00:34:46 +0000316 return 0;
317 }
wdenk9c53f402003-10-15 23:53:47 +0000318
wdenka445ddf2004-06-09 00:34:46 +0000319 priv->phyinfo = curphy;
wdenk9c53f402003-10-15 23:53:47 +0000320
wdenka445ddf2004-06-09 00:34:46 +0000321 phy_run_commands(priv, priv->phyinfo->config);
wdenk9c53f402003-10-15 23:53:47 +0000322
wdenka445ddf2004-06-09 00:34:46 +0000323 return 1;
324}
wdenk9c53f402003-10-15 23:53:47 +0000325
wdenk9c53f402003-10-15 23:53:47 +0000326
wdenka445ddf2004-06-09 00:34:46 +0000327/* Returns which value to write to the control register. */
328/* For 10/100, the value is slightly different */
329uint mii_cr_init(uint mii_reg, struct tsec_private *priv)
330{
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500331 if(priv->flags & TSEC_GIGABIT)
wdenka445ddf2004-06-09 00:34:46 +0000332 return MIIM_CONTROL_INIT;
wdenk9c53f402003-10-15 23:53:47 +0000333 else
wdenka445ddf2004-06-09 00:34:46 +0000334 return MIIM_CR_INIT;
335}
wdenk9c53f402003-10-15 23:53:47 +0000336
wdenk9c53f402003-10-15 23:53:47 +0000337
wdenka445ddf2004-06-09 00:34:46 +0000338/* Parse the status register for link, and then do
339 * auto-negotiation */
340uint mii_parse_sr(uint mii_reg, struct tsec_private *priv)
341{
342 uint timeout = TSEC_TIMEOUT;
wdenk9c53f402003-10-15 23:53:47 +0000343
wdenka445ddf2004-06-09 00:34:46 +0000344 if(mii_reg & MIIM_STATUS_LINK)
345 priv->link = 1;
346 else
347 priv->link = 0;
wdenk9c53f402003-10-15 23:53:47 +0000348
wdenka445ddf2004-06-09 00:34:46 +0000349 if(priv->link) {
350 while((!(mii_reg & MIIM_STATUS_AN_DONE)) && timeout--)
351 mii_reg = read_phy_reg(priv, MIIM_STATUS);
wdenk9c53f402003-10-15 23:53:47 +0000352 }
353
wdenka445ddf2004-06-09 00:34:46 +0000354 return 0;
355}
356
wdenk9c53f402003-10-15 23:53:47 +0000357
wdenka445ddf2004-06-09 00:34:46 +0000358/* Parse the 88E1011's status register for speed and duplex
359 * information */
360uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private *priv)
361{
362 uint speed;
wdenk9c53f402003-10-15 23:53:47 +0000363
wdenka445ddf2004-06-09 00:34:46 +0000364 if(mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
365 priv->duplexity = 1;
366 else
367 priv->duplexity = 0;
368
369 speed = (mii_reg &MIIM_88E1011_PHYSTAT_SPEED);
370
371 switch(speed) {
372 case MIIM_88E1011_PHYSTAT_GBIT:
373 priv->speed = 1000;
374 break;
375 case MIIM_88E1011_PHYSTAT_100:
376 priv->speed = 100;
377 break;
378 default:
379 priv->speed = 10;
wdenk9c53f402003-10-15 23:53:47 +0000380 }
381
wdenka445ddf2004-06-09 00:34:46 +0000382 return 0;
383}
384
wdenk9c53f402003-10-15 23:53:47 +0000385
wdenka445ddf2004-06-09 00:34:46 +0000386/* Parse the cis8201's status register for speed and duplex
387 * information */
388uint mii_parse_cis8201(uint mii_reg, struct tsec_private *priv)
389{
390 uint speed;
391
392 if(mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
393 priv->duplexity = 1;
394 else
395 priv->duplexity = 0;
396
397 speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
398 switch(speed) {
399 case MIIM_CIS8201_AUXCONSTAT_GBIT:
400 priv->speed = 1000;
401 break;
402 case MIIM_CIS8201_AUXCONSTAT_100:
403 priv->speed = 100;
404 break;
405 default:
406 priv->speed = 10;
407 break;
wdenk9c53f402003-10-15 23:53:47 +0000408 }
409
wdenka445ddf2004-06-09 00:34:46 +0000410 return 0;
411}
wdenk9c53f402003-10-15 23:53:47 +0000412
wdenka445ddf2004-06-09 00:34:46 +0000413
414/* Parse the DM9161's status register for speed and duplex
415 * information */
416uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private *priv)
417{
418 if(mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
419 priv->speed = 100;
420 else
421 priv->speed = 10;
422
423 if(mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
424 priv->duplexity = 1;
425 else
426 priv->duplexity = 0;
427
428 return 0;
429}
430
431
432/* Hack to write all 4 PHYs with the LED values */
433uint mii_cis8204_fixled(uint mii_reg, struct tsec_private *priv)
434{
435 uint phyid;
436 volatile tsec_t *regbase = priv->phyregs;
437 int timeout=1000000;
438
439 for(phyid=0;phyid<4;phyid++) {
440 regbase->miimadd = (phyid << 8) | mii_reg;
441 regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
442 asm("msync");
443
444 timeout=1000000;
445 while((regbase->miimind & MIIMIND_BUSY) && timeout--);
wdenk9c53f402003-10-15 23:53:47 +0000446 }
wdenk9c53f402003-10-15 23:53:47 +0000447
wdenka445ddf2004-06-09 00:34:46 +0000448 return MIIM_CIS8204_SLEDCON_INIT;
wdenk9c53f402003-10-15 23:53:47 +0000449}
450
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500451uint mii_cis8204_setmode(uint mii_reg, struct tsec_private *priv)
452{
453 if (priv->flags & TSEC_REDUCED)
454 return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
455 else
456 return MIIM_CIS8204_EPHYCON_INIT;
457}
wdenk9c53f402003-10-15 23:53:47 +0000458
wdenka445ddf2004-06-09 00:34:46 +0000459/* Initialized required registers to appropriate values, zeroing
460 * those we don't care about (unless zero is bad, in which case,
461 * choose a more appropriate value) */
462static void init_registers(volatile tsec_t *regs)
wdenk9c53f402003-10-15 23:53:47 +0000463{
464 /* Clear IEVENT */
465 regs->ievent = IEVENT_INIT_CLEAR;
466
467 regs->imask = IMASK_INIT_CLEAR;
468
469 regs->hash.iaddr0 = 0;
470 regs->hash.iaddr1 = 0;
471 regs->hash.iaddr2 = 0;
472 regs->hash.iaddr3 = 0;
473 regs->hash.iaddr4 = 0;
474 regs->hash.iaddr5 = 0;
475 regs->hash.iaddr6 = 0;
476 regs->hash.iaddr7 = 0;
477
478 regs->hash.gaddr0 = 0;
479 regs->hash.gaddr1 = 0;
480 regs->hash.gaddr2 = 0;
481 regs->hash.gaddr3 = 0;
482 regs->hash.gaddr4 = 0;
483 regs->hash.gaddr5 = 0;
484 regs->hash.gaddr6 = 0;
485 regs->hash.gaddr7 = 0;
486
487 regs->rctrl = 0x00000000;
488
489 /* Init RMON mib registers */
490 memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
491
492 regs->rmon.cam1 = 0xffffffff;
493 regs->rmon.cam2 = 0xffffffff;
494
495 regs->mrblr = MRBLR_INIT_SETTINGS;
496
497 regs->minflr = MINFLR_INIT_SETTINGS;
498
499 regs->attr = ATTR_INIT_SETTINGS;
500 regs->attreli = ATTRELI_INIT_SETTINGS;
501
wdenka445ddf2004-06-09 00:34:46 +0000502}
503
504
505/* Configure maccfg2 based on negotiated speed and duplex
506 * reported by PHY handling code */
507static void adjust_link(struct eth_device *dev)
508{
509 struct tsec_private *priv = (struct tsec_private *)dev->priv;
510 volatile tsec_t *regs = priv->regs;
511
512 if(priv->link) {
513 if(priv->duplexity != 0)
514 regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
515 else
516 regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
517
518 switch(priv->speed) {
519 case 1000:
520 regs->maccfg2 = ((regs->maccfg2&~(MACCFG2_IF))
521 | MACCFG2_GMII);
522 break;
523 case 100:
524 case 10:
525 regs->maccfg2 = ((regs->maccfg2&~(MACCFG2_IF))
526 | MACCFG2_MII);
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500527
528 /* If We're in reduced mode, we
529 * need to say whether we're 10
530 * or 100 MB. */
531 if ((priv->speed == 100)
532 && (priv->flags & TSEC_REDUCED))
533 regs->ecntrl |= ECNTRL_R100;
534 else
535 regs->ecntrl &= ~(ECNTRL_R100);
wdenka445ddf2004-06-09 00:34:46 +0000536 break;
537 default:
538 printf("%s: Speed was bad\n", dev->name);
539 break;
540 }
541
542 printf("Speed: %d, %s duplex\n", priv->speed,
543 (priv->duplexity) ? "full" : "half");
544
545 } else {
546 printf("%s: No link.\n", dev->name);
547 }
wdenk9c53f402003-10-15 23:53:47 +0000548}
549
wdenka445ddf2004-06-09 00:34:46 +0000550
551/* Set up the buffers and their descriptors, and bring up the
552 * interface */
553static void startup_tsec(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000554{
555 int i;
wdenka445ddf2004-06-09 00:34:46 +0000556 struct tsec_private *priv = (struct tsec_private *)dev->priv;
557 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000558
559 /* Point to the buffer descriptors */
560 regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
561 regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
562
563 /* Initialize the Rx Buffer descriptors */
564 for (i = 0; i < PKTBUFSRX; i++) {
565 rtx.rxbd[i].status = RXBD_EMPTY;
566 rtx.rxbd[i].length = 0;
567 rtx.rxbd[i].bufPtr = (uint)NetRxPackets[i];
568 }
569 rtx.rxbd[PKTBUFSRX -1].status |= RXBD_WRAP;
570
571 /* Initialize the TX Buffer Descriptors */
572 for(i=0; i<TX_BUF_CNT; i++) {
573 rtx.txbd[i].status = 0;
574 rtx.txbd[i].length = 0;
575 rtx.txbd[i].bufPtr = 0;
576 }
577 rtx.txbd[TX_BUF_CNT -1].status |= TXBD_WRAP;
578
wdenka445ddf2004-06-09 00:34:46 +0000579 /* Start up the PHY */
580 phy_run_commands(priv, priv->phyinfo->startup);
581 adjust_link(dev);
582
wdenk9c53f402003-10-15 23:53:47 +0000583 /* Enable Transmit and Receive */
584 regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
585
586 /* Tell the DMA it is clear to go */
587 regs->dmactrl |= DMACTRL_INIT_SETTINGS;
588 regs->tstat = TSTAT_CLEAR_THALT;
589 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
590}
591
wdenkbfad55d2005-03-14 23:56:42 +0000592/* This returns the status bits of the device. The return value
wdenk9c53f402003-10-15 23:53:47 +0000593 * is never checked, and this is what the 8260 driver did, so we
wdenkbfad55d2005-03-14 23:56:42 +0000594 * do the same. Presumably, this would be zero if there were no
wdenk9c53f402003-10-15 23:53:47 +0000595 * errors */
596static int tsec_send(struct eth_device* dev, volatile void *packet, int length)
597{
598 int i;
599 int result = 0;
wdenka445ddf2004-06-09 00:34:46 +0000600 struct tsec_private *priv = (struct tsec_private *)dev->priv;
601 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000602
603 /* Find an empty buffer descriptor */
604 for(i=0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
605 if (i >= TOUT_LOOP) {
wdenk3203c8f2004-07-10 21:45:47 +0000606 debug ("%s: tsec: tx buffers full\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +0000607 return result;
608 }
609 }
610
611 rtx.txbd[txIdx].bufPtr = (uint)packet;
612 rtx.txbd[txIdx].length = length;
613 rtx.txbd[txIdx].status |= (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
614
615 /* Tell the DMA to go */
616 regs->tstat = TSTAT_CLEAR_THALT;
617
618 /* Wait for buffer to be transmitted */
619 for(i=0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
620 if (i >= TOUT_LOOP) {
wdenk3203c8f2004-07-10 21:45:47 +0000621 debug ("%s: tsec: tx error\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +0000622 return result;
623 }
624 }
625
626 txIdx = (txIdx + 1) % TX_BUF_CNT;
627 result = rtx.txbd[txIdx].status & TXBD_STATS;
628
629 return result;
630}
631
632static int tsec_recv(struct eth_device* dev)
633{
634 int length;
wdenka445ddf2004-06-09 00:34:46 +0000635 struct tsec_private *priv = (struct tsec_private *)dev->priv;
636 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000637
638 while(!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
639
640 length = rtx.rxbd[rxIdx].length;
641
642 /* Send the packet up if there were no errors */
643 if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
644 NetReceive(NetRxPackets[rxIdx], length - 4);
wdenka445ddf2004-06-09 00:34:46 +0000645 } else {
646 printf("Got error %x\n",
647 (rtx.rxbd[rxIdx].status & RXBD_STATS));
wdenk9c53f402003-10-15 23:53:47 +0000648 }
649
650 rtx.rxbd[rxIdx].length = 0;
651
652 /* Set the wrap bit if this is the last element in the list */
653 rtx.rxbd[rxIdx].status = RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
654
655 rxIdx = (rxIdx + 1) % PKTBUFSRX;
656 }
657
658 if(regs->ievent&IEVENT_BSY) {
659 regs->ievent = IEVENT_BSY;
660 regs->rstat = RSTAT_CLEAR_RHALT;
661 }
662
663 return -1;
664
665}
666
667
wdenka445ddf2004-06-09 00:34:46 +0000668/* Stop the interface */
wdenk9c53f402003-10-15 23:53:47 +0000669static void tsec_halt(struct eth_device* dev)
670{
wdenka445ddf2004-06-09 00:34:46 +0000671 struct tsec_private *priv = (struct tsec_private *)dev->priv;
672 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000673
674 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
675 regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
676
677 while(!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC)));
678
679 regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
680
wdenka445ddf2004-06-09 00:34:46 +0000681 /* Shut down the PHY, as needed */
682 phy_run_commands(priv, priv->phyinfo->shutdown);
683}
684
685
686struct phy_info phy_info_M88E1011S = {
687 0x01410c6,
688 "Marvell 88E1011S",
689 4,
690 (struct phy_cmd[]) { /* config */
691 /* Reset and configure the PHY */
692 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
693 {0x1d, 0x1f, NULL},
694 {0x1e, 0x200c, NULL},
695 {0x1d, 0x5, NULL},
696 {0x1e, 0x0, NULL},
697 {0x1e, 0x100, NULL},
698 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
699 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
700 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
701 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
702 {miim_end,}
703 },
704 (struct phy_cmd[]) { /* startup */
705 /* Status is read once to clear old link state */
706 {MIIM_STATUS, miim_read, NULL},
707 /* Auto-negotiate */
708 {MIIM_STATUS, miim_read, &mii_parse_sr},
709 /* Read the status */
710 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
711 {miim_end,}
712 },
713 (struct phy_cmd[]) { /* shutdown */
714 {miim_end,}
715 },
716};
717
wdenkbfad55d2005-03-14 23:56:42 +0000718struct phy_info phy_info_M88E1111S = {
719 0x01410cc,
720 "Marvell 88E1111S",
721 4,
722 (struct phy_cmd[]) { /* config */
723 /* Reset and configure the PHY */
724 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
725 {0x1d, 0x1f, NULL},
726 {0x1e, 0x200c, NULL},
727 {0x1d, 0x5, NULL},
728 {0x1e, 0x0, NULL},
729 {0x1e, 0x100, NULL},
730 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
731 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
732 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
733 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
734 {miim_end,}
735 },
736 (struct phy_cmd[]) { /* startup */
737 /* Status is read once to clear old link state */
738 {MIIM_STATUS, miim_read, NULL},
739 /* Auto-negotiate */
740 {MIIM_STATUS, miim_read, &mii_parse_sr},
741 /* Read the status */
742 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
743 {miim_end,}
744 },
745 (struct phy_cmd[]) { /* shutdown */
746 {miim_end,}
747 },
748};
749
wdenka445ddf2004-06-09 00:34:46 +0000750struct phy_info phy_info_cis8204 = {
751 0x3f11,
752 "Cicada Cis8204",
753 6,
754 (struct phy_cmd[]) { /* config */
755 /* Override PHY config settings */
756 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
757 /* Configure some basic stuff */
758 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
759 {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT, &mii_cis8204_fixled},
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500760 {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT, &mii_cis8204_setmode},
wdenka445ddf2004-06-09 00:34:46 +0000761 {miim_end,}
762 },
763 (struct phy_cmd[]) { /* startup */
764 /* Read the Status (2x to make sure link is right) */
765 {MIIM_STATUS, miim_read, NULL},
766 /* Auto-negotiate */
767 {MIIM_STATUS, miim_read, &mii_parse_sr},
768 /* Read the status */
769 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
770 {miim_end,}
771 },
772 (struct phy_cmd[]) { /* shutdown */
773 {miim_end,}
774 },
775};
776
777/* Cicada 8201 */
778struct phy_info phy_info_cis8201 = {
779 0xfc41,
780 "CIS8201",
781 4,
782 (struct phy_cmd[]) { /* config */
783 /* Override PHY config settings */
784 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
785 /* Set up the interface mode */
786 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, NULL},
787 /* Configure some basic stuff */
788 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
789 {miim_end,}
790 },
791 (struct phy_cmd[]) { /* startup */
792 /* Read the Status (2x to make sure link is right) */
793 {MIIM_STATUS, miim_read, NULL},
794 /* Auto-negotiate */
795 {MIIM_STATUS, miim_read, &mii_parse_sr},
796 /* Read the status */
797 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
798 {miim_end,}
799 },
800 (struct phy_cmd[]) { /* shutdown */
801 {miim_end,}
802 },
803};
804
805
806struct phy_info phy_info_dm9161 = {
807 0x0181b88,
808 "Davicom DM9161E",
809 4,
810 (struct phy_cmd[]) { /* config */
811 {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
812 /* Do not bypass the scrambler/descrambler */
813 {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
814 /* Clear 10BTCSR to default */
815 {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT, NULL},
816 /* Configure some basic stuff */
817 {MIIM_CONTROL, MIIM_CR_INIT, NULL},
818 /* Restart Auto Negotiation */
819 {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
820 {miim_end,}
821 },
822 (struct phy_cmd[]) { /* startup */
823 /* Status is read once to clear old link state */
824 {MIIM_STATUS, miim_read, NULL},
825 /* Auto-negotiate */
826 {MIIM_STATUS, miim_read, &mii_parse_sr},
827 /* Read the status */
828 {MIIM_DM9161_SCSR, miim_read, &mii_parse_dm9161_scsr},
829 {miim_end,}
830 },
831 (struct phy_cmd[]) { /* shutdown */
832 {miim_end,}
833 },
834};
835
wdenkf41ff3b2005-04-04 23:43:44 +0000836uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
837{
wdenke085e5b2005-04-05 23:32:21 +0000838 unsigned int speed;
839 if (priv->link) {
840 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
wdenkf41ff3b2005-04-04 23:43:44 +0000841
wdenke085e5b2005-04-05 23:32:21 +0000842 switch (speed) {
843 case MIIM_LXT971_SR2_10HDX:
844 priv->speed = 10;
845 priv->duplexity = 0;
846 break;
847 case MIIM_LXT971_SR2_10FDX:
848 priv->speed = 10;
849 priv->duplexity = 1;
850 break;
851 case MIIM_LXT971_SR2_100HDX:
852 priv->speed = 100;
853 priv->duplexity = 0;
854 default:
855 priv->speed = 100;
856 priv->duplexity = 1;
857 break;
858 }
859 } else {
860 priv->speed = 0;
861 priv->duplexity = 0;
862 }
wdenkf41ff3b2005-04-04 23:43:44 +0000863
wdenke085e5b2005-04-05 23:32:21 +0000864 return 0;
wdenkf41ff3b2005-04-04 23:43:44 +0000865}
866
wdenkbfad55d2005-03-14 23:56:42 +0000867static struct phy_info phy_info_lxt971 = {
868 0x0001378e,
869 "LXT971",
870 4,
871 (struct phy_cmd []) { /* config */
wdenkf41ff3b2005-04-04 23:43:44 +0000872 { MIIM_CR, MIIM_CR_INIT, mii_cr_init }, /* autonegotiate */
wdenkbfad55d2005-03-14 23:56:42 +0000873 { miim_end, }
874 },
875 (struct phy_cmd []) { /* startup - enable interrupts */
876 /* { 0x12, 0x00f2, NULL }, */
wdenkbfad55d2005-03-14 23:56:42 +0000877 { MIIM_STATUS, miim_read, NULL },
wdenkf41ff3b2005-04-04 23:43:44 +0000878 { MIIM_STATUS, miim_read, &mii_parse_sr },
879 { MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2 },
wdenkbfad55d2005-03-14 23:56:42 +0000880 { miim_end, }
881 },
882 (struct phy_cmd []) { /* shutdown - disable interrupts */
883 { miim_end, }
884 },
885};
886
wdenka445ddf2004-06-09 00:34:46 +0000887struct phy_info *phy_info[] = {
888#if 0
889 &phy_info_cis8201,
890#endif
891 &phy_info_cis8204,
892 &phy_info_M88E1011S,
wdenkbfad55d2005-03-14 23:56:42 +0000893 &phy_info_M88E1111S,
wdenka445ddf2004-06-09 00:34:46 +0000894 &phy_info_dm9161,
wdenkbfad55d2005-03-14 23:56:42 +0000895 &phy_info_lxt971,
wdenka445ddf2004-06-09 00:34:46 +0000896 NULL
897};
898
899
900/* Grab the identifier of the device's PHY, and search through
wdenkbfad55d2005-03-14 23:56:42 +0000901 * all of the known PHYs to see if one matches. If so, return
wdenka445ddf2004-06-09 00:34:46 +0000902 * it, if not, return NULL */
903struct phy_info * get_phy_info(struct eth_device *dev)
904{
905 struct tsec_private *priv = (struct tsec_private *)dev->priv;
906 uint phy_reg, phy_ID;
907 int i;
908 struct phy_info *theInfo = NULL;
909
910 /* Grab the bits from PHYIR1, and put them in the upper half */
911 phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
912 phy_ID = (phy_reg & 0xffff) << 16;
913
914 /* Grab the bits from PHYIR2, and put them in the lower half */
915 phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
916 phy_ID |= (phy_reg & 0xffff);
917
918 /* loop through all the known PHY types, and find one that */
919 /* matches the ID we read from the PHY. */
920 for(i=0; phy_info[i]; i++) {
921 if(phy_info[i]->id == (phy_ID >> phy_info[i]->shift))
922 theInfo = phy_info[i];
923 }
924
925 if(theInfo == NULL)
926 {
927 printf("%s: PHY id %x is not supported!\n", dev->name, phy_ID);
928 return NULL;
929 } else {
930 printf("%s: PHY is %s (%x)\n", dev->name, theInfo->name,
931 phy_ID);
932 }
933
934 return theInfo;
935}
936
937
938/* Execute the given series of commands on the given device's
939 * PHY, running functions as necessary*/
940void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
941{
942 int i;
943 uint result;
944 volatile tsec_t *phyregs = priv->phyregs;
945
946 phyregs->miimcfg = MIIMCFG_RESET;
947
948 phyregs->miimcfg = MIIMCFG_INIT_VALUE;
949
950 while(phyregs->miimind & MIIMIND_BUSY);
951
952 for(i=0;cmd->mii_reg != miim_end;i++) {
953 if(cmd->mii_data == miim_read) {
954 result = read_phy_reg(priv, cmd->mii_reg);
955
956 if(cmd->funct != NULL)
957 (*(cmd->funct))(result, priv);
958
959 } else {
960 if(cmd->funct != NULL)
961 result = (*(cmd->funct))(cmd->mii_reg, priv);
962 else
963 result = cmd->mii_data;
964
965 write_phy_reg(priv, cmd->mii_reg, result);
966
967 }
968 cmd++;
969 }
970}
971
972
973/* Relocate the function pointers in the phy cmd lists */
974static void relocate_cmds(void)
975{
976 struct phy_cmd **cmdlistptr;
977 struct phy_cmd *cmd;
978 int i,j,k;
979 DECLARE_GLOBAL_DATA_PTR;
980
981 for(i=0; phy_info[i]; i++) {
982 /* First thing's first: relocate the pointers to the
983 * PHY command structures (the structs were done) */
984 phy_info[i] = (struct phy_info *) ((uint)phy_info[i]
985 + gd->reloc_off);
986 phy_info[i]->name += gd->reloc_off;
987 phy_info[i]->config =
988 (struct phy_cmd *)((uint)phy_info[i]->config
989 + gd->reloc_off);
990 phy_info[i]->startup =
991 (struct phy_cmd *)((uint)phy_info[i]->startup
992 + gd->reloc_off);
993 phy_info[i]->shutdown =
994 (struct phy_cmd *)((uint)phy_info[i]->shutdown
995 + gd->reloc_off);
996
997 cmdlistptr = &phy_info[i]->config;
998 j=0;
999 for(;cmdlistptr <= &phy_info[i]->shutdown;cmdlistptr++) {
1000 k=0;
1001 for(cmd=*cmdlistptr;cmd->mii_reg != miim_end;cmd++) {
1002 /* Only relocate non-NULL pointers */
1003 if(cmd->funct)
1004 cmd->funct += gd->reloc_off;
1005
1006 k++;
1007 }
1008 j++;
1009 }
1010 }
1011
1012 relocated = 1;
wdenk78924a72004-04-18 21:45:42 +00001013}
1014
wdenka445ddf2004-06-09 00:34:46 +00001015
wdenk78924a72004-04-18 21:45:42 +00001016#ifndef CONFIG_BITBANGMII
wdenka445ddf2004-06-09 00:34:46 +00001017
1018struct tsec_private * get_priv_for_phy(unsigned char phyaddr)
1019{
1020 int i;
1021
1022 for(i=0;i<MAXCONTROLLERS;i++) {
1023 if(privlist[i]->phyaddr == phyaddr)
1024 return privlist[i];
1025 }
1026
1027 return NULL;
1028}
1029
wdenk78924a72004-04-18 21:45:42 +00001030/*
1031 * Read a MII PHY register.
1032 *
1033 * Returns:
wdenka445ddf2004-06-09 00:34:46 +00001034 * 0 on success
wdenk78924a72004-04-18 21:45:42 +00001035 */
wdenka445ddf2004-06-09 00:34:46 +00001036int miiphy_read(unsigned char addr, unsigned char reg, unsigned short *value)
wdenk78924a72004-04-18 21:45:42 +00001037{
wdenka445ddf2004-06-09 00:34:46 +00001038 unsigned short ret;
1039 struct tsec_private *priv = get_priv_for_phy(addr);
wdenk78924a72004-04-18 21:45:42 +00001040
wdenka445ddf2004-06-09 00:34:46 +00001041 if(NULL == priv) {
1042 printf("Can't read PHY at address %d\n", addr);
1043 return -1;
1044 }
1045
1046 ret = (unsigned short)read_phy_reg(priv, reg);
1047 *value = ret;
wdenk78924a72004-04-18 21:45:42 +00001048
1049 return 0;
1050}
1051
1052/*
1053 * Write a MII PHY register.
1054 *
1055 * Returns:
wdenka445ddf2004-06-09 00:34:46 +00001056 * 0 on success
wdenk78924a72004-04-18 21:45:42 +00001057 */
wdenka445ddf2004-06-09 00:34:46 +00001058int miiphy_write(unsigned char addr, unsigned char reg, unsigned short value)
wdenk78924a72004-04-18 21:45:42 +00001059{
wdenka445ddf2004-06-09 00:34:46 +00001060 struct tsec_private *priv = get_priv_for_phy(addr);
1061
1062 if(NULL == priv) {
1063 printf("Can't write PHY at address %d\n", addr);
1064 return -1;
1065 }
wdenk78924a72004-04-18 21:45:42 +00001066
wdenka445ddf2004-06-09 00:34:46 +00001067 write_phy_reg(priv, reg, value);
wdenk78924a72004-04-18 21:45:42 +00001068
1069 return 0;
wdenk9c53f402003-10-15 23:53:47 +00001070}
wdenka445ddf2004-06-09 00:34:46 +00001071
wdenk78924a72004-04-18 21:45:42 +00001072#endif /* CONFIG_BITBANGMII */
wdenka445ddf2004-06-09 00:34:46 +00001073
wdenk9c53f402003-10-15 23:53:47 +00001074#endif /* CONFIG_TSEC_ENET */