Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src-draft/trunk]: src/sys/dev/usb Reduce gratious changes to -current, espec...



details:   https://anonhg.NetBSD.org/src-all/rev/7a8cc463bc27
branches:  trunk
changeset: 371100:7a8cc463bc27
user:      Martin Husemann <martin%NetBSD.org@localhost>
date:      Sat Jan 15 20:30:15 2022 +0100

description:
Reduce gratious changes to -current, especially sync delays

diffstat:

 sys/dev/usb/if_urtwn.c |  89 ++++++++++++++++++-------------------------------
 1 files changed, 33 insertions(+), 56 deletions(-)

diffs (truncated from 338 to 300 lines):

diff -r c7817c8f77e9 -r 7a8cc463bc27 sys/dev/usb/if_urtwn.c
--- a/sys/dev/usb/if_urtwn.c    Tue Dec 14 21:21:08 2021 +0100
+++ b/sys/dev/usb/if_urtwn.c    Sat Jan 15 20:30:15 2022 +0100
@@ -247,7 +247,6 @@
 static void    urtwn_write_1(struct urtwn_softc *, uint16_t, uint8_t);
 static void    urtwn_write_2(struct urtwn_softc *, uint16_t, uint16_t);
 static void    urtwn_write_4(struct urtwn_softc *, uint16_t, uint32_t);
-static void    urtwn_bb_write(struct urtwn_softc *, uint16_t, uint32_t);
 static int     urtwn_write_region(struct urtwn_softc *, uint16_t, uint8_t *,
                    int);
 static int     urtwn_read_region_1(struct urtwn_softc *, uint16_t, uint8_t *,
@@ -334,6 +333,7 @@
 static void    urtwn_update_mcast(struct ieee80211com *);
 
 /* Aliases. */
+#define        urtwn_bb_write  urtwn_write_4
 #define        urtwn_bb_read   urtwn_read_4
 
 #define urtwn_lookup(d,v,p)    ((const struct urtwn_dev *)usb_lookup(d,v,p))
@@ -749,13 +749,6 @@
                tsleep(&sc->cmdq, 0, "endtask", 0);
 }
 
-static void
-urtwn_bb_write(struct urtwn_softc *sc, uint16_t addr, uint32_t val)
-{
-       urtwn_write_4(sc, addr, val);
-       DELAY(1);
-}
-
 static int
 urtwn_write_region_1(struct urtwn_softc *sc, uint16_t addr, uint8_t *buf,
     int len)
@@ -775,7 +768,6 @@
                DPRINTFN(DBG_REG, ("%s: %s: error=%d: addr=%#x, len=%d\n",
                    device_xname(sc->sc_uw.uw_dev), __func__, error, addr, len));
        }
-       DELAY(1);
        return error;
 }
 
@@ -847,7 +839,6 @@
                DPRINTFN(DBG_REG, ("%s: %s: error=%d: addr=%#x, len=%d\n",
                    device_xname(sc->sc_uw.uw_dev), __func__, error, addr, len));
        }
-       DELAY(1);
        return error;
 }
 
@@ -965,7 +956,6 @@
 
        urtwn_bb_write(sc, R92C_LSSI_PARAM(chain),
            SM(R92C_LSSI_PARAM_ADDR, addr) | SM(R92C_LSSI_PARAM_DATA, val));
-       urtwn_delay_ms(sc, 1);
 }
 
 static void
@@ -975,7 +965,6 @@
 
        urtwn_bb_write(sc, R92C_LSSI_PARAM(chain),
            SM(R88E_LSSI_PARAM_ADDR, addr) | SM(R92C_LSSI_PARAM_DATA, val));
-       urtwn_delay_ms(sc, 1);
 }
 
 static void
@@ -985,7 +974,6 @@
 
        urtwn_bb_write(sc, R92C_LSSI_PARAM(chain),
            SM(R88E_LSSI_PARAM_ADDR, addr) | SM(R92C_LSSI_PARAM_DATA, val));
