2015-04-05 07:13:03 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Bluetooth HCI UART driver for Broadcom devices
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Intel Corporation
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/skbuff.h>
|
2015-05-28 17:25:01 +08:00
|
|
|
#include <linux/firmware.h>
|
2015-08-11 22:35:35 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/acpi.h>
|
2017-08-18 01:59:51 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/property.h>
|
Bluetooth: hci_bcm: Support Apple GPIO handling
Enable Bluetooth on the following Macs which provide custom ACPI methods
to toggle the GPIOs for device wake and shutdown instead of accessing
the pins directly:
MacBook8,1 2015 12"
MacBook9,1 2016 12"
MacBook10,1 2017 12"
MacBookPro13,1 2016 13"
MacBookPro13,2 2016 13" with Touch Bar
MacBookPro13,3 2016 15" with Touch Bar
MacBookPro14,1 2017 13"
MacBookPro14,2 2017 13" with Touch Bar
MacBookPro14,3 2017 15" with Touch Bar
On the MacBook8,1 Bluetooth is muxed with a second device (a debug port
on the SSD) under the control of PCH GPIO 36. Because serdev cannot
deal with multiple slaves yet, it is currently necessary to patch the
DSDT and remove the SSDC device.
The custom ACPI methods are called:
BTLP (Low Power) takes one argument, toggles device wake GPIO
BTPU (Power Up) tells SMC to drive shutdown GPIO high
BTPD (Power Down) tells SMC to drive shutdown GPIO low
BTRS (Reset) calls BTPD followed by BTPU
BTRB unknown, not present on all MacBooks
Search for the BTLP, BTPU and BTPD methods on ->probe and cache them in
struct bcm_device if the machine is a Mac.
Additionally, set the init_speed based on a custom device property
provided by Apple in lieu of _CRS resources. The Broadcom UART's speed
is fixed on Apple Macs: Any attempt to change it results in Bluetooth
status code 0x0c and bcm_set_baudrate() thus always returns -EBUSY.
By setting only the init_speed and leaving oper_speed at zero, we can
achieve that the host UART's speed is adjusted but the Broadcom UART's
speed is left as is.
The host wake pin goes into the SMC which handles it independently
of the OS, so there's no IRQ for it.
Thanks to Ronald Tschalär who did extensive debugging and testing of
this patch and contributed fixes.
ACPI snippet containing the custom methods and device properties
(taken from a MacBook8,1):
Method (BTLP, 1, Serialized)
{
If (LEqual (Arg0, 0x00))
{
Store (0x01, GD54) /* set PCH GPIO 54 direction to input */
}
If (LEqual (Arg0, 0x01))
{
Store (0x00, GD54) /* set PCH GPIO 54 direction to output */
Store (0x00, GP54) /* set PCH GPIO 54 value to low */
}
}
Method (BTPU, 0, Serialized)
{
Store (0x01, \_SB.PCI0.LPCB.EC.BTPC)
Sleep (0x0A)
}
Method (BTPD, 0, Serialized)
{
Store (0x00, \_SB.PCI0.LPCB.EC.BTPC)
Sleep (0x0A)
}
Method (BTRS, 0, Serialized)
{
BTPD ()
BTPU ()
}
Method (_DSM, 4, NotSerialized) // _DSM: Device-Specific Method
{
If (LEqual (Arg0, ToUUID ("a0b5b7c6-1318-441c-b0c9-fe695eaf949b")))
{
Store (Package (0x08)
{
"baud",
Buffer (0x08)
{ 0xC0, 0xC6, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00 },
"parity",
Buffer (0x08)
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
"dataBits",
Buffer (0x08)
{ 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
"stopBits",
Buffer (0x08)
{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
}, Local0)
DTGP (Arg0, Arg1, Arg2, Arg3, RefOf (Local0))
Return (Local0)
}
Return (0x00)
}
Link: https://github.com/Dunedan/mbp-2016-linux/issues/29
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=110901
Reported-by: Leif Liddy <leif.liddy@gmail.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Loic Poulain <loic.poulain@linaro.org>
Cc: Hans de Goede <hdegoede@redhat.com>
Tested-by: Max Shavrick <mxms@me.com> [MacBook8,1]
Tested-by: Leif Liddy <leif.liddy@gmail.com> [MacBook9,1]
Tested-by: Daniel Roschka <danielroschka@phoenitydawn.de> [MacBookPro13,2]
Tested-by: Ronald Tschalär <ronald@innovation.ch> [MacBookPro13,3]
Tested-by: Peter Y. Chuang <peteryuchuang@gmail.com> [MacBookPro14,1]
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Ronald Tschalär <ronald@innovation.ch>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
#include <linux/platform_data/x86/apple.h>
|
2015-08-11 22:35:35 +08:00
|
|
|
#include <linux/platform_device.h>
|
2018-12-17 12:04:43 +08:00
|
|
|
#include <linux/regulator/consumer.h>
|
2015-08-11 22:35:35 +08:00
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/gpio/consumer.h>
|
|
|
|
#include <linux/tty.h>
|
2015-09-04 21:35:44 +08:00
|
|
|
#include <linux/interrupt.h>
|
2015-09-24 00:18:08 +08:00
|
|
|
#include <linux/dmi.h>
|
2015-09-24 00:18:11 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2017-08-18 01:59:51 +08:00
|
|
|
#include <linux/serdev.h>
|
2015-04-05 07:13:03 +08:00
|
|
|
|
|
|
|
#include <net/bluetooth/bluetooth.h>
|
|
|
|
#include <net/bluetooth/hci_core.h>
|
|
|
|
|
2015-04-06 13:52:18 +08:00
|
|
|
#include "btbcm.h"
|
2015-04-05 07:13:03 +08:00
|
|
|
#include "hci_uart.h"
|
2015-04-06 13:52:18 +08:00
|
|
|
|
2017-08-18 03:41:09 +08:00
|
|
|
#define BCM_NULL_PKT 0x00
|
|
|
|
#define BCM_NULL_SIZE 0
|
|
|
|
|
2015-10-08 01:12:54 +08:00
|
|
|
#define BCM_LM_DIAG_PKT 0x07
|
|
|
|
#define BCM_LM_DIAG_SIZE 63
|
|
|
|
|
2015-09-24 00:18:11 +08:00
|
|
|
#define BCM_AUTOSUSPEND_DELAY 5000 /* default autosleep delay */
|
|
|
|
|
2018-12-17 12:04:43 +08:00
|
|
|
#define BCM_NUM_SUPPLIES 2
|
|
|
|
|
2018-01-10 23:32:10 +08:00
|
|
|
/**
|
|
|
|
* struct bcm_device - device driver resources
|
|
|
|
* @serdev_hu: HCI UART controller struct
|
|
|
|
* @list: bcm_device_list node
|
|
|
|
* @dev: physical UART slave
|
|
|
|
* @name: device name logged by bt_dev_*() functions
|
|
|
|
* @device_wakeup: BT_WAKE pin,
|
|
|
|
* assert = Bluetooth device must wake up or remain awake,
|
|
|
|
* deassert = Bluetooth device may sleep when sleep criteria are met
|
|
|
|
* @shutdown: BT_REG_ON pin,
|
|
|
|
* power up or power down Bluetooth device internal regulators
|
2018-01-10 23:32:10 +08:00
|
|
|
* @set_device_wakeup: callback to toggle BT_WAKE pin
|
Bluetooth: hci_bcm: Support Apple GPIO handling
Enable Bluetooth on the following Macs which provide custom ACPI methods
to toggle the GPIOs for device wake and shutdown instead of accessing
the pins directly:
MacBook8,1 2015 12"
MacBook9,1 2016 12"
MacBook10,1 2017 12"
MacBookPro13,1 2016 13"
MacBookPro13,2 2016 13" with Touch Bar
MacBookPro13,3 2016 15" with Touch Bar
MacBookPro14,1 2017 13"
MacBookPro14,2 2017 13" with Touch Bar
MacBookPro14,3 2017 15" with Touch Bar
On the MacBook8,1 Bluetooth is muxed with a second device (a debug port
on the SSD) under the control of PCH GPIO 36. Because serdev cannot
deal with multiple slaves yet, it is currently necessary to patch the
DSDT and remove the SSDC device.
The custom ACPI methods are called:
BTLP (Low Power) takes one argument, toggles device wake GPIO
BTPU (Power Up) tells SMC to drive shutdown GPIO high
BTPD (Power Down) tells SMC to drive shutdown GPIO low
BTRS (Reset) calls BTPD followed by BTPU
BTRB unknown, not present on all MacBooks
Search for the BTLP, BTPU and BTPD methods on ->probe and cache them in
struct bcm_device if the machine is a Mac.
Additionally, set the init_speed based on a custom device property
provided by Apple in lieu of _CRS resources. The Broadcom UART's speed
is fixed on Apple Macs: Any attempt to change it results in Bluetooth
status code 0x0c and bcm_set_baudrate() thus always returns -EBUSY.
By setting only the init_speed and leaving oper_speed at zero, we can
achieve that the host UART's speed is adjusted but the Broadcom UART's
speed is left as is.
The host wake pin goes into the SMC which handles it independently
of the OS, so there's no IRQ for it.
Thanks to Ronald Tschalär who did extensive debugging and testing of
this patch and contributed fixes.
ACPI snippet containing the custom methods and device properties
(taken from a MacBook8,1):
Method (BTLP, 1, Serialized)
{
If (LEqual (Arg0, 0x00))
{
Store (0x01, GD54) /* set PCH GPIO 54 direction to input */
}
If (LEqual (Arg0, 0x01))
{
Store (0x00, GD54) /* set PCH GPIO 54 direction to output */
Store (0x00, GP54) /* set PCH GPIO 54 value to low */
}
}
Method (BTPU, 0, Serialized)
{
Store (0x01, \_SB.PCI0.LPCB.EC.BTPC)
Sleep (0x0A)
}
Method (BTPD, 0, Serialized)
{
Store (0x00, \_SB.PCI0.LPCB.EC.BTPC)
Sleep (0x0A)
}
Method (BTRS, 0, Serialized)
{
BTPD ()
BTPU ()
}
Method (_DSM, 4, NotSerialized) // _DSM: Device-Specific Method
{
If (LEqual (Arg0, ToUUID ("a0b5b7c6-1318-441c-b0c9-fe695eaf949b")))
{
Store (Package (0x08)
{
"baud",
Buffer (0x08)
{ 0xC0, 0xC6, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00 },
"parity",
Buffer (0x08)
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
"dataBits",
Buffer (0x08)
{ 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
"stopBits",
Buffer (0x08)
{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
}, Local0)
DTGP (Arg0, Arg1, Arg2, Arg3, RefOf (Local0))
Return (Local0)
}
Return (0x00)
}
Link: https://github.com/Dunedan/mbp-2016-linux/issues/29
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=110901
Reported-by: Leif Liddy <leif.liddy@gmail.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Loic Poulain <loic.poulain@linaro.org>
Cc: Hans de Goede <hdegoede@redhat.com>
Tested-by: Max Shavrick <mxms@me.com> [MacBook8,1]
Tested-by: Leif Liddy <leif.liddy@gmail.com> [MacBook9,1]
Tested-by: Daniel Roschka <danielroschka@phoenitydawn.de> [MacBookPro13,2]
Tested-by: Ronald Tschalär <ronald@innovation.ch> [MacBookPro13,3]
Tested-by: Peter Y. Chuang <peteryuchuang@gmail.com> [MacBookPro14,1]
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Ronald Tschalär <ronald@innovation.ch>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
* either by accessing @device_wakeup or by calling @btlp
|
2018-01-10 23:32:10 +08:00
|
|
|
* @set_shutdown: callback to toggle BT_REG_ON pin
|
Bluetooth: hci_bcm: Support Apple GPIO handling
Enable Bluetooth on the following Macs which provide custom ACPI methods
to toggle the GPIOs for device wake and shutdown instead of accessing
the pins directly:
MacBook8,1 2015 12"
MacBook9,1 2016 12"
MacBook10,1 2017 12"
MacBookPro13,1 2016 13"
MacBookPro13,2 2016 13" with Touch Bar
MacBookPro13,3 2016 15" with Touch Bar
MacBookPro14,1 2017 13"
MacBookPro14,2 2017 13" with Touch Bar
MacBookPro14,3 2017 15" with Touch Bar
On the MacBook8,1 Bluetooth is muxed with a second device (a debug port
on the SSD) under the control of PCH GPIO 36. Because serdev cannot
deal with multiple slaves yet, it is currently necessary to patch the
DSDT and remove the SSDC device.
The custom ACPI methods are called:
BTLP (Low Power) takes one argument, toggles device wake GPIO
BTPU (Power Up) tells SMC to drive shutdown GPIO high
BTPD (Power Down) tells SMC to drive shutdown GPIO low
BTRS (Reset) calls BTPD followed by BTPU
BTRB unknown, not present on all MacBooks
Search for the BTLP, BTPU and BTPD methods on ->probe and cache them in
struct bcm_device if the machine is a Mac.
Additionally, set the init_speed based on a custom device property
provided by Apple in lieu of _CRS resources. The Broadcom UART's speed
is fixed on Apple Macs: Any attempt to change it results in Bluetooth
status code 0x0c and bcm_set_baudrate() thus always returns -EBUSY.
By setting only the init_speed and leaving oper_speed at zero, we can
achieve that the host UART's speed is adjusted but the Broadcom UART's
speed is left as is.
The host wake pin goes into the SMC which handles it independently
of the OS, so there's no IRQ for it.
Thanks to Ronald Tschalär who did extensive debugging and testing of
this patch and contributed fixes.
ACPI snippet containing the custom methods and device properties
(taken from a MacBook8,1):
Method (BTLP, 1, Serialized)
{
If (LEqual (Arg0, 0x00))
{
Store (0x01, GD54) /* set PCH GPIO 54 direction to input */
}
If (LEqual (Arg0, 0x01))
{
Store (0x00, GD54) /* set PCH GPIO 54 direction to output */
Store (0x00, GP54) /* set PCH GPIO 54 value to low */
}
}
Method (BTPU, 0, Serialized)
{
Store (0x01, \_SB.PCI0.LPCB.EC.BTPC)
Sleep (0x0A)
}
Method (BTPD, 0, Serialized)
{
Store (0x00, \_SB.PCI0.LPCB.EC.BTPC)
Sleep (0x0A)
}
Method (BTRS, 0, Serialized)
{
BTPD ()
BTPU ()
}
Method (_DSM, 4, NotSerialized) // _DSM: Device-Specific Method
{
If (LEqual (Arg0, ToUUID ("a0b5b7c6-1318-441c-b0c9-fe695eaf949b")))
{
Store (Package (0x08)
{
"baud",
Buffer (0x08)
{ 0xC0, 0xC6, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00 },
"parity",
Buffer (0x08)
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
"dataBits",
Buffer (0x08)
{ 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
"stopBits",
Buffer (0x08)
{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
}, Local0)
DTGP (Arg0, Arg1, Arg2, Arg3, RefOf (Local0))
Return (Local0)
}
Return (0x00)
}
Link: https://github.com/Dunedan/mbp-2016-linux/issues/29
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=110901
Reported-by: Leif Liddy <leif.liddy@gmail.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Loic Poulain <loic.poulain@linaro.org>
Cc: Hans de Goede <hdegoede@redhat.com>
Tested-by: Max Shavrick <mxms@me.com> [MacBook8,1]
Tested-by: Leif Liddy <leif.liddy@gmail.com> [MacBook9,1]
Tested-by: Daniel Roschka <danielroschka@phoenitydawn.de> [MacBookPro13,2]
Tested-by: Ronald Tschalär <ronald@innovation.ch> [MacBookPro13,3]
Tested-by: Peter Y. Chuang <peteryuchuang@gmail.com> [MacBookPro14,1]
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Ronald Tschalär <ronald@innovation.ch>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
* either by accessing @shutdown or by calling @btpu/@btpd
|
|
|
|
* @btlp: Apple ACPI method to toggle BT_WAKE pin ("Bluetooth Low Power")
|
|
|
|
* @btpu: Apple ACPI method to drive BT_REG_ON pin high ("Bluetooth Power Up")
|
|
|
|
* @btpd: Apple ACPI method to drive BT_REG_ON pin low ("Bluetooth Power Down")
|
2018-12-17 12:04:41 +08:00
|
|
|
* @txco_clk: external reference frequency clock used by Bluetooth device
|
2018-12-17 12:04:42 +08:00
|
|
|
* @lpo_clk: external LPO clock used by Bluetooth device
|
2018-12-17 12:04:43 +08:00
|
|
|
* @supplies: VBAT and VDDIO supplies used by Bluetooth device
|
|
|
|
* @res_enabled: whether clocks and supplies are prepared and enabled
|
2018-01-10 23:32:10 +08:00
|
|
|
* @init_speed: default baudrate of Bluetooth device;
|
|
|
|
* the host UART is initially set to this baudrate so that
|
|
|
|
* it can configure the Bluetooth device for @oper_speed
|
|
|
|
* @oper_speed: preferred baudrate of Bluetooth device;
|
|
|
|
* set to 0 if @init_speed is already the preferred baudrate
|
|
|
|
* @irq: interrupt triggered by HOST_WAKE_BT pin
|
|
|
|
* @irq_active_low: whether @irq is active low
|
|
|
|
* @hu: pointer to HCI UART controller struct,
|
|
|
|
* used to disable flow control during runtime suspend and system sleep
|
|
|
|
* @is_suspended: whether flow control is currently disabled
|
|
|
|
*/
|
2015-08-11 22:35:35 +08:00
|
|
|
struct bcm_device {
|
2017-10-05 02:43:43 +08:00
|
|
|
/* Must be the first member, hci_serdev.c expects this. */
|
|
|
|
struct hci_uart serdev_hu;
|
2015-08-11 22:35:35 +08:00
|
|
|
struct list_head list;
|
|
|
|
|
2017-10-05 02:43:39 +08:00
|
|
|
struct device *dev;
|
2015-08-11 22:35:35 +08:00
|
|
|
|
|
|
|
const char *name;
|
|
|
|
struct gpio_desc *device_wakeup;
|
|
|
|
struct gpio_desc *shutdown;
|
2018-01-10 23:32:10 +08:00
|
|
|
int (*set_device_wakeup)(struct bcm_device *, bool);
|
|
|
|
int (*set_shutdown)(struct bcm_device *, bool);
|
Bluetooth: hci_bcm: Support Apple GPIO handling
Enable Bluetooth on the following Macs which provide custom ACPI methods
to toggle the GPIOs for device wake and shutdown instead of accessing
the pins directly:
MacBook8,1 2015 12"
MacBook9,1 2016 12"
MacBook10,1 2017 12"
MacBookPro13,1 2016 13"
MacBookPro13,2 2016 13" with Touch Bar
MacBookPro13,3 2016 15" with Touch Bar
MacBookPro14,1 2017 13"
MacBookPro14,2 2017 13" with Touch Bar
MacBookPro14,3 2017 15" with Touch Bar
On the MacBook8,1 Bluetooth is muxed with a second device (a debug port
on the SSD) under the control of PCH GPIO 36. Because serdev cannot
deal with multiple slaves yet, it is currently necessary to patch the
DSDT and remove the SSDC device.
The custom ACPI methods are called:
BTLP (Low Power) takes one argument, toggles device wake GPIO
BTPU (Power Up) tells SMC to drive shutdown GPIO high
BTPD (Power Down) tells SMC to drive shutdown GPIO low
BTRS (Reset) calls BTPD followed by BTPU
BTRB unknown, not present on all MacBooks
Search for the BTLP, BTPU and BTPD methods on ->probe and cache them in
struct bcm_device if the machine is a Mac.
Additionally, set the init_speed based on a custom device property
provided by Apple in lieu of _CRS resources. The Broadcom UART's speed
is fixed on Apple Macs: Any attempt to change it results in Bluetooth
status code 0x0c and bcm_set_baudrate() thus always returns -EBUSY.
By setting only the init_speed and leaving oper_speed at zero, we can
achieve that the host UART's speed is adjusted but the Broadcom UART's
speed is left as is.
The host wake pin goes into the SMC which handles it independently
of the OS, so there's no IRQ for it.
Thanks to Ronald Tschalär who did extensive debugging and testing of
this patch and contributed fixes.
ACPI snippet containing the custom methods and device properties
(taken from a MacBook8,1):
Method (BTLP, 1, Serialized)
{
If (LEqual (Arg0, 0x00))
{
Store (0x01, GD54) /* set PCH GPIO 54 direction to input */
}
If (LEqual (Arg0, 0x01))
{
Store (0x00, GD54) /* set PCH GPIO 54 direction to output */
Store (0x00, GP54) /* set PCH GPIO 54 value to low */
}
}
Method (BTPU, 0, Serialized)
{
Store (0x01, \_SB.PCI0.LPCB.EC.BTPC)
Sleep (0x0A)
}
Method (BTPD, 0, Serialized)
{
Store (0x00, \_SB.PCI0.LPCB.EC.BTPC)
Sleep (0x0A)
}
Method (BTRS, 0, Serialized)
{
BTPD ()
BTPU ()
}
Method (_DSM, 4, NotSerialized) // _DSM: Device-Specific Method
{
If (LEqual (Arg0, ToUUID ("a0b5b7c6-1318-441c-b0c9-fe695eaf949b")))
{
Store (Package (0x08)
{
"baud",
Buffer (0x08)
{ 0xC0, 0xC6, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00 },
"parity",
Buffer (0x08)
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
"dataBits",
Buffer (0x08)
{ 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
"stopBits",
Buffer (0x08)
{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
}, Local0)
DTGP (Arg0, Arg1, Arg2, Arg3, RefOf (Local0))
Return (Local0)
}
Return (0x00)
}
Link: https://github.com/Dunedan/mbp-2016-linux/issues/29
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=110901
Reported-by: Leif Liddy <leif.liddy@gmail.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Loic Poulain <loic.poulain@linaro.org>
Cc: Hans de Goede <hdegoede@redhat.com>
Tested-by: Max Shavrick <mxms@me.com> [MacBook8,1]
Tested-by: Leif Liddy <leif.liddy@gmail.com> [MacBook9,1]
Tested-by: Daniel Roschka <danielroschka@phoenitydawn.de> [MacBookPro13,2]
Tested-by: Ronald Tschalär <ronald@innovation.ch> [MacBookPro13,3]
Tested-by: Peter Y. Chuang <peteryuchuang@gmail.com> [MacBookPro14,1]
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Ronald Tschalär <ronald@innovation.ch>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
acpi_handle btlp, btpu, btpd;
|
2018-03-17 04:28:11 +08:00
|
|
|
int gpio_count;
|
|
|
|
int gpio_int_idx;
|
Bluetooth: hci_bcm: Support Apple GPIO handling
Enable Bluetooth on the following Macs which provide custom ACPI methods
to toggle the GPIOs for device wake and shutdown instead of accessing
the pins directly:
MacBook8,1 2015 12"
MacBook9,1 2016 12"
MacBook10,1 2017 12"
MacBookPro13,1 2016 13"
MacBookPro13,2 2016 13" with Touch Bar
MacBookPro13,3 2016 15" with Touch Bar
MacBookPro14,1 2017 13"
MacBookPro14,2 2017 13" with Touch Bar
MacBookPro14,3 2017 15" with Touch Bar
On the MacBook8,1 Bluetooth is muxed with a second device (a debug port
on the SSD) under the control of PCH GPIO 36. Because serdev cannot
deal with multiple slaves yet, it is currently necessary to patch the
DSDT and remove the SSDC device.
The custom ACPI methods are called:
BTLP (Low Power) takes one argument, toggles device wake GPIO
BTPU (Power Up) tells SMC to drive shutdown GPIO high
BTPD (Power Down) tells SMC to drive shutdown GPIO low
BTRS (Reset) calls BTPD followed by BTPU
BTRB unknown, not present on all MacBooks
Search for the BTLP, BTPU and BTPD methods on ->probe and cache them in
struct bcm_device if the machine is a Mac.
Additionally, set the init_speed based on a custom device property
provided by Apple in lieu of _CRS resources. The Broadcom UART's speed
is fixed on Apple Macs: Any attempt to change it results in Bluetooth
status code 0x0c and bcm_set_baudrate() thus always returns -EBUSY.
By setting only the init_speed and leaving oper_speed at zero, we can
achieve that the host UART's speed is adjusted but the Broadcom UART's
speed is left as is.
The host wake pin goes into the SMC which handles it independently
of the OS, so there's no IRQ for it.
Thanks to Ronald Tschalär who did extensive debugging and testing of
this patch and contributed fixes.
ACPI snippet containing the custom methods and device properties
(taken from a MacBook8,1):
Method (BTLP, 1, Serialized)
{
If (LEqual (Arg0, 0x00))
{
Store (0x01, GD54) /* set PCH GPIO 54 direction to input */
}
If (LEqual (Arg0, 0x01))
{
Store (0x00, GD54) /* set PCH GPIO 54 direction to output */
Store (0x00, GP54) /* set PCH GPIO 54 value to low */
}
}
Method (BTPU, 0, Serialized)
{
Store (0x01, \_SB.PCI0.LPCB.EC.BTPC)
Sleep (0x0A)
}
Method (BTPD, 0, Serialized)
{
Store (0x00, \_SB.PCI0.LPCB.EC.BTPC)
Sleep (0x0A)
}
Method (BTRS, 0, Serialized)
{
BTPD ()
BTPU ()
}
Method (_DSM, 4, NotSerialized) // _DSM: Device-Specific Method
{
If (LEqual (Arg0, ToUUID ("a0b5b7c6-1318-441c-b0c9-fe695eaf949b")))
{
Store (Package (0x08)
{
"baud",
Buffer (0x08)
{ 0xC0, 0xC6, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00 },
"parity",
Buffer (0x08)
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
"dataBits",
Buffer (0x08)
{ 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
"stopBits",
Buffer (0x08)
{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
}, Local0)
DTGP (Arg0, Arg1, Arg2, Arg3, RefOf (Local0))
Return (Local0)
}
Return (0x00)
}
Link: https://github.com/Dunedan/mbp-2016-linux/issues/29
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=110901
Reported-by: Leif Liddy <leif.liddy@gmail.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Loic Poulain <loic.poulain@linaro.org>
Cc: Hans de Goede <hdegoede@redhat.com>
Tested-by: Max Shavrick <mxms@me.com> [MacBook8,1]
Tested-by: Leif Liddy <leif.liddy@gmail.com> [MacBook9,1]
Tested-by: Daniel Roschka <danielroschka@phoenitydawn.de> [MacBookPro13,2]
Tested-by: Ronald Tschalär <ronald@innovation.ch> [MacBookPro13,3]
Tested-by: Peter Y. Chuang <peteryuchuang@gmail.com> [MacBookPro14,1]
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Ronald Tschalär <ronald@innovation.ch>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
#endif
|
2015-08-11 22:35:35 +08:00
|
|
|
|
2018-12-17 12:04:41 +08:00
|
|
|
struct clk *txco_clk;
|
2018-12-17 12:04:42 +08:00
|
|
|
struct clk *lpo_clk;
|
2018-12-17 12:04:43 +08:00
|
|
|
struct regulator_bulk_data supplies[BCM_NUM_SUPPLIES];
|
|
|
|
bool res_enabled;
|
2015-08-11 22:35:37 +08:00
|
|
|
|
|
|
|
u32 init_speed;
|
2017-08-16 15:53:30 +08:00
|
|
|
u32 oper_speed;
|
2015-09-04 21:35:44 +08:00
|
|
|
int irq;
|
2017-10-05 02:43:36 +08:00
|
|
|
bool irq_active_low;
|
2015-08-11 22:35:38 +08:00
|
|
|
|
2015-09-24 00:18:09 +08:00
|
|
|
#ifdef CONFIG_PM
|
2015-08-11 22:35:38 +08:00
|
|
|
struct hci_uart *hu;
|
2018-01-10 23:32:10 +08:00
|
|
|
bool is_suspended;
|
2015-08-11 22:35:38 +08:00
|
|
|
#endif
|
2015-08-11 22:35:35 +08:00
|
|
|
};
|
|
|
|
|
2017-08-18 01:59:51 +08:00
|
|
|
/* generic bcm uart resources */
|
2015-04-06 13:52:18 +08:00
|
|
|
struct bcm_data {
|
2015-08-11 22:35:35 +08:00
|
|
|
struct sk_buff *rx_skb;
|
|
|
|
struct sk_buff_head txq;
|
|
|
|
|
|
|
|
struct bcm_device *dev;
|
2015-04-06 13:52:18 +08:00
|
|
|
};
|
|
|
|
|
2015-08-11 22:35:35 +08:00
|
|
|
/* List of BCM BT UART devices */
|
2015-09-01 18:13:35 +08:00
|
|
|
static DEFINE_MUTEX(bcm_device_lock);
|
2015-08-11 22:35:35 +08:00
|
|
|
static LIST_HEAD(bcm_device_list);
|
|
|
|
|
2018-03-17 04:28:07 +08:00
|
|
|
static int irq_polarity = -1;
|
|
|
|
module_param(irq_polarity, int, 0444);
|
|
|
|
MODULE_PARM_DESC(irq_polarity, "IRQ polarity 0: active-high 1: active-low");
|
|
|
|
|
2017-08-18 01:59:51 +08:00
|
|
|
static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed)
|
|
|
|
{
|
|
|
|
if (hu->serdev)
|
|
|
|
serdev_device_set_baudrate(hu->serdev, speed);
|
|
|
|
else
|
|
|
|
hci_uart_set_baudrate(hu, speed);
|
|
|
|
}
|
|
|
|
|
2015-06-09 22:15:37 +08:00
|
|
|
static int bcm_set_baudrate(struct hci_uart *hu, unsigned int speed)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = hu->hdev;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct bcm_update_uart_baud_rate param;
|
|
|
|
|
|
|
|
if (speed > 3000000) {
|
|
|
|
struct bcm_write_uart_clock_setting clock;
|
|
|
|
|
|
|
|
clock.type = BCM_UART_CLOCK_48MHZ;
|
|
|
|
|
2015-09-01 18:13:36 +08:00
|
|
|
bt_dev_dbg(hdev, "Set Controller clock (%d)", clock.type);
|
2015-06-09 22:15:37 +08:00
|
|
|
|
|
|
|
/* This Broadcom specific command changes the UART's controller
|
|
|
|
* clock for baud rate > 3000000.
|
|
|
|
*/
|
|
|
|
skb = __hci_cmd_sync(hdev, 0xfc45, 1, &clock, HCI_INIT_TIMEOUT);
|
|
|
|
if (IS_ERR(skb)) {
|
|
|
|
int err = PTR_ERR(skb);
|
2015-09-01 18:13:36 +08:00
|
|
|
bt_dev_err(hdev, "BCM: failed to write clock (%d)",
|
|
|
|
err);
|
2015-06-09 22:15:37 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
2015-09-01 18:13:36 +08:00
|
|
|
bt_dev_dbg(hdev, "Set Controller UART speed to %d bit/s", speed);
|
2015-06-09 22:15:37 +08:00
|
|
|
|
|
|
|
param.zero = cpu_to_le16(0);
|
|
|
|
param.baud_rate = cpu_to_le32(speed);
|
|
|
|
|
|
|
|
/* This Broadcom specific command changes the UART's controller baud
|
|
|
|
* rate.
|
|
|
|
*/
|
|
|
|
skb = __hci_cmd_sync(hdev, 0xfc18, sizeof(param), ¶m,
|
|
|
|
HCI_INIT_TIMEOUT);
|
|
|
|
if (IS_ERR(skb)) {
|
|
|
|
int err = PTR_ERR(skb);
|
2015-09-01 18:13:36 +08:00
|
|
|
bt_dev_err(hdev, "BCM: failed to write update baudrate (%d)",
|
|
|
|
err);
|
2015-06-09 22:15:37 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree_skb(skb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-28 21:44:00 +08:00
|
|
|
/* bcm_device_exists should be protected by bcm_device_lock */
|
2015-08-11 22:35:35 +08:00
|
|
|
static bool bcm_device_exists(struct bcm_device *device)
|
|
|
|
{
|
|
|
|
struct list_head *p;
|
|
|
|
|
2017-10-11 21:46:21 +08:00
|
|
|
#ifdef CONFIG_PM
|
2017-10-05 02:43:43 +08:00
|
|
|
/* Devices using serdev always exist */
|
|
|
|
if (device && device->hu && device->hu->serdev)
|
|
|
|
return true;
|
2017-10-11 21:46:21 +08:00
|
|
|
#endif
|
2017-10-05 02:43:43 +08:00
|
|
|
|
2015-08-11 22:35:35 +08:00
|
|
|
list_for_each(p, &bcm_device_list) {
|
|
|
|
struct bcm_device *dev = list_entry(p, struct bcm_device, list);
|
|
|
|
|
|
|
|
if (device == dev)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm_gpio_set_power(struct bcm_device *dev, bool powered)
|
|
|
|
{
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
int err;
|
2015-08-11 22:35:35 +08:00
|
|
|
|
2018-12-17 12:04:43 +08:00
|
|
|
if (powered && !dev->res_enabled) {
|
|
|
|
err = regulator_bulk_enable(BCM_NUM_SUPPLIES, dev->supplies);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-12-17 12:04:42 +08:00
|
|
|
/* LPO clock needs to be 32.768 kHz */
|
|
|
|
err = clk_set_rate(dev->lpo_clk, 32768);
|
|
|
|
if (err) {
|
|
|
|
dev_err(dev->dev, "Could not set LPO clock rate\n");
|
2018-12-17 12:04:43 +08:00
|
|
|
goto err_regulator_disable;
|
2018-12-17 12:04:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
err = clk_prepare_enable(dev->lpo_clk);
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
if (err)
|
2018-12-17 12:04:43 +08:00
|
|
|
goto err_regulator_disable;
|
2018-12-17 12:04:42 +08:00
|
|
|
|
|
|
|
err = clk_prepare_enable(dev->txco_clk);
|
|
|
|
if (err)
|
|
|
|
goto err_lpo_clk_disable;
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
err = dev->set_shutdown(dev, powered);
|
|
|
|
if (err)
|
2018-12-17 12:04:42 +08:00
|
|
|
goto err_txco_clk_disable;
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
|
|
|
|
err = dev->set_device_wakeup(dev, powered);
|
|
|
|
if (err)
|
|
|
|
goto err_revert_shutdown;
|
2015-08-11 22:35:35 +08:00
|
|
|
|
2018-12-17 12:04:43 +08:00
|
|
|
if (!powered && dev->res_enabled) {
|
2018-12-17 12:04:41 +08:00
|
|
|
clk_disable_unprepare(dev->txco_clk);
|
2018-12-17 12:04:42 +08:00
|
|
|
clk_disable_unprepare(dev->lpo_clk);
|
2018-12-17 12:04:43 +08:00
|
|
|
regulator_bulk_disable(BCM_NUM_SUPPLIES, dev->supplies);
|
2018-12-17 12:04:42 +08:00
|
|
|
}
|
2015-08-11 22:35:35 +08:00
|
|
|
|
2018-12-17 12:04:44 +08:00
|
|
|
/* wait for device to power on and come out of reset */
|
|
|
|
usleep_range(10000, 20000);
|
|
|
|
|
2018-12-17 12:04:43 +08:00
|
|
|
dev->res_enabled = powered;
|
2015-08-11 22:35:35 +08:00
|
|
|
|
|
|
|
return 0;
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
|
|
|
|
err_revert_shutdown:
|
|
|
|
dev->set_shutdown(dev, !powered);
|
2018-12-17 12:04:42 +08:00
|
|
|
err_txco_clk_disable:
|
2018-12-17 12:04:43 +08:00
|
|
|
if (powered && !dev->res_enabled)
|
2018-12-17 12:04:41 +08:00
|
|
|
clk_disable_unprepare(dev->txco_clk);
|
2018-12-17 12:04:42 +08:00
|
|
|
err_lpo_clk_disable:
|
2018-12-17 12:04:43 +08:00
|
|
|
if (powered && !dev->res_enabled)
|
2018-12-17 12:04:42 +08:00
|
|
|
clk_disable_unprepare(dev->lpo_clk);
|
2018-12-17 12:04:43 +08:00
|
|
|
err_regulator_disable:
|
|
|
|
if (powered && !dev->res_enabled)
|
|
|
|
regulator_bulk_disable(BCM_NUM_SUPPLIES, dev->supplies);
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
return err;
|
2015-08-11 22:35:35 +08:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:18:09 +08:00
|
|
|
#ifdef CONFIG_PM
|
2015-09-04 21:35:44 +08:00
|
|
|
static irqreturn_t bcm_host_wake(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct bcm_device *bdev = data;
|
|
|
|
|
|
|
|
bt_dev_dbg(bdev, "Host wake IRQ");
|
|
|
|
|
2018-03-15 06:06:02 +08:00
|
|
|
pm_runtime_get(bdev->dev);
|
|
|
|
pm_runtime_mark_last_busy(bdev->dev);
|
|
|
|
pm_runtime_put_autosuspend(bdev->dev);
|
2015-09-24 00:18:11 +08:00
|
|
|
|
2015-09-04 21:35:44 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm_request_irq(struct bcm_data *bcm)
|
|
|
|
{
|
|
|
|
struct bcm_device *bdev = bcm->dev;
|
2017-07-04 18:57:56 +08:00
|
|
|
int err;
|
2015-09-04 21:35:44 +08:00
|
|
|
|
|
|
|
mutex_lock(&bcm_device_lock);
|
|
|
|
if (!bcm_device_exists(bdev)) {
|
|
|
|
err = -ENODEV;
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
2017-07-04 18:57:56 +08:00
|
|
|
if (bdev->irq <= 0) {
|
|
|
|
err = -EOPNOTSUPP;
|
|
|
|
goto unlock;
|
|
|
|
}
|
2015-09-04 21:35:44 +08:00
|
|
|
|
2017-10-05 02:43:39 +08:00
|
|
|
err = devm_request_irq(bdev->dev, bdev->irq, bcm_host_wake,
|
2017-10-05 02:43:36 +08:00
|
|
|
bdev->irq_active_low ? IRQF_TRIGGER_FALLING :
|
|
|
|
IRQF_TRIGGER_RISING,
|
|
|
|
"host_wake", bdev);
|
2018-01-10 23:32:10 +08:00
|
|
|
if (err) {
|
|
|
|
bdev->irq = err;
|
2017-07-04 18:57:56 +08:00
|
|
|
goto unlock;
|
2018-01-10 23:32:10 +08:00
|
|
|
}
|
2015-09-24 00:18:11 +08:00
|
|
|
|
2017-10-05 02:43:39 +08:00
|
|
|
device_init_wakeup(bdev->dev, true);
|
2017-07-04 18:57:56 +08:00
|
|
|
|
2017-10-05 02:43:39 +08:00
|
|
|
pm_runtime_set_autosuspend_delay(bdev->dev,
|
2017-07-04 18:57:56 +08:00
|
|
|
BCM_AUTOSUSPEND_DELAY);
|
2017-10-05 02:43:39 +08:00
|
|
|
pm_runtime_use_autosuspend(bdev->dev);
|
|
|
|
pm_runtime_set_active(bdev->dev);
|
|
|
|
pm_runtime_enable(bdev->dev);
|
2015-09-04 21:35:44 +08:00
|
|
|
|
|
|
|
unlock:
|
|
|
|
mutex_unlock(&bcm_device_lock);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct bcm_set_sleep_mode default_sleep_params = {
|
|
|
|
.sleep_mode = 1, /* 0=Disabled, 1=UART, 2=Reserved, 3=USB */
|
|
|
|
.idle_host = 2, /* idle threshold HOST, in 300ms */
|
|
|
|
.idle_dev = 2, /* idle threshold device, in 300ms */
|
|
|
|
.bt_wake_active = 1, /* BT_WAKE active mode: 1 = high, 0 = low */
|
|
|
|
.host_wake_active = 0, /* HOST_WAKE active mode: 1 = high, 0 = low */
|
|
|
|
.allow_host_sleep = 1, /* Allow host sleep in SCO flag */
|
2015-09-24 00:18:11 +08:00
|
|
|
.combine_modes = 1, /* Combine sleep and LPM flag */
|
2015-09-04 21:35:44 +08:00
|
|
|
.tristate_control = 0, /* Allow tri-state control of UART tx flag */
|
|
|
|
/* Irrelevant USB flags */
|
|
|
|
.usb_auto_sleep = 0,
|
|
|
|
.usb_resume_timeout = 0,
|
2018-01-10 23:32:10 +08:00
|
|
|
.break_to_host = 0,
|
Bluetooth: hci_bcm: Set pulsed_host_wake flag in sleep parameters
The IRQ output of the bcm bt-device is really a level IRQ signal, which
signals a logical high as long as the device's buffer contains data. Since
the draining in the buffer is done in the tty driver, we cannot (easily)
wait in a threaded interrupt handler for the draining, after which the
IRQ should go low again.
So instead we treat the IRQ as an edge interrupt. This opens the window
for a theoretical race where we wakeup, read some data and then autosuspend
*before* the IRQ has gone (logical) low, followed by the device just at
that moment receiving more data, causing the IRQ to stay high and we never
see an edge.
Since we call pm_runtime_mark_last_busy() on every received byte, there
should be plenty time for the IRQ to go (logical) low before we ever
suspend, so this should never happen, but after commit 43fff7683468
("Bluetooth: hci_bcm: Streamline runtime PM code"), which has been reverted
since, this was actually happening causing the device to get stuck in
runtime suspend.
The bcm bt-device actually has a workaround for this, if we set the
pulsed_host_wake flag in the sleep parameters, then the device monitors
if the host is draining the buffer and if not then after a timeout the
device will pulse the IRQ line, causing us to see an edge, fixing the
stuck in suspend condition.
This commit sets the pulsed_host_wake flag to fix the (mostly theoretical)
race caused by us treating the IRQ as an edge IRQ.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-03-15 06:06:03 +08:00
|
|
|
.pulsed_host_wake = 1,
|
2015-09-04 21:35:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int bcm_setup_sleep(struct hci_uart *hu)
|
|
|
|
{
|
|
|
|
struct bcm_data *bcm = hu->priv;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct bcm_set_sleep_mode sleep_params = default_sleep_params;
|
|
|
|
|
2017-10-05 02:43:36 +08:00
|
|
|
sleep_params.host_wake_active = !bcm->dev->irq_active_low;
|
2015-09-04 21:35:44 +08:00
|
|
|
|
|
|
|
skb = __hci_cmd_sync(hu->hdev, 0xfc27, sizeof(sleep_params),
|
|
|
|
&sleep_params, HCI_INIT_TIMEOUT);
|
|
|
|
if (IS_ERR(skb)) {
|
|
|
|
int err = PTR_ERR(skb);
|
|
|
|
bt_dev_err(hu->hdev, "Sleep VSC failed (%d)", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
kfree_skb(skb);
|
|
|
|
|
|
|
|
bt_dev_dbg(hu->hdev, "Set Sleep Parameters VSC succeeded");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline int bcm_request_irq(struct bcm_data *bcm) { return 0; }
|
|
|
|
static inline int bcm_setup_sleep(struct hci_uart *hu) { return 0; }
|
|
|
|
#endif
|
|
|
|
|
2015-10-08 02:08:26 +08:00
|
|
|
static int bcm_set_diag(struct hci_dev *hdev, bool enable)
|
|
|
|
{
|
|
|
|
struct hci_uart *hu = hci_get_drvdata(hdev);
|
|
|
|
struct bcm_data *bcm = hu->priv;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
if (!test_bit(HCI_RUNNING, &hdev->flags))
|
|
|
|
return -ENETDOWN;
|
|
|
|
|
|
|
|
skb = bt_skb_alloc(3, GFP_KERNEL);
|
2015-10-22 17:06:09 +08:00
|
|
|
if (!skb)
|
|
|
|
return -ENOMEM;
|
2015-10-08 02:08:26 +08:00
|
|
|
|
networking: add and use skb_put_u8()
Joe and Bjørn suggested that it'd be nicer to not have the
cast in the fairly common case of doing
*(u8 *)skb_put(skb, 1) = c;
Add skb_put_u8() for this case, and use it across the code,
using the following spatch:
@@
expression SKB, C, S;
typedef u8;
identifier fn = {skb_put};
fresh identifier fn2 = fn ## "_u8";
@@
- *(u8 *)fn(SKB, S) = C;
+ fn2(SKB, C);
Note that due to the "S", the spatch isn't perfect, it should
have checked that S is 1, but there's also places that use a
sizeof expression like sizeof(var) or sizeof(u8) etc. Turns
out that nobody ever did something like
*(u8 *)skb_put(skb, 2) = c;
which would be wrong anyway since the second byte wouldn't be
initialized.
Suggested-by: Joe Perches <joe@perches.com>
Suggested-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 20:29:24 +08:00
|
|
|
skb_put_u8(skb, BCM_LM_DIAG_PKT);
|
|
|
|
skb_put_u8(skb, 0xf0);
|
|
|
|
skb_put_u8(skb, enable);
|
2015-10-08 02:08:26 +08:00
|
|
|
|
|
|
|
skb_queue_tail(&bcm->txq, skb);
|
|
|
|
hci_uart_tx_wakeup(hu);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-06 13:52:18 +08:00
|
|
|
static int bcm_open(struct hci_uart *hu)
|
|
|
|
{
|
|
|
|
struct bcm_data *bcm;
|
2015-08-11 22:35:35 +08:00
|
|
|
struct list_head *p;
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
int err;
|
2015-04-06 13:52:18 +08:00
|
|
|
|
2015-09-01 18:13:36 +08:00
|
|
|
bt_dev_dbg(hu->hdev, "hu %p", hu);
|
2015-04-06 13:52:18 +08:00
|
|
|
|
|
|
|
bcm = kzalloc(sizeof(*bcm), GFP_KERNEL);
|
|
|
|
if (!bcm)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
skb_queue_head_init(&bcm->txq);
|
|
|
|
|
|
|
|
hu->priv = bcm;
|
2015-08-11 22:35:35 +08:00
|
|
|
|
2017-10-05 02:43:43 +08:00
|
|
|
mutex_lock(&bcm_device_lock);
|
|
|
|
|
2017-08-18 01:59:51 +08:00
|
|
|
if (hu->serdev) {
|
2017-10-05 02:43:43 +08:00
|
|
|
bcm->dev = serdev_device_get_drvdata(hu->serdev);
|
2017-08-18 01:59:51 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-03-30 00:15:27 +08:00
|
|
|
if (!hu->tty->dev)
|
|
|
|
goto out;
|
|
|
|
|
2015-08-11 22:35:35 +08:00
|
|
|
list_for_each(p, &bcm_device_list) {
|
|
|
|
struct bcm_device *dev = list_entry(p, struct bcm_device, list);
|
|
|
|
|
|
|
|
/* Retrieve saved bcm_device based on parent of the
|
|
|
|
* platform device (saved during device probe) and
|
|
|
|
* parent of tty device used by hci_uart
|
|
|
|
*/
|
2017-10-05 02:43:39 +08:00
|
|
|
if (hu->tty->dev->parent == dev->dev->parent) {
|
2015-08-11 22:35:35 +08:00
|
|
|
bcm->dev = dev;
|
2015-09-24 00:18:09 +08:00
|
|
|
#ifdef CONFIG_PM
|
2015-08-11 22:35:38 +08:00
|
|
|
dev->hu = hu;
|
|
|
|
#endif
|
2015-08-11 22:35:35 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-30 00:15:27 +08:00
|
|
|
out:
|
2017-10-05 02:43:43 +08:00
|
|
|
if (bcm->dev) {
|
|
|
|
hu->init_speed = bcm->dev->init_speed;
|
|
|
|
hu->oper_speed = bcm->dev->oper_speed;
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
err = bcm_gpio_set_power(bcm->dev, true);
|
|
|
|
if (err)
|
|
|
|
goto err_unset_hu;
|
2017-10-05 02:43:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&bcm_device_lock);
|
2015-04-06 13:52:18 +08:00
|
|
|
return 0;
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
|
|
|
|
err_unset_hu:
|
|
|
|
#ifdef CONFIG_PM
|
2018-05-28 03:04:52 +08:00
|
|
|
if (!hu->serdev)
|
2018-01-22 19:53:24 +08:00
|
|
|
bcm->dev->hu = NULL;
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
#endif
|
|
|
|
mutex_unlock(&bcm_device_lock);
|
|
|
|
hu->priv = NULL;
|
|
|
|
kfree(bcm);
|
|
|
|
return err;
|
2015-04-06 13:52:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm_close(struct hci_uart *hu)
|
|
|
|
{
|
|
|
|
struct bcm_data *bcm = hu->priv;
|
2017-10-05 02:43:43 +08:00
|
|
|
struct bcm_device *bdev = NULL;
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
int err;
|
2015-04-06 13:52:18 +08:00
|
|
|
|
2015-09-01 18:13:36 +08:00
|
|
|
bt_dev_dbg(hu->hdev, "hu %p", hu);
|
2015-04-06 13:52:18 +08:00
|
|
|
|
2015-08-11 22:35:35 +08:00
|
|
|
/* Protect bcm->dev against removal of the device or driver */
|
2015-09-01 18:13:35 +08:00
|
|
|
mutex_lock(&bcm_device_lock);
|
2017-10-05 02:43:43 +08:00
|
|
|
|
|
|
|
if (hu->serdev) {
|
|
|
|
bdev = serdev_device_get_drvdata(hu->serdev);
|
|
|
|
} else if (bcm_device_exists(bcm->dev)) {
|
|
|
|
bdev = bcm->dev;
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
bdev->hu = NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bdev) {
|
2018-01-10 23:32:10 +08:00
|
|
|
if (IS_ENABLED(CONFIG_PM) && bdev->irq > 0) {
|
2017-10-05 02:43:39 +08:00
|
|
|
devm_free_irq(bdev->dev, bdev->irq, bdev);
|
|
|
|
device_init_wakeup(bdev->dev, false);
|
2018-01-10 23:32:10 +08:00
|
|
|
pm_runtime_disable(bdev->dev);
|
2015-09-04 21:35:44 +08:00
|
|
|
}
|
2018-01-10 23:32:10 +08:00
|
|
|
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
err = bcm_gpio_set_power(bdev, false);
|
|
|
|
if (err)
|
|
|
|
bt_dev_err(hu->hdev, "Failed to power down");
|
|
|
|
else
|
|
|
|
pm_runtime_set_suspended(bdev->dev);
|
2015-08-11 22:35:38 +08:00
|
|
|
}
|
2015-09-01 18:13:35 +08:00
|
|
|
mutex_unlock(&bcm_device_lock);
|
2015-08-11 22:35:35 +08:00
|
|
|
|
2015-04-06 13:52:18 +08:00
|
|
|
skb_queue_purge(&bcm->txq);
|
|
|
|
kfree_skb(bcm->rx_skb);
|
|
|
|
kfree(bcm);
|
|
|
|
|
|
|
|
hu->priv = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm_flush(struct hci_uart *hu)
|
|
|
|
{
|
|
|
|
struct bcm_data *bcm = hu->priv;
|
|
|
|
|
2015-09-01 18:13:36 +08:00
|
|
|
bt_dev_dbg(hu->hdev, "hu %p", hu);
|
2015-04-06 13:52:18 +08:00
|
|
|
|
|
|
|
skb_queue_purge(&bcm->txq);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm_setup(struct hci_uart *hu)
|
|
|
|
{
|
2015-09-04 21:35:44 +08:00
|
|
|
struct bcm_data *bcm = hu->priv;
|
2015-05-28 17:25:05 +08:00
|
|
|
char fw_name[64];
|
|
|
|
const struct firmware *fw;
|
2015-06-18 18:43:27 +08:00
|
|
|
unsigned int speed;
|
2015-05-28 17:25:05 +08:00
|
|
|
int err;
|
|
|
|
|
2015-09-01 18:13:36 +08:00
|
|
|
bt_dev_dbg(hu->hdev, "hu %p", hu);
|
2015-04-06 13:52:18 +08:00
|
|
|
|
2015-10-08 02:08:26 +08:00
|
|
|
hu->hdev->set_diag = bcm_set_diag;
|
2015-04-06 13:52:18 +08:00
|
|
|
hu->hdev->set_bdaddr = btbcm_set_bdaddr;
|
|
|
|
|
2018-04-20 20:44:05 +08:00
|
|
|
err = btbcm_initialize(hu->hdev, fw_name, sizeof(fw_name), false);
|
2015-05-28 17:25:05 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = request_firmware(&fw, fw_name, &hu->hdev->dev);
|
|
|
|
if (err < 0) {
|
2015-09-01 18:13:36 +08:00
|
|
|
bt_dev_info(hu->hdev, "BCM: Patch %s not found", fw_name);
|
2015-05-28 17:25:05 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = btbcm_patchram(hu->hdev, fw);
|
|
|
|
if (err) {
|
2015-09-01 18:13:36 +08:00
|
|
|
bt_dev_info(hu->hdev, "BCM: Patch failed (%d)", err);
|
2015-05-28 17:25:05 +08:00
|
|
|
goto finalize;
|
|
|
|
}
|
|
|
|
|
2015-06-18 18:43:27 +08:00
|
|
|
/* Init speed if any */
|
|
|
|
if (hu->init_speed)
|
|
|
|
speed = hu->init_speed;
|
|
|
|
else if (hu->proto->init_speed)
|
|
|
|
speed = hu->proto->init_speed;
|
|
|
|
else
|
|
|
|
speed = 0;
|
|
|
|
|
|
|
|
if (speed)
|
2017-08-18 01:59:51 +08:00
|
|
|
host_set_baudrate(hu, speed);
|
2015-06-18 18:43:27 +08:00
|
|
|
|
|
|
|
/* Operational speed if any */
|
|
|
|
if (hu->oper_speed)
|
|
|
|
speed = hu->oper_speed;
|
|
|
|
else if (hu->proto->oper_speed)
|
|
|
|
speed = hu->proto->oper_speed;
|
|
|
|
else
|
|
|
|
speed = 0;
|
|
|
|
|
|
|
|
if (speed) {
|
|
|
|
err = bcm_set_baudrate(hu, speed);
|
2015-06-09 22:15:37 +08:00
|
|
|
if (!err)
|
2017-08-18 01:59:51 +08:00
|
|
|
host_set_baudrate(hu, speed);
|
2015-06-09 22:15:37 +08:00
|
|
|
}
|
|
|
|
|
2015-05-28 17:25:05 +08:00
|
|
|
finalize:
|
|
|
|
release_firmware(fw);
|
|
|
|
|
|
|
|
err = btbcm_finalize(hu->hdev);
|
2015-09-04 21:35:44 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2017-06-28 01:15:07 +08:00
|
|
|
if (!bcm_request_irq(bcm))
|
2015-09-04 21:35:44 +08:00
|
|
|
err = bcm_setup_sleep(hu);
|
2015-05-28 17:25:05 +08:00
|
|
|
|
|
|
|
return err;
|
2015-04-06 13:52:18 +08:00
|
|
|
}
|
|
|
|
|
2015-10-08 01:12:54 +08:00
|
|
|
#define BCM_RECV_LM_DIAG \
|
|
|
|
.type = BCM_LM_DIAG_PKT, \
|
|
|
|
.hlen = BCM_LM_DIAG_SIZE, \
|
|
|
|
.loff = 0, \
|
|
|
|
.lsize = 0, \
|
|
|
|
.maxlen = BCM_LM_DIAG_SIZE
|
|
|
|
|
2017-08-18 03:41:09 +08:00
|
|
|
#define BCM_RECV_NULL \
|
|
|
|
.type = BCM_NULL_PKT, \
|
|
|
|
.hlen = BCM_NULL_SIZE, \
|
|
|
|
.loff = 0, \
|
|
|
|
.lsize = 0, \
|
|
|
|
.maxlen = BCM_NULL_SIZE
|
|
|
|
|
2015-04-06 14:44:59 +08:00
|
|
|
static const struct h4_recv_pkt bcm_recv_pkts[] = {
|
2015-10-08 01:12:54 +08:00
|
|
|
{ H4_RECV_ACL, .recv = hci_recv_frame },
|
|
|
|
{ H4_RECV_SCO, .recv = hci_recv_frame },
|
|
|
|
{ H4_RECV_EVENT, .recv = hci_recv_frame },
|
|
|
|
{ BCM_RECV_LM_DIAG, .recv = hci_recv_diag },
|
2017-08-18 03:41:09 +08:00
|
|
|
{ BCM_RECV_NULL, .recv = hci_recv_diag },
|
2015-04-06 14:44:59 +08:00
|
|
|
};
|
|
|
|
|
2015-04-06 13:52:18 +08:00
|
|
|
static int bcm_recv(struct hci_uart *hu, const void *data, int count)
|
|
|
|
{
|
|
|
|
struct bcm_data *bcm = hu->priv;
|
|
|
|
|
|
|
|
if (!test_bit(HCI_UART_REGISTERED, &hu->flags))
|
|
|
|
return -EUNATCH;
|
|
|
|
|
2015-04-06 14:44:59 +08:00
|
|
|
bcm->rx_skb = h4_recv_buf(hu->hdev, bcm->rx_skb, data, count,
|
|
|
|
bcm_recv_pkts, ARRAY_SIZE(bcm_recv_pkts));
|
2015-04-06 13:52:18 +08:00
|
|
|
if (IS_ERR(bcm->rx_skb)) {
|
|
|
|
int err = PTR_ERR(bcm->rx_skb);
|
2015-09-01 18:13:36 +08:00
|
|
|
bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err);
|
2015-06-17 20:10:39 +08:00
|
|
|
bcm->rx_skb = NULL;
|
2015-04-06 13:52:18 +08:00
|
|
|
return err;
|
2015-09-24 00:18:11 +08:00
|
|
|
} else if (!bcm->rx_skb) {
|
|
|
|
/* Delay auto-suspend when receiving completed packet */
|
|
|
|
mutex_lock(&bcm_device_lock);
|
2018-03-15 06:06:02 +08:00
|
|
|
if (bcm->dev && bcm_device_exists(bcm->dev)) {
|
|
|
|
pm_runtime_get(bcm->dev->dev);
|
|
|
|
pm_runtime_mark_last_busy(bcm->dev->dev);
|
|
|
|
pm_runtime_put_autosuspend(bcm->dev->dev);
|
|
|
|
}
|
2015-09-24 00:18:11 +08:00
|
|
|
mutex_unlock(&bcm_device_lock);
|
2015-04-06 13:52:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm_enqueue(struct hci_uart *hu, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct bcm_data *bcm = hu->priv;
|
|
|
|
|
2015-09-01 18:13:36 +08:00
|
|
|
bt_dev_dbg(hu->hdev, "hu %p skb %p", hu, skb);
|
2015-04-06 13:52:18 +08:00
|
|
|
|
|
|
|
/* Prepend skb with frame type */
|
2015-11-05 14:33:56 +08:00
|
|
|
memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
|
2015-04-06 13:52:18 +08:00
|
|
|
skb_queue_tail(&bcm->txq, skb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sk_buff *bcm_dequeue(struct hci_uart *hu)
|
|
|
|
{
|
|
|
|
struct bcm_data *bcm = hu->priv;
|
2015-09-24 00:18:11 +08:00
|
|
|
struct sk_buff *skb = NULL;
|
|
|
|
struct bcm_device *bdev = NULL;
|
|
|
|
|
|
|
|
mutex_lock(&bcm_device_lock);
|
|
|
|
|
|
|
|
if (bcm_device_exists(bcm->dev)) {
|
|
|
|
bdev = bcm->dev;
|
2017-10-05 02:43:39 +08:00
|
|
|
pm_runtime_get_sync(bdev->dev);
|
2015-09-24 00:18:11 +08:00
|
|
|
/* Shall be resumed here */
|
|
|
|
}
|
|
|
|
|
|
|
|
skb = skb_dequeue(&bcm->txq);
|
|
|
|
|
|
|
|
if (bdev) {
|
2017-10-05 02:43:39 +08:00
|
|
|
pm_runtime_mark_last_busy(bdev->dev);
|
|
|
|
pm_runtime_put_autosuspend(bdev->dev);
|
2015-09-24 00:18:11 +08:00
|
|
|
}
|
2015-04-06 13:52:18 +08:00
|
|
|
|
2015-09-24 00:18:11 +08:00
|
|
|
mutex_unlock(&bcm_device_lock);
|
|
|
|
|
|
|
|
return skb;
|
2015-04-06 13:52:18 +08:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:18:09 +08:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int bcm_suspend_device(struct device *dev)
|
2015-08-11 22:35:38 +08:00
|
|
|
{
|
2017-10-05 02:43:42 +08:00
|
|
|
struct bcm_device *bdev = dev_get_drvdata(dev);
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
int err;
|
2015-08-11 22:35:38 +08:00
|
|
|
|
2015-09-24 00:18:09 +08:00
|
|
|
bt_dev_dbg(bdev, "");
|
2015-08-28 21:44:00 +08:00
|
|
|
|
2015-09-24 00:18:09 +08:00
|
|
|
if (!bdev->is_suspended && bdev->hu) {
|
2015-08-11 22:35:38 +08:00
|
|
|
hci_uart_set_flow_control(bdev->hu, true);
|
|
|
|
|
2015-09-24 00:18:09 +08:00
|
|
|
/* Once this returns, driver suspends BT via GPIO */
|
2015-08-11 22:35:38 +08:00
|
|
|
bdev->is_suspended = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Suspend the device */
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
err = bdev->set_device_wakeup(bdev, false);
|
|
|
|
if (err) {
|
|
|
|
if (bdev->is_suspended && bdev->hu) {
|
|
|
|
bdev->is_suspended = false;
|
|
|
|
hci_uart_set_flow_control(bdev->hu, false);
|
|
|
|
}
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
Bluetooth: hci_bcm: Mandate presence of shutdown and device wake GPIO
Commit 0395ffc1ee05 ("Bluetooth: hci_bcm: Add PM for BCM devices")
amended this driver to request a shutdown and device wake GPIO on probe,
but mandated that only one of them need to be present:
/* Make sure at-least one of the GPIO is defined and that
* a name is specified for this instance
*/
if ((!dev->device_wakeup && !dev->shutdown) || !dev->name) {
dev_err(&pdev->dev, "invalid platform data\n");
return -EINVAL;
}
However the same commit added a call to bcm_gpio_set_power() to the
->probe hook, which unconditionally accesses *both* GPIOs. Luckily,
the resulting NULL pointer deref was never reported, suggesting there's
no machine where either GPIO is missing.
Commit 8a92056837fd ("Bluetooth: hci_bcm: Add (runtime)pm support to the
serdev driver") removed the check whether at least one of the GPIOs is
present without specifying a reason.
Because commit 62aaefa7d038 ("Bluetooth: hci_bcm: improve use of gpios
API") refactored the driver to use devm_gpiod_get_optional() instead of
devm_gpiod_get(), one is now tempted to believe that the driver doesn't
require *any* of the two GPIOs.
Which is wrong, the driver still requires both GPIOs to avoid a NULL
pointer deref. To this end, establish the status quo ante and request
the GPIOs with devm_gpiod_get() again. Bail out of ->probe if either
of them is missing.
Oddly enough, whereas bcm_gpio_set_power() accesses the device wake pin
unconditionally, bcm_suspend_device() and bcm_resume_device() do check
for its presence before accessing it. Those checks are superfluous,
so remove them.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Loic Poulain <loic.poulain@linaro.org>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
bt_dev_dbg(bdev, "suspend, delaying 15 ms");
|
Bluetooth: hci_bcm: Sleep instead of spinning
The driver calls mdelay(15) in the ->suspend, ->resume, ->runtime_suspend
and ->runtime_resume hook, however spinning for such a long period of
time is discouraged as per Documentation/timers/timers-howto.txt.
The use of mdelay() seems unnecessary, it is allowed to sleep in the
system sleep and runtime PM hooks (with the exception of ->suspend_noirq
and ->resume_noirq) and the driver itself also does not rely on a
non-sleeping ->runtime_resume as the only place where a synchronous
resume is performed, in bcm_dequeue(), is called from a work item in
hci_ldisc.c and hci_serdev.c.
So replace the mdelay(15) with msleep(15).
Note that the delay is inserted after asserting or deasserting the
device wake pin, but in bcm_gpio_set_power() that pin is asserted or
deasserted *without* observing a delay. It is thus unclear if the delay
is necessary at all. It is likewise unclear why it is exactly 15 ms,
the commit introducing it, 118612fb9165 ("Bluetooth: hci_bcm: Add
suspend/resume PM functions"), does not provide a rationale.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Suggested-and-reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
msleep(15);
|
2015-08-11 22:35:38 +08:00
|
|
|
|
2015-09-24 00:18:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm_resume_device(struct device *dev)
|
|
|
|
{
|
2017-10-05 02:43:42 +08:00
|
|
|
struct bcm_device *bdev = dev_get_drvdata(dev);
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
int err;
|
2015-09-24 00:18:09 +08:00
|
|
|
|
|
|
|
bt_dev_dbg(bdev, "");
|
|
|
|
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
err = bdev->set_device_wakeup(bdev, true);
|
|
|
|
if (err) {
|
|
|
|
dev_err(dev, "Failed to power up\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
Bluetooth: hci_bcm: Mandate presence of shutdown and device wake GPIO
Commit 0395ffc1ee05 ("Bluetooth: hci_bcm: Add PM for BCM devices")
amended this driver to request a shutdown and device wake GPIO on probe,
but mandated that only one of them need to be present:
/* Make sure at-least one of the GPIO is defined and that
* a name is specified for this instance
*/
if ((!dev->device_wakeup && !dev->shutdown) || !dev->name) {
dev_err(&pdev->dev, "invalid platform data\n");
return -EINVAL;
}
However the same commit added a call to bcm_gpio_set_power() to the
->probe hook, which unconditionally accesses *both* GPIOs. Luckily,
the resulting NULL pointer deref was never reported, suggesting there's
no machine where either GPIO is missing.
Commit 8a92056837fd ("Bluetooth: hci_bcm: Add (runtime)pm support to the
serdev driver") removed the check whether at least one of the GPIOs is
present without specifying a reason.
Because commit 62aaefa7d038 ("Bluetooth: hci_bcm: improve use of gpios
API") refactored the driver to use devm_gpiod_get_optional() instead of
devm_gpiod_get(), one is now tempted to believe that the driver doesn't
require *any* of the two GPIOs.
Which is wrong, the driver still requires both GPIOs to avoid a NULL
pointer deref. To this end, establish the status quo ante and request
the GPIOs with devm_gpiod_get() again. Bail out of ->probe if either
of them is missing.
Oddly enough, whereas bcm_gpio_set_power() accesses the device wake pin
unconditionally, bcm_suspend_device() and bcm_resume_device() do check
for its presence before accessing it. Those checks are superfluous,
so remove them.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Loic Poulain <loic.poulain@linaro.org>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
bt_dev_dbg(bdev, "resume, delaying 15 ms");
|
Bluetooth: hci_bcm: Sleep instead of spinning
The driver calls mdelay(15) in the ->suspend, ->resume, ->runtime_suspend
and ->runtime_resume hook, however spinning for such a long period of
time is discouraged as per Documentation/timers/timers-howto.txt.
The use of mdelay() seems unnecessary, it is allowed to sleep in the
system sleep and runtime PM hooks (with the exception of ->suspend_noirq
and ->resume_noirq) and the driver itself also does not rely on a
non-sleeping ->runtime_resume as the only place where a synchronous
resume is performed, in bcm_dequeue(), is called from a work item in
hci_ldisc.c and hci_serdev.c.
So replace the mdelay(15) with msleep(15).
Note that the delay is inserted after asserting or deasserting the
device wake pin, but in bcm_gpio_set_power() that pin is asserted or
deasserted *without* observing a delay. It is thus unclear if the delay
is necessary at all. It is likewise unclear why it is exactly 15 ms,
the commit introducing it, 118612fb9165 ("Bluetooth: hci_bcm: Add
suspend/resume PM functions"), does not provide a rationale.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Suggested-and-reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
msleep(15);
|
2015-09-24 00:18:09 +08:00
|
|
|
|
|
|
|
/* When this executes, the device has woken up already */
|
|
|
|
if (bdev->is_suspended && bdev->hu) {
|
|
|
|
bdev->is_suspended = false;
|
|
|
|
|
|
|
|
hci_uart_set_flow_control(bdev->hu, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2017-10-05 02:43:43 +08:00
|
|
|
/* suspend callback */
|
2015-09-24 00:18:09 +08:00
|
|
|
static int bcm_suspend(struct device *dev)
|
|
|
|
{
|
2017-10-05 02:43:42 +08:00
|
|
|
struct bcm_device *bdev = dev_get_drvdata(dev);
|
2015-09-24 00:18:09 +08:00
|
|
|
int error;
|
|
|
|
|
|
|
|
bt_dev_dbg(bdev, "suspend: is_suspended %d", bdev->is_suspended);
|
|
|
|
|
2017-10-05 02:43:43 +08:00
|
|
|
/*
|
|
|
|
* When used with a device instantiated as platform_device, bcm_suspend
|
|
|
|
* can be called at any time as long as the platform device is bound,
|
|
|
|
* so it should use bcm_device_lock to protect access to hci_uart
|
2015-09-24 00:18:09 +08:00
|
|
|
* and device_wake-up GPIO.
|
|
|
|
*/
|
|
|
|
mutex_lock(&bcm_device_lock);
|
|
|
|
|
|
|
|
if (!bdev->hu)
|
|
|
|
goto unlock;
|
|
|
|
|
2015-09-24 00:18:11 +08:00
|
|
|
if (pm_runtime_active(dev))
|
|
|
|
bcm_suspend_device(dev);
|
2015-09-24 00:18:09 +08:00
|
|
|
|
2018-01-10 23:32:10 +08:00
|
|
|
if (device_may_wakeup(dev) && bdev->irq > 0) {
|
2015-09-04 21:35:44 +08:00
|
|
|
error = enable_irq_wake(bdev->irq);
|
|
|
|
if (!error)
|
|
|
|
bt_dev_dbg(bdev, "BCM irq: enabled");
|
|
|
|
}
|
|
|
|
|
2015-08-28 21:44:00 +08:00
|
|
|
unlock:
|
2015-09-01 18:13:35 +08:00
|
|
|
mutex_unlock(&bcm_device_lock);
|
2015-08-28 21:44:00 +08:00
|
|
|
|
2015-08-11 22:35:38 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-05 02:43:43 +08:00
|
|
|
/* resume callback */
|
2015-08-11 22:35:38 +08:00
|
|
|
static int bcm_resume(struct device *dev)
|
|
|
|
{
|
2017-10-05 02:43:42 +08:00
|
|
|
struct bcm_device *bdev = dev_get_drvdata(dev);
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
int err = 0;
|
2015-08-11 22:35:38 +08:00
|
|
|
|
2015-09-01 18:13:36 +08:00
|
|
|
bt_dev_dbg(bdev, "resume: is_suspended %d", bdev->is_suspended);
|
2015-08-11 22:35:38 +08:00
|
|
|
|
2017-10-05 02:43:43 +08:00
|
|
|
/*
|
|
|
|
* When used with a device instantiated as platform_device, bcm_resume
|
|
|
|
* can be called at any time as long as platform device is bound,
|
|
|
|
* so it should use bcm_device_lock to protect access to hci_uart
|
2015-09-24 00:18:09 +08:00
|
|
|
* and device_wake-up GPIO.
|
|
|
|
*/
|
2015-09-01 18:13:35 +08:00
|
|
|
mutex_lock(&bcm_device_lock);
|
2015-08-28 21:44:00 +08:00
|
|
|
|
|
|
|
if (!bdev->hu)
|
|
|
|
goto unlock;
|
|
|
|
|
2018-01-10 23:32:10 +08:00
|
|
|
if (device_may_wakeup(dev) && bdev->irq > 0) {
|
2015-09-04 21:35:44 +08:00
|
|
|
disable_irq_wake(bdev->irq);
|
|
|
|
bt_dev_dbg(bdev, "BCM irq: disabled");
|
|
|
|
}
|
|
|
|
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
err = bcm_resume_device(dev);
|
2015-08-11 22:35:38 +08:00
|
|
|
|
2015-08-28 21:44:00 +08:00
|
|
|
unlock:
|
2015-09-01 18:13:35 +08:00
|
|
|
mutex_unlock(&bcm_device_lock);
|
2015-08-28 21:44:00 +08:00
|
|
|
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
if (!err) {
|
|
|
|
pm_runtime_disable(dev);
|
|
|
|
pm_runtime_set_active(dev);
|
|
|
|
pm_runtime_enable(dev);
|
|
|
|
}
|
2015-09-24 00:18:11 +08:00
|
|
|
|
2015-08-11 22:35:38 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-17 04:28:10 +08:00
|
|
|
static const struct acpi_gpio_params first_gpio = { 0, 0, false };
|
|
|
|
static const struct acpi_gpio_params second_gpio = { 1, 0, false };
|
|
|
|
static const struct acpi_gpio_params third_gpio = { 2, 0, false };
|
2017-01-06 01:10:54 +08:00
|
|
|
|
|
|
|
static const struct acpi_gpio_mapping acpi_bcm_int_last_gpios[] = {
|
2018-03-17 04:28:10 +08:00
|
|
|
{ "device-wakeup-gpios", &first_gpio, 1 },
|
|
|
|
{ "shutdown-gpios", &second_gpio, 1 },
|
|
|
|
{ "host-wakeup-gpios", &third_gpio, 1 },
|
2017-01-06 01:10:54 +08:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct acpi_gpio_mapping acpi_bcm_int_first_gpios[] = {
|
2018-03-17 04:28:10 +08:00
|
|
|
{ "host-wakeup-gpios", &first_gpio, 1 },
|
|
|
|
{ "device-wakeup-gpios", &second_gpio, 1 },
|
|
|
|
{ "shutdown-gpios", &third_gpio, 1 },
|
2015-08-11 22:35:35 +08:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
2018-04-03 22:40:20 +08:00
|
|
|
/* Some firmware reports an IRQ which does not work (wrong pin in fw table?) */
|
|
|
|
static const struct dmi_system_id bcm_broken_irq_dmi_table[] = {
|
|
|
|
{
|
|
|
|
.ident = "Meegopad T08",
|
|
|
|
.matches = {
|
|
|
|
DMI_EXACT_MATCH(DMI_BOARD_VENDOR,
|
|
|
|
"To be filled by OEM."),
|
|
|
|
DMI_EXACT_MATCH(DMI_BOARD_NAME, "T3 MRD"),
|
|
|
|
DMI_EXACT_MATCH(DMI_BOARD_VERSION, "V1.1"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2015-08-12 18:46:01 +08:00
|
|
|
#ifdef CONFIG_ACPI
|
2015-08-11 22:35:37 +08:00
|
|
|
static int bcm_resource(struct acpi_resource *ares, void *data)
|
|
|
|
{
|
|
|
|
struct bcm_device *dev = data;
|
2015-09-04 21:35:44 +08:00
|
|
|
struct acpi_resource_extended_irq *irq;
|
|
|
|
struct acpi_resource_gpio *gpio;
|
|
|
|
struct acpi_resource_uart_serialbus *sb;
|
|
|
|
|
|
|
|
switch (ares->type) {
|
|
|
|
case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
|
|
|
|
irq = &ares->data.extended_irq;
|
2018-03-17 04:28:08 +08:00
|
|
|
if (irq->polarity != ACPI_ACTIVE_LOW)
|
|
|
|
dev_info(dev->dev, "ACPI Interrupt resource is active-high, this is usually wrong, treating the IRQ as active-low\n");
|
|
|
|
dev->irq_active_low = true;
|
2015-09-04 21:35:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_RESOURCE_TYPE_GPIO:
|
|
|
|
gpio = &ares->data.gpio;
|
2018-03-17 04:28:11 +08:00
|
|
|
if (gpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT) {
|
|
|
|
dev->gpio_int_idx = dev->gpio_count;
|
2017-10-05 02:43:36 +08:00
|
|
|
dev->irq_active_low = gpio->polarity == ACPI_ACTIVE_LOW;
|
2018-03-17 04:28:11 +08:00
|
|
|
}
|
|
|
|
dev->gpio_count++;
|
2015-09-04 21:35:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_RESOURCE_TYPE_SERIAL_BUS:
|
2015-08-11 22:35:37 +08:00
|
|
|
sb = &ares->data.uart_serial_bus;
|
2017-08-16 15:53:30 +08:00
|
|
|
if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_UART) {
|
2015-08-11 22:35:37 +08:00
|
|
|
dev->init_speed = sb->default_baud_rate;
|
2017-08-16 15:53:30 +08:00
|
|
|
dev->oper_speed = 4000000;
|
|
|
|
}
|
2015-09-04 21:35:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-08-11 22:35:37 +08:00
|
|
|
}
|
|
|
|
|
2017-10-05 02:43:41 +08:00
|
|
|
return 0;
|
2015-08-11 22:35:37 +08:00
|
|
|
}
|
Bluetooth: hci_bcm: Support Apple GPIO handling
Enable Bluetooth on the following Macs which provide custom ACPI methods
to toggle the GPIOs for device wake and shutdown instead of accessing
the pins directly:
MacBook8,1 2015 12"
MacBook9,1 2016 12"
MacBook10,1 2017 12"
MacBookPro13,1 2016 13"
MacBookPro13,2 2016 13" with Touch Bar
MacBookPro13,3 2016 15" with Touch Bar
MacBookPro14,1 2017 13"
MacBookPro14,2 2017 13" with Touch Bar
MacBookPro14,3 2017 15" with Touch Bar
On the MacBook8,1 Bluetooth is muxed with a second device (a debug port
on the SSD) under the control of PCH GPIO 36. Because serdev cannot
deal with multiple slaves yet, it is currently necessary to patch the
DSDT and remove the SSDC device.
The custom ACPI methods are called:
BTLP (Low Power) takes one argument, toggles device wake GPIO
BTPU (Power Up) tells SMC to drive shutdown GPIO high
BTPD (Power Down) tells SMC to drive shutdown GPIO low
BTRS (Reset) calls BTPD followed by BTPU
BTRB unknown, not present on all MacBooks
Search for the BTLP, BTPU and BTPD methods on ->probe and cache them in
struct bcm_device if the machine is a Mac.
Additionally, set the init_speed based on a custom device property
provided by Apple in lieu of _CRS resources. The Broadcom UART's speed
is fixed on Apple Macs: Any attempt to change it results in Bluetooth
status code 0x0c and bcm_set_baudrate() thus always returns -EBUSY.
By setting only the init_speed and leaving oper_speed at zero, we can
achieve that the host UART's speed is adjusted but the Broadcom UART's
speed is left as is.
The host wake pin goes into the SMC which handles it independently
of the OS, so there's no IRQ for it.
Thanks to Ronald Tschalär who did extensive debugging and testing of
this patch and contributed fixes.
ACPI snippet containing the custom methods and device properties
(taken from a MacBook8,1):
Method (BTLP, 1, Serialized)
{
If (LEqual (Arg0, 0x00))
{
Store (0x01, GD54) /* set PCH GPIO 54 direction to input */
}
If (LEqual (Arg0, 0x01))
{
Store (0x00, GD54) /* set PCH GPIO 54 direction to output */
Store (0x00, GP54) /* set PCH GPIO 54 value to low */
}
}
Method (BTPU, 0, Serialized)
{
Store (0x01, \_SB.PCI0.LPCB.EC.BTPC)
Sleep (0x0A)
}
Method (BTPD, 0, Serialized)
{
Store (0x00, \_SB.PCI0.LPCB.EC.BTPC)
Sleep (0x0A)
}
Method (BTRS, 0, Serialized)
{
BTPD ()
BTPU ()
}
Method (_DSM, 4, NotSerialized) // _DSM: Device-Specific Method
{
If (LEqual (Arg0, ToUUID ("a0b5b7c6-1318-441c-b0c9-fe695eaf949b")))
{
Store (Package (0x08)
{
"baud",
Buffer (0x08)
{ 0xC0, 0xC6, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00 },
"parity",
Buffer (0x08)
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
"dataBits",
Buffer (0x08)
{ 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
"stopBits",
Buffer (0x08)
{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
}, Local0)
DTGP (Arg0, Arg1, Arg2, Arg3, RefOf (Local0))
Return (Local0)
}
Return (0x00)
}
Link: https://github.com/Dunedan/mbp-2016-linux/issues/29
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=110901
Reported-by: Leif Liddy <leif.liddy@gmail.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Loic Poulain <loic.poulain@linaro.org>
Cc: Hans de Goede <hdegoede@redhat.com>
Tested-by: Max Shavrick <mxms@me.com> [MacBook8,1]
Tested-by: Leif Liddy <leif.liddy@gmail.com> [MacBook9,1]
Tested-by: Daniel Roschka <danielroschka@phoenitydawn.de> [MacBookPro13,2]
Tested-by: Ronald Tschalär <ronald@innovation.ch> [MacBookPro13,3]
Tested-by: Peter Y. Chuang <peteryuchuang@gmail.com> [MacBookPro14,1]
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Ronald Tschalär <ronald@innovation.ch>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
|
|
|
|
static int bcm_apple_set_device_wakeup(struct bcm_device *dev, bool awake)
|
|
|
|
{
|
|
|
|
if (ACPI_FAILURE(acpi_execute_simple_method(dev->btlp, NULL, !awake)))
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm_apple_set_shutdown(struct bcm_device *dev, bool powered)
|
|
|
|
{
|
|
|
|
if (ACPI_FAILURE(acpi_evaluate_object(powered ? dev->btpu : dev->btpd,
|
|
|
|
NULL, NULL, NULL)))
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm_apple_get_resources(struct bcm_device *dev)
|
|
|
|
{
|
|
|
|
struct acpi_device *adev = ACPI_COMPANION(dev->dev);
|
|
|
|
const union acpi_object *obj;
|
|
|
|
|
|
|
|
if (!adev ||
|
|
|
|
ACPI_FAILURE(acpi_get_handle(adev->handle, "BTLP", &dev->btlp)) ||
|
|
|
|
ACPI_FAILURE(acpi_get_handle(adev->handle, "BTPU", &dev->btpu)) ||
|
|
|
|
ACPI_FAILURE(acpi_get_handle(adev->handle, "BTPD", &dev->btpd)))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (!acpi_dev_get_property(adev, "baud", ACPI_TYPE_BUFFER, &obj) &&
|
|
|
|
obj->buffer.length == 8)
|
|
|
|
dev->init_speed = *(u64 *)obj->buffer.pointer;
|
|
|
|
|
|
|
|
dev->set_device_wakeup = bcm_apple_set_device_wakeup;
|
|
|
|
dev->set_shutdown = bcm_apple_set_shutdown;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline int bcm_apple_get_resources(struct bcm_device *dev)
|
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
2017-03-10 20:28:20 +08:00
|
|
|
#endif /* CONFIG_ACPI */
|
2015-08-11 22:35:37 +08:00
|
|
|
|
2018-01-10 23:32:10 +08:00
|
|
|
static int bcm_gpio_set_device_wakeup(struct bcm_device *dev, bool awake)
|
|
|
|
{
|
2018-03-06 02:02:35 +08:00
|
|
|
gpiod_set_value_cansleep(dev->device_wakeup, awake);
|
2018-01-10 23:32:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm_gpio_set_shutdown(struct bcm_device *dev, bool powered)
|
|
|
|
{
|
2018-03-06 02:02:35 +08:00
|
|
|
gpiod_set_value_cansleep(dev->shutdown, powered);
|
2018-01-10 23:32:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-17 12:04:41 +08:00
|
|
|
/* Try a bunch of names for TXCO */
|
|
|
|
static struct clk *bcm_get_txco(struct device *dev)
|
|
|
|
{
|
|
|
|
struct clk *clk;
|
|
|
|
|
|
|
|
/* New explicit name */
|
|
|
|
clk = devm_clk_get(dev, "txco");
|
|
|
|
if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER)
|
|
|
|
return clk;
|
|
|
|
|
|
|
|
/* Deprecated name */
|
|
|
|
clk = devm_clk_get(dev, "extclk");
|
|
|
|
if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER)
|
|
|
|
return clk;
|
|
|
|
|
|
|
|
/* Original code used no name at all */
|
|
|
|
return devm_clk_get(dev, NULL);
|
|
|
|
}
|
|
|
|
|
2017-10-05 02:43:40 +08:00
|
|
|
static int bcm_get_resources(struct bcm_device *dev)
|
2015-08-11 22:35:35 +08:00
|
|
|
{
|
2018-04-03 22:40:20 +08:00
|
|
|
const struct dmi_system_id *dmi_id;
|
2018-12-17 12:04:43 +08:00
|
|
|
int err;
|
2018-04-03 22:40:20 +08:00
|
|
|
|
2017-10-05 02:43:39 +08:00
|
|
|
dev->name = dev_name(dev->dev);
|
2015-08-11 22:35:35 +08:00
|
|
|
|
Bluetooth: hci_bcm: Support Apple GPIO handling
Enable Bluetooth on the following Macs which provide custom ACPI methods
to toggle the GPIOs for device wake and shutdown instead of accessing
the pins directly:
MacBook8,1 2015 12"
MacBook9,1 2016 12"
MacBook10,1 2017 12"
MacBookPro13,1 2016 13"
MacBookPro13,2 2016 13" with Touch Bar
MacBookPro13,3 2016 15" with Touch Bar
MacBookPro14,1 2017 13"
MacBookPro14,2 2017 13" with Touch Bar
MacBookPro14,3 2017 15" with Touch Bar
On the MacBook8,1 Bluetooth is muxed with a second device (a debug port
on the SSD) under the control of PCH GPIO 36. Because serdev cannot
deal with multiple slaves yet, it is currently necessary to patch the
DSDT and remove the SSDC device.
The custom ACPI methods are called:
BTLP (Low Power) takes one argument, toggles device wake GPIO
BTPU (Power Up) tells SMC to drive shutdown GPIO high
BTPD (Power Down) tells SMC to drive shutdown GPIO low
BTRS (Reset) calls BTPD followed by BTPU
BTRB unknown, not present on all MacBooks
Search for the BTLP, BTPU and BTPD methods on ->probe and cache them in
struct bcm_device if the machine is a Mac.
Additionally, set the init_speed based on a custom device property
provided by Apple in lieu of _CRS resources. The Broadcom UART's speed
is fixed on Apple Macs: Any attempt to change it results in Bluetooth
status code 0x0c and bcm_set_baudrate() thus always returns -EBUSY.
By setting only the init_speed and leaving oper_speed at zero, we can
achieve that the host UART's speed is adjusted but the Broadcom UART's
speed is left as is.
The host wake pin goes into the SMC which handles it independently
of the OS, so there's no IRQ for it.
Thanks to Ronald Tschalär who did extensive debugging and testing of
this patch and contributed fixes.
ACPI snippet containing the custom methods and device properties
(taken from a MacBook8,1):
Method (BTLP, 1, Serialized)
{
If (LEqual (Arg0, 0x00))
{
Store (0x01, GD54) /* set PCH GPIO 54 direction to input */
}
If (LEqual (Arg0, 0x01))
{
Store (0x00, GD54) /* set PCH GPIO 54 direction to output */
Store (0x00, GP54) /* set PCH GPIO 54 value to low */
}
}
Method (BTPU, 0, Serialized)
{
Store (0x01, \_SB.PCI0.LPCB.EC.BTPC)
Sleep (0x0A)
}
Method (BTPD, 0, Serialized)
{
Store (0x00, \_SB.PCI0.LPCB.EC.BTPC)
Sleep (0x0A)
}
Method (BTRS, 0, Serialized)
{
BTPD ()
BTPU ()
}
Method (_DSM, 4, NotSerialized) // _DSM: Device-Specific Method
{
If (LEqual (Arg0, ToUUID ("a0b5b7c6-1318-441c-b0c9-fe695eaf949b")))
{
Store (Package (0x08)
{
"baud",
Buffer (0x08)
{ 0xC0, 0xC6, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00 },
"parity",
Buffer (0x08)
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
"dataBits",
Buffer (0x08)
{ 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
"stopBits",
Buffer (0x08)
{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
}, Local0)
DTGP (Arg0, Arg1, Arg2, Arg3, RefOf (Local0))
Return (Local0)
}
Return (0x00)
}
Link: https://github.com/Dunedan/mbp-2016-linux/issues/29
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=110901
Reported-by: Leif Liddy <leif.liddy@gmail.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Loic Poulain <loic.poulain@linaro.org>
Cc: Hans de Goede <hdegoede@redhat.com>
Tested-by: Max Shavrick <mxms@me.com> [MacBook8,1]
Tested-by: Leif Liddy <leif.liddy@gmail.com> [MacBook9,1]
Tested-by: Daniel Roschka <danielroschka@phoenitydawn.de> [MacBookPro13,2]
Tested-by: Ronald Tschalär <ronald@innovation.ch> [MacBookPro13,3]
Tested-by: Peter Y. Chuang <peteryuchuang@gmail.com> [MacBookPro14,1]
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Ronald Tschalär <ronald@innovation.ch>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
if (x86_apple_machine && !bcm_apple_get_resources(dev))
|
|
|
|
return 0;
|
|
|
|
|
2018-12-17 12:04:41 +08:00
|
|
|
dev->txco_clk = bcm_get_txco(dev->dev);
|
2017-01-06 01:10:54 +08:00
|
|
|
|
2018-12-17 12:04:39 +08:00
|
|
|
/* Handle deferred probing */
|
2018-12-17 12:04:41 +08:00
|
|
|
if (dev->txco_clk == ERR_PTR(-EPROBE_DEFER))
|
|
|
|
return PTR_ERR(dev->txco_clk);
|
2018-12-17 12:04:39 +08:00
|
|
|
|
2018-12-17 12:04:40 +08:00
|
|
|
/* Ignore all other errors as before */
|
2018-12-17 12:04:41 +08:00
|
|
|
if (IS_ERR(dev->txco_clk))
|
|
|
|
dev->txco_clk = NULL;
|
2018-12-17 12:04:40 +08:00
|
|
|
|
2018-12-17 12:04:42 +08:00
|
|
|
dev->lpo_clk = devm_clk_get(dev->dev, "lpo");
|
|
|
|
if (dev->lpo_clk == ERR_PTR(-EPROBE_DEFER))
|
|
|
|
return PTR_ERR(dev->lpo_clk);
|
|
|
|
|
|
|
|
if (IS_ERR(dev->lpo_clk))
|
|
|
|
dev->lpo_clk = NULL;
|
|
|
|
|
|
|
|
/* Check if we accidentally fetched the lpo clock twice */
|
|
|
|
if (dev->lpo_clk && clk_is_match(dev->lpo_clk, dev->txco_clk)) {
|
|
|
|
devm_clk_put(dev->dev, dev->txco_clk);
|
|
|
|
dev->txco_clk = NULL;
|
|
|
|
}
|
|
|
|
|
2018-02-25 22:10:52 +08:00
|
|
|
dev->device_wakeup = devm_gpiod_get_optional(dev->dev, "device-wakeup",
|
|
|
|
GPIOD_OUT_LOW);
|
2015-08-12 15:20:56 +08:00
|
|
|
if (IS_ERR(dev->device_wakeup))
|
|
|
|
return PTR_ERR(dev->device_wakeup);
|
2015-08-11 22:35:35 +08:00
|
|
|
|
2018-02-25 22:10:52 +08:00
|
|
|
dev->shutdown = devm_gpiod_get_optional(dev->dev, "shutdown",
|
|
|
|
GPIOD_OUT_LOW);
|
2015-08-12 15:20:56 +08:00
|
|
|
if (IS_ERR(dev->shutdown))
|
|
|
|
return PTR_ERR(dev->shutdown);
|
2015-08-11 22:35:35 +08:00
|
|
|
|
2018-01-10 23:32:10 +08:00
|
|
|
dev->set_device_wakeup = bcm_gpio_set_device_wakeup;
|
|
|
|
dev->set_shutdown = bcm_gpio_set_shutdown;
|
|
|
|
|
2018-12-17 12:04:43 +08:00
|
|
|
dev->supplies[0].supply = "vbat";
|
|
|
|
dev->supplies[1].supply = "vddio";
|
|
|
|
err = devm_regulator_bulk_get(dev->dev, BCM_NUM_SUPPLIES,
|
|
|
|
dev->supplies);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2015-09-04 21:35:44 +08:00
|
|
|
/* IRQ can be declared in ACPI table as Interrupt or GpioInt */
|
|
|
|
if (dev->irq <= 0) {
|
|
|
|
struct gpio_desc *gpio;
|
|
|
|
|
2017-10-05 02:43:39 +08:00
|
|
|
gpio = devm_gpiod_get_optional(dev->dev, "host-wakeup",
|
2015-09-04 21:35:44 +08:00
|
|
|
GPIOD_IN);
|
|
|
|
if (IS_ERR(gpio))
|
|
|
|
return PTR_ERR(gpio);
|
|
|
|
|
|
|
|
dev->irq = gpiod_to_irq(gpio);
|
|
|
|
}
|
|
|
|
|
2018-04-03 22:40:20 +08:00
|
|
|
dmi_id = dmi_first_match(bcm_broken_irq_dmi_table);
|
|
|
|
if (dmi_id) {
|
|
|
|
dev_info(dev->dev, "%s: Has a broken IRQ config, disabling IRQ support / runtime-pm\n",
|
|
|
|
dmi_id->ident);
|
|
|
|
dev->irq = 0;
|
|
|
|
}
|
|
|
|
|
2018-01-10 23:32:10 +08:00
|
|
|
dev_dbg(dev->dev, "BCM irq: %d\n", dev->irq);
|
2017-03-10 20:28:20 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
static int bcm_acpi_probe(struct bcm_device *dev)
|
|
|
|
{
|
|
|
|
LIST_HEAD(resources);
|
|
|
|
const struct acpi_gpio_mapping *gpio_mapping = acpi_bcm_int_last_gpios;
|
2017-10-05 02:43:41 +08:00
|
|
|
struct resource_entry *entry;
|
2017-03-10 20:28:20 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-08-11 22:35:37 +08:00
|
|
|
/* Retrieve UART ACPI info */
|
2018-03-17 04:28:11 +08:00
|
|
|
dev->gpio_int_idx = -1;
|
2017-10-05 02:43:39 +08:00
|
|
|
ret = acpi_dev_get_resources(ACPI_COMPANION(dev->dev),
|
2015-09-30 21:26:45 +08:00
|
|
|
&resources, bcm_resource, dev);
|
2015-09-30 21:26:42 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2017-10-05 02:43:41 +08:00
|
|
|
|
|
|
|
resource_list_for_each_entry(entry, &resources) {
|
|
|
|
if (resource_type(entry->res) == IORESOURCE_IRQ) {
|
|
|
|
dev->irq = entry->res->start;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-09-30 21:26:41 +08:00
|
|
|
acpi_dev_free_resource_list(&resources);
|
2015-08-11 22:35:37 +08:00
|
|
|
|
2018-03-17 04:28:11 +08:00
|
|
|
/* If the DSDT uses an Interrupt resource for the IRQ, then there are
|
|
|
|
* only 2 GPIO resources, we use the irq-last mapping for this, since
|
|
|
|
* we already have an irq the 3th / last mapping will not be used.
|
|
|
|
*/
|
|
|
|
if (dev->irq)
|
|
|
|
gpio_mapping = acpi_bcm_int_last_gpios;
|
|
|
|
else if (dev->gpio_int_idx == 0)
|
|
|
|
gpio_mapping = acpi_bcm_int_first_gpios;
|
|
|
|
else if (dev->gpio_int_idx == 2)
|
|
|
|
gpio_mapping = acpi_bcm_int_last_gpios;
|
|
|
|
else
|
|
|
|
dev_warn(dev->dev, "Unexpected ACPI gpio_int_idx: %d\n",
|
|
|
|
dev->gpio_int_idx);
|
|
|
|
|
|
|
|
/* Warn if our expectations are not met. */
|
|
|
|
if (dev->gpio_count != (dev->irq ? 2 : 3))
|
|
|
|
dev_warn(dev->dev, "Unexpected number of ACPI GPIOs: %d\n",
|
|
|
|
dev->gpio_count);
|
|
|
|
|
|
|
|
ret = devm_acpi_dev_add_driver_gpios(dev->dev, gpio_mapping);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2018-03-17 04:28:07 +08:00
|
|
|
if (irq_polarity != -1) {
|
|
|
|
dev->irq_active_low = irq_polarity;
|
|
|
|
dev_warn(dev->dev, "Overwriting IRQ polarity to active %s by module-param\n",
|
|
|
|
dev->irq_active_low ? "low" : "high");
|
2015-09-24 00:18:08 +08:00
|
|
|
}
|
|
|
|
|
2015-08-11 22:35:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2015-08-12 18:46:01 +08:00
|
|
|
#else
|
|
|
|
static int bcm_acpi_probe(struct bcm_device *dev)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_ACPI */
|
2015-08-11 22:35:35 +08:00
|
|
|
|
2017-10-05 02:43:43 +08:00
|
|
|
static int bcm_of_probe(struct bcm_device *bdev)
|
|
|
|
{
|
|
|
|
device_property_read_u32(bdev->dev, "max-speed", &bdev->oper_speed);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-11 22:35:35 +08:00
|
|
|
static int bcm_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct bcm_device *dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
|
|
|
|
if (!dev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-10-05 02:43:39 +08:00
|
|
|
dev->dev = &pdev->dev;
|
2017-10-05 02:43:38 +08:00
|
|
|
dev->irq = platform_get_irq(pdev, 0);
|
2015-08-11 22:35:35 +08:00
|
|
|
|
2017-10-05 02:43:37 +08:00
|
|
|
if (has_acpi_companion(&pdev->dev)) {
|
2017-03-10 20:28:20 +08:00
|
|
|
ret = bcm_acpi_probe(dev);
|
2017-10-05 02:43:37 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-10-05 02:43:40 +08:00
|
|
|
ret = bcm_get_resources(dev);
|
2015-09-30 21:26:44 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2015-08-11 22:35:35 +08:00
|
|
|
|
|
|
|
platform_set_drvdata(pdev, dev);
|
|
|
|
|
|
|
|
dev_info(&pdev->dev, "%s device registered.\n", dev->name);
|
|
|
|
|
|
|
|
/* Place this instance on the device list */
|
2015-09-01 18:13:35 +08:00
|
|
|
mutex_lock(&bcm_device_lock);
|
2015-08-11 22:35:35 +08:00
|
|
|
list_add_tail(&dev->list, &bcm_device_list);
|
2015-09-01 18:13:35 +08:00
|
|
|
mutex_unlock(&bcm_device_lock);
|
2015-08-11 22:35:35 +08:00
|
|
|
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
ret = bcm_gpio_set_power(dev, false);
|
|
|
|
if (ret)
|
|
|
|
dev_err(&pdev->dev, "Failed to power down\n");
|
2015-08-11 22:35:35 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct bcm_device *dev = platform_get_drvdata(pdev);
|
|
|
|
|
2015-09-01 18:13:35 +08:00
|
|
|
mutex_lock(&bcm_device_lock);
|
2015-08-11 22:35:35 +08:00
|
|
|
list_del(&dev->list);
|
2015-09-01 18:13:35 +08:00
|
|
|
mutex_unlock(&bcm_device_lock);
|
2015-08-11 22:35:35 +08:00
|
|
|
|
|
|
|
dev_info(&pdev->dev, "%s device unregistered.\n", dev->name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-06 13:52:18 +08:00
|
|
|
static const struct hci_uart_proto bcm_proto = {
|
|
|
|
.id = HCI_UART_BCM,
|
2016-09-19 18:05:12 +08:00
|
|
|
.name = "Broadcom",
|
2015-10-21 03:30:45 +08:00
|
|
|
.manufacturer = 15,
|
2015-06-09 22:15:37 +08:00
|
|
|
.init_speed = 115200,
|
2015-04-06 13:52:18 +08:00
|
|
|
.open = bcm_open,
|
|
|
|
.close = bcm_close,
|
|
|
|
.flush = bcm_flush,
|
|
|
|
.setup = bcm_setup,
|
2015-06-09 22:15:37 +08:00
|
|
|
.set_baudrate = bcm_set_baudrate,
|
2015-04-06 13:52:18 +08:00
|
|
|
.recv = bcm_recv,
|
|
|
|
.enqueue = bcm_enqueue,
|
|
|
|
.dequeue = bcm_dequeue,
|
|
|
|
};
|
|
|
|
|
2015-08-11 22:35:35 +08:00
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
static const struct acpi_device_id bcm_acpi_match[] = {
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2E00" },
|
|
|
|
{ "BCM2E01" },
|
|
|
|
{ "BCM2E02" },
|
|
|
|
{ "BCM2E03" },
|
|
|
|
{ "BCM2E04" },
|
|
|
|
{ "BCM2E05" },
|
|
|
|
{ "BCM2E06" },
|
|
|
|
{ "BCM2E07" },
|
|
|
|
{ "BCM2E08" },
|
|
|
|
{ "BCM2E09" },
|
|
|
|
{ "BCM2E0A" },
|
|
|
|
{ "BCM2E0B" },
|
|
|
|
{ "BCM2E0C" },
|
|
|
|
{ "BCM2E0D" },
|
|
|
|
{ "BCM2E0E" },
|
|
|
|
{ "BCM2E0F" },
|
|
|
|
{ "BCM2E10" },
|
|
|
|
{ "BCM2E11" },
|
|
|
|
{ "BCM2E12" },
|
|
|
|
{ "BCM2E13" },
|
|
|
|
{ "BCM2E14" },
|
|
|
|
{ "BCM2E15" },
|
|
|
|
{ "BCM2E16" },
|
|
|
|
{ "BCM2E17" },
|
|
|
|
{ "BCM2E18" },
|
|
|
|
{ "BCM2E19" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2E1A" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2E1B" },
|
|
|
|
{ "BCM2E1C" },
|
|
|
|
{ "BCM2E1D" },
|
|
|
|
{ "BCM2E1F" },
|
|
|
|
{ "BCM2E20" },
|
|
|
|
{ "BCM2E21" },
|
|
|
|
{ "BCM2E22" },
|
|
|
|
{ "BCM2E23" },
|
|
|
|
{ "BCM2E24" },
|
|
|
|
{ "BCM2E25" },
|
|
|
|
{ "BCM2E26" },
|
|
|
|
{ "BCM2E27" },
|
|
|
|
{ "BCM2E28" },
|
|
|
|
{ "BCM2E29" },
|
|
|
|
{ "BCM2E2A" },
|
|
|
|
{ "BCM2E2B" },
|
|
|
|
{ "BCM2E2C" },
|
|
|
|
{ "BCM2E2D" },
|
|
|
|
{ "BCM2E2E" },
|
|
|
|
{ "BCM2E2F" },
|
|
|
|
{ "BCM2E30" },
|
|
|
|
{ "BCM2E31" },
|
|
|
|
{ "BCM2E32" },
|
|
|
|
{ "BCM2E33" },
|
|
|
|
{ "BCM2E34" },
|
|
|
|
{ "BCM2E35" },
|
|
|
|
{ "BCM2E36" },
|
|
|
|
{ "BCM2E37" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2E38" },
|
|
|
|
{ "BCM2E39" },
|
|
|
|
{ "BCM2E3A" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2E3B" },
|
|
|
|
{ "BCM2E3C" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2E3D" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2E3E" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2E3F" },
|
|
|
|
{ "BCM2E40" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2E41" },
|
|
|
|
{ "BCM2E42" },
|
|
|
|
{ "BCM2E43" },
|
|
|
|
{ "BCM2E44" },
|
|
|
|
{ "BCM2E45" },
|
|
|
|
{ "BCM2E46" },
|
|
|
|
{ "BCM2E47" },
|
|
|
|
{ "BCM2E48" },
|
|
|
|
{ "BCM2E49" },
|
|
|
|
{ "BCM2E4A" },
|
|
|
|
{ "BCM2E4B" },
|
|
|
|
{ "BCM2E4C" },
|
|
|
|
{ "BCM2E4D" },
|
|
|
|
{ "BCM2E4E" },
|
|
|
|
{ "BCM2E4F" },
|
|
|
|
{ "BCM2E50" },
|
|
|
|
{ "BCM2E51" },
|
|
|
|
{ "BCM2E52" },
|
|
|
|
{ "BCM2E53" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2E54" },
|
|
|
|
{ "BCM2E55" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2E56" },
|
|
|
|
{ "BCM2E57" },
|
|
|
|
{ "BCM2E58" },
|
|
|
|
{ "BCM2E59" },
|
|
|
|
{ "BCM2E5A" },
|
|
|
|
{ "BCM2E5B" },
|
|
|
|
{ "BCM2E5C" },
|
|
|
|
{ "BCM2E5D" },
|
|
|
|
{ "BCM2E5E" },
|
|
|
|
{ "BCM2E5F" },
|
|
|
|
{ "BCM2E60" },
|
|
|
|
{ "BCM2E61" },
|
|
|
|
{ "BCM2E62" },
|
|
|
|
{ "BCM2E63" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2E64" },
|
|
|
|
{ "BCM2E65" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2E66" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2E67" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2E68" },
|
|
|
|
{ "BCM2E69" },
|
|
|
|
{ "BCM2E6B" },
|
|
|
|
{ "BCM2E6D" },
|
|
|
|
{ "BCM2E6E" },
|
|
|
|
{ "BCM2E6F" },
|
|
|
|
{ "BCM2E70" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2E71" },
|
|
|
|
{ "BCM2E72" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2E73" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2E74" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2E75" },
|
|
|
|
{ "BCM2E76" },
|
|
|
|
{ "BCM2E77" },
|
|
|
|
{ "BCM2E78" },
|
|
|
|
{ "BCM2E79" },
|
|
|
|
{ "BCM2E7A" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2E7B" },
|
|
|
|
{ "BCM2E7C" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2E7D" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2E7E" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2E7F" },
|
|
|
|
{ "BCM2E80" },
|
|
|
|
{ "BCM2E81" },
|
|
|
|
{ "BCM2E82" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2E83" },
|
|
|
|
{ "BCM2E84" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2E85" },
|
|
|
|
{ "BCM2E86" },
|
|
|
|
{ "BCM2E87" },
|
|
|
|
{ "BCM2E88" },
|
|
|
|
{ "BCM2E89" },
|
|
|
|
{ "BCM2E8A" },
|
|
|
|
{ "BCM2E8B" },
|
|
|
|
{ "BCM2E8C" },
|
|
|
|
{ "BCM2E8D" },
|
|
|
|
{ "BCM2E8E" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2E90" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2E92" },
|
|
|
|
{ "BCM2E93" },
|
|
|
|
{ "BCM2E94" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2E95" },
|
|
|
|
{ "BCM2E96" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2E97" },
|
|
|
|
{ "BCM2E98" },
|
|
|
|
{ "BCM2E99" },
|
|
|
|
{ "BCM2E9A" },
|
|
|
|
{ "BCM2E9B" },
|
|
|
|
{ "BCM2E9C" },
|
|
|
|
{ "BCM2E9D" },
|
|
|
|
{ "BCM2EA0" },
|
|
|
|
{ "BCM2EA1" },
|
|
|
|
{ "BCM2EA2" },
|
|
|
|
{ "BCM2EA3" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2EA4" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2EA5" },
|
|
|
|
{ "BCM2EA6" },
|
|
|
|
{ "BCM2EA7" },
|
|
|
|
{ "BCM2EA8" },
|
|
|
|
{ "BCM2EA9" },
|
2018-03-17 04:28:11 +08:00
|
|
|
{ "BCM2EAA" },
|
2018-03-21 20:53:18 +08:00
|
|
|
{ "BCM2EAB" },
|
|
|
|
{ "BCM2EAC" },
|
2015-08-11 22:35:35 +08:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(acpi, bcm_acpi_match);
|
|
|
|
#endif
|
|
|
|
|
2017-10-05 02:43:43 +08:00
|
|
|
/* suspend and resume callbacks */
|
2015-09-24 00:18:11 +08:00
|
|
|
static const struct dev_pm_ops bcm_pm_ops = {
|
|
|
|
SET_SYSTEM_SLEEP_PM_OPS(bcm_suspend, bcm_resume)
|
|
|
|
SET_RUNTIME_PM_OPS(bcm_suspend_device, bcm_resume_device, NULL)
|
|
|
|
};
|
2015-08-11 22:35:38 +08:00
|
|
|
|
2015-08-11 22:35:35 +08:00
|
|
|
static struct platform_driver bcm_driver = {
|
|
|
|
.probe = bcm_probe,
|
|
|
|
.remove = bcm_remove,
|
|
|
|
.driver = {
|
|
|
|
.name = "hci_bcm",
|
|
|
|
.acpi_match_table = ACPI_PTR(bcm_acpi_match),
|
2015-08-11 22:35:38 +08:00
|
|
|
.pm = &bcm_pm_ops,
|
2015-08-11 22:35:35 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-08-18 01:59:51 +08:00
|
|
|
static int bcm_serdev_probe(struct serdev_device *serdev)
|
|
|
|
{
|
2017-10-05 02:43:43 +08:00
|
|
|
struct bcm_device *bcmdev;
|
2017-08-18 01:59:51 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
bcmdev = devm_kzalloc(&serdev->dev, sizeof(*bcmdev), GFP_KERNEL);
|
|
|
|
if (!bcmdev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-10-05 02:43:43 +08:00
|
|
|
bcmdev->dev = &serdev->dev;
|
2017-10-11 21:46:21 +08:00
|
|
|
#ifdef CONFIG_PM
|
2017-10-05 02:43:43 +08:00
|
|
|
bcmdev->hu = &bcmdev->serdev_hu;
|
2017-10-11 21:46:21 +08:00
|
|
|
#endif
|
2017-10-05 02:43:43 +08:00
|
|
|
bcmdev->serdev_hu.serdev = serdev;
|
2017-08-18 01:59:51 +08:00
|
|
|
serdev_device_set_drvdata(serdev, bcmdev);
|
|
|
|
|
2017-10-05 02:43:43 +08:00
|
|
|
if (has_acpi_companion(&serdev->dev))
|
|
|
|
err = bcm_acpi_probe(bcmdev);
|
|
|
|
else
|
|
|
|
err = bcm_of_probe(bcmdev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2017-08-18 01:59:51 +08:00
|
|
|
|
2017-10-05 02:43:43 +08:00
|
|
|
err = bcm_get_resources(bcmdev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-03-08 05:39:03 +08:00
|
|
|
if (!bcmdev->shutdown) {
|
|
|
|
dev_warn(&serdev->dev,
|
|
|
|
"No reset resource, using default baud rate\n");
|
|
|
|
bcmdev->oper_speed = bcmdev->init_speed;
|
|
|
|
}
|
|
|
|
|
Bluetooth: hci_bcm: Handle errors properly
A significant portion of this driver lacks error handling. As a first
step, add error paths to bcm_gpio_set_power(), bcm_open(), bcm_close(),
bcm_suspend_device(), bcm_resume_device(), bcm_resume(), bcm_probe() and
bcm_serdev_probe(). (I've also scrutinized bcm_suspend() but think it's
fine as is.)
Those are all the functions accessing the device wake and shutdown GPIO.
On Apple Macs the pins are accessed through ACPI methods, which may fail
for various reasons, hence proper error handling is necessary. Non-Macs
access the pins directly, which may fail as well but the GPIO core does
not yet pass back errors to consumers.
Cc: Frédéric Danis <frederic.danis.oss@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-01-10 23:32:10 +08:00
|
|
|
err = bcm_gpio_set_power(bcmdev, false);
|
|
|
|
if (err)
|
|
|
|
dev_err(&serdev->dev, "Failed to power down\n");
|
2017-10-05 02:43:43 +08:00
|
|
|
|
|
|
|
return hci_uart_register_device(&bcmdev->serdev_hu, &bcm_proto);
|
2017-08-18 01:59:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bcm_serdev_remove(struct serdev_device *serdev)
|
|
|
|
{
|
2017-10-05 02:43:43 +08:00
|
|
|
struct bcm_device *bcmdev = serdev_device_get_drvdata(serdev);
|
2017-08-18 01:59:51 +08:00
|
|
|
|
2017-10-05 02:43:43 +08:00
|
|
|
hci_uart_unregister_device(&bcmdev->serdev_hu);
|
2017-08-18 01:59:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_OF
|
|
|
|
static const struct of_device_id bcm_bluetooth_of_match[] = {
|
2018-12-17 12:04:45 +08:00
|
|
|
{ .compatible = "brcm,bcm20702a1" },
|
2017-08-18 01:59:51 +08:00
|
|
|
{ .compatible = "brcm,bcm43438-bt" },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, bcm_bluetooth_of_match);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct serdev_device_driver bcm_serdev_driver = {
|
|
|
|
.probe = bcm_serdev_probe,
|
|
|
|
.remove = bcm_serdev_remove,
|
|
|
|
.driver = {
|
|
|
|
.name = "hci_uart_bcm",
|
|
|
|
.of_match_table = of_match_ptr(bcm_bluetooth_of_match),
|
2017-10-05 02:43:43 +08:00
|
|
|
.acpi_match_table = ACPI_PTR(bcm_acpi_match),
|
|
|
|
.pm = &bcm_pm_ops,
|
2017-08-18 01:59:51 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-04-06 13:52:18 +08:00
|
|
|
int __init bcm_init(void)
|
|
|
|
{
|
2017-08-18 01:59:51 +08:00
|
|
|
/* For now, we need to keep both platform device
|
|
|
|
* driver (ACPI generated) and serdev driver (DT).
|
|
|
|
*/
|
2015-08-11 22:35:35 +08:00
|
|
|
platform_driver_register(&bcm_driver);
|
2017-08-18 01:59:51 +08:00
|
|
|
serdev_device_driver_register(&bcm_serdev_driver);
|
2015-08-11 22:35:35 +08:00
|
|
|
|
2015-04-06 13:52:18 +08:00
|
|
|
return hci_uart_register_proto(&bcm_proto);
|
|
|
|
}
|
|
|
|
|
|
|
|
int __exit bcm_deinit(void)
|
|
|
|
{
|
2015-08-11 22:35:35 +08:00
|
|
|
platform_driver_unregister(&bcm_driver);
|
2017-08-18 01:59:51 +08:00
|
|
|
serdev_device_driver_unregister(&bcm_serdev_driver);
|
2015-08-11 22:35:35 +08:00
|
|
|
|
2015-04-06 13:52:18 +08:00
|
|
|
return hci_uart_unregister_proto(&bcm_proto);
|
|
|
|
}
|