Quellcode durchsuchen

[rtl818x] Add driver for Realtek 8180/8185 wireless cards

tags/v0.9.8
Joshua Oreman vor 15 Jahren
Ursprung
Commit
14ae602ef0

+ 1
- 0
src/Makefile Datei anzeigen

@@ -61,6 +61,7 @@ SRCDIRS		+= drivers/bus
61 61
 SRCDIRS		+= drivers/net
62 62
 SRCDIRS		+= drivers/net/e1000
63 63
 SRCDIRS		+= drivers/net/phantom
64
+SRCDIRS		+= drivers/net/rtl818x
64 65
 SRCDIRS		+= drivers/block
65 66
 SRCDIRS		+= drivers/nvs
66 67
 SRCDIRS		+= drivers/bitbash

+ 17
- 0
src/drivers/net/rtl818x/rtl8180.c Datei anzeigen

@@ -0,0 +1,17 @@
1
+/* Realtek 8180 card: rtl818x driver + rtl8180 RF modules */
2
+
3
+FILE_LICENCE(GPL2_OR_LATER);
4
+
5
+#include <gpxe/pci.h>
6
+
7
+REQUIRE_OBJECT(rtl818x);
8
+REQUIRE_OBJECT(rtl8180_grf5101);
9
+REQUIRE_OBJECT(rtl8180_max2820);
10
+REQUIRE_OBJECT(rtl8180_sa2400);
11
+
12
+static struct pci_device_id rtl8180_nics[] __unused = {
13
+	PCI_ROM(0x10ec, 0x8180, "rtl8180", "Realtek 8180", 0),
14
+	PCI_ROM(0x1799, 0x6001, "f5d6001", "Belkin F5D6001", 0),
15
+	PCI_ROM(0x1799, 0x6020, "f5d6020", "Belkin F5D6020", 0),
16
+	PCI_ROM(0x1186, 0x3300, "dwl510",  "D-Link DWL-510", 0),
17
+};

+ 186
- 0
src/drivers/net/rtl818x/rtl8180_grf5101.c Datei anzeigen

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

+ 158
- 0
src/drivers/net/rtl818x/rtl8180_max2820.c Datei anzeigen

@@ -0,0 +1,158 @@
1
+/*
2
+ * Radio tuning for Maxim max2820 on RTL8180
3
+ *
4
+ * Copyright 2007 Andrea Merello <andreamrl@tiscali.it>
5
+ *
6
+ * Modified slightly for gPXE, 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 <gpxe/pci.h>
25
+#include <gpxe/net80211.h>
26
+
27
+#include "rtl818x.h"
28
+
29
+FILE_LICENCE(GPL2_ONLY);
30
+
31
+#define MAXIM_ANTENNA 0xb3
32
+
33
+static const u32 max2820_chan[] = {
34
+	12, /* CH 1 */
35
+	17,
36
+	22,
37
+	27,
38
+	32,
39
+	37,
40
+	42,
41
+	47,
42
+	52,
43
+	57,
44
+	62,
45
+	67,
46
+	72,
47
+	84, /* CH 14 */
48
+};
49
+
50
+static void write_max2820(struct net80211_device *dev, u8 addr, u32 data)
51
+{
52
+	struct rtl818x_priv *priv = dev->priv;
53
+	u32 phy_config;
54
+
55
+	phy_config = 0x90 + (data & 0xf);
56
+	phy_config <<= 16;
57
+	phy_config += addr;
58
+	phy_config <<= 8;
59
+	phy_config += (data >> 4) & 0xff;
60
+
61
+	/* This was originally a 32-bit write to a typecast
62
+	   RFPinsOutput, but gcc complained about aliasing rules. -JBO */
63
+	rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, phy_config & 0xffff);
64
+	rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, phy_config >> 16);
65
+
66
+	mdelay(1);
67
+}
68
+
69
+static void max2820_write_phy_antenna(struct net80211_device *dev, short chan)
70
+{
71
+	struct rtl818x_priv *priv = dev->priv;
72
+	u8 ant;
73
+
74
+	ant = MAXIM_ANTENNA;
75
+	if (priv->rfparam & RF_PARAM_ANTBDEFAULT)
76
+		ant |= BB_ANTENNA_B;
77
+	if (chan == 14)
78
+		ant |= BB_ANTATTEN_CHAN14;
79
+
80
+	rtl818x_write_phy(dev, 0x10, ant);
81
+}
82
+
83
+static void max2820_rf_set_channel(struct net80211_device *dev,
84
+				   struct net80211_channel *channelp)
85
+{
86
+	struct rtl818x_priv *priv = dev->priv;
87
+	int channel = channelp->channel_nr;
88
+	unsigned int chan_idx = channel - 1;
89
+	u32 txpw = priv->txpower[chan_idx] & 0xFF;
90
+	u32 chan = max2820_chan[chan_idx];
91
+
92
+	/* While philips SA2400 drive the PA bias from
93
+	 * sa2400, for MAXIM we do this directly from BB */
94
+	rtl818x_write_phy(dev, 3, txpw);
95
+
96
+	max2820_write_phy_antenna(dev, channel);
97
+	write_max2820(dev, 3, chan);
98
+}
99
+
100
+static void max2820_rf_stop(struct net80211_device *dev)
101
+{
102
+	rtl818x_write_phy(dev, 3, 0x8);
103
+	write_max2820(dev, 1, 0);
104
+}
105
+
106
+
107
+static void max2820_rf_init(struct net80211_device *dev)
108
+{
109
+	struct rtl818x_priv *priv = dev->priv;
110
+
111
+	/* MAXIM from netbsd driver */
112
+	write_max2820(dev, 0, 0x007); /* test mode as indicated in datasheet */
113
+	write_max2820(dev, 1, 0x01e); /* enable register */
114
+	write_max2820(dev, 2, 0x001); /* synt register */
115
+
116
+	max2820_rf_set_channel(dev, NULL);
117
+
118
+	write_max2820(dev, 4, 0x313); /* rx register */
119
+
120
+	/* PA is driven directly by the BB, we keep the MAXIM bias
121
+	 * at the highest value in case that setting it to lower
122
+	 * values may introduce some further attenuation somewhere..
123
+	 */
124
+	write_max2820(dev, 5, 0x00f);
125
+
126
+	/* baseband configuration */
127
+	rtl818x_write_phy(dev, 0, 0x88); /* sys1       */
128
+	rtl818x_write_phy(dev, 3, 0x08); /* txagc      */
129
+	rtl818x_write_phy(dev, 4, 0xf8); /* lnadet     */
130
+	rtl818x_write_phy(dev, 5, 0x90); /* ifagcinit  */
131
+	rtl818x_write_phy(dev, 6, 0x1a); /* ifagclimit */
132
+	rtl818x_write_phy(dev, 7, 0x64); /* ifagcdet   */
133
+
134
+	max2820_write_phy_antenna(dev, 1);
135
+
136
+	rtl818x_write_phy(dev, 0x11, 0x88); /* trl */
137
+
138
+	if (rtl818x_ioread8(priv, &priv->map->CONFIG2) &
139
+	    RTL818X_CONFIG2_ANTENNA_DIV)
140
+		rtl818x_write_phy(dev, 0x12, 0xc7);
141
+	else
142
+		rtl818x_write_phy(dev, 0x12, 0x47);
143
+
144
+	rtl818x_write_phy(dev, 0x13, 0x9b);
145
+
146
+	rtl818x_write_phy(dev, 0x19, 0x0);  /* CHESTLIM */
147
+	rtl818x_write_phy(dev, 0x1a, 0x9f); /* CHSQLIM  */
148
+
149
+	max2820_rf_set_channel(dev, NULL);
150
+}
151
+
152
+struct rtl818x_rf_ops max2820_rf_ops __rtl818x_rf_driver = {
153
+	.name		= "Maxim max2820",
154
+	.id		= 4,
155
+	.init		= max2820_rf_init,
156
+	.stop		= max2820_rf_stop,
157
+	.set_chan	= max2820_rf_set_channel
158
+};

+ 217
- 0
src/drivers/net/rtl818x/rtl8180_sa2400.c Datei anzeigen

@@ -0,0 +1,217 @@
1
+/*
2
+ * Radio tuning for Philips SA2400 on RTL8180
3
+ *
4
+ * Copyright 2007 Andrea Merello <andreamrl@tiscali.it>
5
+ *
6
+ * Modified slightly for gPXE, 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 <gpxe/pci.h>
25
+#include <gpxe/net80211.h>
26
+
27
+#include "rtl818x.h"
28
+
29
+FILE_LICENCE(GPL2_ONLY);
30
+
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
35
+
36
+/* RX sensitivity in dbm */
37
+#define SA2400_MAX_SENS 85
38
+
39
+#define SA2400_REG4_FIRDAC_SHIFT 7
40
+
41
+static const u32 sa2400_chan[] = {
42
+	0x00096c, /* ch1 */
43
+	0x080970,
44
+	0x100974,
45
+	0x180978,
46
+	0x000980,
47
+	0x080984,
48
+	0x100988,
49
+	0x18098c,
50
+	0x000994,
51
+	0x080998,
52
+	0x10099c,
53
+	0x1809a0,
54
+	0x0009a8,
55
+	0x0009b4, /* ch 14 */
56
+};
57
+
58
+static void write_sa2400(struct net80211_device *dev, u8 addr, u32 data)
59
+{
60
+	struct rtl818x_priv *priv = dev->priv;
61
+	u32 phy_config;
62
+
63
+	/* MAC will bang bits to the sa2400. sw 3-wire is NOT used */
64
+	phy_config = 0xb0000000;
65
+
66
+	phy_config |= ((u32)(addr & 0xf)) << 24;
67
+	phy_config |= data & 0xffffff;
68
+
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);
73
+
74
+	mdelay(3);
75
+}
76
+
77
+static void sa2400_write_phy_antenna(struct net80211_device *dev, short chan)
78
+{
79
+	struct rtl818x_priv *priv = dev->priv;
80
+	u8 ant = SA2400_ANTENNA;
81
+
82
+	if (priv->rfparam & RF_PARAM_ANTBDEFAULT)
83
+		ant |= BB_ANTENNA_B;
84
+
85
+	if (chan == 14)
86
+		ant |= BB_ANTATTEN_CHAN14;
87
+
88
+	rtl818x_write_phy(dev, 0x10, ant);
89
+
90
+}
91
+
92
+static void sa2400_rf_set_channel(struct net80211_device *dev,
93
+				  struct net80211_channel *channelp)
94
+{
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];
99
+
100
+	write_sa2400(dev, 7, txpw);
101
+
102
+	sa2400_write_phy_antenna(dev, channel);
103
+
104
+	write_sa2400(dev, 0, chan);
105
+	write_sa2400(dev, 1, 0xbb50);
106
+	write_sa2400(dev, 2, 0x80);
107
+	write_sa2400(dev, 3, 0);
108
+}
109
+
110
+static void sa2400_rf_stop(struct net80211_device *dev)
111
+{
112
+	write_sa2400(dev, 4, 0);
113
+}
114
+
115
+static void sa2400_rf_init(struct net80211_device *dev)
116
+{
117
+	struct rtl818x_priv *priv = dev->priv;
118
+	u32 anaparam, txconf;
119
+	u8 firdac;
120
+	int analogphy = priv->rfparam & RF_PARAM_ANALOGPHY;
121
+
122
+	anaparam = priv->anaparam;
123
+	anaparam &= ~(1 << ANAPARAM_TXDACOFF_SHIFT);
124
+	anaparam &= ~ANAPARAM_PWR1_MASK;
125
+	anaparam &= ~ANAPARAM_PWR0_MASK;
126
+
127
+	if (analogphy) {
128
+		anaparam |= SA2400_ANA_ANAPARAM_PWR1_ON << ANAPARAM_PWR1_SHIFT;
129
+		firdac = 0;
130
+	} else {
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;
134
+	}
135
+
136
+	rtl818x_set_anaparam(priv, anaparam);
137
+
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 */
145
+
146
+	if (!analogphy)
147
+		write_sa2400(dev, 4, 0x1938c); /*???*/
148
+
149
+	write_sa2400(dev, 4, 0x19340 | firdac);
150
+
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 */
156
+
157
+	/* new from rtl8180 embedded driver (rtl8181 project) */
158
+	write_sa2400(dev, 6, 0x13ff | (1 << 23)); /* MANRX */
159
+	write_sa2400(dev, 8, 0); /* VCO */
160
+
161
+	if (analogphy) {
162
+		rtl818x_set_anaparam(priv, anaparam |
163
+				     (1 << ANAPARAM_TXDACOFF_SHIFT));
164
+
165
+		txconf = rtl818x_ioread32(priv, &priv->map->TX_CONF);
166
+		rtl818x_iowrite32(priv, &priv->map->TX_CONF,
167
+			txconf | RTL818X_TX_CONF_LOOPBACK_CONT);
168
+
169
+		write_sa2400(dev, 4, 0x19341); /* calibrates DC */
170
+
171
+		/* a 5us delay is required here,
172
+		 * we rely on the 3ms delay introduced in write_sa2400 */
173
+
174
+		write_sa2400(dev, 4, 0x19345);
175
+
176
+		/* a 20us delay is required here,
177
+		 * we rely on the 3ms delay introduced in write_sa2400 */
178
+
179
+		rtl818x_iowrite32(priv, &priv->map->TX_CONF, txconf);
180
+
181
+		rtl818x_set_anaparam(priv, anaparam);
182
+	}
183
+	/* end new code */
184
+
185
+	write_sa2400(dev, 4, 0x19341 | firdac); /* RTX MODE */
186
+
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);
194
+
195
+	sa2400_write_phy_antenna(dev, 1);
196
+
197
+	rtl818x_write_phy(dev, 0x11, 0x80);
198
+
199
+	if (rtl818x_ioread8(priv, &priv->map->CONFIG2) &
200
+	    RTL818X_CONFIG2_ANTENNA_DIV)
201
+		rtl818x_write_phy(dev, 0x12, 0xc7); /* enable ant diversity */
202
+	else
203
+		rtl818x_write_phy(dev, 0x12, 0x47); /* disable ant diversity */
204
+
205
+	rtl818x_write_phy(dev, 0x13, 0x90 | priv->csthreshold);
206
+
207
+	rtl818x_write_phy(dev, 0x19, 0x0);
208
+	rtl818x_write_phy(dev, 0x1a, 0xa0);
209
+}
210
+
211
+struct rtl818x_rf_ops sa2400_rf_ops __rtl818x_rf_driver = {
212
+	.name		= "Philips SA2400",
213
+	.id		= 3,
214
+	.init		= sa2400_rf_init,
215
+	.stop		= sa2400_rf_stop,
216
+	.set_chan	= sa2400_rf_set_channel
217
+};

+ 14
- 0
src/drivers/net/rtl818x/rtl8185.c Datei anzeigen

