3 * Radio tuning for GCT GRF5101 on RTL8180
5 * Copyright 2007 Andrea Merello <andrea.merello@gmail.com>
7 * Code from the BSD driver and the rtl8181 project have been
8 * very useful to understand certain things
10 * I want to thanks the Authors of such projects and the Ndiswrapper
13 * A special Big Thanks also is for all people who donated me cards,
14 * making possible the creation of the original rtl8180 driver
15 * from which this code is derived!
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License version 2 as
19 * published by the Free Software Foundation.
22 #include <linux/init.h>
23 #include <linux/pci.h>
24 #include <linux/delay.h>
25 #include <net/mac80211.h>
30 static const int grf5101_encode
[] = {
37 static void write_grf5101(struct ieee80211_hw
*dev
, u8 addr
, u32 data
)
39 struct rtl8180_priv
*priv
= dev
->priv
;
42 phy_config
= grf5101_encode
[(data
>> 8) & 0xF];
43 phy_config
|= grf5101_encode
[(data
>> 4) & 0xF] << 4;
44 phy_config
|= grf5101_encode
[data
& 0xF] << 8;
45 phy_config
|= grf5101_encode
[(addr
>> 1) & 0xF] << 12;
46 phy_config
|= (addr
& 1) << 16;
47 phy_config
|= grf5101_encode
[(data
& 0xf000) >> 12] << 24;
49 /* MAC will bang bits to the chip */
50 phy_config
|= 0x90000000;
52 rtl818x_iowrite32(priv
,
53 (__le32 __iomem
*) &priv
->map
->RFPinsOutput
, phy_config
);
58 static void grf5101_write_phy_antenna(struct ieee80211_hw
*dev
, short chan
)
60 struct rtl8180_priv
*priv
= dev
->priv
;
61 u8 ant
= GRF5101_ANTENNA
;
63 if (priv
->rfparam
& RF_PARAM_ANTBDEFAULT
)
67 ant
|= BB_ANTATTEN_CHAN14
;
69 rtl8180_write_phy(dev
, 0x10, ant
);
72 static u8
grf5101_rf_calc_rssi(u8 agc
, u8 sq
)
77 /* TODO(?): just return agc (or agc + 5) to avoid mult / div */
81 static void grf5101_rf_set_channel(struct ieee80211_hw
*dev
,
82 struct ieee80211_conf
*conf
)
84 struct rtl8180_priv
*priv
= dev
->priv
;
86 ieee80211_frequency_to_channel(conf
->chandef
.chan
->center_freq
);
87 u32 txpw
= priv
->channels
[channel
- 1].hw_value
& 0xFF;
88 u32 chan
= channel
- 1;
91 write_grf5101(dev
, 0x15, 0x0);
92 write_grf5101(dev
, 0x06, txpw
);
93 write_grf5101(dev
, 0x15, 0x10);
94 write_grf5101(dev
, 0x15, 0x0);
97 write_grf5101(dev
, 0x07, 0x0);
98 write_grf5101(dev
, 0x0B, chan
);
99 write_grf5101(dev
, 0x07, 0x1000);
101 grf5101_write_phy_antenna(dev
, channel
);
104 static void grf5101_rf_stop(struct ieee80211_hw
*dev
)
106 struct rtl8180_priv
*priv
= dev
->priv
;
109 anaparam
= priv
->anaparam
;
110 anaparam
&= 0x000fffff;
111 anaparam
|= 0x3f900000;
112 rtl8180_set_anaparam(priv
, anaparam
);
114 write_grf5101(dev
, 0x07, 0x0);
115 write_grf5101(dev
, 0x1f, 0x45);
116 write_grf5101(dev
, 0x1f, 0x5);
117 write_grf5101(dev
, 0x00, 0x8e4);
120 static void grf5101_rf_init(struct ieee80211_hw
*dev
)
122 struct rtl8180_priv
*priv
= dev
->priv
;
124 rtl8180_set_anaparam(priv
, priv
->anaparam
);
126 write_grf5101(dev
, 0x1f, 0x0);
127 write_grf5101(dev
, 0x1f, 0x0);
128 write_grf5101(dev
, 0x1f, 0x40);
129 write_grf5101(dev
, 0x1f, 0x60);
130 write_grf5101(dev
, 0x1f, 0x61);
131 write_grf5101(dev
, 0x1f, 0x61);
132 write_grf5101(dev
, 0x00, 0xae4);
133 write_grf5101(dev
, 0x1f, 0x1);
134 write_grf5101(dev
, 0x1f, 0x41);
135 write_grf5101(dev
, 0x1f, 0x61);
137 write_grf5101(dev
, 0x01, 0x1a23);
138 write_grf5101(dev
, 0x02, 0x4971);
139 write_grf5101(dev
, 0x03, 0x41de);
140 write_grf5101(dev
, 0x04, 0x2d80);
141 write_grf5101(dev
, 0x05, 0x68ff); /* 0x61ff original value */
142 write_grf5101(dev
, 0x06, 0x0);
143 write_grf5101(dev
, 0x07, 0x0);
144 write_grf5101(dev
, 0x08, 0x7533);
145 write_grf5101(dev
, 0x09, 0xc401);
146 write_grf5101(dev
, 0x0a, 0x0);
147 write_grf5101(dev
, 0x0c, 0x1c7);
148 write_grf5101(dev
, 0x0d, 0x29d3);
149 write_grf5101(dev
, 0x0e, 0x2e8);
150 write_grf5101(dev
, 0x10, 0x192);
151 write_grf5101(dev
, 0x11, 0x248);
152 write_grf5101(dev
, 0x12, 0x0);
153 write_grf5101(dev
, 0x13, 0x20c4);
154 write_grf5101(dev
, 0x14, 0xf4fc);
155 write_grf5101(dev
, 0x15, 0x0);
156 write_grf5101(dev
, 0x16, 0x1500);
158 write_grf5101(dev
, 0x07, 0x1000);
160 /* baseband configuration */
161 rtl8180_write_phy(dev
, 0, 0xa8);
162 rtl8180_write_phy(dev
, 3, 0x0);
163 rtl8180_write_phy(dev
, 4, 0xc0);
164 rtl8180_write_phy(dev
, 5, 0x90);
165 rtl8180_write_phy(dev
, 6, 0x1e);
166 rtl8180_write_phy(dev
, 7, 0x64);
168 grf5101_write_phy_antenna(dev
, 1);
170 rtl8180_write_phy(dev
, 0x11, 0x88);
172 if (rtl818x_ioread8(priv
, &priv
->map
->CONFIG2
) &
173 RTL818X_CONFIG2_ANTENNA_DIV
)
174 rtl8180_write_phy(dev
, 0x12, 0xc0); /* enable ant diversity */
176 rtl8180_write_phy(dev
, 0x12, 0x40); /* disable ant diversity */
178 rtl8180_write_phy(dev
, 0x13, 0x90 | priv
->csthreshold
);
180 rtl8180_write_phy(dev
, 0x19, 0x0);
181 rtl8180_write_phy(dev
, 0x1a, 0xa0);
182 rtl8180_write_phy(dev
, 0x1b, 0x44);
185 const struct rtl818x_rf_ops grf5101_rf_ops
= {
187 .init
= grf5101_rf_init
,
188 .stop
= grf5101_rf_stop
,
189 .set_chan
= grf5101_rf_set_channel
,
190 .calc_rssi
= grf5101_rf_calc_rssi
,