Lines Matching +full:rcar +full:- +full:gen2 +full:- +full:sata
1 // SPDX-License-Identifier: GPL-2.0+
3 * Renesas R-Car SATA driver
6 * Copyright (C) 2013-2015 Cogent Embedded, Inc.
7 * Copyright (C) 2013-2015 Renesas Solutions Corp.
21 /* SH-Navi2G/ATAPI module compatible control registers */
82 /* Serial-ATA HOST control registers */
95 /* SATA INT status register (SATAINTSTAT) bits */
99 /* SATA INT mask register (SATAINTSTAT) bits */
121 /* Gen2 Physical Layer Control Registers */
155 void __iomem *base = priv->base; in sata_rcar_gen1_phy_preinit()
169 void __iomem *base = priv->base; in sata_rcar_gen1_phy_write()
208 void __iomem *base = priv->base; in sata_rcar_gen2_phy_init()
220 struct sata_rcar_priv *priv = ap->host->private_data; in sata_rcar_freeze()
223 iowrite32(priv->sataint_mask, priv->base + SATAINTMASK_REG); in sata_rcar_freeze()
230 struct sata_rcar_priv *priv = ap->host->private_data; in sata_rcar_thaw()
231 void __iomem *base = priv->base; in sata_rcar_thaw()
239 iowrite32(priv->sataint_mask & ~SATA_RCAR_INT_MASK, base + SATAINTMASK_REG); in sata_rcar_thaw()
246 while (count--) { in sata_rcar_ioread16_rep()
257 while (count--) in sata_rcar_iowrite16_rep()
263 return ioread32(ap->ioaddr.status_addr); in sata_rcar_check_status()
268 return ioread32(ap->ioaddr.altstatus_addr); in sata_rcar_check_altstatus()
273 iowrite32(ctl, ap->ioaddr.ctl_addr); in sata_rcar_set_devctl()
278 iowrite32(ATA_DEVICE_OBS, ap->ioaddr.device_addr); in sata_rcar_dev_select()
284 struct ata_ioports *ioaddr = &ap->ioaddr; in sata_rcar_ata_devchk()
289 iowrite32(0x55, ioaddr->nsect_addr); in sata_rcar_ata_devchk()
290 iowrite32(0xaa, ioaddr->lbal_addr); in sata_rcar_ata_devchk()
292 iowrite32(0xaa, ioaddr->nsect_addr); in sata_rcar_ata_devchk()
293 iowrite32(0x55, ioaddr->lbal_addr); in sata_rcar_ata_devchk()
295 iowrite32(0x55, ioaddr->nsect_addr); in sata_rcar_ata_devchk()
296 iowrite32(0xaa, ioaddr->lbal_addr); in sata_rcar_ata_devchk()
298 nsect = ioread32(ioaddr->nsect_addr); in sata_rcar_ata_devchk()
299 lbal = ioread32(ioaddr->lbal_addr); in sata_rcar_ata_devchk()
310 struct ata_port *ap = link->ap; in sata_rcar_wait_after_reset()
319 struct ata_ioports *ioaddr = &ap->ioaddr; in sata_rcar_bus_softreset()
322 iowrite32(ap->ctl, ioaddr->ctl_addr); in sata_rcar_bus_softreset()
324 iowrite32(ap->ctl | ATA_SRST, ioaddr->ctl_addr); in sata_rcar_bus_softreset()
326 iowrite32(ap->ctl, ioaddr->ctl_addr); in sata_rcar_bus_softreset()
327 ap->last_ctl = ap->ctl; in sata_rcar_bus_softreset()
330 return sata_rcar_wait_after_reset(&ap->link, deadline); in sata_rcar_bus_softreset()
336 struct ata_port *ap = link->ap; in sata_rcar_softreset()
347 /* if link is occupied, -ENODEV too is an error */ in sata_rcar_softreset()
348 if (rc && (rc != -ENODEV || sata_scr_valid(link))) { in sata_rcar_softreset()
354 classes[0] = ata_sff_dev_classify(&link->device[0], devmask, &err); in sata_rcar_softreset()
362 struct ata_ioports *ioaddr = &ap->ioaddr; in sata_rcar_tf_load()
363 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; in sata_rcar_tf_load()
365 if (tf->ctl != ap->last_ctl) { in sata_rcar_tf_load()
366 iowrite32(tf->ctl, ioaddr->ctl_addr); in sata_rcar_tf_load()
367 ap->last_ctl = tf->ctl; in sata_rcar_tf_load()
371 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { in sata_rcar_tf_load()
372 iowrite32(tf->hob_feature, ioaddr->feature_addr); in sata_rcar_tf_load()
373 iowrite32(tf->hob_nsect, ioaddr->nsect_addr); in sata_rcar_tf_load()
374 iowrite32(tf->hob_lbal, ioaddr->lbal_addr); in sata_rcar_tf_load()
375 iowrite32(tf->hob_lbam, ioaddr->lbam_addr); in sata_rcar_tf_load()
376 iowrite32(tf->hob_lbah, ioaddr->lbah_addr); in sata_rcar_tf_load()
380 iowrite32(tf->feature, ioaddr->feature_addr); in sata_rcar_tf_load()
381 iowrite32(tf->nsect, ioaddr->nsect_addr); in sata_rcar_tf_load()
382 iowrite32(tf->lbal, ioaddr->lbal_addr); in sata_rcar_tf_load()
383 iowrite32(tf->lbam, ioaddr->lbam_addr); in sata_rcar_tf_load()
384 iowrite32(tf->lbah, ioaddr->lbah_addr); in sata_rcar_tf_load()
387 if (tf->flags & ATA_TFLAG_DEVICE) in sata_rcar_tf_load()
388 iowrite32(tf->device, ioaddr->device_addr); in sata_rcar_tf_load()
395 struct ata_ioports *ioaddr = &ap->ioaddr; in sata_rcar_tf_read()
397 tf->status = sata_rcar_check_status(ap); in sata_rcar_tf_read()
398 tf->error = ioread32(ioaddr->error_addr); in sata_rcar_tf_read()
399 tf->nsect = ioread32(ioaddr->nsect_addr); in sata_rcar_tf_read()
400 tf->lbal = ioread32(ioaddr->lbal_addr); in sata_rcar_tf_read()
401 tf->lbam = ioread32(ioaddr->lbam_addr); in sata_rcar_tf_read()
402 tf->lbah = ioread32(ioaddr->lbah_addr); in sata_rcar_tf_read()
403 tf->device = ioread32(ioaddr->device_addr); in sata_rcar_tf_read()
405 if (tf->flags & ATA_TFLAG_LBA48) { in sata_rcar_tf_read()
406 iowrite32(tf->ctl | ATA_HOB, ioaddr->ctl_addr); in sata_rcar_tf_read()
407 tf->hob_feature = ioread32(ioaddr->error_addr); in sata_rcar_tf_read()
408 tf->hob_nsect = ioread32(ioaddr->nsect_addr); in sata_rcar_tf_read()
409 tf->hob_lbal = ioread32(ioaddr->lbal_addr); in sata_rcar_tf_read()
410 tf->hob_lbam = ioread32(ioaddr->lbam_addr); in sata_rcar_tf_read()
411 tf->hob_lbah = ioread32(ioaddr->lbah_addr); in sata_rcar_tf_read()
412 iowrite32(tf->ctl, ioaddr->ctl_addr); in sata_rcar_tf_read()
413 ap->last_ctl = tf->ctl; in sata_rcar_tf_read()
420 iowrite32(tf->command, ap->ioaddr.command_addr); in sata_rcar_exec_command()
428 struct ata_port *ap = qc->dev->link->ap; in sata_rcar_data_xfer()
429 void __iomem *data_addr = ap->ioaddr.data_addr; in sata_rcar_data_xfer()
443 buf += buflen - 1; in sata_rcar_data_xfer()
468 if (qc == NULL || qc->dma_dir == DMA_TO_DEVICE) in sata_rcar_drain_fifo()
471 ap = qc->ap; in sata_rcar_drain_fifo()
473 for (count = 0; (ap->ops->sff_check_status(ap) & ATA_DRQ) && in sata_rcar_drain_fifo()
475 ioread32(ap->ioaddr.data_addr); in sata_rcar_drain_fifo()
485 return -EINVAL; in sata_rcar_scr_read()
487 *val = ioread32(link->ap->ioaddr.scr_addr + (sc_reg << 2)); in sata_rcar_scr_read()
495 return -EINVAL; in sata_rcar_scr_write()
497 iowrite32(val, link->ap->ioaddr.scr_addr + (sc_reg << 2)); in sata_rcar_scr_write()
503 struct ata_port *ap = qc->ap; in sata_rcar_bmdma_fill_sg()
504 struct ata_bmdma_prd *prd = ap->bmdma_prd; in sata_rcar_bmdma_fill_sg()
508 for_each_sg(qc->sg, sg, qc->n_elem, si) { in sata_rcar_bmdma_fill_sg()
512 * Note: h/w doesn't support 64-bit, so we unconditionally in sata_rcar_bmdma_fill_sg()
522 /* end-of-table flag */ in sata_rcar_bmdma_fill_sg()
523 prd[si - 1].addr |= cpu_to_le32(SATA_RCAR_DTEND); in sata_rcar_bmdma_fill_sg()
528 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) in sata_rcar_qc_prep()
538 struct ata_port *ap = qc->ap; in sata_rcar_bmdma_setup()
539 unsigned int rw = qc->tf.flags & ATA_TFLAG_WRITE; in sata_rcar_bmdma_setup()
540 struct sata_rcar_priv *priv = ap->host->private_data; in sata_rcar_bmdma_setup()
541 void __iomem *base = priv->base; in sata_rcar_bmdma_setup()
546 iowrite32(ap->bmdma_prd_dma, base + ATAPI_DTB_ADR_REG); in sata_rcar_bmdma_setup()
548 /* specify data direction, triple-check start bit is clear */ in sata_rcar_bmdma_setup()
560 ap->ops->sff_exec_command(ap, &qc->tf); in sata_rcar_bmdma_setup()
565 struct ata_port *ap = qc->ap; in sata_rcar_bmdma_start()
566 struct sata_rcar_priv *priv = ap->host->private_data; in sata_rcar_bmdma_start()
567 void __iomem *base = priv->base; in sata_rcar_bmdma_start()
579 struct ata_port *ap = qc->ap; in sata_rcar_bmdma_stop()
580 struct sata_rcar_priv *priv = ap->host->private_data; in sata_rcar_bmdma_stop()
581 void __iomem *base = priv->base; in sata_rcar_bmdma_stop()
592 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ in sata_rcar_bmdma_stop()
598 struct sata_rcar_priv *priv = ap->host->private_data; in sata_rcar_bmdma_status()
602 status = ioread32(priv->base + ATAPI_STATUS_REG); in sata_rcar_bmdma_status()
652 struct sata_rcar_priv *priv = ap->host->private_data; in sata_rcar_serr_interrupt()
653 struct ata_eh_info *ehi = &ap->link.eh_info; in sata_rcar_serr_interrupt()
657 serror = ioread32(priv->base + SCRSERR_REG); in sata_rcar_serr_interrupt()
667 /* Setup a soft-reset EH action */ in sata_rcar_serr_interrupt()
686 qc = ata_qc_from_tag(ap, ap->link.active_tag); in sata_rcar_ata_interrupt()
698 struct sata_rcar_priv *priv = host->private_data; in sata_rcar_interrupt()
699 void __iomem *base = priv->base; in sata_rcar_interrupt()
705 spin_lock_irqsave(&host->lock, flags); in sata_rcar_interrupt()
712 iowrite32(~sataintstat & priv->sataint_mask, base + SATAINTSTAT_REG); in sata_rcar_interrupt()
714 ap = host->ports[0]; in sata_rcar_interrupt()
724 spin_unlock_irqrestore(&host->lock, flags); in sata_rcar_interrupt()
731 struct ata_port *ap = host->ports[0]; in sata_rcar_setup_port()
732 struct ata_ioports *ioaddr = &ap->ioaddr; in sata_rcar_setup_port()
733 struct sata_rcar_priv *priv = host->private_data; in sata_rcar_setup_port()
734 void __iomem *base = priv->base; in sata_rcar_setup_port()
736 ap->ops = &sata_rcar_port_ops; in sata_rcar_setup_port()
737 ap->pio_mask = ATA_PIO4; in sata_rcar_setup_port()
738 ap->udma_mask = ATA_UDMA6; in sata_rcar_setup_port()
739 ap->flags |= ATA_FLAG_SATA; in sata_rcar_setup_port()
741 if (priv->type == RCAR_R8A7790_ES1_SATA) in sata_rcar_setup_port()
742 ap->flags |= ATA_FLAG_NO_DIPM; in sata_rcar_setup_port()
744 ioaddr->cmd_addr = base + SDATA_REG; in sata_rcar_setup_port()
745 ioaddr->ctl_addr = base + SSDEVCON_REG; in sata_rcar_setup_port()
746 ioaddr->scr_addr = base + SCRSSTS_REG; in sata_rcar_setup_port()
747 ioaddr->altstatus_addr = ioaddr->ctl_addr; in sata_rcar_setup_port()
749 ioaddr->data_addr = ioaddr->cmd_addr + (ATA_REG_DATA << 2); in sata_rcar_setup_port()
750 ioaddr->error_addr = ioaddr->cmd_addr + (ATA_REG_ERR << 2); in sata_rcar_setup_port()
751 ioaddr->feature_addr = ioaddr->cmd_addr + (ATA_REG_FEATURE << 2); in sata_rcar_setup_port()
752 ioaddr->nsect_addr = ioaddr->cmd_addr + (ATA_REG_NSECT << 2); in sata_rcar_setup_port()
753 ioaddr->lbal_addr = ioaddr->cmd_addr + (ATA_REG_LBAL << 2); in sata_rcar_setup_port()
754 ioaddr->lbam_addr = ioaddr->cmd_addr + (ATA_REG_LBAM << 2); in sata_rcar_setup_port()
755 ioaddr->lbah_addr = ioaddr->cmd_addr + (ATA_REG_LBAH << 2); in sata_rcar_setup_port()
756 ioaddr->device_addr = ioaddr->cmd_addr + (ATA_REG_DEVICE << 2); in sata_rcar_setup_port()
757 ioaddr->status_addr = ioaddr->cmd_addr + (ATA_REG_STATUS << 2); in sata_rcar_setup_port()
758 ioaddr->command_addr = ioaddr->cmd_addr + (ATA_REG_CMD << 2); in sata_rcar_setup_port()
763 void __iomem *base = priv->base; in sata_rcar_init_module()
766 /* SATA-IP reset state */ in sata_rcar_init_module()
778 /* Release the SATA-IP from the reset state */ in sata_rcar_init_module()
785 iowrite32(priv->sataint_mask, base + SATAINTMASK_REG); in sata_rcar_init_module()
793 struct sata_rcar_priv *priv = host->private_data; in sata_rcar_init_controller()
795 priv->sataint_mask = SATAINTMASK_ALL_GEN2; in sata_rcar_init_controller()
798 switch (priv->type) { in sata_rcar_init_controller()
800 priv->sataint_mask = SATAINTMASK_ALL_GEN1; in sata_rcar_init_controller()
810 dev_warn(host->dev, "SATA phy is not initialized\n"); in sata_rcar_init_controller()
819 /* Deprecated by "renesas,sata-r8a7779" */
820 .compatible = "renesas,rcar-sata",
824 .compatible = "renesas,sata-r8a7779",
828 .compatible = "renesas,sata-r8a7790",
832 .compatible = "renesas,sata-r8a7790-es1",
836 .compatible = "renesas,sata-r8a7791",
840 .compatible = "renesas,sata-r8a7793",
844 .compatible = "renesas,sata-r8a7795",
848 .compatible = "renesas,rcar-gen2-sata",
852 .compatible = "renesas,rcar-gen3-sata",
861 struct device *dev = &pdev->dev; in sata_rcar_probe()
872 return -ENOMEM; in sata_rcar_probe()
874 priv->type = (unsigned long)of_device_get_match_data(dev); in sata_rcar_probe()
883 ret = -ENOMEM; in sata_rcar_probe()
887 host->private_data = priv; in sata_rcar_probe()
889 priv->base = devm_platform_ioremap_resource(pdev, 0); in sata_rcar_probe()
890 if (IS_ERR(priv->base)) { in sata_rcar_probe()
891 ret = PTR_ERR(priv->base); in sata_rcar_probe()
915 struct sata_rcar_priv *priv = host->private_data; in sata_rcar_remove()
916 void __iomem *base = priv->base; in sata_rcar_remove()
924 iowrite32(priv->sataint_mask, base + SATAINTMASK_REG); in sata_rcar_remove()
926 pm_runtime_put(&pdev->dev); in sata_rcar_remove()
927 pm_runtime_disable(&pdev->dev); in sata_rcar_remove()
934 struct sata_rcar_priv *priv = host->private_data; in sata_rcar_suspend()
935 void __iomem *base = priv->base; in sata_rcar_suspend()
942 iowrite32(priv->sataint_mask, base + SATAINTMASK_REG); in sata_rcar_suspend()
952 struct sata_rcar_priv *priv = host->private_data; in sata_rcar_resume()
953 void __iomem *base = priv->base; in sata_rcar_resume()
962 if (priv->type == RCAR_GEN3_SATA) { in sata_rcar_resume()
967 iowrite32(priv->sataint_mask, base + SATAINTMASK_REG); in sata_rcar_resume()
1026 MODULE_DESCRIPTION("Renesas R-Car SATA controller low level driver");