Skip to content

Commit 1fc4926

Browse files
rbilovolFelipe Balbi
authored andcommitted
usb: gadget: function: f_uac1: implement get_alt()
After commit 7e4da3f ("usb: gadget: composite: Test get_alt() presence instead of set_alt()") f_uac1 function became broken because it doesn't have get_alt() callback implementation and composite framework never set altsetting 1 for audiostreaming interface. On host site it looks like: [424339.017711] 21:1:1: usb_set_interface failed (-32) Since host can't set altsetting 1, it can't start playing audio. In order to fix it implemented get_alt along with minor improvements (error conditions checking) similar to what existing f_uac2 has. Cc: Krzysztof Opasiak <[email protected]> Signed-off-by: Ruslan Bilovol <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent d423b96 commit 1fc4926

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

drivers/usb/gadget/function/f_uac1.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ static void f_audio_buffer_free(struct f_audio_buf *audio_buf)
277277
struct f_audio {
278278
struct gaudio card;
279279

280+
u8 ac_intf, ac_alt;
281+
u8 as_intf, as_alt;
282+
280283
/* endpoints handle full and/or high speeds */
281284
struct usb_ep *out_ep;
282285

@@ -586,7 +589,20 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
586589
req_count = opts->req_count;
587590
audio_buf_size = opts->audio_buf_size;
588591

589-
if (intf == 1) {
592+
/* No i/f has more than 2 alt settings */
593+
if (alt > 1) {
594+
ERROR(cdev, "%s:%d Error!\n", __func__, __LINE__);
595+
return -EINVAL;
596+
}
597+
598+
if (intf == audio->ac_intf) {
599+
/* Control I/f has only 1 AltSetting - 0 */
600+
if (alt) {
601+
ERROR(cdev, "%s:%d Error!\n", __func__, __LINE__);
602+
return -EINVAL;
603+
}
604+
return 0;
605+
} else if (intf == audio->as_intf) {
590606
if (alt == 1) {
591607
err = config_ep_by_speed(cdev->gadget, f, out_ep);
592608
if (err)
@@ -631,11 +647,28 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
631647
schedule_work(&audio->playback_work);
632648
}
633649
}
650+
audio->as_alt = alt;
634651
}
635652

636653
return err;
637654
}
638655

656+
static int f_audio_get_alt(struct usb_function *f, unsigned intf)
657+
{
658+
struct f_audio *audio = func_to_audio(f);
659+
struct usb_composite_dev *cdev = f->config->cdev;
660+
661+
if (intf == audio->ac_intf)
662+
return audio->ac_alt;
663+
else if (intf == audio->as_intf)
664+
return audio->as_alt;
665+
else
666+
ERROR(cdev, "%s:%d Invalid Interface %d!\n",
667+
__func__, __LINE__, intf);
668+
669+
return -EINVAL;
670+
}
671+
639672
static void f_audio_disable(struct usb_function *f)
640673
{
641674
return;
@@ -702,12 +735,16 @@ f_audio_bind(struct usb_configuration *c, struct usb_function *f)
702735
if (status < 0)
703736
goto fail;
704737
ac_interface_desc.bInterfaceNumber = status;
738+
audio->ac_intf = status;
739+
audio->ac_alt = 0;
705740

706741
status = usb_interface_id(c, f);
707742
if (status < 0)
708743
goto fail;
709744
as_interface_alt_0_desc.bInterfaceNumber = status;
710745
as_interface_alt_1_desc.bInterfaceNumber = status;
746+
audio->as_intf = status;
747+
audio->as_alt = 0;
711748

712749
status = -ENODEV;
713750

@@ -966,6 +1003,7 @@ static struct usb_function *f_audio_alloc(struct usb_function_instance *fi)
9661003
audio->card.func.bind = f_audio_bind;
9671004
audio->card.func.unbind = f_audio_unbind;
9681005
audio->card.func.set_alt = f_audio_set_alt;
1006+
audio->card.func.get_alt = f_audio_get_alt;
9691007
audio->card.func.setup = f_audio_setup;
9701008
audio->card.func.disable = f_audio_disable;
9711009
audio->card.func.free_func = f_audio_free;

0 commit comments

Comments
 (0)