1
0
mirror of git://projects.qi-hardware.com/openwrt-xburst.git synced 2024-11-27 17:15:00 +02:00

[kernel] make rtl8366 driver OF capable

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@34682 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
blogic 2012-12-15 01:59:08 +00:00
parent 1971309ae5
commit 6886519f62
6 changed files with 121 additions and 66 deletions

View File

@ -15,6 +15,8 @@
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/of_platform.h>
#include <linux/of_gpio.h>
#include <linux/rtl8366.h> #include <linux/rtl8366.h>
#ifdef CONFIG_RTL8366_SMI_DEBUG_FS #ifdef CONFIG_RTL8366_SMI_DEBUG_FS
@ -1370,6 +1372,71 @@ void rtl8366_smi_cleanup(struct rtl8366_smi *smi)
} }
EXPORT_SYMBOL_GPL(rtl8366_smi_cleanup); 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_DESCRIPTION("Realtek RTL8366 SMI interface driver");
MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>"); MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
MODULE_LICENSE("GPL v2"); MODULE_LICENSE("GPL v2");

View File

@ -146,4 +146,6 @@ int rtl8366_sw_set_vlan_enable(struct switch_dev *dev,
const struct switch_attr *attr, const struct switch_attr *attr,
struct switch_val *val); struct switch_val *val);
struct rtl8366_smi* rtl8366_smi_probe(struct platform_device *pdev);
#endif /* _RTL8366_SMI_H */ #endif /* _RTL8366_SMI_H */

View File

