1 // SPDX-License-Identifier: GPL-2.0-only
4 * pata-isapnp.c - ISA PnP PATA controller driver.
5 * Copyright 2005/2006 Red Hat Inc, all rights reserved.
7 * Based in part on ide-pnp.c by Andrey Panin <pazke@donpac.ru>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/isapnp.h>
13 #include <linux/init.h>
14 #include <linux/blkdev.h>
15 #include <linux/delay.h>
16 #include <scsi/scsi_host.h>
17 #include <linux/ata.h>
18 #include <linux/libata.h>
20 #define DRV_NAME "pata_isapnp"
21 #define DRV_VERSION "0.2.5"
23 static struct scsi_host_template isapnp_sht = {
24 ATA_PIO_SHT(DRV_NAME),
27 static struct ata_port_operations isapnp_port_ops = {
28 .inherits = &ata_sff_port_ops,
29 .cable_detect = ata_cable_40wire,
32 static struct ata_port_operations isapnp_noalt_port_ops = {
33 .inherits = &ata_sff_port_ops,
34 .cable_detect = ata_cable_40wire,
35 /* No altstatus so we don't want to use the lost interrupt poll */
36 .lost_interrupt = ATA_OP_NULL,
40 * isapnp_init_one - attach an isapnp interface
42 * @dev_id: matching detect line
44 * Register an ISA bus IDE interface. Such interfaces are PIO 0 and
48 static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id)
50 struct ata_host *host;
52 void __iomem *cmd_addr, *ctl_addr;
54 irq_handler_t handler = NULL;
56 if (pnp_port_valid(idev, 0) == 0)
59 if (pnp_irq_valid(idev, 0)) {
60 irq = pnp_irq(idev, 0);
61 handler = ata_sff_interrupt;
65 host = ata_host_alloc(&idev->dev, 1);
69 /* acquire resources and fill host */
70 cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8);
76 ap->ops = &isapnp_noalt_port_ops;
77 ap->pio_mask = ATA_PIO0;
78 ap->flags |= ATA_FLAG_SLAVE_POSS;
80 ap->ioaddr.cmd_addr = cmd_addr;
82 if (pnp_port_valid(idev, 1)) {
83 ctl_addr = devm_ioport_map(&idev->dev,
84 pnp_port_start(idev, 1), 1);
85 ap->ioaddr.altstatus_addr = ctl_addr;
86 ap->ioaddr.ctl_addr = ctl_addr;
87 ap->ops = &isapnp_port_ops;
90 ata_sff_std_ports(&ap->ioaddr);
92 ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx",
93 (unsigned long long)pnp_port_start(idev, 0),
94 (unsigned long long)pnp_port_start(idev, 1));
97 return ata_host_activate(host, irq, handler, 0,
102 * isapnp_remove_one - unplug an isapnp interface
105 * Remove a previously configured PnP ATA port. Called only on module
106 * unload events as the core does not currently deal with ISAPnP docking.
109 static void isapnp_remove_one(struct pnp_dev *idev)
111 struct device *dev = &idev->dev;
112 struct ata_host *host = dev_get_drvdata(dev);
114 ata_host_detach(host);
117 static struct pnp_device_id isapnp_devices[] = {
118 /* Generic ESDI/IDE/ATA compatible hard disk controller */
119 {.id = "PNP0600", .driver_data = 0},
123 MODULE_DEVICE_TABLE(pnp, isapnp_devices);
125 static struct pnp_driver isapnp_driver = {
127 .id_table = isapnp_devices,
128 .probe = isapnp_init_one,
129 .remove = isapnp_remove_one,
132 module_pnp_driver(isapnp_driver);
133 MODULE_AUTHOR("Alan Cox");
134 MODULE_DESCRIPTION("low-level driver for ISA PnP ATA");
135 MODULE_LICENSE("GPL");
136 MODULE_VERSION(DRV_VERSION);