]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
scsi: ufs: Prepare to add HCI capabilities sysfs
authorAvri Altman <avri.altman@wdc.com>
Sun, 11 Aug 2024 14:37:56 +0000 (17:37 +0300)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 13 Aug 2024 02:11:23 +0000 (22:11 -0400)
Prepare so we'll be able to read various other HCI registers.  While at it,
fix the HCPID & HCMID register names to stand for what they really are.
Also replace the pm_runtime_{get/put}_sync() calls in auto_hibern8_show to
ufshcd_rpm_{get/put}_sync() as any host controller register reads should.

Reviewed-by: Keoseong Park <keosung.park@samsung.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20240811143757.2538212-2-avri.altman@wdc.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/ufs/core/ufs-sysfs.c
include/ufs/ufshci.h

index e80a32421a8c4ca4fdfebd3a59fb9ba15a7f79d8..dec7746c98e0ace710b42fa69417c5f41c04e67b 100644 (file)
@@ -198,6 +198,24 @@ static u32 ufshcd_us_to_ahit(unsigned int timer)
               FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, scale);
 }
 
+static int ufshcd_read_hci_reg(struct ufs_hba *hba, u32 *val, unsigned int reg)
+{
+       down(&hba->host_sem);
+       if (!ufshcd_is_user_access_allowed(hba)) {
+               up(&hba->host_sem);
+               return -EBUSY;
+       }
+
+       ufshcd_rpm_get_sync(hba);
+       ufshcd_hold(hba);
+       *val = ufshcd_readl(hba, reg);
+       ufshcd_release(hba);
+       ufshcd_rpm_put_sync(hba);
+
+       up(&hba->host_sem);
+       return 0;
+}
+
 static ssize_t auto_hibern8_show(struct device *dev,
                                 struct device_attribute *attr, char *buf)
 {
@@ -208,23 +226,11 @@ static ssize_t auto_hibern8_show(struct device *dev,
        if (!ufshcd_is_auto_hibern8_supported(hba))
                return -EOPNOTSUPP;
 
-       down(&hba->host_sem);
-       if (!ufshcd_is_user_access_allowed(hba)) {
-               ret = -EBUSY;
-               goto out;
-       }
-
-       pm_runtime_get_sync(hba->dev);
-       ufshcd_hold(hba);
-       ahit = ufshcd_readl(hba, REG_AUTO_HIBERNATE_IDLE_TIMER);
-       ufshcd_release(hba);
-       pm_runtime_put_sync(hba->dev);
-
-       ret = sysfs_emit(buf, "%d\n", ufshcd_ahit_to_us(ahit));
+       ret = ufshcd_read_hci_reg(hba, &ahit, REG_AUTO_HIBERNATE_IDLE_TIMER);
+       if (ret)
+               return ret;
 
-out:
-       up(&hba->host_sem);
-       return ret;
+       return sysfs_emit(buf, "%d\n", ufshcd_ahit_to_us(ahit));
 }
 
 static ssize_t auto_hibern8_store(struct device *dev,
index 38fe97971a65facdd67a62cfa32fbf48f8a7dbd7..194e3655902ec3d7fc2ca070d549a40cb5499f6f 100644 (file)
@@ -25,8 +25,9 @@ enum {
        REG_CONTROLLER_CAPABILITIES             = 0x00,
        REG_MCQCAP                              = 0x04,
        REG_UFS_VERSION                         = 0x08,
-       REG_CONTROLLER_DEV_ID                   = 0x10,
-       REG_CONTROLLER_PROD_ID                  = 0x14,
+       REG_EXT_CONTROLLER_CAPABILITIES         = 0x0C,
+       REG_CONTROLLER_PID                      = 0x10,
+       REG_CONTROLLER_MID                      = 0x14,
        REG_AUTO_HIBERNATE_IDLE_TIMER           = 0x18,
        REG_INTERRUPT_STATUS                    = 0x20,
        REG_INTERRUPT_ENABLE                    = 0x24,