pata_ninja32.c 5.2 KB

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