[ALSA] oxygen: more initialization
[zen-stable.git] / drivers / ata / pata_acpi.c
blob244098a80ce48c43e81c803f16ccb5fe9a60d3a6
1 /*
2 * ACPI PATA driver
4 * (c) 2007 Red Hat <alan@redhat.com>
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 <scsi/scsi_host.h>
15 #include <acpi/acpi_bus.h>
16 #include <acpi/acnames.h>
17 #include <acpi/acnamesp.h>
18 #include <acpi/acparser.h>
19 #include <acpi/acexcep.h>
20 #include <acpi/acmacros.h>
21 #include <acpi/actypes.h>
23 #include <linux/libata.h>
24 #include <linux/ata.h>
26 #define DRV_NAME "pata_acpi"
27 #define DRV_VERSION "0.2.3"
29 struct pata_acpi {
30 struct ata_acpi_gtm gtm;
31 void *last;
32 unsigned long mask[2];
35 /**
36 * pacpi_pre_reset - check for 40/80 pin
37 * @ap: Port
38 * @deadline: deadline jiffies for the operation
40 * Perform the PATA port setup we need.
43 static int pacpi_pre_reset(struct ata_link *link, unsigned long deadline)
45 struct ata_port *ap = link->ap;
46 struct pata_acpi *acpi = ap->private_data;
47 if (ap->acpi_handle == NULL || ata_acpi_gtm(ap, &acpi->gtm) < 0)
48 return -ENODEV;
50 return ata_std_prereset(link, deadline);
53 /**
54 * pacpi_cable_detect - cable type detection
55 * @ap: port to detect
57 * Perform device specific cable detection
60 static int pacpi_cable_detect(struct ata_port *ap)
62 struct pata_acpi *acpi = ap->private_data;
64 if ((acpi->mask[0] | acpi->mask[1]) & (0xF8 << ATA_SHIFT_UDMA))
65 return ATA_CBL_PATA80;
66 else
67 return ATA_CBL_PATA40;
70 /**
71 * pacpi_error_handler - Setup and error handler
72 * @ap: Port to handle
74 * LOCKING:
75 * None (inherited from caller).
78 static void pacpi_error_handler(struct ata_port *ap)
80 return ata_bmdma_drive_eh(ap, pacpi_pre_reset, ata_std_softreset,
81 NULL, ata_std_postreset);
84 /**
85 * pacpi_discover_modes - filter non ACPI modes
86 * @adev: ATA device
87 * @mask: proposed modes
89 * Try the modes available and see which ones the ACPI method will
90 * set up sensibly. From this we get a mask of ACPI modes we can use
93 static unsigned long pacpi_discover_modes(struct ata_port *ap, struct ata_device *adev)
95 struct pata_acpi *acpi = ap->private_data;
96 struct ata_acpi_gtm probe;
97 unsigned int xfer_mask;
99 probe = acpi->gtm;
101 ata_acpi_gtm(ap, &probe);
103 xfer_mask = ata_acpi_gtm_xfermask(adev, &probe);
105 if (xfer_mask & (0xF8 << ATA_SHIFT_UDMA))
106 ap->cbl = ATA_CBL_PATA80;
108 return xfer_mask;
112 * pacpi_mode_filter - mode filter for ACPI
113 * @adev: device
114 * @mask: mask of valid modes
116 * Filter the valid mode list according to our own specific rules, in
117 * this case the list of discovered valid modes obtained by ACPI probing
120 static unsigned long pacpi_mode_filter(struct ata_device *adev, unsigned long mask)
122 struct pata_acpi *acpi = adev->link->ap->private_data;
123 return ata_pci_default_filter(adev, mask & acpi->mask[adev->devno]);
127 * pacpi_set_piomode - set initial PIO mode data
128 * @ap: ATA interface
129 * @adev: ATA device
132 static void pacpi_set_piomode(struct ata_port *ap, struct ata_device *adev)
134 int unit = adev->devno;
135 struct pata_acpi *acpi = ap->private_data;
136 const struct ata_timing *t;
138 if (!(acpi->gtm.flags & 0x10))
139 unit = 0;
141 /* Now stuff the nS values into the structure */
142 t = ata_timing_find_mode(adev->pio_mode);
143 acpi->gtm.drive[unit].pio = t->cycle;
144 ata_acpi_stm(ap, &acpi->gtm);
145 /* See what mode we actually got */
146 ata_acpi_gtm(ap, &acpi->gtm);
150 * pacpi_set_dmamode - set initial DMA mode data
151 * @ap: ATA interface
152 * @adev: ATA device
155 static void pacpi_set_dmamode(struct ata_port *ap, struct ata_device *adev)
157 int unit = adev->devno;
158 struct pata_acpi *acpi = ap->private_data;
159 const struct ata_timing *t;
161 if (!(acpi->gtm.flags & 0x10))
162 unit = 0;
164 /* Now stuff the nS values into the structure */
165 t = ata_timing_find_mode(adev->dma_mode);
166 if (adev->dma_mode >= XFER_UDMA_0) {
167 acpi->gtm.drive[unit].dma = t->udma;
168 acpi->gtm.flags |= (1 << (2 * unit));
169 } else {
170 acpi->gtm.drive[unit].dma = t->cycle;
171 acpi->gtm.flags &= ~(1 << (2 * unit));
173 ata_acpi_stm(ap, &acpi->gtm);
174 /* See what mode we actually got */
175 ata_acpi_gtm(ap, &acpi->gtm);
179 * pacpi_qc_issue_prot - command issue
180 * @qc: command pending
182 * Called when the libata layer is about to issue a command. We wrap
183 * this interface so that we can load the correct ATA timings if
184 * neccessary.
187 static unsigned int pacpi_qc_issue_prot(struct ata_queued_cmd *qc)
189 struct ata_port *ap = qc->ap;
190 struct ata_device *adev = qc->dev;
191 struct pata_acpi *acpi = ap->private_data;
193 if (acpi->gtm.flags & 0x10)
194 return ata_qc_issue_prot(qc);
196 if (adev != acpi->last) {
197 pacpi_set_piomode(ap, adev);
198 if (adev->dma_mode)
199 pacpi_set_dmamode(ap, adev);
200 acpi->last = adev;
202 return ata_qc_issue_prot(qc);
206 * pacpi_port_start - port setup
207 * @ap: ATA port being set up
209 * Use the port_start hook to maintain private control structures
212 static int pacpi_port_start(struct ata_port *ap)
214 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
215 struct pata_acpi *acpi;
217 int ret;
219 if (ap->acpi_handle == NULL)
220 return -ENODEV;
222 acpi = ap->private_data = devm_kzalloc(&pdev->dev, sizeof(struct pata_acpi), GFP_KERNEL);
223 if (ap->private_data == NULL)
224 return -ENOMEM;
225 acpi->mask[0] = pacpi_discover_modes(ap, &ap->link.device[0]);
226 acpi->mask[1] = pacpi_discover_modes(ap, &ap->link.device[1]);
227 ret = ata_sff_port_start(ap);
228 if (ret < 0)
229 return ret;
231 return ret;
234 static struct scsi_host_template pacpi_sht = {
235 .module = THIS_MODULE,
236 .name = DRV_NAME,
237 .ioctl = ata_scsi_ioctl,
238 .queuecommand = ata_scsi_queuecmd,
239 .can_queue = ATA_DEF_QUEUE,
240 .this_id = ATA_SHT_THIS_ID,
241 .sg_tablesize = LIBATA_MAX_PRD,
242 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
243 .emulated = ATA_SHT_EMULATED,
244 .use_clustering = ATA_SHT_USE_CLUSTERING,
245 .proc_name = DRV_NAME,
246 .dma_boundary = ATA_DMA_BOUNDARY,
247 .slave_configure = ata_scsi_slave_config,
248 .slave_destroy = ata_scsi_slave_destroy,
249 /* Use standard CHS mapping rules */
250 .bios_param = ata_std_bios_param,
253 static const struct ata_port_operations pacpi_ops = {
254 .set_piomode = pacpi_set_piomode,
255 .set_dmamode = pacpi_set_dmamode,
256 .mode_filter = pacpi_mode_filter,
258 /* Task file is PCI ATA format, use helpers */
259 .tf_load = ata_tf_load,
260 .tf_read = ata_tf_read,
261 .check_status = ata_check_status,
262 .exec_command = ata_exec_command,
263 .dev_select = ata_std_dev_select,
265 .freeze = ata_bmdma_freeze,
266 .thaw = ata_bmdma_thaw,
267 .error_handler = pacpi_error_handler,
268 .post_internal_cmd = ata_bmdma_post_internal_cmd,
269 .cable_detect = pacpi_cable_detect,
271 /* BMDMA handling is PCI ATA format, use helpers */
272 .bmdma_setup = ata_bmdma_setup,
273 .bmdma_start = ata_bmdma_start,
274 .bmdma_stop = ata_bmdma_stop,
275 .bmdma_status = ata_bmdma_status,
276 .qc_prep = ata_qc_prep,
277 .qc_issue = pacpi_qc_issue_prot,
278 .data_xfer = ata_data_xfer,
280 /* Timeout handling */
281 .irq_handler = ata_interrupt,
282 .irq_clear = ata_bmdma_irq_clear,
283 .irq_on = ata_irq_on,
285 /* Generic PATA PCI ATA helpers */
286 .port_start = pacpi_port_start,
291 * pacpi_init_one - Register ACPI ATA PCI device with kernel services
292 * @pdev: PCI device to register
293 * @ent: Entry in pacpi_pci_tbl matching with @pdev
295 * Called from kernel PCI layer.
297 * LOCKING:
298 * Inherited from PCI layer (may sleep).
300 * RETURNS:
301 * Zero on success, or -ERRNO value.
304 static int pacpi_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
306 static const struct ata_port_info info = {
307 .sht = &pacpi_sht,
308 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
310 .pio_mask = 0x1f,
311 .mwdma_mask = 0x07,
312 .udma_mask = 0x7f,
314 .port_ops = &pacpi_ops,
316 const struct ata_port_info *ppi[] = { &info, NULL };
317 return ata_pci_init_one(pdev, ppi);
320 static const struct pci_device_id pacpi_pci_tbl[] = {
321 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 1},
322 { } /* terminate list */
325 static struct pci_driver pacpi_pci_driver = {
326 .name = DRV_NAME,
327 .id_table = pacpi_pci_tbl,
328 .probe = pacpi_init_one,
329 .remove = ata_pci_remove_one,
330 #ifdef CONFIG_PM
331 .suspend = ata_pci_device_suspend,
332 .resume = ata_pci_device_resume,
333 #endif
336 static int __init pacpi_init(void)
338 return pci_register_driver(&pacpi_pci_driver);
341 static void __exit pacpi_exit(void)
343 pci_unregister_driver(&pacpi_pci_driver);
346 module_init(pacpi_init);
347 module_exit(pacpi_exit);
349 MODULE_AUTHOR("Alan Cox");
350 MODULE_DESCRIPTION("SCSI low-level driver for ATA in ACPI mode");
351 MODULE_LICENSE("GPL");
352 MODULE_DEVICE_TABLE(pci, pacpi_pci_tbl);
353 MODULE_VERSION(DRV_VERSION);