xref: /openbmc/linux/drivers/mtd/maps/pcmciamtd.c (revision 81d67439)
1 /*
2  * pcmciamtd.c - MTD driver for PCMCIA flash memory cards
3  *
4  * Author: Simon Evans <spse@secret.org.uk>
5  *
6  * Copyright (C) 2002 Simon Evans
7  *
8  * Licence: GPL
9  *
10  */
11 
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/timer.h>
15 #include <linux/init.h>
16 #include <asm/io.h>
17 #include <asm/system.h>
18 
19 #include <pcmcia/cistpl.h>
20 #include <pcmcia/ds.h>
21 
22 #include <linux/mtd/map.h>
23 #include <linux/mtd/mtd.h>
24 
25 #ifdef CONFIG_MTD_DEBUG
26 static int debug = CONFIG_MTD_DEBUG_VERBOSE;
27 module_param(debug, int, 0);
28 MODULE_PARM_DESC(debug, "Set Debug Level 0=quiet, 5=noisy");
29 #undef DEBUG
30 #define DEBUG(n, format, arg...) \
31 	if (n <= debug) {	 \
32 		printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __func__ , ## arg); \
33 	}
34 
35 #else
36 #undef DEBUG
37 #define DEBUG(n, arg...)
38 static const int debug = 0;
39 #endif
40 
41 #define info(format, arg...) printk(KERN_INFO "pcmciamtd: " format "\n" , ## arg)
42 
43 #define DRIVER_DESC	"PCMCIA Flash memory card driver"
44 
45 /* Size of the PCMCIA address space: 26 bits = 64 MB */
46 #define MAX_PCMCIA_ADDR	0x4000000
47 
48 struct pcmciamtd_dev {
49 	struct pcmcia_device	*p_dev;
50 	caddr_t		win_base;	/* ioremapped address of PCMCIA window */
51 	unsigned int	win_size;	/* size of window */
52 	unsigned int	offset;		/* offset into card the window currently points at */
53 	struct map_info	pcmcia_map;
54 	struct mtd_info	*mtd_info;
55 	int		vpp;
56 	char		mtd_name[sizeof(struct cistpl_vers_1_t)];
57 };
58 
59 
60 /* Module parameters */
61 
62 /* 2 = do 16-bit transfers, 1 = do 8-bit transfers */
63 static int bankwidth = 2;
64 
65 /* Speed of memory accesses, in ns */
66 static int mem_speed;
67 
68 /* Force the size of an SRAM card */
69 static int force_size;
70 
71 /* Force Vpp */
72 static int vpp;
73 
74 /* Set Vpp */
75 static int setvpp;
76 
77 /* Force card to be treated as FLASH, ROM or RAM */
78 static int mem_type;
79 
80 MODULE_LICENSE("GPL");
81 MODULE_AUTHOR("Simon Evans <spse@secret.org.uk>");
82 MODULE_DESCRIPTION(DRIVER_DESC);
83 module_param(bankwidth, int, 0);
84 MODULE_PARM_DESC(bankwidth, "Set bankwidth (1=8 bit, 2=16 bit, default=2)");
85 module_param(mem_speed, int, 0);
86 MODULE_PARM_DESC(mem_speed, "Set memory access speed in ns");
87 module_param(force_size, int, 0);
88 MODULE_PARM_DESC(force_size, "Force size of card in MiB (1-64)");
89 module_param(setvpp, int, 0);
90 MODULE_PARM_DESC(setvpp, "Set Vpp (0=Never, 1=On writes, 2=Always on, default=0)");
91 module_param(vpp, int, 0);
92 MODULE_PARM_DESC(vpp, "Vpp value in 1/10ths eg 33=3.3V 120=12V (Dangerous)");
93 module_param(mem_type, int, 0);
94 MODULE_PARM_DESC(mem_type, "Set Memory type (0=Flash, 1=RAM, 2=ROM, default=0)");
95 
96 
97 /* read/write{8,16} copy_{from,to} routines with window remapping
98  * to access whole card
99  */
100 static caddr_t remap_window(struct map_info *map, unsigned long to)
101 {
102 	struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
103 	struct resource *win = (struct resource *) map->map_priv_2;
104 	unsigned int offset;
105 	int ret;
106 
107 	if (!pcmcia_dev_present(dev->p_dev)) {
108 		DEBUG(1, "device removed");
109 		return 0;
110 	}
111 
112 	offset = to & ~(dev->win_size-1);
113 	if (offset != dev->offset) {
114 		DEBUG(2, "Remapping window from 0x%8.8x to 0x%8.8x",
115 		      dev->offset, offset);
116 		ret = pcmcia_map_mem_page(dev->p_dev, win, offset);
117 		if (ret != 0)
118 			return NULL;
119 		dev->offset = offset;
120 	}
121 	return dev->win_base + (to & (dev->win_size-1));
122 }
123 
124 
125 static map_word pcmcia_read8_remap(struct map_info *map, unsigned long ofs)
126 {
127 	caddr_t addr;
128 	map_word d = {{0}};
129 
130 	addr = remap_window(map, ofs);
131 	if(!addr)
132 		return d;
133 
134 	d.x[0] = readb(addr);
135 	DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%02lx", ofs, addr, d.x[0]);
136 	return d;
137 }
138 
139 
140 static map_word pcmcia_read16_remap(struct map_info *map, unsigned long ofs)
141 {
142 	caddr_t addr;
143 	map_word d = {{0}};
144 
145 	addr = remap_window(map, ofs);
146 	if(!addr)
147 		return d;
148 
149 	d.x[0] = readw(addr);
150 	DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%04lx", ofs, addr, d.x[0]);
151 	return d;
152 }
153 
154 
155 static void pcmcia_copy_from_remap(struct map_info *map, void *to, unsigned long from, ssize_t len)
156 {
157 	struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
158 	unsigned long win_size = dev->win_size;
159 
160 	DEBUG(3, "to = %p from = %lu len = %zd", to, from, len);
161 	while(len) {
162 		int toread = win_size - (from & (win_size-1));
163 		caddr_t addr;
164 
165 		if(toread > len)
166 			toread = len;
167 
168 		addr = remap_window(map, from);
169 		if(!addr)
170 			return;
171 
172 		DEBUG(4, "memcpy from %p to %p len = %d", addr, to, toread);
173 		memcpy_fromio(to, addr, toread);
174 		len -= toread;
175 		to += toread;
176 		from += toread;
177 	}
178 }
179 
180 
181 static void pcmcia_write8_remap(struct map_info *map, map_word d, unsigned long adr)
182 {
183 	caddr_t addr = remap_window(map, adr);
184 
185 	if(!addr)
186 		return;
187 
188 	DEBUG(3, "adr = 0x%08lx (%p)  data = 0x%02lx", adr, addr, d.x[0]);
189 	writeb(d.x[0], addr);
190 }
191 
192 
193 static void pcmcia_write16_remap(struct map_info *map, map_word d, unsigned long adr)
194 {
195 	caddr_t addr = remap_window(map, adr);
196 	if(!addr)
197 		return;
198 
199 	DEBUG(3, "adr = 0x%08lx (%p)  data = 0x%04lx", adr, addr, d.x[0]);
200 	writew(d.x[0], addr);
201 }
202 
203 
204 static void pcmcia_copy_to_remap(struct map_info *map, unsigned long to, const void *from, ssize_t len)
205 {
206 	struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
207 	unsigned long win_size = dev->win_size;
208 
209 	DEBUG(3, "to = %lu from = %p len = %zd", to, from, len);
210 	while(len) {
211 		int towrite = win_size - (to & (win_size-1));
212 		caddr_t addr;
213 
214 		if(towrite > len)
215 			towrite = len;
216 
217 		addr = remap_window(map, to);
218 		if(!addr)
219 			return;
220 
221 		DEBUG(4, "memcpy from %p to %p len = %d", from, addr, towrite);
222 		memcpy_toio(addr, from, towrite);
223 		len -= towrite;
224 		to += towrite;
225 		from += towrite;
226 	}
227 }
228 
229 
230 /* read/write{8,16} copy_{from,to} routines with direct access */
231 
232 #define DEV_REMOVED(x)  (!(pcmcia_dev_present(((struct pcmciamtd_dev *)map->map_priv_1)->p_dev)))
233 
234 static map_word pcmcia_read8(struct map_info *map, unsigned long ofs)
235 {
236 	caddr_t win_base = (caddr_t)map->map_priv_2;
237 	map_word d = {{0}};
238 
239 	if(DEV_REMOVED(map))
240 		return d;
241 
242 	d.x[0] = readb(win_base + ofs);
243 	DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%02lx",
244 	      ofs, win_base + ofs, d.x[0]);
245 	return d;
246 }
247 
248 
249 static map_word pcmcia_read16(struct map_info *map, unsigned long ofs)
250 {
251 	caddr_t win_base = (caddr_t)map->map_priv_2;
252 	map_word d = {{0}};
253 
254 	if(DEV_REMOVED(map))
255 		return d;
256 
257 	d.x[0] = readw(win_base + ofs);
258 	DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%04lx",
259 	      ofs, win_base + ofs, d.x[0]);
260 	return d;
261 }
262 
263 
264 static void pcmcia_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
265 {
266 	caddr_t win_base = (caddr_t)map->map_priv_2;
267 
268 	if(DEV_REMOVED(map))
269 		return;
270 
271 	DEBUG(3, "to = %p from = %lu len = %zd", to, from, len);
272 	memcpy_fromio(to, win_base + from, len);
273 }
274 
275 
276 static void pcmcia_write8(struct map_info *map, map_word d, unsigned long adr)
277 {
278 	caddr_t win_base = (caddr_t)map->map_priv_2;
279 
280 	if(DEV_REMOVED(map))
281 		return;
282 
283 	DEBUG(3, "adr = 0x%08lx (%p)  data = 0x%02lx",
284 	      adr, win_base + adr, d.x[0]);
285 	writeb(d.x[0], win_base + adr);
286 }
287 
288 
289 static void pcmcia_write16(struct map_info *map, map_word d, unsigned long adr)
290 {
291 	caddr_t win_base = (caddr_t)map->map_priv_2;
292 
293 	if(DEV_REMOVED(map))
294 		return;
295 
296 	DEBUG(3, "adr = 0x%08lx (%p)  data = 0x%04lx",
297 	      adr, win_base + adr, d.x[0]);
298 	writew(d.x[0], win_base + adr);
299 }
300 
301 
302 static void pcmcia_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
303 {
304 	caddr_t win_base = (caddr_t)map->map_priv_2;
305 
306 	if(DEV_REMOVED(map))
307 		return;
308 
309 	DEBUG(3, "to = %lu from = %p len = %zd", to, from, len);
310 	memcpy_toio(win_base + to, from, len);
311 }
312 
313 
314 static void pcmciamtd_set_vpp(struct map_info *map, int on)
315 {
316 	struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
317 	struct pcmcia_device *link = dev->p_dev;
318 
319 	DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp);
320 	pcmcia_fixup_vpp(link, on ? dev->vpp : 0);
321 }
322 
323 
324 static void pcmciamtd_release(struct pcmcia_device *link)
325 {
326 	struct pcmciamtd_dev *dev = link->priv;
327 
328 	DEBUG(3, "link = 0x%p", link);
329 
330 	if (link->resource[2]->end) {
331 		if(dev->win_base) {
332 			iounmap(dev->win_base);
333 			dev->win_base = NULL;
334 		}
335 	}
336 	pcmcia_disable_device(link);
337 }
338 
339 
340 #ifdef CONFIG_MTD_DEBUG
341 static int pcmciamtd_cistpl_format(struct pcmcia_device *p_dev,
342 				tuple_t *tuple,
343 				void *priv_data)
344 {
345 	cisparse_t parse;
346 
347 	if (!pcmcia_parse_tuple(tuple, &parse)) {
348 		cistpl_format_t *t = &parse.format;
349 		(void)t; /* Shut up, gcc */
350 		DEBUG(2, "Format type: %u, Error Detection: %u, offset = %u, length =%u",
351 			t->type, t->edc, t->offset, t->length);
352 	}
353 	return -ENOSPC;
354 }
355 
356 static int pcmciamtd_cistpl_jedec(struct pcmcia_device *p_dev,
357 				tuple_t *tuple,
358 				void *priv_data)
359 {
360 	cisparse_t parse;
361 	int i;
362 
363 	if (!pcmcia_parse_tuple(tuple, &parse)) {
364 		cistpl_jedec_t *t = &parse.jedec;
365 		for (i = 0; i < t->nid; i++)
366 			DEBUG(2, "JEDEC: 0x%02x 0x%02x",
367 			      t->id[i].mfr, t->id[i].info);
368 	}
369 	return -ENOSPC;
370 }
371 #endif
372 
373 static int pcmciamtd_cistpl_device(struct pcmcia_device *p_dev,
374 				tuple_t *tuple,
375 				void *priv_data)
376 {
377 	struct pcmciamtd_dev *dev = priv_data;
378 	cisparse_t parse;
379 	cistpl_device_t *t = &parse.device;
380 	int i;
381 
382 	if (pcmcia_parse_tuple(tuple, &parse))
383 		return -EINVAL;
384 
385 	DEBUG(2, "Common memory:");
386 	dev->pcmcia_map.size = t->dev[0].size;
387 	/* from here on: DEBUG only */
388 	for (i = 0; i < t->ndev; i++) {
389 		DEBUG(2, "Region %d, type = %u", i, t->dev[i].type);
390 		DEBUG(2, "Region %d, wp = %u", i, t->dev[i].wp);
391 		DEBUG(2, "Region %d, speed = %u ns", i, t->dev[i].speed);
392 		DEBUG(2, "Region %d, size = %u bytes", i, t->dev[i].size);
393 	}
394 	return 0;
395 }
396 
397 static int pcmciamtd_cistpl_geo(struct pcmcia_device *p_dev,
398 				tuple_t *tuple,
399 				void *priv_data)
400 {
401 	struct pcmciamtd_dev *dev = priv_data;
402 	cisparse_t parse;
403 	cistpl_device_geo_t *t = &parse.device_geo;
404 	int i;
405 
406 	if (pcmcia_parse_tuple(tuple, &parse))
407 		return -EINVAL;
408 
409 	dev->pcmcia_map.bankwidth = t->geo[0].buswidth;
410 	/* from here on: DEBUG only */
411 	for (i = 0; i < t->ngeo; i++) {
412 		DEBUG(2, "region: %d bankwidth = %u", i, t->geo[i].buswidth);
413 		DEBUG(2, "region: %d erase_block = %u", i, t->geo[i].erase_block);
414 		DEBUG(2, "region: %d read_block = %u", i, t->geo[i].read_block);
415 		DEBUG(2, "region: %d write_block = %u", i, t->geo[i].write_block);
416 		DEBUG(2, "region: %d partition = %u", i, t->geo[i].partition);
417 		DEBUG(2, "region: %d interleave = %u", i, t->geo[i].interleave);
418 	}
419 	return 0;
420 }
421 
422 
423 static void card_settings(struct pcmciamtd_dev *dev, struct pcmcia_device *p_dev, int *new_name)
424 {
425 	int i;
426 
427 	if (p_dev->prod_id[0]) {
428 		dev->mtd_name[0] = '\0';
429 		for (i = 0; i < 4; i++) {
430 			if (i)
431 				strcat(dev->mtd_name, " ");
432 			if (p_dev->prod_id[i])
433 				strcat(dev->mtd_name, p_dev->prod_id[i]);
434 		}
435 		DEBUG(2, "Found name: %s", dev->mtd_name);
436 	}
437 
438 #ifdef CONFIG_MTD_DEBUG
439 	pcmcia_loop_tuple(p_dev, CISTPL_FORMAT, pcmciamtd_cistpl_format, NULL);
440 	pcmcia_loop_tuple(p_dev, CISTPL_JEDEC_C, pcmciamtd_cistpl_jedec, NULL);
441 #endif
442 	pcmcia_loop_tuple(p_dev, CISTPL_DEVICE, pcmciamtd_cistpl_device, dev);
443 	pcmcia_loop_tuple(p_dev, CISTPL_DEVICE_GEO, pcmciamtd_cistpl_geo, dev);
444 
445 	if(!dev->pcmcia_map.size)
446 		dev->pcmcia_map.size = MAX_PCMCIA_ADDR;
447 
448 	if(!dev->pcmcia_map.bankwidth)
449 		dev->pcmcia_map.bankwidth = 2;
450 
451 	if(force_size) {
452 		dev->pcmcia_map.size = force_size << 20;
453 		DEBUG(2, "size forced to %dM", force_size);
454 	}
455 
456 	if(bankwidth) {
457 		dev->pcmcia_map.bankwidth = bankwidth;
458 		DEBUG(2, "bankwidth forced to %d", bankwidth);
459 	}
460 
461 	dev->pcmcia_map.name = dev->mtd_name;
462 	if(!dev->mtd_name[0]) {
463 		strcpy(dev->mtd_name, "PCMCIA Memory card");
464 		*new_name = 1;
465 	}
466 
467 	DEBUG(1, "Device: Size: %lu Width:%d Name: %s",
468 	      dev->pcmcia_map.size,
469 	      dev->pcmcia_map.bankwidth << 3, dev->mtd_name);
470 }
471 
472 
473 static int pcmciamtd_config(struct pcmcia_device *link)
474 {
475 	struct pcmciamtd_dev *dev = link->priv;
476 	struct mtd_info *mtd = NULL;
477 	int ret;
478 	int i, j = 0;
479 	static char *probes[] = { "jedec_probe", "cfi_probe" };
480 	int new_name = 0;
481 
482 	DEBUG(3, "link=0x%p", link);
483 
484 	card_settings(dev, link, &new_name);
485 
486 	dev->pcmcia_map.phys = NO_XIP;
487 	dev->pcmcia_map.copy_from = pcmcia_copy_from_remap;
488 	dev->pcmcia_map.copy_to = pcmcia_copy_to_remap;
489 	if (dev->pcmcia_map.bankwidth == 1) {
490 		dev->pcmcia_map.read = pcmcia_read8_remap;
491 		dev->pcmcia_map.write = pcmcia_write8_remap;
492 	} else {
493 		dev->pcmcia_map.read = pcmcia_read16_remap;
494 		dev->pcmcia_map.write = pcmcia_write16_remap;
495 	}
496 	if(setvpp == 1)
497 		dev->pcmcia_map.set_vpp = pcmciamtd_set_vpp;
498 
499 	/* Request a memory window for PCMCIA. Some architeures can map windows
500 	 * up to the maximum that PCMCIA can support (64MiB) - this is ideal and
501 	 * we aim for a window the size of the whole card - otherwise we try
502 	 * smaller windows until we succeed
503 	 */
504 
505 	link->resource[2]->flags |=  WIN_MEMORY_TYPE_CM | WIN_ENABLE;
506 	link->resource[2]->flags |= (dev->pcmcia_map.bankwidth == 1) ?
507 					WIN_DATA_WIDTH_8 : WIN_DATA_WIDTH_16;
508 	link->resource[2]->start = 0;
509 	link->resource[2]->end = (force_size) ? force_size << 20 :
510 					MAX_PCMCIA_ADDR;
511 	dev->win_size = 0;
512 
513 	do {
514 		int ret;
515 		DEBUG(2, "requesting window with size = %luKiB memspeed = %d",
516 			(unsigned long) resource_size(link->resource[2]) >> 10,
517 			mem_speed);
518 		ret = pcmcia_request_window(link, link->resource[2], mem_speed);
519 		DEBUG(2, "ret = %d dev->win_size = %d", ret, dev->win_size);
520 		if(ret) {
521 			j++;
522 			link->resource[2]->start = 0;
523 			link->resource[2]->end = (force_size) ?
524 					force_size << 20 : MAX_PCMCIA_ADDR;
525 			link->resource[2]->end >>= j;
526 		} else {
527 			DEBUG(2, "Got window of size %luKiB", (unsigned long)
528 				resource_size(link->resource[2]) >> 10);
529 			dev->win_size = resource_size(link->resource[2]);
530 			break;
531 		}
532 	} while (link->resource[2]->end >= 0x1000);
533 
534 	DEBUG(2, "dev->win_size = %d", dev->win_size);
535 
536 	if(!dev->win_size) {
537 		dev_err(&dev->p_dev->dev, "Cannot allocate memory window\n");
538 		pcmciamtd_release(link);
539 		return -ENODEV;
540 	}
541 	DEBUG(1, "Allocated a window of %dKiB", dev->win_size >> 10);
542 
543 	/* Get write protect status */
544 	dev->win_base = ioremap(link->resource[2]->start,
545 				resource_size(link->resource[2]));
546 	if(!dev->win_base) {
547 		dev_err(&dev->p_dev->dev, "ioremap(%pR) failed\n",
548 			link->resource[2]);
549 		pcmciamtd_release(link);
550 		return -ENODEV;
551 	}
552 	DEBUG(1, "mapped window dev = %p @ %pR, base = %p",
553 	      dev, link->resource[2], dev->win_base);
554 
555 	dev->offset = 0;
556 	dev->pcmcia_map.map_priv_1 = (unsigned long)dev;
557 	dev->pcmcia_map.map_priv_2 = (unsigned long)link->resource[2];
558 
559 	dev->vpp = (vpp) ? vpp : link->socket->socket.Vpp;
560 	if(setvpp == 2) {
561 		link->vpp = dev->vpp;
562 	} else {
563 		link->vpp = 0;
564 	}
565 
566 	link->config_index = 0;
567 	DEBUG(2, "Setting Configuration");
568 	ret = pcmcia_enable_device(link);
569 	if (ret != 0) {
570 		if (dev->win_base) {
571 			iounmap(dev->win_base);
572 			dev->win_base = NULL;
573 		}
574 		return -ENODEV;
575 	}
576 
577 	if(mem_type == 1) {
578 		mtd = do_map_probe("map_ram", &dev->pcmcia_map);
579 	} else if(mem_type == 2) {
580 		mtd = do_map_probe("map_rom", &dev->pcmcia_map);
581 	} else {
582 		for(i = 0; i < ARRAY_SIZE(probes); i++) {
583 			DEBUG(1, "Trying %s", probes[i]);
584 			mtd = do_map_probe(probes[i], &dev->pcmcia_map);
585 			if(mtd)
586 				break;
587 
588 			DEBUG(1, "FAILED: %s", probes[i]);
589 		}
590 	}
591 
592 	if(!mtd) {
593 		DEBUG(1, "Can not find an MTD");
594 		pcmciamtd_release(link);
595 		return -ENODEV;
596 	}
597 
598 	dev->mtd_info = mtd;
599 	mtd->owner = THIS_MODULE;
600 
601 	if(new_name) {
602 		int size = 0;
603 		char unit = ' ';
604 		/* Since we are using a default name, make it better by adding
605 		 * in the size
606 		 */
607 		if(mtd->size < 1048576) { /* <1MiB in size, show size in KiB */
608 			size = mtd->size >> 10;
609 			unit = 'K';
610 		} else {
611 			size = mtd->size >> 20;
612 			unit = 'M';
613 		}
614 		snprintf(dev->mtd_name, sizeof(dev->mtd_name), "%d%ciB %s", size, unit, "PCMCIA Memory card");
615 	}
616 
617 	/* If the memory found is fits completely into the mapped PCMCIA window,
618 	   use the faster non-remapping read/write functions */
619 	if(mtd->size <= dev->win_size) {
620 		DEBUG(1, "Using non remapping memory functions");
621 		dev->pcmcia_map.map_priv_2 = (unsigned long)dev->win_base;
622 		if (dev->pcmcia_map.bankwidth == 1) {
623 			dev->pcmcia_map.read = pcmcia_read8;
624 			dev->pcmcia_map.write = pcmcia_write8;
625 		} else {
626 			dev->pcmcia_map.read = pcmcia_read16;
627 			dev->pcmcia_map.write = pcmcia_write16;
628 		}
629 		dev->pcmcia_map.copy_from = pcmcia_copy_from;
630 		dev->pcmcia_map.copy_to = pcmcia_copy_to;
631 	}
632 
633 	if (mtd_device_register(mtd, NULL, 0)) {
634 		map_destroy(mtd);
635 		dev->mtd_info = NULL;
636 		dev_err(&dev->p_dev->dev,
637 			"Could not register the MTD device\n");
638 		pcmciamtd_release(link);
639 		return -ENODEV;
640 	}
641 	dev_info(&dev->p_dev->dev, "mtd%d: %s\n", mtd->index, mtd->name);
642 	return 0;
643 }
644 
645 
646 static int pcmciamtd_suspend(struct pcmcia_device *dev)
647 {
648 	DEBUG(2, "EVENT_PM_RESUME");
649 
650 	/* get_lock(link); */
651 
652 	return 0;
653 }
654 
655 static int pcmciamtd_resume(struct pcmcia_device *dev)
656 {
657 	DEBUG(2, "EVENT_PM_SUSPEND");
658 
659 	/* free_lock(link); */
660 
661 	return 0;
662 }
663 
664 
665 static void pcmciamtd_detach(struct pcmcia_device *link)
666 {
667 	struct pcmciamtd_dev *dev = link->priv;
668 
669 	DEBUG(3, "link=0x%p", link);
670 
671 	if(dev->mtd_info) {
672 		mtd_device_unregister(dev->mtd_info);
673 		dev_info(&dev->p_dev->dev, "mtd%d: Removing\n",
674 			 dev->mtd_info->index);
675 		map_destroy(dev->mtd_info);
676 	}
677 
678 	pcmciamtd_release(link);
679 }
680 
681 
682 static int pcmciamtd_probe(struct pcmcia_device *link)
683 {
684 	struct pcmciamtd_dev *dev;
685 
686 	/* Create new memory card device */
687 	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
688 	if (!dev) return -ENOMEM;
689 	DEBUG(1, "dev=0x%p", dev);
690 
691 	dev->p_dev = link;
692 	link->priv = dev;
693 
694 	return pcmciamtd_config(link);
695 }
696 
697 static const struct pcmcia_device_id pcmciamtd_ids[] = {
698 	PCMCIA_DEVICE_FUNC_ID(1),
699 	PCMCIA_DEVICE_PROD_ID123("IO DATA", "PCS-2M", "2MB SRAM", 0x547e66dc, 0x1fed36cd, 0x36eadd21),
700 	PCMCIA_DEVICE_PROD_ID12("IBM", "2MB SRAM", 0xb569a6e5, 0x36eadd21),
701 	PCMCIA_DEVICE_PROD_ID12("IBM", "4MB FLASH", 0xb569a6e5, 0x8bc54d2a),
702 	PCMCIA_DEVICE_PROD_ID12("IBM", "8MB FLASH", 0xb569a6e5, 0x6df1be3e),
703 	PCMCIA_DEVICE_PROD_ID12("Intel", "S2E20SW", 0x816cc815, 0xd14c9dcf),
704 	PCMCIA_DEVICE_PROD_ID12("Intel", "S2E8 SW", 0x816cc815, 0xa2d7dedb),
705 	PCMCIA_DEVICE_PROD_ID12("intel", "SERIES2-02 ", 0x40ade711, 0x145cea5c),
706 	PCMCIA_DEVICE_PROD_ID12("intel", "SERIES2-04 ", 0x40ade711, 0x42064dda),
707 	PCMCIA_DEVICE_PROD_ID12("intel", "SERIES2-20 ", 0x40ade711, 0x25ee5cb0),
708 	PCMCIA_DEVICE_PROD_ID12("intel", "VALUE SERIES 100 ", 0x40ade711, 0xdf8506d8),
709 	PCMCIA_DEVICE_PROD_ID12("KINGMAX TECHNOLOGY INC.", "SRAM 256K Bytes", 0x54d0c69c, 0xad12c29c),
710 	PCMCIA_DEVICE_PROD_ID12("Maxtor", "MAXFL MobileMax Flash Memory Card", 0xb68968c8, 0x2dfb47b0),
711 	PCMCIA_DEVICE_PROD_ID123("M-Systems", "M-SYS Flash Memory Card", "(c) M-Systems", 0x7ed2ad87, 0x675dc3fb, 0x7aef3965),
712 	PCMCIA_DEVICE_PROD_ID12("PRETEC", "  2MB SRAM CARD", 0xebf91155, 0x805360ca),
713 	PCMCIA_DEVICE_PROD_ID12("SEIKO EPSON", "WWB101EN20", 0xf9876baf, 0xad0b207b),
714 	PCMCIA_DEVICE_PROD_ID12("SEIKO EPSON", "WWB513EN20", 0xf9876baf, 0xe8d884ad),
715 	PCMCIA_DEVICE_PROD_ID12("SMART Modular Technologies", " 4MB FLASH Card", 0x96fd8277, 0x737a5b05),
716 	PCMCIA_DEVICE_PROD_ID12("Starfish, Inc.", "REX-3000", 0x05ddca47, 0xe7d67bca),
717 	PCMCIA_DEVICE_PROD_ID12("Starfish, Inc.", "REX-4100", 0x05ddca47, 0x7bc32944),
718 	/* the following was commented out in pcmcia-cs-3.2.7 */
719 	/* PCMCIA_DEVICE_PROD_ID12("RATOC Systems,Inc.", "SmartMedia ADAPTER PC Card", 0xf4a2fefe, 0x5885b2ae), */
720 #ifdef CONFIG_MTD_PCMCIA_ANONYMOUS
721 	{ .match_flags = PCMCIA_DEV_ID_MATCH_ANONYMOUS, },
722 #endif
723 	PCMCIA_DEVICE_NULL
724 };
725 MODULE_DEVICE_TABLE(pcmcia, pcmciamtd_ids);
726 
727 static struct pcmcia_driver pcmciamtd_driver = {
728 	.name		= "pcmciamtd",
729 	.probe		= pcmciamtd_probe,
730 	.remove		= pcmciamtd_detach,
731 	.owner		= THIS_MODULE,
732 	.id_table	= pcmciamtd_ids,
733 	.suspend	= pcmciamtd_suspend,
734 	.resume		= pcmciamtd_resume,
735 };
736 
737 
738 static int __init init_pcmciamtd(void)
739 {
740 	if(bankwidth && bankwidth != 1 && bankwidth != 2) {
741 		info("bad bankwidth (%d), using default", bankwidth);
742 		bankwidth = 2;
743 	}
744 	if(force_size && (force_size < 1 || force_size > 64)) {
745 		info("bad force_size (%d), using default", force_size);
746 		force_size = 0;
747 	}
748 	if(mem_type && mem_type != 1 && mem_type != 2) {
749 		info("bad mem_type (%d), using default", mem_type);
750 		mem_type = 0;
751 	}
752 	return pcmcia_register_driver(&pcmciamtd_driver);
753 }
754 
755 
756 static void __exit exit_pcmciamtd(void)
757 {
758 	DEBUG(1, DRIVER_DESC " unloading");
759 	pcmcia_unregister_driver(&pcmciamtd_driver);
760 }
761 
762 module_init(init_pcmciamtd);
763 module_exit(exit_pcmciamtd);
764