delkin_cb.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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/autoconf.h>
  20. #include <linux/types.h>
  21. #include <linux/module.h>
  22. #include <linux/mm.h>
  23. #include <linux/blkdev.h>
  24. #include <linux/hdreg.h>
  25. #include <linux/ide.h>
  26. #include <linux/init.h>
  27. #include <linux/pci.h>
  28. #include <asm/io.h>
  29. /*
  30. * No chip documentation has yet been found,
  31. * so these configuration values were pulled from
  32. * a running Win98 system using "debug".
  33. * This gives around 3MByte/second read performance,
  34. * which is about 2/3 of what the chip is capable of.
  35. *
  36. * There is also a 4KByte mmio region on the card,
  37. * but its purpose has yet to be reverse-engineered.
  38. */
  39. static const u8 setup[] = {
  40. 0x00, 0x05, 0xbe, 0x01, 0x20, 0x8f, 0x00, 0x00,
  41. 0xa4, 0x1f, 0xb3, 0x1b, 0x00, 0x00, 0x00, 0x80,
  42. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43. 0x00, 0x00, 0x00, 0x00, 0xa4, 0x83, 0x02, 0x13,
  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. rc = pci_enable_device(dev);
  54. if (rc) {
  55. printk(KERN_ERR "delkin_cb: pci_enable_device failed (%d)\n", rc);
  56. return rc;
  57. }
  58. rc = pci_request_regions(dev, "delkin_cb");
  59. if (rc) {
  60. printk(KERN_ERR "delkin_cb: pci_request_regions failed (%d)\n", rc);
  61. pci_disable_device(dev);
  62. return rc;
  63. }
  64. base = pci_resource_start(dev, 0);
  65. outb(0x02, base + 0x1e); /* set nIEN to block interrupts */
  66. inb(base + 0x17); /* read status to clear interrupts */
  67. for (i = 0; i < sizeof(setup); ++i) {
  68. if (setup[i])
  69. outb(setup[i], base + i);
  70. }
  71. pci_release_regions(dev); /* IDE layer handles regions itself */
  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. rc = ide_register_hw(&hw, &ide_undecoded_slave, &hwif);
  77. if (rc < 0) {
  78. printk(KERN_ERR "delkin_cb: ide_register_hw failed (%d)\n", rc);
  79. pci_disable_device(dev);
  80. return -ENODEV;
  81. }
  82. pci_set_drvdata(dev, hwif);
  83. hwif->dev = &dev->dev;
  84. drive = &hwif->drives[0];
  85. if (drive->present) {
  86. drive->io_32bit = 1;
  87. drive->unmask = 1;
  88. }
  89. return 0;
  90. }
  91. static void
  92. delkin_cb_remove (struct pci_dev *dev)
  93. {
  94. ide_hwif_t *hwif = pci_get_drvdata(dev);
  95. if (hwif)
  96. ide_unregister(hwif->index);
  97. pci_disable_device(dev);
  98. }
  99. static struct pci_device_id delkin_cb_pci_tbl[] __devinitdata = {
  100. { 0x1145, 0xf021, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  101. { 0x1145, 0xf024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  102. { 0, },
  103. };
  104. MODULE_DEVICE_TABLE(pci, delkin_cb_pci_tbl);
  105. static struct pci_driver driver = {
  106. .name = "Delkin-ASKA-Workbit Cardbus IDE",
  107. .id_table = delkin_cb_pci_tbl,
  108. .probe = delkin_cb_probe,
  109. .remove = delkin_cb_remove,
  110. };
  111. static int
  112. delkin_cb_init (void)
  113. {
  114. return pci_register_driver(&driver);
  115. }
  116. static void
  117. delkin_cb_exit (void)
  118. {
  119. pci_unregister_driver(&driver);
  120. }
  121. module_init(delkin_cb_init);
  122. module_exit(delkin_cb_exit);
  123. MODULE_AUTHOR("Mark Lord");
  124. MODULE_DESCRIPTION("Basic support for Delkin/ASKA/Workbit Cardbus IDE");
  125. MODULE_LICENSE("GPL");