From patchwork Tue Jun 9 08:53:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hayes Wang X-Patchwork-Id: 241983 List-Id: U-Boot discussion From: hayeswang at realtek.com (Hayes Wang) Date: Tue, 9 Jun 2020 16:53:06 +0800 Subject: [PATCH u-boot 3/4] eth/r8152: modify rtl_clear_bp function In-Reply-To: <1394712342-15778-377-Taiwan-albertk@realtek.com> References: <1394712342-15778-377-Taiwan-albertk@realtek.com> Message-ID: <1394712342-15778-380-Taiwan-albertk@realtek.com> 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. Signed-off-by: Hayes Wang --- drivers/usb/eth/r8152.h | 20 ++++++------ drivers/usb/eth/r8152_fw.c | 63 +++++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 35 deletions(-) diff --git a/drivers/usb/eth/r8152.h b/drivers/usb/eth/r8152.h index 4daf4ee87d..ff4262d68d 100644 --- a/drivers/usb/eth/r8152.h +++ b/drivers/usb/eth/r8152.h @@ -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 diff --git a/drivers/usb/eth/r8152_fw.c b/drivers/usb/eth/r8152_fw.c index f953b0384b..5bcf785fc0 100644 --- a/drivers/usb/eth/r8152_fw.c +++ b/drivers/usb/eth/r8152_fw.c @@ -729,28 +729,35 @@ static u16 r8153_pla_patch_d_bp[] = { 0xfc2e, 0x0000, 0xfc30, 0x0000, 0xfc32, 0x0000, 0xfc34, 0x0000, 0xfc36, 0x0000, 0xfc38, 0x0007 }; -static void rtl_clear_bp(struct r8152 *tp) +static void rtl_clear_bp(struct r8152 *tp, u16 type) { - ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_0, 0); - ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_2, 0); - ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_4, 0); - ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_6, 0); - ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_0, 0); - ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_2, 0); - ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_4, 0); - ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_6, 0); + switch (tp->version) { + case RTL_VER_01: + case RTL_VER_02: + case RTL_VER_07: + break; + case RTL_VER_03: + case RTL_VER_04: + case RTL_VER_05: + case RTL_VER_06: + ocp_write_byte(tp, type, PLA_BP_EN, 0); + break; + default: + break; + } - mdelay(6); + ocp_write_word(tp, type, PLA_BP_0, 0); + ocp_write_word(tp, type, PLA_BP_1, 0); + ocp_write_word(tp, type, PLA_BP_2, 0); + ocp_write_word(tp, type, PLA_BP_3, 0); + ocp_write_word(tp, type, PLA_BP_4, 0); + ocp_write_word(tp, type, PLA_BP_5, 0); + ocp_write_word(tp, type, PLA_BP_6, 0); + ocp_write_word(tp, type, PLA_BP_7, 0); - ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_BA, 0); - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_BA, 0); -} + mdelay(6); -static void r8153_clear_bp(struct r8152 *tp) -{ - ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0); - ocp_write_byte(tp, MCU_TYPE_USB, USB_BP_EN, 0); - rtl_clear_bp(tp); + ocp_write_word(tp, type, PLA_BP_BA, 0); } static void r8152b_set_dq_desc(struct r8152 *tp) @@ -826,7 +833,7 @@ void r8152b_firmware(struct r8152 *tp) int i; r8152b_set_dq_desc(tp); - rtl_clear_bp(tp); + rtl_clear_bp(tp, MCU_TYPE_PLA); generic_ocp_write(tp, 0xf800, 0x3f, sizeof(r8152b_pla_patch_a), @@ -847,7 +854,7 @@ void r8152b_firmware(struct r8152 *tp) ocp_write_word(tp, MCU_TYPE_PLA, 0xb098, 0x0200); ocp_write_word(tp, MCU_TYPE_PLA, 0xb092, 0x7030); } else if (tp->version == RTL_VER_02) { - rtl_clear_bp(tp); + rtl_clear_bp(tp, MCU_TYPE_PLA); generic_ocp_write(tp, 0xf800, 0xff, sizeof(r8152b_pla_patch_a2), @@ -866,8 +873,6 @@ void r8153_firmware(struct r8152 *tp) int i; if (tp->version == RTL_VER_03) { - r8153_clear_bp(tp); - r8153_pre_ram_code(tp, 0x7000); for (i = 0; i < ARRAY_SIZE(r8153_ram_code_a); i += 2) @@ -887,7 +892,8 @@ void r8153_firmware(struct r8152 *tp) r8153_post_ram_code(tp); r8153_wdt1_end(tp); - r8153_clear_bp(tp); + + rtl_clear_bp(tp, MCU_TYPE_USB); ocp_write_word(tp, MCU_TYPE_USB, USB_BP_EN, 0x0000); generic_ocp_write(tp, 0xf800, 0xff, @@ -904,6 +910,8 @@ void r8153_firmware(struct r8152 *tp) ocp_write_word(tp, MCU_TYPE_PLA, 0xd38e, 0x0082); } + rtl_clear_bp(tp, MCU_TYPE_PLA); + ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_EN, 0x0000); generic_ocp_write(tp, 0xf800, 0xff, sizeof(r8153_pla_patch_b), @@ -932,7 +940,8 @@ void r8153_firmware(struct r8152 *tp) r8153_post_ram_code(tp); r8153_wdt1_end(tp); - r8153_clear_bp(tp); + + rtl_clear_bp(tp, MCU_TYPE_USB); ocp_write_word(tp, MCU_TYPE_USB, USB_BP_EN, 0x0000); generic_ocp_write(tp, 0xf800, 0xff, @@ -951,6 +960,8 @@ void r8153_firmware(struct r8152 *tp) ocp_write_word(tp, MCU_TYPE_USB, USB_BP_EN, 0x00ef); } + rtl_clear_bp(tp, MCU_TYPE_PLA); + ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_EN, 0x0000); generic_ocp_write(tp, 0xf800, 0xff, sizeof(r8153_pla_patch_c), @@ -985,7 +996,7 @@ void r8153_firmware(struct r8152 *tp) r8153_post_ram_code(tp); - r8153_clear_bp(tp); + rtl_clear_bp(tp, MCU_TYPE_USB); ocp_write_word(tp, MCU_TYPE_USB, USB_BP_EN, 0x0000); generic_ocp_write(tp, 0xf800, 0xff, sizeof(usb_patch_d), @@ -996,6 +1007,8 @@ void r8153_firmware(struct r8152 *tp) r8153_usb_patch_d_bp[i], r8153_usb_patch_d_bp[i+1]); + rtl_clear_bp(tp, MCU_TYPE_PLA); + ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_EN, 0x0000); generic_ocp_write(tp, 0xf800, 0xff, sizeof(pla_patch_d), pla_patch_d, MCU_TYPE_PLA);