blob: fe42a212bb3ebfdc170dcdb5cee1e14f384849dd [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#include <linux/mtd/partitions.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#define WINDOW_ADDR 0x00000000 /* physical properties of flash */
21#define WINDOW_SIZE 0x01000000
22#define BUSWIDTH 2
23#define FLASH_BLOCKSIZE_MAIN 0x20000
24#define FLASH_NUMBLOCKS_MAIN 128
25/* can be "cfi_probe", "jedec_probe", "map_rom", NULL }; */
26#define PROBETYPES { "cfi_probe", NULL }
27
28#define MSG_PREFIX "EDB7312-NOR:" /* prefix for our printk()'s */
29#define MTDID "edb7312-nor" /* for mtdparts= partitioning */
30
31static struct mtd_info *mymtd;
32
33struct map_info edb7312nor_map = {
34 .name = "NOR flash on EDB7312",
35 .size = WINDOW_SIZE,
36 .bankwidth = BUSWIDTH,
37 .phys = WINDOW_ADDR,
38};
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040/*
Thomas Gleixner69f34c92005-11-07 11:15:40 +000041 * MTD partitioning stuff
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 */
43static struct mtd_partition static_partitions[3] =
44{
45 {
46 .name = "ARMboot",
47 .size = 0x40000,
48 .offset = 0
49 },
50 {
51 .name = "Kernel",
52 .size = 0x200000,
53 .offset = 0x40000
54 },
55 {
56 .name = "RootFS",
57 .size = 0xDC0000,
58 .offset = 0x240000
59 },
60};
61
62static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static int mtd_parts_nb = 0;
65static struct mtd_partition *mtd_parts = 0;
66
Dmitri Vorobievd8156ad2008-11-25 02:54:56 +020067static int __init init_edb7312nor(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 static const char *rom_probe_types[] = PROBETYPES;
70 const char **type;
71 const char *part_type = 0;
72
Thomas Gleixner69f34c92005-11-07 11:15:40 +000073 printk(KERN_NOTICE MSG_PREFIX "0x%08x at 0x%08x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 WINDOW_SIZE, WINDOW_ADDR);
75 edb7312nor_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
76
77 if (!edb7312nor_map.virt) {
78 printk(MSG_PREFIX "failed to ioremap\n");
79 return -EIO;
80 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +000081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 simple_map_init(&edb7312nor_map);
83
84 mymtd = 0;
85 type = rom_probe_types;
86 for(; !mymtd && *type; type++) {
87 mymtd = do_map_probe(*type, &edb7312nor_map);
88 }
89 if (mymtd) {
90 mymtd->owner = THIS_MODULE;
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 mtd_parts_nb = parse_mtd_partitions(mymtd, probes, &mtd_parts, MTDID);
93 if (mtd_parts_nb > 0)
Jamie Iles5af3aa22011-05-23 10:23:01 +010094 part_type = "detected";
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Jamie Iles5af3aa22011-05-23 10:23:01 +010096 if (mtd_parts_nb == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 mtd_parts = static_partitions;
98 mtd_parts_nb = ARRAY_SIZE(static_partitions);
99 part_type = "static";
100 }
Jamie Iles5af3aa22011-05-23 10:23:01 +0100101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 if (mtd_parts_nb == 0)
Jamie Iles5af3aa22011-05-23 10:23:01 +0100103 printk(KERN_NOTICE MSG_PREFIX "no partition info available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 printk(KERN_NOTICE MSG_PREFIX
106 "using %s partition definition\n", part_type);
Jamie Iles5af3aa22011-05-23 10:23:01 +0100107 /* Register the whole device first. */
108 mtd_device_register(mymtd, NULL, 0);
109 mtd_device_register(mymtd, mtd_parts, mtd_parts_nb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return 0;
111 }
112
113 iounmap((void *)edb7312nor_map.virt);
114 return -ENXIO;
115}
116
117static void __exit cleanup_edb7312nor(void)
118{
119 if (mymtd) {
Jamie Iles5af3aa22011-05-23 10:23:01 +0100120 mtd_device_unregister(mymtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 map_destroy(mymtd);
122 }
123 if (edb7312nor_map.virt) {
124 iounmap((void *)edb7312nor_map.virt);
125 edb7312nor_map.virt = 0;
126 }
127}
128
129module_init(init_edb7312nor);
130module_exit(cleanup_edb7312nor);
131
132MODULE_LICENSE("GPL");
133MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
134MODULE_DESCRIPTION("Generic configurable MTD map driver");