summaryrefslogtreecommitdiff
path: root/target
diff options
context:
space:
mode:
authorGabor Juhos <juhosg@openwrt.org>2012-03-12 16:28:00 +0000
committerGabor Juhos <juhosg@openwrt.org>2012-03-12 16:28:00 +0000
commit1f79bfec0b80f331e54ac303b6f7cab0f131f7dc (patch)
tree762bcc877501f71d3d07ac48b9976b44628904ec /target
parent2c2c288a3ca262d43749f849506f056e1a81dd2c (diff)
downloadmtk-20170518-1f79bfec0b80f331e54ac303b6f7cab0f131f7dc.zip
mtk-20170518-1f79bfec0b80f331e54ac303b6f7cab0f131f7dc.tar.gz
mtk-20170518-1f79bfec0b80f331e54ac303b6f7cab0f131f7dc.tar.bz2
linux/3.2: allow to set platform_data for phy devices
SVN-Revision: 30905
Diffstat (limited to 'target')
-rw-r--r--target/linux/generic/patches-3.2/710-phy-add-mdio_register_board_info.patch115
1 files changed, 115 insertions, 0 deletions
diff --git a/target/linux/generic/patches-3.2/710-phy-add-mdio_register_board_info.patch b/target/linux/generic/patches-3.2/710-phy-add-mdio_register_board_info.patch
new file mode 100644
index 0000000..8cd6713
--- /dev/null
+++ b/target/linux/generic/patches-3.2/710-phy-add-mdio_register_board_info.patch
@@ -0,0 +1,115 @@
+--- a/drivers/net/phy/mdio_bus.c
++++ b/drivers/net/phy/mdio_bus.c
+@@ -36,6 +36,44 @@
+ #include <asm/irq.h>
+ #include <asm/uaccess.h>
+
++struct mdio_board_entry {
++ struct list_head list;
++ struct mdio_board_info board_info;
++};
++
++static LIST_HEAD(mdio_board_list);
++static DEFINE_MUTEX(mdio_board_lock);
++
++/**
++ * mdio_register_board_info - register PHY devices for a given board
++ * @info: array of chip descriptors
++ * @n: how many descriptors are provided
++ * Context: can sleep
++ *
++ * The board info passed can safely be __initdata ... but be careful of
++ * any embedded pointers (platform_data, etc), they're copied as-is.
++ */
++int __init
++mdiobus_register_board_info(struct mdio_board_info const *info, unsigned n)
++{
++ struct mdio_board_entry *be;
++ int i;
++
++ be = kzalloc(n * sizeof(*be), GFP_KERNEL);
++ if (!be)
++ return -ENOMEM;
++
++ for (i = 0; i < n; i++, be++, info++) {
++ memcpy(&be->board_info, info, sizeof(*info));
++ mutex_lock(&mdio_board_lock);
++ list_add_tail(&be->list, &mdio_board_list);
++ mutex_unlock(&mdio_board_lock);
++ }
++
++ return 0;
++}
++
++
+ /**
+ * mdiobus_alloc - allocate a mii_bus structure
+ *
+@@ -179,15 +217,31 @@ void mdiobus_free(struct mii_bus *bus)
+ }
+ EXPORT_SYMBOL(mdiobus_free);
+
++static void mdiobus_setup_phydev_from_boardinfo(struct mii_bus *bus,
++ struct phy_device *phydev,
++ struct mdio_board_info *bi)
++{
++ if (strcmp(bus->id, bi->bus_id) ||
++ bi->phy_addr != phydev->addr)
++ return;
++
++ phydev->dev.platform_data = (void *) bi->platform_data;
++}
++
+ struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
+ {
+ struct phy_device *phydev;
++ struct mdio_board_entry *be;
+ int err;
+
+ phydev = get_phy_device(bus, addr);
+ if (IS_ERR(phydev) || phydev == NULL)
+ return phydev;
+
++ list_for_each_entry(be, &mdio_board_list, list)
++ mdiobus_setup_phydev_from_boardinfo(bus, phydev,
++ &be->board_info);
++
+ err = phy_device_register(phydev);
+ if (err) {
+ phy_device_free(phydev);
+--- a/include/linux/phy.h
++++ b/include/linux/phy.h
+@@ -394,8 +394,8 @@ struct phy_driver {
+ /* Determines the negotiated speed and duplex */
+ int (*read_status)(struct phy_device *phydev);
+
+- /*
+- * Update the value in phydev->link to reflect the
++ /*
++ * Update the value in phydev->link to reflect the
+ * current link value
+ */
+ int (*update_link)(struct phy_device *phydev);
+@@ -538,4 +538,22 @@ int __init mdio_bus_init(void);
+ void mdio_bus_exit(void);
+
+ extern struct bus_type mdio_bus_type;
++
++struct mdio_board_info {
++ const char *bus_id;
++ int phy_addr;
++
++ const void *platform_data;
++};
++
++#ifdef CONFIG_PHYLIB
++int mdiobus_register_board_info(struct mdio_board_info const *info, unsigned n);
++#else
++static inline int
++mdiobus_register_board_info(struct mdio_board_info const *info, unsigned n)
++{
++ return 0;
++}
++#endif
++
+ #endif /* __PHY_H */