Commit Graph

23 Commits

Author SHA1 Message Date
Bastien Nocera f09ae4ba56 Bluetooth: btmtk: move btusb_mtk_hci_wmt_sync to btmtk.c
JIRA: https://issues.redhat.com/browse/RHEL-61734

commit d019930b0049fc2648a6b279893d8ad330596e81
Author: Chris Lu <chris.lu@mediatek.com>
Date:   Thu Jul 4 14:01:13 2024 +0800

    Bluetooth: btmtk: move btusb_mtk_hci_wmt_sync to btmtk.c

    Move btusb_mtk_hci_wmt_sync from btusb.c to btmtk.c which holds
    vendor specific stuff and would make btusb.c clean.

    Add usb.h header to btmtksdio.c/btmtkuart.c for usb related element
    defined in btmtk.h

    Signed-off-by: Sean Wang <sean.wang@mediatek.com>
    Signed-off-by: Chris Lu <chris.lu@mediatek.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-12-11 15:25:15 +01:00
David Marlin 5364e3f856 Bluetooth: btmtkuart: fix recv_buf() return value
JIRA: https://issues.redhat.com/browse/RHEL-30099

commit 64057f051f20c2a2184b9db7f8037d928d68a4f4
Author: Francesco Dolcini <francesco.dolcini@toradex.com>
Date:   Mon Dec 11 17:40:19 2023 +0100

    Bluetooth: btmtkuart: fix recv_buf() return value

    Serdev recv_buf() callback is supposed to return the amount of bytes
    consumed, therefore an int in between 0 and count.

    Do not return negative number in case of issue, just print an error and
    return count. This fixes a WARN in ttyport_receive_buf().

    Link: https://lore.kernel.org/all/087be419-ec6b-47ad-851a-5e1e3ea5cfcc@kernel.org/
    Fixes: 7237c4c9ec ("Bluetooth: mediatek: Add protocol support for MediaTek serial devices")
    Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: David Marlin <dmarlin@redhat.com>
2024-05-22 21:35:10 -05:00
David Marlin d8343e747a bluetooth: Explicitly include correct DT includes
JIRA: https://issues.redhat.com/browse/RHEL-30099

commit e15f44fb9cb26168a1171a3e8f7f44d11a2727b8
Author: Rob Herring <robh@kernel.org>
Date:   Fri Jul 14 11:40:57 2023 -0600

    bluetooth: Explicitly include correct DT includes

    The DT of_device.h and of_platform.h date back to the separate
    of_platform_bus_type before it as merged into the regular platform bus.
    As part of that merge prepping Arm DT support 13 years ago, they
    "temporarily" include each other. They also include platform_device.h
    and of.h. As a result, there's a pretty much random mix of those include
    files used throughout the tree. In order to detangle these headers and
    replace the implicit includes with struct declarations, users need to
    explicitly include the correct includes.

    Signed-off-by: Rob Herring <robh@kernel.org>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: David Marlin <dmarlin@redhat.com>
2024-05-22 21:35:05 -05:00
Bastien Nocera 3000fe4a94 Bluetooth: btmtkuart: mark OF related data as maybe unused
JIRA: https://issues.redhat.com/browse/RHEL-2530

commit a88ea43b73f109e446f6027df237c8f868127a78
Author: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Date:   Sat Mar 11 12:13:54 2023 +0100

    Bluetooth: btmtkuart: mark OF related data as maybe unused

    The driver can be compile tested with !CONFIG_OF making certain data
    unused:

      drivers/bluetooth/btmtkuart.c:971:36: error: ‘mt7668_data’ defined
      but not used [-Werror=unused-const-variable=]
      drivers/bluetooth/btmtkuart.c:966:36: error: ‘mt7663_data’ defined
      but not used [-Werror=unused-const-variable=]
      drivers/bluetooth/btmtkuart.c:962:36: error: ‘mt7622_data’ defined
      but not used [-Werror=unused-const-variable=]

    Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2023-11-07 11:08:56 +01:00
Gopal Tiwari 66d80582a4 Bluetooth: btmtkuart: fix error handling in mtk_hci_wmt_sync()
Bugzilla: http://bugzilla.redhat.com/2124521

commit a76d269a4e86cfd7d4441e40adccfa67808fe6fa
Author: Dan Carpenter <dan.carpenter@oracle.com>
Date:   Thu Mar 17 10:57:40 2022 +0300

    Bluetooth: btmtkuart: fix error handling in mtk_hci_wmt_sync()

    This code has an uninitialized variable warning:

        drivers/bluetooth/btmtkuart.c:184 mtk_hci_wmt_sync()
        error: uninitialized symbol 'wc'.

    But it also has error paths which have memory leaks.

    Fixes: 8f550f55b155 ("Bluetooth: btmtkuart: rely on BT_MTK module")
    Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
    Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

Signed-off-by: Gopal Tiwari <gtiwari@redhat.com>
2022-10-18 10:32:27 +05:30
Gopal Tiwari b550c27faf Bluetooth: btmtkuart: fix the conflict between mtk and msft vendor event
Bugzilla: http://bugzilla.redhat.com/2124521

commit 6ac034a76aa230c1acb5bce4442d47310b5aa2f3
Author: Sean Wang <sean.wang@mediatek.com>
Date:   Wed Mar 9 08:03:54 2022 +0800

    Bluetooth: btmtkuart: fix the conflict between mtk and msft vendor event

    There is a conflict between MediaTek wmt event and msft vendor extension
    logic in the core layer since 145373cb1b ("Bluetooth: Add framework for
    Microsoft vendor extension") was introduced because we changed the type of
    mediatek wmt event to the type of msft vendor event in the driver.

    But the purpose we reported mediatek event to the core layer is for the
    diagnostic purpose with that we are able to see the full packet trace via
    monitoring socket with btmon. Thus, it is harmless we keep the original
    type of mediatek vendor event here to avoid breaking the msft extension
    function especially they can be supported by Mediatek future devices.

    Signed-off-by: Sean Wang <sean.wang@mediatek.com>
    Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

Signed-off-by: Gopal Tiwari <gtiwari@redhat.com>
2022-10-18 10:32:26 +05:30
Gopal Tiwari 8fae5c5793 Bluetooth: btmtkuart: add .set_bdaddr support
Bugzilla: http://bugzilla.redhat.com/2124521

commit 3640e7f4cb35353b39596816379def67ec9c58f4
Author: Sean Wang <sean.wang@mediatek.com>
Date:   Wed Mar 9 08:03:53 2022 +0800

    Bluetooth: btmtkuart: add .set_bdaddr support

    add .set_bdaddr support

    Signed-off-by: Sean Wang <sean.wang@mediatek.com>
    Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

Signed-off-by: Gopal Tiwari <gtiwari@redhat.com>
2022-10-18 10:32:26 +05:30
Gopal Tiwari b5d9521186 Bluetooth: btmtkuart: rely on BT_MTK module
Bugzilla: http://bugzilla.redhat.com/2124521

commit f5c3f98946e37a1f7ca07a6c6ab33b1223661aec
Author: Sean Wang <sean.wang@mediatek.com>
Date:   Wed Mar 9 08:03:52 2022 +0800

    Bluetooth: btmtkuart: rely on BT_MTK module

    Rely on btmtk module to reduce duplicated code

    Signed-off-by: Sean Wang <sean.wang@mediatek.com>
    Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

Signed-off-by: Gopal Tiwari <gtiwari@redhat.com>
2022-10-18 10:32:26 +05:30
Gopal Tiwari e10984618c Bluetooth: btmtkuart: fix a memleak in mtk_hci_wmt_sync
Bugzilla: http://bugzilla.redhat.com/2066188

commit 3e5f2d90c28f9454e421108554707620bc23269d
Author: Dinghao Liu <dinghao.liu@zju.edu.cn>
Date:   Wed Sep 22 21:49:45 2021 +0800

    Bluetooth: btmtkuart: fix a memleak in mtk_hci_wmt_sync

    bdev->evt_skb will get freed in the normal path and one error path
    of mtk_hci_wmt_sync, while the other error paths do not free it,
    which may cause a memleak. This bug is suggested by a static analysis
    tool, please advise.

    Fixes: e0b67035a9 ("Bluetooth: mediatek: update the common setup between MT7622 and other devices")
    Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
    Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

Signed-off-by: Gopal Tiwari <gtiwari@redhat.com>
2022-04-27 11:48:55 +05:30
Zhang Qilong a1b2fdf97f Bluetooth: btmtkuart: using pm_runtime_resume_and_get instead of pm_runtime_get_sync
Using pm_runtime_resume_and_get is more appropriate
for simplifing code

Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2021-06-26 07:12:38 +02:00
Zijun Hu d3a0fe6b09 Bluetooth: btmtkuart: Use serdev_device_write_buf() instead of serdev_device_write()
serdev_device_write() is not appropriate at here because
serdev_device_write_wakeup() is not used to release completion hold
by the former at @write_wakeup member of struct serdev_device_ops.

Fix by using serdev_device_write_buf() instead of serdev_device_write().

Signed-off-by: Zijun Hu <zijuhu@codeaurora.org>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2020-06-01 08:05:07 +02:00
Chuhong Yuan 4803c54ca2 Bluetooth: btmtkuart: Improve exception handling in btmtuart_probe()
Calls of the functions clk_disable_unprepare() and hci_free_dev()
were missing for the exception handling.
Thus add the missed function calls together with corresponding
jump targets.

Fixes: 055825614c ("Bluetooth: btmtkuart: add an implementation for clock osc property")
Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2020-05-29 13:40:20 +02:00
Sean Wang 055825614c Bluetooth: btmtkuart: add an implementation for clock osc property
Some board requires explicitily control external osscilator via GPIO.
So, add an implementation of a clock property for an external oscillator
to the device.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2019-07-06 13:00:04 +02:00
Sean Wang a3cb6d602a Bluetooth: btmtkuart: add an implementation for boot-gpios property
Not every platform has the pinctrl device integrates the GPIO the function
such as MT7621 whose pinctrl and GPIO are separate hardware so the driver
adds additional boot-gpios to let the MT766[3,8]U can enter the proper boot
mode by gpiod for such platform.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2019-07-06 13:00:04 +02:00
Sean Wang cac63f9b16 Bluetooth: mediatek: Fixed incorrect type in assignment
Fixed warning: incorrect type in assignment reported by kbuild test robot.
The detailed warning is shown as below.

make ARCH=x86_64 allmodconfig
make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

All warnings (new ones prefixed by >>):

btmtkuart.c:671:18: sparse:    warning: incorrect type in assignment
			       (different base types)
btmtkuart.c:671:18: sparse:    expected unsigned int [usertype] baudrate
btmtkuart.c:671:18: sparse:    got restricted __le32 [usertype]

sparse warnings: (new ones prefixed by >>)
btmtkuart.c:671:18: sparse: warning: incorrect type in assignment
			       (different base types)
btmtkuart.c:671:18: sparse:    expected unsigned int [usertype] baudrate
btmtkuart.c:671:18: sparse:    got restricted __le32 [usertype]

vim +671 drivers/bluetooth/btmtkuart.c

   659
   660	static int btmtkuart_change_baudrate(struct hci_dev *hdev)
   661	{
   662		struct btmtkuart_dev *bdev = hci_get_drvdata(hdev);
   663		struct btmtk_hci_wmt_params wmt_params;
   664		u32 baudrate;
   665		u8 param;
   666		int err;
   667
   668		/* Indicate the device to enter the probe state the host is
   669		 * ready to change a new baudrate.
   670		 */
 > 671		baudrate = cpu_to_le32(bdev->desired_speed);
   672		wmt_params.op = MTK_WMT_HIF;

Fixes: 22eaf6c994 ("Bluetooth: mediatek: add support for MediaTek MT7663U and MT7668U UART devices")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2019-04-23 18:09:08 +02:00
Sean Wang 22eaf6c994 Bluetooth: mediatek: add support for MediaTek MT7663U and MT7668U UART devices
This adds the support of enabling MT7663U and MT7668U Bluetooth function
running on the top of btmtkuart driver.

There are a few differences between MT766[3,8]U and MT7622 where
MT766[3,8]U are standalone devices based on UART transport while MT7622
bluetooth is a built-in device on MediaTek SoC communicating with the host
through BTIF serial transport. Thus, extra setup sequence is necessary
for these standalone devices such as remote regulator and reset control via
GPIO, baud rate changing handshake between the host and device and so on.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2019-03-02 19:51:23 +01:00
Sean Wang e0b67035a9 Bluetooth: mediatek: update the common setup between MT7622 and other devices
Update the setup sequence on MT7622 to apply the same flow with MT7663U
and MT7668U USB [1] as much as possible. These additional commands are
required to parse the corresponding event to determine what current state
the Bluetooth device is on and thus it's necessary to extend
mtk_hci_wmt_sync to support the reading status in the same patch.

[1] http://lists.infradead.org/pipermail/linux-mediatek/2019-January/017074.html

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2019-02-18 14:08:55 +01:00
Sean Wang 88e5f366a1 Bluetooth: mediatek: pass a pointer to mtk_hci_wmt_sync
Pass a structure pointer to mtk_hci_wmt_sync rather than several arguments
to avoid take up additional stack area and be better to read the code.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2019-02-18 14:07:38 +01:00
Sean Wang 77f328dbc6 Bluetooth: mediatek: fix up an error path to restore bdev->tx_state
Restore bdev->tx_state with clearing bit BTMTKUART_TX_WAIT_VND_EVT
when there is an error on waiting for the corresponding event.

Fixes: 7237c4c9ec ("Bluetooth: mediatek: Add protocol support for MediaTek serial devices")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2019-02-18 14:06:38 +01:00
Sean Wang adf5d73056 Bluetooth: mediatek: trivial typo fix
add a trivial typo fix from speicfic to specific

Fixes: 7237c4c9ec ("Bluetooth: mediatek: Add protocol support for MediaTek serial devices")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2019-02-18 14:05:29 +01:00
Gustavo A. R. Silva addb3ffbca Bluetooth: mediatek: Fix memory leak
In case memory resources for *fw* were allocated, release them before
return.

Addresses-Coverity-ID: 1472611 ("Resource leak")
Fixes: 7237c4c9ec ("Bluetooth: mediatek: Add protocol support for MediaTek serial devices")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Acked-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-08-21 16:56:20 +02:00
Dan Carpenter 330ad75f6a Bluetooth: mediatek: pass correct size to h4_recv_buf()
We're supposed to pass the number of elements in the mtk_recv_pkts, not
the number of bytes.

Fixes: 7237c4c9ec ("Bluetooth: mediatek: Add protocol support for MediaTek serial devices")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-08-13 15:59:39 +02:00
Sean Wang 7237c4c9ec Bluetooth: mediatek: Add protocol support for MediaTek serial devices
This adds a driver based on serdev driver for the MediaTek serial protocol
based on running H:4, which can enable the built-in Bluetooth device inside
MT7622 SoC.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2018-08-07 21:33:25 +02:00