linux/drivers/usb/gadget/function/u_audio.h
<<
>>
Prefs
   1/*
   2 * u_audio.h -- interface to USB gadget "ALSA sound card" utilities
   3 *
   4 * Copyright (C) 2016
   5 * Author: Ruslan Bilovol <ruslan.bilovol@gmail.com>
   6 *
   7 * This program is free software; you can redistribute it and/or modify
   8 * it under the terms of the GNU General Public License as published by
   9 * the Free Software Foundation; either version 2 of the License, or
  10 * (at your option) any later version.
  11 *
  12 * This program is distributed in the hope that it will be useful,
  13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15 * GNU General Public License for more details.
  16 *
  17 */
  18
  19#ifndef __U_AUDIO_H
  20#define __U_AUDIO_H
  21
  22#include <linux/usb/composite.h>
  23
  24struct uac_params {
  25        /* playback */
  26        int p_chmask;   /* channel mask */
  27        int p_srate;    /* rate in Hz */
  28        int p_ssize;    /* sample size */
  29
  30        /* capture */
  31        int c_chmask;   /* channel mask */
  32        int c_srate;    /* rate in Hz */
  33        int c_ssize;    /* sample size */
  34
  35        int req_number; /* number of preallocated requests */
  36};
  37
  38struct g_audio {
  39        struct usb_function func;
  40        struct usb_gadget *gadget;
  41
  42        struct usb_ep *in_ep;
  43        struct usb_ep *out_ep;
  44
  45        /* Max packet size for all in_ep possible speeds */
  46        unsigned int in_ep_maxpsize;
  47        /* Max packet size for all out_ep possible speeds */
  48        unsigned int out_ep_maxpsize;
  49
  50        /* The ALSA Sound Card it represents on the USB-Client side */
  51        struct snd_uac_chip *uac;
  52
  53        struct uac_params params;
  54};
  55
  56static inline struct g_audio *func_to_g_audio(struct usb_function *f)
  57{
  58        return container_of(f, struct g_audio, func);
  59}
  60
  61static inline uint num_channels(uint chanmask)
  62{
  63        uint num = 0;
  64
  65        while (chanmask) {
  66                num += (chanmask & 1);
  67                chanmask >>= 1;
  68        }
  69
  70        return num;
  71}
  72
  73/*
  74 * g_audio_setup - initialize one virtual ALSA sound card
  75 * @g_audio: struct with filled params, in_ep_maxpsize, out_ep_maxpsize
  76 * @pcm_name: the id string for a PCM instance of this sound card
  77 * @card_name: name of this soundcard
  78 *
  79 * This sets up the single virtual ALSA sound card that may be exported by a
  80 * gadget driver using this framework.
  81 *
  82 * Context: may sleep
  83 *
  84 * Returns zero on success, or a negative error on failure.
  85 */
  86int g_audio_setup(struct g_audio *g_audio, const char *pcm_name,
  87                                        const char *card_name);
  88void g_audio_cleanup(struct g_audio *g_audio);
  89
  90int u_audio_start_capture(struct g_audio *g_audio);
  91void u_audio_stop_capture(struct g_audio *g_audio);
  92int u_audio_start_playback(struct g_audio *g_audio);
  93void u_audio_stop_playback(struct g_audio *g_audio);
  94
  95#endif /* __U_AUDIO_H */
  96