Skip to content

Commit 1a3ac5c

Browse files
shawnguo2Kalle Valo
authored andcommitted
brcmfmac: support parse country code map from DT
With any regulatory domain requests coming from either user space or 802.11 IE (Information Element), the country is coded in ISO3166 standard. It needs to be translated to firmware country code and revision with the mapping info in settings->country_codes table. Support populate country_codes table by parsing the mapping from DT. The BRCMF_BUSTYPE_SDIO bus_type check gets separated from general DT validation, so that country code can be handled as general part rather than SDIO bus specific one. Signed-off-by: Shawn Guo <[email protected]> Reviewed-by: Arend van Spriel <[email protected]> Signed-off-by: Kalle Valo <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 559c664 commit 1a3ac5c

File tree

1 file changed

+55
-2
lines changed
  • drivers/net/wireless/broadcom/brcm80211/brcmfmac

1 file changed

+55
-2
lines changed

drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,59 @@
1212
#include "common.h"
1313
#include "of.h"
1414

15+
static int brcmf_of_get_country_codes(struct device *dev,
16+
struct brcmf_mp_device *settings)
17+
{
18+
struct device_node *np = dev->of_node;
19+
struct brcmfmac_pd_cc_entry *cce;
20+
struct brcmfmac_pd_cc *cc;
21+
int count;
22+
int i;
23+
24+
count = of_property_count_strings(np, "brcm,ccode-map");
25+
if (count < 0) {
26+
/* The property is optional, so return success if it doesn't
27+
* exist. Otherwise propagate the error code.
28+
*/
29+
return (count == -EINVAL) ? 0 : count;
30+
}
31+
32+
cc = devm_kzalloc(dev, sizeof(*cc) + count * sizeof(*cce), GFP_KERNEL);
33+
if (!cc)
34+
return -ENOMEM;
35+
36+
cc->table_size = count;
37+
38+
for (i = 0; i < count; i++) {
39+
const char *map;
40+
41+
cce = &cc->table[i];
42+
43+
if (of_property_read_string_index(np, "brcm,ccode-map",
44+
i, &map))
45+
continue;
46+
47+
/* String format e.g. US-Q2-86 */
48+
if (sscanf(map, "%2c-%2c-%d", cce->iso3166, cce->cc,
49+
&cce->rev) != 3)
50+
brcmf_err("failed to read country map %s\n", map);
51+
else
52+
brcmf_dbg(INFO, "%s-%s-%d\n", cce->iso3166, cce->cc,
53+
cce->rev);
54+
}
55+
56+
settings->country_codes = cc;
57+
58+
return 0;
59+
}
60+
1561
void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
1662
struct brcmf_mp_device *settings)
1763
{
1864
struct brcmfmac_sdio_pd *sdio = &settings->bus.sdio;
1965
struct device_node *root, *np = dev->of_node;
2066
int irq;
67+
int err;
2168
u32 irqf;
2269
u32 val;
2370

@@ -43,8 +90,14 @@ void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
4390
of_node_put(root);
4491
}
4592

46-
if (!np || bus_type != BRCMF_BUSTYPE_SDIO ||
47-
!of_device_is_compatible(np, "brcm,bcm4329-fmac"))
93+
if (!np || !of_device_is_compatible(np, "brcm,bcm4329-fmac"))
94+
return;
95+
96+
err = brcmf_of_get_country_codes(dev, settings);
97+
if (err)
98+
brcmf_err("failed to get OF country code map (err=%d)\n", err);
99+
100+
if (bus_type != BRCMF_BUSTYPE_SDIO)
48101
return;
49102

50103
if (of_property_read_u32(np, "brcm,drive-strength", &val) == 0)

0 commit comments

Comments
 (0)