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