Skip to content

Commit b9d1044

Browse files
avri-altman-sndkmartinkpetersen
authored andcommitted
scsi: ufs: Prepare to add HCI capabilities sysfs
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 <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Reviewed-by: Bean Huo <[email protected]> Signed-off-by: Avri Altman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 992f988 commit b9d1044

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

drivers/ufs/core/ufs-sysfs.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,24 @@ static u32 ufshcd_us_to_ahit(unsigned int timer)
198198
FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, scale);
199199
}
200200

201+
static int ufshcd_read_hci_reg(struct ufs_hba *hba, u32 *val, unsigned int reg)
202+
{
203+
down(&hba->host_sem);
204+
if (!ufshcd_is_user_access_allowed(hba)) {
205+
up(&hba->host_sem);
206+
return -EBUSY;
207+
}
208+
209+
ufshcd_rpm_get_sync(hba);
210+
ufshcd_hold(hba);
211+
*val = ufshcd_readl(hba, reg);
212+
ufshcd_release(hba);
213+
ufshcd_rpm_put_sync(hba);
214+
215+
up(&hba->host_sem);
216+
return 0;
217+
}
218+
201219
static ssize_t auto_hibern8_show(struct device *dev,
202220
struct device_attribute *attr, char *buf)
203221
{
@@ -208,23 +226,11 @@ static ssize_t auto_hibern8_show(struct device *dev,
208226
if (!ufshcd_is_auto_hibern8_supported(hba))
209227
return -EOPNOTSUPP;
210228

211-
down(&hba->host_sem);
212-
if (!ufshcd_is_user_access_allowed(hba)) {
213-
ret = -EBUSY;
214-
goto out;
215-
}
216-
217-
pm_runtime_get_sync(hba->dev);
218-
ufshcd_hold(hba);
219-
ahit = ufshcd_readl(hba, REG_AUTO_HIBERNATE_IDLE_TIMER);
220-
ufshcd_release(hba);
221-
pm_runtime_put_sync(hba->dev);
222-
223-
ret = sysfs_emit(buf, "%d\n", ufshcd_ahit_to_us(ahit));
229+
ret = ufshcd_read_hci_reg(hba, &ahit, REG_AUTO_HIBERNATE_IDLE_TIMER);
230+
if (ret)
231+
return ret;
224232

225-
out:
226-
up(&hba->host_sem);
227-
return ret;
233+
return sysfs_emit(buf, "%d\n", ufshcd_ahit_to_us(ahit));
228234
}
229235

230236
static ssize_t auto_hibern8_store(struct device *dev,

include/ufs/ufshci.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ enum {
2525
REG_CONTROLLER_CAPABILITIES = 0x00,
2626
REG_MCQCAP = 0x04,
2727
REG_UFS_VERSION = 0x08,
28-
REG_CONTROLLER_DEV_ID = 0x10,
29-
REG_CONTROLLER_PROD_ID = 0x14,
28+
REG_EXT_CONTROLLER_CAPABILITIES = 0x0C,
29+
REG_CONTROLLER_PID = 0x10,
30+
REG_CONTROLLER_MID = 0x14,
3031
REG_AUTO_HIBERNATE_IDLE_TIMER = 0x18,
3132
REG_INTERRUPT_STATUS = 0x20,
3233
REG_INTERRUPT_ENABLE = 0x24,

0 commit comments

Comments
 (0)