2 * $Id: pcmciamtd.c,v 1.55 2005/11/07 11:14:28 gleixner Exp $
4 * pcmciamtd.c - MTD driver for PCMCIA flash memory cards
6 * Author: Simon Evans <spse@secret.org.uk>
8 * Copyright (C) 2002 Simon Evans
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/timer.h>
17 #include <linux/init.h>
19 #include <asm/system.h>
21 #include <pcmcia/cs_types.h>
22 #include <pcmcia/cs.h>
23 #include <pcmcia/cistpl.h>
24 #include <pcmcia/ds.h>
26 #include <linux/mtd/map.h>
27 #include <linux/mtd/mtd.h>
29 #ifdef CONFIG_MTD_DEBUG
30 static int debug
= CONFIG_MTD_DEBUG_VERBOSE
;
31 module_param(debug
, int, 0);
32 MODULE_PARM_DESC(debug
, "Set Debug Level 0=quiet, 5=noisy");
34 #define DEBUG(n, format, arg...) \
36 printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __FUNCTION__ , ## arg); \
41 #define DEBUG(n, arg...)
42 static const int debug
= 0;
45 #define err(format, arg...) printk(KERN_ERR "pcmciamtd: " format "\n" , ## arg)
46 #define info(format, arg...) printk(KERN_INFO "pcmciamtd: " format "\n" , ## arg)
47 #define warn(format, arg...) printk(KERN_WARNING "pcmciamtd: " format "\n" , ## arg)
50 #define DRIVER_DESC "PCMCIA Flash memory card driver"
51 #define DRIVER_VERSION "$Revision: 1.55 $"
53 /* Size of the PCMCIA address space: 26 bits = 64 MB */
54 #define MAX_PCMCIA_ADDR 0x4000000
56 struct pcmciamtd_dev
{
57 struct pcmcia_device
*p_dev
;
58 dev_node_t node
; /* device node */
59 caddr_t win_base
; /* ioremapped address of PCMCIA window */
60 unsigned int win_size
; /* size of window */
61 unsigned int offset
; /* offset into card the window currently points at */
62 struct map_info pcmcia_map
;
63 struct mtd_info
*mtd_info
;
65 char mtd_name
[sizeof(struct cistpl_vers_1_t
)];
69 /* Module parameters */
71 /* 2 = do 16-bit transfers, 1 = do 8-bit transfers */
72 static int bankwidth
= 2;
74 /* Speed of memory accesses, in ns */
77 /* Force the size of an SRAM card */
78 static int force_size
;
86 /* Force card to be treated as FLASH, ROM or RAM */
89 MODULE_LICENSE("GPL");
90 MODULE_AUTHOR("Simon Evans <spse@secret.org.uk>");
91 MODULE_DESCRIPTION(DRIVER_DESC
);
92 module_param(bankwidth
, int, 0);
93 MODULE_PARM_DESC(bankwidth
, "Set bankwidth (1=8 bit, 2=16 bit, default=2)");
94 module_param(mem_speed
, int, 0);
95 MODULE_PARM_DESC(mem_speed
, "Set memory access speed in ns");
96 module_param(force_size
, int, 0);
97 MODULE_PARM_DESC(force_size
, "Force size of card in MiB (1-64)");
98 module_param(setvpp
, int, 0);
99 MODULE_PARM_DESC(setvpp
, "Set Vpp (0=Never, 1=On writes, 2=Always on, default=0)");
100 module_param(vpp
, int, 0);
101 MODULE_PARM_DESC(vpp
, "Vpp value in 1/10ths eg 33=3.3V 120=12V (Dangerous)");
102 module_param(mem_type
, int, 0);
103 MODULE_PARM_DESC(mem_type
, "Set Memory type (0=Flash, 1=RAM, 2=ROM, default=0)");
106 /* read/write{8,16} copy_{from,to} routines with window remapping to access whole card */
107 static caddr_t
remap_window(struct map_info
*map
, unsigned long to
)
109 struct pcmciamtd_dev
*dev
= (struct pcmciamtd_dev
*)map
->map_priv_1
;
110 window_handle_t win
= (window_handle_t
)map
->map_priv_2
;
114 if(!(dev
->p_dev
->state
& DEV_PRESENT
)) {
115 DEBUG(1, "device removed state = 0x%4.4X", dev
->p_dev
->state
);
119 mrq
.CardOffset
= to
& ~(dev
->win_size
-1);
120 if(mrq
.CardOffset
!= dev
->offset
) {
121 DEBUG(2, "Remapping window from 0x%8.8x to 0x%8.8x",
122 dev
->offset
, mrq
.CardOffset
);
124 if( (ret
= pcmcia_map_mem_page(win
, &mrq
)) != CS_SUCCESS
) {
125 cs_error(dev
->p_dev
->handle
, MapMemPage
, ret
);
128 dev
->offset
= mrq
.CardOffset
;
130 return dev
->win_base
+ (to
& (dev
->win_size
-1));
134 static map_word
pcmcia_read8_remap(struct map_info
*map
, unsigned long ofs
)
139 addr
= remap_window(map
, ofs
);
143 d
.x
[0] = readb(addr
);
144 DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%02x", ofs
, addr
, d
.x
[0]);
149 static map_word
pcmcia_read16_remap(struct map_info
*map
, unsigned long ofs
)
154 addr
= remap_window(map
, ofs
);
158 d
.x
[0] = readw(addr
);
159 DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%04x", ofs
, addr
, d
.x
[0]);
164 static void pcmcia_copy_from_remap(struct map_info
*map
, void *to
, unsigned long from
, ssize_t len
)
166 struct pcmciamtd_dev
*dev
= (struct pcmciamtd_dev
*)map
->map_priv_1
;
167 unsigned long win_size
= dev
->win_size
;
169 DEBUG(3, "to = %p from = %lu len = %u", to
, from
, len
);
171 int toread
= win_size
- (from
& (win_size
-1));
177 addr
= remap_window(map
, from
);
181 DEBUG(4, "memcpy from %p to %p len = %d", addr
, to
, toread
);
182 memcpy_fromio(to
, addr
, toread
);
190 static void pcmcia_write8_remap(struct map_info
*map
, map_word d
, unsigned long adr
)
192 caddr_t addr
= remap_window(map
, adr
);
197 DEBUG(3, "adr = 0x%08lx (%p) data = 0x%02x", adr
, addr
, d
.x
[0]);
198 writeb(d
.x
[0], addr
);
202 static void pcmcia_write16_remap(struct map_info
*map
, map_word d
, unsigned long adr
)
204 caddr_t addr
= remap_window(map
, adr
);
208 DEBUG(3, "adr = 0x%08lx (%p) data = 0x%04x", adr
, addr
, d
.x
[0]);
209 writew(d
.x
[0], addr
);
213 static void pcmcia_copy_to_remap(struct map_info
*map
, unsigned long to
, const void *from
, ssize_t len
)
215 struct pcmciamtd_dev
*dev
= (struct pcmciamtd_dev
*)map
->map_priv_1
;
216 unsigned long win_size
= dev
->win_size
;
218 DEBUG(3, "to = %lu from = %p len = %u", to
, from
, len
);
220 int towrite
= win_size
- (to
& (win_size
-1));
226 addr
= remap_window(map
, to
);
230 DEBUG(4, "memcpy from %p to %p len = %d", from
, addr
, towrite
);
231 memcpy_toio(addr
, from
, towrite
);
239 /* read/write{8,16} copy_{from,to} routines with direct access */
241 #define DEV_REMOVED(x) (!(*(u_int *)x->map_priv_1 & DEV_PRESENT))
243 static map_word
pcmcia_read8(struct map_info
*map
, unsigned long ofs
)
245 caddr_t win_base
= (caddr_t
)map
->map_priv_2
;
251 d
.x
[0] = readb(win_base
+ ofs
);
252 DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%02x", ofs
, win_base
+ ofs
, d
.x
[0]);
257 static map_word
pcmcia_read16(struct map_info
*map
, unsigned long ofs
)
259 caddr_t win_base
= (caddr_t
)map
->map_priv_2
;
265 d
.x
[0] = readw(win_base
+ ofs
);
266 DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%04x", ofs
, win_base
+ ofs
, d
.x
[0]);
271 static void pcmcia_copy_from(struct map_info
*map
, void *to
, unsigned long from
, ssize_t len
)
273 caddr_t win_base
= (caddr_t
)map
->map_priv_2
;
278 DEBUG(3, "to = %p from = %lu len = %u", to
, from
, len
);
279 memcpy_fromio(to
, win_base
+ from
, len
);
283 static void pcmcia_write8(struct map_info
*map
, u8 d
, unsigned long adr
)
285 caddr_t win_base
= (caddr_t
)map
->map_priv_2
;
290 DEBUG(3, "adr = 0x%08lx (%p) data = 0x%02x", adr
, win_base
+ adr
, d
);
291 writeb(d
, win_base
+ adr
);
295 static void pcmcia_write16(struct map_info
*map
, u16 d
, unsigned long adr
)
297 caddr_t win_base
= (caddr_t
)map
->map_priv_2
;
302 DEBUG(3, "adr = 0x%08lx (%p) data = 0x%04x", adr
, win_base
+ adr
, d
);
303 writew(d
, win_base
+ adr
);
307 static void pcmcia_copy_to(struct map_info
*map
, unsigned long to
, const void *from
, ssize_t len
)
309 caddr_t win_base
= (caddr_t
)map
->map_priv_2
;
314 DEBUG(3, "to = %lu from = %p len = %u", to
, from
, len
);
315 memcpy_toio(win_base
+ to
, from
, len
);
319 static void pcmciamtd_set_vpp(struct map_info
*map
, int on
)
321 struct pcmciamtd_dev
*dev
= (struct pcmciamtd_dev
*)map
->map_priv_1
;
322 dev_link_t
*link
= dev
->p_dev
;
326 mod
.Attributes
= CONF_VPP1_CHANGE_VALID
| CONF_VPP2_CHANGE_VALID
;
328 mod
.Vpp1
= mod
.Vpp2
= on
? dev
->vpp
: 0;
330 DEBUG(2, "dev = %p on = %d vpp = %d\n", dev
, on
, dev
->vpp
);
331 ret
= pcmcia_modify_configuration(link
->handle
, &mod
);
332 if(ret
!= CS_SUCCESS
) {
333 cs_error(link
->handle
, ModifyConfiguration
, ret
);
338 /* After a card is removed, pcmciamtd_release() will unregister the
339 * device, and release the PCMCIA configuration. If the device is
340 * still open, this will be postponed until it is closed.
343 static void pcmciamtd_release(dev_link_t
*link
)
345 struct pcmciamtd_dev
*dev
= link
->priv
;
347 DEBUG(3, "link = 0x%p", link
);
351 iounmap(dev
->win_base
);
352 dev
->win_base
= NULL
;
354 pcmcia_release_window(link
->win
);
356 pcmcia_disable_device(link
->handle
);
360 static void card_settings(struct pcmciamtd_dev
*dev
, dev_link_t
*link
, int *new_name
)
367 tuple
.Attributes
= 0;
368 tuple
.TupleData
= (cisdata_t
*)buf
;
369 tuple
.TupleDataMax
= sizeof(buf
);
370 tuple
.TupleOffset
= 0;
371 tuple
.DesiredTuple
= RETURN_FIRST_TUPLE
;
373 rc
= pcmcia_get_first_tuple(link
->handle
, &tuple
);
374 while(rc
== CS_SUCCESS
) {
375 rc
= pcmcia_get_tuple_data(link
->handle
, &tuple
);
376 if(rc
!= CS_SUCCESS
) {
377 cs_error(link
->handle
, GetTupleData
, rc
);
380 rc
= pcmcia_parse_tuple(link
->handle
, &tuple
, &parse
);
381 if(rc
!= CS_SUCCESS
) {
382 cs_error(link
->handle
, ParseTuple
, rc
);
386 switch(tuple
.TupleCode
) {
387 case CISTPL_FORMAT
: {
388 cistpl_format_t
*t
= &parse
.format
;
389 (void)t
; /* Shut up, gcc */
390 DEBUG(2, "Format type: %u, Error Detection: %u, offset = %u, length =%u",
391 t
->type
, t
->edc
, t
->offset
, t
->length
);
396 case CISTPL_DEVICE
: {
397 cistpl_device_t
*t
= &parse
.device
;
399 DEBUG(2, "Common memory:");
400 dev
->pcmcia_map
.size
= t
->dev
[0].size
;
401 for(i
= 0; i
< t
->ndev
; i
++) {
402 DEBUG(2, "Region %d, type = %u", i
, t
->dev
[i
].type
);
403 DEBUG(2, "Region %d, wp = %u", i
, t
->dev
[i
].wp
);
404 DEBUG(2, "Region %d, speed = %u ns", i
, t
->dev
[i
].speed
);
405 DEBUG(2, "Region %d, size = %u bytes", i
, t
->dev
[i
].size
);
410 case CISTPL_VERS_1
: {
411 cistpl_vers_1_t
*t
= &parse
.version_1
;
414 dev
->mtd_name
[0] = '\0';
415 for(i
= 0; i
< t
->ns
; i
++) {
417 strcat(dev
->mtd_name
, " ");
418 strcat(dev
->mtd_name
, t
->str
+t
->ofs
[i
]);
421 DEBUG(2, "Found name: %s", dev
->mtd_name
);
425 case CISTPL_JEDEC_C
: {
426 cistpl_jedec_t
*t
= &parse
.jedec
;
428 for(i
= 0; i
< t
->nid
; i
++) {
429 DEBUG(2, "JEDEC: 0x%02x 0x%02x", t
->id
[i
].mfr
, t
->id
[i
].info
);
434 case CISTPL_DEVICE_GEO
: {
435 cistpl_device_geo_t
*t
= &parse
.device_geo
;
437 dev
->pcmcia_map
.bankwidth
= t
->geo
[0].buswidth
;
438 for(i
= 0; i
< t
->ngeo
; i
++) {
439 DEBUG(2, "region: %d bankwidth = %u", i
, t
->geo
[i
].buswidth
);
440 DEBUG(2, "region: %d erase_block = %u", i
, t
->geo
[i
].erase_block
);
441 DEBUG(2, "region: %d read_block = %u", i
, t
->geo
[i
].read_block
);
442 DEBUG(2, "region: %d write_block = %u", i
, t
->geo
[i
].write_block
);
443 DEBUG(2, "region: %d partition = %u", i
, t
->geo
[i
].partition
);
444 DEBUG(2, "region: %d interleave = %u", i
, t
->geo
[i
].interleave
);
450 DEBUG(2, "Unknown tuple code %d", tuple
.TupleCode
);
453 rc
= pcmcia_get_next_tuple(link
->handle
, &tuple
);
455 if(!dev
->pcmcia_map
.size
)
456 dev
->pcmcia_map
.size
= MAX_PCMCIA_ADDR
;
458 if(!dev
->pcmcia_map
.bankwidth
)
459 dev
->pcmcia_map
.bankwidth
= 2;
462 dev
->pcmcia_map
.size
= force_size
<< 20;
463 DEBUG(2, "size forced to %dM", force_size
);
467 dev
->pcmcia_map
.bankwidth
= bankwidth
;
468 DEBUG(2, "bankwidth forced to %d", bankwidth
);
471 dev
->pcmcia_map
.name
= dev
->mtd_name
;
472 if(!dev
->mtd_name
[0]) {
473 strcpy(dev
->mtd_name
, "PCMCIA Memory card");
477 DEBUG(1, "Device: Size: %lu Width:%d Name: %s",
478 dev
->pcmcia_map
.size
, dev
->pcmcia_map
.bankwidth
<< 3, dev
->mtd_name
);
482 /* pcmciamtd_config() is scheduled to run after a CARD_INSERTION event
483 * is received, to configure the PCMCIA socket, and to make the
484 * MTD device available to the system.
487 #define CS_CHECK(fn, ret) \
488 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
490 static void pcmciamtd_config(dev_link_t
*link
)
492 struct pcmciamtd_dev
*dev
= link
->priv
;
493 struct mtd_info
*mtd
= NULL
;
496 int last_ret
= 0, last_fn
= 0;
500 static char *probes
[] = { "jedec_probe", "cfi_probe" };
504 DEBUG(3, "link=0x%p", link
);
507 link
->state
|= DEV_CONFIG
;
509 DEBUG(2, "Validating CIS");
510 ret
= pcmcia_validate_cis(link
->handle
, &cisinfo
);
511 if(ret
!= CS_SUCCESS
) {
512 cs_error(link
->handle
, GetTupleData
, ret
);
514 DEBUG(2, "ValidateCIS found %d chains", cisinfo
.Chains
);
517 card_settings(dev
, link
, &new_name
);
519 dev
->pcmcia_map
.phys
= NO_XIP
;
520 dev
->pcmcia_map
.copy_from
= pcmcia_copy_from_remap
;
521 dev
->pcmcia_map
.copy_to
= pcmcia_copy_to_remap
;
522 if (dev
->pcmcia_map
.bankwidth
== 1) {
523 dev
->pcmcia_map
.read
= pcmcia_read8_remap
;
524 dev
->pcmcia_map
.write
= pcmcia_write8_remap
;
526 dev
->pcmcia_map
.read
= pcmcia_read16_remap
;
527 dev
->pcmcia_map
.write
= pcmcia_write16_remap
;
530 dev
->pcmcia_map
.set_vpp
= pcmciamtd_set_vpp
;
532 /* Request a memory window for PCMCIA. Some architeures can map windows upto the maximum
533 that PCMCIA can support (64MiB) - this is ideal and we aim for a window the size of the
534 whole card - otherwise we try smaller windows until we succeed */
536 req
.Attributes
= WIN_MEMORY_TYPE_CM
| WIN_ENABLE
;
537 req
.Attributes
|= (dev
->pcmcia_map
.bankwidth
== 1) ? WIN_DATA_WIDTH_8
: WIN_DATA_WIDTH_16
;
539 req
.AccessSpeed
= mem_speed
;
540 link
->win
= (window_handle_t
)link
->handle
;
541 req
.Size
= (force_size
) ? force_size
<< 20 : MAX_PCMCIA_ADDR
;
546 DEBUG(2, "requesting window with size = %dKiB memspeed = %d",
547 req
.Size
>> 10, req
.AccessSpeed
);
548 ret
= pcmcia_request_window(&link
->handle
, &req
, &link
->win
);
549 DEBUG(2, "ret = %d dev->win_size = %d", ret
, dev
->win_size
);
553 DEBUG(2, "Got window of size %dKiB", req
.Size
>> 10);
554 dev
->win_size
= req
.Size
;
557 } while(req
.Size
>= 0x1000);
559 DEBUG(2, "dev->win_size = %d", dev
->win_size
);
562 err("Cant allocate memory window");
563 pcmciamtd_release(link
);
566 DEBUG(1, "Allocated a window of %dKiB", dev
->win_size
>> 10);
568 /* Get write protect status */
569 CS_CHECK(GetStatus
, pcmcia_get_status(link
->handle
, &status
));
570 DEBUG(2, "status value: 0x%x window handle = 0x%8.8lx",
571 status
.CardState
, (unsigned long)link
->win
);
572 dev
->win_base
= ioremap(req
.Base
, req
.Size
);
574 err("ioremap(%lu, %u) failed", req
.Base
, req
.Size
);
575 pcmciamtd_release(link
);
578 DEBUG(1, "mapped window dev = %p req.base = 0x%lx base = %p size = 0x%x",
579 dev
, req
.Base
, dev
->win_base
, req
.Size
);
582 dev
->pcmcia_map
.map_priv_1
= (unsigned long)dev
;
583 dev
->pcmcia_map
.map_priv_2
= (unsigned long)link
->win
;
585 DEBUG(2, "Getting configuration");
586 CS_CHECK(GetConfigurationInfo
, pcmcia_get_configuration_info(link
->handle
, &t
));
587 DEBUG(2, "Vcc = %d Vpp1 = %d Vpp2 = %d", t
.Vcc
, t
.Vpp1
, t
.Vpp2
);
588 dev
->vpp
= (vpp
) ? vpp
: t
.Vpp1
;
589 link
->conf
.Attributes
= 0;
591 link
->conf
.Vpp
= dev
->vpp
;
596 link
->conf
.IntType
= INT_MEMORY
;
597 link
->conf
.ConfigBase
= t
.ConfigBase
;
598 link
->conf
.Status
= t
.Status
;
599 link
->conf
.Pin
= t
.Pin
;
600 link
->conf
.Copy
= t
.Copy
;
601 link
->conf
.ExtStatus
= t
.ExtStatus
;
602 link
->conf
.ConfigIndex
= 0;
603 link
->conf
.Present
= t
.Present
;
604 DEBUG(2, "Setting Configuration");
605 ret
= pcmcia_request_configuration(link
->handle
, &link
->conf
);
606 if(ret
!= CS_SUCCESS
) {
607 cs_error(link
->handle
, RequestConfiguration
, ret
);
611 mtd
= do_map_probe("map_ram", &dev
->pcmcia_map
);
612 } else if(mem_type
== 2) {
613 mtd
= do_map_probe("map_rom", &dev
->pcmcia_map
);
615 for(i
= 0; i
< sizeof(probes
) / sizeof(char *); i
++) {
616 DEBUG(1, "Trying %s", probes
[i
]);
617 mtd
= do_map_probe(probes
[i
], &dev
->pcmcia_map
);
621 DEBUG(1, "FAILED: %s", probes
[i
]);
626 DEBUG(1, "Cant find an MTD");
627 pcmciamtd_release(link
);
632 mtd
->owner
= THIS_MODULE
;
637 /* Since we are using a default name, make it better by adding in the
639 if(mtd
->size
< 1048576) { /* <1MiB in size, show size in KiB */
640 size
= mtd
->size
>> 10;
643 size
= mtd
->size
>> 20;
646 snprintf(dev
->mtd_name
, sizeof(dev
->mtd_name
), "%d%ciB %s", size
, unit
, "PCMCIA Memory card");
649 /* If the memory found is fits completely into the mapped PCMCIA window,
650 use the faster non-remapping read/write functions */
651 if(mtd
->size
<= dev
->win_size
) {
652 DEBUG(1, "Using non remapping memory functions");
653 dev
->pcmcia_map
.map_priv_1
= (unsigned long)&(dev
->p_dev
->state
);
654 dev
->pcmcia_map
.map_priv_2
= (unsigned long)dev
->win_base
;
655 if (dev
->pcmcia_map
.bankwidth
== 1) {
656 dev
->pcmcia_map
.read
= pcmcia_read8
;
657 dev
->pcmcia_map
.write
= pcmcia_write8
;
659 dev
->pcmcia_map
.read
= pcmcia_read16
;
660 dev
->pcmcia_map
.write
= pcmcia_write16
;
662 dev
->pcmcia_map
.copy_from
= pcmcia_copy_from
;
663 dev
->pcmcia_map
.copy_to
= pcmcia_copy_to
;
666 if(add_mtd_device(mtd
)) {
668 dev
->mtd_info
= NULL
;
669 err("Couldnt register MTD device");
670 pcmciamtd_release(link
);
673 snprintf(dev
->node
.dev_name
, sizeof(dev
->node
.dev_name
), "mtd%d", mtd
->index
);
674 info("mtd%d: %s", mtd
->index
, mtd
->name
);
675 link
->state
&= ~DEV_CONFIG_PENDING
;
676 link
->dev_node
= &dev
->node
;
680 cs_error(link
->handle
, last_fn
, last_ret
);
681 err("CS Error, exiting");
682 pcmciamtd_release(link
);
687 static int pcmciamtd_suspend(struct pcmcia_device
*dev
)
689 DEBUG(2, "EVENT_PM_RESUME");
691 /* get_lock(link); */
696 static int pcmciamtd_resume(struct pcmcia_device
*dev
)
698 DEBUG(2, "EVENT_PM_SUSPEND");
700 /* free_lock(link); */
706 /* This deletes a driver "instance". The device is de-registered
707 * with Card Services. If it has been released, all local data
708 * structures are freed. Otherwise, the structures will be freed
709 * when the device is released.
712 static void pcmciamtd_detach(struct pcmcia_device
*p_dev
)
714 dev_link_t
*link
= dev_to_instance(p_dev
);
716 DEBUG(3, "link=0x%p", link
);
718 if(link
->state
& DEV_CONFIG
) {
719 struct pcmciamtd_dev
*dev
= link
->priv
;
721 del_mtd_device(dev
->mtd_info
);
722 info("mtd%d: Removed", dev
->mtd_info
->index
);
725 pcmciamtd_release(link
);
730 /* pcmciamtd_attach() creates an "instance" of the driver, allocating
731 * local data structures for one device. The device is registered
732 * with Card Services.
735 static int pcmciamtd_attach(struct pcmcia_device
*p_dev
)
737 struct pcmciamtd_dev
*dev
;
738 dev_link_t
*link
= dev_to_instance(p_dev
);
740 /* Create new memory card device */
741 dev
= kmalloc(sizeof(*dev
), GFP_KERNEL
);
742 if (!dev
) return -ENOMEM
;
743 DEBUG(1, "dev=0x%p", dev
);
745 memset(dev
, 0, sizeof(*dev
));
749 link
->conf
.Attributes
= 0;
750 link
->conf
.IntType
= INT_MEMORY
;
752 link
->state
|= DEV_PRESENT
| DEV_CONFIG_PENDING
;
753 pcmciamtd_config(link
);
758 static struct pcmcia_device_id pcmciamtd_ids
[] = {
759 PCMCIA_DEVICE_FUNC_ID(1),
760 PCMCIA_DEVICE_PROD_ID123("IO DATA", "PCS-2M", "2MB SRAM", 0x547e66dc, 0x1fed36cd, 0x36eadd21),
761 PCMCIA_DEVICE_PROD_ID12("IBM", "2MB SRAM", 0xb569a6e5, 0x36eadd21),
762 PCMCIA_DEVICE_PROD_ID12("IBM", "4MB FLASH", 0xb569a6e5, 0x8bc54d2a),
763 PCMCIA_DEVICE_PROD_ID12("IBM", "8MB FLASH", 0xb569a6e5, 0x6df1be3e),
764 PCMCIA_DEVICE_PROD_ID12("Intel", "S2E20SW", 0x816cc815, 0xd14c9dcf),
765 PCMCIA_DEVICE_PROD_ID12("Intel", "S2E8 SW", 0x816cc815, 0xa2d7dedb),
766 PCMCIA_DEVICE_PROD_ID12("intel", "SERIES2-02 ", 0x40ade711, 0x145cea5c),
767 PCMCIA_DEVICE_PROD_ID12("intel", "SERIES2-04 ", 0x40ade711, 0x42064dda),
768 PCMCIA_DEVICE_PROD_ID12("intel", "SERIES2-20 ", 0x40ade711, 0x25ee5cb0),
769 PCMCIA_DEVICE_PROD_ID12("intel", "VALUE SERIES 100 ", 0x40ade711, 0xdf8506d8),
770 PCMCIA_DEVICE_PROD_ID12("KINGMAX TECHNOLOGY INC.", "SRAM 256K Bytes", 0x54d0c69c, 0xad12c29c),
771 PCMCIA_DEVICE_PROD_ID12("Maxtor", "MAXFL MobileMax Flash Memory Card", 0xb68968c8, 0x2dfb47b0),
772 PCMCIA_DEVICE_PROD_ID12("SEIKO EPSON", "WWB101EN20", 0xf9876baf, 0xad0b207b),
773 PCMCIA_DEVICE_PROD_ID12("SEIKO EPSON", "WWB513EN20", 0xf9876baf, 0xe8d884ad),
774 PCMCIA_DEVICE_PROD_ID12("Starfish, Inc.", "REX-3000", 0x05ddca47, 0xe7d67bca),
775 PCMCIA_DEVICE_PROD_ID12("Starfish, Inc.", "REX-4100", 0x05ddca47, 0x7bc32944),
776 /* the following was commented out in pcmcia-cs-3.2.7 */
777 /* PCMCIA_DEVICE_PROD_ID12("RATOC Systems,Inc.", "SmartMedia ADAPTER PC Card", 0xf4a2fefe, 0x5885b2ae), */
778 #ifdef CONFIG_MTD_PCMCIA_ANONYMOUS
779 { .match_flags
= PCMCIA_DEV_ID_MATCH_ANONYMOUS
, },
783 MODULE_DEVICE_TABLE(pcmcia
, pcmciamtd_ids
);
785 static struct pcmcia_driver pcmciamtd_driver
= {
789 .probe
= pcmciamtd_attach
,
790 .remove
= pcmciamtd_detach
,
791 .owner
= THIS_MODULE
,
792 .id_table
= pcmciamtd_ids
,
793 .suspend
= pcmciamtd_suspend
,
794 .resume
= pcmciamtd_resume
,
798 static int __init
init_pcmciamtd(void)
800 info(DRIVER_DESC
" " DRIVER_VERSION
);
802 if(bankwidth
&& bankwidth
!= 1 && bankwidth
!= 2) {
803 info("bad bankwidth (%d), using default", bankwidth
);
806 if(force_size
&& (force_size
< 1 || force_size
> 64)) {
807 info("bad force_size (%d), using default", force_size
);
810 if(mem_type
&& mem_type
!= 1 && mem_type
!= 2) {
811 info("bad mem_type (%d), using default", mem_type
);
814 return pcmcia_register_driver(&pcmciamtd_driver
);
818 static void __exit
exit_pcmciamtd(void)
820 DEBUG(1, DRIVER_DESC
" unloading");
821 pcmcia_unregister_driver(&pcmciamtd_driver
);
824 module_init(init_pcmciamtd
);
825 module_exit(exit_pcmciamtd
);