1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2014 Broadcom Corporation
5 #include <linux/init.h>
7 #include <linux/of_irq.h>
15 static int brcmf_of_get_country_codes(struct device *dev,
16 struct brcmf_mp_device *settings)
18 struct device_node *np = dev->of_node;
19 struct brcmfmac_pd_cc_entry *cce;
20 struct brcmfmac_pd_cc *cc;
24 count = of_property_count_strings(np, "brcm,ccode-map");
26 /* The property is optional, so return success if it doesn't
27 * exist. Otherwise propagate the error code.
29 return (count == -EINVAL) ? 0 : count;
32 cc = devm_kzalloc(dev, struct_size(cc, table, count), GFP_KERNEL);
36 cc->table_size = count;
38 for (i = 0; i < count; i++) {
43 if (of_property_read_string_index(np, "brcm,ccode-map",
47 /* String format e.g. US-Q2-86 */
48 if (sscanf(map, "%2c-%2c-%d", cce->iso3166, cce->cc,
50 brcmf_err("failed to read country map %s\n", map);
52 brcmf_dbg(INFO, "%s-%s-%d\n", cce->iso3166, cce->cc,
56 settings->country_codes = cc;
61 void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
62 struct brcmf_mp_device *settings)
64 struct brcmfmac_sdio_pd *sdio = &settings->bus.sdio;
65 struct device_node *root, *np = dev->of_node;
71 /* Set board-type to the first string of the machine compatible prop */
72 root = of_find_node_by_path("/");
78 of_property_read_string_index(root, "compatible", 0, &tmp);
80 /* get rid of '/' in the compatible string to be able to find the FW */
81 len = strlen(tmp) + 1;
82 board_type = devm_kzalloc(dev, len, GFP_KERNEL);
83 strscpy(board_type, tmp, len);
84 for (i = 0; i < board_type[i]; i++) {
85 if (board_type[i] == '/')
88 settings->board_type = board_type;
93 if (!np || !of_device_is_compatible(np, "brcm,bcm4329-fmac"))
96 err = brcmf_of_get_country_codes(dev, settings);
98 brcmf_err("failed to get OF country code map (err=%d)\n", err);
100 if (bus_type != BRCMF_BUSTYPE_SDIO)
103 if (of_property_read_u32(np, "brcm,drive-strength", &val) == 0)
104 sdio->drive_strength = val;
106 /* make sure there are interrupts defined in the node */
107 if (!of_find_property(np, "interrupts", NULL))
110 irq = irq_of_parse_and_map(np, 0);
112 brcmf_err("interrupt could not be mapped\n");
115 irqf = irqd_get_trigger_type(irq_get_irq_data(irq));
117 sdio->oob_irq_supported = true;
118 sdio->oob_irq_nr = irq;
119 sdio->oob_irq_flags = irqf;