ide-cs.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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 <pcmcia/cistpl.h>
  38. #include <pcmcia/ds.h>
  39. #include <pcmcia/cisreg.h>
  40. #include <pcmcia/ciscode.h>
  41. #define DRV_NAME "ide-cs"
  42. /*====================================================================*/
  43. /* Module parameters */
  44. MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
  45. MODULE_DESCRIPTION("PCMCIA ATA/IDE card driver");
  46. MODULE_LICENSE("Dual MPL/GPL");
  47. /*====================================================================*/
  48. typedef struct ide_info_t {
  49. struct pcmcia_device *p_dev;
  50. struct ide_host *host;
  51. int ndev;
  52. } ide_info_t;
  53. static void ide_release(struct pcmcia_device *);
  54. static int ide_config(struct pcmcia_device *);
  55. static void ide_detach(struct pcmcia_device *p_dev);
  56. static int ide_probe(struct pcmcia_device *link)
  57. {
  58. ide_info_t *info;
  59. dev_dbg(&link->dev, "ide_attach()\n");
  60. /* Create new ide device */
  61. info = kzalloc(sizeof(*info), GFP_KERNEL);
  62. if (!info)
  63. return -ENOMEM;
  64. info->p_dev = link;
  65. link->priv = info;
  66. link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO |
  67. CONF_AUTO_SET_VPP | CONF_AUTO_CHECK_VCC;
  68. return ide_config(link);
  69. } /* ide_attach */
  70. static void ide_detach(struct pcmcia_device *link)
  71. {
  72. ide_info_t *info = link->priv;
  73. dev_dbg(&link->dev, "ide_detach(0x%p)\n", link);
  74. ide_release(link);
  75. kfree(info);
  76. } /* ide_detach */
  77. static const struct ide_port_ops idecs_port_ops = {
  78. .quirkproc = ide_undecoded_slave,
  79. };
  80. static const struct ide_port_info idecs_port_info = {
  81. .port_ops = &idecs_port_ops,
  82. .host_flags = IDE_HFLAG_NO_DMA,
  83. .irq_flags = IRQF_SHARED,
  84. .chipset = ide_pci,
  85. };
  86. static struct ide_host *idecs_register(unsigned long io, unsigned long ctl,
  87. unsigned long irq, struct pcmcia_device *handle)
  88. {
  89. struct ide_host *host;
  90. ide_hwif_t *hwif;
  91. int i, rc;
  92. struct ide_hw hw, *hws[] = { &hw };
  93. if (!request_region(io, 8, DRV_NAME)) {
  94. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
  95. DRV_NAME, io, io + 7);
  96. return NULL;
  97. }
  98. if (!request_region(ctl, 1, DRV_NAME)) {
  99. printk(KERN_ERR "%s: I/O resource 0x%lX not free.\n",
  100. DRV_NAME, ctl);
  101. release_region(io, 8);
  102. return NULL;
  103. }
  104. memset(&hw, 0, sizeof(hw));
  105. ide_std_init_ports(&hw, io, ctl);
  106. hw.irq = irq;
  107. hw.dev = &handle->dev;
  108. rc = ide_host_add(&idecs_port_info, hws, 1, &host);
  109. if (rc)
  110. goto out_release;
  111. hwif = host->ports[0];
  112. if (hwif->present)
  113. return host;
  114. /* retry registration in case device is still spinning up */
  115. for (i = 0; i < 10; i++) {
  116. msleep(100);
  117. ide_port_scan(hwif);
  118. if (hwif->present)
  119. return host;
  120. }
  121. return host;
  122. out_release:
  123. release_region(ctl, 1);
  124. release_region(io, 8);
  125. return NULL;
  126. }
  127. static int pcmcia_check_one_config(struct pcmcia_device *pdev, void *priv_data)
  128. {
  129. int *is_kme = priv_data;
  130. if ((pdev->resource[0]->flags & IO_DATA_PATH_WIDTH)
  131. != IO_DATA_PATH_WIDTH_8) {
  132. pdev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
  133. pdev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
  134. }
  135. pdev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
  136. pdev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
  137. if (pdev->resource[1]->end) {
  138. pdev->resource[0]->end = 8;
  139. pdev->resource[1]->end = (*is_kme) ? 2 : 1;
  140. } else {
  141. if (pdev->resource[0]->end < 16)
  142. return -ENODEV;
  143. }
  144. return pcmcia_request_io(pdev);
  145. }
  146. static int ide_config(struct pcmcia_device *link)
  147. {
  148. ide_info_t *info = link->priv;
  149. int ret = 0, is_kme = 0;
  150. unsigned long io_base, ctl_base;
  151. struct ide_host *host;
  152. dev_dbg(&link->dev, "ide_config(0x%p)\n", link);
  153. is_kme = ((link->manf_id == MANFID_KME) &&
  154. ((link->card_id == PRODID_KME_KXLC005_A) ||
  155. (link->card_id == PRODID_KME_KXLC005_B)));
  156. if (pcmcia_loop_config(link, pcmcia_check_one_config, &is_kme)) {
  157. link->config_flags &= ~CONF_AUTO_CHECK_VCC;
  158. if (pcmcia_loop_config(link, pcmcia_check_one_config, &is_kme))
  159. goto failed; /* No suitable config found */
  160. }
  161. io_base = link->resource[0]->start;
  162. if (link->resource[1]->end)
  163. ctl_base = link->resource[1]->start;
  164. else
  165. ctl_base = link->resource[0]->start + 0x0e;
  166. if (!link->irq)
  167. goto failed;
  168. ret = pcmcia_enable_device(link);
  169. if (ret)
  170. goto failed;
  171. /* disable drive interrupts during IDE probe */
  172. outb(0x02, ctl_base);
  173. /* special setup for KXLC005 card */
  174. if (is_kme)
  175. outb(0x81, ctl_base+1);
  176. host = idecs_register(io_base, ctl_base, link->irq, link);
  177. if (host == NULL && resource_size(link->resource[0]) == 0x20) {
  178. outb(0x02, ctl_base + 0x10);
  179. host = idecs_register(io_base + 0x10, ctl_base + 0x10,
  180. link->irq, link);
  181. }
  182. if (host == NULL)
  183. goto failed;
  184. info->ndev = 1;
  185. info->host = host;
  186. dev_info(&link->dev, "ide-cs: hd%c: Vpp = %d.%d\n",
  187. 'a' + host->ports[0]->index * 2,
  188. link->vpp / 10, link->vpp % 10);
  189. return 0;
  190. failed:
  191. ide_release(link);
  192. return -ENODEV;
  193. } /* ide_config */
  194. static void ide_release(struct pcmcia_device *link)
  195. {
  196. ide_info_t *info = link->priv;
  197. struct ide_host *host = info->host;
  198. dev_dbg(&link->dev, "ide_release(0x%p)\n", link);
  199. if (info->ndev) {
  200. ide_hwif_t *hwif = host->ports[0];
  201. unsigned long data_addr, ctl_addr;
  202. data_addr = hwif->io_ports.data_addr;
  203. ctl_addr = hwif->io_ports.ctl_addr;
  204. ide_host_remove(host);
  205. info->ndev = 0;
  206. release_region(ctl_addr, 1);
  207. release_region(data_addr, 8);
  208. }
  209. pcmcia_disable_device(link);
  210. } /* ide_release */
  211. static const struct pcmcia_device_id ide_ids[] = {
  212. PCMCIA_DEVICE_FUNC_ID(4),
  213. PCMCIA_DEVICE_MANF_CARD(0x0000, 0x0000), /* Corsair */
  214. PCMCIA_DEVICE_MANF_CARD(0x0007, 0x0000), /* Hitachi */
  215. PCMCIA_DEVICE_MANF_CARD(0x000a, 0x0000), /* I-O Data CFA */
  216. PCMCIA_DEVICE_MANF_CARD(0x001c, 0x0001), /* Mitsubishi CFA */
  217. PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704),
  218. PCMCIA_DEVICE_MANF_CARD(0x0032, 0x2904),
  219. PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), /* SanDisk CFA */
  220. PCMCIA_DEVICE_MANF_CARD(0x004f, 0x0000), /* Kingston */
  221. PCMCIA_DEVICE_MANF_CARD(0x0097, 0x1620), /* TI emulated */
  222. PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */
  223. PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d),
  224. PCMCIA_DEVICE_MANF_CARD(0x00ce, 0x0000), /* Samsung */
  225. PCMCIA_DEVICE_MANF_CARD(0x0319, 0x0000), /* Hitachi */
  226. PCMCIA_DEVICE_MANF_CARD(0x2080, 0x0001),
  227. PCMCIA_DEVICE_MANF_CARD(0x4e01, 0x0100), /* Viking CFA */
  228. PCMCIA_DEVICE_MANF_CARD(0x4e01, 0x0200), /* Lexar, Viking CFA */
  229. PCMCIA_DEVICE_PROD_ID123("Caravelle", "PSC-IDE ", "PSC000", 0x8c36137c, 0xd0693ab8, 0x2768a9f0),
  230. PCMCIA_DEVICE_PROD_ID123("CDROM", "IDE", "MCD-601p", 0x1b9179ca, 0xede88951, 0x0d902f74),
  231. PCMCIA_DEVICE_PROD_ID123("PCMCIA", "IDE CARD", "F1", 0x281f1c5d, 0x1907960c, 0xf7fde8b9),
  232. PCMCIA_DEVICE_PROD_ID12("ARGOSY", "CD-ROM", 0x78f308dc, 0x66536591),
  233. PCMCIA_DEVICE_PROD_ID12("ARGOSY", "PnPIDE", 0x78f308dc, 0x0c694728),
  234. PCMCIA_DEVICE_PROD_ID12("CNF ", "CD-ROM", 0x46d7db81, 0x66536591),
  235. PCMCIA_DEVICE_PROD_ID12("CNF CD-M", "CD-ROM", 0x7d93b852, 0x66536591),
  236. PCMCIA_DEVICE_PROD_ID12("Creative Technology Ltd.", "PCMCIA CD-ROM Interface Card", 0xff8c8a45, 0xfe8020c4),
  237. PCMCIA_DEVICE_PROD_ID12("Digital Equipment Corporation.", "Digital Mobile Media CD-ROM", 0x17692a66, 0xef1dcbde),
  238. PCMCIA_DEVICE_PROD_ID12("EXP", "CD+GAME", 0x6f58c983, 0x63c13aaf),
  239. PCMCIA_DEVICE_PROD_ID12("EXP ", "CD-ROM", 0x0a5c52fd, 0x66536591),
  240. PCMCIA_DEVICE_PROD_ID12("EXP ", "PnPIDE", 0x0a5c52fd, 0x0c694728),
  241. PCMCIA_DEVICE_PROD_ID12("FREECOM", "PCCARD-IDE", 0x5714cbf7, 0x48e0ab8e),
  242. PCMCIA_DEVICE_PROD_ID12("HITACHI", "FLASH", 0xf4f43949, 0x9eb86aae),
  243. PCMCIA_DEVICE_PROD_ID12("HITACHI", "microdrive", 0xf4f43949, 0xa6d76178),
  244. PCMCIA_DEVICE_PROD_ID12("Hyperstone", "Model1", 0x3d5b9ef5, 0xca6ab420),
  245. PCMCIA_DEVICE_PROD_ID12("IBM", "microdrive", 0xb569a6e5, 0xa6d76178),
  246. PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753),
  247. PCMCIA_DEVICE_PROD_ID12("KINGSTON", "CF CARD 1GB", 0x2e6d1829, 0x55d5bffb),
  248. PCMCIA_DEVICE_PROD_ID12("KINGSTON", "CF CARD 4GB", 0x2e6d1829, 0x531e7d10),
  249. PCMCIA_DEVICE_PROD_ID12("KINGSTON", "CF8GB", 0x2e6d1829, 0xacbe682e),
  250. PCMCIA_DEVICE_PROD_ID12("IO DATA", "CBIDE2 ", 0x547e66dc, 0x8671043b),
  251. PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149),
  252. PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDEII", 0x547e66dc, 0xb3662674),
  253. PCMCIA_DEVICE_PROD_ID12("LOOKMEET", "CBIDE2 ", 0xe37be2b5, 0x8671043b),
  254. PCMCIA_DEVICE_PROD_ID12("M-Systems", "CF300", 0x7ed2ad87, 0x7e9e78ee),
  255. PCMCIA_DEVICE_PROD_ID12("M-Systems", "CF500", 0x7ed2ad87, 0x7a13045c),
  256. PCMCIA_DEVICE_PROD_ID2("NinjaATA-", 0xebe0bd79),
  257. PCMCIA_DEVICE_PROD_ID12("PCMCIA", "CD-ROM", 0x281f1c5d, 0x66536591),
  258. PCMCIA_DEVICE_PROD_ID12("PCMCIA", "PnPIDE", 0x281f1c5d, 0x0c694728),
  259. PCMCIA_DEVICE_PROD_ID12("SHUTTLE TECHNOLOGY LTD.", "PCCARD-IDE/ATAPI Adapter", 0x4a3f0ba0, 0x322560e1),
  260. PCMCIA_DEVICE_PROD_ID12("SEAGATE", "ST1", 0x87c1b330, 0xe1f30883),
  261. PCMCIA_DEVICE_PROD_ID12("SAMSUNG", "04/05/06", 0x43d74cb4, 0x6a22777d),
  262. PCMCIA_DEVICE_PROD_ID12("SMI VENDOR", "SMI PRODUCT", 0x30896c92, 0x703cc5f6),
  263. PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "MK2001MPL", 0xb4585a1a, 0x3489e003),
  264. PCMCIA_DEVICE_PROD_ID1("TRANSCEND 512M ", 0xd0909443),
  265. PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS1GCF45", 0x709b1bf1, 0xf68b6f32),
  266. PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS1GCF80", 0x709b1bf1, 0x2a54d4b1),
  267. PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS2GCF120", 0x709b1bf1, 0x969aa4f2),
  268. PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS4GCF120", 0x709b1bf1, 0xf54a91c8),
  269. PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS4GCF133", 0x709b1bf1, 0x7558f133),
  270. PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS8GCF133", 0x709b1bf1, 0xb2f89b47),
  271. PCMCIA_DEVICE_PROD_ID12("WIT", "IDE16", 0x244e5994, 0x3e232852),
  272. PCMCIA_DEVICE_PROD_ID12("WEIDA", "TWTTI", 0xcc7cf69c, 0x212bb918),
  273. PCMCIA_DEVICE_PROD_ID1("STI Flash", 0xe4a13209),
  274. PCMCIA_DEVICE_PROD_ID12("STI", "Flash 5.0", 0xbf2df18d, 0x8cb57a0e),
  275. PCMCIA_MFC_DEVICE_PROD_ID12(1, "SanDisk", "ConnectPlus", 0x7a954bd9, 0x74be00c6),
  276. PCMCIA_DEVICE_PROD_ID2("Flash Card", 0x5a362506),
  277. PCMCIA_DEVICE_NULL,
  278. };
  279. MODULE_DEVICE_TABLE(pcmcia, ide_ids);
  280. static struct pcmcia_driver ide_cs_driver = {
  281. .owner = THIS_MODULE,
  282. .name = "ide-cs",
  283. .probe = ide_probe,
  284. .remove = ide_detach,
  285. .id_table = ide_ids,
  286. };
  287. static int __init init_ide_cs(void)
  288. {
  289. return pcmcia_register_driver(&ide_cs_driver);
  290. }
  291. static void __exit exit_ide_cs(void)
  292. {
  293. pcmcia_unregister_driver(&ide_cs_driver);
  294. }
  295. late_initcall(init_ide_cs);
  296. module_exit(exit_ide_cs);