pata_isapnp.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.2"
  18. static struct scsi_host_template isapnp_sht = {
  19. ATA_PIO_SHT(DRV_NAME),
  20. };
  21. static struct ata_port_operations isapnp_port_ops = {
  22. .inherits = &ata_sff_port_ops,
  23. .cable_detect = ata_cable_40wire,
  24. };
  25. /**
  26. * isapnp_init_one - attach an isapnp interface
  27. * @idev: PnP device
  28. * @dev_id: matching detect line
  29. *
  30. * Register an ISA bus IDE interface. Such interfaces are PIO 0 and
  31. * non shared IRQ.
  32. */
  33. static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id)
  34. {
  35. struct ata_host *host;
  36. struct ata_port *ap;
  37. void __iomem *cmd_addr, *ctl_addr;
  38. int irq = 0;
  39. irq_handler_t handler = NULL;
  40. if (pnp_port_valid(idev, 0) == 0)
  41. return -ENODEV;
  42. if (pnp_irq_valid(idev, 0)) {
  43. irq = pnp_irq(idev, 0);
  44. handler = ata_sff_interrupt;
  45. }
  46. /* allocate host */
  47. host = ata_host_alloc(&idev->dev, 1);
  48. if (!host)
  49. return -ENOMEM;
  50. /* acquire resources and fill host */
  51. cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8);
  52. if (!cmd_addr)
  53. return -ENOMEM;
  54. ap = host->ports[0];
  55. ap->ops = &isapnp_port_ops;
  56. ap->pio_mask = 1;
  57. ap->flags |= ATA_FLAG_SLAVE_POSS;
  58. ap->ioaddr.cmd_addr = cmd_addr;
  59. if (pnp_port_valid(idev, 1) == 0) {
  60. ctl_addr = devm_ioport_map(&idev->dev,
  61. pnp_port_start(idev, 1), 1);
  62. ap->ioaddr.altstatus_addr = ctl_addr;
  63. ap->ioaddr.ctl_addr = ctl_addr;
  64. }
  65. ata_sff_std_ports(&ap->ioaddr);
  66. ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx",
  67. (unsigned long long)pnp_port_start(idev, 0),
  68. (unsigned long long)pnp_port_start(idev, 1));
  69. /* activate */
  70. return ata_host_activate(host, irq, handler, 0,
  71. &isapnp_sht);
  72. }
  73. /**
  74. * isapnp_remove_one - unplug an isapnp interface
  75. * @idev: PnP device
  76. *
  77. * Remove a previously configured PnP ATA port. Called only on module
  78. * unload events as the core does not currently deal with ISAPnP docking.
  79. */
  80. static void isapnp_remove_one(struct pnp_dev *idev)
  81. {
  82. struct device *dev = &idev->dev;
  83. struct ata_host *host = dev_get_drvdata(dev);
  84. ata_host_detach(host);
  85. }
  86. static struct pnp_device_id isapnp_devices[] = {
  87. /* Generic ESDI/IDE/ATA compatible hard disk controller */
  88. {.id = "PNP0600", .driver_data = 0},
  89. {.id = ""}
  90. };
  91. MODULE_DEVICE_TABLE(pnp, isapnp_devices);
  92. static struct pnp_driver isapnp_driver = {
  93. .name = DRV_NAME,
  94. .id_table = isapnp_devices,
  95. .probe = isapnp_init_one,
  96. .remove = isapnp_remove_one,
  97. };
  98. static int __init isapnp_init(void)
  99. {
  100. return pnp_register_driver(&isapnp_driver);
  101. }
  102. static void __exit isapnp_exit(void)
  103. {
  104. pnp_unregister_driver(&isapnp_driver);
  105. }
  106. MODULE_AUTHOR("Alan Cox");
  107. MODULE_DESCRIPTION("low-level driver for ISA PnP ATA");
  108. MODULE_LICENSE("GPL");
  109. MODULE_VERSION(DRV_VERSION);
  110. module_init(isapnp_init);
  111. module_exit(isapnp_exit);