Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5070649ybi; Tue, 4 Jun 2019 00:21:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6Eqm6geOnykdNQIWMCkTbUJcoteRjm4JhorvfpwZ77NxJ2kM4FRp1AXLr6oobTNtZ1tRb X-Received: by 2002:a63:135d:: with SMTP id 29mr32631151pgt.38.1559632898554; Tue, 04 Jun 2019 00:21:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559632898; cv=none; d=google.com; s=arc-20160816; b=eqGNqp38b4041kEAEXuqRIHs9LPqux8mbEVL6yd3uRMu0ZjAQrvfhX4M90kbu+x4Fx HFESi+3q57Ux10Xg9ici7rsGItHLoj+m+EVvfiu0nwUcmG/NB9Gw0GU3HuYUivmPJCAt SEa1VeD04EyGbDJ3Oxm3zWq3PEeGmniLrXRSMHUZqCt4lY3w8/dhHkX6K3IgaAxr67H+ 8dvJAUjDMbcdUWJFcfLrO/ZZgOOyqW2SWL/kEYjZOwZsHqzfz1vkHv2D2rSqzbye3rho 7jwCSWkOmlnlhgYon4bheEMpY3gyDPI+D3ZW2oSz8iR+NevNSZewvWADLxIFoGf3U6kw CW1g== 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=D3XWMIqhXFSeKwJRGJ6IYznTDgg0AaloPMfGvuC80wY=; b=MQlg4kBue+hMZmoLzWYdJT5UcKHC7cKOgfSGOrCLXS8yyP4Aa80FGwRWl1rd+WdF8x 4TDSSn5r9Z22iCCOhD515JdSZzz9xjtbnKGXICBENU7kBvnF4hpyq6o0ZtuNWpEF/ldj 7SivCgMRzKIbXZbgRm6Zn71giaRx4D/gDpp6WIZ4FRKeWdugL7koseVZGIz4x4jlHpkm pps7kI+q88yTq1Vr5GmAO+pwg3b1yhU08oDX45LaxTUQqyb9dbrJeXytqbAmwUF9Gbvk WWUVgmuwC4cUcIh/h3tZzpZ4lqv7xN8pUqt1lbOqDfAoQ0P+m3F7Ph2Lxvy8ZaEY/ekK n2yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X8Atb4xA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 g16si17452972pfi.31.2019.06.04.00.21.22; Tue, 04 Jun 2019 00:21:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=X8Atb4xA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1726963AbfFDHUJ (ORCPT + 99 others); Tue, 4 Jun 2019 03:20:09 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:45131 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726885AbfFDHUH (ORCPT ); Tue, 4 Jun 2019 03:20:07 -0400 Received: by mail-pf1-f194.google.com with SMTP id s11so12113093pfm.12 for ; Tue, 04 Jun 2019 00:20:07 -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=D3XWMIqhXFSeKwJRGJ6IYznTDgg0AaloPMfGvuC80wY=; b=X8Atb4xA74DTxVSx/Ukx/fVa0wQKoezZtlxqvBf96Cf95zR2X1FfRXwJesGaQZdL81 Ki3C59Rptp13xpbiX/YwbAQriKHHYOP8RB57asRp25JOM9bmtIgLSecC3+xGNnzsRB/h Xr8W/s+GvDudZP7kUJBeUMf4LPBBKOwKQvyhcIF2pPwUc4M0COinI0f0F9NFxjWqY2y3 KsN2qiYtNfie3Dyb5EO7qO13QROoyWkuFLfEc7m74O01zBpWkQw0GTg2EdHfBiZeD+d9 cZDV5H3fJjtubbILssEhG3IOyBv9mAKLCWwsDVQupXFYhQ5+6TLcCZRQv7dhqVJGWL6z 8CAQ== 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=D3XWMIqhXFSeKwJRGJ6IYznTDgg0AaloPMfGvuC80wY=; b=Fi2uB3NQqDGnDKXEhWS2DmH8AhU47Xb9mIsb0f5Mb4lcxtkLDgSP8a6l7TGPId3Sgl uO6nJyymvn2qX1peejxhy0hxw/tkWddmFNCdkbFvCHLxthV8SXPNJnbe0RfitXTegbOS NkNumnXEP9fvQDx+67Sax81ArGJl1//n+flMYj4aNEcNKR442g4/abAq0VNtA6HZnO5t o9oq77fWasVvbc6qNFKCNgU/9svB21vzRPocxJ5lJYI3Jjwyyl/C9PsK2VtylnZURpEZ gJTIhtKFHPOKy2ZPAfcuEWFH83htgucQdiB2LLp9AKt+78dqgv5fdRchraxbMr+1V5Yd 9G5w== X-Gm-Message-State: APjAAAUZOQwtX7cYx3BYYPGwOsb88EQpCiojSC4L7g9oOr7cj4rO+w1Z d5POZJ6ER7opylgQlBpOqcJvMw== X-Received: by 2002:a17:90a:9504:: with SMTP id t4mr35609032pjo.100.1559632806648; Tue, 04 Jun 2019 00:20:06 -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 d6sm17747446pgv.4.2019.06.04.00.20.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jun 2019 00:20:06 -0700 (PDT) From: Bjorn Andersson To: Pedro Sousa , "James E.J. Bottomley" , "Martin K. Petersen" Cc: Andy Gross , Linus Walleij , Rob Herring , Mark Rutland , 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 2/3] scsi: ufs: Allow resetting the UFS device Date: Tue, 4 Jun 2019 00:20:00 -0700 Message-Id: <20190604072001.9288-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190604072001.9288-1-bjorn.andersson@linaro.org> References: <20190604072001.9288-1-bjorn.andersson@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Acquire the device-reset GPIO and toggle this to reset the UFS device during initialization and host reset. Signed-off-by: Bjorn Andersson --- drivers/scsi/ufs/ufshcd.c | 44 +++++++++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd.h | 4 ++++ 2 files changed, 48 insertions(+) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 8c1c551f2b42..951a0efee536 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" @@ -6104,6 +6105,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 USB 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 @@ -6159,6 +6179,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); @@ -7355,6 +7378,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; @@ -7394,9 +7429,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: @@ -8290,6 +8331,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 ecfa898b9ccc..d8be67742168 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 */ -- 2.18.0