blob: 91ca4d50db042338bcefdff8d66540be76d8909b [file] [log] [blame]
Jeff Garzik669a5db2006-08-29 18:12:40 -04001
2/*
3 * pata-isapnp.c - ISA PnP PATA controller driver.
4 * Copyright 2005/2006 Red Hat Inc <alan@redhat.com>, all rights reserved.
5 *
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 = {
Jeff Garzik669a5db2006-08-29 18:12:40 -040027 .tf_load = ata_tf_load,
28 .tf_read = ata_tf_read,
29 .check_status = ata_check_status,
30 .exec_command = ata_exec_command,
31 .dev_select = ata_std_dev_select,
32
33 .freeze = ata_bmdma_freeze,
34 .thaw = ata_bmdma_thaw,
35 .error_handler = ata_bmdma_error_handler,
36 .post_internal_cmd = ata_bmdma_post_internal_cmd,
Jeff Garzika73984a2007-03-09 08:37:46 -050037 .cable_detect = ata_cable_40wire,
Jeff Garzik669a5db2006-08-29 18:12:40 -040038
39 .qc_prep = ata_qc_prep,
40 .qc_issue = ata_qc_issue_prot,
Jeff Garzikbda30282006-09-27 05:41:13 -040041
Tejun Heo0d5ff562007-02-01 15:06:36 +090042 .data_xfer = ata_data_xfer,
Jeff Garzik669a5db2006-08-29 18:12:40 -040043
Tejun Heo358f9a72008-03-25 12:22:47 +090044 .irq_clear = ata_noop_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +090045 .irq_on = ata_irq_on,
Jeff Garzik669a5db2006-08-29 18:12:40 -040046
Alan Cox81ad1832007-08-22 22:55:41 +010047 .port_start = ata_sff_port_start,
Jeff Garzik669a5db2006-08-29 18:12:40 -040048};
49
50/**
51 * isapnp_init_one - attach an isapnp interface
52 * @idev: PnP device
53 * @dev_id: matching detect line
54 *
55 * Register an ISA bus IDE interface. Such interfaces are PIO 0 and
56 * non shared IRQ.
57 */
58
59static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id)
60{
Tejun Heo5d728822007-04-17 23:44:08 +090061 struct ata_host *host;
62 struct ata_port *ap;
Tejun Heo0d5ff562007-02-01 15:06:36 +090063 void __iomem *cmd_addr, *ctl_addr;
Alan Cox91e33d32007-11-19 14:41:05 +000064 int irq = 0;
65 irq_handler_t handler = NULL;
Jeff Garzik669a5db2006-08-29 18:12:40 -040066
67 if (pnp_port_valid(idev, 0) == 0)
68 return -ENODEV;
69
Alan Cox91e33d32007-11-19 14:41:05 +000070 if (pnp_irq_valid(idev, 0)) {
71 irq = pnp_irq(idev, 0);
72 handler = ata_interrupt;
73 }
Jeff Garzik669a5db2006-08-29 18:12:40 -040074
Tejun Heo5d728822007-04-17 23:44:08 +090075 /* allocate host */
76 host = ata_host_alloc(&idev->dev, 1);
77 if (!host)
78 return -ENOMEM;
79
80 /* acquire resources and fill host */
Tejun Heo0d5ff562007-02-01 15:06:36 +090081 cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8);
82 if (!cmd_addr)
83 return -ENOMEM;
84
Tejun Heo5d728822007-04-17 23:44:08 +090085 ap = host->ports[0];
86
87 ap->ops = &isapnp_port_ops;
88 ap->pio_mask = 1;
89 ap->flags |= ATA_FLAG_SLAVE_POSS;
90
91 ap->ioaddr.cmd_addr = cmd_addr;
Jeff Garzik669a5db2006-08-29 18:12:40 -040092
93 if (pnp_port_valid(idev, 1) == 0) {
Tejun Heo0d5ff562007-02-01 15:06:36 +090094 ctl_addr = devm_ioport_map(&idev->dev,
95 pnp_port_start(idev, 1), 1);
Tejun Heo5d728822007-04-17 23:44:08 +090096 ap->ioaddr.altstatus_addr = ctl_addr;
97 ap->ioaddr.ctl_addr = ctl_addr;
Jeff Garzik669a5db2006-08-29 18:12:40 -040098 }
Jeff Garzik669a5db2006-08-29 18:12:40 -040099
Tejun Heo5d728822007-04-17 23:44:08 +0900100 ata_std_ports(&ap->ioaddr);
101
Tejun Heocbcdd872007-08-18 13:14:55 +0900102 ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx",
103 (unsigned long long)pnp_port_start(idev, 0),
104 (unsigned long long)pnp_port_start(idev, 1));
105
Tejun Heo5d728822007-04-17 23:44:08 +0900106 /* activate */
Alan Cox91e33d32007-11-19 14:41:05 +0000107 return ata_host_activate(host, irq, handler, 0,
Tejun Heo5d728822007-04-17 23:44:08 +0900108 &isapnp_sht);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400109}
110
111/**
112 * isapnp_remove_one - unplug an isapnp interface
113 * @idev: PnP device
114 *
115 * Remove a previously configured PnP ATA port. Called only on module
116 * unload events as the core does not currently deal with ISAPnP docking.
117 */
118
119static void isapnp_remove_one(struct pnp_dev *idev)
120{
121 struct device *dev = &idev->dev;
122 struct ata_host *host = dev_get_drvdata(dev);
123
Tejun Heo24dc5f32007-01-20 16:00:28 +0900124 ata_host_detach(host);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400125}
126
127static struct pnp_device_id isapnp_devices[] = {
128 /* Generic ESDI/IDE/ATA compatible hard disk controller */
129 {.id = "PNP0600", .driver_data = 0},
130 {.id = ""}
131};
132
Jeff Garzik6a286a62007-08-03 11:25:50 -0400133MODULE_DEVICE_TABLE(pnp, isapnp_devices);
134
Jeff Garzik669a5db2006-08-29 18:12:40 -0400135static struct pnp_driver isapnp_driver = {
136 .name = DRV_NAME,
137 .id_table = isapnp_devices,
138 .probe = isapnp_init_one,
139 .remove = isapnp_remove_one,
140};
141
142static int __init isapnp_init(void)
143{
144 return pnp_register_driver(&isapnp_driver);
145}
146
147static void __exit isapnp_exit(void)
148{
149 pnp_unregister_driver(&isapnp_driver);
150}
151
152MODULE_AUTHOR("Alan Cox");
153MODULE_DESCRIPTION("low-level driver for ISA PnP ATA");
154MODULE_LICENSE("GPL");
155MODULE_VERSION(DRV_VERSION);
156
157module_init(isapnp_init);
158module_exit(isapnp_exit);