1 #ifndef LINUX_B43_PHY_COMMON_H_
2 #define LINUX_B43_PHY_COMMON_H_
4 #include <linux/types.h>
9 /* PHY register routing bits */
10 #define B43_PHYROUTE 0x0C00 /* PHY register routing bits mask */
11 #define B43_PHYROUTE_BASE 0x0000 /* Base registers */
12 #define B43_PHYROUTE_OFDM_GPHY 0x0400 /* OFDM register routing for G-PHYs */
13 #define B43_PHYROUTE_EXT_GPHY 0x0800 /* Extended G-PHY registers */
14 #define B43_PHYROUTE_N_BMODE 0x0C00 /* N-PHY BMODE registers */
16 /* CCK (B-PHY) registers. */
17 #define B43_PHY_CCK(reg) ((reg) | B43_PHYROUTE_BASE)
18 /* N-PHY registers. */
19 #define B43_PHY_N(reg) ((reg) | B43_PHYROUTE_BASE)
20 /* N-PHY BMODE registers. */
21 #define B43_PHY_N_BMODE(reg) ((reg) | B43_PHYROUTE_N_BMODE)
22 /* OFDM (A-PHY) registers. */
23 #define B43_PHY_OFDM(reg) ((reg) | B43_PHYROUTE_OFDM_GPHY)
24 /* Extended G-PHY registers. */
25 #define B43_PHY_EXTG(reg) ((reg) | B43_PHYROUTE_EXT_GPHY)
28 /* Masks for the PHY versioning registers. */
29 #define B43_PHYVER_ANALOG 0xF000
30 #define B43_PHYVER_ANALOG_SHIFT 12
31 #define B43_PHYVER_TYPE 0x0F00
32 #define B43_PHYVER_TYPE_SHIFT 8
33 #define B43_PHYVER_VERSION 0x00FF
36 * enum b43_interference_mitigation - Interference Mitigation mode
38 * @B43_INTERFMODE_NONE: Disabled
39 * @B43_INTERFMODE_NONWLAN: Non-WLAN Interference Mitigation
40 * @B43_INTERFMODE_MANUALWLAN: WLAN Interference Mitigation
41 * @B43_INTERFMODE_AUTOWLAN: Automatic WLAN Interference Mitigation
43 enum b43_interference_mitigation
{
45 B43_INTERFMODE_NONWLAN
,
46 B43_INTERFMODE_MANUALWLAN
,
47 B43_INTERFMODE_AUTOWLAN
,
50 /* Antenna identifiers */
52 B43_ANTENNA0
= 0, /* Antenna 0 */
53 B43_ANTENNA1
= 1, /* Antenna 1 */
54 B43_ANTENNA_AUTO0
= 2, /* Automatic, starting with antenna 0 */
55 B43_ANTENNA_AUTO1
= 3, /* Automatic, starting with antenna 1 */
59 B43_ANTENNA_AUTO
= B43_ANTENNA_AUTO0
,
60 B43_ANTENNA_DEFAULT
= B43_ANTENNA_AUTO
,
64 * enum b43_txpwr_result - Return value for the recalc_txpower PHY op.
66 * @B43_TXPWR_RES_NEED_ADJUST: Values changed. Hardware adjustment is needed.
67 * @B43_TXPWR_RES_DONE: No more work to do. Everything is done.
69 enum b43_txpwr_result
{
70 B43_TXPWR_RES_NEED_ADJUST
,
75 * struct b43_phy_operations - Function pointers for PHY ops.
77 * @allocate: Allocate and initialise the PHY data structures.
79 * @free: Destroy and free the PHY data structures.
82 * @prepare_structs: Prepare the PHY data structures.
83 * The data structures allocated in @allocate are
86 * @prepare_hardware: Prepare the PHY. This is called before b43_chip_init to
87 * do some early early PHY hardware init.
88 * Can be NULL, if not required.
89 * @init: Initialize the PHY.
91 * @exit: Shutdown the PHY.
92 * Can be NULL, if not required.
94 * @phy_read: Read from a PHY register.
96 * @phy_write: Write to a PHY register.
98 * @phy_maskset: Maskset a PHY register, taking shortcuts.
99 * If it is NULL, a generic algorithm is used.
100 * @radio_read: Read from a Radio register.
102 * @radio_write: Write to a Radio register.
105 * @supports_hwpctl: Returns a boolean whether Hardware Power Control
106 * is supported or not.
107 * If NULL, hwpctl is assumed to be never supported.
108 * @software_rfkill: Turn the radio ON or OFF.
109 * Possible state values are
110 * RFKILL_STATE_SOFT_BLOCKED or
111 * RFKILL_STATE_UNBLOCKED
113 * @switch_analog: Turn the Analog on/off.
115 * @switch_channel: Switch the radio to another channel.
117 * @get_default_chan: Just returns the default channel number.
119 * @set_rx_antenna: Set the antenna used for RX.
120 * Can be NULL, if not supported.
121 * @interf_mitigation: Switch the Interference Mitigation mode.
122 * Can be NULL, if not supported.
124 * @recalc_txpower: Recalculate the transmission power parameters.
125 * This callback has to recalculate the TX power settings,
126 * but does not need to write them to the hardware, yet.
127 * Returns enum b43_txpwr_result to indicate whether the hardware
128 * needs to be adjusted.
129 * If B43_TXPWR_NEED_ADJUST is returned, @adjust_txpower
130 * will be called later.
131 * If the parameter "ignore_tssi" is true, the TSSI values should
132 * be ignored and a recalculation of the power settings should be
133 * done even if the TSSI values did not change.
134 * This function may sleep, but should not.
136 * @adjust_txpower: Write the previously calculated TX power settings
137 * (from @recalc_txpower) to the hardware.
138 * This function may sleep.
139 * Can be NULL, if (and ONLY if) @recalc_txpower _always_
140 * returns B43_TXPWR_RES_DONE.
142 * @pwork_15sec: Periodic work. Called every 15 seconds.
143 * Can be NULL, if not required.
144 * @pwork_60sec: Periodic work. Called every 60 seconds.
145 * Can be NULL, if not required.
147 struct b43_phy_operations
{
149 int (*allocate
)(struct b43_wldev
*dev
);
150 void (*free
)(struct b43_wldev
*dev
);
151 void (*prepare_structs
)(struct b43_wldev
*dev
);
152 int (*prepare_hardware
)(struct b43_wldev
*dev
);
153 int (*init
)(struct b43_wldev
*dev
);
154 void (*exit
)(struct b43_wldev
*dev
);
156 /* Register access */
157 u16 (*phy_read
)(struct b43_wldev
*dev
, u16 reg
);
158 void (*phy_write
)(struct b43_wldev
*dev
, u16 reg
, u16 value
);
159 void (*phy_maskset
)(struct b43_wldev
*dev
, u16 reg
, u16 mask
, u16 set
);
160 u16 (*radio_read
)(struct b43_wldev
*dev
, u16 reg
);
161 void (*radio_write
)(struct b43_wldev
*dev
, u16 reg
, u16 value
);
164 bool (*supports_hwpctl
)(struct b43_wldev
*dev
);
165 void (*software_rfkill
)(struct b43_wldev
*dev
, bool blocked
);
166 void (*switch_analog
)(struct b43_wldev
*dev
, bool on
);
167 int (*switch_channel
)(struct b43_wldev
*dev
, unsigned int new_channel
);
168 unsigned int (*get_default_chan
)(struct b43_wldev
*dev
);
169 void (*set_rx_antenna
)(struct b43_wldev
*dev
, int antenna
);
170 int (*interf_mitigation
)(struct b43_wldev
*dev
,
171 enum b43_interference_mitigation new_mode
);
173 /* Transmission power adjustment */
174 enum b43_txpwr_result (*recalc_txpower
)(struct b43_wldev
*dev
,
176 void (*adjust_txpower
)(struct b43_wldev
*dev
);
179 void (*pwork_15sec
)(struct b43_wldev
*dev
);
180 void (*pwork_60sec
)(struct b43_wldev
*dev
);
189 /* Hardware operation callbacks. */
190 const struct b43_phy_operations
*ops
;
192 /* Most hardware context information is stored in the standard-
193 * specific data structures pointed to by the pointers below.
194 * Only one of them is valid (the currently enabled PHY). */
195 #ifdef CONFIG_B43_DEBUG
196 /* No union for debug build to force NULL derefs in buggy code. */
201 /* A-PHY specific information */
203 /* G-PHY specific information */
205 /* N-PHY specific information */
207 /* LP-PHY specific information */
208 struct b43_phy_lp
*lp
;
211 /* Band support flags. */
215 /* GMODE bit enabled? */
222 /* PHY revision number. */
225 /* Radio versioning */
226 u16 radio_manuf
; /* Radio manufacturer */
227 u16 radio_ver
; /* Radio version */
228 u8 radio_rev
; /* Radio revision */
230 /* Software state of the radio */
233 /* Desired TX power level (in dBm).
234 * This is set by the user and adjusted in b43_phy_xmitpower(). */
237 /* Hardware Power Control enabled? */
238 bool hardware_power_control
;
240 /* The time (in absolute jiffies) when the next TX power output
241 * check is needed. */
242 unsigned long next_txpwr_check_time
;
244 /* current channel */
245 unsigned int channel
;
247 /* PHY TX errors counter. */
250 #ifdef CONFIG_B43_DEBUG
251 /* PHY registers locked (w.r.t. firmware) */
253 /* Radio registers locked (w.r.t. firmware) */
255 #endif /* B43_DEBUG */
260 * b43_phy_allocate - Allocate PHY structs
261 * Allocate the PHY data structures, based on the current dev->phy.type
263 int b43_phy_allocate(struct b43_wldev
*dev
);
266 * b43_phy_free - Free PHY structs
268 void b43_phy_free(struct b43_wldev
*dev
);
271 * b43_phy_init - Initialise the PHY
273 int b43_phy_init(struct b43_wldev
*dev
);
276 * b43_phy_exit - Cleanup PHY
278 void b43_phy_exit(struct b43_wldev
*dev
);
281 * b43_has_hardware_pctl - Hardware Power Control supported?
282 * Returns a boolean, whether hardware power control is supported.
284 bool b43_has_hardware_pctl(struct b43_wldev
*dev
);
287 * b43_phy_read - 16bit PHY register read access
289 u16
b43_phy_read(struct b43_wldev
*dev
, u16 reg
);
292 * b43_phy_write - 16bit PHY register write access
294 void b43_phy_write(struct b43_wldev
*dev
, u16 reg
, u16 value
);
297 * b43_phy_copy - copy contents of 16bit PHY register to another
299 void b43_phy_copy(struct b43_wldev
*dev
, u16 destreg
, u16 srcreg
);
302 * b43_phy_mask - Mask a PHY register with a mask
304 void b43_phy_mask(struct b43_wldev
*dev
, u16 offset
, u16 mask
);
307 * b43_phy_set - OR a PHY register with a bitmap
309 void b43_phy_set(struct b43_wldev
*dev
, u16 offset
, u16 set
);
312 * b43_phy_maskset - Mask and OR a PHY register with a mask and bitmap
314 void b43_phy_maskset(struct b43_wldev
*dev
, u16 offset
, u16 mask
, u16 set
);
317 * b43_radio_read - 16bit Radio register read access
319 u16
b43_radio_read(struct b43_wldev
*dev
, u16 reg
);
320 #define b43_radio_read16 b43_radio_read /* DEPRECATED */
323 * b43_radio_write - 16bit Radio register write access
325 void b43_radio_write(struct b43_wldev
*dev
, u16 reg
, u16 value
);
326 #define b43_radio_write16 b43_radio_write /* DEPRECATED */
329 * b43_radio_mask - Mask a 16bit radio register with a mask
331 void b43_radio_mask(struct b43_wldev
*dev
, u16 offset
, u16 mask
);
334 * b43_radio_set - OR a 16bit radio register with a bitmap
336 void b43_radio_set(struct b43_wldev
*dev
, u16 offset
, u16 set
);
339 * b43_radio_maskset - Mask and OR a radio register with a mask and bitmap
341 void b43_radio_maskset(struct b43_wldev
*dev
, u16 offset
, u16 mask
, u16 set
);
344 * b43_radio_lock - Lock firmware radio register access
346 void b43_radio_lock(struct b43_wldev
*dev
);
349 * b43_radio_unlock - Unlock firmware radio register access
351 void b43_radio_unlock(struct b43_wldev
*dev
);
354 * b43_phy_lock - Lock firmware PHY register access
356 void b43_phy_lock(struct b43_wldev
*dev
);
359 * b43_phy_unlock - Unlock firmware PHY register access
361 void b43_phy_unlock(struct b43_wldev
*dev
);
364 * b43_switch_channel - Switch to another channel
366 int b43_switch_channel(struct b43_wldev
*dev
, unsigned int new_channel
);
368 * B43_DEFAULT_CHANNEL - Switch to the default channel.
370 #define B43_DEFAULT_CHANNEL UINT_MAX
373 * b43_software_rfkill - Turn the radio ON or OFF in software.
375 void b43_software_rfkill(struct b43_wldev
*dev
, bool blocked
);
378 * b43_phy_txpower_check - Check TX power output.
380 * Compare the current TX power output to the desired power emission
381 * and schedule an adjustment in case it mismatches.
383 * @flags: OR'ed enum b43_phy_txpower_check_flags flags.
384 * See the docs below.
386 void b43_phy_txpower_check(struct b43_wldev
*dev
, unsigned int flags
);
388 * enum b43_phy_txpower_check_flags - Flags for b43_phy_txpower_check()
390 * @B43_TXPWR_IGNORE_TIME: Ignore the schedule time and force-redo
392 * @B43_TXPWR_IGNORE_TSSI: Redo the recalculation, even if the average
393 * TSSI did not change.
395 enum b43_phy_txpower_check_flags
{
396 B43_TXPWR_IGNORE_TIME
= (1 << 0),
397 B43_TXPWR_IGNORE_TSSI
= (1 << 1),
401 void b43_phy_txpower_adjust_work(struct work_struct
*work
);
404 * b43_phy_shm_tssi_read - Read the average of the last 4 TSSI from SHM.
406 * @shm_offset: The SHM address to read the values from.
408 * Returns the average of the 4 TSSI values, or a negative error code.
410 int b43_phy_shm_tssi_read(struct b43_wldev
*dev
, u16 shm_offset
);
413 * b43_phy_switch_analog_generic - Generic PHY operation for switching the Analog.
415 * It does the switching based on the PHY0 core register.
416 * Do _not_ call this directly. Only use it as a switch_analog callback
417 * for struct b43_phy_operations.
419 void b43_phyop_switch_analog_generic(struct b43_wldev
*dev
, bool on
);
422 #endif /* LINUX_B43_PHY_COMMON_H_ */