pata_piccolo.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * pata_piccolo.c - Toshiba Piccolo PATA/SATA controller driver.
  3. *
  4. * This is basically an update to ata_generic.c to add Toshiba Piccolo support
  5. * then split out to keep ata_generic "clean".
  6. *
  7. * Copyright 2005 Red Hat Inc, all rights reserved.
  8. *
  9. * Elements from ide/pci/generic.c
  10. * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
  11. * Portions (C) Copyright 2002 Red Hat Inc <alan@redhat.com>
  12. *
  13. * May be copied or modified under the terms of the GNU General Public License
  14. *
  15. * The timing data tables/programming info are courtesy of the NetBSD driver
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/pci.h>
  20. #include <linux/init.h>
  21. #include <linux/blkdev.h>
  22. #include <linux/delay.h>
  23. #include <scsi/scsi_host.h>
  24. #include <linux/libata.h>
  25. #define DRV_NAME "pata_piccolo"
  26. #define DRV_VERSION "0.0.1"
  27. static void tosh_set_piomode(struct ata_port *ap, struct ata_device *adev)
  28. {
  29. static const u16 pio[6] = { /* For reg 0x50 low word & E088 */
  30. 0x0566, 0x0433, 0x0311, 0x0201, 0x0200, 0x0100
  31. };
  32. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  33. u16 conf;
  34. pci_read_config_word(pdev, 0x50, &conf);
  35. conf &= 0xE088;
  36. conf |= pio[adev->pio_mode - XFER_PIO_0];
  37. pci_write_config_word(pdev, 0x50, conf);
  38. }
  39. static void tosh_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  40. {
  41. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  42. u32 conf;
  43. pci_read_config_dword(pdev, 0x5C, &conf);
  44. conf &= 0x78FFE088; /* Keep the other bits */
  45. if (adev->dma_mode >= XFER_UDMA_0) {
  46. int udma = adev->dma_mode - XFER_UDMA_0;
  47. conf |= 0x80000000;
  48. conf |= (udma + 2) << 28;
  49. conf |= (2 - udma) * 0x111; /* spread into three nibbles */
  50. } else {
  51. static const u32 mwdma[4] = {
  52. 0x0655, 0x0200, 0x0200, 0x0100
  53. };
  54. conf |= mwdma[adev->dma_mode - XFER_MW_DMA_0];
  55. }
  56. pci_write_config_dword(pdev, 0x5C, conf);
  57. }
  58. static struct scsi_host_template tosh_sht = {
  59. ATA_BMDMA_SHT(DRV_NAME),
  60. };
  61. static struct ata_port_operations tosh_port_ops = {
  62. .inherits = &ata_bmdma_port_ops,
  63. .cable_detect = ata_cable_unknown,
  64. .set_piomode = tosh_set_piomode,
  65. .set_dmamode = tosh_set_dmamode
  66. };
  67. /**
  68. * ata_tosh_init - attach generic IDE
  69. * @dev: PCI device found
  70. * @id: match entry
  71. *
  72. * Called each time a matching IDE interface is found. We check if the
  73. * interface is one we wish to claim and if so we perform any chip
  74. * specific hacks then let the ATA layer do the heavy lifting.
  75. */
  76. static int ata_tosh_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  77. {
  78. static const struct ata_port_info info = {
  79. .flags = ATA_FLAG_SLAVE_POSS,
  80. .pio_mask = ATA_PIO5,
  81. .mwdma_mask = ATA_MWDMA2,
  82. .udma_mask = ATA_UDMA2,
  83. .port_ops = &tosh_port_ops
  84. };
  85. const struct ata_port_info *ppi[] = { &info, &ata_dummy_port_info };
  86. /* Just one port for the moment */
  87. return ata_pci_bmdma_init_one(dev, ppi, &tosh_sht, NULL, 0);
  88. }
  89. static struct pci_device_id ata_tosh[] = {
  90. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1), },
  91. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2), },
  92. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_3), },
  93. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_5), },
  94. { 0, },
  95. };
  96. static struct pci_driver ata_tosh_pci_driver = {
  97. .name = DRV_NAME,
  98. .id_table = ata_tosh,
  99. .probe = ata_tosh_init_one,
  100. .remove = ata_pci_remove_one,
  101. #ifdef CONFIG_PM
  102. .suspend = ata_pci_device_suspend,
  103. .resume = ata_pci_device_resume,
  104. #endif
  105. };
  106. static int __init ata_tosh_init(void)
  107. {
  108. return pci_register_driver(&ata_tosh_pci_driver);
  109. }
  110. static void __exit ata_tosh_exit(void)
  111. {
  112. pci_unregister_driver(&ata_tosh_pci_driver);
  113. }
  114. MODULE_AUTHOR("Alan Cox");
  115. MODULE_DESCRIPTION("Low level driver for Toshiba Piccolo ATA");
  116. MODULE_LICENSE("GPL");
  117. MODULE_DEVICE_TABLE(pci, ata_tosh);
  118. MODULE_VERSION(DRV_VERSION);
  119. module_init(ata_tosh_init);
  120. module_exit(ata_tosh_exit);