blob: 4d9ab268cf281c4ad148b61396ee202e873a5d22 [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"
20#define DRV_VERSION "0.1.5"
21
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 = {
41 .port_disable = ata_port_disable,
42 .tf_load = ata_tf_load,
43 .tf_read = ata_tf_read,
44 .check_status = ata_check_status,
45 .exec_command = ata_exec_command,
46 .dev_select = ata_std_dev_select,
47
48 .freeze = ata_bmdma_freeze,
49 .thaw = ata_bmdma_thaw,
50 .error_handler = ata_bmdma_error_handler,
51 .post_internal_cmd = ata_bmdma_post_internal_cmd,
52
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
58 .irq_handler = ata_interrupt,
59 .irq_clear = ata_bmdma_irq_clear,
60
61 .port_start = ata_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{
75 struct ata_probe_ent ae;
Tejun Heo0d5ff562007-02-01 15:06:36 +090076 void __iomem *cmd_addr, *ctl_addr;
Jeff Garzik669a5db2006-08-29 18:12:40 -040077
78 if (pnp_port_valid(idev, 0) == 0)
79 return -ENODEV;
80
81 /* FIXME: Should selected polled PIO here not fail */
82 if (pnp_irq_valid(idev, 0) == 0)
83 return -ENODEV;
84
Tejun Heo0d5ff562007-02-01 15:06:36 +090085 cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8);
86 if (!cmd_addr)
87 return -ENOMEM;
88
Jeff Garzik669a5db2006-08-29 18:12:40 -040089 memset(&ae, 0, sizeof(struct ata_probe_ent));
90 INIT_LIST_HEAD(&ae.node);
91 ae.dev = &idev->dev;
92 ae.port_ops = &isapnp_port_ops;
93 ae.sht = &isapnp_sht;
94 ae.n_ports = 1;
95 ae.pio_mask = 1; /* ISA so PIO 0 cycles */
96 ae.irq = pnp_irq(idev, 0);
97 ae.irq_flags = 0;
98 ae.port_flags = ATA_FLAG_SLAVE_POSS;
Tejun Heo0d5ff562007-02-01 15:06:36 +090099 ae.port[0].cmd_addr = cmd_addr;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400100
101 if (pnp_port_valid(idev, 1) == 0) {
Tejun Heo0d5ff562007-02-01 15:06:36 +0900102 ctl_addr = devm_ioport_map(&idev->dev,
103 pnp_port_start(idev, 1), 1);
104 ae.port[0].altstatus_addr = ctl_addr;
105 ae.port[0].ctl_addr = ctl_addr;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400106 ae.port_flags |= ATA_FLAG_SRST;
107 }
108 ata_std_ports(&ae.port[0]);
109
110 if (ata_device_add(&ae) == 0)
111 return -ENODEV;
112 return 0;
113}
114
115/**
116 * isapnp_remove_one - unplug an isapnp interface
117 * @idev: PnP device
118 *
119 * Remove a previously configured PnP ATA port. Called only on module
120 * unload events as the core does not currently deal with ISAPnP docking.
121 */
122
123static void isapnp_remove_one(struct pnp_dev *idev)
124{
125 struct device *dev = &idev->dev;
126 struct ata_host *host = dev_get_drvdata(dev);
127
Tejun Heo24dc5f32007-01-20 16:00:28 +0900128 ata_host_detach(host);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400129 dev_set_drvdata(dev, NULL);
130}
131
132static struct pnp_device_id isapnp_devices[] = {
133 /* Generic ESDI/IDE/ATA compatible hard disk controller */
134 {.id = "PNP0600", .driver_data = 0},
135 {.id = ""}
136};
137
138static struct pnp_driver isapnp_driver = {
139 .name = DRV_NAME,
140 .id_table = isapnp_devices,
141 .probe = isapnp_init_one,
142 .remove = isapnp_remove_one,
143};
144
145static int __init isapnp_init(void)
146{
147 return pnp_register_driver(&isapnp_driver);
148}
149
150static void __exit isapnp_exit(void)
151{
152 pnp_unregister_driver(&isapnp_driver);
153}
154
155MODULE_AUTHOR("Alan Cox");
156MODULE_DESCRIPTION("low-level driver for ISA PnP ATA");
157MODULE_LICENSE("GPL");
158MODULE_VERSION(DRV_VERSION);
159
160module_init(isapnp_init);
161module_exit(isapnp_exit);