pcmcia: convert pcmcia_request_configuration to pcmcia_enable_device
[linux-2.6.git] / drivers / mtd / maps / pcmciamtd.c
index aa820ee..388db9e 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: pcmciamtd.c,v 1.51 2004/07/12 22:38:29 dwmw2 Exp $
- *
  * pcmciamtd.c - MTD driver for PCMCIA flash memory cards
  *
  * Author: Simon Evans <spse@secret.org.uk>
@@ -18,9 +16,6 @@
 #include <asm/io.h>
 #include <asm/system.h>
 
-#include <pcmcia/version.h>
-#include <pcmcia/cs_types.h>
-#include <pcmcia/cs.h>
 #include <pcmcia/cistpl.h>
 #include <pcmcia/ds.h>
 
 
 #ifdef CONFIG_MTD_DEBUG
 static int debug = CONFIG_MTD_DEBUG_VERBOSE;
-MODULE_PARM(debug, "i");
+module_param(debug, int, 0);
 MODULE_PARM_DESC(debug, "Set Debug Level 0=quiet, 5=noisy");
 #undef DEBUG
 #define DEBUG(n, format, arg...) \
        if (n <= debug) {        \
-               printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __FUNCTION__ , ## arg); \
+               printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __func__ , ## arg); \
        }
 
 #else
@@ -43,20 +38,15 @@ MODULE_PARM_DESC(debug, "Set Debug Level 0=quiet, 5=noisy");
 static const int debug = 0;
 #endif
 
-#define err(format, arg...) printk(KERN_ERR "pcmciamtd: " format "\n" , ## arg)
 #define info(format, arg...) printk(KERN_INFO "pcmciamtd: " format "\n" , ## arg)
-#define warn(format, arg...) printk(KERN_WARNING "pcmciamtd: " format "\n" , ## arg)
-
 
 #define DRIVER_DESC    "PCMCIA Flash memory card driver"
-#define DRIVER_VERSION "$Revision: 1.51 $"
 
 /* Size of the PCMCIA address space: 26 bits = 64 MB */
 #define MAX_PCMCIA_ADDR        0x4000000
 
 struct pcmciamtd_dev {
-       dev_link_t      link;           /* PCMCIA link */
-       dev_node_t      node;           /* device node */
+       struct pcmcia_device    *p_dev;
        caddr_t         win_base;       /* ioremapped address of PCMCIA window */
        unsigned int    win_size;       /* size of window */
        unsigned int    offset;         /* offset into card the window currently points at */
@@ -67,9 +57,6 @@ struct pcmciamtd_dev {
 };
 
 
-static dev_info_t dev_info = "pcmciamtd";
-static dev_link_t *dev_list;
-
 /* Module parameters */
 
 /* 2 = do 16-bit transfers, 1 = do 8-bit transfers */
@@ -93,43 +80,43 @@ static int mem_type;
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Simon Evans <spse@secret.org.uk>");
 MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_PARM(bankwidth, "i");
+module_param(bankwidth, int, 0);
 MODULE_PARM_DESC(bankwidth, "Set bankwidth (1=8 bit, 2=16 bit, default=2)");
-MODULE_PARM(mem_speed, "i");
+module_param(mem_speed, int, 0);
 MODULE_PARM_DESC(mem_speed, "Set memory access speed in ns");
-MODULE_PARM(force_size, "i");
+module_param(force_size, int, 0);
 MODULE_PARM_DESC(force_size, "Force size of card in MiB (1-64)");
-MODULE_PARM(setvpp, "i");
+module_param(setvpp, int, 0);
 MODULE_PARM_DESC(setvpp, "Set Vpp (0=Never, 1=On writes, 2=Always on, default=0)");
-MODULE_PARM(vpp, "i");
+module_param(vpp, int, 0);
 MODULE_PARM_DESC(vpp, "Vpp value in 1/10ths eg 33=3.3V 120=12V (Dangerous)");
-MODULE_PARM(mem_type, "i");
+module_param(mem_type, int, 0);
 MODULE_PARM_DESC(mem_type, "Set Memory type (0=Flash, 1=RAM, 2=ROM, default=0)");
 
 
-/* read/write{8,16} copy_{from,to} routines with window remapping to access whole card */
+/* read/write{8,16} copy_{from,to} routines with window remapping
+ * to access whole card
+ */
 static caddr_t remap_window(struct map_info *map, unsigned long to)
 {
        struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
-       window_handle_t win = (window_handle_t)map->map_priv_2;
-       memreq_t mrq;
+       struct resource *win = (struct resource *) map->map_priv_2;
+       unsigned int offset;
        int ret;
 
-       if(!(dev->link.state & DEV_PRESENT)) {
-               DEBUG(1, "device removed state = 0x%4.4X", dev->link.state);
+       if (!pcmcia_dev_present(dev->p_dev)) {
+               DEBUG(1, "device removed");
                return 0;
        }
 
-       mrq.CardOffset = to & ~(dev->win_size-1);
-       if(mrq.CardOffset != dev->offset) {
+       offset = to & ~(dev->win_size-1);
+       if (offset != dev->offset) {
                DEBUG(2, "Remapping window from 0x%8.8x to 0x%8.8x",
-                     dev->offset, mrq.CardOffset);
-               mrq.Page = 0;
-               if( (ret = pcmcia_map_mem_page(win, &mrq)) != CS_SUCCESS) {
-                       cs_error(dev->link.handle, MapMemPage, ret);
+                     dev->offset, offset);
+               ret = pcmcia_map_mem_page(dev->p_dev, win, offset);
+               if (ret != 0)
                        return NULL;
-               }
-               dev->offset = mrq.CardOffset;
+               dev->offset = offset;
        }
        return dev->win_base + (to & (dev->win_size-1));
 }
@@ -145,7 +132,7 @@ static map_word pcmcia_read8_remap(struct map_info *map, unsigned long ofs)
                return d;
 
        d.x[0] = readb(addr);
-       DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%02x", ofs, addr, d.x[0]);
+       DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%02lx", ofs, addr, d.x[0]);
        return d;
 }
 
@@ -160,7 +147,7 @@ static map_word pcmcia_read16_remap(struct map_info *map, unsigned long ofs)
                return d;
 
        d.x[0] = readw(addr);
-       DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%04x", ofs, addr, d.x[0]);
+       DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%04lx", ofs, addr, d.x[0]);
        return d;
 }
 
