Skip to contentSkip to conversation

r8152: support more chips

PATCH Superseded Hayes Wang 2 participants 24 messages Jun 9, 2020 – Jun 15, 2020 USB

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Hayes Wang

author
#0 lore raw

cover r8152: support more chips

The first two patched are some improvements. And the last two patches are used to support RTL8153B and RTL8154B.

Hayes Wang (4):
eth/r8152: reset bmu after disabling Tx/Rx
eth/r8152: reset PHY after setting it
eth/r8152: modify rtl_clear_bp function
eth/r8152: support RTL8153B/RTL8154B

 drivers/usb/eth/r8152.c    | 223 +++++++++++++++++++++++++++++++++-
 drivers/usb/eth/r8152.h    |  71 +++++++++--
 drivers/usb/eth/r8152_fw.c | 239 +++++++++++++++++++++++++++++++++----
 3 files changed, 493 insertions(+), 40 deletions(-)
Signature · 1 line
2.21.1
author
#1 lore raw

PATCH 1/4 eth/r8152: reset bmu after disabling Tx/Rx

Reset bmu after disabling Tx/Rx. This is used to clear the FIFO of Tx/Rx. The remained data may be transferred after Tx/Rx is re-enabled. And it results in garbage data.

---
 drivers/usb/eth/r8152.c | 14 ++++++++++++++
 drivers/usb/eth/r8152.h |  7 ++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
drivers/usb/eth/r8152.c +14 -0
index f201a1789b..dbb1721882 100644
@@ -568,6 +568,17 @@ static void r8153_power_cut_en(struct r8152 *tp, bool enable)
 	ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data);
 }
 
+static void rtl_reset_bmu(struct r8152 *tp)
+{
+	u32 ocp_data;
+
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_BMU_RESET);
+	ocp_data &= ~(BMU_RESET_EP_IN | BMU_RESET_EP_OUT);
+	ocp_write_byte(tp, MCU_TYPE_USB, USB_BMU_RESET, ocp_data);
+	ocp_data |= BMU_RESET_EP_IN | BMU_RESET_EP_OUT;
+	ocp_write_byte(tp, MCU_TYPE_USB, USB_BMU_RESET, ocp_data);
+}
+
 static int r8152_read_mac(struct r8152 *tp, unsigned char *macaddr)
 {
 	int ret;
@@ -786,6 +797,7 @@ static void r8153_first_init(struct r8152 *tp)
 	r8153_hw_phy_cfg(tp);
 
 	rtl8152_nic_reset(tp);
+	rtl_reset_bmu(tp);
 
 	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
 	ocp_data &= ~NOW_IS_OOB;
@@ -832,6 +844,7 @@ static void r8153_enter_oob(struct r8152 *tp)
 	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
 
 	rtl_disable(tp);
+	rtl_reset_bmu(tp);
 
 	rtl8152_reinit_ll(tp);
 
@@ -873,6 +886,7 @@ static void rtl8153_disable(struct r8152 *tp)
 {
 	r8153_disable_aldps(tp);
 	rtl_disable(tp);
+	rtl_reset_bmu(tp);
 }
 
 static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex)
drivers/usb/eth/r8152.h +6 -1
index 10e0da8eb1..4daf4ee87d 100644
@@ -89,9 +89,10 @@
 #define USB_TX_DMA		0xd434
 #define USB_TOLERANCE		0xd490
 #define USB_LPM_CTRL		0xd41a
+#define USB_BMU_RESET		0xd4b0
 #define USB_UPS_CTRL		0xd800
-#define USB_MISC_0		0xd81a
 #define USB_POWER_CUT		0xd80a
+#define USB_MISC_0		0xd81a
 #define USB_AFE_CTRL2		0xd824
 #define USB_WDT11_CTRL		0xe43c
 #define USB_BP_BA		0xfc26
@@ -324,6 +325,10 @@
 #define TEST_MODE_DISABLE	0x00000001
 #define TX_SIZE_ADJUST1		0x00000100
 
+/* USB_BMU_RESET */
+#define BMU_RESET_EP_IN		0x01
+#define BMU_RESET_EP_OUT	0x02
+
 /* USB_UPS_CTRL */
 #define POWER_CUT		0x0100
 
Signature · 1 line
2.21.1
#2 lore raw

PATCH 1/4 eth/r8152: reset bmu after disabling Tx/Rx

Quoted 15 lines · Hayes Wang

Reset bmu after disabling Tx/Rx. This is used to clear the FIFO of Tx/Rx. The remained data may be transferred after Tx/Rx is re-enabled. And it results in garbage data.

---
 drivers/usb/eth/r8152.c | 14 ++++++++++++++
 drivers/usb/eth/r8152.h |  7 ++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
drivers/usb/eth/r8152.c +0 -0
index f201a1789b..dbb1721882 100644

drivers/usb/eth/r8152.c static void r8153_power_cut_en(struct r8152 *tp, bool enable) · line 573

Quoted 6 lines
drivers/usb/eth/r8152.c +3 -0
@@ -568,6 +568,17 @@ static void r8153_power_cut_en(struct r8152 *tp, bool enable)
 	ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data);
 }
 
