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