rtl8180_grf5101.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Radio tuning for GCT GRF5101 on RTL8180
  3. *
  4. * Copyright 2007 Andrea Merello <andreamrl@tiscali.it>
  5. *
  6. * Code from the BSD driver and the rtl8181 project have been
  7. * very useful to understand certain things
  8. *
  9. * I want to thanks the Authors of such projects and the Ndiswrapper
  10. * project Authors.
  11. *
  12. * A special Big Thanks also is for all people who donated me cards,
  13. * making possible the creation of the original rtl8180 driver
  14. * from which this code is derived!
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License version 2 as
  18. * published by the Free Software Foundation.
  19. */
  20. #include <linux/init.h>
  21. #include <linux/pci.h>
  22. #include <linux/delay.h>
  23. #include <net/mac80211.h>
  24. #include "rtl8180.h"
  25. #include "rtl8180_grf5101.h"
  26. static const int grf5101_encode[] = {
  27. 0x0, 0x8, 0x4, 0xC,
  28. 0x2, 0xA, 0x6, 0xE,
  29. 0x1, 0x9, 0x5, 0xD,
  30. 0x3, 0xB, 0x7, 0xF
  31. };
  32. static void write_grf5101(struct ieee80211_hw *dev, u8 addr, u32 data)
  33. {
  34. struct rtl8180_priv *priv = dev->priv;
  35. u32 phy_config;
  36. phy_config = grf5101_encode[(data >> 8) & 0xF];
  37. phy_config |= grf5101_encode[(data >> 4) & 0xF] << 4;
  38. phy_config |= grf5101_encode[data & 0xF] << 8;
  39. phy_config |= grf5101_encode[(addr >> 1) & 0xF] << 12;
  40. phy_config |= (addr & 1) << 16;
  41. phy_config |= grf5101_encode[(data & 0xf000) >> 12] << 24;
  42. /* MAC will bang bits to the chip */
  43. phy_config |= 0x90000000;
  44. rtl818x_iowrite32(priv,
  45. (__le32 __iomem *) &priv->map->RFPinsOutput, phy_config);
  46. msleep(3);
  47. }
  48. static void grf5101_write_phy_antenna(struct ieee80211_hw *dev, short chan)
  49. {
  50. struct rtl8180_priv *priv = dev->priv;
  51. u8 ant = GRF5101_ANTENNA;
  52. if (priv->rfparam & RF_PARAM_ANTBDEFAULT)
  53. ant |= BB_ANTENNA_B;
  54. if (chan == 14)
  55. ant |= BB_ANTATTEN_CHAN14;
  56. rtl8180_write_phy(dev, 0x10, ant);
  57. }
  58. static void grf5101_rf_set_channel(struct ieee80211_hw *dev,
  59. struct ieee80211_conf *conf)
  60. {
  61. struct rtl8180_priv *priv = dev->priv;
  62. int channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
  63. u32 txpw = priv->channels[channel - 1].hw_value & 0xFF;
  64. u32 chan = channel - 1;
  65. /* set TX power */
  66. write_grf5101(dev, 0x15, 0x0);
  67. write_grf5101(dev, 0x06, txpw);
  68. write_grf5101(dev, 0x15, 0x10);
  69. write_grf5101(dev, 0x15, 0x0);
  70. /* set frequency */
  71. write_grf5101(dev, 0x07, 0x0);
  72. write_grf5101(dev, 0x0B, chan);
  73. write_grf5101(dev, 0x07, 0x1000);
  74. grf5101_write_phy_antenna(dev, channel);
  75. }
  76. static void grf5101_rf_stop(struct ieee80211_hw *dev)
  77. {
  78. struct rtl8180_priv *priv = dev->priv;
  79. u32 anaparam;
  80. anaparam = priv->anaparam;
  81. anaparam &= 0x000fffff;
  82. anaparam |= 0x3f900000;
  83. rtl8180_set_anaparam(priv, anaparam);
  84. write_grf5101(dev, 0x07, 0x0);
  85. write_grf5101(dev, 0x1f, 0x45);
  86. write_grf5101(dev, 0x1f, 0x5);
  87. write_grf5101(dev, 0x00, 0x8e4);
  88. }
  89. static void grf5101_rf_init(struct ieee80211_hw *dev)
  90. {
  91. struct rtl8180_priv *priv = dev->priv;
  92. rtl8180_set_anaparam(priv, priv->anaparam);
  93. write_grf5101(dev, 0x1f, 0x0);
  94. write_grf5101(dev, 0x1f, 0x0);
  95. write_grf5101(dev, 0x1f, 0x40);
  96. write_grf5101(dev, 0x1f, 0x60);
  97. write_grf5101(dev, 0x1f, 0x61);
  98. write_grf5101(dev, 0x1f, 0x61);
  99. write_grf5101(dev, 0x00, 0xae4);
  100. write_grf5101(dev, 0x1f, 0x1);
  101. write_grf5101(dev, 0x1f, 0x41);
  102. write_grf5101(dev, 0x1f, 0x61);
  103. write_grf5101(dev, 0x01, 0x1a23);
  104. write_grf5101(dev, 0x02, 0x4971);
  105. write_grf5101(dev, 0x03, 0x41de);
  106. write_grf5101(dev, 0x04, 0x2d80);
  107. write_grf5101(dev, 0x05, 0x68ff); /* 0x61ff original value */
  108. write_grf5101(dev, 0x06, 0x0);
  109. write_grf5101(dev, 0x07, 0x0);
  110. write_grf5101(dev, 0x08, 0x7533);
  111. write_grf5101(dev, 0x09, 0xc401);
  112. write_grf5101(dev, 0x0a, 0x0);
  113. write_grf5101(dev, 0x0c, 0x1c7);
  114. write_grf5101(dev, 0x0d, 0x29d3);
  115. write_grf5101(dev, 0x0e, 0x2e8);
  116. write_grf5101(dev, 0x10, 0x192);
  117. write_grf5101(dev, 0x11, 0x248);
  118. write_grf5101(dev, 0x12, 0x0);
  119. write_grf5101(dev, 0x13, 0x20c4);
  120. write_grf5101(dev, 0x14, 0xf4fc);
  121. write_grf5101(dev, 0x15, 0x0);
  122. write_grf5101(dev, 0x16, 0x1500);
  123. write_grf5101(dev, 0x07, 0x1000);
  124. /* baseband configuration */
  125. rtl8180_write_phy(dev, 0, 0xa8);
  126. rtl8180_write_phy(dev, 3, 0x0);
  127. rtl8180_write_phy(dev, 4, 0xc0);
  128. rtl8180_write_phy(dev, 5, 0x90);
  129. rtl8180_write_phy(dev, 6, 0x1e);
  130. rtl8180_write_phy(dev, 7, 0x64);
  131. grf5101_write_phy_antenna(dev, 1);
  132. rtl8180_write_phy(dev, 0x11, 0x88);
  133. if (rtl818x_ioread8(priv, &priv->map->CONFIG2) &
  134. RTL818X_CONFIG2_ANTENNA_DIV)
  135. rtl8180_write_phy(dev, 0x12, 0xc0); /* enable ant diversity */
  136. else
  137. rtl8180_write_phy(dev, 0x12, 0x40); /* disable ant diversity */
  138. rtl8180_write_phy(dev, 0x13, 0x90 | priv->csthreshold);
  139. rtl8180_write_phy(dev, 0x19, 0x0);
  140. rtl8180_write_phy(dev, 0x1a, 0xa0);
  141. rtl8180_write_phy(dev, 0x1b, 0x44);
  142. }
  143. const struct rtl818x_rf_ops grf5101_rf_ops = {
  144. .name = "GCT",
  145. .init = grf5101_rf_init,
  146. .stop = grf5101_rf_stop,
  147. .set_chan = grf5101_rf_set_channel
  148. };