Skip to content

Commit

Permalink
usb: core: add implementations for usb suspend/resume hooks
Browse files Browse the repository at this point in the history
In mobile, a co-processor can be used for USB audio. When the co-processor
is working for USB audio, the co-processor is the user/owner of the USB
driver, and the ACPU is able to sleep in such condition to improve power
consumption. In order to support this, we implement the hooks to handle USB
suspend/resume requests.

This commit introduces two hook implementations:
- usb_device_vendor_suspend()
  Determine whether we should skip suspend request according to the status
  of USB audio playback/capture.
  Return:
  - true: let driver.c know that we "handled" and it can just return
          succeeded to ACPU to continue system suspend process.
  - false: let driver.c know that it still run original suspend process.

- usb_device_vendor_resume()
  Determine whether we should skip resume request according to the USB
  device's suspend state.
  Return:
  - true: let driver.c know that it doesn't need to run resume process.
  - false: let driver.c know that it still run original resume process.

Signed-off-by: Puma Hsu <pumahsu@google.com>
  • Loading branch information
Puma Hsu authored and intel-lab-lkp committed Dec 14, 2022
1 parent c37166c commit de7c2e5
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions drivers/usb/core/usb-hooks-impl-goog.c
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2022 Google Corp.
*
* Author:
* Puma Hsu <pumahsu@google.com>
*/

#include <linux/usb.h>
#include "usb.h"

extern int usb_dev_register_vendor_ops(struct usb_device_vendor_ops *vendor_ops);

static bool usb_device_vendor_suspend(struct usb_device *udev, pm_message_t msg)
{
bool usb_playback = false;
bool usb_capture = false;
bool handled = false;

if (!udev)
return handled;

/*
* Note: Our private driver provides APIs to know the device is in audio playback
* or capture.
*
* usb_playback = usb_audio_playback_enabled();
* usb_capture = usb_audio_capture_enabled();
*/

/*
* Note: When the USB audio is working, we will not let the usb device suspend.
* Return handled = true so that the System core can it's suspend process.
*/
if (usb_playback || usb_capture) {
dev_info(&udev->dev, "%s: skip suspend process (playback:%d,capture:%d)\n",
__func__, usb_playback, usb_capture);
handled = true;
}

return handled;
}

static bool usb_device_vendor_resume(struct usb_device *udev, pm_message_t msg)
{
bool handled = false;

if (!udev)
return handled;

/*
* Note: If the udev didn't suspend actually, we don't need to do resume.
*/
if (udev->port_is_suspended || udev->state == USB_STATE_SUSPENDED) {
handled = false;
} else {
dev_info(&udev->dev, "%s: skip resume process\n", __func__);
handled = true;
}

return handled;
}

static struct usb_device_vendor_ops usb_dev_vendor_ops = {
.usb_dev_suspend = usb_device_vendor_suspend,
.usb_dev_resume = usb_device_vendor_resume,
};

int usb_vendor_helper_init(void)
{
return usb_dev_register_vendor_ops(&usb_dev_vendor_ops);
}

0 comments on commit de7c2e5

Please sign in to comment.