public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Gregory CLEMENT <gregory.clement-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public•gmane.org>
To: Rajat Jain <rajatja-hpIqsD4AKlfQT0dZR+AlfA@public•gmane.org>
Cc: Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public•gmane.org>,
	Mark Rutland <mark.rutland-5wv7dgnIgG8@public•gmane.org>,
	Marcel Holtmann <marcel-kz+m5ild9QBg9hUCZPvPmw@public•gmane.org>,
	Gustavo Padovan <gustavo-THi1TnShQwVAfugRpC6u6w@public•gmane.org>,
	Johan Hedberg
	<johan.hedberg-Re5JQEeQqe8AvxtiuMwx3w@public•gmane.org>,
	Amitkumar Karwar
	<akarwar-eYqpPyKDWXRBDgjK7y7TUQ@public•gmane.org>,
	Wei-Ning Huang <wnhuang-F7+t8E8rja9g9hUCZPvPmw@public•gmane.org>,
	Xinming Hu <huxm-eYqpPyKDWXRBDgjK7y7TUQ@public•gmane.org>,
	netdev-u79uwXL29TY76Z2rM5mHXA@public•gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public•gmane.org,
	linux-bluetooth-u79uwXL29TY76Z2rM5mHXA@public•gmane.org,
	Brian Norris
	<briannorris-hpIqsD4AKlfQT0dZR+AlfA@public•gmane.org>,
	rajatxjain-Re5JQEeQqe8AvxtiuMwx3w@public•gmane.org
Subject: Re: [PATCH 3/3] Bluetooth: btusb: Configure Marvel to use one of the pins for oob wakeup
Date: Thu, 15 Dec 2016 09:29:49 +0100	[thread overview]
Message-ID: <87shppk32a.fsf@free-electrons.com> (raw)
In-Reply-To: <1481742779-15105-3-git-send-email-rajatja-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> (Rajat Jain's message of "Wed, 14 Dec 2016 11:12:59 -0800")

Hi Rajat,
 
 On mer., déc. 14 2016, Rajat Jain <rajatja-hpIqsD4AKlfQT0dZR+AlfA@public•gmane.org> wrote:

In your title unless you speak about the comic books you should do a
s/Marvel/Marvell/ :)

Gregory

