[DRIVER MODEL] Convert platform drivers to use struct platform_driver
[deliverable/linux.git] / drivers / mtd / maps / ixp2000.c
CommitLineData
1da177e4 1/*
69f34c98 2 * $Id: ixp2000.c,v 1.9 2005/11/07 11:14:27 gleixner Exp $
1da177e4
LT
3 *
4 * drivers/mtd/maps/ixp2000.c
5 *
6 * Mapping for the Intel XScale IXP2000 based systems
7 *
8 * Copyright (C) 2002 Intel Corp.
9 * Copyright (C) 2003-2004 MontaVista Software, Inc.
10 *
11 * Original Author: Naeem M Afzal <naeem.m.afzal@intel.com>
12 * Maintainer: Deepak Saxena <dsaxena@plexity.net>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
69f34c98 17 *
1da177e4
LT
18 */
19
20#include <linux/module.h>
21#include <linux/types.h>
22#include <linux/init.h>
23#include <linux/kernel.h>
24#include <linux/string.h>
4e57b681
TS
25#include <linux/slab.h>
26#include <linux/ioport.h>
27#include <linux/device.h>
4fd5f826 28#include <linux/platform_device.h>
4e57b681 29
1da177e4
LT
30#include <linux/mtd/mtd.h>
31#include <linux/mtd/map.h>
32#include <linux/mtd/partitions.h>
1da177e4
LT
33
34#include <asm/io.h>
35#include <asm/hardware.h>
1da177e4
LT
36#include <asm/mach/flash.h>
37
38#include <linux/reboot.h>
39
40struct ixp2000_flash_info {
41 struct mtd_info *mtd;
42 struct map_info map;
43 struct mtd_partition *partitions;
44 struct resource *res;
45 int nr_banks;
46};
47
48static inline unsigned long flash_bank_setup(struct map_info *map, unsigned long ofs)
69f34c98
TG
49{
50 unsigned long (*set_bank)(unsigned long) =
1da177e4
LT
51 (unsigned long(*)(unsigned long))map->map_priv_2;
52
53 return (set_bank ? set_bank(ofs) : ofs);
54}
55
56#ifdef __ARMEB__
57/*
69f34c98
TG
58 * Rev A0 and A1 of IXP2400 silicon have a broken addressing unit which
59 * causes the lower address bits to be XORed with 0x11 on 8 bit accesses
1da177e4
LT
60 * and XORed with 0x10 on 16 bit accesses. See the spec update, erratum 44.
61 */
62static int erratum44_workaround = 0;
63
64static inline unsigned long address_fix8_write(unsigned long addr)
65{
66 if (erratum44_workaround) {
67 return (addr ^ 3);
68 }
69 return addr;
70}
71#else
72
73#define address_fix8_write(x) (x)
74#endif
75
76static map_word ixp2000_flash_read8(struct map_info *map, unsigned long ofs)
77{
78 map_word val;
79
80 val.x[0] = *((u8 *)(map->map_priv_1 + flash_bank_setup(map, ofs)));
81 return val;
82}
83
84/*
85 * We can't use the standard memcpy due to the broken SlowPort
86 * address translation on rev A0 and A1 silicon and the fact that
87 * we have banked flash.
88 */
89static void ixp2000_flash_copy_from(struct map_info *map, void *to,
90 unsigned long from, ssize_t len)
91{
92 from = flash_bank_setup(map, from);
69f34c98 93 while(len--)
1da177e4
LT
94 *(__u8 *) to++ = *(__u8 *)(map->map_priv_1 + from++);
95}
96
97static void ixp2000_flash_write8(struct map_info *map, map_word d, unsigned long ofs)
98{
99 *(__u8 *) (address_fix8_write(map->map_priv_1 +
100 flash_bank_setup(map, ofs))) = d.x[0];
101}
102
103static void ixp2000_flash_copy_to(struct map_info *map, unsigned long to,
104 const void *from, ssize_t len)
105{
106 to = flash_bank_setup(map, to);
107 while(len--) {
108 unsigned long tmp = address_fix8_write(map->map_priv_1 + to++);
109 *(__u8 *)(tmp) = *(__u8 *)(from++);
110 }
111}
112
113
3ae5eaec 114static int ixp2000_flash_remove(struct platform_device *dev)
1da177e4 115{
1da177e4 116 struct flash_platform_data *plat = dev->dev.platform_data;
3ae5eaec 117 struct ixp2000_flash_info *info = platform_get_drvdata(dev);
1da177e4 118
3ae5eaec 119 platform_set_drvdata(dev, NULL);
1da177e4
LT
120
121 if(!info)
122 return 0;
123
124 if (info->mtd) {
125 del_mtd_partitions(info->mtd);
126 map_destroy(info->mtd);
127 }
128 if (info->map.map_priv_1)
129 iounmap((void *) info->map.map_priv_1);
130
fa671646 131 kfree(info->partitions);
1da177e4
LT
132
133 if (info->res) {
134 release_resource(info->res);
135 kfree(info->res);
136 }
137
138 if (plat->exit)
139 plat->exit();
140
141 return 0;
142}
143
144
3ae5eaec 145static int ixp2000_flash_probe(struct platform_device *dev)
1da177e4
LT
146{
147 static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
1da177e4 148 struct ixp2000_flash_data *ixp_data = dev->dev.platform_data;
69f34c98 149 struct flash_platform_data *plat;
1da177e4
LT
150 struct ixp2000_flash_info *info;
151 unsigned long window_size;
152 int err = -1;
69f34c98 153
1da177e4
LT
154 if (!ixp_data)
155 return -ENODEV;
156
157 plat = ixp_data->platform_data;
158 if (!plat)
159 return -ENODEV;
160
161 window_size = dev->resource->end - dev->resource->start + 1;
69f34c98 162 dev_info(_dev, "Probe of IXP2000 flash(%d banks x %dMiB)\n",
1da177e4
LT
163 ixp_data->nr_banks, ((u32)window_size >> 20));
164
165 if (plat->width != 1) {
166 dev_err(_dev, "IXP2000 MTD map only supports 8-bit mode, asking for %d\n",
167 plat->width * 8);
168 return -EIO;
169 }
170
171 info = kmalloc(sizeof(struct ixp2000_flash_info), GFP_KERNEL);
172 if(!info) {
173 err = -ENOMEM;
174 goto Error;
69f34c98 175 }
1da177e4
LT
176 memzero(info, sizeof(struct ixp2000_flash_info));
177
3ae5eaec 178 platform_set_drvdata(dev, info);
1da177e4
LT
179
180 /*
181 * Tell the MTD layer we're not 1:1 mapped so that it does
182 * not attempt to do a direct access on us.
183 */
184 info->map.phys = NO_XIP;
69f34c98 185
1da177e4
LT
186 info->nr_banks = ixp_data->nr_banks;
187 info->map.size = ixp_data->nr_banks * window_size;
188 info->map.bankwidth = 1;
189
190 /*
191 * map_priv_2 is used to store a ptr to to the bank_setup routine
192 */
ea17629f 193 info->map.map_priv_2 = (unsigned long) ixp_data->bank_setup;
1da177e4
LT
194
195 info->map.name = dev->dev.bus_id;
196 info->map.read = ixp2000_flash_read8;
197 info->map.write = ixp2000_flash_write8;
198 info->map.copy_from = ixp2000_flash_copy_from;
199 info->map.copy_to = ixp2000_flash_copy_to;
200
69f34c98
TG
201 info->res = request_mem_region(dev->resource->start,
202 dev->resource->end - dev->resource->start + 1,
1da177e4
LT
203 dev->dev.bus_id);
204 if (!info->res) {
205 dev_err(_dev, "Could not reserve memory region\n");
206 err = -ENOMEM;
207 goto Error;
208 }
209
69f34c98 210 info->map.map_priv_1 = (unsigned long) ioremap(dev->resource->start,
1da177e4
LT
211 dev->resource->end - dev->resource->start + 1);
212 if (!info->map.map_priv_1) {
213 dev_err(_dev, "Failed to ioremap flash region\n");
214 err = -EIO;
215 goto Error;
216 }
217
1da177e4
LT
218#if defined(__ARMEB__)
219 /*
220 * Enable erratum 44 workaround for NPUs with broken slowport
221 */
222
223 erratum44_workaround = ixp2000_has_broken_slowport();
224 dev_info(_dev, "Erratum 44 workaround %s\n",
225 erratum44_workaround ? "enabled" : "disabled");
226#endif
227
228 info->mtd = do_map_probe(plat->map_name, &info->map);
229 if (!info->mtd) {
230 dev_err(_dev, "map_probe failed\n");
231 err = -ENXIO;
232 goto Error;
233 }
234 info->mtd->owner = THIS_MODULE;
235
236 err = parse_mtd_partitions(info->mtd, probes, &info->partitions, 0);
237 if (err > 0) {
238 err = add_mtd_partitions(info->mtd, info->partitions, err);
239 if(err)
240 dev_err(_dev, "Could not parse partitions\n");
241 }
242
243 if (err)
244 goto Error;
245
246 return 0;
247
248Error:
3ae5eaec 249 ixp2000_flash_remove(dev);
1da177e4
LT
250 return err;
251}
252
3ae5eaec 253static struct platform_driver ixp2000_flash_driver = {
1da177e4
LT
254 .probe = &ixp2000_flash_probe,
255 .remove = &ixp2000_flash_remove
3ae5eaec
RK
256 .driver = {
257 .name = "IXP2000-Flash",
258 },
1da177e4
LT
259};
260
261static int __init ixp2000_flash_init(void)
262{
3ae5eaec 263 return platform_driver_register(&ixp2000_flash_driver);
1da177e4
LT
264}
265
266static void __exit ixp2000_flash_exit(void)
267{
3ae5eaec 268 platform_driver_unregister(&ixp2000_flash_driver);
1da177e4
LT
269}
270
271module_init(ixp2000_flash_init);
272module_exit(ixp2000_flash_exit);
273MODULE_LICENSE("GPL");
274MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
275
This page took 0.08615 seconds and 5 git commands to generate.