u_audio.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * u_audio.h -- interface to USB gadget "ALSA sound card" utilities
  4. *
  5. * Copyright (C) 2016
  6. * Author: Ruslan Bilovol <ruslan.bilovol@gmail.com>
  7. */
  8. #ifndef __U_AUDIO_H
  9. #define __U_AUDIO_H
  10. #include <linux/usb/composite.h>
  11. struct uac_params {
  12. /* playback */
  13. int p_chmask; /* channel mask */
  14. int p_srate; /* rate in Hz */
  15. int p_ssize; /* sample size */
  16. /* capture */
  17. int c_chmask; /* channel mask */
  18. int c_srate; /* rate in Hz */
  19. int c_ssize; /* sample size */
  20. int req_number; /* number of preallocated requests */
  21. };
  22. struct g_audio {
  23. struct usb_function func;
  24. struct usb_gadget *gadget;
  25. struct usb_ep *in_ep;
  26. struct usb_ep *out_ep;
  27. /* Max packet size for all in_ep possible speeds */
  28. unsigned int in_ep_maxpsize;
  29. /* Max packet size for all out_ep possible speeds */
  30. unsigned int out_ep_maxpsize;
  31. /* The ALSA Sound Card it represents on the USB-Client side */
  32. struct snd_uac_chip *uac;
  33. struct uac_params params;
  34. };
  35. static inline struct g_audio *func_to_g_audio(struct usb_function *f)
  36. {
  37. return container_of(f, struct g_audio, func);
  38. }
  39. static inline uint num_channels(uint chanmask)
  40. {
  41. uint num = 0;
  42. while (chanmask) {
  43. num += (chanmask & 1);
  44. chanmask >>= 1;
  45. }
  46. return num;
  47. }
  48. /*
  49. * g_audio_setup - initialize one virtual ALSA sound card
  50. * @g_audio: struct with filled params, in_ep_maxpsize, out_ep_maxpsize
  51. * @pcm_name: the id string for a PCM instance of this sound card
  52. * @card_name: name of this soundcard
  53. *
  54. * This sets up the single virtual ALSA sound card that may be exported by a
  55. * gadget driver using this framework.
  56. *
  57. * Context: may sleep
  58. *
  59. * Returns zero on success, or a negative error on failure.
  60. */
  61. int g_audio_setup(struct g_audio *g_audio, const char *pcm_name,
  62. const char *card_name);
  63. void g_audio_cleanup(struct g_audio *g_audio);
  64. int u_audio_start_capture(struct g_audio *g_audio);
  65. void u_audio_stop_capture(struct g_audio *g_audio);
  66. int u_audio_start_playback(struct g_audio *g_audio);
  67. void u_audio_stop_playback(struct g_audio *g_audio);
  68. #endif /* __U_AUDIO_H */