[POWERPC] Create Marvell mv64x60 MPSC (serial) platform_data
authorDale Farnsworth <dale@farnsworth.org>
Sat, 12 May 2007 00:55:53 +0000 (10:55 +1000)
committerPaul Mackerras <paulus@samba.org>
Sat, 12 May 2007 01:32:49 +0000 (11:32 +1000)
This patch creates platform_device entries for the Marvell mv64x60
MPSC (multi-protocol serial controller) ports, based on information
contained in the device tree.

This driver (like the other mv64x60 drivers) are unusual in that it
works on both the MIPS and PowerPC architectures.  Because of that,
the drivers do not support the normal PowerPC of_platform_bus_type.
They support platform_bus_type instead.

Signed-off-by: Dale Farnsworth <dale@farnsworth.org>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Paul Mackerras <paulus@samba.org>
arch/powerpc/platforms/embedded6xx/Kconfig
arch/powerpc/sysdev/Makefile
arch/powerpc/sysdev/mv64x60_dev.c [new file with mode: 0644]

index 8f3c2a73e1651f8918a2971b415ce8a84a2e0bd5..abb27c97afe9ecb1fd91420e60e039f755041b9d 100644 (file)
@@ -46,6 +46,9 @@ config MPC10X_BRIDGE
        select PPC_INDIRECT_PCI
        default y
 
+config MV64X60
+       bool
+
 config MPC10X_OPENPIC
        bool
        depends on LINKSTATION
index 041c832bc407882812bd5ea46ad9e6944e9b6a84..452ff5636e41db5f13c8cd19dc2af6a275c18183 100644 (file)
@@ -16,7 +16,7 @@ obj-$(CONFIG_FSL_SOC)         += fsl_soc.o
 obj-$(CONFIG_FSL_PCIE)         += fsl_pcie.o
 obj-$(CONFIG_TSI108_BRIDGE)    += tsi108_pci.o tsi108_dev.o
 obj-$(CONFIG_QUICC_ENGINE)     += qe_lib/
-obj-$(CONFIG_MV64X60)          += mv64x60_pic.o
+obj-$(CONFIG_MV64X60)          += mv64x60_pic.o mv64x60_dev.o
 
 # contains only the suspend handler for time
 obj-$(CONFIG_PM)               += timer.o