-       urtwn_delay_ms(sc, 1);
 }
 
 static uint32_t
@@ -1282,7 +1270,6 @@
            sc->board_type, sc->regulatory));
 
        IEEE80211_ADDR_COPY(ic->ic_macaddr, rom->macaddr);
-
        sc->sc_rf_write = urtwn_r92c_rf_write;
        sc->sc_power_on = urtwn_r92c_power_on;
        sc->sc_dma_init = urtwn_r92c_dma_init;
@@ -1589,7 +1576,6 @@
                }
                sc->ledlink = on;       /* Save LED state. */
        }
-       urtwn_delay_ms(sc, 1);
 }
 
 static void
@@ -3143,11 +3129,10 @@
            R92C_APS_FSMCO_PDN_EN |
            R92C_APS_FSMCO_PFM_ALDN);
 
-       if (urtwn_read_4(sc, R92E_SYS_CFG1_8192E) & R92E_SPSLDO_SEL){
+       if (urtwn_read_4(sc, R92E_SYS_CFG1_8192E) & R92E_SPSLDO_SEL) {
                /* LDO. */
                urtwn_write_1(sc, R92E_LDO_SWR_CTRL, 0xc3);
-       }
-       else    {
+       } else {
                urtwn_write_2(sc, R92C_SYS_SWR_CTRL2, urtwn_read_2(sc,
                    R92C_SYS_SWR_CTRL2) & 0xffff);
                urtwn_write_1(sc, R92E_LDO_SWR_CTRL, 0x83);
@@ -3156,37 +3141,37 @@
        for (ntries = 0; ntries < 2; ntries++) {
                urtwn_write_1(sc, R92C_AFE_PLL_CTRL,
                    urtwn_read_1(sc, R92C_AFE_PLL_CTRL));
-               urtwn_write_2(sc, R92C_AFE_CTRL4, urtwn_read_2(sc,
-                   R92C_AFE_CTRL4));
+               urtwn_write_2(sc, R92C_AFE_CTRL4,
+                   urtwn_read_2(sc, R92C_AFE_CTRL4));
        }
 
        /* Reset BB. */
        urtwn_write_1(sc, R92C_SYS_FUNC_EN,
-       urtwn_read_1(sc, R92C_SYS_FUNC_EN) & ~(R92C_SYS_FUNC_EN_BBRSTB |
-           R92C_SYS_FUNC_EN_BB_GLB_RST));
+           urtwn_read_1(sc, R92C_SYS_FUNC_EN) & ~(R92C_SYS_FUNC_EN_BBRSTB |
+               R92C_SYS_FUNC_EN_BB_GLB_RST));
 
        urtwn_write_1(sc, R92C_AFE_XTAL_CTRL + 2, urtwn_read_1(sc,
            R92C_AFE_XTAL_CTRL + 2) | 0x80);
 
        /* Disable HWPDN. */
-       urtwn_write_2(sc, R92C_APS_FSMCO, urtwn_read_2(sc,
-           R92C_APS_FSMCO) & ~R92C_APS_FSMCO_APDM_HPDN);
+       urtwn_write_2(sc, R92C_APS_FSMCO,
+           urtwn_read_2(sc, R92C_APS_FSMCO) & ~R92C_APS_FSMCO_APDM_HPDN);
 
        /* Disable WL suspend. */
-       urtwn_write_2(sc, R92C_APS_FSMCO, urtwn_read_2(sc,
-           R92C_APS_FSMCO) & ~(R92C_APS_FSMCO_AFSM_PCIE |
-           R92C_APS_FSMCO_AFSM_HSUS));
-
-       urtwn_write_4(sc, R92C_APS_FSMCO, urtwn_read_4(sc,
-           R92C_APS_FSMCO) | R92C_APS_FSMCO_RDY_MACON);
-       urtwn_write_2(sc, R92C_APS_FSMCO, urtwn_read_2(sc,
-           R92C_APS_FSMCO) | R92C_APS_FSMCO_APFM_ONMAC);
+       urtwn_write_2(sc, R92C_APS_FSMCO,
+           urtwn_read_2(sc, R92C_APS_FSMCO) & ~(R92C_APS_FSMCO_AFSM_PCIE |
+               R92C_APS_FSMCO_AFSM_HSUS));
+
+       urtwn_write_4(sc, R92C_APS_FSMCO,
+           urtwn_read_4(sc, R92C_APS_FSMCO) | R92C_APS_FSMCO_RDY_MACON);
+       urtwn_write_2(sc, R92C_APS_FSMCO,
+           urtwn_read_2(sc, R92C_APS_FSMCO) | R92C_APS_FSMCO_APFM_ONMAC);
        for (ntries = 0; ntries < 10000; ntries++) {
                val = urtwn_read_2(sc, R92C_APS_FSMCO) &
-                R92C_APS_FSMCO_APFM_ONMAC;
+                   R92C_APS_FSMCO_APFM_ONMAC;
                if (val == 0x0)
                        break;
-               DELAY(10);
+               DELAY(260);
        }
        if (ntries == 10000) {
                aprint_error_dev(sc->sc_uw.uw_dev,
@@ -3201,6 +3186,10 @@
            R92C_CR_SCHEDULE_EN | R92C_CR_ENSEC;
        urtwn_write_2(sc, R92C_CR, reg);
 
+       urtwn_write_1(sc, 0xfe10, 0x19);
+
+       urtwn_delay_ms(sc, 1);
+
        return 0;
 }
 
@@ -3344,7 +3333,6 @@
        /* Force 8051 reset. */
        urtwn_write_2(sc, R92C_SYS_FUNC_EN,
            urtwn_read_2(sc, R92C_SYS_FUNC_EN) & ~R92C_SYS_FUNC_EN_CPUEN);
-       urtwn_delay_ms(sc, 10);
 }
 
 static void
@@ -3359,24 +3347,24 @@
        if (ISSET(sc->chip, URTWN_CHIP_92EU)) {
                reg = urtwn_read_2(sc, R92C_RSV_CTRL) & ~R92E_RSV_MIO_EN;
                urtwn_write_2(sc,R92C_RSV_CTRL, reg);
+               DELAY(50);
        }
-       DELAY(200);
 
        reg = urtwn_read_2(sc, R92C_SYS_FUNC_EN);
        urtwn_write_2(sc, R92C_SYS_FUNC_EN, reg & ~R92C_SYS_FUNC_EN_CPUEN);
        DELAY(50);
 
        urtwn_write_2(sc, R92C_SYS_FUNC_EN, reg | R92C_SYS_FUNC_EN_CPUEN);
-       DELAY(200);
+       DELAY(50);
 
        if (ISSET(sc->chip, URTWN_CHIP_92EU)) {
                reg = urtwn_read_2(sc, R92C_RSV_CTRL) | R92E_RSV_MIO_EN;
                urtwn_write_2(sc,R92C_RSV_CTRL, reg);
+               DELAY(50);
        }
+
        /* Init firmware commands ring. */
        sc->fwcur = 0;
-       urtwn_delay_ms(sc, 10);
-
 }
 
 static int
