pata_isapnp.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.1.5"
  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. .qc_prep = ata_qc_prep,
  47. .qc_issue = ata_qc_issue_prot,
  48. .data_xfer = ata_data_xfer,
  49. .irq_handler = ata_interrupt,
  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_probe_ent ae;
  66. void __iomem *cmd_addr, *ctl_addr;
  67. if (pnp_port_valid(idev, 0) == 0)
  68. return -ENODEV;
  69. /* FIXME: Should selected polled PIO here not fail */
  70. if (pnp_irq_valid(idev, 0) == 0)
  71. return -ENODEV;
  72. cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8);
  73. if (!cmd_addr)
  74. return -ENOMEM;
  75. memset(&ae, 0, sizeof(struct ata_probe_ent));
  76. INIT_LIST_HEAD(&ae.node);
  77. ae.dev = &idev->dev;
  78. ae.port_ops = &isapnp_port_ops;
  79. ae.sht = &isapnp_sht;
  80. ae.n_ports = 1;
  81. ae.pio_mask = 1; /* ISA so PIO 0 cycles */
  82. ae.irq = pnp_irq(idev, 0);
  83. ae.irq_flags = 0;
  84. ae.port_flags = ATA_FLAG_SLAVE_POSS;
  85. ae.port[0].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. ae.port[0].altstatus_addr = ctl_addr;
  90. ae.port[0].ctl_addr = ctl_addr;
  91. ae.port_flags |= ATA_FLAG_SRST;
  92. }
  93. ata_std_ports(&ae.port[0]);
  94. if (ata_device_add(&ae) == 0)
  95. return -ENODEV;
  96. return 0;
  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. dev_set_drvdata(dev, NULL);
  111. }
  112. static struct pnp_device_id isapnp_devices[] = {
  113. /* Generic ESDI/IDE/ATA compatible hard disk controller */
  114. {.id = "PNP0600", .driver_data = 0},
  115. {.id = ""}
  116. };
  117. static struct pnp_driver isapnp_driver = {
  118. .name = DRV_NAME,
  119. .id_table = isapnp_devices,
  120. .probe = isapnp_init_one,
  121. .remove = isapnp_remove_one,
  122. };
  123. static int __init isapnp_init(void)
  124. {
  125. return pnp_register_driver(&isapnp_driver);
  126. }
  127. static void __exit isapnp_exit(void)
  128. {
  129. pnp_unregister_driver(&isapnp_driver);
  130. }
  131. MODULE_AUTHOR("Alan Cox");
  132. MODULE_DESCRIPTION("low-level driver for ISA PnP ATA");
  133. MODULE_LICENSE("GPL");
  134. MODULE_VERSION(DRV_VERSION);
  135. module_init(isapnp_init);
  136. module_exit(isapnp_exit);