[PATCH 2/5] scsi: ufs: renesas: Remove a static local variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



After refactored code, the driver can store register values in
variables. So, remove a static local variable "save" in
ufs_renesas_reg_control() to improve code readability.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@xxxxxxxxxxx>
---
 drivers/ufs/host/ufs-renesas.c | 97 +++++++++-------------------------
 1 file changed, 25 insertions(+), 72 deletions(-)

diff --git a/drivers/ufs/host/ufs-renesas.c b/drivers/ufs/host/ufs-renesas.c
index 36e880449479..3a393bd4c407 100644
--- a/drivers/ufs/host/ufs-renesas.c
+++ b/drivers/ufs/host/ufs-renesas.c
@@ -23,10 +23,8 @@ struct ufs_renesas_priv {
 };
 
 enum ufs_renesas_init_param_mode {
-	MODE_RESTORE,
-	MODE_SET,
-	MODE_SAVE,
 	MODE_POLL,
+	MODE_READ,
 	MODE_WAIT,
 	MODE_WRITE,
 };
@@ -37,7 +35,6 @@ struct ufs_renesas_init_param {
 	union {
 		u32 expected;
 		u32 delay_us;
-		u32 set;
 		u32 val;
 	} u;
 	u32 mask;
@@ -49,22 +46,15 @@ static void ufs_renesas_dbg_register_dump(struct ufs_hba *hba)
 	ufshcd_dump_regs(hba, 0xc0, 0x40, "regs: 0xc0 + ");
 }
 
