6fda6d88be499d1ce0e79ccc98eb0818f8f713dd
[sfrench/cifs-2.6.git] / drivers / net / ucc_geth_phy.c
1 /*
2  * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved.
3  *
4  * Author: Shlomi Gridish <gridish@freescale.com>
5  *
6  * Description:
7  * UCC GETH Driver -- PHY handling
8  *
9  * Changelog:
10  * Jun 28, 2006 Li Yang <LeoLi@freescale.com>
11  * - Rearrange code and style fixes
12  *
13  * This program is free software; you can redistribute  it and/or modify it
14  * under  the terms of  the GNU General  Public License as published by the
15  * Free Software Foundation;  either version 2 of the  License, or (at your
16  * option) any later version.
17  *
18  */
19
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
22 #include <linux/string.h>
23 #include <linux/errno.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/netdevice.h>
29 #include <linux/etherdevice.h>
30 #include <linux/skbuff.h>
31 #include <linux/spinlock.h>
32 #include <linux/mm.h>
33 #include <linux/module.h>
34 #include <linux/version.h>
35 #include <linux/crc32.h>
36 #include <linux/mii.h>
37 #include <linux/ethtool.h>
38
39 #include <asm/io.h>
40 #include <asm/irq.h>
41 #include <asm/uaccess.h>
42
43 #include "ucc_geth.h"
44 #include "ucc_geth_phy.h"
45
46 #define ugphy_printk(level, format, arg...)  \
47         printk(level format "\n", ## arg)
48
49 #define ugphy_dbg(format, arg...)            \
50         ugphy_printk(KERN_DEBUG, format , ## arg)
51 #define ugphy_err(format, arg...)            \
52         ugphy_printk(KERN_ERR, format , ## arg)
53 #define ugphy_info(format, arg...)           \
54         ugphy_printk(KERN_INFO, format , ## arg)
55 #define ugphy_warn(format, arg...)           \
56         ugphy_printk(KERN_WARNING, format , ## arg)
57
58 #ifdef UGETH_VERBOSE_DEBUG
59 #define ugphy_vdbg ugphy_dbg
60 #else
61 #define ugphy_vdbg(fmt, args...) do { } while (0)
62 #endif                          /* UGETH_VERBOSE_DEBUG */
63
64 static void config_genmii_advert(struct ugeth_mii_info *mii_info);
65 static void genmii_setup_forced(struct ugeth_mii_info *mii_info);
66 static void genmii_restart_aneg(struct ugeth_mii_info *mii_info);
67 static int gbit_config_aneg(struct ugeth_mii_info *mii_info);
68 static int genmii_config_aneg(struct ugeth_mii_info *mii_info);
69 static int genmii_update_link(struct ugeth_mii_info *mii_info);
70 static int genmii_read_status(struct ugeth_mii_info *mii_info);
71
72 static u16 ucc_geth_phy_read(struct ugeth_mii_info *mii_info, u16 regnum)
73 {
74         u16 retval;
75         unsigned long flags;
76
77         ugphy_vdbg("%s: IN", __FUNCTION__);
78
79         spin_lock_irqsave(&mii_info->mdio_lock, flags);
80         retval = mii_info->mdio_read(mii_info->dev, mii_info->mii_id, regnum);
81         spin_unlock_irqrestore(&mii_info->mdio_lock, flags);
82
83         return retval;
84 }
85
86 static void ucc_geth_phy_write(struct ugeth_mii_info *mii_info, u16 regnum, u16 val)
87 {
88         unsigned long flags;
89
90         ugphy_vdbg("%s: IN", __FUNCTION__);
91
92         spin_lock_irqsave(&mii_info->mdio_lock, flags);
93         mii_info->mdio_write(mii_info->dev, mii_info->mii_id, regnum, val);
94         spin_unlock_irqrestore(&mii_info->mdio_lock, flags);
95 }
96
97 /* Write value to the PHY for this device to the register at regnum, */
98 /* waiting until the write is done before it returns.  All PHY */
99 /* configuration has to be done through the TSEC1 MIIM regs */
100 void write_phy_reg(struct net_device *dev, int mii_id, int regnum, int value)
101 {
102         struct ucc_geth_private *ugeth = netdev_priv(dev);
103         struct ucc_mii_mng *mii_regs;
104         enum enet_tbi_mii_reg mii_reg = (enum enet_tbi_mii_reg) regnum;
105         u32 tmp_reg;
106
107         ugphy_vdbg("%s: IN", __FUNCTION__);
108
109         spin_lock_irq(&ugeth->lock);
110
111         mii_regs = ugeth->mii_info->mii_regs;
112
113         /* Set this UCC to be the master of the MII managment */
114         ucc_set_qe_mux_mii_mng(ugeth->ug_info->uf_info.ucc_num);
115
116         /* Stop the MII management read cycle */
117         out_be32(&mii_regs->miimcom, 0);
118         /* Setting up the MII Mangement Address Register */
119         tmp_reg = ((u32) mii_id << MIIMADD_PHY_ADDRESS_SHIFT) | mii_reg;
120         out_be32(&mii_regs->miimadd, tmp_reg);
121
122         /* Setting up the MII Mangement Control Register with the value */
123         out_be32(&mii_regs->miimcon, (u32) value);
124
125         /* Wait till MII management write is complete */
126         while ((in_be32(&mii_regs->miimind)) & MIIMIND_BUSY)
127                 cpu_relax();
128
129         spin_unlock_irq(&ugeth->lock);
130
131         udelay(10000);
132 }
133
134 /* Reads from register regnum in the PHY for device dev, */
135 /* returning the value.  Clears miimcom first.  All PHY */
136 /* configuration has to be done through the TSEC1 MIIM regs */
137 int read_phy_reg(struct net_device *dev, int mii_id, int regnum)
138 {
139         struct ucc_geth_private *ugeth = netdev_priv(dev);
140         struct ucc_mii_mng *mii_regs;
141         enum enet_tbi_mii_reg mii_reg = (enum enet_tbi_mii_reg) regnum;
142         u32 tmp_reg;
143         u16 value;
144
145         ugphy_vdbg("%s: IN", __FUNCTION__);
146
147         spin_lock_irq(&ugeth->lock);
148
149         mii_regs = ugeth->mii_info->mii_regs;
150
151         /* Setting up the MII Mangement Address Register */
152         tmp_reg = ((u32) mii_id << MIIMADD_PHY_ADDRESS_SHIFT) | mii_reg;
153         out_be32(&mii_regs->miimadd, tmp_reg);
154
155         /* Perform an MII management read cycle */
156         out_be32(&mii_regs->miimcom, MIIMCOM_READ_CYCLE);
157
158         /* Wait till MII management write is complete */
159         while ((in_be32(&mii_regs->miimind)) & MIIMIND_BUSY)
160                 cpu_relax();
161
162         udelay(10000);
163
164         /* Read MII management status  */
165         value = (u16) in_be32(&mii_regs->miimstat);
166         out_be32(&mii_regs->miimcom, 0);
167         if (value == 0xffff)
168                 ugphy_warn("read wrong value : mii_id %d,mii_reg %d, base %08x",
169                            mii_id, mii_reg, (u32) & (mii_regs->miimcfg));
170
171         spin_unlock_irq(&ugeth->lock);
172
173         return (value);
174 }
175
176 void mii_clear_phy_interrupt(struct ugeth_mii_info *mii_info)
177 {
178         ugphy_vdbg("%s: IN", __FUNCTION__);
179
180         if (mii_info->phyinfo->ack_interrupt)
181                 mii_info->phyinfo->ack_interrupt(mii_info);
182 }
183
184 void mii_configure_phy_interrupt(struct ugeth_mii_info *mii_info,
185                                  u32 interrupts)
186 {
187         ugphy_vdbg("%s: IN", __FUNCTION__);
188
189         mii_info->interrupts = interrupts;
190         if (mii_info->phyinfo->config_intr)
191                 mii_info->phyinfo->config_intr(mii_info);
192 }
193
194 /* Writes MII_ADVERTISE with the appropriate values, after
195  * sanitizing advertise to make sure only supported features
196  * are advertised
197  */
198 static void config_genmii_advert(struct ugeth_mii_info *mii_info)
199 {
200         u32 advertise;
201         u16 adv;
202
203         ugphy_vdbg("%s: IN", __FUNCTION__);
204
205         /* Only allow advertising what this PHY supports */
206         mii_info->advertising &= mii_info->phyinfo->features;
207         advertise = mii_info->advertising;
208
209         /* Setup standard advertisement */
210         adv = ucc_geth_phy_read(mii_info, MII_ADVERTISE);
211         adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
212         if (advertise & ADVERTISED_10baseT_Half)
213                 adv |= ADVERTISE_10HALF;
214         if (advertise & ADVERTISED_10baseT_Full)
215                 adv |= ADVERTISE_10FULL;
216         if (advertise & ADVERTISED_100baseT_Half)
217                 adv |= ADVERTISE_100HALF;
218         if (advertise & ADVERTISED_100baseT_Full)
219                 adv |= ADVERTISE_100FULL;
220         ucc_geth_phy_write(mii_info, MII_ADVERTISE, adv);
221 }
222
223 static void genmii_setup_forced(struct ugeth_mii_info *mii_info)
224 {
225         u16 ctrl;
226         u32 features = mii_info->phyinfo->features;
227
228         ugphy_vdbg("%s: IN", __FUNCTION__);
229
230         ctrl = ucc_geth_phy_read(mii_info, MII_BMCR);
231
232         ctrl &=
233             ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_SPEED1000 | BMCR_ANENABLE);
234         ctrl |= BMCR_RESET;
235
236         switch (mii_info->speed) {
237         case SPEED_1000:
238                 if (features & (SUPPORTED_1000baseT_Half
239                                 | SUPPORTED_1000baseT_Full)) {
240                         ctrl |= BMCR_SPEED1000;
241                         break;
242                 }
243                 mii_info->speed = SPEED_100;
244         case SPEED_100:
245                 if (features & (SUPPORTED_100baseT_Half
246                                 | SUPPORTED_100baseT_Full)) {
247                         ctrl |= BMCR_SPEED100;
248                         break;
249                 }
250                 mii_info->speed = SPEED_10;
251         case SPEED_10:
252                 if (features & (SUPPORTED_10baseT_Half
253                                 | SUPPORTED_10baseT_Full))
254                         break;
255         default:                /* Unsupported speed! */
256                 ugphy_err("%s: Bad speed!", mii_info->dev->name);
257                 break;
258         }
259
260         ucc_geth_phy_write(mii_info, MII_BMCR, ctrl);
261 }
262
263 /* Enable and Restart Autonegotiation */
264 static void genmii_restart_aneg(struct ugeth_mii_info *mii_info)
265 {
266         u16 ctl;
267
268         ugphy_vdbg("%s: IN", __FUNCTION__);
269
270         ctl = ucc_geth_phy_read(mii_info, MII_BMCR);
271         ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
272         ucc_geth_phy_write(mii_info, MII_BMCR, ctl);
273 }
274
275 static int gbit_config_aneg(struct ugeth_mii_info *mii_info)
276 {
277         u16 adv;
278         u32 advertise;
279
280         ugphy_vdbg("%s: IN", __FUNCTION__);
281
282         if (mii_info->autoneg) {
283                 /* Configure the ADVERTISE register */
284                 config_genmii_advert(mii_info);
285                 advertise = mii_info->advertising;
286
287                 adv = ucc_geth_phy_read(mii_info, MII_1000BASETCONTROL);
288                 adv &= ~(MII_1000BASETCONTROL_FULLDUPLEXCAP |
289                          MII_1000BASETCONTROL_HALFDUPLEXCAP);
290                 if (advertise & SUPPORTED_1000baseT_Half)
291                         adv |= MII_1000BASETCONTROL_HALFDUPLEXCAP;
292                 if (advertise & SUPPORTED_1000baseT_Full)
293                         adv |= MII_1000BASETCONTROL_FULLDUPLEXCAP;
294                 ucc_geth_phy_write(mii_info, MII_1000BASETCONTROL, adv);
295
296                 /* Start/Restart aneg */
297                 genmii_restart_aneg(mii_info);
298         } else
299                 genmii_setup_forced(mii_info);
300
301         return 0;
302 }
303
304 static int genmii_config_aneg(struct ugeth_mii_info *mii_info)
305 {
306         ugphy_vdbg("%s: IN", __FUNCTION__);
307
308         if (mii_info->autoneg) {
309                 config_genmii_advert(mii_info);
310                 genmii_restart_aneg(mii_info);
311         } else
312                 genmii_setup_forced(mii_info);
313
314         return 0;
315 }
316
317 static int genmii_update_link(struct ugeth_mii_info *mii_info)
318 {
319         u16 status;
320
321         ugphy_vdbg("%s: IN", __FUNCTION__);
322
323         /* Do a fake read */
324         ucc_geth_phy_read(mii_info, MII_BMSR);
325
326         /* Read link and autonegotiation status */
327         status = ucc_geth_phy_read(mii_info, MII_BMSR);
328         if ((status & BMSR_LSTATUS) == 0)
329                 mii_info->link = 0;
330         else
331                 mii_info->link = 1;
332
333         /* If we are autonegotiating, and not done,
334          * return an error */
335         if (mii_info->autoneg && !(status & BMSR_ANEGCOMPLETE))
336                 return -EAGAIN;
337
338         return 0;
339 }
340
341 static int genmii_read_status(struct ugeth_mii_info *mii_info)
342 {
343         u16 status;
344         int err;
345
346         ugphy_vdbg("%s: IN", __FUNCTION__);
347
348         /* Update the link, but return if there
349          * was an error */
350         err = genmii_update_link(mii_info);
351         if (err)
352                 return err;
353
354         if (mii_info->autoneg) {
355                 status = ucc_geth_phy_read(mii_info, MII_LPA);
356
357                 if (status & (LPA_10FULL | LPA_100FULL))
358                         mii_info->duplex = DUPLEX_FULL;
359                 else
360                         mii_info->duplex = DUPLEX_HALF;
361                 if (status & (LPA_100FULL | LPA_100HALF))
362                         mii_info->speed = SPEED_100;
363                 else
364                         mii_info->speed = SPEED_10;
365                 mii_info->pause = 0;
366         }
367         /* On non-aneg, we assume what we put in BMCR is the speed,
368          * though magic-aneg shouldn't prevent this case from occurring
369          */
370
371         return 0;
372 }
373
374 static int marvell_init(struct ugeth_mii_info *mii_info)
375 {
376         ugphy_vdbg("%s: IN", __FUNCTION__);
377
378         ucc_geth_phy_write(mii_info, 0x14, 0x0cd2);
379         ucc_geth_phy_write(mii_info, 0x1b,
380                 (ucc_geth_phy_read(mii_info, 0x1b) & ~0x000f) | 0x000b);
381         ucc_geth_phy_write(mii_info, MII_BMCR,
382                   ucc_geth_phy_read(mii_info, MII_BMCR) | BMCR_RESET);
383         msleep(4000);
384
385         return 0;
386 }
387
388 static int marvell_config_aneg(struct ugeth_mii_info *mii_info)
389 {
390         ugphy_vdbg("%s: IN", __FUNCTION__);
391
392         /* The Marvell PHY has an errata which requires
393          * that certain registers get written in order
394          * to restart autonegotiation */
395         ucc_geth_phy_write(mii_info, MII_BMCR, BMCR_RESET);
396
397         ucc_geth_phy_write(mii_info, 0x1d, 0x1f);
398         ucc_geth_phy_write(mii_info, 0x1e, 0x200c);
399         ucc_geth_phy_write(mii_info, 0x1d, 0x5);
400         ucc_geth_phy_write(mii_info, 0x1e, 0);
401         ucc_geth_phy_write(mii_info, 0x1e, 0x100);
402
403         gbit_config_aneg(mii_info);
404
405         return 0;
406 }
407
408 static int marvell_read_status(struct ugeth_mii_info *mii_info)
409 {
410         u16 status;
411         int err;
412
413         ugphy_vdbg("%s: IN", __FUNCTION__);
414
415         /* Update the link, but return if there
416          * was an error */
417         err = genmii_update_link(mii_info);
418         if (err)
419                 return err;
420
421         /* If the link is up, read the speed and duplex */
422         /* If we aren't autonegotiating, assume speeds
423          * are as set */
424         if (mii_info->autoneg && mii_info->link) {
425                 int speed;
426                 status = ucc_geth_phy_read(mii_info, MII_M1011_PHY_SPEC_STATUS);
427
428                 /* Get the duplexity */
429                 if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX)
430                         mii_info->duplex = DUPLEX_FULL;
431                 else
432                         mii_info->duplex = DUPLEX_HALF;
433
434                 /* Get the speed */
435                 speed = status & MII_M1011_PHY_SPEC_STATUS_SPD_MASK;
436                 switch (speed) {
437                 case MII_M1011_PHY_SPEC_STATUS_1000:
438                         mii_info->speed = SPEED_1000;
439                         break;
440                 case MII_M1011_PHY_SPEC_STATUS_100:
441                         mii_info->speed = SPEED_100;
442                         break;
443                 default:
444                         mii_info->speed = SPEED_10;
445                         break;
446                 }
447                 mii_info->pause = 0;
448         }
449
450         return 0;
451 }
452
453 static int marvell_ack_interrupt(struct ugeth_mii_info *mii_info)
454 {
455         ugphy_vdbg("%s: IN", __FUNCTION__);
456
457         /* Clear the interrupts by reading the reg */
458         ucc_geth_phy_read(mii_info, MII_M1011_IEVENT);
459
460         return 0;
461 }
462
463 static int marvell_config_intr(struct ugeth_mii_info *mii_info)
464 {
465         ugphy_vdbg("%s: IN", __FUNCTION__);
466
467         if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
468                 ucc_geth_phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_INIT);
469         else
470                 ucc_geth_phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR);
471
472         return 0;
473 }
474
475 static int cis820x_init(struct ugeth_mii_info *mii_info)
476 {
477         ugphy_vdbg("%s: IN", __FUNCTION__);
478
479         ucc_geth_phy_write(mii_info, MII_CIS8201_AUX_CONSTAT,
480                   MII_CIS8201_AUXCONSTAT_INIT);
481         ucc_geth_phy_write(mii_info, MII_CIS8201_EXT_CON1, MII_CIS8201_EXTCON1_INIT);
482
483         return 0;
484 }
485
486 static int cis820x_read_status(struct ugeth_mii_info *mii_info)
487 {
488         u16 status;
489         int err;
490
491         ugphy_vdbg("%s: IN", __FUNCTION__);
492
493         /* Update the link, but return if there
494          * was an error */
495         err = genmii_update_link(mii_info);
496         if (err)
497                 return err;
498
499         /* If the link is up, read the speed and duplex */
500         /* If we aren't autonegotiating, assume speeds
501          * are as set */
502         if (mii_info->autoneg && mii_info->link) {
503                 int speed;
504
505                 status = ucc_geth_phy_read(mii_info, MII_CIS8201_AUX_CONSTAT);
506                 if (status & MII_CIS8201_AUXCONSTAT_DUPLEX)
507                         mii_info->duplex = DUPLEX_FULL;
508                 else
509                         mii_info->duplex = DUPLEX_HALF;
510
511                 speed = status & MII_CIS8201_AUXCONSTAT_SPEED;
512
513                 switch (speed) {
514                 case MII_CIS8201_AUXCONSTAT_GBIT:
515                         mii_info->speed = SPEED_1000;
516                         break;
517                 case MII_CIS8201_AUXCONSTAT_100:
518                         mii_info->speed = SPEED_100;
519                         break;
520                 default:
521                         mii_info->speed = SPEED_10;
522                         break;
523                 }
524         }
525
526         return 0;
527 }
528
529 static int cis820x_ack_interrupt(struct ugeth_mii_info *mii_info)
530 {
531         ugphy_vdbg("%s: IN", __FUNCTION__);
532
533         ucc_geth_phy_read(mii_info, MII_CIS8201_ISTAT);
534
535         return 0;
536 }
537
538 static int cis820x_config_intr(struct ugeth_mii_info *mii_info)
539 {
540         ugphy_vdbg("%s: IN", __FUNCTION__);
541
542         if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
543                 ucc_geth_phy_write(mii_info, MII_CIS8201_IMASK, MII_CIS8201_IMASK_MASK);
544         else
545                 ucc_geth_phy_write(mii_info, MII_CIS8201_IMASK, 0);
546
547         return 0;
548 }
549
550 #define DM9161_DELAY 10
551
552 static int dm9161_read_status(struct ugeth_mii_info *mii_info)
553 {
554         u16 status;
555         int err;
556
557         ugphy_vdbg("%s: IN", __FUNCTION__);
558
559         /* Update the link, but return if there
560          * was an error */
561         err = genmii_update_link(mii_info);
562         if (err)
563                 return err;
564
565         /* If the link is up, read the speed and duplex */
566         /* If we aren't autonegotiating, assume speeds
567          * are as set */
568         if (mii_info->autoneg && mii_info->link) {
569                 status = ucc_geth_phy_read(mii_info, MII_DM9161_SCSR);
570                 if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_100H))
571                         mii_info->speed = SPEED_100;
572                 else
573                         mii_info->speed = SPEED_10;
574
575                 if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_10F))
576                         mii_info->duplex = DUPLEX_FULL;
577                 else
578                         mii_info->duplex = DUPLEX_HALF;
579         }
580
581         return 0;
582 }
583
584 static int dm9161_config_aneg(struct ugeth_mii_info *mii_info)
585 {
586         struct dm9161_private *priv = mii_info->priv;
587
588         ugphy_vdbg("%s: IN", __FUNCTION__);
589
590         if (0 == priv->resetdone)
591                 return -EAGAIN;
592
593         return 0;
594 }
595
596 static void dm9161_timer(unsigned long data)
597 {
598         struct ugeth_mii_info *mii_info = (struct ugeth_mii_info *)data;
599         struct dm9161_private *priv = mii_info->priv;
600         u16 status = ucc_geth_phy_read(mii_info, MII_BMSR);
601
602         ugphy_vdbg("%s: IN", __FUNCTION__);
603
604         if (status & BMSR_ANEGCOMPLETE) {
605                 priv->resetdone = 1;
606         } else
607                 mod_timer(&priv->timer, jiffies + DM9161_DELAY * HZ);
608 }
609
610 static int dm9161_init(struct ugeth_mii_info *mii_info)
611 {
612         struct dm9161_private *priv;
613
614         ugphy_vdbg("%s: IN", __FUNCTION__);
615
616         /* Allocate the private data structure */
617         priv = kmalloc(sizeof(struct dm9161_private), GFP_KERNEL);
618
619         if (NULL == priv)
620                 return -ENOMEM;
621
622         mii_info->priv = priv;
623
624         /* Reset is not done yet */
625         priv->resetdone = 0;
626
627         ucc_geth_phy_write(mii_info, MII_BMCR,
628                   ucc_geth_phy_read(mii_info, MII_BMCR) | BMCR_RESET);
629
630         ucc_geth_phy_write(mii_info, MII_BMCR,
631                   ucc_geth_phy_read(mii_info, MII_BMCR) & ~BMCR_ISOLATE);
632
633         config_genmii_advert(mii_info);
634         /* Start/Restart aneg */
635         genmii_config_aneg(mii_info);
636
637         /* Start a timer for DM9161_DELAY seconds to wait
638          * for the PHY to be ready */
639         init_timer(&priv->timer);
640         priv->timer.function = &dm9161_timer;
641         priv->timer.data = (unsigned long)mii_info;
642         mod_timer(&priv->timer, jiffies + DM9161_DELAY * HZ);
643
644         return 0;
645 }
646
647 static void dm9161_close(struct ugeth_mii_info *mii_info)
648 {
649         struct dm9161_private *priv = mii_info->priv;
650
651         ugphy_vdbg("%s: IN", __FUNCTION__);
652
653         del_timer_sync(&priv->timer);
654         kfree(priv);
655 }
656
657 static int dm9161_ack_interrupt(struct ugeth_mii_info *mii_info)
658 {
659         ugphy_vdbg("%s: IN", __FUNCTION__);
660
661         /* Clear the interrupts by reading the reg */
662         ucc_geth_phy_read(mii_info, MII_DM9161_INTR);
663
664
665         return 0;
666 }
667
668 static int dm9161_config_intr(struct ugeth_mii_info *mii_info)
669 {
670         ugphy_vdbg("%s: IN", __FUNCTION__);
671
672         if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
673                 ucc_geth_phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_INIT);
674         else
675                 ucc_geth_phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_STOP);
676
677         return 0;
678 }
679
680 /* Cicada 820x */
681 static struct phy_info phy_info_cis820x = {
682         .phy_id = 0x000fc440,
683         .name = "Cicada Cis8204",
684         .phy_id_mask = 0x000fffc0,
685         .features = MII_GBIT_FEATURES,
686         .init = &cis820x_init,
687         .config_aneg = &gbit_config_aneg,
688         .read_status = &cis820x_read_status,
689         .ack_interrupt = &cis820x_ack_interrupt,
690         .config_intr = &cis820x_config_intr,
691 };
692
693 static struct phy_info phy_info_dm9161 = {
694         .phy_id = 0x0181b880,
695         .phy_id_mask = 0x0ffffff0,
696         .name = "Davicom DM9161E",
697         .init = dm9161_init,
698         .config_aneg = dm9161_config_aneg,
699         .read_status = dm9161_read_status,
700         .close = dm9161_close,
701 };
702
703 static struct phy_info phy_info_dm9161a = {
704         .phy_id = 0x0181b8a0,
705         .phy_id_mask = 0x0ffffff0,
706         .name = "Davicom DM9161A",
707         .features = MII_BASIC_FEATURES,
708         .init = dm9161_init,
709         .config_aneg = dm9161_config_aneg,
710         .read_status = dm9161_read_status,
711         .ack_interrupt = dm9161_ack_interrupt,
712         .config_intr = dm9161_config_intr,
713         .close = dm9161_close,
714 };
715
716 static struct phy_info phy_info_marvell = {
717         .phy_id = 0x01410c00,
718         .phy_id_mask = 0xffffff00,
719         .name = "Marvell 88E11x1",
720         .features = MII_GBIT_FEATURES,
721         .init = &marvell_init,
722         .config_aneg = &marvell_config_aneg,
723         .read_status = &marvell_read_status,
724         .ack_interrupt = &marvell_ack_interrupt,
725         .config_intr = &marvell_config_intr,
726 };
727
728 static struct phy_info phy_info_genmii = {
729         .phy_id = 0x00000000,
730         .phy_id_mask = 0x00000000,
731         .name = "Generic MII",
732         .features = MII_BASIC_FEATURES,
733         .config_aneg = genmii_config_aneg,
734         .read_status = genmii_read_status,
735 };
736
737 static struct phy_info *phy_info[] = {
738         &phy_info_cis820x,
739         &phy_info_marvell,
740         &phy_info_dm9161,
741         &phy_info_dm9161a,
742         &phy_info_genmii,
743         NULL
744 };
745
746 /* Use the PHY ID registers to determine what type of PHY is attached
747  * to device dev.  return a struct phy_info structure describing that PHY
748  */
749 struct phy_info *get_phy_info(struct ugeth_mii_info *mii_info)
750 {
751         u16 phy_reg;
752         u32 phy_ID;
753         int i;
754         struct phy_info *theInfo = NULL;
755         struct net_device *dev = mii_info->dev;
756
757         ugphy_vdbg("%s: IN", __FUNCTION__);
758
759         /* Grab the bits from PHYIR1, and put them in the upper half */
760         phy_reg = ucc_geth_phy_read(mii_info, MII_PHYSID1);
761         phy_ID = (phy_reg & 0xffff) << 16;
762
763         /* Grab the bits from PHYIR2, and put them in the lower half */
764         phy_reg = ucc_geth_phy_read(mii_info, MII_PHYSID2);
765         phy_ID |= (phy_reg & 0xffff);
766
767         /* loop through all the known PHY types, and find one that */
768         /* matches the ID we read from the PHY. */
769         for (i = 0; phy_info[i]; i++)
770                 if (phy_info[i]->phy_id == (phy_ID & phy_info[i]->phy_id_mask)){
771                         theInfo = phy_info[i];
772                         break;
773                 }
774
775         /* This shouldn't happen, as we have generic PHY support */
776         if (theInfo == NULL) {
777                 ugphy_info("%s: PHY id %x is not supported!", dev->name,
778                            phy_ID);
779                 return NULL;
780         } else {
781                 ugphy_info("%s: PHY is %s (%x)", dev->name, theInfo->name,
782                            phy_ID);
783         }
784
785         return theInfo;
786 }