@@ -0,0 +1,14 @@
1
+/* Realtek 8185 card: rtl818x driver + rtl8185_rtl8225 RF module */
2
+
3
+FILE_LICENCE(GPL2_OR_LATER);
4
+
5
+#include <gpxe/pci.h>
6
+
7
+REQUIRE_OBJECT(rtl818x);
8
+REQUIRE_OBJECT(rtl8185_rtl8225);
9
+
10
+static struct pci_device_id rtl8185_nics[] __unused = {
11
+	PCI_ROM(0x10ec, 0x8185, "rtl8185", "Realtek 8185", 0),
12
+	PCI_ROM(0x1799, 0x700f, "f5d7000", "Belkin F5D7000", 0),
13
+	PCI_ROM(0x1799, 0x701f, "f5d7010", "Belkin F5D7010", 0),
14
+};

+ 804
- 0
src/drivers/net/rtl818x/rtl8185_rtl8225.c Datei anzeigen

@@ -0,0 +1,804 @@
1
+/*
2
+ * Radio tuning for RTL8225 on RTL8185
3
+ *
4
+ * Copyright 2007 Michael Wu <flamingice@sourmilk.net>
5
+ * Copyright 2007 Andrea Merello <andreamrl@tiscali.it>
6
+ *
7
+ * Modified slightly for gPXE, June 2009 by Joshua Oreman
8
+ *
9
+ * Based on the r8180 driver, which is:
10
+ * Copyright 2005 Andrea Merello <andreamrl@tiscali.it>, et al.
11
+ *
12
+ * Thanks to Realtek for their support!
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License version 2 as
16
+ * published by the Free Software Foundation.
17
+ */
18
+
19
+#include <unistd.h>
20
+#include <gpxe/pci.h>
21
+#include <gpxe/net80211.h>
22
+
23
+#include "rtl818x.h"
24
+
25
+FILE_LICENCE(GPL2_ONLY);
26
+
27
+#define RTL8225_ANAPARAM_ON	0xa0000b59
28
+#define RTL8225_ANAPARAM2_ON	0x860dec11
29
+#define RTL8225_ANAPARAM_OFF	0xa00beb59
30
+#define RTL8225_ANAPARAM2_OFF	0x840dec11
31
+
32
+#define min(a,b) (((a)<(b))?(a):(b))
33
+#define ARRAY_SIZE(a) (int)(sizeof(a)/sizeof((a)[0]))
34
+
35
+static inline void rtl8225_write_phy_ofdm(struct net80211_device *dev,
36
+					  u8 addr, u8 data)
37
+{
38
+	rtl818x_write_phy(dev, addr, data);
39
+}
40
+
41
+static inline void rtl8225_write_phy_cck(struct net80211_device *dev,
42
+					 u8 addr, u8 data)
43
+{
44
+	rtl818x_write_phy(dev, addr, data | 0x10000);
45
+}
46
+
47
+static void rtl8225_write(struct net80211_device *dev, u8 addr, u16 data)
48
+{
49
+	struct rtl818x_priv *priv = dev->priv;
50
+	u16 reg80, reg84, reg82;
51
+	u32 bangdata;
52
+	int i;
53
+
54
+	bangdata = (data << 4) | (addr & 0xf);
55
+
56
+	reg80 = rtl818x_ioread16(priv, &priv->map->RFPinsOutput) & 0xfff3;
57
+	reg82 = rtl818x_ioread16(priv, &priv->map->RFPinsEnable);
58
+
59
+	rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, reg82 | 0x7);
60
+
61
+	reg84 = rtl818x_ioread16(priv, &priv->map->RFPinsSelect);
62
+	rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, reg84 | 0x7 | 0x400);
63
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
64
+	udelay(10);
65
+
66
+	rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80 | (1 << 2));
67
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
68
+	udelay(2);
69
+	rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80);
70
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
71
+	udelay(10);
72
+
73
+	for (i = 15; i >= 0; i--) {
74
+		u16 reg = reg80 | !!(bangdata & (1 << i));
75
+
76
+		if (i & 1)
77
+			rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg);
78
+
79
+		rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg | (1 << 1));
80
+		rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg | (1 << 1));
81
+
82
+		if (!(i & 1))
83
+			rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg);
84
+	}
85
+
86
+	rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80 | (1 << 2));
87
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
88
+	udelay(10);
89
+
90
+	rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80 | (1 << 2));
91
+	rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, reg84 | 0x400);
92
+	rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF);
93
+}
94
+
95
+static u16 rtl8225_read(struct net80211_device *dev, u8 addr)
96
+{
97
+	struct rtl818x_priv *priv = dev->priv;
98
+	u16 reg80, reg82, reg84, out;
99
+	int i;
100
+
101
+	reg80 = rtl818x_ioread16(priv, &priv->map->RFPinsOutput);
102
+	reg82 = rtl818x_ioread16(priv, &priv->map->RFPinsEnable);
103
+	reg84 = rtl818x_ioread16(priv, &priv->map->RFPinsSelect) | 0x400;
104
+
105
+	reg80 &= ~0xF;
106
+
107
+	rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, reg82 | 0x000F);
108
+	rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, reg84 | 0x000F);
109
+
110
+	rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80 | (1 << 2));
111
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
112
+	udelay(4);
113
+	rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80);
114
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
115
+	udelay(5);
116
+
117
+	for (i = 4; i >= 0; i--) {
118
+		u16 reg = reg80 | ((addr >> i) & 1);
119
+
120
+		if (!(i & 1)) {
121
+			rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg);
122
+			rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
123
+			udelay(1);
124
+		}
125
+
126
+		rtl818x_iowrite16(priv, &priv->map->RFPinsOutput,
127
+				  reg | (1 << 1));
128
+		rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
129
+		udelay(2);
130
+		rtl818x_iowrite16(priv, &priv->map->RFPinsOutput,
131
+				  reg | (1 << 1));
132
+		rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
133
+		udelay(2);
134
+
135
+		if (i & 1) {
136
+			rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg);
137
+			rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
138
+			udelay(1);
139
+		}
140
+	}
141
+
142
+	rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x000E);
143
+	rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, 0x040E);
144
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
145
+	rtl818x_iowrite16(priv, &priv->map->RFPinsOutput,
146
+			  reg80 | (1 << 3) | (1 << 1));
147
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
148
+	udelay(2);
149
+	rtl818x_iowrite16(priv, &priv->map->RFPinsOutput,
150
+			  reg80 | (1 << 3));
151
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
152
+	udelay(2);
153
+	rtl818x_iowrite16(priv, &priv->map->RFPinsOutput,
154
+			  reg80 | (1 << 3));
155
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
156
+	udelay(2);
157
+
158
+	out = 0;
159
+	for (i = 11; i >= 0; i--) {
160
+		rtl818x_iowrite16(priv, &priv->map->RFPinsOutput,
161
+				  reg80 | (1 << 3));
162
+		rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
163
+		udelay(1);
164
+		rtl818x_iowrite16(priv, &priv->map->RFPinsOutput,
165
+				  reg80 | (1 << 3) | (1 << 1));
166
+		rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
167
+		udelay(2);
168
+		rtl818x_iowrite16(priv, &priv->map->RFPinsOutput,
169
+				  reg80 | (1 << 3) | (1 << 1));
170
+		rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
171
+		udelay(2);
172
+		rtl818x_iowrite16(priv, &priv->map->RFPinsOutput,
173
+				  reg80 | (1 << 3) | (1 << 1));
174
+		rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
175
+		udelay(2);
176
+
177
+		if (rtl818x_ioread16(priv, &priv->map->RFPinsInput) & (1 << 1))
178
+			out |= 1 << i;
179
+
180
+		rtl818x_iowrite16(priv, &priv->map->RFPinsOutput,
181
+				  reg80 | (1 << 3));
182
+		rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
183
+		udelay(2);
184
+	}
185
+
186
+	rtl818x_iowrite16(priv, &priv->map->RFPinsOutput,
187
+			  reg80 | (1 << 3) | (1 << 2));
188
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
189
+	udelay(2);
190
+
191
+	rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, reg82);
192
+	rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, reg84);
193
+	rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 0x03A0);
194
+
195
+	return out;
196
+}
197
+
198
+static const u16 rtl8225bcd_rxgain[] = {
199
+	0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0408, 0x0409,
200
+	0x040a, 0x040b, 0x0502, 0x0503, 0x0504, 0x0505, 0x0540, 0x0541,
201
+	0x0542, 0x0543, 0x0544, 0x0545, 0x0580, 0x0581, 0x0582, 0x0583,
202
+	0x0584, 0x0585, 0x0588, 0x0589, 0x058a, 0x058b, 0x0643, 0x0644,
203
+	0x0645, 0x0680, 0x0681, 0x0682, 0x0683, 0x0684, 0x0685, 0x0688,
204
+	0x0689, 0x068a, 0x068b, 0x068c, 0x0742, 0x0743, 0x0744, 0x0745,
205
+	0x0780, 0x0781, 0x0782, 0x0783, 0x0784, 0x0785, 0x0788, 0x0789,
206
+	0x078a, 0x078b, 0x078c, 0x078d, 0x0790, 0x0791, 0x0792, 0x0793,
207
+	0x0794, 0x0795, 0x0798, 0x0799, 0x079a, 0x079b, 0x079c, 0x079d,
208
+	0x07a0, 0x07a1, 0x07a2, 0x07a3, 0x07a4, 0x07a5, 0x07a8, 0x07a9,
209
+	0x07aa, 0x07ab, 0x07ac, 0x07ad, 0x07b0, 0x07b1, 0x07b2, 0x07b3,
210
+	0x07b4, 0x07b5, 0x07b8, 0x07b9, 0x07ba, 0x07bb, 0x07bb
211
+};
212
+
213
+static const u8 rtl8225_agc[] = {
214
+	0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e,
215
+	0x9d, 0x9c, 0x9b, 0x9a, 0x99, 0x98, 0x97, 0x96,
216
+	0x95, 0x94, 0x93, 0x92, 0x91, 0x90, 0x8f, 0x8e,
217
+	0x8d, 0x8c, 0x8b, 0x8a, 0x89, 0x88, 0x87, 0x86,
218
+	0x85, 0x84, 0x83, 0x82, 0x81, 0x80, 0x3f, 0x3e,
219
+	0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, 0x37, 0x36,
220
+	0x35, 0x34, 0x33, 0x32, 0x31, 0x30, 0x2f, 0x2e,
221
+	0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, 0x27, 0x26,
222
+	0x25, 0x24, 0x23, 0x22, 0x21, 0x20, 0x1f, 0x1e,
223
+	0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, 0x17, 0x16,
224
+	0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e,
225
+	0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06,
226
+	0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x01, 0x01,
227
+	0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
228
+	0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
229
+	0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
230
+};
231
+
232
+static const u8 rtl8225_gain[] = {
233
+	0x23, 0x88, 0x7c, 0xa5, /* -82dbm */
234
+	0x23, 0x88, 0x7c, 0xb5, /* -82dbm */
235
+	0x23, 0x88, 0x7c, 0xc5, /* -82dbm */
236
+	0x33, 0x80, 0x79, 0xc5, /* -78dbm */
237
+	0x43, 0x78, 0x76, 0xc5, /* -74dbm */
238
+	0x53, 0x60, 0x73, 0xc5, /* -70dbm */
239
+	0x63, 0x58, 0x70, 0xc5, /* -66dbm */
240
+};
241
+
242
+static const u8 rtl8225_threshold[] = {
243
+	0x8d, 0x8d, 0x8d, 0x8d, 0x9d, 0xad, 0xbd
244
+};
245
+
246
+static const u8 rtl8225_tx_gain_cck_ofdm[] = {
247
+	0x02, 0x06, 0x0e, 0x1e, 0x3e, 0x7e
248
+};
249
+
250
+static const u8 rtl8225_tx_power_cck[] = {
251
+	0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02,
252
+	0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02,
253
+	0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02,
254
+	0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02,
255
+	0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03,
256
+	0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03
257
+};
258
+
259
+static const u8 rtl8225_tx_power_cck_ch14[] = {
260
+	0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00,
261
+	0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00,
262
+	0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00,
263
+	0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00,
264
+	0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00,
265
+	0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00
266
+};
267
+
268
+static const u8 rtl8225_tx_power_ofdm[] = {
269
+	0x80, 0x90, 0xa2, 0xb5, 0xcb, 0xe4
270
+};
271
+
272
+static const u32 rtl8225_chan[] = {
273
+	0x085c, 0x08dc, 0x095c, 0x09dc, 0x0a5c, 0x0adc, 0x0b5c,
274
+	0x0bdc, 0x0c5c, 0x0cdc, 0x0d5c, 0x0ddc, 0x0e5c, 0x0f72
275
+};
276
+
277
+static void rtl8225_rf_set_tx_power(struct net80211_device *dev, int channel)
278
+{
279
+	struct rtl818x_priv *priv = dev->priv;
280
+	u8 cck_power, ofdm_power;
281
+	const u8 *tmp;
282
+	u32 reg;
283
+	int i;
284
+
285
+	cck_power = priv->txpower[channel - 1] & 0xFF;
286
+	ofdm_power = priv->txpower[channel - 1] >> 8;
287
+
288
+	cck_power = min(cck_power, (u8)35);
289
+	ofdm_power = min(ofdm_power, (u8)35);
290
+
291
+	rtl818x_iowrite8(priv, &priv->map->TX_GAIN_CCK,
292
+			 rtl8225_tx_gain_cck_ofdm[cck_power / 6] >> 1);
293
+
294
+	if (channel == 14)
295
+		tmp = &rtl8225_tx_power_cck_ch14[(cck_power % 6) * 8];
296
+	else
297
+		tmp = &rtl8225_tx_power_cck[(cck_power % 6) * 8];
298
+
299
+	for (i = 0; i < 8; i++)
300
+		rtl8225_write_phy_cck(dev, 0x44 + i, *tmp++);
301
+
302
+	mdelay(1); /* FIXME: optional? */
303
+
304
+	/* anaparam2 on */
305
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
306
+	reg = rtl818x_ioread8(priv, &priv->map->CONFIG3);
307
+	rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg | RTL818X_CONFIG3_ANAPARAM_WRITE);
308
+	rtl818x_iowrite32(priv, &priv->map->ANAPARAM2, RTL8225_ANAPARAM2_ON);
309
+	rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg & ~RTL818X_CONFIG3_ANAPARAM_WRITE);
310
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
311
+
312
+	rtl818x_iowrite8(priv, &priv->map->TX_GAIN_OFDM,
313
+			 rtl8225_tx_gain_cck_ofdm[ofdm_power/6] >> 1);
314
+
315
+	tmp = &rtl8225_tx_power_ofdm[ofdm_power % 6];
316
+
317
+	rtl8225_write_phy_ofdm(dev, 5, *tmp);
318
+	rtl8225_write_phy_ofdm(dev, 7, *tmp);
319
+
320
+	mdelay(1);
321
+}
322
+
323
+static void rtl8225_rf_init(struct net80211_device *dev)
324
+{
325
+	struct rtl818x_priv *priv = dev->priv;
326
+	int i;
327
+
328
+	rtl818x_set_anaparam(priv, RTL8225_ANAPARAM_ON);
329
+
330
+	/* host_pci_init */
331
+	rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 0x0480);
332
+	rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF);
333
+	rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, 0x0488);
334
+	rtl818x_iowrite8(priv, &priv->map->GP_ENABLE, 0);
335
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
336
+	mdelay(200);	/* FIXME: ehh?? */
337
+	rtl818x_iowrite8(priv, &priv->map->GP_ENABLE, 0xFF & ~(1 << 6));
338
+
339
+	rtl818x_iowrite32(priv, &priv->map->RF_TIMING, 0x000a8008);
340
+
341
+	/* TODO: check if we need really to change BRSR to do RF config */
342
+	rtl818x_ioread16(priv, &priv->map->BRSR);
343
+	rtl818x_iowrite16(priv, &priv->map->BRSR, 0xFFFF);
344
+	rtl818x_iowrite32(priv, &priv->map->RF_PARA, 0x00100044);
345
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
346
+	rtl818x_iowrite8(priv, &priv->map->CONFIG3, 0x44);
347
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
348
+
349
+	rtl8225_write(dev, 0x0, 0x067);
350
+	rtl8225_write(dev, 0x1, 0xFE0);
351
+	rtl8225_write(dev, 0x2, 0x44D);
352
+	rtl8225_write(dev, 0x3, 0x441);
353
+	rtl8225_write(dev, 0x4, 0x8BE);
354
+	rtl8225_write(dev, 0x5, 0xBF0);		/* TODO: minipci */
355
+	rtl8225_write(dev, 0x6, 0xAE6);
356
+	rtl8225_write(dev, 0x7, rtl8225_chan[0]);
357
+	rtl8225_write(dev, 0x8, 0x01F);
358
+	rtl8225_write(dev, 0x9, 0x334);
359
+	rtl8225_write(dev, 0xA, 0xFD4);
360
+	rtl8225_write(dev, 0xB, 0x391);
361
+	rtl8225_write(dev, 0xC, 0x050);
362
+	rtl8225_write(dev, 0xD, 0x6DB);
363
+	rtl8225_write(dev, 0xE, 0x029);
364
+	rtl8225_write(dev, 0xF, 0x914); mdelay(1);
365
+
366
+	rtl8225_write(dev, 0x2, 0xC4D); mdelay(100);
367
+
368
+	rtl8225_write(dev, 0x0, 0x127);
369
+
370
+	for (i = 0; i < ARRAY_SIZE(rtl8225bcd_rxgain); i++) {
371
+		rtl8225_write(dev, 0x1, i + 1);
372
+		rtl8225_write(dev, 0x2, rtl8225bcd_rxgain[i]);
373
+	}
374
+
375
+	rtl8225_write(dev, 0x0, 0x027);
376
+	rtl8225_write(dev, 0x0, 0x22F);
377
+	rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF);
378
+
379
+	for (i = 0; i < ARRAY_SIZE(rtl8225_agc); i++) {
380
+		rtl8225_write_phy_ofdm(dev, 0xB, rtl8225_agc[i]);
381
+		mdelay(1);
382
+		rtl8225_write_phy_ofdm(dev, 0xA, 0x80 + i);
383
+		mdelay(1);
384
+	}
385
+
386
+	mdelay(1);
387
+
388
+	rtl8225_write_phy_ofdm(dev, 0x00, 0x01); mdelay(1);
389
+	rtl8225_write_phy_ofdm(dev, 0x01, 0x02); mdelay(1);
390
+	rtl8225_write_phy_ofdm(dev, 0x02, 0x62); mdelay(1);
391
+	rtl8225_write_phy_ofdm(dev, 0x03, 0x00); mdelay(1);
392
+	rtl8225_write_phy_ofdm(dev, 0x04, 0x00); mdelay(1);
393
+	rtl8225_write_phy_ofdm(dev, 0x05, 0x00); mdelay(1);
394
+	rtl8225_write_phy_ofdm(dev, 0x06, 0x00); mdelay(1);
395
+	rtl8225_write_phy_ofdm(dev, 0x07, 0x00); mdelay(1);
396
+	rtl8225_write_phy_ofdm(dev, 0x08, 0x00); mdelay(1);
397
+	rtl8225_write_phy_ofdm(dev, 0x09, 0xfe); mdelay(1);
398
+	rtl8225_write_phy_ofdm(dev, 0x0a, 0x09); mdelay(1);
399
+	rtl8225_write_phy_ofdm(dev, 0x0b, 0x80); mdelay(1);
400
+	rtl8225_write_phy_ofdm(dev, 0x0c, 0x01); mdelay(1);
401
+	rtl8225_write_phy_ofdm(dev, 0x0e, 0xd3); mdelay(1);
402
+	rtl8225_write_phy_ofdm(dev, 0x0f, 0x38); mdelay(1);
403
+	rtl8225_write_phy_ofdm(dev, 0x10, 0x84); mdelay(1);
404
+	rtl8225_write_phy_ofdm(dev, 0x11, 0x03); mdelay(1);
405
+	rtl8225_write_phy_ofdm(dev, 0x12, 0x20); mdelay(1);
406
+	rtl8225_write_phy_ofdm(dev, 0x13, 0x20); mdelay(1);
407
+	rtl8225_write_phy_ofdm(dev, 0x14, 0x00); mdelay(1);
408
+	rtl8225_write_phy_ofdm(dev, 0x15, 0x40); mdelay(1);
409
+	rtl8225_write_phy_ofdm(dev, 0x16, 0x00); mdelay(1);
410
+	rtl8225_write_phy_ofdm(dev, 0x17, 0x40); mdelay(1);
411
+	rtl8225_write_phy_ofdm(dev, 0x18, 0xef); mdelay(1);
412
+	rtl8225_write_phy_ofdm(dev, 0x19, 0x19); mdelay(1);
413
+	rtl8225_write_phy_ofdm(dev, 0x1a, 0x20); mdelay(1);
414
+	rtl8225_write_phy_ofdm(dev, 0x1b, 0x76); mdelay(1);
415
+	rtl8225_write_phy_ofdm(dev, 0x1c, 0x04); mdelay(1);
416
+	rtl8225_write_phy_ofdm(dev, 0x1e, 0x95); mdelay(1);
417
+	rtl8225_write_phy_ofdm(dev, 0x1f, 0x75); mdelay(1);
418
+	rtl8225_write_phy_ofdm(dev, 0x20, 0x1f); mdelay(1);
419
+	rtl8225_write_phy_ofdm(dev, 0x21, 0x27); mdelay(1);
420
+	rtl8225_write_phy_ofdm(dev, 0x22, 0x16); mdelay(1);
421
+	rtl8225_write_phy_ofdm(dev, 0x24, 0x46); mdelay(1);
422
+	rtl8225_write_phy_ofdm(dev, 0x25, 0x20); mdelay(1);
423
+	rtl8225_write_phy_ofdm(dev, 0x26, 0x90); mdelay(1);
424
+	rtl8225_write_phy_ofdm(dev, 0x27, 0x88); mdelay(1);
425
+
426
+	rtl8225_write_phy_cck(dev, 0x00, 0x98); mdelay(1);
427
+	rtl8225_write_phy_cck(dev, 0x03, 0x20); mdelay(1);
428
+	rtl8225_write_phy_cck(dev, 0x04, 0x7e); mdelay(1);
429
+	rtl8225_write_phy_cck(dev, 0x05, 0x12); mdelay(1);
430
+	rtl8225_write_phy_cck(dev, 0x06, 0xfc); mdelay(1);
431
+	rtl8225_write_phy_cck(dev, 0x07, 0x78); mdelay(1);
432
+	rtl8225_write_phy_cck(dev, 0x08, 0x2e); mdelay(1);
433
+	rtl8225_write_phy_cck(dev, 0x10, 0x93); mdelay(1);
434
+	rtl8225_write_phy_cck(dev, 0x11, 0x88); mdelay(1);
435
+	rtl8225_write_phy_cck(dev, 0x12, 0x47); mdelay(1);
436
+	rtl8225_write_phy_cck(dev, 0x13, 0xd0);
437
+	rtl8225_write_phy_cck(dev, 0x19, 0x00);
438
+	rtl8225_write_phy_cck(dev, 0x1a, 0xa0);
439
+	rtl8225_write_phy_cck(dev, 0x1b, 0x08);
440
+	rtl8225_write_phy_cck(dev, 0x40, 0x86);
441
+	rtl8225_write_phy_cck(dev, 0x41, 0x8d); mdelay(1);
442
+	rtl8225_write_phy_cck(dev, 0x42, 0x15); mdelay(1);
443
+	rtl8225_write_phy_cck(dev, 0x43, 0x18); mdelay(1);
444
+	rtl8225_write_phy_cck(dev, 0x44, 0x1f); mdelay(1);
445
+	rtl8225_write_phy_cck(dev, 0x45, 0x1e); mdelay(1);
446
+	rtl8225_write_phy_cck(dev, 0x46, 0x1a); mdelay(1);
447
+	rtl8225_write_phy_cck(dev, 0x47, 0x15); mdelay(1);
448
+	rtl8225_write_phy_cck(dev, 0x48, 0x10); mdelay(1);
449
+	rtl8225_write_phy_cck(dev, 0x49, 0x0a); mdelay(1);
450
+	rtl8225_write_phy_cck(dev, 0x4a, 0x05); mdelay(1);
451
+	rtl8225_write_phy_cck(dev, 0x4b, 0x02); mdelay(1);
452
+	rtl8225_write_phy_cck(dev, 0x4c, 0x05); mdelay(1);
453
+
454
+	rtl818x_iowrite8(priv, &priv->map->TESTR, 0x0D); mdelay(1);
455
+
456
+	rtl8225_rf_set_tx_power(dev, 1);
457
+
458
+	/* RX antenna default to A */
459
+	rtl8225_write_phy_cck(dev, 0x10, 0x9b); mdelay(1);	/* B: 0xDB */
460
+	rtl8225_write_phy_ofdm(dev, 0x26, 0x90); mdelay(1);	/* B: 0x10 */
461
+
462
+	rtl818x_iowrite8(priv, &priv->map->TX_ANTENNA, 0x03);	/* B: 0x00 */
463
+	mdelay(1);
464
+	rtl818x_iowrite32(priv, (u32 *)((u8 *)priv->map + 0x94), 0x15c00002);
465
+	rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF);
466
+
467
+	rtl8225_write(dev, 0x0c, 0x50);
468
+	/* set OFDM initial gain */
469
+	rtl8225_write_phy_ofdm(dev, 0x0d, rtl8225_gain[4 * 4]);
470
+	rtl8225_write_phy_ofdm(dev, 0x23, rtl8225_gain[4 * 4 + 1]);
471
+	rtl8225_write_phy_ofdm(dev, 0x1b, rtl8225_gain[4 * 4 + 2]);
472
+	rtl8225_write_phy_ofdm(dev, 0x1d, rtl8225_gain[4 * 4 + 3]);
473
+	/* set CCK threshold */
474
+	rtl8225_write_phy_cck(dev, 0x41, rtl8225_threshold[0]);
475
+}
476
+
477
+static const u8 rtl8225z2_tx_power_cck_ch14[] = {
478
+	0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00
479
+};
480
+
481
+static const u8 rtl8225z2_tx_power_cck_B[] = {
482
+	0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x04
483
+};
484
+
485
+static const u8 rtl8225z2_tx_power_cck_A[] = {
486
+	0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04
487
+};
488
+
489
+static const u8 rtl8225z2_tx_power_cck[] = {
490
+	0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04
491
+};
492
+
493
+static void rtl8225z2_rf_set_tx_power(struct net80211_device *dev, int channel)
494
+{
495
+	struct rtl818x_priv *priv = dev->priv;
496
+	u8 cck_power, ofdm_power;
497
+	const u8 *tmp;
498
+	int i;
499
+
500
+	cck_power = priv->txpower[channel - 1] & 0xFF;
501
+	ofdm_power = priv->txpower[channel - 1] >> 8;
502
+
503
+	if (channel == 14)
504
+		tmp = rtl8225z2_tx_power_cck_ch14;
505
+	else if (cck_power == 12)
506
+		tmp = rtl8225z2_tx_power_cck_B;
507
+	else if (cck_power == 13)
508
+		tmp = rtl8225z2_tx_power_cck_A;
509
+	else
510
+		tmp = rtl8225z2_tx_power_cck;
511
+
512
+	for (i = 0; i < 8; i++)
513
+		rtl8225_write_phy_cck(dev, 0x44 + i, *tmp++);
514
+
515
+	cck_power = min(cck_power, (u8)35);
516
+	if (cck_power == 13 || cck_power == 14)
517
+		cck_power = 12;
518
+	if (cck_power >= 15)
519
+		cck_power -= 2;
520
+
521
+	rtl818x_iowrite8(priv, &priv->map->TX_GAIN_CCK, cck_power);
522
+	rtl818x_ioread8(priv, &priv->map->TX_GAIN_CCK);
523
+	mdelay(1);
524
+
525
+	ofdm_power = min(ofdm_power, (u8)35);
526
+	rtl818x_iowrite8(priv, &priv->map->TX_GAIN_OFDM, ofdm_power);
527
+
528
+	rtl8225_write_phy_ofdm(dev, 2, 0x62);
529
+	rtl8225_write_phy_ofdm(dev, 5, 0x00);
530
+	rtl8225_write_phy_ofdm(dev, 6, 0x40);
531
+	rtl8225_write_phy_ofdm(dev, 7, 0x00);
532
+	rtl8225_write_phy_ofdm(dev, 8, 0x40);
533
+
534
+	mdelay(1);
535
+}
536
+
537
+static const u16 rtl8225z2_rxgain[] = {
538
+	0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0008, 0x0009,
539
+	0x000a, 0x000b, 0x0102, 0x0103, 0x0104, 0x0105, 0x0140, 0x0141,
540
+	0x0142, 0x0143, 0x0144, 0x0145, 0x0180, 0x0181, 0x0182, 0x0183,
541
+	0x0184, 0x0185, 0x0188, 0x0189, 0x018a, 0x018b, 0x0243, 0x0244,
542
+	0x0245, 0x0280, 0x0281, 0x0282, 0x0283, 0x0284, 0x0285, 0x0288,
543
+	0x0289, 0x028a, 0x028b, 0x028c, 0x0342, 0x0343, 0x0344, 0x0345,
544
+	0x0380, 0x0381, 0x0382, 0x0383, 0x0384, 0x0385, 0x0388, 0x0389,
545
+	0x038a, 0x038b, 0x038c, 0x038d, 0x0390, 0x0391, 0x0392, 0x0393,
546
+	0x0394, 0x0395, 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d,
547
+	0x03a0, 0x03a1, 0x03a2, 0x03a3, 0x03a4, 0x03a5, 0x03a8, 0x03a9,
548
+	0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03b0, 0x03b1, 0x03b2, 0x03b3,
549
+	0x03b4, 0x03b5, 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bb
550
+};
551
+
552
+static void rtl8225z2_rf_init(struct net80211_device *dev)
553
+{
554
+	struct rtl818x_priv *priv = dev->priv;
555
+	int i;
556
+
557
+	rtl818x_set_anaparam(priv, RTL8225_ANAPARAM_ON);
558
+
559
+	/* host_pci_init */
560
+	rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 0x0480);
561
+	rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF);
562
+	rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, 0x0488);
563
+	rtl818x_iowrite8(priv, &priv->map->GP_ENABLE, 0);
564
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
565
+	mdelay(200);	/* FIXME: ehh?? */
566
+	rtl818x_iowrite8(priv, &priv->map->GP_ENABLE, 0xFF & ~(1 << 6));
567
+
568
+	rtl818x_iowrite32(priv, &priv->map->RF_TIMING, 0x00088008);
569
+
570
+	/* TODO: check if we need really to change BRSR to do RF config */
571
+	rtl818x_ioread16(priv, &priv->map->BRSR);
572
+	rtl818x_iowrite16(priv, &priv->map->BRSR, 0xFFFF);
573
+	rtl818x_iowrite32(priv, &priv->map->RF_PARA, 0x00100044);
574
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
575
+	rtl818x_iowrite8(priv, &priv->map->CONFIG3, 0x44);
576
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
577
+
578
+	rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF);
579
+
580
+	rtl8225_write(dev, 0x0, 0x0B7); mdelay(1);
581
+	rtl8225_write(dev, 0x1, 0xEE0); mdelay(1);
582
+	rtl8225_write(dev, 0x2, 0x44D); mdelay(1);
583
+	rtl8225_write(dev, 0x3, 0x441); mdelay(1);
584
+	rtl8225_write(dev, 0x4, 0x8C3); mdelay(1);
585
+	rtl8225_write(dev, 0x5, 0xC72); mdelay(1);
586
+	rtl8225_write(dev, 0x6, 0x0E6); mdelay(1);
587
+	rtl8225_write(dev, 0x7, 0x82A); mdelay(1);
588
+	rtl8225_write(dev, 0x8, 0x03F); mdelay(1);
589
+	rtl8225_write(dev, 0x9, 0x335); mdelay(1);
590
+	rtl8225_write(dev, 0xa, 0x9D4); mdelay(1);
591
+	rtl8225_write(dev, 0xb, 0x7BB); mdelay(1);
592
+	rtl8225_write(dev, 0xc, 0x850); mdelay(1);
593
+	rtl8225_write(dev, 0xd, 0xCDF); mdelay(1);
594
+	rtl8225_write(dev, 0xe, 0x02B); mdelay(1);
595
+	rtl8225_write(dev, 0xf, 0x114); mdelay(100);
596
+
597
+	if (!(rtl8225_read(dev, 6) & (1 << 7))) {
598
+		rtl8225_write(dev, 0x02, 0x0C4D);
599
+		mdelay(200);
600
+		rtl8225_write(dev, 0x02, 0x044D);
601
+		mdelay(100);
602
+		/* TODO: readd calibration failure message when the calibration
603
+		   check works */
604
+	}
605
+
606
+	rtl8225_write(dev, 0x0, 0x1B7);
607
+	rtl8225_write(dev, 0x3, 0x002);
608
+	rtl8225_write(dev, 0x5, 0x004);
609
+
610
+	for (i = 0; i < ARRAY_SIZE(rtl8225z2_rxgain); i++) {
611
+		rtl8225_write(dev, 0x1, i + 1);
612
+		rtl8225_write(dev, 0x2, rtl8225z2_rxgain[i]);
613
+	}
614
+
615
+	rtl8225_write(dev, 0x0, 0x0B7); mdelay(100);
616
+	rtl8225_write(dev, 0x2, 0xC4D);
617
+
618
+	mdelay(200);
619
+	rtl8225_write(dev, 0x2, 0x44D);
620
+	mdelay(100);
621
+
622
+	rtl8225_write(dev, 0x00, 0x2BF);
623
+	rtl8225_write(dev, 0xFF, 0xFFFF);
624
+
625
+	rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF);
626
+
627
+	for (i = 0; i < ARRAY_SIZE(rtl8225_agc); i++) {
628
+		rtl8225_write_phy_ofdm(dev, 0xB, rtl8225_agc[i]);
629
+		mdelay(1);
630
+		rtl8225_write_phy_ofdm(dev, 0xA, 0x80 + i);
631
+		mdelay(1);
632
+	}
633
+
634
+	mdelay(1);
635
+
636
+	rtl8225_write_phy_ofdm(dev, 0x00, 0x01); mdelay(1);
637
+	rtl8225_write_phy_ofdm(dev, 0x01, 0x02); mdelay(1);
638
+	rtl8225_write_phy_ofdm(dev, 0x02, 0x62); mdelay(1);
639
+	rtl8225_write_phy_ofdm(dev, 0x03, 0x00); mdelay(1);
640
+	rtl8225_write_phy_ofdm(dev, 0x04, 0x00); mdelay(1);
641
+	rtl8225_write_phy_ofdm(dev, 0x05, 0x00); mdelay(1);
642
+	rtl8225_write_phy_ofdm(dev, 0x06, 0x40); mdelay(1);
643
+	rtl8225_write_phy_ofdm(dev, 0x07, 0x00); mdelay(1);
644
+	rtl8225_write_phy_ofdm(dev, 0x08, 0x40); mdelay(1);
645
+	rtl8225_write_phy_ofdm(dev, 0x09, 0xfe); mdelay(1);
646
+	rtl8225_write_phy_ofdm(dev, 0x0a, 0x09); mdelay(1);
647
+	rtl8225_write_phy_ofdm(dev, 0x18, 0xef); mdelay(1);
648
+	rtl8225_write_phy_ofdm(dev, 0x0b, 0x80); mdelay(1);
649
+	rtl8225_write_phy_ofdm(dev, 0x0c, 0x01); mdelay(1);
650
+	rtl8225_write_phy_ofdm(dev, 0x0d, 0x43);
651
+	rtl8225_write_phy_ofdm(dev, 0x0e, 0xd3); mdelay(1);
652
+	rtl8225_write_phy_ofdm(dev, 0x0f, 0x38); mdelay(1);
653
+	rtl8225_write_phy_ofdm(dev, 0x10, 0x84); mdelay(1);
654
+	rtl8225_write_phy_ofdm(dev, 0x11, 0x06); mdelay(1);
655
+	rtl8225_write_phy_ofdm(dev, 0x12, 0x20); mdelay(1);
656
+	rtl8225_write_phy_ofdm(dev, 0x13, 0x20); mdelay(1);
657
+	rtl8225_write_phy_ofdm(dev, 0x14, 0x00); mdelay(1);
658
+	rtl8225_write_phy_ofdm(dev, 0x15, 0x40); mdelay(1);
659
+	rtl8225_write_phy_ofdm(dev, 0x16, 0x00); mdelay(1);
660
+	rtl8225_write_phy_ofdm(dev, 0x17, 0x40); mdelay(1);
661
+	rtl8225_write_phy_ofdm(dev, 0x18, 0xef); mdelay(1);
662
+	rtl8225_write_phy_ofdm(dev, 0x19, 0x19); mdelay(1);
663
+	rtl8225_write_phy_ofdm(dev, 0x1a, 0x20); mdelay(1);
664
+	rtl8225_write_phy_ofdm(dev, 0x1b, 0x11); mdelay(1);
665
+	rtl8225_write_phy_ofdm(dev, 0x1c, 0x04); mdelay(1);
666
+	rtl8225_write_phy_ofdm(dev, 0x1d, 0xc5); mdelay(1);
667
+	rtl8225_write_phy_ofdm(dev, 0x1e, 0xb3); mdelay(1);
668
+	rtl8225_write_phy_ofdm(dev, 0x1f, 0x75); mdelay(1);
669
+	rtl8225_write_phy_ofdm(dev, 0x20, 0x1f); mdelay(1);
670
+	rtl8225_write_phy_ofdm(dev, 0x21, 0x27); mdelay(1);
671
+	rtl8225_write_phy_ofdm(dev, 0x22, 0x16); mdelay(1);
672
+	rtl8225_write_phy_ofdm(dev, 0x23, 0x80); mdelay(1); /* FIXME: not needed? */
673
+	rtl8225_write_phy_ofdm(dev, 0x24, 0x46); mdelay(1);
674
+	rtl8225_write_phy_ofdm(dev, 0x25, 0x20); mdelay(1);
675
+	rtl8225_write_phy_ofdm(dev, 0x26, 0x90); mdelay(1);
676
+	rtl8225_write_phy_ofdm(dev, 0x27, 0x88); mdelay(1);
677
+
678
+	rtl8225_write_phy_cck(dev, 0x00, 0x98); mdelay(1);
679
+	rtl8225_write_phy_cck(dev, 0x03, 0x20); mdelay(1);
680
+	rtl8225_write_phy_cck(dev, 0x04, 0x7e); mdelay(1);
681
+	rtl8225_write_phy_cck(dev, 0x05, 0x12); mdelay(1);
682
+	rtl8225_write_phy_cck(dev, 0x06, 0xfc); mdelay(1);
683
+	rtl8225_write_phy_cck(dev, 0x07, 0x78); mdelay(1);
684
+	rtl8225_write_phy_cck(dev, 0x08, 0x2e); mdelay(1);
685
+	rtl8225_write_phy_cck(dev, 0x10, 0x93); mdelay(1);
686
+	rtl8225_write_phy_cck(dev, 0x11, 0x88); mdelay(1);
687
+	rtl8225_write_phy_cck(dev, 0x12, 0x47); mdelay(1);
688
+	rtl8225_write_phy_cck(dev, 0x13, 0xd0);
689
+	rtl8225_write_phy_cck(dev, 0x19, 0x00);
690
+	rtl8225_write_phy_cck(dev, 0x1a, 0xa0);
691
+	rtl8225_write_phy_cck(dev, 0x1b, 0x08);
692
+	rtl8225_write_phy_cck(dev, 0x40, 0x86);
693
+	rtl8225_write_phy_cck(dev, 0x41, 0x8a); mdelay(1);
694
+	rtl8225_write_phy_cck(dev, 0x42, 0x15); mdelay(1);
695
+	rtl8225_write_phy_cck(dev, 0x43, 0x18); mdelay(1);
696
+	rtl8225_write_phy_cck(dev, 0x44, 0x36); mdelay(1);
697
+	rtl8225_write_phy_cck(dev, 0x45, 0x35); mdelay(1);
698
+	rtl8225_write_phy_cck(dev, 0x46, 0x2e); mdelay(1);
699
+	rtl8225_write_phy_cck(dev, 0x47, 0x25); mdelay(1);
700
+	rtl8225_write_phy_cck(dev, 0x48, 0x1c); mdelay(1);
701
+	rtl8225_write_phy_cck(dev, 0x49, 0x12); mdelay(1);
702
+	rtl8225_write_phy_cck(dev, 0x4a, 0x09); mdelay(1);
703
+	rtl8225_write_phy_cck(dev, 0x4b, 0x04); mdelay(1);
704
+	rtl8225_write_phy_cck(dev, 0x4c, 0x05); mdelay(1);
705
+
706
+	rtl818x_iowrite8(priv, (u8 *)priv->map + 0x5B, 0x0D); mdelay(1);
707
+
708
+	rtl8225z2_rf_set_tx_power(dev, 1);
709
+
710
+	/* RX antenna default to A */
711
+	rtl8225_write_phy_cck(dev, 0x10, 0x9b); mdelay(1);	/* B: 0xDB */
712
+	rtl8225_write_phy_ofdm(dev, 0x26, 0x90); mdelay(1);	/* B: 0x10 */
713
+
714
+	rtl818x_iowrite8(priv, &priv->map->TX_ANTENNA, 0x03);	/* B: 0x00 */
715
+	mdelay(1);
716
+	rtl818x_iowrite32(priv, (u32 *)((u8 *)priv->map + 0x94), 0x15c00002);
717
+	rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF);
718
+}
719
+
720
+static void rtl8225x_rf_init(struct net80211_device *dev)
721
+{
722
+	struct rtl818x_priv *priv = dev->priv;
723
+	u16 reg8, reg9;
724
+
725
+	rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 0x0480);
726
+	rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, 0x0488);
727
+	rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF);
728
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
729
+	mdelay(100);
730
+
731
+	rtl8225_write(dev, 0, 0x1B7);
732
+
733
+	reg8 = rtl8225_read(dev, 8);
734
+	reg9 = rtl8225_read(dev, 9);
735
+
736
+	rtl8225_write(dev, 0, 0x0B7);
737
+
738
+	if (reg8 != 0x588 || reg9 != 0x700) {
739
+		priv->rf_flag = 0;
740
+		rtl8225_rf_init(dev);
741
+	} else {
742
+		priv->rf_flag = 1;
743
+		rtl8225z2_rf_init(dev);
744
+	}
745
+}
746
+
747
+static void rtl8225_rf_stop(struct net80211_device *dev)
748
+{
749
+	struct rtl818x_priv *priv = dev->priv;
750
+	u8 reg;
751
+
752
+	rtl8225_write(dev, 0x4, 0x1f); mdelay(1);
753
+
754
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
755
+	reg = rtl818x_ioread8(priv, &priv->map->CONFIG3);
756
+	rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg | RTL818X_CONFIG3_ANAPARAM_WRITE);
757
+	rtl818x_iowrite32(priv, &priv->map->ANAPARAM2, RTL8225_ANAPARAM2_OFF);
758
+	rtl818x_iowrite32(priv, &priv->map->ANAPARAM, RTL8225_ANAPARAM_OFF);
759
+	rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg & ~RTL818X_CONFIG3_ANAPARAM_WRITE);
760
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
761
+}
762
+
763
+static void rtl8225_rf_set_channel(struct net80211_device *dev,
764
+				   struct net80211_channel *channelp)
765
+{
766
+	struct rtl818x_priv *priv = dev->priv;
767
+	int chan = channelp->channel_nr;
768
+
769
+	if (priv->rf_flag)
770
+		rtl8225z2_rf_set_tx_power(dev, chan);
771
+	else
772
+		rtl8225_rf_set_tx_power(dev, chan);
773
+
774
+	rtl8225_write(dev, 0x7, rtl8225_chan[chan - 1]);
775
+	mdelay(10);
776
+}
777
+
778
+static void rtl8225_rf_conf_erp(struct net80211_device *dev)
779
+{
780
+	struct rtl818x_priv *priv = dev->priv;
781
+
782
+	if (dev->phy_flags & NET80211_PHY_USE_SHORT_SLOT) {
783
+		rtl818x_iowrite8(priv, &priv->map->SLOT, 0x9);
784
+		rtl818x_iowrite8(priv, &priv->map->SIFS, 0x22);
785
+		rtl818x_iowrite8(priv, &priv->map->DIFS, 0x14);
786
+		rtl818x_iowrite8(priv, &priv->map->EIFS, 81);
787
+		rtl818x_iowrite8(priv, &priv->map->CW_VAL, 0x73);
788
+	} else {
789
+		rtl818x_iowrite8(priv, &priv->map->SLOT, 0x14);
790
+		rtl818x_iowrite8(priv, &priv->map->SIFS, 0x44);
791
+		rtl818x_iowrite8(priv, &priv->map->DIFS, 0x24);
792
+		rtl818x_iowrite8(priv, &priv->map->EIFS, 81);
793
+		rtl818x_iowrite8(priv, &priv->map->CW_VAL, 0xa5);
794
+	}
795
+}
796
+
797
+struct rtl818x_rf_ops rtl8225_ops __rtl818x_rf_driver = {
798
+	.name		= "rtl8225",
799
+	.id		= 9,
800
+	.init		= rtl8225x_rf_init,
801
+	.stop		= rtl8225_rf_stop,
802
+	.set_chan	= rtl8225_rf_set_channel,
803
+	.conf_erp	= rtl8225_rf_conf_erp,
804
+};

