1 // SPDX-License-Identifier: GPL-2.0 1 2 /* 3 * UAC3 Power Domain state management functi 4 */ 5 6 #include <linux/slab.h> 7 #include <linux/usb.h> 8 #include <linux/usb/audio.h> 9 #include <linux/usb/audio-v2.h> 10 #include <linux/usb/audio-v3.h> 11 12 #include "usbaudio.h" 13 #include "helper.h" 14 #include "power.h" 15 16 struct snd_usb_power_domain * 17 snd_usb_find_power_domain(struct usb_host_inte 18 unsigned char id) 19 { 20 struct snd_usb_power_domain *pd; 21 void *p; 22 23 pd = kzalloc(sizeof(*pd), GFP_KERNEL); 24 if (!pd) 25 return NULL; 26 27 p = NULL; 28 while ((p = snd_usb_find_csint_desc(ct 29 ct 30 p, 31 struct uac3_power_domain_descr 32 int i; 33 34 if (!snd_usb_validate_audio_de 35 continue; 36 for (i = 0; i < pd_desc->bNrEn 37 if (pd_desc->baEntityI 38 pd->pd_id = pd 39 pd->pd_d1d0_re 40 le16_t 41 pd->pd_d2d0_re 42 le16_t 43 pd->ctrl_iface 44 return pd; 45 } 46 } 47 } 48 49 kfree(pd); 50 return NULL; 51 } 52 53 int snd_usb_power_domain_set(struct snd_usb_au 54 struct snd_usb_po 55 unsigned char sta 56 { 57 struct usb_device *dev = chip->dev; 58 unsigned char current_state; 59 int err, idx; 60 61 idx = snd_usb_ctrl_intf(pd->ctrl_iface 62 63 err = snd_usb_ctl_msg(chip->dev, usb_r 64 UAC2_CS_CUR, 65 USB_RECIP_INTERF 66 UAC3_AC_POWER_DO 67 ¤t_state, 68 if (err < 0) { 69 dev_err(&dev->dev, "Can't get 70 pd->pd_id); 71 return err; 72 } 73 74 if (current_state == state) { 75 dev_dbg(&dev->dev, "UAC3 power 76 pd->pd_id, state); 77 return 0; 78 } 79 80 err = snd_usb_ctl_msg(chip->dev, usb_s 81 USB_RECIP_INTERF 82 UAC3_AC_POWER_DO 83 &state, sizeof(s 84 if (err < 0) { 85 dev_err(&dev->dev, "Can't set 86 state, pd->pd_id); 87 return err; 88 } 89 90 if (state == UAC3_PD_STATE_D0) { 91 switch (current_state) { 92 case UAC3_PD_STATE_D2: 93 udelay(pd->pd_d2d0_rec 94 break; 95 case UAC3_PD_STATE_D1: 96 udelay(pd->pd_d1d0_rec 97 break; 98 default: 99 return -EINVAL; 100 } 101 } 102 103 dev_dbg(&dev->dev, "UAC3 power domain 104 pd->pd_id, state); 105 106 return 0; 107 } 108
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.