blob: be9e90b44587a45c7fce5be7659de52f7613dca9 [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 Cogent EDB7312 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_ADDR 0x00000000 /* physical properties of flash */
24#define WINDOW_SIZE 0x01000000
25#define BUSWIDTH 2
26#define FLASH_BLOCKSIZE_MAIN 0x20000
27#define FLASH_NUMBLOCKS_MAIN 128
28/* can be "cfi_probe", "jedec_probe", "map_rom", NULL }; */
29#define PROBETYPES { "cfi_probe", NULL }
30
31#define MSG_PREFIX "EDB7312-NOR:" /* prefix for our printk()'s */
32#define MTDID "edb7312-nor" /* for mtdparts= partitioning */
33
34static struct mtd_info *mymtd;
35
36struct map_info edb7312nor_map = {
37 .name = "NOR flash on EDB7312",
38 .size = WINDOW_SIZE,
39 .bankwidth = BUSWIDTH,
40 .phys = WINDOW_ADDR,
41};
42
43#ifdef CONFIG_MTD_PARTITIONS
44
45/*
Thomas Gleixner69f34c92005-11-07 11:15:40 +000046 * MTD partitioning stuff
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 */
48static struct mtd_partition static_partitions[3] =
49{
50 {
51 .name = "ARMboot",
52 .size = 0x40000,
53 .offset = 0
54 },
55 {
56 .name = "Kernel",
57 .size = 0x200000,
58 .offset = 0x40000
59 },
60 {
61 .name = "RootFS",
62 .size = 0xDC0000,
63 .offset = 0x240000
64 },
65};
66
67static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
68
69#endif
70
71static int mtd_parts_nb = 0;
72static struct mtd_partition *mtd_parts = 0;
73
Dmitri Vorobievd8156ad2008-11-25 02:54:56 +020074static int __init init_edb7312nor(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 static const char *rom_probe_types[] = PROBETYPES;
77 const char **type;
78 const char *part_type = 0;
79
Thomas Gleixner69f34c92005-11-07 11:15:40 +000080 printk(KERN_NOTICE MSG_PREFIX "0x%08x at 0x%08x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 WINDOW_SIZE, WINDOW_ADDR);
82 edb7312nor_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
83
84 if (!edb7312nor_map.virt) {
85 printk(MSG_PREFIX "failed to ioremap\n");
86 return -EIO;
87 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +000088
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 simple_map_init(&edb7312nor_map);
90
91 mymtd = 0;
92 type = rom_probe_types;
93 for(; !mymtd && *type; type++) {
94 mymtd = do_map_probe(*type, &edb7312nor_map);
95 }
96 if (mymtd) {
97 mymtd->owner = THIS_MODULE;
98
99#ifdef CONFIG_MTD_PARTITIONS
100 mtd_parts_nb = parse_mtd_partitions(mymtd, probes, &mtd_parts, MTDID);
101 if (mtd_parts_nb > 0)
102 part_type = "detected";
103
104 if (mtd_parts_nb == 0)
105 {
106 mtd_parts = static_partitions;
107 mtd_parts_nb = ARRAY_SIZE(static_partitions);
108 part_type = "static";
109 }
110#endif
111 add_mtd_device(mymtd);
112 if (mtd_parts_nb == 0)
113 printk(KERN_NOTICE MSG_PREFIX "no partition info available\n");
114 else
115 {
116 printk(KERN_NOTICE MSG_PREFIX
117 "using %s partition definition\n", part_type);
118 add_mtd_partitions(mymtd, mtd_parts, mtd_parts_nb);
119 }
120 return 0;
121 }
122
123 iounmap((void *)edb7312nor_map.virt);
124 return -ENXIO;
125}
126
127static void __exit cleanup_edb7312nor(void)
128{
129 if (mymtd) {
130 del_mtd_device(mymtd);
131 map_destroy(mymtd);
132 }
133 if (edb7312nor_map.virt) {
134 iounmap((void *)edb7312nor_map.virt);
135 edb7312nor_map.virt = 0;
136 }
137}
138
139module_init(init_edb7312nor);
140module_exit(cleanup_edb7312nor);
141
142MODULE_LICENSE("GPL");
143MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
144MODULE_DESCRIPTION("Generic configurable MTD map driver");