+ 850
- 0
src/drivers/net/rtl818x/rtl818x.c Datei anzeigen

@@ -0,0 +1,850 @@
1
+
2
+/*
3
+ * Linux device driver for RTL8180 / RTL8185
4
+ *
5
+ * Copyright 2007 Michael Wu <flamingice@sourmilk.net>
6
+ * Copyright 2007 Andrea Merello <andreamrl@tiscali.it>
7
+ *
8
+ * Modified for gPXE, June 2009, by Joshua Oreman <oremanj@rwcr.net>
9
+ *
10
+ * Based on the r8180 driver, which is:
11
+ * Copyright 2004-2005 Andrea Merello <andreamrl@tiscali.it>, et al.
12
+ *
13
+ * Thanks to Realtek for their support!
14
+ *
15
+ * This program is free software; you can redistribute it and/or modify
16
+ * it under the terms of the GNU General Public License version 2 as
17
+ * published by the Free Software Foundation.
18
+ */
19
+
20
+FILE_LICENCE(GPL2_ONLY);
21
+
22
+#include <stdint.h>
23
+#include <errno.h>
24
+#include <stdio.h>
25
+#include <unistd.h>
26
+#include <byteswap.h>
27
+#include <gpxe/iobuf.h>
28
+#include <gpxe/malloc.h>
29
+#include <gpxe/pci.h>
30
+#include <gpxe/net80211.h>
31
+#include <gpxe/netdevice.h>
32
+#include <gpxe/threewire.h>
33
+
34
+#include "rtl818x.h"
35
+
36
+/* rtl818x_rates[hw rate number] = rate in 100kbps units */
37
+static const u16 rtl818x_rates[] = {
38
+	10, 20, 55, 110, /* 802.11b */
39
+	60, 90, 120, 180, 240, 360, 480, 540, /* 802.11g */
40
+	0, 0, 0, 0,		/* index safely using a value masked with 0xF */
41
+};
42
+#define RTL818X_NR_B_RATES  4
43
+#define RTL818X_NR_RATES    12
44
+
45
+/* used by RF drivers */
46
+void rtl818x_write_phy(struct net80211_device *dev, u8 addr, u32 data)
47
+{
48
+	struct rtl818x_priv *priv = dev->priv;
49
+	int i = 10;
50
+	u32 buf;
51
+
52
+	buf = (data << 8) | addr;
53
+
54
+	rtl818x_iowrite32(priv, (u32 *)&priv->map->PHY[0], buf | 0x80);
55
+	while (i--) {
56
+		rtl818x_iowrite32(priv, (u32 *)&priv->map->PHY[0], buf);
57
+		if (rtl818x_ioread8(priv, &priv->map->PHY[2]) == (data & 0xFF))
58
+			return;
59
+	}
60
+}
61
+
62
+static void rtl818x_handle_rx(struct net80211_device *dev)
63
+{
64
+	struct rtl818x_priv *priv = dev->priv;
65
+	unsigned int count = RTL818X_RX_RING_SIZE;
66
+
67
+	while (count--) {
68
+		struct rtl818x_rx_desc *entry = &priv->rx_ring[priv->rx_idx];
69
+		struct io_buffer *iob = priv->rx_buf[priv->rx_idx];
70
+		u32 flags = le32_to_cpu(entry->flags);
71
+
72
+		if (flags & RTL818X_RX_DESC_FLAG_OWN)
73
+			return;
74
+
75
+		if (flags & (RTL818X_RX_DESC_FLAG_DMA_FAIL |
76
+			     RTL818X_RX_DESC_FLAG_FOF |
77
+			     RTL818X_RX_DESC_FLAG_RX_ERR)) {
78
+			/* This is crappy hardware. The Linux driver
79
+			   doesn't even log these. */
80
+			goto done;
81
+		} else if (flags & RTL818X_RX_DESC_FLAG_CRC32_ERR) {
82
+			/* This is actually a corrupt packet. */
83
+			DBG2("rtl818x RX:%d CRC fail: flags %08x\n",
84
+			     priv->rx_idx, flags);
85
+			net80211_rx_err(dev, NULL, EIO);
86
+		} else {
87
+			u32 flags2 = le32_to_cpu(entry->flags2);
88
+			struct io_buffer *new_iob = alloc_iob(MAX_RX_SIZE);
89
+			if (!new_iob) {
90
+				net80211_rx_err(dev, NULL, ENOMEM);
91
+				goto done;
92
+			}
93
+
94
+			DBGP("rtl818x RX:%d success: flags %08x %08x\n",
95
+			     priv->rx_idx, flags, flags2);
96
+
97
+			iob_put(iob, flags & 0xFFF);
98
+
99
+			net80211_rx(dev, iob, (flags2 >> 8) & 0x7f,
100
+				    rtl818x_rates[(flags >> 20) & 0xf]);
101
+
102
+			iob = new_iob;
103
+			priv->rx_buf[priv->rx_idx] = iob;
104
+		}
105
+
106
+	done:
107
+		entry->rx_buf = cpu_to_le32(virt_to_bus(iob->data));
108
+		entry->flags = cpu_to_le32(RTL818X_RX_DESC_FLAG_OWN | MAX_RX_SIZE);
109
+
110
+		if (priv->rx_idx == RTL818X_RX_RING_SIZE - 1)
111
+			entry->flags |= cpu_to_le32(RTL818X_RX_DESC_FLAG_EOR);
112
+
113
+		priv->rx_idx = (priv->rx_idx + 1) % RTL818X_RX_RING_SIZE;
114
+	}
115
+}
116
+
117
+static void rtl818x_handle_tx(struct net80211_device *dev)
118
+{
119
+	struct rtl818x_priv *priv = dev->priv;
120
+	unsigned int count = RTL818X_TX_RING_SIZE;
121
+
122
+	while (count--) {
123
+		struct rtl818x_tx_desc *entry = &priv->tx_ring[priv->tx_cons];
124
+		struct io_buffer *iob = priv->tx_buf[priv->tx_cons];
125
+		u32 flags = le32_to_cpu(entry->flags);
126
+		int rc;
127
+
128
+		if ((flags & RTL818X_TX_DESC_FLAG_OWN) || !iob)
129
+			return;
130
+
131
+		rc = 0;
132
+		if (!(flags & RTL818X_TX_DESC_FLAG_TX_OK)) {
133
+			/* our packet was not ACKed properly */
134
+			rc = EIO;
135
+		}
136
+
137
+		net80211_tx_complete(dev, iob, flags & 0xFF, rc);
138
+
139
+		priv->tx_buf[priv->tx_cons] = NULL;
140
+		priv->tx_cons = (priv->tx_cons + 1) % RTL818X_TX_RING_SIZE;
141
+	}
142
+}
143
+
144
+static void rtl818x_poll(struct net80211_device *dev)
145
+{
146
+	struct rtl818x_priv *priv = dev->priv;
147
+	u16 reg = rtl818x_ioread16(priv, &priv->map->INT_STATUS);
148
+
149
+	if (reg == 0xFFFF)
150
+		return;
151
+
152
+	rtl818x_iowrite16(priv, &priv->map->INT_STATUS, reg);
153
+
154
+	if (reg & (RTL818X_INT_TXN_OK | RTL818X_INT_TXN_ERR))
155
+		rtl818x_handle_tx(dev);
156
+
157
+	if (reg & (RTL818X_INT_RX_OK | RTL818X_INT_RX_ERR))
158
+		rtl818x_handle_rx(dev);
159
+}
160
+
161
+#define DIV_ROUND_UP(n,d) (((n)+(d)-1)/(d))
162
+
163
+static int rtl818x_tx(struct net80211_device *dev, struct io_buffer *iob)
164
+{
165
+	struct rtl818x_priv *priv = dev->priv;
166
+	struct rtl818x_tx_desc *entry;
167
+	u32 tx_flags;
168
+	u16 plcp_len = 0;
169
+	int len = iob_len(iob);
170
+
171
+	tx_flags = RTL818X_TX_DESC_FLAG_OWN | RTL818X_TX_DESC_FLAG_FS |
172
+		RTL818X_TX_DESC_FLAG_LS | (priv->hw_rate << 24) | len;
173
+
174
+	if (priv->r8185) {
175
+		tx_flags |= RTL818X_TX_DESC_FLAG_DMA |
176
+			    RTL818X_TX_DESC_FLAG_NO_ENC;
177
+	} else {
178
+		unsigned int remainder;
179
+
180
+		plcp_len = DIV_ROUND_UP(16 * (len + 4),
181
+					(dev->rates[dev->rate] * 2) / 10);
182
+		remainder = (16 * (len + 4)) %
183
+			    ((dev->rates[dev->rate] * 2) / 10);
184
+
185
+		if (remainder > 0 && remainder <= 6)
186
+			plcp_len |= 1 << 15;
187
+	}
188
+
189
+	if (dev->phy_flags & NET80211_PHY_USE_PROTECTION) {
190
+		tx_flags |= RTL818X_TX_DESC_FLAG_CTS;
191
+		tx_flags |= priv->hw_rtscts_rate << 19;
192
+	}
193
+
194
+	entry = &priv->tx_ring[priv->tx_prod];
195
+
196
+	if (entry->flags & RTL818X_TX_DESC_FLAG_OWN) {
197
+		/* card hasn't processed the old packet yet! */
198
+		return -EBUSY;
199
+	}
200
+
201
+	priv->tx_buf[priv->tx_prod] = iob;
202
+	priv->tx_prod = (priv->tx_prod + 1) % RTL818X_TX_RING_SIZE;
203
+
204
+	entry->rts_duration = 0;
205
+	entry->plcp_len = cpu_to_le16(plcp_len);
206
+	entry->tx_buf = cpu_to_le32(virt_to_bus(iob->data));
207
+	entry->frame_len = cpu_to_le32(len);
208
+	entry->flags2 = /* alternate retry rate in 100kbps << 4 */ 0;
209
+	entry->retry_limit = RTL818X_MAX_RETRIES;
210
+	entry->flags = cpu_to_le32(tx_flags);
211
+
212
+	rtl818x_iowrite8(priv, &priv->map->TX_DMA_POLLING, (1 << 5));
213
+
214
+	return 0;
215
+}
216
+
217
+void rtl818x_set_anaparam(struct rtl818x_priv *priv, u32 anaparam)
218
+{
219
+	u8 reg;
220
+
221
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
222
+	reg = rtl818x_ioread8(priv, &priv->map->CONFIG3);
223
+	rtl818x_iowrite8(priv, &priv->map->CONFIG3,
224
+		 reg | RTL818X_CONFIG3_ANAPARAM_WRITE);
225
+	rtl818x_iowrite32(priv, &priv->map->ANAPARAM, anaparam);
226
+	rtl818x_iowrite8(priv, &priv->map->CONFIG3,
227
+		 reg & ~RTL818X_CONFIG3_ANAPARAM_WRITE);
228
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
229
+}
230
+
231
+static int rtl818x_init_hw(struct net80211_device *dev)
232
+{
233
+	struct rtl818x_priv *priv = dev->priv;
234
+	u16 reg;
235
+
236
+	rtl818x_iowrite8(priv, &priv->map->CMD, 0);
237
+	rtl818x_ioread8(priv, &priv->map->CMD);
238
+	mdelay(10);
239
+
240
+	/* reset */
241
+	rtl818x_iowrite16(priv, &priv->map->INT_MASK, 0);
242
+	rtl818x_ioread8(priv, &priv->map->CMD);
243
+
244
+	reg = rtl818x_ioread8(priv, &priv->map->CMD);
245
+	reg &= (1 << 1);
246
+	reg |= RTL818X_CMD_RESET;
247
+	rtl818x_iowrite8(priv, &priv->map->CMD, RTL818X_CMD_RESET);
248
+	rtl818x_ioread8(priv, &priv->map->CMD);
249
+	mdelay(200);
250
+
251
+	/* check success of reset */
252
+	if (rtl818x_ioread8(priv, &priv->map->CMD) & RTL818X_CMD_RESET) {
253
+		DBG("rtl818x %s: reset timeout!\n", dev->netdev->name);
254
+		return -ETIMEDOUT;
255
+	}
256
+
257
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_LOAD);
258
+	rtl818x_ioread8(priv, &priv->map->CMD);
259
+	mdelay(200);
260
+
261
+	if (rtl818x_ioread8(priv, &priv->map->CONFIG3) & (1 << 3)) {
262
+		/* For cardbus */
263
+		reg = rtl818x_ioread8(priv, &priv->map->CONFIG3);
264
+		reg |= 1 << 1;
265
+		rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg);
266
+		reg = rtl818x_ioread16(priv, &priv->map->FEMR);
267
+		reg |= (1 << 15) | (1 << 14) | (1 << 4);
268
+		rtl818x_iowrite16(priv, &priv->map->FEMR, reg);
269
+	}
270
+
271
+	rtl818x_iowrite8(priv, &priv->map->MSR, 0);
272
+
273
+	if (!priv->r8185)
274
+		rtl818x_set_anaparam(priv, priv->anaparam);
275
+
276
+	rtl818x_iowrite32(priv, &priv->map->RDSAR, priv->rx_ring_dma);
277
+	rtl818x_iowrite32(priv, &priv->map->TNPDA, priv->tx_ring_dma);
278
+
279
+	/* TODO: necessary? specs indicate not */
280
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
281
+	reg = rtl818x_ioread8(priv, &priv->map->CONFIG2);
282
+	rtl818x_iowrite8(priv, &priv->map->CONFIG2, reg & ~(1 << 3));
283
+	if (priv->r8185) {
284
+		reg = rtl818x_ioread8(priv, &priv->map->CONFIG2);
285
+		rtl818x_iowrite8(priv, &priv->map->CONFIG2, reg | (1 << 4));
286
+	}
287
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
288
+
289
+	/* TODO: set CONFIG5 for calibrating AGC on rtl8180 + philips radio? */
290
+
291
+	/* TODO: turn off hw wep on rtl8180 */
292
+
293
+	rtl818x_iowrite32(priv, &priv->map->INT_TIMEOUT, 0);
294
+
295
+	if (priv->r8185) {
296
+		rtl818x_iowrite8(priv, &priv->map->WPA_CONF, 0);
297
+		rtl818x_iowrite8(priv, &priv->map->RATE_FALLBACK, 0x81);
298
+		rtl818x_iowrite8(priv, &priv->map->RESP_RATE, (8 << 4) | 0);
299
+
300
+		rtl818x_iowrite16(priv, &priv->map->BRSR, 0x01F3);
301
+
302
+		/* TODO: set ClkRun enable? necessary? */
303
+		reg = rtl818x_ioread8(priv, &priv->map->GP_ENABLE);
304
+		rtl818x_iowrite8(priv, &priv->map->GP_ENABLE, reg & ~(1 << 6));
305
+		rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
306
+		reg = rtl818x_ioread8(priv, &priv->map->CONFIG3);
307
+		rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg | (1 << 2));
308
+		rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
309
+	} else {
310
+		rtl818x_iowrite16(priv, &priv->map->BRSR, 0x1);
311
+		rtl818x_iowrite8(priv, &priv->map->SECURITY, 0);
312
+
313
+		rtl818x_iowrite8(priv, &priv->map->PHY_DELAY, 0x6);
314
+		rtl818x_iowrite8(priv, &priv->map->CARRIER_SENSE_COUNTER, 0x4C);
315
+	}
316
+
317
+	priv->rf->init(dev);
318
+	if (priv->r8185)
319
+		rtl818x_iowrite16(priv, &priv->map->BRSR, 0x01F3);
320
+	return 0;
321
+}
322
+
323
+static int rtl818x_init_rx_ring(struct net80211_device *dev)
324
+{
325
+	struct rtl818x_priv *priv = dev->priv;
326
+	struct rtl818x_rx_desc *entry;
327
+	int i;
328
+
329
+	priv->rx_ring = malloc_dma(sizeof(*priv->rx_ring) * RTL818X_RX_RING_SIZE,
330
+				   RTL818X_RING_ALIGN);
331
+	priv->rx_ring_dma = virt_to_bus(priv->rx_ring);
332
+	if (!priv->rx_ring) {
333
+		DBG("rtl818x %s: cannot allocate RX ring\n", dev->netdev->name);
334
+		return -ENOMEM;
335
+	}
336
+
337
+	memset(priv->rx_ring, 0, sizeof(*priv->rx_ring) * RTL818X_RX_RING_SIZE);
338
+	priv->rx_idx = 0;
339
+
340
+	for (i = 0; i < RTL818X_RX_RING_SIZE; i++) {
341
+		struct io_buffer *iob = alloc_iob(MAX_RX_SIZE);
342
+		entry = &priv->rx_ring[i];
343
+		if (!iob)
344
+			return -ENOMEM;
345
+
346
+		priv->rx_buf[i] = iob;
347
+		entry->rx_buf = cpu_to_le32(virt_to_bus(iob->data));
348
+		entry->flags = cpu_to_le32(RTL818X_RX_DESC_FLAG_OWN |
349
+					   MAX_RX_SIZE);
350
+	}
351
+	entry->flags |= cpu_to_le32(RTL818X_RX_DESC_FLAG_EOR);
352
+	return 0;
353
+}
354
+
355
+static void rtl818x_free_rx_ring(struct net80211_device *dev)
356
+{
357
+	struct rtl818x_priv *priv = dev->priv;
358
+	int i;
359
+
360
+	for (i = 0; i < RTL818X_RX_RING_SIZE; i++) {
361
+		free_iob(priv->rx_buf[i]);
362
+		priv->rx_buf[i] = NULL;
363
+	}
364
+
365
+	free_dma(priv->rx_ring, sizeof(*priv->rx_ring) * RTL818X_RX_RING_SIZE);
366
+	priv->rx_ring = NULL;
367
+}
368
+
369
+static int rtl818x_init_tx_ring(struct net80211_device *dev)
370
+{
371
+	struct rtl818x_priv *priv = dev->priv;
372
+	int i;
373
+
374
+	priv->tx_ring = malloc_dma(sizeof(*priv->tx_ring) * RTL818X_TX_RING_SIZE,
375
+				   RTL818X_RING_ALIGN);
376
+	priv->tx_ring_dma = virt_to_bus(priv->tx_ring);
377
+	if (!priv->tx_ring) {
378
+		DBG("rtl818x %s: cannot allocate TX ring\n", dev->netdev->name);
379
+		return -ENOMEM;
380
+	}
381
+
382
+	memset(priv->tx_ring, 0, sizeof(*priv->tx_ring) * RTL818X_TX_RING_SIZE);
383
+	priv->tx_prod = priv->tx_cons = 0;
384
+
385
+	for (i = 0; i < RTL818X_TX_RING_SIZE; i++)
386
+		priv->tx_ring[i].next_tx_desc = cpu_to_le32(priv->tx_ring_dma +
387
+				((i + 1) % RTL818X_TX_RING_SIZE) * sizeof(*priv->tx_ring));
388
+
389
+	return 0;
390
+}
391
+
392
+static void rtl818x_free_tx_ring(struct net80211_device *dev)
393
+{
394
+	struct rtl818x_priv *priv = dev->priv;
395
+	int i;
396
+
397
+	for (i = 0; i < RTL818X_TX_RING_SIZE; i++) {
398
+		if (priv->tx_buf[i])
399
+			net80211_tx_complete(dev, priv->tx_buf[i], 0, ECANCELED);
400
+		priv->tx_buf[i] = NULL;
401
+	}
402
+
403
+	free_dma(priv->tx_ring, sizeof(*priv->tx_ring) * RTL818X_TX_RING_SIZE);
404
+	priv->tx_ring = NULL;
405
+}
406
+
407
+static void rtl818x_irq(struct net80211_device *dev, int enable)
408
+{
409
+	struct rtl818x_priv *priv = dev->priv;
410
+	rtl818x_iowrite16(priv, &priv->map->INT_MASK, enable? 0xFFFF : 0);
411
+}
412
+
413
+/* Sets the MAC address of the card. */
414
+static void rtl818x_set_hwaddr(struct net80211_device *dev, u8 *hwaddr)
415
+{
416
+	struct rtl818x_priv *priv = dev->priv;
417
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
418
+	rtl818x_iowrite32(priv, (u32 *)&priv->map->MAC[0],
419
+			  le32_to_cpu(*(u32 *)hwaddr));
420
+	rtl818x_iowrite16(priv, (u16 *)&priv->map->MAC[4],
421
+			  le16_to_cpu(*(u16 *)(hwaddr + 4)));
422
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
423
+}
424
+
425
+static int rtl818x_start(struct net80211_device *dev)
426
+{
427
+	struct rtl818x_priv *priv = dev->priv;
428
+	int ret;
429
+	u32 reg;
430
+
431
+	ret = rtl818x_init_rx_ring(dev);
432
+	if (ret)
433
+		return ret;
434
+
435
+	ret = rtl818x_init_tx_ring(dev);
436
+	if (ret)
437
+		goto err_free_rings;
438
+
439
+	ret = rtl818x_init_hw(dev);
440
+	if (ret)
441
+		goto err_free_rings;
442
+
443
+	rtl818x_set_hwaddr(dev, dev->netdev->ll_addr);
444
+
445
+	rtl818x_iowrite32(priv, &priv->map->RDSAR, priv->rx_ring_dma);
446
+	rtl818x_iowrite32(priv, &priv->map->TNPDA, priv->tx_ring_dma);
447
+
448
+	rtl818x_iowrite16(priv, &priv->map->INT_MASK, 0);
449
+
450
+	rtl818x_iowrite32(priv, &priv->map->MAR[0], ~0);
451
+	rtl818x_iowrite32(priv, &priv->map->MAR[1], ~0);
452
+
453
+	reg = RTL818X_RX_CONF_ONLYERLPKT |
454
+	      RTL818X_RX_CONF_RX_AUTORESETPHY |
455
+	      RTL818X_RX_CONF_MGMT |
456
+	      RTL818X_RX_CONF_DATA |
457
+	      (7 << 8 /* MAX RX DMA */) |
458
+	      RTL818X_RX_CONF_BROADCAST |
459
+	      RTL818X_RX_CONF_NICMAC;
460
+
461
+	if (priv->r8185)
462
+		reg |= RTL818X_RX_CONF_CSDM1 | RTL818X_RX_CONF_CSDM2;
463
+	else {
464
+		reg |= (priv->rfparam & RF_PARAM_CARRIERSENSE1)
465
+			? RTL818X_RX_CONF_CSDM1 : 0;
466
+		reg |= (priv->rfparam & RF_PARAM_CARRIERSENSE2)
467
+			? RTL818X_RX_CONF_CSDM2 : 0;
468
+	}
469
+
470
+	priv->rx_conf = reg;
471
+	rtl818x_iowrite32(priv, &priv->map->RX_CONF, reg);
472
+
473
+	if (priv->r8185) {
474
+		reg = rtl818x_ioread8(priv, &priv->map->CW_CONF);
475
+		reg &= ~RTL818X_CW_CONF_PERPACKET_CW_SHIFT;
476
+		reg |= RTL818X_CW_CONF_PERPACKET_RETRY_SHIFT;
477
+		rtl818x_iowrite8(priv, &priv->map->CW_CONF, reg);
478
+
479
+		reg = rtl818x_ioread8(priv, &priv->map->TX_AGC_CTL);
480
+		reg &= ~RTL818X_TX_AGC_CTL_PERPACKET_GAIN_SHIFT;
481
+		reg &= ~RTL818X_TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT;
482
+		reg |=  RTL818X_TX_AGC_CTL_FEEDBACK_ANT;
483
+		rtl818x_iowrite8(priv, &priv->map->TX_AGC_CTL, reg);
484
+
485
+		/* disable early TX */
486
+		rtl818x_iowrite8(priv, (u8 *)priv->map + 0xec, 0x3f);
487
+	}
488
+
489
+	reg = rtl818x_ioread32(priv, &priv->map->TX_CONF);
490
+	reg |= (6 << 21 /* MAX TX DMA */) |
491
+	       RTL818X_TX_CONF_NO_ICV;
492
+
493
+	if (priv->r8185)
494
+		reg &= ~RTL818X_TX_CONF_PROBE_DTS;
495
+	else
496
+		reg &= ~RTL818X_TX_CONF_HW_SEQNUM;
497
+
498
+	/* different meaning, same value on both rtl8185 and rtl8180 */
499
+	reg &= ~RTL818X_TX_CONF_SAT_HWPLCP;
500
+
501
+	rtl818x_iowrite32(priv, &priv->map->TX_CONF, reg);
502
+
503
+	reg = rtl818x_ioread8(priv, &priv->map->CMD);
504
+	reg |= RTL818X_CMD_RX_ENABLE;
505
+	reg |= RTL818X_CMD_TX_ENABLE;
506
+	rtl818x_iowrite8(priv, &priv->map->CMD, reg);
507
+
508
+	DBG("%s rtl818x: started\n", dev->netdev->name);
509
+
510
+	return 0;
511
+
512
+ err_free_rings:
513
+	rtl818x_free_rx_ring(dev);
514
+	if (priv->tx_ring)
515
+		rtl818x_free_tx_ring(dev);
516
+
517
+	DBG("%s rtl818x: failed to start\n", dev->netdev->name);
518
+
519
+	return ret;
520
+}
521
+
522
+static void rtl818x_stop(struct net80211_device *dev)
523
+{
524
+	struct rtl818x_priv *priv = dev->priv;
525
+	u8 reg;
526
+
527
+	rtl818x_irq(dev, 0);
528
+
529
+	reg = rtl818x_ioread8(priv, &priv->map->CMD);
530
+	reg &= ~RTL818X_CMD_TX_ENABLE;
531
+	reg &= ~RTL818X_CMD_RX_ENABLE;
532
+	rtl818x_iowrite8(priv, &priv->map->CMD, reg);
533
+
534
+	priv->rf->stop(dev);
535
+
536
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
537
+	reg = rtl818x_ioread8(priv, &priv->map->CONFIG4);
538
+	rtl818x_iowrite8(priv, &priv->map->CONFIG4, reg | RTL818X_CONFIG4_VCOOFF);
539
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
540
+
541
+	rtl818x_free_rx_ring(dev);
542
+	rtl818x_free_tx_ring(dev);
543
+}
544
+
545
+static int rtl818x_config(struct net80211_device *dev, int changed)
546
+{
547
+	struct rtl818x_priv *priv = dev->priv;
548
+	int i;
549
+
550
+	if (changed & NET80211_CFG_CHANNEL)
551
+		priv->rf->set_chan(dev, &dev->channels[dev->channel]);
552
+
553
+	if (changed & NET80211_CFG_ASSOC) {
554
+		for (i = 0; i < ETH_ALEN; i++)
555
+			rtl818x_iowrite8(priv, &priv->map->BSSID[i], dev->bssid[i]);
556
+		rtl818x_iowrite8(priv, &priv->map->MSR,
557
+				 dev->state & NET80211_ASSOCIATED?
558
+					RTL818X_MSR_INFRA : RTL818X_MSR_NO_LINK);
559
+	}
560
+
561
+	if (changed & NET80211_CFG_PHY_PARAMS)
562
+		priv->rf->conf_erp(dev);
563
+
564
+	if (changed & NET80211_CFG_RATE) {
565
+		/* figure out the hardware rate number for the new
566
+		   logical rate */
567
+		int hw_rate;
568
+		for (hw_rate = 0; hw_rate < RTL818X_NR_RATES &&
569
+			     rtl818x_rates[hw_rate] != dev->rates[dev->rate];
570
+		     hw_rate++)
571
+			;
572
+		if (hw_rate >= RTL818X_NR_RATES)
573
+			return -EINVAL;
574
+
575
+		priv->hw_rate = hw_rate;
576
+
577
+		/* and the RTS/CTS rate */
578
+		for (hw_rate = 0; hw_rate < RTL818X_NR_RATES &&
579
+			     rtl818x_rates[hw_rate] !=
580
+				dev->rates[dev->rtscts_rate];
581
+		     hw_rate++)
582
+			;
583
+		if (hw_rate >= RTL818X_NR_RATES)
584
+			hw_rate = priv->hw_rate;
585
+
586
+		priv->hw_rtscts_rate = hw_rate;
587
+	}
588
+
589
+	return 0;
590
+}
591
+
592
+static const u8 rtl818x_eeprom_bits[] = {
593
+	[SPI_BIT_SCLK] = RTL818X_EEPROM_CMD_CK,
594
+	[SPI_BIT_MISO] = RTL818X_EEPROM_CMD_READ,
595
+	[SPI_BIT_MOSI] = RTL818X_EEPROM_CMD_WRITE,
596
+	[SPI_BIT_SS(0)] = RTL818X_EEPROM_CMD_CS,
597
+};
598
+
599
+static int rtl818x_spi_read_bit(struct bit_basher *basher, unsigned int bit_id)
600
+{
601
+	struct rtl818x_priv *priv = container_of(basher, struct rtl818x_priv,
602
+						 spibit.basher);
603
+
604
+	u8 reg = rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
605
+	return reg & rtl818x_eeprom_bits[bit_id];
606
+}
607
+
608
+static void rtl818x_spi_write_bit(struct bit_basher *basher,
609
+				  unsigned int bit_id, unsigned long data)
610
+{
611
+	struct rtl818x_priv *priv = container_of(basher, struct rtl818x_priv,
612
+						 spibit.basher);
613
+
614
+	u8 reg = rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
615
+	u8 mask = rtl818x_eeprom_bits[bit_id];
616
+	reg = (reg & ~mask) | (data & mask);
617
+
618
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, reg);
619
+
620
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
621
+	udelay(10);
622
+}
623
+
624
+static struct bit_basher_operations rtl818x_basher_ops = {
625
+	.read = rtl818x_spi_read_bit,
626
+	.write = rtl818x_spi_write_bit,
627
+};
628
+
629
+/* The net80211 code makes a copy of this, so we're OK modifying the
630
+   static version as we initialize the card, as long as we don't
631
+   depend on possibly-modified values in case there are multiple cards. */
632
+static struct net80211_hw_info rtl818x_hwinfo = {
633
+	/* MAC address filled in at runtime */
634
+	/* modes filled in at runtime */
635
+	.bands = NET80211_BAND_2GHZ,
636
+	.flags = NET80211_HW_RX_HAS_FCS,
637
+	.signal_type = NET80211_SIGNAL_ARBITRARY,
638
+	/* supported rates filled in at runtime */
639
+	.signal_max = 65,
640
+	.channel_change_time = 1000, /* no idea what the actual value is */
641
+};
642
+
643
+static const char *rtl818x_rf_names[] = {
644
+	NULL,			/* no 0 */
645
+	"Intersil", "RFMD",	/* unsupported 1-2 */
646
+	"SA2400", "max2820", "GRF5101",	/* supported 3-5 */
647
+	NULL, NULL, NULL,	/* no 6-8 */
648
+	"RTL8225",		/* supported 9 */
649
+	"RTL8255",		/* unsupported 10 */
650
+};
651
+#define RTL818X_NR_RF_NAMES 11
652
+
653
+struct net80211_device_operations rtl818x_operations = {
654
+	.open = rtl818x_start,
655
+	.close = rtl818x_stop,
656
+	.transmit = rtl818x_tx,
657
+	.poll = rtl818x_poll,
658
+	.irq = rtl818x_irq,
659
+	.config = rtl818x_config,
660
+};
661
+
662
+static int rtl818x_probe(struct pci_device *pdev,
663
+			 const struct pci_device_id *id __unused)
664
+{
665
+	struct net80211_device *dev;
666
+	struct rtl818x_priv *priv;
667
+	struct rtl818x_rf_ops *rf;
668
+	int err, i;
669
+	const char *chip_name;
670
+	u32 reg;
671
+	u16 eeprom_val;
672
+
673
+	adjust_pci_device(pdev);
674
+
675
+	dev = net80211_alloc(sizeof(*priv));
676
+	if (!dev) {
677
+		DBG("rtl818x: net80211 alloc failed\n");
678
+		return -ENOMEM;
679
+	}
680
+
681
+	priv = dev->priv;
682
+	priv->pdev = pdev;
683
+	dev->netdev->dev = &pdev->dev;
684
+
685
+	priv->map = (struct rtl818x_csr *)pdev->ioaddr;
686
+	if (!priv->map)
687
+		priv->map = (struct rtl818x_csr *)pdev->membase;
688
+
689
+	if (!priv->map) {
690
+		DBG("rtl818x: cannot find device memory\n");
691
+		err = -ENXIO;
692
+		goto err_free_dev;
693
+	}
694
+
695
+	reg = rtl818x_ioread32(priv, &priv->map->TX_CONF);
696
+	reg &= RTL818X_TX_CONF_HWVER_MASK;
697
+	switch (reg) {
698
+	case RTL818X_TX_CONF_R8180_ABCD:
699
+		chip_name = "0";
700
+		break;
701
+	case RTL818X_TX_CONF_R8180_F:
702
+		chip_name = "0vF";
703
+		break;
704
+	case RTL818X_TX_CONF_R8185_ABC:
705
+		chip_name = "5";
706
+		break;
707
+	case RTL818X_TX_CONF_R8185_D:
708
+		chip_name = "5vD";
709
+		break;
710
+	default:
711
+		DBG("rtl818x: Unknown chip! (0x%x)\n", reg >> 25);
712
+		err = -ENOSYS;
713
+		goto err_free_dev;
714
+	}
715
+
716
+	priv->r8185 = reg & RTL818X_TX_CONF_R8185_ABC;
717
+
718
+	memcpy(rtl818x_hwinfo.supported_rates, rtl818x_rates,
719
+	       sizeof(*rtl818x_rates) * RTL818X_NR_RATES);
720
+
721
+	if (priv->r8185) {
722
+		rtl818x_hwinfo.modes = NET80211_MODE_B | NET80211_MODE_G;
723
+		rtl818x_hwinfo.nr_supported_rates = RTL818X_NR_RATES;
724
+	} else {
725
+		rtl818x_hwinfo.modes = NET80211_MODE_B;
726
+		rtl818x_hwinfo.nr_supported_rates = RTL818X_NR_B_RATES;
727
+	}
728
+
729
+	priv->spibit.basher.op = &rtl818x_basher_ops;
730
+	priv->spibit.bus.mode = SPI_MODE_THREEWIRE;
731
+	init_spi_bit_basher(&priv->spibit);
732
+
733
+	DBG2("rtl818x RX_CONF: %08x\n", rtl818x_ioread32(priv, &priv->map->RX_CONF));
734
+
735
+	if (rtl818x_ioread32(priv, &priv->map->RX_CONF) & (1 << 6))
736
+		init_at93c66(&priv->eeprom, 16);
737
+	else
738
+		init_at93c46(&priv->eeprom, 16);
739
+	priv->eeprom.bus = &priv->spibit.bus;
740
+
741
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_PROGRAM);
742
+	rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
743
+	udelay(10);
744
+
745
+	nvs_read(&priv->eeprom.nvs, 0x06, &eeprom_val, 2);
746
+	DBG2("rtl818x eeprom val = %04x\n", eeprom_val);
747
+	eeprom_val &= 0xFF;
748
+
749
+	priv->rf = NULL;
750
+	for_each_table_entry(rf, RTL818X_RF_DRIVERS) {
751
+		if (rf->id == eeprom_val) {
752
+			priv->rf = rf;
753
+			break;
754
+		}
755
+	}
756
+
757
+	if (!priv->rf) {
758
+		if (eeprom_val < RTL818X_NR_RF_NAMES &&
759
+		    rtl818x_rf_names[eeprom_val] != NULL)
760
+			DBG("rtl818x: %s RF frontend not supported!\n",
761
+			    rtl818x_rf_names[eeprom_val]);
762
+		else
763
+			DBG("rtl818x: RF frontend #%d not recognized!\n",
764
+			    eeprom_val);
765
+
766
+		err = -ENOSYS;
767
+		goto err_free_dev;
768
+	}
769
+
770
+	nvs_read(&priv->eeprom.nvs, 0x17, &eeprom_val, 2);
771
+	priv->csthreshold = eeprom_val >> 8;
772
+	if (!priv->r8185) {
773
+		nvs_read(&priv->eeprom.nvs, 0xD, &priv->anaparam, 4);
774
+		nvs_read(&priv->eeprom.nvs, 0x19, &priv->rfparam, 2);
775
+		priv->anaparam = le32_to_cpu(priv->anaparam);
776
+		priv->rfparam = le16_to_cpu(priv->rfparam);
777
+	}
778
+
779
+	/* read the MAC address */
780
+	nvs_read(&priv->eeprom.nvs, 0x7, rtl818x_hwinfo.hwaddr, 6);
781
+
782
+	/* CCK TX power */
783
+	for (i = 0; i < 14; i += 2) {
784
+		u16 txpwr;
785
+		nvs_read(&priv->eeprom.nvs, 0x10 + (i >> 1), &txpwr, 2);
786
+		priv->txpower[i] = txpwr & 0xFF;
787
+		priv->txpower[i + 1] = txpwr >> 8;
788
+	}
789
+
790
+	/* OFDM TX power */
791
+	if (priv->r8185) {
792
+		for (i = 0; i < 14; i += 2) {
793
+			u16 txpwr;
794
+			nvs_read(&priv->eeprom.nvs, 0x20 + (i >> 1), &txpwr, 2);
795
+			priv->txpower[i] |= (txpwr & 0xFF) << 8;
796
+			priv->txpower[i + 1] |= txpwr & 0xFF00;
797
+		}
798
+	}
799
+
800
+	rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
801
+
802
+	err = net80211_register(dev, &rtl818x_operations, &rtl818x_hwinfo);
803
+	if (err) {
804
+		DBG("rtl818x: cannot register device\n");
805
+		goto err_free_dev;
806
+	}
807
+
808
+	DBG("rtl818x: Realtek RTL818%s (RF chip %s) with address %s\n",
809
+	    chip_name, priv->rf->name, netdev_hwaddr(dev->netdev));
810
+
811
+	return 0;
812
+
813
+ err_free_dev:
814
+	pci_set_drvdata(pdev, NULL);
815
+	net80211_free(dev);
816
+	return err;
817
+}
818
+
819
+static void rtl818x_remove(struct pci_device *pdev)
820
+{
821
+	struct net80211_device *dev = pci_get_drvdata(pdev);
822
+
823
+	if (!dev)
824
+		return;
825
+
826
+	net80211_unregister(dev);
827
+	net80211_free(dev);
828
+}
829
+
830
+/* Hide PCI_ROM definitions in here from parserom.pl; the definitions
831
+   that should be used are in rtl8180.c and rtl8185.c. */
832
+#define RTL_ROM PCI_ROM
833
+
834
+static struct pci_device_id rtl818x_nics[] = {
835
+	RTL_ROM(0x10ec, 0x8185, "rtl8185", "Realtek 8185", 0),
836
+	RTL_ROM(0x1799, 0x700f, "f5d7000", "Belkin F5D7000", 0),
837
+	RTL_ROM(0x1799, 0x701f, "f5d7010", "Belkin F5D7010", 0),
838
+
839
+	RTL_ROM(0x10ec, 0x8180, "rtl8180", "Realtek 8180", 0),
840
+	RTL_ROM(0x1799, 0x6001, "f5d6001", "Belkin F5D6001", 0),
841
+	RTL_ROM(0x1799, 0x6020, "f5d6020", "Belkin F5D6020", 0),
842
+	RTL_ROM(0x1186, 0x3300, "dwl510",  "D-Link DWL-510", 0),
843
+};
844
+
845
+struct pci_driver rtl818x_driver __pci_driver = {
846
+	.ids            = rtl818x_nics,
847
+	.id_count       = sizeof(rtl818x_nics) / sizeof(rtl818x_nics[0]),
848
+	.probe		= rtl818x_probe,
849
+	.remove		= rtl818x_remove,
850
+};

