ALSA: hda - Add static_hdmi_pcm option to HDMI codec parser
[linux-2.6/next.git] / drivers / ata / pata_acpi.c
blobc8d47034d5e99d679155f4be31b72d9c441d2e87
1 /*
2 * ACPI PATA driver
4 * (c) 2007 Red Hat
5 */
7 #include <linux/kernel.h>
8 #include <linux/module.h>
9 #include <linux/pci.h>
10 #include <linux/init.h>
11 #include <linux/blkdev.h>
12 #include <linux/delay.h>
13 #include <linux/device.h>
14 #include <linux/gfp.h>
15 #include <scsi/scsi_host.h>
16 #include <acpi/acpi_bus.h>
18 #include <linux/libata.h>
19 #include <linux/ata.h>
21 #define DRV_NAME "pata_acpi"
22 #define DRV_VERSION "0.2.3"
24 struct pata_acpi {
25 struct ata_acpi_gtm gtm;
26 void *last;
27 unsigned long mask[2];
30 /**
31 * pacpi_pre_reset - check for 40/80 pin
32 * @ap: Port
33 * @deadline: deadline jiffies for the operation
35 * Perform the PATA port setup we need.
38 static int pacpi_pre_reset(struct ata_link *link, unsigned long deadline)
40 struct ata_port *ap = link->ap;
41 struct pata_acpi *acpi = ap->private_data;
42 if (ap->acpi_handle == NULL || ata_acpi_gtm(ap, &acpi->gtm) < 0)
43 return -ENODEV;
45 return ata_sff_prereset(link, deadline);
48 /**
49 * pacpi_cable_detect - cable type detection
50 * @ap: port to detect
52 * Perform device specific cable detection
55 static int pacpi_cable_detect(struct ata_port *ap)
57 struct pata_acpi *acpi = ap->private_data;
59 if ((acpi->mask[0] | acpi->mask[1]) & (0xF8 << ATA_SHIFT_UDMA))
60 return ATA_CBL_PATA80;
61 else
62 return ATA_CBL_PATA40;
65 /**
66 * pacpi_discover_modes - filter non ACPI modes
67 * @adev: ATA device
68 * @mask: proposed modes
70 * Try the modes available and see which ones the ACPI method will
71 * set up sensibly. From this we get a mask of ACPI modes we can use
74 static unsigned long pacpi_discover_modes(struct ata_port *ap, struct ata_device *adev)
76 struct pata_acpi *acpi = ap->private_data;
77 struct ata_acpi_gtm probe;
78 unsigned int xfer_mask;
80 probe = acpi->gtm;
82 ata_acpi_gtm(ap, &probe);
84 xfer_mask = ata_acpi_gtm_xfermask(adev, &probe);
86 if (xfer_mask & (0xF8 << ATA_SHIFT_UDMA))
87 ap->cbl = ATA_CBL_PATA80;
89 return xfer_mask;
92 /**
93 * pacpi_mode_filter - mode filter for ACPI
94 * @adev: device
95 * @mask: mask of valid modes
97 * Filter the valid mode list according to our own specific rules, in
98 * this case the list of discovered valid modes obtained by ACPI probing
101 static unsigned long pacpi_mode_filter(struct ata_device *adev, unsigned long mask)
103 struct pata_acpi *acpi = adev->link->ap->private_data;
104 return mask & acpi->mask[adev->devno];
108 * pacpi_set_piomode - set initial PIO mode data
109 * @ap: ATA interface
110 * @adev: ATA device
113 static void pacpi_set_piomode(struct ata_port *ap, struct ata_device *adev)
115 int unit = adev->devno;
116 struct pata_acpi *acpi = ap->private_data;
117 const struct ata_timing *t;
119 if (!(acpi->gtm.flags & 0x10))
120 unit = 0;
122 /* Now stuff the nS values into the structure */
123 t = ata_timing_find_mode(adev->pio_mode);
124 acpi->gtm.drive[unit].pio = t->cycle;
125 ata_acpi_stm(ap, &acpi->gtm);
126 /* See what mode we actually got */
127 ata_acpi_gtm(ap, &acpi->gtm);
131 * pacpi_set_dmamode - set initial DMA mode data
132 * @ap: ATA interface
133 * @adev: ATA device
136 static void pacpi_set_dmamode(struct ata_port *ap, struct ata_device *adev)
138 int unit = adev->devno;
139 struct pata_acpi *acpi = ap->private_data;
140 const struct ata_timing *t;
142 if (!(acpi->gtm.flags & 0x10))
143 unit = 0;
145 /* Now stuff the nS values into the structure */
146 t = ata_timing_find_mode(adev->dma_mode);
147 if (adev->dma_mode >= XFER_UDMA_0) {
148 acpi->gtm.drive[unit].dma = t->udma;
149 acpi->gtm.flags |= (1 << (2 * unit));
150 } else {
151 acpi->gtm.drive[unit].dma = t->cycle;
152 acpi->gtm.flags &= ~(1 << (2 * unit));
154 ata_acpi_stm(ap, &acpi->gtm);
155 /* See what mode we actually got */
156 ata_acpi_gtm(ap, &acpi->gtm);
160 * pacpi_qc_issue - command issue
161 * @qc: command pending
163 * Called when the libata layer is about to issue a command. We wrap
164 * this interface so that we can load the correct ATA timings if
165 * necessary.
168 static unsigned int pacpi_qc_issue(struct ata_queued_cmd *qc)
170 struct ata_port *ap = qc->ap;
171 struct ata_device *adev = qc->dev;
172 struct pata_acpi *acpi = ap->private_data;
174 if (acpi->gtm.flags & 0x10)
175 return ata_bmdma_qc_issue(qc);
177 if (adev != acpi->last) {
178 pacpi_set_piomode(ap, adev);
179 if (ata_dma_enabled(adev))
180 pacpi_set_dmamode(ap, adev);
181 acpi->last = adev;
183 return ata_bmdma_qc_issue(qc);
187 * pacpi_port_start - port setup
188 * @ap: ATA port being set up
190 * Use the port_start hook to maintain private control structures
193 static int pacpi_port_start(struct ata_port *ap)
195 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
196 struct pata_acpi *acpi;
198 int ret;
200 if (ap->acpi_handle == NULL)
201 return -ENODEV;
203 acpi = ap->private_data = devm_kzalloc(&pdev->dev, sizeof(struct pata_acpi), GFP_KERNEL);
204 if (ap->private_data == NULL)
205 return -ENOMEM;
206 acpi->mask[0] = pacpi_discover_modes(ap, &ap->link.device[0]);
207 acpi->mask[1] = pacpi_discover_modes(ap, &ap->link.device[1]);
208 ret = ata_bmdma_port_start(ap);
209 if (ret < 0)
210 return ret;
212 return ret;
215 static struct scsi_host_template pacpi_sht = {
216 ATA_BMDMA_SHT(DRV_NAME),
219 static struct ata_port_operations pacpi_ops = {
220 .inherits = &ata_bmdma_port_ops,
221 .qc_issue = pacpi_qc_issue,
222 .cable_detect = pacpi_cable_detect,
223 .mode_filter = pacpi_mode_filter,
224 .set_piomode = pacpi_set_piomode,
225 .set_dmamode = pacpi_set_dmamode,
226 .prereset = pacpi_pre_reset,
227 .port_start = pacpi_port_start,
232 * pacpi_init_one - Register ACPI ATA PCI device with kernel services
233 * @pdev: PCI device to register
234 * @ent: Entry in pacpi_pci_tbl matching with @pdev
236 * Called from kernel PCI layer.
238 * LOCKING:
239 * Inherited from PCI layer (may sleep).
241 * RETURNS:
242 * Zero on success, or -ERRNO value.
245 static int pacpi_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
247 static const struct ata_port_info info = {
248 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
250 .pio_mask = ATA_PIO4,
251 .mwdma_mask = ATA_MWDMA2,
252 .udma_mask = ATA_UDMA6,
254 .port_ops = &pacpi_ops,
256 const struct ata_port_info *ppi[] = { &info, NULL };
257 if (pdev->vendor == PCI_VENDOR_ID_ATI) {
258 int rc = pcim_enable_device(pdev);
259 if (rc < 0)
260 return rc;
261 pcim_pin_device(pdev);
263 return ata_pci_bmdma_init_one(pdev, ppi, &pacpi_sht, NULL, 0);
266 static const struct pci_device_id pacpi_pci_tbl[] = {
267 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 1},
268 { } /* terminate list */
271 static struct pci_driver pacpi_pci_driver = {
272 .name = DRV_NAME,
273 .id_table = pacpi_pci_tbl,
274 .probe = pacpi_init_one,
275 .remove = ata_pci_remove_one,
276 #ifdef CONFIG_PM
277 .suspend = ata_pci_device_suspend,
278 .resume = ata_pci_device_resume,
279 #endif
282 static int __init pacpi_init(void)
284 return pci_register_driver(&pacpi_pci_driver);
287 static void __exit pacpi_exit(void)
289 pci_unregister_driver(&pacpi_pci_driver);
292 module_init(pacpi_init);
293 module_exit(pacpi_exit);
295 MODULE_AUTHOR("Alan Cox");
296 MODULE_DESCRIPTION("SCSI low-level driver for ATA in ACPI mode");
297 MODULE_LICENSE("GPL");
298 MODULE_DEVICE_TABLE(pci, pacpi_pci_tbl);
299 MODULE_VERSION(DRV_VERSION);