pata_isapnp.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.1"
  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. if (pnp_port_valid(idev, 0) == 0)
  69. return -ENODEV;
  70. /* FIXME: Should selected polled PIO here not fail */
  71. if (pnp_irq_valid(idev, 0) == 0)
  72. return -ENODEV;
  73. /* allocate host */
  74. host = ata_host_alloc(&idev->dev, 1);
  75. if (!host)
  76. return -ENOMEM;
  77. /* acquire resources and fill host */
  78. cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8);
  79. if (!cmd_addr)
  80. return -ENOMEM;
  81. ap = host->ports[0];
  82. ap->ops = &isapnp_port_ops;
  83. ap->pio_mask = 1;
  84. ap->flags |= ATA_FLAG_SLAVE_POSS;
  85. ap->ioaddr.cmd_addr = cmd_addr;
  86. if (pnp_port_valid(idev, 1) == 0) {
  87. ctl_addr = devm_ioport_map(&idev->dev,
  88. pnp_port_start(idev, 1), 1);
  89. ap->ioaddr.altstatus_addr = ctl_addr;
  90. ap->ioaddr.ctl_addr = ctl_addr;
  91. }
  92. ata_std_ports(&ap->ioaddr);
  93. /* activate */
  94. return ata_host_activate(host, pnp_irq(idev, 0), ata_interrupt, 0,
  95. &isapnp_sht);
  96. }
  97. /**
  98. * isapnp_remove_one - unplug an isapnp interface
  99. * @idev: PnP device
  100. *
  101. * Remove a previously configured PnP ATA port. Called only on module
  102. * unload events as the core does not currently deal with ISAPnP docking.
  103. */
  104. static void isapnp_remove_one(struct pnp_dev *idev)
  105. {
  106. struct device *dev = &idev->dev;
  107. struct ata_host *host = dev_get_drvdata(dev);
  108. ata_host_detach(host);
  109. }
  110. static struct pnp_device_id isapnp_devices[] = {
  111. /* Generic ESDI/IDE/ATA compatible hard disk controller */
  112. {.id = "PNP0600", .driver_data = 0},
  113. {.id = ""}
  114. };
  115. static struct pnp_driver isapnp_driver = {
  116. .name = DRV_NAME,
  117. .id_table = isapnp_devices,
  118. .probe = isapnp_init_one,
  119. .remove = isapnp_remove_one,
  120. };
  121. static int __init isapnp_init(void)
  122. {
  123. return pnp_register_driver(&isapnp_driver);
  124. }
  125. static void __exit isapnp_exit(void)
  126. {
  127. pnp_unregister_driver(&isapnp_driver);
  128. }
  129. MODULE_AUTHOR("Alan Cox");
  130. MODULE_DESCRIPTION("low-level driver for ISA PnP ATA");
  131. MODULE_LICENSE("GPL");
  132. MODULE_VERSION(DRV_VERSION);
  133. module_init(isapnp_init);
  134. module_exit(isapnp_exit);