blob: 994f168b54a804184ebb01b20b8acda16230e62d [file] [log] [blame]
Jeff Garzik669a5db2006-08-29 18:12:40 -04001
2/*
3 * pata-isapnp.c - ISA PnP PATA controller driver.
Alan Coxab771632008-10-27 15:09:10 +00004 * Copyright 2005/2006 Red Hat Inc, all rights reserved.
Jeff Garzik669a5db2006-08-29 18:12:40 -04005 *
6 * Based in part on ide-pnp.c by Andrey Panin <pazke@donpac.ru>
7 */
8
9#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/isapnp.h>
12#include <linux/init.h>
13#include <linux/blkdev.h>
14#include <linux/delay.h>
15#include <scsi/scsi_host.h>
16#include <linux/ata.h>
17#include <linux/libata.h>
18
19#define DRV_NAME "pata_isapnp"
Alan Coxc96f1732009-03-24 10:23:46 +000020#define DRV_VERSION "0.2.5"
Jeff Garzik669a5db2006-08-29 18:12:40 -040021
22static struct scsi_host_template isapnp_sht = {
Tejun Heo68d1d072008-03-25 12:22:49 +090023 ATA_PIO_SHT(DRV_NAME),
Jeff Garzik669a5db2006-08-29 18:12:40 -040024};
25
26static struct ata_port_operations isapnp_port_ops = {
Tejun Heo029cfd62008-03-25 12:22:49 +090027 .inherits = &ata_sff_port_ops,
Jeff Garzika73984a2007-03-09 08:37:46 -050028 .cable_detect = ata_cable_40wire,
Jeff Garzik669a5db2006-08-29 18:12:40 -040029};
30
Alan Coxc96f1732009-03-24 10:23:46 +000031static struct ata_port_operations isapnp_noalt_port_ops = {
32 .inherits = &ata_sff_port_ops,
33 .cable_detect = ata_cable_40wire,
34 /* No altstatus so we don't want to use the lost interrupt poll */
35 .lost_interrupt = ATA_OP_NULL,
36};
37
Jeff Garzik669a5db2006-08-29 18:12:40 -040038/**
39 * isapnp_init_one - attach an isapnp interface
40 * @idev: PnP device
41 * @dev_id: matching detect line
42 *
43 * Register an ISA bus IDE interface. Such interfaces are PIO 0 and
44 * non shared IRQ.
45 */
46
47static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id)
48{
Tejun Heo5d728822007-04-17 23:44:08 +090049 struct ata_host *host;
50 struct ata_port *ap;
Tejun Heo0d5ff562007-02-01 15:06:36 +090051 void __iomem *cmd_addr, *ctl_addr;
Alan Cox91e33d32007-11-19 14:41:05 +000052 int irq = 0;
53 irq_handler_t handler = NULL;
Jeff Garzik669a5db2006-08-29 18:12:40 -040054
55 if (pnp_port_valid(idev, 0) == 0)
56 return -ENODEV;
57
Alan Cox91e33d32007-11-19 14:41:05 +000058 if (pnp_irq_valid(idev, 0)) {
59 irq = pnp_irq(idev, 0);
Tejun Heo9363c382008-04-07 22:47:16 +090060 handler = ata_sff_interrupt;
Alan Cox91e33d32007-11-19 14:41:05 +000061 }
Jeff Garzik669a5db2006-08-29 18:12:40 -040062
Tejun Heo5d728822007-04-17 23:44:08 +090063 /* allocate host */
64 host = ata_host_alloc(&idev->dev, 1);
65 if (!host)
66 return -ENOMEM;
67
68 /* acquire resources and fill host */
Tejun Heo0d5ff562007-02-01 15:06:36 +090069 cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8);
70 if (!cmd_addr)
71 return -ENOMEM;
72
Tejun Heo5d728822007-04-17 23:44:08 +090073 ap = host->ports[0];
74
Alan Coxc96f1732009-03-24 10:23:46 +000075 ap->ops = &isapnp_noalt_port_ops;
Erik Inge Bolsø14bdef92009-03-14 21:38:24 +010076 ap->pio_mask = ATA_PIO0;
Tejun Heo5d728822007-04-17 23:44:08 +090077 ap->flags |= ATA_FLAG_SLAVE_POSS;
78
79 ap->ioaddr.cmd_addr = cmd_addr;
Jeff Garzik669a5db2006-08-29 18:12:40 -040080
Ondrej Zaryfc0012e2013-09-12 23:01:29 +020081 if (pnp_port_valid(idev, 1)) {
Tejun Heo0d5ff562007-02-01 15:06:36 +090082 ctl_addr = devm_ioport_map(&idev->dev,
83 pnp_port_start(idev, 1), 1);
Tejun Heo5d728822007-04-17 23:44:08 +090084 ap->ioaddr.altstatus_addr = ctl_addr;
85 ap->ioaddr.ctl_addr = ctl_addr;
Alan Coxc96f1732009-03-24 10:23:46 +000086 ap->ops = &isapnp_port_ops;
Jeff Garzik669a5db2006-08-29 18:12:40 -040087 }
Jeff Garzik669a5db2006-08-29 18:12:40 -040088
Tejun Heo9363c382008-04-07 22:47:16 +090089 ata_sff_std_ports(&ap->ioaddr);
Tejun Heo5d728822007-04-17 23:44:08 +090090
Tejun Heocbcdd872007-08-18 13:14:55 +090091 ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx",
92 (unsigned long long)pnp_port_start(idev, 0),
93 (unsigned long long)pnp_port_start(idev, 1));
94
Tejun Heo5d728822007-04-17 23:44:08 +090095 /* activate */
Alan Cox91e33d32007-11-19 14:41:05 +000096 return ata_host_activate(host, irq, handler, 0,
Tejun Heo5d728822007-04-17 23:44:08 +090097 &isapnp_sht);
Jeff Garzik669a5db2006-08-29 18:12:40 -040098}
99
100/**
101 * isapnp_remove_one - unplug an isapnp interface
102 * @idev: PnP device
103 *
104 * Remove a previously configured PnP ATA port. Called only on module
105 * unload events as the core does not currently deal with ISAPnP docking.
106 */
107
108static void isapnp_remove_one(struct pnp_dev *idev)
109{
110 struct device *dev = &idev->dev;
111 struct ata_host *host = dev_get_drvdata(dev);
112
Tejun Heo24dc5f32007-01-20 16:00:28 +0900113 ata_host_detach(host);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400114}
115
116static struct pnp_device_id isapnp_devices[] = {
117 /* Generic ESDI/IDE/ATA compatible hard disk controller */
118 {.id = "PNP0600", .driver_data = 0},
119 {.id = ""}
120};
121
Jeff Garzik6a286a62007-08-03 11:25:50 -0400122MODULE_DEVICE_TABLE(pnp, isapnp_devices);
123
Jeff Garzik669a5db2006-08-29 18:12:40 -0400124static struct pnp_driver isapnp_driver = {
125 .name = DRV_NAME,
126 .id_table = isapnp_devices,
127 .probe = isapnp_init_one,
128 .remove = isapnp_remove_one,
129};
130
Peter Huewe99c876b2015-03-16 21:46:32 +0100131module_pnp_driver(isapnp_driver);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400132MODULE_AUTHOR("Alan Cox");
133MODULE_DESCRIPTION("low-level driver for ISA PnP ATA");
134MODULE_LICENSE("GPL");
135MODULE_VERSION(DRV_VERSION);