-static void ufs_renesas_reg_control(struct ufs_hba *hba,
-				    const struct ufs_renesas_init_param *p)
+static u32 ufs_renesas_reg_control(struct ufs_hba *hba,
+				   const struct ufs_renesas_init_param *p)
 {
-	static u32 save[MAX_INDEX];
+	u32 val = 0;
 	int ret;
-	u32 val;
 
 	switch (p->mode) {
-	case MODE_RESTORE:
-		ufshcd_writel(hba, save[p->index], p->reg);
-		break;
-	case MODE_SET:
-		save[p->index] |= p->u.set;
-		break;
-	case MODE_SAVE:
-		save[p->index] = ufshcd_readl(hba, p->reg) & p->mask;
+	case MODE_READ:
+		val = ufshcd_readl(hba, p->reg);
 		break;
 	case MODE_POLL:
 		ret = readl_poll_timeout_atomic(hba->mmio_base + p->reg,
@@ -87,52 +77,29 @@ static void ufs_renesas_reg_control(struct ufs_hba *hba,
 	default:
 		break;
 	}
-}
 
-static void ufs_renesas_param_poll(struct ufs_hba *hba, u32 reg, u32 expected,
-				   u32 mask)
-{
-	struct ufs_renesas_init_param param = { 0 };
-
-	param.mode = MODE_POLL;
-	param.reg = reg;
-	param.u.expected = expected;
-	param.mask = mask;
-
-	ufs_renesas_reg_control(hba, &param);
+	return val;
 }
 
-static void ufs_renesas_param_restore(struct ufs_hba *hba, u32 reg, u32 index)
+static u32 ufs_renesas_param_read(struct ufs_hba *hba, u32 reg)
 {
 	struct ufs_renesas_init_param param = { 0 };
 
-	param.mode = MODE_RESTORE;
+	param.mode = MODE_READ;
 	param.reg = reg;
-	param.index = index;
 
-	ufs_renesas_reg_control(hba, &param);
+	return ufs_renesas_reg_control(hba, &param);
 }
 
-static void ufs_renesas_param_save(struct ufs_hba *hba, u32 reg, u32 mask,
-				   u32 index)
+static void ufs_renesas_param_poll(struct ufs_hba *hba, u32 reg, u32 expected,
+				   u32 mask)
 {
 	struct ufs_renesas_init_param param = { 0 };
 
-	param.mode = MODE_SAVE;
+	param.mode = MODE_POLL;
 	param.reg = reg;
+	param.u.expected = expected;
 	param.mask = mask;
-	param.index = index;
-
-	ufs_renesas_reg_control(hba, &param);
-}
-
-static void ufs_renesas_param_set(struct ufs_hba *hba, u32 index, u32 set)
-{
-	struct ufs_renesas_init_param param = { 0 };
-
-	param.mode = MODE_SAVE;
-	param.index = index;
-	param.u.set = set;
 
 	ufs_renesas_reg_control(hba, &param);
 }
@@ -173,15 +140,6 @@ static void ufs_renesas_param_write_800_80c_poll(struct ufs_hba *hba, u32 addr,
 	ufs_renesas_param_poll(hba, 0xd4, BIT(8), BIT(8));
 }
 
-static void ufs_renesas_param_restore_800_80c_poll(struct ufs_hba *hba, u32 index)
-{
-	ufs_renesas_param_write_d0_d4(hba, 0x0000080c, 0x00000100);
-	ufs_renesas_param_write(hba, 0xd0, 0x00000800);
-	ufs_renesas_param_restore(hba, 0xd4, index);
-	ufs_renesas_param_write(hba, 0xd0, 0x0000080c);
-	ufs_renesas_param_poll(hba, 0xd4, BIT(8), BIT(8));
-}
-
 static void ufs_renesas_param_write_804_80c_poll(struct ufs_hba *hba, u32 addr, u32 data_804)
 {
 	ufs_renesas_param_write_d0_d4(hba, 0x0000080c, 0x00000100);
@@ -212,6 +170,8 @@ static void ufs_renesas_param_write_phy(struct ufs_hba *hba, u32 addr16, u32 dat
 
 static void ufs_renesas_param_set_phy(struct ufs_hba *hba, u32 addr16, u32 data16)
 {
+	u32 low, high;
+
 	ufs_renesas_param_write(hba, 0xf0, 1);
 	ufs_renesas_param_write_800_80c_poll(hba, 0x16, addr16 & 0xff);
 	ufs_renesas_param_write_800_80c_poll(hba, 0x17, (addr16 >> 8) & 0xff);
@@ -219,24 +179,15 @@ static void ufs_renesas_param_set_phy(struct ufs_hba *hba, u32 addr16, u32 data1
 	ufs_renesas_param_write_828_82c_poll(hba, 0x0f000000);
 	ufs_renesas_param_write_804_80c_poll(hba, 0x1a, 0);
 	ufs_renesas_param_write(hba, 0xd0, 0x00000808);
-	ufs_renesas_param_save(hba, 0xd4, 0xff, SET_PHY_INDEX_LO);
+	low = ufs_renesas_param_read(hba, 0xd4) & 0xff;
 	ufs_renesas_param_write_804_80c_poll(hba, 0x1b, 0);
 	ufs_renesas_param_write(hba, 0xd0, 0x00000808);
-	ufs_renesas_param_save(hba, 0xd4, 0xff, SET_PHY_INDEX_HI);
-	ufs_renesas_param_write_828_82c_poll(hba, 0x0f000000);
-	ufs_renesas_param_write(hba, 0xf0, 0);
-	ufs_renesas_param_write(hba, 0xf0, 1);
-	ufs_renesas_param_write_800_80c_poll(hba, 0x16, addr16 & 0xff);
-	ufs_renesas_param_write_800_80c_poll(hba, 0x17, (addr16 >> 8) & 0xff);
-	ufs_renesas_param_set(hba, SET_PHY_INDEX_LO,
-			      ((data16 & 0xff) << 16) | BIT(8) | 0x18);
-	ufs_renesas_param_restore_800_80c_poll(hba, SET_PHY_INDEX_LO);
-	ufs_renesas_param_set(hba, SET_PHY_INDEX_HI,
-			      (((data16 >> 8) & 0xff) << 16) | BIT(8) | 0x19);
-	ufs_renesas_param_restore_800_80c_poll(hba, SET_PHY_INDEX_HI);
-	ufs_renesas_param_write_800_80c_poll(hba, 0x1c, 0x01);
+	high = ufs_renesas_param_read(hba, 0xd4) & 0xff;
 	ufs_renesas_param_write_828_82c_poll(hba, 0x0f000000);
 	ufs_renesas_param_write(hba, 0xf0, 0);
+
+	data16 |= (high << 8) | low;
+	ufs_renesas_param_write_phy(hba, addr16, data16);
 }
 
 static void ufs_renesas_param_indirect_write(struct ufs_hba *hba, u32 gpio,
@@ -260,6 +211,8 @@ static void ufs_renesas_param_indirect_poll(struct ufs_hba *hba, u32 gpio,
 
 static void ufs_renesas_pre_init(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);
@@ -287,7 +240,7 @@ static void ufs_renesas_pre_init(struct ufs_hba *hba)
 			       BIT(8) | BIT(6) | BIT(0));
 
 	ufs_renesas_param_write(hba, 0xd0, 0x00000d00);
-	ufs_renesas_param_save(hba, 0xd4, 0x0000ffff, TIMER_INDEX);
+	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);
@@ -382,7 +335,7 @@ static void ufs_renesas_pre_init(struct ufs_hba *hba)
 
 	ufs_renesas_param_write(hba, 0xf0, 0);
 	ufs_renesas_param_write(hba, 0xd0, 0x00000d00);
-	ufs_renesas_param_restore(hba, 0xd4, TIMER_INDEX);
+	ufs_renesas_param_write(hba, 0xd4, timer_val);
 }
 
 static int ufs_renesas_hce_enable_notify(struct ufs_hba *hba,
-- 
2.25.1





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux