Skip to content

Commit

Permalink
Bluetooth: btmtksdio: handle runtime pm only when sdio_func is available
Browse files Browse the repository at this point in the history
Runtime pm ops is not aware the sdio_func status that is probably
being disabled by btmtksdio_close. Thus, we are only able to access the
sdio_func for the runtime pm operations only when the sdio_func is
available.

Fixes: 7f3c563 ("Bluetooth: btmtksdio: Add runtime PM support to SDIO based Bluetooth")
Co-developed-by: Mark-yw Chen <mark-yw.chen@mediatek.com>
Signed-off-by: Mark-yw Chen <mark-yw.chen@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
  • Loading branch information
Sean Wang authored and Marcel Holtmann committed Dec 3, 2021
1 parent c97a747 commit 4b4b222
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/bluetooth/btmtksdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ MODULE_DEVICE_TABLE(sdio, btmtksdio_table);

#define BTMTKSDIO_TX_WAIT_VND_EVT 1
#define BTMTKSDIO_HW_TX_READY 2
#define BTMTKSDIO_FUNC_ENABLED 3

struct mtkbtsdio_hdr {
__le16 len;
Expand Down Expand Up @@ -539,6 +540,8 @@ static int btmtksdio_open(struct hci_dev *hdev)
if (err < 0)
goto err_release_host;

set_bit(BTMTKSDIO_FUNC_ENABLED, &bdev->tx_state);

/* Get ownership from the device */
sdio_writel(bdev->func, C_FW_OWN_REQ_CLR, MTK_REG_CHLPCR, &err);
if (err < 0)
Expand Down Expand Up @@ -640,6 +643,7 @@ static int btmtksdio_close(struct hci_dev *hdev)
if (err < 0)
bt_dev_err(bdev->hdev, "Cannot return ownership to device");

clear_bit(BTMTKSDIO_FUNC_ENABLED, &bdev->tx_state);
sdio_disable_func(bdev->func);

sdio_release_host(bdev->func);
Expand Down Expand Up @@ -1058,6 +1062,9 @@ static int btmtksdio_runtime_suspend(struct device *dev)
if (!bdev)
return 0;

if (!test_bit(BTMTKSDIO_FUNC_ENABLED, &bdev->tx_state))
return 0;

sdio_claim_host(bdev->func);

sdio_writel(bdev->func, C_FW_OWN_REQ_SET, MTK_REG_CHLPCR, &err);
Expand Down Expand Up @@ -1085,6 +1092,9 @@ static int btmtksdio_runtime_resume(struct device *dev)
if (!bdev)
return 0;

if (!test_bit(BTMTKSDIO_FUNC_ENABLED, &bdev->tx_state))
return 0;

sdio_claim_host(bdev->func);

sdio_writel(bdev->func, C_FW_OWN_REQ_CLR, MTK_REG_CHLPCR, &err);
Expand Down

0 comments on commit 4b4b222

Please sign in to comment.