1191762Simp/*
2191762Simp * Copyright (c) 2007 The DragonFly Project.  All rights reserved.
3191762Simp *
4191762Simp * This code is derived from software contributed to The DragonFly Project
5191762Simp * by Sepherosa Ziehau <sepherosa@gmail.com>
6191762Simp *
7191762Simp * Redistribution and use in source and binary forms, with or without
8191762Simp * modification, are permitted provided that the following conditions
9191762Simp * are met:
10191762Simp *
11191762Simp * 1. Redistributions of source code must retain the above copyright
12191762Simp *    notice, this list of conditions and the following disclaimer.
13191762Simp * 2. Redistributions in binary form must reproduce the above copyright
14191762Simp *    notice, this list of conditions and the following disclaimer in
15191762Simp *    the documentation and/or other materials provided with the
16191762Simp *    distribution.
17191762Simp * 3. Neither the name of The DragonFly Project nor the names of its
18191762Simp *    contributors may be used to endorse or promote products derived
19191762Simp *    from this software without specific, prior written permission.
20191762Simp *
21191762Simp * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22191762Simp * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23191762Simp * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24191762Simp * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25191762Simp * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26191762Simp * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27191762Simp * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28191762Simp * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29191762Simp * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30191762Simp * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31191762Simp * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32191762Simp * SUCH DAMAGE.
33191762Simp *
34191762Simp * $DragonFly: src/sys/dev/netif/bwi/bwirf.h,v 1.3 2007/10/03 04:53:19 sephe Exp $
35191762Simp * $FreeBSD: releng/10.2/sys/dev/bwi/bwirf.h 191762 2009-05-03 04:01:43Z imp $
36191762Simp */
37191762Simp
38191762Simp#ifndef _BWI_RF_H
39191762Simp#define _BWI_RF_H
40191762Simp
41191762Simpint		bwi_rf_attach(struct bwi_mac *);
42191762Simpvoid		bwi_rf_clear_state(struct bwi_rf *);
43191762Simp
44191762Simpint		bwi_rf_map_txpower(struct bwi_mac *);
45191762Simpvoid		bwi_rf_lo_adjust(struct bwi_mac *, const struct bwi_tpctl *);
46191762Simpvoid		bwi_rf_set_chan(struct bwi_mac *, u_int, int);
47191762Simpvoid		bwi_rf_get_gains(struct bwi_mac *);
48191762Simpvoid		bwi_rf_init(struct bwi_mac *);
49191762Simpvoid		bwi_rf_init_bcm2050(struct bwi_mac *);
50191762Simpvoid		bwi_rf_init_hw_nrssi_table(struct bwi_mac *, uint16_t);
51191762Simpvoid		bwi_rf_set_ant_mode(struct bwi_mac *, int);
52191762Simp
53191762Simpvoid		bwi_rf_clear_tssi(struct bwi_mac *);
54191762Simpint		bwi_rf_get_latest_tssi(struct bwi_mac *, int8_t[], uint16_t);
55191762Simpint		bwi_rf_tssi2dbm(struct bwi_mac *, int8_t, int8_t *);
56191762Simp
57191762Simpvoid		bwi_rf_write(struct bwi_mac *, uint16_t, uint16_t);
58191762Simpuint16_t	bwi_rf_read(struct bwi_mac *, uint16_t);
59191762Simp
60191762Simpstatic __inline void
61191762Simpbwi_rf_off(struct bwi_mac *_mac)
62191762Simp{
63191762Simp	_mac->mac_rf.rf_off(_mac);
64191762Simp	/* TODO:LED */
65191762Simp
66191762Simp	_mac->mac_rf.rf_flags &= ~BWI_RF_F_ON;
67191762Simp}
68191762Simp
69191762Simpstatic __inline void
70191762Simpbwi_rf_on(struct bwi_mac *_mac)
71191762Simp{
72191762Simp	if (_mac->mac_rf.rf_flags & BWI_RF_F_ON)
73191762Simp		return;
74191762Simp
75191762Simp	_mac->mac_rf.rf_on(_mac);
76191762Simp	/* TODO: LED */
77191762Simp
78191762Simp	_mac->mac_rf.rf_flags |= BWI_RF_F_ON;
79191762Simp}
80191762Simp
81191762Simpstatic __inline void
82191762Simpbwi_rf_calc_nrssi_slope(struct bwi_mac *_mac)
83191762Simp{
84191762Simp	_mac->mac_rf.rf_calc_nrssi_slope(_mac);
85191762Simp}
86191762Simp
87191762Simpstatic __inline void
88191762Simpbwi_rf_set_nrssi_thr(struct bwi_mac *_mac)
89191762Simp{
90191762Simp	_mac->mac_rf.rf_set_nrssi_thr(_mac);
91191762Simp}
92191762Simp
93191762Simpstatic __inline int
94191762Simpbwi_rf_calc_rssi(struct bwi_mac *_mac, const struct bwi_rxbuf_hdr *_hdr)
95191762Simp{
96191762Simp	return _mac->mac_rf.rf_calc_rssi(_mac, _hdr);
97191762Simp}
98191762Simp
99191762Simpstatic __inline int
100191762Simpbwi_rf_calc_noise(struct bwi_mac *_mac)
101191762Simp{
102191762Simp	return _mac->mac_rf.rf_calc_noise(_mac);
103191762Simp}
104191762Simp
105191762Simpstatic __inline void
106191762Simpbwi_rf_lo_update(struct bwi_mac *_mac)
107191762Simp{
108191762Simp	return _mac->mac_rf.rf_lo_update(_mac);
109191762Simp}
110191762Simp
111191762Simp#define RF_WRITE(mac, ofs, val)		bwi_rf_write((mac), (ofs), (val))
112191762Simp#define RF_READ(mac, ofs)		bwi_rf_read((mac), (ofs))
113191762Simp
114191762Simp#define RF_SETBITS(mac, ofs, bits)		\
115191762Simp	RF_WRITE((mac), (ofs), RF_READ((mac), (ofs)) | (bits))
116191762Simp#define RF_CLRBITS(mac, ofs, bits)		\
117191762Simp	RF_WRITE((mac), (ofs), RF_READ((mac), (ofs)) & ~(bits))
118191762Simp#define RF_FILT_SETBITS(mac, ofs, filt, bits)	\
119191762Simp	RF_WRITE((mac), (ofs), (RF_READ((mac), (ofs)) & (filt)) | (bits))
120191762Simp
121191762Simp#define BWI_RFR_ATTEN			0x43
122191762Simp
123191762Simp#define BWI_RFR_TXPWR			0x52
124191762Simp#define BWI_RFR_TXPWR1_MASK		__BITS(6, 4)
125191762Simp
126191762Simp#define BWI_RFR_BBP_ATTEN		0x60
127191762Simp#define BWI_RFR_BBP_ATTEN_CALIB_BIT	__BIT(0)
128191762Simp#define BWI_RFR_BBP_ATTEN_CALIB_IDX	__BITS(4, 1)
129191762Simp
130191762Simp/*
131191762Simp * TSSI -- TX power maps
132191762Simp */
133191762Simp/*
134191762Simp * http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table
135191762Simp * B PHY
136191762Simp */
137191762Simp#define BWI_TXPOWER_MAP_11B \
138191762Simp	0x4d,	0x4c,	0x4b,	0x4a,	0x4a,	0x49,	0x48,	0x47,	\
139191762Simp	0x47,	0x46,	0x45,	0x45,	0x44,	0x43,	0x42,	0x42,	\
140191762Simp	0x41,	0x40,	0x3f,	0x3e,	0x3d,	0x3c,	0x3b,	0x3a,	\
141191762Simp	0x39,	0x38,	0x37,	0x36,	0x35,	0x34,	0x32,	0x31,	\
142191762Simp	0x30,	0x2f,	0x2d,	0x2c,	0x2b,	0x29,	0x28,	0x26,	\
143191762Simp	0x25,	0x23,	0x21,	0x1f,	0x1d,	0x1a,	0x17,	0x14,	\
144191762Simp	0x10,	0x0c,	0x06,	0x00,	-7,	-7,	-7,	-7, 	\
145191762Simp	-7,	-7,	-7,	-7,	-7,	-7,	-7,	-7
146191762Simp/*
147191762Simp * http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table
148191762Simp * G PHY
149191762Simp */
150191762Simp#define BWI_TXPOWER_MAP_11G \
151191762Simp	77,	77,	77,	76,	76,	76,	75,	75,	\
152191762Simp	74,	74,	73,	73,	73,	72,	72,	71,	\
153191762Simp	71,	70,	70,	69,	68,	68,	67,	67,	\
154191762Simp	66,	65,	65,	64,	63,	63,	62,	61,	\
155191762Simp	60,	59,	58,	57,	56,	55,	54,	53,	\
156191762Simp	52,	50,	49,	47,	45,	43,	40,	37,	\
157191762Simp	33,	28,	22,	14,	5,	-7,	-20,	-20,	\
158191762Simp	-20,	-20,	-20,	-20,	-20,	-20,	-20,	-20
159191762Simp
160191762Simp#endif	/* !_BWI_RF_H */
161