delkin_cb.c 3.9 KB

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