2 * Copyright (c) 2013 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 /*********************channel spec common functions*********************/
18 #include <linux/module.h>
20 #include <brcmu_utils.h>
21 #include <brcmu_wifi.h>
22 #include <brcmu_d11.h>
24 static void brcmu_d11n_encchspec(struct brcmu_chan
*ch
)
26 ch
->chspec
= ch
->chnum
& BRCMU_CHSPEC_CH_MASK
;
29 case BRCMU_CHAN_BW_20
:
30 ch
->chspec
|= BRCMU_CHSPEC_D11N_BW_20
| BRCMU_CHSPEC_D11N_SB_N
;
32 case BRCMU_CHAN_BW_40
:
38 if (ch
->chnum
<= CH_MAX_2G_CHANNEL
)
39 ch
->chspec
|= BRCMU_CHSPEC_D11N_BND_2G
;
41 ch
->chspec
|= BRCMU_CHSPEC_D11N_BND_5G
;
44 static void brcmu_d11ac_encchspec(struct brcmu_chan
*ch
)
46 ch
->chspec
= ch
->chnum
& BRCMU_CHSPEC_CH_MASK
;
49 case BRCMU_CHAN_BW_20
:
50 ch
->chspec
|= BRCMU_CHSPEC_D11AC_BW_20
;
52 case BRCMU_CHAN_BW_40
:
53 case BRCMU_CHAN_BW_80
:
54 case BRCMU_CHAN_BW_80P80
:
55 case BRCMU_CHAN_BW_160
:
61 if (ch
->chnum
<= CH_MAX_2G_CHANNEL
)
62 ch
->chspec
|= BRCMU_CHSPEC_D11AC_BND_2G
;
64 ch
->chspec
|= BRCMU_CHSPEC_D11AC_BND_5G
;
67 static void brcmu_d11n_decchspec(struct brcmu_chan
*ch
)
71 ch
->chnum
= (u8
)(ch
->chspec
& BRCMU_CHSPEC_CH_MASK
);
73 switch (ch
->chspec
& BRCMU_CHSPEC_D11N_BW_MASK
) {
74 case BRCMU_CHSPEC_D11N_BW_20
:
75 ch
->bw
= BRCMU_CHAN_BW_20
;
77 case BRCMU_CHSPEC_D11N_BW_40
:
78 ch
->bw
= BRCMU_CHAN_BW_40
;
79 val
= ch
->chspec
& BRCMU_CHSPEC_D11N_SB_MASK
;
80 if (val
== BRCMU_CHSPEC_D11N_SB_L
) {
81 ch
->sb
= BRCMU_CHAN_SB_L
;
82 ch
->chnum
-= CH_10MHZ_APART
;
84 ch
->sb
= BRCMU_CHAN_SB_U
;
85 ch
->chnum
+= CH_10MHZ_APART
;
93 switch (ch
->chspec
& BRCMU_CHSPEC_D11N_BND_MASK
) {
94 case BRCMU_CHSPEC_D11N_BND_5G
:
95 ch
->band
= BRCMU_CHAN_BAND_5G
;
97 case BRCMU_CHSPEC_D11N_BND_2G
:
98 ch
->band
= BRCMU_CHAN_BAND_2G
;
106 static void brcmu_d11ac_decchspec(struct brcmu_chan
*ch
)
110 ch
->chnum
= (u8
)(ch
->chspec
& BRCMU_CHSPEC_CH_MASK
);
112 switch (ch
->chspec
& BRCMU_CHSPEC_D11AC_BW_MASK
) {
113 case BRCMU_CHSPEC_D11AC_BW_20
:
114 ch
->bw
= BRCMU_CHAN_BW_20
;
116 case BRCMU_CHSPEC_D11AC_BW_40
:
117 ch
->bw
= BRCMU_CHAN_BW_40
;
118 val
= ch
->chspec
& BRCMU_CHSPEC_D11AC_SB_MASK
;
119 if (val
== BRCMU_CHSPEC_D11AC_SB_L
) {
120 ch
->sb
= BRCMU_CHAN_SB_L
;
121 ch
->chnum
-= CH_10MHZ_APART
;
122 } else if (val
== BRCMU_CHSPEC_D11AC_SB_U
) {
123 ch
->sb
= BRCMU_CHAN_SB_U
;
124 ch
->chnum
+= CH_10MHZ_APART
;
129 case BRCMU_CHSPEC_D11AC_BW_80
:
130 ch
->bw
= BRCMU_CHAN_BW_80
;
132 case BRCMU_CHSPEC_D11AC_BW_8080
:
133 case BRCMU_CHSPEC_D11AC_BW_160
:
139 switch (ch
->chspec
& BRCMU_CHSPEC_D11AC_BND_MASK
) {
140 case BRCMU_CHSPEC_D11AC_BND_5G
:
141 ch
->band
= BRCMU_CHAN_BAND_5G
;
143 case BRCMU_CHSPEC_D11AC_BND_2G
:
144 ch
->band
= BRCMU_CHAN_BAND_2G
;
152 void brcmu_d11_attach(struct brcmu_d11inf
*d11inf
)
154 if (d11inf
->io_type
== BRCMU_D11N_IOTYPE
) {
155 d11inf
->encchspec
= brcmu_d11n_encchspec
;
156 d11inf
->decchspec
= brcmu_d11n_decchspec
;
158 d11inf
->encchspec
= brcmu_d11ac_encchspec
;
159 d11inf
->decchspec
= brcmu_d11ac_decchspec
;
162 EXPORT_SYMBOL(brcmu_d11_attach
);