]>
Commit | Line | Data |
---|---|---|
f6532111 MW |
1 | |
2 | /* | |
3 | * Radio tuning for GCT GRF5101 on RTL8180 | |
4 | * | |
5 | * Copyright 2007 Andrea Merello <[email protected]> | |
6 | * | |
7 | * Code from the BSD driver and the rtl8181 project have been | |
8 | * very useful to understand certain things | |
9 | * | |
10 | * I want to thanks the Authors of such projects and the Ndiswrapper | |
11 | * project Authors. | |
12 | * | |
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! | |
16 | * | |
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. | |
20 | */ | |
21 | ||
22 | #include <linux/init.h> | |
23 | #include <linux/pci.h> | |
24 | #include <linux/delay.h> | |
25 | #include <net/mac80211.h> | |
26 | ||
27 | #include "rtl8180.h" | |
28 | #include "rtl8180_grf5101.h" | |
29 | ||
30 | static const int grf5101_encode[] = { | |
31 | 0x0, 0x8, 0x4, 0xC, | |
32 | 0x2, 0xA, 0x6, 0xE, | |
33 | 0x1, 0x9, 0x5, 0xD, | |
34 | 0x3, 0xB, 0x7, 0xF | |
35 | }; | |
36 | ||
37 | static void write_grf5101(struct ieee80211_hw *dev, u8 addr, u32 data) | |
38 | { | |
39 | struct rtl8180_priv *priv = dev->priv; | |
40 | u32 phy_config; | |
41 | ||
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; | |
48 | ||
49 | /* MAC will bang bits to the chip */ | |
50 | phy_config |= 0x90000000; | |
51 | ||
52 | rtl818x_iowrite32(priv, | |
53 | (__le32 __iomem *) &priv->map->RFPinsOutput, phy_config); | |
54 | ||
55 | msleep(3); | |
56 | } | |
57 | ||
58 | static void grf5101_write_phy_antenna(struct ieee80211_hw *dev, short chan) | |
59 | { | |
60 | struct rtl8180_priv *priv = dev->priv; | |
61 | u8 ant = GRF5101_ANTENNA; | |
62 | ||
63 | if (priv->rfparam & RF_PARAM_ANTBDEFAULT) | |
64 | ant |= BB_ANTENNA_B; | |
65 | ||
66 | if (chan == 14) | |
67 | ant |= BB_ANTATTEN_CHAN14; | |
68 | ||
69 | rtl8180_write_phy(dev, 0x10, ant); | |
70 | } | |
71 | ||
72 | static void grf5101_rf_set_channel(struct ieee80211_hw *dev, | |
73 | struct ieee80211_conf *conf) | |
74 | { | |
75 | struct rtl8180_priv *priv = dev->priv; | |
8318d78a JB |
76 | int channel = ieee80211_frequency_to_channel(conf->channel->center_freq); |
77 | u32 txpw = priv->channels[channel - 1].hw_value & 0xFF; | |
78 | u32 chan = channel - 1; | |
f6532111 MW |
79 | |
80 | /* set TX power */ | |
81 | write_grf5101(dev, 0x15, 0x0); | |
82 | write_grf5101(dev, 0x06, txpw); | |
83 | write_grf5101(dev, 0x15, 0x10); | |
84 | write_grf5101(dev, 0x15, 0x0); | |
85 | ||
86 | /* set frequency */ | |
87 | write_grf5101(dev, 0x07, 0x0); | |
88 | write_grf5101(dev, 0x0B, chan); | |
89 | write_grf5101(dev, 0x07, 0x1000); | |
90 | ||
bc1b1fb2 | 91 | grf5101_write_phy_antenna(dev, channel); |
f6532111 MW |
92 | } |
93 | ||
94 | static void grf5101_rf_stop(struct ieee80211_hw *dev) | |
95 | { | |
96 | struct rtl8180_priv *priv = dev->priv; | |
97 | u32 anaparam; | |
98 | ||
99 | anaparam = priv->anaparam; | |
100 | anaparam &= 0x000fffff; | |
101 | anaparam |= 0x3f900000; | |
102 | rtl8180_set_anaparam(priv, anaparam); | |
103 | ||
104 | write_grf5101(dev, 0x07, 0x0); | |
105 | write_grf5101(dev, 0x1f, 0x45); | |
106 | write_grf5101(dev, 0x1f, 0x5); | |
107 | write_grf5101(dev, 0x00, 0x8e4); | |
108 | } | |
109 | ||
110 | static void grf5101_rf_init(struct ieee80211_hw *dev) | |
111 | { | |
112 | struct rtl8180_priv *priv = dev->priv; | |
113 | ||
114 | rtl8180_set_anaparam(priv, priv->anaparam); | |
115 | ||
116 | write_grf5101(dev, 0x1f, 0x0); | |
117 | write_grf5101(dev, 0x1f, 0x0); | |
118 | write_grf5101(dev, 0x1f, 0x40); | |
119 | write_grf5101(dev, 0x1f, 0x60); | |
120 | write_grf5101(dev, 0x1f, 0x61); | |
121 | write_grf5101(dev, 0x1f, 0x61); | |
122 | write_grf5101(dev, 0x00, 0xae4); | |
123 | write_grf5101(dev, 0x1f, 0x1); | |
124 | write_grf5101(dev, 0x1f, 0x41); | |
125 | write_grf5101(dev, 0x1f, 0x61); | |
126 | ||
127 | write_grf5101(dev, 0x01, 0x1a23); | |
128 | write_grf5101(dev, 0x02, 0x4971); | |
129 | write_grf5101(dev, 0x03, 0x41de); | |
130 | write_grf5101(dev, 0x04, 0x2d80); | |
131 | write_grf5101(dev, 0x05, 0x68ff); /* 0x61ff original value */ | |
132 | write_grf5101(dev, 0x06, 0x0); | |
133 | write_grf5101(dev, 0x07, 0x0); | |
134 | write_grf5101(dev, 0x08, 0x7533); | |
135 | write_grf5101(dev, 0x09, 0xc401); | |
136 | write_grf5101(dev, 0x0a, 0x0); | |
137 | write_grf5101(dev, 0x0c, 0x1c7); | |
138 | write_grf5101(dev, 0x0d, 0x29d3); | |
139 | write_grf5101(dev, 0x0e, 0x2e8); | |
140 | write_grf5101(dev, 0x10, 0x192); | |
141 | write_grf5101(dev, 0x11, 0x248); | |
142 | write_grf5101(dev, 0x12, 0x0); | |
143 | write_grf5101(dev, 0x13, 0x20c4); | |
144 | write_grf5101(dev, 0x14, 0xf4fc); | |
145 | write_grf5101(dev, 0x15, 0x0); | |
146 | write_grf5101(dev, 0x16, 0x1500); | |
147 | ||
148 | write_grf5101(dev, 0x07, 0x1000); | |
149 | ||
150 | /* baseband configuration */ | |
151 | rtl8180_write_phy(dev, 0, 0xa8); | |
152 | rtl8180_write_phy(dev, 3, 0x0); | |
153 | rtl8180_write_phy(dev, 4, 0xc0); | |
154 | rtl8180_write_phy(dev, 5, 0x90); | |
155 | rtl8180_write_phy(dev, 6, 0x1e); | |
156 | rtl8180_write_phy(dev, 7, 0x64); | |
157 | ||
158 | grf5101_write_phy_antenna(dev, 1); | |
159 | ||
160 | rtl8180_write_phy(dev, 0x11, 0x88); | |
161 | ||
162 | if (rtl818x_ioread8(priv, &priv->map->CONFIG2) & | |
163 | RTL818X_CONFIG2_ANTENNA_DIV) | |
164 | rtl8180_write_phy(dev, 0x12, 0xc0); /* enable ant diversity */ | |
165 | else | |
166 | rtl8180_write_phy(dev, 0x12, 0x40); /* disable ant diversity */ | |
167 | ||
168 | rtl8180_write_phy(dev, 0x13, 0x90 | priv->csthreshold); | |
169 | ||
170 | rtl8180_write_phy(dev, 0x19, 0x0); | |
171 | rtl8180_write_phy(dev, 0x1a, 0xa0); | |
172 | rtl8180_write_phy(dev, 0x1b, 0x44); | |
173 | } | |
174 | ||
175 | const struct rtl818x_rf_ops grf5101_rf_ops = { | |
176 | .name = "GCT", | |
177 | .init = grf5101_rf_init, | |
178 | .stop = grf5101_rf_stop, | |
179 | .set_chan = grf5101_rf_set_channel | |
180 | }; |