PageRenderTime 176ms CodeModel.GetById 70ms app.highlight 9ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/mtd/maps/cdb89712.c

https://bitbucket.org/ndreys/linux-sunxi
C | 278 lines | 214 code | 59 blank | 5 comment | 17 complexity | 667069533bd6e5b98073b8d5cef07610 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1/*
  2 * Flash on Cirrus CDB89712
  3 *
  4 */
  5
  6#include <linux/module.h>
  7#include <linux/types.h>
  8#include <linux/kernel.h>
  9#include <linux/ioport.h>
 10#include <linux/init.h>
 11#include <asm/io.h>
 12#include <mach/hardware.h>
 13#include <linux/mtd/mtd.h>
 14#include <linux/mtd/map.h>
 15#include <linux/mtd/partitions.h>
 16
 17/* dynamic ioremap() areas */
 18#define FLASH_START      0x00000000
 19#define FLASH_SIZE       0x800000
 20#define FLASH_WIDTH      4
 21
 22#define SRAM_START       0x60000000
 23#define SRAM_SIZE        0xc000
 24#define SRAM_WIDTH       4
 25
 26#define BOOTROM_START    0x70000000
 27#define BOOTROM_SIZE     0x80
 28#define BOOTROM_WIDTH    4
 29
 30
 31static struct mtd_info *flash_mtd;
 32
 33struct map_info cdb89712_flash_map = {
 34	.name = "flash",
 35	.size = FLASH_SIZE,
 36	.bankwidth = FLASH_WIDTH,
 37	.phys = FLASH_START,
 38};
 39
 40struct resource cdb89712_flash_resource = {
 41	.name =   "Flash",
 42	.start =  FLASH_START,
 43	.end =    FLASH_START + FLASH_SIZE - 1,
 44	.flags =  IORESOURCE_IO | IORESOURCE_BUSY,
 45};
 46
 47static int __init init_cdb89712_flash (void)
 48{
 49	int err;
 50
 51	if (request_resource (&ioport_resource, &cdb89712_flash_resource)) {
 52		printk(KERN_NOTICE "Failed to reserve Cdb89712 FLASH space\n");
 53		err = -EBUSY;
 54		goto out;
 55	}
 56
 57	cdb89712_flash_map.virt = ioremap(FLASH_START, FLASH_SIZE);
 58	if (!cdb89712_flash_map.virt) {
 59		printk(KERN_NOTICE "Failed to ioremap Cdb89712 FLASH space\n");
 60		err = -EIO;
 61		goto out_resource;
 62	}
 63	simple_map_init(&cdb89712_flash_map);
 64	flash_mtd = do_map_probe("cfi_probe", &cdb89712_flash_map);
 65	if (!flash_mtd) {
 66		flash_mtd = do_map_probe("map_rom", &cdb89712_flash_map);
 67		if (flash_mtd)
 68			flash_mtd->erasesize = 0x10000;
 69	}
 70	if (!flash_mtd) {
 71		printk("FLASH probe failed\n");
 72		err = -ENXIO;
 73		goto out_ioremap;
 74	}
 75
 76	flash_mtd->owner = THIS_MODULE;
 77
 78	if (mtd_device_register(flash_mtd, NULL, 0)) {
 79		printk("FLASH device addition failed\n");
 80		err = -ENOMEM;
 81		goto out_probe;
 82	}
 83
 84	return 0;
 85
 86out_probe:
 87	map_destroy(flash_mtd);
 88	flash_mtd = 0;
 89out_ioremap:
 90	iounmap((void *)cdb89712_flash_map.virt);
 91out_resource:
 92	release_resource (&cdb89712_flash_resource);
 93out:
 94	return err;
 95}
 96
 97
 98
 99
