2 * Radio tuning for GCT GRF5101 on RTL8180
4 * Copyright 2007 Andrea Merello <andreamrl@tiscali.it>
6 * Modified slightly for iPXE, June 2009 by Joshua Oreman.
8 * Code from the BSD driver and the rtl8181 project have been
9 * very useful to understand certain things
11 * I want to thanks the Authors of such projects and the Ndiswrapper
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!
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.
25 #include <ipxe/net80211.h>
29 FILE_LICENCE(GPL2_ONLY);
31 #define GRF5101_ANTENNA 0xA3
33 static const int grf5101_encode[] = {
40 static void write_grf5101(struct net80211_device *dev, u8 addr, u32 data)
42 struct rtl818x_priv *priv = dev->priv;
45 phy_config = grf5101_encode[(data >> 8) & 0xF];
46 phy_config |= grf5101_encode[(data >> 4) & 0xF] << 4;
47 phy_config |= grf5101_encode[data & 0xF] << 8;
48 phy_config |= grf5101_encode[(addr >> 1) & 0xF] << 12;
49 phy_config |= (addr & 1) << 16;
50 phy_config |= grf5101_encode[(data & 0xf000) >> 12] << 24;
52 /* MAC will bang bits to the chip */
53 phy_config |= 0x90000000;
55 /* This was originally a 32-bit write to a typecast
56 RFPinsOutput, but gcc complained about aliasing rules. -JBO */
57 rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, phy_config & 0xffff);
58 rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, phy_config >> 16);
63 static void grf5101_write_phy_antenna(struct net80211_device *dev, short chan)
65 struct rtl818x_priv *priv = dev->priv;
66 u8 ant = GRF5101_ANTENNA;
68 if (priv->rfparam & RF_PARAM_ANTBDEFAULT)
72 ant |= BB_ANTATTEN_CHAN14;
74 rtl818x_write_phy(dev, 0x10, ant);
77 static void grf5101_rf_set_channel(struct net80211_device *dev,
78 struct net80211_channel *channelp)
80 struct rtl818x_priv *priv = dev->priv;
81 int channel = channelp->channel_nr;
82 u32 txpw = priv->txpower[channel - 1] & 0xFF;
83 u32 chan = channel - 1;
86 write_grf5101(dev, 0x15, 0x0);
87 write_grf5101(dev, 0x06, txpw);
88 write_grf5101(dev, 0x15, 0x10);
89 write_grf5101(dev, 0x15, 0x0);
92 write_grf5101(dev, 0x07, 0x0);
93 write_grf5101(dev, 0x0B, chan);
94 write_grf5101(dev, 0x07, 0x1000);
96 grf5101_write_phy_antenna(dev, channel);
99 static void grf5101_rf_stop(struct net80211_device *dev)
101 struct rtl818x_priv *priv = dev->priv;
104 anaparam = priv->anaparam;
105 anaparam &= 0x000fffff;
106 anaparam |= 0x3f900000;
107 rtl818x_set_anaparam(priv, anaparam);
109 write_grf5101(dev, 0x07, 0x0);
110 write_grf5101(dev, 0x1f, 0x45);
111 write_grf5101(dev, 0x1f, 0x5);
112 write_grf5101(dev, 0x00, 0x8e4);
115 static void grf5101_rf_init(struct net80211_device *dev)
117 struct rtl818x_priv *priv = dev->priv;
119 rtl818x_set_anaparam(priv, priv->anaparam);
121 write_grf5101(dev, 0x1f, 0x0);
122 write_grf5101(dev, 0x1f, 0x0);
123 write_grf5101(dev, 0x1f, 0x40);
124 write_grf5101(dev, 0x1f, 0x60);
125 write_grf5101(dev, 0x1f, 0x61);
126 write_grf5101(dev, 0x1f, 0x61);
127 write_grf5101(dev, 0x00, 0xae4);
128 write_grf5101(dev, 0x1f, 0x1);
129 write_grf5101(dev, 0x1f, 0x41);
130 write_grf5101(dev, 0x1f, 0x61);
132 write_grf5101(dev, 0x01, 0x1a23);
133 write_grf5101(dev, 0x02, 0x4971);
134 write_grf5101(dev, 0x03, 0x41de);
135 write_grf5101(dev, 0x04, 0x2d80);
136 write_grf5101(dev, 0x05, 0x68ff); /* 0x61ff original value */
137 write_grf5101(dev, 0x06, 0x0);
138 write_grf5101(dev, 0x07, 0x0);
139 write_grf5101(dev, 0x08, 0x7533);
140 write_grf5101(dev, 0x09, 0xc401);
141 write_grf5101(dev, 0x0a, 0x0);
142 write_grf5101(dev, 0x0c, 0x1c7);
143 write_grf5101(dev, 0x0d, 0x29d3);
144 write_grf5101(dev, 0x0e, 0x2e8);
145 write_grf5101(dev, 0x10, 0x192);
146 write_grf5101(dev, 0x11, 0x248);
147 write_grf5101(dev, 0x12, 0x0);
148 write_grf5101(dev, 0x13, 0x20c4);
149 write_grf5101(dev, 0x14, 0xf4fc);
150 write_grf5101(dev, 0x15, 0x0);
151 write_grf5101(dev, 0x16, 0x1500);
153 write_grf5101(dev, 0x07, 0x1000);
155 /* baseband configuration */
156 rtl818x_write_phy(dev, 0, 0xa8);
157 rtl818x_write_phy(dev, 3, 0x0);
158 rtl818x_write_phy(dev, 4, 0xc0);
159 rtl818x_write_phy(dev, 5, 0x90);
160 rtl818x_write_phy(dev, 6, 0x1e);
161 rtl818x_write_phy(dev, 7, 0x64);
163 grf5101_write_phy_antenna(dev, 1);
165 rtl818x_write_phy(dev, 0x11, 0x88);
167 if (rtl818x_ioread8(priv, &priv->map->CONFIG2) &
168 RTL818X_CONFIG2_ANTENNA_DIV)
169 rtl818x_write_phy(dev, 0x12, 0xc0); /* enable ant diversity */
171 rtl818x_write_phy(dev, 0x12, 0x40); /* disable ant diversity */
173 rtl818x_write_phy(dev, 0x13, 0x90 | priv->csthreshold);
175 rtl818x_write_phy(dev, 0x19, 0x0);
176 rtl818x_write_phy(dev, 0x1a, 0xa0);
177 rtl818x_write_phy(dev, 0x1b, 0x44);
180 struct rtl818x_rf_ops grf5101_rf_ops __rtl818x_rf_driver = {
181 .name = "GCT GRF5101",
183 .init = grf5101_rf_init,
184 .stop = grf5101_rf_stop,
185 .set_chan = grf5101_rf_set_channel