From patchwork Mon Jan 7 10:11:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bough Chen X-Patchwork-Id: 10750261 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F043113B5 for ; Mon, 7 Jan 2019 10:16:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE0C028A45 for ; Mon, 7 Jan 2019 10:16:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1FBE28A47; Mon, 7 Jan 2019 10:16:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A85D28A45 for ; Mon, 7 Jan 2019 10:16:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726622AbfAGKQT (ORCPT ); Mon, 7 Jan 2019 05:16:19 -0500 Received: from mail-eopbgr130073.outbound.protection.outlook.com ([40.107.13.73]:43744 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726710AbfAGKQT (ORCPT ); Mon, 7 Jan 2019 05:16:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7W7ehWckf3i+iWJ0t48MSfqQQMA/75qsXR1dscaLZHc=; b=KKr084/4L1WMCAKYv7LO08gVPpyNM7WJjJnJk5p6zQF1L7BCt5wYqo20l3v+X3EhXZ+kEmYL6ND3RgnGjNXkmHBGk3/nQ1EqGfiq5AgRWi3YESLC6sR5+ohm01YIfkfSNnf/NerljOxXlLMkm/ds8Jjsxx5uRd2uv+Yqwrf+MUE= Received: from VI1PR04MB5040.eurprd04.prod.outlook.com (20.177.50.97) by VI1PR04MB2126.eurprd04.prod.outlook.com (10.166.43.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1495.7; Mon, 7 Jan 2019 10:11:39 +0000 Received: from VI1PR04MB5040.eurprd04.prod.outlook.com ([fe80::ed39:18ba:6fbc:d025]) by VI1PR04MB5040.eurprd04.prod.outlook.com ([fe80::ed39:18ba:6fbc:d025%2]) with mapi id 15.20.1495.011; Mon, 7 Jan 2019 10:11:39 +0000 From: BOUGH CHEN To: "ulf.hansson@linaro.org" , "adrian.hunter@intel.com" CC: dl-linux-imx , "linux-mmc@vger.kernel.org" Subject: [PATCH 4/5] mmc: sdhci-esdhc-imx: add CMDQ support Thread-Topic: [PATCH 4/5] mmc: sdhci-esdhc-imx: add CMDQ support Thread-Index: AQHUpnFh11gY9MGSeUq4pIezVfCkcQ== Date: Mon, 7 Jan 2019 10:11:39 +0000 Message-ID: <20190107101757.27647-4-haibo.chen@nxp.com> References: <20190107101757.27647-1-haibo.chen@nxp.com> In-Reply-To: <20190107101757.27647-1-haibo.chen@nxp.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.17.1 x-clientproxiedby: HK2PR04CA0052.apcprd04.prod.outlook.com (2603:1096:202:14::20) To VI1PR04MB5040.eurprd04.prod.outlook.com (2603:10a6:803:59::33) authentication-results: spf=none (sender IP is ) smtp.mailfrom=haibo.chen@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [92.121.68.129] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;VI1PR04MB2126;6:UQOdF3VWfW/dcvuR7GX+9PVodQ6aNXNy7VbZvgmDxNAooEzwjoHqWD9977WUIbHVMFoX3jZWIQYTYJUb1GNvsROcI8C5dpx+bnlHiOG3BVEdNWRSJ+6zDQ2c7tw1SJGqPrHKC4x22eR5t2TZv06hXyuf3utN2Dd4x8smYXRjQhqfptq3SYEdJGeFY2AsgF0PyIlh331+EJqPOlT8MMpuz3LtyCsuZV12HEuVzp4eO6NcyQhs3AxJxY/ZK2GEGABSlaob8ekPDvhnBmVtahKkVPSis67nR/JSsG88kDTimnjVoeMJHBWsqyLrLN4mgWkixkuCC+ycitVyTpcPJ2Rwh/E9yg0ZVe3Pw4bvkzgnijBqwugutL8JoqUPJLV285VXDuPoWwfwQxxG5FT6ptZcWkbzI3KRJeNbbnBdRAR06HTOi31P7J3BvwaZB8LuZL+uu3pTS2vB6Us+RC1W874zQg==;5:CWslak4InK3DVwk7bTbjpfUKlZmveVXEBFRV5KLSaxKeJ3SXA9vkslSM0lxe9OTCIeOAdhtC9ZPKdgkJ1x07Qgqr3uTs4pnisJE3b1cQOX22cY8c/lZHqdJDUqUC2oVWoawQy5/C8foSt+BT4SeE2mbSGooBqS0od2M3gxetipLqbn5+pIYgxg9abqdI059pwHp2Kv371E5VFwr0ODNvaw==;7:xZi2+vq45kYNcxS4KWQ9sIT+gNsSN9Hdsrql8B1tMtVezNGrM1+gd7kmh5MxHIB3EV8e5n3USeGR1wAj4aTq077A+kG2rVCI8A8KqX9NIb3w7k1xb/4KRoNGgb0aBjsm8i4NyGWhqqXhxDBMjECJAQ== x-ms-office365-filtering-correlation-id: aee3fa2b-16fb-48bf-e477-08d674888375 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:VI1PR04MB2126; x-ms-traffictypediagnostic: VI1PR04MB2126: x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(3230021)(908002)(999002)(5005026)(6040522)(8220060)(2401047)(8121501046)(10201501046)(3231475)(944501520)(52105112)(93006095)(93001095)(3002001)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123558120)(20161123564045)(201708071742011)(7699051)(76991095);SRVR:VI1PR04MB2126;BCL:0;PCL:0;RULEID:;SRVR:VI1PR04MB2126; x-forefront-prvs: 0910AAF391 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39860400002)(366004)(136003)(396003)(376002)(346002)(199004)(189003)(8676002)(76176011)(81156014)(81166006)(50226002)(305945005)(5660300001)(106356001)(52116002)(110136005)(71200400001)(2501003)(54906003)(486006)(8936002)(4326008)(102836004)(575784001)(14444005)(478600001)(7736002)(316002)(14454004)(256004)(71190400001)(86362001)(105586002)(3846002)(6116002)(186003)(6512007)(53936002)(386003)(99286004)(6506007)(97736004)(26005)(2616005)(11346002)(476003)(66066001)(6436002)(36756003)(25786009)(53346004)(68736007)(446003)(1076003)(6486002)(2906002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR04MB2126;H:VI1PR04MB5040.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: tZj8hIBxdQiFyXRZ37J6aJAz8ng6jxPCIQ3AUC3eGHa6+3hClLVrgazQtiRjbgN0SsqhByKPjerBqk3iksic+6YIv942udYZnqtL/hc7+cEbXbIpF3xr2wPKvZM9o0jGzFr0ed8BfPqUbzNyeVzaohY1ji0lnDtQYPZmZPujCYUXuWPe/smrl6rVGlB+WOgkAYWgWg2Jrk2jzMajC22t6xSm5yFoJtL8RkAKrViR07ZAdgrKkfKxE7+PPMpO+0arT0/VUviUoWd8vl3uLwZYf0N+xClSyYnurfn3BFav5clpdWSM7FtSw/ovN5GA1O5f spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: aee3fa2b-16fb-48bf-e477-08d674888375 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Jan 2019 10:11:36.5356 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB2126 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add CMDQ support for imx8qm/imx8qxp. Signed-off-by: Haibo Chen Acked-by: Adrian Hunter --- drivers/mmc/host/Kconfig | 1 + drivers/mmc/host/sdhci-esdhc-imx.c | 116 ++++++++++++++++++++++++++++- 2 files changed, 114 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig index cf984f0f0246..1d67d253f564 100644 --- a/drivers/mmc/host/Kconfig +++ b/drivers/mmc/host/Kconfig @@ -214,6 +214,7 @@ config MMC_SDHCI_ESDHC_IMX depends on ARCH_MXC depends on MMC_SDHCI_PLTFM select MMC_SDHCI_IO_ACCESSORS + select MMC_CQHCI help This selects the Freescale eSDHC/uSDHC controller support found on i.MX25, i.MX35 i.MX5x and i.MX6x. diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c index 08bba97706d0..3ada951f9df5 100644 --- a/drivers/mmc/host/sdhci-esdhc-imx.c +++ b/drivers/mmc/host/sdhci-esdhc-imx.c @@ -27,6 +27,7 @@ #include #include "sdhci-pltfm.h" #include "sdhci-esdhc.h" +#include "cqhci.h" #define ESDHC_SYS_CTRL_DTOCV_MASK 0x0f #define ESDHC_CTRL_D3CD 0x08 @@ -106,6 +107,9 @@ */ #define ESDHC_INT_VENDOR_SPEC_DMA_ERR (1 << 28) +/* the address offset of CQHCI */ +#define ESDHC_CQHCI_ADDR_OFFSET 0x100 + /* * The CMDTYPE of the CMD register (offset 0xE) should be set to * "11" when the STOP CMD12 is issued on imx53 to abort one @@ -143,6 +147,8 @@ #define ESDHC_FLAG_HS400 BIT(9) /* The IP supports HS400ES mode */ #define ESDHC_FLAG_HS400_ES BIT(10) +/* The IP has Host Controller Interface for Command Queuing */ +#define ESDHC_FLAG_CQHCI BIT(11) struct esdhc_soc_data { u32 flags; @@ -188,7 +194,8 @@ static struct esdhc_soc_data usdhc_imx7d_data = { static struct esdhc_soc_data usdhc_imx8qxp_data = { .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING | ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200 - | ESDHC_FLAG_HS400 | ESDHC_FLAG_HS400_ES, + | ESDHC_FLAG_HS400 | ESDHC_FLAG_HS400_ES + | ESDHC_FLAG_CQHCI, }; struct pltfm_imx_data { @@ -1061,6 +1068,19 @@ static void esdhc_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) SDHCI_TIMEOUT_CONTROL); } +static u32 esdhc_cqhci_irq(struct sdhci_host *host, u32 intmask) +{ + int cmd_error = 0; + int data_error = 0; + + if (!sdhci_cqe_irq(host, intmask, &cmd_error, &data_error)) + return intmask; + + cqhci_irq(host->mmc, intmask, cmd_error, data_error); + + return 0; +} + static struct sdhci_ops sdhci_esdhc_ops = { .read_l = esdhc_readl_le, .read_w = esdhc_readw_le, @@ -1077,6 +1097,7 @@ static struct sdhci_ops sdhci_esdhc_ops = { .set_bus_width = esdhc_pltfm_set_bus_width, .set_uhs_signaling = esdhc_set_uhs_signaling, .reset = esdhc_reset, + .irq = esdhc_cqhci_irq, }; static const struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = { @@ -1152,6 +1173,55 @@ static void sdhci_esdhc_imx_hwinit(struct sdhci_host *host) } } +static void esdhc_cqe_enable(struct mmc_host *mmc) +{ + struct sdhci_host *host = mmc_priv(mmc); + u32 reg; + u16 mode; + int count = 10; + + /* + * CQE gets stuck if it sees Buffer Read Enable bit set, which can be + * the case after tuning, so ensure the buffer is drained. + */ + reg = sdhci_readl(host, SDHCI_PRESENT_STATE); + while (reg & SDHCI_DATA_AVAILABLE) { + sdhci_readl(host, SDHCI_BUFFER); + reg = sdhci_readl(host, SDHCI_PRESENT_STATE); + if (count-- == 0) { + dev_warn(mmc_dev(host->mmc), + "CQE may get stuck because the Buffer Read Enable bit is set\n"); + break; + } + mdelay(1); + } + + /* + * Runtime resume will reset the entire host controller, which + * will also clear the DMAEN/BCEN of register ESDHC_MIX_CTRL. + * Here set DMAEN and BCEN when enable CMDQ. + */ + mode = sdhci_readw(host, SDHCI_TRANSFER_MODE); + if (host->flags & SDHCI_REQ_USE_DMA) + mode |= SDHCI_TRNS_DMA; + if (!(host->quirks2 & SDHCI_QUIRK2_SUPPORT_SINGLE)) + mode |= SDHCI_TRNS_BLK_CNT_EN; + sdhci_writew(host, mode, SDHCI_TRANSFER_MODE); + + sdhci_cqe_enable(mmc); +} + +static void esdhc_sdhci_dumpregs(struct mmc_host *mmc) +{ + sdhci_dumpregs(mmc_priv(mmc)); +} + +static const struct cqhci_host_ops esdhc_cqhci_ops = { + .enable = esdhc_cqe_enable, + .disable = sdhci_cqe_disable, + .dumpregs = esdhc_sdhci_dumpregs, +}; + #ifdef CONFIG_OF static int sdhci_esdhc_imx_probe_dt(struct platform_device *pdev, @@ -1279,6 +1349,7 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev) of_match_device(imx_esdhc_dt_ids, &pdev->dev); struct sdhci_pltfm_host *pltfm_host; struct sdhci_host *host; + struct cqhci_host *cq_host; int err; struct pltfm_imx_data *imx_data; @@ -1363,6 +1434,22 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev) esdhc_hs400_enhanced_strobe; } + if (imx_data->socdata->flags & ESDHC_FLAG_CQHCI) { + host->mmc->caps2 |= MMC_CAP2_CQE; + cq_host = devm_kzalloc(&pdev->dev, sizeof(*cq_host), GFP_KERNEL); + if (IS_ERR(cq_host)) { + err = PTR_ERR(cq_host); + goto disable_ahb_clk; + } + + cq_host->mmio = host->ioaddr + ESDHC_CQHCI_ADDR_OFFSET; + cq_host->ops = &esdhc_cqhci_ops; + + err = cqhci_init(cq_host, host->mmc, false); + if (err) + goto disable_ahb_clk; + } + if (of_id) err = sdhci_esdhc_imx_probe_dt(pdev, host, imx_data); else @@ -1425,6 +1512,12 @@ static int sdhci_esdhc_suspend(struct device *dev) struct sdhci_host *host = dev_get_drvdata(dev); int ret; + if (host->mmc->caps2 & MMC_CAP2_CQE) { + ret = cqhci_suspend(host->mmc); + if (ret) + return ret; + } + if (host->tuning_mode != SDHCI_TUNING_MODE_3) mmc_retune_needed(host->mmc); @@ -1437,13 +1530,21 @@ static int sdhci_esdhc_suspend(struct device *dev) static int sdhci_esdhc_resume(struct device *dev) { struct sdhci_host *host = dev_get_drvdata(dev); + int ret; pinctrl_pm_select_default_state(dev); /* re-initialize hw state in case it's lost in low power mode */ sdhci_esdhc_imx_hwinit(host); - return sdhci_resume_host(host); + ret = sdhci_resume_host(host); + if (ret) + return ret; + + if (host->mmc->caps2 & MMC_CAP2_CQE) + ret = cqhci_resume(host->mmc); + + return ret; } #endif @@ -1455,6 +1556,12 @@ static int sdhci_esdhc_runtime_suspend(struct device *dev) struct pltfm_imx_data *imx_data = sdhci_pltfm_priv(pltfm_host); int ret; + if (host->mmc->caps2 & MMC_CAP2_CQE) { + ret = cqhci_suspend(host->mmc); + if (ret) + return ret; + } + ret = sdhci_runtime_suspend_host(host); if (ret) return ret; @@ -1498,7 +1605,10 @@ static int sdhci_esdhc_runtime_resume(struct device *dev) if (err) goto disable_ipg_clk; - return 0; + if (host->mmc->caps2 & MMC_CAP2_CQE) + err = cqhci_resume(host->mmc); + + return err; disable_ipg_clk: if (!sdhci_sdio_irq_enabled(host))