ramips: ramips_esw: convert it to be a platform driver
authorGabor Juhos <juhosg@openwrt.org>
Wed, 8 Dec 2010 10:15:00 +0000 (10:15 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Wed, 8 Dec 2010 10:15:00 +0000 (10:15 +0000)
SVN-Revision: 24331

target/linux/ramips/files/arch/mips/include/asm/mach-ralink/rt305x_esw_platform.h [new file with mode: 0644]
target/linux/ramips/files/arch/mips/ralink/rt305x/devices.c
target/linux/ramips/files/arch/mips/ralink/rt305x/devices.h
target/linux/ramips/files/drivers/net/ramips.c
target/linux/ramips/files/drivers/net/ramips_esw.c

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 (file)
index 0000000..fd1f6eb
--- /dev/null
@@ -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 */
index 4ee0d4f1b48ad91dea73514055a81d50aa55eeae..46bf460d9c35a2912d6301e30792184886fc8f9a 100644 (file)
@@ -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);
 }
 
index b731f868355179fd746c28bcf1d4c7e96f573975..6a267116b5c3b9f13de7565425ffdac935e13252 100644 (file)
@@ -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
 #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;
index 812507328fa638bba168d4fb72781d1dd36514eb..63570c7914b6839e141a0bb1c20e077647296f0c 100644 (file)
@@ -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);
index e8041b48dfde08d4c38f3e62186811346add78ca..87479c65443e7f10621d2f074581624d444cc2f0 100644 (file)
@@ -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)
 
 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);
 }