From patchwork Wed Aug 10 08:03:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guodong Xu X-Patchwork-Id: 9273521 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 95DF86075E for ; Wed, 10 Aug 2016 18:40:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86B3125EA6 for ; Wed, 10 Aug 2016 18:40:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7896026785; Wed, 10 Aug 2016 18:40:00 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 C2BF226785 for ; Wed, 10 Aug 2016 18:39:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753463AbcHJSjy (ORCPT ); Wed, 10 Aug 2016 14:39:54 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:35641 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751059AbcHJSjw (ORCPT ); Wed, 10 Aug 2016 14:39:52 -0400 Received: by mail-pf0-f175.google.com with SMTP id x72so18414868pfd.2 for ; Wed, 10 Aug 2016 11:39:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nfSyP9hh+ZHNkGQk/FRRqhVBWHeYwaWnwMGCVvg3qOA=; b=JzdZGJ+qGRBi6TZx5MuB7NztcXOyVZpndU57mYx+GOCPZDajeYp4ZtkbZtU06Q4bPF UjxMC80bhYH+eQOrrX17U4eXv7DWDmc0HpMgyBuRzeAzmEpvmfbtmZQbc8ep2gomNiH1 8TEoasB1wCPPAId2+l/vOe2kg1LitWepynySI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nfSyP9hh+ZHNkGQk/FRRqhVBWHeYwaWnwMGCVvg3qOA=; b=OSwxz4R71RfMDR6I9Un/N8Tppfj/DthsiKCfrQDoGIGmXNO2w5rUhU3THnBD885TBn 3EE1ykEf/DUTJQ/sdDTOjkWrUIx3b9qgotw/qbPrGbv2Sv7marFNm8k0lFdr7OyeKYet nQCV8uYGbzZ7ncHHeZrn+fVlmHu29PR1+Ap04XMpWHFxA5AHMlRCrP9yJUJPeMsGZGGf hyjb3FQzBevUHHg/Io2NtuhcRopvArm6zvJa7vMpHz85r11Rlgh92uRMQWoJpD/YMUqG pVX2DS9GN5KNCLq0TRMfnGCahTs/mhxmquiCeIG4p5S6CD/GZ7kmKXwRaBs5BRrfytHv zPUg== X-Gm-Message-State: AEkooutHM0ccGGEnGRtAtxp4r3m9ABvjntW4O3nrliqIDYc13hLse6rDeN4CXATpE4iDJFTB X-Received: by 10.98.80.220 with SMTP id g89mr4872698pfj.12.1470816245935; Wed, 10 Aug 2016 01:04:05 -0700 (PDT) Received: from localhost.localdomain ([45.56.159.82]) by smtp.gmail.com with ESMTPSA id 15sm61387706pfz.36.2016.08.10.01.04.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Aug 2016 01:04:05 -0700 (PDT) From: Guodong Xu To: heiko@sntech.de, shawn.lin@rock-chips.com, jh80.chung@samsung.com, robh+dt@kernel.org, mark.rutland@arm.com, ulf.hansson@linaro.org, guodong.xu@linaro.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mmc@vger.kernel.org, Xinwei Kong , Zhangfei Gao Subject: [PATCH v4 2/2] mmc: dw_mmc: add reset support to dwmmc host controller Date: Wed, 10 Aug 2016 16:03:48 +0800 Message-Id: <1470816228-8874-3-git-send-email-guodong.xu@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470816228-8874-1-git-send-email-guodong.xu@linaro.org> References: <1470816228-8874-1-git-send-email-guodong.xu@linaro.org> 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 Dwmmc host controller may in unknown state when entering kernel boot. One example is when booting from eMMC, bootloader need initialize MMC host controller into some state so it can read. In order to make sure MMC host controller in a clean initial state, this reset support is added. With this patch, a 'resets' property can be added into dw_mmc device tree node. The hardware logic is: dwmmc host controller IP receives a reset signal from a 'reset provider' (eg. power management unit). The 'resets' property points to this reset signal. So, during dwmmc driver probe, it can use this signal to reset itself. Refer to [1] for more information. [1] Documentation/devicetree/bindings/reset/reset.txt Signed-off-by: Guodong Xu Signed-off-by: Xinwei Kong Signed-off-by: Zhangfei Gao Reviewed-by: Shawn Lin --- drivers/mmc/host/dw_mmc.c | 23 ++++++++++++++++++++++- include/linux/mmc/dw_mmc.h | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 32380d5..481d441 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -2915,6 +2915,13 @@ static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host) if (!pdata) return ERR_PTR(-ENOMEM); + /* find reset controller when exist */ + pdata->rstc = devm_reset_control_get_optional(dev, NULL); + if (IS_ERR(pdata->rstc)) { + if (PTR_ERR(pdata->rstc) == -EPROBE_DEFER) + return ERR_PTR(-EPROBE_DEFER); + } + /* find out number of slots supported */ of_property_read_u32(np, "num-slots", &pdata->num_slots); @@ -2986,7 +2993,9 @@ int dw_mci_probe(struct dw_mci *host) if (!host->pdata) { host->pdata = dw_mci_parse_dt(host); - if (IS_ERR(host->pdata)) { + if (PTR_ERR(host->pdata) == -EPROBE_DEFER) { + return -EPROBE_DEFER; + } else if (IS_ERR(host->pdata)) { dev_err(host->dev, "platform data not available\n"); return -EINVAL; } @@ -3040,6 +3049,12 @@ int dw_mci_probe(struct dw_mci *host) } } + if (!IS_ERR(host->pdata->rstc)) { + reset_control_assert(host->pdata->rstc); + usleep_range(10, 50); + reset_control_deassert(host->pdata->rstc); + } + setup_timer(&host->cmd11_timer, dw_mci_cmd11_timer, (unsigned long)host); @@ -3189,6 +3204,9 @@ err_dmaunmap: if (host->use_dma && host->dma_ops->exit) host->dma_ops->exit(host); + if (!IS_ERR(host->pdata->rstc)) + reset_control_assert(host->pdata->rstc); + err_clk_ciu: if (!IS_ERR(host->ciu_clk)) clk_disable_unprepare(host->ciu_clk); @@ -3221,6 +3239,9 @@ void dw_mci_remove(struct dw_mci *host) if (host->use_dma && host->dma_ops->exit) host->dma_ops->exit(host); + if (!IS_ERR(host->pdata->rstc)) + reset_control_assert(host->pdata->rstc); + if (!IS_ERR(host->ciu_clk)) clk_disable_unprepare(host->ciu_clk); diff --git a/include/linux/mmc/dw_mmc.h b/include/linux/mmc/dw_mmc.h index 83b0edfc..f5af2bd 100644 --- a/include/linux/mmc/dw_mmc.h +++ b/include/linux/mmc/dw_mmc.h @@ -17,6 +17,7 @@ #include #include #include +#include #define MAX_MCI_SLOTS 2 @@ -259,6 +260,7 @@ struct dw_mci_board { /* delay in mS before detecting cards after interrupt */ u32 detect_delay_ms; + struct reset_control *rstc; struct dw_mci_dma_ops *dma_ops; struct dma_pdata *data; };