aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/ata/sata_rcar.c102
1 files changed, 57 insertions, 45 deletions
diff --git a/drivers/ata/sata_rcar.c b/drivers/ata/sata_rcar.c
index 178165be0c32..f0d3e43570ee 100644
--- a/drivers/ata/sata_rcar.c
+++ b/drivers/ata/sata_rcar.c
@@ -130,41 +130,44 @@ struct sata_rcar_priv {
130 130
131static void sata_rcar_phy_initialize(struct sata_rcar_priv *priv) 131static void sata_rcar_phy_initialize(struct sata_rcar_priv *priv)
132{ 132{
133 void __iomem *base = priv->base;
134
133 /* idle state */ 135 /* idle state */
134 iowrite32(0, priv->base + SATAPHYADDR_REG); 136 iowrite32(0, base + SATAPHYADDR_REG);
135 /* reset */ 137 /* reset */
136 iowrite32(SATAPHYRESET_PHYRST, priv->base + SATAPHYRESET_REG); 138 iowrite32(SATAPHYRESET_PHYRST, base + SATAPHYRESET_REG);
137 udelay(10); 139 udelay(10);
138 /* deassert reset */ 140 /* deassert reset */
139 iowrite32(0, priv->base + SATAPHYRESET_REG); 141 iowrite32(0, base + SATAPHYRESET_REG);
140} 142}
141 143
142static void sata_rcar_phy_write(struct sata_rcar_priv *priv, u16 reg, u32 val, 144static void sata_rcar_phy_write(struct sata_rcar_priv *priv, u16 reg, u32 val,
143 int group) 145 int group)
144{ 146{
147 void __iomem *base = priv->base;
145 int timeout; 148 int timeout;
146 149
147 /* deassert reset */ 150 /* deassert reset */
148 iowrite32(0, priv->base + SATAPHYRESET_REG); 151 iowrite32(0, base + SATAPHYRESET_REG);
149 /* lane 1 */ 152 /* lane 1 */
150 iowrite32(SATAPHYACCEN_PHYLANE, priv->base + SATAPHYACCEN_REG); 153 iowrite32(SATAPHYACCEN_PHYLANE, base + SATAPHYACCEN_REG);
151 /* write phy register value */ 154 /* write phy register value */
152 iowrite32(val, priv->base + SATAPHYWDATA_REG); 155 iowrite32(val, base + SATAPHYWDATA_REG);
153 /* set register group */ 156 /* set register group */
154 if (group) 157 if (group)
155 reg |= SATAPHYADDR_PHYRATEMODE; 158 reg |= SATAPHYADDR_PHYRATEMODE;
156 /* write command */ 159 /* write command */
157 iowrite32(SATAPHYADDR_PHYCMD_WRITE | reg, priv->base + SATAPHYADDR_REG); 160 iowrite32(SATAPHYADDR_PHYCMD_WRITE | reg, base + SATAPHYADDR_REG);
158 /* wait for ack */ 161 /* wait for ack */
159 for (timeout = 0; timeout < 100; timeout++) { 162 for (timeout = 0; timeout < 100; timeout++) {
160 val = ioread32(priv->base + SATAPHYACK_REG); 163 val = ioread32(base + SATAPHYACK_REG);
161 if (val & SATAPHYACK_PHYACK) 164 if (val & SATAPHYACK_PHYACK)
162 break; 165 break;
163 } 166 }
164 if (timeout >= 100) 167 if (timeout >= 100)
165 pr_err("%s timeout\n", __func__); 168 pr_err("%s timeout\n", __func__);
166 /* idle state */ 169 /* idle state */
167 iowrite32(0, priv->base + SATAPHYADDR_REG); 170 iowrite32(0, base + SATAPHYADDR_REG);
168} 171}
169 172
170static void sata_rcar_freeze(struct ata_port *ap) 173static void sata_rcar_freeze(struct ata_port *ap)
@@ -180,14 +183,15 @@ static void sata_rcar_freeze(struct ata_port *ap)
180static void sata_rcar_thaw(struct ata_port *ap) 183static void sata_rcar_thaw(struct ata_port *ap)
181{ 184{
182 struct sata_rcar_priv *priv = ap->host->private_data; 185 struct sata_rcar_priv *priv = ap->host->private_data;
186 void __iomem *base = priv->base;
183 187
184 /* ack */ 188 /* ack */
185 iowrite32(~SATA_RCAR_INT_MASK, priv->base + SATAINTSTAT_REG); 189 iowrite32(~SATA_RCAR_INT_MASK, base + SATAINTSTAT_REG);
186 190
187 ata_sff_thaw(ap); 191 ata_sff_thaw(ap);
188 192
189 /* unmask */ 193 /* unmask */
190 iowrite32(0x7ff & ~SATA_RCAR_INT_MASK, priv->base + SATAINTMASK_REG); 194 iowrite32(0x7ff & ~SATA_RCAR_INT_MASK, base + SATAINTMASK_REG);
191} 195}
192 196
193static void sata_rcar_ioread16_rep(void __iomem *reg, void *buffer, int count) 197static void sata_rcar_ioread16_rep(void __iomem *reg, void *buffer, int count)
@@ -509,15 +513,16 @@ static void sata_rcar_bmdma_setup(struct ata_queued_cmd *qc)
509{ 513{
510 struct ata_port *ap = qc->ap; 514 struct ata_port *ap = qc->ap;
511 unsigned int rw = qc->tf.flags & ATA_TFLAG_WRITE; 515 unsigned int rw = qc->tf.flags & ATA_TFLAG_WRITE;
512 u32 dmactl;
513 struct sata_rcar_priv *priv = ap->host->private_data; 516 struct sata_rcar_priv *priv = ap->host->private_data;
517 void __iomem *base = priv->base;
518 u32 dmactl;
514 519
515 /* load PRD table addr. */ 520 /* load PRD table addr. */
516 mb(); /* make sure PRD table writes are visible to controller */ 521 mb(); /* make sure PRD table writes are visible to controller */
517 iowrite32(ap->bmdma_prd_dma, priv->base + ATAPI_DTB_ADR_REG); 522 iowrite32(ap->bmdma_prd_dma, base + ATAPI_DTB_ADR_REG);
518 523
519 /* specify data direction, triple-check start bit is clear */ 524 /* specify data direction, triple-check start bit is clear */
520 dmactl = ioread32(priv->base + ATAPI_CONTROL1_REG); 525 dmactl = ioread32(base + ATAPI_CONTROL1_REG);
521 dmactl &= ~(ATAPI_CONTROL1_RW | ATAPI_CONTROL1_STOP); 526 dmactl &= ~(ATAPI_CONTROL1_RW | ATAPI_CONTROL1_STOP);
522 if (dmactl & ATAPI_CONTROL1_START) { 527 if (dmactl & ATAPI_CONTROL1_START) {
523 dmactl &= ~ATAPI_CONTROL1_START; 528 dmactl &= ~ATAPI_CONTROL1_START;
@@ -525,7 +530,7 @@ static void sata_rcar_bmdma_setup(struct ata_queued_cmd *qc)
525 } 530 }
526 if (!rw) 531 if (!rw)
527 dmactl |= ATAPI_CONTROL1_RW; 532 dmactl |= ATAPI_CONTROL1_RW;
528 iowrite32(dmactl, priv->base + ATAPI_CONTROL1_REG); 533 iowrite32(dmactl, base + ATAPI_CONTROL1_REG);
529 534
530 /* issue r/w command */ 535 /* issue r/w command */
531 ap->ops->sff_exec_command(ap, &qc->tf); 536 ap->ops->sff_exec_command(ap, &qc->tf);
@@ -534,27 +539,29 @@ static void sata_rcar_bmdma_setup(struct ata_queued_cmd *qc)
534static void sata_rcar_bmdma_start(struct ata_queued_cmd *qc) 539static void sata_rcar_bmdma_start(struct ata_queued_cmd *qc)
535{ 540{
536 struct ata_port *ap = qc->ap; 541 struct ata_port *ap = qc->ap;
537 u32 dmactl;
538 struct sata_rcar_priv *priv = ap->host->private_data; 542 struct sata_rcar_priv *priv = ap->host->private_data;
543 void __iomem *base = priv->base;
544 u32 dmactl;
539 545
540 /* start host DMA transaction */ 546 /* start host DMA transaction */
541 dmactl = ioread32(priv->base + ATAPI_CONTROL1_REG); 547 dmactl = ioread32(base + ATAPI_CONTROL1_REG);
542 dmactl |= ATAPI_CONTROL1_START; 548 dmactl |= ATAPI_CONTROL1_START;
543 iowrite32(dmactl, priv->base + ATAPI_CONTROL1_REG); 549 iowrite32(dmactl, base + ATAPI_CONTROL1_REG);
544} 550}
545 551
546static void sata_rcar_bmdma_stop(struct ata_queued_cmd *qc) 552static void sata_rcar_bmdma_stop(struct ata_queued_cmd *qc)
547{ 553{
548 struct ata_port *ap = qc->ap; 554 struct ata_port *ap = qc->ap;
549 struct sata_rcar_priv *priv = ap->host->private_data; 555 struct sata_rcar_priv *priv = ap->host->private_data;
556 void __iomem *base = priv->base;
550 u32 dmactl; 557 u32 dmactl;
551 558
552 /* force termination of DMA transfer if active */ 559 /* force termination of DMA transfer if active */
553 dmactl = ioread32(priv->base + ATAPI_CONTROL1_REG); 560 dmactl = ioread32(base + ATAPI_CONTROL1_REG);
554 if (dmactl & ATAPI_CONTROL1_START) { 561 if (dmactl & ATAPI_CONTROL1_START) {
555 dmactl &= ~ATAPI_CONTROL1_START; 562 dmactl &= ~ATAPI_CONTROL1_START;
556 dmactl |= ATAPI_CONTROL1_STOP; 563 dmactl |= ATAPI_CONTROL1_STOP;
557 iowrite32(dmactl, priv->base + ATAPI_CONTROL1_REG); 564 iowrite32(dmactl, base + ATAPI_CONTROL1_REG);
558 } 565 }
559 566
560 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ 567 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
@@ -564,8 +571,8 @@ static void sata_rcar_bmdma_stop(struct ata_queued_cmd *qc)
564static u8 sata_rcar_bmdma_status(struct ata_port *ap) 571static u8 sata_rcar_bmdma_status(struct ata_port *ap)
565{ 572{
566 struct sata_rcar_priv *priv = ap->host->private_data; 573 struct sata_rcar_priv *priv = ap->host->private_data;
567 u32 status;
568 u8 host_stat = 0; 574 u8 host_stat = 0;
575 u32 status;
569 576
570 status = ioread32(priv->base + ATAPI_STATUS_REG); 577 status = ioread32(priv->base + ATAPI_STATUS_REG);
571 if (status & ATAPI_STATUS_DEVINT) 578 if (status & ATAPI_STATUS_DEVINT)
@@ -666,19 +673,19 @@ static irqreturn_t sata_rcar_interrupt(int irq, void *dev_instance)
666{ 673{
667 struct ata_host *host = dev_instance; 674 struct ata_host *host = dev_instance;
668 struct sata_rcar_priv *priv = host->private_data; 675 struct sata_rcar_priv *priv = host->private_data;
669 struct ata_port *ap; 676 void __iomem *base = priv->base;
670 unsigned int handled = 0; 677 unsigned int handled = 0;
678 struct ata_port *ap;
671 u32 sataintstat; 679 u32 sataintstat;
672 unsigned long flags; 680 unsigned long flags;
673 681
674 spin_lock_irqsave(&host->lock, flags); 682 spin_lock_irqsave(&host->lock, flags);
675 683
676 sataintstat = ioread32(priv->base + SATAINTSTAT_REG); 684 sataintstat = ioread32(base + SATAINTSTAT_REG);
677 if (!sataintstat) 685 if (!sataintstat)
678 goto done; 686 goto done;
679 /* ack */ 687 /* ack */
680 iowrite32(sataintstat & ~SATA_RCAR_INT_MASK, 688 iowrite32(sataintstat & ~SATA_RCAR_INT_MASK, base + SATAINTSTAT_REG);
681 priv->base + SATAINTSTAT_REG);
682 689
683 ap = host->ports[0]; 690 ap = host->ports[0];
684 691
@@ -699,15 +706,16 @@ static void sata_rcar_setup_port(struct ata_host *host)
699 struct ata_port *ap = host->ports[0]; 706 struct ata_port *ap = host->ports[0];
700 struct ata_ioports *ioaddr = &ap->ioaddr; 707 struct ata_ioports *ioaddr = &ap->ioaddr;
701 struct sata_rcar_priv *priv = host->private_data; 708 struct sata_rcar_priv *priv = host->private_data;
709 void __iomem *base = priv->base;
702 710
703 ap->ops = &sata_rcar_port_ops; 711 ap->ops = &sata_rcar_port_ops;
704 ap->pio_mask = ATA_PIO4; 712 ap->pio_mask = ATA_PIO4;
705 ap->udma_mask = ATA_UDMA6; 713 ap->udma_mask = ATA_UDMA6;
706 ap->flags |= ATA_FLAG_SATA; 714 ap->flags |= ATA_FLAG_SATA;
707 715
708 ioaddr->cmd_addr = priv->base + SDATA_REG; 716 ioaddr->cmd_addr = base + SDATA_REG;
709 ioaddr->ctl_addr = priv->base + SSDEVCON_REG; 717 ioaddr->ctl_addr = base + SSDEVCON_REG;
710 ioaddr->scr_addr = priv->base + SCRSSTS_REG; 718 ioaddr->scr_addr = base + SCRSSTS_REG;
711 ioaddr->altstatus_addr = ioaddr->ctl_addr; 719 ioaddr->altstatus_addr = ioaddr->ctl_addr;
712 720
713 ioaddr->data_addr = ioaddr->cmd_addr + (ATA_REG_DATA << 2); 721 ioaddr->data_addr = ioaddr->cmd_addr + (ATA_REG_DATA << 2);
@@ -725,6 +733,7 @@ static void sata_rcar_setup_port(struct ata_host *host)
725static void sata_rcar_init_controller(struct ata_host *host) 733static void sata_rcar_init_controller(struct ata_host *host)
726{ 734{
727 struct sata_rcar_priv *priv = host->private_data; 735 struct sata_rcar_priv *priv = host->private_data;
736 void __iomem *base = priv->base;
728 u32 val; 737 u32 val;
729 738
730 /* reset and setup phy */ 739 /* reset and setup phy */
@@ -737,27 +746,27 @@ static void sata_rcar_init_controller(struct ata_host *host)
737 sata_rcar_phy_write(priv, SATAPCTLR4_REG, 0x28E80000, 0); 746 sata_rcar_phy_write(priv, SATAPCTLR4_REG, 0x28E80000, 0);
738 747
739 /* SATA-IP reset state */ 748 /* SATA-IP reset state */
740 val = ioread32(priv->base + ATAPI_CONTROL1_REG); 749 val = ioread32(base + ATAPI_CONTROL1_REG);
741 val |= ATAPI_CONTROL1_RESET; 750 val |= ATAPI_CONTROL1_RESET;
742 iowrite32(val, priv->base + ATAPI_CONTROL1_REG); 751 iowrite32(val, base + ATAPI_CONTROL1_REG);
743 752
744 /* ISM mode, PRD mode, DTEND flag at bit 0 */ 753 /* ISM mode, PRD mode, DTEND flag at bit 0 */
745 val = ioread32(priv->base + ATAPI_CONTROL1_REG); 754 val = ioread32(base + ATAPI_CONTROL1_REG);
746 val |= ATAPI_CONTROL1_ISM; 755 val |= ATAPI_CONTROL1_ISM;
747 val |= ATAPI_CONTROL1_DESE; 756 val |= ATAPI_CONTROL1_DESE;
748 val |= ATAPI_CONTROL1_DTA32M; 757 val |= ATAPI_CONTROL1_DTA32M;
749 iowrite32(val, priv->base + ATAPI_CONTROL1_REG); 758 iowrite32(val, base + ATAPI_CONTROL1_REG);
750 759
751 /* Release the SATA-IP from the reset state */ 760 /* Release the SATA-IP from the reset state */
752 val = ioread32(priv->base + ATAPI_CONTROL1_REG); 761 val = ioread32(base + ATAPI_CONTROL1_REG);
753 val &= ~ATAPI_CONTROL1_RESET; 762 val &= ~ATAPI_CONTROL1_RESET;
754 iowrite32(val, priv->base + ATAPI_CONTROL1_REG); 763 iowrite32(val, base + ATAPI_CONTROL1_REG);
755 764
756 /* ack and mask */ 765 /* ack and mask */
757 iowrite32(0, priv->base + SATAINTSTAT_REG); 766 iowrite32(0, base + SATAINTSTAT_REG);
758 iowrite32(0x7ff, priv->base + SATAINTMASK_REG); 767 iowrite32(0x7ff, base + SATAINTMASK_REG);
759 /* enable interrupts */ 768 /* enable interrupts */
760 iowrite32(ATAPI_INT_ENABLE_SATAINT, priv->base + ATAPI_INT_ENABLE_REG); 769 iowrite32(ATAPI_INT_ENABLE_SATAINT, base + ATAPI_INT_ENABLE_REG);
761} 770}
762 771
763static int sata_rcar_probe(struct platform_device *pdev) 772static int sata_rcar_probe(struct platform_device *pdev)
@@ -824,14 +833,15 @@ static int sata_rcar_remove(struct platform_device *pdev)
824{ 833{
825 struct ata_host *host = platform_get_drvdata(pdev); 834 struct ata_host *host = platform_get_drvdata(pdev);
826 struct sata_rcar_priv *priv = host->private_data; 835 struct sata_rcar_priv *priv = host->private_data;
836 void __iomem *base = priv->base;
827 837
828 ata_host_detach(host); 838 ata_host_detach(host);
829 839
830 /* disable interrupts */ 840 /* disable interrupts */
831 iowrite32(0, priv->base + ATAPI_INT_ENABLE_REG); 841 iowrite32(0, base + ATAPI_INT_ENABLE_REG);
832 /* ack and mask */ 842 /* ack and mask */
833 iowrite32(0, priv->base + SATAINTSTAT_REG); 843 iowrite32(0, base + SATAINTSTAT_REG);
834 iowrite32(0x7ff, priv->base + SATAINTMASK_REG); 844 iowrite32(0x7ff, base + SATAINTMASK_REG);
835 845
836 clk_disable(priv->clk); 846 clk_disable(priv->clk);
837 847
@@ -843,14 +853,15 @@ static int sata_rcar_suspend(struct device *dev)
843{ 853{
844 struct ata_host *host = dev_get_drvdata(dev); 854 struct ata_host *host = dev_get_drvdata(dev);
845 struct sata_rcar_priv *priv = host->private_data; 855 struct sata_rcar_priv *priv = host->private_data;
856 void __iomem *base = priv->base;
846 int ret; 857 int ret;
847 858
848 ret = ata_host_suspend(host, PMSG_SUSPEND); 859 ret = ata_host_suspend(host, PMSG_SUSPEND);
849 if (!ret) { 860 if (!ret) {
850 /* disable interrupts */ 861 /* disable interrupts */
851 iowrite32(0, priv->base + ATAPI_INT_ENABLE_REG); 862 iowrite32(0, base + ATAPI_INT_ENABLE_REG);
852 /* mask */ 863 /* mask */
853 iowrite32(0x7ff, priv->base + SATAINTMASK_REG); 864 iowrite32(0x7ff, base + SATAINTMASK_REG);
854 865
855 clk_disable(priv->clk); 866 clk_disable(priv->clk);
856 } 867 }
@@ -862,14 +873,15 @@ static int sata_rcar_resume(struct device *dev)
862{ 873{
863 struct ata_host *host = dev_get_drvdata(dev); 874 struct ata_host *host = dev_get_drvdata(dev);
864 struct sata_rcar_priv *priv = host->private_data; 875 struct sata_rcar_priv *priv = host->private_data;
876 void __iomem *base = priv->base;
865 877
866 clk_enable(priv->clk); 878 clk_enable(priv->clk);
867 879
868 /* ack and mask */ 880 /* ack and mask */
869 iowrite32(0, priv->base + SATAINTSTAT_REG); 881 iowrite32(0, base + SATAINTSTAT_REG);
870 iowrite32(0x7ff, priv->base + SATAINTMASK_REG); 882 iowrite32(0x7ff, base + SATAINTMASK_REG);
871 /* enable interrupts */ 883 /* enable interrupts */
872 iowrite32(ATAPI_INT_ENABLE_SATAINT, priv->base + ATAPI_INT_ENABLE_REG); 884 iowrite32(ATAPI_INT_ENABLE_SATAINT, base + ATAPI_INT_ENABLE_REG);
873 885
874 ata_host_resume(host); 886 ata_host_resume(host);
875 887