iPXE
rtl8180_max2820.c
Go to the documentation of this file.
1 /*
2  * Radio tuning for Maxim max2820 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 
29 FILE_LICENCE(GPL2_ONLY);
30 FILE_SECBOOT(FORBIDDEN);
31 
32 #define MAXIM_ANTENNA 0xb3
33 
34 static const u32 max2820_chan[] = {
35  12, /* CH 1 */
36  17,
37  22,
38  27,
39  32,
40  37,
41  42,
42  47,
43  52,
44  57,
45  62,
46  67,
47  72,
48  84, /* CH 14 */
49 };
50 
51 static void write_max2820(struct net80211_device *dev, u8 addr, u32 data)
52 {
53  struct rtl818x_priv *priv = dev->priv;
54  u32 phy_config;
55 
56  phy_config = 0x90 + (data & 0xf);
57  phy_config <<= 16;
58  phy_config += addr;
59  phy_config <<= 8;
60  phy_config += (data >> 4) & 0xff;
61 
62  /* This was originally a 32-bit write to a typecast
63  RFPinsOutput, but gcc complained about aliasing rules. -JBO */
64  rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, phy_config & 0xffff);
65  rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, phy_config >> 16);
66 
67  mdelay(1);
68 }
69 
70 static void max2820_write_phy_antenna(struct net80211_device *dev, short chan)
71 {
72  struct rtl818x_priv *priv = dev->priv;
73  u8 ant;
74 
75  ant = MAXIM_ANTENNA;
76  if (priv->rfparam & RF_PARAM_ANTBDEFAULT)
77  ant |= BB_ANTENNA_B;
78  if (chan == 14)
79  ant |= BB_ANTATTEN_CHAN14;
80 
81  rtl818x_write_phy(dev, 0x10, ant);
82 }
83 
84 static void max2820_rf_set_channel(struct net80211_device *dev,
85  struct net80211_channel *channelp)
86 {
87  struct rtl818x_priv *priv = dev->priv;
88  int channel = channelp->channel_nr;
89  unsigned int chan_idx = channel - 1;
90  u32 txpw = priv->txpower[chan_idx] & 0xFF;
91  u32 chan = max2820_chan[chan_idx];
92 
93  /* While philips SA2400 drive the PA bias from
94  * sa2400, for MAXIM we do this directly from BB */
95  rtl818x_write_phy(dev, 3, txpw);
96 
98  write_max2820(dev, 3, chan);
99 }
100 
101 static void max2820_rf_stop(struct net80211_device *dev)
102 {
103  rtl818x_write_phy(dev, 3, 0x8);
104  write_max2820(dev, 1, 0);
105 }
106 
107 
108 static void max2820_rf_init(struct net80211_device *dev)
109 {
110  struct rtl818x_priv *priv = dev->priv;
111 
112  /* MAXIM from netbsd driver */
113  write_max2820(dev, 0, 0x007); /* test mode as indicated in datasheet */
114  write_max2820(dev, 1, 0x01e); /* enable register */
115  write_max2820(dev, 2, 0x001); /* synt register */
116 
118 
119  write_max2820(dev, 4, 0x313); /* rx register */
120 
121  /* PA is driven directly by the BB, we keep the MAXIM bias
122  * at the highest value in case that setting it to lower
123  * values may introduce some further attenuation somewhere..
124  */
125  write_max2820(dev, 5, 0x00f);
126 
127  /* baseband configuration */
128  rtl818x_write_phy(dev, 0, 0x88); /* sys1 */
129  rtl818x_write_phy(dev, 3, 0x08); /* txagc */
130  rtl818x_write_phy(dev, 4, 0xf8); /* lnadet */
131  rtl818x_write_phy(dev, 5, 0x90); /* ifagcinit */
132  rtl818x_write_phy(dev, 6, 0x1a); /* ifagclimit */
133  rtl818x_write_phy(dev, 7, 0x64); /* ifagcdet */
134 
136 
137  rtl818x_write_phy(dev, 0x11, 0x88); /* trl */
138 
139  if (rtl818x_ioread8(priv, &priv->map->CONFIG2) &
141  rtl818x_write_phy(dev, 0x12, 0xc7);
142  else
143  rtl818x_write_phy(dev, 0x12, 0x47);
144 
145  rtl818x_write_phy(dev, 0x13, 0x9b);
146 
147  rtl818x_write_phy(dev, 0x19, 0x0); /* CHESTLIM */
148  rtl818x_write_phy(dev, 0x1a, 0x9f); /* CHSQLIM */
149 
151 }
152 
153 struct rtl818x_rf_ops max2820_rf_ops __rtl818x_rf_driver = {
154  .name = "Maxim max2820",
155  .id = 4,
156  .init = max2820_rf_init,
157  .stop = max2820_rf_stop,
158  .set_chan = max2820_rf_set_channel
159 };
char * name
Definition: rtl818x.h:353
FILE_LICENCE(GPL2_ONLY)
void rtl818x_write_phy(struct net80211_device *dev, u8 addr, u32 data)
Definition: rtl818x.c:48
static u8 rtl818x_ioread8(struct rtl818x_priv *priv __unused, u8 *addr)
Definition: rtl818x.h:316
static void max2820_write_phy_antenna(struct net80211_device *dev, short chan)
static void max2820_rf_set_channel(struct net80211_device *dev, struct net80211_channel *channelp)
FILE_SECBOOT(FORBIDDEN)
static void max2820_rf_init(struct net80211_device *dev)
#define BB_ANTENNA_B
Definition: rtl818x.h:206
#define MAXIM_ANTENNA
uint32_t channel
RNDIS channel.
Definition: netvsc.h:14
void * priv
Driver private data.
Definition: net80211.h:798
#define BB_ANTATTEN_CHAN14
Definition: rtl818x.h:205
The iPXE 802.11 MAC layer.
PCI bus.
Structure encapsulating the complete state of an 802.11 device.
Definition: net80211.h:786
uint32_t addr
Buffer address.
Definition: dwmac.h:20
An 802.11 RF channel.
Definition: net80211.h:385
static const u32 max2820_chan[]
struct rtl818x_rf_ops max2820_rf_ops __rtl818x_rf_driver
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
uint8_t data[48]
Additional event data.
Definition: ena.h:22
static void write_max2820(struct net80211_device *dev, u8 addr, u32 data)
static void rtl818x_iowrite16(struct rtl818x_priv *priv __unused, u16 *addr, u16 val)
Definition: rtl818x.h:337
u8 channel_nr
A channel number interpreted according to the band.
Definition: net80211.h:405
#define RF_PARAM_ANTBDEFAULT
Definition: rtl818x.h:201
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
static void max2820_rf_stop(struct net80211_device *dev)
uint8_t u8
Definition: stdint.h:20
uint32_t u32
Definition: stdint.h:24
#define RTL818X_CONFIG2_ANTENNA_DIV
Definition: rtl818x.h:115