blob: 4320e79863219d6858e74d376c991be6588a6cf7 [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 = {
23 .module = THIS_MODULE,
24 .name = DRV_NAME,
25 .ioctl = ata_scsi_ioctl,
26 .queuecommand = ata_scsi_queuecmd,
27 .can_queue = ATA_DEF_QUEUE,
28 .this_id = ATA_SHT_THIS_ID,
29 .sg_tablesize = LIBATA_MAX_PRD,
Jeff Garzik669a5db2006-08-29 18:12:40 -040030 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
31 .emulated = ATA_SHT_EMULATED,
32 .use_clustering = ATA_SHT_USE_CLUSTERING,
33 .proc_name = DRV_NAME,
34 .dma_boundary = ATA_DMA_BOUNDARY,
35 .slave_configure = ata_scsi_slave_config,
Tejun Heoafdfe892006-11-29 11:26:47 +090036 .slave_destroy = ata_scsi_slave_destroy,
Jeff Garzik669a5db2006-08-29 18:12:40 -040037 .bios_param = ata_std_bios_param,
38};
39
40static struct ata_port_operations isapnp_port_ops = {
Jeff Garzik669a5db2006-08-29 18:12:40 -040041 .tf_load = ata_tf_load,
42 .tf_read = ata_tf_read,
43 .check_status = ata_check_status,
44 .exec_command = ata_exec_command,
45 .dev_select = ata_std_dev_select,
46
47 .freeze = ata_bmdma_freeze,
48 .thaw = ata_bmdma_thaw,
49 .error_handler = ata_bmdma_error_handler,
50 .post_internal_cmd = ata_bmdma_post_internal_cmd,
Jeff Garzika73984a2007-03-09 08:37:46 -050051 .cable_detect = ata_cable_40wire,
Jeff Garzik669a5db2006-08-29 18:12:40 -040052
53 .qc_prep = ata_qc_prep,
54 .qc_issue = ata_qc_issue_prot,
Jeff Garzikbda30282006-09-27 05:41:13 -040055
Tejun Heo0d5ff562007-02-01 15:06:36 +090056 .data_xfer = ata_data_xfer,
Jeff Garzik669a5db2006-08-29 18:12:40 -040057
Jeff Garzik669a5db2006-08-29 18:12:40 -040058 .irq_clear = ata_bmdma_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +090059 .irq_on = ata_irq_on,
Jeff Garzik669a5db2006-08-29 18:12:40 -040060
Alan Cox81ad1832007-08-22 22:55:41 +010061 .port_start = ata_sff_port_start,
Jeff Garzik669a5db2006-08-29 18:12:40 -040062};
63
64/**
65 * isapnp_init_one - attach an isapnp interface
66 * @idev: PnP device
67 * @dev_id: matching detect line
68 *
69 * Register an ISA bus IDE interface. Such interfaces are PIO 0 and
70 * non shared IRQ.
71 */
72
73static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id)
74{
Tejun Heo5d728822007-04-17 23:44:08 +090075 struct ata_host *host;
76 struct ata_port *ap;
Tejun Heo0d5ff562007-02-01 15:06:36 +090077 void __iomem *cmd_addr, *ctl_addr;
Alan Cox91e33d32007-11-19 14:41:05 +000078 int irq = 0;
79 irq_handler_t handler = NULL;
Jeff Garzik669a5db2006-08-29 18:12:40 -040080
81 if (pnp_port_valid(idev, 0) == 0)
82 return -ENODEV;
83
Alan Cox91e33d32007-11-19 14:41:05 +000084 if (pnp_irq_valid(idev, 0)) {
85 irq = pnp_irq(idev, 0);
86 handler = ata_interrupt;
87 }
Jeff Garzik669a5db2006-08-29 18:12:40 -040088
Tejun Heo5d728822007-04-17 23:44:08 +090089 /* allocate host */
90 host = ata_host_alloc(&idev->dev, 1);
91 if (!host)
92 return -ENOMEM;
93
94 /* acquire resources and fill host */
Tejun Heo0d5ff562007-02-01 15:06:36 +090095 cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8);
96 if (!cmd_addr)
97 return -ENOMEM;
98
Tejun Heo5d728822007-04-17 23:44:08 +090099 ap = host->ports[0];
100
101 ap->ops = &isapnp_port_ops;
102 ap->pio_mask = 1;
103 ap->flags |= ATA_FLAG_SLAVE_POSS;
104
105 ap->ioaddr.cmd_addr = cmd_addr;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400106
107 if (pnp_port_valid(idev, 1) == 0) {
Tejun Heo0d5ff562007-02-01 15:06:36 +0900108 ctl_addr = devm_ioport_map(&idev->dev,
109 pnp_port_start(idev, 1), 1);
Tejun Heo5d728822007-04-17 23:44:08 +0900110 ap->ioaddr.altstatus_addr = ctl_addr;
111 ap->ioaddr.ctl_addr = ctl_addr;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400112 }
Jeff Garzik669a5db2006-08-29 18:12:40 -0400113
Tejun Heo5d728822007-04-17 23:44:08 +0900114 ata_std_ports(&ap->ioaddr);
115
Tejun Heocbcdd872007-08-18 13:14:55 +0900116 ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx",
117 (unsigned long long)pnp_port_start(idev, 0),
118 (unsigned long long)pnp_port_start(idev, 1));
119
Tejun Heo5d728822007-04-17 23:44:08 +0900120 /* activate */
Alan Cox91e33d32007-11-19 14:41:05 +0000121 return ata_host_activate(host, irq, handler, 0,
Tejun Heo5d728822007-04-17 23:44:08 +0900122 &isapnp_sht);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400123}
124
125/**
126 * isapnp_remove_one - unplug an isapnp interface
127 * @idev: PnP device
128 *
129 * Remove a previously configured PnP ATA port. Called only on module
130 * unload events as the core does not currently deal with ISAPnP docking.
131 */
132
133static void isapnp_remove_one(struct pnp_dev *idev)
134{
135 struct device *dev = &idev->dev;
136 struct ata_host *host = dev_get_drvdata(dev);
137
Tejun Heo24dc5f32007-01-20 16:00:28 +0900138 ata_host_detach(host);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400139}
140
141static struct pnp_device_id isapnp_devices[] = {
142 /* Generic ESDI/IDE/ATA compatible hard disk controller */
143 {.id = "PNP0600", .driver_data = 0},
144 {.id = ""}
145};
146
Jeff Garzik6a286a62007-08-03 11:25:50 -0400147MODULE_DEVICE_TABLE(pnp, isapnp_devices);
148
Jeff Garzik669a5db2006-08-29 18:12:40 -0400149static struct pnp_driver isapnp_driver = {
150 .name = DRV_NAME,
151 .id_table = isapnp_devices,
152 .probe = isapnp_init_one,
153 .remove = isapnp_remove_one,
154};
155
156static int __init isapnp_init(void)
157{
158 return pnp_register_driver(&isapnp_driver);
159}
160
161static void __exit isapnp_exit(void)
162{
163 pnp_unregister_driver(&isapnp_driver);
164}
165
166MODULE_AUTHOR("Alan Cox");
167MODULE_DESCRIPTION("low-level driver for ISA PnP ATA");
168MODULE_LICENSE("GPL");
169MODULE_VERSION(DRV_VERSION);
170
171module_init(isapnp_init);
172module_exit(isapnp_exit);