2 * $Id: edb7312.c,v 1.2 2002/09/05 05:11:24 acurtis Exp $
4 * Handle mapping of the NOR flash on Cogent EDB7312 boards
6 * Copyright 2002 SYSGO Real-Time Solutions GmbH
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.
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
17 #include <linux/mtd/mtd.h>
18 #include <linux/mtd/map.h>
19 #include <linux/config.h>
21 #ifdef CONFIG_MTD_PARTITIONS
22 #include <linux/mtd/partitions.h>
25 #define WINDOW_ADDR 0x00000000 /* physical properties of flash */
26 #define WINDOW_SIZE 0x01000000
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 }
33 #define MSG_PREFIX "EDB7312-NOR:" /* prefix for our printk()'s */
34 #define MTDID "edb7312-nor" /* for mtdparts= partitioning */
36 static struct mtd_info *mymtd;
38 __u8 edb7312nor_read8(struct map_info *map, unsigned long ofs)
40 return __raw_readb(map->map_priv_1 + ofs);
43 __u16 edb7312nor_read16(struct map_info *map, unsigned long ofs)
45 return __raw_readw(map->map_priv_1 + ofs);
48 __u32 edb7312nor_read32(struct map_info *map, unsigned long ofs)
50 return __raw_readl(map->map_priv_1 + ofs);
53 void edb7312nor_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
55 memcpy_fromio(to, map->map_priv_1 + from, len);
58 void edb7312nor_write8(struct map_info *map, __u8 d, unsigned long adr)
60 __raw_writeb(d, map->map_priv_1 + adr);
64 void edb7312nor_write16(struct map_info *map, __u16 d, unsigned long adr)
66 __raw_writew(d, map->map_priv_1 + adr);
70 void edb7312nor_write32(struct map_info *map, __u32 d, unsigned long adr)
72 __raw_writel(d, map->map_priv_1 + adr);
76 void edb7312nor_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
78 memcpy_toio(map->map_priv_1 + to, from, len);
81 struct map_info edb7312nor_map = {
82 name: "NOR flash on EDB7312",
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
95 #ifdef CONFIG_MTD_PARTITIONS
98 * MTD partitioning stuff
100 static struct mtd_partition static_partitions[3] =
119 #define NB_OF(x) (sizeof (x) / sizeof (x[0]))
121 #ifdef CONFIG_MTD_CMDLINE_PARTS
122 int parse_cmdline_partitions(struct mtd_info *master,
123 struct mtd_partition **pparts,
129 static int mtd_parts_nb = 0;
130 static struct mtd_partition *mtd_parts = 0;
132 int __init init_edb7312nor(void)
134 static const char *rom_probe_types[] = PROBETYPES;
136 const char *part_type = 0;
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);
143 if (!edb7312nor_map.map_priv_1) {
144 printk(MSG_PREFIX "failed to ioremap\n");
149 type = rom_probe_types;
150 for(; !mymtd && *type; type++) {
151 mymtd = do_map_probe(*type, &edb7312nor_map);
154 mymtd->module = THIS_MODULE;
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";
162 if (mtd_parts_nb == 0)
164 mtd_parts = static_partitions;
165 mtd_parts_nb = NB_OF(static_partitions);
166 part_type = "static";
169 add_mtd_device(mymtd);
170 if (mtd_parts_nb == 0)
171 printk(KERN_NOTICE MSG_PREFIX "no partition info available\n");
174 printk(KERN_NOTICE MSG_PREFIX
175 "using %s partition definition\n", part_type);
176 add_mtd_partitions(mymtd, mtd_parts, mtd_parts_nb);
181 iounmap((void *)edb7312nor_map.map_priv_1);
185 static void __exit cleanup_edb7312nor(void)
188 del_mtd_device(mymtd);
191 if (edb7312nor_map.map_priv_1) {
192 iounmap((void *)edb7312nor_map.map_priv_1);
193 edb7312nor_map.map_priv_1 = 0;
197 module_init(init_edb7312nor);
198 module_exit(cleanup_edb7312nor);
200 MODULE_LICENSE("GPL");
201 MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
202 MODULE_DESCRIPTION("Generic configurable MTD map driver");