@ -13,7 +13,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/platform_device.h> #include <linux/of_platform.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/rtl8366.h> #include <linux/rtl8366.h>
@ -1179,22 +1179,9 @@ static int __devinit rtl8366rb_probe(struct platform_device *pdev)
printk(KERN_NOTICE RTL8366RB_DRIVER_DESC printk(KERN_NOTICE RTL8366RB_DRIVER_DESC
" version " RTL8366RB_DRIVER_VER"\n"); " version " RTL8366RB_DRIVER_VER"\n");
pdata = pdev->dev.platform_data; smi = rtl8366_smi_probe(pdev);
if (!pdata) { if (!smi)
dev_err(&pdev->dev, "no platform data specified\n"); return -ENODEV;
err = -EINVAL;
goto err_out;
}
smi = rtl8366_smi_alloc(&pdev->dev);
if (!smi) {
err = -ENOMEM;
goto err_out;
}
smi->gpio_sda = pdata->gpio_sda;
smi->gpio_sck = pdata->gpio_sck;
smi->hw_reset = pdata->hw_reset;
smi->clk_delay = 10; smi->clk_delay = 10;
smi->cmd_read = 0xa9; smi->cmd_read = 0xa9;
@ -1241,10 +1228,19 @@ static int __devexit rtl8366rb_remove(struct platform_device *pdev)
return 0; return 0;
} }
#ifdef CONFIG_OF
static const struct of_device_id rtl8366rb_match[] = {
{ .compatible = "rtl8366rb" },
{},
};
MODULE_DEVICE_TABLE(of, rtl8366rb_match);
#endif
static struct platform_driver rtl8366rb_driver = { static struct platform_driver rtl8366rb_driver = {
.driver = { .driver = {
.name = RTL8366RB_DRIVER_NAME, .name = RTL8366RB_DRIVER_NAME,
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = of_match_ptr(rtl8366rb_match),
}, },
.probe = rtl8366rb_probe, .probe = rtl8366rb_probe,
.remove = __devexit_p(rtl8366rb_remove), .remove = __devexit_p(rtl8366rb_remove),

View File

@ -12,7 +12,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/platform_device.h> #include <linux/of_platform.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/rtl8366.h> #include <linux/rtl8366.h>
@ -1059,22 +1059,9 @@ static int __devinit rtl8366s_probe(struct platform_device *pdev)
printk(KERN_NOTICE RTL8366S_DRIVER_DESC printk(KERN_NOTICE RTL8366S_DRIVER_DESC
" version " RTL8366S_DRIVER_VER"\n"); " version " RTL8366S_DRIVER_VER"\n");
pdata = pdev->dev.platform_data; smi = rtl8366_smi_probe(pdev);
if (!pdata) { if (!smi)
dev_err(&pdev->dev, "no platform data specified\n"); return -ENODEV;
err = -EINVAL;
goto err_out;
}
smi = rtl8366_smi_alloc(&pdev->dev);
if (!smi) {
err = -ENOMEM;
goto err_out;
}
smi->gpio_sda = pdata->gpio_sda;
smi->gpio_sck = pdata->gpio_sck;
smi->hw_reset = pdata->hw_reset;
smi->clk_delay = 10; smi->clk_delay = 10;
smi->cmd_read = 0xa9; smi->cmd_read = 0xa9;
@ -1121,10 +1108,19 @@ static int __devexit rtl8366s_remove(struct platform_device *pdev)
return 0; return 0;
} }
#ifdef CONFIG_OF
static const struct of_device_id rtl8366s_match[] = {
{ .compatible = "rtl8366s" },
{},
};
MODULE_DEVICE_TABLE(of, rtl8366s_match);
#endif
static struct platform_driver rtl8366s_driver = { static struct platform_driver rtl8366s_driver = {
.driver = { .driver = {
.name = RTL8366S_DRIVER_NAME, .name = RTL8366S_DRIVER_NAME,
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = of_match_ptr(rtl8366s_match),
}, },
.probe = rtl8366s_probe, .probe = rtl8366s_probe,
.remove = __devexit_p(rtl8366s_remove), .remove = __devexit_p(rtl8366s_remove),

View File

@ -11,7 +11,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/platform_device.h> #include <linux/of_platform.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/rtl8367.h> #include <linux/rtl8367.h>
@ -1677,22 +1677,9 @@ static int __devinit rtl8367_probe(struct platform_device *pdev)
struct rtl8366_smi *smi; struct rtl8366_smi *smi;
int err; int err;
pdata = pdev->dev.platform_data; smi = rtl8366_smi_probe(pdev);
if (!pdata) { if (!smi)
dev_err(&pdev->dev, "no platform data specified\n"); return -ENODEV;
err = -EINVAL;
goto err_out;
}
smi = rtl8366_smi_alloc(&pdev->dev);
if (!smi) {
err = -ENOMEM;
goto err_out;
}
smi->gpio_sda = pdata->gpio_sda;
smi->gpio_sck = pdata->gpio_sck;
smi->hw_reset = pdata->hw_reset;
smi->clk_delay = 1500; smi->clk_delay = 1500;
smi->cmd_read = 0xb9; smi->cmd_read = 0xb9;
@ -1747,10 +1734,19 @@ static void rtl8367_shutdown(struct platform_device *pdev)
rtl8367_reset_chip(smi); rtl8367_reset_chip(smi);
} }
#ifdef CONFIG_OF
static const struct of_device_id rtl8367_match[] = {
{ .compatible = "rtl8367" },
{},
};
MODULE_DEVICE_TABLE(of, rtl83767_match);
#endif
static struct platform_driver rtl8367_driver = { static struct platform_driver rtl8367_driver = {
.driver = { .driver = {
.name = RTL8367_DRIVER_NAME, .name = RTL8367_DRIVER_NAME,
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = of_match_ptr(rtl8367_match),
}, },
.probe = rtl8367_probe, .probe = rtl8367_probe,
.remove = __devexit_p(rtl8367_remove), .remove = __devexit_p(rtl8367_remove),

View File

@ -11,7 +11,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/platform_device.h> #include <linux/of_platform.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/rtl8367.h> #include <linux/rtl8367.h>
@ -1459,21 +1459,10 @@ static int __devinit rtl8367b_probe(struct platform_device *pdev)
struct rtl8366_smi *smi; struct rtl8366_smi *smi;
int err; int err;
pdata = pdev->dev.platform_data; smi = rtl8366_smi_probe(pdev);
if (!pdata) { if (!smi)
dev_err(&pdev->dev, "no platform data specified\n"); return -ENODEV;
err = -EINVAL;
goto err_out;
}
smi = rtl8366_smi_alloc(&pdev->dev);
if (!smi) {
err = -ENOMEM;
goto err_out;
}
smi->gpio_sda = pdata->gpio_sda;
smi->gpio_sck = pdata->gpio_sck;
smi->clk_delay = 1500; smi->clk_delay = 1500;
smi->cmd_read = 0xb9; smi->cmd_read = 0xb9;
smi->cmd_write = 0xb8; smi->cmd_write = 0xb8;
@ -1527,10 +1516,19 @@ static void rtl8367b_shutdown(struct platform_device *pdev)
rtl8367b_reset_chip(smi); rtl8367b_reset_chip(smi);
} }
#ifdef CONFIG_OF
static const struct of_device_id rtl8367b_match[] = {
{ .compatible = "rtl8367b" },
{},
};
MODULE_DEVICE_TABLE(of, rtl8367b_match);
#endif
static struct platform_driver rtl8367b_driver = { static struct platform_driver rtl8367b_driver = {
.driver = { .driver = {
.name = RTL8367B_DRIVER_NAME, .name = RTL8367B_DRIVER_NAME,
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = of_match_ptr(rtl8367b_match),
}, },
.probe = rtl8367b_probe, .probe = rtl8367b_probe,
.remove = __devexit_p(rtl8367b_remove), .remove = __devexit_p(rtl8367b_remove),