Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Map driver for Intel XScale PXA2xx platforms.
0004  *
0005  * Author:  Nicolas Pitre
0006  * Copyright:   (C) 2001 MontaVista Software Inc.
0007  */
0008 
0009 #include <linux/module.h>
0010 #include <linux/types.h>
0011 #include <linux/slab.h>
0012 #include <linux/kernel.h>
0013 #include <linux/platform_device.h>
0014 #include <linux/mtd/mtd.h>
0015 #include <linux/mtd/map.h>
0016 #include <linux/mtd/partitions.h>
0017 
0018 #include <asm/io.h>
0019 #include <asm/mach/flash.h>
0020 
0021 #define CACHELINESIZE   32
0022 
0023 static void pxa2xx_map_inval_cache(struct map_info *map, unsigned long from,
0024                       ssize_t len)
0025 {
0026     unsigned long start = (unsigned long)map->cached + from;
0027     unsigned long end = start + len;
0028 
0029     start &= ~(CACHELINESIZE - 1);
0030     while (start < end) {
0031         /* invalidate D cache line */
0032         asm volatile ("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
0033         start += CACHELINESIZE;
0034     }
0035 }
0036 
0037 struct pxa2xx_flash_info {
0038     struct mtd_info     *mtd;
0039     struct map_info     map;
0040 };
0041 
0042 static const char * const probes[] = { "RedBoot", "cmdlinepart", NULL };
0043 
0044 static int pxa2xx_flash_probe(struct platform_device *pdev)
0045 {
0046     struct flash_platform_data *flash = dev_get_platdata(&pdev->dev);
0047     struct pxa2xx_flash_info *info;
0048     struct resource *res;
0049 
0050     res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
0051     if (!res)
0052         return -ENODEV;
0053 
0054     info = kzalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL);
0055     if (!info)
0056         return -ENOMEM;
0057 
0058     info->map.name = flash->name;
0059     info->map.bankwidth = flash->width;
0060     info->map.phys = res->start;
0061     info->map.size = resource_size(res);
0062 
0063     info->map.virt = ioremap(info->map.phys, info->map.size);
0064     if (!info->map.virt) {
0065         printk(KERN_WARNING "Failed to ioremap %s\n",
0066                info->map.name);
0067         return -ENOMEM;
0068     }
0069     info->map.cached = ioremap_cache(info->map.phys, info->map.size);
0070     if (!info->map.cached)
0071         printk(KERN_WARNING "Failed to ioremap cached %s\n",
0072                info->map.name);
0073     info->map.inval_cache = pxa2xx_map_inval_cache;
0074     simple_map_init(&info->map);
0075 
0076     printk(KERN_NOTICE
0077            "Probing %s at physical address 0x%08lx"
0078            " (%d-bit bankwidth)\n",
0079            info->map.name, (unsigned long)info->map.phys,
0080            info->map.bankwidth * 8);
0081 
0082     info->mtd = do_map_probe(flash->map_name, &info->map);
0083 
0084     if (!info->mtd) {
0085         iounmap((void *)info->map.virt);
0086         if (info->map.cached)
0087             iounmap(info->map.cached);
0088         return -EIO;
0089     }
0090     info->mtd->dev.parent = &pdev->dev;
0091 
0092     mtd_device_parse_register(info->mtd, probes, NULL, flash->parts,
0093                   flash->nr_parts);
0094 
0095     platform_set_drvdata(pdev, info);
0096     return 0;
0097 }
0098 
0099 static int pxa2xx_flash_remove(struct platform_device *dev)
0100 {
0101     struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
0102 
0103     mtd_device_unregister(info->mtd);
0104 
0105     map_destroy(info->mtd);
0106     iounmap(info->map.virt);
0107     if (info->map.cached)
0108         iounmap(info->map.cached);
0109     kfree(info);
0110     return 0;
0111 }
0112 
0113 #ifdef CONFIG_PM
0114 static void pxa2xx_flash_shutdown(struct platform_device *dev)
0115 {
0116     struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
0117 
0118     if (info && mtd_suspend(info->mtd) == 0)
0119         mtd_resume(info->mtd);
0120 }
0121 #else
0122 #define pxa2xx_flash_shutdown NULL
0123 #endif
0124 
0125 static struct platform_driver pxa2xx_flash_driver = {
0126     .driver = {
0127         .name       = "pxa2xx-flash",
0128     },
0129     .probe      = pxa2xx_flash_probe,
0130     .remove     = pxa2xx_flash_remove,
0131     .shutdown   = pxa2xx_flash_shutdown,
0132 };
0133 
0134 module_platform_driver(pxa2xx_flash_driver);
0135 
0136 MODULE_LICENSE("GPL");
0137 MODULE_AUTHOR("Nicolas Pitre <nico@fluxnic.net>");
0138 MODULE_DESCRIPTION("MTD map driver for Intel XScale PXA2xx");