Hi David,

On Wed, Jan 16, 2008 at 10:35:51AM +0200, David Saada wrote:
> 
> Add MII commands to the UEC driver. Note that once a UEC device is
> selected, any device on its MDIO bus can be addressed.

Long ago I did something like that too (quite useful for playing
with MII registers ;-).

Though, I've done it in different way: I modified miiphyutil.c's
miiphy_register() to accept eth_device instead of device name, thus no
need of devlist hack in the UEC driver...

Unfortunately I didn't find time to convert every user of the
miiphy_register() and submit the patch. So.. while you're at it, maybe
something like this would be better approach?

diff --git a/common/miiphyutil.c b/common/miiphyutil.c
index 281f0b2..3750bb6 100644
--- a/common/miiphyutil.c
+++ b/common/miiphyutil.c
@@ -48,10 +48,11 @@
 
 struct mii_dev {
        struct list_head link;
+       struct eth_device *edev;
        char *name;
-       int (*read) (char *devname, unsigned char addr,
+       int (*read) (struct eth_device *edev, unsigned char addr,
                     unsigned char reg, unsigned short *value);
-       int (*write) (char *devname, unsigned char addr,
+       int (*write) (struct eth_device *edev, unsigned char addr,
                      unsigned char reg, unsigned short value);
 };
 
@@ -72,12 +73,13 @@ void miiphy_init ()
  *
  * Register read and write MII access routines for the device <name>.
  */
-void miiphy_register (char *name,
-                     int (*read) (char *devname, unsigned char addr,
+void miiphy_register (struct eth_device *edev,
+                     int (*read) (struct eth_device *edev, unsigned char addr,
                                   unsigned char reg, unsigned short *value),
-                     int (*write) (char *devname, unsigned char addr,
+                     int (*write) (struct eth_device *edev, unsigned char addr,
                                    unsigned char reg, unsigned short value))
 {
+       char *name = edev->name;
        struct list_head *entry;
        struct mii_dev *new_dev;
        struct mii_dev *miidev;
@@ -109,6 +111,7 @@ void miiphy_register (char *name,
        INIT_LIST_HEAD (&new_dev->link);
        new_dev->read = read;
        new_dev->write = write;
+       new_dev->edev = edev;
        new_dev->name = (char *)(new_dev + 1);
        strncpy (new_dev->name, name, name_len);
        new_dev->name[name_len] = '\0';
@@ -175,7 +178,7 @@ int miiphy_read (char *devname, unsigned char addr, 
unsigned char reg,
 
                if (strcmp (devname, dev->name) == 0) {
                        found_dev = 1;
-                       read_ret = dev->read (devname, addr, reg, value);
+                       read_ret = dev->read (dev->edev, addr, reg, value);
                        break;
                }
        }
@@ -212,7 +215,7 @@ int miiphy_write (char *devname, unsigned char addr, 
unsigned char reg,
 
                if (strcmp (devname, dev->name) == 0) {
                        found_dev = 1;
-                       write_ret = dev->write (devname, addr, reg, value);
+                       write_ret = dev->write (dev->edev, addr, reg, value);
                        break;
                }
        }
diff --git a/drivers/qe/uec.c b/drivers/qe/uec.c
index a27c12a..2d29403 100644
--- a/drivers/qe/uec.c
+++ b/drivers/qe/uec.c
@@ -1296,6 +1296,9 @@ int uec_initialize(int index)
 
        phy_change(dev);
 
+       if (index == 1)
+               uec_mmiphy_register(dev);
+
        return 1;
 }
 #endif /* CONFIG_QE */
diff --git a/drivers/qe/uec_phy.c b/drivers/qe/uec_phy.c
index 6882d03..ccd6645 100644
--- a/drivers/qe/uec_phy.c
+++ b/drivers/qe/uec_phy.c
@@ -681,4 +681,28 @@ void change_phy_interface_mode (struct eth_device *dev, 
enet_interface_e mode)
        marvell_phy_interface_mode (dev, mode);
 #endif
 }
+
+
+#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
+       && !defined(BITBANGMII)
+static int uec_miiphy_read(struct eth_device *dev, unsigned char addr,
+                           unsigned char reg, unsigned short *value)
+{
+       *value = uec_read_phy_reg(dev, addr, reg);
+       return 0;
+}
+
+static int uec_miiphy_write(struct eth_device *dev, unsigned char addr,
+                            unsigned char reg, unsigned short value)
+{
+       uec_write_phy_reg(dev, addr, reg, value);
+       return 0;
+}
+
+void uec_mmiphy_register(struct eth_device *dev)
+{
+       miiphy_register(dev, uec_miiphy_read, uec_miiphy_write);
+}
+#endif
+
 #endif /* CONFIG_QE */
diff --git a/drivers/qe/uec_phy.h b/drivers/qe/uec_phy.h
index 6f769fb..ef62f0b 100644
--- a/drivers/qe/uec_phy.h
+++ b/drivers/qe/uec_phy.h
@@ -261,4 +261,5 @@ int uec_read_phy_reg (struct eth_device *dev, int mii_id, 
int regnum);
 void mii_clear_phy_interrupt (struct uec_mii_info *mii_info);
 void mii_configure_phy_interrupt (struct uec_mii_info *mii_info,
                                  u32 interrupts);
+void uec_mmiphy_register(struct eth_device *dev);
 #endif /* __UEC_PHY_H__ */
diff --git a/include/miiphy.h b/include/miiphy.h
index 5518a0a..0ff4ae6 100644
--- a/include/miiphy.h
+++ b/include/miiphy.h
@@ -48,10 +48,10 @@ int miiphy_link (char *devname, unsigned char addr);
 
 void miiphy_init (void);
 
-void miiphy_register (char *devname,
-                     int (*read) (char *devname, unsigned char addr,
+void miiphy_register (struct eth_device *edev,
+                     int (*read) (struct eth_device *edev, unsigned char addr,
                                   unsigned char reg, unsigned short *value),
-                     int (*write) (char *devname, unsigned char addr,
+                     int (*write) (struct eth_device *edev, unsigned char addr,
                                    unsigned char reg, unsigned short value));
 
 int miiphy_set_current_dev (char *devname);

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
U-Boot-Users mailing list
U-Boot-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/u-boot-users

Reply via email to