xref: /openbmc/linux/drivers/net/wireless/broadcom/b43/phy_g.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
258619b14SKalle Valo #ifndef LINUX_B43_PHY_G_H_
358619b14SKalle Valo #define LINUX_B43_PHY_G_H_
458619b14SKalle Valo 
558619b14SKalle Valo /* OFDM PHY registers are defined in the A-PHY header. */
658619b14SKalle Valo #include "phy_a.h"
758619b14SKalle Valo 
858619b14SKalle Valo /* CCK (B) PHY Registers */
958619b14SKalle Valo #define B43_PHY_VERSION_CCK		B43_PHY_CCK(0x00)	/* Versioning register for B-PHY */
1058619b14SKalle Valo #define B43_PHY_CCKBBANDCFG		B43_PHY_CCK(0x01)	/* Contains antenna 0/1 control bit */
1158619b14SKalle Valo #define B43_PHY_PGACTL			B43_PHY_CCK(0x15)	/* PGA control */
1258619b14SKalle Valo #define  B43_PHY_PGACTL_LPF		0x1000	/* Low pass filter (?) */
1358619b14SKalle Valo #define  B43_PHY_PGACTL_LOWBANDW	0x0040	/* Low bandwidth flag */
1458619b14SKalle Valo #define  B43_PHY_PGACTL_UNKNOWN		0xEFA0
1558619b14SKalle Valo #define B43_PHY_FBCTL1			B43_PHY_CCK(0x18)	/* Frequency bandwidth control 1 */
1658619b14SKalle Valo #define B43_PHY_ITSSI			B43_PHY_CCK(0x29)	/* Idle TSSI */
1758619b14SKalle Valo #define B43_PHY_LO_LEAKAGE		B43_PHY_CCK(0x2D)	/* Measured LO leakage */
1858619b14SKalle Valo #define B43_PHY_ENERGY			B43_PHY_CCK(0x33)	/* Energy */
1958619b14SKalle Valo #define B43_PHY_SYNCCTL			B43_PHY_CCK(0x35)
2058619b14SKalle Valo #define B43_PHY_FBCTL2			B43_PHY_CCK(0x38)	/* Frequency bandwidth control 2 */
2158619b14SKalle Valo #define B43_PHY_DACCTL			B43_PHY_CCK(0x60)	/* DAC control */
2258619b14SKalle Valo #define B43_PHY_RCCALOVER		B43_PHY_CCK(0x78)	/* RC calibration override */
2358619b14SKalle Valo 
2458619b14SKalle Valo /* Extended G-PHY Registers */
2558619b14SKalle Valo #define B43_PHY_CLASSCTL		B43_PHY_EXTG(0x02)	/* Classify control */
2658619b14SKalle Valo #define B43_PHY_GTABCTL			B43_PHY_EXTG(0x03)	/* G-PHY table control (see below) */
2758619b14SKalle Valo #define  B43_PHY_GTABOFF		0x03FF	/* G-PHY table offset (see below) */
2858619b14SKalle Valo #define  B43_PHY_GTABNR			0xFC00	/* G-PHY table number (see below) */
2958619b14SKalle Valo #define  B43_PHY_GTABNR_SHIFT		10
3058619b14SKalle Valo #define B43_PHY_GTABDATA		B43_PHY_EXTG(0x04)	/* G-PHY table data */
3158619b14SKalle Valo #define B43_PHY_LO_MASK			B43_PHY_EXTG(0x0F)	/* Local Oscillator control mask */
3258619b14SKalle Valo #define B43_PHY_LO_CTL			B43_PHY_EXTG(0x10)	/* Local Oscillator control */
3358619b14SKalle Valo #define B43_PHY_RFOVER			B43_PHY_EXTG(0x11)	/* RF override */
3458619b14SKalle Valo #define B43_PHY_RFOVERVAL		B43_PHY_EXTG(0x12)	/* RF override value */
3558619b14SKalle Valo #define  B43_PHY_RFOVERVAL_EXTLNA	0x8000
3658619b14SKalle Valo #define  B43_PHY_RFOVERVAL_LNA		0x7000
3758619b14SKalle Valo #define  B43_PHY_RFOVERVAL_LNA_SHIFT	12
3858619b14SKalle Valo #define  B43_PHY_RFOVERVAL_PGA		0x0F00
3958619b14SKalle Valo #define  B43_PHY_RFOVERVAL_PGA_SHIFT	8
4058619b14SKalle Valo #define  B43_PHY_RFOVERVAL_UNK		0x0010	/* Unknown, always set. */
4158619b14SKalle Valo #define  B43_PHY_RFOVERVAL_TRSWRX	0x00E0
4258619b14SKalle Valo #define  B43_PHY_RFOVERVAL_BW		0x0003	/* Bandwidth flags */
4358619b14SKalle Valo #define   B43_PHY_RFOVERVAL_BW_LPF	0x0001	/* Low Pass Filter */
4458619b14SKalle Valo #define   B43_PHY_RFOVERVAL_BW_LBW	0x0002	/* Low Bandwidth (when set), high when unset */
4558619b14SKalle Valo #define B43_PHY_ANALOGOVER		B43_PHY_EXTG(0x14)	/* Analog override */
4658619b14SKalle Valo #define B43_PHY_ANALOGOVERVAL		B43_PHY_EXTG(0x15)	/* Analog override value */
4758619b14SKalle Valo 
4858619b14SKalle Valo 
4958619b14SKalle Valo /*** G-PHY table numbers */
5058619b14SKalle Valo #define B43_GTAB(number, offset)	(((number) << B43_PHY_GTABNR_SHIFT) | (offset))
5158619b14SKalle Valo #define B43_GTAB_NRSSI			B43_GTAB(0x00, 0)
5258619b14SKalle Valo #define B43_GTAB_TRFEMW			B43_GTAB(0x0C, 0x120)
5358619b14SKalle Valo #define B43_GTAB_ORIGTR			B43_GTAB(0x2E, 0x298)
5458619b14SKalle Valo 
5558619b14SKalle Valo u16 b43_gtab_read(struct b43_wldev *dev, u16 table, u16 offset);
5658619b14SKalle Valo void b43_gtab_write(struct b43_wldev *dev, u16 table, u16 offset, u16 value);
5758619b14SKalle Valo 
5858619b14SKalle Valo 
5958619b14SKalle Valo /* Returns the boolean whether "TX Magnification" is enabled. */
6058619b14SKalle Valo #define has_tx_magnification(phy) \
6158619b14SKalle Valo 	(((phy)->rev >= 2) &&			\
6258619b14SKalle Valo 	 ((phy)->radio_ver == 0x2050) &&	\
6358619b14SKalle Valo 	 ((phy)->radio_rev == 8))
6458619b14SKalle Valo /* Card uses the loopback gain stuff */
6558619b14SKalle Valo #define has_loopback_gain(phy) \
6658619b14SKalle Valo 	(((phy)->rev > 1) || ((phy)->gmode))
6758619b14SKalle Valo 
6858619b14SKalle Valo /* Radio Attenuation (RF Attenuation) */
6958619b14SKalle Valo struct b43_rfatt {
7058619b14SKalle Valo 	u8 att;			/* Attenuation value */
7158619b14SKalle Valo 	bool with_padmix;	/* Flag, PAD Mixer enabled. */
7258619b14SKalle Valo };
7358619b14SKalle Valo struct b43_rfatt_list {
7458619b14SKalle Valo 	/* Attenuation values list */
7558619b14SKalle Valo 	const struct b43_rfatt *list;
7658619b14SKalle Valo 	u8 len;
7758619b14SKalle Valo 	/* Minimum/Maximum attenuation values */
7858619b14SKalle Valo 	u8 min_val;
7958619b14SKalle Valo 	u8 max_val;
8058619b14SKalle Valo };
8158619b14SKalle Valo 
8258619b14SKalle Valo /* Returns true, if the values are the same. */
b43_compare_rfatt(const struct b43_rfatt * a,const struct b43_rfatt * b)8358619b14SKalle Valo static inline bool b43_compare_rfatt(const struct b43_rfatt *a,
8458619b14SKalle Valo 				     const struct b43_rfatt *b)
8558619b14SKalle Valo {
8658619b14SKalle Valo 	return ((a->att == b->att) &&
8758619b14SKalle Valo 		(a->with_padmix == b->with_padmix));
8858619b14SKalle Valo }
8958619b14SKalle Valo 
9058619b14SKalle Valo /* Baseband Attenuation */
9158619b14SKalle Valo struct b43_bbatt {
9258619b14SKalle Valo 	u8 att;			/* Attenuation value */
9358619b14SKalle Valo };
9458619b14SKalle Valo struct b43_bbatt_list {
9558619b14SKalle Valo 	/* Attenuation values list */
9658619b14SKalle Valo 	const struct b43_bbatt *list;
9758619b14SKalle Valo 	u8 len;
9858619b14SKalle Valo 	/* Minimum/Maximum attenuation values */
9958619b14SKalle Valo 	u8 min_val;
10058619b14SKalle Valo 	u8 max_val;
10158619b14SKalle Valo };
10258619b14SKalle Valo 
10358619b14SKalle Valo /* Returns true, if the values are the same. */
b43_compare_bbatt(const struct b43_bbatt * a,const struct b43_bbatt * b)10458619b14SKalle Valo static inline bool b43_compare_bbatt(const struct b43_bbatt *a,
10558619b14SKalle Valo 				     const struct b43_bbatt *b)
10658619b14SKalle Valo {
10758619b14SKalle Valo 	return (a->att == b->att);
10858619b14SKalle Valo }
10958619b14SKalle Valo 
11058619b14SKalle Valo /* tx_control bits. */
11158619b14SKalle Valo #define B43_TXCTL_PA3DB		0x40	/* PA Gain 3dB */
11258619b14SKalle Valo #define B43_TXCTL_PA2DB		0x20	/* PA Gain 2dB */
11358619b14SKalle Valo #define B43_TXCTL_TXMIX		0x10	/* TX Mixer Gain */
11458619b14SKalle Valo 
11558619b14SKalle Valo struct b43_txpower_lo_control;
11658619b14SKalle Valo 
11758619b14SKalle Valo struct b43_phy_g {
11858619b14SKalle Valo 	/* ACI (adjacent channel interference) flags. */
11958619b14SKalle Valo 	bool aci_enable;
12058619b14SKalle Valo 	bool aci_wlan_automatic;
12158619b14SKalle Valo 	bool aci_hw_rssi;
12258619b14SKalle Valo 
12358619b14SKalle Valo 	/* Radio switched on/off */
12458619b14SKalle Valo 	bool radio_on;
12558619b14SKalle Valo 	struct {
12658619b14SKalle Valo 		/* Values saved when turning the radio off.
12758619b14SKalle Valo 		 * They are needed when turning it on again. */
12858619b14SKalle Valo 		bool valid;
12958619b14SKalle Valo 		u16 rfover;
13058619b14SKalle Valo 		u16 rfoverval;
13158619b14SKalle Valo 	} radio_off_context;
13258619b14SKalle Valo 
13358619b14SKalle Valo 	u16 minlowsig[2];
13458619b14SKalle Valo 	u16 minlowsigpos[2];
13558619b14SKalle Valo 
13658619b14SKalle Valo 	/* Pointer to the table used to convert a
13758619b14SKalle Valo 	 * TSSI value to dBm-Q5.2 */
13858619b14SKalle Valo 	const s8 *tssi2dbm;
13958619b14SKalle Valo 	/* tssi2dbm is kmalloc()ed. Only used for free()ing. */
14058619b14SKalle Valo 	bool dyn_tssi_tbl;
14158619b14SKalle Valo 	/* Target idle TSSI */
14258619b14SKalle Valo 	int tgt_idle_tssi;
14358619b14SKalle Valo 	/* Current idle TSSI */
14458619b14SKalle Valo 	int cur_idle_tssi;
14558619b14SKalle Valo 	/* The current average TSSI. */
14658619b14SKalle Valo 	u8 average_tssi;
14758619b14SKalle Valo 	/* Current TX power level attenuation control values */
14858619b14SKalle Valo 	struct b43_bbatt bbatt;
14958619b14SKalle Valo 	struct b43_rfatt rfatt;
15058619b14SKalle Valo 	u8 tx_control;		/* B43_TXCTL_XXX */
15158619b14SKalle Valo 	/* The calculated attenuation deltas that are used later
15258619b14SKalle Valo 	 * when adjusting the actual power output. */
15358619b14SKalle Valo 	int bbatt_delta;
15458619b14SKalle Valo 	int rfatt_delta;
15558619b14SKalle Valo 
15658619b14SKalle Valo 	/* LocalOscillator control values. */
15758619b14SKalle Valo 	struct b43_txpower_lo_control *lo_control;
15858619b14SKalle Valo 	/* Values from b43_calc_loopback_gain() */
15958619b14SKalle Valo 	s16 max_lb_gain;	/* Maximum Loopback gain in hdB */
16058619b14SKalle Valo 	s16 trsw_rx_gain;	/* TRSW RX gain in hdB */
16158619b14SKalle Valo 	s16 lna_lod_gain;	/* LNA lod */
16258619b14SKalle Valo 	s16 lna_gain;		/* LNA */
16358619b14SKalle Valo 	s16 pga_gain;		/* PGA */
16458619b14SKalle Valo 
16558619b14SKalle Valo 	/* Current Interference Mitigation mode */
16658619b14SKalle Valo 	int interfmode;
16758619b14SKalle Valo 	/* Stack of saved values from the Interference Mitigation code.
16858619b14SKalle Valo 	 * Each value in the stack is laid out as follows:
16958619b14SKalle Valo 	 * bit 0-11:  offset
17058619b14SKalle Valo 	 * bit 12-15: register ID
17158619b14SKalle Valo 	 * bit 16-32: value
17258619b14SKalle Valo 	 * register ID is: 0x1 PHY, 0x2 Radio, 0x3 ILT
17358619b14SKalle Valo 	 */
17458619b14SKalle Valo #define B43_INTERFSTACK_SIZE	26
17558619b14SKalle Valo 	u32 interfstack[B43_INTERFSTACK_SIZE];	//FIXME: use a data structure
17658619b14SKalle Valo 
17758619b14SKalle Valo 	/* Saved values from the NRSSI Slope calculation */
17858619b14SKalle Valo 	s16 nrssi[2];
17958619b14SKalle Valo 	s32 nrssislope;
18058619b14SKalle Valo 	/* In memory nrssi lookup table. */
18158619b14SKalle Valo 	s8 nrssi_lt[64];
18258619b14SKalle Valo 
18358619b14SKalle Valo 	u16 lofcal;
18458619b14SKalle Valo 
18558619b14SKalle Valo 	u16 initval;		//FIXME rename?
18658619b14SKalle Valo 
18758619b14SKalle Valo 	/* The device does address auto increment for the OFDM tables.
18858619b14SKalle Valo 	 * We cache the previously used address here and omit the address
18958619b14SKalle Valo 	 * write on the next table access, if possible. */
19058619b14SKalle Valo 	u16 ofdmtab_addr; /* The address currently set in hardware. */
19158619b14SKalle Valo 	enum { /* The last data flow direction. */
19258619b14SKalle Valo 		B43_OFDMTAB_DIRECTION_UNKNOWN = 0,
19358619b14SKalle Valo 		B43_OFDMTAB_DIRECTION_READ,
19458619b14SKalle Valo 		B43_OFDMTAB_DIRECTION_WRITE,
19558619b14SKalle Valo 	} ofdmtab_addr_direction;
19658619b14SKalle Valo };
19758619b14SKalle Valo 
19858619b14SKalle Valo void b43_gphy_set_baseband_attenuation(struct b43_wldev *dev,
19958619b14SKalle Valo 				       u16 baseband_attenuation);
20058619b14SKalle Valo void b43_gphy_channel_switch(struct b43_wldev *dev,
20158619b14SKalle Valo 			     unsigned int channel,
20258619b14SKalle Valo 			     bool synthetic_pu_workaround);
20358619b14SKalle Valo u8 * b43_generate_dyn_tssi2dbm_tab(struct b43_wldev *dev,
20458619b14SKalle Valo 				   s16 pab0, s16 pab1, s16 pab2);
20558619b14SKalle Valo 
20658619b14SKalle Valo struct b43_phy_operations;
20758619b14SKalle Valo extern const struct b43_phy_operations b43_phyops_g;
20858619b14SKalle Valo 
20958619b14SKalle Valo #endif /* LINUX_B43_PHY_G_H_ */
210