iPXE
rtl8180_sa2400.c
Go to the documentation of this file.
1/*
2 * Radio tuning for Philips SA2400 on RTL8180
3 *
4 * Copyright 2007 Andrea Merello <andreamrl@tiscali.it>
5 *
6 * Modified slightly for iPXE, June 2009 by Joshua Oreman.
7 *
8 * Code from the BSD driver and the rtl8181 project have been
9 * very useful to understand certain things
10 *
11 * I want to thanks the Authors of such projects and the Ndiswrapper
12 * project Authors.
13 *
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!
17 *
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.
21 */
22
23#include <unistd.h>
24#include <ipxe/pci.h>
25#include <ipxe/net80211.h>
26
27#include "rtl818x.h"
28
29FILE_LICENCE(GPL2_ONLY);
30FILE_SECBOOT(FORBIDDEN);
31
32#define SA2400_ANTENNA 0x91
33#define SA2400_DIG_ANAPARAM_PWR1_ON 0x8
34#define SA2400_ANA_ANAPARAM_PWR1_ON 0x28
35#define SA2400_ANAPARAM_PWR0_ON 0x3
36
37/* RX sensitivity in dbm */
38#define SA2400_MAX_SENS 85
39
40#define SA2400_REG4_FIRDAC_SHIFT 7
41
42static const u32 sa2400_chan[] = {
43 0x00096c, /* ch1 */
44 0x080970,
45 0x100974,
46 0x180978,
47 0x000980,
48 0x080984,
49 0x100988,
50 0x18098c,
51 0x000994,
52 0x080998,
53 0x10099c,
54 0x1809a0,
55 0x0009a8,
56 0x0009b4, /* ch 14 */
57};
58
59static void write_sa2400(struct net80211_device *dev, u8 addr, u32 data)
60{
61 struct rtl818x_priv *priv = dev->priv;
62 u32 phy_config;
63
64 /* MAC will bang bits to the sa2400. sw 3-wire is NOT used */
65 phy_config = 0xb0000000;
66
67 phy_config |= ((u32)(addr & 0xf)) << 24;
68 phy_config |= data & 0xffffff;
69
70 /* This was originally a 32-bit write to a typecast
71 RFPinsOutput, but gcc complained about aliasing rules. -JBO */
72 rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, phy_config & 0xffff);
73 rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, phy_config >> 16);
74
75 mdelay(3);
76}
77
78static void sa2400_write_phy_antenna(struct net80211_device *dev, short chan)
79{
80 struct rtl818x_priv *priv = dev->priv;
81 u8 ant = SA2400_ANTENNA;
82
83 if (priv->rfparam & RF_PARAM_ANTBDEFAULT)
84 ant |= BB_ANTENNA_B;
85
86 if (chan == 14)
87 ant |= BB_ANTATTEN_CHAN14;
88
89 rtl818x_write_phy(dev, 0x10, ant);
90
91}
92
93static void sa2400_rf_set_channel(struct net80211_device *dev,
94 struct net80211_channel *channelp)
95{
96 struct rtl818x_priv *priv = dev->priv;
97 int channel = channelp->channel_nr;
98 u32 txpw = priv->txpower[channel - 1] & 0xFF;
99 u32 chan = sa2400_chan[channel - 1];
100
101 write_sa2400(dev, 7, txpw);
102
104
105 write_sa2400(dev, 0, chan);
106 write_sa2400(dev, 1, 0xbb50);
107 write_sa2400(dev, 2, 0x80);
108 write_sa2400(dev, 3, 0);
109}
110
111static void sa2400_rf_stop(struct net80211_device *dev)
112{
113 write_sa2400(dev, 4, 0);
114}
115
116static void sa2400_rf_init(struct net80211_device *dev)
117{
118 struct rtl818x_priv *priv = dev->priv;
119 u32 anaparam, txconf;
120 u8 firdac;
121 int analogphy = priv->rfparam & RF_PARAM_ANALOGPHY;
122
123 anaparam = priv->anaparam;
127
128 if (analogphy) {
130 firdac = 0;
131 } else {
134 firdac = 1 << SA2400_REG4_FIRDAC_SHIFT;
135 }
136
138
139 write_sa2400(dev, 0, sa2400_chan[0]);
140 write_sa2400(dev, 1, 0xbb50);
141 write_sa2400(dev, 2, 0x80);
142 write_sa2400(dev, 3, 0);
143 write_sa2400(dev, 4, 0x19340 | firdac);
144 write_sa2400(dev, 5, 0x1dfb | (SA2400_MAX_SENS - 54) << 15);
145 write_sa2400(dev, 4, 0x19348 | firdac); /* calibrate VCO */
146
147 if (!analogphy)
148 write_sa2400(dev, 4, 0x1938c); /*???*/
149
150 write_sa2400(dev, 4, 0x19340 | firdac);
151
152 write_sa2400(dev, 0, sa2400_chan[0]);
153 write_sa2400(dev, 1, 0xbb50);
154 write_sa2400(dev, 2, 0x80);
155 write_sa2400(dev, 3, 0);
156 write_sa2400(dev, 4, 0x19344 | firdac); /* calibrate filter */
157
158 /* new from rtl8180 embedded driver (rtl8181 project) */
159 write_sa2400(dev, 6, 0x13ff | (1 << 23)); /* MANRX */
160 write_sa2400(dev, 8, 0); /* VCO */
161
162 if (analogphy) {
165
166 txconf = rtl818x_ioread32(priv, &priv->map->TX_CONF);
167 rtl818x_iowrite32(priv, &priv->map->TX_CONF,
169
170 write_sa2400(dev, 4, 0x19341); /* calibrates DC */
171
172 /* a 5us delay is required here,
173 * we rely on the 3ms delay introduced in write_sa2400 */
174
175 write_sa2400(dev, 4, 0x19345);
176
177 /* a 20us delay is required here,
178 * we rely on the 3ms delay introduced in write_sa2400 */
179
180 rtl818x_iowrite32(priv, &priv->map->TX_CONF, txconf);
181
183 }
184 /* end new code */
185
186 write_sa2400(dev, 4, 0x19341 | firdac); /* RTX MODE */
187
188 /* baseband configuration */
189 rtl818x_write_phy(dev, 0, 0x98);
190 rtl818x_write_phy(dev, 3, 0x38);
191 rtl818x_write_phy(dev, 4, 0xe0);
192 rtl818x_write_phy(dev, 5, 0x90);
193 rtl818x_write_phy(dev, 6, 0x1a);
194 rtl818x_write_phy(dev, 7, 0x64);
195
197
198 rtl818x_write_phy(dev, 0x11, 0x80);
199
200 if (rtl818x_ioread8(priv, &priv->map->CONFIG2) &
202 rtl818x_write_phy(dev, 0x12, 0xc7); /* enable ant diversity */
203 else
204 rtl818x_write_phy(dev, 0x12, 0x47); /* disable ant diversity */
205
206 rtl818x_write_phy(dev, 0x13, 0x90 | priv->csthreshold);
207
208 rtl818x_write_phy(dev, 0x19, 0x0);
209 rtl818x_write_phy(dev, 0x1a, 0xa0);
210}
211
212struct rtl818x_rf_ops sa2400_rf_ops __rtl818x_rf_driver = {
213 .name = "Philips SA2400",
214 .id = 3,
215 .init = sa2400_rf_init,
216 .stop = sa2400_rf_stop,
217 .set_chan = sa2400_rf_set_channel
218};
uint32_t addr
Buffer address.
Definition dwmac.h:9
uint8_t data[48]
Additional event data.
Definition ena.h:11
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define u8
Definition igbvf_osdep.h:40
The iPXE 802.11 MAC layer.
uint32_t channel
RNDIS channel.
Definition netvsc.h:3
PCI bus.
#define SA2400_ANA_ANAPARAM_PWR1_ON
#define SA2400_DIG_ANAPARAM_PWR1_ON
#define SA2400_ANTENNA
static void sa2400_rf_stop(struct net80211_device *dev)
static void sa2400_write_phy_antenna(struct net80211_device *dev, short chan)
#define SA2400_REG4_FIRDAC_SHIFT
static void sa2400_rf_init(struct net80211_device *dev)
#define SA2400_MAX_SENS
#define SA2400_ANAPARAM_PWR0_ON
static const u32 sa2400_chan[]
static void write_sa2400(struct net80211_device *dev, u8 addr, u32 data)
static void sa2400_rf_set_channel(struct net80211_device *dev, struct net80211_channel *channelp)
void rtl818x_write_phy(struct net80211_device *dev, u8 addr, u32 data)
Definition rtl818x.c:48
void rtl818x_set_anaparam(struct rtl818x_priv *priv, u32 anaparam)
Definition rtl818x.c:221
#define ANAPARAM_PWR0_MASK
Definition rtl818x.h:215
#define BB_ANTATTEN_CHAN14
Definition rtl818x.h:205
#define ANAPARAM_TXDACOFF_SHIFT
Definition rtl818x.h:213
#define RTL818X_CONFIG2_ANTENNA_DIV
Definition rtl818x.h:115
#define ANAPARAM_PWR1_SHIFT
Definition rtl818x.h:216
#define BB_ANTENNA_B
Definition rtl818x.h:206
#define ANAPARAM_PWR1_MASK
Definition rtl818x.h:217
#define __rtl818x_rf_driver
Definition rtl818x.h:350
static u8 rtl818x_ioread8(struct rtl818x_priv *priv __unused, u8 *addr)
Definition rtl818x.h:316
static void rtl818x_iowrite16(struct rtl818x_priv *priv __unused, u16 *addr, u16 val)
Definition rtl818x.h:337
static void rtl818x_iowrite32(struct rtl818x_priv *priv __unused, u32 *addr, u32 val)
Definition rtl818x.h:343
#define ANAPARAM_PWR0_SHIFT
Definition rtl818x.h:214
#define RTL818X_TX_CONF_LOOPBACK_CONT
Definition rtl818x.h:70
static u32 rtl818x_ioread32(struct rtl818x_priv *priv __unused, u32 *addr)
Definition rtl818x.h:326
#define RF_PARAM_ANTBDEFAULT
Definition rtl818x.h:201
#define RF_PARAM_ANALOGPHY
Definition rtl818x.h:200
An 802.11 RF channel.
Definition net80211.h:386
u8 channel_nr
A channel number interpreted according to the band.
Definition net80211.h:405
Structure encapsulating the complete state of an 802.11 device.
Definition net80211.h:787
void * priv
Driver private data.
Definition net80211.h:798
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition timer.c:79
static struct tlan_private * priv
Definition tlan.c:225
#define u32
Definition vga.h:21