blob: aa7e0cb2893c791311e71356ec79d074745129a6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Map for flash chips on Wind River PowerQUICC II SBC82xx board.
3 *
4 * Copyright (C) 2004 Red Hat, Inc.
5 *
6 * Author: David Woodhouse <dwmw2@infradead.org>
7 *
8 */
9
10#include <linux/module.h>
11#include <linux/types.h>
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/slab.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>
19
20#include <asm/immap_cpm2.h>
21
22static struct mtd_info *sbcmtd[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24struct map_info sbc82xx_flash_map[3] = {
25 {.name = "Boot flash"},
26 {.name = "Alternate boot flash"},
27 {.name = "User flash"}
28};
29
30static struct mtd_partition smallflash_parts[] = {
31 {
32 .name = "space",
33 .size = 0x100000,
34 .offset = 0,
35 }, {
36 .name = "bootloader",
37 .size = MTDPART_SIZ_FULL,
38 .offset = MTDPART_OFS_APPEND,
39 }
40};
41
42static struct mtd_partition bigflash_parts[] = {
43 {
44 .name = "bootloader",
45 .size = 0x00100000,
46 .offset = 0,
47 }, {
48 .name = "file system",
49 .size = 0x01f00000,
50 .offset = MTDPART_OFS_APPEND,
51 }, {
52 .name = "boot config",
53 .size = 0x00100000,
54 .offset = MTDPART_OFS_APPEND,
55 }, {
56 .name = "space",
57 .size = 0x01f00000,
58 .offset = MTDPART_OFS_APPEND,
59 }
60};
61
62static const char *part_probes[] __initdata = {"cmdlinepart", "RedBoot", NULL};
63
64#define init_sbc82xx_one_flash(map, br, or) \
65do { \
66 (map).phys = (br & 1) ? (br & 0xffff8000) : 0; \
67 (map).size = (br & 1) ? (~(or & 0xffff8000) + 1) : 0; \
68 switch (br & 0x00001800) { \
69 case 0x00000000: \
70 case 0x00000800: (map).bankwidth = 1; break; \
71 case 0x00001000: (map).bankwidth = 2; break; \
72 case 0x00001800: (map).bankwidth = 4; break; \
73 } \
74} while (0);
75
Dmitri Vorobiev8d240322008-11-25 02:55:11 +020076static int __init init_sbc82xx_flash(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
78 volatile memctl_cpm2_t *mc = &cpm2_immr->im_memctl;
79 int bigflash;
80 int i;
81
82#ifdef CONFIG_SBC8560
83 mc = ioremap(0xff700000 + 0x5000, sizeof(memctl_cpm2_t));
84#else
85 mc = &cpm2_immr->im_memctl;
86#endif
87
88 bigflash = 1;
89 if ((mc->memc_br0 & 0x00001800) == 0x00001800)
90 bigflash = 0;
91
92 init_sbc82xx_one_flash(sbc82xx_flash_map[0], mc->memc_br0, mc->memc_or0);
93 init_sbc82xx_one_flash(sbc82xx_flash_map[1], mc->memc_br6, mc->memc_or6);
94 init_sbc82xx_one_flash(sbc82xx_flash_map[2], mc->memc_br1, mc->memc_or1);
95
96#ifdef CONFIG_SBC8560
97 iounmap((void *) mc);
98#endif
99
100 for (i=0; i<3; i++) {
101 int8_t flashcs[3] = { 0, 6, 1 };
102 int nr_parts;
Dmitry Eremin-Solenikove062e2f2011-06-02 18:00:20 +0400103 struct mtd_partition *defparts;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 printk(KERN_NOTICE "PowerQUICC II %s (%ld MiB on CS%d",
106 sbc82xx_flash_map[i].name,
107 (sbc82xx_flash_map[i].size >> 20),
108 flashcs[i]);
109 if (!sbc82xx_flash_map[i].phys) {
110 /* We know it can't be at zero. */
111 printk("): disabled by bootloader.\n");
112 continue;
113 }
114 printk(" at %08lx)\n", sbc82xx_flash_map[i].phys);
115
Dmitry Eremin-Solenikove062e2f2011-06-02 18:00:20 +0400116 sbc82xx_flash_map[i].virt = ioremap(sbc82xx_flash_map[i].phys,
117 sbc82xx_flash_map[i].size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 if (!sbc82xx_flash_map[i].virt) {
120 printk("Failed to ioremap\n");
121 continue;
122 }
123
124 simple_map_init(&sbc82xx_flash_map[i]);
125
126 sbcmtd[i] = do_map_probe("cfi_probe", &sbc82xx_flash_map[i]);
127
128 if (!sbcmtd[i])
129 continue;
130
131 sbcmtd[i]->owner = THIS_MODULE;
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 /* No partitioning detected. Use default */
134 if (i == 2) {
Dmitry Eremin-Solenikove062e2f2011-06-02 18:00:20 +0400135 defparts = NULL;
136 nr_parts = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 } else if (i == bigflash) {
Dmitry Eremin-Solenikove062e2f2011-06-02 18:00:20 +0400138 defparts = bigflash_parts;
139 nr_parts = ARRAY_SIZE(bigflash_parts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 } else {
Dmitry Eremin-Solenikove062e2f2011-06-02 18:00:20 +0400141 defparts = smallflash_parts;
142 nr_parts = ARRAY_SIZE(smallflash_parts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
Dmitry Eremin-Solenikove062e2f2011-06-02 18:00:20 +0400144
145 mtd_device_parse_register(sbcmtd[i], part_probes, 0,
146 defparts, nr_parts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 }
148 return 0;
149}
150
151static void __exit cleanup_sbc82xx_flash(void)
152{
153 int i;
154
155 for (i=0; i<3; i++) {
156 if (!sbcmtd[i])
157 continue;
158
Dmitry Eremin-Solenikove062e2f2011-06-02 18:00:20 +0400159 mtd_device_unregister(sbcmtd[i]);
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 map_destroy(sbcmtd[i]);
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 iounmap((void *)sbc82xx_flash_map[i].virt);
164 sbc82xx_flash_map[i].virt = 0;
165 }
166}
167
168module_init(init_sbc82xx_flash);
169module_exit(cleanup_sbc82xx_flash);
170
171
172MODULE_LICENSE("GPL");
173MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
174MODULE_DESCRIPTION("Flash map driver for WindRiver PowerQUICC II");