Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp740465imm; Tue, 5 Jun 2018 03:49:34 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIY6HL2sTuJuLrSzGtjXST04/trLJijQpr/28W4sVOeWESExK+Syc+w4otPB2ctYo9xbrE/ X-Received: by 2002:a17:902:2006:: with SMTP id n6-v6mr26094164pla.125.1528195774568; Tue, 05 Jun 2018 03:49:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528195774; cv=none; d=google.com; s=arc-20160816; b=f9DVVt9JPpMS6D+lGnOVqxVz8PSOdvUjemVAwzy87M4XoyVwO0M66p6YtnWQetsCct V7iNyVOkj5ExM7b7ZWN/+pTAa5LXYpyKPsVpEEpPb7ncfoCkFq2N/f4Pssu1aG8wo6MG WafbFqZP/6v7OFeohuScuajN43pScOHrQX6BSsczyjyJzejOOw3nxKMLi67EZEVCVYsY 28tHRZOMj/LeO23EvBXsuD0GCv1HSPksQcmGNcUI0dC4o6wo1fT6cnGO9vAgyhHsBFEX rc74g4A0JKuIlmKQsFB6O8W1Ea9i7RJj4lMDDAK7QiE9a5/m8K3E9Se0VKX83JUqOSRW Kvfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language:thread-index :content-transfer-encoding:mime-version:message-id:date:subject :in-reply-to:references:cc:to:from:dmarc-filter:dkim-signature :dkim-signature:arc-authentication-results; bh=bNJzPqw0tXV6dp5W9OOeMZMYnHop5mRrxoHnxreG+Eg=; b=wYvZlZ3WUVIy9m3yJKc5VF+mr5z9es2NRGbQCqIFiPsR6+I6nCreSD3VtLZJSvlyKF IAF58rH/POA0XswzfK73JaG2Pu7FrdhZflaaNIlp+g1R3DsjEU21K+NXdlM7K2hQ8UXg Oo2pM+wR2OH9sQn5mKViqw9co60kVnQgF6V0RyH9hoRR1Sn8Tf0cOlPJNgupldla91Sq 1mNWbLViXiyNE6f+8GwwxCn66b6zo01gEmE0E/tC6bFKwpa5xrmi0bxAC61rnA5wks7p a0pFXeunny/WpNS1BeQ19+Q2c5RaSw4M2CBvI+inEJEVqMTXA4yzJURsd8Oc3uwFAVXE lVyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=VTGH7WF/; dkim=pass header.i=@codeaurora.org header.s=default header.b=I9LR4DxA; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t23-v6si50335304plo.508.2018.06.05.03.49.20; Tue, 05 Jun 2018 03:49:34 -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=@codeaurora.org header.s=default header.b=VTGH7WF/; dkim=pass header.i=@codeaurora.org header.s=default header.b=I9LR4DxA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751619AbeFEKs4 (ORCPT + 99 others); Tue, 5 Jun 2018 06:48:56 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:59402 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751498AbeFEKsy (ORCPT ); Tue, 5 Jun 2018 06:48:54 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id CAC0D60591; Tue, 5 Jun 2018 10:48:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1528195733; bh=Vuc4wTpc6tLrVXphFGLrwOLlwlR1xpsSiv/CIHMubCA=; h=From:To:Cc:References:In-Reply-To:Subject:Date:From; b=VTGH7WF/sYHwn0qtnIG78xGh5+UtPS+Li7W12pE0Hd8pJxU7e1OwrCosQbcGS7fOE 3mZgFbaMHf3iaKsPNl6p1urIg0zzeEzF3cc239pqMqQety4QT7763AaR1eU5iu5Vvh DHjizloc5PdtRUY04bgP2VKpkZylSpiErF0xbtf0= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,TVD_RCVD_SINGLE,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from SAYALIL (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: sayalil@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 6AC45601A8; Tue, 5 Jun 2018 10:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1528195732; bh=Vuc4wTpc6tLrVXphFGLrwOLlwlR1xpsSiv/CIHMubCA=; h=From:To:Cc:References:In-Reply-To:Subject:Date:From; b=I9LR4DxAS9osoaraXdmKF8DfbG+ZAHiERwAFn4oBvfOCbbwfer5v3HdUv1uku5L2l twHeiom8pttPiQyCWTsMXvT2nhXY8ytbF1Hu3cLtjQ2iW0+S4V052fpVaxAqnrq7z+ gmLZWfGUUIKhF6RimU7wsYvLiPrtqabveHzQqhks= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 6AC45601A8 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=sayalil@codeaurora.org From: "sayali" To: "'Kyuho Choi'" Cc: , , , , , , , , , , "'open list'" References: <1527849774-7623-1-git-send-email-sayalil@codeaurora.org> <1527849774-7623-2-git-send-email-sayalil@codeaurora.org> In-Reply-To: Subject: RE: [PATCH V1 1/3] scsi: ufs: set the device reference clock setting Date: Tue, 5 Jun 2018 16:18:46 +0530 Message-ID: <000801d3fcba$cafa3c30$60eeb490$@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQKGja9h2+sAa9B7VDYjBpPLWNjYigKV7YTZAlkPtOiixOBpYA== Content-Language: en-us Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org -----Original Message----- From: Kyuho Choi [mailto:chlrbgh0@gmail.com]=20 Sent: Saturday, June 02, 2018 11:04 AM To: Sayali Lokhande Cc: subhashj@codeaurora.org; cang@codeaurora.org; = vivek.gautam@codeaurora.org; rnayak@codeaurora.org; = vinholikatti@gmail.com; jejb@linux.vnet.ibm.com; = martin.petersen@oracle.com; asutoshd@codeaurora.org; = evgreen@chromium.org; linux-scsi@vger.kernel.org; open list = Subject: Re: [PATCH V1 1/3] scsi: ufs: set the device reference clock = setting Hi Sayali, On 6/1/18, Sayali Lokhande wrote: > From: Subhash Jadavani > > UFS host supplies the reference clock to UFS device and UFS device=20 > specification allows host to provide one of the 4 frequencies (19.2=20 > MHz, > 26 MHz, 38.4 MHz, 52 MHz) for reference clock. Host should set the=20 > device reference clock frequency setting in the device based on what=20 > frequency it is supplying to UFS device. > > Signed-off-by: Subhash Jadavani > [cang@codeaurora.org: Resolved trivial merge conflicts] > Signed-off-by: Can Guo > Signed-off-by: Sayali Lokhande > --- > drivers/scsi/ufs/ufs.h | 9 +++++++ > drivers/scsi/ufs/ufshcd.c | 62 > +++++++++++++++++++++++++++++++++++++++++++++++ > drivers/scsi/ufs/ufshcd.h | 1 + > 3 files changed, 72 insertions(+) > > diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index=20 > 14e5bf7..e15deb0 100644 > --- a/drivers/scsi/ufs/ufs.h > +++ b/drivers/scsi/ufs/ufs.h > @@ -378,6 +378,15 @@ enum query_opcode { > UPIU_QUERY_OPCODE_TOGGLE_FLAG =3D 0x8, > }; > > +/* bRefClkFreq attribute values */ > +enum ref_clk_freq { > + REF_CLK_FREQ_19_2_MHZ =3D 0x0, > + REF_CLK_FREQ_26_MHZ =3D 0x1, > + REF_CLK_FREQ_38_4_MHZ =3D 0x2, > + REF_CLK_FREQ_52_MHZ =3D 0x3, > + REF_CLK_FREQ_MAX =3D REF_CLK_FREQ_52_MHZ, > +}; > + > /* Query response result code */ > enum { > QUERY_RESULT_SUCCESS =3D 0x00, > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c=20 > index c5b1bf1..3669bc4 100644 > --- a/drivers/scsi/ufs/ufshcd.c > +++ b/drivers/scsi/ufs/ufshcd.c > @@ -6297,6 +6297,63 @@ static void ufshcd_def_desc_sizes(struct=20 > ufs_hba > *hba) > } > > /** > + * ufshcd_set_dev_ref_clk - set the device bRefClkFreq > + * @hba: per-adapter instance > + * @ref_clk_freq: refrerence clock frequency to be set > + * > + * Read the current value of the bRefClkFreq attribute from device=20 > + and > update it > + * if host is supplying different reference clock frequency than one > mentioned > + * in bRefClkFreq attribute. > + * > + * Returns zero on success, non-zero error value on failure. > + */ > +static int ufshcd_set_dev_ref_clk(struct ufs_hba *hba, u32=20 > +ref_clk_freq) { > + int err =3D 0; > + int ref_clk =3D -1; > + static const char * const ref_clk_freqs[] =3D {"19.2 MHz", "26 MHz", > + "38.4 MHz", "52 MHz"}; > + > + hba->dev_ref_clk_freq =3D ref_clk_freq; > + err =3D ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR, > + QUERY_ATTR_IDN_REF_CLK_FREQ, 0, 0, &ref_clk); > + > + if (err) { > + dev_err(hba->dev, "%s: failed reading bRefClkFreq. err =3D %d\n", > + __func__, err); > + goto out; > + } > + > + if ((ref_clk < 0) || (ref_clk > REF_CLK_FREQ_52_MHZ)) { > + dev_err(hba->dev, "%s: invalid ref_clk setting =3D %d\n", > + __func__, ref_clk); > + err =3D -EINVAL; > + goto out; > + } > + > + if (ref_clk =3D=3D hba->dev_ref_clk_freq) > + goto out; /* nothing to update */ > + > + err =3D ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_WRITE_ATTR, > + QUERY_ATTR_IDN_REF_CLK_FREQ, 0, 0, > + &hba->dev_ref_clk_freq); > + > + if (err) > + dev_err(hba->dev, "%s: bRefClkFreq setting to %s failed\n", > + __func__, ref_clk_freqs[hba->dev_ref_clk_freq]); > + else > + /* > + * It is good to print this out here to debug any later failures > + * related to gear switch. > + */ > + dev_info(hba->dev, "%s: bRefClkFreq setting to %s succeeded\n", > + __func__, ref_clk_freqs[hba->dev_ref_clk_freq]); > + > +out: > + return err; > +} > + > +/** > * ufshcd_probe_hba - probe hba to detect device and initialize > * @hba: per-adapter instance > * > @@ -6361,6 +6418,11 @@ static int ufshcd_probe_hba(struct ufs_hba = *hba) > "%s: Failed getting max supported power mode\n", > __func__); > } else { > + /* > + * Set the right value to bRefClkFreq before attempting to > + * switch to HS gears. > + */ > + ufshcd_set_dev_ref_clk(hba, REF_CLK_FREQ_19_2_MHZ); How it works in 26MHz refclk support host like exynos series?. As I = understood, there default refclk value are 26MHz for host and device. In that case, your code maybe set device's refclk to 19.2MHz. It would = be need to set same refclk value both host and device for switch to HS. [Sayali] : As per HPG, we set ref_clk to 19.2 Mhz (for host and device). = But as it can vary for others (like exynos as you pointed), I think its = better to parse ref_clk frequency from device tree instead of passing = hardcoded value. DT approach was present in my previous patchset, I will = update/add it again in my next patch set. > ret =3D ufshcd_config_pwr_mode(hba, &hba->max_pwr_info.info); > if (ret) { > dev_err(hba->dev, "%s: Failed setting power mode, err =3D %d\n",=20 > diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h=20 > index 8110dcd..b026ad8 100644 > --- a/drivers/scsi/ufs/ufshcd.h > +++ b/drivers/scsi/ufs/ufshcd.h > @@ -548,6 +548,7 @@ struct ufs_hba { > void *priv; > unsigned int irq; > bool is_irq_enabled; > + u32 dev_ref_clk_freq; > > /* Interrupt aggregation support is broken */ > #define UFSHCD_QUIRK_BROKEN_INTR_AGGR 0x1 > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora=20 > Forum, a Linux Foundation Collaborative Project > > BR, Kyuho Choi