29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/pci.h>
35 #include <linux/device.h>
40 #define DRV_NAME "pata_atp867x"
41 #define DRV_VERSION "0.7.5"
84 #define ATP867X_IOBASE(ap) ((ap)->host->iomap[0])
85 #define ATP867X_SYS_INFO(ap) (0x3F + ATP867X_IOBASE(ap))
87 #define ATP867X_IO_PORTBASE(ap, port) (0x00 + ATP867X_IOBASE(ap) + \
88 (port) * ATP867X_IO_CHANNEL_OFFSET)
89 #define ATP867X_IO_DMABASE(ap, port) (0x40 + \
90 ATP867X_IO_PORTBASE((ap), (port)))
92 #define ATP867X_IO_STATUS(ap, port) (0x07 + \
93 ATP867X_IO_PORTBASE((ap), (port)))
94 #define ATP867X_IO_ALTSTATUS(ap, port) (0x0E + \
95 ATP867X_IO_PORTBASE((ap), (port)))
100 #define ATP867X_IO_MSTRPIOSPD(ap, port) (0x08 + \
101 ATP867X_IO_DMABASE((ap), (port)))
102 #define ATP867X_IO_SLAVPIOSPD(ap, port) (0x09 + \
103 ATP867X_IO_DMABASE((ap), (port)))
104 #define ATP867X_IO_8BPIOSPD(ap, port) (0x0A + \
105 ATP867X_IO_DMABASE((ap), (port)))
106 #define ATP867X_IO_DMAMODE(ap, port) (0x0B + \
107 ATP867X_IO_DMABASE((ap), (port)))
109 #define ATP867X_IO_PORTSPD(ap, port) (0x4A + \
110 ATP867X_IO_PORTBASE((ap), (port)))
111 #define ATP867X_IO_PREREAD(ap, port) (0x4C + \
112 ATP867X_IO_PORTBASE((ap), (port)))
143 if (adev->
devno & 1) {
153 static int atp867x_get_active_clocks_shifted(
struct ata_port *ap,
157 unsigned char clocks = clk;
174 "Using 12clk.\n", clk);
181 goto active_clock_shift_done;
184 active_clock_shift_done:
188 static int atp867x_get_recover_clocks_shifted(
unsigned int clk)
190 unsigned char clocks = clk;
206 "Using default 12clk.\n", clk);
224 T = 1000000000 / 33333;
240 b = atp867x_get_active_clocks_shifted(ap,
t.active) |
241 atp867x_get_recover_clocks_shifted(
t.recover);
248 b = atp867x_get_active_clocks_shifted(ap,
t.act8b) |
249 atp867x_get_recover_clocks_shifted(
t.rec8b);
254 static int atp867x_cable_override(
struct pci_dev *pdev)
264 static int atp867x_cable_detect(
struct ata_port *ap)
268 if (atp867x_cable_override(pdev))
279 .inherits = &ata_bmdma_port_ops,
280 .cable_detect = atp867x_cable_detect,
281 .set_piomode = atp867x_set_piomode,
282 .set_dmamode = atp867x_set_dmamode,
287 static void atp867x_check_res(
struct pci_dev *pdev)
301 static void atp867x_check_ports(
struct ata_port *ap,
int port)
303 struct ata_ioports *ioaddr = &ap->ioaddr;
307 " cmd_addr =0x%llx, 0x%llx\n"
308 " ctl_addr =0x%llx, 0x%llx\n"
309 " bmdma_addr =0x%llx, 0x%llx\n"
310 " data_addr =0x%llx\n"
311 " error_addr =0x%llx\n"
312 " feature_addr =0x%llx\n"
313 " nsect_addr =0x%llx\n"
314 " lbal_addr =0x%llx\n"
315 " lbam_addr =0x%llx\n"
316 " lbah_addr =0x%llx\n"
317 " device_addr =0x%llx\n"
318 " status_addr =0x%llx\n"
319 " command_addr =0x%llx\n"
320 " dp->dma_mode =0x%llx\n"
321 " dp->mstr_piospd =0x%llx\n"
322 " dp->slave_piospd =0x%llx\n"
323 " dp->eightb_piospd =0x%llx\n"
324 " dp->pci66mhz =0x%lx\n",
326 (
unsigned long long)ioaddr->cmd_addr,
328 (
unsigned long long)ioaddr->ctl_addr,
330 (
unsigned long long)ioaddr->bmdma_addr,
332 (
unsigned long long)ioaddr->data_addr,
333 (
unsigned long long)ioaddr->error_addr,
334 (
unsigned long long)ioaddr->feature_addr,
335 (
unsigned long long)ioaddr->nsect_addr,
336 (
unsigned long long)ioaddr->lbal_addr,
337 (
unsigned long long)ioaddr->lbam_addr,
338 (
unsigned long long)ioaddr->lbah_addr,
339 (
unsigned long long)ioaddr->device_addr,
340 (
unsigned long long)ioaddr->status_addr,
341 (
unsigned long long)ioaddr->command_addr,
350 static int atp867x_set_priv(
struct ata_port *ap)
387 " to %d\n", pci_name(pdev), v);
418 static int atp867x_ata_pci_sff_init_host(
struct ata_host *host)
422 unsigned int mask = 0;
436 atp867x_check_res(pdev);
440 (
unsigned long long)(host->
iomap[i]));
446 for (i = 0; i < host->
n_ports; i++) {
448 struct ata_ioports *ioaddr = &ap->ioaddr;
451 ioaddr->ctl_addr = ioaddr->altstatus_addr
456 rc = atp867x_set_priv(ap);
461 atp867x_check_ports(ap, i);
464 (
unsigned long)ioaddr->cmd_addr,
465 (
unsigned long)ioaddr->ctl_addr);
467 (
unsigned long)ioaddr->bmdma_addr);
473 dev_err(gdev,
"no available native port\n");
487 static int atp867x_init_one(
struct pci_dev *pdev,
494 .port_ops = &atp867x_ops,
512 dev_err(&pdev->
dev,
"failed to allocate ATA host\n");
517 rc = atp867x_ata_pci_sff_init_host(host);
528 dev_err(&pdev->
dev,
"failed to activate host\n");
535 static int atp867x_reinit_one(
struct pci_dev *pdev)
540 rc = ata_pci_device_do_resume(pdev);
546 ata_host_resume(host);
559 .id_table = atp867x_pci_tbl,
560 .probe = atp867x_init_one,
561 .remove = ata_pci_remove_one,
563 .suspend = ata_pci_device_suspend,
564 .resume = atp867x_reinit_one,