ide-cs.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. /*======================================================================
  2. A driver for PCMCIA IDE/ATA disk cards
  3. The contents of this file are subject to the Mozilla Public
  4. License Version 1.1 (the "License"); you may not use this file
  5. except in compliance with the License. You may obtain a copy of
  6. the License at http://www.mozilla.org/MPL/
  7. Software distributed under the License is distributed on an "AS
  8. IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9. implied. See the License for the specific language governing
  10. rights and limitations under the License.
  11. The initial developer of the original code is David A. Hinds
  12. <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
  13. are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
  14. Alternatively, the contents of this file may be used under the
  15. terms of the GNU General Public License version 2 (the "GPL"), in
  16. which case the provisions of the GPL are applicable instead of the
  17. above. If you wish to allow the use of your version of this file
  18. only under the terms of the GPL and not to allow others to use
  19. your version of this file under the MPL, indicate your decision
  20. by deleting the provisions above and replace them with the notice
  21. and other provisions required by the GPL. If you do not delete
  22. the provisions above, a recipient may use your version of this
  23. file under either the MPL or the GPL.
  24. ======================================================================*/
  25. #include <linux/module.h>
  26. #include <linux/kernel.h>
  27. #include <linux/init.h>
  28. #include <linux/ptrace.h>
  29. #include <linux/slab.h>
  30. #include <linux/string.h>
  31. #include <linux/timer.h>
  32. #include <linux/ioport.h>
  33. #include <linux/ide.h>
  34. #include <linux/major.h>
  35. #include <linux/delay.h>
  36. #include <asm/io.h>
  37. #include <asm/system.h>
  38. #include <pcmcia/cistpl.h>
  39. #include <pcmcia/ds.h>
  40. #include <pcmcia/cisreg.h>
  41. #include <pcmcia/ciscode.h>
  42. #define DRV_NAME "ide-cs"
  43. /*====================================================================*/
  44. /* Module parameters */
  45. MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
  46. MODULE_DESCRIPTION("PCMCIA ATA/IDE card driver");
  47. MODULE_LICENSE("Dual MPL/GPL");
  48. /*====================================================================*/
  49. typedef struct ide_info_t {
  50. struct pcmcia_device *p_dev;
  51. struct ide_host *host;
  52. int ndev;
  53. } ide_info_t;
  54. static void ide_release(struct pcmcia_device *);
  55. static int ide_config(struct pcmcia_device *);
  56. static void ide_detach(struct pcmcia_device *p_dev);
  57. /*======================================================================
  58. ide_attach() creates an "instance" of the driver, allocating
  59. local data structures for one device. The device is registered
  60. with Card Services.
  61. ======================================================================*/
  62. static int ide_probe(struct pcmcia_device *link)
  63. {
  64. ide_info_t *info;
  65. dev_dbg(&link->dev, "ide_attach()\n");
  66. /* Create new ide device */
  67. info = kzalloc(sizeof(*info), GFP_KERNEL);
  68. if (!info)
  69. return -ENOMEM;
  70. info->p_dev = link;
  71. link->priv = info;
  72. link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO |
  73. CONF_AUTO_SET_VPP | CONF_AUTO_CHECK_VCC;
  74. return ide_config(link);
  75. } /* ide_attach */
  76. /*======================================================================
  77. This deletes a driver "instance". The device is de-registered
  78. with Card Services. If it has been released, all local data
  79. structures are freed. Otherwise, the structures will be freed
  80. when the device is released.
  81. ======================================================================*/
  82. static void ide_detach(struct pcmcia_device *link)
  83. {
  84. ide_info_t *info = link->priv;
  85. dev_dbg(&link->dev, "ide_detach(0x%p)\n", link);
  86. ide_release(link);
  87. kfree(info);
  88. } /* ide_detach */
  89. static const struct ide_port_ops idecs_port_ops = {
  90. .quirkproc = ide_undecoded_slave,
  91. };
  92. static const struct ide_port_info idecs_port_info = {
  93. .port_ops = &idecs_port_ops,
  94. .host_flags = IDE_HFLAG_NO_DMA,
  95. .irq_flags = IRQF_SHARED,
  96. .chipset = ide_pci,
  97. };
  98. static struct ide_host *idecs_register(unsigned long io, unsigned long ctl,
  99. unsigned long irq, struct pcmcia_device *handle)
  100. {
  101. struct ide_host *host;
  102. ide_hwif_t *hwif;
  103. int i, rc;
  104. struct ide_hw hw, *hws[] = { &hw };
  105. if (!request_region(io, 8, DRV_NAME)) {
  106. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
  107. DRV_NAME, io, io + 7);
  108. return NULL;
  109. }
  110. if (!request_region(ctl, 1, DRV_NAME)) {
  111. printk(KERN_ERR "%s: I/O resource 0x%lX not free.\n",
  112. DRV_NAME, ctl);
  113. release_region(io, 8);
  114. return NULL;
  115. }
  116. memset(&hw, 0, sizeof(hw));
  117. ide_std_init_ports(&hw, io, ctl);
  118. hw.irq = irq;
  119. hw.dev = &handle->dev;
  120. rc = ide_host_add(&idecs_port_info, hws, 1, &host);
  121. if (rc)
  122. goto out_release;
  123. hwif = host->ports[0];
  124. if (hwif->present)
  125. return host;
  126. /* retry registration in case device is still spinning up */
  127. for (i = 0; i < 10; i++) {
  128. msleep(100);
  129. ide_port_scan(hwif);
  130. if (hwif->present)
  131. return host;
  132. }
  133. return host;
  134. out_release:
  135. release_region(ctl, 1);
  136. release_region(io, 8);
  137. return NULL;
  138. }
  139. /*======================================================================
  140. ide_config() is scheduled to run after a CARD_INSERTION event
  141. is received, to configure the PCMCIA socket, and to make the
  142. ide device available to the system.
  143. ======================================================================*/
  144. static int pcmcia_check_one_config(struct pcmcia_device *pdev, void *priv_data)
  145. {
  146. int *is_kme = priv_data;
  147. if (!(pdev->resource[0]->flags & IO_DATA_PATH_WIDTH_8)) {
  148. pdev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
  149. pdev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
  150. }
  151. pdev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
  152. pdev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
  153. if (pdev->resource[1]->end) {
  154. pdev->resource[0]->end = 8;
  155. pdev->resource[1]->end = (*is_kme) ? 2 : 1;
  156. } else {
  157. if (pdev->resource[0]->end < 16)
  158. return -ENODEV;
  159. }
  160. return pcmcia_request_io(pdev);
  161. }
  162. static int ide_config(struct pcmcia_device *link)
  163. {
  164. ide_info_t *info = link->priv;
  165. int ret = 0, is_kme = 0;
  166. unsigned long io_base, ctl_base;
  167. struct ide_host *host;
  168. dev_dbg(&link->dev, "ide_config(0x%p)\n", link);
  169. is_kme = ((link->manf_id == MANFID_KME) &&
  170. ((link->card_id == PRODID_KME_KXLC005_A) ||
  171. (link->card_id == PRODID_KME_KXLC005_B)));
  172. if (pcmcia_loop_config(link, pcmcia_check_one_config, &is_kme)) {
  173. link->config_flags &= ~CONF_AUTO_CHECK_VCC;
  174. if (pcmcia_loop_config(link, pcmcia_check_one_config, &is_kme))
  175. goto failed; /* No suitable config found */
  176. }
  177. io_base = link->resource[0]->start;
  178. if (link->resource[1]->end)
  179. ctl_base = link->resource[1]->start;
  180. else
  181. ctl_base = link->resource[0]->start + 0x0e;
  182. if (!link->irq)
  183. goto failed;
  184. ret = pcmcia_enable_device(link);
  185. if (ret)
  186. goto failed;
  187. /* disable drive interrupts during IDE probe */
  188. outb(0x02, ctl_base);
  189. /* special setup for KXLC005 card */
  190. if (is_kme)
  191. outb(0x81, ctl_base+1);
  192. host = idecs_register(io_base, ctl_base, link->irq, link);
  193. if (host == NULL && resource_size(link->resource[0]) == 0x20) {
  194. outb(0x02, ctl_base + 0x10);
  195. host = idecs_register(io_base + 0x10, ctl_base + 0x10,
  196. link->irq, link);
  197. }
  198. if (host == NULL)
  199. goto failed;
  200. info->ndev = 1;
  201. info->host = host;
  202. dev_info(&link->dev, "ide-cs: hd%c: Vpp = %d.%d\n",
  203. 'a' + host->ports[0]->index * 2,
  204. link->vpp / 10, link->vpp % 10);
  205. return 0;
  206. failed:
  207. ide_release(link);
  208. return -ENODEV;
  209. } /* ide_config */
  210. /*======================================================================
  211. After a card is removed, ide_release() will unregister the net
  212. device, and release the PCMCIA configuration. If the device is
  213. still open, this will be postponed until it is closed.
  214. ======================================================================*/
  215. static void ide_release(struct pcmcia_device *link)
  216. {
  217. ide_info_t *info = link->priv;
  218. struct ide_host *host = info->host;
  219. dev_dbg(&link->dev, "ide_release(0x%p)\n", link);
  220. if (info->ndev) {
  221. ide_hwif_t *hwif = host->ports[0];
  222. unsigned long data_addr, ctl_addr;
  223. data_addr = hwif->io_ports.data_addr;
  224. ctl_addr = hwif->io_ports.ctl_addr;
  225. ide_host_remove(host);
  226. info->ndev = 0;
  227. release_region(ctl_addr, 1);
  228. release_region(data_addr, 8);
  229. }
  230. pcmcia_disable_device(link);
  231. } /* ide_release */
  232. /*======================================================================
  233. The card status event handler. Mostly, this schedules other
  234. stuff to run after an event is received. A CARD_REMOVAL event
  235. also sets some flags to discourage the ide drivers from
  236. talking to the ports.
  237. ======================================================================*/
  238. static struct pcmcia_device_id ide_ids[] = {
  239. PCMCIA_DEVICE_FUNC_ID(4),
  240. PCMCIA_DEVICE_MANF_CARD(0x0000, 0x0000), /* Corsair */
  241. PCMCIA_DEVICE_MANF_CARD(0x0007, 0x0000), /* Hitachi */
  242. PCMCIA_DEVICE_MANF_CARD(0x000a, 0x0000), /* I-O Data CFA */
  243. PCMCIA_DEVICE_MANF_CARD(0x001c, 0x0001), /* Mitsubishi CFA */
  244. PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704),
  245. PCMCIA_DEVICE_MANF_CARD(0x0032, 0x2904),
  246. PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), /* SanDisk CFA */
  247. PCMCIA_DEVICE_MANF_CARD(0x004f, 0x0000), /* Kingston */
  248. PCMCIA_DEVICE_MANF_CARD(0x0097, 0x1620), /* TI emulated */
  249. PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */
  250. PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d),
  251. PCMCIA_DEVICE_MANF_CARD(0x00ce, 0x0000), /* Samsung */
  252. PCMCIA_DEVICE_MANF_CARD(0x0319, 0x0000), /* Hitachi */
  253. PCMCIA_DEVICE_MANF_CARD(0x2080, 0x0001),
  254. PCMCIA_DEVICE_MANF_CARD(0x4e01, 0x0100), /* Viking CFA */
  255. PCMCIA_DEVICE_MANF_CARD(0x4e01, 0x0200), /* Lexar, Viking CFA */
  256. PCMCIA_DEVICE_PROD_ID123("Caravelle", "PSC-IDE ", "PSC000", 0x8c36137c, 0xd0693ab8, 0x2768a9f0),
  257. PCMCIA_DEVICE_PROD_ID123("CDROM", "IDE", "MCD-601p", 0x1b9179ca, 0xede88951, 0x0d902f74),
  258. PCMCIA_DEVICE_PROD_ID123("PCMCIA", "IDE CARD", "F1", 0x281f1c5d, 0x1907960c, 0xf7fde8b9),
  259. PCMCIA_DEVICE_PROD_ID12("ARGOSY", "CD-ROM", 0x78f308dc, 0x66536591),
  260. PCMCIA_DEVICE_PROD_ID12("ARGOSY", "PnPIDE", 0x78f308dc, 0x0c694728),
  261. PCMCIA_DEVICE_PROD_ID12("CNF ", "CD-ROM", 0x46d7db81, 0x66536591),
  262. PCMCIA_DEVICE_PROD_ID12("CNF CD-M", "CD-ROM", 0x7d93b852, 0x66536591),
  263. PCMCIA_DEVICE_PROD_ID12("Creative Technology Ltd.", "PCMCIA CD-ROM Interface Card", 0xff8c8a45, 0xfe8020c4),
  264. PCMCIA_DEVICE_PROD_ID12("Digital Equipment Corporation.", "Digital Mobile Media CD-ROM", 0x17692a66, 0xef1dcbde),
  265. PCMCIA_DEVICE_PROD_ID12("EXP", "CD+GAME", 0x6f58c983, 0x63c13aaf),
  266. PCMCIA_DEVICE_PROD_ID12("EXP ", "CD-ROM", 0x0a5c52fd, 0x66536591),
  267. PCMCIA_DEVICE_PROD_ID12("EXP ", "PnPIDE", 0x0a5c52fd, 0x0c694728),
  268. PCMCIA_DEVICE_PROD_ID12("FREECOM", "PCCARD-IDE", 0x5714cbf7, 0x48e0ab8e),
  269. PCMCIA_DEVICE_PROD_ID12("HITACHI", "FLASH", 0xf4f43949, 0x9eb86aae),
  270. PCMCIA_DEVICE_PROD_ID12("HITACHI", "microdrive", 0xf4f43949, 0xa6d76178),
  271. PCMCIA_DEVICE_PROD_ID12("Hyperstone", "Model1", 0x3d5b9ef5, 0xca6ab420),
  272. PCMCIA_DEVICE_PROD_ID12("IBM", "microdrive", 0xb569a6e5, 0xa6d76178),
  273. PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753),
  274. PCMCIA_DEVICE_PROD_ID12("KINGSTON", "CF CARD 1GB", 0x2e6d1829, 0x55d5bffb),
  275. PCMCIA_DEVICE_PROD_ID12("KINGSTON", "CF CARD 4GB", 0x2e6d1829, 0x531e7d10),
  276. PCMCIA_DEVICE_PROD_ID12("KINGSTON", "CF8GB", 0x2e6d1829, 0xacbe682e),
  277. PCMCIA_DEVICE_PROD_ID12("IO DATA", "CBIDE2 ", 0x547e66dc, 0x8671043b),
  278. PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149),
  279. PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDEII", 0x547e66dc, 0xb3662674),
  280. PCMCIA_DEVICE_PROD_ID12("LOOKMEET", "CBIDE2 ", 0xe37be2b5, 0x8671043b),
  281. PCMCIA_DEVICE_PROD_ID12("M-Systems", "CF300", 0x7ed2ad87, 0x7e9e78ee),
  282. PCMCIA_DEVICE_PROD_ID12("M-Systems", "CF500", 0x7ed2ad87, 0x7a13045c),
  283. PCMCIA_DEVICE_PROD_ID2("NinjaATA-", 0xebe0bd79),
  284. PCMCIA_DEVICE_PROD_ID12("PCMCIA", "CD-ROM", 0x281f1c5d, 0x66536591),
  285. PCMCIA_DEVICE_PROD_ID12("PCMCIA", "PnPIDE", 0x281f1c5d, 0x0c694728),
  286. PCMCIA_DEVICE_PROD_ID12("SHUTTLE TECHNOLOGY LTD.", "PCCARD-IDE/ATAPI Adapter", 0x4a3f0ba0, 0x322560e1),
  287. PCMCIA_DEVICE_PROD_ID12("SEAGATE", "ST1", 0x87c1b330, 0xe1f30883),
  288. PCMCIA_DEVICE_PROD_ID12("SAMSUNG", "04/05/06", 0x43d74cb4, 0x6a22777d),
  289. PCMCIA_DEVICE_PROD_ID12("SMI VENDOR", "SMI PRODUCT", 0x30896c92, 0x703cc5f6),
  290. PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "MK2001MPL", 0xb4585a1a, 0x3489e003),
  291. PCMCIA_DEVICE_PROD_ID1("TRANSCEND 512M ", 0xd0909443),
  292. PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS1GCF45", 0x709b1bf1, 0xf68b6f32),
  293. PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS1GCF80", 0x709b1bf1, 0x2a54d4b1),
  294. PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS2GCF120", 0x709b1bf1, 0x969aa4f2),
  295. PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS4GCF120", 0x709b1bf1, 0xf54a91c8),
  296. PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS4GCF133", 0x709b1bf1, 0x7558f133),
  297. PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS8GCF133", 0x709b1bf1, 0xb2f89b47),
  298. PCMCIA_DEVICE_PROD_ID12("WIT", "IDE16", 0x244e5994, 0x3e232852),
  299. PCMCIA_DEVICE_PROD_ID12("WEIDA", "TWTTI", 0xcc7cf69c, 0x212bb918),
  300. PCMCIA_DEVICE_PROD_ID1("STI Flash", 0xe4a13209),
  301. PCMCIA_DEVICE_PROD_ID12("STI", "Flash 5.0", 0xbf2df18d, 0x8cb57a0e),
  302. PCMCIA_MFC_DEVICE_PROD_ID12(1, "SanDisk", "ConnectPlus", 0x7a954bd9, 0x74be00c6),
  303. PCMCIA_DEVICE_PROD_ID2("Flash Card", 0x5a362506),
  304. PCMCIA_DEVICE_NULL,
  305. };
  306. MODULE_DEVICE_TABLE(pcmcia, ide_ids);
  307. static struct pcmcia_driver ide_cs_driver = {
  308. .owner = THIS_MODULE,
  309. .drv = {
  310. .name = "ide-cs",
  311. },
  312. .probe = ide_probe,
  313. .remove = ide_detach,
  314. .id_table = ide_ids,
  315. };
  316. static int __init init_ide_cs(void)
  317. {
  318. return pcmcia_register_driver(&ide_cs_driver);
  319. }
  320. static void __exit exit_ide_cs(void)
  321. {
  322. pcmcia_unregister_driver(&ide_cs_driver);
  323. }
  324. late_initcall(init_ide_cs);
  325. module_exit(exit_ide_cs);