soc-utils.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * soc-util.c -- ALSA SoC Audio Layer utility functions
  3. *
  4. * Copyright 2009 Wolfson Microelectronics PLC.
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. * Liam Girdwood <lrg@slimlogic.co.uk>
  8. *
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. */
  15. #include <linux/platform_device.h>
  16. #include <sound/core.h>
  17. #include <sound/pcm.h>
  18. #include <sound/pcm_params.h>
  19. #include <sound/soc.h>
  20. int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots)
  21. {
  22. return sample_size * channels * tdm_slots;
  23. }
  24. EXPORT_SYMBOL_GPL(snd_soc_calc_frame_size);
  25. int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params)
  26. {
  27. int sample_size;
  28. sample_size = snd_pcm_format_width(params_format(params));
  29. if (sample_size < 0)
  30. return sample_size;
  31. return snd_soc_calc_frame_size(sample_size, params_channels(params),
  32. 1);
  33. }
  34. EXPORT_SYMBOL_GPL(snd_soc_params_to_frame_size);
  35. int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots)
  36. {
  37. return fs * snd_soc_calc_frame_size(sample_size, channels, tdm_slots);
  38. }
  39. EXPORT_SYMBOL_GPL(snd_soc_calc_bclk);
  40. int snd_soc_params_to_bclk(struct snd_pcm_hw_params *params)
  41. {
  42. int ret;
  43. ret = snd_soc_params_to_frame_size(params);
  44. if (ret > 0)
  45. return ret * params_rate(params);
  46. else
  47. return ret;
  48. }
  49. EXPORT_SYMBOL_GPL(snd_soc_params_to_bclk);
  50. static const struct snd_pcm_hardware dummy_dma_hardware = {
  51. .formats = 0xffffffff,
  52. .channels_min = 1,
  53. .channels_max = UINT_MAX,
  54. /* Random values to keep userspace happy when checking constraints */
  55. .info = SNDRV_PCM_INFO_INTERLEAVED |
  56. SNDRV_PCM_INFO_BLOCK_TRANSFER,
  57. .buffer_bytes_max = 128*1024,
  58. .period_bytes_min = PAGE_SIZE,
  59. .period_bytes_max = PAGE_SIZE*2,
  60. .periods_min = 2,
  61. .periods_max = 128,
  62. };
  63. static int dummy_dma_open(struct snd_pcm_substream *substream)
  64. {
  65. snd_soc_set_runtime_hwparams(substream, &dummy_dma_hardware);
  66. return 0;
  67. }
  68. static struct snd_pcm_ops dummy_dma_ops = {
  69. .open = dummy_dma_open,
  70. .ioctl = snd_pcm_lib_ioctl,
  71. };
  72. static struct snd_soc_platform_driver dummy_platform = {
  73. .ops = &dummy_dma_ops,
  74. };
  75. static __devinit int snd_soc_dummy_probe(struct platform_device *pdev)
  76. {
  77. return snd_soc_register_platform(&pdev->dev, &dummy_platform);
  78. }
  79. static __devexit int snd_soc_dummy_remove(struct platform_device *pdev)
  80. {
  81. snd_soc_unregister_platform(&pdev->dev);
  82. return 0;
  83. }
  84. static struct platform_driver soc_dummy_driver = {
  85. .driver = {
  86. .name = "snd-soc-dummy",
  87. .owner = THIS_MODULE,
  88. },
  89. .probe = snd_soc_dummy_probe,
  90. .remove = __devexit_p(snd_soc_dummy_remove),
  91. };
  92. static struct platform_device *soc_dummy_dev;
  93. int __init snd_soc_util_init(void)
  94. {
  95. int ret;
  96. soc_dummy_dev = platform_device_alloc("snd-soc-dummy", -1);
  97. if (!soc_dummy_dev)
  98. return -ENOMEM;
  99. ret = platform_device_add(soc_dummy_dev);
  100. if (ret != 0) {
  101. platform_device_put(soc_dummy_dev);
  102. return ret;
  103. }
  104. ret = platform_driver_register(&soc_dummy_driver);
  105. if (ret != 0)
  106. platform_device_unregister(soc_dummy_dev);
  107. return ret;
  108. }
  109. void __exit snd_soc_util_exit(void)
  110. {
  111. platform_device_unregister(soc_dummy_dev);
  112. platform_driver_unregister(&soc_dummy_driver);
  113. }