diff mbox series

[2/3] Bluetooth: btrtl: use board DT compatible string as config postfix

Message ID BYAPR20MB2472E58CDDC6B56773A050FABCF79@BYAPR20MB2472.namprd20.prod.outlook.com
State New
Headers show
Series [1/3] Bluetooth: btrtl: try config w/o postfix if postfixed one failed to load | expand

Commit Message

icenowy@outlook.com April 22, 2022, 4:02 p.m. UTC
From: Icenowy Zheng <icenowy@sipeed.com>

Mimic the behavior of brcmfmac driver, which uses the DT compatible
string of the board as the NVRAM postfix.

Signed-off-by: Icenowy Zheng <icenowy@sipeed.com>
---
 drivers/bluetooth/hci_h5.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
diff mbox series

Patch

diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
index c5a0409ef84f..d1f90b23a5e0 100644
--- a/drivers/bluetooth/hci_h5.c
+++ b/drivers/bluetooth/hci_h5.c
@@ -817,6 +817,7 @@  static int h5_serdev_probe(struct serdev_device *serdev)
 {
 	struct device *dev = &serdev->dev;
 	struct h5 *h5;
+	struct device_node *root;
 	const struct h5_device_data *data;
 
 	h5 = devm_kzalloc(dev, sizeof(*h5), GFP_KERNEL);
@@ -847,6 +848,32 @@  static int h5_serdev_probe(struct serdev_device *serdev)
 			return -ENODEV;
 
 		h5->vnd = data->vnd;
+
+		/* Set id to the first string of the machine compatible prop */
+		root = of_find_node_by_path("/");
+		if (root) {
+			int i, len;
+			char *id;
+			const char *tmp;
+
+			of_property_read_string_index(root, "compatible", 0,
+						      &tmp);
+
+			/*
+			 * get rid of '/' in the compatible string to be able
+			 * to find the FW
+			 */
+			len = strlen(tmp) + 1;
+			id = devm_kzalloc(dev, len, GFP_KERNEL);
+			strscpy(id, tmp, len);
+			for (i = 0; i < id[i]; i++) {
+				if (id[i] == '/')
+					id[i] = '-';
+			}
+			h5->id = id;
+
+			of_node_put(root);
+		}
 	}
 
 	if (data->driver_info & H5_INFO_WAKEUP_DISABLE)