Skip to contentSkip to conversation

Bluetooth: btintel_pcie: Add support for _suspend() / _resume()

PATCH Superseded Kiran K 5 participants 7 messages Jul 25, 2025 – Jul 26, 2025

Subsystems (2)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Kiran K

author
#0 lore raw

PATCH v6 1/1 Bluetooth: btintel_pcie: Add support for _suspend() / _resume()

From: Chandrashekar Devegowda <[email protected]>

This patch implements _suspend() and _resume() functions for the Bluetooth controller. When the system enters a suspended state, the driver notifies the controller to perform necessary housekeeping tasks by writing to the sleep control register and waits for an alive interrupt. The firmware raises the alive interrupt when it has transitioned to the D3 state. The same flow occurs when the system resumes.

Command to test host initiated wakeup after 60 seconds sudo rtcwake -m mem -s 60

dmesg log (tested on Whale Peak2 on Panther Lake platform) On system suspend:

[Fri Jul 25 11:05:37 2025] Bluetooth: hci0: device entered into d3 state from d0 in 80 us

On system resume:

[Fri Jul 25 11:06:36 2025] Bluetooth: hci0: device entered into d0 state from d3 in 7117 us

---
changes in v6:
- s/delta/delta_us/g
- s/CONFIG_PM/CONFIG_PM_SLEEP/g
- use pm_sleep_pr()/pm_str() to avoid #ifdefs
- remove the code to set persistance mode as its not relevant to this patch

changes in v5:
- refactor _suspend() / _resume() to set the D3HOT/D3COLD based on power event
- remove SIMPLE_DEV_PM_OPS and define the required pm_ops callback functions

changes in v4:
- Moved document and section details from the commit message as comment in code.

changes in v3:
- Corrected the typo's
- Updated the CC list as suggested.
- Corrected the format specifiers in the logs.

changes in v2:
- Updated the commit message with test steps and logs.
- Added logs to include the timeout message.
- Fixed a potential race condition during suspend and resume.

 drivers/bluetooth/btintel_pcie.c | 90 ++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
drivers/bluetooth/btintel_pcie.c +90 -0
index 6e7bbbd35279..c419521493fe 100644
@@ -2573,11 +2573,101 @@ static void btintel_pcie_coredump(struct device *dev)
 }
 #endif
 
