special usb hub handling, IDE disks, and retries all over the place
[linux-2.4.git] / drivers / mtd / maps / edb7312.c
1 /*
2  * $Id: edb7312.c,v 1.2 2002/09/05 05:11:24 acurtis Exp $
3  *
4  * Handle mapping of the NOR flash on Cogent EDB7312 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 <asm/io.h>
17 #include <linux/mtd/mtd.h>
18 #include <linux/mtd/map.h>
19 #include <linux/config.h>
20
21 #ifdef CONFIG_MTD_PARTITIONS
22 #include <linux/mtd/partitions.h>
23 #endif
24
25 #define WINDOW_ADDR 0x00000000      /* physical properties of flash */
26 #define WINDOW_SIZE 0x01000000
27 #define BUSWIDTH    2
28 #define FLASH_BLOCKSIZE_MAIN    0x20000
29 #define FLASH_NUMBLOCKS_MAIN    128
30 /* can be "cfi_probe", "jedec_probe", "map_rom", 0 }; */
31 #define PROBETYPES { "cfi_probe", 0 }
32
33 #define MSG_PREFIX "EDB7312-NOR:"   /* prefix for our printk()'s */
34 #define MTDID      "edb7312-nor"    /* for mtdparts= partitioning */
35
36 static struct mtd_info *mymtd;
37
38 __u8 edb7312nor_read8(struct map_info *map, unsigned long ofs)
39 {
40         return __raw_readb(map->map_priv_1 + ofs);
41 }
42
43 __u16 edb7312nor_read16(struct map_info *map, unsigned long ofs)
44 {
45         return __raw_readw(map->map_priv_1 + ofs);
46 }
47
48 __u32 edb7312nor_read32(struct map_info *map, unsigned long ofs)
49 {
50         return __raw_readl(map->map_priv_1 + ofs);
51 }
52
53 void edb7312nor_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
54 {
55         memcpy_fromio(to, map->map_priv_1 + from, len);
56 }
57
58 void edb7312nor_write8(struct map_info *map, __u8 d, unsigned long adr)
59 {
60         __raw_writeb(d, map->map_priv_1 + adr);
61         mb();
62 }
63
64 void edb7312nor_write16(struct map_info *map, __u16 d, unsigned long adr)
65 {
66         __raw_writew(d, map->map_priv_1 + adr);
67         mb();
68 }
69
70 void edb7312nor_write32(struct map_info *map, __u32 d, unsigned long adr)
71 {
72         __raw_writel(d, map->map_priv_1 + adr);
73         mb();
74 }
75
76 void edb7312nor_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
77 {
78         memcpy_toio(map->map_priv_1 + to, from, len);
79 }
80
81 struct map_info edb7312nor_map = {
82         name: "NOR flash on EDB7312",
83         size: WINDOW_SIZE,
84         buswidth: BUSWIDTH,
85         read8: edb7312nor_read8,
86         read16: edb7312nor_read16,
87         read32: edb7312nor_read32,
88         copy_from: edb7312nor_copy_from,
89         write8: edb7312nor_write8,
90         write16: edb7312nor_write16,
91         write32: edb7312nor_write32,
92         copy_to: edb7312nor_copy_to
93 };
94
95 #ifdef CONFIG_MTD_PARTITIONS
96
97 /*
98  * MTD partitioning stuff 
99  */
100 static struct mtd_partition static_partitions[3] =
101 {
102     {
103         name: "ARMboot",
104           size: 0x40000,
105           offset: 0
106     },
107     {
108         name: "Kernel",
109           size: 0x200000,
110           offset: 0x40000
111     },
112     {
113         name: "RootFS",
114           size: 0xDC0000,
115           offset: 0x240000
116     },
117 };
118
119 #define NB_OF(x) (sizeof (x) / sizeof (x[0]))
120
121 #ifdef CONFIG_MTD_CMDLINE_PARTS
122 int parse_cmdline_partitions(struct mtd_info *master, 
123                              struct mtd_partition **pparts,
124                              const char *mtd_id);
125 #endif
126
127 #endif
128
129 static int                   mtd_parts_nb = 0;
130 static struct mtd_partition *mtd_parts    = 0;
131
132 int __init init_edb7312nor(void)
133 {
134         static const char *rom_probe_types[] = PROBETYPES;
135         const char **type;
136         const char *part_type = 0;
137
138         printk(KERN_NOTICE MSG_PREFIX "0x%08x at 0x%08x\n", 
139                WINDOW_SIZE, WINDOW_ADDR);
140         edb7312nor_map.map_priv_1 = (unsigned long)
141           ioremap(WINDOW_ADDR, WINDOW_SIZE);
142
143         if (!edb7312nor_map.map_priv_1) {
144                 printk(MSG_PREFIX "failed to ioremap\n");
145                 return -EIO;
146         }
147
148         mymtd = 0;
149         type = rom_probe_types;
150         for(; !mymtd && *type; type++) {
151                 mymtd = do_map_probe(*type, &edb7312nor_map);
152         }
153         if (mymtd) {
154                 mymtd->module = THIS_MODULE;
155
156 #ifdef CONFIG_MTD_PARTITIONS
157 #ifdef CONFIG_MTD_CMDLINE_PARTS
158                 mtd_parts_nb = parse_cmdline_partitions(mymtd, &mtd_parts, MTDID);
159                 if (mtd_parts_nb > 0)
160                   part_type = "command line";
161 #endif
162                 if (mtd_parts_nb == 0)
163                 {
164                         mtd_parts = static_partitions;
165                         mtd_parts_nb = NB_OF(static_partitions);
166                         part_type = "static";
167                 }
168 #endif
169                 add_mtd_device(mymtd);
170                 if (mtd_parts_nb == 0)
171                   printk(KERN_NOTICE MSG_PREFIX "no partition info available\n");
172                 else
173                 {
174                         printk(KERN_NOTICE MSG_PREFIX
175                                "using %s partition definition\n", part_type);
176                         add_mtd_partitions(mymtd, mtd_parts, mtd_parts_nb);
177                 }
178                 return 0;
179         }
180
181         iounmap((void *)edb7312nor_map.map_priv_1);
182         return -ENXIO;
183 }
184
185 static void __exit cleanup_edb7312nor(void)
186 {
187         if (mymtd) {
188                 del_mtd_device(mymtd);
189                 map_destroy(mymtd);
190         }
191         if (edb7312nor_map.map_priv_1) {
192                 iounmap((void *)edb7312nor_map.map_priv_1);
193                 edb7312nor_map.map_priv_1 = 0;
194         }
195 }
196
197 module_init(init_edb7312nor);
198 module_exit(cleanup_edb7312nor);
199
200 MODULE_LICENSE("GPL");
201 MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
202 MODULE_DESCRIPTION("Generic configurable MTD map driver");