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 4ee0d4f..46bf460 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 b731f86..6a26711 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 8125073..63570c7 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 e8041b4..87479c6 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);
 }