100
101static struct mtd_info *sram_mtd;
102
103struct map_info cdb89712_sram_map = {
104	.name = "SRAM",
105	.size = SRAM_SIZE,
106	.bankwidth = SRAM_WIDTH,
107	.phys = SRAM_START,
108};
109
110struct resource cdb89712_sram_resource = {
111	.name =   "SRAM",
112	.start =  SRAM_START,
113	.end =    SRAM_START + SRAM_SIZE - 1,
114	.flags =  IORESOURCE_IO | IORESOURCE_BUSY,
115};
116
117static int __init init_cdb89712_sram (void)
118{
119	int err;
120
121	if (request_resource (&ioport_resource, &cdb89712_sram_resource)) {
122		printk(KERN_NOTICE "Failed to reserve Cdb89712 SRAM space\n");
123		err = -EBUSY;
124		goto out;
125	}
126
127	cdb89712_sram_map.virt = ioremap(SRAM_START, SRAM_SIZE);
128	if (!cdb89712_sram_map.virt) {
129		printk(KERN_NOTICE "Failed to ioremap Cdb89712 SRAM space\n");
130		err = -EIO;
131		goto out_resource;
132	}
133	simple_map_init(&cdb89712_sram_map);
134	sram_mtd = do_map_probe("map_ram", &cdb89712_sram_map);
135	if (!sram_mtd) {
136		printk("SRAM probe failed\n");
137		err = -ENXIO;
138		goto out_ioremap;
139	}
140
141	sram_mtd->owner = THIS_MODULE;
142	sram_mtd->erasesize = 16;
143
144	if (mtd_device_register(sram_mtd, NULL, 0)) {
145		printk("SRAM device addition failed\n");
146		err = -ENOMEM;
147		goto out_probe;
148	}
149
150	return 0;
151
152out_probe:
153	map_destroy(sram_mtd);
154	sram_mtd = 0;
155out_ioremap:
156	iounmap((void *)cdb89712_sram_map.virt);
157out_resource:
158	release_resource (&cdb89712_sram_resource);
159out:
160	return err;
161}
162
163
164
165
166
167
168
169static struct mtd_info *bootrom_mtd;
170
171struct map_info cdb89712_bootrom_map = {
172	.name = "BootROM",
173	.size = BOOTROM_SIZE,
174	.bankwidth = BOOTROM_WIDTH,
175	.phys = BOOTROM_START,
176};
177
178struct resource cdb89712_bootrom_resource = {
179	.name =   "BootROM",
180	.start =  BOOTROM_START,
181	.end =    BOOTROM_START + BOOTROM_SIZE - 1,
182	.flags =  IORESOURCE_IO | IORESOURCE_BUSY,
183};
184
185static int __init init_cdb89712_bootrom (void)
186{
187	int err;
188
189	if (request_resource (&ioport_resource, &cdb89712_bootrom_resource)) {
190		printk(KERN_NOTICE "Failed to reserve Cdb89712 BOOTROM space\n");
191		err = -EBUSY;
192		goto out;
193	}
194
195	cdb89712_bootrom_map.virt = ioremap(BOOTROM_START, BOOTROM_SIZE);
196	if (!cdb89712_bootrom_map.virt) {
197		printk(KERN_NOTICE "Failed to ioremap Cdb89712 BootROM space\n");
198		err = -EIO;
199		goto out_resource;
200	}
201	simple_map_init(&cdb89712_bootrom_map);
202	bootrom_mtd = do_map_probe("map_rom", &cdb89712_bootrom_map);
203	if (!bootrom_mtd) {
204		printk("BootROM probe failed\n");
205		err = -ENXIO;
206		goto out_ioremap;
207	}
208
209	bootrom_mtd->owner = THIS_MODULE;
210	bootrom_mtd->erasesize = 0x10000;
211
212	if (mtd_device_register(bootrom_mtd, NULL, 0)) {
213		printk("BootROM device addition failed\n");
214		err = -ENOMEM;
215		goto out_probe;
216	}
217
218	return 0;
219
220out_probe:
221	map_destroy(bootrom_mtd);
222	bootrom_mtd = 0;
223out_ioremap:
224	iounmap((void *)cdb89712_bootrom_map.virt);
225out_resource:
226	release_resource (&cdb89712_bootrom_resource);
227out:
228	return err;
229}
230
231
232
233
234
235static int __init init_cdb89712_maps(void)
236{
237
238       	printk(KERN_INFO "Cirrus CDB89712 MTD mappings:\n  Flash 0x%x at 0x%x\n  SRAM 0x%x at 0x%x\n  BootROM 0x%x at 0x%x\n",
239	       FLASH_SIZE, FLASH_START, SRAM_SIZE, SRAM_START, BOOTROM_SIZE, BOOTROM_START);
240
241	init_cdb89712_flash();
242	init_cdb89712_sram();
243	init_cdb89712_bootrom();
244
245	return 0;
246}
247
248
249static void __exit cleanup_cdb89712_maps(void)
250{
251	if (sram_mtd) {
252		mtd_device_unregister(sram_mtd);
253		map_destroy(sram_mtd);
254		iounmap((void *)cdb89712_sram_map.virt);
255		release_resource (&cdb89712_sram_resource);
256	}
257
258	if (flash_mtd) {
259		mtd_device_unregister(flash_mtd);
260		map_destroy(flash_mtd);
261		iounmap((void *)cdb89712_flash_map.virt);
262		release_resource (&cdb89712_flash_resource);
263	}
264
265	if (bootrom_mtd) {
266		mtd_device_unregister(bootrom_mtd);
267		map_destroy(bootrom_mtd);
268		iounmap((void *)cdb89712_bootrom_map.virt);
269		release_resource (&cdb89712_bootrom_resource);
270	}
271}
272
273module_init(init_cdb89712_maps);
274module_exit(cleanup_cdb89712_maps);
275
276MODULE_AUTHOR("Ray L");
277MODULE_DESCRIPTION("ARM CDB89712 map driver");
278MODULE_LICENSE("GPL");