at91: factorize sram init
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Mon, 9 May 2011 19:20:09 +0000 (03:20 +0800)
committerArnd Bergmann <arnd@arndb.de>
Thu, 28 Jul 2011 15:07:29 +0000 (15:07 +0000)
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: Patrice Vilchez <patrice.vilchez@atmel.com>
arch/arm/mach-at91/at91cap9.c
arch/arm/mach-at91/at91rm9200.c
arch/arm/mach-at91/at91sam9260.c
arch/arm/mach-at91/at91sam9261.c
arch/arm/mach-at91/at91sam9263.c
arch/arm/mach-at91/at91sam9g45.c
arch/arm/mach-at91/at91sam9rl.c
arch/arm/mach-at91/generic.h
arch/arm/mach-at91/setup.c

index 8fabf91fe2e509ffb328ee7408372685c8bce5c1..bfc684441ef8db534154c15e05ac3f08de50ada7 100644 (file)
 #include "generic.h"
 #include "clock.h"
 
-static struct map_desc at91cap9_sram_desc[] __initdata = {
-       {
-               .virtual        = AT91_IO_VIRT_BASE - AT91CAP9_SRAM_SIZE,
-               .pfn            = __phys_to_pfn(AT91CAP9_SRAM_BASE),
-               .length         = AT91CAP9_SRAM_SIZE,
-               .type           = MT_DEVICE,
-       },
-};
-
 /* --------------------------------------------------------------------
  *  Clocks
  * -------------------------------------------------------------------- */
@@ -337,7 +328,7 @@ static void at91cap9_poweroff(void)
 
 static void __init at91cap9_map_io(void)
 {
-       iotable_init(at91cap9_sram_desc, ARRAY_SIZE(at91cap9_sram_desc));
+       at91_init_sram(0, AT91CAP9_SRAM_BASE, AT91CAP9_SRAM_SIZE);
 }
 
 static void __init at91cap9_initialize(void)
index 010407802cdc9ad6ddf441acb665b598b74d8a5f..f73302dbc6a547272624bee244224aa2fa06e520 100644 (file)
@@ -30,11 +30,6 @@ static struct map_desc at91rm9200_io_desc[] __initdata = {
                .pfn            = __phys_to_pfn(AT91RM9200_BASE_EMAC),
                .length         = SZ_16K,
                .type           = MT_DEVICE,
-       }, {
-               .virtual        = AT91_IO_VIRT_BASE - AT91RM9200_SRAM_SIZE,
-               .pfn            = __phys_to_pfn(AT91RM9200_SRAM_BASE),
-               .length         = AT91RM9200_SRAM_SIZE,
-               .type           = MT_DEVICE,
        },
 };
 
@@ -306,6 +301,7 @@ static void at91rm9200_reset(void)
 static void __init at91rm9200_map_io(void)
 {
        /* Map peripherals */
+       at91_init_sram(0, AT91RM9200_SRAM_BASE, AT91RM9200_SRAM_SIZE);
        iotable_init(at91rm9200_io_desc, ARRAY_SIZE(at91rm9200_io_desc));
 }
 
index 1addfef73b6c2f4d8eacd5b5eba9bebe92010cf9..cb397be14448eaa767ddbfd94bdf4fbdf8c25254 100644 (file)
 #include "generic.h"
 #include "clock.h"
 
-static struct map_desc at91sam9260_sram_desc[] __initdata = {
-       {
-               .virtual        = AT91_IO_VIRT_BASE - AT91SAM9260_SRAM0_SIZE,
-               .pfn            = __phys_to_pfn(AT91SAM9260_SRAM0_BASE),
-               .length         = AT91SAM9260_SRAM0_SIZE,
-               .type           = MT_DEVICE,
-       }, {
-               .virtual        = AT91_IO_VIRT_BASE - AT91SAM9260_SRAM0_SIZE - AT91SAM9260_SRAM1_SIZE,
-               .pfn            = __phys_to_pfn(AT91SAM9260_SRAM1_BASE),
-               .length         = AT91SAM9260_SRAM1_SIZE,
-               .type           = MT_DEVICE,
-       }
-};
-
-static struct map_desc at91sam9g20_sram_desc[] __initdata = {
-       {
-               .virtual        = AT91_IO_VIRT_BASE - AT91SAM9G20_SRAM0_SIZE,
-               .pfn            = __phys_to_pfn(AT91SAM9G20_SRAM0_BASE),
-               .length         = AT91SAM9G20_SRAM0_SIZE,
-               .type           = MT_DEVICE,
-       }, {
-               .virtual        = AT91_IO_VIRT_BASE - AT91SAM9G20_SRAM0_SIZE - AT91SAM9G20_SRAM1_SIZE,
-               .pfn            = __phys_to_pfn(AT91SAM9G20_SRAM1_BASE),
-               .length         = AT91SAM9G20_SRAM1_SIZE,
-               .type           = MT_DEVICE,
-       }
-};
-
-static struct map_desc at91sam9xe_sram_desc[] __initdata = {
-       {
-               .pfn            = __phys_to_pfn(AT91SAM9XE_SRAM_BASE),
-               .type           = MT_DEVICE,
-       }
-};
-
 /* --------------------------------------------------------------------
  *  Clocks
  * -------------------------------------------------------------------- */
