From patchwork Thu Jun 6 01:02:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 165939 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp8057712ili; Wed, 5 Jun 2019 18:03:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzViHa87I0r/qBrfJ1VM3d3+m21kdHFHtpFk3jwHkS7tzgL8gS8JvyFyWMHJAVXQdzM0qN/ X-Received: by 2002:a17:902:1125:: with SMTP id d34mr47194526pla.101.1559782984207; Wed, 05 Jun 2019 18:03:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559782984; cv=none; d=google.com; s=arc-20160816; b=SQT9O5XPqaPiOJkcGr+GjQ/Evh/1SVWrLOp7/wG3YSGbL2oIHU9i6+1NrDI6lspxXF 0eBr3EKD/YkxPQrf5hjX8usEUnNV2EXMg3CmVElwgydVWjyIlXe+FkIhkLl/vyMakTXL wUwfQCI/jk3BIQccdV9NxGjNzudlYafCJatiGmqOYQR5nanFhBCtbEBt3yhTagYXm1Zi 9vrR5xWYr3QO8fzCn93F6+ET+VqsC8uZ/z8Atpl02qf/hEBFf7tSpCxL5nuTMWDnoFez p/bMuC+n0VJHBXXuypKrUITtvu/MwgkB3ccUcbuTahdKM7oEHanANTcBHjRFVhhKg/3K G+OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=TRkaMCNla3WROe2zX2J+aawx5FPMRl6GLVsgLcTqYp4=; b=k3GzfPUxfoPN7VJQhCXkqJkzjCx1PkbHyJUF1yT1RDH5zaO1xjoU7K69uI+7Rqf0i0 aAbJJJ4XA+F9NBF0ZmdEztXLgyCEUgmlkuoWFt0TdjMIFf9WMfTkQMivnThelBx/7BWT X5oKcaS/tcfxb3LU6Rr0Ch8a9BfGtyTbJWEfIjeRLqlLLNXXMTKvyzNdYxChyssrFaDo ZYrennNxXAYiZOuOYki09i8kCXLX3fUpcOompehX/GQEWMAH3ylIKV1JibfGDWAzZayc Zevqm4JKmAQK8SsczTMqMAjdda2W3WYCzYLNhD/oT5PFdi5BWj1VMMukr6YT8zBoOOt8 u61g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="K/0/Gm79"; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p5si157489pls.431.2019.06.05.18.03.03; Wed, 05 Jun 2019 18:03:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="K/0/Gm79"; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726728AbfFFBDD (ORCPT + 15 others); Wed, 5 Jun 2019 21:03:03 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:36768 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726691AbfFFBC4 (ORCPT ); Wed, 5 Jun 2019 21:02:56 -0400 Received: by mail-pl1-f195.google.com with SMTP id d21so206264plr.3 for ; Wed, 05 Jun 2019 18:02:56 -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=TRkaMCNla3WROe2zX2J+aawx5FPMRl6GLVsgLcTqYp4=; b=K/0/Gm794r4cZynF3tQa3us7NLsO4055saUEDKMdCoqEl8/U5h3/6Bcr1JpalYR7Ja WZilVpAMt32SJrlRaVuMyC9E2bRt5qpGoLFZmQBY/xLov2/FQG9+dPbH86jHN7SkdDOU Jv7hPFz25UgshRGGPpj/weMhRpcPpKV/44/J//8xxQYn16cjNJ6fKmxz3vjoXyctwMii YJSFbuFXe68CJl2iaCJc7ADESb6+q3pU9W3s0glKdeEFPVffRYDCsLmZQsjGqpL531H0 /iTsZGABgYdgBYVkp/Z9x3KvjLrIx8bUnklmu2n93jGrNvlO16/qNXp8Da9h8nyFRfvE Knew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TRkaMCNla3WROe2zX2J+aawx5FPMRl6GLVsgLcTqYp4=; b=r2k9ns0aFo25ZxAYWD4eobRXuC5rm8NYigYYwE/YNIS3V5xcHyNtnZP5eRsoCo/6Kw DkdY8WsAdzRDlzC8B+wbMkarCueMvfFgbEzAM4oYos12fx8kqnysckptjKRGSyWI+yrK 2OrX+Ui0KIH24yZA/GhaCg0/Cls7IfulPXL45R6JlK8z5GxC34AUTgbDP4GMuJYrnXXi 4d99gLwFP/O1HfFubm+IP50GbeGaCxNUDF3z7AxDuVW7oUPW40w+g0RVDNNvwKSFNtTU iCszeugK+MYqBmU8GHXWJ/DQ0dn53KWzZSn++tvj0LfTVK7dLsNJXGrmGEinBWxJGCC6 pwxA== X-Gm-Message-State: APjAAAWKhdNu+XUtZotbgPMdRQAp8T1rEVuqHUk9mjXygmOfqhmjCWKL RU6tz5CEBRYJGh0c/bR1skmRishF9T4= X-Received: by 2002:a17:902:1003:: with SMTP id b3mr48249534pla.172.1559782975403; Wed, 05 Jun 2019 18:02:55 -0700 (PDT) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id 144sm170856pfy.54.2019.06.05.18.02.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jun 2019 18:02:54 -0700 (PDT) From: Bjorn Andersson To: Rob Herring , Mark Rutland , Alim Akhtar , Avri Altman , Pedro Sousa , "James E.J. Bottomley" , "Martin K. Petersen" Cc: Andy Gross , Linus Walleij , Evan Green , linux-arm-msm@vger.kernel.org, linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH v2 2/3] scsi: ufs: Allow resetting the UFS device Date: Wed, 5 Jun 2019 18:02:48 -0700 Message-Id: <20190606010249.3538-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190606010249.3538-1-bjorn.andersson@linaro.org> References: <20190606010249.3538-1-bjorn.andersson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Acquire the device-reset GPIO and toggle this to reset the UFS device during initialization and host reset. Based on downstream support implemented by Subhash Jadavani . Tested-by: John Stultz Signed-off-by: Bjorn Andersson --- Changes since v1: - Added gpio to DT binding document - Fixed spelling of UFS .../devicetree/bindings/ufs/ufshcd-pltfrm.txt | 2 + drivers/scsi/ufs/ufshcd.c | 44 +++++++++++++++++++ drivers/scsi/ufs/ufshcd.h | 4 ++ 3 files changed, 50 insertions(+) -- 2.18.0 Reviewed-by: Linus Walleij diff --git a/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt b/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt index a74720486ee2..d562d8b4919c 100644 --- a/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt +++ b/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt @@ -54,6 +54,8 @@ Optional properties: PHY reset from the UFS controller. - resets : reset node register - reset-names : describe reset node register, the "rst" corresponds to reset the whole UFS IP. +- device-reset-gpios : A phandle and gpio specifier denoting the GPIO connected + to the RESET pin of the UFS memory device. Note: If above properties are not defined it can be assumed that the supply regulators or clocks are always on. diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index a208589426b1..eaa384d67684 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "ufshcd.h" #include "ufs_quirks.h" #include "unipro.h" @@ -6135,6 +6136,25 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) return err; } +/** + * ufshcd_device_reset() - toggle the (optional) device reset line + * @hba: per-adapter instance + * + * Toggles the (optional) reset line to reset the attached device. + */ +static void ufshcd_device_reset(struct ufs_hba *hba) +{ + /* + * The UFS device shall detect reset pulses of 1us, sleep for 10us to + * be on the safe side. + */ + gpiod_set_value_cansleep(hba->device_reset, 1); + usleep_range(10, 15); + + gpiod_set_value_cansleep(hba->device_reset, 0); + usleep_range(10, 15); +} + /** * ufshcd_host_reset_and_restore - reset and restore host controller * @hba: per-adapter instance @@ -6190,6 +6210,9 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba) int retries = MAX_HOST_RESET_RETRIES; do { + /* Reset the attached device */ + ufshcd_device_reset(hba); + err = ufshcd_host_reset_and_restore(hba); } while (err && --retries); @@ -7386,6 +7409,18 @@ static void ufshcd_variant_hba_exit(struct ufs_hba *hba) ufshcd_vops_exit(hba); } +static int ufshcd_init_device_reset(struct ufs_hba *hba) +{ + hba->device_reset = devm_gpiod_get_optional(hba->dev, "device-reset", + GPIOD_OUT_HIGH); + if (IS_ERR(hba->device_reset)) { + dev_err(hba->dev, "failed to acquire reset gpio: %ld\n", + PTR_ERR(hba->device_reset)); + } + + return PTR_ERR_OR_ZERO(hba->device_reset); +} + static int ufshcd_hba_init(struct ufs_hba *hba) { int err; @@ -7425,9 +7460,15 @@ static int ufshcd_hba_init(struct ufs_hba *hba) if (err) goto out_disable_vreg; + err = ufshcd_init_device_reset(hba); + if (err) + goto out_disable_variant; + hba->is_powered = true; goto out; +out_disable_variant: + ufshcd_vops_setup_regulators(hba, false); out_disable_vreg: ufshcd_setup_vreg(hba, false); out_disable_clks: @@ -8321,6 +8362,9 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) goto exit_gating; } + /* Reset the attached device */ + ufshcd_device_reset(hba); + /* Host controller enable */ err = ufshcd_hba_enable(hba); if (err) { diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 994d73d03207..4443928ba7d2 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -72,6 +72,8 @@ #define UFSHCD "ufshcd" #define UFSHCD_DRIVER_VERSION "0.2" +struct gpio_desc; + struct ufs_hba; enum dev_cmd_type { @@ -706,6 +708,8 @@ struct ufs_hba { struct device bsg_dev; struct request_queue *bsg_queue; + + struct gpio_desc *device_reset; }; /* Returns true if clocks can be gated. Otherwise false */