pcm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /*
  2. * Line 6 Linux USB driver
  3. *
  4. * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation, version 2.
  9. *
  10. */
  11. #include <linux/slab.h>
  12. #include <linux/export.h>
  13. #include <sound/core.h>
  14. #include <sound/control.h>
  15. #include <sound/pcm.h>
  16. #include <sound/pcm_params.h>
  17. #include "capture.h"
  18. #include "driver.h"
  19. #include "playback.h"
  20. /* impulse response volume controls */
  21. static int snd_line6_impulse_volume_info(struct snd_kcontrol *kcontrol,
  22. struct snd_ctl_elem_info *uinfo)
  23. {
  24. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  25. uinfo->count = 1;
  26. uinfo->value.integer.min = 0;
  27. uinfo->value.integer.max = 255;
  28. return 0;
  29. }
  30. static int snd_line6_impulse_volume_get(struct snd_kcontrol *kcontrol,
  31. struct snd_ctl_elem_value *ucontrol)
  32. {
  33. struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
  34. ucontrol->value.integer.value[0] = line6pcm->impulse_volume;
  35. return 0;
  36. }
  37. static int snd_line6_impulse_volume_put(struct snd_kcontrol *kcontrol,
  38. struct snd_ctl_elem_value *ucontrol)
  39. {
  40. struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
  41. int value = ucontrol->value.integer.value[0];
  42. int err;
  43. if (line6pcm->impulse_volume == value)
  44. return 0;
  45. line6pcm->impulse_volume = value;
  46. if (value > 0) {
  47. err = line6_pcm_acquire(line6pcm, LINE6_STREAM_IMPULSE, true);
  48. if (err < 0) {
  49. line6pcm->impulse_volume = 0;
  50. return err;
  51. }
  52. } else {
  53. line6_pcm_release(line6pcm, LINE6_STREAM_IMPULSE);
  54. }
  55. return 1;
  56. }
  57. /* impulse response period controls */
  58. static int snd_line6_impulse_period_info(struct snd_kcontrol *kcontrol,
  59. struct snd_ctl_elem_info *uinfo)
  60. {
  61. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  62. uinfo->count = 1;
  63. uinfo->value.integer.min = 0;
  64. uinfo->value.integer.max = 2000;
  65. return 0;
  66. }
  67. static int snd_line6_impulse_period_get(struct snd_kcontrol *kcontrol,
  68. struct snd_ctl_elem_value *ucontrol)
  69. {
  70. struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
  71. ucontrol->value.integer.value[0] = line6pcm->impulse_period;
  72. return 0;
  73. }
  74. static int snd_line6_impulse_period_put(struct snd_kcontrol *kcontrol,
  75. struct snd_ctl_elem_value *ucontrol)
  76. {
  77. struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
  78. int value = ucontrol->value.integer.value[0];
  79. if (line6pcm->impulse_period == value)
  80. return 0;
  81. line6pcm->impulse_period = value;
  82. return 1;
  83. }
  84. /*
  85. Unlink all currently active URBs.
  86. */
  87. static void line6_unlink_audio_urbs(struct snd_line6_pcm *line6pcm,
  88. struct line6_pcm_stream *pcms)
  89. {
  90. int i;
  91. for (i = 0; i < line6pcm->line6->iso_buffers; i++) {
  92. if (test_bit(i, &pcms->active_urbs)) {
  93. if (!test_and_set_bit(i, &pcms->unlink_urbs))
  94. usb_unlink_urb(pcms->urbs[i]);
  95. }
  96. }
  97. }
  98. /*
  99. Wait until unlinking of all currently active URBs has been finished.
  100. */
  101. static void line6_wait_clear_audio_urbs(struct snd_line6_pcm *line6pcm,
  102. struct line6_pcm_stream *pcms)
  103. {
  104. int timeout = HZ;
  105. int i;
  106. int alive;
  107. do {
  108. alive = 0;
  109. for (i = 0; i < line6pcm->line6->iso_buffers; i++) {
  110. if (test_bit(i, &pcms->active_urbs))
  111. alive++;
  112. }
  113. if (!alive)
  114. break;
  115. set_current_state(TASK_UNINTERRUPTIBLE);
  116. schedule_timeout(1);
  117. } while (--timeout > 0);
  118. if (alive)
  119. dev_err(line6pcm->line6->ifcdev,
  120. "timeout: still %d active urbs..\n", alive);
  121. }
  122. static inline struct line6_pcm_stream *
  123. get_stream(struct snd_line6_pcm *line6pcm, int direction)
  124. {
  125. return (direction == SNDRV_PCM_STREAM_PLAYBACK) ?
  126. &line6pcm->out : &line6pcm->in;
  127. }
  128. /* allocate a buffer if not opened yet;
  129. * call this in line6pcm.state_mutex
  130. */
  131. static int line6_buffer_acquire(struct snd_line6_pcm *line6pcm,
  132. struct line6_pcm_stream *pstr, int direction, int type)
  133. {
  134. const int pkt_size =
  135. (direction == SNDRV_PCM_STREAM_PLAYBACK) ?
  136. line6pcm->max_packet_size_out :
  137. line6pcm->max_packet_size_in;
  138. /* Invoked multiple times in a row so allocate once only */
  139. if (!test_and_set_bit(type, &pstr->opened) && !pstr->buffer) {
  140. pstr->buffer = kmalloc(line6pcm->line6->iso_buffers *
  141. LINE6_ISO_PACKETS * pkt_size, GFP_KERNEL);
  142. if (!pstr->buffer)
  143. return -ENOMEM;
  144. }
  145. return 0;
  146. }
  147. /* free a buffer if all streams are closed;
  148. * call this in line6pcm.state_mutex
  149. */
  150. static void line6_buffer_release(struct snd_line6_pcm *line6pcm,
  151. struct line6_pcm_stream *pstr, int type)
  152. {
  153. clear_bit(type, &pstr->opened);
  154. if (!pstr->opened) {
  155. line6_wait_clear_audio_urbs(line6pcm, pstr);
  156. kfree(pstr->buffer);
  157. pstr->buffer = NULL;
  158. }
  159. }
  160. /* start a PCM stream */
  161. static int line6_stream_start(struct snd_line6_pcm *line6pcm, int direction,
  162. int type)
  163. {
  164. unsigned long flags;
  165. struct line6_pcm_stream *pstr = get_stream(line6pcm, direction);
  166. int ret = 0;
  167. spin_lock_irqsave(&pstr->lock, flags);
  168. if (!test_and_set_bit(type, &pstr->running) &&
  169. !(pstr->active_urbs || pstr->unlink_urbs)) {
  170. pstr->count = 0;
  171. /* Submit all currently available URBs */
  172. if (direction == SNDRV_PCM_STREAM_PLAYBACK)
  173. ret = line6_submit_audio_out_all_urbs(line6pcm);
  174. else
  175. ret = line6_submit_audio_in_all_urbs(line6pcm);
  176. }
  177. if (ret < 0)
  178. clear_bit(type, &pstr->running);
  179. spin_unlock_irqrestore(&pstr->lock, flags);
  180. return ret;
  181. }
  182. /* stop a PCM stream; this doesn't sync with the unlinked URBs */
  183. static void line6_stream_stop(struct snd_line6_pcm *line6pcm, int direction,
  184. int type)
  185. {
  186. unsigned long flags;
  187. struct line6_pcm_stream *pstr = get_stream(line6pcm, direction);
  188. spin_lock_irqsave(&pstr->lock, flags);
  189. clear_bit(type, &pstr->running);
  190. if (!pstr->running) {
  191. spin_unlock_irqrestore(&pstr->lock, flags);
  192. line6_unlink_audio_urbs(line6pcm, pstr);
  193. spin_lock_irqsave(&pstr->lock, flags);
  194. if (direction == SNDRV_PCM_STREAM_CAPTURE) {
  195. line6pcm->prev_fbuf = NULL;
  196. line6pcm->prev_fsize = 0;
  197. }
  198. }
  199. spin_unlock_irqrestore(&pstr->lock, flags);
  200. }
  201. /* common PCM trigger callback */
  202. int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd)
  203. {
  204. struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
  205. struct snd_pcm_substream *s;
  206. int err;
  207. clear_bit(LINE6_FLAG_PREPARED, &line6pcm->flags);
  208. snd_pcm_group_for_each_entry(s, substream) {
  209. if (s->pcm->card != substream->pcm->card)
  210. continue;
  211. switch (cmd) {
  212. case SNDRV_PCM_TRIGGER_START:
  213. case SNDRV_PCM_TRIGGER_RESUME:
  214. if (s->stream == SNDRV_PCM_STREAM_CAPTURE &&
  215. (line6pcm->line6->properties->capabilities &
  216. LINE6_CAP_IN_NEEDS_OUT)) {
  217. err = line6_stream_start(line6pcm, SNDRV_PCM_STREAM_PLAYBACK,
  218. LINE6_STREAM_CAPTURE_HELPER);
  219. if (err < 0)
  220. return err;
  221. }
  222. err = line6_stream_start(line6pcm, s->stream,
  223. LINE6_STREAM_PCM);
  224. if (err < 0)
  225. return err;
  226. break;
  227. case SNDRV_PCM_TRIGGER_STOP:
  228. case SNDRV_PCM_TRIGGER_SUSPEND:
  229. if (s->stream == SNDRV_PCM_STREAM_CAPTURE &&
  230. (line6pcm->line6->properties->capabilities &
  231. LINE6_CAP_IN_NEEDS_OUT)) {
  232. line6_stream_stop(line6pcm, SNDRV_PCM_STREAM_PLAYBACK,
  233. LINE6_STREAM_CAPTURE_HELPER);
  234. }
  235. line6_stream_stop(line6pcm, s->stream,
  236. LINE6_STREAM_PCM);
  237. break;
  238. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  239. if (s->stream != SNDRV_PCM_STREAM_PLAYBACK)
  240. return -EINVAL;
  241. set_bit(LINE6_FLAG_PAUSE_PLAYBACK, &line6pcm->flags);
  242. break;
  243. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  244. if (s->stream != SNDRV_PCM_STREAM_PLAYBACK)
  245. return -EINVAL;
  246. clear_bit(LINE6_FLAG_PAUSE_PLAYBACK, &line6pcm->flags);
  247. break;
  248. default:
  249. return -EINVAL;
  250. }
  251. }
  252. return 0;
  253. }
  254. /* common PCM pointer callback */
  255. snd_pcm_uframes_t snd_line6_pointer(struct snd_pcm_substream *substream)
  256. {
  257. struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
  258. struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream);
  259. return pstr->pos_done;
  260. }
  261. /* Acquire and optionally start duplex streams:
  262. * type is either LINE6_STREAM_IMPULSE or LINE6_STREAM_MONITOR
  263. */
  264. int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type, bool start)
  265. {
  266. struct line6_pcm_stream *pstr;
  267. int ret = 0, dir;
  268. /* TODO: We should assert SNDRV_PCM_STREAM_PLAYBACK/CAPTURE == 0/1 */
  269. mutex_lock(&line6pcm->state_mutex);
  270. for (dir = 0; dir < 2; dir++) {
  271. pstr = get_stream(line6pcm, dir);
  272. ret = line6_buffer_acquire(line6pcm, pstr, dir, type);
  273. if (ret < 0)
  274. goto error;
  275. if (!pstr->running)
  276. line6_wait_clear_audio_urbs(line6pcm, pstr);
  277. }
  278. if (start) {
  279. for (dir = 0; dir < 2; dir++) {
  280. ret = line6_stream_start(line6pcm, dir, type);
  281. if (ret < 0)
  282. goto error;
  283. }
  284. }
  285. error:
  286. mutex_unlock(&line6pcm->state_mutex);
  287. if (ret < 0)
  288. line6_pcm_release(line6pcm, type);
  289. return ret;
  290. }
  291. EXPORT_SYMBOL_GPL(line6_pcm_acquire);
  292. /* Stop and release duplex streams */
  293. void line6_pcm_release(struct snd_line6_pcm *line6pcm, int type)
  294. {
  295. struct line6_pcm_stream *pstr;
  296. int dir;
  297. mutex_lock(&line6pcm->state_mutex);
  298. for (dir = 0; dir < 2; dir++)
  299. line6_stream_stop(line6pcm, dir, type);
  300. for (dir = 0; dir < 2; dir++) {
  301. pstr = get_stream(line6pcm, dir);
  302. line6_buffer_release(line6pcm, pstr, type);
  303. }
  304. mutex_unlock(&line6pcm->state_mutex);
  305. }
  306. EXPORT_SYMBOL_GPL(line6_pcm_release);
  307. /* common PCM hw_params callback */
  308. int snd_line6_hw_params(struct snd_pcm_substream *substream,
  309. struct snd_pcm_hw_params *hw_params)
  310. {
  311. int ret;
  312. struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
  313. struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream);
  314. mutex_lock(&line6pcm->state_mutex);
  315. ret = line6_buffer_acquire(line6pcm, pstr, substream->stream,
  316. LINE6_STREAM_PCM);
  317. if (ret < 0)
  318. goto error;
  319. ret = snd_pcm_lib_malloc_pages(substream,
  320. params_buffer_bytes(hw_params));
  321. if (ret < 0) {
  322. line6_buffer_release(line6pcm, pstr, LINE6_STREAM_PCM);
  323. goto error;
  324. }
  325. pstr->period = params_period_bytes(hw_params);
  326. error:
  327. mutex_unlock(&line6pcm->state_mutex);
  328. return ret;
  329. }
  330. /* common PCM hw_free callback */
  331. int snd_line6_hw_free(struct snd_pcm_substream *substream)
  332. {
  333. struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
  334. struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream);
  335. mutex_lock(&line6pcm->state_mutex);
  336. line6_buffer_release(line6pcm, pstr, LINE6_STREAM_PCM);
  337. mutex_unlock(&line6pcm->state_mutex);
  338. return snd_pcm_lib_free_pages(substream);
  339. }
  340. /* control info callback */
  341. static int snd_line6_control_playback_info(struct snd_kcontrol *kcontrol,
  342. struct snd_ctl_elem_info *uinfo)
  343. {
  344. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  345. uinfo->count = 2;
  346. uinfo->value.integer.min = 0;
  347. uinfo->value.integer.max = 256;
  348. return 0;
  349. }
  350. /* control get callback */
  351. static int snd_line6_control_playback_get(struct snd_kcontrol *kcontrol,
  352. struct snd_ctl_elem_value *ucontrol)
  353. {
  354. int i;
  355. struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
  356. for (i = 0; i < 2; i++)
  357. ucontrol->value.integer.value[i] = line6pcm->volume_playback[i];
  358. return 0;
  359. }
  360. /* control put callback */
  361. static int snd_line6_control_playback_put(struct snd_kcontrol *kcontrol,
  362. struct snd_ctl_elem_value *ucontrol)
  363. {
  364. int i, changed = 0;
  365. struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
  366. for (i = 0; i < 2; i++)
  367. if (line6pcm->volume_playback[i] !=
  368. ucontrol->value.integer.value[i]) {
  369. line6pcm->volume_playback[i] =
  370. ucontrol->value.integer.value[i];
  371. changed = 1;
  372. }
  373. return changed;
  374. }
  375. /* control definition */
  376. static struct snd_kcontrol_new line6_controls[] = {
  377. {
  378. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  379. .name = "PCM Playback Volume",
  380. .info = snd_line6_control_playback_info,
  381. .get = snd_line6_control_playback_get,
  382. .put = snd_line6_control_playback_put
  383. },
  384. {
  385. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  386. .name = "Impulse Response Volume",
  387. .info = snd_line6_impulse_volume_info,
  388. .get = snd_line6_impulse_volume_get,
  389. .put = snd_line6_impulse_volume_put
  390. },
  391. {
  392. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  393. .name = "Impulse Response Period",
  394. .info = snd_line6_impulse_period_info,
  395. .get = snd_line6_impulse_period_get,
  396. .put = snd_line6_impulse_period_put
  397. },
  398. };
  399. /*
  400. Cleanup the PCM device.
  401. */
  402. static void cleanup_urbs(struct line6_pcm_stream *pcms, int iso_buffers)
  403. {
  404. int i;
  405. /* Most likely impossible in current code... */
  406. if (pcms->urbs == NULL)
  407. return;
  408. for (i = 0; i < iso_buffers; i++) {
  409. if (pcms->urbs[i]) {
  410. usb_kill_urb(pcms->urbs[i]);
  411. usb_free_urb(pcms->urbs[i]);
  412. }
  413. }
  414. kfree(pcms->urbs);
  415. pcms->urbs = NULL;
  416. }
  417. static void line6_cleanup_pcm(struct snd_pcm *pcm)
  418. {
  419. struct snd_line6_pcm *line6pcm = snd_pcm_chip(pcm);
  420. cleanup_urbs(&line6pcm->out, line6pcm->line6->iso_buffers);
  421. cleanup_urbs(&line6pcm->in, line6pcm->line6->iso_buffers);
  422. kfree(line6pcm);
  423. }
  424. /* create a PCM device */
  425. static int snd_line6_new_pcm(struct usb_line6 *line6, struct snd_pcm **pcm_ret)
  426. {
  427. struct snd_pcm *pcm;
  428. int err;
  429. err = snd_pcm_new(line6->card, (char *)line6->properties->name,
  430. 0, 1, 1, pcm_ret);
  431. if (err < 0)
  432. return err;
  433. pcm = *pcm_ret;
  434. strcpy(pcm->name, line6->properties->name);
  435. /* set operators */
  436. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  437. &snd_line6_playback_ops);
  438. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_line6_capture_ops);
  439. /* pre-allocation of buffers */
  440. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  441. snd_dma_continuous_data
  442. (GFP_KERNEL), 64 * 1024,
  443. 128 * 1024);
  444. return 0;
  445. }
  446. /*
  447. Sync with PCM stream stops.
  448. */
  449. void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm)
  450. {
  451. line6_unlink_audio_urbs(line6pcm, &line6pcm->out);
  452. line6_unlink_audio_urbs(line6pcm, &line6pcm->in);
  453. line6_wait_clear_audio_urbs(line6pcm, &line6pcm->out);
  454. line6_wait_clear_audio_urbs(line6pcm, &line6pcm->in);
  455. }
  456. /*
  457. Create and register the PCM device and mixer entries.
  458. Create URBs for playback and capture.
  459. */
  460. int line6_init_pcm(struct usb_line6 *line6,
  461. struct line6_pcm_properties *properties)
  462. {
  463. int i, err;
  464. unsigned ep_read = line6->properties->ep_audio_r;
  465. unsigned ep_write = line6->properties->ep_audio_w;
  466. struct snd_pcm *pcm;
  467. struct snd_line6_pcm *line6pcm;
  468. if (!(line6->properties->capabilities & LINE6_CAP_PCM))
  469. return 0; /* skip PCM initialization and report success */
  470. err = snd_line6_new_pcm(line6, &pcm);
  471. if (err < 0)
  472. return err;
  473. line6pcm = kzalloc(sizeof(*line6pcm), GFP_KERNEL);
  474. if (!line6pcm)
  475. return -ENOMEM;
  476. mutex_init(&line6pcm->state_mutex);
  477. line6pcm->pcm = pcm;
  478. line6pcm->properties = properties;
  479. line6pcm->volume_playback[0] = line6pcm->volume_playback[1] = 255;
  480. line6pcm->volume_monitor = 255;
  481. line6pcm->line6 = line6;
  482. line6pcm->max_packet_size_in =
  483. usb_maxpacket(line6->usbdev,
  484. usb_rcvisocpipe(line6->usbdev, ep_read), 0);
  485. line6pcm->max_packet_size_out =
  486. usb_maxpacket(line6->usbdev,
  487. usb_sndisocpipe(line6->usbdev, ep_write), 1);
  488. spin_lock_init(&line6pcm->out.lock);
  489. spin_lock_init(&line6pcm->in.lock);
  490. line6pcm->impulse_period = LINE6_IMPULSE_DEFAULT_PERIOD;
  491. line6->line6pcm = line6pcm;
  492. pcm->private_data = line6pcm;
  493. pcm->private_free = line6_cleanup_pcm;
  494. err = line6_create_audio_out_urbs(line6pcm);
  495. if (err < 0)
  496. return err;
  497. err = line6_create_audio_in_urbs(line6pcm);
  498. if (err < 0)
  499. return err;
  500. /* mixer: */
  501. for (i = 0; i < ARRAY_SIZE(line6_controls); i++) {
  502. err = snd_ctl_add(line6->card,
  503. snd_ctl_new1(&line6_controls[i], line6pcm));
  504. if (err < 0)
  505. return err;
  506. }
  507. return 0;
  508. }
  509. EXPORT_SYMBOL_GPL(line6_init_pcm);
  510. /* prepare pcm callback */
  511. int snd_line6_prepare(struct snd_pcm_substream *substream)
  512. {
  513. struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
  514. struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream);
  515. mutex_lock(&line6pcm->state_mutex);
  516. if (!pstr->running)
  517. line6_wait_clear_audio_urbs(line6pcm, pstr);
  518. if (!test_and_set_bit(LINE6_FLAG_PREPARED, &line6pcm->flags)) {
  519. line6pcm->out.count = 0;
  520. line6pcm->out.pos = 0;
  521. line6pcm->out.pos_done = 0;
  522. line6pcm->out.bytes = 0;
  523. line6pcm->in.count = 0;
  524. line6pcm->in.pos_done = 0;
  525. line6pcm->in.bytes = 0;
  526. }
  527. mutex_unlock(&line6pcm->state_mutex);
  528. return 0;
  529. }