diff options
author | John Crispin <blogic@openwrt.org> | 2012-04-13 03:36:46 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2012-05-21 09:31:55 -0400 |
commit | 02fa961fbf1c79783781cb8967b80ceaa8be4832 (patch) | |
tree | 4ed7bbcb5854ee1009d8ab3783768ba377d4c4b6 /drivers/mtd/maps/lantiq-flash.c | |
parent | cdb8612147b7fba751e6fa193f32b09937a7e16b (diff) |
MTD: MIPS: lantiq: implement OF support
Adds bindings for OF and make use of module_platform_driver for lantiq
based socs.
Signed-off-by: John Crispin <blogic@openwrt.org>
Acked-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Cc: linux-mtd@lists.infradead.org
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/3811/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'drivers/mtd/maps/lantiq-flash.c')
-rw-r--r-- | drivers/mtd/maps/lantiq-flash.c | 69 |
1 files changed, 25 insertions, 44 deletions
diff --git a/drivers/mtd/maps/lantiq-flash.c b/drivers/mtd/maps/lantiq-flash.c index b5401e355745..aefa11121674 100644 --- a/drivers/mtd/maps/lantiq-flash.c +++ b/drivers/mtd/maps/lantiq-flash.c | |||
@@ -21,7 +21,6 @@ | |||
21 | #include <linux/mtd/physmap.h> | 21 | #include <linux/mtd/physmap.h> |
22 | 22 | ||
23 | #include <lantiq_soc.h> | 23 | #include <lantiq_soc.h> |
24 | #include <lantiq_platform.h> | ||
25 | 24 | ||
26 | /* | 25 | /* |
27 | * The NOR flash is connected to the same external bus unit (EBU) as PCI. | 26 | * The NOR flash is connected to the same external bus unit (EBU) as PCI. |
@@ -44,8 +43,9 @@ struct ltq_mtd { | |||
44 | struct map_info *map; | 43 | struct map_info *map; |
45 | }; | 44 | }; |
46 | 45 | ||
47 | static char ltq_map_name[] = "ltq_nor"; | 46 | static const char ltq_map_name[] = "ltq_nor"; |
48 | static const char *ltq_probe_types[] __devinitconst = { "cmdlinepart", NULL }; | 47 | static const char *ltq_probe_types[] __devinitconst = { |
48 | "cmdlinepart", "ofpart", NULL }; | ||
49 | 49 | ||
50 | static map_word | 50 | static map_word |
51 | ltq_read16(struct map_info *map, unsigned long adr) | 51 | ltq_read16(struct map_info *map, unsigned long adr) |
@@ -108,12 +108,11 @@ ltq_copy_to(struct map_info *map, unsigned long to, | |||
108 | spin_unlock_irqrestore(&ebu_lock, flags); | 108 | spin_unlock_irqrestore(&ebu_lock, flags); |
109 | } | 109 | } |
110 | 110 | ||
111 | static int __init | 111 | static int __devinit |
112 | ltq_mtd_probe(struct platform_device *pdev) | 112 | ltq_mtd_probe(struct platform_device *pdev) |
113 | { | 113 | { |
114 | struct physmap_flash_data *ltq_mtd_data = dev_get_platdata(&pdev->dev); | 114 | struct mtd_part_parser_data ppdata; |
115 | struct ltq_mtd *ltq_mtd; | 115 | struct ltq_mtd *ltq_mtd; |
116 | struct resource *res; | ||
117 | struct cfi_private *cfi; | 116 | struct cfi_private *cfi; |
118 | int err; | 117 | int err; |
119 | 118 | ||
@@ -122,28 +121,19 @@ ltq_mtd_probe(struct platform_device *pdev) | |||
122 | 121 | ||
123 | ltq_mtd->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 122 | ltq_mtd->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
124 | if (!ltq_mtd->res) { | 123 | if (!ltq_mtd->res) { |
125 | dev_err(&pdev->dev, "failed to get memory resource"); | 124 | dev_err(&pdev->dev, "failed to get memory resource\n"); |
126 | err = -ENOENT; | 125 | err = -ENOENT; |
127 | goto err_out; | 126 | goto err_out; |
128 | } | 127 | } |
129 | 128 | ||
130 | res = devm_request_mem_region(&pdev->dev, ltq_mtd->res->start, | ||
131 | resource_size(ltq_mtd->res), dev_name(&pdev->dev)); | ||
132 | if (!ltq_mtd->res) { | ||
133 | dev_err(&pdev->dev, "failed to request mem resource"); | ||
134 | err = -EBUSY; | ||
135 | goto err_out; | ||
136 | } | ||
137 | |||
138 | ltq_mtd->map = kzalloc(sizeof(struct map_info), GFP_KERNEL); | 129 | ltq_mtd->map = kzalloc(sizeof(struct map_info), GFP_KERNEL); |
139 | ltq_mtd->map->phys = res->start; | 130 | ltq_mtd->map->phys = ltq_mtd->res->start; |
140 | ltq_mtd->map->size = resource_size(res); | 131 | ltq_mtd->map->size = resource_size(ltq_mtd->res); |
141 | ltq_mtd->map->virt = devm_ioremap_nocache(&pdev->dev, | 132 | ltq_mtd->map->virt = devm_request_and_ioremap(&pdev->dev, ltq_mtd->res); |
142 | ltq_mtd->map->phys, ltq_mtd->map->size); | ||
143 | if (!ltq_mtd->map->virt) { | 133 | if (!ltq_mtd->map->virt) { |
144 | dev_err(&pdev->dev, "failed to ioremap!\n"); | 134 | dev_err(&pdev->dev, "failed to remap mem resource\n"); |
145 | err = -ENOMEM; | 135 | err = -EBUSY; |
146 | goto err_free; | 136 | goto err_out; |
147 | } | 137 | } |
148 | 138 | ||
149 | ltq_mtd->map->name = ltq_map_name; | 139 | ltq_mtd->map->name = ltq_map_name; |
@@ -169,9 +159,9 @@ ltq_mtd_probe(struct platform_device *pdev) | |||
169 | cfi->addr_unlock1 ^= 1; | 159 | cfi->addr_unlock1 ^= 1; |
170 | cfi->addr_unlock2 ^= 1; | 160 | cfi->addr_unlock2 ^= 1; |
171 | 161 | ||
172 | err = mtd_device_parse_register(ltq_mtd->mtd, ltq_probe_types, NULL, | 162 | ppdata.of_node = pdev->dev.of_node; |
173 | ltq_mtd_data->parts, | 163 | err = mtd_device_parse_register(ltq_mtd->mtd, ltq_probe_types, |
174 | ltq_mtd_data->nr_parts); | 164 | &ppdata, NULL, 0); |
175 | if (err) { | 165 | if (err) { |
176 | dev_err(&pdev->dev, "failed to add partitions\n"); | 166 | dev_err(&pdev->dev, "failed to add partitions\n"); |
177 | goto err_destroy; | 167 | goto err_destroy; |
@@ -204,32 +194,23 @@ ltq_mtd_remove(struct platform_device *pdev) | |||
204 | return 0; | 194 | return 0; |
205 | } | 195 | } |
206 | 196 | ||
197 | static const struct of_device_id ltq_mtd_match[] = { | ||
198 | { .compatible = "lantiq,nor" }, | ||
199 | {}, | ||
200 | }; | ||
201 | MODULE_DEVICE_TABLE(of, ltq_mtd_match); | ||
202 | |||
207 | static struct platform_driver ltq_mtd_driver = { | 203 | static struct platform_driver ltq_mtd_driver = { |
204 | .probe = ltq_mtd_probe, | ||
208 | .remove = __devexit_p(ltq_mtd_remove), | 205 | .remove = __devexit_p(ltq_mtd_remove), |
209 | .driver = { | 206 | .driver = { |
210 | .name = "ltq_nor", | 207 | .name = "ltq-nor", |
211 | .owner = THIS_MODULE, | 208 | .owner = THIS_MODULE, |
209 | .of_match_table = ltq_mtd_match, | ||
212 | }, | 210 | }, |
213 | }; | 211 | }; |
214 | 212 | ||
215 | static int __init | 213 | module_platform_driver(ltq_mtd_driver); |
216 | init_ltq_mtd(void) | ||
217 | { | ||
218 | int ret = platform_driver_probe(<q_mtd_driver, ltq_mtd_probe); | ||
219 | |||
220 | if (ret) | ||
221 | pr_err("ltq_nor: error registering platform driver"); | ||
222 | return ret; | ||
223 | } | ||
224 | |||
225 | static void __exit | ||
226 | exit_ltq_mtd(void) | ||
227 | { | ||
228 | platform_driver_unregister(<q_mtd_driver); | ||
229 | } | ||
230 | |||
231 | module_init(init_ltq_mtd); | ||
232 | module_exit(exit_ltq_mtd); | ||
233 | 214 | ||
234 | MODULE_LICENSE("GPL"); | 215 | MODULE_LICENSE("GPL"); |
235 | MODULE_AUTHOR("John Crispin <blogic@openwrt.org>"); | 216 | MODULE_AUTHOR("John Crispin <blogic@openwrt.org>"); |