+#ifdef CONFIG_PM_SLEEP
+static int btintel_pcie_suspend_late(struct device *dev, pm_message_t mesg)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct btintel_pcie_data *data;
+	ktime_t start;
+	u32 dxstate;
+	s64 delta_us;
+	int err;
+
+	data = pci_get_drvdata(pdev);
+
+	dxstate = (mesg.event == PM_EVENT_SUSPEND ?
+		   BTINTEL_PCIE_STATE_D3_HOT : BTINTEL_PCIE_STATE_D3_COLD);
+
+	data->gp0_received = false;
+
+	start = ktime_get();
+
+	/* Refer: 6.4.11.7 -> Platform power management */
+	btintel_pcie_wr_sleep_cntrl(data, dxstate);
+	err = wait_event_timeout(data->gp0_wait_q, data->gp0_received,
+				 msecs_to_jiffies(BTINTEL_DEFAULT_INTR_TIMEOUT_MS));
+	if (err == 0) {
+		bt_dev_err(data->hdev, "Timeout (%u ms) on alive interrupt for D3 entry",
+				BTINTEL_DEFAULT_INTR_TIMEOUT_MS);
+		return -EBUSY;
+	}
+
+	delta_us = ktime_to_ns(ktime_get() - start) / 1000;
+	bt_dev_info(data->hdev, "device entered into d3 state from d0 in %lld us",
+		    delta_us);
+	return 0;
+}
+
+static int btintel_pcie_suspend(struct device *dev)
+{
+	return btintel_pcie_suspend_late(dev, PMSG_SUSPEND);
+}
+
+static int btintel_pcie_hibernate(struct device *dev)
+{
+	return btintel_pcie_suspend_late(dev, PMSG_HIBERNATE);
+}
+
+static int btintel_pcie_freeze(struct device *dev)
+{
+	return btintel_pcie_suspend_late(dev, PMSG_FREEZE);
+}
+
+static int btintel_pcie_resume(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct btintel_pcie_data *data;
+	ktime_t start;
+	int err;
+	s64 delta_us;
+
+	data = pci_get_drvdata(pdev);
+	data->gp0_received = false;
+
+	start = ktime_get();
+
+	/* Refer: 6.4.11.7 -> Platform power management */
+	btintel_pcie_wr_sleep_cntrl(data, BTINTEL_PCIE_STATE_D0);
+	err = wait_event_timeout(data->gp0_wait_q, data->gp0_received,
+				 msecs_to_jiffies(BTINTEL_DEFAULT_INTR_TIMEOUT_MS));
+	if (err == 0) {
+		bt_dev_err(data->hdev, "Timeout (%u ms) on alive interrupt for D0 entry",
+				BTINTEL_DEFAULT_INTR_TIMEOUT_MS);
+		return -EBUSY;
+	}
+
+	delta_us = ktime_to_ns(ktime_get() - start) / 1000;
+	bt_dev_info(data->hdev, "device entered into d0 state from d3 in %lld us",
+		    delta_us);
+	return 0;
+}
+
+const struct dev_pm_ops btintel_pcie_pm_ops = {
+	.suspend = pm_sleep_ptr(btintel_pcie_suspend),
+	.resume = pm_sleep_ptr(btintel_pcie_resume),
+	.freeze = pm_sleep_ptr(btintel_pcie_freeze),
+	.thaw = pm_sleep_ptr(btintel_pcie_resume),
+	.poweroff = pm_sleep_ptr(btintel_pcie_hibernate),
+	.restore = pm_sleep_ptr(btintel_pcie_resume),
+};
+#endif
+
 static struct pci_driver btintel_pcie_driver = {
 	.name = KBUILD_MODNAME,
 	.id_table = btintel_pcie_table,
 	.probe = btintel_pcie_probe,
 	.remove = btintel_pcie_remove,
+	.driver.pm = pm_ptr(&btintel_pcie_pm_ops),
 #ifdef CONFIG_DEV_COREDUMP
 	.driver.coredump = btintel_pcie_coredump
 #endif
Signature · 1 line
2.43.0
#1 lore raw

This is an automated email and please do not reply to this email.

Dear Submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.

----- Output -----

error: patch failed: drivers/bluetooth/btintel_pcie.c:2573
error: drivers/bluetooth/btintel_pcie.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch

Please resolve the issue and submit the patches again.

---
Regards,
Linux Bluetooth

Reviewed-by on v6 1/1
#2 lore raw
In reply to Kiran K

Dear Kiran,

Thank you for sending the improved version 6.

Am 25.07.25 um 11:01 schrieb Kiran K:

Quoted 63 lines

From: Chandrashekar Devegowda <[email protected]>

This patch implements _suspend() and _resume() functions for the Bluetooth controller. When the system enters a suspended state, the driver notifies the controller to perform necessary housekeeping tasks by writing to the sleep control register and waits for an alive interrupt. The firmware raises the alive interrupt when it has transitioned to the D3 state. The same flow occurs when the system resumes.

Command to test host initiated wakeup after 60 seconds sudo rtcwake -m mem -s 60

dmesg log (tested on Whale Peak2 on Panther Lake platform) On system suspend:

[Fri Jul 25 11:05:37 2025] Bluetooth: hci0: device entered into d3 state from d0 in 80 us

On system resume:

[Fri Jul 25 11:06:36 2025] Bluetooth: hci0: device entered into d0 state from d3 in 7117 us

---
changes in v6:
- s/delta/delta_us/g
- s/CONFIG_PM/CONFIG_PM_SLEEP/g
- use pm_sleep_pr()/pm_str() to avoid #ifdefs
- remove the code to set persistance mode as its not relevant to this patch

changes in v5:
- refactor _suspend() / _resume() to set the D3HOT/D3COLD based on power event
- remove SIMPLE_DEV_PM_OPS and define the required pm_ops callback functions

changes in v4:
- Moved document and section details from the commit message as comment in code.

changes in v3:
- Corrected the typo's
- Updated the CC list as suggested.
- Corrected the format specifiers in the logs.

changes in v2:
- Updated the commit message with test steps and logs.
- Added logs to include the timeout message.
- Fixed a potential race condition during suspend and resume.

  drivers/bluetooth/btintel_pcie.c | 90 ++++++++++++++++++++++++++++++++
  1 file changed, 90 insertions(+)
drivers/bluetooth/btintel_pcie.c +4 -0
index 6e7bbbd35279..c419521493fe 100644
@@ -2573,11 +2573,101 @@ static void btintel_pcie_coredump(struct device *dev)
  }
  #endif
 
+#ifdef CONFIG_PM_SLEEP
+static int btintel_pcie_suspend_late(struct device *dev, pm_message_t mesg)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);

drivers/bluetooth/btintel_pcie.c static void btintel_pcie_coredump(struct device *dev) · line 2589

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10 -0
+	struct btintel_pcie_data *data;
+	ktime_t start;
+	u32 dxstate;
+	s64 delta_us;
+	int err;
+
+	data = pci_get_drvdata(pdev);
+
+	dxstate = (mesg.event == PM_EVENT_SUSPEND ?
+		   BTINTEL_PCIE_STATE_D3_HOT : BTINTEL_PCIE_STATE_D3_COLD);

I believe the brackets are uncommon. You actually can leave it out, or, if brackets need to be used, only surround the condition.