+static void rtl_reset_bmu(struct r8152 *tp)
+{
+	u32 ocp_data;

You're writing a byte, shouldn't that be u8 ?

author
#3 lore raw

PATCH 1/4 eth/r8152: reset bmu after disabling Tx/Rx

Marek Vasut [mailto:marex at denx.de]

Quoted 1 line

Sent: Tuesday, June 09, 2020 10:21 PM

[...]

Quoted 5 lines

drivers/usb/eth/r8152.c static void r8153_power_cut_en(struct r8152 *tp, bool enable) · line 573

Quoted 3 lines
drivers/usb/eth/r8152.c +3 -0
+static void rtl_reset_bmu(struct r8152 *tp)
+{
+	u32 ocp_data;

You're writing a byte, shouldn't that be u8 ?

The minimum length which is used to read or write the register of the device through control transfer is 4-byte. Therefore, I always use "u32" to access 1, 2, or 4 bytes data. Then, I don't need another variable to deal with it.

Best Regards,
Hayes

#4 lore raw

PATCH 1/4 eth/r8152: reset bmu after disabling Tx/Rx

Quoted 9 lines · Hayes Wang

Marek Vasut [mailto:marex at denx.de]

Quoted 1 line

Sent: Tuesday, June 09, 2020 10:21 PM

[...]

Quoted 5 lines

drivers/usb/eth/r8152.c static void r8153_power_cut_en(struct r8152 *tp, bool enable) · line 573

Quoted 3 lines
drivers/usb/eth/r8152.c +3 -0
+static void rtl_reset_bmu(struct r8152 *tp)
+{
+	u32 ocp_data;

You're writing a byte, shouldn't that be u8 ?

Quoted 5 lines

The minimum length which is used to read or write the register of the device through control transfer is 4-byte. Therefore, I always use "u32" to access 1, 2, or 4 bytes data. Then, I don't need another variable to deal with it.

ocp_read_byte() returns u8, and while ocp_write_byte() expects u32 as data, it masks away all but the LSByte, so it should be OK to use u8?

author
#5 lore raw

PATCH 1/4 eth/r8152: reset bmu after disabling Tx/Rx

Marek Vasut [mailto:marex at denx.de]

Quoted 1 line

Sent: Wednesday, June 10, 2020 7:05 PM

[...]

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

drivers/usb/eth/r8152.c static void r8153_power_cut_en(struct r8152 *tp, bool enable) · line 573

Quoted 3 lines
drivers/usb/eth/r8152.c +3 -0
+static void rtl_reset_bmu(struct r8152 *tp)
+{
+	u32 ocp_data;

You're writing a byte, shouldn't that be u8 ?

Quoted 8 lines
Quoted 5 lines

The minimum length which is used to read or write the register of the device through control transfer is 4-byte. Therefore, I always use "u32" to access 1, 2, or 4 bytes data. Then, I don't need another variable to deal with it.

ocp_read_byte() returns u8, and while ocp_write_byte() expects u32 as data, it masks away all but the LSByte, so it should be OK to use u8?

Yes, you are right.

Best Regards,
Hayes

author
#6 lore raw

PATCH 2/4 eth/r8152: reset PHY after setting it

In reply to Hayes Wang

Some settings of PHY have to work after resetting PHY.

---
 drivers/usb/eth/r8152.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/eth/r8152.c +1 -1
index dbb1721882..d774a0fa63 100644
@@ -947,7 +947,7 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex)
 			return -EINVAL;
 		}
 
-		bmcr = BMCR_ANENABLE | BMCR_ANRESTART;
+		bmcr = BMCR_ANENABLE | BMCR_ANRESTART | BMCR_RESET;
 	}
 
 	if (tp->supports_gmii)
Signature · 1 line
2.21.1
#7 lore raw

PATCH 2/4 eth/r8152: reset PHY after setting it

Quoted 12 lines · Hayes Wang

Some settings of PHY have to work after resetting PHY.

---
 drivers/usb/eth/r8152.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/eth/r8152.c +0 -0
index dbb1721882..d774a0fa63 100644

drivers/usb/eth/r8152.c static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex) · line 950

Quoted 5 lines
drivers/usb/eth/r8152.c +1 -1
@@ -947,7 +947,7 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex)
 			return -EINVAL;
 		}
 
-		bmcr = BMCR_ANENABLE | BMCR_ANRESTART;
+		bmcr = BMCR_ANENABLE | BMCR_ANRESTART | BMCR_RESET;

Do you really need to reset a PHY while resetting the autonegotiation ? I think if you reset the PHY , then the ANEG operation is restarted by default or undefined, no ?

author
#8 lore raw

PATCH 2/4 eth/r8152: reset PHY after setting it

Marek Vasut [mailto:marex at denx.de]

Quoted 1 line

Sent: Tuesday, June 09, 2020 10:22 PM

[...]

Quoted 6 lines

drivers/usb/eth/r8152.c static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex) · line 950

Quoted 2 lines
drivers/usb/eth/r8152.c +1 -1
-		bmcr = BMCR_ANENABLE | BMCR_ANRESTART;
+		bmcr = BMCR_ANENABLE | BMCR_ANRESTART | BMCR_RESET;

Do you really need to reset a PHY while resetting the autonegotiation ? I think if you reset the PHY , then the ANEG operation is restarted by default or undefined, no ?

The setting is from the HW engineer. And I follow
the rule for a long time. I think they know what
they do.

Best Regards,
Hayes

#9 lore raw

PATCH 2/4 eth/r8152: reset PHY after setting it

Quoted 10 lines · Hayes Wang

Marek Vasut [mailto:marex at denx.de]

Quoted 1 line

Sent: Tuesday, June 09, 2020 10:22 PM

[...]

Quoted 6 lines

drivers/usb/eth/r8152.c static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex) · line 950

