1 // SPDX-License-Identifier: GPL-2.0
3 * UAC3 Power Domain state management functions
6 #include <linux/slab.h>
8 #include <linux/usb/audio.h>
9 #include <linux/usb/audio-v2.h>
10 #include <linux/usb/audio-v3.h>
16 struct snd_usb_power_domain *
17 snd_usb_find_power_domain(struct usb_host_interface *ctrl_iface,
20 struct snd_usb_power_domain *pd;
23 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
28 while ((p = snd_usb_find_csint_desc(ctrl_iface->extra,
30 p, UAC3_POWER_DOMAIN)) != NULL) {
31 struct uac3_power_domain_descriptor *pd_desc = p;
34 if (!snd_usb_validate_audio_desc(p, UAC_VERSION_3))
36 for (i = 0; i < pd_desc->bNrEntities; i++) {
37 if (pd_desc->baEntityID[i] == id) {
38 pd->pd_id = pd_desc->bPowerDomainID;
40 le16_to_cpu(pd_desc->waRecoveryTime1);
42 le16_to_cpu(pd_desc->waRecoveryTime2);
52 int snd_usb_power_domain_set(struct snd_usb_audio *chip,
53 struct snd_usb_power_domain *pd,
56 struct usb_device *dev = chip->dev;
57 unsigned char current_state;
60 idx = snd_usb_ctrl_intf(chip) | (pd->pd_id << 8);
62 err = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0),
64 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
65 UAC3_AC_POWER_DOMAIN_CONTROL << 8, idx,
66 ¤t_state, sizeof(current_state));
68 dev_err(&dev->dev, "Can't get UAC3 power state for id %d\n",
73 if (current_state == state) {
74 dev_dbg(&dev->dev, "UAC3 power domain id %d already in state %d\n",
79 err = snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC2_CS_CUR,
80 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
81 UAC3_AC_POWER_DOMAIN_CONTROL << 8, idx,
82 &state, sizeof(state));
84 dev_err(&dev->dev, "Can't set UAC3 power state to %d for id %d\n",
89 if (state == UAC3_PD_STATE_D0) {
90 switch (current_state) {
91 case UAC3_PD_STATE_D2:
92 udelay(pd->pd_d2d0_rec * 50);
94 case UAC3_PD_STATE_D1:
95 udelay(pd->pd_d1d0_rec * 50);
102 dev_dbg(&dev->dev, "UAC3 power domain id %d change to state %d\n",