scsi: ufs: Fix regulator operations and remove "<name>-fixed-regulator" device tree property
Subsystems (2)
Hi,
Sorry please help review V3 instead of previous versions.
In this version I fix and add more details in commit messages, and add one patch to fix "undefined voltage range" issue as well.
This patch series fixes UFS regulator operations, including voltage and current (re-)configuration flow during initialization or different power modes.
Besides, remove "<name>-fixed-regulator" device tree property because it is not necessary anymore after fixes.
V3:
- Fix and add more details in commit messages.
- Add one patch "scsi: ufs: Avoid configuring undefined voltage range on a regulator".
V2:
- Add two patches to prepare to and remove "<name>-fixed-regulator" device tree property.
- Add more details on patch "scsi: ufs: remove unused min_uA field in struct ufs_vreg" (Marc Gonzalez).
Stanley Chu (5):
scsi: ufs: Remove unused min_uA field in struct ufs_vreg
scsi: ufs: Avoid configuring undefined voltage range on a regulator
scsi: ufs: Fix regulator load and icc-level configuration
scsi: ufs: Change "<name>-max-microamp" to non-mandatory property
scsi: ufs: Remove "<name>-fixed-regulator" device tree property
drivers/scsi/ufs/ufs.h | 1 - drivers/scsi/ufs/ufshcd-pltfrm.c | 14 +++----------- drivers/scsi/ufs/ufshcd.c | 28 ++++++++++++++++++++-------- 3 files changed, 23 insertions(+), 20 deletions(-)
A message that is not in the archive (sent off-list or not yet received): 1552875280-16196-1-git-send-email-stanley.chu-NuS5LvNUpcJWk0Htik3J/[email protected]
v3 cover scsi: ufs: Fix regulator operations and remove "<name>-fixed-regulator" device tree property
Hi,
Sorry please help review V3 instead of previous versions.
In this version I fix and add more details in commit messages, and add one patch to fix "undefined voltage range" issue as well.
This patch series fixes UFS regulator operations, including voltage and current (re-)configuration flow during initialization or different power modes.
Besides, remove "<name>-fixed-regulator" device tree property because it is not necessary anymore after fixes.
V3:
- Fix and add more details in commit messages.
- Add one patch "scsi: ufs: Avoid configuring undefined voltage range on a regulator".
V2:
- Add two patches to prepare to and remove "<name>-fixed-regulator" device tree property.
- Add more details on patch "scsi: ufs: remove unused min_uA field in struct ufs_vreg" (Marc Gonzalez).
Stanley Chu (5):
scsi: ufs: Remove unused min_uA field in struct ufs_vreg
scsi: ufs: Avoid configuring undefined voltage range on a regulator
scsi: ufs: Fix regulator load and icc-level configuration
scsi: ufs: Change "<name>-max-microamp" to non-mandatory property
scsi: ufs: Remove "<name>-fixed-regulator" device tree property
drivers/scsi/ufs/ufs.h | 1 - drivers/scsi/ufs/ufshcd-pltfrm.c | 14 +++----------- drivers/scsi/ufs/ufshcd.c | 28 ++++++++++++++++++++-------- 3 files changed, 23 insertions(+), 20 deletions(-)
Signature · 1 line
2.18.0
A message that is not in the archive (sent off-list or not yet received): 1552875280-16196-2-git-send-email-stanley.chu-NuS5LvNUpcJWk0Htik3J/[email protected]
Hi Avri, Alim, Pedrom,
Gentle ping for this series.
Quoted 24 lines · Stanley Chu
Hi,
Sorry please help review V3 instead of previous versions.
In this version I fix and add more details in commit messages, and add one patch to fix "undefined voltage range" issue as well.This patch series fixes UFS regulator operations, including voltage and current (re-)configuration flow during initialization or different power modes.
Besides, remove "<name>-fixed-regulator" device tree property because it is not necessary anymore after fixes.
V3:
- Fix and add more details in commit messages.
- Add one patch "scsi: ufs: Avoid configuring undefined voltage range on a regulator".V2:
- Add two patches to prepare to and remove "<name>-fixed-regulator" device tree property.
- Add more details on patch "scsi: ufs: remove unusedmin_uAfield in structufs_vreg" (Marc Gonzalez).Stanley Chu (5):
scsi: ufs: Remove unusedmin_uAfield in structufs_vreg
scsi: ufs: Avoid configuring undefined voltage range on a regulator
scsi: ufs: Fix regulator load and icc-level configuration
scsi: ufs: Change "<name>-max-microamp" to non-mandatory property
scsi: ufs: Remove "<name>-fixed-regulator" device tree property
Quoted 5 lines
drivers/scsi/ufs/ufs.h | 1 - drivers/scsi/ufs/ufshcd-pltfrm.c | 14 +++----------- drivers/scsi/ufs/ufshcd.c | 28 ++++++++++++++++++++-------- 3 files changed, 23 insertions(+), 20 deletions(-)
Thanks,
Stanley
PATCH v3 1/5 scsi: ufs: Remove unused min_uA field in struct ufs_vreg
In reply to a message not in the archiveThere are two fields related to regulator current limit in structufs_vreg: "min_uA" and "max_uA".
"max_uA" is probed by "<name>-max-microamp" property from device tree and used for
- regulator_set_load operations, and
- icc_level configuration in device.
However "min_uA" field is not used anywhere, thus we can remove it.
--- drivers/scsi/ufs/ufs.h | 1 - drivers/scsi/ufs/ufshcd-pltfrm.c | 1 - 2 files changed, 2 deletions(-)
drivers/scsi/ufs/ufs.h +0 -1
@@ -516,7 +516,6 @@ struct ufs_vreg {bool enabled;int min_uV;int max_uV; -int min_uA;int max_uA; };
drivers/scsi/ufs/ufshcd-pltfrm.c +0 -1
@@ -164,7 +164,6 @@ static int ufshcd_populate_vreg(struct device *dev, const char *name, goto out; } - vreg->min_uA =0 ;if (!strcmp (name,"vcc" )) {if (of_property_read_bool (np,"vcc-supply-1p8" )) { vreg->min_uV =UFS_VREG_VCC_1P8_MIN_UV ;
Signature · 1 line
2.18.0
A message that is not in the archive (sent off-list or not yet received): 1552875280-16196-3-git-send-email-stanley.chu-NuS5LvNUpcJWk0Htik3J/[email protected]
Alim Akhtar
Acked-byRe: [PATCH v3 1/5] scsi: ufs: Remove unused min_uA field in struct ufs_vreg
Hi Stanley
Quoted 7 lines · Stanley Chu
There are two fields related to regulator current limit in struct
ufs_vreg: "min_uA" and "max_uA"."
max_uA" is probed by "<name>-max-microamp" property from device tree and used for
Quoted 8 lines
-
regulator_set_loadoperations, and
-icc_levelconfiguration in device.However "
min_uA" field is not used anywhere, thus we can remove it.Reviewed-by Marc Gonzalez <[email protected]>---
Looks good.
Quoted 31 lines
drivers/scsi/ufs/ufs.h | 1 - drivers/scsi/ufs/ufshcd-pltfrm.c | 1 - 2 files changed, 2 deletions(-)drivers/scsi/ufs/ufs.h +0
-1@@ -516,7 +516,6 @@ struct ufs_vreg {bool enabled;int min_uV;int max_uV; -int min_uA;int max_uA; };drivers/scsi/ufs/ufshcd-pltfrm.c +0
-2@@ -164,7 +164,6 @@ static int ufshcd_populate_vreg(struct device *dev, const char *name, goto out; } - vreg->min_uA =0 ;if (!strcmp (name,"vcc" )) {if (of_property_read_bool (np,"vcc-supply-1p8" )) { vreg->min_uV =UFS_VREG_VCC_1P8_MIN_UV ; --2.18.0
Signature · 2 lines
Regards, Alim
PATCH v3 2/5 scsi: ufs: Avoid configuring undefined voltage range on a regulator
In reply to a message not in the archiveFor regulators used by UFS, vcc, vccq and vccq2 will have voltage range initialized by ufshcd_populate_vreg(), however other regulators may not have voltage range settings if undefined in dt-bindings.
In this case, both "min_uV" and "max_uV" fields in ufs_vreg struct will be zero values and used as new voltage range for voltage configuration in different power modes.
Currently this may have no harm because if both "min_uV" and "max_uV" always keep "zero value", regulator_set_voltage() will always bypass such invalid values and return "good" results.
However improper values shall be fixed to avoid future potential bug. Simply bypass voltage configuration if voltage range is not defined.
--- drivers/scsi/ufs/ufshcd.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/scsi/ufs/ufshcd.c +8 -5
@@ -7024,12 +7024,15 @@ static int ufshcd_config_vreg(struct device *dev, name = vreg->name;if (regulator_count_voltages (reg) >0 ) { - min_uV = on ? vreg->min_uV :0 ; - ret =regulator_set_voltage (reg, min_uV, vreg->max_uV); -if (ret) { -dev_err (dev,"%s: %s set voltage failed, err=%d\n" , +if (vreg->min_uV && vreg->max_uV) { + min_uV = on ? vreg->min_uV :0 ; + ret =regulator_set_voltage (reg, min_uV, vreg->max_uV); +if (ret) { +dev_err (dev, +"%s: %s set voltage failed, err=%d\n" , __func__, name, ret); - goto out; + goto out; + } } uA_load = on ? vreg->max_uA :0 ;
Signature · 1 line
2.18.0
PATCH v3 3/5 scsi: ufs: Fix regulator load and icc-level configuration
In reply to a message not in the archiveCurrently if a regulator has "<name>-fixed-regulator" property in device tree, it will skip current limit configuration. This lead to a zero "max_uA" value in struct ufs_vreg.
However, "regulator_set_load" operation shall be required on those regulators which specifically configured current limit, otherwise a zero max_uA value may cause unexpected behavior when this regulator is enabled or set as high power mode.
Similarly, in icc_level configuration flow, icc_level shall be updated if specified regulator has also configured current limit, otherwise a zero max_uA will lead to wrong icc_level which may cause unexpected results after written to device.
--- drivers/scsi/ufs/ufshcd.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/scsi/ufs/ufshcd.c +12 -3
@@ -6279,19 +6279,19 @@ static u32 ufshcd_find_max_sup_active_icc_level(struct ufs_hba *hba, goto out; } -if (hba->vreg_info.vcc) +if (hba->vreg_info.vcc && hba->vreg_info.vcc->max_uA) icc_level =ufshcd_get_max_icc_level ( hba->vreg_info.vcc->max_uA,POWER_DESC_MAX_ACTV_ICC_LVLS -1 , &desc_buf[PWR_DESC_ACTIVE_LVLS_VCC_0 ]); -if (hba->vreg_info.vccq) +if (hba->vreg_info.vccq && hba->vreg_info.vccq->max_uA) icc_level =ufshcd_get_max_icc_level ( hba->vreg_info.vccq->max_uA, icc_level, &desc_buf[PWR_DESC_ACTIVE_LVLS_VCCQ_0 ]); -if (hba->vreg_info.vccq2) +if (hba->vreg_info.vccq2 && hba->vreg_info.vccq2->max_uA) icc_level = ufshcd_get_max_icc_level( hba->vreg_info.vccq2->max_uA, icc_level,
@@ -6989,6 +6989,15 @@ static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,if (!vreg)return 0 ; +/* +* "set_load" operation shall be required on those regulators +* which specifically configured current limitation. Otherwise +* zero max_uA may cause unexpected behavior when regulator is +* enabled or set as high power mode. +*/ +if (!vreg->max_uA) +return 0 ; + ret =regulator_set_load (vreg->reg, ua);if (ret <0 ) { dev_err(dev, "%s: %s set load (ua=%d) failed, err=%d\n",
Signature · 1 line
2.18.0
PATCH v3 4/5 scsi: ufs: Change "<name>-max-microamp" to non-mandatory property
In reply to a message not in the archiveIn dt-bindings for ufs, "<name>-max-microamp" property indicates current limit and is mandatory if "<name>-fixed-regulator" is not defined on a specified regulator.
However, in some platforms, regulators without "<name>-fixed-regulator" deifned may not need to define their current limit. They may only want to define voltage range for proper voltage switching in different power modes, especially for vcc, vccq or vccq2.
However, missing "<name>-max-microamp" property in device tree will lead to initialization fail, thus above limitation shall be resolved to tolerate such kind of regulators.
After resolving this, these regulators without "<name>-max-microamp" will have undefined "max current" value, i.e., zero value in "max_uA" field in struct ufs_vreg. Because we do bypass current switching operation (by regulator_set_load) in case of undefined current limit, this patch shall be safe.
--- drivers/scsi/ufs/ufshcd-pltfrm.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/scsi/ufs/ufshcd-pltfrm.c +3 -5
@@ -157,11 +157,9 @@ static int ufshcd_populate_vreg(struct device *dev, const char *name, goto out;snprintf (prop_name,MAX_PROP_SIZE ,"%s-max-microamp" , name); - ret =of_property_read_u32 (np, prop_name, &vreg->max_uA); -if (ret) { -dev_err (dev,"%s: unable to find %s err %d\n" , - __func__, prop_name, ret); - goto out; +if (of_property_read_u32 (np, prop_name, &vreg->max_uA)) { +dev_info (dev,"%s: unable to find %s\n" , __func__, prop_name); + vreg->max_uA =0 ; }if (!strcmp (name,"vcc" )) {
Signature · 1 line
2.18.0
PATCH v3 5/5 scsi: ufs: Remove "<name>-fixed-regulator" device tree property
In reply to a message not in the archive"<name>-fixed-regulator" device tree property can be safely removed because below things are fixed or resolved,
1. "<name>-max-microamp" becomes optional property: Undefined "<name>-max-microamp" will not cause initialization fail if "<name>-fixed-regulator" is not defined.
2. Current switching operation (by regulator_set_load) now has rules:
Regulators will have undefined current limit if "<name>-fixed-regulator" is not defined. But this is safe because only regulator which has configured current limit from "<name>-max-microamp" property is allowed to change its load.
Although "<name>-fixed-regulator" is not used in any dt-bindings in tree, this patch is still safe for regulators already defined "<name>-fixed-regulator", the reason is described as below.
If a regulator defined "<name>-fixed-regulator" before, the behavior after this patch is described as below,
1. "<name>-max-microamp":
If a regulator defined "<name>-fixed-regulator", it is not necessary to define "<name>-max-microamp" property in device tree and it is expected to have an undefined current limit, i.e., "max_uA" field is zero in struct ufs_vreg. This is exactly the same as patched.
2. "vcc-supply-1p8" or volatge range settings:
* For vcc, vccq or vccq2, these three regulators shall not define "<name>-fixed-regulator" because defining it will lead to undefined voltage range and thus voltage switching will be unexpected.
* For other regulators with undefined voltage range, voltage range will be still undefined after patched.
Therefore this patch is safe for all existed regulators with "<name>-fixed-regulator" property already defined.
--- drivers/scsi/ufs/ufshcd-pltfrm.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/scsi/ufs/ufshcd-pltfrm.c +0 -5
@@ -151,11 +151,6 @@ static int ufshcd_populate_vreg(struct device *dev, const char *name, vreg->name =kstrdup (name,GFP_KERNEL ); -/* if fixed regulator no need further initialization */ -snprintf (prop_name,MAX_PROP_SIZE ,"%s-fixed-regulator" , name); -if (of_property_read_bool (np, prop_name)) - goto out; -snprintf (prop_name,MAX_PROP_SIZE ,"%s-max-microamp" , name);if (of_property_read_u32 (np, prop_name, &vreg->max_uA)) {dev_info (dev,"%s: unable to find %s\n" , __func__, prop_name);
Signature · 1 line
2.18.0