@@ -170,14 +157,14 @@ static void pcmcia_copy_from_remap(struct map_info *map, void *to, unsigned long
        struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
        unsigned long win_size = dev->win_size;
 
-       DEBUG(3, "to = %p from = %lu len = %u", to, from, len);
+       DEBUG(3, "to = %p from = %lu len = %zd", to, from, len);
        while(len) {
                int toread = win_size - (from & (win_size-1));
                caddr_t addr;
 
                if(toread > len)
                        toread = len;
-               
+
                addr = remap_window(map, from);
                if(!addr)
                        return;
@@ -198,7 +185,7 @@ static void pcmcia_write8_remap(struct map_info *map, map_word d, unsigned long
        if(!addr)
                return;
 
-       DEBUG(3, "adr = 0x%08lx (%p)  data = 0x%02x", adr, addr, d.x[0]);
+       DEBUG(3, "adr = 0x%08lx (%p)  data = 0x%02lx", adr, addr, d.x[0]);
        writeb(d.x[0], addr);
 }
 
@@ -209,7 +196,7 @@ static void pcmcia_write16_remap(struct map_info *map, map_word d, unsigned long
        if(!addr)
                return;
 
-       DEBUG(3, "adr = 0x%08lx (%p)  data = 0x%04x", adr, addr, d.x[0]);
+       DEBUG(3, "adr = 0x%08lx (%p)  data = 0x%04lx", adr, addr, d.x[0]);
        writew(d.x[0], addr);
 }
 
@@ -219,7 +206,7 @@ static void pcmcia_copy_to_remap(struct map_info *map, unsigned long to, const v
        struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
        unsigned long win_size = dev->win_size;
 
-       DEBUG(3, "to = %lu from = %p len = %u", to, from, len);
+       DEBUG(3, "to = %lu from = %p len = %zd", to, from, len);
        while(len) {
                int towrite = win_size - (to & (win_size-1));
                caddr_t addr;
@@ -242,7 +229,7 @@ static void pcmcia_copy_to_remap(struct map_info *map, unsigned long to, const v
 
 /* read/write{8,16} copy_{from,to} routines with direct access */
 
-#define DEV_REMOVED(x)  (!(*(u_int *)x->map_priv_1 & DEV_PRESENT))
+#define DEV_REMOVED(x)  (!(pcmcia_dev_present(((struct pcmciamtd_dev *)map->map_priv_1)->p_dev)))
 
 static map_word pcmcia_read8(struct map_info *map, unsigned long ofs)
 {
@@ -253,7 +240,8 @@ static map_word pcmcia_read8(struct map_info *map, unsigned long ofs)
                return d;
 
        d.x[0] = readb(win_base + ofs);
-       DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%02x", ofs, win_base + ofs, d.x[0]);
+       DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%02lx",
+             ofs, win_base + ofs, d.x[0]);
        return d;
 }
 
@@ -267,7 +255,8 @@ static map_word pcmcia_read16(struct map_info *map, unsigned long ofs)
                return d;
 
        d.x[0] = readw(win_base + ofs);
-       DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%04x", ofs, win_base + ofs, d.x[0]);
+       DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%04lx",
+             ofs, win_base + ofs, d.x[0]);
        return d;
 }
 
@@ -279,32 +268,34 @@ static void pcmcia_copy_from(struct map_info *map, void *to, unsigned long from,
        if(DEV_REMOVED(map))
                return;
 
-       DEBUG(3, "to = %p from = %lu len = %u", to, from, len);
+       DEBUG(3, "to = %p from = %lu len = %zd", to, from, len);
        memcpy_fromio(to, win_base + from, len);
 }
 
 
-static void pcmcia_write8(struct map_info *map, u8 d, unsigned long adr)
+static void pcmcia_write8(struct map_info *map, map_word d, unsigned long adr)
 {
        caddr_t win_base = (caddr_t)map->map_priv_2;
 
        if(DEV_REMOVED(map))
                return;
 
-       DEBUG(3, "adr = 0x%08lx (%p)  data = 0x%02x", adr, win_base + adr, d);
-       writeb(d, win_base + adr);
+       DEBUG(3, "adr = 0x%08lx (%p)  data = 0x%02lx",
+             adr, win_base + adr, d.x[0]);
+       writeb(d.x[0], win_base + adr);
 }
 
 
-static void pcmcia_write16(struct map_info *map, u16 d, unsigned long adr)
+static void pcmcia_write16(struct map_info *map, map_word d, unsigned long adr)
 {
        caddr_t win_base = (caddr_t)map->map_priv_2;
 
        if(DEV_REMOVED(map))
                return;
 
-       DEBUG(3, "adr = 0x%08lx (%p)  data = 0x%04x", adr, win_base + adr, d);
-       writew(d, win_base + adr);
+       DEBUG(3, "adr = 0x%08lx (%p)  data = 0x%04lx",
+             adr, win_base + adr, d.x[0]);
+       writew(d.x[0], win_base + adr);
 }
 
 
@@ -315,7 +306,7 @@ static void pcmcia_copy_to(struct map_info *map, unsigned long to, const void *f
        if(DEV_REMOVED(map))
                return;
 
-       DEBUG(3, "to = %lu from = %p len = %u", to, from, len);
+       DEBUG(3, "to = %lu from = %p len = %zd", to, from, len);
        memcpy_toio(win_base + to, from, len);
 }
 
@@ -323,19 +314,10 @@ static void pcmcia_copy_to(struct map_info *map, unsigned long to, const void *f
 static void pcmciamtd_set_vpp(struct map_info *map, int on)
 {
        struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
-       dev_link_t *link = &dev->link;
-       modconf_t mod;
-       int ret;
-
-       mod.Attributes = CONF_VPP1_CHANGE_VALID | CONF_VPP2_CHANGE_VALID;
-       mod.Vcc = 0;
-       mod.Vpp1 = mod.Vpp2 = on ? dev->vpp : 0;
+       struct pcmcia_device *link = dev->p_dev;
 
        DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp);
-       ret = pcmcia_modify_configuration(link->handle, &mod);
-       if(ret != CS_SUCCESS) {
-               cs_error(link->handle, ModifyConfiguration, ret);
-       }
+       pcmcia_fixup_vpp(link, on ? dev->vpp : 0);
 }
 
 
@@ -344,119 +326,127 @@ static void pcmciamtd_set_vpp(struct map_info *map, int on)
  * still open, this will be postponed until it is closed.
  */
 
-static void pcmciamtd_release(dev_link_t *link)
+static void pcmciamtd_release(struct pcmcia_device *link)
 {
        struct pcmciamtd_dev *dev = link->priv;
 
        DEBUG(3, "link = 0x%p", link);
 
-       if (link->win) {
+       if (link->resource[2]->end) {
                if(dev->win_base) {
                        iounmap(dev->win_base);
                        dev->win_base = NULL;
                }
-               pcmcia_release_window(link->win);
        }
-       pcmcia_release_configuration(link->handle);
-       link->state &= ~DEV_CONFIG;
+       pcmcia_disable_device(link);
 }
 
 
-static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_name)
+#ifdef CONFIG_MTD_DEBUG
+static int pcmciamtd_cistpl_format(struct pcmcia_device *p_dev,
+                               tuple_t *tuple,
+                               void *priv_data)
 {
-       int rc;
-       tuple_t tuple;
        cisparse_t parse;
-       u_char buf[64];
-
-       tuple.Attributes = 0;
-       tuple.TupleData = (cisdata_t *)buf;
-       tuple.TupleDataMax = sizeof(buf);
-       tuple.TupleOffset = 0;
-       tuple.DesiredTuple = RETURN_FIRST_TUPLE;
-
-       rc = pcmcia_get_first_tuple(link->handle, &tuple);
-       while(rc == CS_SUCCESS) {
-               rc = pcmcia_get_tuple_data(link->handle, &tuple);
-               if(rc != CS_SUCCESS) {
-                       cs_error(link->handle, GetTupleData, rc);
-                       break;
-               }
-               rc = pcmcia_parse_tuple(link->handle, &tuple, &parse);
-               if(rc != CS_SUCCESS) {
-                       cs_error(link->handle, ParseTuple, rc);
-                       break;
-               }
-               
-               switch(tuple.TupleCode) {
-               case  CISTPL_FORMAT: {
-                       cistpl_format_t *t = &parse.format;
-                       (void)t; /* Shut up, gcc */
-                       DEBUG(2, "Format type: %u, Error Detection: %u, offset = %u, length =%u",
-                             t->type, t->edc, t->offset, t->length);
-                       break;
-                       
-               }
-                       
-               case CISTPL_DEVICE: {
-                       cistpl_device_t *t = &parse.device;
-                       int i;
-                       DEBUG(2, "Common memory:");
-                       dev->pcmcia_map.size = t->dev[0].size;
-                       for(i = 0; i < t->ndev; i++) {
-                               DEBUG(2, "Region %d, type = %u", i, t->dev[i].type);
-                               DEBUG(2, "Region %d, wp = %u", i, t->dev[i].wp);
-                               DEBUG(2, "Region %d, speed = %u ns", i, t->dev[i].speed);
-                               DEBUG(2, "Region %d, size = %u bytes", i, t->dev[i].size);
-                       }
-                       break;
-               }
-                       
-               case CISTPL_VERS_1: {
-                       cistpl_vers_1_t *t = &parse.version_1;
-                       int i;
-                       if(t->ns) {
-                               dev->mtd_name[0] = '\0';
-                               for(i = 0; i < t->ns; i++) {
-                                       if(i)
-                                               strcat(dev->mtd_name, " ");
-                                       strcat(dev->mtd_name, t->str+t->ofs[i]);
-                               }
-                       }
-                       DEBUG(2, "Found name: %s", dev->mtd_name);
-                       break;
-               }
-                       
-               case CISTPL_JEDEC_C: {
-                       cistpl_jedec_t *t = &parse.jedec;
-                       int i;
-                       for(i = 0; i < t->nid; i++) {
-                               DEBUG(2, "JEDEC: 0x%02x 0x%02x", t->id[i].mfr, t->id[i].info);
-                       }
-                       break;
-               }
-                       
-               case CISTPL_DEVICE_GEO: {
-                       cistpl_device_geo_t *t = &parse.device_geo;
-                       int i;
-                       dev->pcmcia_map.bankwidth = t->geo[0].buswidth;
-                       for(i = 0; i < t->ngeo; i++) {
-                               DEBUG(2, "region: %d bankwidth = %u", i, t->geo[i].buswidth);
-                               DEBUG(2, "region: %d erase_block = %u", i, t->geo[i].erase_block);
-                               DEBUG(2, "region: %d read_block = %u", i, t->geo[i].read_block);
-                               DEBUG(2, "region: %d write_block = %u", i, t->geo[i].write_block);
-                               DEBUG(2, "region: %d partition = %u", i, t->geo[i].partition);
-                               DEBUG(2, "region: %d interleave = %u", i, t->geo[i].interleave);
-                       }
-                       break;
-               }
-                       
-               default:
-                       DEBUG(2, "Unknown tuple code %d", tuple.TupleCode);
+
+       if (!pcmcia_parse_tuple(tuple, &parse)) {
+               cistpl_format_t *t = &parse.format;
+               (void)t; /* Shut up, gcc */
+               DEBUG(2, "Format type: %u, Error Detection: %u, offset = %u, length =%u",
+                       t->type, t->edc, t->offset, t->length);
+       }
+       return -ENOSPC;
+}
+
+static int pcmciamtd_cistpl_jedec(struct pcmcia_device *p_dev,
+                               tuple_t *tuple,
+                               void *priv_data)
+{
+       cisparse_t parse;
+       int i;
+
+       if (!pcmcia_parse_tuple(tuple, &parse)) {
+               cistpl_jedec_t *t = &parse.jedec;
+               for (i = 0; i < t->nid; i++)
+                       DEBUG(2, "JEDEC: 0x%02x 0x%02x",
+                             t->id[i].mfr, t->id[i].info);
+       }
+       return -ENOSPC;
+}
+#endif
+
+static int pcmciamtd_cistpl_device(struct pcmcia_device *p_dev,
+                               tuple_t *tuple,
+                               void *priv_data)
+{
+       struct pcmciamtd_dev *dev = priv_data;
+       cisparse_t parse;
+       cistpl_device_t *t = &parse.device;
+       int i;
+
+       if (pcmcia_parse_tuple(tuple, &parse))
+               return -EINVAL;
+
+       DEBUG(2, "Common memory:");
+       dev->pcmcia_map.size = t->dev[0].size;
+       /* from here on: DEBUG only */
+       for (i = 0; i < t->ndev; i++) {
+               DEBUG(2, "Region %d, type = %u", i, t->dev[i].type);
+               DEBUG(2, "Region %d, wp = %u", i, t->dev[i].wp);
+               DEBUG(2, "Region %d, speed = %u ns", i, t->dev[i].speed);
+               DEBUG(2, "Region %d, size = %u bytes", i, t->dev[i].size);
+       }
+       return 0;
+}
+
+static int pcmciamtd_cistpl_geo(struct pcmcia_device *p_dev,
+                               tuple_t *tuple,
+                               void *priv_data)
+{
+       struct pcmciamtd_dev *dev = priv_data;
+       cisparse_t parse;
+       cistpl_device_geo_t *t = &parse.device_geo;
+       int i;
+
+       if (pcmcia_parse_tuple(tuple, &parse))
+               return -EINVAL;
+
+       dev->pcmcia_map.bankwidth = t->geo[0].buswidth;
+       /* from here on: DEBUG only */
+       for (i = 0; i < t->ngeo; i++) {
+               DEBUG(2, "region: %d bankwidth = %u", i, t->geo[i].buswidth);
+               DEBUG(2, "region: %d erase_block = %u", i, t->geo[i].erase_block);
+               DEBUG(2, "region: %d read_block = %u", i, t->geo[i].read_block);
+               DEBUG(2, "region: %d write_block = %u", i, t->geo[i].write_block);
+               DEBUG(2, "region: %d partition = %u", i, t->geo[i].partition);
+               DEBUG(2, "region: %d interleave = %u", i, t->geo[i].interleave);
+       }
+       return 0;
+}
+
+
+static void card_settings(struct pcmciamtd_dev *dev, struct pcmcia_device *p_dev, int *new_name)
+{
+       int i;
+
+       if (p_dev->prod_id[0]) {
+               dev->mtd_name[0] = '\0';
+               for (i = 0; i < 4; i++) {
+                       if (i)
+                               strcat(dev->mtd_name, " ");
+                       if (p_dev->prod_id[i])
+                               strcat(dev->mtd_name, p_dev->prod_id[i]);
                }
-               
-               rc = pcmcia_get_next_tuple(link->handle, &tuple);
+               DEBUG(2, "Found name: %s", dev->mtd_name);
        }
+
+#ifdef CONFIG_MTD_DEBUG
+       pcmcia_loop_tuple(p_dev, CISTPL_FORMAT, pcmciamtd_cistpl_format, NULL);
+       pcmcia_loop_tuple(p_dev, CISTPL_JEDEC_C, pcmciamtd_cistpl_jedec, NULL);
+#endif
+       pcmcia_loop_tuple(p_dev, CISTPL_DEVICE, pcmciamtd_cistpl_device, dev);
+       pcmcia_loop_tuple(p_dev, CISTPL_DEVICE_GEO, pcmciamtd_cistpl_geo, dev);
+
        if(!dev->pcmcia_map.size)
                dev->pcmcia_map.size = MAX_PCMCIA_ADDR;
 
@@ -471,7 +461,7 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
        if(bankwidth) {
                dev->pcmcia_map.bankwidth = bankwidth;
                DEBUG(2, "bankwidth forced to %d", bankwidth);
-       }               
+       }
 
        dev->pcmcia_map.name = dev->mtd_name;
        if(!dev->mtd_name[0]) {
@@ -480,7 +470,8 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
        }
 
        DEBUG(1, "Device: Size: %lu Width:%d Name: %s",
-             dev->pcmcia_map.size, dev->pcmcia_map.bankwidth << 3, dev->mtd_name);
+             dev->pcmcia_map.size,
+             dev->pcmcia_map.bankwidth << 3, dev->mtd_name);
 }
 
 
@@ -489,36 +480,17 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
  * MTD device available to the system.
  */
 
-#define CS_CHECK(fn, ret) \
-do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
-
-static void pcmciamtd_config(dev_link_t *link)
+static int pcmciamtd_config(struct pcmcia_device *link)
 {
        struct pcmciamtd_dev *dev = link->priv;
        struct mtd_info *mtd = NULL;
-       cs_status_t status;
-       win_req_t req;
-       int last_ret = 0, last_fn = 0;
        int ret;
-       int i;
-       config_info_t t;
+       int i, j = 0;
        static char *probes[] = { "jedec_probe", "cfi_probe" };
-       cisinfo_t cisinfo;
        int new_name = 0;
 
        DEBUG(3, "link=0x%p", link);
 
-       /* Configure card */
-       link->state |= DEV_CONFIG;
-
-       DEBUG(2, "Validating CIS");
-       ret = pcmcia_validate_cis(link->handle, &cisinfo);
-       if(ret != CS_SUCCESS) {
-               cs_error(link->handle, GetTupleData, ret);
-       } else {
-               DEBUG(2, "ValidateCIS found %d chains", cisinfo.Chains);
-       }
-
        card_settings(dev, link, &new_name);
 
        dev->pcmcia_map.phys = NO_XIP;
@@ -534,85 +506,82 @@ static void pcmciamtd_config(dev_link_t *link)
        if(setvpp == 1)
                dev->pcmcia_map.set_vpp = pcmciamtd_set_vpp;
 
-       /* Request a memory window for PCMCIA. Some architeures can map windows upto the maximum
-          that PCMCIA can support (64MiB) - this is ideal and we aim for a window the size of the
-          whole card - otherwise we try smaller windows until we succeed */
-
-       req.Attributes =  WIN_MEMORY_TYPE_CM | WIN_ENABLE;
-       req.Attributes |= (dev->pcmcia_map.bankwidth == 1) ? WIN_DATA_WIDTH_8 : WIN_DATA_WIDTH_16;
-       req.Base = 0;
-       req.AccessSpeed = mem_speed;
-       link->win = (window_handle_t)link->handle;
-       req.Size = (force_size) ? force_size << 20 : MAX_PCMCIA_ADDR;
+       /* Request a memory window for PCMCIA. Some architeures can map windows
+        * upto the maximum that PCMCIA can support (64MiB) - this is ideal and
+        * we aim for a window the size of the whole card - otherwise we try
+        * smaller windows until we succeed
+        */
+
+       link->resource[2]->flags |=  WIN_MEMORY_TYPE_CM | WIN_ENABLE;
+       link->resource[2]->flags |= (dev->pcmcia_map.bankwidth == 1) ?
+                                       WIN_DATA_WIDTH_8 : WIN_DATA_WIDTH_16;
+       link->resource[2]->start = 0;
+       link->resource[2]->end = (force_size) ? force_size << 20 :
+                                       MAX_PCMCIA_ADDR;
        dev->win_size = 0;
 
        do {
                int ret;
-               DEBUG(2, "requesting window with size = %dKiB memspeed = %d",
-                     req.Size >> 10, req.AccessSpeed);
-               ret = pcmcia_request_window(&link->handle, &req, &link->win);
+               DEBUG(2, "requesting window with size = %luKiB memspeed = %d",
+                       (unsigned long) resource_size(link->resource[2]) >> 10,
+                       mem_speed);
+               ret = pcmcia_request_window(link, link->resource[2], mem_speed);
                DEBUG(2, "ret = %d dev->win_size = %d", ret, dev->win_size);
                if(ret) {
-                       req.Size >>= 1;
+                       j++;
+                       link->resource[2]->start = 0;
+                       link->resource[2]->end = (force_size) ?
+                                       force_size << 20 : MAX_PCMCIA_ADDR;
+                       link->resource[2]->end >>= j;
                } else {
-                       DEBUG(2, "Got window of size %dKiB", req.Size >> 10);
-                       dev->win_size = req.Size;
+                       DEBUG(2, "Got window of size %luKiB", (unsigned long)
+                               resource_size(link->resource[2]) >> 10);
+                       dev->win_size = resource_size(link->resource[2]);
                        break;
                }
-       } while(req.Size >= 0x1000);
+       } while (link->resource[2]->end >= 0x1000);
 
        DEBUG(2, "dev->win_size = %d", dev->win_size);
 
        if(!dev->win_size) {
-               err("Cant allocate memory window");
+               dev_err(&dev->p_dev->dev, "Cannot allocate memory window\n");
                pcmciamtd_release(link);
-               return;
+               return -ENODEV;
        }
        DEBUG(1, "Allocated a window of %dKiB", dev->win_size >> 10);
-               
+
        /* Get write protect status */
-       CS_CHECK(GetStatus, pcmcia_get_status(link->handle, &status));
-       DEBUG(2, "status value: 0x%x window handle = 0x%8.8lx",
-             status.CardState, (unsigned long)link->win);
-       dev->win_base = ioremap(req.Base, req.Size);
+       dev->win_base = ioremap(link->resource[2]->start,
+                               resource_size(link->resource[2]));
        if(!dev->win_base) {
-               err("ioremap(%lu, %u) failed", req.Base, req.Size);
+               dev_err(&dev->p_dev->dev, "ioremap(%pR) failed\n",
+                       link->resource[2]);
                pcmciamtd_release(link);
-               return;
+               return -ENODEV;
        }
-       DEBUG(1, "mapped window dev = %p req.base = 0x%lx base = %p size = 0x%x",
-             dev, req.Base, dev->win_base, req.Size);
+       DEBUG(1, "mapped window dev = %p @ %pR, base = %p",
+             dev, link->resource[2], dev->win_base);
 
        dev->offset = 0;
        dev->pcmcia_map.map_priv_1 = (unsigned long)dev;
-       dev->pcmcia_map.map_priv_2 = (unsigned long)link->win;
-
-       DEBUG(2, "Getting configuration");
-       CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link->handle, &t));
-       DEBUG(2, "Vcc = %d Vpp1 = %d Vpp2 = %d", t.Vcc, t.Vpp1, t.Vpp2);
-       dev->vpp = (vpp) ? vpp : t.Vpp1;
-       link->conf.Attributes = 0;
-       link->conf.Vcc = t.Vcc;
+       dev->pcmcia_map.map_priv_2 = (unsigned long)link->resource[2];
+
+       dev->vpp = (vpp) ? vpp : link->socket->socket.Vpp;
        if(setvpp == 2) {
-               link->conf.Vpp1 = dev->vpp;
-               link->conf.Vpp2 = dev->vpp;
+               link->vpp = dev->vpp;
        } else {
-               link->conf.Vpp1 = 0;
-               link->conf.Vpp2 = 0;
+               link->vpp = 0;
        }
 
