Commit 2369afb6 authored by David S. Miller's avatar David S. Miller

Merge branch 'for-upstream' of...

Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next

Johan Hedberg says:

====================
pull request: bluetooth-next 2019-03-02

Here's one more bluetooth-next pull request for the 5.1 kernel:

 - Added support for MediaTek MT7663U and MT7668U UART devices
 - Cleanups & fixes to the hci_qca driver
 - Fixed wakeup pin behavior for QCA6174A controller

Please let me know if there are any issues pulling. Thanks.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 9eb35914 22eaf6c9
...@@ -9,6 +9,9 @@ Required properties: ...@@ -9,6 +9,9 @@ Required properties:
(more may be added later) are: (more may be added later) are:
"usb1286,204e" (Marvell 8997) "usb1286,204e" (Marvell 8997)
"usbcf3,e300" (Qualcomm QCA6174A)
"usb4ca,301a" (Qualcomm QCA6174A (Lite-On))
Also, vendors that use btusb may have device additional properties, e.g: Also, vendors that use btusb may have device additional properties, e.g:
Documentation/devicetree/bindings/net/marvell-bt-8xxx.txt Documentation/devicetree/bindings/net/marvell-bt-8xxx.txt
......
...@@ -33,3 +33,67 @@ Example: ...@@ -33,3 +33,67 @@ Example:
clock-names = "ref"; clock-names = "ref";
}; };
}; };
MediaTek UART based Bluetooth Devices
==================================
This device is a serial attached device to UART device and thus it must be a
child node of the serial node with UART.
Please refer to the following documents for generic properties:
Documentation/devicetree/bindings/serial/slave-device.txt
Required properties:
- compatible: Must be
"mediatek,mt7663u-bluetooth": for MT7663U device
"mediatek,mt7668u-bluetooth": for MT7668U device
- vcc-supply: Main voltage regulator
- pinctrl-names: Should be "default", "runtime"
- pinctrl-0: Should contain UART RXD low when the device is powered up to
enter proper bootstrap mode.
- pinctrl-1: Should contain UART mode pin ctrl
Optional properties:
- reset-gpios: GPIO used to reset the device whose initial state keeps low,
if the GPIO is missing, then board-level design should be
guaranteed.
- current-speed: Current baud rate of the device whose defaults to 921600
Example:
uart1_pins_boot: uart1-default {
pins-dat {
pinmux = <MT7623_PIN_81_URXD1_FUNC_GPIO81>;
output-low;
};
};
uart1_pins_runtime: uart1-runtime {
pins-dat {
pinmux = <MT7623_PIN_81_URXD1_FUNC_URXD1>,
<MT7623_PIN_82_UTXD1_FUNC_UTXD1>;
};
};
uart1: serial@11003000 {
compatible = "mediatek,mt7623-uart",
"mediatek,mt6577-uart";
reg = <0 0x11003000 0 0x400>;
interrupts = <GIC_SPI 52 IRQ_TYPE_LEVEL_LOW>;
clocks = <&pericfg CLK_PERI_UART1_SEL>,
<&pericfg CLK_PERI_UART1>;
clock-names = "baud", "bus";
bluetooth {
compatible = "mediatek,mt7663u-bluetooth";
vcc-supply = <&reg_5v>;
reset-gpios = <&pio 24 GPIO_ACTIVE_LOW>;
pinctrl-names = "default", "runtime";
pinctrl-0 = <&uart1_pins_boot>;
pinctrl-1 = <&uart1_pins_runtime>;
current-speed = <921600>;
};
};
...@@ -200,6 +200,19 @@ backlight: backlight { ...@@ -200,6 +200,19 @@ backlight: backlight {
pinctrl-0 = <&bl_en>; pinctrl-0 = <&bl_en>;
pwm-delay-us = <10000>; pwm-delay-us = <10000>;
}; };
gpio_keys: gpio-keys {
compatible = "gpio-keys";
pinctrl-names = "default";
pinctrl-0 = <&bt_host_wake_l>;
wake_on_bt: wake-on-bt {
label = "Wake-on-Bluetooth";
gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
linux,code = <KEY_WAKEUP>;
wakeup-source;
};
};
}; };
&ppvar_bigcpu { &ppvar_bigcpu {
......
...@@ -175,6 +175,21 @@ dmic: dmic { ...@@ -175,6 +175,21 @@ dmic: dmic {
pinctrl-0 = <&dmic_en>; pinctrl-0 = <&dmic_en>;
wakeup-delay-ms = <250>; wakeup-delay-ms = <250>;
}; };
gpio_keys: gpio-keys {
compatible = "gpio-keys";
pinctrl-names = "default";
pinctrl-0 = <&pen_eject_odl>;
pen-insert {
label = "Pen Insert";
/* Insert = low, eject = high */
gpios = <&gpio1 1 GPIO_ACTIVE_LOW>;
linux,code = <SW_PEN_INSERTED>;
linux,input-type = <EV_SW>;
wakeup-source;
};
};
}; };
/* pp900_s0 aliases */ /* pp900_s0 aliases */
...@@ -328,20 +343,6 @@ &cru { ...@@ -328,20 +343,6 @@ &cru {
<400000000>; <400000000>;
}; };
&gpio_keys {
pinctrl-names = "default";
pinctrl-0 = <&bt_host_wake_l>, <&pen_eject_odl>;
pen-insert {
label = "Pen Insert";
/* Insert = low, eject = high */
gpios = <&gpio1 1 GPIO_ACTIVE_LOW>;
linux,code = <SW_PEN_INSERTED>;
linux,input-type = <EV_SW>;
wakeup-source;
};
};
&i2c_tunnel { &i2c_tunnel {
google,remote-bus = <0>; google,remote-bus = <0>;
}; };
...@@ -437,8 +438,19 @@ &spi2 { ...@@ -437,8 +438,19 @@ &spi2 {
status = "okay"; status = "okay";
}; };
&wake_on_bt { &usb_host0_ohci {
gpios = <&gpio1 2 GPIO_ACTIVE_LOW>; #address-cells = <1>;
#size-cells = <0>;
qca_bt: bluetooth@1 {
compatible = "usbcf3,e300", "usb4ca,301a";
reg = <1>;
pinctrl-names = "default";
pinctrl-0 = <&bt_host_wake_l>;
interrupt-parent = <&gpio1>;
interrupts = <2 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "wakeup";
};
}; };
/* PINCTRL OVERRIDES */ /* PINCTRL OVERRIDES */
...@@ -455,7 +467,7 @@ &bl_en { ...@@ -455,7 +467,7 @@ &bl_en {
}; };
&bt_host_wake_l { &bt_host_wake_l {
rockchip,pins = <1 2 RK_FUNC_GPIO &pcfg_pull_up>; rockchip,pins = <1 2 RK_FUNC_GPIO &pcfg_pull_none>;
}; };
&ec_ap_int_l { &ec_ap_int_l {
......
...@@ -269,19 +269,6 @@ ap_rtc_clk: ap-rtc-clk { ...@@ -269,19 +269,6 @@ ap_rtc_clk: ap-rtc-clk {
#clock-cells = <0>; #clock-cells = <0>;
}; };
gpio_keys: gpio-keys {
compatible = "gpio-keys";
pinctrl-names = "default";
pinctrl-0 = <&bt_host_wake_l>;
wake_on_bt: wake-on-bt {
label = "Wake-on-Bluetooth";
gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
linux,code = <KEY_WAKEUP>;
wakeup-source;
};
};
max98357a: max98357a { max98357a: max98357a {
compatible = "maxim,max98357a"; compatible = "maxim,max98357a";
pinctrl-names = "default"; pinctrl-names = "default";
......
...@@ -12,11 +12,15 @@ ...@@ -12,11 +12,15 @@
#include <linux/atomic.h> #include <linux/atomic.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/firmware.h> #include <linux/firmware.h>
#include <linux/gpio/consumer.h>
#include <linux/iopoll.h> #include <linux/iopoll.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_device.h>
#include <linux/pinctrl/consumer.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/regulator/consumer.h>
#include <linux/serdev.h> #include <linux/serdev.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
...@@ -25,18 +29,26 @@ ...@@ -25,18 +29,26 @@
#include "h4_recv.h" #include "h4_recv.h"
#define VERSION "0.1" #define VERSION "0.2"
#define FIRMWARE_MT7622 "mediatek/mt7622pr2h.bin" #define FIRMWARE_MT7622 "mediatek/mt7622pr2h.bin"
#define FIRMWARE_MT7663 "mediatek/mt7663pr2h.bin"
#define FIRMWARE_MT7668 "mediatek/mt7668pr2h.bin"
#define MTK_STP_TLR_SIZE 2 #define MTK_STP_TLR_SIZE 2
#define BTMTKUART_TX_STATE_ACTIVE 1 #define BTMTKUART_TX_STATE_ACTIVE 1
#define BTMTKUART_TX_STATE_WAKEUP 2 #define BTMTKUART_TX_STATE_WAKEUP 2
#define BTMTKUART_TX_WAIT_VND_EVT 3 #define BTMTKUART_TX_WAIT_VND_EVT 3
#define BTMTKUART_REQUIRED_WAKEUP 4
#define BTMTKUART_FLAG_STANDALONE_HW BIT(0)
enum { enum {
MTK_WMT_PATCH_DWNLD = 0x1, MTK_WMT_PATCH_DWNLD = 0x1,
MTK_WMT_TEST = 0x2,
MTK_WMT_WAKEUP = 0x3,
MTK_WMT_HIF = 0x4,
MTK_WMT_FUNC_CTRL = 0x6, MTK_WMT_FUNC_CTRL = 0x6,
MTK_WMT_RST = 0x7, MTK_WMT_RST = 0x7,
MTK_WMT_SEMAPHORE = 0x17, MTK_WMT_SEMAPHORE = 0x17,
...@@ -57,6 +69,11 @@ struct mtk_stp_hdr { ...@@ -57,6 +69,11 @@ struct mtk_stp_hdr {
u8 cs; u8 cs;
} __packed; } __packed;
struct btmtkuart_data {
unsigned int flags;
const char *fwname;
};
struct mtk_wmt_hdr { struct mtk_wmt_hdr {
u8 dir; u8 dir;
u8 op; u8 op;
...@@ -100,6 +117,14 @@ struct btmtkuart_dev { ...@@ -100,6 +117,14 @@ struct btmtkuart_dev {
struct serdev_device *serdev; struct serdev_device *serdev;
struct clk *clk; struct clk *clk;
struct regulator *vcc;
struct gpio_desc *reset;
struct pinctrl *pinctrl;
struct pinctrl_state *pins_runtime;
struct pinctrl_state *pins_boot;
speed_t desired_speed;
speed_t curr_speed;
struct work_struct tx_work; struct work_struct tx_work;
unsigned long tx_state; unsigned long tx_state;
struct sk_buff_head txq; struct sk_buff_head txq;
...@@ -110,8 +135,15 @@ struct btmtkuart_dev { ...@@ -110,8 +135,15 @@ struct btmtkuart_dev {
u8 stp_pad[6]; u8 stp_pad[6];
u8 stp_cursor; u8 stp_cursor;
u16 stp_dlen; u16 stp_dlen;
const struct btmtkuart_data *data;
}; };
#define btmtkuart_is_standalone(bdev) \
((bdev)->data->flags & BTMTKUART_FLAG_STANDALONE_HW)
#define btmtkuart_is_builtin_soc(bdev) \
!((bdev)->data->flags & BTMTKUART_FLAG_STANDALONE_HW)
static int mtk_hci_wmt_sync(struct hci_dev *hdev, static int mtk_hci_wmt_sync(struct hci_dev *hdev,
struct btmtk_hci_wmt_params *wmt_params) struct btmtk_hci_wmt_params *wmt_params)
{ {
...@@ -202,7 +234,7 @@ static int mtk_hci_wmt_sync(struct hci_dev *hdev, ...@@ -202,7 +234,7 @@ static int mtk_hci_wmt_sync(struct hci_dev *hdev,
return err; return err;
} }
static int mtk_setup_fw(struct hci_dev *hdev) static int mtk_setup_firmware(struct hci_dev *hdev, const char *fwname)
{ {
struct btmtk_hci_wmt_params wmt_params; struct btmtk_hci_wmt_params wmt_params;
const struct firmware *fw; const struct firmware *fw;
...@@ -211,7 +243,7 @@ static int mtk_setup_fw(struct hci_dev *hdev) ...@@ -211,7 +243,7 @@ static int mtk_setup_fw(struct hci_dev *hdev)
int err, dlen; int err, dlen;
u8 flag; u8 flag;
err = request_firmware(&fw, FIRMWARE_MT7622, &hdev->dev); err = request_firmware(&fw, fwname, &hdev->dev);
if (err < 0) { if (err < 0) {
bt_dev_err(hdev, "Failed to load firmware file (%d)", err); bt_dev_err(hdev, "Failed to load firmware file (%d)", err);
return err; return err;
...@@ -523,6 +555,23 @@ static int btmtkuart_open(struct hci_dev *hdev) ...@@ -523,6 +555,23 @@ static int btmtkuart_open(struct hci_dev *hdev)
goto err_open; goto err_open;
} }
if (btmtkuart_is_standalone(bdev)) {
if (bdev->curr_speed != bdev->desired_speed)
err = serdev_device_set_baudrate(bdev->serdev,
115200);
else
err = serdev_device_set_baudrate(bdev->serdev,
bdev->desired_speed);
if (err < 0) {
bt_dev_err(hdev, "Unable to set baudrate UART device %s",
dev_name(&bdev->serdev->dev));
goto err_serdev_close;
}
serdev_device_set_flow_control(bdev->serdev, false);
}
bdev->stp_cursor = 2; bdev->stp_cursor = 2;
bdev->stp_dlen = 0; bdev->stp_dlen = 0;
...@@ -546,6 +595,8 @@ static int btmtkuart_open(struct hci_dev *hdev) ...@@ -546,6 +595,8 @@ static int btmtkuart_open(struct hci_dev *hdev)
pm_runtime_put_sync(dev); pm_runtime_put_sync(dev);
err_disable_rpm: err_disable_rpm:
pm_runtime_disable(dev); pm_runtime_disable(dev);
err_serdev_close:
serdev_device_close(bdev->serdev);
err_open: err_open:
return err; return err;
} }
...@@ -606,8 +657,74 @@ static int btmtkuart_func_query(struct hci_dev *hdev) ...@@ -606,8 +657,74 @@ static int btmtkuart_func_query(struct hci_dev *hdev)
return status; return status;
} }
static int btmtkuart_change_baudrate(struct hci_dev *hdev)
{
struct btmtkuart_dev *bdev = hci_get_drvdata(hdev);
struct btmtk_hci_wmt_params wmt_params;
u32 baudrate;
u8 param;
int err;
/* Indicate the device to enter the probe state the host is
* ready to change a new baudrate.
*/
baudrate = cpu_to_le32(bdev->desired_speed);
wmt_params.op = MTK_WMT_HIF;
wmt_params.flag = 1;
wmt_params.dlen = 4;
wmt_params.data = &baudrate;
wmt_params.status = NULL;
err = mtk_hci_wmt_sync(hdev, &wmt_params);
if (err < 0) {
bt_dev_err(hdev, "Failed to device baudrate (%d)", err);
return err;
}
err = serdev_device_set_baudrate(bdev->serdev,
bdev->desired_speed);
if (err < 0) {
bt_dev_err(hdev, "Failed to set up host baudrate (%d)",
err);
return err;
}
serdev_device_set_flow_control(bdev->serdev, false);
/* Send a dummy byte 0xff to activate the new baudrate */
param = 0xff;
err = serdev_device_write(bdev->serdev, &param, sizeof(param),
MAX_SCHEDULE_TIMEOUT);
if (err < 0 || err < sizeof(param))
return err;
serdev_device_wait_until_sent(bdev->serdev, 0);
/* Wait some time for the device changing baudrate done */
usleep_range(20000, 22000);
/* Test the new baudrate */
wmt_params.op = MTK_WMT_TEST;
wmt_params.flag = 7;
wmt_params.dlen = 0;
wmt_params.data = NULL;
wmt_params.status = NULL;
err = mtk_hci_wmt_sync(hdev, &wmt_params);
if (err < 0) {
bt_dev_err(hdev, "Failed to test new baudrate (%d)",
err);
return err;
}
bdev->curr_speed = bdev->desired_speed;
return 0;
}
static int btmtkuart_setup(struct hci_dev *hdev) static int btmtkuart_setup(struct hci_dev *hdev)
{ {
struct btmtkuart_dev *bdev = hci_get_drvdata(hdev);
struct btmtk_hci_wmt_params wmt_params; struct btmtk_hci_wmt_params wmt_params;
ktime_t calltime, delta, rettime; ktime_t calltime, delta, rettime;
struct btmtk_tci_sleep tci_sleep; struct btmtk_tci_sleep tci_sleep;
...@@ -618,6 +735,28 @@ static int btmtkuart_setup(struct hci_dev *hdev) ...@@ -618,6 +735,28 @@ static int btmtkuart_setup(struct hci_dev *hdev)
calltime = ktime_get(); calltime = ktime_get();
/* Wakeup MCUSYS is required for certain devices before we start to
* do any setups.
*/
if (test_bit(BTMTKUART_REQUIRED_WAKEUP, &bdev->tx_state)) {
wmt_params.op = MTK_WMT_WAKEUP;
wmt_params.flag = 3;
wmt_params.dlen = 0;
wmt_params.data = NULL;
wmt_params.status = NULL;
err = mtk_hci_wmt_sync(hdev, &wmt_params);
if (err < 0) {
bt_dev_err(hdev, "Failed to wakeup the chip (%d)", err);
return err;
}
clear_bit(BTMTKUART_REQUIRED_WAKEUP, &bdev->tx_state);
}
if (btmtkuart_is_standalone(bdev))
btmtkuart_change_baudrate(hdev);
/* Query whether the firmware is already download */ /* Query whether the firmware is already download */
wmt_params.op = MTK_WMT_SEMAPHORE; wmt_params.op = MTK_WMT_SEMAPHORE;
wmt_params.flag = 1; wmt_params.flag = 1;
...@@ -637,7 +776,7 @@ static int btmtkuart_setup(struct hci_dev *hdev) ...@@ -637,7 +776,7 @@ static int btmtkuart_setup(struct hci_dev *hdev)
} }
/* Setup a firmware which the device definitely requires */ /* Setup a firmware which the device definitely requires */
err = mtk_setup_fw(hdev); err = mtk_setup_firmware(hdev, bdev->data->fwname);
if (err < 0) if (err < 0)
return err; return err;
...@@ -754,24 +893,82 @@ static int btmtkuart_send_frame(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -754,24 +893,82 @@ static int btmtkuart_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
return 0; return 0;
} }
static int btmtkuart_parse_dt(struct serdev_device *serdev)
{
struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev);
struct device_node *node = serdev->dev.of_node;
u32 speed = 921600;
int err;
if (btmtkuart_is_standalone(bdev)) {
of_property_read_u32(node, "current-speed", &speed);
bdev->desired_speed = speed;
bdev->vcc = devm_regulator_get(&serdev->dev, "vcc");
if (IS_ERR(bdev->vcc)) {
err = PTR_ERR(bdev->vcc);
return err;
}
bdev->pinctrl = devm_pinctrl_get(&serdev->dev);
if (IS_ERR(bdev->pinctrl)) {
err = PTR_ERR(bdev->pinctrl);
return err;
}
bdev->pins_boot = pinctrl_lookup_state(bdev->pinctrl,
"default");
if (IS_ERR(bdev->pins_boot)) {
err = PTR_ERR(bdev->pins_boot);
return err;
}
bdev->pins_runtime = pinctrl_lookup_state(bdev->pinctrl,
"runtime");
if (IS_ERR(bdev->pins_runtime)) {
err = PTR_ERR(bdev->pins_runtime);
return err;
}
bdev->reset = devm_gpiod_get_optional(&serdev->dev, "reset",
GPIOD_OUT_LOW);
if (IS_ERR(bdev->reset)) {
err = PTR_ERR(bdev->reset);
return err;
}
} else if (btmtkuart_is_builtin_soc(bdev)) {
bdev->clk = devm_clk_get(&serdev->dev, "ref");
if (IS_ERR(bdev->clk))
return PTR_ERR(bdev->clk);
}
return 0;
}
static int btmtkuart_probe(struct serdev_device *serdev) static int btmtkuart_probe(struct serdev_device *serdev)
{ {
struct btmtkuart_dev *bdev; struct btmtkuart_dev *bdev;
struct hci_dev *hdev; struct hci_dev *hdev;
int err;
bdev = devm_kzalloc(&serdev->dev, sizeof(*bdev), GFP_KERNEL); bdev = devm_kzalloc(&serdev->dev, sizeof(*bdev), GFP_KERNEL);
if (!bdev) if (!bdev)
return -ENOMEM; return -ENOMEM;
bdev->clk = devm_clk_get(&serdev->dev, "ref"); bdev->data = of_device_get_match_data(&serdev->dev);
if (IS_ERR(bdev->clk)) if (!bdev->data)
return PTR_ERR(bdev->clk); return -ENODEV;
bdev->serdev = serdev; bdev->serdev = serdev;
serdev_device_set_drvdata(serdev, bdev); serdev_device_set_drvdata(serdev, bdev);
serdev_device_set_client_ops(serdev, &btmtkuart_client_ops); serdev_device_set_client_ops(serdev, &btmtkuart_client_ops);
err = btmtkuart_parse_dt(serdev);
if (err < 0)
return err;
INIT_WORK(&bdev->tx_work, btmtkuart_tx_work); INIT_WORK(&bdev->tx_work, btmtkuart_tx_work);
skb_queue_head_init(&bdev->txq); skb_queue_head_init(&bdev->txq);
...@@ -798,13 +995,54 @@ static int btmtkuart_probe(struct serdev_device *serdev) ...@@ -798,13 +995,54 @@ static int btmtkuart_probe(struct serdev_device *serdev)
hdev->manufacturer = 70; hdev->manufacturer = 70;
set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks); set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
if (hci_register_dev(hdev) < 0) { if (btmtkuart_is_standalone(bdev)) {
/* Switch to the specific pin state for the booting requires */
pinctrl_select_state(bdev->pinctrl, bdev->pins_boot);
/* Power on */
err = regulator_enable(bdev->vcc);
if (err < 0)
return err;
/* Reset if the reset-gpios is available otherwise the board
* -level design should be guaranteed.
*/
if (bdev->reset) {
gpiod_set_value_cansleep(bdev->reset, 1);
usleep_range(1000, 2000);
gpiod_set_value_cansleep(bdev->reset, 0);
}
/* Wait some time until device got ready and switch to the pin
* mode the device requires for UART transfers.
*/
msleep(50);
pinctrl_select_state(bdev->pinctrl, bdev->pins_runtime);
/* A standalone device doesn't depends on power domain on SoC,
* so mark it as no callbacks.
*/
pm_runtime_no_callbacks(&serdev->dev);
set_bit(BTMTKUART_REQUIRED_WAKEUP, &bdev->tx_state);
}
err = hci_register_dev(hdev);
if (err < 0) {
dev_err(&serdev->dev, "Can't register HCI device\n"); dev_err(&serdev->dev, "Can't register HCI device\n");
hci_free_dev(hdev); hci_free_dev(hdev);
return -ENODEV; goto err_regulator_disable;
} }
return 0; return 0;
err_regulator_disable:
if (btmtkuart_is_standalone(bdev)) {
pinctrl_select_state(bdev->pinctrl, bdev->pins_boot);
regulator_disable(bdev->vcc);
}
return err;
} }
static void btmtkuart_remove(struct serdev_device *serdev) static void btmtkuart_remove(struct serdev_device *serdev)
...@@ -812,13 +1050,34 @@ static void btmtkuart_remove(struct serdev_device *serdev) ...@@ -812,13 +1050,34 @@ static void btmtkuart_remove(struct serdev_device *serdev)
struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev); struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev);
struct hci_dev *hdev = bdev->hdev; struct hci_dev *hdev = bdev->hdev;
if (btmtkuart_is_standalone(bdev)) {
pinctrl_select_state(bdev->pinctrl, bdev->pins_boot);
regulator_disable(bdev->vcc);
}
hci_unregister_dev(hdev); hci_unregister_dev(hdev);
hci_free_dev(hdev); hci_free_dev(hdev);
} }
static const struct btmtkuart_data mt7622_data = {
.fwname = FIRMWARE_MT7622,
};
static const struct btmtkuart_data mt7663_data = {
.flags = BTMTKUART_FLAG_STANDALONE_HW,
.fwname = FIRMWARE_MT7663,
};
static const struct btmtkuart_data mt7668_data = {
.flags = BTMTKUART_FLAG_STANDALONE_HW,
.fwname = FIRMWARE_MT7668,
};
#ifdef CONFIG_OF #ifdef CONFIG_OF
static const struct of_device_id mtk_of_match_table[] = { static const struct of_device_id mtk_of_match_table[] = {
{ .compatible = "mediatek,mt7622-bluetooth"}, { .compatible = "mediatek,mt7622-bluetooth", .data = &mt7622_data},
{ .compatible = "mediatek,mt7663u-bluetooth", .data = &mt7663_data},
{ .compatible = "mediatek,mt7668u-bluetooth", .data = &mt7668_data},
{ } { }
}; };
MODULE_DEVICE_TABLE(of, mtk_of_match_table); MODULE_DEVICE_TABLE(of, mtk_of_match_table);
...@@ -840,3 +1099,5 @@ MODULE_DESCRIPTION("MediaTek Bluetooth Serial driver ver " VERSION); ...@@ -840,3 +1099,5 @@ MODULE_DESCRIPTION("MediaTek Bluetooth Serial driver ver " VERSION);
MODULE_VERSION(VERSION); MODULE_VERSION(VERSION);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_FIRMWARE(FIRMWARE_MT7622); MODULE_FIRMWARE(FIRMWARE_MT7622);
MODULE_FIRMWARE(FIRMWARE_MT7663);
MODULE_FIRMWARE(FIRMWARE_MT7668);
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
struct btqcomsmd { struct btqcomsmd {
struct hci_dev *hdev; struct hci_dev *hdev;
bdaddr_t bdaddr;
struct rpmsg_endpoint *acl_channel; struct rpmsg_endpoint *acl_channel;
struct rpmsg_endpoint *cmd_channel; struct rpmsg_endpoint *cmd_channel;
}; };
...@@ -116,32 +115,17 @@ static int btqcomsmd_close(struct hci_dev *hdev) ...@@ -116,32 +115,17 @@ static int btqcomsmd_close(struct hci_dev *hdev)
static int btqcomsmd_setup(struct hci_dev *hdev) static int btqcomsmd_setup(struct hci_dev *hdev)
{ {
struct btqcomsmd *btq = hci_get_drvdata(hdev);
struct sk_buff *skb; struct sk_buff *skb;
int err;
skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
if (IS_ERR(skb)) if (IS_ERR(skb))
return PTR_ERR(skb); return PTR_ERR(skb);
kfree_skb(skb); kfree_skb(skb);
/* Devices do not have persistent storage for BD address. If no /* Devices do not have persistent storage for BD address. Retrieve
* BD address has been retrieved during probe, mark the device * it from the firmware node property.
* as having an invalid BD address.
*/
if (!bacmp(&btq->bdaddr, BDADDR_ANY)) {
set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
return 0;
}
/* When setting a configured BD address fails, mark the device
* as having an invalid BD address.
*/ */
err = qca_set_bdaddr_rome(hdev, &btq->bdaddr); set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks);
if (err) {
set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
return 0;
}
return 0; return 0;
} }
...@@ -169,15 +153,6 @@ static int btqcomsmd_probe(struct platform_device *pdev) ...@@ -169,15 +153,6 @@ static int btqcomsmd_probe(struct platform_device *pdev)
if (IS_ERR(btq->cmd_channel)) if (IS_ERR(btq->cmd_channel))
return PTR_ERR(btq->cmd_channel); return PTR_ERR(btq->cmd_channel);
/* The local-bd-address property is usually injected by the
* bootloader which has access to the allocated BD address.
*/
if (!of_property_read_u8_array(pdev->dev.of_node, "local-bd-address",
(u8 *)&btq->bdaddr, sizeof(bdaddr_t))) {
dev_info(&pdev->dev, "BD address %pMR retrieved from device-tree",
&btq->bdaddr);
}
hdev = hci_alloc_dev(); hdev = hci_alloc_dev();
if (!hdev) if (!hdev)
return -ENOMEM; return -ENOMEM;
......
...@@ -2917,6 +2917,8 @@ static irqreturn_t btusb_oob_wake_handler(int irq, void *priv) ...@@ -2917,6 +2917,8 @@ static irqreturn_t btusb_oob_wake_handler(int irq, void *priv)
static const struct of_device_id btusb_match_table[] = { static const struct of_device_id btusb_match_table[] = {
{ .compatible = "usb1286,204e" }, { .compatible = "usb1286,204e" },
{ .compatible = "usbcf3,e300" }, /* QCA6174A */
{ .compatible = "usb4ca,301a" }, /* QCA6174A (Lite-On) */
{ } { }
}; };
MODULE_DEVICE_TABLE(of, btusb_match_table); MODULE_DEVICE_TABLE(of, btusb_match_table);
......
...@@ -696,14 +696,13 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id) ...@@ -696,14 +696,13 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id)
return -EPROTONOSUPPORT; return -EPROTONOSUPPORT;
hu->proto = p; hu->proto = p;
set_bit(HCI_UART_PROTO_READY, &hu->flags);
err = hci_uart_register_dev(hu); err = hci_uart_register_dev(hu);
if (err) { if (err) {
clear_bit(HCI_UART_PROTO_READY, &hu->flags);
return err; return err;
} }
set_bit(HCI_UART_PROTO_READY, &hu->flags);
return 0; return 0;
} }
......
...@@ -59,8 +59,7 @@ ...@@ -59,8 +59,7 @@
#define IBS_WAKE_RETRANS_TIMEOUT_MS 100 #define IBS_WAKE_RETRANS_TIMEOUT_MS 100
#define IBS_TX_IDLE_TIMEOUT_MS 2000 #define IBS_TX_IDLE_TIMEOUT_MS 2000
#define BAUDRATE_SETTLE_TIMEOUT_MS 300 #define CMD_TRANS_TIMEOUT_MS 100
#define POWER_PULSE_TRANS_TIMEOUT_MS 100
/* susclk rate */ /* susclk rate */
#define SUSCLK_RATE_32KHZ 32768 #define SUSCLK_RATE_32KHZ 32768
...@@ -964,6 +963,7 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate) ...@@ -964,6 +963,7 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
{ {
struct hci_uart *hu = hci_get_drvdata(hdev); struct hci_uart *hu = hci_get_drvdata(hdev);
struct qca_data *qca = hu->priv; struct qca_data *qca = hu->priv;
struct qca_serdev *qcadev;
struct sk_buff *skb; struct sk_buff *skb;
u8 cmd[] = { 0x01, 0x48, 0xFC, 0x01, 0x00 }; u8 cmd[] = { 0x01, 0x48, 0xFC, 0x01, 0x00 };
...@@ -985,13 +985,21 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate) ...@@ -985,13 +985,21 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
skb_queue_tail(&qca->txq, skb); skb_queue_tail(&qca->txq, skb);
hci_uart_tx_wakeup(hu); hci_uart_tx_wakeup(hu);
/* wait 300ms to change new baudrate on controller side qcadev = serdev_device_get_drvdata(hu->serdev);
* controller will come back after they receive this HCI command
* then host can communicate with new baudrate to controller /* Wait for the baudrate change request to be sent */
*/
set_current_state(TASK_UNINTERRUPTIBLE); while (!skb_queue_empty(&qca->txq))
schedule_timeout(msecs_to_jiffies(BAUDRATE_SETTLE_TIMEOUT_MS)); usleep_range(100, 200);
set_current_state(TASK_RUNNING);
serdev_device_wait_until_sent(hu->serdev,
msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS));
/* Give the controller time to process the request */
if (qcadev->btsoc_type == QCA_WCN3990)
msleep(10);
else
msleep(300);
return 0; return 0;
} }
...@@ -1004,10 +1012,11 @@ static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed) ...@@ -1004,10 +1012,11 @@ static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed)
hci_uart_set_baudrate(hu, speed); hci_uart_set_baudrate(hu, speed);
} }
static int qca_send_power_pulse(struct hci_uart *hu, u8 cmd) static int qca_send_power_pulse(struct hci_uart *hu, bool on)
{ {
int ret; int ret;
int timeout = msecs_to_jiffies(POWER_PULSE_TRANS_TIMEOUT_MS); int timeout = msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS);
u8 cmd = on ? QCA_WCN3990_POWERON_PULSE : QCA_WCN3990_POWEROFF_PULSE;
/* These power pulses are single byte command which are sent /* These power pulses are single byte command which are sent
* at required baudrate to wcn3990. On wcn3990, we have an external * at required baudrate to wcn3990. On wcn3990, we have an external
...@@ -1030,11 +1039,14 @@ static int qca_send_power_pulse(struct hci_uart *hu, u8 cmd) ...@@ -1030,11 +1039,14 @@ static int qca_send_power_pulse(struct hci_uart *hu, u8 cmd)
} }
serdev_device_wait_until_sent(hu->serdev, timeout); serdev_device_wait_until_sent(hu->serdev, timeout);
/* Wait for 100 uS for SoC to settle down */
usleep_range(100, 200);
hci_uart_set_flow_control(hu, false); hci_uart_set_flow_control(hu, false);
/* Give to controller time to boot/shutdown */
if (on)
msleep(100);
else
msleep(10);
return 0; return 0;
} }
...@@ -1138,18 +1150,15 @@ static int qca_wcn3990_init(struct hci_uart *hu) ...@@ -1138,18 +1150,15 @@ static int qca_wcn3990_init(struct hci_uart *hu)
/* Forcefully enable wcn3990 to enter in to boot mode. */ /* Forcefully enable wcn3990 to enter in to boot mode. */
host_set_baudrate(hu, 2400); host_set_baudrate(hu, 2400);
ret = qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE); ret = qca_send_power_pulse(hu, false);
if (ret) if (ret)
return ret; return ret;
qca_set_speed(hu, QCA_INIT_SPEED); qca_set_speed(hu, QCA_INIT_SPEED);
ret = qca_send_power_pulse(hu, QCA_WCN3990_POWERON_PULSE); ret = qca_send_power_pulse(hu, true);
if (ret) if (ret)
return ret; return ret;
/* Wait for 100 ms for SoC to boot */
msleep(100);
/* Now the device is in ready state to communicate with host. /* Now the device is in ready state to communicate with host.
* To sync host with device we need to reopen port. * To sync host with device we need to reopen port.
* Without this, we will have RTS and CTS synchronization * Without this, we will have RTS and CTS synchronization
...@@ -1192,6 +1201,7 @@ static int qca_setup(struct hci_uart *hu) ...@@ -1192,6 +1201,7 @@ static int qca_setup(struct hci_uart *hu)
* setup for every hci up. * setup for every hci up.
*/ */
set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks); set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks);
hu->hdev->shutdown = qca_power_off; hu->hdev->shutdown = qca_power_off;
ret = qca_wcn3990_init(hu); ret = qca_wcn3990_init(hu);
if (ret) if (ret)
...@@ -1289,7 +1299,7 @@ static void qca_power_shutdown(struct hci_uart *hu) ...@@ -1289,7 +1299,7 @@ static void qca_power_shutdown(struct hci_uart *hu)
spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
host_set_baudrate(hu, 2400); host_set_baudrate(hu, 2400);
qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE); qca_send_power_pulse(hu, false);
qca_power_setup(hu, false); qca_power_setup(hu, false);
} }
......
...@@ -158,6 +158,18 @@ enum { ...@@ -158,6 +158,18 @@ enum {
*/ */
HCI_QUIRK_INVALID_BDADDR, HCI_QUIRK_INVALID_BDADDR,
/* When this quirk is set, the public Bluetooth address
* initially reported by HCI Read BD Address command
* is considered invalid. The public BD Address can be
* specified in the fwnode property 'local-bd-address'.
* If this property does not exist or is invalid controller
* configuration is required before this device can be used.
*
* This quirk can be set before hci_register_dev is called or
* during the hdev->setup vendor callback.
*/
HCI_QUIRK_USE_BDADDR_PROPERTY,
/* When this quirk is set, the duplicate filtering during /* When this quirk is set, the duplicate filtering during
* scanning is based on Bluetooth devices addresses. To allow * scanning is based on Bluetooth devices addresses. To allow
* RSSI based updates, restart scanning if needed. * RSSI based updates, restart scanning if needed.
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <linux/rfkill.h> #include <linux/rfkill.h>
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/crypto.h> #include <linux/crypto.h>
#include <linux/property.h>
#include <asm/unaligned.h> #include <asm/unaligned.h>
#include <net/bluetooth/bluetooth.h> #include <net/bluetooth/bluetooth.h>
...@@ -1355,6 +1356,32 @@ int hci_inquiry(void __user *arg) ...@@ -1355,6 +1356,32 @@ int hci_inquiry(void __user *arg)
return err; return err;
} }
/**
* hci_dev_get_bd_addr_from_property - Get the Bluetooth Device Address
* (BD_ADDR) for a HCI device from
* a firmware node property.
* @hdev: The HCI device
*
* Search the firmware node for 'local-bd-address'.
*
* All-zero BD addresses are rejected, because those could be properties
* that exist in the firmware tables, but were not updated by the firmware. For
* example, the DTS could define 'local-bd-address', with zero BD addresses.
*/
static void hci_dev_get_bd_addr_from_property(struct hci_dev *hdev)
{
struct fwnode_handle *fwnode = dev_fwnode(hdev->dev.parent);
bdaddr_t ba;
int ret;
ret = fwnode_property_read_u8_array(fwnode, "local-bd-address",
(u8 *)&ba, sizeof(ba));
if (ret < 0 || !bacmp(&ba, BDADDR_ANY))
return;
bacpy(&hdev->public_addr, &ba);
}
static int hci_dev_do_open(struct hci_dev *hdev) static int hci_dev_do_open(struct hci_dev *hdev)
{ {
int ret = 0; int ret = 0;
...@@ -1422,6 +1449,22 @@ static int hci_dev_do_open(struct hci_dev *hdev) ...@@ -1422,6 +1449,22 @@ static int hci_dev_do_open(struct hci_dev *hdev)
if (hdev->setup) if (hdev->setup)
ret = hdev->setup(hdev); ret = hdev->setup(hdev);
if (ret)
goto setup_failed;
if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) {
if (!bacmp(&hdev->public_addr, BDADDR_ANY))
hci_dev_get_bd_addr_from_property(hdev);
if (bacmp(&hdev->public_addr, BDADDR_ANY) &&
hdev->set_bdaddr)
ret = hdev->set_bdaddr(hdev,
&hdev->public_addr);
else
ret = -EADDRNOTAVAIL;
}
setup_failed:
/* The transport driver can set these quirks before /* The transport driver can set these quirks before
* creating the HCI device or in its setup callback. * creating the HCI device or in its setup callback.
* *
......
...@@ -474,7 +474,6 @@ static int read_ext_index_list(struct sock *sk, struct hci_dev *hdev, ...@@ -474,7 +474,6 @@ static int read_ext_index_list(struct sock *sk, struct hci_dev *hdev,
{ {
struct mgmt_rp_read_ext_index_list *rp; struct mgmt_rp_read_ext_index_list *rp;
struct hci_dev *d; struct hci_dev *d;
size_t rp_len;
u16 count; u16 count;
int err; int err;
...@@ -488,8 +487,7 @@ static int read_ext_index_list(struct sock *sk, struct hci_dev *hdev, ...@@ -488,8 +487,7 @@ static int read_ext_index_list(struct sock *sk, struct hci_dev *hdev,
count++; count++;
} }
rp_len = sizeof(*rp) + (sizeof(rp->entry[0]) * count); rp = kmalloc(struct_size(rp, entry, count), GFP_ATOMIC);
rp = kmalloc(rp_len, GFP_ATOMIC);
if (!rp) { if (!rp) {
read_unlock(&hci_dev_list_lock); read_unlock(&hci_dev_list_lock);
return -ENOMEM; return -ENOMEM;
...@@ -525,7 +523,6 @@ static int read_ext_index_list(struct sock *sk, struct hci_dev *hdev, ...@@ -525,7 +523,6 @@ static int read_ext_index_list(struct sock *sk, struct hci_dev *hdev,
} }
rp->num_controllers = cpu_to_le16(count); rp->num_controllers = cpu_to_le16(count);
rp_len = sizeof(*rp) + (sizeof(rp->entry[0]) * count);
read_unlock(&hci_dev_list_lock); read_unlock(&hci_dev_list_lock);
...@@ -538,7 +535,8 @@ static int read_ext_index_list(struct sock *sk, struct hci_dev *hdev, ...@@ -538,7 +535,8 @@ static int read_ext_index_list(struct sock *sk, struct hci_dev *hdev,
hci_sock_clear_flag(sk, HCI_MGMT_UNCONF_INDEX_EVENTS); hci_sock_clear_flag(sk, HCI_MGMT_UNCONF_INDEX_EVENTS);
err = mgmt_cmd_complete(sk, MGMT_INDEX_NONE, err = mgmt_cmd_complete(sk, MGMT_INDEX_NONE,
MGMT_OP_READ_EXT_INDEX_LIST, 0, rp, rp_len); MGMT_OP_READ_EXT_INDEX_LIST, 0, rp,
struct_size(rp, entry, count));
kfree(rp); kfree(rp);
...@@ -551,7 +549,8 @@ static bool is_configured(struct hci_dev *hdev) ...@@ -551,7 +549,8 @@ static bool is_configured(struct hci_dev *hdev)
!hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED))
return false; return false;
if (test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) && if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) ||
test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) &&
!bacmp(&hdev->public_addr, BDADDR_ANY)) !bacmp(&hdev->public_addr, BDADDR_ANY))
return false; return false;
...@@ -566,7 +565,8 @@ static __le32 get_missing_options(struct hci_dev *hdev) ...@@ -566,7 +565,8 @@ static __le32 get_missing_options(struct hci_dev *hdev)
!hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED))
options |= MGMT_OPTION_EXTERNAL_CONFIG; options |= MGMT_OPTION_EXTERNAL_CONFIG;
if (test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) && if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) ||
test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) &&
!bacmp(&hdev->public_addr, BDADDR_ANY)) !bacmp(&hdev->public_addr, BDADDR_ANY))
options |= MGMT_OPTION_PUBLIC_ADDRESS; options |= MGMT_OPTION_PUBLIC_ADDRESS;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment