[adm5120] change switch register access macros
[openwrt.git] / target / linux / adm5120 / files / drivers / mtd / maps / adm5120-flash.c
index 0a2590e..b84492f 100644 (file)
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/io.h>
 #include <linux/device.h>
-
 #include <linux/platform_device.h>
+
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/map.h>
 #include <linux/mtd/partitions.h>
 
-#include <asm/io.h>
-
-#include <asm/mach-adm5120/adm5120_defs.h>
-#include <asm/mach-adm5120/adm5120_switch.h>
-#include <asm/mach-adm5120/adm5120_mpmc.h>
-#include <asm/mach-adm5120/adm5120_platform.h>
+#include <adm5120_defs.h>
+#include <adm5120_switch.h>
+#include <adm5120_mpmc.h>
+#include <adm5120_platform.h>
 
 #define DRV_NAME       "adm5120-flash"
 #define DRV_DESC       "ADM5120 flash MAP driver"
@@ -78,7 +77,6 @@ struct adm5120_flash_info {
 struct flash_desc {
        u32     phys;
        u32     srs_shift;
-       u32     mpmc_reg;
 };
 
 /*
@@ -98,11 +96,9 @@ static u32 flash_sizes[8] = {
 static struct flash_desc flash_descs[2] = {
        {
                .phys           = ADM5120_SRAM0_BASE,
-               .mpmc_reg       = MPMC_REG_SC1,
                .srs_shift      = MEMCTRL_SRS0_SHIFT,
        }, {
                .phys           = ADM5120_SRAM1_BASE,
-               .mpmc_reg       = MPMC_REG_SC0,
                .srs_shift      = MEMCTRL_SRS1_SHIFT,
        }
 };
@@ -176,7 +172,7 @@ static void adm5120_flash_write(struct map_info *map, const map_word datum,
 {
        struct adm5120_map_info *amap = map_to_amap(map);
 
-       MAP_DBG(map,"writing to ofs %lX\n", ofs);
+       MAP_DBG(map, "writing to ofs %lX\n", ofs);
 
        if (ofs > amap->window_size)
                return;
@@ -224,14 +220,15 @@ static int adm5120_flash_initres(struct adm5120_flash_info *info)
        struct map_info *map = &info->amap.map;
        int err = 0;
 
-       info->res = request_mem_region(map->phys, map->size, map->name);
+       info->res = request_mem_region(map->phys, info->amap.window_size,
+                       map->name);
        if (info->res == NULL) {
                MAP_ERR(map, "could not reserve memory region\n");
                err = -ENOMEM;
                goto out;
        }
 
-       map->virt = ioremap_nocache(map->phys, map->size);
+       map->virt = ioremap_nocache(map->phys, info->amap.window_size);
        if (map->virt == NULL) {
                MAP_ERR(map, "failed to ioremap flash region\n");
                err = -ENOMEM;
@@ -242,18 +239,13 @@ out:
        return err;
 }
 
-#define SWITCH_READ(r) *(u32 *)(KSEG1ADDR(ADM5120_SWITCH_BASE)+(r))
-#define SWITCH_WRITE(r,v) *(u32 *)(KSEG1ADDR(ADM5120_SWITCH_BASE)+(r))=(v)
-#define MPMC_READ(r) *(u32 *)(KSEG1ADDR(ADM5120_MPMC_BASE)+(r))
-#define MPMC_WRITE(r,v) *(u32 *)(KSEG1ADDR(ADM5120_MPMC_BASE)+(r))=(v)
-
 static int adm5120_flash_initinfo(struct adm5120_flash_info *info,
                struct platform_device *dev)
 {
        struct map_info *map = &info->amap.map;
        struct adm5120_flash_platform_data *pdata = dev->dev.platform_data;
        struct flash_desc *fdesc;
-       u32 t;
+       u32 t = 0;
 
        map->name = dev->dev.bus_id;
 
@@ -264,17 +256,30 @@ static int adm5120_flash_initinfo(struct adm5120_flash_info *info,
 
        fdesc = &flash_descs[dev->id];
 
-       /* get memory window size */
-       t = SWITCH_READ(SWITCH_REG_MEMCTRL) >> fdesc->srs_shift;
-       t &= MEMCTRL_SRS_MASK;
-       info->amap.window_size = flash_sizes[t];
+       if (pdata)
+               info->amap.window_size = pdata->window_size;
+
        if (info->amap.window_size == 0) {
-               MAP_ERR(map, "invalid flash size detected\n");
+               /* get memory window size */
+               t = SW_READ_REG(SWITCH_REG_MEMCTRL) >> fdesc->srs_shift;
+               t &= MEMCTRL_SRS_MASK;
+               info->amap.window_size = flash_sizes[t];
+       }
+
+       if (info->amap.window_size == 0) {
+               MAP_ERR(map, "unable to determine window size\n");
                goto err_out;
        }
 
        /* get flash bus width */
-       t = MPMC_READ(fdesc->mpmc_reg) & SC_MW_MASK;
+       switch (dev->id) {
+       case 0:
+               t = MPMC_READ_REG(SC1) & SC_MW_MASK;
+               break;
+       case 1:
+               t = MPMC_READ_REG(SC0) & SC_MW_MASK;
+               break;
+       }
        map->bankwidth = flash_bankwidths[t];
        if (map->bankwidth == 0) {
                MAP_ERR(map, "invalid bus width detected\n");
@@ -330,7 +335,7 @@ static void adm5120_flash_initbanks(struct adm5120_flash_info *info)
 #ifdef CONFIG_MTD_PARTITIONS
 static int adm5120_flash_initparts(struct adm5120_flash_info *info)
 {
-       struct adm5120_flash_platform_data *pdata = info->dev->dev.platform_data;
+       struct adm5120_flash_platform_data *pdata;
        struct map_info *map = &info->amap.map;
        int num_parsers;
        const char *parser[2];
@@ -340,6 +345,7 @@ static int adm5120_flash_initparts(struct adm5120_flash_info *info)
 
        info->nr_parts = 0;
 
+       pdata = info->dev->dev.platform_data;
        if (pdata == NULL)
                goto out;
 
@@ -358,7 +364,7 @@ static int adm5120_flash_initparts(struct adm5120_flash_info *info)
                num_parsers = MAX_PARSED_PARTS;
 
        parser[1] = NULL;
-       for (i=0; i<num_parsers; i++) {
+       for (i = 0; i < num_parsers; i++) {
                parser[0] = parse_types[i];
 
                MAP_INFO(map, "parsing \"%s\" partitions\n",
@@ -395,7 +401,7 @@ static void adm5120_flash_remove_mtd(struct adm5120_flash_info *info)
 
        if (info->nr_parts) {
                del_mtd_partitions(info->mtd);
-               for (i=0; i<MAX_PARSED_PARTS; i++)
+               for (i = 0; i < MAX_PARSED_PARTS; i++)
                        if (info->parts[i] != NULL)
                                kfree(info->parts[i]);
        } else {
@@ -497,7 +503,8 @@ static int adm5120_flash_probe(struct platform_device *dev)
                goto err_out;
 
        if (info->nr_parts == 0) {
-               MAP_INFO(map, "no partitions available, registering whole flash\n");
+               MAP_INFO(map, "no partitions available, registering "
+                       "whole flash\n");
                add_mtd_device(info->mtd);
        }
 
@@ -509,7 +516,8 @@ err_out:
 }
 
 #ifdef CONFIG_PM
-static int adm5120_flash_suspend(struct platform_device *dev, pm_message_t state)
+static int adm5120_flash_suspend(struct platform_device *dev,
+               pm_message_t state)
 {
        struct adm5120_flash_info *info = platform_get_drvdata(dev);
        int ret = 0;
This page took 0.02942 seconds and 4 git commands to generate.