acpi_pad: build only on X86
[linux-2.6/linux-acpi-2.6.git] / drivers / mtd / maps / rbtx4939-flash.c
blob83ed64512c5e6f076192abf097cb9aacde1c2ab6
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 #ifdef CONFIG_MTD_PARTITIONS
29 int nr_parts;
30 struct mtd_partition *parts;
31 #endif
34 static int rbtx4939_flash_remove(struct platform_device *dev)
36 struct rbtx4939_flash_info *info;
38 info = platform_get_drvdata(dev);
39 if (!info)
40 return 0;
41 platform_set_drvdata(dev, NULL);
43 if (info->mtd) {
44 #ifdef CONFIG_MTD_PARTITIONS
45 struct rbtx4939_flash_data *pdata = dev->dev.platform_data;
47 if (info->nr_parts) {
48 del_mtd_partitions(info->mtd);
49 kfree(info->parts);
50 } else if (pdata->nr_parts)
51 del_mtd_partitions(info->mtd);
52 else
53 del_mtd_device(info->mtd);
54 #else
55 del_mtd_device(info->mtd);
56 #endif
57 map_destroy(info->mtd);
59 return 0;
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 };
65 #endif
67 static int rbtx4939_flash_probe(struct platform_device *dev)
69 struct rbtx4939_flash_data *pdata;
70 struct rbtx4939_flash_info *info;
71 struct resource *res;
72 const char **probe_type;
73 int err = 0;
74 unsigned long size;
76 pdata = dev->dev.platform_data;
77 if (!pdata)
78 return -ENODEV;
80 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
81 if (!res)
82 return -ENODEV;
83 info = devm_kzalloc(&dev->dev, sizeof(struct rbtx4939_flash_info),
84 GFP_KERNEL);
85 if (!info)
86 return -ENOMEM;
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,
94 dev_name(&dev->dev)))
95 return -EBUSY;
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);
103 if (!info->map.virt)
104 return -EBUSY;
106 if (pdata->map_init)
107 (*pdata->map_init)(&info->map);
108 else
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);
114 if (!info->mtd) {
115 dev_err(&dev->dev, "map_probe failed\n");
116 err = -ENXIO;
117 goto err_out;
119 info->mtd->owner = THIS_MODULE;
120 if (err)
121 goto err_out;
123 #ifdef CONFIG_MTD_PARTITIONS
124 err = parse_mtd_partitions(info->mtd, part_probe_types,
125 &info->parts, 0);
126 if (err > 0) {
127 add_mtd_partitions(info->mtd, info->parts, err);
128 info->nr_parts = err;
129 return 0;
132 if (pdata->nr_parts) {
133 pr_notice("Using rbtx4939 partition information\n");
134 add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts);
135 return 0;
137 #endif
139 add_mtd_device(info->mtd);
140 return 0;
142 err_out:
143 rbtx4939_flash_remove(dev);
144 return err;
147 #ifdef CONFIG_PM
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);
156 #else
157 #define rbtx4939_flash_shutdown NULL
158 #endif
160 static struct platform_driver rbtx4939_flash_driver = {
161 .probe = rbtx4939_flash_probe,
162 .remove = rbtx4939_flash_remove,
163 .shutdown = rbtx4939_flash_shutdown,
164 .driver = {
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");