-       link->conf.IntType = INT_MEMORY;
-       link->conf.ConfigBase = t.ConfigBase;
-       link->conf.Status = t.Status;
-       link->conf.Pin = t.Pin;
-       link->conf.Copy = t.Copy;
-       link->conf.ExtStatus = t.ExtStatus;
-       link->conf.ConfigIndex = 0;
-       link->conf.Present = t.Present;
+       link->config_index = 0;
        DEBUG(2, "Setting Configuration");
-       ret = pcmcia_request_configuration(link->handle, &link->conf);
-       if(ret != CS_SUCCESS) {
-               cs_error(link->handle, RequestConfiguration, ret);
+       ret = pcmcia_enable_device(link);
+       if (ret != 0) {
+               if (dev->win_base) {
+                       iounmap(dev->win_base);
+                       dev->win_base = NULL;
+               }
+               return -ENODEV;
        }
 
        if(mem_type == 1) {
@@ -620,20 +589,20 @@ static void pcmciamtd_config(dev_link_t *link)
        } else if(mem_type == 2) {
                mtd = do_map_probe("map_rom", &dev->pcmcia_map);
        } else {
-               for(i = 0; i < sizeof(probes) / sizeof(char *); i++) {
+               for(i = 0; i < ARRAY_SIZE(probes); i++) {
                        DEBUG(1, "Trying %s", probes[i]);
                        mtd = do_map_probe(probes[i], &dev->pcmcia_map);
                        if(mtd)
                                break;
-                       
+
                        DEBUG(1, "FAILED: %s", probes[i]);
                }
        }
-       
+
        if(!mtd) {
-               DEBUG(1, "Cant find an MTD");
+               DEBUG(1, "Can not find an MTD");
                pcmciamtd_release(link);
-               return;
+               return -ENODEV;
        }
 
        dev->mtd_info = mtd;
@@ -642,8 +611,9 @@ static void pcmciamtd_config(dev_link_t *link)
        if(new_name) {
                int size = 0;
                char unit = ' ';
-               /* Since we are using a default name, make it better by adding in the
-                  size */
+               /* Since we are using a default name, make it better by adding
+                * in the size
+                */
                if(mtd->size < 1048576) { /* <1MiB in size, show size in KiB */
                        size = mtd->size >> 10;
                        unit = 'K';
@@ -658,7 +628,6 @@ static void pcmciamtd_config(dev_link_t *link)
           use the faster non-remapping read/write functions */
        if(mtd->size <= dev->win_size) {
                DEBUG(1, "Using non remapping memory functions");
-               dev->pcmcia_map.map_priv_1 = (unsigned long)&(dev->link.state);
                dev->pcmcia_map.map_priv_2 = (unsigned long)dev->win_base;
                if (dev->pcmcia_map.bankwidth == 1) {
                        dev->pcmcia_map.read = pcmcia_read8;
@@ -674,73 +643,35 @@ static void pcmciamtd_config(dev_link_t *link)
        if(add_mtd_device(mtd)) {
                map_destroy(mtd);
                dev->mtd_info = NULL;
-               err("Couldnt register MTD device");
+               dev_err(&dev->p_dev->dev,
+                       "Could not register the MTD device\n");
                pcmciamtd_release(link);
-               return;
+               return -ENODEV;
        }
-       snprintf(dev->node.dev_name, sizeof(dev->node.dev_name), "mtd%d", mtd->index);
-       info("mtd%d: %s", mtd->index, mtd->name);
-       link->state &= ~DEV_CONFIG_PENDING;
-       link->dev = &dev->node;
-       return;
-
- cs_failed:
-       cs_error(link->handle, last_fn, last_ret);
-       err("CS Error, exiting");
+       dev_info(&dev->p_dev->dev, "mtd%d: %s\n", mtd->index, mtd->name);
+       return 0;
+
+       dev_err(&dev->p_dev->dev, "CS Error, exiting\n");
        pcmciamtd_release(link);
-       return;
+       return -ENODEV;
 }
 
 
-/* The card status event handler.  Mostly, this schedules other
- * stuff to run after an event is received.  A CARD_REMOVAL event
- * also sets some flags to discourage the driver from trying
- * to talk to the card any more.
- */
+static int pcmciamtd_suspend(struct pcmcia_device *dev)
+{
+       DEBUG(2, "EVENT_PM_RESUME");
+
+       /* get_lock(link); */
 
-static int pcmciamtd_event(event_t event, int priority,
-                       event_callback_args_t *args)
+       return 0;
+}
+
+static int pcmciamtd_resume(struct pcmcia_device *dev)
 {
-       dev_link_t *link = args->client_data;
-
-       DEBUG(1, "event=0x%06x", event);
-       switch (event) {
-       case CS_EVENT_CARD_REMOVAL:
-               DEBUG(2, "EVENT_CARD_REMOVAL");
-               link->state &= ~DEV_PRESENT;
-               if (link->state & DEV_CONFIG) {
-                       struct pcmciamtd_dev *dev = link->priv;
-                       if(dev->mtd_info) {
-                               del_mtd_device(dev->mtd_info);
-                               info("mtd%d: Removed", dev->mtd_info->index);
-                       }
-                       pcmciamtd_release(link);
-               }
-               break;
-       case CS_EVENT_CARD_INSERTION:
-               DEBUG(2, "EVENT_CARD_INSERTION");
-               link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
-               pcmciamtd_config(link);
-               break;
-       case CS_EVENT_PM_SUSPEND:
-               DEBUG(2, "EVENT_PM_SUSPEND");
-               link->state |= DEV_SUSPEND;
-               /* Fall through... */
-       case CS_EVENT_RESET_PHYSICAL:
-               DEBUG(2, "EVENT_RESET_PHYSICAL");
-               /* get_lock(link); */
-               break;
-       case CS_EVENT_PM_RESUME:
-               DEBUG(2, "EVENT_PM_RESUME");
-               link->state &= ~DEV_SUSPEND;
-               /* Fall through... */
-       case CS_EVENT_CARD_RESET:
-               DEBUG(2, "EVENT_CARD_RESET");
-               /* free_lock(link); */
-               break;
-       default:
-               DEBUG(2, "Unknown event %d", event);
-       }
+       DEBUG(2, "EVENT_PM_SUSPEND");
+
+       /* free_lock(link); */
+
        return 0;
 }
 
@@ -751,23 +682,20 @@ static int pcmciamtd_event(event_t event, int priority,
  * when the device is released.
  */
 
-static void pcmciamtd_detach(dev_link_t *link)
+static void pcmciamtd_detach(struct pcmcia_device *link)
 {
-       DEBUG(3, "link=0x%p", link);
+       struct pcmciamtd_dev *dev = link->priv;
 
-       if(link->state & DEV_CONFIG) {
-               pcmciamtd_release(link);
-       }
+       DEBUG(3, "link=0x%p", link);
 
-       if (link->handle) {
-               int ret;
-               DEBUG(2, "Deregistering with card services");
-               ret = pcmcia_deregister_client(link->handle);
-               if (ret != CS_SUCCESS)
-                       cs_error(link->handle, DeregisterClient, ret);
+       if(dev->mtd_info) {
+               del_mtd_device(dev->mtd_info);
+               dev_info(&dev->p_dev->dev, "mtd%d: Removing\n",
+                        dev->mtd_info->index);
+               map_destroy(dev->mtd_info);
        }
 
-       link->state |= DEV_STALE_LINK;
+       pcmciamtd_release(link);
 }
 
 
@@ -776,41 +704,19 @@ static void pcmciamtd_detach(dev_link_t *link)
  * with Card Services.
  */
 
-static dev_link_t *pcmciamtd_attach(void)
+static int pcmciamtd_probe(struct pcmcia_device *link)
 {
        struct pcmciamtd_dev *dev;
-       dev_link_t *link;
-       client_reg_t client_reg;
-       int ret;
 
        /* Create new memory card device */
-       dev = kmalloc(sizeof(*dev), GFP_KERNEL);
-       if (!dev) return NULL;
+       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+       if (!dev) return -ENOMEM;
        DEBUG(1, "dev=0x%p", dev);
 
-       memset(dev, 0, sizeof(*dev));
-       link = &dev->link;
+       dev->p_dev = link;
        link->priv = dev;
 
-       link->conf.Attributes = 0;
-       link->conf.IntType = INT_MEMORY;
-
-       link->next = dev_list;
-       dev_list = link;
-
-       /* Register with Card Services */
-       client_reg.dev_info = &dev_info;
-       client_reg.Version = 0x0210;
-       client_reg.event_callback_args.client_data = link;
-       DEBUG(2, "Calling RegisterClient");
-       ret = pcmcia_register_client(&link->handle, &client_reg);
-       if (ret != 0) {
-               cs_error(link->handle, RegisterClient, ret);
-               pcmciamtd_detach(link);
-               return NULL;
-       }
-       DEBUG(2, "link = %p", link);
-       return link;
+       return pcmciamtd_config(link);
 }
 
 static struct pcmcia_device_id pcmciamtd_ids[] = {
@@ -827,8 +733,11 @@ static struct pcmcia_device_id pcmciamtd_ids[] = {
        PCMCIA_DEVICE_PROD_ID12("intel", "VALUE SERIES 100 ", 0x40ade711, 0xdf8506d8),
        PCMCIA_DEVICE_PROD_ID12("KINGMAX TECHNOLOGY INC.", "SRAM 256K Bytes", 0x54d0c69c, 0xad12c29c),
        PCMCIA_DEVICE_PROD_ID12("Maxtor", "MAXFL MobileMax Flash Memory Card", 0xb68968c8, 0x2dfb47b0),
+       PCMCIA_DEVICE_PROD_ID123("M-Systems", "M-SYS Flash Memory Card", "(c) M-Systems", 0x7ed2ad87, 0x675dc3fb, 0x7aef3965),
+       PCMCIA_DEVICE_PROD_ID12("PRETEC", "  2MB SRAM CARD", 0xebf91155, 0x805360ca),
        PCMCIA_DEVICE_PROD_ID12("SEIKO EPSON", "WWB101EN20", 0xf9876baf, 0xad0b207b),
        PCMCIA_DEVICE_PROD_ID12("SEIKO EPSON", "WWB513EN20", 0xf9876baf, 0xe8d884ad),
+       PCMCIA_DEVICE_PROD_ID12("SMART Modular Technologies", " 4MB FLASH Card", 0x96fd8277, 0x737a5b05),
        PCMCIA_DEVICE_PROD_ID12("Starfish, Inc.", "REX-3000", 0x05ddca47, 0xe7d67bca),
        PCMCIA_DEVICE_PROD_ID12("Starfish, Inc.", "REX-4100", 0x05ddca47, 0x7bc32944),
        /* the following was commented out in pcmcia-cs-3.2.7 */
@@ -844,17 +753,18 @@ static struct pcmcia_driver pcmciamtd_driver = {
        .drv            = {
                .name   = "pcmciamtd"
        },
-       .attach         = pcmciamtd_attach,
-       .event          = pcmciamtd_event,
-       .detach         = pcmciamtd_detach,
+       .probe          = pcmciamtd_probe,
+       .remove         = pcmciamtd_detach,
        .owner          = THIS_MODULE,
        .id_table       = pcmciamtd_ids,
+       .suspend        = pcmciamtd_suspend,
+       .resume         = pcmciamtd_resume,
 };
 
 
 static int __init init_pcmciamtd(void)
 {
-       info(DRIVER_DESC " " DRIVER_VERSION);
+       info(DRIVER_DESC);
 
        if(bankwidth && bankwidth != 1 && bankwidth != 2) {
                info("bad bankwidth (%d), using default", bankwidth);
@@ -876,7 +786,6 @@ static void __exit exit_pcmciamtd(void)
 {
        DEBUG(1, DRIVER_DESC " unloading");
        pcmcia_unregister_driver(&pcmciamtd_driver);
-       BUG_ON(dev_list != NULL);
 }
 
 module_init(init_pcmciamtd);