@@ -3496,7 +3484,7 @@
 
        /* Reset the FWDL checksum. */
        urtwn_write_1(sc, R92C_MCUFWDL,
-       urtwn_read_1(sc, R92C_MCUFWDL) | R92C_MCUFWDL_CHKSUM_RPT);
+           urtwn_read_1(sc, R92C_MCUFWDL) | R92C_MCUFWDL_CHKSUM_RPT);
 
        DELAY(50);
        /* download firmware */
@@ -3537,8 +3525,6 @@
        if (ISSET(sc->chip, URTWN_CHIP_88E) ||
            ISSET(sc->chip, URTWN_CHIP_92EU))
                urtwn_r88e_fw_reset(sc);
-       else
-               urtwn_fw_reset(sc);
        for (ntries = 0; ntries < 6000; ntries++) {
                if (urtwn_read_4(sc, R92C_MCUFWDL) & R92C_MCUFWDL_WINTINI_RDY)
                        break;
@@ -3550,7 +3536,7 @@
                error = ETIMEDOUT;
                goto fail;
        }
-       urtwn_delay_ms(sc, 10);
+
  fail:
        firmware_free(fw, fwlen);
        return error;
@@ -3812,6 +3798,7 @@
                        break;
                }
                urtwn_bb_write(sc, prog->regs[i], prog->vals[i]);