@@ -334,20 +299,20 @@ static void __init at91sam9xe_map_io(void)
                        sram_size = SZ_16K;
        }
 
-       at91sam9xe_sram_desc->virtual = AT91_IO_VIRT_BASE - sram_size;
-       at91sam9xe_sram_desc->length = sram_size;
-
-       iotable_init(at91sam9xe_sram_desc, ARRAY_SIZE(at91sam9xe_sram_desc));
+       at91_init_sram(0, AT91SAM9XE_SRAM_BASE, sram_size);
 }
 
 static void __init at91sam9260_map_io(void)
 {
-       if (cpu_is_at91sam9xe())
+       if (cpu_is_at91sam9xe()) {
                at91sam9xe_map_io();
-       else if (cpu_is_at91sam9g20())
-               iotable_init(at91sam9g20_sram_desc, ARRAY_SIZE(at91sam9g20_sram_desc));
-       else
-               iotable_init(at91sam9260_sram_desc, ARRAY_SIZE(at91sam9260_sram_desc));
+       } else if (cpu_is_at91sam9g20()) {
+               at91_init_sram(0, AT91SAM9G20_SRAM0_BASE, AT91SAM9G20_SRAM0_SIZE);
+               at91_init_sram(1, AT91SAM9G20_SRAM1_BASE, AT91SAM9G20_SRAM1_SIZE);
+       } else {
+               at91_init_sram(0, AT91SAM9260_SRAM0_BASE, AT91SAM9260_SRAM0_SIZE);
+               at91_init_sram(1, AT91SAM9260_SRAM1_BASE, AT91SAM9260_SRAM1_SIZE);
+       }
 }
 
 static void __init at91sam9260_initialize(void)
index 8f97bd4a5268e9924989e463c61ab503e3f08f58..d522b47e30b5a82322da83f6fed63d7d110dab5a 100644 (file)
 #include "generic.h"
 #include "clock.h"
 
-static struct map_desc at91sam9261_sram_desc[] __initdata = {
-       {
-               .virtual        = AT91_IO_VIRT_BASE - AT91SAM9261_SRAM_SIZE,
-               .pfn            = __phys_to_pfn(AT91SAM9261_SRAM_BASE),
-               .length         = AT91SAM9261_SRAM_SIZE,
-               .type           = MT_DEVICE,
-       },
-};
-
-static struct map_desc at91sam9g10_sram_desc[] __initdata = {
-       {
-               .virtual        = AT91_IO_VIRT_BASE - AT91SAM9G10_SRAM_SIZE,
-               .pfn            = __phys_to_pfn(AT91SAM9G10_SRAM_BASE),
-               .length         = AT91SAM9G10_SRAM_SIZE,
-               .type           = MT_DEVICE,
-       },
-};
-
 /* --------------------------------------------------------------------
  *  Clocks
  * -------------------------------------------------------------------- */
@@ -297,9 +279,9 @@ static void at91sam9261_poweroff(void)
 static void __init at91sam9261_map_io(void)
 {
        if (cpu_is_at91sam9g10())
-               iotable_init(at91sam9g10_sram_desc, ARRAY_SIZE(at91sam9g10_sram_desc));
+               at91_init_sram(0, AT91SAM9G10_SRAM_BASE, AT91SAM9G10_SRAM_SIZE);
        else
-               iotable_init(at91sam9261_sram_desc, ARRAY_SIZE(at91sam9261_sram_desc));
+               at91_init_sram(0, AT91SAM9261_SRAM_BASE, AT91SAM9261_SRAM_SIZE);
 }
 
 static void __init at91sam9261_initialize(void)
index da13f02acf5176b0008a5a1cb061cab9a8c0766e..044f3c927e64723e6ef8f6733ef90b386ebaecb7 100644 (file)
 #include "generic.h"
 #include "clock.h"
 
-static struct map_desc at91sam9263_sram_desc[] __initdata = {
-       {
-               .virtual        = AT91_IO_VIRT_BASE - AT91SAM9263_SRAM0_SIZE,
-               .pfn            = __phys_to_pfn(AT91SAM9263_SRAM0_BASE),
-               .length         = AT91SAM9263_SRAM0_SIZE,
-               .type           = MT_DEVICE,
-       }, {
-               .virtual        = AT91_IO_VIRT_BASE - AT91SAM9263_SRAM0_SIZE - AT91SAM9263_SRAM1_SIZE,
-               .pfn            = __phys_to_pfn(AT91SAM9263_SRAM1_BASE),
-               .length         = AT91SAM9263_SRAM1_SIZE,
-               .type           = MT_DEVICE,
-       },
-};
-
 /* --------------------------------------------------------------------
  *  Clocks
  * -------------------------------------------------------------------- */
