Message ID | 1394712342-15778-378-Taiwan-albertk@realtek.com |
---|---|
State | Superseded |
Headers | show |
Series | r8152: support more chips | expand |
On 6/9/20 10:53 AM, Hayes Wang wrote: > 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. > > Signed-off-by: Hayes Wang <hayeswang at realtek.com> > --- > drivers/usb/eth/r8152.c | 14 ++++++++++++++ > drivers/usb/eth/r8152.h | 7 ++++++- > 2 files changed, 20 insertions(+), 1 deletion(-) > > diff --git a/drivers/usb/eth/r8152.c b/drivers/usb/eth/r8152.c > index f201a1789b..dbb1721882 100644 > --- a/drivers/usb/eth/r8152.c > +++ b/drivers/usb/eth/r8152.c > @@ -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 ?
Marek Vasut [mailto:marex at denx.de] > Sent: Tuesday, June 09, 2020 10:21 PM [...] > > +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
On 6/10/20 11:27 AM, Hayes Wang wrote: > Marek Vasut [mailto:marex at denx.de] >> Sent: Tuesday, June 09, 2020 10:21 PM > [...] >>> +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. 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?
Marek Vasut [mailto:marex at denx.de] > Sent: Wednesday, June 10, 2020 7:05 PM [...] > >>> +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. > > 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
diff --git a/drivers/usb/eth/r8152.c b/drivers/usb/eth/r8152.c index f201a1789b..dbb1721882 100644 --- a/drivers/usb/eth/r8152.c +++ b/drivers/usb/eth/r8152.c @@ -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) diff --git a/drivers/usb/eth/r8152.h b/drivers/usb/eth/r8152.h index 10e0da8eb1..4daf4ee87d 100644 --- a/drivers/usb/eth/r8152.h +++ b/drivers/usb/eth/r8152.h @@ -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
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. Signed-off-by: Hayes Wang <hayeswang at realtek.com> --- drivers/usb/eth/r8152.c | 14 ++++++++++++++ drivers/usb/eth/r8152.h | 7 ++++++- 2 files changed, 20 insertions(+), 1 deletion(-)