r8152: support more chips
v2 cover r8152: support more chips
v2:
For patch #1, replace u32 with u8 for rtl_reset_bmu().
For patch #3, use USB_BP(n) to replace USB_BP_0 ~ USB_BP_7. Write the registers in bulk for rtl_clear_bp().
For patch #4, add a macro for the magic value. Remove type casts. Write the register in bulk, if it is possible. Reduce indent.
v1:
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
PATCH v2 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
@@ -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) +{ +u8 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
@@ -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
Marek Vasut
AppliedPATCH v2 1/4 eth/r8152: reset bmu after disabling Tx/Rx
Quoted 5 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.
Signed-off-by Hayes Wang <[email protected]>
Applied all to next, thanks!
PATCH v2 2/4 eth/r8152: reset PHY after setting it
In reply to Hayes WangSome 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
@@ -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
PATCH v2 3/4 eth/r8152: modify rtl_clear_bp function
In reply to Hayes WangThe 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.
Besides, clear the firmware by writing the relative registers in bulk.
--- drivers/usb/eth/r8152.h | 13 ++------- drivers/usb/eth/r8152_fw.c | 58 ++++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 35 deletions(-)
drivers/usb/eth/r8152.h +3 -10
@@ -95,16 +95,9 @@#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 (n) (0xfc28 + 2 * (n)) +#define USB_BP_EN PLA_BP_EN/* OCP Registers */ #define OCP_ALDPS_CONFIG 0x2010
drivers/usb/eth/r8152_fw.c +33 -25
122 lines not on this page · raw message
Signature · 1 line
2.21.1
PATCH v2 4/4 eth/r8152: support RTL8153B/RTL8154B
In reply to Hayes WangThis is used to support RTL8153B and RTL8154B.
--- drivers/usb/eth/r8152.c | 207 ++++++++++++++++++++++++++++++++++++- drivers/usb/eth/r8152.h | 41 +++++++- drivers/usb/eth/r8152_fw.c | 170 ++++++++++++++++++++++++++++++ 3 files changed, 414 insertions(+), 4 deletions(-)
drivers/usb/eth/r8152.c +205 -2
@@ -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 , +RX_AUXILIARY_TIMER /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) +{ +u16 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 ); + ocp_data = ((ocp_data &0x1fff0 ) >>1 ) | (ocp_data &0x7 ); +if (ocp_data !=0xffff ) +ocp_reg_write (tp,OCP_ADC_IOFFSET , ocp_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 +39 -2
147 lines not on this page · raw message
drivers/usb/eth/r8152_fw.c +170 -0
186 lines not on this page · raw message
Signature · 1 line
2.21.1