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_max2820.c 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Radio tuning for Maxim max2820 on RTL8180
  3. *
  4. * Copyright 2007 Andrea Merello <andreamrl@tiscali.it>
  5. *
  6. * Modified slightly for gPXE, 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 <gpxe/pci.h>
  24. #include <gpxe/net80211.h>
  25. #include "rtl818x.h"
  26. FILE_LICENCE(GPL2_ONLY);
  27. #define MAXIM_ANTENNA 0xb3
  28. static const u32 max2820_chan[] = {
  29. 12, /* CH 1 */
  30. 17,
  31. 22,
  32. 27,
  33. 32,
  34. 37,
  35. 42,
  36. 47,
  37. 52,
  38. 57,
  39. 62,
  40. 67,
  41. 72,
  42. 84, /* CH 14 */
  43. };
  44. static void write_max2820(struct net80211_device *dev, u8 addr, u32 data)
  45. {
  46. struct rtl818x_priv *priv = dev->priv;
  47. u32 phy_config;
  48. phy_config = 0x90 + (data & 0xf);
  49. phy_config <<= 16;
  50. phy_config += addr;
  51. phy_config <<= 8;
  52. phy_config += (data >> 4) & 0xff;
  53. /* This was originally a 32-bit write to a typecast
  54. RFPinsOutput, but gcc complained about aliasing rules. -JBO */
  55. rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, phy_config & 0xffff);
  56. rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, phy_config >> 16);
  57. mdelay(1);
  58. }
  59. static void max2820_write_phy_antenna(struct net80211_device *dev, short chan)
  60. {
  61. struct rtl818x_priv *priv = dev->priv;
  62. u8 ant;
  63. ant = MAXIM_ANTENNA;
  64. if (priv->rfparam & RF_PARAM_ANTBDEFAULT)
  65. ant |= BB_ANTENNA_B;
  66. if (chan == 14)
  67. ant |= BB_ANTATTEN_CHAN14;
  68. rtl818x_write_phy(dev, 0x10, ant);
  69. }
  70. static void max2820_rf_set_channel(struct net80211_device *dev,
  71. struct net80211_channel *channelp)
  72. {
  73. struct rtl818x_priv *priv = dev->priv;
  74. int channel = channelp->channel_nr;
  75. unsigned int chan_idx = channel - 1;
  76. u32 txpw = priv->txpower[chan_idx] & 0xFF;
  77. u32 chan = max2820_chan[chan_idx];
  78. /* While philips SA2400 drive the PA bias from
  79. * sa2400, for MAXIM we do this directly from BB */
  80. rtl818x_write_phy(dev, 3, txpw);
  81. max2820_write_phy_antenna(dev, channel);
  82. write_max2820(dev, 3, chan);
  83. }
  84. static void max2820_rf_stop(struct net80211_device *dev)
  85. {
  86. rtl818x_write_phy(dev, 3, 0x8);
  87. write_max2820(dev, 1, 0);
  88. }
  89. static void max2820_rf_init(struct net80211_device *dev)
  90. {
  91. struct rtl818x_priv *priv = dev->priv;
  92. /* MAXIM from netbsd driver */
  93. write_max2820(dev, 0, 0x007); /* test mode as indicated in datasheet */
  94. write_max2820(dev, 1, 0x01e); /* enable register */
  95. write_max2820(dev, 2, 0x001); /* synt register */
  96. max2820_rf_set_channel(dev, NULL);
  97. write_max2820(dev, 4, 0x313); /* rx register */
  98. /* PA is driven directly by the BB, we keep the MAXIM bias
  99. * at the highest value in case that setting it to lower
  100. * values may introduce some further attenuation somewhere..
  101. */
  102. write_max2820(dev, 5, 0x00f);
  103. /* baseband configuration */
  104. rtl818x_write_phy(dev, 0, 0x88); /* sys1 */
  105. rtl818x_write_phy(dev, 3, 0x08); /* txagc */
  106. rtl818x_write_phy(dev, 4, 0xf8); /* lnadet */
  107. rtl818x_write_phy(dev, 5, 0x90); /* ifagcinit */
  108. rtl818x_write_phy(dev, 6, 0x1a); /* ifagclimit */
  109. rtl818x_write_phy(dev, 7, 0x64); /* ifagcdet */
  110. max2820_write_phy_antenna(dev, 1);
  111. rtl818x_write_phy(dev, 0x11, 0x88); /* trl */
  112. if (rtl818x_ioread8(priv, &priv->map->CONFIG2) &
  113. RTL818X_CONFIG2_ANTENNA_DIV)
  114. rtl818x_write_phy(dev, 0x12, 0xc7);
  115. else
  116. rtl818x_write_phy(dev, 0x12, 0x47);
  117. rtl818x_write_phy(dev, 0x13, 0x9b);
  118. rtl818x_write_phy(dev, 0x19, 0x0); /* CHESTLIM */
  119. rtl818x_write_phy(dev, 0x1a, 0x9f); /* CHSQLIM */
  120. max2820_rf_set_channel(dev, NULL);
  121. }
  122. struct rtl818x_rf_ops max2820_rf_ops __rtl818x_rf_driver = {
  123. .name = "Maxim max2820",
  124. .id = 4,
  125. .init = max2820_rf_init,
  126. .stop = max2820_rf_stop,
  127. .set_chan = max2820_rf_set_channel
  128. };