pata_ninja32.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 + 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.0.1"
  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_std_dev_select(ap, device);
  69. ninja32_set_piomode(ap, adev);
  70. }
  71. }
  72. static struct scsi_host_template ninja32_sht = {
  73. .module = THIS_MODULE,
  74. .name = DRV_NAME,
  75. .ioctl = ata_scsi_ioctl,
  76. .queuecommand = ata_scsi_queuecmd,
  77. .can_queue = ATA_DEF_QUEUE,
  78. .this_id = ATA_SHT_THIS_ID,
  79. .sg_tablesize = LIBATA_MAX_PRD,
  80. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  81. .emulated = ATA_SHT_EMULATED,
  82. .use_clustering = ATA_SHT_USE_CLUSTERING,
  83. .proc_name = DRV_NAME,
  84. .dma_boundary = ATA_DMA_BOUNDARY,
  85. .slave_configure = ata_scsi_slave_config,
  86. .slave_destroy = ata_scsi_slave_destroy,
  87. .bios_param = ata_std_bios_param,
  88. };
  89. static struct ata_port_operations ninja32_port_ops = {
  90. .set_piomode = ninja32_set_piomode,
  91. .mode_filter = ata_pci_default_filter,
  92. .tf_load = ata_tf_load,
  93. .tf_read = ata_tf_read,
  94. .check_status = ata_check_status,
  95. .exec_command = ata_exec_command,
  96. .dev_select = ninja32_dev_select,
  97. .freeze = ata_bmdma_freeze,
  98. .thaw = ata_bmdma_thaw,
  99. .error_handler = ata_bmdma_error_handler,
  100. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  101. .cable_detect = ata_cable_40wire,
  102. .bmdma_setup = ata_bmdma_setup,
  103. .bmdma_start = ata_bmdma_start,
  104. .bmdma_stop = ata_bmdma_stop,
  105. .bmdma_status = ata_bmdma_status,
  106. .qc_prep = ata_qc_prep,
  107. .qc_issue = ata_qc_issue_prot,
  108. .data_xfer = ata_data_xfer,
  109. .irq_handler = ata_interrupt,
  110. .irq_clear = ata_bmdma_irq_clear,
  111. .irq_on = ata_irq_on,
  112. .port_start = ata_sff_port_start,
  113. };
  114. static int ninja32_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  115. {
  116. struct ata_host *host;
  117. struct ata_port *ap;
  118. void __iomem *base;
  119. int rc;
  120. host = ata_host_alloc(&dev->dev, 1);
  121. if (!host)
  122. return -ENOMEM;
  123. ap = host->ports[0];
  124. /* Set up the PCI device */
  125. rc = pcim_enable_device(dev);
  126. if (rc)
  127. return rc;
  128. rc = pcim_iomap_regions(dev, 1 << 0, DRV_NAME);
  129. if (rc == -EBUSY)
  130. pcim_pin_device(dev);
  131. if (rc)
  132. return rc;
  133. host->iomap = pcim_iomap_table(dev);
  134. rc = pci_set_dma_mask(dev, ATA_DMA_MASK);
  135. if (rc)
  136. return rc;
  137. rc = pci_set_consistent_dma_mask(dev, ATA_DMA_MASK);
  138. if (rc)
  139. return rc;
  140. pci_set_master(dev);
  141. /* Set up the register mappings */
  142. base = host->iomap[0];
  143. if (!base)
  144. return -ENOMEM;
  145. ap->ops = &ninja32_port_ops;
  146. ap->pio_mask = 0x1F;
  147. ap->flags |= ATA_FLAG_SLAVE_POSS;
  148. ap->ioaddr.cmd_addr = base + 0x10;
  149. ap->ioaddr.ctl_addr = base + 0x1E;
  150. ap->ioaddr.altstatus_addr = base + 0x1E;
  151. ap->ioaddr.bmdma_addr = base;
  152. ata_std_ports(&ap->ioaddr);
  153. iowrite8(0x05, base + 0x01); /* Enable interrupt lines */
  154. iowrite8(0xB3, base + 0x02); /* Burst, ?? setup */
  155. iowrite8(0x00, base + 0x04); /* WAIT0 ? */
  156. /* FIXME: Should we disable them at remove ? */
  157. return ata_host_activate(host, dev->irq, ata_interrupt,
  158. IRQF_SHARED, &ninja32_sht);
  159. }
  160. static const struct pci_device_id ninja32[] = {
  161. { 0x1145, 0xf021, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  162. { 0x1145, 0xf024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  163. { },
  164. };
  165. static struct pci_driver ninja32_pci_driver = {
  166. .name = DRV_NAME,
  167. .id_table = ninja32,
  168. .probe = ninja32_init_one,
  169. .remove = ata_pci_remove_one
  170. };
  171. static int __init ninja32_init(void)
  172. {
  173. return pci_register_driver(&ninja32_pci_driver);
  174. }
  175. static void __exit ninja32_exit(void)
  176. {
  177. pci_unregister_driver(&ninja32_pci_driver);
  178. }
  179. MODULE_AUTHOR("Alan Cox");
  180. MODULE_DESCRIPTION("low-level driver for Ninja32 ATA");
  181. MODULE_LICENSE("GPL");
  182. MODULE_DEVICE_TABLE(pci, ninja32);
  183. MODULE_VERSION(DRV_VERSION);
  184. module_init(ninja32_init);
  185. module_exit(ninja32_exit);