Quoted 2 lines
drivers/usb/eth/r8152.c +1 -1
-		bmcr = BMCR_ANENABLE | BMCR_ANRESTART;
+		bmcr = BMCR_ANENABLE | BMCR_ANRESTART | BMCR_RESET;

Do you really need to reset a PHY while resetting the autonegotiation ? I think if you reset the PHY , then the ANEG operation is restarted by default or undefined, no ?

Quoted 3 lines

The setting is from the HW engineer. And I follow
the rule for a long time. I think they know what
they do.

If the hardware is OK with it, then that's fine.

author
#10 lore raw

PATCH 3/4 eth/r8152: modify rtl_clear_bp function

In reply to Hayes Wang

The original rtl_clear_bp() is used to clear the firmware of both PLA and USB MCU. The new one could clear the firmware of PLA or USB independently. It is unnecessary to clear firmware, if there is no one to be updated.

---
 drivers/usb/eth/r8152.h    | 20 ++++++------
 drivers/usb/eth/r8152_fw.c | 63 +++++++++++++++++++++++---------------
 2 files changed, 48 insertions(+), 35 deletions(-)
drivers/usb/eth/r8152.h +10 -10
index 4daf4ee87d..ff4262d68d 100644
@@ -95,16 +95,16 @@
 #define USB_MISC_0		0xd81a
 #define USB_AFE_CTRL2		0xd824
 #define USB_WDT11_CTRL		0xe43c
-#define USB_BP_BA		0xfc26
-#define USB_BP_0		0xfc28
-#define USB_BP_1		0xfc2a
-#define USB_BP_2		0xfc2c
-#define USB_BP_3		0xfc2e
-#define USB_BP_4		0xfc30
-#define USB_BP_5		0xfc32
-#define USB_BP_6		0xfc34
-#define USB_BP_7		0xfc36
-#define USB_BP_EN		0xfc38
+#define USB_BP_BA		PLA_BP_BA
+#define USB_BP_0		PLA_BP_0
+#define USB_BP_1		PLA_BP_1
+#define USB_BP_2		PLA_BP_2
+#define USB_BP_3		PLA_BP_3
+#define USB_BP_4		PLA_BP_4
+#define USB_BP_5		PLA_BP_5
+#define USB_BP_6		PLA_BP_6
+#define USB_BP_7		PLA_BP_7
+#define USB_BP_EN		PLA_BP_EN
 
 /* OCP Registers */
 #define OCP_ALDPS_CONFIG	0x2010
drivers/usb/eth/r8152_fw.c +38 -25

127 lines not on this page · raw message

Signature · 1 line
2.21.1
#11 lore raw

PATCH 3/4 eth/r8152: modify rtl_clear_bp function

Quoted 29 lines · Hayes Wang

The original rtl_clear_bp() is used to clear the firmware of both PLA and USB MCU. The new one could clear the firmware of PLA or USB independently. It is unnecessary to clear firmware, if there is no one to be updated.

---
 drivers/usb/eth/r8152.h    | 20 ++++++------
 drivers/usb/eth/r8152_fw.c | 63 +++++++++++++++++++++++---------------
 2 files changed, 48 insertions(+), 35 deletions(-)
drivers/usb/eth/r8152.h +0 -10
index 4daf4ee87d..ff4262d68d 100644
@@ -95,16 +95,16 @@
 #define USB_MISC_0		0xd81a
 #define USB_AFE_CTRL2		0xd824
 #define USB_WDT11_CTRL		0xe43c
-#define USB_BP_BA		0xfc26
-#define USB_BP_0		0xfc28
-#define USB_BP_1		0xfc2a
-#define USB_BP_2		0xfc2c
-#define USB_BP_3		0xfc2e
-#define USB_BP_4		0xfc30
-#define USB_BP_5		0xfc32
-#define USB_BP_6		0xfc34
-#define USB_BP_7		0xfc36
-#define USB_BP_EN		0xfc38

drivers/usb/eth/r8152.h line 107

Quoted 10 lines
drivers/usb/eth/r8152.h +10 -0
+#define USB_BP_BA		PLA_BP_BA
+#define USB_BP_0		PLA_BP_0
+#define USB_BP_1		PLA_BP_1
+#define USB_BP_2		PLA_BP_2
+#define USB_BP_3		PLA_BP_3
+#define USB_BP_4		PLA_BP_4
+#define USB_BP_5		PLA_BP_5
+#define USB_BP_6		PLA_BP_6
+#define USB_BP_7		PLA_BP_7
+#define USB_BP_EN		PLA_BP_EN

Can you make this into USB_BP(n) (0xfc28 + 2 * (n)) ?

[...]

author
#12 lore raw

PATCH 4/4 eth/r8152: support RTL8153B/RTL8154B

In reply to Hayes Wang

This is used to support RTL8153B and RTL8154B.

---
 drivers/usb/eth/r8152.c    | 207 ++++++++++++++++++++++++++++++++++++-
 drivers/usb/eth/r8152.h    |  46 ++++++++-
 drivers/usb/eth/r8152_fw.c | 176 +++++++++++++++++++++++++++++++
 3 files changed, 425 insertions(+), 4 deletions(-)
drivers/usb/eth/r8152.c +205 -2
index d774a0fa63..aa64d1d4af 100644
@@ -68,6 +68,8 @@ static const struct r8152_version r8152_versions[] = {
 	{ 0x5c20, RTL_VER_05, 1 },
 	{ 0x5c30, RTL_VER_06, 1 },
 	{ 0x4800, RTL_VER_07, 0 },
+	{ 0x6000, RTL_VER_08, 1 },
+	{ 0x6010, RTL_VER_09, 1 },
 };
 
 static
