From patchwork Tue Apr 15 02:41:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 3988641 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 745E29F2BA for ; Tue, 15 Apr 2014 02:44:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 53E4B201DC for ; Tue, 15 Apr 2014 02:44:52 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1BC33201E4 for ; Tue, 15 Apr 2014 02:44:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WZtKc-0006Wq-6l; Tue, 15 Apr 2014 02:42:42 +0000 Received: from co9ehsobe004.messaging.microsoft.com ([207.46.163.27] helo=co9outboundpool.messaging.microsoft.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WZtKY-0006UB-WA for linux-arm-kernel@lists.infradead.org; Tue, 15 Apr 2014 02:42:39 +0000 Received: from mail182-co9-R.bigfish.com (10.236.132.232) by CO9EHSOBE003.bigfish.com (10.236.130.66) with Microsoft SMTP Server id 14.1.225.22; Tue, 15 Apr 2014 02:41:39 +0000 Received: from mail182-co9 (localhost [127.0.0.1]) by mail182-co9-R.bigfish.com (Postfix) with ESMTP id 004DD380237; Tue, 15 Apr 2014 02:41:39 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zze0eahzz1f42h2148h1ee6h1de0h1fdah2073h2146h1202h1e76h2189h1d1ah1d2ah21bch1fc6h208chzz1de098h8275bh1de097hz2dh2a8h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1b2fh2222h224fh1fb3h1d0ch1d2eh1d3fh1dfeh1dffh1e23h1fe8h1ff5h2218h2216h226dh22d0h24afh2327h2336h2438h2461h2487h24d7h2516h2545h255eh25cch25f6h2605h268bh26d3h1155h) Received: from mail182-co9 (localhost.localdomain [127.0.0.1]) by mail182-co9 (MessageSwitch) id 1397529697611961_2779; Tue, 15 Apr 2014 02:41:37 +0000 (UTC) Received: from CO9EHSMHS015.bigfish.com (unknown [10.236.132.240]) by mail182-co9.bigfish.com (Postfix) with ESMTP id 85BA7600C8; Tue, 15 Apr 2014 02:41:37 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO9EHSMHS015.bigfish.com (10.236.130.25) with Microsoft SMTP Server (TLS) id 14.16.227.3; Tue, 15 Apr 2014 02:41:37 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server (TLS) id 14.3.174.2; Tue, 15 Apr 2014 02:42:12 +0000 Received: from dragon.ap.freescale.net ([10.192.185.149]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id s3F2g6Jq003582; Mon, 14 Apr 2014 19:42:10 -0700 From: Shawn Guo To: Subject: [PATCH 2/2] ahci: imx: software workaround for phy reset issue in resume Date: Tue, 15 Apr 2014 10:41:43 +0800 Message-ID: <1397529703-21165-2-git-send-email-shawn.guo@freescale.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1397529703-21165-1-git-send-email-shawn.guo@freescale.com> References: <1397529703-21165-1-git-send-email-shawn.guo@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% X-FOPE-CONNECTOR: Id%0$Dn%FREESCALE.MAIL.ONMICROSOFT.COM$RO%1$TLS%0$FQDN%$TlsDn% X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140414_194239_107048_26D12DB6 X-CRM114-Status: GOOD ( 19.64 ) X-Spam-Score: -1.6 (-) Cc: Tejun Heo , Richard Zhu , Shawn Guo , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY, UNRESOLVED_TEMPLATE autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When suspending imx6q systems which have rootfs on SATA, the following error will likely be seen in resume. The SATA link will fail to come up, and it results in an unusable system across the suspend/resume cycle. $ echo mem > /sys/power/state PM: Syncing filesystems ... done. PM: Preparing system for mem sleep Freezing user space processes ... (elapsed 0.002 seconds) done. Freezing remaining freezable tasks ... (elapsed 0.002 seconds) done. PM: Entering mem sleep sd 0:0:0:0: [sda] Synchronizing SCSI cache sd 0:0:0:0: [sda] Stopping disk PM: suspend of devices complete after 61.914 msecs PM: suspend devices took 0.070 seconds PM: late suspend of devices complete after 4.906 msecs PM: noirq suspend of devices complete after 4.521 msecs Disabling non-boot CPUs ... CPU1: shutdown CPU2: shutdown CPU3: shutdown Enabling non-boot CPUs ... CPU1: Booted secondary processor CPU1 is up CPU2: Booted secondary processor CPU2 is up CPU3: Booted secondary processor CPU3 is up PM: noirq resume of devices complete after 10.486 msecs PM: early resume of devices complete after 4.679 msecs sd 0:0:0:0: [sda] Starting disk PM: resume of devices complete after 22.674 msecs PM: resume devices took 0.030 seconds PM: Finishing wakeup. Restarting tasks ... done. $ ata1: SATA link down (SStatus 1 SControl 300) ata1: SATA link down (SStatus 1 SControl 300) ata1: limiting SATA link speed to 1.5 Gbps ata1: SATA link down (SStatus 1 SControl 310) ata1.00: disabled ata1: exception Emask 0x10 SAct 0x0 SErr 0x4040000 action 0xe frozen t4 ata1: irq_stat 0x00000040, connection status changed ata1: SError: { CommWake DevExch } ata1: hard resetting link sd 0:0:0:0: rejecting I/O to offline device sd 0:0:0:0: killing request sd 0:0:0:0: rejecting I/O to offline device Aborting journal on device sda2-8. sd 0:0:0:0: rejecting I/O to offline device EXT4-fs warning (device sda2): ext4_end_bio:317: I/O error writing to inode 132577 (offset 0 size 0 starting block 26235) Buffer I/O error on device sda2, logical block 10169 ... It's caused by a silicon issue that SATA phy does not get reset by controller when coming back from LPM. The patch adds a software workaround for this issue. It enforces a software reset on SATA phy in imx_sata_enable() function, so that we can ensure SATA link will come up properly in both power-on and resume. The software reset is implemented by writing phy reset register through the phy control register bus interface. Functions imx_phy_reg_[addressing|write|read]() implement this bus interface, while imx_sata_phy_reset() performs the actually reset operation. Signed-off-by: Richard Zhu Signed-off-by: Shawn Guo Tested-by: Fabio Estevam --- drivers/ata/ahci_imx.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) diff --git a/drivers/ata/ahci_imx.c b/drivers/ata/ahci_imx.c index 39629b4..7d4756d 100644 --- a/drivers/ata/ahci_imx.c +++ b/drivers/ata/ahci_imx.c @@ -31,6 +31,18 @@ #define IMX_SATA_TIMER1MS 0x00e0 #define IMX_SATA_P0PHYCR 0x0178 #define P0PHYCR_TEST_PDDQ (1 << 20) +#define P0PHYCR_CR_READ (1 << 19) +#define P0PHYCR_CR_WRITE (1 << 18) +#define P0PHYCR_CR_CAP_DATA (1 << 17) +#define P0PHYCR_CR_CAP_ADDR (1 << 16) +#define IMX_SATA_P0PHYSR 0x017c +#define P0PHYSR_CR_ACK (1 << 18) +#define P0PHYSR_CR_DATA_OUT 0xffff + +#define IMX_PHY_LANE0_OUT_STAT 0x2003 +#define LANE0_OUT_STAT_RX_PLL_STATE (1 << 1) +#define IMX_PHY_CLOCK_RESET 0x7f3f +#define CLOCK_RESET_RESET (1 << 0) enum ahci_imx_type { AHCI_IMX53, @@ -52,9 +64,165 @@ MODULE_PARM_DESC(hotplug, "AHCI IMX hot-plug support (0=Don't support, 1=support static void ahci_imx_host_stop(struct ata_host *host); +static int imx_phy_ack_polling(void __iomem *mmio, bool assert) +{ + int timeout = 100; + u32 srval; + + do { + srval = readl(mmio + IMX_SATA_P0PHYSR); + if ((assert ? srval : ~srval) & P0PHYSR_CR_ACK) + break; + usleep_range(100, 200); + } while (--timeout); + + return timeout ? 0 : -ETIMEDOUT; +} + +static int imx_phy_reg_addressing(u16 addr, void __iomem *mmio) +{ + u32 crval = addr; + int ret; + + /* 1. Supply the address on cr_data_in */ + writel(crval, mmio + IMX_SATA_P0PHYCR); + + /* 2. Assert the cr_cap_addr signal */ + crval |= P0PHYCR_CR_CAP_ADDR; + writel(crval, mmio + IMX_SATA_P0PHYCR); + + /* 3. Wait for the cr_ack signal to be asserted */ + ret = imx_phy_ack_polling(mmio, true); + if (ret) + return ret; + + /* 4. Deassert cr_cap_addr */ + crval &= ~P0PHYCR_CR_CAP_ADDR; + writel(crval, mmio + IMX_SATA_P0PHYCR); + + /* 5. Wait for cr_ack to be deasserted */ + ret = imx_phy_ack_polling(mmio, false); + if (ret) + return ret; + + return 0; +} + +static int imx_phy_reg_write(u16 val, void __iomem *mmio) +{ + u32 crval = val; + int ret; + + /* 1. Supply the data on cr_data_in */ + writel(crval, mmio + IMX_SATA_P0PHYCR); + + /* 2. Assert the cr_cap_data signal */ + crval |= P0PHYCR_CR_CAP_DATA; + writel(crval, mmio + IMX_SATA_P0PHYCR); + + /* 3. Wait for the cr_ack signal to be asserted */ + ret = imx_phy_ack_polling(mmio, true); + if (ret) + return ret; + + /* 4. Deassert cr_cap_data */ + crval &= ~P0PHYCR_CR_CAP_DATA; + writel(crval, mmio + IMX_SATA_P0PHYCR); + + /* 5. Wait for cr_ack to be deasserted */ + ret = imx_phy_ack_polling(mmio, false); + if (ret) + return ret; + + /* 6. Assert the cr_write signal */ + crval |= P0PHYCR_CR_WRITE; + writel(crval, mmio + IMX_SATA_P0PHYCR); + + /* 7. Wait for cr_ack to be asserted */ + ret = imx_phy_ack_polling(mmio, true); + if (ret) + return ret; + + /* 8. Deassert cr_write */ + crval &= ~P0PHYCR_CR_WRITE; + writel(crval, mmio + IMX_SATA_P0PHYCR); + + /* 9. Wait for cr_ack to be deasserted */ + ret = imx_phy_ack_polling(mmio, false); + if (ret) + return ret; + + return 0; +} + +static int imx_phy_reg_read(u16 *val, void __iomem *mmio) +{ + u32 crval = 0; + int ret; + + /* 1. Assert the cr_read signal */ + crval |= P0PHYCR_CR_READ; + writel(crval, mmio + IMX_SATA_P0PHYCR); + + /* 2. Wait for the cr_ack signal to be asserted */ + ret = imx_phy_ack_polling(mmio, true); + if (ret) + return ret; + + /* 3. Capture the data from cr_data_out[] */ + *val = readl(mmio + IMX_SATA_P0PHYSR) & P0PHYSR_CR_DATA_OUT; + + /* 4. Deassert cr_read */ + crval &= ~P0PHYCR_CR_READ; + writel(crval, mmio + IMX_SATA_P0PHYCR); + + /* 5. Wait for cr_ack to be deasserted */ + ret = imx_phy_ack_polling(mmio, false); + if (ret) + return ret; + + return 0; +} + +static int imx_sata_phy_reset(struct ahci_host_priv *hpriv) +{ + void __iomem *mmio = hpriv->mmio; + int timeout = 10; + u16 val; + int ret; + + /* Reset SATA PHY by setting RESET bit of PHY register CLOCK_RESET */ + ret = imx_phy_reg_addressing(IMX_PHY_CLOCK_RESET, mmio); + if (ret) + return ret; + /* + * For phy reset operation, we skip the timeout checking, because phy + * will be unable to acknowledge in this case. + */ + imx_phy_reg_write(CLOCK_RESET_RESET, mmio); + + usleep_range(100, 200); + + /* Wait for PHY RX_PLL to be stable */ + do { + ret = imx_phy_reg_addressing(IMX_PHY_LANE0_OUT_STAT, mmio); + if (ret) + return ret; + ret = imx_phy_reg_read(&val, mmio); + if (ret) + return ret; + if (val & LANE0_OUT_STAT_RX_PLL_STATE) + break; + usleep_range(100, 200); + } while (--timeout); + + return timeout ? 0 : -ETIMEDOUT; +} + static int imx_sata_enable(struct ahci_host_priv *hpriv) { struct imx_ahci_priv *imxpriv = hpriv->plat_data; + struct device *dev = &imxpriv->ahci_pdev->dev; int ret; if (imxpriv->no_device) @@ -99,6 +267,12 @@ static int imx_sata_enable(struct ahci_host_priv *hpriv) regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13, IMX6Q_GPR13_SATA_MPLL_CLK_EN, IMX6Q_GPR13_SATA_MPLL_CLK_EN); + + ret = imx_sata_phy_reset(hpriv); + if (ret) { + dev_err(dev, "failed to reset phy: %d\n", ret); + goto disable_regulator; + } } usleep_range(1000, 2000); @@ -215,6 +389,7 @@ static int imx_ahci_probe(struct platform_device *pdev) if (!imxpriv) return -ENOMEM; + imxpriv->ahci_pdev = pdev; imxpriv->no_device = false; imxpriv->first_time = true; imxpriv->type = (enum ahci_imx_type)of_id->data;