blob: 12ad47f38dff7005ee5e868fe807b6af5c73a096 [file] [log] [blame]
Rafał Miłeckid7520b12011-06-13 16:20:06 +02001/*
2
3 Broadcom B43 wireless driver
4 IEEE 802.11n HT-PHY support
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20
21*/
22
23#include <linux/slab.h>
24
25#include "b43.h"
26#include "phy_ht.h"
Rafał Miłecki5192bf52011-06-19 12:17:19 +020027#include "radio_2059.h"
Rafał Miłeckid7520b12011-06-13 16:20:06 +020028#include "main.h"
29
Rafał Miłecki39ca5542011-06-19 12:17:20 +020030static void b43_radio_2059_channel_setup(struct b43_wldev *dev,
31 const struct b43_phy_ht_channeltab_e_radio2059 *e)
32{
33 /* TODO */
34}
35
36static void b43_phy_ht_channel_setup(struct b43_wldev *dev,
37 const struct b43_phy_ht_channeltab_e_phy *e,
38 struct ieee80211_channel *new_channel)
39{
40 /* TODO */
41}
42
43static int b43_phy_ht_set_channel(struct b43_wldev *dev,
44 struct ieee80211_channel *channel,
45 enum nl80211_channel_type channel_type)
46{
47 struct b43_phy *phy = &dev->phy;
48
49 const struct b43_phy_ht_channeltab_e_radio2059 *chent_r2059 = NULL;
50
51 if (phy->radio_ver == 0x2059) {
52 chent_r2059 = b43_phy_ht_get_channeltab_e_r2059(dev,
53 channel->center_freq);
54 if (!chent_r2059)
55 return -ESRCH;
56 } else {
57 return -ESRCH;
58 }
59
60 /* TODO: In case of N-PHY some bandwidth switching goes here */
61
62 if (phy->radio_ver == 0x2059) {
63 b43_radio_2059_channel_setup(dev, chent_r2059);
64 b43_phy_ht_channel_setup(dev, &(chent_r2059->phy_regs),
65 channel);
66 } else {
67 return -ESRCH;
68 }
69
70 return 0;
71}
72
Rafał Miłeckid7520b12011-06-13 16:20:06 +020073/**************************************************
74 * Basic PHY ops.
75 **************************************************/
76
77static int b43_phy_ht_op_allocate(struct b43_wldev *dev)
78{
79 struct b43_phy_ht *phy_ht;
80
81 phy_ht = kzalloc(sizeof(*phy_ht), GFP_KERNEL);
82 if (!phy_ht)
83 return -ENOMEM;
84 dev->phy.ht = phy_ht;
85
86 return 0;
87}
88
89static void b43_phy_ht_op_prepare_structs(struct b43_wldev *dev)
90{
91 struct b43_phy *phy = &dev->phy;
92 struct b43_phy_ht *phy_ht = phy->ht;
93
94 memset(phy_ht, 0, sizeof(*phy_ht));
95}
96
97static void b43_phy_ht_op_free(struct b43_wldev *dev)
98{
99 struct b43_phy *phy = &dev->phy;
100 struct b43_phy_ht *phy_ht = phy->ht;
101
102 kfree(phy_ht);
103 phy->ht = NULL;
104}
105
Rafał Miłeckie7c62552011-06-19 02:18:11 +0200106/* http://bcm-v4.sipsolutions.net/802.11/Radio/Switch%20Radio */
107static void b43_phy_ht_op_software_rfkill(struct b43_wldev *dev,
108 bool blocked)
109{
110 if (b43_read32(dev, B43_MMIO_MACCTL) & B43_MACCTL_ENABLED)
111 b43err(dev->wl, "MAC not suspended\n");
112
113 if (blocked) {
114 b43_phy_mask(dev, B43_PHY_HT_RF_CTL1, ~0);
115 } else {
Rafał Miłecki1a3f71a2011-06-19 02:18:12 +0200116 b43_phy_mask(dev, B43_PHY_HT_RF_CTL1, ~0);
117 b43_phy_maskset(dev, B43_PHY_HT_RF_CTL1, ~0, 0x1);
118 b43_phy_mask(dev, B43_PHY_HT_RF_CTL1, ~0);
119 b43_phy_maskset(dev, B43_PHY_HT_RF_CTL1, ~0, 0x2);
Rafał Miłeckie7c62552011-06-19 02:18:11 +0200120 }
121}
122
Rafał Miłeckia8e82742011-06-16 01:59:20 +0200123static void b43_phy_ht_op_switch_analog(struct b43_wldev *dev, bool on)
124{
125 if (on) {
126 b43_phy_write(dev, B43_PHY_HT_AFE_CTL2, 0x00cd);
127 b43_phy_write(dev, B43_PHY_HT_AFE_CTL1, 0x0000);
128 b43_phy_write(dev, B43_PHY_HT_AFE_CTL4, 0x00cd);
129 b43_phy_write(dev, B43_PHY_HT_AFE_CTL3, 0x0000);
130 b43_phy_write(dev, B43_PHY_HT_AFE_CTL6, 0x00cd);
131 b43_phy_write(dev, B43_PHY_HT_AFE_CTL5, 0x0000);
132 } else {
133 b43_phy_write(dev, B43_PHY_HT_AFE_CTL1, 0x07ff);
134 b43_phy_write(dev, B43_PHY_HT_AFE_CTL2, 0x00fd);
135 b43_phy_write(dev, B43_PHY_HT_AFE_CTL3, 0x07ff);
136 b43_phy_write(dev, B43_PHY_HT_AFE_CTL4, 0x00fd);
137 b43_phy_write(dev, B43_PHY_HT_AFE_CTL5, 0x07ff);
138 b43_phy_write(dev, B43_PHY_HT_AFE_CTL6, 0x00fd);
139 }
140}
141
Rafał Miłecki39ca5542011-06-19 12:17:20 +0200142static int b43_phy_ht_op_switch_channel(struct b43_wldev *dev,
143 unsigned int new_channel)
144{
145 struct ieee80211_channel *channel = dev->wl->hw->conf.channel;
146 enum nl80211_channel_type channel_type = dev->wl->hw->conf.channel_type;
147
148 if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
149 if ((new_channel < 1) || (new_channel > 14))
150 return -EINVAL;
151 } else {
152 return -EINVAL;
153 }
154
155 return b43_phy_ht_set_channel(dev, channel, channel_type);
156}
157
Rafał Miłeckid7520b12011-06-13 16:20:06 +0200158static unsigned int b43_phy_ht_op_get_default_chan(struct b43_wldev *dev)
159{
160 if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ)
161 return 1;
162 return 36;
163}
164
165/**************************************************
166 * R/W ops.
167 **************************************************/
168
169static u16 b43_phy_ht_op_read(struct b43_wldev *dev, u16 reg)
170{
171 b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
172 return b43_read16(dev, B43_MMIO_PHY_DATA);
173}
174
175static void b43_phy_ht_op_write(struct b43_wldev *dev, u16 reg, u16 value)
176{
177 b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
178 b43_write16(dev, B43_MMIO_PHY_DATA, value);
179}
180
181static void b43_phy_ht_op_maskset(struct b43_wldev *dev, u16 reg, u16 mask,
182 u16 set)
183{
184 b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
185 b43_write16(dev, B43_MMIO_PHY_DATA,
186 (b43_read16(dev, B43_MMIO_PHY_DATA) & mask) | set);
187}
188
Rafał Miłecki4cabd422011-06-16 01:59:19 +0200189static u16 b43_phy_ht_op_radio_read(struct b43_wldev *dev, u16 reg)
190{
191 /* HT-PHY needs 0x200 for read access */
192 reg |= 0x200;
193
194 b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
195 return b43_read16(dev, B43_MMIO_RADIO24_DATA);
196}
197
198static void b43_phy_ht_op_radio_write(struct b43_wldev *dev, u16 reg,
199 u16 value)
200{
201 b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
202 b43_write16(dev, B43_MMIO_RADIO24_DATA, value);
203}
204
Rafał Miłeckid7520b12011-06-13 16:20:06 +0200205/**************************************************
206 * PHY ops struct.
207 **************************************************/
208
209const struct b43_phy_operations b43_phyops_ht = {
210 .allocate = b43_phy_ht_op_allocate,
211 .free = b43_phy_ht_op_free,
212 .prepare_structs = b43_phy_ht_op_prepare_structs,
213 /*
214 .init = b43_phy_ht_op_init,
215 */
216 .phy_read = b43_phy_ht_op_read,
217 .phy_write = b43_phy_ht_op_write,
218 .phy_maskset = b43_phy_ht_op_maskset,
Rafał Miłeckid7520b12011-06-13 16:20:06 +0200219 .radio_read = b43_phy_ht_op_radio_read,
220 .radio_write = b43_phy_ht_op_radio_write,
Rafał Miłeckid7520b12011-06-13 16:20:06 +0200221 .software_rfkill = b43_phy_ht_op_software_rfkill,
222 .switch_analog = b43_phy_ht_op_switch_analog,
Rafał Miłeckid7520b12011-06-13 16:20:06 +0200223 .switch_channel = b43_phy_ht_op_switch_channel,
Rafał Miłeckid7520b12011-06-13 16:20:06 +0200224 .get_default_chan = b43_phy_ht_op_get_default_chan,
225 /*
226 .recalc_txpower = b43_phy_ht_op_recalc_txpower,
227 .adjust_txpower = b43_phy_ht_op_adjust_txpower,
228 */
229};