Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Handle mapping of the NOR flash on implementa A7 boards
0004  *
0005  * Copyright 2002 SYSGO Real-Time Solutions GmbH
0006  */
0007 
0008 #include <linux/module.h>
0009 #include <linux/types.h>
0010 #include <linux/kernel.h>
0011 #include <linux/init.h>
0012 #include <asm/io.h>
0013 #include <linux/mtd/mtd.h>
0014 #include <linux/mtd/map.h>
0015 #include <linux/mtd/partitions.h>
0016 
0017 #define WINDOW_ADDR0 0x00000000      /* physical properties of flash */
0018 #define WINDOW_SIZE0 0x00800000
0019 #define WINDOW_ADDR1 0x10000000      /* physical properties of flash */
0020 #define WINDOW_SIZE1 0x00800000
0021 #define NUM_FLASHBANKS 2
0022 #define BUSWIDTH     4
0023 
0024 #define MSG_PREFIX "impA7:"   /* prefix for our printk()'s */
0025 #define MTDID      "impa7-%d"  /* for mtdparts= partitioning */
0026 
0027 static struct mtd_info *impa7_mtd[NUM_FLASHBANKS];
0028 
0029 static const char * const rom_probe_types[] = { "jedec_probe", NULL };
0030 
0031 static struct map_info impa7_map[NUM_FLASHBANKS] = {
0032     {
0033         .name = "impA7 NOR Flash Bank #0",
0034         .size = WINDOW_SIZE0,
0035         .bankwidth = BUSWIDTH,
0036     },
0037     {
0038         .name = "impA7 NOR Flash Bank #1",
0039         .size = WINDOW_SIZE1,
0040         .bankwidth = BUSWIDTH,
0041     },
0042 };
0043 
0044 /*
0045  * MTD partitioning stuff
0046  */
0047 static const struct mtd_partition partitions[] =
0048 {
0049     {
0050         .name = "FileSystem",
0051         .size = 0x800000,
0052         .offset = 0x00000000
0053     },
0054 };
0055 
0056 static int __init init_impa7(void)
0057 {
0058     const char * const *type;
0059     int i;
0060     static struct { u_long addr; u_long size; } pt[NUM_FLASHBANKS] = {
0061       { WINDOW_ADDR0, WINDOW_SIZE0 },
0062       { WINDOW_ADDR1, WINDOW_SIZE1 },
0063         };
0064     int devicesfound = 0;
0065 
0066     for(i=0; i<NUM_FLASHBANKS; i++)
0067     {
0068         printk(KERN_NOTICE MSG_PREFIX "probing 0x%08lx at 0x%08lx\n",
0069                pt[i].size, pt[i].addr);
0070 
0071         impa7_map[i].phys = pt[i].addr;
0072         impa7_map[i].virt = ioremap(pt[i].addr, pt[i].size);
0073         if (!impa7_map[i].virt) {
0074             printk(MSG_PREFIX "failed to ioremap\n");
0075             return -EIO;
0076         }
0077         simple_map_init(&impa7_map[i]);
0078 
0079         impa7_mtd[i] = NULL;
0080         type = rom_probe_types;
0081         for(; !impa7_mtd[i] && *type; type++) {
0082             impa7_mtd[i] = do_map_probe(*type, &impa7_map[i]);
0083         }
0084 
0085         if (impa7_mtd[i]) {
0086             impa7_mtd[i]->owner = THIS_MODULE;
0087             devicesfound++;
0088             mtd_device_register(impa7_mtd[i], partitions,
0089                         ARRAY_SIZE(partitions));
0090         } else {
0091             iounmap((void __iomem *)impa7_map[i].virt);
0092         }
0093     }
0094     return devicesfound == 0 ? -ENXIO : 0;
0095 }
0096 
0097 static void __exit cleanup_impa7(void)
0098 {
0099     int i;
0100     for (i=0; i<NUM_FLASHBANKS; i++) {
0101         if (impa7_mtd[i]) {
0102             mtd_device_unregister(impa7_mtd[i]);
0103             map_destroy(impa7_mtd[i]);
0104             iounmap((void __iomem *)impa7_map[i].virt);
0105             impa7_map[i].virt = NULL;
0106         }
0107     }
0108 }
0109 
0110 module_init(init_impa7);
0111 module_exit(cleanup_impa7);
0112 
0113 MODULE_LICENSE("GPL");
0114 MODULE_AUTHOR("Pavel Bartusek <pba@sysgo.de>");
0115 MODULE_DESCRIPTION("MTD map driver for implementa impA7");