All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
To: Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
Cc: Marcel Holtmann <marcel@holtmann.org>,
	Johan Hedberg <johan.hedberg@gmail.com>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
	Amitkumar Karwar <amitkarwar@gmail.com>,
	Ganapathi Bhat <ganapathi017@gmail.com>,
	Sharvari Harisangam <sharvari.harisangam@nxp.com>,
	Xinming Hu <huxinming820@gmail.com>,
	Kalle Valo <kvalo@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	devicetree@vger.kernel.org, linux@ew.tq-group.com,
	Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Subject: [RFC 3/5] bluetooth: hci_mrvl: select firmwares to load by match data
Date: Wed, 26 Oct 2022 15:15:32 +0200	[thread overview]
Message-ID: <8417016ef049fa74a3b2961fdbc91638aebaf3a6.1666786471.git.matthias.schiffer@ew.tq-group.com> (raw)
In-Reply-To: <cover.1666786471.git.matthias.schiffer@ew.tq-group.com>

Make the driver more generic by adding a driver info struct. We also add
support for devices without firmware (for example when the firmware is
loaded by the WLAN driver on a combined module).

Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
---
 drivers/bluetooth/hci_mrvl.c | 57 +++++++++++++++++++++++++++++-------
 1 file changed, 46 insertions(+), 11 deletions(-)

diff --git a/drivers/bluetooth/hci_mrvl.c b/drivers/bluetooth/hci_mrvl.c
index fbc3f7c3a5c7..5d191687a34a 100644
--- a/drivers/bluetooth/hci_mrvl.c
+++ b/drivers/bluetooth/hci_mrvl.c
@@ -14,6 +14,7 @@
 #include <linux/module.h>
 #include <linux/tty.h>
 #include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/serdev.h>
 
 #include <net/bluetooth/bluetooth.h>
@@ -33,6 +34,20 @@ enum {
 	STATE_FW_REQ_PENDING,
 };
 
+struct mrvl_driver_info {
+	const char *firmware_helper;
+	const char *firmware;
+};
+
+static const struct mrvl_driver_info mrvl_driver_info_8897 = {
+	.firmware_helper = "mrvl/helper_uart_3000000.bin",
+	.firmware = "mrvl/uart8897_bt.bin",
+};
+
+/* Fallback for non-OF instances */
+static const struct mrvl_driver_info *const mrvl_driver_info_default =
+	&mrvl_driver_info_8897;
+
 struct mrvl_data {
 	struct sk_buff *rx_skb;
 	struct sk_buff_head txq;
@@ -44,6 +59,7 @@ struct mrvl_data {
 
 struct mrvl_serdev {
 	struct hci_uart hu;
+	const struct mrvl_driver_info *info;
 };
 
 struct hci_mrvl_pkt {
@@ -353,18 +369,29 @@ static int mrvl_load_firmware(struct hci_dev *hdev, const char *name)
 
 static int mrvl_setup(struct hci_uart *hu)
 {
+	const struct mrvl_driver_info *info;
 	int err;
 
-	hci_uart_set_flow_control(hu, true);
+	if (hu->serdev) {
+		struct mrvl_serdev *mrvldev = serdev_device_get_drvdata(hu->serdev);
 
-	err = mrvl_load_firmware(hu->hdev, "mrvl/helper_uart_3000000.bin");
-	if (err) {
-		bt_dev_err(hu->hdev, "Unable to download firmware helper");
-		return -EINVAL;
+		info = mrvldev->info;
+	} else {
+		info = mrvl_driver_info_default;
 	}
 
-	/* Let the final ack go out before switching the baudrate */
-	hci_uart_wait_until_sent(hu);
+	if (info->firmware_helper) {
+		hci_uart_set_flow_control(hu, true);
+
+		err = mrvl_load_firmware(hu->hdev, info->firmware_helper);
+		if (err) {
+			bt_dev_err(hu->hdev, "Unable to download firmware helper");
+			return -EINVAL;
+		}
+
+		/* Let the final ack go out before switching the baudrate */
+		hci_uart_wait_until_sent(hu);
+	}
 
 	if (hu->serdev)
 		serdev_device_set_baudrate(hu->serdev, 3000000);
@@ -373,9 +400,11 @@ static int mrvl_setup(struct hci_uart *hu)
 
 	hci_uart_set_flow_control(hu, false);
 
-	err = mrvl_load_firmware(hu->hdev, "mrvl/uart8897_bt.bin");
-	if (err)
-		return err;
+	if (info->firmware) {
+		err = mrvl_load_firmware(hu->hdev, info->firmware);
+		if (err)
+			return err;
+	}
 
 	return 0;
 }
@@ -401,6 +430,12 @@ static int mrvl_serdev_probe(struct serdev_device *serdev)
 	if (!mrvldev)
 		return -ENOMEM;
 
+	if (IS_ENABLED(CONFIG_OF)) {
+		mrvldev->info = of_device_get_match_data(&serdev->dev);
+		if (!mrvldev->info)
+			return -ENODEV;
+	}
+
 	mrvldev->hu.serdev = serdev;
 	serdev_device_set_drvdata(serdev, mrvldev);
 
@@ -416,7 +451,7 @@ static void mrvl_serdev_remove(struct serdev_device *serdev)
 
 #ifdef CONFIG_OF
 static const struct of_device_id mrvl_bluetooth_of_match[] = {
-	{ .compatible = "mrvl,88w8897" },
+	{ .compatible = "mrvl,88w8897", .data = &mrvl_driver_info_8897 },
 	{ },
 };
 MODULE_DEVICE_TABLE(of, mrvl_bluetooth_of_match);
-- 
2.25.1


  parent reply	other threads:[~2022-10-26 13:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-26 13:15 [RFC 0/5] "notify-device" for cross-driver readiness notification Matthias Schiffer
2022-10-26 13:15 ` [RFC 1/5] misc: introduce notify-device driver Matthias Schiffer
2022-10-26 13:32   ` "notify-device" for cross-driver readiness notification bluez.test.bot
2022-10-26 14:37   ` [RFC 1/5] misc: introduce notify-device driver Greg Kroah-Hartman
2022-10-27 16:33     ` Matthias Schiffer
2022-10-27 16:48       ` Greg Kroah-Hartman
2022-10-28  9:10         ` Matthias Schiffer
2022-10-27  0:04   ` kernel test robot
2022-10-26 13:15 ` [RFC 2/5] wireless: mwifiex: signal firmware readiness using notify-device Matthias Schiffer
2022-10-26 14:47   ` kernel test robot
2022-10-26 13:15 ` Matthias Schiffer [this message]
2022-10-26 13:15 ` [RFC 4/5] bluetooth: hci_mrvl: add support for SD8987 Matthias Schiffer
2022-10-27  1:55   ` kernel test robot
2022-10-26 13:15 ` [RFC 5/5] bluetooth: hci_mrvl: allow waiting for firmware load using notify-device Matthias Schiffer
2022-10-26 17:22   ` Krzysztof Kozlowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8417016ef049fa74a3b2961fdbc91638aebaf3a6.1666786471.git.matthias.schiffer@ew.tq-group.com \
    --to=matthias.schiffer@ew.tq-group.com \
    --cc=amitkarwar@gmail.com \
    --cc=arnd@arndb.de \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=ganapathi017@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=huxinming820@gmail.com \
    --cc=johan.hedberg@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=kuba@kernel.org \
    --cc=kvalo@kernel.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linux@ew.tq-group.com \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=robh+dt@kernel.org \
    --cc=sharvari.harisangam@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.