From: Mark A. Greer <mgr...@mvista.com>

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 <mgr...@mvista.com>
---

This patch replaces 1/16 v3.

It adds 'EXPORT_SYMBOL(davinci_get_soc_info);' to common.c
and nothing else.  The other v3 patches should apply fine
on top of this one.

 arch/arm/mach-davinci/Makefile              |    2 +-
 arch/arm/mach-davinci/board-dm355-evm.c     |    2 +-
 arch/arm/mach-davinci/board-dm355-leopard.c |    2 +-
 arch/arm/mach-davinci/board-dm644x-evm.c    |    2 +-
 arch/arm/mach-davinci/board-dm646x-evm.c    |    2 +-
 arch/arm/mach-davinci/board-sffsdr.c        |    2 +-
 arch/arm/mach-davinci/common.c              |   60 +++++++++++++++++++++++++++
 arch/arm/mach-davinci/dm355.c               |   18 ++++++++
 arch/arm/mach-davinci/dm644x.c              |   18 ++++++++
 arch/arm/mach-davinci/dm646x.c              |   18 ++++++++
 arch/arm/mach-davinci/include/mach/common.h |   11 ++++-
 arch/arm/mach-davinci/include/mach/dm355.h  |    3 +-
 arch/arm/mach-davinci/io.c                  |   38 -----------------
 13 files changed, 131 insertions(+), 47 deletions(-)
 create mode 100644 arch/arm/mach-davinci/common.c

diff --git a/arch/arm/mach-davinci/Makefile b/arch/arm/mach-davinci/Makefile
index 370a507..ca2ceef 100644
--- a/arch/arm/mach-davinci/Makefile
+++ b/arch/arm/mach-davinci/Makefile
@@ -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 usb.o dma.o iram.o
+                          gpio.o devices.o usb.o dma.o iram.o common.o
 
 obj-$(CONFIG_DAVINCI_MUX)              += mux.o
 
