blob: 2682ab51a36786732fdd08b83b8cde83f331ad62 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Handle mapping of the NOR flash on implementa A7 boards
3 *
4 * Copyright 2002 SYSGO Real-Time Solutions GmbH
Thomas Gleixner69f34c92005-11-07 11:15:40 +00005 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/module.h>
12#include <linux/types.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <asm/io.h>
16#include <linux/mtd/mtd.h>
17#include <linux/mtd/map.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#ifdef CONFIG_MTD_PARTITIONS
20#include <linux/mtd/partitions.h>
21#endif
22
23#define WINDOW_ADDR0 0x00000000 /* physical properties of flash */
24#define WINDOW_SIZE0 0x00800000
25#define WINDOW_ADDR1 0x10000000 /* physical properties of flash */
26#define WINDOW_SIZE1 0x00800000
27#define NUM_FLASHBANKS 2
28#define BUSWIDTH 4
29
30/* can be { "cfi_probe", "jedec_probe", "map_rom", NULL } */
31#define PROBETYPES { "jedec_probe", NULL }
32
33#define MSG_PREFIX "impA7:" /* prefix for our printk()'s */
34#define MTDID "impa7-%d" /* for mtdparts= partitioning */
35
36static struct mtd_info *impa7_mtd[NUM_FLASHBANKS];
37
38
39static struct map_info impa7_map[NUM_FLASHBANKS] = {
40 {
41 .name = "impA7 NOR Flash Bank #0",
42 .size = WINDOW_SIZE0,
43 .bankwidth = BUSWIDTH,
44 },
45 {
46 .name = "impA7 NOR Flash Bank #1",
47 .size = WINDOW_SIZE1,
48 .bankwidth = BUSWIDTH,
49 },
50};
51
52#ifdef CONFIG_MTD_PARTITIONS
53
54/*
Thomas Gleixner69f34c92005-11-07 11:15:40 +000055 * MTD partitioning stuff
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 */
57static struct mtd_partition static_partitions[] =
58{
59 {
60 .name = "FileSystem",
61 .size = 0x800000,
62 .offset = 0x00000000
63 },
64};
65
66static int mtd_parts_nb[NUM_FLASHBANKS];
67static struct mtd_partition *mtd_parts[NUM_FLASHBANKS];
68
69#endif
70
71static const char *probes[] = { "cmdlinepart", NULL };
72
73int __init init_impa7(void)
74{
75 static const char *rom_probe_types[] = PROBETYPES;
76 const char **type;
77 const char *part_type = 0;
78 int i;
79 static struct { u_long addr; u_long size; } pt[NUM_FLASHBANKS] = {
80 { WINDOW_ADDR0, WINDOW_SIZE0 },
81 { WINDOW_ADDR1, WINDOW_SIZE1 },
82 };
83 int devicesfound = 0;
84
85 for(i=0; i<NUM_FLASHBANKS; i++)
86 {
87 printk(KERN_NOTICE MSG_PREFIX "probing 0x%08lx at 0x%08lx\n",
88 pt[i].size, pt[i].addr);
89
90 impa7_map[i].phys = pt[i].addr;
91 impa7_map[i].virt = ioremap(pt[i].addr, pt[i].size);
92 if (!impa7_map[i].virt) {
93 printk(MSG_PREFIX "failed to ioremap\n");
94 return -EIO;
95 }
96 simple_map_init(&impa7_map[i]);
97
98 impa7_mtd[i] = 0;
99 type = rom_probe_types;
100 for(; !impa7_mtd[i] && *type; type++) {
101 impa7_mtd[i] = do_map_probe(*type, &impa7_map[i]);
102 }
103
104 if (impa7_mtd[i]) {
105 impa7_mtd[i]->owner = THIS_MODULE;
106 devicesfound++;
107#ifdef CONFIG_MTD_PARTITIONS
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000108 mtd_parts_nb[i] = parse_mtd_partitions(impa7_mtd[i],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 probes,
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000110 &mtd_parts[i],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 0);
112 if (mtd_parts_nb[i] > 0) {
113 part_type = "command line";
114 } else {
115 mtd_parts[i] = static_partitions;
116 mtd_parts_nb[i] = ARRAY_SIZE(static_partitions);
117 part_type = "static";
118 }
119
120 printk(KERN_NOTICE MSG_PREFIX
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000121 "using %s partition definition\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 part_type);
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000123 add_mtd_partitions(impa7_mtd[i],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 mtd_parts[i], mtd_parts_nb[i]);
125#else
126 add_mtd_device(impa7_mtd[i]);
127
128#endif
129 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000130 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 iounmap((void *)impa7_map[i].virt);
132 }
133 return devicesfound == 0 ? -ENXIO : 0;
134}
135
136static void __exit cleanup_impa7(void)
137{
138 int i;
139 for (i=0; i<NUM_FLASHBANKS; i++) {
140 if (impa7_mtd[i]) {
141#ifdef CONFIG_MTD_PARTITIONS
142 del_mtd_partitions(impa7_mtd[i]);
143#else
144 del_mtd_device(impa7_mtd[i]);
145#endif
146 map_destroy(impa7_mtd[i]);
147 iounmap((void *)impa7_map[i].virt);
148 impa7_map[i].virt = 0;
149 }
150 }
151}
152
153module_init(init_impa7);
154module_exit(cleanup_impa7);
155
156MODULE_LICENSE("GPL");
157MODULE_AUTHOR("Pavel Bartusek <pba@sysgo.de>");
158MODULE_DESCRIPTION("MTD map driver for implementa impA7");