ar9003_phy.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. /* TODO */
  98. }
  99. static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
  100. struct ath9k_channel *chan)
  101. {
  102. u32 pll;
  103. pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
  104. if (chan && IS_CHAN_HALF_RATE(chan))
  105. pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
  106. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  107. pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
  108. if (chan && IS_CHAN_5GHZ(chan)) {
  109. pll |= SM(0x28, AR_RTC_9300_PLL_DIV);
  110. /*
  111. * When doing fast clock, set PLL to 0x142c
  112. */
  113. if (IS_CHAN_A_5MHZ_SPACED(chan))
  114. pll = 0x142c;
  115. } else
  116. pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
  117. return pll;
  118. }
  119. static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
  120. struct ath9k_channel *chan)
  121. {
  122. /* TODO */
  123. }
  124. static void ar9003_hw_init_bb(struct ath_hw *ah,
  125. struct ath9k_channel *chan)
  126. {
  127. /* TODO */
  128. }
  129. static int ar9003_hw_process_ini(struct ath_hw *ah,
  130. struct ath9k_channel *chan)
  131. {
  132. /* TODO */
  133. return -1;
  134. }
  135. static void ar9003_hw_set_rfmode(struct ath_hw *ah,
  136. struct ath9k_channel *chan)
  137. {
  138. /* TODO */
  139. }
  140. static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
  141. {
  142. /* TODO */
  143. }
  144. static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
  145. struct ath9k_channel *chan)
  146. {
  147. /* TODO */
  148. }
  149. static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
  150. {
  151. /* TODO */
  152. return false;
  153. }
  154. static void ar9003_hw_rfbus_done(struct ath_hw *ah)
  155. {
  156. /* TODO */
  157. }
  158. static void ar9003_hw_enable_rfkill(struct ath_hw *ah)
  159. {
  160. /* TODO */
  161. }
  162. static void ar9003_hw_set_diversity(struct ath_hw *ah, bool value)
  163. {
  164. /* TODO */
  165. }
  166. void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
  167. {
  168. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  169. priv_ops->rf_set_freq = ar9003_hw_set_channel;
  170. priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
  171. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
  172. priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
  173. priv_ops->init_bb = ar9003_hw_init_bb;
  174. priv_ops->process_ini = ar9003_hw_process_ini;
  175. priv_ops->set_rfmode = ar9003_hw_set_rfmode;
  176. priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
  177. priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
  178. priv_ops->rfbus_req = ar9003_hw_rfbus_req;
  179. priv_ops->rfbus_done = ar9003_hw_rfbus_done;
  180. priv_ops->enable_rfkill = ar9003_hw_enable_rfkill;
  181. priv_ops->set_diversity = ar9003_hw_set_diversity;
  182. }