mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bean Huo <beanhuo@iokpp.de>
To: avri.altman@wdc.com, bvanassche@acm.org, alim.akhtar@samsung.com,
	jejb@linux.ibm.com, martin.petersen@oracle.com,
	stanley.chu@mediatek.com, mani@kernel.org, quic_cang@quicinc.com,
	quic_asutoshd@quicinc.com, beanhuo@micron.com
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	mikebi@micron.com, lporzio@micron.com
Subject: [PATCH v1 2/2] scsi: ufs: core: Add sysfs node for UFS RTC update
Date: Thu,  9 Nov 2023 13:52:17 +0100	[thread overview]
Message-ID: <20231109125217.185462-3-beanhuo@iokpp.de> (raw)
In-Reply-To: <20231109125217.185462-1-beanhuo@iokpp.de>

From: Bean Huo <beanhuo@micron.com>

This patch introduces a sysfs node named 'rtc_update_ms' within the kernel, enabling users to
adjust the RTC periodic update frequency to suit the specific requirements of the system and
UFS. Also, this patch allows the user to disable periodic update RTC  in the UFS idle time.

Signed-off-by: Bean Huo <beanhuo@micron.com>
---
 drivers/ufs/core/ufs-sysfs.c | 31 +++++++++++++++++++++++++++++++
 drivers/ufs/core/ufshcd.c    |  4 ++--
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
index c95906443d5f..d42846316a86 100644
--- a/drivers/ufs/core/ufs-sysfs.c
+++ b/drivers/ufs/core/ufs-sysfs.c
@@ -255,6 +255,35 @@ static ssize_t wb_on_store(struct device *dev, struct device_attribute *attr,
 	return res < 0 ? res : count;
 }
 
+static ssize_t rtc_update_ms_show(struct device *dev, struct device_attribute *attr,
+			  char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%d\n", hba->dev_info.rtc_update_period);
+}
+
+static ssize_t rtc_update_ms_store(struct device *dev, struct device_attribute *attr,
+			   const char *buf, size_t count)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+	unsigned int ms;
+	bool resume_period_update;
+
+	if (kstrtouint(buf, 0, &ms))
+		return -EINVAL;
+
+	if (!hba->dev_info.rtc_update_period && ms > 0)
+		resume_period_update =  true;
+	/* Minimum and maximum update frequency should be synchronized with all UFS vendors */
+	hba->dev_info.rtc_update_period = ms;
+
+	if (resume_period_update)
+		schedule_delayed_work(&hba->ufs_rtc_delayed_work,
+						msecs_to_jiffies(hba->dev_info.rtc_update_period));
+	return count;
+}
+
 static ssize_t enable_wb_buf_flush_show(struct device *dev,
 				    struct device_attribute *attr,
 				    char *buf)
@@ -339,6 +368,7 @@ static DEVICE_ATTR_RW(auto_hibern8);
 static DEVICE_ATTR_RW(wb_on);
 static DEVICE_ATTR_RW(enable_wb_buf_flush);
 static DEVICE_ATTR_RW(wb_flush_threshold);
+static DEVICE_ATTR_RW(rtc_update_ms);
 
 static struct attribute *ufs_sysfs_ufshcd_attrs[] = {
 	&dev_attr_rpm_lvl.attr,
@@ -351,6 +381,7 @@ static struct attribute *ufs_sysfs_ufshcd_attrs[] = {
 	&dev_attr_wb_on.attr,
 	&dev_attr_enable_wb_buf_flush.attr,
 	&dev_attr_wb_flush_threshold.attr,
+	&dev_attr_rtc_update_ms.attr,
 	NULL
 };
 
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index f0e3dd3dd280..ae9b60619fd3 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -8234,9 +8234,9 @@ static void ufshcd_rtc_work(struct work_struct *work)
 
 	ufshcd_update_rtc(hba);
 out:
-	if (ufshcd_is_ufs_dev_active(hba))
+	if (ufshcd_is_ufs_dev_active(hba) && hba->dev_info.rtc_update_period)
 		schedule_delayed_work(&hba->ufs_rtc_delayed_work,
-							msecs_to_jiffies(UFS_RTC_UPDATE_EVERY_MS));
+						msecs_to_jiffies(hba->dev_info.rtc_update_period));
 	return;
 }
 
-- 
2.34.1


  parent reply	other threads:[~2023-11-09 12:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-09 12:52 [PATCH v1 0/2] Add UFS RTC support Bean Huo
2023-11-09 12:52 ` [PATCH v1 1/2] scsi: ufs: core: " Bean Huo
2023-11-09 14:05   ` Thomas Weißschuh
2023-11-14 18:27     ` Bean Huo
2023-11-14 18:53       ` Thomas Weißschuh
2023-11-09 15:09   ` Avri Altman
2023-11-14 18:42     ` Bean Huo
2023-11-09 18:06   ` Bart Van Assche
2023-11-09 12:52 ` Bean Huo [this message]
2023-11-09 14:05   ` [PATCH v1 2/2] scsi: ufs: core: Add sysfs node for UFS RTC update Thomas Weißschuh
2023-11-14 18:39     ` Bean Huo
2023-11-14 18:48       ` Thomas Weißschuh
2023-11-09 15:10   ` Avri Altman
2023-11-09 18:07   ` Bart Van Assche
2023-11-14 18:46     ` Bean Huo
2023-11-12  2:02   ` kernel test robot
2023-11-09 15:10 ` [PATCH v1 0/2] Add UFS RTC support Avri Altman
2023-11-09 18:07 ` Bart Van Assche

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231109125217.185462-3-beanhuo@iokpp.de \
    --to=beanhuo@iokpp.de \
    --cc=alim.akhtar@samsung.com \
    --cc=avri.altman@wdc.com \
    --cc=beanhuo@micron.com \
    --cc=bvanassche@acm.org \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=lporzio@micron.com \
    --cc=mani@kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mikebi@micron.com \
    --cc=quic_asutoshd@quicinc.com \
    --cc=quic_cang@quicinc.com \
    --cc=stanley.chu@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®