axg-frddr.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // SPDX-License-Identifier: (GPL-2.0 OR MIT)
  2. //
  3. // Copyright (c) 2018 BayLibre, SAS.
  4. // Author: Jerome Brunet <jbrunet@baylibre.com>
  5. /* This driver implements the frontend playback DAI of AXG based SoCs */
  6. #include <linux/clk.h>
  7. #include <linux/regmap.h>
  8. #include <linux/module.h>
  9. #include <linux/of_platform.h>
  10. #include <sound/soc.h>
  11. #include <sound/soc-dai.h>
  12. #include "axg-fifo.h"
  13. #define CTRL0_FRDDR_PP_MODE BIT(30)
  14. static int axg_frddr_dai_startup(struct snd_pcm_substream *substream,
  15. struct snd_soc_dai *dai)
  16. {
  17. struct axg_fifo *fifo = snd_soc_dai_get_drvdata(dai);
  18. unsigned int fifo_depth, fifo_threshold;
  19. int ret;
  20. /* Enable pclk to access registers and clock the fifo ip */
  21. ret = clk_prepare_enable(fifo->pclk);
  22. if (ret)
  23. return ret;
  24. /* Apply single buffer mode to the interface */
  25. regmap_update_bits(fifo->map, FIFO_CTRL0, CTRL0_FRDDR_PP_MODE, 0);
  26. /*
  27. * TODO: We could adapt the fifo depth and the fifo threshold
  28. * depending on the expected memory throughput and lantencies
  29. * For now, we'll just use the same values as the vendor kernel
  30. * Depth and threshold are zero based.
  31. */
  32. fifo_depth = AXG_FIFO_MIN_CNT - 1;
  33. fifo_threshold = (AXG_FIFO_MIN_CNT / 2) - 1;
  34. regmap_update_bits(fifo->map, FIFO_CTRL1,
  35. CTRL1_FRDDR_DEPTH_MASK | CTRL1_THRESHOLD_MASK,
  36. CTRL1_FRDDR_DEPTH(fifo_depth) |
  37. CTRL1_THRESHOLD(fifo_threshold));
  38. return 0;
  39. }
  40. static void axg_frddr_dai_shutdown(struct snd_pcm_substream *substream,
  41. struct snd_soc_dai *dai)
  42. {
  43. struct axg_fifo *fifo = snd_soc_dai_get_drvdata(dai);
  44. clk_disable_unprepare(fifo->pclk);
  45. }
  46. static int axg_frddr_pcm_new(struct snd_soc_pcm_runtime *rtd,
  47. struct snd_soc_dai *dai)
  48. {
  49. return axg_fifo_pcm_new(rtd, SNDRV_PCM_STREAM_PLAYBACK);
  50. }
  51. static const struct snd_soc_dai_ops axg_frddr_ops = {
  52. .startup = axg_frddr_dai_startup,
  53. .shutdown = axg_frddr_dai_shutdown,
  54. };
  55. static struct snd_soc_dai_driver axg_frddr_dai_drv = {
  56. .name = "FRDDR",
  57. .playback = {
  58. .stream_name = "Playback",
  59. .channels_min = 1,
  60. .channels_max = AXG_FIFO_CH_MAX,
  61. .rates = AXG_FIFO_RATES,
  62. .formats = AXG_FIFO_FORMATS,
  63. },
  64. .ops = &axg_frddr_ops,
  65. .pcm_new = axg_frddr_pcm_new,
  66. };
  67. static const char * const axg_frddr_sel_texts[] = {
  68. "OUT 0", "OUT 1", "OUT 2", "OUT 3"
  69. };
  70. static SOC_ENUM_SINGLE_DECL(axg_frddr_sel_enum, FIFO_CTRL0, CTRL0_SEL_SHIFT,
  71. axg_frddr_sel_texts);
  72. static const struct snd_kcontrol_new axg_frddr_out_demux =
  73. SOC_DAPM_ENUM("Output Sink", axg_frddr_sel_enum);
  74. static const struct snd_soc_dapm_widget axg_frddr_dapm_widgets[] = {
  75. SND_SOC_DAPM_DEMUX("SINK SEL", SND_SOC_NOPM, 0, 0,
  76. &axg_frddr_out_demux),
  77. SND_SOC_DAPM_AIF_OUT("OUT 0", NULL, 0, SND_SOC_NOPM, 0, 0),
  78. SND_SOC_DAPM_AIF_OUT("OUT 1", NULL, 0, SND_SOC_NOPM, 0, 0),
  79. SND_SOC_DAPM_AIF_OUT("OUT 2", NULL, 0, SND_SOC_NOPM, 0, 0),
  80. SND_SOC_DAPM_AIF_OUT("OUT 3", NULL, 0, SND_SOC_NOPM, 0, 0),
  81. };
  82. static const struct snd_soc_dapm_route axg_frddr_dapm_routes[] = {
  83. { "SINK SEL", NULL, "Playback" },
  84. { "OUT 0", "OUT 0", "SINK SEL" },
  85. { "OUT 1", "OUT 1", "SINK SEL" },
  86. { "OUT 2", "OUT 2", "SINK SEL" },
  87. { "OUT 3", "OUT 3", "SINK SEL" },
  88. };
  89. static const struct snd_soc_component_driver axg_frddr_component_drv = {
  90. .dapm_widgets = axg_frddr_dapm_widgets,
  91. .num_dapm_widgets = ARRAY_SIZE(axg_frddr_dapm_widgets),
  92. .dapm_routes = axg_frddr_dapm_routes,
  93. .num_dapm_routes = ARRAY_SIZE(axg_frddr_dapm_routes),
  94. .ops = &axg_fifo_pcm_ops
  95. };
  96. static const struct axg_fifo_match_data axg_frddr_match_data = {
  97. .component_drv = &axg_frddr_component_drv,
  98. .dai_drv = &axg_frddr_dai_drv
  99. };
  100. static const struct of_device_id axg_frddr_of_match[] = {
  101. {
  102. .compatible = "amlogic,axg-frddr",
  103. .data = &axg_frddr_match_data,
  104. }, {}
  105. };
  106. MODULE_DEVICE_TABLE(of, axg_frddr_of_match);
  107. static struct platform_driver axg_frddr_pdrv = {
  108. .probe = axg_fifo_probe,
  109. .driver = {
  110. .name = "axg-frddr",
  111. .of_match_table = axg_frddr_of_match,
  112. },
  113. };
  114. module_platform_driver(axg_frddr_pdrv);
  115. MODULE_DESCRIPTION("Amlogic AXG playback fifo driver");
  116. MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
  117. MODULE_LICENSE("GPL v2");