Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

rtl8180_sa2400.c 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Radio tuning for Philips SA2400 on RTL8180
  3. *
  4. * Copyright 2007 Andrea Merello <andreamrl@tiscali.it>
  5. *
  6. * Modified slightly for iPXE, June 2009 by Joshua Oreman.
  7. *
  8. * Code from the BSD driver and the rtl8181 project have been
  9. * very useful to understand certain things
  10. *
  11. * I want to thanks the Authors of such projects and the Ndiswrapper
  12. * project Authors.
  13. *
  14. * A special Big Thanks also is for all people who donated me cards,
  15. * making possible the creation of the original rtl8180 driver
  16. * from which this code is derived!
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License version 2 as
  20. * published by the Free Software Foundation.
  21. */
  22. #include <unistd.h>
  23. #include <ipxe/pci.h>
  24. #include <ipxe/net80211.h>
  25. #include "rtl818x.h"
  26. FILE_LICENCE(GPL2_ONLY);
  27. #define SA2400_ANTENNA 0x91
  28. #define SA2400_DIG_ANAPARAM_PWR1_ON 0x8
  29. #define SA2400_ANA_ANAPARAM_PWR1_ON 0x28
  30. #define SA2400_ANAPARAM_PWR0_ON 0x3
  31. /* RX sensitivity in dbm */
  32. #define SA2400_MAX_SENS 85
  33. #define SA2400_REG4_FIRDAC_SHIFT 7
  34. static const u32 sa2400_chan[] = {
  35. 0x00096c, /* ch1 */
  36. 0x080970,
  37. 0x100974,
  38. 0x180978,
  39. 0x000980,
  40. 0x080984,
  41. 0x100988,
  42. 0x18098c,
  43. 0x000994,
  44. 0x080998,
  45. 0x10099c,
  46. 0x1809a0,
  47. 0x0009a8,
  48. 0x0009b4, /* ch 14 */
  49. };
  50. static void write_sa2400(struct net80211_device *dev, u8 addr, u32 data)
  51. {
  52. struct rtl818x_priv *priv = dev->priv;
  53. u32 phy_config;
  54. /* MAC will bang bits to the sa2400. sw 3-wire is NOT used */
  55. phy_config = 0xb0000000;
  56. phy_config |= ((u32)(addr & 0xf)) << 24;
  57. phy_config |= data & 0xffffff;
  58. /* This was originally a 32-bit write to a typecast
  59. RFPinsOutput, but gcc complained about aliasing rules. -JBO */
  60. rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, phy_config & 0xffff);
  61. rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, phy_config >> 16);
  62. mdelay(3);
  63. }
  64. static void sa2400_write_phy_antenna(struct net80211_device *dev, short chan)
  65. {
  66. struct rtl818x_priv *priv = dev->priv;
  67. u8 ant = SA2400_ANTENNA;
  68. if (priv->rfparam & RF_PARAM_ANTBDEFAULT)
  69. ant |= BB_ANTENNA_B;
  70. if (chan == 14)
  71. ant |= BB_ANTATTEN_CHAN14;
  72. rtl818x_write_phy(dev, 0x10, ant);
  73. }
  74. static void sa2400_rf_set_channel(struct net80211_device *dev,
  75. struct net80211_channel *channelp)
  76. {
  77. struct rtl818x_priv *priv = dev->priv;
  78. int channel = channelp->channel_nr;
  79. u32 txpw = priv->txpower[channel - 1] & 0xFF;
  80. u32 chan = sa2400_chan[channel - 1];
  81. write_sa2400(dev, 7, txpw);
  82. sa2400_write_phy_antenna(dev, channel);
  83. write_sa2400(dev, 0, chan);
  84. write_sa2400(dev, 1, 0xbb50);
  85. write_sa2400(dev, 2, 0x80);
  86. write_sa2400(dev, 3, 0);
  87. }
  88. static void sa2400_rf_stop(struct net80211_device *dev)
  89. {
  90. write_sa2400(dev, 4, 0);
  91. }
  92. static void sa2400_rf_init(struct net80211_device *dev)
  93. {
  94. struct rtl818x_priv *priv = dev->priv;
  95. u32 anaparam, txconf;
  96. u8 firdac;
  97. int analogphy = priv->rfparam & RF_PARAM_ANALOGPHY;
  98. anaparam = priv->anaparam;
  99. anaparam &= ~(1 << ANAPARAM_TXDACOFF_SHIFT);
  100. anaparam &= ~ANAPARAM_PWR1_MASK;
  101. anaparam &= ~ANAPARAM_PWR0_MASK;
  102. if (analogphy) {
  103. anaparam |= SA2400_ANA_ANAPARAM_PWR1_ON << ANAPARAM_PWR1_SHIFT;
  104. firdac = 0;
  105. } else {
  106. anaparam |= (SA2400_DIG_ANAPARAM_PWR1_ON << ANAPARAM_PWR1_SHIFT);
  107. anaparam |= (SA2400_ANAPARAM_PWR0_ON << ANAPARAM_PWR0_SHIFT);
  108. firdac = 1 << SA2400_REG4_FIRDAC_SHIFT;
  109. }
  110. rtl818x_set_anaparam(priv, anaparam);
  111. write_sa2400(dev, 0, sa2400_chan[0]);
  112. write_sa2400(dev, 1, 0xbb50);
  113. write_sa2400(dev, 2, 0x80);
  114. write_sa2400(dev, 3, 0);
  115. write_sa2400(dev, 4, 0x19340 | firdac);
  116. write_sa2400(dev, 5, 0x1dfb | (SA2400_MAX_SENS - 54) << 15);
  117. write_sa2400(dev, 4, 0x19348 | firdac); /* calibrate VCO */
  118. if (!analogphy)
  119. write_sa2400(dev, 4, 0x1938c); /*???*/
  120. write_sa2400(dev, 4, 0x19340 | firdac);
  121. write_sa2400(dev, 0, sa2400_chan[0]);
  122. write_sa2400(dev, 1, 0xbb50);
  123. write_sa2400(dev, 2, 0x80);
  124. write_sa2400(dev, 3, 0);
  125. write_sa2400(dev, 4, 0x19344 | firdac); /* calibrate filter */
  126. /* new from rtl8180 embedded driver (rtl8181 project) */
  127. write_sa2400(dev, 6, 0x13ff | (1 << 23)); /* MANRX */
  128. write_sa2400(dev, 8, 0); /* VCO */
  129. if (analogphy) {
  130. rtl818x_set_anaparam(priv, anaparam |
  131. (1 << ANAPARAM_TXDACOFF_SHIFT));
  132. txconf = rtl818x_ioread32(priv, &priv->map->TX_CONF);
  133. rtl818x_iowrite32(priv, &priv->map->TX_CONF,
  134. txconf | RTL818X_TX_CONF_LOOPBACK_CONT);
  135. write_sa2400(dev, 4, 0x19341); /* calibrates DC */
  136. /* a 5us delay is required here,
  137. * we rely on the 3ms delay introduced in write_sa2400 */
  138. write_sa2400(dev, 4, 0x19345);
  139. /* a 20us delay is required here,
  140. * we rely on the 3ms delay introduced in write_sa2400 */
  141. rtl818x_iowrite32(priv, &priv->map->TX_CONF, txconf);
  142. rtl818x_set_anaparam(priv, anaparam);
  143. }
  144. /* end new code */
  145. write_sa2400(dev, 4, 0x19341 | firdac); /* RTX MODE */
  146. /* baseband configuration */
  147. rtl818x_write_phy(dev, 0, 0x98);
  148. rtl818x_write_phy(dev, 3, 0x38);
  149. rtl818x_write_phy(dev, 4, 0xe0);
  150. rtl818x_write_phy(dev, 5, 0x90);
  151. rtl818x_write_phy(dev, 6, 0x1a);
  152. rtl818x_write_phy(dev, 7, 0x64);
  153. sa2400_write_phy_antenna(dev, 1);
  154. rtl818x_write_phy(dev, 0x11, 0x80);
  155. if (rtl818x_ioread8(priv, &priv->map->CONFIG2) &
  156. RTL818X_CONFIG2_ANTENNA_DIV)
  157. rtl818x_write_phy(dev, 0x12, 0xc7); /* enable ant diversity */
  158. else
  159. rtl818x_write_phy(dev, 0x12, 0x47); /* disable ant diversity */
  160. rtl818x_write_phy(dev, 0x13, 0x90 | priv->csthreshold);
  161. rtl818x_write_phy(dev, 0x19, 0x0);
  162. rtl818x_write_phy(dev, 0x1a, 0xa0);
  163. }
  164. struct rtl818x_rf_ops sa2400_rf_ops __rtl818x_rf_driver = {
  165. .name = "Philips SA2400",
  166. .id = 3,
  167. .init = sa2400_rf_init,
  168. .stop = sa2400_rf_stop,
  169. .set_chan = sa2400_rf_set_channel
  170. };