Quoted 74 lines
drivers/bluetooth/btintel_pcie.c +74 -0
+
+	data->gp0_received = false;
+
+	start = ktime_get();
+
+	/* Refer: 6.4.11.7 -> Platform power management */
+	btintel_pcie_wr_sleep_cntrl(data, dxstate);
+	err = wait_event_timeout(data->gp0_wait_q, data->gp0_received,
+				 msecs_to_jiffies(BTINTEL_DEFAULT_INTR_TIMEOUT_MS));
+	if (err == 0) {
+		bt_dev_err(data->hdev, "Timeout (%u ms) on alive interrupt for D3 entry",
+				BTINTEL_DEFAULT_INTR_TIMEOUT_MS);
+		return -EBUSY;
+	}
+
+	delta_us = ktime_to_ns(ktime_get() - start) / 1000;
+	bt_dev_info(data->hdev, "device entered into d3 state from d0 in %lld us",
+		    delta_us);
+	return 0;
+}
+
+static int btintel_pcie_suspend(struct device *dev)
+{
+	return btintel_pcie_suspend_late(dev, PMSG_SUSPEND);
+}
+
+static int btintel_pcie_hibernate(struct device *dev)
+{
+	return btintel_pcie_suspend_late(dev, PMSG_HIBERNATE);
+}
+
+static int btintel_pcie_freeze(struct device *dev)
+{
+	return btintel_pcie_suspend_late(dev, PMSG_FREEZE);
+}
+
+static int btintel_pcie_resume(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct btintel_pcie_data *data;
+	ktime_t start;
+	int err;
+	s64 delta_us;
+
+	data = pci_get_drvdata(pdev);
+	data->gp0_received = false;
+
+	start = ktime_get();
+
+	/* Refer: 6.4.11.7 -> Platform power management */
+	btintel_pcie_wr_sleep_cntrl(data, BTINTEL_PCIE_STATE_D0);
+	err = wait_event_timeout(data->gp0_wait_q, data->gp0_received,
+				 msecs_to_jiffies(BTINTEL_DEFAULT_INTR_TIMEOUT_MS));
+	if (err == 0) {
+		bt_dev_err(data->hdev, "Timeout (%u ms) on alive interrupt for D0 entry",
+				BTINTEL_DEFAULT_INTR_TIMEOUT_MS);
+		return -EBUSY;
+	}
+
+	delta_us = ktime_to_ns(ktime_get() - start) / 1000;
+	bt_dev_info(data->hdev, "device entered into d0 state from d3 in %lld us",
+		    delta_us);
+	return 0;
+}
+
+const struct dev_pm_ops btintel_pcie_pm_ops = {
+	.suspend = pm_sleep_ptr(btintel_pcie_suspend),
+	.resume = pm_sleep_ptr(btintel_pcie_resume),
+	.freeze = pm_sleep_ptr(btintel_pcie_freeze),
+	.thaw = pm_sleep_ptr(btintel_pcie_resume),
+	.poweroff = pm_sleep_ptr(btintel_pcie_hibernate),
+	.restore = pm_sleep_ptr(btintel_pcie_resume),
+};
+#endif

