1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/init.h>
22#include <linux/pci.h>
23#include <linux/delay.h>
24#include <net/mac80211.h>
25
26#include "rtl8180.h"
27#include "max2820.h"
28
29static const u32 max2820_chan[] = {
30 12,
31 17,
32 22,
33 27,
34 32,
35 37,
36 42,
37 47,
38 52,
39 57,
40 62,
41 67,
42 72,
43 84,
44};
45
46static void write_max2820(struct ieee80211_hw *dev, u8 addr, u32 data)
47{
48 struct rtl8180_priv *priv = dev->priv;
49 u32 phy_config;
50
51 phy_config = 0x90 + (data & 0xf);
52 phy_config <<= 16;
53 phy_config += addr;
54 phy_config <<= 8;
55 phy_config += (data >> 4) & 0xff;
56
57 rtl818x_iowrite32(priv,
58 (__le32 __iomem *) &priv->map->RFPinsOutput, phy_config);
59
60 msleep(1);
61}
62
63static void max2820_write_phy_antenna(struct ieee80211_hw *dev, short chan)
64{
65 struct rtl8180_priv *priv = dev->priv;
66 u8 ant;
67
68 ant = MAXIM_ANTENNA;
69 if (priv->rfparam & RF_PARAM_ANTBDEFAULT)
70 ant |= BB_ANTENNA_B;
71 if (chan == 14)
72 ant |= BB_ANTATTEN_CHAN14;
73
74 rtl8180_write_phy(dev, 0x10, ant);
75}
76
77static u8 max2820_rf_calc_rssi(u8 agc, u8 sq)
78{
79 bool odd;
80
81 odd = !!(agc & 1);
82
83 agc >>= 1;
84 if (odd)
85 agc += 76;
86 else
87 agc += 66;
88
89
90 return 65 * agc / 100;
91}
92
93static void max2820_rf_set_channel(struct ieee80211_hw *dev,
94 struct ieee80211_conf *conf)
95{
96 struct rtl8180_priv *priv = dev->priv;
97 int channel = conf ?
98 ieee80211_frequency_to_channel(conf->chandef.chan->center_freq) : 1;
99 unsigned int chan_idx = channel - 1;
100 u32 txpw = priv->channels[chan_idx].hw_value & 0xFF;
101 u32 chan = max2820_chan[chan_idx];
102
103
104
105 rtl8180_write_phy(dev, 3, txpw);
106
107 max2820_write_phy_antenna(dev, channel);
108 write_max2820(dev, 3, chan);
109}
110
111static void max2820_rf_stop(struct ieee80211_hw *dev)
112{
113 rtl8180_write_phy(dev, 3, 0x8);
114 write_max2820(dev, 1, 0);
115}
116
117
118static void max2820_rf_init(struct ieee80211_hw *dev)
119{
120 struct rtl8180_priv *priv = dev->priv;
121
122
123 write_max2820(dev, 0, 0x007);
124 write_max2820(dev, 1, 0x01e);
125 write_max2820(dev, 2, 0x001);
126
127 max2820_rf_set_channel(dev, NULL);
128
129 write_max2820(dev, 4, 0x313);
130
131
132
133
134
135 write_max2820(dev, 5, 0x00f);
136
137
138 rtl8180_write_phy(dev, 0, 0x88);
139 rtl8180_write_phy(dev, 3, 0x08);
140 rtl8180_write_phy(dev, 4, 0xf8);
141 rtl8180_write_phy(dev, 5, 0x90);
142 rtl8180_write_phy(dev, 6, 0x1a);
143 rtl8180_write_phy(dev, 7, 0x64);
144
145 max2820_write_phy_antenna(dev, 1);
146
147 rtl8180_write_phy(dev, 0x11, 0x88);
148
149 if (rtl818x_ioread8(priv, &priv->map->CONFIG2) &
150 RTL818X_CONFIG2_ANTENNA_DIV)
151 rtl8180_write_phy(dev, 0x12, 0xc7);
152 else
153 rtl8180_write_phy(dev, 0x12, 0x47);
154
155 rtl8180_write_phy(dev, 0x13, 0x9b);
156
157 rtl8180_write_phy(dev, 0x19, 0x0);
158 rtl8180_write_phy(dev, 0x1a, 0x9f);
159
160 max2820_rf_set_channel(dev, NULL);
161}
162
163const struct rtl818x_rf_ops max2820_rf_ops = {
164 .name = "Maxim",
165 .init = max2820_rf_init,
166 .stop = max2820_rf_stop,
167 .set_chan = max2820_rf_set_channel,
168 .calc_rssi = max2820_rf_calc_rssi,
169};
170