+ 359
- 0
src/drivers/net/rtl818x/rtl818x.h Datei anzeigen

@@ -0,0 +1,359 @@
1
+/*
2
+ * Definitions for RTL818x hardware
3
+ *
4
+ * Copyright 2007 Michael Wu <flamingice@sourmilk.net>
5
+ * Copyright 2007 Andrea Merello <andreamrl@tiscali.it>
6
+ *
7
+ * Modified for gPXE, June 2009, by Joshua Oreman <oremanj@rwcr.net>
8
+ *
9
+ * Based on the r8187 driver, which is:
10
+ * Copyright 2005 Andrea Merello <andreamrl@tiscali.it>, et al.
11
+ *
12
+ * This program is free software; you can redistribute it and/or modify
13
+ * it under the terms of the GNU General Public License version 2 as
14
+ * published by the Free Software Foundation.
15
+ */
16
+
17
+#ifndef RTL818X_H
18
+#define RTL818X_H
19
+
20
+#include <gpxe/spi_bit.h>
21
+#include <gpxe/tables.h>
22
+
23
+FILE_LICENCE(GPL2_ONLY);
24
+
25
+struct rtl818x_csr {
26
+	u8	MAC[6];
27
+	u8	reserved_0[2];
28
+	u32	MAR[2];
29
+	u8	RX_FIFO_COUNT;
30
+	u8	reserved_1;
31
+	u8	TX_FIFO_COUNT;
32
+	u8	BQREQ;
33
+	u8	reserved_2[4];
34
+	u32	TSFT[2];
35
+	u32	TLPDA;
36
+	u32	TNPDA;
37
+	u32	THPDA;
38
+	u16	BRSR;
39
+	u8	BSSID[6];
40
+	u8	RESP_RATE;
41
+	u8	EIFS;
42
+	u8	reserved_3[1];
43
+	u8	CMD;
44
+#define RTL818X_CMD_TX_ENABLE		(1 << 2)
45
+#define RTL818X_CMD_RX_ENABLE		(1 << 3)
46
+#define RTL818X_CMD_RESET		(1 << 4)
47
+	u8	reserved_4[4];
48
+	u16	INT_MASK;
49
+	u16	INT_STATUS;
50
+#define RTL818X_INT_RX_OK		(1 <<  0)
51
+#define RTL818X_INT_RX_ERR		(1 <<  1)
52
+#define RTL818X_INT_TXL_OK		(1 <<  2)
53
+#define RTL818X_INT_TXL_ERR		(1 <<  3)
54
+#define RTL818X_INT_RX_DU		(1 <<  4)
55
+#define RTL818X_INT_RX_FO		(1 <<  5)
56
+#define RTL818X_INT_TXN_OK		(1 <<  6)
57
+#define RTL818X_INT_TXN_ERR		(1 <<  7)
58
+#define RTL818X_INT_TXH_OK		(1 <<  8)
59
+#define RTL818X_INT_TXH_ERR		(1 <<  9)
60
+#define RTL818X_INT_TXB_OK		(1 << 10)
61
+#define RTL818X_INT_TXB_ERR		(1 << 11)
62
+#define RTL818X_INT_ATIM		(1 << 12)
63
+#define RTL818X_INT_BEACON		(1 << 13)
64
+#define RTL818X_INT_TIME_OUT		(1 << 14)
65
+#define RTL818X_INT_TX_FO		(1 << 15)
66
+	u32	TX_CONF;
67
+#define RTL818X_TX_CONF_LOOPBACK_MAC	(1 << 17)
68
+#define RTL818X_TX_CONF_LOOPBACK_CONT	(3 << 17)
69
+#define RTL818X_TX_CONF_NO_ICV		(1 << 19)
70
+#define RTL818X_TX_CONF_DISCW		(1 << 20)
71
+#define RTL818X_TX_CONF_SAT_HWPLCP	(1 << 24)
72
+#define RTL818X_TX_CONF_R8180_ABCD	(2 << 25)
73
+#define RTL818X_TX_CONF_R8180_F		(3 << 25)
74
+#define RTL818X_TX_CONF_R8185_ABC	(4 << 25)
75
+#define RTL818X_TX_CONF_R8185_D		(5 << 25)
76
+#define RTL818X_TX_CONF_R8187vD		(5 << 25)
77
+#define RTL818X_TX_CONF_R8187vD_B	(6 << 25)
78
+#define RTL818X_TX_CONF_HWVER_MASK	(7 << 25)
79
+#define RTL818X_TX_CONF_DISREQQSIZE	(1 << 28)
80
+#define RTL818X_TX_CONF_PROBE_DTS	(1 << 29)
81
+#define RTL818X_TX_CONF_HW_SEQNUM	(1 << 30)
82
+#define RTL818X_TX_CONF_CW_MIN		(1 << 31)
83
+	u32	RX_CONF;
84
+#define RTL818X_RX_CONF_MONITOR		(1 <<  0)
85
+#define RTL818X_RX_CONF_NICMAC		(1 <<  1)
86
+#define RTL818X_RX_CONF_MULTICAST	(1 <<  2)
87
+#define RTL818X_RX_CONF_BROADCAST	(1 <<  3)
88
+#define RTL818X_RX_CONF_FCS		(1 <<  5)
89
+#define RTL818X_RX_CONF_DATA		(1 << 18)
90
+#define RTL818X_RX_CONF_CTRL		(1 << 19)
91
+#define RTL818X_RX_CONF_MGMT		(1 << 20)
92
+#define RTL818X_RX_CONF_ADDR3		(1 << 21)
93
+#define RTL818X_RX_CONF_PM		(1 << 22)
94
+#define RTL818X_RX_CONF_BSSID		(1 << 23)
95
+#define RTL818X_RX_CONF_RX_AUTORESETPHY	(1 << 28)
96
+#define RTL818X_RX_CONF_CSDM1		(1 << 29)
97
+#define RTL818X_RX_CONF_CSDM2		(1 << 30)
98
+#define RTL818X_RX_CONF_ONLYERLPKT	(1 << 31)
99
+	u32	INT_TIMEOUT;
100
+	u32	TBDA;
101
+	u8	EEPROM_CMD;
102
+#define RTL818X_EEPROM_CMD_READ		(1 << 0)
103
+#define RTL818X_EEPROM_CMD_WRITE	(1 << 1)
104
+#define RTL818X_EEPROM_CMD_CK		(1 << 2)
105
+#define RTL818X_EEPROM_CMD_CS		(1 << 3)
106
+#define RTL818X_EEPROM_CMD_NORMAL	(0 << 6)
107
+#define RTL818X_EEPROM_CMD_LOAD		(1 << 6)
108
+#define RTL818X_EEPROM_CMD_PROGRAM	(2 << 6)
109
+#define RTL818X_EEPROM_CMD_CONFIG	(3 << 6)
110
+	u8	CONFIG0;
111
+	u8	CONFIG1;
112
+	u8	CONFIG2;
113
+#define RTL818X_CONFIG2_ANTENNA_DIV	(1 << 6)
114
+	u32	ANAPARAM;
115
+	u8	MSR;
116
+#define RTL818X_MSR_NO_LINK		(0 << 2)
117
+#define RTL818X_MSR_ADHOC		(1 << 2)
118
+#define RTL818X_MSR_INFRA		(2 << 2)
119
+#define RTL818X_MSR_MASTER		(3 << 2)
120
+#define RTL818X_MSR_ENEDCA		(4 << 2)
121
+	u8	CONFIG3;
122
+#define RTL818X_CONFIG3_ANAPARAM_WRITE	(1 << 6)
123
+#define RTL818X_CONFIG3_GNT_SELECT	(1 << 7)
124
+	u8	CONFIG4;
125
+#define RTL818X_CONFIG4_POWEROFF	(1 << 6)
126
+#define RTL818X_CONFIG4_VCOOFF		(1 << 7)
127
+	u8	TESTR;
128
+	u8	reserved_9[2];
129
+	u8	PGSELECT;
130
+	u8	SECURITY;
131
+	u32	ANAPARAM2;
132
+	u8	reserved_10[12];
133
+	u16	BEACON_INTERVAL;
134
+	u16	ATIM_WND;
135
+	u16	BEACON_INTERVAL_TIME;
136
+	u16	ATIMTR_INTERVAL;
137
+	u8	PHY_DELAY;
138
+	u8	CARRIER_SENSE_COUNTER;
139
+	u8	reserved_11[2];
140
+	u8	PHY[4];
141
+	u16	RFPinsOutput;
142
+	u16	RFPinsEnable;
143
+	u16	RFPinsSelect;
144
+	u16	RFPinsInput;
145
+	u32	RF_PARA;
146
+	u32	RF_TIMING;
147
+	u8	GP_ENABLE;
148
+	u8	GPIO;
149
+	u8	reserved_12[2];
150
+	u32	HSSI_PARA;
151
+	u8	reserved_13[4];
152
+	u8	TX_AGC_CTL;
153
+#define RTL818X_TX_AGC_CTL_PERPACKET_GAIN_SHIFT		(1 << 0)
154
+#define RTL818X_TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT	(1 << 1)
155
+#define RTL818X_TX_AGC_CTL_FEEDBACK_ANT			(1 << 2)
156
+	u8	TX_GAIN_CCK;
157
+	u8	TX_GAIN_OFDM;
158
+	u8	TX_ANTENNA;
159
+	u8	reserved_14[16];
160
+	u8	WPA_CONF;
161
+	u8	reserved_15[3];
162
+	u8	SIFS;
163
+	u8	DIFS;
164
+	u8	SLOT;
165
+	u8	reserved_16[5];
166
+	u8	CW_CONF;
167
+#define RTL818X_CW_CONF_PERPACKET_CW_SHIFT	(1 << 0)
168
+#define RTL818X_CW_CONF_PERPACKET_RETRY_SHIFT	(1 << 1)
169
+	u8	CW_VAL;
170
+	u8	RATE_FALLBACK;
171
+#define RTL818X_RATE_FALLBACK_ENABLE	(1 << 7)
172
+	u8	ACM_CONTROL;
173
+	u8	reserved_17[24];
174
+	u8	CONFIG5;
175
+	u8	TX_DMA_POLLING;
176
+	u8	reserved_18[2];
177
+	u16	CWR;
178
+	u8	RETRY_CTR;
179
+	u8	reserved_19[3];
180
+	u16	INT_MIG;
181
+/* RTL818X_R8187B_*: magic numbers from ioregisters */
182
+#define RTL818X_R8187B_B	0
183
+#define RTL818X_R8187B_D	1
184
+#define RTL818X_R8187B_E	2
185
+	u32	RDSAR;
186
+	u16	TID_AC_MAP;
187
+	u8	reserved_20[4];
188
+	u8	ANAPARAM3;
189
+	u8	reserved_21[5];
190
+	u16	FEMR;
191
+	u8	reserved_22[4];
192
+	u16	TALLY_CNT;
193
+	u8	TALLY_SEL;
194
+} __attribute__((packed));
195
+
196
+#define MAX_RX_SIZE IEEE80211_MAX_FRAME_LEN
197
+
198
+#define RF_PARAM_ANALOGPHY	(1 << 0)
199
+#define RF_PARAM_ANTBDEFAULT	(1 << 1)
200
+#define RF_PARAM_CARRIERSENSE1	(1 << 2)
201
+#define RF_PARAM_CARRIERSENSE2	(1 << 3)
202
+
203
+#define BB_ANTATTEN_CHAN14	0x0C
204
+#define BB_ANTENNA_B 		0x40
205
+
206
+#define BB_HOST_BANG 		(1 << 30)
207
+#define BB_HOST_BANG_EN 	(1 << 2)
208
+#define BB_HOST_BANG_CLK 	(1 << 1)
209
+#define BB_HOST_BANG_DATA	1
210
+
211
+#define ANAPARAM_TXDACOFF_SHIFT	27
212
+#define ANAPARAM_PWR0_SHIFT	28
213
+#define ANAPARAM_PWR0_MASK 	(0x07 << ANAPARAM_PWR0_SHIFT)
214
+#define ANAPARAM_PWR1_SHIFT	20
215
+#define ANAPARAM_PWR1_MASK	(0x7F << ANAPARAM_PWR1_SHIFT)
216
+
217
+#define RTL818X_RX_RING_SIZE	8 /* doesn't have to be a power of 2 */
218
+#define RTL818X_TX_RING_SIZE	8 /* nor this [but 2^n is very slightly faster] */
219
+#define RTL818X_RING_ALIGN	256
220
+
221
+#define RTL818X_MAX_RETRIES     4
222
+
223
+enum rtl818x_tx_desc_flags {
224
+	RTL818X_TX_DESC_FLAG_NO_ENC	= (1 << 15),
225
+	RTL818X_TX_DESC_FLAG_TX_OK	= (1 << 15),
226
+	RTL818X_TX_DESC_FLAG_SPLCP	= (1 << 16),
227
+	RTL818X_TX_DESC_FLAG_RX_UNDER	= (1 << 16),
228
+	RTL818X_TX_DESC_FLAG_MOREFRAG	= (1 << 17),
229
+	RTL818X_TX_DESC_FLAG_CTS	= (1 << 18),
230
+	RTL818X_TX_DESC_FLAG_RTS	= (1 << 23),
231
+	RTL818X_TX_DESC_FLAG_LS		= (1 << 28),
232
+	RTL818X_TX_DESC_FLAG_FS		= (1 << 29),
233
+	RTL818X_TX_DESC_FLAG_DMA	= (1 << 30),
234
+	RTL818X_TX_DESC_FLAG_OWN	= (1 << 31)
235
+};
236
+
237
+struct rtl818x_tx_desc {
238
+	u32 flags;
239
+	u16 rts_duration;
240
+	u16 plcp_len;
241
+	u32 tx_buf;
242
+	u32 frame_len;
243
+	u32 next_tx_desc;
244
+	u8 cw;
245
+	u8 retry_limit;
246
+	u8 agc;
247
+	u8 flags2;
248
+	u32 reserved[2];
249
+} __attribute__ ((packed));
250
+
251
+enum rtl818x_rx_desc_flags {
252
+	RTL818X_RX_DESC_FLAG_ICV_ERR	= (1 << 12),
253
+	RTL818X_RX_DESC_FLAG_CRC32_ERR	= (1 << 13),
254
+	RTL818X_RX_DESC_FLAG_PM		= (1 << 14),
255
+	RTL818X_RX_DESC_FLAG_RX_ERR	= (1 << 15),
256
+	RTL818X_RX_DESC_FLAG_BCAST	= (1 << 16),
257
+	RTL818X_RX_DESC_FLAG_PAM	= (1 << 17),
258
+	RTL818X_RX_DESC_FLAG_MCAST	= (1 << 18),
259
+	RTL818X_RX_DESC_FLAG_QOS	= (1 << 19), /* RTL8187(B) only */
260
+	RTL818X_RX_DESC_FLAG_TRSW	= (1 << 24), /* RTL8187(B) only */
261
+	RTL818X_RX_DESC_FLAG_SPLCP	= (1 << 25),
262
+	RTL818X_RX_DESC_FLAG_FOF	= (1 << 26),
263
+	RTL818X_RX_DESC_FLAG_DMA_FAIL	= (1 << 27),
264
+	RTL818X_RX_DESC_FLAG_LS		= (1 << 28),
265
+	RTL818X_RX_DESC_FLAG_FS		= (1 << 29),
266
+	RTL818X_RX_DESC_FLAG_EOR	= (1 << 30),
267
+	RTL818X_RX_DESC_FLAG_OWN	= (1 << 31)
268
+};
269
+
270
+struct rtl818x_rx_desc {
271
+	u32 flags;
272
+	u32 flags2;
273
+	union {
274
+		u32 rx_buf;
275
+		u64 tsft;
276
+	};
277
+} __attribute__ ((packed));
278
+
279
+struct rtl818x_priv {
280
+	struct rtl818x_csr *map;
281
+	const struct rtl818x_rf_ops *rf;
282
+	int rf_flag; /* whatever RF driver wishes to use it for */
283
+	int hw_rate;
284
+	int hw_rtscts_rate;
285
+
286
+	struct spi_bit_basher spibit;
287
+	struct spi_device eeprom;
288
+
289
+	struct rtl818x_rx_desc *rx_ring;
290
+	u32 rx_ring_dma;
291
+	unsigned int rx_idx;	/* next desc to be filled by card */
292
+	struct io_buffer *rx_buf[RTL818X_RX_RING_SIZE];
293
+
294
+	struct rtl818x_tx_desc *tx_ring;
295
+	u32 tx_ring_dma;
296
+	unsigned int tx_cons;	/* next desc to be filled by card */
297
+	unsigned int tx_prod;	/* next desc to be filled by driver */
298
+	struct io_buffer *tx_buf[RTL818X_TX_RING_SIZE];
299
+
300
+	struct pci_device *pdev;
301
+	u32 rx_conf;
302
+
303
+	u16 txpower[14];
304
+
305
+	int r8185;
306
+	u32 anaparam;
307
+	u16 rfparam;
308
+	u8 csthreshold;
309
+};
310
+
311
+void rtl818x_write_phy(struct net80211_device *dev, u8 addr, u32 data);
312
+void rtl818x_set_anaparam(struct rtl818x_priv *priv, u32 anaparam);
313
+
314
+static inline u8 rtl818x_ioread8(struct rtl818x_priv *priv __unused, u8 *addr)
315
+{
316
+	return inb(addr);
317
+}
318
+
319
+static inline u16 rtl818x_ioread16(struct rtl818x_priv *priv __unused, u16 *addr)
320
+{
321
+	return inw(addr);
322
+}
323
+
324
+static inline u32 rtl818x_ioread32(struct rtl818x_priv *priv __unused, u32 *addr)
325
+{
326
+	return inl(addr);
327
+}
328
+
329
+static inline void rtl818x_iowrite8(struct rtl818x_priv *priv __unused,
330
+				    u8 *addr, u8 val)
331
+{
332
+	outb(val, addr);
333
+}
334
+
335
+static inline void rtl818x_iowrite16(struct rtl818x_priv *priv __unused,
336
+				     u16 *addr, u16 val)
337
+{
338
+	outw(val, addr);
339
+}
340
+
341
+static inline void rtl818x_iowrite32(struct rtl818x_priv *priv __unused,
342
+				     u32 *addr, u32 val)
343
+{
344
+	outl(val, addr);
345
+}
346
+
347
+#define RTL818X_RF_DRIVERS __table(struct rtl818x_rf_ops, "rtl818x_rf_drivers")
348
+#define __rtl818x_rf_driver __table_entry(RTL818X_RF_DRIVERS, 01)
349
+
350
+struct rtl818x_rf_ops {
351
+	char *name;
352
+	u8 id;			/* as identified in EEPROM */
353
+	void (*init)(struct net80211_device *dev);
354
+	void (*stop)(struct net80211_device *dev);
355
+	void (*set_chan)(struct net80211_device *dev, struct net80211_channel *chan);
356
+	void (*conf_erp)(struct net80211_device *dev); /* set based on dev->erp_flags */
357
+};
358
+
359
+#endif /* RTL818X_H */

+ 1
- 0
src/include/gpxe/errfile.h Datei anzeigen

@@ -110,6 +110,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
110 110
 #define ERRFILE_phantom		     ( ERRFILE_DRIVER | 0x004b0000 )
111 111
 #define ERRFILE_ne2k_isa	     ( ERRFILE_DRIVER | 0x004c0000 )
112 112
 #define ERRFILE_b44		     ( ERRFILE_DRIVER | 0x004d0000 )
113
+#define ERRFILE_rtl818x		     ( ERRFILE_DRIVER | 0x004e0000 )
113 114
 
114 115
 #define ERRFILE_scsi		     ( ERRFILE_DRIVER | 0x00700000 )
115 116
 #define ERRFILE_arbel		     ( ERRFILE_DRIVER | 0x00710000 )

Laden…
Abbrechen
Speichern