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) 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 __FBSDID("$FreeBSD$"); 23 24 #include "opt_wlan.h" 25 26 #include <sys/param.h> 27 #include <sys/lock.h> 28 #include <sys/mutex.h> 29 #include <sys/mbuf.h> 30 #include <sys/kernel.h> 31 #include <sys/socket.h> 32 #include <sys/systm.h> 33 #include <sys/malloc.h> 34 #include <sys/queue.h> 35 #include <sys/taskqueue.h> 36 #include <sys/bus.h> 37 #include <sys/endian.h> 38 #include <sys/linker.h> 39 40 #include <net/if.h> 41 #include <net/ethernet.h> 42 #include <net/if_media.h> 43 44 #include <net80211/ieee80211_var.h> 45 #include <net80211/ieee80211_radiotap.h> 46 47 #include <dev/rtwn/if_rtwnreg.h> 48 #include <dev/rtwn/if_rtwnvar.h> 49 50 #include <dev/rtwn/rtl8192c/r92c.h> 51 #include <dev/rtwn/rtl8192c/r92c_reg.h> 52 53 54 void 55 r92c_iq_calib(struct rtwn_softc *sc) 56 { 57 /* XXX TODO */ 58 } 59 60 void 61 r92c_lc_calib(struct rtwn_softc *sc) 62 { 63 uint32_t rf_ac[2]; 64 uint8_t txmode; 65 int i; 66 67 txmode = rtwn_read_1(sc, R92C_OFDM1_LSTF + 3); 68 if ((txmode & 0x70) != 0) { 69 /* Disable all continuous Tx. */ 70 rtwn_write_1(sc, R92C_OFDM1_LSTF + 3, txmode & ~0x70); 71 72 /* Set RF mode to standby mode. */ 73 for (i = 0; i < sc->nrxchains; i++) { 74 rf_ac[i] = rtwn_rf_read(sc, i, R92C_RF_AC); 75 rtwn_rf_write(sc, i, R92C_RF_AC, 76 RW(rf_ac[i], R92C_RF_AC_MODE, 77 R92C_RF_AC_MODE_STANDBY)); 78 } 79 } else { 80 /* Block all Tx queues. */ 81 rtwn_write_1(sc, R92C_TXPAUSE, R92C_TX_QUEUE_ALL); 82 } 83 /* Start calibration. */ 84 rtwn_rf_setbits(sc, 0, R92C_RF_CHNLBW, 0, R92C_RF_CHNLBW_LCSTART); 85 86 /* Give calibration the time to complete. */ 87 rtwn_delay(sc, 100000); /* 100ms */ 88 89 /* Restore configuration. */ 90 if ((txmode & 0x70) != 0) { 91 /* Restore Tx mode. */ 92 rtwn_write_1(sc, R92C_OFDM1_LSTF + 3, txmode); 93 /* Restore RF mode. */ 94 for (i = 0; i < sc->nrxchains; i++) 95 rtwn_rf_write(sc, i, R92C_RF_AC, rf_ac[i]); 96 } else { 97 /* Unblock all Tx queues. */ 98 rtwn_write_1(sc, R92C_TXPAUSE, 0x00); 99 } 100 } 101 102 void 103 r92c_temp_measure(struct rtwn_softc *sc) 104 { 105 rtwn_rf_write(sc, 0, R92C_RF_T_METER, R92C_RF_T_METER_START); 106 } 107 108 uint8_t 109 r92c_temp_read(struct rtwn_softc *sc) 110 { 111 return (MS(rtwn_rf_read(sc, 0, R92C_RF_T_METER), 112 R92C_RF_T_METER_VAL)); 113 } 114