pcmciamtd.c 20 KB

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