1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2e644f7d6STodd Poynor /* 3e644f7d6STodd Poynor * Map driver for Intel XScale PXA2xx platforms. 4e644f7d6STodd Poynor * 5e644f7d6STodd Poynor * Author: Nicolas Pitre 6e644f7d6STodd Poynor * Copyright: (C) 2001 MontaVista Software Inc. 7e644f7d6STodd Poynor */ 8e644f7d6STodd Poynor 9e644f7d6STodd Poynor #include <linux/module.h> 10e644f7d6STodd Poynor #include <linux/types.h> 115a0e3ad6STejun Heo #include <linux/slab.h> 12e644f7d6STodd Poynor #include <linux/kernel.h> 13e644f7d6STodd Poynor #include <linux/platform_device.h> 14e644f7d6STodd Poynor #include <linux/mtd/mtd.h> 15e644f7d6STodd Poynor #include <linux/mtd/map.h> 16e644f7d6STodd Poynor #include <linux/mtd/partitions.h> 17e644f7d6STodd Poynor 18e644f7d6STodd Poynor #include <asm/io.h> 19a09e64fbSRussell King #include <mach/hardware.h> 20e644f7d6STodd Poynor 21e644f7d6STodd Poynor #include <asm/mach/flash.h> 22e644f7d6STodd Poynor 23ccaf5f05SNicolas Pitre #define CACHELINESIZE 32 24ccaf5f05SNicolas Pitre 25e644f7d6STodd Poynor static void pxa2xx_map_inval_cache(struct map_info *map, unsigned long from, 26e644f7d6STodd Poynor ssize_t len) 27e644f7d6STodd Poynor { 28ccaf5f05SNicolas Pitre unsigned long start = (unsigned long)map->cached + from; 29ccaf5f05SNicolas Pitre unsigned long end = start + len; 30ccaf5f05SNicolas Pitre 31ccaf5f05SNicolas Pitre start &= ~(CACHELINESIZE - 1); 32ccaf5f05SNicolas Pitre while (start < end) { 33ccaf5f05SNicolas Pitre /* invalidate D cache line */ 34ccaf5f05SNicolas Pitre asm volatile ("mcr p15, 0, %0, c7, c6, 1" : : "r" (start)); 35ccaf5f05SNicolas Pitre start += CACHELINESIZE; 36ccaf5f05SNicolas Pitre } 37e644f7d6STodd Poynor } 38e644f7d6STodd Poynor 39e644f7d6STodd Poynor struct pxa2xx_flash_info { 40e644f7d6STodd Poynor struct mtd_info *mtd; 41e644f7d6STodd Poynor struct map_info map; 42e644f7d6STodd Poynor }; 43e644f7d6STodd Poynor 440984c891SArtem Bityutskiy static const char * const probes[] = { "RedBoot", "cmdlinepart", NULL }; 45e644f7d6STodd Poynor 4606f25510SBill Pemberton static int pxa2xx_flash_probe(struct platform_device *pdev) 47e644f7d6STodd Poynor { 48d20d5a57SJingoo Han struct flash_platform_data *flash = dev_get_platdata(&pdev->dev); 49e644f7d6STodd Poynor struct pxa2xx_flash_info *info; 50e644f7d6STodd Poynor struct resource *res; 51e644f7d6STodd Poynor 52e644f7d6STodd Poynor res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 53e644f7d6STodd Poynor if (!res) 54e644f7d6STodd Poynor return -ENODEV; 55e644f7d6STodd Poynor 562bfefa4cSJulia Lawall info = kzalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL); 57e644f7d6STodd Poynor if (!info) 58e644f7d6STodd Poynor return -ENOMEM; 59e644f7d6STodd Poynor 607c4bb4f8SGeert Uytterhoeven info->map.name = flash->name; 61e644f7d6STodd Poynor info->map.bankwidth = flash->width; 62e644f7d6STodd Poynor info->map.phys = res->start; 6328f65c11SJoe Perches info->map.size = resource_size(res); 64e644f7d6STodd Poynor 65e644f7d6STodd Poynor info->map.virt = ioremap(info->map.phys, info->map.size); 66e644f7d6STodd Poynor if (!info->map.virt) { 67e644f7d6STodd Poynor printk(KERN_WARNING "Failed to ioremap %s\n", 68e644f7d6STodd Poynor info->map.name); 69e644f7d6STodd Poynor return -ENOMEM; 70e644f7d6STodd Poynor } 71*97ef08aeSChristoph Hellwig info->map.cached = ioremap_cache(info->map.phys, info->map.size); 72e644f7d6STodd Poynor if (!info->map.cached) 73e644f7d6STodd Poynor printk(KERN_WARNING "Failed to ioremap cached %s\n", 74e644f7d6STodd Poynor info->map.name); 75e644f7d6STodd Poynor info->map.inval_cache = pxa2xx_map_inval_cache; 76e644f7d6STodd Poynor simple_map_init(&info->map); 77e644f7d6STodd Poynor 78e644f7d6STodd Poynor printk(KERN_NOTICE 79e644f7d6STodd Poynor "Probing %s at physical address 0x%08lx" 80e644f7d6STodd Poynor " (%d-bit bankwidth)\n", 81e644f7d6STodd Poynor info->map.name, (unsigned long)info->map.phys, 82e644f7d6STodd Poynor info->map.bankwidth * 8); 83e644f7d6STodd Poynor 84e644f7d6STodd Poynor info->mtd = do_map_probe(flash->map_name, &info->map); 85e644f7d6STodd Poynor 86e644f7d6STodd Poynor if (!info->mtd) { 87e644f7d6STodd Poynor iounmap((void *)info->map.virt); 88e644f7d6STodd Poynor if (info->map.cached) 89e644f7d6STodd Poynor iounmap(info->map.cached); 90e644f7d6STodd Poynor return -EIO; 91e644f7d6STodd Poynor } 922451581fSFrans Klaver info->mtd->dev.parent = &pdev->dev; 93e644f7d6STodd Poynor 9442d7fbe2SArtem Bityutskiy mtd_device_parse_register(info->mtd, probes, NULL, flash->parts, 9542d7fbe2SArtem Bityutskiy flash->nr_parts); 96e644f7d6STodd Poynor 977a192ec3SMing Lei platform_set_drvdata(pdev, info); 98e644f7d6STodd Poynor return 0; 99e644f7d6STodd Poynor } 100e644f7d6STodd Poynor 101810b7e06SBill Pemberton static int pxa2xx_flash_remove(struct platform_device *dev) 102e644f7d6STodd Poynor { 1037a192ec3SMing Lei struct pxa2xx_flash_info *info = platform_get_drvdata(dev); 104e644f7d6STodd Poynor 1053dfad123SJamie Iles mtd_device_unregister(info->mtd); 106e644f7d6STodd Poynor 107e644f7d6STodd Poynor map_destroy(info->mtd); 108e644f7d6STodd Poynor iounmap(info->map.virt); 109e644f7d6STodd Poynor if (info->map.cached) 1107769aea2SArd Biesheuvel iounmap(info->map.cached); 111e644f7d6STodd Poynor kfree(info); 112e644f7d6STodd Poynor return 0; 113e644f7d6STodd Poynor } 114e644f7d6STodd Poynor 115e644f7d6STodd Poynor #ifdef CONFIG_PM 1167a192ec3SMing Lei static void pxa2xx_flash_shutdown(struct platform_device *dev) 117e644f7d6STodd Poynor { 1187a192ec3SMing Lei struct pxa2xx_flash_info *info = platform_get_drvdata(dev); 119e644f7d6STodd Poynor 1203fe4bae8SArtem Bityutskiy if (info && mtd_suspend(info->mtd) == 0) 121ead995f8SArtem Bityutskiy mtd_resume(info->mtd); 122e644f7d6STodd Poynor } 123e644f7d6STodd Poynor #else 124e644f7d6STodd Poynor #define pxa2xx_flash_shutdown NULL 125e644f7d6STodd Poynor #endif 126e644f7d6STodd Poynor 1277a192ec3SMing Lei static struct platform_driver pxa2xx_flash_driver = { 1287a192ec3SMing Lei .driver = { 129e644f7d6STodd Poynor .name = "pxa2xx-flash", 1307a192ec3SMing Lei }, 131e644f7d6STodd Poynor .probe = pxa2xx_flash_probe, 1325153b88cSBill Pemberton .remove = pxa2xx_flash_remove, 133e644f7d6STodd Poynor .shutdown = pxa2xx_flash_shutdown, 134e644f7d6STodd Poynor }; 135e644f7d6STodd Poynor 136f99640deSAxel Lin module_platform_driver(pxa2xx_flash_driver); 137e644f7d6STodd Poynor 138e644f7d6STodd Poynor MODULE_LICENSE("GPL"); 1392f82af08SNicolas Pitre MODULE_AUTHOR("Nicolas Pitre <nico@fluxnic.net>"); 140e644f7d6STodd Poynor MODULE_DESCRIPTION("MTD map driver for Intel XScale PXA2xx"); 141