@@ -331,6 +333,12 @@ void sram_write(struct r8152 *tp, u16 addr, u16 data)
 	ocp_reg_write(tp, OCP_SRAM_DATA, data);
 }
 
+static u16 sram_read(struct r8152 *tp, u16 addr)
+{
+	ocp_reg_write(tp, OCP_SRAM_ADDR, addr);
+	return ocp_reg_read(tp, OCP_SRAM_DATA);
+}
+
 int r8152_wait_for_bit(struct r8152 *tp, bool ocp_reg, u16 type, u16 index,
 		       const u32 mask, bool set, unsigned int timeout)
 {
@@ -467,12 +475,56 @@ static void r8153_set_rx_early_timeout(struct r8152 *tp)
 {
 	u32 ocp_data = tp->coalesce / 8;
 
-	ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT, ocp_data);
+	switch (tp->version) {
+	case RTL_VER_03:
+	case RTL_VER_04:
+	case RTL_VER_05:
+	case RTL_VER_06:
+		ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT,
+			       ocp_data);
+		break;
+
+	case RTL_VER_08:
+	case RTL_VER_09:
+		/* The RTL8153B uses USB_RX_EXTRA_AGGR_TMR for rx timeout
+		 * primarily. For USB_RX_EARLY_TIMEOUT, we fix it to 1264ns.
+		 */
+		ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT,
+			       1264 / 8);
+		ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EXTRA_AGGR_TMR,
+			       ocp_data);
+		break;
+
+	default:
+		debug("** %s Invalid Device\n", __func__);
+		break;
+	}
 }
 
 static void r8153_set_rx_early_size(struct r8152 *tp)
 {
-	u32 ocp_data = (RTL8152_AGG_BUF_SZ - RTL8153_RMS) / 4;
+	u32 ocp_data = (RTL8152_AGG_BUF_SZ - RTL8153_RMS -
+			sizeof(struct rx_desc));
+
+	switch (tp->version) {
+	case RTL_VER_03:
+	case RTL_VER_04:
+	case RTL_VER_05:
+	case RTL_VER_06:
+		ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE,
+			       ocp_data / 4);
+		break;
+
+	case RTL_VER_08:
+	case RTL_VER_09:
+		ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE,
+			       ocp_data / 8);
+		break;
+
+	default:
+		debug("** %s Invalid Device\n", __func__);
+		break;
+	}
 
 	ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE, ocp_data);
 }
@@ -540,6 +592,19 @@ static void r8153_u1u2en(struct r8152 *tp, bool enable)
 	usb_ocp_write(tp, USB_TOLERANCE, BYTE_EN_SIX_BYTES, sizeof(u1u2), u1u2);
 }
 
+static void r8153b_u1u2en(struct r8152 *tp, bool enable)
+{
+	u32 ocp_data;
+
+	ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_LPM_CONFIG);
+	if (enable)
+		ocp_data |= LPM_U1U2_EN;
+	else
+		ocp_data &= ~LPM_U1U2_EN;
+
+	ocp_write_word(tp, MCU_TYPE_USB, USB_LPM_CONFIG, ocp_data);
+}
+
 static void r8153_u2p3en(struct r8152 *tp, bool enable)
 {
 	u32 ocp_data;
@@ -784,6 +849,71 @@ static void r8153_hw_phy_cfg(struct r8152 *tp)
 	sram_write(tp, SRAM_10M_AMP2, 0x0208);
 }
 
+static u32 r8152_efuse_read(struct r8152 *tp, u8 addr)
+{
+	u32 ocp_data;
+
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_EFUSE_CMD, EFUSE_READ_CMD | addr);
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EFUSE_CMD);
+	ocp_data = (ocp_data & EFUSE_DATA_BIT16) << 9;	/* data of bit16 */
+	ocp_data |= ocp_read_word(tp, MCU_TYPE_PLA, PLA_EFUSE_DATA);
+
+	return ocp_data;
+}
+
+static void r8153b_hw_phy_cfg(struct r8152 *tp)
+{
+	u32 ocp_data;
+	u16 data;
+
+	data = r8152_mdio_read(tp, MII_BMCR);
+	if (data & BMCR_PDOWN) {
+		data &= ~BMCR_PDOWN;
+		r8152_mdio_write(tp, MII_BMCR, data);
+	}
+
+	/* U1/U2/L1 idle timer. 500 us */
+	ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);
+
+	r8153b_firmware(tp);
+
+	data = sram_read(tp, SRAM_GREEN_CFG);
+	data |= R_TUNE_EN;
+	sram_write(tp, SRAM_GREEN_CFG, data);
+	data = ocp_reg_read(tp, OCP_NCTL_CFG);
+	data |= PGA_RETURN_EN;
+	ocp_reg_write(tp, OCP_NCTL_CFG, data);
+
+	/* ADC Bias Calibration:
+	 * read efuse offset 0x7d to get a 17-bit data. Remove the dummy/fake
+	 * bit (bit3) to rebuild the real 16-bit data. Write the data to the
+	 * ADC ioffset.
+	 */
+	ocp_data = r8152_efuse_read(tp, 0x7d);
+	data = (u16)(((ocp_data & 0x1fff0) >> 1) | (ocp_data & 0x7));
+	if (data != 0xffff)
+		ocp_reg_write(tp, OCP_ADC_IOFFSET, data);
+
+	/* ups mode tx-link-pulse timing adjustment:
+	 * rg_saw_cnt = OCP reg 0xC426 Bit[13:0]
+	 * swr_cnt_1ms_ini = 16000000 / rg_saw_cnt
+	 */
+	ocp_data = ocp_reg_read(tp, 0xc426);
+	ocp_data &= 0x3fff;
+	if (ocp_data) {
+		u32 swr_cnt_1ms_ini;
+
+		swr_cnt_1ms_ini = (16000000 / ocp_data) & SAW_CNT_1MS_MASK;
+		ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CFG);
+		ocp_data = (ocp_data & ~SAW_CNT_1MS_MASK) | swr_cnt_1ms_ini;
+		ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CFG, ocp_data);
+	}
+
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR);
+	ocp_data |= PFM_PWM_SWITCH;
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data);
+}
+
 static void r8153_first_init(struct r8152 *tp)
 {
 	u32 ocp_data;
@@ -991,6 +1121,16 @@ static void rtl8153_down(struct r8152 *tp)
 	r8153_enter_oob(tp);
 }
 
