On 2020-12-22 10:04, Kiwoong Kim wrote:
>> As per specs, e.g, JESD220E chapter 7.2, while powering off/on the
>> ufs device, RST_N signal and REF_CLK signal should be between
>> VSS(Ground) and VCCQ/VCCQ2.
>>
>> To flexibly control device reset line, re-name the function
>> ufschd_vops_device_reset(sturct ufs_hba *hba) to ufshcd_
>> vops_toggle_device_reset(sturct ufs_hba *hba, bool down). The new
>> parameter "bool down" is used to separate device reset line pulling
>> down from pulling up.
>>
>> Cc: Kiwoong Kim <kwmad.kim@xxxxxxxxxxx>
>> Cc: Stanley Chu <stanley.chu@xxxxxxxxxxxx>
>> Signed-off-by: Ziqi Chen <ziqichen@xxxxxxxxxxxxxx>
>> ---
>> drivers/scsi/ufs/ufs-mediatek.c | 27 +++++++++-----------------
>> drivers/scsi/ufs/ufs-qcom.c | 22 ++++++++++-----------
>> drivers/scsi/ufs/ufshcd.c | 43
>> ++++++++++++++++++++++++++++++------
> --
>> ---
>> drivers/scsi/ufs/ufshcd.h | 10 +++++-----
>> 4 files changed, 56 insertions(+), 46 deletions(-)
>>
>> diff --git a/drivers/scsi/ufs/ufs-mediatek.c b/drivers/scsi/ufs/ufs-
>> mediatek.c index 80618af..bff2c42 100644
>> --- a/drivers/scsi/ufs/ufs-mediatek.c
>> +++ b/drivers/scsi/ufs/ufs-mediatek.c
>> @@ -841,27 +841,18 @@ static int ufs_mtk_link_startup_notify(struct
>> ufs_hba *hba,
>> return ret;
>> }
>>
>> -static int ufs_mtk_device_reset(struct ufs_hba *hba)
>> +static int ufs_mtk_toggle_device_reset(struct ufs_hba *hba, bool
>> down)
>> {
>> struct arm_smccc_res res;
>>
>> - ufs_mtk_device_reset_ctrl(0, res);
>> -
>> - /*
>> - * The reset signal is active low. UFS devices shall detect
>> - * more than or equal to 1us of positive or negative RST_n
>> - * pulse width.
>> - *
>> - * To be on safe side, keep the reset low for at least 10us.
>> - */
>> - usleep_range(10, 15);
>> -
>> - ufs_mtk_device_reset_ctrl(1, res);
>> -
>> - /* Some devices may need time to respond to rst_n */
>> - usleep_range(10000, 15000);
>> + if (down) {
>> + ufs_mtk_device_reset_ctrl(0, res);
>> + } else {
>> + ufs_mtk_device_reset_ctrl(1, res);
>>
>> - dev_info(hba->dev, "device reset done\n");
>> + /* Some devices may need time to respond to rst_n */
>> + usleep_range(10000, 15000);
>> + }
>>
>> return 0;
>> }
>> @@ -1052,7 +1043,7 @@ static const struct ufs_hba_variant_ops
>> ufs_hba_mtk_vops = {
>> .suspend = ufs_mtk_suspend,
>> .resume = ufs_mtk_resume,
>> .dbg_register_dump = ufs_mtk_dbg_register_dump,
>> - .device_reset = ufs_mtk_device_reset,
>> + .toggle_device_reset = ufs_mtk_toggle_device_reset,
>> .event_notify = ufs_mtk_event_notify,
>> };
>>
>> diff --git a/drivers/scsi/ufs/ufs-qcom.c
>> b/drivers/scsi/ufs/ufs-qcom.c index 2206b1e..c2ccaa5 100644
>> --- a/drivers/scsi/ufs/ufs-qcom.c
>> +++ b/drivers/scsi/ufs/ufs-qcom.c
>> @@ -1404,12 +1404,13 @@ static void ufs_qcom_dump_dbg_regs(struct
>> ufs_hba
>> *hba) }
>>
>> /**
>> - * ufs_qcom_device_reset() - toggle the (optional) device reset line
>> + * ufs_qcom_toggle_device_reset() - toggle the (optional) device
>> reset
>> + line
>> * @hba: per-adapter instance
>> + * @down: pull down or pull up device reset line
>> *
>> * Toggles the (optional) reset line to reset the attached device.
>> */
>> -static int ufs_qcom_device_reset(struct ufs_hba *hba)
>> +static int ufs_qcom_toggle_device_reset(struct ufs_hba *hba, bool
>> down)
>> {
>> struct ufs_qcom_host *host = ufshcd_get_variant(hba);
>>
>> @@ -1417,15 +1418,12 @@ static int ufs_qcom_device_reset(struct
>> ufs_hba
>> *hba)
>> if (!host->device_reset)
>> return -EOPNOTSUPP;
>>
>> - /*
>> - * The UFS device shall detect reset pulses of 1us, sleep for 10us
>> to
>> - * be on the safe side.
>> - */
>> - gpiod_set_value_cansleep(host->device_reset, 1);
>> - usleep_range(10, 15);
>> -
>> - gpiod_set_value_cansleep(host->device_reset, 0);
>> - usleep_range(10, 15);
>> + if (down) {
>> + gpiod_set_value_cansleep(host->device_reset, 1);
>> + } else {
>> + gpiod_set_value_cansleep(host->device_reset, 0);
>> + usleep_range(10, 15);
>> + }
>>
>> return 0;
>> }
>> @@ -1473,7 +1471,7 @@ static const struct ufs_hba_variant_ops
>> ufs_hba_qcom_vops = {
>> .suspend = ufs_qcom_suspend,
>> .resume = ufs_qcom_resume,
>> .dbg_register_dump = ufs_qcom_dump_dbg_regs,
>> - .device_reset = ufs_qcom_device_reset,
>> + .toggle_device_reset = ufs_qcom_toggle_device_reset,
>> .config_scaling_param = ufs_qcom_config_scaling_param,
>> .program_key = ufs_qcom_ice_program_key,
>> };
>> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
>> index e221add..2ee905f 100644
>> --- a/drivers/scsi/ufs/ufshcd.c
>> +++ b/drivers/scsi/ufs/ufshcd.c
>> @@ -585,7 +585,20 @@ static void ufshcd_device_reset(struct ufs_hba
>> *hba)
>> {
>> int err;
>>
>> - err = ufshcd_vops_device_reset(hba);
>> + err = ufshcd_vops_toggle_device_reset(hba, true);
>> + if (err) {
>> + dev_err(hba->dev, "device reset pulling down failure: %d\n",
>> err);
>> + return;
>> + }
>> +
>> + /*
>> + * The reset signal is active low. The UFS device
>> + * shall detect reset pulses of 1us, sleep for at
>> + * least 10us to be on the safe side.
>> + */
>> + usleep_range(10, 15);
>
> Is there any point where UFS specification tells this explicitly?
> I think this should be moved only if the number, i.e. 10 and 15 just
> relies on hardware conditions.
>
>
> Thanks.
> Kiwoong Kim
Hi Kiwoong,
Thanks for your comment. JESD220E Line 610~611 "The UFS device shall
detect more than or equal to 1us of positive or negative RST_n pulse".
Both QCOM and Mediatek use 10~15us. What number do you think more
appropriate?
Best Regards,
Ziqi