diff mbox series

[B/C/D,v2,1/1] UBUNTU: SAUCE: Bluetooth: Support for LED on Edge Gateways

Message ID 20181017114210.30774-2-jesse.sung@canonical.com
State New
Headers show
Series Support Edge Gateway's Bluetooth LED | expand

Commit Message

Wen-chien Jesse Sung Oct. 17, 2018, 11:42 a.m. UTC
BugLink: https://launchpad.net/bugs/1798332

For Edge Gateway 5000/5100 only.

Add code for controlling bluetooth LED via firmware, and turns
the LED on and off when the interface is up and down accordingly.

Signed-off-by: Wen-chien Jesse Sung <jesse.sung@canonical.com>
---
 drivers/bluetooth/btusb.c | 42 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

Comments

Kleber Sacilotto de Souza Oct. 17, 2018, 3:14 p.m. UTC | #1
On 10/17/18 13:42, Wen-chien Jesse Sung wrote:
> BugLink: https://launchpad.net/bugs/1798332
> 
> For Edge Gateway 5000/5100 only.
> 
> Add code for controlling bluetooth LED via firmware, and turns
> the LED on and off when the interface is up and down accordingly.
> 
> Signed-off-by: Wen-chien Jesse Sung <jesse.sung@canonical.com>

Same with this one, already on Xenial since a long time:

Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>

> ---
>  drivers/bluetooth/btusb.c | 42 ++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 41 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> index 7d89db53edc8..e300f19ba762 100644
> --- a/drivers/bluetooth/btusb.c
> +++ b/drivers/bluetooth/btusb.c
> @@ -28,6 +28,7 @@
>  #include <linux/firmware.h>
>  #include <linux/of_device.h>
>  #include <linux/of_irq.h>
> +#include <linux/pci.h>
>  #include <linux/suspend.h>
>  #include <asm/unaligned.h>
>  
> @@ -2522,6 +2523,35 @@ static int btusb_set_bdaddr_marvell(struct hci_dev *hdev,
>  	return 0;
>  }
>  
> +#define BTUSB_EDGE_LED_COMMAND		0xfc77
> +
> +static void btusb_edge_set_led(struct hci_dev *hdev, bool state)
> +{
> +	struct sk_buff *skb;
> +	u8 config_led[] = { 0x09, 0x00, 0x01, 0x01 };
> +
> +	if (state)
> +		config_led[1] = 0x01;
> +
> +	skb = __hci_cmd_sync(hdev, BTUSB_EDGE_LED_COMMAND, sizeof(config_led), config_led, HCI_INIT_TIMEOUT);
> +	if (IS_ERR(skb))
> +		BT_ERR("%s fail to set LED (%ld)", hdev->name, PTR_ERR(skb));
> +	else
> +		kfree_skb(skb);
> +}
> +
> +static int btusb_edge_post_init(struct hci_dev *hdev)
> +{
> +	btusb_edge_set_led(hdev, true);
> +	return 0;
> +}
> +
> +static int btusb_edge_shutdown(struct hci_dev *hdev)
> +{
> +	btusb_edge_set_led(hdev, false);
> +	return 0;
> +}
> +
>  static int btusb_set_bdaddr_ath3012(struct hci_dev *hdev,
>  				    const bdaddr_t *bdaddr)
>  {
> @@ -3156,8 +3186,18 @@ static int btusb_probe(struct usb_interface *intf,
>  		set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks);
>  	}
>  
> -	if (id->driver_info & BTUSB_MARVELL)
> +	if (id->driver_info & BTUSB_MARVELL) {
> +		struct pci_dev *pdev;
>  		hdev->set_bdaddr = btusb_set_bdaddr_marvell;
> +		pdev = pci_get_subsys(PCI_ANY_ID, PCI_ANY_ID, 0x1028, 0x0720, NULL);
> +		if (!pdev)
> +			pdev = pci_get_subsys(PCI_ANY_ID, PCI_ANY_ID, 0x1028, 0x0733, NULL);
> +		if (pdev) {
> +			pci_dev_put(pdev);
> +			hdev->post_init = btusb_edge_post_init;
> +			hdev->shutdown = btusb_edge_shutdown;
> +		}
> +	}
>  
>  	if (id->driver_info & BTUSB_SWAVE) {
>  		set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks);
>
Stefan Bader Oct. 17, 2018, 4:10 p.m. UTC | #2
On 17.10.18 13:42, Wen-chien Jesse Sung wrote:
> BugLink: https://launchpad.net/bugs/1798332
> 
> For Edge Gateway 5000/5100 only.
> 
> Add code for controlling bluetooth LED via firmware, and turns
> the LED on and off when the interface is up and down accordingly.
> 
> Signed-off-by: Wen-chien Jesse Sung <jesse.sung@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
> ---
>  drivers/bluetooth/btusb.c | 42 ++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 41 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> index 7d89db53edc8..e300f19ba762 100644
> --- a/drivers/bluetooth/btusb.c
> +++ b/drivers/bluetooth/btusb.c
> @@ -28,6 +28,7 @@
>  #include <linux/firmware.h>
>  #include <linux/of_device.h>
>  #include <linux/of_irq.h>
> +#include <linux/pci.h>
>  #include <linux/suspend.h>
>  #include <asm/unaligned.h>
>  
> @@ -2522,6 +2523,35 @@ static int btusb_set_bdaddr_marvell(struct hci_dev *hdev,
>  	return 0;
>  }
>  
> +#define BTUSB_EDGE_LED_COMMAND		0xfc77
> +
> +static void btusb_edge_set_led(struct hci_dev *hdev, bool state)
> +{
> +	struct sk_buff *skb;
> +	u8 config_led[] = { 0x09, 0x00, 0x01, 0x01 };
> +
> +	if (state)
> +		config_led[1] = 0x01;
> +
> +	skb = __hci_cmd_sync(hdev, BTUSB_EDGE_LED_COMMAND, sizeof(config_led), config_led, HCI_INIT_TIMEOUT);
> +	if (IS_ERR(skb))
> +		BT_ERR("%s fail to set LED (%ld)", hdev->name, PTR_ERR(skb));
> +	else
> +		kfree_skb(skb);
> +}
> +
> +static int btusb_edge_post_init(struct hci_dev *hdev)
> +{
> +	btusb_edge_set_led(hdev, true);
> +	return 0;
> +}
> +
> +static int btusb_edge_shutdown(struct hci_dev *hdev)
> +{
> +	btusb_edge_set_led(hdev, false);
> +	return 0;
> +}
> +
>  static int btusb_set_bdaddr_ath3012(struct hci_dev *hdev,
>  				    const bdaddr_t *bdaddr)
>  {
> @@ -3156,8 +3186,18 @@ static int btusb_probe(struct usb_interface *intf,
>  		set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks);
>  	}
>  
> -	if (id->driver_info & BTUSB_MARVELL)
> +	if (id->driver_info & BTUSB_MARVELL) {
> +		struct pci_dev *pdev;
>  		hdev->set_bdaddr = btusb_set_bdaddr_marvell;
> +		pdev = pci_get_subsys(PCI_ANY_ID, PCI_ANY_ID, 0x1028, 0x0720, NULL);
> +		if (!pdev)
> +			pdev = pci_get_subsys(PCI_ANY_ID, PCI_ANY_ID, 0x1028, 0x0733, NULL);
> +		if (pdev) {
> +			pci_dev_put(pdev);
> +			hdev->post_init = btusb_edge_post_init;
> +			hdev->shutdown = btusb_edge_shutdown;
> +		}
> +	}
>  
>  	if (id->driver_info & BTUSB_SWAVE) {
>  		set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks);
>
diff mbox series

