pata_isapnp.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * pata-isapnp.c - ISA PnP PATA controller driver.
  4. * Copyright 2005/2006 Red Hat Inc, all rights reserved.
  5. *
  6. * Based in part on ide-pnp.c by Andrey Panin <[email protected]>
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/isapnp.h>
  11. #include <linux/init.h>
  12. #include <linux/blkdev.h>
  13. #include <linux/delay.h>
  14. #include <scsi/scsi_host.h>
  15. #include <linux/ata.h>
  16. #include <linux/libata.h>
  17. #define DRV_NAME "pata_isapnp"
  18. #define DRV_VERSION "0.2.5"
  19. static struct scsi_host_template isapnp_sht = {
  20. ATA_PIO_SHT(DRV_NAME),
  21. };
  22. static struct ata_port_operations isapnp_port_ops = {
  23. .inherits = &ata_sff_port_ops,
  24. .cable_detect = ata_cable_40wire,
  25. };
  26. static struct ata_port_operations isapnp_noalt_port_ops = {
  27. .inherits = &ata_sff_port_ops,
  28. .cable_detect = ata_cable_40wire,
  29. /* No altstatus so we don't want to use the lost interrupt poll */
  30. .lost_interrupt = ATA_OP_NULL,
  31. };
  32. /**
  33. * isapnp_init_one - attach an isapnp interface
  34. * @idev: PnP device
  35. * @dev_id: matching detect line
  36. *
  37. * Register an ISA bus IDE interface. Such interfaces are PIO 0 and
  38. * non shared IRQ.
  39. */
  40. static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id)
  41. {
  42. struct ata_host *host;
  43. struct ata_port *ap;
  44. void __iomem *cmd_addr, *ctl_addr;
  45. int irq = 0;
  46. irq_handler_t handler = NULL;
  47. if (pnp_port_valid(idev, 0) == 0)
  48. return -ENODEV;
  49. if (pnp_irq_valid(idev, 0)) {
  50. irq = pnp_irq(idev, 0);
  51. handler = ata_sff_interrupt;
  52. }
  53. /* allocate host */
  54. host = ata_host_alloc(&idev->dev, 1);
  55. if (!host)
  56. return -ENOMEM;
  57. /* acquire resources and fill host */
  58. cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8);
  59. if (!cmd_addr)
  60. return -ENOMEM;
  61. ap = host->ports[0];
  62. ap->ops = &isapnp_noalt_port_ops;
  63. ap->pio_mask = ATA_PIO0;
  64. ap->flags |= ATA_FLAG_SLAVE_POSS;
  65. ap->ioaddr.cmd_addr = cmd_addr;
  66. if (pnp_port_valid(idev, 1)) {
  67. ctl_addr = devm_ioport_map(&idev->dev,
  68. pnp_port_start(idev, 1), 1);
  69. if (!ctl_addr)
  70. return -ENOMEM;
  71. ap->ioaddr.altstatus_addr = ctl_addr;
  72. ap->ioaddr.ctl_addr = ctl_addr;
  73. ap->ops = &isapnp_port_ops;
  74. }
  75. ata_sff_std_ports(&ap->ioaddr);
  76. ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx",
  77. (unsigned long long)pnp_port_start(idev, 0),
  78. (unsigned long long)pnp_port_start(idev, 1));
  79. /* activate */
  80. return ata_host_activate(host, irq, handler, 0,
  81. &isapnp_sht);
  82. }
  83. /**
  84. * isapnp_remove_one - unplug an isapnp interface
  85. * @idev: PnP device
  86. *
  87. * Remove a previously configured PnP ATA port. Called only on module
  88. * unload events as the core does not currently deal with ISAPnP docking.
  89. */
  90. static void isapnp_remove_one(struct pnp_dev *idev)
  91. {
  92. struct device *dev = &idev->dev;
  93. struct ata_host *host = dev_get_drvdata(dev);
  94. ata_host_detach(host);
  95. }
  96. static struct pnp_device_id isapnp_devices[] = {
  97. /* Generic ESDI/IDE/ATA compatible hard disk controller */
  98. {.id = "PNP0600", .driver_data = 0},
  99. {.id = ""}
  100. };
  101. MODULE_DEVICE_TABLE(pnp, isapnp_devices);
  102. static struct pnp_driver isapnp_driver = {
  103. .name = DRV_NAME,
  104. .id_table = isapnp_devices,
  105. .probe = isapnp_init_one,
  106. .remove = isapnp_remove_one,
  107. };
  108. module_pnp_driver(isapnp_driver);
  109. MODULE_AUTHOR("Alan Cox");
  110. MODULE_DESCRIPTION("low-level driver for ISA PnP ATA");
  111. MODULE_LICENSE("GPL");
  112. MODULE_VERSION(DRV_VERSION);