blob: 43bb224430d3cec4bac2b1aa80d8035c5b70858a [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Jeff Garzik669a5db2006-08-29 18:12:40 -04002
3/*
4 * pata-isapnp.c - ISA PnP PATA controller driver.
Alan Coxab771632008-10-27 15:09:10 +00005 * Copyright 2005/2006 Red Hat Inc, all rights reserved.
Jeff Garzik669a5db2006-08-29 18:12:40 -04006 *
7 * Based in part on ide-pnp.c by Andrey Panin <pazke@donpac.ru>
8 */
9
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>
19
20#define DRV_NAME "pata_isapnp"
Alan Coxc96f1732009-03-24 10:23:46 +000021#define DRV_VERSION "0.2.5"
Jeff Garzik669a5db2006-08-29 18:12:40 -040022
23static struct scsi_host_template isapnp_sht = {
Tejun Heo68d1d072008-03-25 12:22:49 +090024 ATA_PIO_SHT(DRV_NAME),
Jeff Garzik669a5db2006-08-29 18:12:40 -040025};
26
27static struct ata_port_operations isapnp_port_ops = {
Tejun Heo029cfd62008-03-25 12:22:49 +090028 .inherits = &ata_sff_port_ops,
Jeff Garzika73984a2007-03-09 08:37:46 -050029 .cable_detect = ata_cable_40wire,
Jeff Garzik669a5db2006-08-29 18:12:40 -040030};
31
Alan Coxc96f1732009-03-24 10:23:46 +000032static 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,
37};
38
Jeff Garzik669a5db2006-08-29 18:12:40 -040039/**
40 * isapnp_init_one - attach an isapnp interface
41 * @idev: PnP device
42 * @dev_id: matching detect line
43 *
44 * Register an ISA bus IDE interface. Such interfaces are PIO 0 and
45 * non shared IRQ.
46 */
47
48static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id)
49{
Tejun Heo5d728822007-04-17 23:44:08 +090050 struct ata_host *host;
51 struct ata_port *ap;
Tejun Heo0d5ff562007-02-01 15:06:36 +090052 void __iomem *cmd_addr, *ctl_addr;
Alan Cox91e33d32007-11-19 14:41:05 +000053 int irq = 0;
54 irq_handler_t handler = NULL;
Jeff Garzik669a5db2006-08-29 18:12:40 -040055
56 if (pnp_port_valid(idev, 0) == 0)
57 return -ENODEV;
58
Alan Cox91e33d32007-11-19 14:41:05 +000059 if (pnp_irq_valid(idev, 0)) {
60 irq = pnp_irq(idev, 0);
Tejun Heo9363c382008-04-07 22:47:16 +090061 handler = ata_sff_interrupt;
Alan Cox91e33d32007-11-19 14:41:05 +000062 }
Jeff Garzik669a5db2006-08-29 18:12:40 -040063
Tejun Heo5d728822007-04-17 23:44:08 +090064 /* allocate host */
65 host = ata_host_alloc(&idev->dev, 1);
66 if (!host)
67 return -ENOMEM;
68
69 /* acquire resources and fill host */
Tejun Heo0d5ff562007-02-01 15:06:36 +090070 cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8);
71 if (!cmd_addr)
72 return -ENOMEM;
73
Tejun Heo5d728822007-04-17 23:44:08 +090074 ap = host->ports[0];
75
Alan Coxc96f1732009-03-24 10:23:46 +000076 ap->ops = &isapnp_noalt_port_ops;
Erik Inge Bolsø14bdef92009-03-14 21:38:24 +010077 ap->pio_mask = ATA_PIO0;
Tejun Heo5d728822007-04-17 23:44:08 +090078 ap->flags |= ATA_FLAG_SLAVE_POSS;
79
80 ap->ioaddr.cmd_addr = cmd_addr;
Jeff Garzik669a5db2006-08-29 18:12:40 -040081
Ondrej Zaryfc0012e2013-09-12 23:01:29 +020082 if (pnp_port_valid(idev, 1)) {
Tejun Heo0d5ff562007-02-01 15:06:36 +090083 ctl_addr = devm_ioport_map(&idev->dev,
84 pnp_port_start(idev, 1), 1);
Tejun Heo5d728822007-04-17 23:44:08 +090085 ap->ioaddr.altstatus_addr = ctl_addr;
86 ap->ioaddr.ctl_addr = ctl_addr;
Alan Coxc96f1732009-03-24 10:23:46 +000087 ap->ops = &isapnp_port_ops;
Jeff Garzik669a5db2006-08-29 18:12:40 -040088 }
Jeff Garzik669a5db2006-08-29 18:12:40 -040089
Tejun Heo9363c382008-04-07 22:47:16 +090090 ata_sff_std_ports(&ap->ioaddr);
Tejun Heo5d728822007-04-17 23:44:08 +090091
Tejun Heocbcdd872007-08-18 13:14:55 +090092 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));
95
Tejun Heo5d728822007-04-17 23:44:08 +090096 /* activate */
Alan Cox91e33d32007-11-19 14:41:05 +000097 return ata_host_activate(host, irq, handler, 0,
Tejun Heo5d728822007-04-17 23:44:08 +090098 &isapnp_sht);
Jeff Garzik669a5db2006-08-29 18:12:40 -040099}
100
101/**
102 * isapnp_remove_one - unplug an isapnp interface
103 * @idev: PnP device
104 *
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.
107 */
108
109static void isapnp_remove_one(struct pnp_dev *idev)
110{
111 struct device *dev = &idev->dev;
112 struct ata_host *host = dev_get_drvdata(dev);
113
Tejun Heo24dc5f32007-01-20 16:00:28 +0900114 ata_host_detach(host);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400115}
116
117static struct pnp_device_id isapnp_devices[] = {
118 /* Generic ESDI/IDE/ATA compatible hard disk controller */
119 {.id = "PNP0600", .driver_data = 0},
120 {.id = ""}
121};
122
Jeff Garzik6a286a62007-08-03 11:25:50 -0400123MODULE_DEVICE_TABLE(pnp, isapnp_devices);
124
Jeff Garzik669a5db2006-08-29 18:12:40 -0400125static struct pnp_driver isapnp_driver = {
126 .name = DRV_NAME,
127 .id_table = isapnp_devices,
128 .probe = isapnp_init_one,
129 .remove = isapnp_remove_one,
130};
131
Peter Huewe99c876b2015-03-16 21:46:32 +0100132module_pnp_driver(isapnp_driver);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400133MODULE_AUTHOR("Alan Cox");
134MODULE_DESCRIPTION("low-level driver for ISA PnP ATA");
135MODULE_LICENSE("GPL");
136MODULE_VERSION(DRV_VERSION);