aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/sata_via.c
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2007-02-17 15:09:59 -0500
committerJeff Garzik <jeff@garzik.org>2007-02-17 15:09:59 -0500
commit48c871c1f6a7c7044dd76774fb469e65c7e2e4e8 (patch)
treeda3aa535c98cc0957851354ceb0fbff7482d7a9d /drivers/ata/sata_via.c
parent1a1689344add3333d28d1b5495d8043a3877d01c (diff)
parent4409d28140d9a6e6e3f4f1fdaf7234c4b965d954 (diff)
Merge branch 'gfar' of master.kernel.org:/pub/scm/linux/kernel/git/galak/powerpc into upstream
Diffstat (limited to 'drivers/ata/sata_via.c')
-rw-r--r--drivers/ata/sata_via.c193
1 files changed, 137 insertions, 56 deletions
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index d3d5c0d57032..baca6d79bb0b 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -44,7 +44,6 @@
44#include <linux/device.h> 44#include <linux/device.h>
45#include <scsi/scsi_host.h> 45#include <scsi/scsi_host.h>
46#include <linux/libata.h> 46#include <linux/libata.h>
47#include <asm/io.h>
48 47
49#define DRV_NAME "sata_via" 48#define DRV_NAME "sata_via"
50#define DRV_VERSION "2.0" 49#define DRV_VERSION "2.0"
@@ -59,11 +58,14 @@ enum {
59 SATA_INT_GATE = 0x41, /* SATA interrupt gating */ 58 SATA_INT_GATE = 0x41, /* SATA interrupt gating */
60 SATA_NATIVE_MODE = 0x42, /* Native mode enable */ 59 SATA_NATIVE_MODE = 0x42, /* Native mode enable */
61 SATA_PATA_SHARING = 0x49, /* PATA/SATA sharing func ctrl */ 60 SATA_PATA_SHARING = 0x49, /* PATA/SATA sharing func ctrl */
62 61 PATA_UDMA_TIMING = 0xB3, /* PATA timing for DMA/ cable detect */
62 PATA_PIO_TIMING = 0xAB, /* PATA timing register */
63
63 PORT0 = (1 << 1), 64 PORT0 = (1 << 1),
64 PORT1 = (1 << 0), 65 PORT1 = (1 << 0),
65 ALL_PORTS = PORT0 | PORT1, 66 ALL_PORTS = PORT0 | PORT1,
66 N_PORTS = 2, 67 PATA_PORT = 2, /* PATA is port 2 */
68 N_PORTS = 3,
67 69
68 NATIVE_MODE_ALL = (1 << 7) | (1 << 6) | (1 << 5) | (1 << 4), 70 NATIVE_MODE_ALL = (1 << 7) | (1 << 6) | (1 << 5) | (1 << 4),
69 71
@@ -76,6 +78,11 @@ static u32 svia_scr_read (struct ata_port *ap, unsigned int sc_reg);
76static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 78static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
77static void svia_noop_freeze(struct ata_port *ap); 79static void svia_noop_freeze(struct ata_port *ap);
78static void vt6420_error_handler(struct ata_port *ap); 80static void vt6420_error_handler(struct ata_port *ap);
81static void vt6421_sata_error_handler(struct ata_port *ap);
82static void vt6421_pata_error_handler(struct ata_port *ap);
83static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev);
84static void vt6421_set_dma_mode(struct ata_port *ap, struct ata_device *adev);
85static int vt6421_port_start(struct ata_port *ap);
79 86
80static const struct pci_device_id svia_pci_tbl[] = { 87static const struct pci_device_id svia_pci_tbl[] = {
81 { PCI_VDEVICE(VIA, 0x5337), vt6420 }, 88 { PCI_VDEVICE(VIA, 0x5337), vt6420 },
@@ -127,7 +134,7 @@ static const struct ata_port_operations vt6420_sata_ops = {
127 134
128 .qc_prep = ata_qc_prep, 135 .qc_prep = ata_qc_prep,
129 .qc_issue = ata_qc_issue_prot, 136 .qc_issue = ata_qc_issue_prot,
130 .data_xfer = ata_pio_data_xfer, 137 .data_xfer = ata_data_xfer,
131 138
132 .freeze = svia_noop_freeze, 139 .freeze = svia_noop_freeze,
133 .thaw = ata_bmdma_thaw, 140 .thaw = ata_bmdma_thaw,
@@ -136,15 +143,49 @@ static const struct ata_port_operations vt6420_sata_ops = {
136 143
137 .irq_handler = ata_interrupt, 144 .irq_handler = ata_interrupt,
138 .irq_clear = ata_bmdma_irq_clear, 145 .irq_clear = ata_bmdma_irq_clear,
146 .irq_on = ata_irq_on,
147 .irq_ack = ata_irq_ack,
139 148
140 .port_start = ata_port_start, 149 .port_start = ata_port_start,
141 .port_stop = ata_port_stop,
142 .host_stop = ata_host_stop,
143}; 150};
144 151
145static const struct ata_port_operations vt6421_sata_ops = { 152static const struct ata_port_operations vt6421_pata_ops = {
146 .port_disable = ata_port_disable, 153 .port_disable = ata_port_disable,
154
155 .set_piomode = vt6421_set_pio_mode,
156 .set_dmamode = vt6421_set_dma_mode,
157
158 .tf_load = ata_tf_load,
159 .tf_read = ata_tf_read,
160 .check_status = ata_check_status,
161 .exec_command = ata_exec_command,
162 .dev_select = ata_std_dev_select,
163
164 .bmdma_setup = ata_bmdma_setup,
165 .bmdma_start = ata_bmdma_start,
166 .bmdma_stop = ata_bmdma_stop,
167 .bmdma_status = ata_bmdma_status,
168
169 .qc_prep = ata_qc_prep,
170 .qc_issue = ata_qc_issue_prot,
171 .data_xfer = ata_data_xfer,
172
173 .freeze = ata_bmdma_freeze,
174 .thaw = ata_bmdma_thaw,
175 .error_handler = vt6421_pata_error_handler,
176 .post_internal_cmd = ata_bmdma_post_internal_cmd,
147 177
178 .irq_handler = ata_interrupt,
179 .irq_clear = ata_bmdma_irq_clear,
180 .irq_on = ata_irq_on,
181 .irq_ack = ata_irq_ack,
182
183 .port_start = vt6421_port_start,
184};
185
186static const struct ata_port_operations vt6421_sata_ops = {
187 .port_disable = ata_port_disable,
188
148 .tf_load = ata_tf_load, 189 .tf_load = ata_tf_load,
149 .tf_read = ata_tf_read, 190 .tf_read = ata_tf_read,
150 .check_status = ata_check_status, 191 .check_status = ata_check_status,
@@ -158,22 +199,22 @@ static const struct ata_port_operations vt6421_sata_ops = {
158 199
159 .qc_prep = ata_qc_prep, 200 .qc_prep = ata_qc_prep,
160 .qc_issue = ata_qc_issue_prot, 201 .qc_issue = ata_qc_issue_prot,
161 .data_xfer = ata_pio_data_xfer, 202 .data_xfer = ata_data_xfer,
162 203
163 .freeze = ata_bmdma_freeze, 204 .freeze = ata_bmdma_freeze,
164 .thaw = ata_bmdma_thaw, 205 .thaw = ata_bmdma_thaw,
165 .error_handler = ata_bmdma_error_handler, 206 .error_handler = vt6421_sata_error_handler,
166 .post_internal_cmd = ata_bmdma_post_internal_cmd, 207 .post_internal_cmd = ata_bmdma_post_internal_cmd,
167 208
168 .irq_handler = ata_interrupt, 209 .irq_handler = ata_interrupt,
169 .irq_clear = ata_bmdma_irq_clear, 210 .irq_clear = ata_bmdma_irq_clear,
211 .irq_on = ata_irq_on,
212 .irq_ack = ata_irq_ack,
170 213
171 .scr_read = svia_scr_read, 214 .scr_read = svia_scr_read,
172 .scr_write = svia_scr_write, 215 .scr_write = svia_scr_write,
173 216
174 .port_start = ata_port_start, 217 .port_start = vt6421_port_start,
175 .port_stop = ata_port_stop,
176 .host_stop = ata_host_stop,
177}; 218};
178 219
179static struct ata_port_info vt6420_port_info = { 220static struct ata_port_info vt6420_port_info = {
@@ -195,14 +236,14 @@ static u32 svia_scr_read (struct ata_port *ap, unsigned int sc_reg)
195{ 236{
196 if (sc_reg > SCR_CONTROL) 237 if (sc_reg > SCR_CONTROL)
197 return 0xffffffffU; 238 return 0xffffffffU;
198 return inl(ap->ioaddr.scr_addr + (4 * sc_reg)); 239 return ioread32(ap->ioaddr.scr_addr + (4 * sc_reg));
199} 240}
200 241
201static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) 242static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
202{ 243{
203 if (sc_reg > SCR_CONTROL) 244 if (sc_reg > SCR_CONTROL)
204 return; 245 return;
205 outl(val, ap->ioaddr.scr_addr + (4 * sc_reg)); 246 iowrite32(val, ap->ioaddr.scr_addr + (4 * sc_reg));
206} 247}
207 248
208static void svia_noop_freeze(struct ata_port *ap) 249static void svia_noop_freeze(struct ata_port *ap)
@@ -289,6 +330,61 @@ static void vt6420_error_handler(struct ata_port *ap)
289 NULL, ata_std_postreset); 330 NULL, ata_std_postreset);
290} 331}
291 332
333static int vt6421_pata_prereset(struct ata_port *ap)
334{
335 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
336 u8 tmp;
337
338 pci_read_config_byte(pdev, PATA_UDMA_TIMING, &tmp);
339 if (tmp & 0x10)
340 ap->cbl = ATA_CBL_PATA40;
341 else
342 ap->cbl = ATA_CBL_PATA80;
343 return 0;
344}
345
346static void vt6421_pata_error_handler(struct ata_port *ap)
347{
348 return ata_bmdma_drive_eh(ap, vt6421_pata_prereset, ata_std_softreset,
349 NULL, ata_std_postreset);
350}
351
352static int vt6421_sata_prereset(struct ata_port *ap)
353{
354 ap->cbl = ATA_CBL_SATA;
355 return 0;
356}
357
358static void vt6421_sata_error_handler(struct ata_port *ap)
359{
360 return ata_bmdma_drive_eh(ap, vt6421_sata_prereset, ata_std_softreset,
361 NULL, ata_std_postreset);
362}
363
364static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev)
365{
366 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
367 static const u8 pio_bits[] = { 0xA8, 0x65, 0x65, 0x31, 0x20 };
368 pci_write_config_byte(pdev, PATA_PIO_TIMING, pio_bits[adev->pio_mode - XFER_PIO_0]);
369}
370
371static void vt6421_set_dma_mode(struct ata_port *ap, struct ata_device *adev)
372{
373 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
374 static const u8 udma_bits[] = { 0xEE, 0xE8, 0xE6, 0xE4, 0xE2, 0xE1, 0xE0, 0xE0 };
375 pci_write_config_byte(pdev, PATA_UDMA_TIMING, udma_bits[adev->pio_mode - XFER_UDMA_0]);
376}
377
378static int vt6421_port_start(struct ata_port *ap)
379{
380 if (ap->port_no == PATA_PORT) {
381 ap->ops = &vt6421_pata_ops;
382 ap->mwdma_mask = 0;
383 ap->flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_LEGACY | ATA_FLAG_SRST;
384 }
385 return ata_port_start(ap);
386}
387
292static const unsigned int svia_bar_sizes[] = { 388static const unsigned int svia_bar_sizes[] = {
293 8, 4, 8, 4, 16, 256 389 8, 4, 8, 4, 16, 256
294}; 390};
@@ -297,31 +393,28 @@ static const unsigned int vt6421_bar_sizes[] = {
297 16, 16, 16, 16, 32, 128 393 16, 16, 16, 16, 32, 128
298}; 394};
299 395
300static unsigned long svia_scr_addr(unsigned long addr, unsigned int port) 396static void __iomem * svia_scr_addr(void __iomem *addr, unsigned int port)
301{ 397{
302 return addr + (port * 128); 398 return addr + (port * 128);
303} 399}
304 400
305static unsigned long vt6421_scr_addr(unsigned long addr, unsigned int port) 401static void __iomem * vt6421_scr_addr(void __iomem *addr, unsigned int port)
306{ 402{
307 return addr + (port * 64); 403 return addr + (port * 64);
308} 404}
309 405
310static void vt6421_init_addrs(struct ata_probe_ent *probe_ent, 406static void vt6421_init_addrs(struct ata_probe_ent *probe_ent,
311 struct pci_dev *pdev, 407 void __iomem * const *iomap, unsigned int port)
312 unsigned int port)
313{ 408{
314 unsigned long reg_addr = pci_resource_start(pdev, port); 409 void __iomem *reg_addr = iomap[port];
315 unsigned long bmdma_addr = pci_resource_start(pdev, 4) + (port * 8); 410 void __iomem *bmdma_addr = iomap[4] + (port * 8);
316 unsigned long scr_addr;
317 411
318 probe_ent->port[port].cmd_addr = reg_addr; 412 probe_ent->port[port].cmd_addr = reg_addr;
319 probe_ent->port[port].altstatus_addr = 413 probe_ent->port[port].altstatus_addr =
320 probe_ent->port[port].ctl_addr = (reg_addr + 8) | ATA_PCI_CTL_OFS; 414 probe_ent->port[port].ctl_addr = (void __iomem *)
415 ((unsigned long)(reg_addr + 8) | ATA_PCI_CTL_OFS);
321 probe_ent->port[port].bmdma_addr = bmdma_addr; 416 probe_ent->port[port].bmdma_addr = bmdma_addr;
322 417 probe_ent->port[port].scr_addr = vt6421_scr_addr(iomap[5], port);
323 scr_addr = vt6421_scr_addr(pci_resource_start(pdev, 5), port);
324 probe_ent->port[port].scr_addr = scr_addr;
325 418
326 ata_std_ports(&probe_ent->port[port]); 419 ata_std_ports(&probe_ent->port[port]);
327} 420}
@@ -330,16 +423,16 @@ static struct ata_probe_ent *vt6420_init_probe_ent(struct pci_dev *pdev)
330{ 423{
331 struct ata_probe_ent *probe_ent; 424 struct ata_probe_ent *probe_ent;
332 struct ata_port_info *ppi[2]; 425 struct ata_port_info *ppi[2];
333 426 void __iomem * const *iomap;
427
334 ppi[0] = ppi[1] = &vt6420_port_info; 428 ppi[0] = ppi[1] = &vt6420_port_info;
335 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 429 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
336 if (!probe_ent) 430 if (!probe_ent)
337 return NULL; 431 return NULL;
338 432
339 probe_ent->port[0].scr_addr = 433 iomap = pcim_iomap_table(pdev);
340 svia_scr_addr(pci_resource_start(pdev, 5), 0); 434 probe_ent->port[0].scr_addr = svia_scr_addr(iomap[5], 0);
341 probe_ent->port[1].scr_addr = 435 probe_ent->port[1].scr_addr = svia_scr_addr(iomap[5], 1);
342 svia_scr_addr(pci_resource_start(pdev, 5), 1);
343 436
344 return probe_ent; 437 return probe_ent;
345} 438}
@@ -349,7 +442,7 @@ static struct ata_probe_ent *vt6421_init_probe_ent(struct pci_dev *pdev)
349 struct ata_probe_ent *probe_ent; 442 struct ata_probe_ent *probe_ent;
350 unsigned int i; 443 unsigned int i;
351 444
352 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 445 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
353 if (!probe_ent) 446 if (!probe_ent)
354 return NULL; 447 return NULL;
355 448
@@ -368,7 +461,7 @@ static struct ata_probe_ent *vt6421_init_probe_ent(struct pci_dev *pdev)
368 probe_ent->udma_mask = 0x7f; 461 probe_ent->udma_mask = 0x7f;
369 462
370 for (i = 0; i < N_PORTS; i++) 463 for (i = 0; i < N_PORTS; i++)
371 vt6421_init_addrs(probe_ent, pdev, i); 464 vt6421_init_addrs(probe_ent, pcim_iomap_table(pdev), i);
372 465
373 return probe_ent; 466 return probe_ent;
374} 467}
@@ -420,20 +513,19 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
420 struct ata_probe_ent *probe_ent; 513 struct ata_probe_ent *probe_ent;
421 int board_id = (int) ent->driver_data; 514 int board_id = (int) ent->driver_data;
422 const int *bar_sizes; 515 const int *bar_sizes;
423 int pci_dev_busy = 0;
424 u8 tmp8; 516 u8 tmp8;
425 517
426 if (!printed_version++) 518 if (!printed_version++)
427 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 519 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
428 520
429 rc = pci_enable_device(pdev); 521 rc = pcim_enable_device(pdev);
430 if (rc) 522 if (rc)
431 return rc; 523 return rc;
432 524
433 rc = pci_request_regions(pdev, DRV_NAME); 525 rc = pcim_iomap_regions(pdev, 0x1f, DRV_NAME);
434 if (rc) { 526 if (rc) {
435 pci_dev_busy = 1; 527 pcim_pin_device(pdev);
436 goto err_out; 528 return rc;
437 } 529 }
438 530
439 if (board_id == vt6420) { 531 if (board_id == vt6420) {
@@ -442,8 +534,7 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
442 dev_printk(KERN_ERR, &pdev->dev, 534 dev_printk(KERN_ERR, &pdev->dev,
443 "SATA master/slave not supported (0x%x)\n", 535 "SATA master/slave not supported (0x%x)\n",
444 (int) tmp8); 536 (int) tmp8);
445 rc = -EIO; 537 return -EIO;
446 goto err_out_regions;
447 } 538 }
448 539
449 bar_sizes = &svia_bar_sizes[0]; 540 bar_sizes = &svia_bar_sizes[0];
@@ -459,16 +550,15 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
459 i, 550 i,
460 (unsigned long long)pci_resource_start(pdev, i), 551 (unsigned long long)pci_resource_start(pdev, i),
461 (unsigned long long)pci_resource_len(pdev, i)); 552 (unsigned long long)pci_resource_len(pdev, i));
462 rc = -ENODEV; 553 return -ENODEV;
463 goto err_out_regions;
464 } 554 }
465 555
466 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 556 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
467 if (rc) 557 if (rc)
468 goto err_out_regions; 558 return rc;
469 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); 559 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
470 if (rc) 560 if (rc)
471 goto err_out_regions; 561 return rc;
472 562
473 if (board_id == vt6420) 563 if (board_id == vt6420)
474 probe_ent = vt6420_init_probe_ent(pdev); 564 probe_ent = vt6420_init_probe_ent(pdev);
@@ -477,26 +567,18 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
477 567
478 if (!probe_ent) { 568 if (!probe_ent) {
479 dev_printk(KERN_ERR, &pdev->dev, "out of memory\n"); 569 dev_printk(KERN_ERR, &pdev->dev, "out of memory\n");
480 rc = -ENOMEM; 570 return -ENOMEM;
481 goto err_out_regions;
482 } 571 }
483 572
484 svia_configure(pdev); 573 svia_configure(pdev);
485 574
486 pci_set_master(pdev); 575 pci_set_master(pdev);
487 576
488 /* FIXME: check ata_device_add return value */ 577 if (!ata_device_add(probe_ent))
489 ata_device_add(probe_ent); 578 return -ENODEV;
490 kfree(probe_ent);
491 579
580 devm_kfree(&pdev->dev, probe_ent);
492 return 0; 581 return 0;
493
494err_out_regions:
495 pci_release_regions(pdev);
496err_out:
497 if (!pci_dev_busy)
498 pci_disable_device(pdev);
499 return rc;
500} 582}
501 583
502static int __init svia_init(void) 584static int __init svia_init(void)
@@ -511,4 +593,3 @@ static void __exit svia_exit(void)
511 593
512module_init(svia_init); 594module_init(svia_init);
513module_exit(svia_exit); 595module_exit(svia_exit);
514