pata_ninja32.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * pata_ninja32.c - Ninja32 PATA for new ATA layer
  3. * (C) 2007 Red Hat Inc
  4. *
  5. * Note: The controller like many controllers has shared timings for
  6. * PIO and DMA. We thus flip to the DMA timings in dma_start and flip back
  7. * in the dma_stop function. Thus we actually don't need a set_dmamode
  8. * method as the PIO method is always called and will set the right PIO
  9. * timing parameters.
  10. *
  11. * The Ninja32 Cardbus is not a generic SFF controller. Instead it is
  12. * laid out as follows off BAR 0. This is based upon Mark Lord's delkin
  13. * driver and the extensive analysis done by the BSD developers, notably
  14. * ITOH Yasufumi.
  15. *
  16. * Base + 0x00 IRQ Status
  17. * Base + 0x01 IRQ control
  18. * Base + 0x02 Chipset control
  19. * Base + 0x03 Unknown
  20. * Base + 0x04 VDMA and reset control + wait bits
  21. * Base + 0x08 BMIMBA
  22. * Base + 0x0C DMA Length
  23. * Base + 0x10 Taskfile
  24. * Base + 0x18 BMDMA Status ?
  25. * Base + 0x1C
  26. * Base + 0x1D Bus master control
  27. * bit 0 = enable
  28. * bit 1 = 0 write/1 read
  29. * bit 2 = 1 sgtable
  30. * bit 3 = go
  31. * bit 4-6 wait bits
  32. * bit 7 = done
  33. * Base + 0x1E AltStatus
  34. * Base + 0x1F timing register
  35. */
  36. #include <linux/kernel.h>
  37. #include <linux/module.h>
  38. #include <linux/pci.h>
  39. #include <linux/init.h>
  40. #include <linux/blkdev.h>
  41. #include <linux/delay.h>
  42. #include <scsi/scsi_host.h>
  43. #include <linux/libata.h>
  44. #define DRV_NAME "pata_ninja32"
  45. #define DRV_VERSION "0.1.5"
  46. /**
  47. * ninja32_set_piomode - set initial PIO mode data
  48. * @ap: ATA interface
  49. * @adev: ATA device
  50. *
  51. * Called to do the PIO mode setup. Our timing registers are shared
  52. * but we want to set the PIO timing by default.
  53. */
  54. static void ninja32_set_piomode(struct ata_port *ap, struct ata_device *adev)
  55. {
  56. static u16 pio_timing[5] = {
  57. 0xd6, 0x85, 0x44, 0x33, 0x13
  58. };
  59. iowrite8(pio_timing[adev->pio_mode - XFER_PIO_0],
  60. ap->ioaddr.bmdma_addr + 0x1f);
  61. ap->private_data = adev;
  62. }
  63. static void ninja32_dev_select(struct ata_port *ap, unsigned int device)
  64. {
  65. struct ata_device *adev = &ap->link.device[device];
  66. if (ap->private_data != adev) {
  67. iowrite8(0xd6, ap->ioaddr.bmdma_addr + 0x1f);
  68. ata_sff_dev_select(ap, device);
  69. ninja32_set_piomode(ap, adev);
  70. }
  71. }
  72. static struct scsi_host_template ninja32_sht = {
  73. ATA_BMDMA_SHT(DRV_NAME),
  74. };
  75. static struct ata_port_operations ninja32_port_ops = {
  76. .inherits = &ata_bmdma_port_ops,
  77. .sff_dev_select = ninja32_dev_select,
  78. .cable_detect = ata_cable_40wire,
  79. .set_piomode = ninja32_set_piomode,
  80. .sff_data_xfer = ata_sff_data_xfer32
  81. };
  82. static void ninja32_program(void __iomem *base)
  83. {
  84. iowrite8(0x05, base + 0x01); /* Enable interrupt lines */
  85. iowrite8(0xBE, base + 0x02); /* Burst, ?? setup */
  86. iowrite8(0x01, base + 0x03); /* Unknown */
  87. iowrite8(0x20, base + 0x04); /* WAIT0 */
  88. iowrite8(0x8f, base + 0x05); /* Unknown */
  89. iowrite8(0xa4, base + 0x1c); /* Unknown */
  90. iowrite8(0x83, base + 0x1d); /* BMDMA control: WAIT0 */
  91. }
  92. static int ninja32_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  93. {
  94. struct ata_host *host;
  95. struct ata_port *ap;
  96. void __iomem *base;
  97. int rc;
  98. host = ata_host_alloc(&dev->dev, 1);
  99. if (!host)
  100. return -ENOMEM;
  101. ap = host->ports[0];
  102. /* Set up the PCI device */
  103. rc = pcim_enable_device(dev);
  104. if (rc)
  105. return rc;
  106. rc = pcim_iomap_regions(dev, 1 << 0, DRV_NAME);
  107. if (rc == -EBUSY)
  108. pcim_pin_device(dev);
  109. if (rc)
  110. return rc;
  111. host->iomap = pcim_iomap_table(dev);
  112. rc = pci_set_dma_mask(dev, ATA_DMA_MASK);
  113. if (rc)
  114. return rc;
  115. rc = pci_set_consistent_dma_mask(dev, ATA_DMA_MASK);
  116. if (rc)
  117. return rc;
  118. pci_set_master(dev);
  119. /* Set up the register mappings. We use the I/O mapping as only the
  120. older chips also have MMIO on BAR 1 */
  121. base = host->iomap[0];
  122. if (!base)
  123. return -ENOMEM;
  124. ap->ops = &ninja32_port_ops;
  125. ap->pio_mask = ATA_PIO4;
  126. ap->flags |= ATA_FLAG_SLAVE_POSS;
  127. ap->ioaddr.cmd_addr = base + 0x10;
  128. ap->ioaddr.ctl_addr = base + 0x1E;
  129. ap->ioaddr.altstatus_addr = base + 0x1E;
  130. ap->ioaddr.bmdma_addr = base;
  131. ata_sff_std_ports(&ap->ioaddr);
  132. ap->pflags = ATA_PFLAG_PIO32 | ATA_PFLAG_PIO32CHANGE;
  133. ninja32_program(base);
  134. /* FIXME: Should we disable them at remove ? */
  135. return ata_host_activate(host, dev->irq, ata_bmdma_interrupt,
  136. IRQF_SHARED, &ninja32_sht);
  137. }
  138. #ifdef CONFIG_PM
  139. static int ninja32_reinit_one(struct pci_dev *pdev)
  140. {
  141. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  142. int rc;
  143. rc = ata_pci_device_do_resume(pdev);
  144. if (rc)
  145. return rc;
  146. ninja32_program(host->iomap[0]);
  147. ata_host_resume(host);
  148. return 0;
  149. }
  150. #endif
  151. static const struct pci_device_id ninja32[] = {
  152. { 0x10FC, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  153. { 0x1145, 0x8008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  154. { 0x1145, 0xf008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  155. { 0x1145, 0xf021, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  156. { 0x1145, 0xf024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  157. { 0x1145, 0xf02C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  158. { },
  159. };
  160. static struct pci_driver ninja32_pci_driver = {
  161. .name = DRV_NAME,
  162. .id_table = ninja32,
  163. .probe = ninja32_init_one,
  164. .remove = ata_pci_remove_one,
  165. #ifdef CONFIG_PM
  166. .suspend = ata_pci_device_suspend,
  167. .resume = ninja32_reinit_one,
  168. #endif
  169. };
  170. static int __init ninja32_init(void)
  171. {
  172. return pci_register_driver(&ninja32_pci_driver);
  173. }
  174. static void __exit ninja32_exit(void)
  175. {
  176. pci_unregister_driver(&ninja32_pci_driver);
  177. }
  178. MODULE_AUTHOR("Alan Cox");
  179. MODULE_DESCRIPTION("low-level driver for Ninja32 ATA");
  180. MODULE_LICENSE("GPL");
  181. MODULE_DEVICE_TABLE(pci, ninja32);
  182. MODULE_VERSION(DRV_VERSION);
  183. module_init(ninja32_init);
  184. module_exit(ninja32_exit);