You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rtl8180_grf5101.c 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Radio tuning for GCT GRF5101 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 GRF5101_ANTENNA 0xA3
  28. static const int grf5101_encode[] = {
  29. 0x0, 0x8, 0x4, 0xC,
  30. 0x2, 0xA, 0x6, 0xE,
  31. 0x1, 0x9, 0x5, 0xD,
  32. 0x3, 0xB, 0x7, 0xF
  33. };
  34. static void write_grf5101(struct net80211_device *dev, u8 addr, u32 data)
  35. {
  36. struct rtl818x_priv *priv = dev->priv;
  37. u32 phy_config;
  38. phy_config = grf5101_encode[(data >> 8) & 0xF];
  39. phy_config |= grf5101_encode[(data >> 4) & 0xF] << 4;
  40. phy_config |= grf5101_encode[data & 0xF] << 8;
  41. phy_config |= grf5101_encode[(addr >> 1) & 0xF] << 12;
  42. phy_config |= (addr & 1) << 16;
  43. phy_config |= grf5101_encode[(data & 0xf000) >> 12] << 24;
  44. /* MAC will bang bits to the chip */
  45. phy_config |= 0x90000000;
  46. /* This was originally a 32-bit write to a typecast
  47. RFPinsOutput, but gcc complained about aliasing rules. -JBO */
  48. rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, phy_config & 0xffff);
  49. rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, phy_config >> 16);
  50. mdelay(3);
  51. }
  52. static void grf5101_write_phy_antenna(struct net80211_device *dev, short chan)
  53. {
  54. struct rtl818x_priv *priv = dev->priv;
  55. u8 ant = GRF5101_ANTENNA;
  56. if (priv->rfparam & RF_PARAM_ANTBDEFAULT)
  57. ant |= BB_ANTENNA_B;
  58. if (chan == 14)
  59. ant |= BB_ANTATTEN_CHAN14;
  60. rtl818x_write_phy(dev, 0x10, ant);
  61. }
  62. static void grf5101_rf_set_channel(struct net80211_device *dev,
  63. struct net80211_channel *channelp)
  64. {
  65. struct rtl818x_priv *priv = dev->priv;
  66. int channel = channelp->channel_nr;
  67. u32 txpw = priv->txpower[channel - 1] & 0xFF;
  68. u32 chan = channel - 1;
  69. /* set TX power */
  70. write_grf5101(dev, 0x15, 0x0);
  71. write_grf5101(dev, 0x06, txpw);
  72. write_grf5101(dev, 0x15, 0x10);
  73. write_grf5101(dev, 0x15, 0x0);
  74. /* set frequency */
  75. write_grf5101(dev, 0x07, 0x0);
  76. write_grf5101(dev, 0x0B, chan);
  77. write_grf5101(dev, 0x07, 0x1000);
  78. grf5101_write_phy_antenna(dev, channel);
  79. }
  80. static void grf5101_rf_stop(struct net80211_device *dev)
  81. {
  82. struct rtl818x_priv *priv = dev->priv;
  83. u32 anaparam;
  84. anaparam = priv->anaparam;
  85. anaparam &= 0x000fffff;
  86. anaparam |= 0x3f900000;
  87. rtl818x_set_anaparam(priv, anaparam);
  88. write_grf5101(dev, 0x07, 0x0);
  89. write_grf5101(dev, 0x1f, 0x45);
  90. write_grf5101(dev, 0x1f, 0x5);
  91. write_grf5101(dev, 0x00, 0x8e4);
  92. }
  93. static void grf5101_rf_init(struct net80211_device *dev)
  94. {
  95. struct rtl818x_priv *priv = dev->priv;
  96. rtl818x_set_anaparam(priv, priv->anaparam);
  97. write_grf5101(dev, 0x1f, 0x0);
  98. write_grf5101(dev, 0x1f, 0x0);
  99. write_grf5101(dev, 0x1f, 0x40);
  100. write_grf5101(dev, 0x1f, 0x60);
  101. write_grf5101(dev, 0x1f, 0x61);
  102. write_grf5101(dev, 0x1f, 0x61);
  103. write_grf5101(dev, 0x00, 0xae4);
  104. write_grf5101(dev, 0x1f, 0x1);
  105. write_grf5101(dev, 0x1f, 0x41);
  106. write_grf5101(dev, 0x1f, 0x61);
  107. write_grf5101(dev, 0x01, 0x1a23);
  108. write_grf5101(dev, 0x02, 0x4971);
  109. write_grf5101(dev, 0x03, 0x41de);
  110. write_grf5101(dev, 0x04, 0x2d80);
  111. write_grf5101(dev, 0x05, 0x68ff); /* 0x61ff original value */
  112. write_grf5101(dev, 0x06, 0x0);
  113. write_grf5101(dev, 0x07, 0x0);
  114. write_grf5101(dev, 0x08, 0x7533);
  115. write_grf5101(dev, 0x09, 0xc401);
  116. write_grf5101(dev, 0x0a, 0x0);
  117. write_grf5101(dev, 0x0c, 0x1c7);
  118. write_grf5101(dev, 0x0d, 0x29d3);
  119. write_grf5101(dev, 0x0e, 0x2e8);
  120. write_grf5101(dev, 0x10, 0x192);
  121. write_grf5101(dev, 0x11, 0x248);
  122. write_grf5101(dev, 0x12, 0x0);
  123. write_grf5101(dev, 0x13, 0x20c4);
  124. write_grf5101(dev, 0x14, 0xf4fc);
  125. write_grf5101(dev, 0x15, 0x0);
  126. write_grf5101(dev, 0x16, 0x1500);
  127. write_grf5101(dev, 0x07, 0x1000);
  128. /* baseband configuration */
  129. rtl818x_write_phy(dev, 0, 0xa8);
  130. rtl818x_write_phy(dev, 3, 0x0);
  131. rtl818x_write_phy(dev, 4, 0xc0);
  132. rtl818x_write_phy(dev, 5, 0x90);
  133. rtl818x_write_phy(dev, 6, 0x1e);
  134. rtl818x_write_phy(dev, 7, 0x64);
  135. grf5101_write_phy_antenna(dev, 1);
  136. rtl818x_write_phy(dev, 0x11, 0x88);
  137. if (rtl818x_ioread8(priv, &priv->map->CONFIG2) &
  138. RTL818X_CONFIG2_ANTENNA_DIV)
  139. rtl818x_write_phy(dev, 0x12, 0xc0); /* enable ant diversity */
  140. else
  141. rtl818x_write_phy(dev, 0x12, 0x40); /* disable ant diversity */
  142. rtl818x_write_phy(dev, 0x13, 0x90 | priv->csthreshold);
  143. rtl818x_write_phy(dev, 0x19, 0x0);
  144. rtl818x_write_phy(dev, 0x1a, 0xa0);
  145. rtl818x_write_phy(dev, 0x1b, 0x44);
  146. }
  147. struct rtl818x_rf_ops grf5101_rf_ops __rtl818x_rf_driver = {
  148. .name = "GCT GRF5101",
  149. .id = 5,
  150. .init = grf5101_rf_init,
  151. .stop = grf5101_rf_stop,
  152. .set_chan = grf5101_rf_set_channel
  153. };