xref: /freebsd/sys/dev/rtwn/rtl8192c/r92c_llt.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
1*60b9567dSKevin Lo /*	$OpenBSD: if_urtwn.c,v 1.16 2011/02/10 17:26:40 jakemsr Exp $	*/
2*60b9567dSKevin Lo 
3*60b9567dSKevin Lo /*-
4*60b9567dSKevin Lo  * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
5*60b9567dSKevin Lo  * Copyright (c) 2014 Kevin Lo <kevlo@FreeBSD.org>
6*60b9567dSKevin Lo  * Copyright (c) 2015-2016 Andriy Voskoboinyk <avos@FreeBSD.org>
7*60b9567dSKevin Lo  *
8*60b9567dSKevin Lo  * Permission to use, copy, modify, and distribute this software for any
9*60b9567dSKevin Lo  * purpose with or without fee is hereby granted, provided that the above
10*60b9567dSKevin Lo  * copyright notice and this permission notice appear in all copies.
11*60b9567dSKevin Lo  *
12*60b9567dSKevin Lo  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13*60b9567dSKevin Lo  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14*60b9567dSKevin Lo  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15*60b9567dSKevin Lo  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16*60b9567dSKevin Lo  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17*60b9567dSKevin Lo  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18*60b9567dSKevin Lo  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19*60b9567dSKevin Lo  */
20*60b9567dSKevin Lo 
21*60b9567dSKevin Lo #include <sys/cdefs.h>
22*60b9567dSKevin Lo #include "opt_wlan.h"
23*60b9567dSKevin Lo 
24*60b9567dSKevin Lo #include <sys/param.h>
25*60b9567dSKevin Lo #include <sys/lock.h>
26*60b9567dSKevin Lo #include <sys/mutex.h>
27*60b9567dSKevin Lo #include <sys/mbuf.h>
28*60b9567dSKevin Lo #include <sys/kernel.h>
29*60b9567dSKevin Lo #include <sys/socket.h>
30*60b9567dSKevin Lo #include <sys/systm.h>
31*60b9567dSKevin Lo #include <sys/malloc.h>
32*60b9567dSKevin Lo #include <sys/queue.h>
33*60b9567dSKevin Lo #include <sys/taskqueue.h>
34*60b9567dSKevin Lo #include <sys/bus.h>
35*60b9567dSKevin Lo #include <sys/endian.h>
36*60b9567dSKevin Lo #include <sys/linker.h>
37*60b9567dSKevin Lo 
38*60b9567dSKevin Lo #include <net/if.h>
39*60b9567dSKevin Lo #include <net/ethernet.h>
40*60b9567dSKevin Lo #include <net/if_media.h>
41*60b9567dSKevin Lo 
42*60b9567dSKevin Lo #include <net80211/ieee80211_var.h>
43*60b9567dSKevin Lo #include <net80211/ieee80211_radiotap.h>
44*60b9567dSKevin Lo 
45*60b9567dSKevin Lo #include <dev/rtwn/if_rtwnreg.h>
46*60b9567dSKevin Lo #include <dev/rtwn/if_rtwnvar.h>
47*60b9567dSKevin Lo 
48*60b9567dSKevin Lo #include <dev/rtwn/rtl8192c/r92c.h>
49*60b9567dSKevin Lo #include <dev/rtwn/rtl8192c/r92c_reg.h>
50*60b9567dSKevin Lo #include <dev/rtwn/rtl8192c/r92c_var.h>
51*60b9567dSKevin Lo 
52*60b9567dSKevin Lo int
r92c_llt_write(struct rtwn_softc * sc,uint32_t addr,uint32_t data)53*60b9567dSKevin Lo r92c_llt_write(struct rtwn_softc *sc, uint32_t addr, uint32_t data)
54*60b9567dSKevin Lo {
55*60b9567dSKevin Lo 	int ntries, error;
56*60b9567dSKevin Lo 
57*60b9567dSKevin Lo 	error = rtwn_write_4(sc, R92C_LLT_INIT,
58*60b9567dSKevin Lo 	    SM(R92C_LLT_INIT_OP, R92C_LLT_INIT_OP_WRITE) |
59*60b9567dSKevin Lo 	    SM(R92C_LLT_INIT_ADDR, addr) |
60*60b9567dSKevin Lo 	    SM(R92C_LLT_INIT_DATA, data));
61*60b9567dSKevin Lo 	if (error != 0)
62*60b9567dSKevin Lo 		return (error);
63*60b9567dSKevin Lo 	/* Wait for write operation to complete. */
64*60b9567dSKevin Lo 	for (ntries = 0; ntries < 20; ntries++) {
65*60b9567dSKevin Lo 		if (MS(rtwn_read_4(sc, R92C_LLT_INIT), R92C_LLT_INIT_OP) ==
66*60b9567dSKevin Lo 		    R92C_LLT_INIT_OP_NO_ACTIVE)
67*60b9567dSKevin Lo 			return (0);
68*60b9567dSKevin Lo 		rtwn_delay(sc, 10);
69*60b9567dSKevin Lo 	}
70*60b9567dSKevin Lo 	return (ETIMEDOUT);
71*60b9567dSKevin Lo }
72