iPXE
rtl8180_grf5101.c
Go to the documentation of this file.
1/*
2 * Radio tuning for GCT GRF5101 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 GRF5101_ANTENNA 0xA3
33
34static const int grf5101_encode[] = {
35 0x0, 0x8, 0x4, 0xC,
36 0x2, 0xA, 0x6, 0xE,
37 0x1, 0x9, 0x5, 0xD,
38 0x3, 0xB, 0x7, 0xF
39};
40
41static void write_grf5101(struct net80211_device *dev, u8 addr, u32 data)
42{
43 struct rtl818x_priv *priv = dev->priv;
44 u32 phy_config;
45
46 phy_config = grf5101_encode[(data >> 8) & 0xF];
47 phy_config |= grf5101_encode[(data >> 4) & 0xF] << 4;
48 phy_config |= grf5101_encode[data & 0xF] << 8;
49 phy_config |= grf5101_encode[(addr >> 1) & 0xF] << 12;
50 phy_config |= (addr & 1) << 16;
51 phy_config |= grf5101_encode[(data & 0xf000) >> 12] << 24;
52
53 /* MAC will bang bits to the chip */
54 phy_config |= 0x90000000;
55
56 /* This was originally a 32-bit write to a typecast
57 RFPinsOutput, but gcc complained about aliasing rules. -JBO */
58 rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, phy_config & 0xffff);
59 rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, phy_config >> 16);
60
61 mdelay(3);
62}
63
64static void grf5101_write_phy_antenna(struct net80211_device *dev, short chan)
65{
66 struct rtl818x_priv *priv = dev->priv;
67 u8 ant = GRF5101_ANTENNA;
68
69 if (priv->rfparam & RF_PARAM_ANTBDEFAULT)
70 ant |= BB_ANTENNA_B;
71
72 if (chan == 14)
73 ant |= BB_ANTATTEN_CHAN14;
74
75 rtl818x_write_phy(dev, 0x10, ant);
76}
77
79 struct net80211_channel *channelp)
80{
81 struct rtl818x_priv *priv = dev->priv;
82 int channel = channelp->channel_nr;
83 u32 txpw = priv->txpower[channel - 1] & 0xFF;
84 u32 chan = channel - 1;
85
86 /* set TX power */
87 write_grf5101(dev, 0x15, 0x0);
88 write_grf5101(dev, 0x06, txpw);
89 write_grf5101(dev, 0x15, 0x10);
90 write_grf5101(dev, 0x15, 0x0);
91
92 /* set frequency */
93 write_grf5101(dev, 0x07, 0x0);
94 write_grf5101(dev, 0x0B, chan);
95 write_grf5101(dev, 0x07, 0x1000);
96
98}
99
100static void grf5101_rf_stop(struct net80211_device *dev)
101{
102 struct rtl818x_priv *priv = dev->priv;
104
105 anaparam = priv->anaparam;
106 anaparam &= 0x000fffff;
107 anaparam |= 0x3f900000;
109
110 write_grf5101(dev, 0x07, 0x0);
111 write_grf5101(dev, 0x1f, 0x45);
112 write_grf5101(dev, 0x1f, 0x5);
113 write_grf5101(dev, 0x00, 0x8e4);
114}
115
116static void grf5101_rf_init(struct net80211_device *dev)
117{
118 struct rtl818x_priv *priv = dev->priv;
119
120 rtl818x_set_anaparam(priv, priv->anaparam);
121
122 write_grf5101(dev, 0x1f, 0x0);
123 write_grf5101(dev, 0x1f, 0x0);
124 write_grf5101(dev, 0x1f, 0x40);
125 write_grf5101(dev, 0x1f, 0x60);
126 write_grf5101(dev, 0x1f, 0x61);
127 write_grf5101(dev, 0x1f, 0x61);
128 write_grf5101(dev, 0x00, 0xae4);
129 write_grf5101(dev, 0x1f, 0x1);
130 write_grf5101(dev, 0x1f, 0x41);
131 write_grf5101(dev, 0x1f, 0x61);
132
133 write_grf5101(dev, 0x01, 0x1a23);
134 write_grf5101(dev, 0x02, 0x4971);
135 write_grf5101(dev, 0x03, 0x41de);
136 write_grf5101(dev, 0x04, 0x2d80);
137 write_grf5101(dev, 0x05, 0x68ff); /* 0x61ff original value */
138 write_grf5101(dev, 0x06, 0x0);
139 write_grf5101(dev, 0x07, 0x0);
140 write_grf5101(dev, 0x08, 0x7533);
141 write_grf5101(dev, 0x09, 0xc401);
142 write_grf5101(dev, 0x0a, 0x0);
143 write_grf5101(dev, 0x0c, 0x1c7);
144 write_grf5101(dev, 0x0d, 0x29d3);
145 write_grf5101(dev, 0x0e, 0x2e8);
146 write_grf5101(dev, 0x10, 0x192);
147 write_grf5101(dev, 0x11, 0x248);
148 write_grf5101(dev, 0x12, 0x0);
149 write_grf5101(dev, 0x13, 0x20c4);
150 write_grf5101(dev, 0x14, 0xf4fc);
151 write_grf5101(dev, 0x15, 0x0);
152 write_grf5101(dev, 0x16, 0x1500);
153
154 write_grf5101(dev, 0x07, 0x1000);
155
156 /* baseband configuration */
157 rtl818x_write_phy(dev, 0, 0xa8);
158 rtl818x_write_phy(dev, 3, 0x0);
159 rtl818x_write_phy(dev, 4, 0xc0);
160 rtl818x_write_phy(dev, 5, 0x90);
161 rtl818x_write_phy(dev, 6, 0x1e);
162 rtl818x_write_phy(dev, 7, 0x64);
163
165
166 rtl818x_write_phy(dev, 0x11, 0x88);
167
168 if (rtl818x_ioread8(priv, &priv->map->CONFIG2) &
170 rtl818x_write_phy(dev, 0x12, 0xc0); /* enable ant diversity */
171 else
172 rtl818x_write_phy(dev, 0x12, 0x40); /* disable ant diversity */
173
174 rtl818x_write_phy(dev, 0x13, 0x90 | priv->csthreshold);
175
176 rtl818x_write_phy(dev, 0x19, 0x0);
177 rtl818x_write_phy(dev, 0x1a, 0xa0);
178 rtl818x_write_phy(dev, 0x1b, 0x44);
179}
180
181struct rtl818x_rf_ops grf5101_rf_ops __rtl818x_rf_driver = {
182 .name = "GCT GRF5101",
183 .id = 5,
184 .init = grf5101_rf_init,
185 .stop = grf5101_rf_stop,
186 .set_chan = grf5101_rf_set_channel
187};
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.
static void write_grf5101(struct net80211_device *dev, u8 addr, u32 data)
static void grf5101_rf_init(struct net80211_device *dev)
static const int grf5101_encode[]
static void grf5101_rf_set_channel(struct net80211_device *dev, struct net80211_channel *channelp)
static void grf5101_write_phy_antenna(struct net80211_device *dev, short chan)
#define GRF5101_ANTENNA
static void grf5101_rf_stop(struct net80211_device *dev)
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 BB_ANTATTEN_CHAN14
Definition rtl818x.h:205
#define RTL818X_CONFIG2_ANTENNA_DIV
Definition rtl818x.h:115
#define BB_ANTENNA_B
Definition rtl818x.h:206
#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
#define RF_PARAM_ANTBDEFAULT
Definition rtl818x.h:201
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