+static void rtl8153b_up(struct r8152 *tp)
+{
+	r8153_first_init(tp);
+}
+
+static void rtl8153b_down(struct r8152 *tp)
+{
+	r8153_enter_oob(tp);
+}
+
 static void r8152b_get_version(struct r8152 *tp)
 {
 	u32 ocp_data;
@@ -1154,6 +1294,60 @@ static void r8153_init(struct r8152 *tp)
 	rtl_tally_reset(tp);
 }
 
+static void r8153b_init(struct r8152 *tp)
+{
+	u32 ocp_data;
+	int i;
+
+	r8153_disable_aldps(tp);
+	r8153b_u1u2en(tp, false);
+
+	r8152_wait_for_bit(tp, 0, MCU_TYPE_PLA, PLA_BOOT_CTRL,
+			   AUTOLOAD_DONE, 1, R8152_WAIT_TIMEOUT);
+
+	for (i = 0; i < R8152_WAIT_TIMEOUT; i++) {
+		ocp_data = ocp_reg_read(tp, OCP_PHY_STATUS) & PHY_STAT_MASK;
+		if (ocp_data == PHY_STAT_LAN_ON || ocp_data == PHY_STAT_PWRDN)
+			break;
+
+		mdelay(1);
+	}
+
+	r8153_u2p3en(tp, false);
+
+	/* MSC timer = 0xfff * 8ms = 32760 ms */
+	ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff);
+
+	r8153_power_cut_en(tp, false);
+
+	/* MAC clock speed down */
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2);
+	ocp_data |= MAC_CLK_SPDWN_EN;
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, ocp_data);
+
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3);
+	ocp_data &= ~PLA_MCU_SPDWN_EN;
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
+
+	if (tp->version == RTL_VER_09) {
+		/* Disable Test IO for 32QFN */
+		if (ocp_read_byte(tp, MCU_TYPE_PLA, 0xdc00) & BIT(5)) {
+			ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR);
+			ocp_data |= TEST_IO_OFF;
+			ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data);
+		}
+	}
+
+	/* rx aggregation */
+	ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL);
+	ocp_data &= ~(RX_AGG_DISABLE | RX_ZERO_EN);
+	ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data);
+
+	rtl_tally_reset(tp);
+	r8153b_hw_phy_cfg(tp);
+	r8152b_enable_fc(tp);
+}
+
 static void rtl8152_unload(struct r8152 *tp)
 {
 	if (tp->version != RTL_VER_01)
@@ -1194,6 +1388,15 @@ static int rtl_ops_init(struct r8152 *tp)
 		ops->unload		= rtl8153_unload;
 		break;
 
+	case RTL_VER_08:
+	case RTL_VER_09:
+		ops->init		= r8153b_init;
+		ops->enable		= rtl8153_enable;
+		ops->disable		= rtl8153_disable;
+		ops->up			= rtl8153b_up;
+		ops->down		= rtl8153b_down;
+		break;
+
 	default:
 		ret = -ENODEV;
 		printf("r8152 Unknown Device\n");
drivers/usb/eth/r8152.h +44 -2

149 lines not on this page · raw message

drivers/usb/eth/r8152_fw.c +176 -0

192 lines not on this page · raw message

Signature · 1 line
2.21.1
#13 lore raw

PATCH 4/4 eth/r8152: support RTL8153B/RTL8154B

Quoted 1 line · Hayes Wang

This is used to support RTL8153B and RTL8154B.

[...]

drivers/usb/eth/r8152.c static void r8153_set_rx_early_timeout(struct r8152 *tp) · line 493

Quoted 11 lines
drivers/usb/eth/r8152.c +11 -0
+		ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT,
+			       ocp_data);
+		break;
+
+	case RTL_VER_08:
+	case RTL_VER_09:
+		/* The RTL8153B uses USB_RX_EXTRA_AGGR_TMR for rx timeout
+		 * primarily. For USB_RX_EARLY_TIMEOUT, we fix it to 1264ns.
+		 */
+		ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT,
+			       1264 / 8);

Can you add some macro for this 1264 magic value ?

Quoted 9 lines
drivers/usb/eth/r8152.c +8 -0
+		ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EXTRA_AGGR_TMR,
+			       ocp_data);
+		break;
+
+	default:
+		debug("** %s Invalid Device\n", __func__);
+		break;
+	}
 }

[...]

