pata_isapnp.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * pata-isapnp.c - ISA PnP PATA controller driver.
  3. * Copyright 2005/2006 Red Hat Inc <alan@redhat.com>, all rights reserved.
  4. *
  5. * Based in part on ide-pnp.c by Andrey Panin <pazke@donpac.ru>
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/isapnp.h>
  10. #include <linux/init.h>
  11. #include <linux/blkdev.h>
  12. #include <linux/delay.h>
  13. #include <scsi/scsi_host.h>
  14. #include <linux/ata.h>
  15. #include <linux/libata.h>
  16. #define DRV_NAME "pata_isapnp"
  17. #define DRV_VERSION "0.2.0"
  18. static struct scsi_host_template isapnp_sht = {
  19. .module = THIS_MODULE,
  20. .name = DRV_NAME,
  21. .ioctl = ata_scsi_ioctl,
  22. .queuecommand = ata_scsi_queuecmd,
  23. .can_queue = ATA_DEF_QUEUE,
  24. .this_id = ATA_SHT_THIS_ID,
  25. .sg_tablesize = LIBATA_MAX_PRD,
  26. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  27. .emulated = ATA_SHT_EMULATED,
  28. .use_clustering = ATA_SHT_USE_CLUSTERING,
  29. .proc_name = DRV_NAME,
  30. .dma_boundary = ATA_DMA_BOUNDARY,
  31. .slave_configure = ata_scsi_slave_config,
  32. .slave_destroy = ata_scsi_slave_destroy,
  33. .bios_param = ata_std_bios_param,
  34. };
  35. static struct ata_port_operations isapnp_port_ops = {
  36. .port_disable = ata_port_disable,
  37. .tf_load = ata_tf_load,
  38. .tf_read = ata_tf_read,
  39. .check_status = ata_check_status,
  40. .exec_command = ata_exec_command,
  41. .dev_select = ata_std_dev_select,
  42. .freeze = ata_bmdma_freeze,
  43. .thaw = ata_bmdma_thaw,
  44. .error_handler = ata_bmdma_error_handler,
  45. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  46. .cable_detect = ata_cable_40wire,
  47. .qc_prep = ata_qc_prep,
  48. .qc_issue = ata_qc_issue_prot,
  49. .data_xfer = ata_data_xfer,
  50. .irq_clear = ata_bmdma_irq_clear,
  51. .irq_on = ata_irq_on,
  52. .irq_ack = ata_irq_ack,
  53. .port_start = ata_port_start,
  54. };
  55. /**
  56. * isapnp_init_one - attach an isapnp interface
  57. * @idev: PnP device
  58. * @dev_id: matching detect line
  59. *
  60. * Register an ISA bus IDE interface. Such interfaces are PIO 0 and
  61. * non shared IRQ.
  62. */
  63. static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id)
  64. {
  65. struct ata_host *host;
  66. struct ata_port *ap;
  67. void __iomem *cmd_addr, *ctl_addr;
  68. int rc;
  69. if (pnp_port_valid(idev, 0) == 0)
  70. return -ENODEV;
  71. /* FIXME: Should selected polled PIO here not fail */
  72. if (pnp_irq_valid(idev, 0) == 0)
  73. return -ENODEV;
  74. /* allocate host */
  75. host = ata_host_alloc(&idev->dev, 1);
  76. if (!host)
  77. return -ENOMEM;
  78. /* acquire resources and fill host */
  79. cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8);
  80. if (!cmd_addr)
  81. return -ENOMEM;
  82. ap = host->ports[0];
  83. ap->ops = &isapnp_port_ops;
  84. ap->pio_mask = 1;
  85. ap->flags |= ATA_FLAG_SLAVE_POSS;
  86. ap->ioaddr.cmd_addr = cmd_addr;
  87. if (pnp_port_valid(idev, 1) == 0) {
  88. ctl_addr = devm_ioport_map(&idev->dev,
  89. pnp_port_start(idev, 1), 1);
  90. ap->ioaddr.altstatus_addr = ctl_addr;
  91. ap->ioaddr.ctl_addr = ctl_addr;
  92. }
  93. ata_std_ports(&ap->ioaddr);
  94. /* activate */
  95. return ata_host_activate(host, pnp_irq(idev, 0), ata_interrupt, 0,
  96. &isapnp_sht);
  97. }
  98. /**
  99. * isapnp_remove_one - unplug an isapnp interface
  100. * @idev: PnP device
  101. *
  102. * Remove a previously configured PnP ATA port. Called only on module
  103. * unload events as the core does not currently deal with ISAPnP docking.
  104. */
  105. static void isapnp_remove_one(struct pnp_dev *idev)
  106. {
  107. struct device *dev = &idev->dev;
  108. struct ata_host *host = dev_get_drvdata(dev);
  109. ata_host_detach(host);
  110. }
  111. static struct pnp_device_id isapnp_devices[] = {
  112. /* Generic ESDI/IDE/ATA compatible hard disk controller */
  113. {.id = "PNP0600", .driver_data = 0},
  114. {.id = ""}
  115. };
  116. static struct pnp_driver isapnp_driver = {
  117. .name = DRV_NAME,
  118. .id_table = isapnp_devices,
  119. .probe = isapnp_init_one,
  120. .remove = isapnp_remove_one,
  121. };
  122. static int __init isapnp_init(void)
  123. {
  124. return pnp_register_driver(&isapnp_driver);
  125. }
  126. static void __exit isapnp_exit(void)
  127. {
  128. pnp_unregister_driver(&isapnp_driver);
  129. }
  130. MODULE_AUTHOR("Alan Cox");
  131. MODULE_DESCRIPTION("low-level driver for ISA PnP ATA");
  132. MODULE_LICENSE("GPL");
  133. MODULE_VERSION(DRV_VERSION);
  134. module_init(isapnp_init);
  135. module_exit(isapnp_exit);