drivers/bluetooth/btintel_pcie.c static void btintel_pcie_coredump(struct device *dev) · line 2673

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +2 -0
+
  static struct pci_driver btintel_pcie_driver = {
  	.name = KBUILD_MODNAME,
  	.id_table = btintel_pcie_table,
  	.probe = btintel_pcie_probe,
  	.remove = btintel_pcie_remove,
+	.driver.pm = pm_ptr(&btintel_pcie_pm_ops),
  #ifdef CONFIG_DEV_COREDUMP
  	.driver.coredump = btintel_pcie_coredump
  #endif

With the above comment fixed, please feel free to add:

Kind regards,

Paul

author
#3 lore raw

Hi Paul,

Quoted 190 lines

-----Original Message-----
From: Paul Menzel <[email protected]>
Sent: Friday, July 25, 2025 2:35 PM
To: K, Kiran <[email protected]>; Devegowda, Chandrashekar <[email protected]>
Cc: [email protected]; Srivatsa, Ravishankar <[email protected]>; Tumkur Narayan, Chethan <[email protected]>; [email protected]; linux- [email protected]
Subject: Re: [PATCH v6] Bluetooth: btintel_pcie: Add support for _suspend() / _resume()

Dear Kiran,

Thank you for sending the improved version 6.

Am 25.07.25 um 11:01 schrieb Kiran K:

Quoted 33 lines

From: Chandrashekar Devegowda <[email protected]>

This patch implements _suspend() and _resume() functions for the Bluetooth controller. When the system enters a suspended state, the driver notifies the controller to perform necessary housekeeping tasks by writing to the sleep control register and waits for an alive interrupt. The firmware raises the alive interrupt when it has transitioned to the D3 state. The same flow occurs when the system resumes.

Command to test host initiated wakeup after 60 seconds sudo rtcwake -m mem -s 60

dmesg log (tested on Whale Peak2 on Panther Lake platform) On system suspend:

[Fri Jul 25 11:05:37 2025] Bluetooth: hci0: device entered into d3

state from d0 in 80 us

On system resume:

[Fri Jul 25 11:06:36 2025] Bluetooth: hci0: device entered into d0

state from d3 in 7117 us

Signed-off-by: Chandrashekar Devegowda
<[email protected]>

---
changes in v6:
- s/delta/delta_us/g
- s/CONFIG_PM/CONFIG_PM_SLEEP/g
- use pm_sleep_pr()/pm_str() to avoid #ifdefs
- remove the code to set persistance mode as its not relevant to
this patch

Quoted 2 lines

changes in v5:
- refactor _suspend() / _resume() to set the D3HOT/D3COLD based on

power

Quoted 6 lines

event
- remove SIMPLE_DEV_PM_OPS and define the required pm_ops callback functions

changes in v4:
- Moved document and section details from the commit message as

comment in code.

drivers/bluetooth/btintel_pcie.c static void btintel_pcie_coredump(struct device

Quoted 20 lines

changes in v3:
- Corrected the typo's
- Updated the CC list as suggested.
- Corrected the format specifiers in the logs.

changes in v2:
- Updated the commit message with test steps and logs.
- Added logs to include the timeout message.
- Fixed a potential race condition during suspend and resume.

  drivers/bluetooth/btintel_pcie.c | 90 ++++++++++++++++++++++++++++++++
  1 file changed, 90 insertions(+)
drivers/bluetooth/btintel_pcie.c +0 -0
index 6e7bbbd35279..c419521493fe 100644
@@ -2573,11 +2573,101 @@ static void btintel_pcie_coredump(struct device

*dev)

Quoted 7 lines
drivers/bluetooth/btintel_pcie.c +4 -0
  }
  #endif
 
+#ifdef CONFIG_PM_SLEEP
+static int btintel_pcie_suspend_late(struct device *dev, pm_message_t
+mesg) {
+	struct pci_dev *pdev = to_pci_dev(dev);

drivers/bluetooth/btintel_pcie.c static void btintel_pcie_coredump(struct device *dev)

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10 -0
+	struct btintel_pcie_data *data;
+	ktime_t start;
+	u32 dxstate;
+	s64 delta_us;
+	int err;
+
+	data = pci_get_drvdata(pdev);
+
+	dxstate = (mesg.event == PM_EVENT_SUSPEND ?
+		   BTINTEL_PCIE_STATE_D3_HOT :

BTINTEL_PCIE_STATE_D3_COLD);

I believe the brackets are uncommon. You actually can leave it out, or, if brackets need to be used, only surround the condition.

drivers/bluetooth/btintel_pcie.c static void btintel_pcie_coredump(struct device *dev) · line 2604

Quoted 9 lines
drivers/bluetooth/btintel_pcie.c +9 -0
+
+	data->gp0_received = false;
+
+	start = ktime_get();
+
+	/* Refer: 6.4.11.7 -> Platform power management */
+	btintel_pcie_wr_sleep_cntrl(data, dxstate);
+	err = wait_event_timeout(data->gp0_wait_q, data->gp0_received,
+

msecs_to_jiffies(BTINTEL_DEFAULT_INTR_TIMEOUT_MS));

drivers/bluetooth/btintel_pcie.c static void btintel_pcie_coredump(struct device · line 2600

Quoted 2 lines
drivers/bluetooth/btintel_pcie.c +2 -0
+	if (err == 0) {
+		bt_dev_err(data->hdev, "Timeout (%u ms) on alive interrupt

for D3 entry",

drivers/bluetooth/btintel_pcie.c static void btintel_pcie_coredump(struct device *dev)

Quoted 6 lines
drivers/bluetooth/btintel_pcie.c +6 -0
+				BTINTEL_DEFAULT_INTR_TIMEOUT_MS);
+		return -EBUSY;
+	}
+
+	delta_us = ktime_to_ns(ktime_get() - start) / 1000;
+	bt_dev_info(data->hdev, "device entered into d3 state from d0 in %lld

us",

Quoted 19 lines
drivers/bluetooth/btintel_pcie.c +19 -0
+		    delta_us);
+	return 0;
+}
+
+static int btintel_pcie_suspend(struct device *dev) {
+	return btintel_pcie_suspend_late(dev, PMSG_SUSPEND); }
+
+static int btintel_pcie_hibernate(struct device *dev) {
+	return btintel_pcie_suspend_late(dev, PMSG_HIBERNATE); }
+
+static int btintel_pcie_freeze(struct device *dev) {
+	return btintel_pcie_suspend_late(dev, PMSG_FREEZE); }
+
+static int btintel_pcie_resume(struct device *dev) {
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct btintel_pcie_data *data;
+	ktime_t start;
+	int err;
+	s64 delta_us;

drivers/bluetooth/btintel_pcie.c static void btintel_pcie_coredump(struct device *dev) · line 2648

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10 -0
+
+	data = pci_get_drvdata(pdev);
+	data->gp0_received = false;
+
+	start = ktime_get();
+
+	/* Refer: 6.4.11.7 -> Platform power management */
+	btintel_pcie_wr_sleep_cntrl(data, BTINTEL_PCIE_STATE_D0);
+	err = wait_event_timeout(data->gp0_wait_q, data->gp0_received,
+

msecs_to_jiffies(BTINTEL_DEFAULT_INTR_TIMEOUT_MS));

drivers/bluetooth/btintel_pcie.c static void btintel_pcie_coredump(struct device · line 2637

Quoted 2 lines
drivers/bluetooth/btintel_pcie.c +2 -0
+	if (err == 0) {
+		bt_dev_err(data->hdev, "Timeout (%u ms) on alive interrupt

for D0 entry",

drivers/bluetooth/btintel_pcie.c static void btintel_pcie_coredump(struct device *dev)

Quoted 6 lines
drivers/bluetooth/btintel_pcie.c +6 -0
+				BTINTEL_DEFAULT_INTR_TIMEOUT_MS);
+		return -EBUSY;
+	}
+
+	delta_us = ktime_to_ns(ktime_get() - start) / 1000;
+	bt_dev_info(data->hdev, "device entered into d0 state from d3 in %lld

us",

Quoted 13 lines
drivers/bluetooth/btintel_pcie.c +13 -0
+		    delta_us);
+	return 0;
+}
+
+const struct dev_pm_ops btintel_pcie_pm_ops = {
+	.suspend = pm_sleep_ptr(btintel_pcie_suspend),
+	.resume = pm_sleep_ptr(btintel_pcie_resume),
+	.freeze = pm_sleep_ptr(btintel_pcie_freeze),
+	.thaw = pm_sleep_ptr(btintel_pcie_resume),
+	.poweroff = pm_sleep_ptr(btintel_pcie_hibernate),
+	.restore = pm_sleep_ptr(btintel_pcie_resume),
+};
+#endif

drivers/bluetooth/btintel_pcie.c static void btintel_pcie_coredump(struct device *dev) · line 2673

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +2 -0
+
  static struct pci_driver btintel_pcie_driver = {
  	.name = KBUILD_MODNAME,
  	.id_table = btintel_pcie_table,
  	.probe = btintel_pcie_probe,
  	.remove = btintel_pcie_remove,
+	.driver.pm = pm_ptr(&btintel_pcie_pm_ops),
  #ifdef CONFIG_DEV_COREDUMP
  	.driver.coredump = btintel_pcie_coredump
  #endif

With the above comment fixed, please feel free to add:

Quoted 1 line

Ack.

Quoted 5 lines

Kind regards,

Paul

Thanks,
Kiran

#4 lore raw
In reply to Kiran K
kernel test robot noticed the following build errors:

Hi Kiran,

kernel test robot noticed the following build errors:

[auto build test ERROR on bluetooth/master]
[also build test ERROR on linus/master v6.16-rc7]
[cannot apply to bluetooth-next/master next-20250725]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Kiran-K/Bluetooth-btintel_pcie-Add-support-for-_suspend-_resume/20250725-164819
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git master
patch link:    https://lore.kernel.org/r/20250725090133.1358775-1-kiran.k%40intel.com
patch subject: [PATCH v6] Bluetooth: btintel_pcie: Add support for _suspend() / _resume()
config: loongarch-randconfig-001-20250725 (https://download.01.org/0day-ci/archive/20250725/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250725/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from include/linux/kernel.h:36,
from drivers/bluetooth/btintel_pcie.c:9:

>> drivers/bluetooth/btintel_pcie.c:2454:30: error: 'btintel_pcie_pm_ops' undeclared here (not in a function); did you mean 'btintel_pcie_in_op'?
    2454 |         .driver.pm = pm_ptr(&btintel_pcie_pm_ops),
         |                              ^~~~~~~~~~~~~~~~~~~
   include/linux/util_macros.h:136:44: note: in definition of macro 'PTR_IF'
     136 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/bluetooth/btintel_pcie.c:2454:22: note: in expansion of macro 'pm_ptr'
    2454 |         .driver.pm = pm_ptr(&btintel_pcie_pm_ops),
         |                      ^~~~~~

vim +2454 drivers/bluetooth/btintel_pcie.c

2448
2449 static struct pci_driver btintel_pcie_driver = {
2450 .name = KBUILD_MODNAME,
2451 .id_table = btintel_pcie_table,
2452 .probe = btintel_pcie_probe,
2453 .remove = btintel_pcie_remove,

> 2454		.driver.pm = pm_ptr(&btintel_pcie_pm_ops),

2455 #ifdef CONFIG_DEV_COREDUMP
2456 .driver.coredump = btintel_pcie_coredump
2457 #endif
2458 };
2459 module_pci_driver(btintel_pcie_driver);
2460

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw
In reply to Kiran K

Hi Kiran,

Quoted 145 lines · Kiran K

From: Chandrashekar Devegowda <[email protected]>

This patch implements _suspend() and _resume() functions for the Bluetooth controller. When the system enters a suspended state, the driver notifies the controller to perform necessary housekeeping tasks by writing to the sleep control register and waits for an alive interrupt. The firmware raises the alive interrupt when it has transitioned to the D3 state. The same flow occurs when the system resumes.

Command to test host initiated wakeup after 60 seconds sudo rtcwake -m mem -s 60

dmesg log (tested on Whale Peak2 on Panther Lake platform) On system suspend:

[Fri Jul 25 11:05:37 2025] Bluetooth: hci0: device entered into d3 state from d0 in 80 us

On system resume:

[Fri Jul 25 11:06:36 2025] Bluetooth: hci0: device entered into d0 state from d3 in 7117 us

---
changes in v6:
- s/delta/delta_us/g
- s/CONFIG_PM/CONFIG_PM_SLEEP/g
- use pm_sleep_pr()/pm_str() to avoid #ifdefs
- remove the code to set persistance mode as its not relevant to this patch

changes in v5:
- refactor _suspend() / _resume() to set the D3HOT/D3COLD based on power event
- remove SIMPLE_DEV_PM_OPS and define the required pm_ops callback functions

changes in v4:
- Moved document and section details from the commit message as comment in code.

changes in v3:
- Corrected the typo's
- Updated the CC list as suggested.
- Corrected the format specifiers in the logs.

changes in v2:
- Updated the commit message with test steps and logs.
- Added logs to include the timeout message.
- Fixed a potential race condition during suspend and resume.

 drivers/bluetooth/btintel_pcie.c | 90 ++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
drivers/bluetooth/btintel_pcie.c +85 -0
index 6e7bbbd35279..c419521493fe 100644
@@ -2573,11 +2573,101 @@ static void btintel_pcie_coredump(struct device *dev)
 }
 #endif
 
+#ifdef CONFIG_PM_SLEEP
+static int btintel_pcie_suspend_late(struct device *dev, pm_message_t mesg)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+       struct btintel_pcie_data *data;
+       ktime_t start;
+       u32 dxstate;
+       s64 delta_us;
+       int err;
+
+       data = pci_get_drvdata(pdev);
+
+       dxstate = (mesg.event == PM_EVENT_SUSPEND ?
+                  BTINTEL_PCIE_STATE_D3_HOT : BTINTEL_PCIE_STATE_D3_COLD);
+
+       data->gp0_received = false;
+
+       start = ktime_get();
+
+       /* Refer: 6.4.11.7 -> Platform power management */
+       btintel_pcie_wr_sleep_cntrl(data, dxstate);
+       err = wait_event_timeout(data->gp0_wait_q, data->gp0_received,
+                                msecs_to_jiffies(BTINTEL_DEFAULT_INTR_TIMEOUT_MS));
+       if (err == 0) {
+               bt_dev_err(data->hdev, "Timeout (%u ms) on alive interrupt for D3 entry",
+                               BTINTEL_DEFAULT_INTR_TIMEOUT_MS);
+               return -EBUSY;
+       }
+
+       delta_us = ktime_to_ns(ktime_get() - start) / 1000;
+       bt_dev_info(data->hdev, "device entered into d3 state from d0 in %lld us",
+                   delta_us);
+       return 0;
+}
+
+static int btintel_pcie_suspend(struct device *dev)
+{
+       return btintel_pcie_suspend_late(dev, PMSG_SUSPEND);
+}
+
+static int btintel_pcie_hibernate(struct device *dev)
+{
+       return btintel_pcie_suspend_late(dev, PMSG_HIBERNATE);
+}
+
+static int btintel_pcie_freeze(struct device *dev)
+{
+       return btintel_pcie_suspend_late(dev, PMSG_FREEZE);
+}
+
+static int btintel_pcie_resume(struct device *dev)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+       struct btintel_pcie_data *data;
+       ktime_t start;
+       int err;
+       s64 delta_us;
+
+       data = pci_get_drvdata(pdev);
+       data->gp0_received = false;
+
+       start = ktime_get();
+
+       /* Refer: 6.4.11.7 -> Platform power management */
+       btintel_pcie_wr_sleep_cntrl(data, BTINTEL_PCIE_STATE_D0);
+       err = wait_event_timeout(data->gp0_wait_q, data->gp0_received,
+                                msecs_to_jiffies(BTINTEL_DEFAULT_INTR_TIMEOUT_MS));
+       if (err == 0) {
+               bt_dev_err(data->hdev, "Timeout (%u ms) on alive interrupt for D0 entry",
+                               BTINTEL_DEFAULT_INTR_TIMEOUT_MS);
+               return -EBUSY;
+       }
+
+       delta_us = ktime_to_ns(ktime_get() - start) / 1000;
+       bt_dev_info(data->hdev, "device entered into d0 state from d3 in %lld us",
+                   delta_us);
+       return 0;
+}
+
+const struct dev_pm_ops btintel_pcie_pm_ops = {
+       .suspend = pm_sleep_ptr(btintel_pcie_suspend),
+       .resume = pm_sleep_ptr(btintel_pcie_resume),
+       .freeze = pm_sleep_ptr(btintel_pcie_freeze),
+       .thaw = pm_sleep_ptr(btintel_pcie_resume),
+       .poweroff = pm_sleep_ptr(btintel_pcie_hibernate),

drivers/bluetooth/btintel_pcie.c static void btintel_pcie_coredump(struct device *dev) · line 2670

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +5 -0
+       .restore = pm_sleep_ptr(btintel_pcie_resume),
+};
+#endif
+
 static struct pci_driver btintel_pcie_driver = {
        .name = KBUILD_MODNAME,
        .id_table = btintel_pcie_table,
        .probe = btintel_pcie_probe,
        .remove = btintel_pcie_remove,
+       .driver.pm = pm_ptr(&btintel_pcie_pm_ops),

This doesn't seem quite right, btintel_pcie_pm_ops is behind CONFIG_PM_SLEEP not just CONFIG_PM, so it would be undefined if just CONFIG_PM is set, so we might as well do:

drivers/bluetooth/btintel_pcie.c +7 -7
index 5b32f5a6b0b0..2f1b1be94080 100644
@@ -2654,12 +2654,12 @@ static int btintel_pcie_resume(struct device *dev)
 }
 
 const struct dev_pm_ops btintel_pcie_pm_ops = {
-       .suspend = pm_sleep_ptr(btintel_pcie_suspend),
-       .resume = pm_sleep_ptr(btintel_pcie_resume),
-       .freeze = pm_sleep_ptr(btintel_pcie_freeze),
-       .thaw = pm_sleep_ptr(btintel_pcie_resume),
-       .poweroff = pm_sleep_ptr(btintel_pcie_hibernate),
-       .restore = pm_sleep_ptr(btintel_pcie_resume),
+       .suspend = btintel_pcie_suspend,
+       .resume = btintel_pcie_resume,
+       .freeze = btintel_pcie_freeze,
+       .thaw = btintel_pcie_resume,
+       .poweroff = btintel_pcie_hibernate,
+       .restore = btintel_pcie_resume,
 };
 #endif
 
@@ -2668,7 +2668,7 @@ static struct pci_driver btintel_pcie_driver = {
        .id_table = btintel_pcie_table,
        .probe = btintel_pcie_probe,
        .remove = btintel_pcie_remove,
-       .driver.pm = pm_ptr(&btintel_pcie_pm_ops),
+       .driver.pm = pm_sleep_ptr(&btintel_pcie_pm_ops),
 #ifdef CONFIG_DEV_COREDUMP
        .driver.coredump = btintel_pcie_coredump
 #endif
Quoted 7 lines
drivers/bluetooth/btintel_pcie.c +0 -1
 #ifdef CONFIG_DEV_COREDUMP
        .driver.coredump = btintel_pcie_coredump
 #endif
--

2.43.0

Signature · 1 line
Luiz Augusto von Dentz
author
#6 lore raw

Hi Luiz,

Quoted 171 lines

-----Original Message-----
From: Luiz Augusto von Dentz <[email protected]>
Sent: Friday, July 25, 2025 7:24 PM
To: K, Kiran <[email protected]>
Cc: [email protected]; Srivatsa, Ravishankar <[email protected]>; Tumkur Narayan, Chethan <[email protected]>; [email protected]; linux- [email protected]; Devegowda, Chandrashekar <[email protected]>
Subject: Re: [PATCH v6] Bluetooth: btintel_pcie: Add support for _suspend() / _resume()

Hi Kiran,

Quoted 34 lines · Kiran K

From: Chandrashekar Devegowda <[email protected]>

This patch implements _suspend() and _resume() functions for the Bluetooth controller. When the system enters a suspended state, the driver notifies the controller to perform necessary housekeeping tasks by writing to the sleep control register and waits for an alive interrupt. The firmware raises the alive interrupt when it has transitioned to the D3 state. The same flow occurs when the system resumes.

Command to test host initiated wakeup after 60 seconds sudo rtcwake -m mem -s 60

dmesg log (tested on Whale Peak2 on Panther Lake platform) On system suspend:

[Fri Jul 25 11:05:37 2025] Bluetooth: hci0: device entered into d3

state from d0 in 80 us

On system resume:

[Fri Jul 25 11:06:36 2025] Bluetooth: hci0: device entered into d0

state from d3 in 7117 us

Signed-off-by: Chandrashekar Devegowda
<[email protected]>

---
changes in v6:
- s/delta/delta_us/g
- s/CONFIG_PM/CONFIG_PM_SLEEP/g
- use pm_sleep_pr()/pm_str() to avoid #ifdefs
- remove the code to set persistance mode as its not relevant to
this patch

Quoted 2 lines

changes in v5:
- refactor _suspend() / _resume() to set the D3HOT/D3COLD based on

power

Quoted 6 lines

event
- remove SIMPLE_DEV_PM_OPS and define the required pm_ops callback functions

changes in v4:
- Moved document and section details from the commit message as

comment in code.

Quoted 39 lines

changes in v3:
- Corrected the typo's
- Updated the CC list as suggested.
- Corrected the format specifiers in the logs.

changes in v2:
- Updated the commit message with test steps and logs.
- Added logs to include the timeout message.
- Fixed a potential race condition during suspend and resume.

 drivers/bluetooth/btintel_pcie.c | 90
++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
drivers/bluetooth/btintel_pcie.c +0 -0
index 6e7bbbd35279..c419521493fe 100644
@@ -2573,11 +2573,101 @@ static void btintel_pcie_coredump(struct

device *dev) } #endif

drivers/bluetooth/btintel_pcie.c +16 -0
+#ifdef CONFIG_PM_SLEEP
+static int btintel_pcie_suspend_late(struct device *dev, pm_message_t
+mesg) {
+       struct pci_dev *pdev = to_pci_dev(dev);
+       struct btintel_pcie_data *data;
+       ktime_t start;
+       u32 dxstate;
+       s64 delta_us;
+       int err;
+
+       data = pci_get_drvdata(pdev);
+
+       dxstate = (mesg.event == PM_EVENT_SUSPEND ?
+                  BTINTEL_PCIE_STATE_D3_HOT :
+ BTINTEL_PCIE_STATE_D3_COLD);
+

drivers/bluetooth/btintel_pcie.c

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10 -0
+       data->gp0_received = false;
+
+       start = ktime_get();
+
+       /* Refer: 6.4.11.7 -> Platform power management */
+       btintel_pcie_wr_sleep_cntrl(data, dxstate);
+       err = wait_event_timeout(data->gp0_wait_q, data->gp0_received,
+                                msecs_to_jiffies(BTINTEL_DEFAULT_INTR_TIMEOUT_MS));
+       if (err == 0) {
+               bt_dev_err(data->hdev, "Timeout (%u ms) on alive interrupt for D3

entry",

drivers/bluetooth/btintel_pcie.c

Quoted 6 lines
drivers/bluetooth/btintel_pcie.c +6 -0
+                               BTINTEL_DEFAULT_INTR_TIMEOUT_MS);
+               return -EBUSY;
+       }
+
+       delta_us = ktime_to_ns(ktime_get() - start) / 1000;
+       bt_dev_info(data->hdev, "device entered into d3 state from d0 in %lld

us",

Quoted 21 lines
drivers/bluetooth/btintel_pcie.c +21 -0
+                   delta_us);
+       return 0;
+}
+
+static int btintel_pcie_suspend(struct device *dev) {
+       return btintel_pcie_suspend_late(dev, PMSG_SUSPEND); }
+
+static int btintel_pcie_hibernate(struct device *dev) {
+       return btintel_pcie_suspend_late(dev, PMSG_HIBERNATE); }
+
+static int btintel_pcie_freeze(struct device *dev) {
+       return btintel_pcie_suspend_late(dev, PMSG_FREEZE); }
+
+static int btintel_pcie_resume(struct device *dev) {
+       struct pci_dev *pdev = to_pci_dev(dev);
+       struct btintel_pcie_data *data;
+       ktime_t start;
+       int err;
+       s64 delta_us;
+
+       data = pci_get_drvdata(pdev);

drivers/bluetooth/btintel_pcie.c

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10 -0
+       data->gp0_received = false;
+
+       start = ktime_get();
+
+       /* Refer: 6.4.11.7 -> Platform power management */
+       btintel_pcie_wr_sleep_cntrl(data, BTINTEL_PCIE_STATE_D0);
+       err = wait_event_timeout(data->gp0_wait_q, data->gp0_received,
+                                msecs_to_jiffies(BTINTEL_DEFAULT_INTR_TIMEOUT_MS));
+       if (err == 0) {
+               bt_dev_err(data->hdev, "Timeout (%u ms) on alive interrupt for D0

entry",

drivers/bluetooth/btintel_pcie.c

Quoted 6 lines
drivers/bluetooth/btintel_pcie.c +6 -0
+                               BTINTEL_DEFAULT_INTR_TIMEOUT_MS);
+               return -EBUSY;
+       }
+
+       delta_us = ktime_to_ns(ktime_get() - start) / 1000;
+       bt_dev_info(data->hdev, "device entered into d0 state from d3 in %lld

us",

Quoted 16 lines
drivers/bluetooth/btintel_pcie.c +14 -0
+                   delta_us);
+       return 0;
+}
+
+const struct dev_pm_ops btintel_pcie_pm_ops = {
+       .suspend = pm_sleep_ptr(btintel_pcie_suspend),
+       .resume = pm_sleep_ptr(btintel_pcie_resume),
+       .freeze = pm_sleep_ptr(btintel_pcie_freeze),
+       .thaw = pm_sleep_ptr(btintel_pcie_resume),
+       .poweroff = pm_sleep_ptr(btintel_pcie_hibernate),
+       .restore = pm_sleep_ptr(btintel_pcie_resume),
+};
+#endif
+
 static struct pci_driver btintel_pcie_driver = {
        .name = KBUILD_MODNAME,
Quoted 9 lines
Quoted 4 lines

.id_table = btintel_pcie_table,
.probe = btintel_pcie_probe,
.remove = btintel_pcie_remove,
+ .driver.pm = pm_ptr(&btintel_pcie_pm_ops),

This doesn't seem quite right, btintel_pcie_pm_ops is behind CONFIG_PM_SLEEP not just CONFIG_PM, so it would be undefined if just CONFIG_PM is set, so we might as well do:

Agree. I will remove the usage of CONFIG_PM_SLEEP and instead rely on pm_sleep_ptr() and pm_ptr().

Quoted 41 lines
drivers/bluetooth/btintel_pcie.c +7 -7
index 5b32f5a6b0b0..2f1b1be94080 100644
@@ -2654,12 +2654,12 @@ static int btintel_pcie_resume(struct device *dev)
 }
 
 const struct dev_pm_ops btintel_pcie_pm_ops = {
-       .suspend = pm_sleep_ptr(btintel_pcie_suspend),
-       .resume = pm_sleep_ptr(btintel_pcie_resume),
-       .freeze = pm_sleep_ptr(btintel_pcie_freeze),
-       .thaw = pm_sleep_ptr(btintel_pcie_resume),
-       .poweroff = pm_sleep_ptr(btintel_pcie_hibernate),
-       .restore = pm_sleep_ptr(btintel_pcie_resume),
+       .suspend = btintel_pcie_suspend,
+       .resume = btintel_pcie_resume,
+       .freeze = btintel_pcie_freeze,
+       .thaw = btintel_pcie_resume,
+       .poweroff = btintel_pcie_hibernate,
+       .restore = btintel_pcie_resume,
 };
 #endif
 
@@ -2668,7 +2668,7 @@ static struct pci_driver btintel_pcie_driver = {
       .id_table = btintel_pcie_table,
       .probe = btintel_pcie_probe,
       .remove = btintel_pcie_remove,
-       .driver.pm = pm_ptr(&btintel_pcie_pm_ops),
+       .driver.pm = pm_sleep_ptr(&btintel_pcie_pm_ops),
 #ifdef CONFIG_DEV_COREDUMP
       .driver.coredump = btintel_pcie_coredump  #endif
 
Quoted 7 lines

#ifdef CONFIG_DEV_COREDUMP
.driver.coredump = btintel_pcie_coredump #endif
--
2.43.0

Quoted 2 lines

--
Luiz Augusto von Dentz

Thanks,
Kiran