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