blob: 15cdb9148aab2500085a664dad6e0c624aa71f4f [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"
Jeff Garzik2a3103c2007-08-31 04:54:06 -040020#define DRV_VERSION "0.2.2"
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
31/**
32 * isapnp_init_one - attach an isapnp interface
33 * @idev: PnP device
34 * @dev_id: matching detect line
35 *
36 * Register an ISA bus IDE interface. Such interfaces are PIO 0 and
37 * non shared IRQ.
38 */
39
40static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id)
41{
Tejun Heo5d728822007-04-17 23:44:08 +090042 struct ata_host *host;
43 struct ata_port *ap;
Tejun Heo0d5ff562007-02-01 15:06:36 +090044 void __iomem *cmd_addr, *ctl_addr;
Alan Cox91e33d32007-11-19 14:41:05 +000045 int irq = 0;
46 irq_handler_t handler = NULL;
Jeff Garzik669a5db2006-08-29 18:12:40 -040047
48 if (pnp_port_valid(idev, 0) == 0)
49 return -ENODEV;
50
Alan Cox91e33d32007-11-19 14:41:05 +000051 if (pnp_irq_valid(idev, 0)) {
52 irq = pnp_irq(idev, 0);
Tejun Heo9363c382008-04-07 22:47:16 +090053 handler = ata_sff_interrupt;
Alan Cox91e33d32007-11-19 14:41:05 +000054 }
Jeff Garzik669a5db2006-08-29 18:12:40 -040055
Tejun Heo5d728822007-04-17 23:44:08 +090056 /* allocate host */
57 host = ata_host_alloc(&idev->dev, 1);
58 if (!host)
59 return -ENOMEM;
60
61 /* acquire resources and fill host */
Tejun Heo0d5ff562007-02-01 15:06:36 +090062 cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8);
63 if (!cmd_addr)
64 return -ENOMEM;
65
Tejun Heo5d728822007-04-17 23:44:08 +090066 ap = host->ports[0];
67
68 ap->ops = &isapnp_port_ops;
69 ap->pio_mask = 1;
70 ap->flags |= ATA_FLAG_SLAVE_POSS;
71
72 ap->ioaddr.cmd_addr = cmd_addr;
Jeff Garzik669a5db2006-08-29 18:12:40 -040073
74 if (pnp_port_valid(idev, 1) == 0) {
Tejun Heo0d5ff562007-02-01 15:06:36 +090075 ctl_addr = devm_ioport_map(&idev->dev,
76 pnp_port_start(idev, 1), 1);
Tejun Heo5d728822007-04-17 23:44:08 +090077 ap->ioaddr.altstatus_addr = ctl_addr;
78 ap->ioaddr.ctl_addr = ctl_addr;
Jeff Garzik669a5db2006-08-29 18:12:40 -040079 }
Jeff Garzik669a5db2006-08-29 18:12:40 -040080
Tejun Heo9363c382008-04-07 22:47:16 +090081 ata_sff_std_ports(&ap->ioaddr);
Tejun Heo5d728822007-04-17 23:44:08 +090082
Tejun Heocbcdd872007-08-18 13:14:55 +090083 ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx",
84 (unsigned long long)pnp_port_start(idev, 0),
85 (unsigned long long)pnp_port_start(idev, 1));
86
Tejun Heo5d728822007-04-17 23:44:08 +090087 /* activate */
Alan Cox91e33d32007-11-19 14:41:05 +000088 return ata_host_activate(host, irq, handler, 0,
Tejun Heo5d728822007-04-17 23:44:08 +090089 &isapnp_sht);
Jeff Garzik669a5db2006-08-29 18:12:40 -040090}
91
92/**
93 * isapnp_remove_one - unplug an isapnp interface
94 * @idev: PnP device
95 *
96 * Remove a previously configured PnP ATA port. Called only on module
97 * unload events as the core does not currently deal with ISAPnP docking.
98 */
99
100static void isapnp_remove_one(struct pnp_dev *idev)
101{
102 struct device *dev = &idev->dev;
103 struct ata_host *host = dev_get_drvdata(dev);
104
Tejun Heo24dc5f32007-01-20 16:00:28 +0900105 ata_host_detach(host);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400106}
107
108static struct pnp_device_id isapnp_devices[] = {
109 /* Generic ESDI/IDE/ATA compatible hard disk controller */
110 {.id = "PNP0600", .driver_data = 0},
111 {.id = ""}
112};
113
Jeff Garzik6a286a62007-08-03 11:25:50 -0400114MODULE_DEVICE_TABLE(pnp, isapnp_devices);
115
Jeff Garzik669a5db2006-08-29 18:12:40 -0400116static struct pnp_driver isapnp_driver = {
117 .name = DRV_NAME,
118 .id_table = isapnp_devices,
119 .probe = isapnp_init_one,
120 .remove = isapnp_remove_one,
121};
122
123static int __init isapnp_init(void)
124{
125 return pnp_register_driver(&isapnp_driver);
126}
127
128static void __exit isapnp_exit(void)
129{
130 pnp_unregister_driver(&isapnp_driver);
131}
132
133MODULE_AUTHOR("Alan Cox");
134MODULE_DESCRIPTION("low-level driver for ISA PnP ATA");
135MODULE_LICENSE("GPL");
136MODULE_VERSION(DRV_VERSION);
137
138module_init(isapnp_init);
139module_exit(isapnp_exit);