most_snd.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * sound.c - Sound component for Mostcore
  4. *
  5. * Copyright (C) 2015 Microchip Technology Germany II GmbH & Co. KG
  6. */
  7. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  8. #include <linux/module.h>
  9. #include <linux/printk.h>
  10. #include <linux/kernel.h>
  11. #include <linux/slab.h>
  12. #include <linux/init.h>
  13. #include <sound/core.h>
  14. #include <sound/pcm.h>
  15. #include <sound/pcm_params.h>
  16. #include <linux/sched.h>
  17. #include <linux/kthread.h>
  18. #include <linux/most.h>
  19. #define DRIVER_NAME "sound"
  20. #define STRING_SIZE 80
  21. static struct most_component comp;
  22. /**
  23. * struct channel - private structure to keep channel specific data
  24. * @substream: stores the substream structure
  25. * @iface: interface for which the channel belongs to
  26. * @cfg: channel configuration
  27. * @card: registered sound card
  28. * @list: list for private use
  29. * @id: channel index
  30. * @period_pos: current period position (ring buffer)
  31. * @buffer_pos: current buffer position (ring buffer)
  32. * @is_stream_running: identifies whether a stream is running or not
  33. * @opened: set when the stream is opened
  34. * @playback_task: playback thread
  35. * @playback_waitq: waitq used by playback thread
  36. */
  37. struct channel {
  38. struct snd_pcm_substream *substream;
  39. struct snd_pcm_hardware pcm_hardware;
  40. struct most_interface *iface;
  41. struct most_channel_config *cfg;
  42. struct snd_card *card;
  43. struct list_head list;
  44. int id;
  45. unsigned int period_pos;
  46. unsigned int buffer_pos;
  47. bool is_stream_running;
  48. struct task_struct *playback_task;
  49. wait_queue_head_t playback_waitq;
  50. void (*copy_fn)(void *alsa, void *most, unsigned int bytes);
  51. };
  52. struct sound_adapter {
  53. struct list_head dev_list;
  54. struct most_interface *iface;
  55. struct snd_card *card;
  56. struct list_head list;
  57. bool registered;
  58. int pcm_dev_idx;
  59. };
  60. static struct list_head adpt_list;
  61. #define MOST_PCM_INFO (SNDRV_PCM_INFO_MMAP | \
  62. SNDRV_PCM_INFO_MMAP_VALID | \
  63. SNDRV_PCM_INFO_BATCH | \
  64. SNDRV_PCM_INFO_INTERLEAVED | \
  65. SNDRV_PCM_INFO_BLOCK_TRANSFER)
  66. static void swap_copy16(u16 *dest, const u16 *source, unsigned int bytes)
  67. {
  68. unsigned int i = 0;
  69. while (i < (bytes / 2)) {
  70. dest[i] = swab16(source[i]);
  71. i++;
  72. }
  73. }
  74. static void swap_copy24(u8 *dest, const u8 *source, unsigned int bytes)
  75. {
  76. unsigned int i = 0;
  77. if (bytes < 2)
  78. return;
  79. while (i < bytes - 2) {
  80. dest[i] = source[i + 2];
  81. dest[i + 1] = source[i + 1];
  82. dest[i + 2] = source[i];
  83. i += 3;
  84. }
  85. }
  86. static void swap_copy32(u32 *dest, const u32 *source, unsigned int bytes)
  87. {
  88. unsigned int i = 0;
  89. while (i < bytes / 4) {
  90. dest[i] = swab32(source[i]);
  91. i++;
  92. }
  93. }
  94. static void alsa_to_most_memcpy(void *alsa, void *most, unsigned int bytes)
  95. {
  96. memcpy(most, alsa, bytes);
  97. }
  98. static void alsa_to_most_copy16(void *alsa, void *most, unsigned int bytes)
  99. {
  100. swap_copy16(most, alsa, bytes);
  101. }
  102. static void alsa_to_most_copy24(void *alsa, void *most, unsigned int bytes)
  103. {
  104. swap_copy24(most, alsa, bytes);
  105. }
  106. static void alsa_to_most_copy32(void *alsa, void *most, unsigned int bytes)
  107. {
  108. swap_copy32(most, alsa, bytes);
  109. }
  110. static void most_to_alsa_memcpy(void *alsa, void *most, unsigned int bytes)
  111. {
  112. memcpy(alsa, most, bytes);
  113. }
  114. static void most_to_alsa_copy16(void *alsa, void *most, unsigned int bytes)
  115. {
  116. swap_copy16(alsa, most, bytes);
  117. }
  118. static void most_to_alsa_copy24(void *alsa, void *most, unsigned int bytes)
  119. {
  120. swap_copy24(alsa, most, bytes);
  121. }
  122. static void most_to_alsa_copy32(void *alsa, void *most, unsigned int bytes)
  123. {
  124. swap_copy32(alsa, most, bytes);
  125. }
  126. /**
  127. * get_channel - get pointer to channel
  128. * @iface: interface structure
  129. * @channel_id: channel ID
  130. *
  131. * This traverses the channel list and returns the channel matching the
  132. * ID and interface.
  133. *
  134. * Returns pointer to channel on success or NULL otherwise.
  135. */
  136. static struct channel *get_channel(struct most_interface *iface,
  137. int channel_id)
  138. {
  139. struct sound_adapter *adpt = iface->priv;
  140. struct channel *channel;
  141. list_for_each_entry(channel, &adpt->dev_list, list) {
  142. if ((channel->iface == iface) && (channel->id == channel_id))
  143. return channel;
  144. }
  145. return NULL;
  146. }
  147. /**
  148. * copy_data - implements data copying function
  149. * @channel: channel
  150. * @mbo: MBO from core
  151. *
  152. * Copy data from/to ring buffer to/from MBO and update the buffer position
  153. */
  154. static bool copy_data(struct channel *channel, struct mbo *mbo)
  155. {
  156. struct snd_pcm_runtime *const runtime = channel->substream->runtime;
  157. unsigned int const frame_bytes = channel->cfg->subbuffer_size;
  158. unsigned int const buffer_size = runtime->buffer_size;
  159. unsigned int frames;
  160. unsigned int fr0;
  161. if (channel->cfg->direction & MOST_CH_RX)
  162. frames = mbo->processed_length / frame_bytes;
  163. else
  164. frames = mbo->buffer_length / frame_bytes;
  165. fr0 = min(buffer_size - channel->buffer_pos, frames);
  166. channel->copy_fn(runtime->dma_area + channel->buffer_pos * frame_bytes,
  167. mbo->virt_address,
  168. fr0 * frame_bytes);
  169. if (frames > fr0) {
  170. /* wrap around at end of ring buffer */
  171. channel->copy_fn(runtime->dma_area,
  172. mbo->virt_address + fr0 * frame_bytes,
  173. (frames - fr0) * frame_bytes);
  174. }
  175. channel->buffer_pos += frames;
  176. if (channel->buffer_pos >= buffer_size)
  177. channel->buffer_pos -= buffer_size;
  178. channel->period_pos += frames;
  179. if (channel->period_pos >= runtime->period_size) {
  180. channel->period_pos -= runtime->period_size;
  181. return true;
  182. }
  183. return false;
  184. }
  185. /**
  186. * playback_thread - function implements the playback thread
  187. * @data: private data
  188. *
  189. * Thread which does the playback functionality in a loop. It waits for a free
  190. * MBO from mostcore for a particular channel and copy the data from ring buffer
  191. * to MBO. Submit the MBO back to mostcore, after copying the data.
  192. *
  193. * Returns 0 on success or error code otherwise.
  194. */
  195. static int playback_thread(void *data)
  196. {
  197. struct channel *const channel = data;
  198. while (!kthread_should_stop()) {
  199. struct mbo *mbo = NULL;
  200. bool period_elapsed = false;
  201. wait_event_interruptible(
  202. channel->playback_waitq,
  203. kthread_should_stop() ||
  204. (channel->is_stream_running &&
  205. (mbo = most_get_mbo(channel->iface, channel->id,
  206. &comp))));
  207. if (!mbo)
  208. continue;
  209. if (channel->is_stream_running)
  210. period_elapsed = copy_data(channel, mbo);
  211. else
  212. memset(mbo->virt_address, 0, mbo->buffer_length);
  213. most_submit_mbo(mbo);
  214. if (period_elapsed)
  215. snd_pcm_period_elapsed(channel->substream);
  216. }
  217. return 0;
  218. }
  219. /**
  220. * pcm_open - implements open callback function for PCM middle layer
  221. * @substream: pointer to ALSA PCM substream
  222. *
  223. * This is called when a PCM substream is opened. At least, the function should
  224. * initialize the runtime->hw record.
  225. *
  226. * Returns 0 on success or error code otherwise.
  227. */
  228. static int pcm_open(struct snd_pcm_substream *substream)
  229. {
  230. struct channel *channel = substream->private_data;
  231. struct snd_pcm_runtime *runtime = substream->runtime;
  232. struct most_channel_config *cfg = channel->cfg;
  233. int ret;
  234. channel->substream = substream;
  235. if (cfg->direction == MOST_CH_TX) {
  236. channel->playback_task = kthread_run(playback_thread, channel,
  237. "most_audio_playback");
  238. if (IS_ERR(channel->playback_task)) {
  239. pr_err("Couldn't start thread\n");
  240. return PTR_ERR(channel->playback_task);
  241. }
  242. }
  243. ret = most_start_channel(channel->iface, channel->id, &comp);
  244. if (ret) {
  245. pr_err("most_start_channel() failed!\n");
  246. if (cfg->direction == MOST_CH_TX)
  247. kthread_stop(channel->playback_task);
  248. return ret;
  249. }
  250. runtime->hw = channel->pcm_hardware;
  251. return 0;
  252. }
  253. /**
  254. * pcm_close - implements close callback function for PCM middle layer
  255. * @substream: sub-stream pointer
  256. *
  257. * Obviously, this is called when a PCM substream is closed. Any private
  258. * instance for a PCM substream allocated in the open callback will be
  259. * released here.
  260. *
  261. * Returns 0 on success or error code otherwise.
  262. */
  263. static int pcm_close(struct snd_pcm_substream *substream)
  264. {
  265. struct channel *channel = substream->private_data;
  266. if (channel->cfg->direction == MOST_CH_TX)
  267. kthread_stop(channel->playback_task);
  268. most_stop_channel(channel->iface, channel->id, &comp);
  269. return 0;
  270. }
  271. /**
  272. * pcm_prepare - implements prepare callback function for PCM middle layer
  273. * @substream: substream pointer
  274. *
  275. * This callback is called when the PCM is "prepared". Format rate, sample rate,
  276. * etc., can be set here. This callback can be called many times at each setup.
  277. *
  278. * Returns 0 on success or error code otherwise.
  279. */
  280. static int pcm_prepare(struct snd_pcm_substream *substream)
  281. {
  282. struct channel *channel = substream->private_data;
  283. struct snd_pcm_runtime *runtime = substream->runtime;
  284. struct most_channel_config *cfg = channel->cfg;
  285. int width = snd_pcm_format_physical_width(runtime->format);
  286. channel->copy_fn = NULL;
  287. if (cfg->direction == MOST_CH_TX) {
  288. if (snd_pcm_format_big_endian(runtime->format) || width == 8)
  289. channel->copy_fn = alsa_to_most_memcpy;
  290. else if (width == 16)
  291. channel->copy_fn = alsa_to_most_copy16;
  292. else if (width == 24)
  293. channel->copy_fn = alsa_to_most_copy24;
  294. else if (width == 32)
  295. channel->copy_fn = alsa_to_most_copy32;
  296. } else {
  297. if (snd_pcm_format_big_endian(runtime->format) || width == 8)
  298. channel->copy_fn = most_to_alsa_memcpy;
  299. else if (width == 16)
  300. channel->copy_fn = most_to_alsa_copy16;
  301. else if (width == 24)
  302. channel->copy_fn = most_to_alsa_copy24;
  303. else if (width == 32)
  304. channel->copy_fn = most_to_alsa_copy32;
  305. }
  306. if (!channel->copy_fn)
  307. return -EINVAL;
  308. channel->period_pos = 0;
  309. channel->buffer_pos = 0;
  310. return 0;
  311. }
  312. /**
  313. * pcm_trigger - implements trigger callback function for PCM middle layer
  314. * @substream: substream pointer
  315. * @cmd: action to perform
  316. *
  317. * This is called when the PCM is started, stopped or paused. The action will be
  318. * specified in the second argument, SNDRV_PCM_TRIGGER_XXX
  319. *
  320. * Returns 0 on success or error code otherwise.
  321. */
  322. static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  323. {
  324. struct channel *channel = substream->private_data;
  325. switch (cmd) {
  326. case SNDRV_PCM_TRIGGER_START:
  327. channel->is_stream_running = true;
  328. wake_up_interruptible(&channel->playback_waitq);
  329. return 0;
  330. case SNDRV_PCM_TRIGGER_STOP:
  331. channel->is_stream_running = false;
  332. return 0;
  333. default:
  334. return -EINVAL;
  335. }
  336. return 0;
  337. }
  338. /**
  339. * pcm_pointer - implements pointer callback function for PCM middle layer
  340. * @substream: substream pointer
  341. *
  342. * This callback is called when the PCM middle layer inquires the current
  343. * hardware position on the buffer. The position must be returned in frames,
  344. * ranging from 0 to buffer_size-1.
  345. */
  346. static snd_pcm_uframes_t pcm_pointer(struct snd_pcm_substream *substream)
  347. {
  348. struct channel *channel = substream->private_data;
  349. return channel->buffer_pos;
  350. }
  351. /**
  352. * Initialization of struct snd_pcm_ops
  353. */
  354. static const struct snd_pcm_ops pcm_ops = {
  355. .open = pcm_open,
  356. .close = pcm_close,
  357. .prepare = pcm_prepare,
  358. .trigger = pcm_trigger,
  359. .pointer = pcm_pointer,
  360. };
  361. static int split_arg_list(char *buf, u16 *ch_num, char **sample_res)
  362. {
  363. char *num;
  364. int ret;
  365. num = strsep(&buf, "x");
  366. if (!num)
  367. goto err;
  368. ret = kstrtou16(num, 0, ch_num);
  369. if (ret)
  370. goto err;
  371. *sample_res = strsep(&buf, ".\n");
  372. if (!*sample_res)
  373. goto err;
  374. return 0;
  375. err:
  376. pr_err("Bad PCM format\n");
  377. return -EINVAL;
  378. }
  379. static const struct sample_resolution_info {
  380. const char *sample_res;
  381. int bytes;
  382. u64 formats;
  383. } sinfo[] = {
  384. { "8", 1, SNDRV_PCM_FMTBIT_S8 },
  385. { "16", 2, SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE },
  386. { "24", 3, SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE },
  387. { "32", 4, SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE },
  388. };
  389. static int audio_set_hw_params(struct snd_pcm_hardware *pcm_hw,
  390. u16 ch_num, char *sample_res,
  391. struct most_channel_config *cfg)
  392. {
  393. int i;
  394. for (i = 0; i < ARRAY_SIZE(sinfo); i++) {
  395. if (!strcmp(sample_res, sinfo[i].sample_res))
  396. goto found;
  397. }
  398. pr_err("Unsupported PCM format\n");
  399. return -EINVAL;
  400. found:
  401. if (!ch_num) {
  402. pr_err("Bad number of channels\n");
  403. return -EINVAL;
  404. }
  405. if (cfg->subbuffer_size != ch_num * sinfo[i].bytes) {
  406. pr_err("Audio resolution doesn't fit subbuffer size\n");
  407. return -EINVAL;
  408. }
  409. pcm_hw->info = MOST_PCM_INFO;
  410. pcm_hw->rates = SNDRV_PCM_RATE_48000;
  411. pcm_hw->rate_min = 48000;
  412. pcm_hw->rate_max = 48000;
  413. pcm_hw->buffer_bytes_max = cfg->num_buffers * cfg->buffer_size;
  414. pcm_hw->period_bytes_min = cfg->buffer_size;
  415. pcm_hw->period_bytes_max = cfg->buffer_size;
  416. pcm_hw->periods_min = 1;
  417. pcm_hw->periods_max = cfg->num_buffers;
  418. pcm_hw->channels_min = ch_num;
  419. pcm_hw->channels_max = ch_num;
  420. pcm_hw->formats = sinfo[i].formats;
  421. return 0;
  422. }
  423. static void release_adapter(struct sound_adapter *adpt)
  424. {
  425. struct channel *channel, *tmp;
  426. list_for_each_entry_safe(channel, tmp, &adpt->dev_list, list) {
  427. list_del(&channel->list);
  428. kfree(channel);
  429. }
  430. if (adpt->card)
  431. snd_card_free(adpt->card);
  432. list_del(&adpt->list);
  433. kfree(adpt);
  434. }
  435. /**
  436. * audio_probe_channel - probe function of the driver module
  437. * @iface: pointer to interface instance
  438. * @channel_id: channel index/ID
  439. * @cfg: pointer to actual channel configuration
  440. * @arg_list: string that provides the name of the device to be created in /dev
  441. * plus the desired audio resolution
  442. *
  443. * Creates sound card, pcm device, sets pcm ops and registers sound card.
  444. *
  445. * Returns 0 on success or error code otherwise.
  446. */
  447. static int audio_probe_channel(struct most_interface *iface, int channel_id,
  448. struct most_channel_config *cfg,
  449. char *device_name, char *arg_list)
  450. {
  451. struct channel *channel;
  452. struct sound_adapter *adpt;
  453. struct snd_pcm *pcm;
  454. int playback_count = 0;
  455. int capture_count = 0;
  456. int ret;
  457. int direction;
  458. u16 ch_num;
  459. char *sample_res;
  460. char arg_list_cpy[STRING_SIZE];
  461. if (cfg->data_type != MOST_CH_SYNC) {
  462. pr_err("Incompatible channel type\n");
  463. return -EINVAL;
  464. }
  465. strscpy(arg_list_cpy, arg_list, STRING_SIZE);
  466. ret = split_arg_list(arg_list_cpy, &ch_num, &sample_res);
  467. if (ret < 0)
  468. return ret;
  469. list_for_each_entry(adpt, &adpt_list, list) {
  470. if (adpt->iface != iface)
  471. continue;
  472. if (adpt->registered)
  473. return -ENOSPC;
  474. adpt->pcm_dev_idx++;
  475. goto skip_adpt_alloc;
  476. }
  477. adpt = kzalloc(sizeof(*adpt), GFP_KERNEL);
  478. if (!adpt)
  479. return -ENOMEM;
  480. adpt->iface = iface;
  481. INIT_LIST_HEAD(&adpt->dev_list);
  482. iface->priv = adpt;
  483. list_add_tail(&adpt->list, &adpt_list);
  484. ret = snd_card_new(iface->driver_dev, -1, "INIC", THIS_MODULE,
  485. sizeof(*channel), &adpt->card);
  486. if (ret < 0)
  487. goto err_free_adpt;
  488. snprintf(adpt->card->driver, sizeof(adpt->card->driver),
  489. "%s", DRIVER_NAME);
  490. snprintf(adpt->card->shortname, sizeof(adpt->card->shortname),
  491. "Microchip INIC");
  492. snprintf(adpt->card->longname, sizeof(adpt->card->longname),
  493. "%s at %s", adpt->card->shortname, iface->description);
  494. skip_adpt_alloc:
  495. if (get_channel(iface, channel_id)) {
  496. pr_err("channel (%s:%d) is already linked\n",
  497. iface->description, channel_id);
  498. return -EEXIST;
  499. }
  500. if (cfg->direction == MOST_CH_TX) {
  501. playback_count = 1;
  502. direction = SNDRV_PCM_STREAM_PLAYBACK;
  503. } else {
  504. capture_count = 1;
  505. direction = SNDRV_PCM_STREAM_CAPTURE;
  506. }
  507. channel = kzalloc(sizeof(*channel), GFP_KERNEL);
  508. if (!channel) {
  509. ret = -ENOMEM;
  510. goto err_free_adpt;
  511. }
  512. channel->card = adpt->card;
  513. channel->cfg = cfg;
  514. channel->iface = iface;
  515. channel->id = channel_id;
  516. init_waitqueue_head(&channel->playback_waitq);
  517. list_add_tail(&channel->list, &adpt->dev_list);
  518. ret = audio_set_hw_params(&channel->pcm_hardware, ch_num, sample_res,
  519. cfg);
  520. if (ret)
  521. goto err_free_adpt;
  522. ret = snd_pcm_new(adpt->card, device_name, adpt->pcm_dev_idx,
  523. playback_count, capture_count, &pcm);
  524. if (ret < 0)
  525. goto err_free_adpt;
  526. pcm->private_data = channel;
  527. strscpy(pcm->name, device_name, sizeof(pcm->name));
  528. snd_pcm_set_ops(pcm, direction, &pcm_ops);
  529. snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0);
  530. return 0;
  531. err_free_adpt:
  532. release_adapter(adpt);
  533. return ret;
  534. }
  535. static int audio_create_sound_card(void)
  536. {
  537. int ret;
  538. struct sound_adapter *adpt;
  539. list_for_each_entry(adpt, &adpt_list, list) {
  540. if (!adpt->registered)
  541. goto adpt_alloc;
  542. }
  543. return -ENODEV;
  544. adpt_alloc:
  545. ret = snd_card_register(adpt->card);
  546. if (ret < 0) {
  547. release_adapter(adpt);
  548. return ret;
  549. }
  550. adpt->registered = true;
  551. return 0;
  552. }
  553. /**
  554. * audio_disconnect_channel - function to disconnect a channel
  555. * @iface: pointer to interface instance
  556. * @channel_id: channel index
  557. *
  558. * This frees allocated memory and removes the sound card from ALSA
  559. *
  560. * Returns 0 on success or error code otherwise.
  561. */
  562. static int audio_disconnect_channel(struct most_interface *iface,
  563. int channel_id)
  564. {
  565. struct channel *channel;
  566. struct sound_adapter *adpt = iface->priv;
  567. channel = get_channel(iface, channel_id);
  568. if (!channel)
  569. return -EINVAL;
  570. list_del(&channel->list);
  571. kfree(channel);
  572. if (list_empty(&adpt->dev_list))
  573. release_adapter(adpt);
  574. return 0;
  575. }
  576. /**
  577. * audio_rx_completion - completion handler for rx channels
  578. * @mbo: pointer to buffer object that has completed
  579. *
  580. * This searches for the channel this MBO belongs to and copy the data from MBO
  581. * to ring buffer
  582. *
  583. * Returns 0 on success or error code otherwise.
  584. */
  585. static int audio_rx_completion(struct mbo *mbo)
  586. {
  587. struct channel *channel = get_channel(mbo->ifp, mbo->hdm_channel_id);
  588. bool period_elapsed = false;
  589. if (!channel)
  590. return -EINVAL;
  591. if (channel->is_stream_running)
  592. period_elapsed = copy_data(channel, mbo);
  593. most_put_mbo(mbo);
  594. if (period_elapsed)
  595. snd_pcm_period_elapsed(channel->substream);
  596. return 0;
  597. }
  598. /**
  599. * audio_tx_completion - completion handler for tx channels
  600. * @iface: pointer to interface instance
  601. * @channel_id: channel index/ID
  602. *
  603. * This searches the channel that belongs to this combination of interface
  604. * pointer and channel ID and wakes a process sitting in the wait queue of
  605. * this channel.
  606. *
  607. * Returns 0 on success or error code otherwise.
  608. */
  609. static int audio_tx_completion(struct most_interface *iface, int channel_id)
  610. {
  611. struct channel *channel = get_channel(iface, channel_id);
  612. if (!channel)
  613. return -EINVAL;
  614. wake_up_interruptible(&channel->playback_waitq);
  615. return 0;
  616. }
  617. /**
  618. * Initialization of the struct most_component
  619. */
  620. static struct most_component comp = {
  621. .mod = THIS_MODULE,
  622. .name = DRIVER_NAME,
  623. .probe_channel = audio_probe_channel,
  624. .disconnect_channel = audio_disconnect_channel,
  625. .rx_completion = audio_rx_completion,
  626. .tx_completion = audio_tx_completion,
  627. .cfg_complete = audio_create_sound_card,
  628. };
  629. static int __init audio_init(void)
  630. {
  631. int ret;
  632. INIT_LIST_HEAD(&adpt_list);
  633. ret = most_register_component(&comp);
  634. if (ret) {
  635. pr_err("Failed to register %s\n", comp.name);
  636. return ret;
  637. }
  638. ret = most_register_configfs_subsys(&comp);
  639. if (ret) {
  640. pr_err("Failed to register %s configfs subsys\n", comp.name);
  641. most_deregister_component(&comp);
  642. }
  643. return ret;
  644. }
  645. static void __exit audio_exit(void)
  646. {
  647. most_deregister_configfs_subsys(&comp);
  648. most_deregister_component(&comp);
  649. }
  650. module_init(audio_init);
  651. module_exit(audio_exit);
  652. MODULE_LICENSE("GPL");
  653. MODULE_AUTHOR("Christian Gromm <[email protected]>");
  654. MODULE_DESCRIPTION("Sound Component Module for Mostcore");