]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - include/linux/phy.h
lz4: fix wrong compress buffer size for 64-bits
[karo-tx-linux.git] / include / linux / phy.h
index a89cb0eef911eaea6ebf037ed276f9138426bac3..d6f3641e79332889ba121c1c684e7da1b40a27f8 100644 (file)
 #ifndef __PHY_H
 #define __PHY_H
 
+#include <linux/compiler.h>
 #include <linux/spinlock.h>
 #include <linux/ethtool.h>
+#include <linux/mdio.h>
 #include <linux/mii.h>
 #include <linux/module.h>
 #include <linux/timer.h>
@@ -58,6 +60,7 @@
 #define PHY_HAS_INTERRUPT      0x00000001
 #define PHY_HAS_MAGICANEG      0x00000002
 #define PHY_IS_INTERNAL                0x00000004
+#define MDIO_DEVICE_IS_PHY     0x80000000
 
 /* Interface Mode definitions */
 typedef enum {
@@ -158,8 +161,8 @@ struct mii_bus {
        const char *name;
        char id[MII_BUS_ID_SIZE];
        void *priv;
-       int (*read)(struct mii_bus *bus, int phy_id, int regnum);
-       int (*write)(struct mii_bus *bus, int phy_id, int regnum, u16 val);
+       int (*read)(struct mii_bus *bus, int addr, int regnum);
+       int (*write)(struct mii_bus *bus, int addr, int regnum, u16 val);
        int (*reset)(struct mii_bus *bus);
 
        /*
@@ -178,7 +181,7 @@ struct mii_bus {
        struct device dev;
 
        /* list of all PHYs on bus */
-       struct phy_device *phy_map[PHY_MAX_ADDR];
+       struct mdio_device *mdio_map[PHY_MAX_ADDR];
 
        /* PHY addresses to be ignored when probing */
        u32 phy_mask;
@@ -187,10 +190,10 @@ struct mii_bus {
        u32 phy_ignore_ta_mask;
 
        /*
-        * Pointer to an array of interrupts, each PHY's
-        * interrupt at the index matching its address
+        * An array of interrupts, each PHY's interrupt at the index
+        * matching its address
         */
-       int *irq;
+       int irq[PHY_MAX_ADDR];
 };
 #define to_mii_bus(d) container_of(d, struct mii_bus, dev)
 
@@ -212,11 +215,6 @@ static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev)
 
 void devm_mdiobus_free(struct device *dev, struct mii_bus *bus);
 struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
-int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
-int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum);
-int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
-int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val);
-
 
 #define PHY_INTERRUPT_DISABLED 0x0
 #define PHY_INTERRUPT_ENABLED  0x80000000
