delkin_cb.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 int __devinit
  43. delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
  44. {
  45. unsigned long base;
  46. hw_regs_t hw;
  47. ide_hwif_t *hwif = NULL;
  48. ide_drive_t *drive;
  49. int i, rc;
  50. u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
  51. rc = pci_enable_device(dev);
  52. if (rc) {
  53. printk(KERN_ERR "delkin_cb: pci_enable_device failed (%d)\n", rc);
  54. return rc;
  55. }
  56. rc = pci_request_regions(dev, "delkin_cb");
  57. if (rc) {
  58. printk(KERN_ERR "delkin_cb: pci_request_regions failed (%d)\n", rc);
  59. pci_disable_device(dev);
  60. return rc;
  61. }
  62. base = pci_resource_start(dev, 0);
  63. outb(0x02, base + 0x1e); /* set nIEN to block interrupts */
  64. inb(base + 0x17); /* read status to clear interrupts */
  65. for (i = 0; i < sizeof(setup); ++i) {
  66. if (setup[i])
  67. outb(setup[i], base + i);
  68. }
  69. memset(&hw, 0, sizeof(hw));
  70. ide_std_init_ports(&hw, base + 0x10, base + 0x1e);
  71. hw.irq = dev->irq;
  72. hw.chipset = ide_pci; /* this enables IRQ sharing */
  73. hwif = ide_find_port();
  74. if (hwif == NULL)
  75. goto out_disable;
  76. i = hwif->index;
  77. if (hwif->present)
  78. ide_unregister(i);
  79. else
  80. ide_init_port_data(hwif, i);
  81. ide_init_port_hw(hwif, &hw);
  82. hwif->mmio = 1;
  83. hwif->quirkproc = &ide_undecoded_slave;
  84. idx[0] = i;
  85. ide_device_add(idx, NULL);
  86. if (!hwif->present)
  87. goto out_disable;
  88. pci_set_drvdata(dev, hwif);
  89. hwif->dev = &dev->dev;
  90. drive = &hwif->drives[0];
  91. if (drive->present) {
  92. drive->io_32bit = 1;
  93. drive->unmask = 1;
  94. }
  95. return 0;
  96. out_disable:
  97. printk(KERN_ERR "delkin_cb: no IDE devices found\n");
  98. pci_release_regions(dev);
  99. pci_disable_device(dev);
  100. return -ENODEV;
  101. }
  102. static void
  103. delkin_cb_remove (struct pci_dev *dev)
  104. {
  105. ide_hwif_t *hwif = pci_get_drvdata(dev);
  106. if (hwif)
  107. ide_unregister(hwif->index);
  108. pci_release_regions(dev);
  109. pci_disable_device(dev);
  110. }
  111. static struct pci_device_id delkin_cb_pci_tbl[] __devinitdata = {
  112. { 0x1145, 0xf021, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  113. { 0x1145, 0xf024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  114. { 0, },
  115. };
  116. MODULE_DEVICE_TABLE(pci, delkin_cb_pci_tbl);
  117. static struct pci_driver driver = {
  118. .name = "Delkin-ASKA-Workbit Cardbus IDE",
  119. .id_table = delkin_cb_pci_tbl,
  120. .probe = delkin_cb_probe,
  121. .remove = delkin_cb_remove,
  122. };
  123. static int
  124. delkin_cb_init (void)
  125. {
  126. return pci_register_driver(&driver);
  127. }
  128. static void
  129. delkin_cb_exit (void)
  130. {
  131. pci_unregister_driver(&driver);
  132. }
  133. module_init(delkin_cb_init);
  134. module_exit(delkin_cb_exit);
  135. MODULE_AUTHOR("Mark Lord");
  136. MODULE_DESCRIPTION("Basic support for Delkin/ASKA/Workbit Cardbus IDE");
  137. MODULE_LICENSE("GPL");