include: replace linux/module.h with "struct module" wherever possible
[linux-2.6/next.git] / drivers / mtd / maps / rbtx4939-flash.c
blob761fb459d2c74179105fb9ded586681c66ae6aae
1 /*
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 {
26 struct mtd_info *mtd;
27 struct map_info map;
28 int nr_parts;
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);
37 if (!info)
38 return 0;
39 platform_set_drvdata(dev, NULL);
41 if (info->mtd) {
42 struct rbtx4939_flash_data *pdata = dev->dev.platform_data;
44 if (info->nr_parts)
45 kfree(info->parts);
46 mtd_device_unregister(info->mtd);
47 map_destroy(info->mtd);
49 return 0;
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;
59 struct resource *res;
60 const char **probe_type;
61 int err = 0;
62 unsigned long size;
64 pdata = dev->dev.platform_data;
65 if (!pdata)
66 return -ENODEV;
68 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
69 if (!res)
70 return -ENODEV;
71 info = devm_kzalloc(&dev->dev, sizeof(struct rbtx4939_flash_info),
72 GFP_KERNEL);
73 if (!info)
74 return -ENOMEM;
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,
82 dev_name(&dev->dev)))
83 return -EBUSY;
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);
91 if (!info->map.virt)
92 return -EBUSY;
94 if (pdata->map_init)
95 (*pdata->map_init)(&info->map);
96 else
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);
102 if (!info->mtd) {
103 dev_err(&dev->dev, "map_probe failed\n");
104 err = -ENXIO;
105 goto err_out;
107 info->mtd->owner = THIS_MODULE;
108 if (err)
109 goto err_out;
111 err = parse_mtd_partitions(info->mtd, part_probe_types,
112 &info->parts, 0);
113 if (err > 0) {
114 mtd_device_register(info->mtd, info->parts, err);
115 info->nr_parts = err;
116 return 0;
119 if (pdata->nr_parts) {
120 pr_notice("Using rbtx4939 partition information\n");
121 mtd_device_register(info->mtd, pdata->parts, pdata->nr_parts);
122 return 0;
125 mtd_device_register(info->mtd, NULL, 0);
126 return 0;
128 err_out:
129 rbtx4939_flash_remove(dev);
130 return err;
133 #ifdef CONFIG_PM
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);
142 #else
143 #define rbtx4939_flash_shutdown NULL
144 #endif
146 static struct platform_driver rbtx4939_flash_driver = {
147 .probe = rbtx4939_flash_probe,
148 .remove = rbtx4939_flash_remove,
149 .shutdown = rbtx4939_flash_shutdown,
150 .driver = {
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");