Commit | Line | Data |
---|---|---|
09c434b8 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
669a5db4 JG |
2 | |
3 | /* | |
4 | * pata-isapnp.c - ISA PnP PATA controller driver. | |
ab771630 | 5 | * Copyright 2005/2006 Red Hat Inc, all rights reserved. |
669a5db4 JG |
6 | * |
7 | * Based in part on ide-pnp.c by Andrey Panin <pazke@donpac.ru> | |
8 | */ | |
9 | ||
10 | #include <linux/kernel.h> | |
11 | #include <linux/module.h> | |
12 | #include <linux/isapnp.h> | |
13 | #include <linux/init.h> | |
14 | #include <linux/blkdev.h> | |
15 | #include <linux/delay.h> | |
16 | #include <scsi/scsi_host.h> | |
17 | #include <linux/ata.h> | |
18 | #include <linux/libata.h> | |
19 | ||
20 | #define DRV_NAME "pata_isapnp" | |
c96f1732 | 21 | #define DRV_VERSION "0.2.5" |
669a5db4 | 22 | |
25df73d9 | 23 | static const struct scsi_host_template isapnp_sht = { |
68d1d07b | 24 | ATA_PIO_SHT(DRV_NAME), |
669a5db4 JG |
25 | }; |
26 | ||
27 | static struct ata_port_operations isapnp_port_ops = { | |
029cfd6b | 28 | .inherits = &ata_sff_port_ops, |
a73984a0 | 29 | .cable_detect = ata_cable_40wire, |
669a5db4 JG |
30 | }; |
31 | ||
c96f1732 AC |
32 | static struct ata_port_operations isapnp_noalt_port_ops = { |
33 | .inherits = &ata_sff_port_ops, | |
34 | .cable_detect = ata_cable_40wire, | |
35 | /* No altstatus so we don't want to use the lost interrupt poll */ | |
36 | .lost_interrupt = ATA_OP_NULL, | |
37 | }; | |
38 | ||
669a5db4 JG |
39 | /** |
40 | * isapnp_init_one - attach an isapnp interface | |
41 | * @idev: PnP device | |
42 | * @dev_id: matching detect line | |
43 | * | |
44 | * Register an ISA bus IDE interface. Such interfaces are PIO 0 and | |
45 | * non shared IRQ. | |
46 | */ | |
47 | ||
48 | static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id) | |
49 | { | |
5d728824 TH |
50 | struct ata_host *host; |
51 | struct ata_port *ap; | |
0d5ff566 | 52 | void __iomem *cmd_addr, *ctl_addr; |
91e33d31 AC |
53 | int irq = 0; |
54 | irq_handler_t handler = NULL; | |
669a5db4 JG |
55 | |
56 | if (pnp_port_valid(idev, 0) == 0) | |
57 | return -ENODEV; | |
58 | ||
91e33d31 AC |
59 | if (pnp_irq_valid(idev, 0)) { |
60 | irq = pnp_irq(idev, 0); | |
9363c382 | 61 | handler = ata_sff_interrupt; |
91e33d31 | 62 | } |
669a5db4 | 63 | |
5d728824 TH |
64 | /* allocate host */ |
65 | host = ata_host_alloc(&idev->dev, 1); | |
66 | if (!host) | |
67 | return -ENOMEM; | |
68 | ||
69 | /* acquire resources and fill host */ | |
0d5ff566 TH |
70 | cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8); |
71 | if (!cmd_addr) | |
72 | return -ENOMEM; | |
73 | ||
5d728824 TH |
74 | ap = host->ports[0]; |
75 | ||
c96f1732 | 76 | ap->ops = &isapnp_noalt_port_ops; |
14bdef98 | 77 | ap->pio_mask = ATA_PIO0; |
5d728824 TH |
78 | ap->flags |= ATA_FLAG_SLAVE_POSS; |
79 | ||
80 | ap->ioaddr.cmd_addr = cmd_addr; | |
669a5db4 | 81 | |
fc0012ec | 82 | if (pnp_port_valid(idev, 1)) { |
0d5ff566 TH |
83 | ctl_addr = devm_ioport_map(&idev->dev, |
84 | pnp_port_start(idev, 1), 1); | |
a6925165 CN |
85 | if (!ctl_addr) |
86 | return -ENOMEM; | |
87 | ||
5d728824 TH |
88 | ap->ioaddr.altstatus_addr = ctl_addr; |
89 | ap->ioaddr.ctl_addr = ctl_addr; | |
c96f1732 | 90 | ap->ops = &isapnp_port_ops; |
669a5db4 | 91 | } |
669a5db4 | 92 | |
9363c382 | 93 | ata_sff_std_ports(&ap->ioaddr); |
5d728824 | 94 | |
cbcdd875 TH |
95 | ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx", |
96 | (unsigned long long)pnp_port_start(idev, 0), | |
97 | (unsigned long long)pnp_port_start(idev, 1)); | |
98 | ||
5d728824 | 99 | /* activate */ |
91e33d31 | 100 | return ata_host_activate(host, irq, handler, 0, |
5d728824 | 101 | &isapnp_sht); |
669a5db4 JG |
102 | } |
103 | ||
104 | /** | |
105 | * isapnp_remove_one - unplug an isapnp interface | |
106 | * @idev: PnP device | |
107 | * | |
108 | * Remove a previously configured PnP ATA port. Called only on module | |
109 | * unload events as the core does not currently deal with ISAPnP docking. | |
110 | */ | |
111 | ||
112 | static void isapnp_remove_one(struct pnp_dev *idev) | |
113 | { | |
114 | struct device *dev = &idev->dev; | |
115 | struct ata_host *host = dev_get_drvdata(dev); | |
116 | ||
24dc5f33 | 117 | ata_host_detach(host); |
669a5db4 JG |
118 | } |
119 | ||
120 | static struct pnp_device_id isapnp_devices[] = { | |
121 | /* Generic ESDI/IDE/ATA compatible hard disk controller */ | |
122 | {.id = "PNP0600", .driver_data = 0}, | |
123 | {.id = ""} | |
124 | }; | |
125 | ||
6a286a6d JG |
126 | MODULE_DEVICE_TABLE(pnp, isapnp_devices); |
127 | ||
669a5db4 JG |
128 | static struct pnp_driver isapnp_driver = { |
129 | .name = DRV_NAME, | |
130 | .id_table = isapnp_devices, | |
131 | .probe = isapnp_init_one, | |
132 | .remove = isapnp_remove_one, | |
133 | }; | |
134 | ||
99c876be | 135 | module_pnp_driver(isapnp_driver); |
669a5db4 JG |
136 | MODULE_AUTHOR("Alan Cox"); |
137 | MODULE_DESCRIPTION("low-level driver for ISA PnP ATA"); | |
138 | MODULE_LICENSE("GPL"); | |
139 | MODULE_VERSION(DRV_VERSION); |