From: Mark A. Greer <[email protected]>

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 can
then modify anything in that structure before calling a
common init routine that makes a copy of the structure,
maps in I/O regions, etc.  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 occupy space 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 <[email protected]>
---
 arch/arm/mach-davinci/Makefile              |    2 +-
 arch/arm/mach-davinci/board-dm355-evm.c     |   10 ++++-
 arch/arm/mach-davinci/board-dm355-leopard.c |   10 ++++-
 arch/arm/mach-davinci/board-dm644x-evm.c    |   10 ++++-
 arch/arm/mach-davinci/board-dm646x-evm.c    |   10 ++++-
 arch/arm/mach-davinci/board-sffsdr.c        |   10 ++++-
 arch/arm/mach-davinci/common.c              |   59 +++++++++++++++++++++++++++
 arch/arm/mach-davinci/dm355.c               |   17 ++++++++
 arch/arm/mach-davinci/dm644x.c              |   17 ++++++++
 arch/arm/mach-davinci/dm646x.c              |   17 ++++++++
 arch/arm/mach-davinci/include/mach/common.h |   11 +++++-
 arch/arm/mach-davinci/include/mach/dm355.h  |    1 +
 arch/arm/mach-davinci/include/mach/dm644x.h |    2 +
 arch/arm/mach-davinci/include/mach/dm646x.h |    2 +
 arch/arm/mach-davinci/io.c                  |   39 ------------------
 15 files changed, 166 insertions(+), 51 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..f882028 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,8 +190,13 @@ static struct davinci_uart_config uart_config __initdata = 
{
 
 static void __init dm355_evm_map_io(void)
 {
-       davinci_map_common_io();
-       dm355_init();
+       int ret;
+
+       ret = davinci_common_init(&davinci_soc_info_dm355);
+       if (ret)
+               pr_err("SoC Initialization failed\n");
+       else
+               dm355_init();
 }
 
 static int dm355evm_mmc_get_cd(int module)
diff --git a/arch/arm/mach-davinci/board-dm355-leopard.c 
b/arch/arm/mach-davinci/board-dm355-leopard.c
index c29d30e..dedbe3a 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,8 +189,13 @@ static struct davinci_uart_config uart_config __initdata = 
{
 
 static void __init dm355_leopard_map_io(void)
 {
-       davinci_map_common_io();
-       dm355_init();
+       int ret;
+
+       ret = davinci_common_init(&davinci_soc_info_dm355);
+       if (ret)
+               pr_err("SoC Initialization failed\n");
+       else
+               dm355_init();
 }
 
 static int dm355leopard_mmc_get_cd(int module)
diff --git a/arch/arm/mach-davinci/board-dm644x-evm.c 
b/arch/arm/mach-davinci/board-dm644x-evm.c
index 384ad69..de3617c 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,8 +599,13 @@ static struct davinci_uart_config uart_config __initdata = 
{
 static void __init
 davinci_evm_map_io(void)
 {
-       davinci_map_common_io();
-       dm644x_init();
+       int ret;
+
+       ret = davinci_common_init(&davinci_soc_info_dm644x);
+       if (ret)
+               pr_err("SoC Initialization failed\n");
+       else
+               dm644x_init();
 }
 
 static int davinci_phy_fixup(struct phy_device *phydev)
diff --git a/arch/arm/mach-davinci/board-dm646x-evm.c 
b/arch/arm/mach-davinci/board-dm646x-evm.c
index 7321d5e..30ce97c 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>
@@ -123,8 +124,13 @@ static void __init evm_init_i2c(void)
 
 static void __init davinci_map_io(void)
 {
-       davinci_map_common_io();
-       dm646x_init();
+       int ret;
+
+       ret = davinci_common_init(&davinci_soc_info_dm646x);
+       if (ret)
+               pr_err("SoC Initialization failed\n");
+       else
+               dm646x_init();
 }
 
 static __init void evm_init(void)
diff --git a/arch/arm/mach-davinci/board-sffsdr.c 
b/arch/arm/mach-davinci/board-sffsdr.c
index 2589b0e..13e6cb5 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,8 +156,13 @@ static struct davinci_uart_config uart_config __initdata = 
{
 
 static void __init davinci_sffsdr_map_io(void)
 {
-       davinci_map_common_io();
-       dm644x_init();
+       int ret;
+
+       ret = davinci_common_init(&davinci_soc_info_dm644x);
+       if (ret)
+               pr_err("SoC Initialization failed\n");
+       else
+               dm644x_init();
 }
 
 static __init void davinci_sffsdr_init(void)
diff --git a/arch/arm/mach-davinci/common.c b/arch/arm/mach-davinci/common.c
new file mode 100644
index 0000000..151d09b
--- /dev/null
+++ b/arch/arm/mach-davinci/common.c
@@ -0,0 +1,59 @@
+/*
+ * Code commons to all DaVinci SoCs.
+ *
+ * Author: Mark A. Greer <[email protected]>
+ *
+ * 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;
+}
+
+int __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 0;
+
+err:
+       return ret;
+}
diff --git a/arch/arm/mach-davinci/dm355.c b/arch/arm/mach-davinci/dm355.c
index 5f31649..b04a32d 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,6 +525,20 @@ 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
+       },
+};
+
+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_clk_init(dm355_clks);
diff --git a/arch/arm/mach-davinci/dm644x.c b/arch/arm/mach-davinci/dm644x.c
index 6a08568..6142b72 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,6 +466,20 @@ 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
+       },
+};
+
+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_clk_init(dm644x_clks);
diff --git a/arch/arm/mach-davinci/dm646x.c b/arch/arm/mach-davinci/dm646x.c
index b302f12..347ceb6 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,6 +445,20 @@ 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
+       },
+};
+
+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_clk_init(dm646x_clks);
diff --git a/arch/arm/mach-davinci/include/mach/common.h 
b/arch/arm/mach-davinci/include/mach/common.h
index 1917709..be21767 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 int 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..60de381 100644
--- a/arch/arm/mach-davinci/include/mach/dm355.h
+++ b/arch/arm/mach-davinci/include/mach/dm355.h
@@ -16,6 +16,7 @@
 void __init dm355_init(void);
 
 struct spi_board_info;
+extern struct davinci_soc_info davinci_soc_info_dm355;
 
 void dm355_init_spi0(unsigned chipselect_mask,
                struct spi_board_info *info, unsigned len);
diff --git a/arch/arm/mach-davinci/include/mach/dm644x.h 
b/arch/arm/mach-davinci/include/mach/dm644x.h
index ace167a..7bc0313 100644
--- a/arch/arm/mach-davinci/include/mach/dm644x.h
+++ b/arch/arm/mach-davinci/include/mach/dm644x.h
@@ -36,4 +36,6 @@
 void __init dm644x_init(void);
 void dm644x_init_emac(struct emac_platform_data *pdata);
 
+extern struct davinci_soc_info davinci_soc_info_dm644x;
+
 #endif /* __ASM_ARCH_DM644X_H */
diff --git a/arch/arm/mach-davinci/include/mach/dm646x.h 
b/arch/arm/mach-davinci/include/mach/dm646x.h
index 02ce872..4541b4e 100644
--- a/arch/arm/mach-davinci/include/mach/dm646x.h
+++ b/arch/arm/mach-davinci/include/mach/dm646x.h
@@ -25,4 +25,6 @@
 void __init dm646x_init(void);
 void dm646x_init_emac(struct emac_platform_data *pdata);
 
+extern struct davinci_soc_info davinci_soc_info_dm646x;
+
 #endif /* __ASM_ARCH_DM646X_H */
diff --git a/arch/arm/mach-davinci/io.c b/arch/arm/mach-davinci/io.c
index 5f77af7..49912b4 100644
--- a/arch/arm/mach-davinci/io.c
+++ b/arch/arm/mach-davinci/io.c
@@ -9,48 +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>
-#include <mach/mux.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
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to