> Date: Sat, 7 Jul 2012 16:35:46 +0200
> From: Stefan Sperling <s...@openbsd.org>
> 
> rt2560 is selecting antennas before initialising the baseband
> processor (BBP), however initialising antennas involves tweaking
> of BBP registers.
> 
> The diff below (taken from dragonfly, written by sephe) ensures
> antennas are selected after the BBP has been initialised.
> 
> Part of this diff was committed in r1.26 of rt2560.c and subsequently
> backed out because it caused problems. Apparently the missing piece was
> a busy-wait loop before reading in rt2560_bbp_read(), which has since
> been added to dragonfly:
> 
>    commit dd8ea05f8d30bd38ecd334718e4263d8c56ce67a
>    Author: Sepherosa Ziehau <se...@dragonflybsd.org>
>    Date:   Thu Apr 12 12:54:07 2007 +0000
> 
>    When read BBP registers, avoid writing to BBPCSR until it is no longer 
> busy.
>    After this bug fixing, TX/RX antenna setup can be safely put after BBP
>    initialization, which is a correct place for it, since BBP initialization
>    will overwrite RX antenna BBP register with default value.  Before this bug
>    fixing, putting TX/RX antenna setup after BBP initailization always results
>    in strange TX/RX problems, which I experienced when I fiddled with my ASUS
>    WL-107G; and some OpenBSD folks had this problems too, before Damien 
> reverted
>    related changes in OpenBSD.
> 
> Tested with an RT2560 cardbus ral which still seems happy.
> 
> Any testers/oks?

ok kettenis@

> 
> Index: rt2560.c
> ===================================================================
> RCS file: /cvs/src/sys/dev/ic/rt2560.c,v
> retrieving revision 1.58
> diff -u -p -r1.58 rt2560.c
> --- rt2560.c  22 Feb 2011 20:05:03 -0000      1.58
> +++ rt2560.c  7 Jul 2012 14:23:42 -0000
> @@ -2102,6 +2102,16 @@ rt2560_bbp_read(struct rt2560_softc *sc,
>       uint32_t val;
>       int ntries;
>  
> +     for (ntries = 0; ntries < 100; ntries++) {
> +             if (!(RAL_READ(sc, RT2560_BBPCSR) & RT2560_BBP_BUSY))
> +                     break;
> +             DELAY(1);
> +     }
> +     if (ntries == 100) {
> +             printf("%s: could not read from BBP\n", sc->sc_dev.dv_xname);
> +             return 0;
> +     }
> +
>       val = RT2560_BBP_BUSY | reg << 8;
>       RAL_WRITE(sc, RT2560_BBPCSR, val);
>  
> @@ -2626,8 +2636,6 @@ rt2560_init(struct ifnet *ifp)
>       /* set basic rate set (will be updated later) */
>       RAL_WRITE(sc, RT2560_ARSP_PLCP_1, 0x153);
>  
> -     rt2560_set_txantenna(sc, 1);
> -     rt2560_set_rxantenna(sc, 1);
>       rt2560_set_slottime(sc);
>       rt2560_update_plcp(sc);
>       rt2560_update_led(sc, 0, 0);
> @@ -2639,6 +2647,9 @@ rt2560_init(struct ifnet *ifp)
>               rt2560_stop(ifp, 1);
>               return EIO;
>       }
> +
> +     rt2560_set_txantenna(sc, 1);
> +     rt2560_set_rxantenna(sc, 1);
>  
>       /* set default BSS channel */
>       ic->ic_bss->ni_chan = ic->ic_ibss_chan;

Reply via email to