[go: nahoru, domu]

pismo.c revision 395b228858778d3c44f7c413693a6acaa8bb62dc
1f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux/*
2f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux * PISMO memory driver - http://www.pismoworld.org/
3f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux *
4f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux * For ARM Realview and Versatile platforms
5f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux *
6f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux * This program is free software; you can redistribute it and/or modify
7f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux * it under the terms of the GNU General Public License as published by
8f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux * the Free Software Foundation; either version 2 of the License.
9f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux */
10f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux#include <linux/init.h>
11f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux#include <linux/module.h>
12f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux#include <linux/i2c.h>
13f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux#include <linux/platform_device.h>
14f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux#include <linux/spinlock.h>
15f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux#include <linux/mutex.h>
16f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux#include <linux/mtd/physmap.h>
17f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux#include <linux/mtd/plat-ram.h>
18f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux#include <linux/mtd/pismo.h>
19f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
20f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux#define PISMO_NUM_CS	5
21f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
22f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstruct pismo_cs_block {
23f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	u8	type;
24f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	u8	width;
25f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	__le16	access;
26f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	__le32	size;
27f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	u32	reserved[2];
28f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	char	device[32];
29f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux} __packed;
30f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
31f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstruct pismo_eeprom {
32f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct pismo_cs_block cs[PISMO_NUM_CS];
33f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	char	board[15];
34f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	u8	sum;
35f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux} __packed;
36f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
37f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstruct pismo_mem {
38f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	phys_addr_t base;
39f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	u32	size;
40f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	u16	access;
41f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	u8	width;
42f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	u8	type;
43f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux};
44f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
45f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstruct pismo_data {
46f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct i2c_client	*client;
47f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	void			(*vpp)(void *, int);
48f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	void			*vpp_data;
49f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct platform_device	*dev[PISMO_NUM_CS];
50f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux};
51f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
52f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux/* FIXME: set_vpp could do with a better calling convention */
53f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic struct pismo_data *vpp_pismo;
54f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic DEFINE_MUTEX(pismo_mutex);
55f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
56f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic int pismo_setvpp_probe_fix(struct pismo_data *pismo)
57f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux{
58f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	mutex_lock(&pismo_mutex);
59f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	if (vpp_pismo) {
60f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		mutex_unlock(&pismo_mutex);
61f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		kfree(pismo);
62f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		return -EBUSY;
63f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	}
64f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	vpp_pismo = pismo;
65f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	mutex_unlock(&pismo_mutex);
66f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	return 0;
67f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux}
68f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
69f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic void pismo_setvpp_remove_fix(struct pismo_data *pismo)
70f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux{
71f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	mutex_lock(&pismo_mutex);
72f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	if (vpp_pismo == pismo)
73f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		vpp_pismo = NULL;
74f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	mutex_unlock(&pismo_mutex);
75f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux}
76f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
77f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic void pismo_set_vpp(struct map_info *map, int on)
78f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux{
79f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct pismo_data *pismo = vpp_pismo;
80f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
81f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	pismo->vpp(pismo->vpp_data, on);
82f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux}
83f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux/* end of hack */
84f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
85f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
86f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic unsigned int __devinit pismo_width_to_bytes(unsigned int width)
87f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux{
88f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	width &= 15;
89f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	if (width > 2)
90f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		return 0;
91f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	return 1 << width;
92f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux}
93f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
94f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic int __devinit pismo_eeprom_read(struct i2c_client *client, void *buf,
95f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	u8 addr, size_t size)
96f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux{
97f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	int ret;
98f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct i2c_msg msg[] = {
99f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		{
100f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux			.addr = client->addr,
101f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux			.len = sizeof(addr),
102f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux			.buf = &addr,
103f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		}, {
104f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux			.addr = client->addr,
105f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux			.flags = I2C_M_RD,
106f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux			.len = size,
107f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux			.buf = buf,
108f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		},
109f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	};
110f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
111f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
112f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
113f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	return ret == ARRAY_SIZE(msg) ? size : -EIO;
114f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux}
115f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
116f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic int __devinit pismo_add_device(struct pismo_data *pismo, int i,
117f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct pismo_mem *region, const char *name, void *pdata, size_t psize)
118f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux{
119f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct platform_device *dev;
120f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct resource res = { };
121f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	phys_addr_t base = region.base;
122f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	int ret;
123f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
124f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	if (base == ~0)
125f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		return -ENXIO;
126f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
127f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	res.start = base;
128f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	res.end = base + region->size - 1;
129f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	res.flags = IORESOURCE_MEM;
130f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
131f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	dev = platform_device_alloc(name, i);
132f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	if (!dev)
133f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		return -ENOMEM;
134f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	dev->dev.parent = &pismo->client->dev;
135f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
136f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	do {
137f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		ret = platform_device_add_resources(dev, &res, 1);
138f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		if (ret)
139f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux			break;
140f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
141f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		ret = platform_device_add_data(dev, pdata, psize);
142f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		if (ret)
143f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux			break;
144f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
145f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		ret = platform_device_add(dev);
146f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		if (ret)
147f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux			break;
148f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
149f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		pismo->dev[i] = dev;
150f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		return 0;
151f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	} while (0);
152f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
153f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	platform_device_put(dev);
154f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	return ret;
155f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux}
156f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
157f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic int __devinit pismo_add_nor(struct pismo_data *pismo, int i,
158f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct pismo_mem *region)
159f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux{
160f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct physmap_flash_data data = {
161f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		.width = region->width,
162f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	};
163f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
164f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	if (pismo->vpp)
165f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		data.set_vpp = pismo_set_vpp;
166f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
167f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	return pismo_add_device(pismo, i, region, "physmap-flash",
168f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		&data, sizeof(data));
169f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux}
170f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
171f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic int __devinit pismo_add_sram(struct pismo_data *pismo, int i,
172f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct pismo_mem *region)
173f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux{
174f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct platdata_mtd_ram data = {
175f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		.bankwidth = region->width,
176f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	};
177f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
178f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	return pismo_add_device(pismo, i, region, "mtd-ram",
179f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		&data, sizeof(data));
180f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux}
181f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
182f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic void __devinit pismo_add_one(struct pismo_data *pismo, int i,
183f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	const struct pismo_cs_block *cs, phys_addr_t base)
184f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux{
185f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct device *dev = &pismo->client->dev;
186f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct pismo_mem region;
187f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
188f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	region.base = base;
189f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	region.type = cs->type;
190f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	region.width = pismo_width_to_bytes(cs->width);
191f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	region.access = le16_to_cpu(cs->access);
192f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	region.size = le32_to_cpu(cs->size);
193f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
194f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	if (region.width == 0) {
195f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		dev_err(dev, "cs%u: bad width: %02x, ignoring\n", i, cs->width);
196f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		return;
197f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	}
198f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
199f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	/*
200f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	 * FIXME: may need to the platforms memory controller here, but at
201f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	 * the moment we assume that it has already been correctly setup.
202f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	 * The memory controller can also tell us the base address as well.
203f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	 */
204f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
205f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	dev_info(dev, "cs%u: %.32s: type %02x access %u00ps size %uK\n",
206f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		i, cs->device, region.type, region.access, region.size / 1024);
207f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
208f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	switch (region.type) {
209f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	case 0:
210f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		break;
211f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	case 1:
212f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		/* static DOC */
213f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		break;
214f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	case 2:
215f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		/* static NOR */
216f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		pismo_add_nor(pismo, i, &region);
217f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		break;
218f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	case 3:
219f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		/* static RAM */
220f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		pismo_add_sram(pismo, i, &region);
221f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		break;
222f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	}
223f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux}
224f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
225f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic int __devexit pismo_remove(struct i2c_client *client)
226f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux{
227f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct pismo_data *pismo = i2c_get_clientdata(client);
228f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	int i;
229f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
230f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	for (i = 0; i < ARRAY_SIZE(pismo->dev); i++)
231f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		platform_device_unregister(pismo->dev[i]);
232f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
233f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	/* FIXME: set_vpp needs saner arguments */
234f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	pismo_setvpp_remove_fix(pismo);
235f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
236395b228858778d3c44f7c413693a6acaa8bb62dcWolfram Sang	i2c_set_clientdata(client, NULL);
237f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	kfree(pismo);
238f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
239f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	return 0;
240f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux}
241f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
242f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic int __devinit pismo_probe(struct i2c_client *client,
243f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux				 const struct i2c_device_id *id)
244f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux{
245f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
246f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct pismo_pdata *pdata = client->dev.platform_data;
247f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct pismo_eeprom eeprom;
248f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	struct pismo_data *pismo;
249f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	int ret, i;
250f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
251f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
252f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		dev_err(&client->dev, "functionality mismatch\n");
253f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		return -EIO;
254f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	}
255f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
256f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	pismo = kzalloc(sizeof(*pismo), GFP_KERNEL);
257f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	if (!pismo)
258f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		return -ENOMEM;
259f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
260f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	/* FIXME: set_vpp needs saner arguments */
261f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	ret = pismo_setvpp_probe_fix(pismo);
262f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	if (ret)
263f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		return ret;
264f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
265f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	pismo->client = client;
266f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	if (pdata) {
267f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		pismo->vpp = pdata->set_vpp;
268f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		pismo->vpp_data = pdata->vpp_data;
269f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	}
270f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	i2c_set_clientdata(client, pismo);
271f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
272f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	ret = pismo_eeprom_read(client, &eeprom, 0, sizeof(eeprom));
273f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	if (ret < 0) {
274f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		dev_err(&client->dev, "error reading EEPROM: %d\n", ret);
275395b228858778d3c44f7c413693a6acaa8bb62dcWolfram Sang		goto exit_free;
276f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	}
277f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
278f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	dev_info(&client->dev, "%.15s board found\n", eeprom.board);
279f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
280f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	for (i = 0; i < ARRAY_SIZE(eeprom.cs); i++)
281f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		if (eeprom.cs[i].type != 0xff)
282f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux			pismo_add_one(pismo, i, &eeprom.cs[i],
283f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux				      pdata->cs_addrs[i]);
284f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
285f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	return 0;
286395b228858778d3c44f7c413693a6acaa8bb62dcWolfram Sang
287395b228858778d3c44f7c413693a6acaa8bb62dcWolfram Sang exit_free:
288395b228858778d3c44f7c413693a6acaa8bb62dcWolfram Sang	i2c_set_clientdata(client, NULL);
289395b228858778d3c44f7c413693a6acaa8bb62dcWolfram Sang	kfree(pismo);
290395b228858778d3c44f7c413693a6acaa8bb62dcWolfram Sang	return ret;
291f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux}
292f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
293f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic const struct i2c_device_id pismo_id[] = {
294f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	{ "pismo" },
295f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	{ },
296f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux};
297f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM LinuxMODULE_DEVICE_TABLE(i2c, pismo_id);
298f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
299f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic struct i2c_driver pismo_driver = {
300f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	.driver	= {
301f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		.name	= "pismo",
302f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux		.owner	= THIS_MODULE,
303f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	},
304f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	.probe		= pismo_probe,
305f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	.remove		= __devexit_p(pismo_remove),
306f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	.id_table	= pismo_id,
307f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux};
308f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
309f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic int __init pismo_init(void)
310f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux{
311f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	BUILD_BUG_ON(sizeof(struct pismo_cs_block) != 48);
312f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	BUILD_BUG_ON(sizeof(struct pismo_eeprom) != 256);
313f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
314f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	return i2c_add_driver(&pismo_driver);
315f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux}
316f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxmodule_init(pismo_init);
317f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
318f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxstatic void __exit pismo_exit(void)
319f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux{
320f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux	i2c_del_driver(&pismo_driver);
321f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux}
322f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linuxmodule_exit(pismo_exit);
323f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM Linux
324f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM LinuxMODULE_AUTHOR("Russell King <linux@arm.linux.org.uk>");
325f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM LinuxMODULE_DESCRIPTION("PISMO memory driver");
326f6a8c60960bbea378142d1fa1b3d111555ee41c7Russell King - ARM LinuxMODULE_LICENSE("GPL");
327