Quoted 20 lines
drivers/usb/eth/r8152.c +20 -0
+static void r8153b_hw_phy_cfg(struct r8152 *tp)
+{
+	u32 ocp_data;
+	u16 data;
+
+	data = r8152_mdio_read(tp, MII_BMCR);
+	if (data & BMCR_PDOWN) {
+		data &= ~BMCR_PDOWN;
+		r8152_mdio_write(tp, MII_BMCR, data);
+	}
+
+	/* U1/U2/L1 idle timer. 500 us */
+	ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);
+
+	r8153b_firmware(tp);
+
+	data = sram_read(tp, SRAM_GREEN_CFG);
+	data |= R_TUNE_EN;
+	sram_write(tp, SRAM_GREEN_CFG, data);
+	data = ocp_reg_read(tp, OCP_NCTL_CFG);

drivers/usb/eth/r8152.c static void r8153_hw_phy_cfg(struct r8152 *tp) · line 893

Quoted 10 lines
drivers/usb/eth/r8152.c +10 -0
+	data |= PGA_RETURN_EN;
+	ocp_reg_write(tp, OCP_NCTL_CFG, data);
+
+	/* ADC Bias Calibration:
+	 * read efuse offset 0x7d to get a 17-bit data. Remove the dummy/fake
+	 * bit (bit3) to rebuild the real 16-bit data. Write the data to the
+	 * ADC ioffset.
+	 */
+	ocp_data = r8152_efuse_read(tp, 0x7d);
+	data = (u16)(((ocp_data & 0x1fff0) >> 1) | (ocp_data & 0x7));

Are these type casts really needed ?

[...]

Quoted 11 lines

static void rtl_clear_bp(struct r8152 *tp, u16 type) {

drivers/usb/eth/r8152_fw.c +3 -0
 	switch (tp->version) {
@@ -742,7 +863,23 @@ static void rtl_clear_bp(struct r8152 *tp, u16 type)
 	case RTL_VER_06:
 		ocp_write_byte(tp, type, PLA_BP_EN, 0);
 		break;
+	case RTL_VER_08:
+	case RTL_VER_09:
 	default:
+		if (type == MCU_TYPE_USB) {

drivers/usb/eth/r8152_fw.c static void rtl_clear_bp(struct r8152 *tp, u16 type) · line 879

Quoted 10 lines
drivers/usb/eth/r8152_fw.c +10 -0
+			ocp_write_byte(tp, MCU_TYPE_USB, USB_BP2_EN, 0);
+
+			ocp_write_word(tp, MCU_TYPE_USB, USB_BP_8, 0);
+			ocp_write_word(tp, MCU_TYPE_USB, USB_BP_9, 0);
+			ocp_write_word(tp, MCU_TYPE_USB, USB_BP_10, 0);
+			ocp_write_word(tp, MCU_TYPE_USB, USB_BP_11, 0);
+			ocp_write_word(tp, MCU_TYPE_USB, USB_BP_12, 0);
+			ocp_write_word(tp, MCU_TYPE_USB, USB_BP_13, 0);
+			ocp_write_word(tp, MCU_TYPE_USB, USB_BP_14, 0);
+			ocp_write_word(tp, MCU_TYPE_USB, USB_BP_15, 0);

Can those registers be written in bulk ?

Quoted 7 lines
drivers/usb/eth/r8152_fw.c +3 -0
+		} else {
+			ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0);
+		}
 		break;
 	}
 

drivers/usb/eth/r8152_fw.c void r8153_firmware(struct r8152 *tp) · line 1172

Quoted 9 lines
drivers/usb/eth/r8152_fw.c +6 -0
@@ -1027,3 +1164,42 @@ void r8153_firmware(struct r8152 *tp)
 		ocp_write_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1, ocp_data);
 	}
 }