Patch

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 7d89db53edc8..e300f19ba762 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -28,6 +28,7 @@ 
 #include <linux/firmware.h>
 #include <linux/of_device.h>
 #include <linux/of_irq.h>
+#include <linux/pci.h>
 #include <linux/suspend.h>
 #include <asm/unaligned.h>
 
@@ -2522,6 +2523,35 @@  static int btusb_set_bdaddr_marvell(struct hci_dev *hdev,
 	return 0;
 }
 
+#define BTUSB_EDGE_LED_COMMAND		0xfc77
+
+static void btusb_edge_set_led(struct hci_dev *hdev, bool state)
+{
+	struct sk_buff *skb;
+	u8 config_led[] = { 0x09, 0x00, 0x01, 0x01 };
+
+	if (state)
+		config_led[1] = 0x01;
+
+	skb = __hci_cmd_sync(hdev, BTUSB_EDGE_LED_COMMAND, sizeof(config_led), config_led, HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb))
+		BT_ERR("%s fail to set LED (%ld)", hdev->name, PTR_ERR(skb));
+	else
+		kfree_skb(skb);
+}
+
+static int btusb_edge_post_init(struct hci_dev *hdev)
+{
+	btusb_edge_set_led(hdev, true);
+	return 0;
+}
+
+static int btusb_edge_shutdown(struct hci_dev *hdev)
+{
+	btusb_edge_set_led(hdev, false);
+	return 0;
+}
+
 static int btusb_set_bdaddr_ath3012(struct hci_dev *hdev,
 				    const bdaddr_t *bdaddr)
 {
@@ -3156,8 +3186,18 @@  static int btusb_probe(struct usb_interface *intf,
 		set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks);
 	}
 
-	if (id->driver_info & BTUSB_MARVELL)
+	if (id->driver_info & BTUSB_MARVELL) {
+		struct pci_dev *pdev;
 		hdev->set_bdaddr = btusb_set_bdaddr_marvell;
+		pdev = pci_get_subsys(PCI_ANY_ID, PCI_ANY_ID, 0x1028, 0x0720, NULL);
+		if (!pdev)
+			pdev = pci_get_subsys(PCI_ANY_ID, PCI_ANY_ID, 0x1028, 0x0733, NULL);
+		if (pdev) {
+			pci_dev_put(pdev);
+			hdev->post_init = btusb_edge_post_init;
+			hdev->shutdown = btusb_edge_shutdown;
+		}
+	}
 
 	if (id->driver_info & BTUSB_SWAVE) {
 		set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks);