12 #include <linux/module.h>
13 #include <linux/slab.h>
24 #define info(format, arg...) printk(KERN_INFO "pcmciamtd: " format "\n" , ## arg)
26 #define DRIVER_DESC "PCMCIA Flash memory card driver"
29 #define MAX_PCMCIA_ADDR 0x4000000
46 static int bankwidth = 2;
52 static int force_size;
73 MODULE_PARM_DESC(setvpp,
"Set Vpp (0=Never, 1=On writes, 2=Always on, default=0)");
96 if (offset != dev->
offset) {
97 pr_debug(
"Remapping window from 0x%8.8x to 0x%8.8x\n",
113 addr = remap_window(map, ofs);
118 pr_debug(
"ofs = 0x%08lx (%p) data = 0x%02lx\n", ofs, addr, d.
x[0]);
123 static map_word pcmcia_read16_remap(
struct map_info *map,
unsigned long ofs)
128 addr = remap_window(map, ofs);
133 pr_debug(
"ofs = 0x%08lx (%p) data = 0x%04lx\n", ofs, addr, d.
x[0]);
138 static void pcmcia_copy_from_remap(
struct map_info *map,
void *to,
unsigned long from,
ssize_t len)
143 pr_debug(
"to = %p from = %lu len = %zd\n", to, from, len);
151 addr = remap_window(map, from);
155 pr_debug(
"memcpy from %p to %p len = %d\n", addr, to, toread);
164 static void pcmcia_write8_remap(
struct map_info *map,
map_word d,
unsigned long adr)
166 caddr_t addr = remap_window(map, adr);
171 pr_debug(
"adr = 0x%08lx (%p) data = 0x%02lx\n", adr, addr, d.
x[0]);
176 static void pcmcia_write16_remap(
struct map_info *map,
map_word d,
unsigned long adr)
178 caddr_t addr = remap_window(map, adr);
182 pr_debug(
"adr = 0x%08lx (%p) data = 0x%04lx\n", adr, addr, d.
x[0]);
187 static void pcmcia_copy_to_remap(
struct map_info *map,
unsigned long to,
const void *from,
ssize_t len)
192 pr_debug(
"to = %lu from = %p len = %zd\n", to, from, len);
200 addr = remap_window(map, to);
204 pr_debug(
"memcpy from %p to %p len = %d\n", from, addr, towrite);
215 #define DEV_REMOVED(x) (!(pcmcia_dev_present(((struct pcmciamtd_dev *)map->map_priv_1)->p_dev)))
226 pr_debug(
"ofs = 0x%08lx (%p) data = 0x%02lx\n",
241 pr_debug(
"ofs = 0x%08lx (%p) data = 0x%04lx\n",
247 static void pcmcia_copy_from(
struct map_info *map,
void *to,
unsigned long from,
ssize_t len)
254 pr_debug(
"to = %p from = %lu len = %zd\n", to, from, len);
259 static void pcmcia_write8(
struct map_info *map,
map_word d,
unsigned long adr)
266 pr_debug(
"adr = 0x%08lx (%p) data = 0x%02lx\n",
267 adr, win_base + adr, d.
x[0]);
268 writeb(d.
x[0], win_base + adr);
272 static void pcmcia_write16(
struct map_info *map,
map_word d,
unsigned long adr)
279 pr_debug(
"adr = 0x%08lx (%p) data = 0x%04lx\n",
280 adr, win_base + adr, d.
x[0]);
281 writew(d.
x[0], win_base + adr);
285 static void pcmcia_copy_to(
struct map_info *map,
unsigned long to,
const void *from,
ssize_t len)
292 pr_debug(
"to = %lu from = %p len = %zd\n", to, from, len);
298 static int pcmcia_vpp_refcnt;
299 static void pcmciamtd_set_vpp(
struct map_info *map,
int on)
305 pr_debug(
"dev = %p on = %d vpp = %d\n\n", dev, on, dev->
vpp);
308 if (++pcmcia_vpp_refcnt == 1)
311 if (--pcmcia_vpp_refcnt == 0)
314 spin_unlock_irqrestore(&pcmcia_vpp_lock,
flags);
318 static void pcmciamtd_release(
struct pcmcia_device *
link)
324 if (link->resource[2]->end) {
334 static int pcmciamtd_cistpl_format(
struct pcmcia_device *
p_dev,
343 pr_debug(
"Format type: %u, Error Detection: %u, offset = %u, length =%u\n",
349 static int pcmciamtd_cistpl_jedec(
struct pcmcia_device *p_dev,
358 for (i = 0; i < t->
nid; i++)
360 t->
id[i].mfr, t->
id[i].info);
365 static int pcmciamtd_cistpl_device(
struct pcmcia_device *p_dev,
380 for (i = 0; i < t->
ndev; i++) {
381 pr_debug(
"Region %d, type = %u\n", i, t->
dev[i].type);
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);
389 static int pcmciamtd_cistpl_geo(
struct pcmcia_device *p_dev,
403 for (i = 0; i < t->
ngeo; i++) {
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);
415 static void card_settings(
struct pcmciamtd_dev *dev,
struct pcmcia_device *p_dev,
int *new_name)
419 if (p_dev->prod_id[0]) {
421 for (i = 0; i < 4; i++) {
424 if (p_dev->prod_id[i])
432 pcmcia_loop_tuple(p_dev,
CISTPL_DEVICE, pcmciamtd_cistpl_device, dev);
443 pr_debug(
"size forced to %dM\n", force_size);
448 pr_debug(
"bankwidth forced to %d\n", bankwidth);
457 pr_debug(
"Device: Size: %lu Width:%d Name: %s\n",
463 static int pcmciamtd_config(
struct pcmcia_device *link)
469 static char *probes[] = {
"jedec_probe",
"cfi_probe" };
474 card_settings(dev, link, &new_name);
477 dev->
pcmcia_map.copy_from = pcmcia_copy_from_remap;
478 dev->
pcmcia_map.copy_to = pcmcia_copy_to_remap;
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 :
505 pr_debug(
"requesting window with size = %luKiB memspeed = %d\n",
506 (
unsigned long) resource_size(link->resource[2]) >> 10,
512 link->resource[2]->start = 0;
513 link->resource[2]->end = (force_size) ?
515 link->resource[2]->end >>=
j;
517 pr_debug(
"Got window of size %luKiB\n", (
unsigned long)
518 resource_size(link->resource[2]) >> 10);
519 dev->
win_size = resource_size(link->resource[2]);
522 }
while (link->resource[2]->end >= 0x1000);
527 dev_err(&dev->
p_dev->dev,
"Cannot allocate memory window\n");
528 pcmciamtd_release(link);
535 resource_size(link->resource[2]));
539 pcmciamtd_release(link);
542 pr_debug(
"mapped window dev = %p @ %pR, base = %p\n",
543 dev, link->resource[2], dev->
win_base);
549 dev->
vpp = (
vpp) ?
vpp : link->socket->socket.Vpp;
551 link->vpp = dev->
vpp;
556 link->config_index = 0;
557 pr_debug(
"Setting Configuration\n");
578 pr_debug(
"FAILED: %s\n", probes[i]);
584 pcmciamtd_release(link);
597 if(mtd->
size < 1048576) {
598 size = mtd->
size >> 10;
601 size = mtd->
size >> 20;
610 pr_debug(
"Using non remapping memory functions\n");
627 "Could not register the MTD device\n");
628 pcmciamtd_release(link);
636 static int pcmciamtd_suspend(
struct pcmcia_device *dev)
645 static int pcmciamtd_resume(
struct pcmcia_device *dev)
655 static void pcmciamtd_detach(
struct pcmcia_device *link)
668 pcmciamtd_release(link);
672 static int pcmciamtd_probe(
struct pcmcia_device *link)
684 return pcmciamtd_config(link);
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),
701 PCMCIA_DEVICE_PROD_ID123(
"M-Systems",
"M-SYS Flash Memory Card",
"(c) M-Systems", 0x7ed2ad87, 0x675dc3fb, 0x7aef3965),
702 PCMCIA_DEVICE_PROD_ID12(
"PRETEC",
" 2MB SRAM CARD", 0xebf91155, 0x805360ca),
703 PCMCIA_DEVICE_PROD_ID12(
"SEIKO EPSON",
"WWB101EN20", 0xf9876baf, 0xad0b207b),
704 PCMCIA_DEVICE_PROD_ID12(
"SEIKO EPSON",
"WWB513EN20", 0xf9876baf, 0xe8d884ad),
705 PCMCIA_DEVICE_PROD_ID12(
"SMART Modular Technologies",
" 4MB FLASH Card", 0x96fd8277, 0x737a5b05),
706 PCMCIA_DEVICE_PROD_ID12(
"Starfish, Inc.",
"REX-3000", 0x05ddca47, 0xe7d67bca),
707 PCMCIA_DEVICE_PROD_ID12(
"Starfish, Inc.",
"REX-4100", 0x05ddca47, 0x7bc32944),
710 #ifdef CONFIG_MTD_PCMCIA_ANONYMOUS
717 static struct pcmcia_driver pcmciamtd_driver = {
719 .probe = pcmciamtd_probe,
720 .remove = pcmciamtd_detach,
722 .id_table = pcmciamtd_ids,
723 .suspend = pcmciamtd_suspend,
724 .resume = pcmciamtd_resume,
728 static int __init init_pcmciamtd(
void)
730 if(bankwidth && bankwidth != 1 && bankwidth != 2) {
731 info(
"bad bankwidth (%d), using default", bankwidth);
734 if(force_size && (force_size < 1 || force_size > 64)) {
735 info(
"bad force_size (%d), using default", force_size);
746 static void __exit exit_pcmciamtd(
void)