phy.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. #ifndef B43_PHY_H_
  2. #define B43_PHY_H_
  3. #include <linux/types.h>
  4. struct b43_wldev;
  5. struct b43_phy;
  6. /*** PHY Registers ***/
  7. /* Routing */
  8. #define B43_PHYROUTE 0x0C00 /* PHY register routing bits mask */
  9. #define B43_PHYROUTE_BASE 0x0000 /* Base registers */
  10. #define B43_PHYROUTE_OFDM_GPHY 0x0400 /* OFDM register routing for G-PHYs */
  11. #define B43_PHYROUTE_EXT_GPHY 0x0800 /* Extended G-PHY registers */
  12. #define B43_PHYROUTE_N_BMODE 0x0C00 /* N-PHY BMODE registers */
  13. /* CCK (B-PHY) registers. */
  14. #define B43_PHY_CCK(reg) ((reg) | B43_PHYROUTE_BASE)
  15. /* N-PHY registers. */
  16. #define B43_PHY_N(reg) ((reg) | B43_PHYROUTE_BASE)
  17. /* N-PHY BMODE registers. */
  18. #define B43_PHY_N_BMODE(reg) ((reg) | B43_PHYROUTE_N_BMODE)
  19. /* OFDM (A-PHY) registers. */
  20. #define B43_PHY_OFDM(reg) ((reg) | B43_PHYROUTE_OFDM_GPHY)
  21. /* Extended G-PHY registers. */
  22. #define B43_PHY_EXTG(reg) ((reg) | B43_PHYROUTE_EXT_GPHY)
  23. /* OFDM (A) PHY Registers */
  24. #define B43_PHY_VERSION_OFDM B43_PHY_OFDM(0x00) /* Versioning register for A-PHY */
  25. #define B43_PHY_BBANDCFG B43_PHY_OFDM(0x01) /* Baseband config */
  26. #define B43_PHY_BBANDCFG_RXANT 0x180 /* RX Antenna selection */
  27. #define B43_PHY_BBANDCFG_RXANT_SHIFT 7
  28. #define B43_PHY_PWRDOWN B43_PHY_OFDM(0x03) /* Powerdown */
  29. #define B43_PHY_CRSTHRES1_R1 B43_PHY_OFDM(0x06) /* CRS Threshold 1 (phy.rev 1 only) */
  30. #define B43_PHY_LNAHPFCTL B43_PHY_OFDM(0x1C) /* LNA/HPF control */
  31. #define B43_PHY_LPFGAINCTL B43_PHY_OFDM(0x20) /* LPF Gain control */
  32. #define B43_PHY_ADIVRELATED B43_PHY_OFDM(0x27) /* FIXME rename */
  33. #define B43_PHY_CRS0 B43_PHY_OFDM(0x29)
  34. #define B43_PHY_CRS0_EN 0x4000
  35. #define B43_PHY_PEAK_COUNT B43_PHY_OFDM(0x30)
  36. #define B43_PHY_ANTDWELL B43_PHY_OFDM(0x2B) /* Antenna dwell */
  37. #define B43_PHY_ANTDWELL_AUTODIV1 0x0100 /* Automatic RX diversity start antenna */
  38. #define B43_PHY_ENCORE B43_PHY_OFDM(0x49) /* "Encore" (RangeMax / BroadRange) */
  39. #define B43_PHY_ENCORE_EN 0x0200 /* Encore enable */
  40. #define B43_PHY_LMS B43_PHY_OFDM(0x55)
  41. #define B43_PHY_OFDM61 B43_PHY_OFDM(0x61) /* FIXME rename */
  42. #define B43_PHY_OFDM61_10 0x0010 /* FIXME rename */
  43. #define B43_PHY_IQBAL B43_PHY_OFDM(0x69) /* I/Q balance */
  44. #define B43_PHY_BBTXDC_BIAS B43_PHY_OFDM(0x6B) /* Baseband TX DC bias */
  45. #define B43_PHY_OTABLECTL B43_PHY_OFDM(0x72) /* OFDM table control (see below) */
  46. #define B43_PHY_OTABLEOFF 0x03FF /* OFDM table offset (see below) */
  47. #define B43_PHY_OTABLENR 0xFC00 /* OFDM table number (see below) */
  48. #define B43_PHY_OTABLENR_SHIFT 10
  49. #define B43_PHY_OTABLEI B43_PHY_OFDM(0x73) /* OFDM table data I */
  50. #define B43_PHY_OTABLEQ B43_PHY_OFDM(0x74) /* OFDM table data Q */
  51. #define B43_PHY_HPWR_TSSICTL B43_PHY_OFDM(0x78) /* Hardware power TSSI control */
  52. #define B43_PHY_ADCCTL B43_PHY_OFDM(0x7A) /* ADC control */
  53. #define B43_PHY_IDLE_TSSI B43_PHY_OFDM(0x7B)
  54. #define B43_PHY_A_TEMP_SENSE B43_PHY_OFDM(0x7C) /* A PHY temperature sense */
  55. #define B43_PHY_NRSSITHRES B43_PHY_OFDM(0x8A) /* NRSSI threshold */
  56. #define B43_PHY_ANTWRSETT B43_PHY_OFDM(0x8C) /* Antenna WR settle */
  57. #define B43_PHY_ANTWRSETT_ARXDIV 0x2000 /* Automatic RX diversity enabled */
  58. #define B43_PHY_CLIPPWRDOWNT B43_PHY_OFDM(0x93) /* Clip powerdown threshold */
  59. #define B43_PHY_OFDM9B B43_PHY_OFDM(0x9B) /* FIXME rename */
  60. #define B43_PHY_N1P1GAIN B43_PHY_OFDM(0xA0)
  61. #define B43_PHY_P1P2GAIN B43_PHY_OFDM(0xA1)
  62. #define B43_PHY_N1N2GAIN B43_PHY_OFDM(0xA2)
  63. #define B43_PHY_CLIPTHRES B43_PHY_OFDM(0xA3)
  64. #define B43_PHY_CLIPN1P2THRES B43_PHY_OFDM(0xA4)
  65. #define B43_PHY_CCKSHIFTBITS_WA B43_PHY_OFDM(0xA5) /* CCK shiftbits workaround, FIXME rename */
  66. #define B43_PHY_CCKSHIFTBITS B43_PHY_OFDM(0xA7) /* FIXME rename */
  67. #define B43_PHY_DIVSRCHIDX B43_PHY_OFDM(0xA8) /* Divider search gain/index */
  68. #define B43_PHY_CLIPP2THRES B43_PHY_OFDM(0xA9)
  69. #define B43_PHY_CLIPP3THRES B43_PHY_OFDM(0xAA)
  70. #define B43_PHY_DIVP1P2GAIN B43_PHY_OFDM(0xAB)
  71. #define B43_PHY_DIVSRCHGAINBACK B43_PHY_OFDM(0xAD) /* Divider search gain back */
  72. #define B43_PHY_DIVSRCHGAINCHNG B43_PHY_OFDM(0xAE) /* Divider search gain change */
  73. #define B43_PHY_CRSTHRES1 B43_PHY_OFDM(0xC0) /* CRS Threshold 1 (phy.rev >= 2 only) */
  74. #define B43_PHY_CRSTHRES2 B43_PHY_OFDM(0xC1) /* CRS Threshold 2 (phy.rev >= 2 only) */
  75. #define B43_PHY_TSSIP_LTBASE B43_PHY_OFDM(0x380) /* TSSI power lookup table base */
  76. #define B43_PHY_DC_LTBASE B43_PHY_OFDM(0x3A0) /* DC lookup table base */
  77. #define B43_PHY_GAIN_LTBASE B43_PHY_OFDM(0x3C0) /* Gain lookup table base */
  78. /* CCK (B) PHY Registers */
  79. #define B43_PHY_VERSION_CCK B43_PHY_CCK(0x00) /* Versioning register for B-PHY */
  80. #define B43_PHY_CCKBBANDCFG B43_PHY_CCK(0x01) /* Contains antenna 0/1 control bit */
  81. #define B43_PHY_PGACTL B43_PHY_CCK(0x15) /* PGA control */
  82. #define B43_PHY_PGACTL_LPF 0x1000 /* Low pass filter (?) */
  83. #define B43_PHY_PGACTL_LOWBANDW 0x0040 /* Low bandwidth flag */
  84. #define B43_PHY_PGACTL_UNKNOWN 0xEFA0
  85. #define B43_PHY_FBCTL1 B43_PHY_CCK(0x18) /* Frequency bandwidth control 1 */
  86. #define B43_PHY_ITSSI B43_PHY_CCK(0x29) /* Idle TSSI */
  87. #define B43_PHY_LO_LEAKAGE B43_PHY_CCK(0x2D) /* Measured LO leakage */
  88. #define B43_PHY_ENERGY B43_PHY_CCK(0x33) /* Energy */
  89. #define B43_PHY_SYNCCTL B43_PHY_CCK(0x35)
  90. #define B43_PHY_FBCTL2 B43_PHY_CCK(0x38) /* Frequency bandwidth control 2 */
  91. #define B43_PHY_DACCTL B43_PHY_CCK(0x60) /* DAC control */
  92. #define B43_PHY_RCCALOVER B43_PHY_CCK(0x78) /* RC calibration override */
  93. /* Extended G-PHY Registers */
  94. #define B43_PHY_CLASSCTL B43_PHY_EXTG(0x02) /* Classify control */
  95. #define B43_PHY_GTABCTL B43_PHY_EXTG(0x03) /* G-PHY table control (see below) */
  96. #define B43_PHY_GTABOFF 0x03FF /* G-PHY table offset (see below) */
  97. #define B43_PHY_GTABNR 0xFC00 /* G-PHY table number (see below) */
  98. #define B43_PHY_GTABNR_SHIFT 10
  99. #define B43_PHY_GTABDATA B43_PHY_EXTG(0x04) /* G-PHY table data */
  100. #define B43_PHY_LO_MASK B43_PHY_EXTG(0x0F) /* Local Oscillator control mask */
  101. #define B43_PHY_LO_CTL B43_PHY_EXTG(0x10) /* Local Oscillator control */
  102. #define B43_PHY_RFOVER B43_PHY_EXTG(0x11) /* RF override */
  103. #define B43_PHY_RFOVERVAL B43_PHY_EXTG(0x12) /* RF override value */
  104. #define B43_PHY_RFOVERVAL_EXTLNA 0x8000
  105. #define B43_PHY_RFOVERVAL_LNA 0x7000
  106. #define B43_PHY_RFOVERVAL_LNA_SHIFT 12
  107. #define B43_PHY_RFOVERVAL_PGA 0x0F00
  108. #define B43_PHY_RFOVERVAL_PGA_SHIFT 8
  109. #define B43_PHY_RFOVERVAL_UNK 0x0010 /* Unknown, always set. */
  110. #define B43_PHY_RFOVERVAL_TRSWRX 0x00E0
  111. #define B43_PHY_RFOVERVAL_BW 0x0003 /* Bandwidth flags */
  112. #define B43_PHY_RFOVERVAL_BW_LPF 0x0001 /* Low Pass Filter */
  113. #define B43_PHY_RFOVERVAL_BW_LBW 0x0002 /* Low Bandwidth (when set), high when unset */
  114. #define B43_PHY_ANALOGOVER B43_PHY_EXTG(0x14) /* Analog override */
  115. #define B43_PHY_ANALOGOVERVAL B43_PHY_EXTG(0x15) /* Analog override value */
  116. /*** OFDM table numbers ***/
  117. #define B43_OFDMTAB(number, offset) (((number) << B43_PHY_OTABLENR_SHIFT) | (offset))
  118. #define B43_OFDMTAB_AGC1 B43_OFDMTAB(0x00, 0)
  119. #define B43_OFDMTAB_GAIN0 B43_OFDMTAB(0x00, 0)
  120. #define B43_OFDMTAB_GAINX B43_OFDMTAB(0x01, 0) //TODO rename
  121. #define B43_OFDMTAB_GAIN1 B43_OFDMTAB(0x01, 4)
  122. #define B43_OFDMTAB_AGC3 B43_OFDMTAB(0x02, 0)
  123. #define B43_OFDMTAB_GAIN2 B43_OFDMTAB(0x02, 3)
  124. #define B43_OFDMTAB_LNAHPFGAIN1 B43_OFDMTAB(0x03, 0)
  125. #define B43_OFDMTAB_WRSSI B43_OFDMTAB(0x04, 0)
  126. #define B43_OFDMTAB_LNAHPFGAIN2 B43_OFDMTAB(0x04, 0)
  127. #define B43_OFDMTAB_NOISESCALE B43_OFDMTAB(0x05, 0)
  128. #define B43_OFDMTAB_AGC2 B43_OFDMTAB(0x06, 0)
  129. #define B43_OFDMTAB_ROTOR B43_OFDMTAB(0x08, 0)
  130. #define B43_OFDMTAB_ADVRETARD B43_OFDMTAB(0x09, 0)
  131. #define B43_OFDMTAB_DAC B43_OFDMTAB(0x0C, 0)
  132. #define B43_OFDMTAB_DC B43_OFDMTAB(0x0E, 7)
  133. #define B43_OFDMTAB_PWRDYN2 B43_OFDMTAB(0x0E, 12)
  134. #define B43_OFDMTAB_LNAGAIN B43_OFDMTAB(0x0E, 13)
  135. #define B43_OFDMTAB_UNKNOWN_0F B43_OFDMTAB(0x0F, 0) //TODO rename
  136. #define B43_OFDMTAB_UNKNOWN_APHY B43_OFDMTAB(0x0F, 7) //TODO rename
  137. #define B43_OFDMTAB_LPFGAIN B43_OFDMTAB(0x0F, 12)
  138. #define B43_OFDMTAB_RSSI B43_OFDMTAB(0x10, 0)
  139. #define B43_OFDMTAB_UNKNOWN_11 B43_OFDMTAB(0x11, 4) //TODO rename
  140. #define B43_OFDMTAB_AGC1_R1 B43_OFDMTAB(0x13, 0)
  141. #define B43_OFDMTAB_GAINX_R1 B43_OFDMTAB(0x14, 0) //TODO remove!
  142. #define B43_OFDMTAB_MINSIGSQ B43_OFDMTAB(0x14, 0)
  143. #define B43_OFDMTAB_AGC3_R1 B43_OFDMTAB(0x15, 0)
  144. #define B43_OFDMTAB_WRSSI_R1 B43_OFDMTAB(0x15, 4)
  145. #define B43_OFDMTAB_TSSI B43_OFDMTAB(0x15, 0)
  146. #define B43_OFDMTAB_DACRFPABB B43_OFDMTAB(0x16, 0)
  147. #define B43_OFDMTAB_DACOFF B43_OFDMTAB(0x17, 0)
  148. #define B43_OFDMTAB_DCBIAS B43_OFDMTAB(0x18, 0)
  149. u16 b43_ofdmtab_read16(struct b43_wldev *dev, u16 table, u16 offset);
  150. void b43_ofdmtab_write16(struct b43_wldev *dev, u16 table,
  151. u16 offset, u16 value);
  152. u32 b43_ofdmtab_read32(struct b43_wldev *dev, u16 table, u16 offset);
  153. void b43_ofdmtab_write32(struct b43_wldev *dev, u16 table,
  154. u16 offset, u32 value);
  155. /*** G-PHY table numbers */
  156. #define B43_GTAB(number, offset) (((number) << B43_PHY_GTABNR_SHIFT) | (offset))
  157. #define B43_GTAB_NRSSI B43_GTAB(0x00, 0)
  158. #define B43_GTAB_TRFEMW B43_GTAB(0x0C, 0x120)
  159. #define B43_GTAB_ORIGTR B43_GTAB(0x2E, 0x298)
  160. u16 b43_gtab_read(struct b43_wldev *dev, u16 table, u16 offset); //TODO implement
  161. void b43_gtab_write(struct b43_wldev *dev, u16 table, u16 offset, u16 value); //TODO implement
  162. #define B43_DEFAULT_CHANNEL_A 36
  163. #define B43_DEFAULT_CHANNEL_BG 6
  164. enum {
  165. B43_ANTENNA0, /* Antenna 0 */
  166. B43_ANTENNA1, /* Antenna 0 */
  167. B43_ANTENNA_AUTO1, /* Automatic, starting with antenna 1 */
  168. B43_ANTENNA_AUTO0, /* Automatic, starting with antenna 0 */
  169. B43_ANTENNA2,
  170. B43_ANTENNA3 = 8,
  171. B43_ANTENNA_AUTO = B43_ANTENNA_AUTO0,
  172. B43_ANTENNA_DEFAULT = B43_ANTENNA_AUTO,
  173. };
  174. enum {
  175. B43_INTERFMODE_NONE,
  176. B43_INTERFMODE_NONWLAN,
  177. B43_INTERFMODE_MANUALWLAN,
  178. B43_INTERFMODE_AUTOWLAN,
  179. };
  180. /* Masks for the different PHY versioning registers. */
  181. #define B43_PHYVER_ANALOG 0xF000
  182. #define B43_PHYVER_ANALOG_SHIFT 12
  183. #define B43_PHYVER_TYPE 0x0F00
  184. #define B43_PHYVER_TYPE_SHIFT 8
  185. #define B43_PHYVER_VERSION 0x00FF
  186. void b43_phy_lock(struct b43_wldev *dev);
  187. void b43_phy_unlock(struct b43_wldev *dev);
  188. /* Read a value from a PHY register */
  189. u16 b43_phy_read(struct b43_wldev *dev, u16 offset);
  190. /* Write a value to a PHY register */
  191. void b43_phy_write(struct b43_wldev *dev, u16 offset, u16 val);
  192. /* Mask a PHY register with a mask */
  193. void b43_phy_mask(struct b43_wldev *dev, u16 offset, u16 mask);
  194. /* OR a PHY register with a bitmap */
  195. void b43_phy_set(struct b43_wldev *dev, u16 offset, u16 set);
  196. /* Mask and OR a PHY register with a mask and bitmap */
  197. void b43_phy_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set);
  198. int b43_phy_init_tssi2dbm_table(struct b43_wldev *dev);
  199. void b43_phy_early_init(struct b43_wldev *dev);
  200. int b43_phy_init(struct b43_wldev *dev);
  201. void b43_set_rx_antenna(struct b43_wldev *dev, int antenna);
  202. void b43_phy_xmitpower(struct b43_wldev *dev);
  203. void b43_gphy_dc_lt_init(struct b43_wldev *dev);
  204. /* Returns the boolean whether the board has HardwarePowerControl */
  205. bool b43_has_hardware_pctl(struct b43_phy *phy);
  206. /* Returns the boolean whether "TX Magnification" is enabled. */
  207. #define has_tx_magnification(phy) \
  208. (((phy)->rev >= 2) && \
  209. ((phy)->radio_ver == 0x2050) && \
  210. ((phy)->radio_rev == 8))
  211. /* Card uses the loopback gain stuff */
  212. #define has_loopback_gain(phy) \
  213. (((phy)->rev > 1) || ((phy)->gmode))
  214. /* Radio Attenuation (RF Attenuation) */
  215. struct b43_rfatt {
  216. u8 att; /* Attenuation value */
  217. bool with_padmix; /* Flag, PAD Mixer enabled. */
  218. };
  219. struct b43_rfatt_list {
  220. /* Attenuation values list */
  221. const struct b43_rfatt *list;
  222. u8 len;
  223. /* Minimum/Maximum attenuation values */
  224. u8 min_val;
  225. u8 max_val;
  226. };
  227. /* Baseband Attenuation */
  228. struct b43_bbatt {
  229. u8 att; /* Attenuation value */
  230. };
  231. struct b43_bbatt_list {
  232. /* Attenuation values list */
  233. const struct b43_bbatt *list;
  234. u8 len;
  235. /* Minimum/Maximum attenuation values */
  236. u8 min_val;
  237. u8 max_val;
  238. };
  239. /* tx_control bits. */
  240. #define B43_TXCTL_PA3DB 0x40 /* PA Gain 3dB */
  241. #define B43_TXCTL_PA2DB 0x20 /* PA Gain 2dB */
  242. #define B43_TXCTL_TXMIX 0x10 /* TX Mixer Gain */
  243. /* Write BasebandAttenuation value to the device. */
  244. void b43_phy_set_baseband_attenuation(struct b43_wldev *dev,
  245. u16 baseband_attenuation);
  246. extern const u8 b43_radio_channel_codes_bg[];
  247. void b43_radio_lock(struct b43_wldev *dev);
  248. void b43_radio_unlock(struct b43_wldev *dev);
  249. /* Read a value from a 16bit radio register */
  250. u16 b43_radio_read16(struct b43_wldev *dev, u16 offset);
  251. /* Write a value to a 16bit radio register */
  252. void b43_radio_write16(struct b43_wldev *dev, u16 offset, u16 val);
  253. /* Mask a 16bit radio register with a mask */
  254. void b43_radio_mask(struct b43_wldev *dev, u16 offset, u16 mask);
  255. /* OR a 16bit radio register with a bitmap */
  256. void b43_radio_set(struct b43_wldev *dev, u16 offset, u16 set);
  257. /* Mask and OR a PHY register with a mask and bitmap */
  258. void b43_radio_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set);
  259. u16 b43_radio_init2050(struct b43_wldev *dev);
  260. void b43_radio_init2060(struct b43_wldev *dev);
  261. void b43_radio_turn_on(struct b43_wldev *dev);
  262. void b43_radio_turn_off(struct b43_wldev *dev, bool force);
  263. int b43_radio_selectchannel(struct b43_wldev *dev, u8 channel,
  264. int synthetic_pu_workaround);
  265. u8 b43_radio_aci_detect(struct b43_wldev *dev, u8 channel);
  266. u8 b43_radio_aci_scan(struct b43_wldev *dev);
  267. int b43_radio_set_interference_mitigation(struct b43_wldev *dev, int mode);
  268. void b43_calc_nrssi_slope(struct b43_wldev *dev);
  269. void b43_calc_nrssi_threshold(struct b43_wldev *dev);
  270. s16 b43_nrssi_hw_read(struct b43_wldev *dev, u16 offset);
  271. void b43_nrssi_hw_write(struct b43_wldev *dev, u16 offset, s16 val);
  272. void b43_nrssi_hw_update(struct b43_wldev *dev, u16 val);
  273. void b43_nrssi_mem_update(struct b43_wldev *dev);
  274. void b43_radio_set_tx_iq(struct b43_wldev *dev);
  275. u16 b43_radio_calibrationvalue(struct b43_wldev *dev);
  276. void b43_put_attenuation_into_ranges(struct b43_wldev *dev,
  277. int *_bbatt, int *_rfatt);
  278. void b43_set_txpower_g(struct b43_wldev *dev,
  279. const struct b43_bbatt *bbatt,
  280. const struct b43_rfatt *rfatt, u8 tx_control);
  281. #endif /* B43_PHY_H_ */