@@ -311,7 +297,8 @@ static void at91sam9263_poweroff(void)
 
 static void __init at91sam9263_map_io(void)
 {
-       iotable_init(at91sam9263_sram_desc, ARRAY_SIZE(at91sam9263_sram_desc));
+       at91_init_sram(0, AT91SAM9263_SRAM0_BASE, AT91SAM9263_SRAM0_SIZE);
+       at91_init_sram(1, AT91SAM9263_SRAM1_BASE, AT91SAM9263_SRAM1_SIZE);
 }
 
 static void __init at91sam9263_initialize(void)
index cbc06451a45f61c836274994276993fbfc698dd8..e04c5fb6f1ee36bd4e652dc3640f776fd31a9bf4 100644 (file)
 #include "generic.h"
 #include "clock.h"
 
-static struct map_desc at91sam9g45_sram_desc[] __initdata = {
-       {
-               .virtual        = AT91_IO_VIRT_BASE - AT91SAM9G45_SRAM_SIZE,
-               .pfn            = __phys_to_pfn(AT91SAM9G45_SRAM_BASE),
-               .length         = AT91SAM9G45_SRAM_SIZE,
-               .type           = MT_DEVICE,
-       }
-};
-
 /* --------------------------------------------------------------------
  *  Clocks
  * -------------------------------------------------------------------- */
@@ -327,7 +318,7 @@ static void at91sam9g45_poweroff(void)
 
 static void __init at91sam9g45_map_io(void)
 {
-       iotable_init(at91sam9g45_sram_desc, ARRAY_SIZE(at91sam9g45_sram_desc));
+       at91_init_sram(0, AT91SAM9G45_SRAM_BASE, AT91SAM9G45_SRAM_SIZE);
 }
 
 static void __init at91sam9g45_initialize(void)
index 55ee7d0a9bf4beb4db17454402950c56f32085a4..a238105d2c11dabb385c7f8bbbcfa20be87b2982 100644 (file)
 #include "generic.h"
 #include "clock.h"
 
-static struct map_desc at91sam9rl_sram_desc[] __initdata = {
-       {
-               .pfn            = __phys_to_pfn(AT91SAM9RL_SRAM_BASE),
-               .type           = MT_DEVICE,
-       }
-};
-
 /* --------------------------------------------------------------------
  *  Clocks
  * -------------------------------------------------------------------- */
@@ -293,11 +286,8 @@ static void __init at91sam9rl_map_io(void)
                        sram_size = SZ_16K;
        }
 
-       at91sam9rl_sram_desc->virtual = AT91_IO_VIRT_BASE - sram_size;
-       at91sam9rl_sram_desc->length = sram_size;
-
        /* Map SRAM */
-       iotable_init(at91sam9rl_sram_desc, ARRAY_SIZE(at91sam9rl_sram_desc));
+       at91_init_sram(0, AT91SAM9RL_SRAM_BASE, sram_size);
 }
 
 static void __init at91sam9rl_initialize(void)
index a9d6ed4dbbc881a2dddbbad4e1cdf33bbfb2ea1a..938b34f577419b9dba43f466c3d59dfe4b73fe69 100644 (file)
@@ -12,6 +12,8 @@
 
  /* Map io */
 extern void __init at91_map_io(void);
+extern void __init at91_init_sram(int bank, unsigned long base,
+                                 unsigned int length);
 
  /* Processors */
 extern void __init at91rm9200_set_type(int type);
index 43251efd90d408836e0138fd0bcf0a5f04ac25ac..816599fce55b783e145203538661edc86188c8af 100644 (file)
@@ -45,6 +45,26 @@ void __init at91_init_interrupts(unsigned int *priority)
        at91_gpio_irq_setup();
 }
 
+static struct map_desc sram_desc[2] __initdata;
+
+void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
+{
+       struct map_desc *desc = &sram_desc[bank];
+
+       desc->virtual = AT91_IO_VIRT_BASE - length;
+       if (bank > 0)
+               desc->virtual -= sram_desc[bank - 1].length;
+
+       desc->pfn = __phys_to_pfn(base);
+       desc->length = length;
+       desc->type = MT_DEVICE;
+
+       pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
+               base, length, desc->virtual);
+
+       iotable_init(desc, 1);
+}
+
 static struct map_desc at91_io_desc __initdata = {
        .virtual        = AT91_VA_BASE_SYS,
        .pfn            = __phys_to_pfn(AT91_BASE_SYS),