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> 14e644f7d6STodd Poynor #include <linux/kernel.h> 15e644f7d6STodd Poynor #include <linux/init.h> 16e644f7d6STodd Poynor #include <linux/platform_device.h> 17e644f7d6STodd Poynor #include <linux/mtd/mtd.h> 18e644f7d6STodd Poynor #include <linux/mtd/map.h> 19e644f7d6STodd Poynor #include <linux/mtd/partitions.h> 20e644f7d6STodd Poynor 21e644f7d6STodd Poynor #include <asm/io.h> 22e644f7d6STodd Poynor #include <asm/hardware.h> 23*355aaffdSLinus Torvalds #include <asm/cacheflush.h> 24e644f7d6STodd Poynor 25e644f7d6STodd Poynor #include <asm/mach/flash.h> 26e644f7d6STodd Poynor 27e644f7d6STodd Poynor static void pxa2xx_map_inval_cache(struct map_info *map, unsigned long from, 28e644f7d6STodd Poynor ssize_t len) 29e644f7d6STodd Poynor { 30*355aaffdSLinus Torvalds flush_ioremap_region(map->phys, map->cached, from, len); 31e644f7d6STodd Poynor } 32e644f7d6STodd Poynor 33e644f7d6STodd Poynor struct pxa2xx_flash_info { 34e644f7d6STodd Poynor struct mtd_partition *parts; 35e644f7d6STodd Poynor int nr_parts; 36e644f7d6STodd Poynor struct mtd_info *mtd; 37e644f7d6STodd Poynor struct map_info map; 38e644f7d6STodd Poynor }; 39e644f7d6STodd Poynor 40e644f7d6STodd Poynor 41e644f7d6STodd Poynor static const char *probes[] = { "RedBoot", "cmdlinepart", NULL }; 42e644f7d6STodd Poynor 43e644f7d6STodd Poynor 44e644f7d6STodd Poynor static int __init pxa2xx_flash_probe(struct device *dev) 45e644f7d6STodd Poynor { 46e644f7d6STodd Poynor struct platform_device *pdev = to_platform_device(dev); 47e644f7d6STodd Poynor struct flash_platform_data *flash = pdev->dev.platform_data; 48e644f7d6STodd Poynor struct pxa2xx_flash_info *info; 49e644f7d6STodd Poynor struct mtd_partition *parts; 50e644f7d6STodd Poynor struct resource *res; 51e644f7d6STodd Poynor int ret = 0; 52e644f7d6STodd Poynor 53e644f7d6STodd Poynor res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 54e644f7d6STodd Poynor if (!res) 55e644f7d6STodd Poynor return -ENODEV; 56e644f7d6STodd Poynor 57e644f7d6STodd Poynor info = kmalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL); 58e644f7d6STodd Poynor if (!info) 59e644f7d6STodd Poynor return -ENOMEM; 60e644f7d6STodd Poynor 61e644f7d6STodd Poynor memset(info, 0, sizeof(struct pxa2xx_flash_info)); 62e644f7d6STodd Poynor info->map.name = (char *) flash->name; 63e644f7d6STodd Poynor info->map.bankwidth = flash->width; 64e644f7d6STodd Poynor info->map.phys = res->start; 65e644f7d6STodd Poynor info->map.size = res->end - res->start + 1; 66e644f7d6STodd Poynor info->parts = flash->parts; 67e644f7d6STodd Poynor info->nr_parts = flash->nr_parts; 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 99e644f7d6STodd Poynor #ifdef CONFIG_MTD_PARTITIONS 100e644f7d6STodd Poynor ret = parse_mtd_partitions(info->mtd, probes, &parts, 0); 101e644f7d6STodd Poynor 102e644f7d6STodd Poynor if (ret > 0) { 103e644f7d6STodd Poynor info->nr_parts = ret; 104e644f7d6STodd Poynor info->parts = parts; 105e644f7d6STodd Poynor } 106e644f7d6STodd Poynor #endif 107e644f7d6STodd Poynor 108e644f7d6STodd Poynor if (info->nr_parts) { 109e644f7d6STodd Poynor add_mtd_partitions(info->mtd, info->parts, 110e644f7d6STodd Poynor info->nr_parts); 111e644f7d6STodd Poynor } else { 112e644f7d6STodd Poynor printk("Registering %s as whole device\n", 113e644f7d6STodd Poynor info->map.name); 114e644f7d6STodd Poynor add_mtd_device(info->mtd); 115e644f7d6STodd Poynor } 116e644f7d6STodd Poynor 117e644f7d6STodd Poynor dev_set_drvdata(dev, info); 118e644f7d6STodd Poynor return 0; 119e644f7d6STodd Poynor } 120e644f7d6STodd Poynor 121e644f7d6STodd Poynor static int __exit pxa2xx_flash_remove(struct device *dev) 122e644f7d6STodd Poynor { 123e644f7d6STodd Poynor struct pxa2xx_flash_info *info = dev_get_drvdata(dev); 124e644f7d6STodd Poynor 125e644f7d6STodd Poynor dev_set_drvdata(dev, NULL); 126e644f7d6STodd Poynor 127e644f7d6STodd Poynor #ifdef CONFIG_MTD_PARTITIONS 128e644f7d6STodd Poynor if (info->nr_parts) 129e644f7d6STodd Poynor del_mtd_partitions(info->mtd); 130e644f7d6STodd Poynor else 131e644f7d6STodd Poynor #endif 132e644f7d6STodd Poynor del_mtd_device(info->mtd); 133e644f7d6STodd Poynor 134e644f7d6STodd Poynor map_destroy(info->mtd); 135e644f7d6STodd Poynor iounmap(info->map.virt); 136e644f7d6STodd Poynor if (info->map.cached) 137e644f7d6STodd Poynor iounmap(info->map.cached); 138e644f7d6STodd Poynor kfree(info->parts); 139e644f7d6STodd Poynor kfree(info); 140e644f7d6STodd Poynor return 0; 141e644f7d6STodd Poynor } 142e644f7d6STodd Poynor 143e644f7d6STodd Poynor #ifdef CONFIG_PM 144e644f7d6STodd Poynor static int pxa2xx_flash_suspend(struct device *dev, pm_message_t state) 145e644f7d6STodd Poynor { 146e644f7d6STodd Poynor struct pxa2xx_flash_info *info = dev_get_drvdata(dev); 147e644f7d6STodd Poynor int ret = 0; 148e644f7d6STodd Poynor 149e644f7d6STodd Poynor if (info->mtd && info->mtd->suspend) 150e644f7d6STodd Poynor ret = info->mtd->suspend(info->mtd); 151e644f7d6STodd Poynor return ret; 152e644f7d6STodd Poynor } 153e644f7d6STodd Poynor 154e644f7d6STodd Poynor static int pxa2xx_flash_resume(struct device *dev) 155e644f7d6STodd Poynor { 156e644f7d6STodd Poynor struct pxa2xx_flash_info *info = dev_get_drvdata(dev); 157e644f7d6STodd Poynor 158e644f7d6STodd Poynor if (info->mtd && info->mtd->resume) 159e644f7d6STodd Poynor info->mtd->resume(info->mtd); 160e644f7d6STodd Poynor return 0; 161e644f7d6STodd Poynor } 162e644f7d6STodd Poynor static void pxa2xx_flash_shutdown(struct device *dev) 163e644f7d6STodd Poynor { 164e644f7d6STodd Poynor struct pxa2xx_flash_info *info = dev_get_drvdata(dev); 165e644f7d6STodd Poynor 166e644f7d6STodd Poynor if (info && info->mtd->suspend(info->mtd) == 0) 167e644f7d6STodd Poynor info->mtd->resume(info->mtd); 168e644f7d6STodd Poynor } 169e644f7d6STodd Poynor #else 170e644f7d6STodd Poynor #define pxa2xx_flash_suspend NULL 171e644f7d6STodd Poynor #define pxa2xx_flash_resume NULL 172e644f7d6STodd Poynor #define pxa2xx_flash_shutdown NULL 173e644f7d6STodd Poynor #endif 174e644f7d6STodd Poynor 175e644f7d6STodd Poynor static struct device_driver pxa2xx_flash_driver = { 176e644f7d6STodd Poynor .name = "pxa2xx-flash", 177e644f7d6STodd Poynor .bus = &platform_bus_type, 178e644f7d6STodd Poynor .probe = pxa2xx_flash_probe, 179e644f7d6STodd Poynor .remove = __exit_p(pxa2xx_flash_remove), 180e644f7d6STodd Poynor .suspend = pxa2xx_flash_suspend, 181e644f7d6STodd Poynor .resume = pxa2xx_flash_resume, 182e644f7d6STodd Poynor .shutdown = pxa2xx_flash_shutdown, 183e644f7d6STodd Poynor }; 184e644f7d6STodd Poynor 185e644f7d6STodd Poynor static int __init init_pxa2xx_flash(void) 186e644f7d6STodd Poynor { 187e644f7d6STodd Poynor return driver_register(&pxa2xx_flash_driver); 188e644f7d6STodd Poynor } 189e644f7d6STodd Poynor 190e644f7d6STodd Poynor static void __exit cleanup_pxa2xx_flash(void) 191e644f7d6STodd Poynor { 192e644f7d6STodd Poynor driver_unregister(&pxa2xx_flash_driver); 193e644f7d6STodd Poynor } 194e644f7d6STodd Poynor 195e644f7d6STodd Poynor module_init(init_pxa2xx_flash); 196e644f7d6STodd Poynor module_exit(cleanup_pxa2xx_flash); 197e644f7d6STodd Poynor 198e644f7d6STodd Poynor MODULE_LICENSE("GPL"); 199e644f7d6STodd Poynor MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>"); 200e644f7d6STodd Poynor MODULE_DESCRIPTION("MTD map driver for Intel XScale PXA2xx"); 201