[PATCH 3/5] scsi: ufs: renesas: Remove register control helper function

Neil Armstrong neil.armstrong at linaro.org
Mon Jan 5 16:20:02 CET 2026


On 1/3/26 01:22, Marek Vasut wrote:
> From: Yoshihiro Shimoda <yoshihiro.shimoda.uh at renesas.com>
> 
> After refactoring the code, ufs_renesas_reg_control() is no longer needed,
> because all operations are simple and can be called directly.  Remove the
> ufs_renesas_reg_control() helper function, and call udelay() directly.
> 
> Ported from Linux kernel commit
> 855bde8ce5bc ("scsi: ufs: renesas: Remove register control helper function")
> with replaced readl_poll_timeout_atomic() with readl_poll_sleep_timeout().
> 
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh at renesas.com>
> Signed-off-by: Geert Uytterhoeven <geert+renesas at glider.be>
> Link: https://lore.kernel.org/r/69500e4c18be1ca1de360f9e797e282ffef04004.1741179611.git.geert+renesas@glider.be
> Signed-off-by: Martin K. Petersen <martin.petersen at oracle.com>
> Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
> ---
> Cc: Bhupesh Sharma <bhupesh.linux at gmail.com>
> Cc: Neil Armstrong <neil.armstrong at linaro.org>
> Cc: Nobuhiro Iwamatsu <iwamatsu at nigauri.org>
> Cc: Tom Rini <trini at konsulko.com>
> Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh at renesas.com>
> Cc: u-boot at lists.denx.de
> ---
>   drivers/ufs/ufs-renesas.c | 101 ++++++--------------------------------
>   1 file changed, 14 insertions(+), 87 deletions(-)
> 
> diff --git a/drivers/ufs/ufs-renesas.c b/drivers/ufs/ufs-renesas.c
> index 8c9a9ec7695..c8fbe61901b 100644
> --- a/drivers/ufs/ufs-renesas.c
> +++ b/drivers/ufs/ufs-renesas.c
> @@ -23,100 +23,27 @@ struct ufs_renesas_priv {
>   	bool initialized;	/* The hardware needs initialization once */
>   };
>   
> -enum ufs_renesas_init_param_mode {
> -	MODE_POLL,
> -	MODE_READ,
> -	MODE_WAIT,
> -	MODE_WRITE,
> -};
> -
> -struct ufs_renesas_init_param {
> -	enum ufs_renesas_init_param_mode mode;
> -	u32 reg;
> -	union {
> -		u32 expected;
> -		u32 delay_us;
> -		u32 val;
> -	} u;
> -	u32 mask;
> -	u32 index;
> -};
> -
> -static u32 ufs_renesas_reg_control(struct ufs_hba *hba,
> -				   const struct ufs_renesas_init_param *p)
> -{
> -	u32 val = 0;
> -	int ret;
> -
> -	switch (p->mode) {
> -	case MODE_POLL:
> -		ret = readl_poll_timeout(hba->mmio_base + p->reg, val,
> -					 (val & p->mask) == p->u.expected,
> -					 10000);
> -		if (ret)
> -			dev_err(hba->dev, "%s: poll failed %d (%08x, %08x, %08x)\n",
> -				__func__, ret, val, p->mask, p->u.expected);
> -		break;
> -	case MODE_READ:
> -		val = ufshcd_readl(hba, p->reg);
> -		break;
> -	case MODE_WAIT:
> -		if (p->u.delay_us > 1000)
> -			mdelay(DIV_ROUND_UP(p->u.delay_us, 1000));
> -		else
> -			udelay(p->u.delay_us);
> -		break;
> -	case MODE_WRITE:
> -		ufshcd_writel(hba, p->u.val, p->reg);
> -		break;
> -	default:
> -		break;
> -	}
> -
> -	return val;
> -}
> -
>   static void ufs_renesas_poll(struct ufs_hba *hba, u32 reg, u32 expected, u32 mask)
>   {
> -	struct ufs_renesas_init_param param = {
> -		.mode = MODE_POLL,
> -		.reg = reg,
> -		.u.expected = expected,
> -		.mask = mask,
> -	};
> -
> -	ufs_renesas_reg_control(hba, &param);
> +	int ret;
> +	u32 val;
> +
> +	ret = readl_poll_sleep_timeout(hba->mmio_base + reg,
> +				       val, (val & mask) == expected,
> +				       10, 1000);
> +	if (ret)
> +		dev_err(hba->dev, "%s: poll failed %d (%08x, %08x, %08x)\n",
> +			__func__, ret, val, mask, expected);
>   }
>   
>   static u32 ufs_renesas_read(struct ufs_hba *hba, u32 reg)
>   {
> -	struct ufs_renesas_init_param param = {
> -		.mode = MODE_READ,
> -		.reg = reg,
> -	};
> -
> -	return ufs_renesas_reg_control(hba, &param);
> -}
> -
> -static void ufs_renesas_wait(struct ufs_hba *hba, u32 delay_us)
> -{
> -	struct ufs_renesas_init_param param = {
> -		.mode = MODE_WAIT,
> -		.u.delay_us = delay_us,
> -	};
> -
> -	ufs_renesas_reg_control(hba, &param);
> +	return ufshcd_readl(hba, reg);
>   }
>   
>   static void ufs_renesas_write(struct ufs_hba *hba, u32 reg, u32 value)
>   {
> -	struct ufs_renesas_init_param param = {
> -		.mode = MODE_WRITE,
> -		.reg = reg,
> -		.u.val = value,
> -	};
> -
> -	ufs_renesas_reg_control(hba, &param);
> +	ufshcd_writel(hba, value, reg);
>   }
>   
>   static void ufs_renesas_write_d0_d4(struct ufs_hba *hba, u32 data_d0, u32 data_d4)
> @@ -210,13 +137,13 @@ static void ufs_renesas_pre_init(struct ufs_hba *hba)
>   	/* This setting is for SERIES B */
>   	ufs_renesas_write(hba, 0xc0, 0x49425308);
>   	ufs_renesas_write_d0_d4(hba, 0x00000104, 0x00000002);
> -	ufs_renesas_wait(hba, 1);
> +	udelay(1);
>   	ufs_renesas_write_d0_d4(hba, 0x00000828, 0x00000200);
> -	ufs_renesas_wait(hba, 1);
> +	udelay(1);
>   	ufs_renesas_write_d0_d4(hba, 0x00000828, 0x00000000);
>   	ufs_renesas_write_d0_d4(hba, 0x00000104, 0x00000001);
>   	ufs_renesas_write_d0_d4(hba, 0x00000940, 0x00000001);
> -	ufs_renesas_wait(hba, 1);
> +	udelay(1);
>   	ufs_renesas_write_d0_d4(hba, 0x00000940, 0x00000000);
>   
>   	ufs_renesas_write(hba, 0xc0, 0x49425308);

Reviewed-by: Neil Armstrong <neil.armstrong at linaro.org>

Thanks,
Neil


More information about the U-Boot mailing list