+
+void r8153b_firmware(struct r8152 *tp)
+{
+	int i;
+
+	if (tp->version == RTL_VER_09) {

Invert the condition and reduce indent.

if (tp->version != RTL_VER_09)
return;

...

Quoted 3 lines
drivers/usb/eth/r8152_fw.c +3 -0
+		u32 ocp_data;
+
+		rtl_clear_bp(tp, MCU_TYPE_USB);

[...]

author
#14 lore raw

PATCH 4/4 eth/r8152: support RTL8153B/RTL8154B

Marek Vasut [mailto:marex at denx.de]

Quoted 1 line

Sent: Tuesday, June 09, 2020 10:27 PM

[...]

Quoted 9 lines

drivers/usb/eth/r8152.c static void r8153_hw_phy_cfg(struct r8152 *tp) · line 893

Quoted 7 lines
drivers/usb/eth/r8152.c +7 -0
+	/* ADC Bias Calibration:
+	 * read efuse offset 0x7d to get a 17-bit data. Remove the dummy/fake
+	 * bit (bit3) to rebuild the real 16-bit data. Write the data to the
+	 * ADC ioffset.
+	 */
+	ocp_data = r8152_efuse_read(tp, 0x7d);
+	data = (u16)(((ocp_data & 0x1fff0) >> 1) | (ocp_data & 0x7));

Are these type casts really needed ?

Is there not a warning from u32 to u16?

Best Regards,
Hayes

#15 lore raw

PATCH 4/4 eth/r8152: support RTL8153B/RTL8154B

Quoted 13 lines · Hayes Wang

Marek Vasut [mailto:marex at denx.de]

Quoted 1 line

Sent: Tuesday, June 09, 2020 10:27 PM

[...]

Quoted 9 lines

drivers/usb/eth/r8152.c static void r8153_hw_phy_cfg(struct r8152 *tp) · line 893

Quoted 7 lines
drivers/usb/eth/r8152.c +7 -0
+	/* ADC Bias Calibration:
+	 * read efuse offset 0x7d to get a 17-bit data. Remove the dummy/fake
+	 * bit (bit3) to rebuild the real 16-bit data. Write the data to the
+	 * ADC ioffset.
+	 */
+	ocp_data = r8152_efuse_read(tp, 0x7d);
+	data = (u16)(((ocp_data & 0x1fff0) >> 1) | (ocp_data & 0x7));

Are these type casts really needed ?

Quoted 1 line

Is there not a warning from u32 to u16?

There is, but it seems justified to warn about conversion from u32 to u16, so maybe that needs to be fixed ?

author
#16 lore raw

PATCH 4/4 eth/r8152: support RTL8153B/RTL8154B

Marek Vasut [mailto:marex at denx.de]

Quoted 1 line

Sent: Wednesday, June 10, 2020 8:54 PM

[...]

Quoted 11 lines
Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	/* ADC Bias Calibration:
+	 * read efuse offset 0x7d to get a 17-bit data. Remove the

dummy/fake

Quoted 8 lines
Quoted 7 lines

drivers/usb/eth/r8152.c static void r8153_hw_phy_cfg(struct r8152 *tp) · line 893

Quoted 5 lines
drivers/usb/eth/r8152.c +5 -0
+	 * bit (bit3) to rebuild the real 16-bit data. Write the data to the
+	 * ADC ioffset.
+	 */
+	ocp_data = r8152_efuse_read(tp, 0x7d);
+	data = (u16)(((ocp_data & 0x1fff0) >> 1) | (ocp_data & 0x7));

Are these type casts really needed ?

Quoted 4 lines
Quoted 1 line

Is there not a warning from u32 to u16?

There is, but it seems justified to warn about conversion from u32 to u16, so maybe that needs to be fixed ?

Excuse me. I don't understand what you mean.
The original is 17-bit data, so I use u32 to store it. And, the final desired data is 16-bit. That is why
I have to convert it from u32 to u16.

Best Regards,
Hayes

#17 lore raw

PATCH 4/4 eth/r8152: support RTL8153B/RTL8154B

Quoted 16 lines · Hayes Wang

Marek Vasut [mailto:marex at denx.de]

Quoted 1 line

Sent: Wednesday, June 10, 2020 8:54 PM

[...]

Quoted 13 lines
Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	/* ADC Bias Calibration:
+	 * read efuse offset 0x7d to get a 17-bit data. Remove the

dummy/fake

Quoted 9 lines
Quoted 7 lines

drivers/usb/eth/r8152.c static void r8153_hw_phy_cfg(struct r8152 *tp) · line 893

Quoted 5 lines
drivers/usb/eth/r8152.c +5 -0
+	 * bit (bit3) to rebuild the real 16-bit data. Write the data to the
+	 * ADC ioffset.
+	 */
+	ocp_data = r8152_efuse_read(tp, 0x7d);
+	data = (u16)(((ocp_data & 0x1fff0) >> 1) | (ocp_data & 0x7));

Are these type casts really needed ?

Is there not a warning from u32 to u16?

Quoted 7 lines
Quoted 2 lines

There is, but it seems justified to warn about conversion from u32 to u16, so maybe that needs to be fixed ?

Excuse me. I don't understand what you mean.
The original is 17-bit data, so I use u32 to store it. And, the final desired data is 16-bit. That is why
I have to convert it from u32 to u16.

So what happens to that bit 17 , is it dropped ?

author
#18 lore raw

PATCH 4/4 eth/r8152: support RTL8153B/RTL8154B

Marek Vasut [mailto:marex at denx.de]

Quoted 1 line

Sent: Wednesday, June 10, 2020 9:21 PM

[...]

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	/* ADC Bias Calibration:
+	 * read efuse offset 0x7d to get a 17-bit data. Remove the

dummy/fake

Quoted 9 lines
Quoted 7 lines

drivers/usb/eth/r8152.c static void r8153_hw_phy_cfg(struct r8152 *tp) · line 893

Quoted 5 lines
drivers/usb/eth/r8152.c +5 -0
+	 * bit (bit3) to rebuild the real 16-bit data. Write the data to the
+	 * ADC ioffset.
+	 */
+	ocp_data = r8152_efuse_read(tp, 0x7d);
+	data = (u16)(((ocp_data & 0x1fff0) >> 1) | (ocp_data & 0x7));

Are these type casts really needed ?

Is there not a warning from u32 to u16?

There is, but it seems justified to warn about conversion from u32 to u16, so maybe that needs to be fixed ?

Quoted 6 lines
Quoted 4 lines

Excuse me. I don't understand what you mean.
The original is 17-bit data, so I use u32 to store it. And, the final desired data is 16-bit. That is why
I have to convert it from u32 to u16.

So what happens to that bit 17 , is it dropped ?

I have descripted is in the code, such as following.

/* ADC Bias Calibration:
* read efuse offset 0x7d to get a 17-bit data. Remove the dummy/fake
* bit (bit3) to rebuild the real 16-bit data. Write the data to the
* ADC ioffset.
*/

The real data (16-bit) would be inserted a dummy bit, and store the 17-bit to efuse offset 0x7d. Therefore, when reading the 17-bit data from efuse, we have to remove the dummy to get the real data.

Best Regards,
Hayes

#19 lore raw

PATCH 4/4 eth/r8152: support RTL8153B/RTL8154B

Quoted 34 lines · Hayes Wang

Marek Vasut [mailto:marex at denx.de]

Quoted 1 line

Sent: Wednesday, June 10, 2020 9:21 PM

[...]

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	/* ADC Bias Calibration:
+	 * read efuse offset 0x7d to get a 17-bit data. Remove the

dummy/fake

Quoted 9 lines
Quoted 7 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+	 * bit (bit3) to rebuild the real 16-bit data. Write the data to the
+	 * ADC ioffset.
+	 */
+	ocp_data = r8152_efuse_read(tp, 0x7d);
+	data = (u16)(((ocp_data & 0x1fff0) >> 1) | (ocp_data & 0x7));

Are these type casts really needed ?

Is there not a warning from u32 to u16?

There is, but it seems justified to warn about conversion from u32 to u16, so maybe that needs to be fixed ?

Quoted 6 lines
Quoted 4 lines

Excuse me. I don't understand what you mean.
The original is 17-bit data, so I use u32 to store it. And, the final desired data is 16-bit. That is why
I have to convert it from u32 to u16.

So what happens to that bit 17 , is it dropped ?

I have descripted is in the code, such as following.

/* ADC Bias Calibration:
* read efuse offset 0x7d to get a 17-bit data. Remove the dummy/fake
* bit (bit3) to rebuild the real 16-bit data. Write the data to the
* ADC ioffset.
*/

Quoted 4 lines

The real data (16-bit) would be inserted a dummy bit, and store the 17-bit to efuse offset 0x7d. Therefore, when reading the 17-bit data from efuse, we have to remove the dummy to get the real data.

Ah, hmm, then let's use u32 type and be done with it. That solves the typecasts and is safe. Would that work ?

author
#20 lore raw

PATCH 4/4 eth/r8152: support RTL8153B/RTL8154B

Marek Vasut [mailto:marex at denx.de]

Quoted 1 line

Sent: Friday, June 12, 2020 8:05 AM

[...]

Quoted 7 lines
Quoted 4 lines

The real data (16-bit) would be inserted a dummy bit, and store the 17-bit to efuse offset 0x7d. Therefore, when reading the 17-bit data from efuse, we have to remove the dummy to get the real data.

Ah, hmm, then let's use u32 type and be done with it. That solves the typecasts and is safe. Would that work ?

The unit of PHY data is 2-byte, so I think I have to convert it.

void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data);

Best Regards,
Hayes

#21 lore raw

PATCH 4/4 eth/r8152: support RTL8153B/RTL8154B

Quoted 8 lines · Hayes Wang

Marek Vasut [mailto:marex at denx.de]

Quoted 1 line

Sent: Friday, June 12, 2020 8:05 AM

[...]

Quoted 5 lines
Quoted 4 lines

The real data (16-bit) would be inserted a dummy bit, and store the 17-bit to efuse offset 0x7d. Therefore, when reading the 17-bit data from efuse, we have to remove the dummy to get the real data.

Quoted 6 lines
Quoted 2 lines

Ah, hmm, then let's use u32 type and be done with it. That solves the typecasts and is safe. Would that work ?

The unit of PHY data is 2-byte, so I think I have to convert it.

void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data);

