1*7453645fSAndriy Voskoboinyk /* $OpenBSD: if_urtwn.c,v 1.16 2011/02/10 17:26:40 jakemsr Exp $ */
2*7453645fSAndriy Voskoboinyk
3*7453645fSAndriy Voskoboinyk /*-
4*7453645fSAndriy Voskoboinyk * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
5*7453645fSAndriy Voskoboinyk * Copyright (c) 2014 Kevin Lo <kevlo@FreeBSD.org>
6*7453645fSAndriy Voskoboinyk * Copyright (c) 2015-2016 Andriy Voskoboinyk <avos@FreeBSD.org>
7*7453645fSAndriy Voskoboinyk *
8*7453645fSAndriy Voskoboinyk * Permission to use, copy, modify, and distribute this software for any
9*7453645fSAndriy Voskoboinyk * purpose with or without fee is hereby granted, provided that the above
10*7453645fSAndriy Voskoboinyk * copyright notice and this permission notice appear in all copies.
11*7453645fSAndriy Voskoboinyk *
12*7453645fSAndriy Voskoboinyk * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13*7453645fSAndriy Voskoboinyk * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14*7453645fSAndriy Voskoboinyk * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15*7453645fSAndriy Voskoboinyk * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16*7453645fSAndriy Voskoboinyk * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17*7453645fSAndriy Voskoboinyk * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18*7453645fSAndriy Voskoboinyk * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19*7453645fSAndriy Voskoboinyk */
20*7453645fSAndriy Voskoboinyk
21*7453645fSAndriy Voskoboinyk #include <sys/cdefs.h>
22*7453645fSAndriy Voskoboinyk #include "opt_wlan.h"
23*7453645fSAndriy Voskoboinyk
24*7453645fSAndriy Voskoboinyk #include <sys/param.h>
25*7453645fSAndriy Voskoboinyk #include <sys/lock.h>
26*7453645fSAndriy Voskoboinyk #include <sys/mutex.h>
27*7453645fSAndriy Voskoboinyk #include <sys/mbuf.h>
28*7453645fSAndriy Voskoboinyk #include <sys/kernel.h>
29*7453645fSAndriy Voskoboinyk #include <sys/socket.h>
30*7453645fSAndriy Voskoboinyk #include <sys/systm.h>
31*7453645fSAndriy Voskoboinyk #include <sys/malloc.h>
32*7453645fSAndriy Voskoboinyk #include <sys/queue.h>
33*7453645fSAndriy Voskoboinyk #include <sys/taskqueue.h>
34*7453645fSAndriy Voskoboinyk #include <sys/bus.h>
35*7453645fSAndriy Voskoboinyk #include <sys/endian.h>
36*7453645fSAndriy Voskoboinyk #include <sys/linker.h>
37*7453645fSAndriy Voskoboinyk
38*7453645fSAndriy Voskoboinyk #include <net/if.h>
39*7453645fSAndriy Voskoboinyk #include <net/ethernet.h>
40*7453645fSAndriy Voskoboinyk #include <net/if_media.h>
41*7453645fSAndriy Voskoboinyk
42*7453645fSAndriy Voskoboinyk #include <net80211/ieee80211_var.h>
43*7453645fSAndriy Voskoboinyk #include <net80211/ieee80211_radiotap.h>
44*7453645fSAndriy Voskoboinyk
45*7453645fSAndriy Voskoboinyk #include <dev/rtwn/if_rtwnreg.h>
46*7453645fSAndriy Voskoboinyk #include <dev/rtwn/if_rtwnvar.h>
47*7453645fSAndriy Voskoboinyk
48*7453645fSAndriy Voskoboinyk #include <dev/rtwn/rtl8192c/r92c.h>
49*7453645fSAndriy Voskoboinyk #include <dev/rtwn/rtl8192c/r92c_reg.h>
50*7453645fSAndriy Voskoboinyk #include <dev/rtwn/rtl8192c/r92c_var.h>
51*7453645fSAndriy Voskoboinyk #include <dev/rtwn/rtl8192c/r92c_rom_defs.h>
52*7453645fSAndriy Voskoboinyk
53*7453645fSAndriy Voskoboinyk uint32_t
r92c_rf_read(struct rtwn_softc * sc,int chain,uint8_t addr)54*7453645fSAndriy Voskoboinyk r92c_rf_read(struct rtwn_softc *sc, int chain, uint8_t addr)
55*7453645fSAndriy Voskoboinyk {
56*7453645fSAndriy Voskoboinyk struct r92c_softc *rs = sc->sc_priv;
57*7453645fSAndriy Voskoboinyk uint32_t reg[R92C_MAX_CHAINS], val;
58*7453645fSAndriy Voskoboinyk
59*7453645fSAndriy Voskoboinyk reg[0] = rtwn_bb_read(sc, R92C_HSSI_PARAM2(0));
60*7453645fSAndriy Voskoboinyk if (chain != 0)
61*7453645fSAndriy Voskoboinyk reg[chain] = rtwn_bb_read(sc, R92C_HSSI_PARAM2(chain));
62*7453645fSAndriy Voskoboinyk
63*7453645fSAndriy Voskoboinyk rtwn_bb_write(sc, R92C_HSSI_PARAM2(0),
64*7453645fSAndriy Voskoboinyk reg[0] & ~R92C_HSSI_PARAM2_READ_EDGE);
65*7453645fSAndriy Voskoboinyk rtwn_delay(sc, rs->rf_read_delay[0]);
66*7453645fSAndriy Voskoboinyk
67*7453645fSAndriy Voskoboinyk rtwn_bb_write(sc, R92C_HSSI_PARAM2(chain),
68*7453645fSAndriy Voskoboinyk RW(reg[chain], R92C_HSSI_PARAM2_READ_ADDR, addr) |
69*7453645fSAndriy Voskoboinyk R92C_HSSI_PARAM2_READ_EDGE);
70*7453645fSAndriy Voskoboinyk rtwn_delay(sc, rs->rf_read_delay[1]);
71*7453645fSAndriy Voskoboinyk
72*7453645fSAndriy Voskoboinyk rtwn_bb_write(sc, R92C_HSSI_PARAM2(0),
73*7453645fSAndriy Voskoboinyk reg[0] | R92C_HSSI_PARAM2_READ_EDGE);
74*7453645fSAndriy Voskoboinyk rtwn_delay(sc, rs->rf_read_delay[2]);
75*7453645fSAndriy Voskoboinyk
76*7453645fSAndriy Voskoboinyk if (rtwn_bb_read(sc, R92C_HSSI_PARAM1(chain)) & R92C_HSSI_PARAM1_PI)
77*7453645fSAndriy Voskoboinyk val = rtwn_bb_read(sc, R92C_HSPI_READBACK(chain));
78*7453645fSAndriy Voskoboinyk else
79*7453645fSAndriy Voskoboinyk val = rtwn_bb_read(sc, R92C_LSSI_READBACK(chain));
80*7453645fSAndriy Voskoboinyk return (MS(val, R92C_LSSI_READBACK_DATA));
81*7453645fSAndriy Voskoboinyk }
82*7453645fSAndriy Voskoboinyk
83*7453645fSAndriy Voskoboinyk void
r92c_rf_write(struct rtwn_softc * sc,int chain,uint8_t addr,uint32_t val)84*7453645fSAndriy Voskoboinyk r92c_rf_write(struct rtwn_softc *sc, int chain, uint8_t addr,
85*7453645fSAndriy Voskoboinyk uint32_t val)
86*7453645fSAndriy Voskoboinyk {
87*7453645fSAndriy Voskoboinyk rtwn_bb_write(sc, R92C_LSSI_PARAM(chain),
88*7453645fSAndriy Voskoboinyk SM(R92C_LSSI_PARAM_ADDR, addr) |
89*7453645fSAndriy Voskoboinyk SM(R92C_LSSI_PARAM_DATA, val));
90*7453645fSAndriy Voskoboinyk }
91