mix.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * mix.c
  3. *
  4. * Copyright (c) 2015 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include "rsnd.h"
  11. #define MIX_NAME_SIZE 16
  12. #define MIX_NAME "mix"
  13. struct rsnd_mix {
  14. struct rsnd_mix_platform_info *info; /* rcar_snd.h */
  15. struct rsnd_mod mod;
  16. };
  17. #define rsnd_mix_nr(priv) ((priv)->mix_nr)
  18. #define for_each_rsnd_mix(pos, priv, i) \
  19. for ((i) = 0; \
  20. ((i) < rsnd_mix_nr(priv)) && \
  21. ((pos) = (struct rsnd_mix *)(priv)->mix + i); \
  22. i++)
  23. static void rsnd_mix_soft_reset(struct rsnd_mod *mod)
  24. {
  25. rsnd_mod_write(mod, MIX_SWRSR, 0);
  26. rsnd_mod_write(mod, MIX_SWRSR, 1);
  27. }
  28. #define rsnd_mix_initialize_lock(mod) __rsnd_mix_initialize_lock(mod, 1)
  29. #define rsnd_mix_initialize_unlock(mod) __rsnd_mix_initialize_lock(mod, 0)
  30. static void __rsnd_mix_initialize_lock(struct rsnd_mod *mod, u32 enable)
  31. {
  32. rsnd_mod_write(mod, MIX_MIXIR, enable);
  33. }
  34. static void rsnd_mix_volume_update(struct rsnd_dai_stream *io,
  35. struct rsnd_mod *mod)
  36. {
  37. /* Disable MIX dB setting */
  38. rsnd_mod_write(mod, MIX_MDBER, 0);
  39. rsnd_mod_write(mod, MIX_MDBAR, 0);
  40. rsnd_mod_write(mod, MIX_MDBBR, 0);
  41. rsnd_mod_write(mod, MIX_MDBCR, 0);
  42. rsnd_mod_write(mod, MIX_MDBDR, 0);
  43. /* Enable MIX dB setting */
  44. rsnd_mod_write(mod, MIX_MDBER, 1);
  45. }
  46. static int rsnd_mix_init(struct rsnd_mod *mod,
  47. struct rsnd_dai_stream *io,
  48. struct rsnd_priv *priv)
  49. {
  50. rsnd_mod_hw_start(mod);
  51. rsnd_mix_soft_reset(mod);
  52. rsnd_mix_initialize_lock(mod);
  53. rsnd_mod_write(mod, MIX_ADINR, rsnd_get_adinr_chan(mod, io));
  54. rsnd_path_parse(priv, io);
  55. /* volume step */
  56. rsnd_mod_write(mod, MIX_MIXMR, 0);
  57. rsnd_mod_write(mod, MIX_MVPDR, 0);
  58. rsnd_mix_volume_update(io, mod);
  59. rsnd_mix_initialize_unlock(mod);
  60. return 0;
  61. }
  62. static int rsnd_mix_quit(struct rsnd_mod *mod,
  63. struct rsnd_dai_stream *io,
  64. struct rsnd_priv *priv)
  65. {
  66. rsnd_mod_hw_stop(mod);
  67. return 0;
  68. }
  69. static struct rsnd_mod_ops rsnd_mix_ops = {
  70. .name = MIX_NAME,
  71. .init = rsnd_mix_init,
  72. .quit = rsnd_mix_quit,
  73. };
  74. struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id)
  75. {
  76. if (WARN_ON(id < 0 || id >= rsnd_mix_nr(priv)))
  77. id = 0;
  78. return &((struct rsnd_mix *)(priv->mix) + id)->mod;
  79. }
  80. static void rsnd_of_parse_mix(struct platform_device *pdev,
  81. const struct rsnd_of_data *of_data,
  82. struct rsnd_priv *priv)
  83. {
  84. struct device_node *node;
  85. struct rsnd_mix_platform_info *mix_info;
  86. struct rcar_snd_info *info = rsnd_priv_to_info(priv);
  87. struct device *dev = &pdev->dev;
  88. int nr;
  89. if (!of_data)
  90. return;
  91. node = of_get_child_by_name(dev->of_node, "rcar_sound,mix");
  92. if (!node)
  93. return;
  94. nr = of_get_child_count(node);
  95. if (!nr)
  96. goto rsnd_of_parse_mix_end;
  97. mix_info = devm_kzalloc(dev,
  98. sizeof(struct rsnd_mix_platform_info) * nr,
  99. GFP_KERNEL);
  100. if (!mix_info) {
  101. dev_err(dev, "mix info allocation error\n");
  102. goto rsnd_of_parse_mix_end;
  103. }
  104. info->mix_info = mix_info;
  105. info->mix_info_nr = nr;
  106. rsnd_of_parse_mix_end:
  107. of_node_put(node);
  108. }
  109. int rsnd_mix_probe(struct platform_device *pdev,
  110. const struct rsnd_of_data *of_data,
  111. struct rsnd_priv *priv)
  112. {
  113. struct rcar_snd_info *info = rsnd_priv_to_info(priv);
  114. struct device *dev = rsnd_priv_to_dev(priv);
  115. struct rsnd_mix *mix;
  116. struct clk *clk;
  117. char name[MIX_NAME_SIZE];
  118. int i, nr, ret;
  119. /* This driver doesn't support Gen1 at this point */
  120. if (rsnd_is_gen1(priv)) {
  121. dev_warn(dev, "MIX is not supported on Gen1\n");
  122. return -EINVAL;
  123. }
  124. rsnd_of_parse_mix(pdev, of_data, priv);
  125. nr = info->mix_info_nr;
  126. if (!nr)
  127. return 0;
  128. mix = devm_kzalloc(dev, sizeof(*mix) * nr, GFP_KERNEL);
  129. if (!mix)
  130. return -ENOMEM;
  131. priv->mix_nr = nr;
  132. priv->mix = mix;
  133. for_each_rsnd_mix(mix, priv, i) {
  134. snprintf(name, MIX_NAME_SIZE, "%s.%d",
  135. MIX_NAME, i);
  136. clk = devm_clk_get(dev, name);
  137. if (IS_ERR(clk))
  138. return PTR_ERR(clk);
  139. mix->info = &info->mix_info[i];
  140. ret = rsnd_mod_init(priv, &mix->mod, &rsnd_mix_ops,
  141. clk, RSND_MOD_MIX, i);
  142. if (ret)
  143. return ret;
  144. }
  145. return 0;
  146. }
  147. void rsnd_mix_remove(struct platform_device *pdev,
  148. struct rsnd_priv *priv)
  149. {
  150. struct rsnd_mix *mix;
  151. int i;
  152. for_each_rsnd_mix(mix, priv, i) {
  153. rsnd_mod_quit(&mix->mod);
  154. }
  155. }