1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2014 Broadcom Corporation
5 #include <linux/init.h>
7 #include <linux/of_irq.h>
16 static int brcmf_of_get_country_codes(struct device *dev,
17 struct brcmf_mp_device *settings)
19 struct device_node *np = dev->of_node;
20 struct brcmfmac_pd_cc_entry *cce;
21 struct brcmfmac_pd_cc *cc;
25 count = of_property_count_strings(np, "brcm,ccode-map");
27 /* The property is optional, so return success if it doesn't
28 * exist. Otherwise propagate the error code.
30 return (count == -EINVAL) ? 0 : count;
33 cc = devm_kzalloc(dev, sizeof(*cc) + count * sizeof(*cce), GFP_KERNEL);
37 cc->table_size = count;
39 for (i = 0; i < count; i++) {
44 if (of_property_read_string_index(np, "brcm,ccode-map",
48 /* String format e.g. US-Q2-86 */
49 if (sscanf(map, "%2c-%2c-%d", cce->iso3166, cce->cc,
51 brcmf_err("failed to read country map %s\n", map);
53 brcmf_dbg(INFO, "%s-%s-%d\n", cce->iso3166, cce->cc,
57 settings->country_codes = cc;
62 void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
63 struct brcmf_mp_device *settings)
65 struct brcmfmac_sdio_pd *sdio = &settings->bus.sdio;
66 struct device_node *root, *np = dev->of_node;
72 /* Set board-type to the first string of the machine compatible prop */
73 root = of_find_node_by_path("/");
79 of_property_read_string_index(root, "compatible", 0, &tmp);
81 /* get rid of '/' in the compatible string to be able to find the FW */
82 len = strlen(tmp) + 1;
83 board_type = devm_kzalloc(dev, len, GFP_KERNEL);
84 strscpy(board_type, tmp, len);
85 for (i = 0; i < board_type[i]; i++) {
86 if (board_type[i] == '/')
89 settings->board_type = board_type;
94 if (!np || !of_device_is_compatible(np, "brcm,bcm4329-fmac"))
97 err = brcmf_of_get_country_codes(dev, settings);
99 brcmf_err("failed to get OF country code map (err=%d)\n", err);
101 if (bus_type != BRCMF_BUSTYPE_SDIO)
104 if (of_property_read_u32(np, "brcm,drive-strength", &val) == 0)
105 sdio->drive_strength = val;
107 /* make sure there are interrupts defined in the node */
108 if (!of_find_property(np, "interrupts", NULL))
111 irq = irq_of_parse_and_map(np, 0);
113 brcmf_err("interrupt could not be mapped\n");
116 irqf = irqd_get_trigger_type(irq_get_irq_data(irq));
118 sdio->oob_irq_supported = true;
119 sdio->oob_irq_nr = irq;
120 sdio->oob_irq_flags = irqf;
123 struct brcmf_firmware_mapping *
124 brcmf_of_fwnames(struct device *dev, u32 *fwname_count)
126 struct device_node *np = dev->of_node;
127 struct brcmf_firmware_mapping *fwnames;
128 struct device_node *map_np, *fw_np;
132 map_np = of_get_child_by_name(np, "firmwares");
133 of_count = of_get_child_count(map_np);
137 fwnames = devm_kcalloc(dev, of_count,
138 sizeof(struct brcmf_firmware_mapping),
141 for_each_child_of_node(map_np, fw_np)
143 struct brcmf_firmware_mapping *cur = &fwnames[count];
145 if (of_property_read_u32(fw_np, "chipid", &cur->chipid) ||
146 of_property_read_u32(fw_np, "revmask", &cur->revmask))
148 cur->fw_base = of_get_property(fw_np, "fw_base", NULL);
153 *fwname_count = count;
155 return count ? fwnames : NULL;