diff --git a/arch/arm/mach-davinci/board-dm355-evm.c 
b/arch/arm/mach-davinci/board-dm355-evm.c
index c2cf531..7faf452 100644
--- a/arch/arm/mach-davinci/board-dm355-evm.c
+++ b/arch/arm/mach-davinci/board-dm355-evm.c
@@ -38,6 +38,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
@@ -189,7 +190,6 @@ static struct davinci_uart_config uart_config __initdata = {
 
 static void __init dm355_evm_map_io(void)
 {
-       davinci_map_common_io();
        dm355_init();
 }
 
diff --git a/arch/arm/mach-davinci/board-dm355-leopard.c 
b/arch/arm/mach-davinci/board-dm355-leopard.c
index c29d30e..9568c2c 100644
--- a/arch/arm/mach-davinci/board-dm355-leopard.c
+++ b/arch/arm/mach-davinci/board-dm355-leopard.c
@@ -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_leopard_map_io(void)
 {
-       davinci_map_common_io();
        dm355_init();
 }
 
diff --git a/arch/arm/mach-davinci/board-dm644x-evm.c 
b/arch/arm/mach-davinci/board-dm644x-evm.c
index 384ad69..369440c 100644
--- a/arch/arm/mach-davinci/board-dm644x-evm.c
+++ b/arch/arm/mach-davinci/board-dm644x-evm.c
@@ -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 */
@@ -598,7 +599,6 @@ static struct davinci_uart_config uart_config __initdata = {
 static void __init
 davinci_evm_map_io(void)
 {
-       davinci_map_common_io();
        dm644x_init();
 }
 
diff --git a/arch/arm/mach-davinci/board-dm646x-evm.c 
b/arch/arm/mach-davinci/board-dm646x-evm.c
index 5dd3006..91d2c5a 100644
--- a/arch/arm/mach-davinci/board-dm646x-evm.c
+++ b/arch/arm/mach-davinci/board-dm646x-evm.c
@@ -39,6 +39,7 @@
 #include <mach/serial.h>
 #include <mach/i2c.h>
 #include <mach/mmc.h>
+#include <mach/common.h>
 
 #include <linux/platform_device.h>
 #include <linux/i2c.h>
@@ -122,7 +123,6 @@ static void __init evm_init_i2c(void)
 
 static void __init davinci_map_io(void)
 {
-       davinci_map_common_io();
        dm646x_init();
 }
 
diff --git a/arch/arm/mach-davinci/board-sffsdr.c 
b/arch/arm/mach-davinci/board-sffsdr.c
index 2589b0e..a663a20 100644
--- a/arch/arm/mach-davinci/board-sffsdr.c
+++ b/arch/arm/mach-davinci/board-sffsdr.c
@@ -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 */
@@ -155,7 +156,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
index 0000000..6af1f90
--- /dev/null
+++ b/arch/arm/mach-davinci/common.c
@@ -0,0 +1,60 @@
+/*
+ * Code commons to all DaVinci SoCs.
+ *
+ * Author: Mark A. Greer <mgr...@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>
+
+static struct davinci_soc_info davinci_soc_info;
+
+struct davinci_soc_info *davinci_get_soc_info(void)
+{
+       return &davinci_soc_info;
+}
+EXPORT_SYMBOL(davinci_get_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");
+}
diff --git a/arch/arm/mach-davinci/dm355.c b/arch/arm/mach-davinci/dm355.c
index 5f31649..4a6c429 100644
--- a/arch/arm/mach-davinci/dm355.c
+++ b/arch/arm/mach-davinci/dm355.c
@@ -16,6 +16,8 @@
 
 #include <linux/spi/spi.h>
 
+#include <asm/mach/map.h>
+
 #include <mach/dm355.h>
 #include <mach/clock.h>
 #include <mach/cpu.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));;
 }
diff --git a/arch/arm/mach-davinci/dm644x.c b/arch/arm/mach-davinci/dm644x.c
index 6a08568..a4a5c8b 100644
--- a/arch/arm/mach-davinci/dm644x.c
+++ b/arch/arm/mach-davinci/dm644x.c
@@ -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/cpu.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));
 }
diff --git a/arch/arm/mach-davinci/dm646x.c b/arch/arm/mach-davinci/dm646x.c
index b302f12..5b129d3 100644
--- a/arch/arm/mach-davinci/dm646x.c
+++ b/arch/arm/mach-davinci/dm646x.c
@@ -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/cpu.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));
 }
diff --git a/arch/arm/mach-davinci/include/mach/common.h 
b/arch/arm/mach-davinci/include/mach/common.h
index 1917709..4ce21c9 100644
--- a/arch/arm/mach-davinci/include/mach/common.h
+++ b/arch/arm/mach-davinci/include/mach/common.h
@@ -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,14 @@ 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_get_soc_info(void);
+extern void davinci_common_init(struct davinci_soc_info *soc_info);
+extern void davinci_check_revision(void);
+
 #endif /* __ARCH_ARM_MACH_DAVINCI_COMMON_H */
diff --git a/arch/arm/mach-davinci/include/mach/dm355.h 
b/arch/arm/mach-davinci/include/mach/dm355.h
index f7100b6..54903b7 100644
--- a/arch/arm/mach-davinci/include/mach/dm355.h
+++ b/arch/arm/mach-davinci/include/mach/dm355.h
@@ -13,10 +13,9 @@
 
 #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);
 
diff --git a/arch/arm/mach-davinci/io.c b/arch/arm/mach-davinci/io.c
index a548abb..49912b4 100644
--- a/arch/arm/mach-davinci/io.c
+++ b/arch/arm/mach-davinci/io.c
@@ -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)))
-- 
1.6.0.3


_______________________________________________
Davinci-linux-open-source mailing list
Davinci-linux-open-source@linux.davincidsp.com
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to