mtd: maps: add const qualifiers
[linux-2.6-microblaze.git] / drivers / mtd / maps / rbtx4939-flash.c
1 /*
2  * rbtx4939-flash (based on physmap.c)
3  *
4  * This is a simplified physmap driver with map_init callback function.
5  *
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.
9  *
10  * Copyright (C) 2009 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
11  */
12
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>
24
25 struct rbtx4939_flash_info {
26         struct mtd_info *mtd;
27         struct map_info map;
28 };
29
30 static int rbtx4939_flash_remove(struct platform_device *dev)
31 {
32         struct rbtx4939_flash_info *info;
33
34         info = platform_get_drvdata(dev);
35         if (!info)
36                 return 0;
37         platform_set_drvdata(dev, NULL);
38
39         if (info->mtd) {
40                 struct rbtx4939_flash_data *pdata = dev->dev.platform_data;
41
42                 mtd_device_unregister(info->mtd);
43                 map_destroy(info->mtd);
44         }
45         return 0;
46 }
47
48 static const char * const rom_probe_types[] = {
49         "cfi_probe", "jedec_probe", NULL };
50
51 static int rbtx4939_flash_probe(struct platform_device *dev)
52 {
53         struct rbtx4939_flash_data *pdata;
54         struct rbtx4939_flash_info *info;
55         struct resource *res;
56         const char * const *probe_type;
57         int err = 0;
58         unsigned long size;
59
60         pdata = dev->dev.platform_data;
61         if (!pdata)
62                 return -ENODEV;
63
64         res = platform_get_resource(dev, IORESOURCE_MEM, 0);
65         if (!res)
66                 return -ENODEV;
67         info = devm_kzalloc(&dev->dev, sizeof(struct rbtx4939_flash_info),
68                             GFP_KERNEL);
69         if (!info)
70                 return -ENOMEM;
71
72         platform_set_drvdata(dev, info);
73
74         size = resource_size(res);
75         pr_notice("rbtx4939 platform flash device: %pR\n", res);
76
77         if (!devm_request_mem_region(&dev->dev, res->start, size,
78                                      dev_name(&dev->dev)))
79                 return -EBUSY;
80
81         info->map.name = dev_name(&dev->dev);
82         info->map.phys = res->start;
83         info->map.size = size;
84         info->map.bankwidth = pdata->width;
85
86         info->map.virt = devm_ioremap(&dev->dev, info->map.phys, size);
87         if (!info->map.virt)
88                 return -EBUSY;
89
90         if (pdata->map_init)
91                 (*pdata->map_init)(&info->map);
92         else
93                 simple_map_init(&info->map);
94
95         probe_type = rom_probe_types;
96         for (; !info->mtd && *probe_type; probe_type++)
97                 info->mtd = do_map_probe(*probe_type, &info->map);
98         if (!info->mtd) {
99                 dev_err(&dev->dev, "map_probe failed\n");
100                 err = -ENXIO;
101                 goto err_out;
102         }
103         info->mtd->owner = THIS_MODULE;
104         err = mtd_device_parse_register(info->mtd, NULL, NULL, pdata->parts,
105                                         pdata->nr_parts);
106
107         if (err)
108                 goto err_out;
109         return 0;
110
111 err_out:
112         rbtx4939_flash_remove(dev);
113         return err;
114 }
115
116 #ifdef CONFIG_PM
117 static void rbtx4939_flash_shutdown(struct platform_device *dev)
118 {
119         struct rbtx4939_flash_info *info = platform_get_drvdata(dev);
120
121         if (mtd_suspend(info->mtd) == 0)
122                 mtd_resume(info->mtd);
123 }
124 #else
125 #define rbtx4939_flash_shutdown NULL
126 #endif
127
128 static struct platform_driver rbtx4939_flash_driver = {
129         .probe          = rbtx4939_flash_probe,
130         .remove         = rbtx4939_flash_remove,
131         .shutdown       = rbtx4939_flash_shutdown,
132         .driver         = {
133                 .name   = "rbtx4939-flash",
134                 .owner  = THIS_MODULE,
135         },
136 };
137
138 module_platform_driver(rbtx4939_flash_driver);
139
140 MODULE_LICENSE("GPL");
141 MODULE_DESCRIPTION("RBTX4939 MTD map driver");
142 MODULE_ALIAS("platform:rbtx4939-flash");