delkin_cb.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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/ide.h>
  22. #include <linux/init.h>
  23. #include <linux/pci.h>
  24. #include <asm/io.h>
  25. /*
  26. * No chip documentation has yet been found,
  27. * so these configuration values were pulled from
  28. * a running Win98 system using "debug".
  29. * This gives around 3MByte/second read performance,
  30. * which is about 2/3 of what the chip is capable of.
  31. *
  32. * There is also a 4KByte mmio region on the card,
  33. * but its purpose has yet to be reverse-engineered.
  34. */
  35. static const u8 setup[] = {
  36. 0x00, 0x05, 0xbe, 0x01, 0x20, 0x8f, 0x00, 0x00,
  37. 0xa4, 0x1f, 0xb3, 0x1b, 0x00, 0x00, 0x00, 0x80,
  38. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39. 0x00, 0x00, 0x00, 0x00, 0xa4, 0x83, 0x02, 0x13,
  40. };
  41. static const struct ide_port_ops delkin_cb_port_ops = {
  42. .quirkproc = ide_undecoded_slave,
  43. };
  44. static int delkin_cb_init_chipset(struct pci_dev *dev)
  45. {
  46. unsigned long base = pci_resource_start(dev, 0);
  47. int i;
  48. outb(0x02, base + 0x1e); /* set nIEN to block interrupts */
  49. inb(base + 0x17); /* read status to clear interrupts */
  50. for (i = 0; i < sizeof(setup); ++i) {
  51. if (setup[i])
  52. outb(setup[i], base + i);
  53. }
  54. return 0;
  55. }
  56. static const struct ide_port_info delkin_cb_port_info = {
  57. .port_ops = &delkin_cb_port_ops,
  58. .host_flags = IDE_HFLAG_IO_32BIT | IDE_HFLAG_UNMASK_IRQS |
  59. IDE_HFLAG_NO_DMA,
  60. .irq_flags = IRQF_SHARED,
  61. .init_chipset = delkin_cb_init_chipset,
  62. .chipset = ide_pci,
  63. };
  64. static int delkin_cb_probe(struct pci_dev *dev, const struct pci_device_id *id)
  65. {
  66. struct ide_host *host;
  67. unsigned long base;
  68. int rc;
  69. struct ide_hw hw, *hws[] = { &hw };
  70. rc = pci_enable_device(dev);
  71. if (rc) {
  72. printk(KERN_ERR "delkin_cb: pci_enable_device failed (%d)\n", rc);
  73. return rc;
  74. }
  75. rc = pci_request_regions(dev, "delkin_cb");
  76. if (rc) {
  77. printk(KERN_ERR "delkin_cb: pci_request_regions failed (%d)\n", rc);
  78. pci_disable_device(dev);
  79. return rc;
  80. }
  81. base = pci_resource_start(dev, 0);
  82. delkin_cb_init_chipset(dev);
  83. memset(&hw, 0, sizeof(hw));
  84. ide_std_init_ports(&hw, base + 0x10, base + 0x1e);
  85. hw.irq = dev->irq;
  86. hw.dev = &dev->dev;
  87. rc = ide_host_add(&delkin_cb_port_info, hws, 1, &host);
  88. if (rc)
  89. goto out_disable;
  90. pci_set_drvdata(dev, host);
  91. return 0;
  92. out_disable:
  93. pci_release_regions(dev);
  94. pci_disable_device(dev);
  95. return rc;
  96. }
  97. static void
  98. delkin_cb_remove (struct pci_dev *dev)
  99. {
  100. struct ide_host *host = pci_get_drvdata(dev);
  101. ide_host_remove(host);
  102. pci_release_regions(dev);
  103. pci_disable_device(dev);
  104. }
  105. #ifdef CONFIG_PM
  106. static int delkin_cb_suspend(struct pci_dev *dev, pm_message_t state)
  107. {
  108. pci_save_state(dev);
  109. pci_disable_device(dev);
  110. pci_set_power_state(dev, pci_choose_state(dev, state));
  111. return 0;
  112. }
  113. static int delkin_cb_resume(struct pci_dev *dev)
  114. {
  115. struct ide_host *host = pci_get_drvdata(dev);
  116. int rc;
  117. pci_set_power_state(dev, PCI_D0);
  118. rc = pci_enable_device(dev);
  119. if (rc)
  120. return rc;
  121. pci_restore_state(dev);
  122. pci_set_master(dev);
  123. if (host->init_chipset)
  124. host->init_chipset(dev);
  125. return 0;
  126. }
  127. #else
  128. #define delkin_cb_suspend NULL
  129. #define delkin_cb_resume NULL
  130. #endif
  131. static struct pci_device_id delkin_cb_pci_tbl[] = {
  132. { 0x1145, 0xf021, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  133. { 0x1145, 0xf024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  134. { 0, },
  135. };
  136. MODULE_DEVICE_TABLE(pci, delkin_cb_pci_tbl);
  137. static struct pci_driver delkin_cb_pci_driver = {
  138. .name = "Delkin-ASKA-Workbit Cardbus IDE",
  139. .id_table = delkin_cb_pci_tbl,
  140. .probe = delkin_cb_probe,
  141. .remove = delkin_cb_remove,
  142. .suspend = delkin_cb_suspend,
  143. .resume = delkin_cb_resume,
  144. };
  145. module_pci_driver(delkin_cb_pci_driver);
  146. MODULE_AUTHOR("Mark Lord");
  147. MODULE_DESCRIPTION("Basic support for Delkin/ASKA/Workbit Cardbus IDE");
  148. MODULE_LICENSE("GPL");