davinci: Encapsulate SoC-specific data in a structure
authorMark A. Greer <mgreer@mvista.com>
Wed, 15 Apr 2009 19:38:58 +0000 (12:38 -0700)
committerKevin Hilman <khilman@deeprootsystems.com>
Tue, 26 May 2009 15:14:04 +0000 (08:14 -0700)
Create a structure to encapsulate SoC-specific information.
This will assist in generalizing code so it can be used by
different SoCs that have similar hardware but with minor
differences such as having a different base address.

The idea is that the code for each SoC fills out a structure
with the correct information.  The board-specific code then
calls the SoC init routine which in turn will call a common
init routine that makes a copy of the structure, maps in I/O
regions, etc.

After initialization, code can get a pointer to the structure
by calling davinci_get_soc_info().  Eventually, the common
init routine will make a copy of all of the data pointed to
by the structure so the original data can be made __init_data.
That way the data for SoC's that aren't being used won't consume
memory for the entire life of the kernel.

The structure will be extended in subsequent patches but
initially, it holds the map_desc structure for any I/O
regions the SoC/board wants statically mapped.

Signed-off-by: Mark A. Greer <mgreer@mvista.com>
Signed-off-by: Kevin Hilman <khilman@deeprootsystems.com>
13 files changed:
arch/arm/mach-davinci/Makefile
arch/arm/mach-davinci/board-dm355-evm.c
arch/arm/mach-davinci/board-dm355-leopard.c
arch/arm/mach-davinci/board-dm644x-evm.c
arch/arm/mach-davinci/board-dm646x-evm.c
arch/arm/mach-davinci/board-sffsdr.c
arch/arm/mach-davinci/common.c [new file with mode: 0644]
arch/arm/mach-davinci/dm355.c
arch/arm/mach-davinci/dm644x.c
arch/arm/mach-davinci/dm646x.c
arch/arm/mach-davinci/include/mach/common.h
arch/arm/mach-davinci/include/mach/dm355.h
arch/arm/mach-davinci/io.c

index 2873149da7f024ce9d737973fe12a7cb9fa6068e..74d25f69934e32eebd32c2ce46b2325f277036a0 100644 (file)
@@ -5,7 +5,7 @@
 
 # Common objects
 obj-y                  := time.o irq.o clock.o serial.o io.o id.o psc.o \
-                          gpio.o devices.o dma.o usb.o
+                          gpio.o devices.o dma.o usb.o common.o
 
 obj-$(CONFIG_DAVINCI_MUX)              += mux.o
 obj-$(CONFIG_CP_INTC)                  += cp_intc.o
index 087441313dd715dcd1e544ec727433df6ddcdc63..5ac2f565d860e934df9a52de72a4294c1b0f7fb3 100644 (file)
@@ -37,6 +37,7 @@
 #include <mach/serial.h>
 #include <mach/nand.h>
 #include <mach/mmc.h>
+#include <mach/common.h>
 
 #define DAVINCI_ASYNC_EMIF_CONTROL_BASE                0x01e10000
 #define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE       0x02000000
