ar9003_phy.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * Copyright (c) 2010 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "hw.h"
  17. #include "ar9003_phy.h"
  18. /**
  19. * ar9003_hw_set_channel - set channel on single-chip device
  20. * @ah: atheros hardware structure
  21. * @chan:
  22. *
  23. * This is the function to change channel on single-chip devices, that is
  24. * all devices after ar9280.
  25. *
  26. * This function takes the channel value in MHz and sets
  27. * hardware channel value. Assumes writes have been enabled to analog bus.
  28. *
  29. * Actual Expression,
  30. *
  31. * For 2GHz channel,
  32. * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  33. * (freq_ref = 40MHz)
  34. *
  35. * For 5GHz channel,
  36. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
  37. * (freq_ref = 40MHz/(24>>amodeRefSel))
  38. *
  39. * For 5GHz channels which are 5MHz spaced,
  40. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  41. * (freq_ref = 40MHz)
  42. */
  43. static int ar9003_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  44. {
  45. u16 bMode, fracMode = 0, aModeRefSel = 0;
  46. u32 freq, channelSel = 0, reg32 = 0;
  47. struct chan_centers centers;
  48. int loadSynthChannel;
  49. ath9k_hw_get_channel_centers(ah, chan, &centers);
  50. freq = centers.synth_center;
  51. if (freq < 4800) { /* 2 GHz, fractional mode */
  52. channelSel = CHANSEL_2G(freq);
  53. /* Set to 2G mode */
  54. bMode = 1;
  55. } else {
  56. channelSel = CHANSEL_5G(freq);
  57. /* Doubler is ON, so, divide channelSel by 2. */
  58. channelSel >>= 1;
  59. /* Set to 5G mode */
  60. bMode = 0;
  61. }
  62. /* Enable fractional mode for all channels */
  63. fracMode = 1;
  64. aModeRefSel = 0;
  65. loadSynthChannel = 0;
  66. reg32 = (bMode << 29);
  67. REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
  68. /* Enable Long shift Select for Synthesizer */
  69. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH4,
  70. AR_PHY_SYNTH4_LONG_SHIFT_SELECT, 1);
  71. /* Program Synth. setting */
  72. reg32 = (channelSel << 2) | (fracMode << 30) |
  73. (aModeRefSel << 28) | (loadSynthChannel << 31);
  74. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  75. /* Toggle Load Synth channel bit */
  76. loadSynthChannel = 1;
  77. reg32 = (channelSel << 2) | (fracMode << 30) |
  78. (aModeRefSel << 28) | (loadSynthChannel << 31);
  79. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  80. ah->curchan = chan;
  81. ah->curchan_rad_index = -1;
  82. return 0;
  83. }
  84. /**
  85. * ar9003_hw_spur_mitigate - convert baseband spur frequency
  86. * @ah: atheros hardware structure
  87. * @chan:
  88. *
  89. * For single-chip solutions. Converts to baseband spur frequency given the
  90. * input channel frequency and compute register settings below.
  91. *
  92. * Spur mitigation for MRC CCK
  93. */
  94. static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
  95. struct ath9k_channel *chan)
  96. {
  97. u32 spur_freq[4] = { 2420, 2440, 2464, 2480 };
  98. int cur_bb_spur, negative = 0, cck_spur_freq;
  99. int i;
  100. /*
  101. * Need to verify range +/- 10 MHz in control channel, otherwise spur
  102. * is out-of-band and can be ignored.
  103. */
  104. for (i = 0; i < 4; i++) {
  105. negative = 0;
  106. cur_bb_spur = spur_freq[i] - chan->channel;
  107. if (cur_bb_spur < 0) {
  108. negative = 1;
  109. cur_bb_spur = -cur_bb_spur;
  110. }
  111. if (cur_bb_spur < 10) {
  112. cck_spur_freq = (int)((cur_bb_spur << 19) / 11);
  113. if (negative == 1)
  114. cck_spur_freq = -cck_spur_freq;
  115. cck_spur_freq = cck_spur_freq & 0xfffff;
  116. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  117. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x7);
  118. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  119. AR_PHY_CCK_SPUR_MIT_SPUR_RSSI_THR, 0x7f);
  120. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  121. AR_PHY_CCK_SPUR_MIT_SPUR_FILTER_TYPE,
  122. 0x2);
  123. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  124. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT,
  125. 0x1);
  126. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  127. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ,
  128. cck_spur_freq);
  129. return;
  130. }
  131. }
  132. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  133. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x5);
  134. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  135. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 0x0);
  136. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  137. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 0x0);
  138. }
  139. static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
  140. struct ath9k_channel *chan)
  141. {
  142. u32 pll;
  143. pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
  144. if (chan && IS_CHAN_HALF_RATE(chan))
  145. pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
  146. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  147. pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
  148. if (chan && IS_CHAN_5GHZ(chan)) {
  149. pll |= SM(0x28, AR_RTC_9300_PLL_DIV);
  150. /*
  151. * When doing fast clock, set PLL to 0x142c
  152. */
  153. if (IS_CHAN_A_5MHZ_SPACED(chan))
  154. pll = 0x142c;
  155. } else
  156. pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
  157. return pll;
  158. }
  159. static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
  160. struct ath9k_channel *chan)
  161. {
  162. /* TODO */
  163. }
  164. static void ar9003_hw_init_bb(struct ath_hw *ah,
  165. struct ath9k_channel *chan)
  166. {
  167. /* TODO */
  168. }
  169. static int ar9003_hw_process_ini(struct ath_hw *ah,
  170. struct ath9k_channel *chan)
  171. {
  172. /* TODO */
  173. return -1;
  174. }
  175. static void ar9003_hw_set_rfmode(struct ath_hw *ah,
  176. struct ath9k_channel *chan)
  177. {
  178. /* TODO */
  179. }
  180. static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
  181. {
  182. /* TODO */
  183. }
  184. static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
  185. struct ath9k_channel *chan)
  186. {
  187. /* TODO */
  188. }
  189. static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
  190. {
  191. /* TODO */
  192. return false;
  193. }
  194. static void ar9003_hw_rfbus_done(struct ath_hw *ah)
  195. {
  196. /* TODO */
  197. }
  198. static void ar9003_hw_enable_rfkill(struct ath_hw *ah)
  199. {
  200. /* TODO */
  201. }
  202. static void ar9003_hw_set_diversity(struct ath_hw *ah, bool value)
  203. {
  204. /* TODO */
  205. }
  206. void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
  207. {
  208. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  209. priv_ops->rf_set_freq = ar9003_hw_set_channel;
  210. priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
  211. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
  212. priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
  213. priv_ops->init_bb = ar9003_hw_init_bb;
  214. priv_ops->process_ini = ar9003_hw_process_ini;
  215. priv_ops->set_rfmode = ar9003_hw_set_rfmode;
  216. priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
  217. priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
  218. priv_ops->rfbus_req = ar9003_hw_rfbus_req;
  219. priv_ops->rfbus_done = ar9003_hw_rfbus_done;
  220. priv_ops->enable_rfkill = ar9003_hw_enable_rfkill;
  221. priv_ops->set_diversity = ar9003_hw_set_diversity;
  222. }