Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 2 | * $Id: pcmciamtd.c,v 1.55 2005/11/07 11:14:28 gleixner Exp $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * pcmciamtd.c - MTD driver for PCMCIA flash memory cards |
| 5 | * |
| 6 | * Author: Simon Evans <spse@secret.org.uk> |
| 7 | * |
| 8 | * Copyright (C) 2002 Simon Evans |
| 9 | * |
| 10 | * Licence: GPL |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/timer.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <asm/io.h> |
| 19 | #include <asm/system.h> |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <pcmcia/cs_types.h> |
| 22 | #include <pcmcia/cs.h> |
| 23 | #include <pcmcia/cistpl.h> |
| 24 | #include <pcmcia/ds.h> |
| 25 | |
| 26 | #include <linux/mtd/map.h> |
| 27 | #include <linux/mtd/mtd.h> |
| 28 | |
| 29 | #ifdef CONFIG_MTD_DEBUG |
| 30 | static int debug = CONFIG_MTD_DEBUG_VERBOSE; |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 31 | module_param(debug, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | MODULE_PARM_DESC(debug, "Set Debug Level 0=quiet, 5=noisy"); |
| 33 | #undef DEBUG |
| 34 | #define DEBUG(n, format, arg...) \ |
| 35 | if (n <= debug) { \ |
Harvey Harrison | cb53b3b | 2008-04-18 13:44:19 -0700 | [diff] [blame] | 36 | printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __func__ , ## arg); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | #else |
| 40 | #undef DEBUG |
| 41 | #define DEBUG(n, arg...) |
| 42 | static const int debug = 0; |
| 43 | #endif |
| 44 | |
| 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) |
| 48 | |
| 49 | |
| 50 | #define DRIVER_DESC "PCMCIA Flash memory card driver" |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 51 | #define DRIVER_VERSION "$Revision: 1.55 $" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | /* Size of the PCMCIA address space: 26 bits = 64 MB */ |
| 54 | #define MAX_PCMCIA_ADDR 0x4000000 |
| 55 | |
| 56 | struct pcmciamtd_dev { |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 57 | struct pcmcia_device *p_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
| 64 | int vpp; |
| 65 | char mtd_name[sizeof(struct cistpl_vers_1_t)]; |
| 66 | }; |
| 67 | |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | /* Module parameters */ |
| 70 | |
| 71 | /* 2 = do 16-bit transfers, 1 = do 8-bit transfers */ |
| 72 | static int bankwidth = 2; |
| 73 | |
| 74 | /* Speed of memory accesses, in ns */ |
| 75 | static int mem_speed; |
| 76 | |
| 77 | /* Force the size of an SRAM card */ |
| 78 | static int force_size; |
| 79 | |
| 80 | /* Force Vpp */ |
| 81 | static int vpp; |
| 82 | |
| 83 | /* Set Vpp */ |
| 84 | static int setvpp; |
| 85 | |
| 86 | /* Force card to be treated as FLASH, ROM or RAM */ |
| 87 | static int mem_type; |
| 88 | |
| 89 | MODULE_LICENSE("GPL"); |
| 90 | MODULE_AUTHOR("Simon Evans <spse@secret.org.uk>"); |
| 91 | MODULE_DESCRIPTION(DRIVER_DESC); |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 92 | module_param(bankwidth, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | MODULE_PARM_DESC(bankwidth, "Set bankwidth (1=8 bit, 2=16 bit, default=2)"); |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 94 | module_param(mem_speed, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | MODULE_PARM_DESC(mem_speed, "Set memory access speed in ns"); |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 96 | module_param(force_size, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | MODULE_PARM_DESC(force_size, "Force size of card in MiB (1-64)"); |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 98 | module_param(setvpp, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | MODULE_PARM_DESC(setvpp, "Set Vpp (0=Never, 1=On writes, 2=Always on, default=0)"); |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 100 | module_param(vpp, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | MODULE_PARM_DESC(vpp, "Vpp value in 1/10ths eg 33=3.3V 120=12V (Dangerous)"); |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 102 | module_param(mem_type, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | MODULE_PARM_DESC(mem_type, "Set Memory type (0=Flash, 1=RAM, 2=ROM, default=0)"); |
| 104 | |
| 105 | |
| 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) |
| 108 | { |
| 109 | struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1; |
| 110 | window_handle_t win = (window_handle_t)map->map_priv_2; |
| 111 | memreq_t mrq; |
| 112 | int ret; |
| 113 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 114 | if (!pcmcia_dev_present(dev->p_dev)) { |
| 115 | DEBUG(1, "device removed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | return 0; |
| 117 | } |
| 118 | |
| 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); |
| 123 | mrq.Page = 0; |
| 124 | if( (ret = pcmcia_map_mem_page(win, &mrq)) != CS_SUCCESS) { |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 125 | cs_error(dev->p_dev, MapMemPage, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | return NULL; |
| 127 | } |
| 128 | dev->offset = mrq.CardOffset; |
| 129 | } |
| 130 | return dev->win_base + (to & (dev->win_size-1)); |
| 131 | } |
| 132 | |
| 133 | |
| 134 | static map_word pcmcia_read8_remap(struct map_info *map, unsigned long ofs) |
| 135 | { |
| 136 | caddr_t addr; |
| 137 | map_word d = {{0}}; |
| 138 | |
| 139 | addr = remap_window(map, ofs); |
| 140 | if(!addr) |
| 141 | return d; |
| 142 | |
| 143 | d.x[0] = readb(addr); |
| 144 | DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%02x", ofs, addr, d.x[0]); |
| 145 | return d; |
| 146 | } |
| 147 | |
| 148 | |
| 149 | static map_word pcmcia_read16_remap(struct map_info *map, unsigned long ofs) |
| 150 | { |
| 151 | caddr_t addr; |
| 152 | map_word d = {{0}}; |
| 153 | |
| 154 | addr = remap_window(map, ofs); |
| 155 | if(!addr) |
| 156 | return d; |
| 157 | |
| 158 | d.x[0] = readw(addr); |
| 159 | DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%04x", ofs, addr, d.x[0]); |
| 160 | return d; |
| 161 | } |
| 162 | |
| 163 | |
| 164 | static void pcmcia_copy_from_remap(struct map_info *map, void *to, unsigned long from, ssize_t len) |
| 165 | { |
| 166 | struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1; |
| 167 | unsigned long win_size = dev->win_size; |
| 168 | |
| 169 | DEBUG(3, "to = %p from = %lu len = %u", to, from, len); |
| 170 | while(len) { |
| 171 | int toread = win_size - (from & (win_size-1)); |
| 172 | caddr_t addr; |
| 173 | |
| 174 | if(toread > len) |
| 175 | toread = len; |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | addr = remap_window(map, from); |
| 178 | if(!addr) |
| 179 | return; |
| 180 | |
| 181 | DEBUG(4, "memcpy from %p to %p len = %d", addr, to, toread); |
| 182 | memcpy_fromio(to, addr, toread); |
| 183 | len -= toread; |
| 184 | to += toread; |
| 185 | from += toread; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | |
| 190 | static void pcmcia_write8_remap(struct map_info *map, map_word d, unsigned long adr) |
| 191 | { |
| 192 | caddr_t addr = remap_window(map, adr); |
| 193 | |
| 194 | if(!addr) |
| 195 | return; |
| 196 | |
| 197 | DEBUG(3, "adr = 0x%08lx (%p) data = 0x%02x", adr, addr, d.x[0]); |
| 198 | writeb(d.x[0], addr); |
| 199 | } |
| 200 | |
| 201 | |
| 202 | static void pcmcia_write16_remap(struct map_info *map, map_word d, unsigned long adr) |
| 203 | { |
| 204 | caddr_t addr = remap_window(map, adr); |
| 205 | if(!addr) |
| 206 | return; |
| 207 | |
| 208 | DEBUG(3, "adr = 0x%08lx (%p) data = 0x%04x", adr, addr, d.x[0]); |
| 209 | writew(d.x[0], addr); |
| 210 | } |
| 211 | |
| 212 | |
| 213 | static void pcmcia_copy_to_remap(struct map_info *map, unsigned long to, const void *from, ssize_t len) |
| 214 | { |
| 215 | struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1; |
| 216 | unsigned long win_size = dev->win_size; |
| 217 | |
| 218 | DEBUG(3, "to = %lu from = %p len = %u", to, from, len); |
| 219 | while(len) { |
| 220 | int towrite = win_size - (to & (win_size-1)); |
| 221 | caddr_t addr; |
| 222 | |
| 223 | if(towrite > len) |
| 224 | towrite = len; |
| 225 | |
| 226 | addr = remap_window(map, to); |
| 227 | if(!addr) |
| 228 | return; |
| 229 | |
| 230 | DEBUG(4, "memcpy from %p to %p len = %d", from, addr, towrite); |
| 231 | memcpy_toio(addr, from, towrite); |
| 232 | len -= towrite; |
| 233 | to += towrite; |
| 234 | from += towrite; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | |
| 239 | /* read/write{8,16} copy_{from,to} routines with direct access */ |
| 240 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 241 | #define DEV_REMOVED(x) (!(pcmcia_dev_present(((struct pcmciamtd_dev *)map->map_priv_1)->p_dev))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
| 243 | static map_word pcmcia_read8(struct map_info *map, unsigned long ofs) |
| 244 | { |
| 245 | caddr_t win_base = (caddr_t)map->map_priv_2; |
| 246 | map_word d = {{0}}; |
| 247 | |
| 248 | if(DEV_REMOVED(map)) |
| 249 | return d; |
| 250 | |
| 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]); |
| 253 | return d; |
| 254 | } |
| 255 | |
| 256 | |
| 257 | static map_word pcmcia_read16(struct map_info *map, unsigned long ofs) |
| 258 | { |
| 259 | caddr_t win_base = (caddr_t)map->map_priv_2; |
| 260 | map_word d = {{0}}; |
| 261 | |
| 262 | if(DEV_REMOVED(map)) |
| 263 | return d; |
| 264 | |
| 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]); |
| 267 | return d; |
| 268 | } |
| 269 | |
| 270 | |
| 271 | static void pcmcia_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) |
| 272 | { |
| 273 | caddr_t win_base = (caddr_t)map->map_priv_2; |
| 274 | |
| 275 | if(DEV_REMOVED(map)) |
| 276 | return; |
| 277 | |
| 278 | DEBUG(3, "to = %p from = %lu len = %u", to, from, len); |
| 279 | memcpy_fromio(to, win_base + from, len); |
| 280 | } |
| 281 | |
| 282 | |
| 283 | static void pcmcia_write8(struct map_info *map, u8 d, unsigned long adr) |
| 284 | { |
| 285 | caddr_t win_base = (caddr_t)map->map_priv_2; |
| 286 | |
| 287 | if(DEV_REMOVED(map)) |
| 288 | return; |
| 289 | |
| 290 | DEBUG(3, "adr = 0x%08lx (%p) data = 0x%02x", adr, win_base + adr, d); |
| 291 | writeb(d, win_base + adr); |
| 292 | } |
| 293 | |
| 294 | |
| 295 | static void pcmcia_write16(struct map_info *map, u16 d, unsigned long adr) |
| 296 | { |
| 297 | caddr_t win_base = (caddr_t)map->map_priv_2; |
| 298 | |
| 299 | if(DEV_REMOVED(map)) |
| 300 | return; |
| 301 | |
| 302 | DEBUG(3, "adr = 0x%08lx (%p) data = 0x%04x", adr, win_base + adr, d); |
| 303 | writew(d, win_base + adr); |
| 304 | } |
| 305 | |
| 306 | |
| 307 | static void pcmcia_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len) |
| 308 | { |
| 309 | caddr_t win_base = (caddr_t)map->map_priv_2; |
| 310 | |
| 311 | if(DEV_REMOVED(map)) |
| 312 | return; |
| 313 | |
| 314 | DEBUG(3, "to = %lu from = %p len = %u", to, from, len); |
| 315 | memcpy_toio(win_base + to, from, len); |
| 316 | } |
| 317 | |
| 318 | |
| 319 | static void pcmciamtd_set_vpp(struct map_info *map, int on) |
| 320 | { |
| 321 | struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 322 | struct pcmcia_device *link = dev->p_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | modconf_t mod; |
| 324 | int ret; |
| 325 | |
| 326 | mod.Attributes = CONF_VPP1_CHANGE_VALID | CONF_VPP2_CHANGE_VALID; |
| 327 | mod.Vcc = 0; |
| 328 | mod.Vpp1 = mod.Vpp2 = on ? dev->vpp : 0; |
| 329 | |
| 330 | DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp); |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 331 | ret = pcmcia_modify_configuration(link, &mod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | if(ret != CS_SUCCESS) { |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 333 | cs_error(link, ModifyConfiguration, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
| 337 | |
| 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. |
| 341 | */ |
| 342 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 343 | static void pcmciamtd_release(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | { |
| 345 | struct pcmciamtd_dev *dev = link->priv; |
| 346 | |
| 347 | DEBUG(3, "link = 0x%p", link); |
| 348 | |
| 349 | if (link->win) { |
| 350 | if(dev->win_base) { |
| 351 | iounmap(dev->win_base); |
| 352 | dev->win_base = NULL; |
| 353 | } |
| 354 | pcmcia_release_window(link->win); |
| 355 | } |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 356 | pcmcia_disable_device(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 360 | static void card_settings(struct pcmciamtd_dev *dev, struct pcmcia_device *link, int *new_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | { |
| 362 | int rc; |
| 363 | tuple_t tuple; |
| 364 | cisparse_t parse; |
| 365 | u_char buf[64]; |
| 366 | |
| 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; |
| 372 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 373 | rc = pcmcia_get_first_tuple(link, &tuple); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | while(rc == CS_SUCCESS) { |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 375 | rc = pcmcia_get_tuple_data(link, &tuple); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | if(rc != CS_SUCCESS) { |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 377 | cs_error(link, GetTupleData, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | break; |
| 379 | } |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 380 | rc = pcmcia_parse_tuple(link, &tuple, &parse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | if(rc != CS_SUCCESS) { |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 382 | cs_error(link, ParseTuple, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | break; |
| 384 | } |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
| 392 | break; |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | case CISTPL_DEVICE: { |
| 397 | cistpl_device_t *t = &parse.device; |
| 398 | int i; |
| 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); |
| 406 | } |
| 407 | break; |
| 408 | } |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | case CISTPL_VERS_1: { |
| 411 | cistpl_vers_1_t *t = &parse.version_1; |
| 412 | int i; |
| 413 | if(t->ns) { |
| 414 | dev->mtd_name[0] = '\0'; |
| 415 | for(i = 0; i < t->ns; i++) { |
| 416 | if(i) |
| 417 | strcat(dev->mtd_name, " "); |
| 418 | strcat(dev->mtd_name, t->str+t->ofs[i]); |
| 419 | } |
| 420 | } |
| 421 | DEBUG(2, "Found name: %s", dev->mtd_name); |
| 422 | break; |
| 423 | } |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | case CISTPL_JEDEC_C: { |
| 426 | cistpl_jedec_t *t = &parse.jedec; |
| 427 | int i; |
| 428 | for(i = 0; i < t->nid; i++) { |
| 429 | DEBUG(2, "JEDEC: 0x%02x 0x%02x", t->id[i].mfr, t->id[i].info); |
| 430 | } |
| 431 | break; |
| 432 | } |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 433 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | case CISTPL_DEVICE_GEO: { |
| 435 | cistpl_device_geo_t *t = &parse.device_geo; |
| 436 | int i; |
| 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); |
| 445 | } |
| 446 | break; |
| 447 | } |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | default: |
| 450 | DEBUG(2, "Unknown tuple code %d", tuple.TupleCode); |
| 451 | } |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 452 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 453 | rc = pcmcia_get_next_tuple(link, &tuple); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | if(!dev->pcmcia_map.size) |
| 456 | dev->pcmcia_map.size = MAX_PCMCIA_ADDR; |
| 457 | |
| 458 | if(!dev->pcmcia_map.bankwidth) |
| 459 | dev->pcmcia_map.bankwidth = 2; |
| 460 | |
| 461 | if(force_size) { |
| 462 | dev->pcmcia_map.size = force_size << 20; |
| 463 | DEBUG(2, "size forced to %dM", force_size); |
| 464 | } |
| 465 | |
| 466 | if(bankwidth) { |
| 467 | dev->pcmcia_map.bankwidth = bankwidth; |
| 468 | DEBUG(2, "bankwidth forced to %d", bankwidth); |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 469 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
| 471 | dev->pcmcia_map.name = dev->mtd_name; |
| 472 | if(!dev->mtd_name[0]) { |
| 473 | strcpy(dev->mtd_name, "PCMCIA Memory card"); |
| 474 | *new_name = 1; |
| 475 | } |
| 476 | |
| 477 | DEBUG(1, "Device: Size: %lu Width:%d Name: %s", |
| 478 | dev->pcmcia_map.size, dev->pcmcia_map.bankwidth << 3, dev->mtd_name); |
| 479 | } |
| 480 | |
| 481 | |
| 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. |
| 485 | */ |
| 486 | |
| 487 | #define CS_CHECK(fn, ret) \ |
| 488 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) |
| 489 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 490 | static int pcmciamtd_config(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | { |
| 492 | struct pcmciamtd_dev *dev = link->priv; |
| 493 | struct mtd_info *mtd = NULL; |
| 494 | cs_status_t status; |
| 495 | win_req_t req; |
| 496 | int last_ret = 0, last_fn = 0; |
| 497 | int ret; |
| 498 | int i; |
| 499 | config_info_t t; |
| 500 | static char *probes[] = { "jedec_probe", "cfi_probe" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | int new_name = 0; |
| 502 | |
| 503 | DEBUG(3, "link=0x%p", link); |
| 504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | DEBUG(2, "Validating CIS"); |
Dominik Brodowski | c5081d5 | 2008-06-19 20:12:34 +0200 | [diff] [blame] | 506 | ret = pcmcia_validate_cis(link, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | if(ret != CS_SUCCESS) { |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 508 | cs_error(link, GetTupleData, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | card_settings(dev, link, &new_name); |
| 512 | |
| 513 | dev->pcmcia_map.phys = NO_XIP; |
| 514 | dev->pcmcia_map.copy_from = pcmcia_copy_from_remap; |
| 515 | dev->pcmcia_map.copy_to = pcmcia_copy_to_remap; |
| 516 | if (dev->pcmcia_map.bankwidth == 1) { |
| 517 | dev->pcmcia_map.read = pcmcia_read8_remap; |
| 518 | dev->pcmcia_map.write = pcmcia_write8_remap; |
| 519 | } else { |
| 520 | dev->pcmcia_map.read = pcmcia_read16_remap; |
| 521 | dev->pcmcia_map.write = pcmcia_write16_remap; |
| 522 | } |
| 523 | if(setvpp == 1) |
| 524 | dev->pcmcia_map.set_vpp = pcmciamtd_set_vpp; |
| 525 | |
| 526 | /* Request a memory window for PCMCIA. Some architeures can map windows upto the maximum |
| 527 | that PCMCIA can support (64MiB) - this is ideal and we aim for a window the size of the |
| 528 | whole card - otherwise we try smaller windows until we succeed */ |
| 529 | |
| 530 | req.Attributes = WIN_MEMORY_TYPE_CM | WIN_ENABLE; |
| 531 | req.Attributes |= (dev->pcmcia_map.bankwidth == 1) ? WIN_DATA_WIDTH_8 : WIN_DATA_WIDTH_16; |
| 532 | req.Base = 0; |
| 533 | req.AccessSpeed = mem_speed; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 534 | link->win = (window_handle_t)link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | req.Size = (force_size) ? force_size << 20 : MAX_PCMCIA_ADDR; |
| 536 | dev->win_size = 0; |
| 537 | |
| 538 | do { |
| 539 | int ret; |
| 540 | DEBUG(2, "requesting window with size = %dKiB memspeed = %d", |
| 541 | req.Size >> 10, req.AccessSpeed); |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 542 | ret = pcmcia_request_window(&link, &req, &link->win); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | DEBUG(2, "ret = %d dev->win_size = %d", ret, dev->win_size); |
| 544 | if(ret) { |
| 545 | req.Size >>= 1; |
| 546 | } else { |
| 547 | DEBUG(2, "Got window of size %dKiB", req.Size >> 10); |
| 548 | dev->win_size = req.Size; |
| 549 | break; |
| 550 | } |
| 551 | } while(req.Size >= 0x1000); |
| 552 | |
| 553 | DEBUG(2, "dev->win_size = %d", dev->win_size); |
| 554 | |
| 555 | if(!dev->win_size) { |
| 556 | err("Cant allocate memory window"); |
| 557 | pcmciamtd_release(link); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 558 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | } |
| 560 | DEBUG(1, "Allocated a window of %dKiB", dev->win_size >> 10); |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | /* Get write protect status */ |
Dominik Brodowski | 4aeba01 | 2008-06-20 13:24:31 +0200 | [diff] [blame^] | 563 | DEBUG(2, "window handle = 0x%8.8lx", (unsigned long)link->win); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | dev->win_base = ioremap(req.Base, req.Size); |
| 565 | if(!dev->win_base) { |
| 566 | err("ioremap(%lu, %u) failed", req.Base, req.Size); |
| 567 | pcmciamtd_release(link); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 568 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | } |
| 570 | DEBUG(1, "mapped window dev = %p req.base = 0x%lx base = %p size = 0x%x", |
| 571 | dev, req.Base, dev->win_base, req.Size); |
| 572 | |
| 573 | dev->offset = 0; |
| 574 | dev->pcmcia_map.map_priv_1 = (unsigned long)dev; |
| 575 | dev->pcmcia_map.map_priv_2 = (unsigned long)link->win; |
| 576 | |
| 577 | DEBUG(2, "Getting configuration"); |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 578 | CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | DEBUG(2, "Vcc = %d Vpp1 = %d Vpp2 = %d", t.Vcc, t.Vpp1, t.Vpp2); |
| 580 | dev->vpp = (vpp) ? vpp : t.Vpp1; |
| 581 | link->conf.Attributes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | if(setvpp == 2) { |
Dominik Brodowski | 70294b4 | 2006-01-15 12:43:16 +0100 | [diff] [blame] | 583 | link->conf.Vpp = dev->vpp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | } else { |
Dominik Brodowski | 70294b4 | 2006-01-15 12:43:16 +0100 | [diff] [blame] | 585 | link->conf.Vpp = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | link->conf.IntType = INT_MEMORY; |
| 589 | link->conf.ConfigBase = t.ConfigBase; |
| 590 | link->conf.Status = t.Status; |
| 591 | link->conf.Pin = t.Pin; |
| 592 | link->conf.Copy = t.Copy; |
| 593 | link->conf.ExtStatus = t.ExtStatus; |
| 594 | link->conf.ConfigIndex = 0; |
| 595 | link->conf.Present = t.Present; |
| 596 | DEBUG(2, "Setting Configuration"); |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 597 | ret = pcmcia_request_configuration(link, &link->conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | if(ret != CS_SUCCESS) { |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 599 | cs_error(link, RequestConfiguration, ret); |
Amol Lad | 25f0c65 | 2006-09-21 18:12:43 +0530 | [diff] [blame] | 600 | if (dev->win_base) { |
| 601 | iounmap(dev->win_base); |
| 602 | dev->win_base = NULL; |
| 603 | } |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 604 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | if(mem_type == 1) { |
| 608 | mtd = do_map_probe("map_ram", &dev->pcmcia_map); |
| 609 | } else if(mem_type == 2) { |
| 610 | mtd = do_map_probe("map_rom", &dev->pcmcia_map); |
| 611 | } else { |
Tobias Klauser | 87d10f3 | 2006-03-31 02:29:45 -0800 | [diff] [blame] | 612 | for(i = 0; i < ARRAY_SIZE(probes); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | DEBUG(1, "Trying %s", probes[i]); |
| 614 | mtd = do_map_probe(probes[i], &dev->pcmcia_map); |
| 615 | if(mtd) |
| 616 | break; |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | DEBUG(1, "FAILED: %s", probes[i]); |
| 619 | } |
| 620 | } |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | if(!mtd) { |
| 623 | DEBUG(1, "Cant find an MTD"); |
| 624 | pcmciamtd_release(link); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 625 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | dev->mtd_info = mtd; |
| 629 | mtd->owner = THIS_MODULE; |
| 630 | |
| 631 | if(new_name) { |
| 632 | int size = 0; |
| 633 | char unit = ' '; |
| 634 | /* Since we are using a default name, make it better by adding in the |
| 635 | size */ |
| 636 | if(mtd->size < 1048576) { /* <1MiB in size, show size in KiB */ |
| 637 | size = mtd->size >> 10; |
| 638 | unit = 'K'; |
| 639 | } else { |
| 640 | size = mtd->size >> 20; |
| 641 | unit = 'M'; |
| 642 | } |
| 643 | snprintf(dev->mtd_name, sizeof(dev->mtd_name), "%d%ciB %s", size, unit, "PCMCIA Memory card"); |
| 644 | } |
| 645 | |
| 646 | /* If the memory found is fits completely into the mapped PCMCIA window, |
| 647 | use the faster non-remapping read/write functions */ |
| 648 | if(mtd->size <= dev->win_size) { |
| 649 | DEBUG(1, "Using non remapping memory functions"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | dev->pcmcia_map.map_priv_2 = (unsigned long)dev->win_base; |
| 651 | if (dev->pcmcia_map.bankwidth == 1) { |
| 652 | dev->pcmcia_map.read = pcmcia_read8; |
| 653 | dev->pcmcia_map.write = pcmcia_write8; |
| 654 | } else { |
| 655 | dev->pcmcia_map.read = pcmcia_read16; |
| 656 | dev->pcmcia_map.write = pcmcia_write16; |
| 657 | } |
| 658 | dev->pcmcia_map.copy_from = pcmcia_copy_from; |
| 659 | dev->pcmcia_map.copy_to = pcmcia_copy_to; |
| 660 | } |
| 661 | |
| 662 | if(add_mtd_device(mtd)) { |
| 663 | map_destroy(mtd); |
| 664 | dev->mtd_info = NULL; |
| 665 | err("Couldnt register MTD device"); |
| 666 | pcmciamtd_release(link); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 667 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } |
| 669 | snprintf(dev->node.dev_name, sizeof(dev->node.dev_name), "mtd%d", mtd->index); |
| 670 | info("mtd%d: %s", mtd->index, mtd->name); |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 671 | link->dev_node = &dev->node; |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 672 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
| 674 | cs_failed: |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 675 | cs_error(link, last_fn, last_ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | err("CS Error, exiting"); |
| 677 | pcmciamtd_release(link); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 678 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 682 | static int pcmciamtd_suspend(struct pcmcia_device *dev) |
| 683 | { |
| 684 | DEBUG(2, "EVENT_PM_RESUME"); |
| 685 | |
| 686 | /* get_lock(link); */ |
| 687 | |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | static int pcmciamtd_resume(struct pcmcia_device *dev) |
| 692 | { |
| 693 | DEBUG(2, "EVENT_PM_SUSPEND"); |
| 694 | |
| 695 | /* free_lock(link); */ |
| 696 | |
| 697 | return 0; |
| 698 | } |
| 699 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
| 701 | /* This deletes a driver "instance". The device is de-registered |
| 702 | * with Card Services. If it has been released, all local data |
| 703 | * structures are freed. Otherwise, the structures will be freed |
| 704 | * when the device is released. |
| 705 | */ |
| 706 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 707 | static void pcmciamtd_detach(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | { |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 709 | struct pcmciamtd_dev *dev = link->priv; |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 710 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | DEBUG(3, "link=0x%p", link); |
| 712 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 713 | if(dev->mtd_info) { |
| 714 | del_mtd_device(dev->mtd_info); |
Sean Young | 599fb32 | 2006-05-17 11:47:48 +0100 | [diff] [blame] | 715 | map_destroy(dev->mtd_info); |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 716 | info("mtd%d: Removed", dev->mtd_info->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 718 | |
| 719 | pcmciamtd_release(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | |
| 723 | /* pcmciamtd_attach() creates an "instance" of the driver, allocating |
| 724 | * local data structures for one device. The device is registered |
| 725 | * with Card Services. |
| 726 | */ |
| 727 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 728 | static int pcmciamtd_probe(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | { |
| 730 | struct pcmciamtd_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
| 732 | /* Create new memory card device */ |
Burman Yan | 95b93a0 | 2006-11-15 21:10:29 +0200 | [diff] [blame] | 733 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 734 | if (!dev) return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | DEBUG(1, "dev=0x%p", dev); |
| 736 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 737 | dev->p_dev = link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | link->priv = dev; |
| 739 | |
| 740 | link->conf.Attributes = 0; |
| 741 | link->conf.IntType = INT_MEMORY; |
| 742 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 743 | return pcmciamtd_config(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Dominik Brodowski | 11d28a3 | 2005-06-27 16:28:32 -0700 | [diff] [blame] | 746 | static struct pcmcia_device_id pcmciamtd_ids[] = { |
| 747 | PCMCIA_DEVICE_FUNC_ID(1), |
| 748 | PCMCIA_DEVICE_PROD_ID123("IO DATA", "PCS-2M", "2MB SRAM", 0x547e66dc, 0x1fed36cd, 0x36eadd21), |
| 749 | PCMCIA_DEVICE_PROD_ID12("IBM", "2MB SRAM", 0xb569a6e5, 0x36eadd21), |
| 750 | PCMCIA_DEVICE_PROD_ID12("IBM", "4MB FLASH", 0xb569a6e5, 0x8bc54d2a), |
| 751 | PCMCIA_DEVICE_PROD_ID12("IBM", "8MB FLASH", 0xb569a6e5, 0x6df1be3e), |
| 752 | PCMCIA_DEVICE_PROD_ID12("Intel", "S2E20SW", 0x816cc815, 0xd14c9dcf), |
| 753 | PCMCIA_DEVICE_PROD_ID12("Intel", "S2E8 SW", 0x816cc815, 0xa2d7dedb), |
| 754 | PCMCIA_DEVICE_PROD_ID12("intel", "SERIES2-02 ", 0x40ade711, 0x145cea5c), |
| 755 | PCMCIA_DEVICE_PROD_ID12("intel", "SERIES2-04 ", 0x40ade711, 0x42064dda), |
| 756 | PCMCIA_DEVICE_PROD_ID12("intel", "SERIES2-20 ", 0x40ade711, 0x25ee5cb0), |
| 757 | PCMCIA_DEVICE_PROD_ID12("intel", "VALUE SERIES 100 ", 0x40ade711, 0xdf8506d8), |
| 758 | PCMCIA_DEVICE_PROD_ID12("KINGMAX TECHNOLOGY INC.", "SRAM 256K Bytes", 0x54d0c69c, 0xad12c29c), |
| 759 | PCMCIA_DEVICE_PROD_ID12("Maxtor", "MAXFL MobileMax Flash Memory Card", 0xb68968c8, 0x2dfb47b0), |
| 760 | PCMCIA_DEVICE_PROD_ID12("SEIKO EPSON", "WWB101EN20", 0xf9876baf, 0xad0b207b), |
| 761 | PCMCIA_DEVICE_PROD_ID12("SEIKO EPSON", "WWB513EN20", 0xf9876baf, 0xe8d884ad), |
| 762 | PCMCIA_DEVICE_PROD_ID12("Starfish, Inc.", "REX-3000", 0x05ddca47, 0xe7d67bca), |
| 763 | PCMCIA_DEVICE_PROD_ID12("Starfish, Inc.", "REX-4100", 0x05ddca47, 0x7bc32944), |
| 764 | /* the following was commented out in pcmcia-cs-3.2.7 */ |
| 765 | /* PCMCIA_DEVICE_PROD_ID12("RATOC Systems,Inc.", "SmartMedia ADAPTER PC Card", 0xf4a2fefe, 0x5885b2ae), */ |
| 766 | #ifdef CONFIG_MTD_PCMCIA_ANONYMOUS |
| 767 | { .match_flags = PCMCIA_DEV_ID_MATCH_ANONYMOUS, }, |
| 768 | #endif |
| 769 | PCMCIA_DEVICE_NULL |
| 770 | }; |
| 771 | MODULE_DEVICE_TABLE(pcmcia, pcmciamtd_ids); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
| 773 | static struct pcmcia_driver pcmciamtd_driver = { |
| 774 | .drv = { |
| 775 | .name = "pcmciamtd" |
| 776 | }, |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 777 | .probe = pcmciamtd_probe, |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 778 | .remove = pcmciamtd_detach, |
Dominik Brodowski | 11d28a3 | 2005-06-27 16:28:32 -0700 | [diff] [blame] | 779 | .owner = THIS_MODULE, |
| 780 | .id_table = pcmciamtd_ids, |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 781 | .suspend = pcmciamtd_suspend, |
| 782 | .resume = pcmciamtd_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | }; |
| 784 | |
| 785 | |
| 786 | static int __init init_pcmciamtd(void) |
| 787 | { |
| 788 | info(DRIVER_DESC " " DRIVER_VERSION); |
| 789 | |
| 790 | if(bankwidth && bankwidth != 1 && bankwidth != 2) { |
| 791 | info("bad bankwidth (%d), using default", bankwidth); |
| 792 | bankwidth = 2; |
| 793 | } |
| 794 | if(force_size && (force_size < 1 || force_size > 64)) { |
| 795 | info("bad force_size (%d), using default", force_size); |
| 796 | force_size = 0; |
| 797 | } |
| 798 | if(mem_type && mem_type != 1 && mem_type != 2) { |
| 799 | info("bad mem_type (%d), using default", mem_type); |
| 800 | mem_type = 0; |
| 801 | } |
| 802 | return pcmcia_register_driver(&pcmciamtd_driver); |
| 803 | } |
| 804 | |
| 805 | |
| 806 | static void __exit exit_pcmciamtd(void) |
| 807 | { |
| 808 | DEBUG(1, DRIVER_DESC " unloading"); |
| 809 | pcmcia_unregister_driver(&pcmciamtd_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | module_init(init_pcmciamtd); |
| 813 | module_exit(exit_pcmciamtd); |