@@ -361,14 +359,12 @@ struct phy_c45_device_ids {
  * handling, as well as handling shifts in PHY hardware state
  */
 struct phy_device {
+       struct mdio_device mdio;
+
        /* Information about the PHY type */
        /* And management functions */
        struct phy_driver *drv;
 
-       struct mii_bus *bus;
-
-       struct device dev;
-
        u32 phy_id;
 
        struct phy_c45_device_ids c45_ids;
@@ -384,9 +380,6 @@ struct phy_device {
 
        phy_interface_t interface;
 
-       /* Bus address of the PHY (0-31) */
-       int addr;
-
        /*
         * forced speed & duplex (no autoneg)
         * partner speed & duplex & pause (autoneg)
@@ -435,10 +428,12 @@ struct phy_device {
 
        void (*adjust_link)(struct net_device *dev);
 };
-#define to_phy_device(d) container_of(d, struct phy_device, dev)
+#define to_phy_device(d) container_of(to_mdio_device(d), \
+                                     struct phy_device, mdio)
 
 /* struct phy_driver: Driver structure for a particular PHY type
  *
+ * driver_data: static driver data
  * phy_id: The result of reading the UID registers of this PHY
  *   type, and ANDing them with the phy_id_mask.  This driver
  *   only works for PHYs with IDs which match this field
@@ -448,7 +443,6 @@ struct phy_device {
  *   by this PHY
  * flags: A bitfield defining certain other features this PHY
  *   supports (like interrupts)
- * driver_data: static driver data
  *
  * The drivers must implement config_aneg and read_status.  All
  * other functions are optional. Note that none of these
@@ -459,6 +453,7 @@ struct phy_device {
  * supported in the driver).
  */
 struct phy_driver {
+       struct mdio_driver_common mdiodrv;
        u32 phy_id;
        char *name;
        unsigned int phy_id_mask;
@@ -594,10 +589,9 @@ struct phy_driver {
        void (*get_strings)(struct phy_device *dev, u8 *data);
        void (*get_stats)(struct phy_device *dev,
                          struct ethtool_stats *stats, u64 *data);
-
-       struct device_driver driver;
 };
-#define to_phy_driver(d) container_of(d, struct phy_driver, driver)
+#define to_phy_driver(d) container_of(to_mdio_common_driver(d),                \
+                                     struct phy_driver, mdiodrv)
 
 #define PHY_ANY_ID "MATCH ANY PHY"
 #define PHY_ANY_UID 0xffffffff
@@ -625,7 +619,7 @@ static inline int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
        if (!phydev->is_c45)
                return -EOPNOTSUPP;
 
-       return mdiobus_read(phydev->bus, phydev->addr,
+       return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr,
                            MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff));
 }
 
@@ -633,14 +627,12 @@ static inline int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
  * phy_read_mmd_indirect - reads data from the MMD registers
  * @phydev: The PHY device bus
  * @prtad: MMD Address
- * @devad: MMD DEVAD
  * @addr: PHY address on the MII bus
  *
  * Description: it reads data from the MMD registers (clause 22 to access to
  * clause 45) of the specified phy address.
  */
-int phy_read_mmd_indirect(struct phy_device *phydev, int prtad,
-                         int devad, int addr);
+int phy_read_mmd_indirect(struct phy_device *phydev, int prtad, int devad);
 
 /**
  * phy_read - Convenience function for reading a given PHY register
@@ -653,7 +645,7 @@ int phy_read_mmd_indirect(struct phy_device *phydev, int prtad,
  */
 static inline int phy_read(struct phy_device *phydev, u32 regnum)
 {
-       return mdiobus_read(phydev->bus, phydev->addr, regnum);
+       return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum);
 }
 
 /**
@@ -668,7 +660,7 @@ static inline int phy_read(struct phy_device *phydev, u32 regnum)
  */
 static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val)
 {
-       return mdiobus_write(phydev->bus, phydev->addr, regnum, val);
+       return mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, val);
 }
 
 /**
@@ -731,7 +723,7 @@ static inline int phy_write_mmd(struct phy_device *phydev, int devad,
 
        regnum = MII_ADDR_C45 | ((devad & 0x1f) << 16) | (regnum & 0xffff);
 
-       return mdiobus_write(phydev->bus, phydev->addr, regnum, val);
+       return mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, val);
 }
 
 /**
@@ -739,14 +731,13 @@ static inline int phy_write_mmd(struct phy_device *phydev, int devad,
  * @phydev: The PHY device
  * @prtad: MMD Address
  * @devad: MMD DEVAD
- * @addr: PHY address on the MII bus
  * @data: data to write in the MMD register
  *
  * Description: Write data from the MMD registers of the specified
  * phy address.
  */
 void phy_write_mmd_indirect(struct phy_device *phydev, int prtad,
-                           int devad, int addr, u32 data);
+                           int devad, u32 data);
 
 struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
                                     bool is_c45,
@@ -781,6 +772,20 @@ static inline int phy_read_status(struct phy_device *phydev)
        return phydev->drv->read_status(phydev);
 }
 
+#define phydev_err(_phydev, format, args...)   \
+       dev_err(&_phydev->mdio.dev, format, ##args)
+
+#define phydev_dbg(_phydev, format, args...)   \
+       dev_dbg(&_phydev->mdio.dev, format, ##args);
+
+static inline const char *phydev_name(const struct phy_device *phydev)
+{
+       return dev_name(&phydev->mdio.dev);
+}
+
+void phy_attached_print(struct phy_device *phydev, const char *fmt, ...)
+       __printf(2, 3);
+void phy_attached_info(struct phy_device *phydev);
 int genphy_config_init(struct phy_device *phydev);
 int genphy_setup_forced(struct phy_device *phydev);
 int genphy_restart_aneg(struct phy_device *phydev);
@@ -793,8 +798,9 @@ int genphy_resume(struct phy_device *phydev);
 int genphy_soft_reset(struct phy_device *phydev);
 void phy_driver_unregister(struct phy_driver *drv);
 void phy_drivers_unregister(struct phy_driver *drv, int n);
-int phy_driver_register(struct phy_driver *new_driver);
-int phy_drivers_register(struct phy_driver *new_driver, int n);
+int phy_driver_register(struct phy_driver *new_driver, struct module *owner);
+int phy_drivers_register(struct phy_driver *new_driver, int n,
+                        struct module *owner);
 void phy_state_machine(struct work_struct *work);
 void phy_change(struct work_struct *work);
 void phy_mac_interrupt(struct phy_device *phydev, int new_link);
@@ -839,7 +845,7 @@ extern struct bus_type mdio_bus_type;
 #define phy_module_driver(__phy_drivers, __count)                      \
 static int __init phy_module_init(void)                                        \
 {                                                                      \
-       return phy_drivers_register(__phy_drivers, __count);            \
+       return phy_drivers_register(__phy_drivers, __count, THIS_MODULE); \
 }                                                                      \
 module_init(phy_module_init);                                          \
 static void __exit phy_module_exit(void)                               \