@@ -188,7 +189,6 @@ static struct davinci_uart_config uart_config __initdata = {
 
 static void __init dm355_evm_map_io(void)
 {
-       davinci_map_common_io();
        dm355_init();
 }
 
index d4562f5ff93bddba6bf001af1ff7529c0972a926..28c9008df4f45f1cd43879a83958d69845886485 100644 (file)
@@ -36,6 +36,7 @@
 #include <mach/serial.h>
 #include <mach/nand.h>
 #include <mach/mmc.h>
+#include <mach/common.h>
 
 #define DAVINCI_ASYNC_EMIF_CONTROL_BASE                0x01e10000
 #define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE       0x02000000
@@ -187,7 +188,6 @@ static struct davinci_uart_config uart_config __initdata = {
 
 static void __init dm355_leopard_map_io(void)
 {
-       davinci_map_common_io();
        dm355_init();
 }
 
index 02e7cdaf8daa9793c56e14a9a369552acf88efb1..cfe89c409735ce407bf29e5c85c963d034cbb1b9 100644 (file)
@@ -45,6 +45,7 @@
 #include <mach/psc.h>
 #include <mach/nand.h>
 #include <mach/mmc.h>
+#include <mach/common.h>
 
 #define DM644X_EVM_PHY_MASK            (0x2)
 #define DM644X_EVM_MDIO_FREQUENCY      (2200000) /* PHY bus frequency */
@@ -609,7 +610,6 @@ static struct davinci_uart_config uart_config __initdata = {
 static void __init
 davinci_evm_map_io(void)
 {
-       davinci_map_common_io();
        dm644x_init();
 }
 
index aedde3cdb82f6667b2d6eeb04cdd91aa9b256257..becae51d6dd114dc3e332307e602e265228d1fd0 100644 (file)
@@ -47,6 +47,7 @@
 #include <mach/i2c.h>
 #include <mach/mmc.h>
 #include <mach/emac.h>
+#include <mach/common.h>
 
 #define DM646X_EVM_PHY_MASK            (0x2)
 #define DM646X_EVM_MDIO_FREQUENCY      (2200000) /* PHY bus frequency */
@@ -265,7 +266,6 @@ static void __init evm_init_i2c(void)
 
 static void __init davinci_map_io(void)
 {
-       davinci_map_common_io();
        dm646x_init();
 }
 
index 913dad93540b84cb709795f6243bd2ec627d472e..938b4467809ec68096418c2febc1d367cc9d32f2 100644 (file)
@@ -53,6 +53,7 @@
 #include <mach/serial.h>
 #include <mach/psc.h>
 #include <mach/mux.h>
+#include <mach/common.h>
 
 #define SFFSDR_PHY_MASK                (0x2)
 #define SFFSDR_MDIO_FREQUENCY  (2200000) /* PHY bus frequency */
@@ -152,7 +153,6 @@ static struct davinci_uart_config uart_config __initdata = {
 
 static void __init davinci_sffsdr_map_io(void)
 {
-       davinci_map_common_io();
        dm644x_init();
 }
 
diff --git a/arch/arm/mach-davinci/common.c b/arch/arm/mach-davinci/common.c
new file mode 100644 (file)
index 0000000..9a5486f
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Code commons to all DaVinci SoCs.
+ *
+ * Author: Mark A. Greer <mgreer@mvista.com>
+ *
+ * 2009 (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/module.h>
+#include <linux/io.h>
+
+#include <asm/tlb.h>
+#include <asm/mach/map.h>
+
+#include <mach/common.h>
+
+struct davinci_soc_info davinci_soc_info;
+EXPORT_SYMBOL(davinci_soc_info);
+
+void __init davinci_common_init(struct davinci_soc_info *soc_info)
+{
+       int ret;
+
+       if (!soc_info) {
+               ret = -EINVAL;
+               goto err;
+       }
+
+       memcpy(&davinci_soc_info, soc_info, sizeof(struct davinci_soc_info));
+
+       if (davinci_soc_info.io_desc && (davinci_soc_info.io_desc_num > 0))
+               iotable_init(davinci_soc_info.io_desc,
+                               davinci_soc_info.io_desc_num);
+
+       /*
+        * Normally devicemaps_init() would flush caches and tlb after
+        * mdesc->map_io(), but we must also do it here because of the CPU
+        * revision check below.
+        */
+       local_flush_tlb_all();
+       flush_cache_all();
+
+       /*
+        * We want to check CPU revision early for cpu_is_xxxx() macros.
+        * IO space mapping must be initialized before we can do that.
+        */
+       davinci_check_revision();
+
+       return;
+
+err:
+       pr_err("davinci_common_init: SoC Initialization failed\n");
+}
index c02115f1eb9bc42934924ad15d3468073d0bd4ac..6d1abfdcfb72716fd41771d218f8840492e73fd5 100644 (file)
@@ -16,6 +16,8 @@
 
 #include <linux/spi/spi.h>
 
+#include <asm/mach/map.h>
+
 #include <mach/dm355.h>
 #include <mach/clock.h>
 #include <mach/cputype.h>
@@ -23,6 +25,7 @@
 #include <mach/psc.h>
 #include <mach/mux.h>
 #include <mach/irqs.h>
+#include <mach/common.h>
 
 #include "clock.h"
 #include "mux.h"
@@ -522,8 +525,23 @@ static struct platform_device dm355_edma_device = {
 
 /*----------------------------------------------------------------------*/
 
+static struct map_desc dm355_io_desc[] = {
+       {
+               .virtual        = IO_VIRT,
+               .pfn            = __phys_to_pfn(IO_PHYS),
+               .length         = IO_SIZE,
+               .type           = MT_DEVICE
+       },
+};
+
+static struct davinci_soc_info davinci_soc_info_dm355 = {
+       .io_desc                = dm355_io_desc,
+       .io_desc_num            = ARRAY_SIZE(dm355_io_desc),
+};
+
 void __init dm355_init(void)
 {
+       davinci_common_init(&davinci_soc_info_dm355);
        davinci_clk_init(dm355_clks);
        davinci_mux_register(dm355_pins, ARRAY_SIZE(dm355_pins));;
 }
index 0419d571bdcac13f43f205c31eaa44440726db0a..79f113698b0bd7aeb55a11c9b0e5905b07bf833b 100644 (file)
@@ -13,6 +13,8 @@
 #include <linux/clk.h>
 #include <linux/platform_device.h>
 
+#include <asm/mach/map.h>
+
 #include <mach/dm644x.h>
 #include <mach/clock.h>
 #include <mach/cputype.h>
@@ -20,6 +22,7 @@
 #include <mach/irqs.h>
 #include <mach/psc.h>
 #include <mach/mux.h>
+#include <mach/common.h>
 
 #include "clock.h"
 #include "mux.h"
@@ -463,8 +466,23 @@ void dm644x_init_emac(struct emac_platform_data *unused) {}
 
 #endif
 
+static struct map_desc dm644x_io_desc[] = {
+       {
+               .virtual        = IO_VIRT,
+               .pfn            = __phys_to_pfn(IO_PHYS),
+               .length         = IO_SIZE,
+               .type           = MT_DEVICE
+       },
+};
+
+static struct davinci_soc_info davinci_soc_info_dm644x = {
+       .io_desc                = dm644x_io_desc,
+       .io_desc_num            = ARRAY_SIZE(dm644x_io_desc),
+};
+
 void __init dm644x_init(void)
 {
+       davinci_common_init(&davinci_soc_info_dm644x);
        davinci_clk_init(dm644x_clks);
        davinci_mux_register(dm644x_pins, ARRAY_SIZE(dm644x_pins));
 }
index 975ed062ce244806b0441eb8323a29e2179b8c7b..8547ec02c9e19041088e89b24535cee2ab30fa28 100644 (file)
@@ -13,6 +13,8 @@
 #include <linux/clk.h>
 #include <linux/platform_device.h>
 
+#include <asm/mach/map.h>
+
 #include <mach/dm646x.h>
 #include <mach/clock.h>
 #include <mach/cputype.h>
@@ -20,6 +22,7 @@
 #include <mach/irqs.h>
 #include <mach/psc.h>
 #include <mach/mux.h>
+#include <mach/common.h>
 
 #include "clock.h"
 #include "mux.h"
@@ -442,8 +445,23 @@ void dm646x_init_emac(struct emac_platform_data *unused) {}
 
 #endif
 
+static struct map_desc dm646x_io_desc[] = {
+       {
+               .virtual        = IO_VIRT,
+               .pfn            = __phys_to_pfn(IO_PHYS),
+               .length         = IO_SIZE,
+               .type           = MT_DEVICE
+       },
+};
+
+static struct davinci_soc_info davinci_soc_info_dm646x = {
+       .io_desc                = dm646x_io_desc,
+       .io_desc_num            = ARRAY_SIZE(dm646x_io_desc),
+};
+
 void __init dm646x_init(void)
 {
+       davinci_common_init(&davinci_soc_info_dm646x);
        davinci_clk_init(dm646x_clks);
        davinci_mux_register(dm646x_pins, ARRAY_SIZE(dm646x_pins));
 }
index 1917709762507c01d54dcd14be933e94e4c8b9a4..770a1baa97dc42b99f1acf47bdfd9528584265ec 100644 (file)
@@ -17,7 +17,6 @@ struct sys_timer;
 extern struct sys_timer davinci_timer;
 
 extern void davinci_irq_init(void);
-extern void davinci_map_common_io(void);
 
 /* parameters describe VBUS sourcing for host mode */
 extern void setup_usb(unsigned mA, unsigned potpgt_msec);
@@ -25,4 +24,15 @@ extern void setup_usb(unsigned mA, unsigned potpgt_msec);
 /* parameters describe VBUS sourcing for host mode */
 extern void setup_usb(unsigned mA, unsigned potpgt_msec);
 
+/* SoC specific init support */
+struct davinci_soc_info {
+       struct map_desc                 *io_desc;
+       unsigned long                   io_desc_num;
+};
+
+extern struct davinci_soc_info davinci_soc_info;
+
+extern void davinci_common_init(struct davinci_soc_info *soc_info);
+extern void davinci_check_revision(void);
+
 #endif /* __ARCH_ARM_MACH_DAVINCI_COMMON_H */
index f7100b658992ef764c8cf514490cb079ca108c15..54903b72438e2484e87cd188c64cc426aedf5568 100644 (file)
 
 #include <mach/hardware.h>
 
-void __init dm355_init(void);
-
 struct spi_board_info;
 
+void __init dm355_init(void);
 void dm355_init_spi0(unsigned chipselect_mask,
                struct spi_board_info *info, unsigned len);
 
index a548abb513e2d559108a53184cb5abaa90c9df09..49912b48b1b0f7a26c2b65729686687f84bb460a 100644 (file)
@@ -9,47 +9,9 @@
  */
 
 #include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/init.h>
 #include <linux/io.h>
 
 #include <asm/tlb.h>
-#include <asm/memory.h>
-
-#include <asm/mach/map.h>
-#include <mach/clock.h>
-
-extern void davinci_check_revision(void);
-
-/*
- * The machine specific code may provide the extra mapping besides the
- * default mapping provided here.
- */
-static struct map_desc davinci_io_desc[] __initdata = {
-       {
-               .virtual        = IO_VIRT,
-               .pfn            = __phys_to_pfn(IO_PHYS),
-               .length         = IO_SIZE,
-               .type           = MT_DEVICE
-       },
-};
-
-void __init davinci_map_common_io(void)
-{
-       iotable_init(davinci_io_desc, ARRAY_SIZE(davinci_io_desc));
-
-       /* Normally devicemaps_init() would flush caches and tlb after
-        * mdesc->map_io(), but we must also do it here because of the CPU
-        * revision check below.
-        */
-       local_flush_tlb_all();
-       flush_cache_all();
-
-       /* We want to check CPU revision early for cpu_is_xxxx() macros.
-        * IO space mapping must be initialized before we can do that.
-        */
-       davinci_check_revision();
-}
 
 #define BETWEEN(p, st, sz)     ((p) >= (st) && (p) < ((st) + (sz)))
 #define XLATE(p, pst, vst)     ((void __iomem *)((p) - (pst) + (vst)))