1 // SPDX-License-Identifier: GPL-2.0-only
3 * rbtx4939-flash (based on physmap.c)
5 * This is a simplified physmap driver with map_init callback function.
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13 #include <linux/slab.h>
14 #include <linux/device.h>
15 #include <linux/platform_device.h>
16 #include <linux/mtd/mtd.h>
17 #include <linux/mtd/map.h>
18 #include <linux/mtd/partitions.h>
19 #include <asm/txx9/rbtx4939.h>
21 struct rbtx4939_flash_info {
26 static int rbtx4939_flash_remove(struct platform_device *dev)
28 struct rbtx4939_flash_info *info;
30 info = platform_get_drvdata(dev);
35 mtd_device_unregister(info->mtd);
36 map_destroy(info->mtd);
41 static const char * const rom_probe_types[] = {
42 "cfi_probe", "jedec_probe", NULL };
44 static int rbtx4939_flash_probe(struct platform_device *dev)
46 struct rbtx4939_flash_data *pdata;
47 struct rbtx4939_flash_info *info;
49 const char * const *probe_type;
53 pdata = dev_get_platdata(&dev->dev);
57 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
60 info = devm_kzalloc(&dev->dev, sizeof(struct rbtx4939_flash_info),
65 platform_set_drvdata(dev, info);
67 size = resource_size(res);
68 pr_notice("rbtx4939 platform flash device: %pR\n", res);
70 if (!devm_request_mem_region(&dev->dev, res->start, size,
74 info->map.name = dev_name(&dev->dev);
75 info->map.phys = res->start;
76 info->map.size = size;
77 info->map.bankwidth = pdata->width;
79 info->map.virt = devm_ioremap(&dev->dev, info->map.phys, size);
84 (*pdata->map_init)(&info->map);
86 simple_map_init(&info->map);
88 probe_type = rom_probe_types;
89 for (; !info->mtd && *probe_type; probe_type++)
90 info->mtd = do_map_probe(*probe_type, &info->map);
92 dev_err(&dev->dev, "map_probe failed\n");
96 info->mtd->dev.parent = &dev->dev;
97 err = mtd_device_register(info->mtd, pdata->parts, pdata->nr_parts);
104 rbtx4939_flash_remove(dev);
109 static void rbtx4939_flash_shutdown(struct platform_device *dev)
111 struct rbtx4939_flash_info *info = platform_get_drvdata(dev);
113 if (mtd_suspend(info->mtd) == 0)
114 mtd_resume(info->mtd);
117 #define rbtx4939_flash_shutdown NULL
120 static struct platform_driver rbtx4939_flash_driver = {
121 .probe = rbtx4939_flash_probe,
122 .remove = rbtx4939_flash_remove,
123 .shutdown = rbtx4939_flash_shutdown,
125 .name = "rbtx4939-flash",
129 module_platform_driver(rbtx4939_flash_driver);
131 MODULE_LICENSE("GPL");
132 MODULE_DESCRIPTION("RBTX4939 MTD map driver");
133 MODULE_ALIAS("platform:rbtx4939-flash");