Commit eb9fecb9 authored by Ruslan Bilovol's avatar Ruslan Bilovol Committed by Felipe Balbi

usb: gadget: f_uac2: split out audio core

Abstract the peripheral side ALSA sound card code from
the f_uac2 function into a component that can be called
by various functions, so the various flavors can be split
apart and selectively reused.

Visible changes:
 - add uac_params structure to pass audio paramteres for
   g_audio_setup
 - make ALSA sound card's name configurable
 - add [in/out]_ep_maxpsize
 - allocate snd_uac_chip structure during g_audio_setup
 - add u_audio_[start/stop]_[capture/playback] functions
Signed-off-by: default avatarRuslan Bilovol <ruslan.bilovol@gmail.com>
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent 7158b57a
...@@ -158,6 +158,9 @@ config USB_U_SERIAL ...@@ -158,6 +158,9 @@ config USB_U_SERIAL
config USB_U_ETHER config USB_U_ETHER
tristate tristate
config USB_U_AUDIO
tristate
config USB_F_SERIAL config USB_F_SERIAL
tristate tristate
...@@ -381,6 +384,7 @@ config USB_CONFIGFS_F_UAC2 ...@@ -381,6 +384,7 @@ config USB_CONFIGFS_F_UAC2
depends on SND depends on SND
select USB_LIBCOMPOSITE select USB_LIBCOMPOSITE
select SND_PCM select SND_PCM
select USB_U_AUDIO
select USB_F_UAC2 select USB_F_UAC2
help help
This Audio function is compatible with USB Audio Class This Audio function is compatible with USB Audio Class
......
...@@ -32,6 +32,7 @@ usb_f_mass_storage-y := f_mass_storage.o storage_common.o ...@@ -32,6 +32,7 @@ usb_f_mass_storage-y := f_mass_storage.o storage_common.o
obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o
usb_f_fs-y := f_fs.o usb_f_fs-y := f_fs.o
obj-$(CONFIG_USB_F_FS) += usb_f_fs.o obj-$(CONFIG_USB_F_FS) += usb_f_fs.o
obj-$(CONFIG_USB_U_AUDIO) += u_audio.o
usb_f_uac1-y := f_uac1.o u_uac1.o usb_f_uac1-y := f_uac1.o u_uac1.o
obj-$(CONFIG_USB_F_UAC1) += usb_f_uac1.o obj-$(CONFIG_USB_F_UAC1) += usb_f_uac1.o
usb_f_uac2-y := f_uac2.o usb_f_uac2-y := f_uac2.o
......
This diff is collapsed.
This diff is collapsed.
/*
* u_audio.h -- interface to USB gadget "ALSA sound card" utilities
*
* Copyright (C) 2016
* Author: Ruslan Bilovol <ruslan.bilovol@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef __U_AUDIO_H
#define __U_AUDIO_H
#include <linux/usb/composite.h>
struct uac_params {
/* playback */
int p_chmask; /* channel mask */
int p_srate; /* rate in Hz */
int p_ssize; /* sample size */
/* capture */
int c_chmask; /* channel mask */
int c_srate; /* rate in Hz */
int c_ssize; /* sample size */
int req_number; /* number of preallocated requests */
};
struct g_audio {
struct usb_function func;
struct usb_gadget *gadget;
struct usb_ep *in_ep;
struct usb_ep *out_ep;
/* Max packet size for all in_ep possible speeds */
unsigned int in_ep_maxpsize;
/* Max packet size for all out_ep possible speeds */
unsigned int out_ep_maxpsize;
/* The ALSA Sound Card it represents on the USB-Client side */
struct snd_uac_chip *uac;
struct uac_params params;
};
static inline struct g_audio *func_to_g_audio(struct usb_function *f)
{
return container_of(f, struct g_audio, func);
}
static inline uint num_channels(uint chanmask)
{
uint num = 0;
while (chanmask) {
num += (chanmask & 1);
chanmask >>= 1;
}
return num;
}
/*
* g_audio_setup - initialize one virtual ALSA sound card
* @g_audio: struct with filled params, in_ep_maxpsize, out_ep_maxpsize
* @pcm_name: the id string for a PCM instance of this sound card
* @card_name: name of this soundcard
*
* This sets up the single virtual ALSA sound card that may be exported by a
* gadget driver using this framework.
*
* Context: may sleep
*
* Returns zero on success, or a negative error on failure.
*/
int g_audio_setup(struct g_audio *g_audio, const char *pcm_name,
const char *card_name);
void g_audio_cleanup(struct g_audio *g_audio);
int u_audio_start_capture(struct g_audio *g_audio);
void u_audio_stop_capture(struct g_audio *g_audio);
int u_audio_start_playback(struct g_audio *g_audio);
void u_audio_stop_playback(struct g_audio *g_audio);
#endif /* __U_AUDIO_H */
...@@ -56,6 +56,7 @@ config USB_AUDIO ...@@ -56,6 +56,7 @@ config USB_AUDIO
select SND_PCM select SND_PCM
select USB_F_UAC1 if GADGET_UAC1 select USB_F_UAC1 if GADGET_UAC1
select USB_F_UAC2 if !GADGET_UAC1 select USB_F_UAC2 if !GADGET_UAC1
select USB_U_AUDIO if USB_F_UAC2
help help
This Gadget Audio driver is compatible with USB Audio Class This Gadget Audio driver is compatible with USB Audio Class
specification 2.0. It implements 1 AudioControl interface, specification 2.0. It implements 1 AudioControl interface,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment