xref: /linux/drivers/mtd/maps/pxa2xx-flash.c (revision 0984c8910426371205da0b60fc1dae64a996fb64)
1e644f7d6STodd Poynor /*
2e644f7d6STodd Poynor  * Map driver for Intel XScale PXA2xx platforms.
3e644f7d6STodd Poynor  *
4e644f7d6STodd Poynor  * Author:	Nicolas Pitre
5e644f7d6STodd Poynor  * Copyright:	(C) 2001 MontaVista Software Inc.
6e644f7d6STodd Poynor  *
7e644f7d6STodd Poynor  * This program is free software; you can redistribute it and/or modify
8e644f7d6STodd Poynor  * it under the terms of the GNU General Public License version 2 as
9e644f7d6STodd Poynor  * published by the Free Software Foundation.
10e644f7d6STodd Poynor  */
11e644f7d6STodd Poynor 
12e644f7d6STodd Poynor #include <linux/module.h>
13e644f7d6STodd Poynor #include <linux/types.h>
145a0e3ad6STejun Heo #include <linux/slab.h>
15e644f7d6STodd Poynor #include <linux/kernel.h>
16e644f7d6STodd Poynor #include <linux/init.h>
17e644f7d6STodd Poynor #include <linux/platform_device.h>
18e644f7d6STodd Poynor #include <linux/mtd/mtd.h>
19e644f7d6STodd Poynor #include <linux/mtd/map.h>
20e644f7d6STodd Poynor #include <linux/mtd/partitions.h>
21e644f7d6STodd Poynor 
22e644f7d6STodd Poynor #include <asm/io.h>
23a09e64fbSRussell King #include <mach/hardware.h>
24e644f7d6STodd Poynor 
25e644f7d6STodd Poynor #include <asm/mach/flash.h>
26e644f7d6STodd Poynor 
27ccaf5f05SNicolas Pitre #define CACHELINESIZE	32
28ccaf5f05SNicolas Pitre 
29e644f7d6STodd Poynor static void pxa2xx_map_inval_cache(struct map_info *map, unsigned long from,
30e644f7d6STodd Poynor 				      ssize_t len)
31e644f7d6STodd Poynor {
32ccaf5f05SNicolas Pitre 	unsigned long start = (unsigned long)map->cached + from;
33ccaf5f05SNicolas Pitre 	unsigned long end = start + len;
34ccaf5f05SNicolas Pitre 
35ccaf5f05SNicolas Pitre 	start &= ~(CACHELINESIZE - 1);
36ccaf5f05SNicolas Pitre 	while (start < end) {
37ccaf5f05SNicolas Pitre 		/* invalidate D cache line */
38ccaf5f05SNicolas Pitre 		asm volatile ("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
39ccaf5f05SNicolas Pitre 		start += CACHELINESIZE;
40ccaf5f05SNicolas Pitre 	}
41e644f7d6STodd Poynor }
42e644f7d6STodd Poynor 
43e644f7d6STodd Poynor struct pxa2xx_flash_info {
44e644f7d6STodd Poynor 	struct mtd_info		*mtd;
45e644f7d6STodd Poynor 	struct map_info		map;
46e644f7d6STodd Poynor };
47e644f7d6STodd Poynor 
48*0984c891SArtem Bityutskiy static const char * const probes[] = { "RedBoot", "cmdlinepart", NULL };
49e644f7d6STodd Poynor 
5006f25510SBill Pemberton static int pxa2xx_flash_probe(struct platform_device *pdev)
51e644f7d6STodd Poynor {
52e644f7d6STodd Poynor 	struct flash_platform_data *flash = pdev->dev.platform_data;
53e644f7d6STodd Poynor 	struct pxa2xx_flash_info *info;
54e644f7d6STodd Poynor 	struct resource *res;
55e644f7d6STodd Poynor 
56e644f7d6STodd Poynor 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
57e644f7d6STodd Poynor 	if (!res)
58e644f7d6STodd Poynor 		return -ENODEV;
59e644f7d6STodd Poynor 
602bfefa4cSJulia Lawall 	info = kzalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL);
61e644f7d6STodd Poynor 	if (!info)
62e644f7d6STodd Poynor 		return -ENOMEM;
63e644f7d6STodd Poynor 
64e644f7d6STodd Poynor 	info->map.name = (char *) flash->name;
65e644f7d6STodd Poynor 	info->map.bankwidth = flash->width;
66e644f7d6STodd Poynor 	info->map.phys = res->start;
6728f65c11SJoe Perches 	info->map.size = resource_size(res);
68e644f7d6STodd Poynor 
69e644f7d6STodd Poynor 	info->map.virt = ioremap(info->map.phys, info->map.size);
70e644f7d6STodd Poynor 	if (!info->map.virt) {
71e644f7d6STodd Poynor 		printk(KERN_WARNING "Failed to ioremap %s\n",
72e644f7d6STodd Poynor 		       info->map.name);
73e644f7d6STodd Poynor 		return -ENOMEM;
74e644f7d6STodd Poynor 	}
75e644f7d6STodd Poynor 	info->map.cached =
76e644f7d6STodd Poynor 		ioremap_cached(info->map.phys, info->map.size);
77e644f7d6STodd Poynor 	if (!info->map.cached)
78e644f7d6STodd Poynor 		printk(KERN_WARNING "Failed to ioremap cached %s\n",
79e644f7d6STodd Poynor 		       info->map.name);
80e644f7d6STodd Poynor 	info->map.inval_cache = pxa2xx_map_inval_cache;
81e644f7d6STodd Poynor 	simple_map_init(&info->map);
82e644f7d6STodd Poynor 
83e644f7d6STodd Poynor 	printk(KERN_NOTICE
84e644f7d6STodd Poynor 	       "Probing %s at physical address 0x%08lx"
85e644f7d6STodd Poynor 	       " (%d-bit bankwidth)\n",
86e644f7d6STodd Poynor 	       info->map.name, (unsigned long)info->map.phys,
87e644f7d6STodd Poynor 	       info->map.bankwidth * 8);
88e644f7d6STodd Poynor 
89e644f7d6STodd Poynor 	info->mtd = do_map_probe(flash->map_name, &info->map);
90e644f7d6STodd Poynor 
91e644f7d6STodd Poynor 	if (!info->mtd) {
92e644f7d6STodd Poynor 		iounmap((void *)info->map.virt);
93e644f7d6STodd Poynor 		if (info->map.cached)
94e644f7d6STodd Poynor 			iounmap(info->map.cached);
95e644f7d6STodd Poynor 		return -EIO;
96e644f7d6STodd Poynor 	}
97e644f7d6STodd Poynor 	info->mtd->owner = THIS_MODULE;
98e644f7d6STodd Poynor 
9942d7fbe2SArtem Bityutskiy 	mtd_device_parse_register(info->mtd, probes, NULL, flash->parts,
10042d7fbe2SArtem Bityutskiy 				  flash->nr_parts);
101e644f7d6STodd Poynor 
1027a192ec3SMing Lei 	platform_set_drvdata(pdev, info);
103e644f7d6STodd Poynor 	return 0;
104e644f7d6STodd Poynor }
105e644f7d6STodd Poynor 
106810b7e06SBill Pemberton static int pxa2xx_flash_remove(struct platform_device *dev)
107e644f7d6STodd Poynor {
1087a192ec3SMing Lei 	struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
109e644f7d6STodd Poynor 
1107a192ec3SMing Lei 	platform_set_drvdata(dev, NULL);
111e644f7d6STodd Poynor 
1123dfad123SJamie Iles 	mtd_device_unregister(info->mtd);
113e644f7d6STodd Poynor 
114e644f7d6STodd Poynor 	map_destroy(info->mtd);
115e644f7d6STodd Poynor 	iounmap(info->map.virt);
116e644f7d6STodd Poynor 	if (info->map.cached)
117e644f7d6STodd Poynor 		iounmap(info->map.cached);
118e644f7d6STodd Poynor 	kfree(info);
119e644f7d6STodd Poynor 	return 0;
120e644f7d6STodd Poynor }
121e644f7d6STodd Poynor 
122e644f7d6STodd Poynor #ifdef CONFIG_PM
1237a192ec3SMing Lei static void pxa2xx_flash_shutdown(struct platform_device *dev)
124e644f7d6STodd Poynor {
1257a192ec3SMing Lei 	struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
126e644f7d6STodd Poynor 
1273fe4bae8SArtem Bityutskiy 	if (info && mtd_suspend(info->mtd) == 0)
128ead995f8SArtem Bityutskiy 		mtd_resume(info->mtd);
129e644f7d6STodd Poynor }
130e644f7d6STodd Poynor #else
131e644f7d6STodd Poynor #define pxa2xx_flash_shutdown NULL
132e644f7d6STodd Poynor #endif
133e644f7d6STodd Poynor 
1347a192ec3SMing Lei static struct platform_driver pxa2xx_flash_driver = {
1357a192ec3SMing Lei 	.driver = {
136e644f7d6STodd Poynor 		.name		= "pxa2xx-flash",
1377a192ec3SMing Lei 		.owner		= THIS_MODULE,
1387a192ec3SMing Lei 	},
139e644f7d6STodd Poynor 	.probe		= pxa2xx_flash_probe,
1405153b88cSBill Pemberton 	.remove		= pxa2xx_flash_remove,
141e644f7d6STodd Poynor 	.shutdown	= pxa2xx_flash_shutdown,
142e644f7d6STodd Poynor };
143e644f7d6STodd Poynor 
144f99640deSAxel Lin module_platform_driver(pxa2xx_flash_driver);
145e644f7d6STodd Poynor 
146e644f7d6STodd Poynor MODULE_LICENSE("GPL");
1472f82af08SNicolas Pitre MODULE_AUTHOR("Nicolas Pitre <nico@fluxnic.net>");
148e644f7d6STodd Poynor MODULE_DESCRIPTION("MTD map driver for Intel XScale PXA2xx");
149