aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/common.c')
-rw-r--r--target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/common.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/common.c b/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/common.c
index 8b0b55d891..fb359dc4fa 100644
--- a/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/common.c
+++ b/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/common.c
@@ -121,28 +121,45 @@ void rtl_table_release(struct table_reg *r)
// pr_info("Unlock done\n");
}
+static int rtl_table_exec(struct table_reg *r, bool is_write, int idx)
+{
+ int ret = 0;
+ u32 cmd, val;
+
+ /* Read/write bit has inverted meaning on RTL838x */
+ if (r->rmode)
+ cmd = is_write ? 0 : BIT(r->c_bit);
+ else
+ cmd = is_write ? BIT(r->c_bit) : 0;
+
+ cmd |= BIT(r->c_bit + 1); /* Execute bit */
+ cmd |= r->tbl << r->t_bit; /* Table type */
+ cmd |= idx & (BIT(r->t_bit) - 1); /* Index */
+
+ sw_w32(cmd, r->addr);
+
+ ret = readx_poll_timeout(sw_r32, r->addr, val,
+ !(val & BIT(r->c_bit + 1)), 20, 10000);
+ if (ret)
+ pr_err("%s: timeout\n", __func__);
+
+ return ret;
+}
+
/*
* Reads table index idx into the data registers of the table
*/
-void rtl_table_read(struct table_reg *r, int idx)
+int rtl_table_read(struct table_reg *r, int idx)
{
- u32 cmd = r->rmode ? BIT(r->c_bit) : 0;
-
- cmd |= BIT(r->c_bit + 1) | (r->tbl << r->t_bit) | (idx & (BIT(r->t_bit) - 1));
- sw_w32(cmd, r->addr);
- do { } while (sw_r32(r->addr) & BIT(r->c_bit + 1));
+ return rtl_table_exec(r, false, idx);
}
/*
* Writes the content of the table data registers into the table at index idx
*/
-void rtl_table_write(struct table_reg *r, int idx)
+int rtl_table_write(struct table_reg *r, int idx)
{
- u32 cmd = r->rmode ? 0 : BIT(r->c_bit);
-
- cmd |= BIT(r->c_bit + 1) | (r->tbl << r->t_bit) | (idx & (BIT(r->t_bit) - 1));
- sw_w32(cmd, r->addr);
- do { } while (sw_r32(r->addr) & BIT(r->c_bit + 1));
+ return rtl_table_exec(r, true, idx);
}
/*