xref: /linux/drivers/net/wireless/broadcom/b43legacy/phy.h (revision 58e16d792a6a8c6b750f637a4649967fcac853dc)
1*ca47d344SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2423e3ce3SKalle Valo /*
3423e3ce3SKalle Valo 
4423e3ce3SKalle Valo   Broadcom B43legacy wireless driver
5423e3ce3SKalle Valo 
6423e3ce3SKalle Valo   Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
7423e3ce3SKalle Valo 		     Stefano Brivio <stefano.brivio@polimi.it>
8423e3ce3SKalle Valo 		     Michael Buesch <m@bues.ch>
9423e3ce3SKalle Valo 		     Danny van Dyk <kugelfang@gentoo.org>
10423e3ce3SKalle Valo 		     Andreas Jaggi <andreas.jaggi@waterwave.ch>
11423e3ce3SKalle Valo   Copyright (c) 2007 Larry Finger <Larry.Finger@lwfinger.net>
12423e3ce3SKalle Valo 
13423e3ce3SKalle Valo   Some parts of the code in this file are derived from the ipw2200
14423e3ce3SKalle Valo   driver  Copyright(c) 2003 - 2004 Intel Corporation.
15423e3ce3SKalle Valo 
16423e3ce3SKalle Valo 
17423e3ce3SKalle Valo */
18423e3ce3SKalle Valo 
19423e3ce3SKalle Valo #ifndef B43legacy_PHY_H_
20423e3ce3SKalle Valo #define B43legacy_PHY_H_
21423e3ce3SKalle Valo 
22423e3ce3SKalle Valo #include <linux/types.h>
23423e3ce3SKalle Valo 
24423e3ce3SKalle Valo enum {
25423e3ce3SKalle Valo 	B43legacy_ANTENNA0,	  /* Antenna 0 */
26423e3ce3SKalle Valo 	B43legacy_ANTENNA1,	  /* Antenna 0 */
27423e3ce3SKalle Valo 	B43legacy_ANTENNA_AUTO1,  /* Automatic, starting with antenna 1 */
28423e3ce3SKalle Valo 	B43legacy_ANTENNA_AUTO0,  /* Automatic, starting with antenna 0 */
29423e3ce3SKalle Valo 
30423e3ce3SKalle Valo 	B43legacy_ANTENNA_AUTO	= B43legacy_ANTENNA_AUTO0,
31423e3ce3SKalle Valo 	B43legacy_ANTENNA_DEFAULT = B43legacy_ANTENNA_AUTO,
32423e3ce3SKalle Valo };
33423e3ce3SKalle Valo 
34423e3ce3SKalle Valo enum {
35423e3ce3SKalle Valo 	B43legacy_INTERFMODE_NONE,
36423e3ce3SKalle Valo 	B43legacy_INTERFMODE_NONWLAN,
37423e3ce3SKalle Valo 	B43legacy_INTERFMODE_MANUALWLAN,
38423e3ce3SKalle Valo 	B43legacy_INTERFMODE_AUTOWLAN,
39423e3ce3SKalle Valo };
40423e3ce3SKalle Valo 
41423e3ce3SKalle Valo /*** PHY Registers ***/
42423e3ce3SKalle Valo 
43423e3ce3SKalle Valo /* Routing */
44423e3ce3SKalle Valo #define B43legacy_PHYROUTE_OFDM_GPHY	0x400
45423e3ce3SKalle Valo #define B43legacy_PHYROUTE_EXT_GPHY	0x800
46423e3ce3SKalle Valo 
47423e3ce3SKalle Valo /* Base registers. */
48423e3ce3SKalle Valo #define B43legacy_PHY_BASE(reg)	(reg)
49423e3ce3SKalle Valo /* OFDM (A) registers of a G-PHY */
50423e3ce3SKalle Valo #define B43legacy_PHY_OFDM(reg)	((reg) | B43legacy_PHYROUTE_OFDM_GPHY)
51423e3ce3SKalle Valo /* Extended G-PHY registers */
52423e3ce3SKalle Valo #define B43legacy_PHY_EXTG(reg)	((reg) | B43legacy_PHYROUTE_EXT_GPHY)
53423e3ce3SKalle Valo 
54423e3ce3SKalle Valo 
55423e3ce3SKalle Valo /* Extended G-PHY Registers */
56423e3ce3SKalle Valo #define B43legacy_PHY_CLASSCTL		B43legacy_PHY_EXTG(0x02)	/* Classify control */
57423e3ce3SKalle Valo #define B43legacy_PHY_GTABCTL		B43legacy_PHY_EXTG(0x03)	/* G-PHY table control (see below) */
58423e3ce3SKalle Valo #define  B43legacy_PHY_GTABOFF		0x03FF			/* G-PHY table offset (see below) */
59423e3ce3SKalle Valo #define  B43legacy_PHY_GTABNR		0xFC00			/* G-PHY table number (see below) */
60423e3ce3SKalle Valo #define  B43legacy_PHY_GTABNR_SHIFT	10
61423e3ce3SKalle Valo #define B43legacy_PHY_GTABDATA		B43legacy_PHY_EXTG(0x04)	/* G-PHY table data */
62423e3ce3SKalle Valo #define B43legacy_PHY_LO_MASK		B43legacy_PHY_EXTG(0x0F)	/* Local Oscillator control mask */
63423e3ce3SKalle Valo #define B43legacy_PHY_LO_CTL		B43legacy_PHY_EXTG(0x10)	/* Local Oscillator control */
64423e3ce3SKalle Valo #define B43legacy_PHY_RFOVER		B43legacy_PHY_EXTG(0x11)	/* RF override */
65423e3ce3SKalle Valo #define B43legacy_PHY_RFOVERVAL		B43legacy_PHY_EXTG(0x12)	/* RF override value */
66423e3ce3SKalle Valo /*** OFDM table numbers ***/
67423e3ce3SKalle Valo #define B43legacy_OFDMTAB(number, offset)				\
68423e3ce3SKalle Valo 			  (((number) << B43legacy_PHY_OTABLENR_SHIFT)	\
69423e3ce3SKalle Valo 			  | (offset))
70423e3ce3SKalle Valo #define B43legacy_OFDMTAB_AGC1		B43legacy_OFDMTAB(0x00, 0)
71423e3ce3SKalle Valo #define B43legacy_OFDMTAB_GAIN0		B43legacy_OFDMTAB(0x00, 0)
72423e3ce3SKalle Valo #define B43legacy_OFDMTAB_GAINX		B43legacy_OFDMTAB(0x01, 0)
73423e3ce3SKalle Valo #define B43legacy_OFDMTAB_GAIN1		B43legacy_OFDMTAB(0x01, 4)
74423e3ce3SKalle Valo #define B43legacy_OFDMTAB_AGC3		B43legacy_OFDMTAB(0x02, 0)
75423e3ce3SKalle Valo #define B43legacy_OFDMTAB_GAIN2		B43legacy_OFDMTAB(0x02, 3)
76423e3ce3SKalle Valo #define B43legacy_OFDMTAB_LNAHPFGAIN1	B43legacy_OFDMTAB(0x03, 0)
77423e3ce3SKalle Valo #define B43legacy_OFDMTAB_WRSSI		B43legacy_OFDMTAB(0x04, 0)
78423e3ce3SKalle Valo #define B43legacy_OFDMTAB_LNAHPFGAIN2	B43legacy_OFDMTAB(0x04, 0)
79423e3ce3SKalle Valo #define B43legacy_OFDMTAB_NOISESCALE	B43legacy_OFDMTAB(0x05, 0)
80423e3ce3SKalle Valo #define B43legacy_OFDMTAB_AGC2		B43legacy_OFDMTAB(0x06, 0)
81423e3ce3SKalle Valo #define B43legacy_OFDMTAB_ROTOR		B43legacy_OFDMTAB(0x08, 0)
82423e3ce3SKalle Valo #define B43legacy_OFDMTAB_ADVRETARD	B43legacy_OFDMTAB(0x09, 0)
83423e3ce3SKalle Valo #define B43legacy_OFDMTAB_DAC		B43legacy_OFDMTAB(0x0C, 0)
84423e3ce3SKalle Valo #define B43legacy_OFDMTAB_DC		B43legacy_OFDMTAB(0x0E, 7)
85423e3ce3SKalle Valo #define B43legacy_OFDMTAB_PWRDYN2	B43legacy_OFDMTAB(0x0E, 12)
86423e3ce3SKalle Valo #define B43legacy_OFDMTAB_LNAGAIN	B43legacy_OFDMTAB(0x0E, 13)
87423e3ce3SKalle Valo 
88423e3ce3SKalle Valo #define B43legacy_OFDMTAB_LPFGAIN	B43legacy_OFDMTAB(0x0F, 12)
89423e3ce3SKalle Valo #define B43legacy_OFDMTAB_RSSI		B43legacy_OFDMTAB(0x10, 0)
90423e3ce3SKalle Valo 
91423e3ce3SKalle Valo #define B43legacy_OFDMTAB_AGC1_R1	B43legacy_OFDMTAB(0x13, 0)
92423e3ce3SKalle Valo #define B43legacy_OFDMTAB_GAINX_R1	B43legacy_OFDMTAB(0x14, 0)
93423e3ce3SKalle Valo #define B43legacy_OFDMTAB_MINSIGSQ	B43legacy_OFDMTAB(0x14, 1)
94423e3ce3SKalle Valo #define B43legacy_OFDMTAB_AGC3_R1	B43legacy_OFDMTAB(0x15, 0)
95423e3ce3SKalle Valo #define B43legacy_OFDMTAB_WRSSI_R1	B43legacy_OFDMTAB(0x15, 4)
96423e3ce3SKalle Valo #define B43legacy_OFDMTAB_TSSI		B43legacy_OFDMTAB(0x15, 0)
97423e3ce3SKalle Valo #define B43legacy_OFDMTAB_DACRFPABB	B43legacy_OFDMTAB(0x16, 0)
98423e3ce3SKalle Valo #define B43legacy_OFDMTAB_DACOFF	B43legacy_OFDMTAB(0x17, 0)
99423e3ce3SKalle Valo #define B43legacy_OFDMTAB_DCBIAS	B43legacy_OFDMTAB(0x18, 0)
100423e3ce3SKalle Valo 
101423e3ce3SKalle Valo void b43legacy_put_attenuation_into_ranges(int *_bbatt, int *_rfatt);
102423e3ce3SKalle Valo 
103423e3ce3SKalle Valo /* OFDM (A) PHY Registers */
104423e3ce3SKalle Valo #define B43legacy_PHY_VERSION_OFDM	B43legacy_PHY_OFDM(0x00)	/* Versioning register for A-PHY */
105423e3ce3SKalle Valo #define B43legacy_PHY_BBANDCFG		B43legacy_PHY_OFDM(0x01)	/* Baseband config */
106423e3ce3SKalle Valo #define  B43legacy_PHY_BBANDCFG_RXANT	0x180			/* RX Antenna selection */
107423e3ce3SKalle Valo #define  B43legacy_PHY_BBANDCFG_RXANT_SHIFT	7
108423e3ce3SKalle Valo #define B43legacy_PHY_PWRDOWN		B43legacy_PHY_OFDM(0x03)	/* Powerdown */
109423e3ce3SKalle Valo #define B43legacy_PHY_CRSTHRES1		B43legacy_PHY_OFDM(0x06)	/* CRS Threshold 1 */
110423e3ce3SKalle Valo #define B43legacy_PHY_LNAHPFCTL		B43legacy_PHY_OFDM(0x1C)	/* LNA/HPF control */
111423e3ce3SKalle Valo #define B43legacy_PHY_ADIVRELATED	B43legacy_PHY_OFDM(0x27)	/* FIXME rename */
112423e3ce3SKalle Valo #define B43legacy_PHY_CRS0		B43legacy_PHY_OFDM(0x29)
113423e3ce3SKalle Valo #define B43legacy_PHY_ANTDWELL		B43legacy_PHY_OFDM(0x2B)	/* Antenna dwell */
114423e3ce3SKalle Valo #define  B43legacy_PHY_ANTDWELL_AUTODIV1	0x0100			/* Automatic RX diversity start antenna */
115423e3ce3SKalle Valo #define B43legacy_PHY_ENCORE		B43legacy_PHY_OFDM(0x49)	/* "Encore" (RangeMax / BroadRange) */
116423e3ce3SKalle Valo #define  B43legacy_PHY_ENCORE_EN	0x0200				/* Encore enable */
117423e3ce3SKalle Valo #define B43legacy_PHY_LMS		B43legacy_PHY_OFDM(0x55)
118423e3ce3SKalle Valo #define B43legacy_PHY_OFDM61		B43legacy_PHY_OFDM(0x61)	/* FIXME rename */
119423e3ce3SKalle Valo #define  B43legacy_PHY_OFDM61_10	0x0010				/* FIXME rename */
120423e3ce3SKalle Valo #define B43legacy_PHY_IQBAL		B43legacy_PHY_OFDM(0x69)	/* I/Q balance */
121423e3ce3SKalle Valo #define B43legacy_PHY_OTABLECTL		B43legacy_PHY_OFDM(0x72)	/* OFDM table control (see below) */
122423e3ce3SKalle Valo #define  B43legacy_PHY_OTABLEOFF	0x03FF				/* OFDM table offset (see below) */
123423e3ce3SKalle Valo #define  B43legacy_PHY_OTABLENR		0xFC00				/* OFDM table number (see below) */
124423e3ce3SKalle Valo #define  B43legacy_PHY_OTABLENR_SHIFT	10
125423e3ce3SKalle Valo #define B43legacy_PHY_OTABLEI		B43legacy_PHY_OFDM(0x73)	/* OFDM table data I */
126423e3ce3SKalle Valo #define B43legacy_PHY_OTABLEQ		B43legacy_PHY_OFDM(0x74)	/* OFDM table data Q */
127423e3ce3SKalle Valo #define B43legacy_PHY_HPWR_TSSICTL	B43legacy_PHY_OFDM(0x78)	/* Hardware power TSSI control */
128423e3ce3SKalle Valo #define B43legacy_PHY_NRSSITHRES	B43legacy_PHY_OFDM(0x8A)	/* NRSSI threshold */
129423e3ce3SKalle Valo #define B43legacy_PHY_ANTWRSETT		B43legacy_PHY_OFDM(0x8C)	/* Antenna WR settle */
130423e3ce3SKalle Valo #define  B43legacy_PHY_ANTWRSETT_ARXDIV	0x2000				/* Automatic RX diversity enabled */
131423e3ce3SKalle Valo #define B43legacy_PHY_CLIPPWRDOWNT	B43legacy_PHY_OFDM(0x93)	/* Clip powerdown threshold */
132423e3ce3SKalle Valo #define B43legacy_PHY_OFDM9B		B43legacy_PHY_OFDM(0x9B)	/* FIXME rename */
133423e3ce3SKalle Valo #define B43legacy_PHY_N1P1GAIN		B43legacy_PHY_OFDM(0xA0)
134423e3ce3SKalle Valo #define B43legacy_PHY_P1P2GAIN		B43legacy_PHY_OFDM(0xA1)
135423e3ce3SKalle Valo #define B43legacy_PHY_N1N2GAIN		B43legacy_PHY_OFDM(0xA2)
136423e3ce3SKalle Valo #define B43legacy_PHY_CLIPTHRES		B43legacy_PHY_OFDM(0xA3)
137423e3ce3SKalle Valo #define B43legacy_PHY_CLIPN1P2THRES	B43legacy_PHY_OFDM(0xA4)
138423e3ce3SKalle Valo #define B43legacy_PHY_DIVSRCHIDX	B43legacy_PHY_OFDM(0xA8)	/* Divider search gain/index */
139423e3ce3SKalle Valo #define B43legacy_PHY_CLIPP2THRES	B43legacy_PHY_OFDM(0xA9)
140423e3ce3SKalle Valo #define B43legacy_PHY_CLIPP3THRES	B43legacy_PHY_OFDM(0xAA)
141423e3ce3SKalle Valo #define B43legacy_PHY_DIVP1P2GAIN	B43legacy_PHY_OFDM(0xAB)
142423e3ce3SKalle Valo #define B43legacy_PHY_DIVSRCHGAINBACK	B43legacy_PHY_OFDM(0xAD)	/* Divider search gain back */
143423e3ce3SKalle Valo #define B43legacy_PHY_DIVSRCHGAINCHNG	B43legacy_PHY_OFDM(0xAE)	/* Divider search gain change */
144423e3ce3SKalle Valo #define B43legacy_PHY_CRSTHRES1_R1	B43legacy_PHY_OFDM(0xC0)	/* CRS Threshold 1 (rev 1 only) */
145423e3ce3SKalle Valo #define B43legacy_PHY_CRSTHRES2_R1	B43legacy_PHY_OFDM(0xC1)	/* CRS Threshold 2 (rev 1 only) */
146423e3ce3SKalle Valo #define B43legacy_PHY_TSSIP_LTBASE	B43legacy_PHY_OFDM(0x380)	/* TSSI power lookup table base */
147423e3ce3SKalle Valo #define B43legacy_PHY_DC_LTBASE		B43legacy_PHY_OFDM(0x3A0)	/* DC lookup table base */
148423e3ce3SKalle Valo #define B43legacy_PHY_GAIN_LTBASE	B43legacy_PHY_OFDM(0x3C0)	/* Gain lookup table base */
149423e3ce3SKalle Valo 
150423e3ce3SKalle Valo void b43legacy_put_attenuation_into_ranges(int *_bbatt, int *_rfatt);
151423e3ce3SKalle Valo 
152423e3ce3SKalle Valo /* Masks for the different PHY versioning registers. */
153423e3ce3SKalle Valo #define B43legacy_PHYVER_ANALOG		0xF000
154423e3ce3SKalle Valo #define B43legacy_PHYVER_ANALOG_SHIFT	12
155423e3ce3SKalle Valo #define B43legacy_PHYVER_TYPE		0x0F00
156423e3ce3SKalle Valo #define B43legacy_PHYVER_TYPE_SHIFT	8
157423e3ce3SKalle Valo #define B43legacy_PHYVER_VERSION	0x00FF
158423e3ce3SKalle Valo 
159423e3ce3SKalle Valo struct b43legacy_wldev;
160423e3ce3SKalle Valo 
161423e3ce3SKalle Valo void b43legacy_phy_lock(struct b43legacy_wldev *dev);
162423e3ce3SKalle Valo void b43legacy_phy_unlock(struct b43legacy_wldev *dev);
163423e3ce3SKalle Valo 
164423e3ce3SKalle Valo /* Card uses the loopback gain stuff */
165423e3ce3SKalle Valo #define has_loopback_gain(phy)			 \
166423e3ce3SKalle Valo 	(((phy)->rev > 1) || ((phy)->gmode))
167423e3ce3SKalle Valo 
168423e3ce3SKalle Valo u16 b43legacy_phy_read(struct b43legacy_wldev *dev, u16 offset);
169423e3ce3SKalle Valo void b43legacy_phy_write(struct b43legacy_wldev *dev, u16 offset, u16 val);
170423e3ce3SKalle Valo 
171423e3ce3SKalle Valo int b43legacy_phy_init_tssi2dbm_table(struct b43legacy_wldev *dev);
172423e3ce3SKalle Valo int b43legacy_phy_init(struct b43legacy_wldev *dev);
173423e3ce3SKalle Valo 
174423e3ce3SKalle Valo void b43legacy_set_rx_antenna(struct b43legacy_wldev *dev, int antenna);
175423e3ce3SKalle Valo 
176423e3ce3SKalle Valo void b43legacy_phy_set_antenna_diversity(struct b43legacy_wldev *dev);
177423e3ce3SKalle Valo void b43legacy_phy_calibrate(struct b43legacy_wldev *dev);
178423e3ce3SKalle Valo int b43legacy_phy_connect(struct b43legacy_wldev *dev, int connect);
179423e3ce3SKalle Valo 
180423e3ce3SKalle Valo void b43legacy_phy_lo_b_measure(struct b43legacy_wldev *dev);
181423e3ce3SKalle Valo void b43legacy_phy_lo_g_measure(struct b43legacy_wldev *dev);
182423e3ce3SKalle Valo void b43legacy_phy_xmitpower(struct b43legacy_wldev *dev);
183423e3ce3SKalle Valo 
184423e3ce3SKalle Valo /* Adjust the LocalOscillator to the saved values.
185423e3ce3SKalle Valo  * "fixed" is only set to 1 once in initialization. Set to 0 otherwise.
186423e3ce3SKalle Valo  */
187423e3ce3SKalle Valo void b43legacy_phy_lo_adjust(struct b43legacy_wldev *dev, int fixed);
188423e3ce3SKalle Valo void b43legacy_phy_lo_mark_all_unused(struct b43legacy_wldev *dev);
189423e3ce3SKalle Valo 
190423e3ce3SKalle Valo void b43legacy_phy_set_baseband_attenuation(struct b43legacy_wldev *dev,
191423e3ce3SKalle Valo 					    u16 baseband_attenuation);
192423e3ce3SKalle Valo 
193423e3ce3SKalle Valo void b43legacy_power_saving_ctl_bits(struct b43legacy_wldev *dev,
194423e3ce3SKalle Valo 				     int bit25, int bit26);
195423e3ce3SKalle Valo 
196423e3ce3SKalle Valo #endif /* B43legacy_PHY_H_ */
197