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_partition *parts; 45e644f7d6STodd Poynor int nr_parts; 46e644f7d6STodd Poynor struct mtd_info *mtd; 47e644f7d6STodd Poynor struct map_info map; 48e644f7d6STodd Poynor }; 49e644f7d6STodd Poynor 50e644f7d6STodd Poynor 51e644f7d6STodd Poynor static const char *probes[] = { "RedBoot", "cmdlinepart", NULL }; 52e644f7d6STodd Poynor 53e644f7d6STodd Poynor 54f9d1bf75SMarek Vasut static int __devinit pxa2xx_flash_probe(struct platform_device *pdev) 55e644f7d6STodd Poynor { 56e644f7d6STodd Poynor struct flash_platform_data *flash = pdev->dev.platform_data; 57e644f7d6STodd Poynor struct pxa2xx_flash_info *info; 58e644f7d6STodd Poynor struct mtd_partition *parts; 59e644f7d6STodd Poynor struct resource *res; 60e644f7d6STodd Poynor int ret = 0; 61e644f7d6STodd Poynor 62e644f7d6STodd Poynor res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 63e644f7d6STodd Poynor if (!res) 64e644f7d6STodd Poynor return -ENODEV; 65e644f7d6STodd Poynor 662bfefa4cSJulia Lawall info = kzalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL); 67e644f7d6STodd Poynor if (!info) 68e644f7d6STodd Poynor return -ENOMEM; 69e644f7d6STodd Poynor 70e644f7d6STodd Poynor info->map.name = (char *) flash->name; 71e644f7d6STodd Poynor info->map.bankwidth = flash->width; 72e644f7d6STodd Poynor info->map.phys = res->start; 73e644f7d6STodd Poynor info->map.size = res->end - res->start + 1; 74e644f7d6STodd Poynor info->parts = flash->parts; 75e644f7d6STodd Poynor info->nr_parts = flash->nr_parts; 76e644f7d6STodd Poynor 77e644f7d6STodd Poynor info->map.virt = ioremap(info->map.phys, info->map.size); 78e644f7d6STodd Poynor if (!info->map.virt) { 79e644f7d6STodd Poynor printk(KERN_WARNING "Failed to ioremap %s\n", 80e644f7d6STodd Poynor info->map.name); 81e644f7d6STodd Poynor return -ENOMEM; 82e644f7d6STodd Poynor } 83e644f7d6STodd Poynor info->map.cached = 84e644f7d6STodd Poynor ioremap_cached(info->map.phys, info->map.size); 85e644f7d6STodd Poynor if (!info->map.cached) 86e644f7d6STodd Poynor printk(KERN_WARNING "Failed to ioremap cached %s\n", 87e644f7d6STodd Poynor info->map.name); 88e644f7d6STodd Poynor info->map.inval_cache = pxa2xx_map_inval_cache; 89e644f7d6STodd Poynor simple_map_init(&info->map); 90e644f7d6STodd Poynor 91e644f7d6STodd Poynor printk(KERN_NOTICE 92e644f7d6STodd Poynor "Probing %s at physical address 0x%08lx" 93e644f7d6STodd Poynor " (%d-bit bankwidth)\n", 94e644f7d6STodd Poynor info->map.name, (unsigned long)info->map.phys, 95e644f7d6STodd Poynor info->map.bankwidth * 8); 96e644f7d6STodd Poynor 97e644f7d6STodd Poynor info->mtd = do_map_probe(flash->map_name, &info->map); 98e644f7d6STodd Poynor 99e644f7d6STodd Poynor if (!info->mtd) { 100e644f7d6STodd Poynor iounmap((void *)info->map.virt); 101e644f7d6STodd Poynor if (info->map.cached) 102e644f7d6STodd Poynor iounmap(info->map.cached); 103e644f7d6STodd Poynor return -EIO; 104e644f7d6STodd Poynor } 105e644f7d6STodd Poynor info->mtd->owner = THIS_MODULE; 106e644f7d6STodd Poynor 107e644f7d6STodd Poynor ret = parse_mtd_partitions(info->mtd, probes, &parts, 0); 108e644f7d6STodd Poynor 109e644f7d6STodd Poynor if (ret > 0) { 110e644f7d6STodd Poynor info->nr_parts = ret; 111e644f7d6STodd Poynor info->parts = parts; 112e644f7d6STodd Poynor } 113e644f7d6STodd Poynor 114*3dfad123SJamie Iles if (!info->nr_parts) 115e644f7d6STodd Poynor printk("Registering %s as whole device\n", 116e644f7d6STodd Poynor info->map.name); 117*3dfad123SJamie Iles 118*3dfad123SJamie Iles mtd_device_register(info->mtd, info->parts, info->nr_parts); 119e644f7d6STodd Poynor 1207a192ec3SMing Lei platform_set_drvdata(pdev, info); 121e644f7d6STodd Poynor return 0; 122e644f7d6STodd Poynor } 123e644f7d6STodd Poynor 12467a52bb9SRussell King static int __devexit pxa2xx_flash_remove(struct platform_device *dev) 125e644f7d6STodd Poynor { 1267a192ec3SMing Lei struct pxa2xx_flash_info *info = platform_get_drvdata(dev); 127e644f7d6STodd Poynor 1287a192ec3SMing Lei platform_set_drvdata(dev, NULL); 129e644f7d6STodd Poynor 130*3dfad123SJamie Iles mtd_device_unregister(info->mtd); 131e644f7d6STodd Poynor 132e644f7d6STodd Poynor map_destroy(info->mtd); 133e644f7d6STodd Poynor iounmap(info->map.virt); 134e644f7d6STodd Poynor if (info->map.cached) 135e644f7d6STodd Poynor iounmap(info->map.cached); 136e644f7d6STodd Poynor kfree(info->parts); 137e644f7d6STodd Poynor kfree(info); 138e644f7d6STodd Poynor return 0; 139e644f7d6STodd Poynor } 140e644f7d6STodd Poynor 141e644f7d6STodd Poynor #ifdef CONFIG_PM 1427a192ec3SMing Lei static void pxa2xx_flash_shutdown(struct platform_device *dev) 143e644f7d6STodd Poynor { 1447a192ec3SMing Lei struct pxa2xx_flash_info *info = platform_get_drvdata(dev); 145e644f7d6STodd Poynor 146e644f7d6STodd Poynor if (info && info->mtd->suspend(info->mtd) == 0) 147e644f7d6STodd Poynor info->mtd->resume(info->mtd); 148e644f7d6STodd Poynor } 149e644f7d6STodd Poynor #else 150e644f7d6STodd Poynor #define pxa2xx_flash_shutdown NULL 151e644f7d6STodd Poynor #endif 152e644f7d6STodd Poynor 1537a192ec3SMing Lei static struct platform_driver pxa2xx_flash_driver = { 1547a192ec3SMing Lei .driver = { 155e644f7d6STodd Poynor .name = "pxa2xx-flash", 1567a192ec3SMing Lei .owner = THIS_MODULE, 1577a192ec3SMing Lei }, 158e644f7d6STodd Poynor .probe = pxa2xx_flash_probe, 1597a192ec3SMing Lei .remove = __devexit_p(pxa2xx_flash_remove), 160e644f7d6STodd Poynor .shutdown = pxa2xx_flash_shutdown, 161e644f7d6STodd Poynor }; 162e644f7d6STodd Poynor 163e644f7d6STodd Poynor static int __init init_pxa2xx_flash(void) 164e644f7d6STodd Poynor { 1657a192ec3SMing Lei return platform_driver_register(&pxa2xx_flash_driver); 166e644f7d6STodd Poynor } 167e644f7d6STodd Poynor 168e644f7d6STodd Poynor static void __exit cleanup_pxa2xx_flash(void) 169e644f7d6STodd Poynor { 1707a192ec3SMing Lei platform_driver_unregister(&pxa2xx_flash_driver); 171e644f7d6STodd Poynor } 172e644f7d6STodd Poynor 173e644f7d6STodd Poynor module_init(init_pxa2xx_flash); 174e644f7d6STodd Poynor module_exit(cleanup_pxa2xx_flash); 175e644f7d6STodd Poynor 176e644f7d6STodd Poynor MODULE_LICENSE("GPL"); 1772f82af08SNicolas Pitre MODULE_AUTHOR("Nicolas Pitre <nico@fluxnic.net>"); 178e644f7d6STodd Poynor MODULE_DESCRIPTION("MTD map driver for Intel XScale PXA2xx"); 179