Try this:

	ocp_data = r8152_efuse_read(tp, 0x7d);
	ocp_data = (ocp_data & 0x1fff0) >> 1) | (ocp_data & 0x7);
	if (data != 0xffff)
		ocp_reg_write(tp, OCP_ADC_IOFFSET, data);

That should work, no ? Or does it generate compiler warnings ?

There should be some way to remove that cast I hope, the rest of the patch is OK.

author
#22 lore raw

PATCH 4/4 eth/r8152: support RTL8153B/RTL8154B

Marek Vasut [mailto:marex at denx.de]

Quoted 1 line

Sent: Friday, June 12, 2020 7:53 PM

[...]

Quoted 6 lines

Try this:

	ocp_data = r8152_efuse_read(tp, 0x7d);
	ocp_data = (ocp_data & 0x1fff0) >> 1) | (ocp_data & 0x7);
	if (data != 0xffff)
		ocp_reg_write(tp, OCP_ADC_IOFFSET, data);

I think you mean

	ocp_data = r8152_efuse_read(tp, 0x7d);
	ocp_data = ((ocp_data & 0x1fff0) >> 1) | (ocp_data & 0x7);
	if (ocp_data != 0xffff)
		ocp_reg_write(tp, OCP_ADC_IOFFSET, ocp_data);
Quoted 1 line

That should work, no ? Or does it generate compiler warnings ?

It shows no warning.

Best Regards,
Hayes

#23 lore raw

PATCH 4/4 eth/r8152: support RTL8153B/RTL8154B

Quoted 10 lines · Hayes Wang

Marek Vasut [mailto:marex at denx.de]

Quoted 1 line

Sent: Friday, June 12, 2020 7:53 PM

[...]

Quoted 6 lines

Try this:

	ocp_data = r8152_efuse_read(tp, 0x7d);
	ocp_data = (ocp_data & 0x1fff0) >> 1) | (ocp_data & 0x7);
	if (data != 0xffff)
		ocp_reg_write(tp, OCP_ADC_IOFFSET, data);
Quoted 6 lines

I think you mean

	ocp_data = r8152_efuse_read(tp, 0x7d);
	ocp_data = ((ocp_data & 0x1fff0) >> 1) | (ocp_data & 0x7);
	if (ocp_data != 0xffff)
		ocp_reg_write(tp, OCP_ADC_IOFFSET, ocp_data);

Yes

Quoted 3 lines
Quoted 1 line

That should work, no ? Or does it generate compiler warnings ?

It shows no warning.

Then lets do this ?