+               DELAY(1);
        }
 
        if (sc->chip & URTWN_CHIP_92C_1T2R) {
@@ -3856,12 +3843,15 @@
        /* Write AGC values. */
        for (i = 0; i < prog->agccount; i++) {
                urtwn_bb_write(sc, R92C_OFDM0_AGCRSSITABLE, prog->agcvals[i]);
+               DELAY(1);
        }
 
        if (ISSET(sc->chip, URTWN_CHIP_88E) ||
            ISSET(sc->chip, URTWN_CHIP_92EU)) {
                urtwn_bb_write(sc, R92C_OFDM0_AGCCORE1(0), 0x69553422);
+               DELAY(1);
                urtwn_bb_write(sc, R92C_OFDM0_AGCCORE1(0), 0x69553420);
+               DELAY(1);
        }
 
        if (ISSET(sc->chip, URTWN_CHIP_92EU)) {
@@ -3873,7 +3863,6 @@
                urtwn_bb_write(sc, R92C_AFE_CTRL3,
                    RW(reg, R92C_AFE_XTAL_CTRL_ADDR,
                    crystalcap | crystalcap << 6));
-               urtwn_delay_ms(sc, 1);
                urtwn_write_4(sc, R92C_AFE_XTAL_CTRL, 0xf81fb);
        } else if (ISSET(sc->chip, URTWN_CHIP_88E)) {
                crystalcap = sc->r88e_rom[0xb9];
@@ -3890,7 +3879,6 @@
                        SET(sc->sc_uw.uw_flags, URTWN_FLAG_CCK_HIPWR);
                }
        }
-       urtwn_delay_ms(sc, 1);
 }
 
 static void __noinline
@@ -3965,7 +3953,6 @@
                /* Restore RF_ENV control type. */
                reg = urtwn_bb_read(sc, R92C_FPGA0_RFIFACESW(idx)) & ~mask;
                urtwn_bb_write(sc, R92C_FPGA0_RFIFACESW(idx), reg | saved);
-               urtwn_delay_ms(sc, 1);
        }
 
        if ((sc->chip & (URTWN_CHIP_UMC_A_CUT | URTWN_CHIP_92C)) ==
@@ -4399,7 +4386,6 @@
        for (i = 0; i < sc->nrxchains; i++) {
                urtwn_rf_write(sc, i, R92C_RF_CHNLBW,
                    RW(sc->rf_chnlbw[i], R92C_RF_CHNLBW_CHNL, chan));
-               urtwn_delay_ms(sc, 1);
        }
 
        if (ht40m) {
@@ -4462,7 +4448,6 @@
                     ISSET(sc->chip, URTWN_CHIP_92EU) ?
                      R88E_RF_CHNLBW_BW20 : R92C_RF_CHNLBW_BW20));
        }
-       urtwn_delay_ms(sc, 1);
 }
 
 static void __noinline
@@ -4522,11 +4507,9 @@
                urtwn_bb_write(sc, R92C_HSSI_PARAM1(0),
                    urtwn_bb_read(sc, R92C_HSSI_PARAM1(0))|
                    R92C_HSSI_PARAM1_PI);



Home | Main Index | Thread Index | Old Index