9c3785aa67c1aee6e44d64d9e3e90bcf8a38b561
[linux-flexiantxendom0-3.2.10.git] / drivers / mtd / maps / impa7.c
1 /*
2  * $Id: impa7.c,v 1.8 2003/05/21 12:45:18 dwmw2 Exp $
3  *
4  * Handle mapping of the NOR flash on implementa A7 boards
5  *
6  * Copyright 2002 SYSGO Real-Time Solutions GmbH
7  * 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <asm/io.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/map.h>
20 #include <linux/config.h>
21
22 #ifdef CONFIG_MTD_PARTITIONS
23 #include <linux/mtd/partitions.h>
24 #endif
25
26 #define WINDOW_ADDR0 0x00000000      /* physical properties of flash */
27 #define WINDOW_SIZE0 0x00800000
28 #define WINDOW_ADDR1 0x10000000      /* physical properties of flash */
29 #define WINDOW_SIZE1 0x00800000
30 #define NUM_FLASHBANKS 2
31 #define BUSWIDTH     4
32
33 /* can be { "cfi_probe", "jedec_probe", "map_rom", 0 }; */
34 #define PROBETYPES { "jedec_probe", 0 }
35
36 #define MSG_PREFIX "impA7:"   /* prefix for our printk()'s */
37 #define MTDID      "impa7-%d"  /* for mtdparts= partitioning */
38
39 static struct mtd_info *impa7_mtd[NUM_FLASHBANKS] = { 0 };
40
41
42 static struct map_info impa7_map[NUM_FLASHBANKS] = {
43         {
44                 .name = "impA7 NOR Flash Bank #0",
45                 .size = WINDOW_SIZE0,
46                 .buswidth = BUSWIDTH,
47         },
48         {
49                 .name = "impA7 NOR Flash Bank #1",
50                 .size = WINDOW_SIZE1,
51                 .buswidth = BUSWIDTH,
52         },
53 };
54
55 #ifdef CONFIG_MTD_PARTITIONS
56
57 /*
58  * MTD partitioning stuff 
59  */
60 static struct mtd_partition static_partitions[] =
61 {
62         {
63                 .name = "FileSystem",
64                 .size = 0x800000,
65                 .offset = 0x00000000
66         },
67 };
68
69 #define NB_OF(x) (sizeof (x) / sizeof (x[0]))
70
71 #endif
72
73 static int                   mtd_parts_nb = 0;
74 static struct mtd_partition *mtd_parts    = 0;
75 static const char *probes[] = { "cmdlinepart", NULL };
76
77 int __init init_impa7(void)
78 {
79         static const char *rom_probe_types[] = PROBETYPES;
80         const char **type;
81         const char *part_type = 0;
82         int i;
83         static struct { u_long addr; u_long size; } pt[NUM_FLASHBANKS] = {
84           { WINDOW_ADDR0, WINDOW_SIZE0 },
85           { WINDOW_ADDR1, WINDOW_SIZE1 },
86         };
87         char mtdid[10];
88         int devicesfound = 0;
89
90         for(i=0; i<NUM_FLASHBANKS; i++)
91         {
92                 printk(KERN_NOTICE MSG_PREFIX "probing 0x%08lx at 0x%08lx\n",
93                        pt[i].size, pt[i].addr);
94
95                 impa7_map[i].phys = pt[i].addr;
96                 impa7_map[i].virt = (unsigned long)
97                   ioremap(pt[i].addr, pt[i].size);
98                 if (!impa7_map[i].virt) {
99                         printk(MSG_PREFIX "failed to ioremap\n");
100                         return -EIO;
101                 }
102                 simple_map_init(&impa7_map[i]);
103
104                 impa7_mtd[i] = 0;
105                 type = rom_probe_types;
106                 for(; !impa7_mtd[i] && *type; type++) {
107                         impa7_mtd[i] = do_map_probe(*type, &impa7_map[i]);
108                 }
109
110                 if (impa7_mtd[i]) 
111                 {
112                         impa7_mtd[i]->owner = THIS_MODULE;
113                         add_mtd_device(impa7_mtd[i]);
114                         devicesfound++;
115 #ifdef CONFIG_MTD_PARTITIONS
116                         mtd_parts_nb = parse_mtd_partitions(impa7_mtd[i], 
117                                                             probes,
118                                                             &mtd_parts, 
119                                                             0);
120                         if (mtd_parts_nb > 0)
121                           part_type = "command line";
122 #endif
123                         if (mtd_parts_nb <= 0)
124                         {
125                                 mtd_parts = static_partitions;
126                                 mtd_parts_nb = NB_OF(static_partitions);
127                                 part_type = "static";
128                         }
129                         if (mtd_parts_nb <= 0)
130                         {
131                                 printk(KERN_NOTICE MSG_PREFIX 
132                                        "no partition info available\n");
133                         }
134                         else
135                         {
136                                 printk(KERN_NOTICE MSG_PREFIX
137                                        "using %s partition definition\n", 
138                                        part_type);
139                                 add_mtd_partitions(impa7_mtd[i], 
140                                                    mtd_parts, mtd_parts_nb);
141                         }
142 #endif
143                 }
144                 else 
145                   iounmap((void *)impa7_map[i].virt);
146         }
147         return devicesfound == 0 ? -ENXIO : 0;
148 }
149
150 static void __exit cleanup_impa7(void)
151 {
152         int i;
153         for (i=0; i<NUM_FLASHBANKS; i++) 
154         {
155                 if (impa7_mtd[i]) 
156                 {
157                         del_mtd_device(impa7_mtd[i]);
158                         map_destroy(impa7_mtd[i]);
159                 }
160                 if (impa7_map[i].virt)
161                 {
162                         iounmap((void *)impa7_map[i].virt);
163                         impa7_map[i].virt = 0;
164                 }
165         }
166 }
167
168 module_init(init_impa7);
169 module_exit(cleanup_impa7);
170
171 MODULE_LICENSE("GPL");
172 MODULE_AUTHOR("Pavel Bartusek <pba@sysgo.de>");
173 MODULE_DESCRIPTION("MTD map driver for implementa impA7");