aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/ramips
diff options
context:
space:
mode:
authorGabor Juhos <juhosg@openwrt.org>2010-12-08 10:15:00 +0000
committerGabor Juhos <juhosg@openwrt.org>2010-12-08 10:15:00 +0000
commit418e052c05c9de090fde782ab320e2ca25a16761 (patch)
tree72c1e4669293fbe110c6ba601e8c25ec52c614bc /target/linux/ramips
parenta0e968135aff665d2bf93388bd8e30ac22b607a5 (diff)
downloadupstream-418e052c05c9de090fde782ab320e2ca25a16761.tar.gz
upstream-418e052c05c9de090fde782ab320e2ca25a16761.tar.bz2
upstream-418e052c05c9de090fde782ab320e2ca25a16761.zip
ramips: ramips_esw: convert it to be a platform driver
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@24331 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'target/linux/ramips')
-rw-r--r--target/linux/ramips/files/arch/mips/include/asm/mach-ralink/rt305x_esw_platform.h18
-rw-r--r--target/linux/ramips/files/arch/mips/ralink/rt305x/devices.c21
-rw-r--r--target/linux/ramips/files/arch/mips/ralink/rt305x/devices.h6
-rw-r--r--target/linux/ramips/files/drivers/net/ramips.c22
-rw-r--r--target/linux/ramips/files/drivers/net/ramips_esw.c80
5 files changed, 134 insertions, 13 deletions
diff --git a/target/linux/ramips/files/arch/mips/include/asm/mach-ralink/rt305x_esw_platform.h b/target/linux/ramips/files/arch/mips/include/asm/mach-ralink/rt305x_esw_platform.h
new file mode 100644
index 0000000000..fd1f6eb19a
--- /dev/null
+++ b/target/linux/ramips/files/arch/mips/include/asm/mach-ralink/rt305x_esw_platform.h
@@ -0,0 +1,18 @@
+/*
+ * Ralink RT305x SoC platform device registration
+ *
+ * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#ifndef _RT305X_ESW_PLATFORM_H
+#define _RT305X_ESW_PLATFORM_H
+
+struct rt305x_esw_platform_data
+{
+};
+
+#endif /* _RT305X_ESW_PLATFORM_H */
diff --git a/target/linux/ramips/files/arch/mips/ralink/rt305x/devices.c b/target/linux/ramips/files/arch/mips/ralink/rt305x/devices.c
index 4ee0d4f1b4..46bf460d9c 100644
--- a/target/linux/ramips/files/arch/mips/ralink/rt305x/devices.c
+++ b/target/linux/ramips/files/arch/mips/ralink/rt305x/devices.c
@@ -1,7 +1,7 @@
/*
* Ralink RT305x SoC platform device registration
*
- * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
+ * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
@@ -130,10 +130,29 @@ static struct platform_device rt305x_eth_device = {
}
};
+static struct resource rt305x_esw_resources[] = {
+ {
+ .start = RT305X_SWITCH_BASE,
+ .end = RT305X_SWITCH_BASE + PAGE_SIZE - 1,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+struct rt305x_esw_platform_data rt305x_esw_data;
+static struct platform_device rt305x_esw_device = {
+ .name = "rt305x-esw",
+ .resource = rt305x_esw_resources,
+ .num_resources = ARRAY_SIZE(rt305x_esw_resources),
+ .dev = {
+ .platform_data = &rt305x_esw_data,
+ }
+};
+
void __init rt305x_register_ethernet(void)
{
ramips_eth_data.sys_freq = rt305x_sys_freq;
+ platform_device_register(&rt305x_esw_device);
platform_device_register(&rt305x_eth_device);
}
diff --git a/target/linux/ramips/files/arch/mips/ralink/rt305x/devices.h b/target/linux/ramips/files/arch/mips/ralink/rt305x/devices.h
index b731f86835..6a267116b5 100644
--- a/target/linux/ramips/files/arch/mips/ralink/rt305x/devices.h
+++ b/target/linux/ramips/files/arch/mips/ralink/rt305x/devices.h
@@ -1,7 +1,7 @@
/*
* Ralink RT305x SoC specific platform device definitions
*
- * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
+ * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
@@ -11,8 +11,12 @@
#ifndef __RT305X_DEVICES_H
#define __RT305X_DEVICES_H
+#include <asm/mach-ralink/rt305x_esw_platform.h>
+
struct physmap_flash_data;
+extern struct rt305x_esw_platform_data rt305x_esw_data;
+
extern void rt305x_register_flash(unsigned int id,
struct physmap_flash_data *pdata) __init;
extern void rt305x_register_ethernet(void) __init;
diff --git a/target/linux/ramips/files/drivers/net/ramips.c b/target/linux/ramips/files/drivers/net/ramips.c
index 812507328f..63570c7914 100644
--- a/target/linux/ramips/files/drivers/net/ramips.c
+++ b/target/linux/ramips/files/drivers/net/ramips.c
@@ -33,6 +33,9 @@
#ifdef CONFIG_RALINK_RT305X
#include "ramips_esw.c"
+#else
+static inline int rt305x_esw_init(void) { return 0; }
+static inline void rt305x_esw_exit(void) { }
#endif
#define phys_to_bus(a) (a & 0x1FFFFFFF)
@@ -507,9 +510,6 @@ ramips_eth_plat_probe(struct platform_device *plat)
goto err_free_dev;
}
-#ifdef CONFIG_RALINK_RT305X
- rt305x_esw_init();
-#endif
printk(KERN_DEBUG "ramips_eth: loaded\n");
return 0;
@@ -541,10 +541,23 @@ static struct platform_driver ramips_eth_driver = {
static int __init
ramips_eth_init(void)
{
- int ret = platform_driver_register(&ramips_eth_driver);
+ int ret;
+
+ ret = rt305x_esw_init();
if (ret)
+ return ret;
+
+ ret = platform_driver_register(&ramips_eth_driver);
+ if (ret) {
printk(KERN_ERR
"ramips_eth: Error registering platfom driver!\n");
+ goto esw_cleanup;
+ }
+
+ return 0;
+
+esw_cleanup:
+ rt305x_esw_exit();
return ret;
}
@@ -552,6 +565,7 @@ static void __exit
ramips_eth_cleanup(void)
{
platform_driver_unregister(&ramips_eth_driver);
+ rt305x_esw_exit();
}
module_init(ramips_eth_init);
diff --git a/target/linux/ramips/files/drivers/net/ramips_esw.c b/target/linux/ramips/files/drivers/net/ramips_esw.c
index e8041b48df..87479c6544 100644
--- a/target/linux/ramips/files/drivers/net/ramips_esw.c
+++ b/target/linux/ramips/files/drivers/net/ramips_esw.c
@@ -1,5 +1,7 @@
-#include <rt305x.h>
+#include <linux/ioport.h>
+
#include <rt305x_regs.h>
+#include <rt305x_esw_platform.h>
#define GPIO_PRUPOSE 0x60
#define GPIO_MDIO_BIT (1<<7)
@@ -10,10 +12,9 @@
struct rt305x_esw {
void __iomem *base;
+ struct rt305x_esw_platform_data *pdata;
};
-static struct rt305x_esw rt305x_esw;
-
static inline void
ramips_esw_wr(struct rt305x_esw *esw, u32 val, unsigned reg)
{
@@ -121,15 +122,80 @@ rt305x_esw_hw_init(struct rt305x_esw *esw)
}
static int
-rt305x_esw_init(void)
+rt305x_esw_probe(struct platform_device *pdev)
{
+ struct rt305x_esw_platform_data *pdata;
struct rt305x_esw *esw;
+ struct resource *res;
+ int err;
+
+ pdata = pdev->dev.platform_data;
+ if (!pdata)
+ return -EINVAL;
- esw = &rt305x_esw;
- esw->base = ioremap_nocache(RT305X_SWITCH_BASE, PAGE_SIZE);
- if(!esw->base)
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res) {
+ dev_err(&pdev->dev, "no memory resource found\n");
return -ENOMEM;
+ }
+
+ esw = kzalloc(sizeof (struct rt305x_esw), GFP_KERNEL);
+ if (!esw) {
+ dev_err(&pdev->dev, "no memory for private data\n");
+ return -ENOMEM;
+ }
+ esw->base = ioremap(res->start, resource_size(res));
+ if (!esw->base) {
+ dev_err(&pdev->dev, "ioremap failed\n");
+ err = -ENOMEM;
+ goto free_esw;
+ }
+
+ platform_set_drvdata(pdev, esw);
+
+ esw->pdata = pdata;
rt305x_esw_hw_init(esw);
+
return 0;
+
+free_esw:
+ kfree(esw);
+ return err;
+}
+
+static int
+rt305x_esw_remove(struct platform_device *pdev)
+{
+ struct rt305x_esw *esw;
+
+ esw = platform_get_drvdata(pdev);
+ if (esw) {
+ platform_set_drvdata(pdev, NULL);
+ iounmap(esw->base);
+ kfree(esw);
+ }
+
+ return 0;
+}
+
+static struct platform_driver rt305x_esw_driver = {
+ .probe = rt305x_esw_probe,
+ .remove = rt305x_esw_remove,
+ .driver = {
+ .name = "rt305x-esw",
+ .owner = THIS_MODULE,
+ },
+};
+
+static int __init
+rt305x_esw_init(void)
+{
+ return platform_driver_register(&rt305x_esw_driver);
+}
+
+static void __exit
+rt305x_esw_exit(void)
+{
+ platform_driver_unregister(&rt305x_esw_driver);
}