]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
eth/r8152: modify rtl_clear_bp function
authorHayes Wang <hayeswang@realtek.com>
Tue, 16 Jun 2020 09:09:46 +0000 (17:09 +0800)
committerMarek Vasut <marex@denx.de>
Tue, 1 Sep 2020 12:47:36 +0000 (14:47 +0200)
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.

Besides, clear the firmware by writing the relative registers in
bulk.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
drivers/usb/eth/r8152.h
drivers/usb/eth/r8152_fw.c

index 4daf4ee87d7828b9aa5c649fc3f7ab469c40d846..710637d7a2133e457d4ef9e52eef21dc99e14652 100644 (file)
 #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
index f953b0384b88b2799e979700f602304e784656d4..2da1f221b4e0d9608a190aace5c45007fa61ebc3 100644 (file)
@@ -729,28 +729,30 @@ 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);
+       u8 zeros[16] = {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);
+       generic_ocp_write(tp, USB_BP(0), 0xff, sizeof(zeros), zeros, type);
 
-       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 +828,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 +849,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 +868,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 +887,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 +905,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 +935,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 +955,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 +991,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 +1002,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);