diff mbox series

[5/5] scsi: ufs: renesas: Add reusable functions

Message ID 20240708120931.1703956-6-yoshihiro.shimoda.uh@renesas.com (mailing list archive)
State Superseded
Headers show
Series scsi: ufs: renesas: Refactor code for other UFS controller | expand

Commit Message

Yoshihiro Shimoda July 8, 2024, 12:09 p.m. UTC
Since some settings can be reused on other UFS controller (R-Car S4-8
ES 1.2), add reusable functions.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 drivers/ufs/host/ufs-renesas.c | 64 +++++++++++++++++++++++-----------
 1 file changed, 44 insertions(+), 20 deletions(-)
diff mbox series

Patch

diff --git a/drivers/ufs/host/ufs-renesas.c b/drivers/ufs/host/ufs-renesas.c
index abe33b0c64db..48b3ccad99c1 100644
--- a/drivers/ufs/host/ufs-renesas.c
+++ b/drivers/ufs/host/ufs-renesas.c
@@ -201,11 +201,8 @@  static void ufs_renesas_param_write_phy_10ad_10af(struct ufs_hba *hba,
 	ufs_renesas_param_write_phy(hba, 0x10ae, 0x0000);
 }
 
-static void ufs_renesas_pre_init(struct ufs_hba *hba)
+static void ufs_renesas_init_ufshc(struct ufs_hba *hba)
 {
-	u32 timer_val;
-
-	/* This setting is for SERIES B */
 	ufs_renesas_param_write(hba, 0xc0, 0x49425308);
 	ufs_renesas_param_write_d0_d4(hba, 0x00000104, 0x00000002);
 	udelay(1);
@@ -219,6 +216,46 @@  static void ufs_renesas_pre_init(struct ufs_hba *hba)
 
 	ufs_renesas_param_write(hba, 0xc0, 0x49425308);
 	ufs_renesas_param_write(hba, 0xc0, 0x41584901);
+}
+
+static u32 ufs_renesas_init_disable_timer(struct ufs_hba *hba)
+{
+	u32 timer_val;
+
+	ufs_renesas_param_write(hba, 0xd0, 0x00000d00);
+	timer_val = ufs_renesas_param_read(hba, 0xd4) & 0x0000ffff;
+	ufs_renesas_param_write(hba, 0xd4, 0x00000000);
+	ufs_renesas_param_write_d0_d4(hba, 0x0000082c, 0x0f000000);
+	ufs_renesas_param_write_d0_d4(hba, 0x00000828, 0x08000000);
+	ufs_renesas_param_write(hba, 0xd0, 0x0000082c);
+	ufs_renesas_param_poll(hba, 0xd4, BIT(27), BIT(27));
+	ufs_renesas_param_write(hba, 0xd0, 0x00000d2c);
+	ufs_renesas_param_poll(hba, 0xd4, BIT(0), BIT(0));
+
+	return timer_val;
+}
+
+static void ufs_renesas_init_enable_timer(struct ufs_hba *hba, u32 timer_val)
+{
+	ufs_renesas_param_write(hba, 0xf0, 0);
+	ufs_renesas_param_write(hba, 0xd0, 0x00000d00);
+	ufs_renesas_param_write(hba, 0xd4, timer_val);
+}
+
+static void ufs_renesas_init_compensation_and_slicers(struct ufs_hba *hba)
+{
+	ufs_renesas_param_write_phy_10ad_10af(hba, 0x0000, 0x0001);
+	ufs_renesas_param_write_phy_10ad_10af(hba, 0x0000, 0x0002);
+	ufs_renesas_param_write_phy_10ad_10af(hba, 0x0080, 0x0000);
+	ufs_renesas_param_write_phy_10ad_10af(hba, 0x0080, 0x001a);
+}
+
+static void ufs_renesas_pre_init(struct ufs_hba *hba)
+{
+	u32 timer_val;
+
+	/* This setting is for SERIES B */
+	ufs_renesas_init_ufshc(hba);
 
 	ufs_renesas_param_write_d0_d4(hba, 0x0000080c, 0x00000100);
 	ufs_renesas_param_write_d0_d4(hba, 0x00000804, 0x00000000);
@@ -231,15 +268,7 @@  static void ufs_renesas_pre_init(struct ufs_hba *hba)
 	ufs_renesas_param_poll(hba, 0xd4, BIT(8) | BIT(6) | BIT(0),
 			       BIT(8) | BIT(6) | BIT(0));
 
-	ufs_renesas_param_write(hba, 0xd0, 0x00000d00);
-	timer_val = ufs_renesas_param_read(hba, 0xd4) & 0x0000ffff;
-	ufs_renesas_param_write(hba, 0xd4, 0x00000000);
-	ufs_renesas_param_write_d0_d4(hba, 0x0000082c, 0x0f000000);
-	ufs_renesas_param_write_d0_d4(hba, 0x00000828, 0x08000000);
-	ufs_renesas_param_write(hba, 0xd0, 0x0000082c);
-	ufs_renesas_param_poll(hba, 0xd4, BIT(27), BIT(27));
-	ufs_renesas_param_write(hba, 0xd0, 0x00000d2c);
-	ufs_renesas_param_poll(hba, 0xd4, BIT(0), BIT(0));
+	timer_val = ufs_renesas_init_disable_timer(hba);
 
 	/* phy setup */
 	ufs_renesas_param_indirect_write(hba, 1, 0x01, 0x001f);
@@ -276,10 +305,7 @@  static void ufs_renesas_pre_init(struct ufs_hba *hba)
 	ufs_renesas_param_write_phy(hba, 0x4000, 0x0000);
 	ufs_renesas_param_write_phy(hba, 0x4001, 0x0000);
 
-	ufs_renesas_param_write_phy_10ad_10af(hba, 0x0000, 0x0001);
-	ufs_renesas_param_write_phy_10ad_10af(hba, 0x0000, 0x0002);
-	ufs_renesas_param_write_phy_10ad_10af(hba, 0x0080, 0x0000);
-	ufs_renesas_param_write_phy_10ad_10af(hba, 0x0080, 0x001a);
+	ufs_renesas_init_compensation_and_slicers(hba);
 
 	ufs_renesas_param_indirect_write(hba, 7, 0x70, 0x0016);
 	ufs_renesas_param_indirect_write(hba, 7, 0x71, 0x0016);
@@ -306,9 +332,7 @@  static void ufs_renesas_pre_init(struct ufs_hba *hba)
 	ufs_renesas_param_indirect_poll(hba, 7, 0x41, 0, BIT(7));
 	/* end of phy setup */
 
-	ufs_renesas_param_write(hba, 0xf0, 0);
-	ufs_renesas_param_write(hba, 0xd0, 0x00000d00);
-	ufs_renesas_param_write(hba, 0xd4, timer_val);
+	ufs_renesas_init_enable_timer(hba, timer_val);
 }
 
 static int ufs_renesas_hce_enable_notify(struct ufs_hba *hba,