u_audio.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * u_audio.c -- interface to USB gadget "ALSA sound card" utilities
  3. *
  4. * Copyright (C) 2016
  5. * Author: Ruslan Bilovol <ruslan.bilovol@gmail.com>
  6. *
  7. * Sound card implementation was cut-and-pasted with changes
  8. * from f_uac2.c and has:
  9. * Copyright (C) 2011
  10. * Yadwinder Singh (yadi.brar01@gmail.com)
  11. * Jaswinder Singh (jaswinder.singh@linaro.org)
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. */
  23. #include <linux/module.h>
  24. #include <sound/core.h>
  25. #include <sound/pcm.h>
  26. #include <sound/pcm_params.h>
  27. #include "u_audio.h"
  28. #define BUFF_SIZE_MAX (PAGE_SIZE * 16)
  29. #define PRD_SIZE_MAX PAGE_SIZE
  30. #define MIN_PERIODS 4
  31. struct uac_req {
  32. struct uac_rtd_params *pp; /* parent param */
  33. struct usb_request *req;
  34. };
  35. /* Runtime data params for one stream */
  36. struct uac_rtd_params {
  37. struct snd_uac_chip *uac; /* parent chip */
  38. bool ep_enabled; /* if the ep is enabled */
  39. /* Size of the ring buffer */
  40. size_t dma_bytes;
  41. unsigned char *dma_area;
  42. struct snd_pcm_substream *ss;
  43. /* Ring buffer */
  44. ssize_t hw_ptr;
  45. void *rbuf;
  46. size_t period_size;
  47. unsigned max_psize; /* MaxPacketSize of endpoint */
  48. struct uac_req *ureq;
  49. spinlock_t lock;
  50. };
  51. struct snd_uac_chip {
  52. struct g_audio *audio_dev;
  53. struct uac_rtd_params p_prm;
  54. struct uac_rtd_params c_prm;
  55. struct snd_card *card;
  56. struct snd_pcm *pcm;
  57. /* timekeeping for the playback endpoint */
  58. unsigned int p_interval;
  59. unsigned int p_residue;
  60. /* pre-calculated values for playback iso completion */
  61. unsigned int p_pktsize;
  62. unsigned int p_pktsize_residue;
  63. unsigned int p_framesize;
  64. };
  65. static const struct snd_pcm_hardware uac_pcm_hardware = {
  66. .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER
  67. | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID
  68. | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME,
  69. .rates = SNDRV_PCM_RATE_CONTINUOUS,
  70. .periods_max = BUFF_SIZE_MAX / PRD_SIZE_MAX,
  71. .buffer_bytes_max = BUFF_SIZE_MAX,
  72. .period_bytes_max = PRD_SIZE_MAX,
  73. .periods_min = MIN_PERIODS,
  74. };
  75. static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req)
  76. {
  77. unsigned pending;
  78. unsigned long flags;
  79. unsigned int hw_ptr;
  80. bool update_alsa = false;
  81. int status = req->status;
  82. struct uac_req *ur = req->context;
  83. struct snd_pcm_substream *substream;
  84. struct uac_rtd_params *prm = ur->pp;
  85. struct snd_uac_chip *uac = prm->uac;
  86. /* i/f shutting down */
  87. if (!prm->ep_enabled || req->status == -ESHUTDOWN)
  88. return;
  89. /*
  90. * We can't really do much about bad xfers.
  91. * Afterall, the ISOCH xfers could fail legitimately.
  92. */
  93. if (status)
  94. pr_debug("%s: iso_complete status(%d) %d/%d\n",
  95. __func__, status, req->actual, req->length);
  96. substream = prm->ss;
  97. /* Do nothing if ALSA isn't active */
  98. if (!substream)
  99. goto exit;
  100. spin_lock_irqsave(&prm->lock, flags);
  101. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  102. /*
  103. * For each IN packet, take the quotient of the current data
  104. * rate and the endpoint's interval as the base packet size.
  105. * If there is a residue from this division, add it to the
  106. * residue accumulator.
  107. */
  108. req->length = uac->p_pktsize;
  109. uac->p_residue += uac->p_pktsize_residue;
  110. /*
  111. * Whenever there are more bytes in the accumulator than we
  112. * need to add one more sample frame, increase this packet's
  113. * size and decrease the accumulator.
  114. */
  115. if (uac->p_residue / uac->p_interval >= uac->p_framesize) {
  116. req->length += uac->p_framesize;
  117. uac->p_residue -= uac->p_framesize *
  118. uac->p_interval;
  119. }
  120. req->actual = req->length;
  121. }
  122. pending = prm->hw_ptr % prm->period_size;
  123. pending += req->actual;
  124. if (pending >= prm->period_size)
  125. update_alsa = true;
  126. hw_ptr = prm->hw_ptr;
  127. prm->hw_ptr = (prm->hw_ptr + req->actual) % prm->dma_bytes;
  128. spin_unlock_irqrestore(&prm->lock, flags);
  129. /* Pack USB load in ALSA ring buffer */
  130. pending = prm->dma_bytes - hw_ptr;
  131. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  132. if (unlikely(pending < req->actual)) {
  133. memcpy(req->buf, prm->dma_area + hw_ptr, pending);
  134. memcpy(req->buf + pending, prm->dma_area,
  135. req->actual - pending);
  136. } else {
  137. memcpy(req->buf, prm->dma_area + hw_ptr, req->actual);
  138. }
  139. } else {
  140. if (unlikely(pending < req->actual)) {
  141. memcpy(prm->dma_area + hw_ptr, req->buf, pending);
  142. memcpy(prm->dma_area, req->buf + pending,
  143. req->actual - pending);
  144. } else {
  145. memcpy(prm->dma_area + hw_ptr, req->buf, req->actual);
  146. }
  147. }
  148. exit:
  149. if (usb_ep_queue(ep, req, GFP_ATOMIC))
  150. dev_err(uac->card->dev, "%d Error!\n", __LINE__);
  151. if (update_alsa)
  152. snd_pcm_period_elapsed(substream);
  153. }
  154. static int uac_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  155. {
  156. struct snd_uac_chip *uac = snd_pcm_substream_chip(substream);
  157. struct uac_rtd_params *prm;
  158. struct g_audio *audio_dev;
  159. struct uac_params *params;
  160. unsigned long flags;
  161. int err = 0;
  162. audio_dev = uac->audio_dev;
  163. params = &audio_dev->params;
  164. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  165. prm = &uac->p_prm;
  166. else
  167. prm = &uac->c_prm;
  168. spin_lock_irqsave(&prm->lock, flags);
  169. /* Reset */
  170. prm->hw_ptr = 0;
  171. switch (cmd) {
  172. case SNDRV_PCM_TRIGGER_START:
  173. case SNDRV_PCM_TRIGGER_RESUME:
  174. prm->ss = substream;
  175. break;
  176. case SNDRV_PCM_TRIGGER_STOP:
  177. case SNDRV_PCM_TRIGGER_SUSPEND:
  178. prm->ss = NULL;
  179. break;
  180. default:
  181. err = -EINVAL;
  182. }
  183. spin_unlock_irqrestore(&prm->lock, flags);
  184. /* Clear buffer after Play stops */
  185. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && !prm->ss)
  186. memset(prm->rbuf, 0, prm->max_psize * params->req_number);
  187. return err;
  188. }
  189. static snd_pcm_uframes_t uac_pcm_pointer(struct snd_pcm_substream *substream)
  190. {
  191. struct snd_uac_chip *uac = snd_pcm_substream_chip(substream);
  192. struct uac_rtd_params *prm;
  193. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  194. prm = &uac->p_prm;
  195. else
  196. prm = &uac->c_prm;
  197. return bytes_to_frames(substream->runtime, prm->hw_ptr);
  198. }
  199. static int uac_pcm_hw_params(struct snd_pcm_substream *substream,
  200. struct snd_pcm_hw_params *hw_params)
  201. {
  202. struct snd_uac_chip *uac = snd_pcm_substream_chip(substream);
  203. struct uac_rtd_params *prm;
  204. int err;
  205. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  206. prm = &uac->p_prm;
  207. else
  208. prm = &uac->c_prm;
  209. err = snd_pcm_lib_malloc_pages(substream,
  210. params_buffer_bytes(hw_params));
  211. if (err >= 0) {
  212. prm->dma_bytes = substream->runtime->dma_bytes;
  213. prm->dma_area = substream->runtime->dma_area;
  214. prm->period_size = params_period_bytes(hw_params);
  215. }
  216. return err;
  217. }
  218. static int uac_pcm_hw_free(struct snd_pcm_substream *substream)
  219. {
  220. struct snd_uac_chip *uac = snd_pcm_substream_chip(substream);
  221. struct uac_rtd_params *prm;
  222. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  223. prm = &uac->p_prm;
  224. else
  225. prm = &uac->c_prm;
  226. prm->dma_area = NULL;
  227. prm->dma_bytes = 0;
  228. prm->period_size = 0;
  229. return snd_pcm_lib_free_pages(substream);
  230. }
  231. static int uac_pcm_open(struct snd_pcm_substream *substream)
  232. {
  233. struct snd_uac_chip *uac = snd_pcm_substream_chip(substream);
  234. struct snd_pcm_runtime *runtime = substream->runtime;
  235. struct g_audio *audio_dev;
  236. struct uac_params *params;
  237. int p_ssize, c_ssize;
  238. int p_srate, c_srate;
  239. int p_chmask, c_chmask;
  240. audio_dev = uac->audio_dev;
  241. params = &audio_dev->params;
  242. p_ssize = params->p_ssize;
  243. c_ssize = params->c_ssize;
  244. p_srate = params->p_srate;
  245. c_srate = params->c_srate;
  246. p_chmask = params->p_chmask;
  247. c_chmask = params->c_chmask;
  248. uac->p_residue = 0;
  249. runtime->hw = uac_pcm_hardware;
  250. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  251. spin_lock_init(&uac->p_prm.lock);
  252. runtime->hw.rate_min = p_srate;
  253. switch (p_ssize) {
  254. case 3:
  255. runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_3LE;
  256. break;
  257. case 4:
  258. runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE;
  259. break;
  260. default:
  261. runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
  262. break;
  263. }
  264. runtime->hw.channels_min = num_channels(p_chmask);
  265. runtime->hw.period_bytes_min = 2 * uac->p_prm.max_psize
  266. / runtime->hw.periods_min;
  267. } else {
  268. spin_lock_init(&uac->c_prm.lock);
  269. runtime->hw.rate_min = c_srate;
  270. switch (c_ssize) {
  271. case 3:
  272. runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_3LE;
  273. break;
  274. case 4:
  275. runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE;
  276. break;
  277. default:
  278. runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
  279. break;
  280. }
  281. runtime->hw.channels_min = num_channels(c_chmask);
  282. runtime->hw.period_bytes_min = 2 * uac->c_prm.max_psize
  283. / runtime->hw.periods_min;
  284. }
  285. runtime->hw.rate_max = runtime->hw.rate_min;
  286. runtime->hw.channels_max = runtime->hw.channels_min;
  287. snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
  288. return 0;
  289. }
  290. /* ALSA cries without these function pointers */
  291. static int uac_pcm_null(struct snd_pcm_substream *substream)
  292. {
  293. return 0;
  294. }
  295. static const struct snd_pcm_ops uac_pcm_ops = {
  296. .open = uac_pcm_open,
  297. .close = uac_pcm_null,
  298. .ioctl = snd_pcm_lib_ioctl,
  299. .hw_params = uac_pcm_hw_params,
  300. .hw_free = uac_pcm_hw_free,
  301. .trigger = uac_pcm_trigger,
  302. .pointer = uac_pcm_pointer,
  303. .prepare = uac_pcm_null,
  304. };
  305. static inline void free_ep(struct uac_rtd_params *prm, struct usb_ep *ep)
  306. {
  307. struct snd_uac_chip *uac = prm->uac;
  308. struct g_audio *audio_dev;
  309. struct uac_params *params;
  310. int i;
  311. if (!prm->ep_enabled)
  312. return;
  313. prm->ep_enabled = false;
  314. audio_dev = uac->audio_dev;
  315. params = &audio_dev->params;
  316. for (i = 0; i < params->req_number; i++) {
  317. if (prm->ureq[i].req) {
  318. usb_ep_dequeue(ep, prm->ureq[i].req);
  319. usb_ep_free_request(ep, prm->ureq[i].req);
  320. prm->ureq[i].req = NULL;
  321. }
  322. }
  323. if (usb_ep_disable(ep))
  324. dev_err(uac->card->dev, "%s:%d Error!\n", __func__, __LINE__);
  325. }
  326. int u_audio_start_capture(struct g_audio *audio_dev)
  327. {
  328. struct snd_uac_chip *uac = audio_dev->uac;
  329. struct usb_gadget *gadget = audio_dev->gadget;
  330. struct device *dev = &gadget->dev;
  331. struct usb_request *req;
  332. struct usb_ep *ep;
  333. struct uac_rtd_params *prm;
  334. struct uac_params *params = &audio_dev->params;
  335. int req_len, i;
  336. ep = audio_dev->out_ep;
  337. prm = &uac->c_prm;
  338. config_ep_by_speed(gadget, &audio_dev->func, ep);
  339. req_len = prm->max_psize;
  340. prm->ep_enabled = true;
  341. usb_ep_enable(ep);
  342. for (i = 0; i < params->req_number; i++) {
  343. if (!prm->ureq[i].req) {
  344. req = usb_ep_alloc_request(ep, GFP_ATOMIC);
  345. if (req == NULL)
  346. return -ENOMEM;
  347. prm->ureq[i].req = req;
  348. prm->ureq[i].pp = prm;
  349. req->zero = 0;
  350. req->context = &prm->ureq[i];
  351. req->length = req_len;
  352. req->complete = u_audio_iso_complete;
  353. req->buf = prm->rbuf + i * prm->max_psize;
  354. }
  355. if (usb_ep_queue(ep, prm->ureq[i].req, GFP_ATOMIC))
  356. dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
  357. }
  358. return 0;
  359. }
  360. EXPORT_SYMBOL_GPL(u_audio_start_capture);
  361. void u_audio_stop_capture(struct g_audio *audio_dev)
  362. {
  363. struct snd_uac_chip *uac = audio_dev->uac;
  364. free_ep(&uac->c_prm, audio_dev->out_ep);
  365. }
  366. EXPORT_SYMBOL_GPL(u_audio_stop_capture);
  367. int u_audio_start_playback(struct g_audio *audio_dev)
  368. {
  369. struct snd_uac_chip *uac = audio_dev->uac;
  370. struct usb_gadget *gadget = audio_dev->gadget;
  371. struct device *dev = &gadget->dev;
  372. struct usb_request *req;
  373. struct usb_ep *ep;
  374. struct uac_rtd_params *prm;
  375. struct uac_params *params = &audio_dev->params;
  376. unsigned int factor, rate;
  377. const struct usb_endpoint_descriptor *ep_desc;
  378. int req_len, i;
  379. ep = audio_dev->in_ep;
  380. prm = &uac->p_prm;
  381. config_ep_by_speed(gadget, &audio_dev->func, ep);
  382. ep_desc = ep->desc;
  383. /* pre-calculate the playback endpoint's interval */
  384. if (gadget->speed == USB_SPEED_FULL)
  385. factor = 1000;
  386. else
  387. factor = 8000;
  388. /* pre-compute some values for iso_complete() */
  389. uac->p_framesize = params->p_ssize *
  390. num_channels(params->p_chmask);
  391. rate = params->p_srate * uac->p_framesize;
  392. uac->p_interval = factor / (1 << (ep_desc->bInterval - 1));
  393. uac->p_pktsize = min_t(unsigned int, rate / uac->p_interval,
  394. prm->max_psize);
  395. if (uac->p_pktsize < prm->max_psize)
  396. uac->p_pktsize_residue = rate % uac->p_interval;
  397. else
  398. uac->p_pktsize_residue = 0;
  399. req_len = uac->p_pktsize;
  400. uac->p_residue = 0;
  401. prm->ep_enabled = true;
  402. usb_ep_enable(ep);
  403. for (i = 0; i < params->req_number; i++) {
  404. if (!prm->ureq[i].req) {
  405. req = usb_ep_alloc_request(ep, GFP_ATOMIC);
  406. if (req == NULL)
  407. return -ENOMEM;
  408. prm->ureq[i].req = req;
  409. prm->ureq[i].pp = prm;
  410. req->zero = 0;
  411. req->context = &prm->ureq[i];
  412. req->length = req_len;
  413. req->complete = u_audio_iso_complete;
  414. req->buf = prm->rbuf + i * prm->max_psize;
  415. }
  416. if (usb_ep_queue(ep, prm->ureq[i].req, GFP_ATOMIC))
  417. dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
  418. }
  419. return 0;
  420. }
  421. EXPORT_SYMBOL_GPL(u_audio_start_playback);
  422. void u_audio_stop_playback(struct g_audio *audio_dev)
  423. {
  424. struct snd_uac_chip *uac = audio_dev->uac;
  425. free_ep(&uac->p_prm, audio_dev->in_ep);
  426. }
  427. EXPORT_SYMBOL_GPL(u_audio_stop_playback);
  428. int g_audio_setup(struct g_audio *g_audio, const char *pcm_name,
  429. const char *card_name)
  430. {
  431. struct snd_uac_chip *uac;
  432. struct snd_card *card;
  433. struct snd_pcm *pcm;
  434. struct uac_params *params;
  435. int p_chmask, c_chmask;
  436. int err;
  437. if (!g_audio)
  438. return -EINVAL;
  439. uac = kzalloc(sizeof(*uac), GFP_KERNEL);
  440. if (!uac)
  441. return -ENOMEM;
  442. g_audio->uac = uac;
  443. uac->audio_dev = g_audio;
  444. params = &g_audio->params;
  445. p_chmask = params->p_chmask;
  446. c_chmask = params->c_chmask;
  447. if (c_chmask) {
  448. struct uac_rtd_params *prm = &uac->c_prm;
  449. uac->c_prm.uac = uac;
  450. prm->max_psize = g_audio->out_ep_maxpsize;
  451. prm->ureq = kcalloc(params->req_number, sizeof(struct uac_req),
  452. GFP_KERNEL);
  453. if (!prm->ureq) {
  454. err = -ENOMEM;
  455. goto fail;
  456. }
  457. prm->rbuf = kcalloc(params->req_number, prm->max_psize,
  458. GFP_KERNEL);
  459. if (!prm->rbuf) {
  460. prm->max_psize = 0;
  461. err = -ENOMEM;
  462. goto fail;
  463. }
  464. }
  465. if (p_chmask) {
  466. struct uac_rtd_params *prm = &uac->p_prm;
  467. uac->p_prm.uac = uac;
  468. prm->max_psize = g_audio->in_ep_maxpsize;
  469. prm->ureq = kcalloc(params->req_number, sizeof(struct uac_req),
  470. GFP_KERNEL);
  471. if (!prm->ureq) {
  472. err = -ENOMEM;
  473. goto fail;
  474. }
  475. prm->rbuf = kcalloc(params->req_number, prm->max_psize,
  476. GFP_KERNEL);
  477. if (!prm->rbuf) {
  478. prm->max_psize = 0;
  479. err = -ENOMEM;
  480. goto fail;
  481. }
  482. }
  483. /* Choose any slot, with no id */
  484. err = snd_card_new(&g_audio->gadget->dev,
  485. -1, NULL, THIS_MODULE, 0, &card);
  486. if (err < 0)
  487. goto fail;
  488. uac->card = card;
  489. /*
  490. * Create first PCM device
  491. * Create a substream only for non-zero channel streams
  492. */
  493. err = snd_pcm_new(uac->card, pcm_name, 0,
  494. p_chmask ? 1 : 0, c_chmask ? 1 : 0, &pcm);
  495. if (err < 0)
  496. goto snd_fail;
  497. strcpy(pcm->name, pcm_name);
  498. pcm->private_data = uac;
  499. uac->pcm = pcm;
  500. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &uac_pcm_ops);
  501. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &uac_pcm_ops);
  502. strcpy(card->driver, card_name);
  503. strcpy(card->shortname, card_name);
  504. sprintf(card->longname, "%s %i", card_name, card->dev->id);
  505. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  506. snd_dma_continuous_data(GFP_KERNEL), 0, BUFF_SIZE_MAX);
  507. err = snd_card_register(card);
  508. if (!err)
  509. return 0;
  510. snd_fail:
  511. snd_card_free(card);
  512. fail:
  513. kfree(uac->p_prm.ureq);
  514. kfree(uac->c_prm.ureq);
  515. kfree(uac->p_prm.rbuf);
  516. kfree(uac->c_prm.rbuf);
  517. kfree(uac);
  518. return err;
  519. }
  520. EXPORT_SYMBOL_GPL(g_audio_setup);
  521. void g_audio_cleanup(struct g_audio *g_audio)
  522. {
  523. struct snd_uac_chip *uac;
  524. struct snd_card *card;
  525. if (!g_audio || !g_audio->uac)
  526. return;
  527. uac = g_audio->uac;
  528. card = uac->card;
  529. if (card)
  530. snd_card_free(card);
  531. kfree(uac->p_prm.ureq);
  532. kfree(uac->c_prm.ureq);
  533. kfree(uac->p_prm.rbuf);
  534. kfree(uac->c_prm.rbuf);
  535. kfree(uac);
  536. }
  537. EXPORT_SYMBOL_GPL(g_audio_cleanup);
  538. MODULE_LICENSE("GPL");
  539. MODULE_DESCRIPTION("USB gadget \"ALSA sound card\" utilities");
  540. MODULE_AUTHOR("Ruslan Bilovol");