1 // SPDX-License-Identifier: ISC
2 /*
3  * Copyright (c) 2014 Broadcom Corporation
4  */
5 #include <linux/init.h>
6 #include <linux/of.h>
7 #include <linux/of_irq.h>
8 
9 #include <defs.h>
10 #include "debug.h"
11 #include "core.h"
12 #include "common.h"
13 #include "of.h"
14 
15 void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
16 		    struct brcmf_mp_device *settings)
17 {
18 	struct brcmfmac_sdio_pd *sdio = &settings->bus.sdio;
19 	struct device_node *root, *np = dev->of_node;
20 	int irq;
21 	u32 irqf;
22 	u32 val;
23 
24 	/* Set board-type to the first string of the machine compatible prop */
25 	root = of_find_node_by_path("/");
26 	if (root) {
27 		int i, len;
28 		char *board_type;
29 		const char *tmp;
30 
31 		of_property_read_string_index(root, "compatible", 0, &tmp);
32 
33 		/* get rid of '/' in the compatible string to be able to find the FW */
34 		len = strlen(tmp) + 1;
35 		board_type = devm_kzalloc(dev, len, GFP_KERNEL);
36 		strscpy(board_type, tmp, len);
37 		for (i = 0; i < board_type[i]; i++) {
38 			if (board_type[i] == '/')
39 				board_type[i] = '-';
40 		}
41 		settings->board_type = board_type;
42 
43 		of_node_put(root);
44 	}
45 
46 	if (!np || bus_type != BRCMF_BUSTYPE_SDIO ||
47 	    !of_device_is_compatible(np, "brcm,bcm4329-fmac"))
48 		return;
49 
50 	if (of_property_read_u32(np, "brcm,drive-strength", &val) == 0)
51 		sdio->drive_strength = val;
52 
53 	/* make sure there are interrupts defined in the node */
54 	if (!of_find_property(np, "interrupts", NULL))
55 		return;
56 
57 	irq = irq_of_parse_and_map(np, 0);
58 	if (!irq) {
59 		brcmf_err("interrupt could not be mapped\n");
60 		return;
61 	}
62 	irqf = irqd_get_trigger_type(irq_get_irq_data(irq));
63 
64 	sdio->oob_irq_supported = true;
65 	sdio->oob_irq_nr = irq;
66 	sdio->oob_irq_flags = irqf;
67 }
68