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 {
29 struct mtd_partition *parts;
32 static int rbtx4939_flash_remove(struct platform_device *dev)
34 struct rbtx4939_flash_info *info;
36 info = platform_get_drvdata(dev);
39 platform_set_drvdata(dev, NULL);
42 struct rbtx4939_flash_data *pdata = dev->dev.platform_data;
46 mtd_device_unregister(info->mtd);
47 map_destroy(info->mtd);
52 static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
53 static const char *part_probe_types[] = { "cmdlinepart", NULL };
55 static int rbtx4939_flash_probe(struct platform_device *dev)
57 struct rbtx4939_flash_data *pdata;
58 struct rbtx4939_flash_info *info;
60 const char **probe_type;
64 pdata = dev->dev.platform_data;
68 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
71 info = devm_kzalloc(&dev->dev, sizeof(struct rbtx4939_flash_info),
76 platform_set_drvdata(dev, info);
78 size = resource_size(res);
79 pr_notice("rbtx4939 platform flash device: %pR\n", res);
81 if (!devm_request_mem_region(&dev->dev, res->start, size,
85 info->map.name = dev_name(&dev->dev);
86 info->map.phys = res->start;
87 info->map.size = size;
88 info->map.bankwidth = pdata->width;
90 info->map.virt = devm_ioremap(&dev->dev, info->map.phys, size);
95 (*pdata->map_init)(&info->map);
97 simple_map_init(&info->map);
99 probe_type = rom_probe_types;
100 for (; !info->mtd && *probe_type; probe_type++)
101 info->mtd = do_map_probe(*probe_type, &info->map);
103 dev_err(&dev->dev, "map_probe failed\n");
107 info->mtd->owner = THIS_MODULE;
111 err = parse_mtd_partitions(info->mtd, part_probe_types,
114 mtd_device_register(info->mtd, info->parts, err);
115 info->nr_parts = err;
119 if (pdata->nr_parts) {
120 pr_notice("Using rbtx4939 partition information\n");
121 mtd_device_register(info->mtd, pdata->parts, pdata->nr_parts);
125 mtd_device_register(info->mtd, NULL, 0);
129 rbtx4939_flash_remove(dev);
134 static void rbtx4939_flash_shutdown(struct platform_device *dev)
136 struct rbtx4939_flash_info *info = platform_get_drvdata(dev);
138 if (info->mtd->suspend && info->mtd->resume)
139 if (info->mtd->suspend(info->mtd) == 0)
140 info->mtd->resume(info->mtd);
143 #define rbtx4939_flash_shutdown NULL
146 static struct platform_driver rbtx4939_flash_driver = {
147 .probe = rbtx4939_flash_probe,
148 .remove = rbtx4939_flash_remove,
149 .shutdown = rbtx4939_flash_shutdown,
151 .name = "rbtx4939-flash",
152 .owner = THIS_MODULE,
156 static int __init rbtx4939_flash_init(void)
158 return platform_driver_register(&rbtx4939_flash_driver);
161 static void __exit rbtx4939_flash_exit(void)
163 platform_driver_unregister(&rbtx4939_flash_driver);
166 module_init(rbtx4939_flash_init);
167 module_exit(rbtx4939_flash_exit);
169 MODULE_LICENSE("GPL");
170 MODULE_DESCRIPTION("RBTX4939 MTD map driver");
171 MODULE_ALIAS("platform:rbtx4939-flash");