generic: rtl8366: introduce rtl8366_smi_ops
authorGabor Juhos <juhosg@openwrt.org>
Sat, 26 Jun 2010 19:15:57 +0000 (19:15 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Sat, 26 Jun 2010 19:15:57 +0000 (19:15 +0000)
SVN-Revision: 21910

target/linux/generic-2.6/files/drivers/net/phy/rtl8366_smi.c
target/linux/generic-2.6/files/drivers/net/phy/rtl8366_smi.h
target/linux/generic-2.6/files/drivers/net/phy/rtl8366rb.c
target/linux/generic-2.6/files/drivers/net/phy/rtl8366s.c

index 7091190b8dd641b89e30995c0b063edca296d51f..d40d9e7f73618431269225dc6fc027f228096a64 100644 (file)
@@ -272,6 +272,9 @@ int rtl8366_smi_init(struct rtl8366_smi *smi)
        if (!smi->parent)
                return -EINVAL;
 
+       if (!smi->ops)
+               return -EINVAL;
+
        err = gpio_request(smi->gpio_sda, dev_name(smi->parent));
        if (err) {
                dev_err(smi->parent, "gpio_request failed for %u, err=%d\n",
@@ -291,8 +294,16 @@ int rtl8366_smi_init(struct rtl8366_smi *smi)
        dev_info(smi->parent, "using GPIO pins %u (SDA) and %u (SCK)\n",
                 smi->gpio_sda, smi->gpio_sck);
 
+       err = smi->ops->detect(smi);
+       if (err) {
+               dev_err(smi->parent, "chip detection failed, err=%d\n", err);
+               goto err_free_sck;
+       }
+
        return 0;
 
+ err_free_sck:
+       gpio_free(smi->gpio_sck);
  err_free_sda:
        gpio_free(smi->gpio_sda);
  err_out:
index e68fa9a5b37d7a3a34a09b3662a591de8aab8f72..ae51c425eff2fd80adfc0503b4c3059756b432d6 100644 (file)
 #ifndef _RTL8366_SMI_H
 #define _RTL8366_SMI_H
 
+struct rtl8366_smi_ops;
+
 struct rtl8366_smi {
        struct device           *parent;
        unsigned int            gpio_sda;
        unsigned int            gpio_sck;
        spinlock_t              lock;
+
+       struct rtl8366_smi_ops  *ops;
+};
+
+struct rtl8366_smi_ops {
+       int     (*detect)(struct rtl8366_smi *smi);
 };
 
 int rtl8366_smi_init(struct rtl8366_smi *smi);
index fd8b7e49d1336c5b98e8f41ad080b95eb157ba8a..eca2586a24b3f22f52235ae54e8a1c8cf8806155 100644 (file)
@@ -26,7 +26,7 @@
 #endif
 
 #define RTL8366S_DRIVER_DESC   "Realtek RTL8366RB ethernet switch driver"
-#define RTL8366S_DRIVER_VER    "0.2.0"
+#define RTL8366S_DRIVER_VER    "0.2.2"
 
 #define RTL8366S_PHY_NO_MAX                 4
 #define RTL8366S_PHY_PAGE_MAX               7
@@ -1573,14 +1573,25 @@ static int rtl8366rb_mii_bus_match(struct mii_bus *bus)
 
 static int rtl8366rb_setup(struct rtl8366rb *rtl)
 {
-       struct rtl8366_smi *smi = &rtl->smi;
+       int ret;
+
+       ret = rtl8366rb_reset_chip(rtl);
+       if (ret)
+               return ret;
+
+       rtl8366rb_debugfs_init(rtl);
+       return 0;
+}
+
+static int rtl8366rb_detect(struct rtl8366_smi *smi)
+{
        u32 chip_id = 0;
        u32 chip_ver = 0;
        int ret;
 
        ret = rtl8366_smi_read_reg(smi, RTL8366S_CHIP_ID_REG, &chip_id);
        if (ret) {
-               dev_err(rtl->parent, "unable to read chip id\n");
+               dev_err(smi->parent, "unable to read chip id\n");
                return ret;
        }
 
@@ -1588,28 +1599,27 @@ static int rtl8366rb_setup(struct rtl8366rb *rtl)
        case RTL8366S_CHIP_ID_8366:
                break;
        default:
-               dev_err(rtl->parent, "unknown chip id (%04x)\n", chip_id);
+               dev_err(smi->parent, "unknown chip id (%04x)\n", chip_id);
                return -ENODEV;
        }
 
        ret = rtl8366_smi_read_reg(smi, RTL8366S_CHIP_VERSION_CTRL_REG,
                                   &chip_ver);
        if (ret) {
-               dev_err(rtl->parent, "unable to read chip version\n");
+               dev_err(smi->parent, "unable to read chip version\n");
                return ret;
        }
 
-       dev_info(rtl->parent, "RTL%04x ver. %u chip found\n",
+       dev_info(smi->parent, "RTL%04x ver. %u chip found\n",
                 chip_id, chip_ver & RTL8366S_CHIP_VERSION_MASK);
 
-       ret = rtl8366rb_reset_chip(rtl);
-       if (ret)
-               return ret;
-
-       rtl8366rb_debugfs_init(rtl);
        return 0;
 }
 
+static struct rtl8366_smi_ops rtl8366rb_smi_ops = {
+       .detect         = rtl8366rb_detect,
+};
+
 static int __init rtl8366rb_probe(struct platform_device *pdev)
 {
        static int rtl8366_smi_version_printed;
@@ -1642,6 +1652,7 @@ static int __init rtl8366rb_probe(struct platform_device *pdev)
        smi->parent = &pdev->dev;
        smi->gpio_sda = pdata->gpio_sda;
        smi->gpio_sck = pdata->gpio_sck;
+       smi->ops = &rtl8366rb_smi_ops;
 
        err = rtl8366_smi_init(smi);
        if (err)
index c4ba2c11ef21d7fc9bba528348ced892e09895c7..c09b4b1a2c714ba4f29dc8d2774c145c267da446 100644 (file)
@@ -26,7 +26,7 @@
 #endif
 
 #define RTL8366S_DRIVER_DESC   "Realtek RTL8366S ethernet switch driver"
-#define RTL8366S_DRIVER_VER    "0.2.1"
+#define RTL8366S_DRIVER_VER    "0.2.2"
 
 #define RTL8366S_PHY_NO_MAX                 4
 #define RTL8366S_PHY_PAGE_MAX               7
@@ -1542,14 +1542,25 @@ static int rtl8366s_mii_bus_match(struct mii_bus *bus)
 
 static int rtl8366s_setup(struct rtl8366s *rtl)
 {
-       struct rtl8366_smi *smi = &rtl->smi;
+       int ret;
+
+       ret = rtl8366s_reset_chip(rtl);
+       if (ret)
+               return ret;
+
+       rtl8366s_debugfs_init(rtl);
+       return 0;
+}
+
+static int rtl8366s_detect(struct rtl8366_smi *smi)
+{
        u32 chip_id = 0;
        u32 chip_ver = 0;
        int ret;
 
        ret = rtl8366_smi_read_reg(smi, RTL8366S_CHIP_ID_REG, &chip_id);
        if (ret) {
-               dev_err(rtl->parent, "unable to read chip id\n");
+               dev_err(smi->parent, "unable to read chip id\n");
                return ret;
        }
 
@@ -1557,28 +1568,27 @@ static int rtl8366s_setup(struct rtl8366s *rtl)
        case RTL8366S_CHIP_ID_8366:
                break;
        default:
-               dev_err(rtl->parent, "unknown chip id (%04x)\n", chip_id);
+               dev_err(smi->parent, "unknown chip id (%04x)\n", chip_id);
                return -ENODEV;
        }
 
        ret = rtl8366_smi_read_reg(smi, RTL8366S_CHIP_VERSION_CTRL_REG,
                                   &chip_ver);
        if (ret) {
-               dev_err(rtl->parent, "unable to read chip version\n");
+               dev_err(smi->parent, "unable to read chip version\n");
                return ret;
        }
 
-       dev_info(rtl->parent, "RTL%04x ver. %u chip found\n",
+       dev_info(smi->parent, "RTL%04x ver. %u chip found\n",
                 chip_id, chip_ver & RTL8366S_CHIP_VERSION_MASK);
 
-       ret = rtl8366s_reset_chip(rtl);
-       if (ret)
-               return ret;
-
-       rtl8366s_debugfs_init(rtl);
        return 0;
 }
 
+static struct rtl8366_smi_ops rtl8366s_smi_ops = {
+       .detect         = rtl8366s_detect,
+};
+
 static int __init rtl8366s_probe(struct platform_device *pdev)
 {
        static int rtl8366_smi_version_printed;
@@ -1611,6 +1621,7 @@ static int __init rtl8366s_probe(struct platform_device *pdev)
        smi->parent = &pdev->dev;
        smi->gpio_sda = pdata->gpio_sda;
        smi->gpio_sck = pdata->gpio_sck;
+       smi->ops = &rtl8366s_smi_ops;
 
        err = rtl8366_smi_init(smi);
        if (err)