rtl8180_max2820.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Radio tuning for Maxim max2820 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_max2820.h"
  26. static const u32 max2820_chan[] = {
  27. 12, /* CH 1 */
  28. 17,
  29. 22,
  30. 27,
  31. 32,
  32. 37,
  33. 42,
  34. 47,
  35. 52,
  36. 57,
  37. 62,
  38. 67,
  39. 72,
  40. 84, /* CH 14 */
  41. };
  42. static void write_max2820(struct ieee80211_hw *dev, u8 addr, u32 data)
  43. {
  44. struct rtl8180_priv *priv = dev->priv;
  45. u32 phy_config;
  46. phy_config = 0x90 + (data & 0xf);
  47. phy_config <<= 16;
  48. phy_config += addr;
  49. phy_config <<= 8;
  50. phy_config += (data >> 4) & 0xff;
  51. rtl818x_iowrite32(priv,
  52. (__le32 __iomem *) &priv->map->RFPinsOutput, phy_config);
  53. msleep(1);
  54. }
  55. static void max2820_write_phy_antenna(struct ieee80211_hw *dev, short chan)
  56. {
  57. struct rtl8180_priv *priv = dev->priv;
  58. u8 ant;
  59. ant = MAXIM_ANTENNA;
  60. if (priv->rfparam & RF_PARAM_ANTBDEFAULT)
  61. ant |= BB_ANTENNA_B;
  62. if (chan == 14)
  63. ant |= BB_ANTATTEN_CHAN14;
  64. rtl8180_write_phy(dev, 0x10, ant);
  65. }
  66. static void max2820_rf_set_channel(struct ieee80211_hw *dev,
  67. struct ieee80211_conf *conf)
  68. {
  69. struct rtl8180_priv *priv = dev->priv;
  70. int channel = conf ?
  71. ieee80211_frequency_to_channel(conf->channel->center_freq) : 1;
  72. unsigned int chan_idx = channel - 1;
  73. u32 txpw = priv->channels[chan_idx].hw_value & 0xFF;
  74. u32 chan = max2820_chan[chan_idx];
  75. /* While philips SA2400 drive the PA bias from
  76. * sa2400, for MAXIM we do this directly from BB */
  77. rtl8180_write_phy(dev, 3, txpw);
  78. max2820_write_phy_antenna(dev, channel);
  79. write_max2820(dev, 3, chan);
  80. }
  81. static void max2820_rf_stop(struct ieee80211_hw *dev)
  82. {
  83. rtl8180_write_phy(dev, 3, 0x8);
  84. write_max2820(dev, 1, 0);
  85. }
  86. static void max2820_rf_init(struct ieee80211_hw *dev)
  87. {
  88. struct rtl8180_priv *priv = dev->priv;
  89. /* MAXIM from netbsd driver */
  90. write_max2820(dev, 0, 0x007); /* test mode as indicated in datasheet */
  91. write_max2820(dev, 1, 0x01e); /* enable register */
  92. write_max2820(dev, 2, 0x001); /* synt register */
  93. max2820_rf_set_channel(dev, NULL);
  94. write_max2820(dev, 4, 0x313); /* rx register */
  95. /* PA is driven directly by the BB, we keep the MAXIM bias
  96. * at the highest value in case that setting it to lower
  97. * values may introduce some further attenuation somewhere..
  98. */
  99. write_max2820(dev, 5, 0x00f);
  100. /* baseband configuration */
  101. rtl8180_write_phy(dev, 0, 0x88); /* sys1 */
  102. rtl8180_write_phy(dev, 3, 0x08); /* txagc */
  103. rtl8180_write_phy(dev, 4, 0xf8); /* lnadet */
  104. rtl8180_write_phy(dev, 5, 0x90); /* ifagcinit */
  105. rtl8180_write_phy(dev, 6, 0x1a); /* ifagclimit */
  106. rtl8180_write_phy(dev, 7, 0x64); /* ifagcdet */
  107. max2820_write_phy_antenna(dev, 1);
  108. rtl8180_write_phy(dev, 0x11, 0x88); /* trl */
  109. if (rtl818x_ioread8(priv, &priv->map->CONFIG2) &
  110. RTL818X_CONFIG2_ANTENNA_DIV)
  111. rtl8180_write_phy(dev, 0x12, 0xc7);
  112. else
  113. rtl8180_write_phy(dev, 0x12, 0x47);
  114. rtl8180_write_phy(dev, 0x13, 0x9b);
  115. rtl8180_write_phy(dev, 0x19, 0x0); /* CHESTLIM */
  116. rtl8180_write_phy(dev, 0x1a, 0x9f); /* CHSQLIM */
  117. max2820_rf_set_channel(dev, NULL);
  118. }
  119. const struct rtl818x_rf_ops max2820_rf_ops = {
  120. .name = "Maxim",
  121. .init = max2820_rf_init,
  122. .stop = max2820_rf_stop,
  123. .set_chan = max2820_rf_set_channel
  124. };