]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/mtd/maps/ixp4xx.c
[MTD] NAND sharpsl.c: Add support for akita and borzoi models
[mirror_ubuntu-artful-kernel.git] / drivers / mtd / maps / ixp4xx.c
CommitLineData
1da177e4 1/*
e4c212ef 2 * $Id: ixp4xx.c,v 1.8 2005/09/08 10:32:20 dvrabel Exp $
1da177e4
LT
3 *
4 * drivers/mtd/maps/ixp4xx.c
5 *
6 * MTD Map file for IXP4XX based systems. Please do not make per-board
7 * changes in here. If your board needs special setup, do it in your
8 * platform level code in arch/arm/mach-ixp4xx/board-setup.c
9 *
10 * Original Author: Intel Corporation
11 * Maintainer: Deepak Saxena <dsaxena@mvista.com>
12 *
13 * Copyright (C) 2002 Intel Corporation
14 * Copyright (C) 2003-2004 MontaVista Software, Inc.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/types.h>
20#include <linux/init.h>
21#include <linux/kernel.h>
22#include <linux/string.h>
4e57b681
TS
23#include <linux/slab.h>
24#include <linux/ioport.h>
25#include <linux/device.h>
4fd5f826 26#include <linux/platform_device.h>
4e57b681 27
1da177e4
LT
28#include <linux/mtd/mtd.h>
29#include <linux/mtd/map.h>
30#include <linux/mtd/partitions.h>
4e57b681 31
1da177e4 32#include <asm/io.h>
1da177e4
LT
33#include <asm/mach/flash.h>
34
35#include <linux/reboot.h>
36
37#ifndef __ARMEB__
38#define BYTE0(h) ((h) & 0xFF)
39#define BYTE1(h) (((h) >> 8) & 0xFF)
40#else
41#define BYTE0(h) (((h) >> 8) & 0xFF)
42#define BYTE1(h) ((h) & 0xFF)
43#endif
44
45static map_word ixp4xx_read16(struct map_info *map, unsigned long ofs)
46{
47 map_word val;
48 val.x[0] = *(__u16 *) (map->map_priv_1 + ofs);
49 return val;
50}
51
52/*
53 * The IXP4xx expansion bus only allows 16-bit wide acceses
54 * when attached to a 16-bit wide device (such as the 28F128J3A),
55 * so we can't just memcpy_fromio().
56 */
57static void ixp4xx_copy_from(struct map_info *map, void *to,
58 unsigned long from, ssize_t len)
59{
60 int i;
61 u8 *dest = (u8 *) to;
62 u16 *src = (u16 *) (map->map_priv_1 + from);
63 u16 data;
64
65 for (i = 0; i < (len / 2); i++) {
66 data = src[i];
67 dest[i * 2] = BYTE0(data);
68 dest[i * 2 + 1] = BYTE1(data);
69 }
70
71 if (len & 1)
72 dest[len - 1] = BYTE0(src[i]);
73}
74
75/*
76 * Unaligned writes are ignored, causing the 8-bit
77 * probe to fail and proceed to the 16-bit probe (which succeeds).
78 */
79static void ixp4xx_probe_write16(struct map_info *map, map_word d, unsigned long adr)
80{
81 if (!(adr & 1))
82 *(__u16 *) (map->map_priv_1 + adr) = d.x[0];
83}
84
85/*
86 * Fast write16 function without the probing check above
87 */
88static void ixp4xx_write16(struct map_info *map, map_word d, unsigned long adr)
89{
90 *(__u16 *) (map->map_priv_1 + adr) = d.x[0];
91}
92
93struct ixp4xx_flash_info {
94 struct mtd_info *mtd;
95 struct map_info map;
96 struct mtd_partition *partitions;
97 struct resource *res;
98};
99
100static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
101
102static int ixp4xx_flash_remove(struct device *_dev)
103{
104 struct platform_device *dev = to_platform_device(_dev);
105 struct flash_platform_data *plat = dev->dev.platform_data;
106 struct ixp4xx_flash_info *info = dev_get_drvdata(&dev->dev);
107 map_word d;
108
109 dev_set_drvdata(&dev->dev, NULL);
110
111 if(!info)
112 return 0;
113
1da177e4
LT
114 if (info->mtd) {
115 del_mtd_partitions(info->mtd);
116 map_destroy(info->mtd);
117 }
118 if (info->map.map_priv_1)
119 iounmap((void *) info->map.map_priv_1);
120
121 if (info->partitions)
122 kfree(info->partitions);
123
124 if (info->res) {
125 release_resource(info->res);
126 kfree(info->res);
127 }
128
129 if (plat->exit)
130 plat->exit();
131
1da177e4
LT
132 return 0;
133}
134
135static int ixp4xx_flash_probe(struct device *_dev)
136{
137 struct platform_device *dev = to_platform_device(_dev);
138 struct flash_platform_data *plat = dev->dev.platform_data;
139 struct ixp4xx_flash_info *info;
140 int err = -1;
141
142 if (!plat)
143 return -ENODEV;
144
145 if (plat->init) {
146 err = plat->init();
147 if (err)
148 return err;
149 }
150
151 info = kmalloc(sizeof(struct ixp4xx_flash_info), GFP_KERNEL);
152 if(!info) {
153 err = -ENOMEM;
154 goto Error;
155 }
156 memzero(info, sizeof(struct ixp4xx_flash_info));
157
158 dev_set_drvdata(&dev->dev, info);
159
1da177e4
LT
160 /*
161 * Tell the MTD layer we're not 1:1 mapped so that it does
162 * not attempt to do a direct access on us.
163 */
164 info->map.phys = NO_XIP;
165 info->map.size = dev->resource->end - dev->resource->start + 1;
166
167 /*
168 * We only support 16-bit accesses for now. If and when
169 * any board use 8-bit access, we'll fixup the driver to
170 * handle that.
171 */
172 info->map.bankwidth = 2;
173 info->map.name = dev->dev.bus_id;
174 info->map.read = ixp4xx_read16,
175 info->map.write = ixp4xx_probe_write16,
176 info->map.copy_from = ixp4xx_copy_from,
177
178 info->res = request_mem_region(dev->resource->start,
179 dev->resource->end - dev->resource->start + 1,
180 "IXP4XXFlash");
181 if (!info->res) {
182 printk(KERN_ERR "IXP4XXFlash: Could not reserve memory region\n");
183 err = -ENOMEM;
184 goto Error;
185 }
186
187 info->map.map_priv_1 = ioremap(dev->resource->start,
188 dev->resource->end - dev->resource->start + 1);
189 if (!info->map.map_priv_1) {
190 printk(KERN_ERR "IXP4XXFlash: Failed to ioremap region\n");
191 err = -EIO;
192 goto Error;
193 }
194
195 info->mtd = do_map_probe(plat->map_name, &info->map);
196 if (!info->mtd) {
197 printk(KERN_ERR "IXP4XXFlash: map_probe failed\n");
198 err = -ENXIO;
199 goto Error;
200 }
201 info->mtd->owner = THIS_MODULE;
202
203 /* Use the fast version */
204 info->map.write = ixp4xx_write16,
205
206 err = parse_mtd_partitions(info->mtd, probes, &info->partitions, 0);
207 if (err > 0) {
208 err = add_mtd_partitions(info->mtd, info->partitions, err);
209 if(err)
210 printk(KERN_ERR "Could not parse partitions\n");
211 }
212
213 if (err)
214 goto Error;
215
216 return 0;
217
218Error:
219 ixp4xx_flash_remove(_dev);
220 return err;
221}
222
223static struct device_driver ixp4xx_flash_driver = {
224 .name = "IXP4XX-Flash",
225 .bus = &platform_bus_type,
226 .probe = ixp4xx_flash_probe,
227 .remove = ixp4xx_flash_remove,
228};
229
230static int __init ixp4xx_flash_init(void)
231{
232 return driver_register(&ixp4xx_flash_driver);
233}
234
235static void __exit ixp4xx_flash_exit(void)
236{
237 driver_unregister(&ixp4xx_flash_driver);
238}
239
240
241module_init(ixp4xx_flash_init);
242module_exit(ixp4xx_flash_exit);
243
244MODULE_LICENSE("GPL");
82810a90 245MODULE_DESCRIPTION("MTD map driver for Intel IXP4xx systems");
1da177e4
LT
246MODULE_AUTHOR("Deepak Saxena");
247