generic: rtl8366s: add support support for initvals from DTS
[openwrt/openwrt.git] / target / linux / generic / files / drivers / net / phy / rtl8366s.c
index 6e5e48749ba3ed76ae0e40940a9df4812c74b457..b54b4b13b06ea47e06c5a7de752b350dd70e7e24 100644 (file)
@@ -12,6 +12,8 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/device.h>
+#include <linux/of.h>
 #include <linux/of_platform.h>
 #include <linux/delay.h>
 #include <linux/skbuff.h>
 #include <linux/of_platform.h>
 #include <linux/delay.h>
 #include <linux/skbuff.h>
@@ -252,17 +254,42 @@ static int rtl8366s_setup(struct rtl8366_smi *smi)
 {
        struct rtl8366_platform_data *pdata;
        int err;
 {
        struct rtl8366_platform_data *pdata;
        int err;
+       unsigned i;
+#ifdef CONFIG_OF
+       struct device_node *np;
+       unsigned num_initvals;
+       const __be32 *paddr;
+#endif
 
        pdata = smi->parent->platform_data;
 
        pdata = smi->parent->platform_data;
-       if (pdata->num_initvals && pdata->initvals) {
-               unsigned i;
-
+       if (pdata && pdata->num_initvals && pdata->initvals) {
                dev_info(smi->parent, "applying initvals\n");
                for (i = 0; i < pdata->num_initvals; i++)
                        REG_WR(smi, pdata->initvals[i].reg,
                               pdata->initvals[i].val);
        }
 
                dev_info(smi->parent, "applying initvals\n");
                for (i = 0; i < pdata->num_initvals; i++)
                        REG_WR(smi, pdata->initvals[i].reg,
                               pdata->initvals[i].val);
        }
 
+#ifdef CONFIG_OF
+       np = smi->parent->of_node;
+
+       paddr = of_get_property(np, "realtek,initvals", &num_initvals);
+       if (paddr) {
+               dev_info(smi->parent, "applying initvals from DTS\n");
+
+               if (num_initvals < (2 * sizeof(*paddr)))
+                       return -EINVAL;
+
+               num_initvals /= sizeof(*paddr);
+
+               for (i = 0; i < num_initvals - 1; i += 2) {
+                       u32 reg = be32_to_cpup(paddr + i);
+                       u32 val = be32_to_cpup(paddr + i + 1);
+
+                       REG_WR(smi, reg, val);
+               }
+       }
+#endif
+
        /* set maximum packet length to 1536 bytes */
        REG_RMW(smi, RTL8366S_SGCR, RTL8366S_SGCR_MAX_LENGTH_MASK,
                RTL8366S_SGCR_MAX_LENGTH_1536);
        /* set maximum packet length to 1536 bytes */
        REG_RMW(smi, RTL8366S_SGCR, RTL8366S_SGCR_MAX_LENGTH_MASK,
                RTL8366S_SGCR_MAX_LENGTH_1536);
@@ -1048,10 +1075,9 @@ static struct rtl8366_smi_ops rtl8366s_smi_ops = {
        .enable_port    = rtl8366s_enable_port,
 };
 
        .enable_port    = rtl8366s_enable_port,
 };
 
-static int __devinit rtl8366s_probe(struct platform_device *pdev)
+static int rtl8366s_probe(struct platform_device *pdev)
 {
        static int rtl8366_smi_version_printed;
 {
        static int rtl8366_smi_version_printed;
-       struct rtl8366_platform_data *pdata;
        struct rtl8366_smi *smi;
        int err;
 
        struct rtl8366_smi *smi;
        int err;
 
@@ -1090,11 +1116,10 @@ static int __devinit rtl8366s_probe(struct platform_device *pdev)
        rtl8366_smi_cleanup(smi);
  err_free_smi:
        kfree(smi);
        rtl8366_smi_cleanup(smi);
  err_free_smi:
        kfree(smi);
- err_out:
        return err;
 }
 
        return err;
 }
 
-static int __devexit rtl8366s_remove(struct platform_device *pdev)
+static int rtl8366s_remove(struct platform_device *pdev)
 {
        struct rtl8366_smi *smi = platform_get_drvdata(pdev);
 
 {
        struct rtl8366_smi *smi = platform_get_drvdata(pdev);
 
@@ -1110,7 +1135,7 @@ static int __devexit rtl8366s_remove(struct platform_device *pdev)
 
 #ifdef CONFIG_OF
 static const struct of_device_id rtl8366s_match[] = {
 
 #ifdef CONFIG_OF
 static const struct of_device_id rtl8366s_match[] = {
-       { .compatible = "rtl8366s" },
+       { .compatible = "realtek,rtl8366s" },
        {},
 };
 MODULE_DEVICE_TABLE(of, rtl8366s_match);
        {},
 };
 MODULE_DEVICE_TABLE(of, rtl8366s_match);
@@ -1120,10 +1145,12 @@ static struct platform_driver rtl8366s_driver = {
        .driver = {
                .name           = RTL8366S_DRIVER_NAME,
                .owner          = THIS_MODULE,
        .driver = {
                .name           = RTL8366S_DRIVER_NAME,
                .owner          = THIS_MODULE,
+#ifdef CONFIG_OF
                .of_match_table = of_match_ptr(rtl8366s_match),
                .of_match_table = of_match_ptr(rtl8366s_match),
+#endif
        },
        .probe          = rtl8366s_probe,
        },
        .probe          = rtl8366s_probe,
-       .remove         = __devexit_p(rtl8366s_remove),
+       .remove         = rtl8366s_remove,
 };
 
 static int __init rtl8366s_module_init(void)
 };
 
 static int __init rtl8366s_module_init(void)