diff --git a/arch/powerpc/sysdev/mv64x60_dev.c b/arch/powerpc/sysdev/mv64x60_dev.c
new file mode 100644 (file)
index 0000000..735d20f
--- /dev/null
@@ -0,0 +1,221 @@
+/*
+ * Platform device setup for Marvell mv64360/mv64460 host bridges (Discovery)
+ *
+ * Author: Dale Farnsworth <dale@farnsworth.org>
+ *
+ * 2007 (c) MontaVista, Software, Inc.  This file is licensed under
+ * the terms of the GNU General Public License version 2.  This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ */
+
+#include <linux/stddef.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/mv643xx.h>
+#include <linux/platform_device.h>
+
+#include <asm/prom.h>
+
+/*
+ * These functions provide the necessary setup for the mv64x60 drivers.
+ * These drivers are unusual in that they work on both the MIPS and PowerPC
+ * architectures.  Because of that, the drivers do not support the normal
+ * PowerPC of_platform_bus_type.  They support platform_bus_type instead.
+ */
+
+/*
+ * Create MPSC platform devices
+ */
+static int __init mv64x60_mpsc_register_shared_pdev(struct device_node *np)
+{
+       struct platform_device *pdev;
+       struct resource r[2];
+       struct mpsc_shared_pdata pdata;
+       const phandle *ph;
+       struct device_node *mpscrouting, *mpscintr;
+       int err;
+
+       ph = of_get_property(np, "mpscrouting", NULL);
+       mpscrouting = of_find_node_by_phandle(*ph);
+       if (!mpscrouting)
+               return -ENODEV;
+
+       err = of_address_to_resource(mpscrouting, 0, &r[0]);
+       of_node_put(mpscrouting);
+       if (err)
+               return err;
+
+       ph = of_get_property(np, "mpscintr", NULL);
+       mpscintr = of_find_node_by_phandle(*ph);
+       if (!mpscintr)
+               return -ENODEV;
+
+       err = of_address_to_resource(mpscintr, 0, &r[1]);
+       of_node_put(mpscintr);
+       if (err)
+               return err;
+
+       memset(&pdata, 0, sizeof(pdata));
+
+       pdev = platform_device_alloc(MPSC_SHARED_NAME, 0);
+       if (!pdev)
+               return -ENOMEM;
+
+       err = platform_device_add_resources(pdev, r, 2);
+       if (err)
+               goto error;
+
+       err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
+       if (err)
+               goto error;
+
+       err = platform_device_add(pdev);
+       if (err)
+               goto error;
+
+       return 0;
+
+error:
+       platform_device_put(pdev);
+       return err;
+}
+
+
+static int __init mv64x60_mpsc_device_setup(struct device_node *np, int id)
+{
+       struct resource r[5];
+       struct mpsc_pdata pdata;
+       struct platform_device *pdev;
+       const unsigned int *prop;
+       const phandle *ph;
+       struct device_node *sdma, *brg;
+       int err;
+       int port_number;
+
+       /* only register the shared platform device the first time through */
+       if (id == 0 && (err = mv64x60_mpsc_register_shared_pdev(np)))
+               return err;
+
+       memset(r, 0, sizeof(r));
+
+       err = of_address_to_resource(np, 0, &r[0]);
+       if (err)
+               return err;
+
+       of_irq_to_resource(np, 0, &r[4]);
+
+       ph = of_get_property(np, "sdma", NULL);
+       sdma = of_find_node_by_phandle(*ph);
+       if (!sdma)
+               return -ENODEV;
+
+       of_irq_to_resource(sdma, 0, &r[3]);
+       err = of_address_to_resource(sdma, 0, &r[1]);
+       of_node_put(sdma);
+       if (err)
+               return err;
+
+       ph = of_get_property(np, "brg", NULL);
+       brg = of_find_node_by_phandle(*ph);
+       if (!brg)
+               return -ENODEV;
+
+       err = of_address_to_resource(brg, 0, &r[2]);
+       of_node_put(brg);
+       if (err)
+               return err;
+
+       prop = of_get_property(np, "block-index", NULL);
+       if (!prop)
+               return -ENODEV;
+       port_number = *(int *)prop;
+
+       memset(&pdata, 0, sizeof(pdata));
+
+       pdata.cache_mgmt = 1; /* All current revs need this set */
+
+       prop = of_get_property(np, "max_idle", NULL);
+       if (prop)
+               pdata.max_idle = *prop;
+
+       prop = of_get_property(brg, "current-speed", NULL);
+       if (prop)
+               pdata.default_baud = *prop;
+
+       /* Default is 8 bits, no parity, no flow control */
+       pdata.default_bits = 8;
+       pdata.default_parity = 'n';
+       pdata.default_flow = 'n';
+
+       prop = of_get_property(np, "chr_1", NULL);
+       if (prop)
+               pdata.chr_1_val = *prop;
+
+       prop = of_get_property(np, "chr_2", NULL);
+       if (prop)
+               pdata.chr_2_val = *prop;
+
+       prop = of_get_property(np, "chr_10", NULL);
+       if (prop)
+               pdata.chr_10_val = *prop;
+
+       prop = of_get_property(np, "mpcr", NULL);
+       if (prop)
+               pdata.mpcr_val = *prop;
+
+       prop = of_get_property(brg, "bcr", NULL);
+       if (prop)
+               pdata.bcr_val = *prop;
+
+       pdata.brg_can_tune = 1; /* All current revs need this set */
+
+       prop = of_get_property(brg, "clock-src", NULL);
+       if (prop)
+               pdata.brg_clk_src = *prop;
+
+       prop = of_get_property(brg, "clock-frequency", NULL);
+       if (prop)
+               pdata.brg_clk_freq = *prop;
+
+       pdev = platform_device_alloc(MPSC_CTLR_NAME, port_number);
+       if (!pdev)
+               return -ENOMEM;
+
+       err = platform_device_add_resources(pdev, r, 5);
+       if (err)
+               goto error;
+
+       err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
+       if (err)
+               goto error;
+
+       err = platform_device_add(pdev);
+       if (err)
+               goto error;
+
+       return 0;
+
+error:
+       platform_device_put(pdev);
+       return err;
+}
+
+static int __init mv64x60_device_setup(void)
+{
+       struct device_node *np = NULL;
+       int id;
+       int err;
+
+       for (id = 0;
+            (np = of_find_compatible_node(np, "serial", "marvell,mpsc")); id++)
+               if ((err = mv64x60_mpsc_device_setup(np, id)))
+                       goto error;
+
+       return 0;
+
+error:
+       of_node_put(np);
+       return err;
+}
+arch_initcall(mv64x60_device_setup);