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