blob: 763dbb0f41795f3ce1968cdf7d090665cf13876e [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
30/**************************************************
31 * Basic PHY ops.
32 **************************************************/
33
34static int b43_phy_ht_op_allocate(struct b43_wldev *dev)
35{
36 struct b43_phy_ht *phy_ht;
37
38 phy_ht = kzalloc(sizeof(*phy_ht), GFP_KERNEL);
39 if (!phy_ht)
40 return -ENOMEM;
41 dev->phy.ht = phy_ht;
42
43 return 0;
44}
45
46static void b43_phy_ht_op_prepare_structs(struct b43_wldev *dev)
47{
48 struct b43_phy *phy = &dev->phy;
49 struct b43_phy_ht *phy_ht = phy->ht;
50
51 memset(phy_ht, 0, sizeof(*phy_ht));
52}
53
54static void b43_phy_ht_op_free(struct b43_wldev *dev)
55{
56 struct b43_phy *phy = &dev->phy;
57 struct b43_phy_ht *phy_ht = phy->ht;
58
59 kfree(phy_ht);
60 phy->ht = NULL;
61}
62
Rafał Miłeckie7c62552011-06-19 02:18:11 +020063/* http://bcm-v4.sipsolutions.net/802.11/Radio/Switch%20Radio */
64static void b43_phy_ht_op_software_rfkill(struct b43_wldev *dev,
65 bool blocked)
66{
67 if (b43_read32(dev, B43_MMIO_MACCTL) & B43_MACCTL_ENABLED)
68 b43err(dev->wl, "MAC not suspended\n");
69
70 if (blocked) {
71 b43_phy_mask(dev, B43_PHY_HT_RF_CTL1, ~0);
72 } else {
Rafał Miłecki1a3f71a2011-06-19 02:18:12 +020073 b43_phy_mask(dev, B43_PHY_HT_RF_CTL1, ~0);
74 b43_phy_maskset(dev, B43_PHY_HT_RF_CTL1, ~0, 0x1);
75 b43_phy_mask(dev, B43_PHY_HT_RF_CTL1, ~0);
76 b43_phy_maskset(dev, B43_PHY_HT_RF_CTL1, ~0, 0x2);
Rafał Miłeckie7c62552011-06-19 02:18:11 +020077 }
78}
79
Rafał Miłeckia8e82742011-06-16 01:59:20 +020080static void b43_phy_ht_op_switch_analog(struct b43_wldev *dev, bool on)
81{
82 if (on) {
83 b43_phy_write(dev, B43_PHY_HT_AFE_CTL2, 0x00cd);
84 b43_phy_write(dev, B43_PHY_HT_AFE_CTL1, 0x0000);
85 b43_phy_write(dev, B43_PHY_HT_AFE_CTL4, 0x00cd);
86 b43_phy_write(dev, B43_PHY_HT_AFE_CTL3, 0x0000);
87 b43_phy_write(dev, B43_PHY_HT_AFE_CTL6, 0x00cd);
88 b43_phy_write(dev, B43_PHY_HT_AFE_CTL5, 0x0000);
89 } else {
90 b43_phy_write(dev, B43_PHY_HT_AFE_CTL1, 0x07ff);
91 b43_phy_write(dev, B43_PHY_HT_AFE_CTL2, 0x00fd);
92 b43_phy_write(dev, B43_PHY_HT_AFE_CTL3, 0x07ff);
93 b43_phy_write(dev, B43_PHY_HT_AFE_CTL4, 0x00fd);
94 b43_phy_write(dev, B43_PHY_HT_AFE_CTL5, 0x07ff);
95 b43_phy_write(dev, B43_PHY_HT_AFE_CTL6, 0x00fd);
96 }
97}
98
Rafał Miłeckid7520b12011-06-13 16:20:06 +020099static unsigned int b43_phy_ht_op_get_default_chan(struct b43_wldev *dev)
100{
101 if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ)
102 return 1;
103 return 36;
104}
105
106/**************************************************
107 * R/W ops.
108 **************************************************/
109
110static u16 b43_phy_ht_op_read(struct b43_wldev *dev, u16 reg)
111{
112 b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
113 return b43_read16(dev, B43_MMIO_PHY_DATA);
114}
115
116static void b43_phy_ht_op_write(struct b43_wldev *dev, u16 reg, u16 value)
117{
118 b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
119 b43_write16(dev, B43_MMIO_PHY_DATA, value);
120}
121
122static void b43_phy_ht_op_maskset(struct b43_wldev *dev, u16 reg, u16 mask,
123 u16 set)
124{
125 b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
126 b43_write16(dev, B43_MMIO_PHY_DATA,
127 (b43_read16(dev, B43_MMIO_PHY_DATA) & mask) | set);
128}
129
Rafał Miłecki4cabd422011-06-16 01:59:19 +0200130static u16 b43_phy_ht_op_radio_read(struct b43_wldev *dev, u16 reg)
131{
132 /* HT-PHY needs 0x200 for read access */
133 reg |= 0x200;
134
135 b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
136 return b43_read16(dev, B43_MMIO_RADIO24_DATA);
137}
138
139static void b43_phy_ht_op_radio_write(struct b43_wldev *dev, u16 reg,
140 u16 value)
141{
142 b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
143 b43_write16(dev, B43_MMIO_RADIO24_DATA, value);
144}
145
Rafał Miłeckid7520b12011-06-13 16:20:06 +0200146/**************************************************
147 * PHY ops struct.
148 **************************************************/
149
150const struct b43_phy_operations b43_phyops_ht = {
151 .allocate = b43_phy_ht_op_allocate,
152 .free = b43_phy_ht_op_free,
153 .prepare_structs = b43_phy_ht_op_prepare_structs,
154 /*
155 .init = b43_phy_ht_op_init,
156 */
157 .phy_read = b43_phy_ht_op_read,
158 .phy_write = b43_phy_ht_op_write,
159 .phy_maskset = b43_phy_ht_op_maskset,
Rafał Miłeckid7520b12011-06-13 16:20:06 +0200160 .radio_read = b43_phy_ht_op_radio_read,
161 .radio_write = b43_phy_ht_op_radio_write,
Rafał Miłeckid7520b12011-06-13 16:20:06 +0200162 .software_rfkill = b43_phy_ht_op_software_rfkill,
163 .switch_analog = b43_phy_ht_op_switch_analog,
Rafał Miłeckia8e82742011-06-16 01:59:20 +0200164 /*
Rafał Miłeckid7520b12011-06-13 16:20:06 +0200165 .switch_channel = b43_phy_ht_op_switch_channel,
166 */
167 .get_default_chan = b43_phy_ht_op_get_default_chan,
168 /*
169 .recalc_txpower = b43_phy_ht_op_recalc_txpower,
170 .adjust_txpower = b43_phy_ht_op_adjust_txpower,
171 */
172};