> The Marvell devices may have many gpio pins, and hence for wakeup
> on these out-of-band pins, the chip needs to be told which pin is
> to be used for wakeup, using an hci command.
>
> Thus, we read the pin number etc from the device tree node and send
> a command to the chip.
>
> Signed-off-by: Rajat Jain <rajatja-hpIqsD4AKlfQT0dZR+AlfA@public•gmane.org>
> ---
> Note that while I would have liked to name the compatible string as more
> like "marvell, usb8997-bt", the devicetrees/bindings/usb/usb-device.txt
> requires the compatible property to be of the form "usbVID,PID".
>
>  .../{marvell-bt-sd8xxx.txt => marvell-bt-8xxx.txt} | 25 ++++++++-
>  drivers/bluetooth/btusb.c                          | 59 ++++++++++++++++++++++
>  2 files changed, 82 insertions(+), 2 deletions(-)
>  rename Documentation/devicetree/bindings/net/{marvell-bt-sd8xxx.txt => marvell-bt-8xxx.txt} (76%)
>
> diff --git a/Documentation/devicetree/bindings/net/marvell-bt-sd8xxx.txt b/Documentation/devicetree/bindings/net/marvell-bt-8xxx.txt
> similarity index 76%
> rename from Documentation/devicetree/bindings/net/marvell-bt-sd8xxx.txt
> rename to Documentation/devicetree/bindings/net/marvell-bt-8xxx.txt
> index 6a9a63c..471bef8 100644
> --- a/Documentation/devicetree/bindings/net/marvell-bt-sd8xxx.txt
> +++ b/Documentation/devicetree/bindings/net/marvell-bt-8xxx.txt
> @@ -1,4 +1,4 @@
> -Marvell 8897/8997 (sd8897/sd8997) bluetooth SDIO devices
> +Marvell 8897/8997 (sd8897/sd8997) bluetooth devices (SDIO or USB based)
>  ------
>  
>  Required properties:
> @@ -6,11 +6,13 @@ Required properties:
>    - compatible : should be one of the following:
>  	* "marvell,sd8897-bt"
>  	* "marvell,sd8997-bt"
> +	* "usb1286,204e"
>  
>  Optional properties:
>  
>    - marvell,cal-data: Calibration data downloaded to the device during
>  		      initialization. This is an array of 28 values(u8).
> +		      This is only applicable to SDIO devices.
>  
>    - marvell,wakeup-pin: It represents wakeup pin number of the bluetooth chip.
>  		        firmware will use the pin to wakeup host system (u16).
> @@ -29,7 +31,9 @@ Example:
>  IRQ pin 119 is used as system wakeup source interrupt.
>  wakeup pin 13 and gap 100ms are configured so that firmware can wakeup host
>  using this device side pin and wakeup latency.
> -calibration data is also available in below example.
> +
> +Example for SDIO device follows (calibration data is also available in
> +below example).
>  
>  &mmc3 {
>  	status = "okay";
> @@ -54,3 +58,20 @@ calibration data is also available in below example.
>  		marvell,wakeup-gap-ms = /bits/ 16 <0x64>;
>  	};
>  };
> +
> +Example for USB device:
> +
> +&usb_host1_ohci {
> +    status = "okay";
> +    #address-cells = <1>;
> +    #size-cells = <0>;
> +
> +    mvl_bt1: bt@1 {
> +	compatible = "usb1286,204e";
> +	reg = <1>;
> +	interrupt-parent = <&gpio0>;
> +	interrupts = <119 IRQ_TYPE_LEVEL_LOW>;
> +	marvell,wakeup-pin = /bits/ 16 <0x0d>;
> +	marvell,wakeup-gap-ms = /bits/ 16 <0x64>;
> +    };
> +};
> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> index 32a6f22..99d7f6d 100644
> --- a/drivers/bluetooth/btusb.c
> +++ b/drivers/bluetooth/btusb.c
> @@ -2343,6 +2343,58 @@ static int btusb_shutdown_intel(struct hci_dev *hdev)
>  	return 0;
>  }
>  
> +#ifdef CONFIG_PM
> +static const struct of_device_id mvl_oob_wake_match_table[] = {
> +	{ .compatible = "usb1286,204e" },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(of, mvl_oob_wake_match_table);
> +
> +/* Configure an out-of-band gpio as wake-up pin, if specified in device tree */
> +static int marvell_config_oob_wake(struct hci_dev *hdev)
> +{
> +	struct sk_buff *skb;
> +	struct btusb_data *data = hci_get_drvdata(hdev);
> +	struct device *dev = &data->udev->dev;
> +	u16 pin, gap, opcode;
> +	int ret;
> +	u8 cmd[5];
> +
> +	if (!of_match_device(mvl_oob_wake_match_table, dev))
> +		return 0;
> +
> +	if (of_property_read_u16(dev->of_node, "marvell,wakeup-pin", &pin) ||
> +	    of_property_read_u16(dev->of_node, "marvell,wakeup-gap-ms", &gap))
> +		return -EINVAL;
> +
> +	/* Vendor specific command to configure a GPIO as wake-up pin */
> +	opcode = hci_opcode_pack(0x3F, 0x59);
> +	cmd[0] = opcode & 0xFF;
> +	cmd[1] = opcode >> 8;
> +	cmd[2] = 2; /* length of parameters that follow */
> +	cmd[3] = pin;
> +	cmd[4] = gap; /* time in ms, for which wakeup pin should be asserted */
> +
> +	skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
> +	if (!skb) {
> +		bt_dev_err(hdev, "%s: No memory\n", __func__);
> +		return -ENOMEM;
> +	}
> +
> +	memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
> +	hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
> +
> +	ret = btusb_send_frame(hdev, skb);
> +	if (ret) {
> +		bt_dev_err(hdev, "%s: configuration failed\n", __func__);
> +		kfree_skb(skb);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +#endif
> +
>  static int btusb_set_bdaddr_marvell(struct hci_dev *hdev,
>  				    const bdaddr_t *bdaddr)
>  {
> @@ -2917,6 +2969,13 @@ static int btusb_probe(struct usb_interface *intf,
>  	err = btusb_config_oob_wake(hdev);
>  	if (err)
>  		goto out_free_dev;
> +
> +	/* Marvel devices may need a specific chip configuration */
> +	if (id->driver_info & BTUSB_MARVELL && data->oob_wake_irq) {
> +		err = marvell_config_oob_wake(hdev);
> +		if (err)
> +			goto out_free_dev;
> +	}
>  #endif
>  	if (id->driver_info & BTUSB_CW6622)
>  		set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks);
> -- 
> 2.8.0.rc3.226.g39d4020
>

-- 
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

  parent reply	other threads:[~2016-12-15  8:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-14 19:12 [PATCH 1/3] Bluetooth: btusb: Use an error label for error paths Rajat Jain
     [not found] ` <1481742779-15105-1-git-send-email-rajatja-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2016-12-14 19:12   ` [PATCH 2/3] Bluetooth: btusb: Add out-of-band wakeup support Rajat Jain
     [not found]     ` <1481742779-15105-2-git-send-email-rajatja-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2016-12-15  3:21       ` Brian Norris
     [not found]         ` <20161215032105.GA88921-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2016-12-16 19:43           ` Rajat Jain
2016-12-14 19:12   ` [PATCH 3/3] Bluetooth: btusb: Configure Marvel to use one of the pins for oob wakeup Rajat Jain
     [not found]     ` <1481742779-15105-3-git-send-email-rajatja-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2016-12-15  8:29       ` Gregory CLEMENT [this message]
2016-12-19 22:04     ` Rob Herring

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=87shppk32a.fsf@free-electrons.com \
    --to=gregory.clement-wi1+55scjutkeb57/3fjtnbpr1lh4cv8@public$(echo .)gmane.org \
    --cc=akarwar-eYqpPyKDWXRBDgjK7y7TUQ@public$(echo .)gmane.org \
    --cc=briannorris-hpIqsD4AKlfQT0dZR+AlfA@public$(echo .)gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public$(echo .)gmane.org \
    --cc=gustavo-THi1TnShQwVAfugRpC6u6w@public$(echo .)gmane.org \
    --cc=huxm-eYqpPyKDWXRBDgjK7y7TUQ@public$(echo .)gmane.org \
    --cc=johan.hedberg-Re5JQEeQqe8AvxtiuMwx3w@public$(echo .)gmane.org \
    --cc=linux-bluetooth-u79uwXL29TY76Z2rM5mHXA@public$(echo .)gmane.org \
    --cc=marcel-kz+m5ild9QBg9hUCZPvPmw@public$(echo .)gmane.org \
    --cc=mark.rutland-5wv7dgnIgG8@public$(echo .)gmane.org \
    --cc=netdev-u79uwXL29TY76Z2rM5mHXA@public$(echo .)gmane.org \
    --cc=rajatja-hpIqsD4AKlfQT0dZR+AlfA@public$(echo .)gmane.org \
    --cc=rajatxjain-Re5JQEeQqe8AvxtiuMwx3w@public$(echo .)gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public$(echo .)gmane.org \
    --cc=wnhuang-F7+t8E8rja9g9hUCZPvPmw@public$(echo .)gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox