diff options
author | John Crispin <john@openwrt.org> | 2012-12-15 01:59:08 +0000 |
---|---|---|
committer | John Crispin <john@openwrt.org> | 2012-12-15 01:59:08 +0000 |
commit | d8678644f9b18f36bdd5e7825e09c65dfcd049dc (patch) | |
tree | 58eabb9135e265150ce4b02e68f80da6be95803f /target/linux/generic/files/drivers/net/phy/rtl8366_smi.c | |
parent | 5ba98739146396935a76a52391e612024bf15cfa (diff) | |
download | upstream-d8678644f9b18f36bdd5e7825e09c65dfcd049dc.tar.gz upstream-d8678644f9b18f36bdd5e7825e09c65dfcd049dc.tar.bz2 upstream-d8678644f9b18f36bdd5e7825e09c65dfcd049dc.zip |
make rtl8366 driver OF capable
SVN-Revision: 34682
Diffstat (limited to 'target/linux/generic/files/drivers/net/phy/rtl8366_smi.c')
-rw-r--r-- | target/linux/generic/files/drivers/net/phy/rtl8366_smi.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/target/linux/generic/files/drivers/net/phy/rtl8366_smi.c b/target/linux/generic/files/drivers/net/phy/rtl8366_smi.c index be85274e78..44074633e2 100644 --- a/target/linux/generic/files/drivers/net/phy/rtl8366_smi.c +++ b/target/linux/generic/files/drivers/net/phy/rtl8366_smi.c @@ -15,6 +15,8 @@ #include <linux/gpio.h> #include <linux/spinlock.h> #include <linux/skbuff.h> +#include <linux/of_platform.h> +#include <linux/of_gpio.h> #include <linux/rtl8366.h> #ifdef CONFIG_RTL8366_SMI_DEBUG_FS @@ -1370,6 +1372,71 @@ void rtl8366_smi_cleanup(struct rtl8366_smi *smi) } EXPORT_SYMBOL_GPL(rtl8366_smi_cleanup); +#ifdef CONFIG_OF +int rtl8366_smi_probe_of(struct platform_device *pdev, struct rtl8366_smi *smi) +{ + int sck = of_get_named_gpio(pdev->dev.of_node, "gpio-sck", 0); + int sda = of_get_named_gpio(pdev->dev.of_node, "gpio-sda", 0); + + if (!sck || !sda) { + dev_err(&pdev->dev, "gpios missing in devictree\n"); + return -EINVAL; + } + + smi->gpio_sda = sda; + smi->gpio_sck = sck; + + return 0; +} +#else +static inline int rtl8366_smi_probe_of(struct device_node *np, struct rtl8366_smi *smi) +{ + return -ENODEV; +} +#endif + +int rtl8366_smi_probe_plat(struct platform_device *pdev, struct rtl8366_smi *smi) +{ + struct rtl8366_platform_data *pdata = pdev->dev.platform_data; + + if (!pdev->dev.platform_data) { + dev_err(&pdev->dev, "no platform data specified\n"); + return -EINVAL; + } + + smi->gpio_sda = pdata->gpio_sda; + smi->gpio_sck = pdata->gpio_sck; + smi->hw_reset = pdata->hw_reset; + + return 0; +} + + +struct rtl8366_smi *rtl8366_smi_probe(struct platform_device *pdev) +{ + struct rtl8366_smi *smi; + int err; + + smi = rtl8366_smi_alloc(&pdev->dev); + if (!smi) + return NULL; + + if (pdev->dev.of_node) + err = rtl8366_smi_probe_of(pdev, smi); + else + err = rtl8366_smi_probe_plat(pdev, smi); + + if (err) + goto free_smi; + + return smi; + +free_smi: + kfree(smi); + return NULL; +} +EXPORT_SYMBOL_GPL(rtl8366_smi_probe); + MODULE_DESCRIPTION("Realtek RTL8366 SMI interface driver"); MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>"); MODULE_LICENSE("GPL v2"); |