2 * rbtx4939-flash (based on physmap.c)
4 * This is a simplified physmap driver with map_init callback function.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Copyright (C) 2009 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/slab.h>
18 #include <linux/device.h>
19 #include <linux/platform_device.h>
20 #include <linux/mtd/mtd.h>
21 #include <linux/mtd/map.h>
22 #include <linux/mtd/partitions.h>
23 #include <asm/txx9/rbtx4939.h>
25 struct rbtx4939_flash_info {
28 #ifdef CONFIG_MTD_PARTITIONS
30 struct mtd_partition *parts;
34 static int rbtx4939_flash_remove(struct platform_device *dev)
36 struct rbtx4939_flash_info *info;
38 info = platform_get_drvdata(dev);
41 platform_set_drvdata(dev, NULL);
44 #ifdef CONFIG_MTD_PARTITIONS
45 struct rbtx4939_flash_data *pdata = dev->dev.platform_data;
48 del_mtd_partitions(info->mtd);
50 } else if (pdata->nr_parts)
51 del_mtd_partitions(info->mtd);
53 del_mtd_device(info->mtd);
55 del_mtd_device(info->mtd);
57 map_destroy(info->mtd);
62 static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
63 #ifdef CONFIG_MTD_PARTITIONS
64 static const char *part_probe_types[] = { "cmdlinepart", NULL };
67 static int rbtx4939_flash_probe(struct platform_device *dev)
69 struct rbtx4939_flash_data *pdata;
70 struct rbtx4939_flash_info *info;
72 const char **probe_type;
76 pdata = dev->dev.platform_data;
80 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
83 info = devm_kzalloc(&dev->dev, sizeof(struct rbtx4939_flash_info),
88 platform_set_drvdata(dev, info);
90 size = resource_size(res);
91 pr_notice("rbtx4939 platform flash device: %pR\n", res);
93 if (!devm_request_mem_region(&dev->dev, res->start, size,
97 info->map.name = dev_name(&dev->dev);
98 info->map.phys = res->start;
99 info->map.size = size;
100 info->map.bankwidth = pdata->width;
102 info->map.virt = devm_ioremap(&dev->dev, info->map.phys, size);
107 (*pdata->map_init)(&info->map);
109 simple_map_init(&info->map);
111 probe_type = rom_probe_types;
112 for (; !info->mtd && *probe_type; probe_type++)
113 info->mtd = do_map_probe(*probe_type, &info->map);
115 dev_err(&dev->dev, "map_probe failed\n");
119 info->mtd->owner = THIS_MODULE;
123 #ifdef CONFIG_MTD_PARTITIONS
124 err = parse_mtd_partitions(info->mtd, part_probe_types,
127 add_mtd_partitions(info->mtd, info->parts, err);
128 info->nr_parts = err;
132 if (pdata->nr_parts) {
133 pr_notice("Using rbtx4939 partition information\n");
134 add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts);
139 add_mtd_device(info->mtd);
143 rbtx4939_flash_remove(dev);
148 static void rbtx4939_flash_shutdown(struct platform_device *dev)
150 struct rbtx4939_flash_info *info = platform_get_drvdata(dev);
152 if (info->mtd->suspend && info->mtd->resume)
153 if (info->mtd->suspend(info->mtd) == 0)
154 info->mtd->resume(info->mtd);
157 #define rbtx4939_flash_shutdown NULL
160 static struct platform_driver rbtx4939_flash_driver = {
161 .probe = rbtx4939_flash_probe,
162 .remove = rbtx4939_flash_remove,
163 .shutdown = rbtx4939_flash_shutdown,
165 .name = "rbtx4939-flash",
166 .owner = THIS_MODULE,
170 static int __init rbtx4939_flash_init(void)
172 return platform_driver_register(&rbtx4939_flash_driver);
175 static void __exit rbtx4939_flash_exit(void)
177 platform_driver_unregister(&rbtx4939_flash_driver);
180 module_init(rbtx4939_flash_init);
181 module_exit(rbtx4939_flash_exit);
183 MODULE_LICENSE("GPL");
184 MODULE_DESCRIPTION("RBTX4939 MTD map driver");
185 MODULE_ALIAS("platform:rbtx4939-flash");