12 #include <linux/kernel.h>
13 #include <linux/module.h>
16 #include <linux/slab.h>
36 #define DRV_NAME "pata_octeon_cf"
37 #define DRV_VERSION "2.1"
55 static unsigned int ns_to_tim_reg(
unsigned int tim_mult,
unsigned int nsecs)
69 static void octeon_cf_set_boot_reg_cfg(
int cs)
74 reg_cfg.s.tim_mult = 2;
124 trh = ns_to_tim_reg(2, 20);
132 octeon_cf_set_boot_reg_cfg(cs);
135 octeon_cf_set_boot_reg_cfg(cs + 1);
144 reg_tim.s.waitm = use_iordy;
154 reg_tim.s.pause =
pause;
156 reg_tim.s.wr_hld = trh;
158 reg_tim.s.rd_hld = trh;
164 reg_tim.s.ce = ns_to_tim_reg(2, 5);
181 unsigned int dma_ackh;
182 unsigned int dma_arq;
184 unsigned int T0, Tkr, Td;
185 unsigned int tim_mult;
201 pause = 25 - dma_arq * 1000 /
206 oe_n =
max(T0 - oe_a, Tkr);
208 dma_tim.s.dmack_pi = 1;
210 dma_tim.s.oe_n = ns_to_tim_reg(tim_mult, oe_n);
211 dma_tim.s.oe_a = ns_to_tim_reg(tim_mult, oe_a);
217 dma_tim.s.dmack_s = ns_to_tim_reg(tim_mult, 20);
218 dma_tim.s.dmack_h = ns_to_tim_reg(tim_mult, dma_ackh);
220 dma_tim.s.dmarq = dma_arq;
221 dma_tim.s.pause = ns_to_tim_reg(tim_mult, pause);
223 dma_tim.s.rd_dly = 0;
226 dma_tim.s.we_n = ns_to_tim_reg(tim_mult, oe_n);
227 dma_tim.s.we_a = ns_to_tim_reg(tim_mult, oe_a);
229 pr_debug(
"ns to ticks (mult %d) of %d is: %d\n", tim_mult, 60,
230 ns_to_tim_reg(tim_mult, 60));
231 pr_debug(
"oe_n: %d, oe_a: %d, dmack_s: %d, dmack_h: "
232 "%d, dmarq: %d, pause: %d\n",
233 dma_tim.s.oe_n, dma_tim.s.oe_a, dma_tim.s.dmack_s,
234 dma_tim.s.dmack_h, dma_tim.s.dmarq, dma_tim.s.pause);
249 static unsigned int octeon_cf_data_xfer8(
struct ata_device *dev,
270 ioread8(ap->ioaddr.altstatus_addr);
288 static unsigned int octeon_cf_data_xfer16(
struct ata_device *dev,
289 unsigned char *buffer,
294 void __iomem *data_addr = ap->ioaddr.data_addr;
309 ioread8(ap->ioaddr.altstatus_addr);
321 __le16 align_buf[1] = { 0 };
325 memcpy(buffer, align_buf, 1);
327 memcpy(align_buf, buffer, 1);
348 tf->
nsect = blob & 0xff;
349 tf->
lbal = blob >> 8;
352 tf->
lbam = blob & 0xff;
353 tf->
lbah = blob >> 8;
360 if (
likely(ap->ioaddr.ctl_addr)) {
375 ap->last_ctl = tf->
ctl;
382 static u8 octeon_cf_check_status16(
struct ata_port *ap)
385 void __iomem *base = ap->ioaddr.data_addr;
391 static int octeon_cf_softreset16(
struct ata_link *
link,
unsigned int *classes,
392 unsigned long deadline)
395 void __iomem *base = ap->ioaddr.data_addr;
399 DPRINTK(
"about to softreset\n");
414 DPRINTK(
"EXIT, classes[0]=%u [1]=%u\n", classes[0], classes[1]);
422 static void octeon_cf_tf_load16(
struct ata_port *ap,
427 void __iomem *base = ap->ioaddr.data_addr;
429 if (tf->
ctl != ap->last_ctl) {
431 ap->last_ctl = tf->
ctl;
438 VPRINTK(
"hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
449 VPRINTK(
"feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
460 static void octeon_cf_dev_select(
struct ata_port *ap,
unsigned int device)
470 static void octeon_cf_exec_command16(
struct ata_port *ap,
474 void __iomem *base = ap->ioaddr.data_addr;
492 static void octeon_cf_irq_on(
struct ata_port *ap)
496 static void octeon_cf_irq_clear(
struct ata_port *ap)
511 ap->
ops->sff_exec_command(ap, &qc->
tf);
536 mio_boot_dma_int.u64 = 0;
537 mio_boot_dma_int.s.done = 1;
539 mio_boot_dma_int.u64);
543 mio_boot_dma_int.u64);
546 mio_boot_dma_cfg.u64 = 0;
547 mio_boot_dma_cfg.s.en = 1;
558 mio_boot_dma_cfg.s.clr = 0;
561 mio_boot_dma_cfg.s.size =
sg_dma_len(sg) / 2 - 1;
564 mio_boot_dma_cfg.s.swap8 = 1;
568 VPRINTK(
"%s %d bytes address=%p\n",
569 (mio_boot_dma_cfg.s.rw) ?
"write" :
"read", sg->
length,
570 (
void *)(
unsigned long)mio_boot_dma_cfg.s.adr);
573 mio_boot_dma_cfg.u64);
582 static unsigned int octeon_cf_dma_finished(
struct ata_port *ap,
592 VPRINTK(
"ata%u: protocol %d task_state %d\n",
602 if (
dma_cfg.s.size != 0xfffff) {
621 status = ap->
ops->sff_check_status(ap);
635 static irqreturn_t octeon_cf_interrupt(
int irq,
void *dev_instance)
640 unsigned int handled = 0;
646 for (i = 0; i < host->
n_ports; i++) {
655 ocd = ap->
dev->platform_data;
662 qc = ata_qc_from_tag(ap, ap->
link.active_tag);
665 if (dma_int.s.done && !
dma_cfg.s.en) {
669 octeon_cf_dma_start(qc);
677 status =
ioread8(ap->ioaddr.altstatus_addr);
696 handled |= octeon_cf_dma_finished(ap, qc);
700 spin_unlock_irqrestore(&host->
lock, flags);
726 status =
ioread8(ap->ioaddr.altstatus_addr);
733 qc = ata_qc_from_tag(ap, ap->
link.active_tag);
735 octeon_cf_dma_finished(ap, qc);
737 spin_unlock_irqrestore(&host->
lock, flags);
740 static void octeon_cf_dev_config(
struct ata_device *dev)
762 switch (qc->
tf.protocol) {
766 ap->
ops->sff_tf_load(ap, &qc->
tf);
767 octeon_cf_dma_setup(qc);
768 octeon_cf_dma_start(qc);
773 dev_err(ap->
dev,
"Error, ATAPI not supported\n");
785 .check_atapi_dma = octeon_cf_check_atapi_dma,
787 .qc_issue = octeon_cf_qc_issue,
788 .sff_dev_select = octeon_cf_dev_select,
789 .sff_irq_on = octeon_cf_irq_on,
790 .sff_irq_clear = octeon_cf_irq_clear,
792 .set_piomode = octeon_cf_set_piomode,
793 .set_dmamode = octeon_cf_set_dmamode,
794 .dev_config = octeon_cf_dev_config,
817 ocd = pdev->
dev.platform_data;
820 resource_size(res_cs0));
832 resource_size(res_cs1));
838 cf_port = kzalloc(
sizeof(*cf_port),
GFP_KERNEL);
850 ap->
ops = &octeon_cf_ops;
856 ap->ioaddr.cmd_addr = base;
859 ap->ioaddr.altstatus_addr = base + 0xe;
860 ap->ioaddr.ctl_addr = base + 0xe;
861 octeon_cf_ops.sff_data_xfer = octeon_cf_data_xfer8;
864 ap->ioaddr.cmd_addr = base + (
ATA_REG_CMD << 1) + 1;
866 ap->ioaddr.error_addr = base + (
ATA_REG_ERR << 1) + 1;
874 ap->ioaddr.command_addr = base + (
ATA_REG_CMD << 1) + 1;
875 ap->ioaddr.altstatus_addr = cs1 + (6 << 1) + 1;
876 ap->ioaddr.ctl_addr = cs1 + (6 << 1) + 1;
877 octeon_cf_ops.sff_data_xfer = octeon_cf_data_xfer16;
881 irq_handler = octeon_cf_interrupt;
888 octeon_cf_delayed_finish);
892 octeon_cf_ops.sff_data_xfer = octeon_cf_data_xfer16;
893 octeon_cf_ops.
softreset = octeon_cf_softreset16;
894 octeon_cf_ops.sff_check_status = octeon_cf_check_status16;
895 octeon_cf_ops.sff_tf_read = octeon_cf_tf_read16;
896 octeon_cf_ops.sff_tf_load = octeon_cf_tf_load16;
897 octeon_cf_ops.sff_exec_command = octeon_cf_exec_command16;
902 ap->ioaddr.ctl_addr = base + 0xe;
903 ap->ioaddr.altstatus_addr = base + 0xe;
906 ata_port_desc(ap,
"cmd %p ctl %p", base, ap->ioaddr.ctl_addr);
909 snprintf(version,
sizeof(version),
"%s %d bit%s",
912 (cs1) ?
", True IDE" :
"");
923 .probe = octeon_cf_probe,
930 static int __init octeon_cf_init(
void)