2 * Radio tuning for Philips SA2400 on RTL8180
4 * Copyright 2007 Andrea Merello <andreamrl@tiscali.it>
6 * Modified slightly for gPXE, 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 <gpxe/net80211.h>
29 FILE_LICENCE(GPL2_ONLY
);
31 #define SA2400_ANTENNA 0x91
32 #define SA2400_DIG_ANAPARAM_PWR1_ON 0x8
33 #define SA2400_ANA_ANAPARAM_PWR1_ON 0x28
34 #define SA2400_ANAPARAM_PWR0_ON 0x3
36 /* RX sensitivity in dbm */
37 #define SA2400_MAX_SENS 85
39 #define SA2400_REG4_FIRDAC_SHIFT 7
41 static const u32 sa2400_chan
[] = {
58 static void write_sa2400(struct net80211_device
*dev
, u8 addr
, u32 data
)
60 struct rtl818x_priv
*priv
= dev
->priv
;
63 /* MAC will bang bits to the sa2400. sw 3-wire is NOT used */
64 phy_config
= 0xb0000000;
66 phy_config
|= ((u32
)(addr
& 0xf)) << 24;
67 phy_config
|= data
& 0xffffff;
69 /* This was originally a 32-bit write to a typecast
70 RFPinsOutput, but gcc complained about aliasing rules. -JBO */
71 rtl818x_iowrite16(priv
, &priv
->map
->RFPinsOutput
, phy_config
& 0xffff);
72 rtl818x_iowrite16(priv
, &priv
->map
->RFPinsEnable
, phy_config
>> 16);
77 static void sa2400_write_phy_antenna(struct net80211_device
*dev
, short chan
)
79 struct rtl818x_priv
*priv
= dev
->priv
;
80 u8 ant
= SA2400_ANTENNA
;
82 if (priv
->rfparam
& RF_PARAM_ANTBDEFAULT
)
86 ant
|= BB_ANTATTEN_CHAN14
;
88 rtl818x_write_phy(dev
, 0x10, ant
);
92 static void sa2400_rf_set_channel(struct net80211_device
*dev
,
93 struct net80211_channel
*channelp
)
95 struct rtl818x_priv
*priv
= dev
->priv
;
96 int channel
= channelp
->channel_nr
;
97 u32 txpw
= priv
->txpower
[channel
- 1] & 0xFF;
98 u32 chan
= sa2400_chan
[channel
- 1];
100 write_sa2400(dev
, 7, txpw
);
102 sa2400_write_phy_antenna(dev
, channel
);
104 write_sa2400(dev
, 0, chan
);
105 write_sa2400(dev
, 1, 0xbb50);
106 write_sa2400(dev
, 2, 0x80);
107 write_sa2400(dev
, 3, 0);
110 static void sa2400_rf_stop(struct net80211_device
*dev
)
112 write_sa2400(dev
, 4, 0);
115 static void sa2400_rf_init(struct net80211_device
*dev
)
117 struct rtl818x_priv
*priv
= dev
->priv
;
118 u32 anaparam
, txconf
;
120 int analogphy
= priv
->rfparam
& RF_PARAM_ANALOGPHY
;
122 anaparam
= priv
->anaparam
;
123 anaparam
&= ~(1 << ANAPARAM_TXDACOFF_SHIFT
);
124 anaparam
&= ~ANAPARAM_PWR1_MASK
;
125 anaparam
&= ~ANAPARAM_PWR0_MASK
;
128 anaparam
|= SA2400_ANA_ANAPARAM_PWR1_ON
<< ANAPARAM_PWR1_SHIFT
;
131 anaparam
|= (SA2400_DIG_ANAPARAM_PWR1_ON
<< ANAPARAM_PWR1_SHIFT
);
132 anaparam
|= (SA2400_ANAPARAM_PWR0_ON
<< ANAPARAM_PWR0_SHIFT
);
133 firdac
= 1 << SA2400_REG4_FIRDAC_SHIFT
;
136 rtl818x_set_anaparam(priv
, anaparam
);
138 write_sa2400(dev
, 0, sa2400_chan
[0]);
139 write_sa2400(dev
, 1, 0xbb50);
140 write_sa2400(dev
, 2, 0x80);
141 write_sa2400(dev
, 3, 0);
142 write_sa2400(dev
, 4, 0x19340 | firdac
);
143 write_sa2400(dev
, 5, 0x1dfb | (SA2400_MAX_SENS
- 54) << 15);
144 write_sa2400(dev
, 4, 0x19348 | firdac
); /* calibrate VCO */
147 write_sa2400(dev
, 4, 0x1938c); /*???*/
149 write_sa2400(dev
, 4, 0x19340 | firdac
);
151 write_sa2400(dev
, 0, sa2400_chan
[0]);
152 write_sa2400(dev
, 1, 0xbb50);
153 write_sa2400(dev
, 2, 0x80);
154 write_sa2400(dev
, 3, 0);
155 write_sa2400(dev
, 4, 0x19344 | firdac
); /* calibrate filter */
157 /* new from rtl8180 embedded driver (rtl8181 project) */
158 write_sa2400(dev
, 6, 0x13ff | (1 << 23)); /* MANRX */
159 write_sa2400(dev
, 8, 0); /* VCO */
162 rtl818x_set_anaparam(priv
, anaparam
|
163 (1 << ANAPARAM_TXDACOFF_SHIFT
));
165 txconf
= rtl818x_ioread32(priv
, &priv
->map
->TX_CONF
);
166 rtl818x_iowrite32(priv
, &priv
->map
->TX_CONF
,
167 txconf
| RTL818X_TX_CONF_LOOPBACK_CONT
);
169 write_sa2400(dev
, 4, 0x19341); /* calibrates DC */
171 /* a 5us delay is required here,
172 * we rely on the 3ms delay introduced in write_sa2400 */
174 write_sa2400(dev
, 4, 0x19345);
176 /* a 20us delay is required here,
177 * we rely on the 3ms delay introduced in write_sa2400 */
179 rtl818x_iowrite32(priv
, &priv
->map
->TX_CONF
, txconf
);
181 rtl818x_set_anaparam(priv
, anaparam
);
185 write_sa2400(dev
, 4, 0x19341 | firdac
); /* RTX MODE */
187 /* baseband configuration */
188 rtl818x_write_phy(dev
, 0, 0x98);
189 rtl818x_write_phy(dev
, 3, 0x38);
190 rtl818x_write_phy(dev
, 4, 0xe0);
191 rtl818x_write_phy(dev
, 5, 0x90);
192 rtl818x_write_phy(dev
, 6, 0x1a);
193 rtl818x_write_phy(dev
, 7, 0x64);
195 sa2400_write_phy_antenna(dev
, 1);
197 rtl818x_write_phy(dev
, 0x11, 0x80);
199 if (rtl818x_ioread8(priv
, &priv
->map
->CONFIG2
) &
200 RTL818X_CONFIG2_ANTENNA_DIV
)
201 rtl818x_write_phy(dev
, 0x12, 0xc7); /* enable ant diversity */
203 rtl818x_write_phy(dev
, 0x12, 0x47); /* disable ant diversity */
205 rtl818x_write_phy(dev
, 0x13, 0x90 | priv
->csthreshold
);
207 rtl818x_write_phy(dev
, 0x19, 0x0);
208 rtl818x_write_phy(dev
, 0x1a, 0xa0);
211 struct rtl818x_rf_ops sa2400_rf_ops __rtl818x_rf_driver
= {
212 .name
= "Philips SA2400",
214 .init
= sa2400_rf_init
,
215 .stop
= sa2400_rf_stop
,
216 .set_chan
= sa2400_rf_set_channel