delkin_cb.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Created 20 Oct 2004 by Mark Lord
  3. *
  4. * Basic support for Delkin/ASKA/Workbit Cardbus CompactFlash adapter
  5. *
  6. * Modeled after the 16-bit PCMCIA driver: ide-cs.c
  7. *
  8. * This is slightly peculiar, in that it is a PCI driver,
  9. * but is NOT an IDE PCI driver -- the IDE layer does not directly
  10. * support hot insertion/removal of PCI interfaces, so this driver
  11. * is unable to use the IDE PCI interfaces. Instead, it uses the
  12. * same interfaces as the ide-cs (PCMCIA) driver uses.
  13. * On the plus side, the driver is also smaller/simpler this way.
  14. *
  15. * This file is subject to the terms and conditions of the GNU General Public
  16. * License. See the file COPYING in the main directory of this archive for
  17. * more details.
  18. */
  19. #include <linux/types.h>
  20. #include <linux/module.h>
  21. #include <linux/hdreg.h>
  22. #include <linux/ide.h>
  23. #include <linux/init.h>
  24. #include <linux/pci.h>
  25. #include <asm/io.h>
  26. /*
  27. * No chip documentation has yet been found,
  28. * so these configuration values were pulled from
  29. * a running Win98 system using "debug".
  30. * This gives around 3MByte/second read performance,
  31. * which is about 2/3 of what the chip is capable of.
  32. *
  33. * There is also a 4KByte mmio region on the card,
  34. * but its purpose has yet to be reverse-engineered.
  35. */
  36. static const u8 setup[] = {
  37. 0x00, 0x05, 0xbe, 0x01, 0x20, 0x8f, 0x00, 0x00,
  38. 0xa4, 0x1f, 0xb3, 0x1b, 0x00, 0x00, 0x00, 0x80,
  39. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40. 0x00, 0x00, 0x00, 0x00, 0xa4, 0x83, 0x02, 0x13,
  41. };
  42. static const struct ide_port_ops delkin_cb_port_ops = {
  43. .quirkproc = ide_undecoded_slave,
  44. };
  45. static const struct ide_port_info delkin_cb_port_info = {
  46. .port_ops = &delkin_cb_port_ops,
  47. .host_flags = IDE_HFLAG_IO_32BIT | IDE_HFLAG_UNMASK_IRQS |
  48. IDE_HFLAG_NO_DMA,
  49. };
  50. static int __devinit
  51. delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
  52. {
  53. unsigned long base;
  54. hw_regs_t hw;
  55. ide_hwif_t *hwif = NULL;
  56. int i, rc;
  57. u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
  58. rc = pci_enable_device(dev);
  59. if (rc) {
  60. printk(KERN_ERR "delkin_cb: pci_enable_device failed (%d)\n", rc);
  61. return rc;
  62. }
  63. rc = pci_request_regions(dev, "delkin_cb");
  64. if (rc) {
  65. printk(KERN_ERR "delkin_cb: pci_request_regions failed (%d)\n", rc);
  66. pci_disable_device(dev);
  67. return rc;
  68. }
  69. base = pci_resource_start(dev, 0);
  70. outb(0x02, base + 0x1e); /* set nIEN to block interrupts */
  71. inb(base + 0x17); /* read status to clear interrupts */
  72. for (i = 0; i < sizeof(setup); ++i) {
  73. if (setup[i])
  74. outb(setup[i], base + i);
  75. }
  76. memset(&hw, 0, sizeof(hw));
  77. ide_std_init_ports(&hw, base + 0x10, base + 0x1e);
  78. hw.irq = dev->irq;
  79. hw.dev = &dev->dev;
  80. hw.chipset = ide_pci; /* this enables IRQ sharing */
  81. hwif = ide_find_port();
  82. if (hwif == NULL)
  83. goto out_disable;
  84. i = hwif->index;
  85. ide_init_port_hw(hwif, &hw);
  86. idx[0] = i;
  87. ide_device_add(idx, &delkin_cb_port_info);
  88. pci_set_drvdata(dev, hwif);
  89. return 0;
  90. out_disable:
  91. pci_release_regions(dev);
  92. pci_disable_device(dev);
  93. return -ENODEV;
  94. }
  95. static void
  96. delkin_cb_remove (struct pci_dev *dev)
  97. {
  98. ide_hwif_t *hwif = pci_get_drvdata(dev);
  99. ide_unregister(hwif);
  100. pci_release_regions(dev);
  101. pci_disable_device(dev);
  102. }
  103. static struct pci_device_id delkin_cb_pci_tbl[] __devinitdata = {
  104. { 0x1145, 0xf021, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  105. { 0x1145, 0xf024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  106. { 0, },
  107. };
  108. MODULE_DEVICE_TABLE(pci, delkin_cb_pci_tbl);
  109. static struct pci_driver driver = {
  110. .name = "Delkin-ASKA-Workbit Cardbus IDE",
  111. .id_table = delkin_cb_pci_tbl,
  112. .probe = delkin_cb_probe,
  113. .remove = delkin_cb_remove,
  114. };
  115. static int __init delkin_cb_init(void)
  116. {
  117. return pci_register_driver(&driver);
  118. }
  119. static void __exit delkin_cb_exit(void)
  120. {
  121. pci_unregister_driver(&driver);
  122. }
  123. module_init(delkin_cb_init);
  124. module_exit(delkin_cb_exit);
  125. MODULE_AUTHOR("Mark Lord");
  126. MODULE_DESCRIPTION("Basic support for Delkin/ASKA/Workbit Cardbus IDE");
  127. MODULE_LICENSE("GPL");