Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / mtd / maps / rbtx4939-flash.c
blob39c86c0b0ec1623b8a190983e2d5e98437b5356e
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * rbtx4939-flash (based on physmap.c)
5 * This is a simplified physmap driver with map_init callback function.
7 * Copyright (C) 2009 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
8 */
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 {
22 struct mtd_info *mtd;
23 struct map_info map;
26 static int rbtx4939_flash_remove(struct platform_device *dev)
28 struct rbtx4939_flash_info *info;
30 info = platform_get_drvdata(dev);
31 if (!info)
32 return 0;
34 if (info->mtd) {
35 mtd_device_unregister(info->mtd);
36 map_destroy(info->mtd);
38 return 0;
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;
48 struct resource *res;
49 const char * const *probe_type;
50 int err = 0;
51 unsigned long size;
53 pdata = dev_get_platdata(&dev->dev);
54 if (!pdata)
55 return -ENODEV;
57 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
58 if (!res)
59 return -ENODEV;
60 info = devm_kzalloc(&dev->dev, sizeof(struct rbtx4939_flash_info),
61 GFP_KERNEL);
62 if (!info)
63 return -ENOMEM;
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,
71 dev_name(&dev->dev)))
72 return -EBUSY;
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);
80 if (!info->map.virt)
81 return -EBUSY;
83 if (pdata->map_init)
84 (*pdata->map_init)(&info->map);
85 else
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);
91 if (!info->mtd) {
92 dev_err(&dev->dev, "map_probe failed\n");
93 err = -ENXIO;
94 goto err_out;
96 info->mtd->dev.parent = &dev->dev;
97 err = mtd_device_register(info->mtd, pdata->parts, pdata->nr_parts);
99 if (err)
100 goto err_out;
101 return 0;
103 err_out:
104 rbtx4939_flash_remove(dev);
105 return err;
108 #ifdef CONFIG_PM
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);
116 #else
117 #define rbtx4939_flash_shutdown NULL
118 #endif
120 static struct platform_driver rbtx4939_flash_driver = {
121 .probe = rbtx4939_flash_probe,
122 .remove = rbtx4939_flash_remove,
123 .shutdown = rbtx4939_flash_shutdown,
124 .driver = {
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");