mix.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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_mod mod;
  15. };
  16. #define rsnd_mix_get(priv, id) ((struct rsnd_mix *)(priv->mix) + id)
  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_activation(struct rsnd_mod *mod)
  24. {
  25. rsnd_mod_write(mod, MIX_SWRSR, 0);
  26. rsnd_mod_write(mod, MIX_SWRSR, 1);
  27. }
  28. static void rsnd_mix_halt(struct rsnd_mod *mod)
  29. {
  30. rsnd_mod_write(mod, MIX_MIXIR, 1);
  31. rsnd_mod_write(mod, MIX_SWRSR, 0);
  32. }
  33. static void rsnd_mix_volume_parameter(struct rsnd_dai_stream *io,
  34. struct rsnd_mod *mod)
  35. {
  36. rsnd_mod_write(mod, MIX_MDBAR, 0);
  37. rsnd_mod_write(mod, MIX_MDBBR, 0);
  38. rsnd_mod_write(mod, MIX_MDBCR, 0);
  39. rsnd_mod_write(mod, MIX_MDBDR, 0);
  40. }
  41. static void rsnd_mix_volume_init(struct rsnd_dai_stream *io,
  42. struct rsnd_mod *mod)
  43. {
  44. rsnd_mod_write(mod, MIX_MIXIR, 1);
  45. /* General Information */
  46. rsnd_mod_write(mod, MIX_ADINR, rsnd_runtime_channel_after_ctu(io));
  47. /* volume step */
  48. rsnd_mod_write(mod, MIX_MIXMR, 0);
  49. rsnd_mod_write(mod, MIX_MVPDR, 0);
  50. /* common volume parameter */
  51. rsnd_mix_volume_parameter(io, mod);
  52. rsnd_mod_write(mod, MIX_MIXIR, 0);
  53. }
  54. static void rsnd_mix_volume_update(struct rsnd_dai_stream *io,
  55. struct rsnd_mod *mod)
  56. {
  57. /* Disable MIX dB setting */
  58. rsnd_mod_write(mod, MIX_MDBER, 0);
  59. /* common volume parameter */
  60. rsnd_mix_volume_parameter(io, mod);
  61. /* Enable MIX dB setting */
  62. rsnd_mod_write(mod, MIX_MDBER, 1);
  63. }
  64. static int rsnd_mix_probe_(struct rsnd_mod *mod,
  65. struct rsnd_dai_stream *io,
  66. struct rsnd_priv *priv)
  67. {
  68. return rsnd_cmd_attach(io, rsnd_mod_id(mod));
  69. }
  70. static int rsnd_mix_init(struct rsnd_mod *mod,
  71. struct rsnd_dai_stream *io,
  72. struct rsnd_priv *priv)
  73. {
  74. rsnd_mod_power_on(mod);
  75. rsnd_mix_activation(mod);
  76. rsnd_mix_volume_init(io, mod);
  77. rsnd_mix_volume_update(io, mod);
  78. return 0;
  79. }
  80. static int rsnd_mix_quit(struct rsnd_mod *mod,
  81. struct rsnd_dai_stream *io,
  82. struct rsnd_priv *priv)
  83. {
  84. rsnd_mix_halt(mod);
  85. rsnd_mod_power_off(mod);
  86. return 0;
  87. }
  88. static struct rsnd_mod_ops rsnd_mix_ops = {
  89. .name = MIX_NAME,
  90. .probe = rsnd_mix_probe_,
  91. .init = rsnd_mix_init,
  92. .quit = rsnd_mix_quit,
  93. };
  94. struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id)
  95. {
  96. if (WARN_ON(id < 0 || id >= rsnd_mix_nr(priv)))
  97. id = 0;
  98. return rsnd_mod_get(rsnd_mix_get(priv, id));
  99. }
  100. int rsnd_mix_probe(struct rsnd_priv *priv)
  101. {
  102. struct device_node *node;
  103. struct device_node *np;
  104. struct device *dev = rsnd_priv_to_dev(priv);
  105. struct rsnd_mix *mix;
  106. struct clk *clk;
  107. char name[MIX_NAME_SIZE];
  108. int i, nr, ret;
  109. /* This driver doesn't support Gen1 at this point */
  110. if (rsnd_is_gen1(priv))
  111. return 0;
  112. node = rsnd_mix_of_node(priv);
  113. if (!node)
  114. return 0; /* not used is not error */
  115. nr = of_get_child_count(node);
  116. if (!nr) {
  117. ret = -EINVAL;
  118. goto rsnd_mix_probe_done;
  119. }
  120. mix = devm_kzalloc(dev, sizeof(*mix) * nr, GFP_KERNEL);
  121. if (!mix) {
  122. ret = -ENOMEM;
  123. goto rsnd_mix_probe_done;
  124. }
  125. priv->mix_nr = nr;
  126. priv->mix = mix;
  127. i = 0;
  128. ret = 0;
  129. for_each_child_of_node(node, np) {
  130. mix = rsnd_mix_get(priv, i);
  131. snprintf(name, MIX_NAME_SIZE, "%s.%d",
  132. MIX_NAME, i);
  133. clk = devm_clk_get(dev, name);
  134. if (IS_ERR(clk)) {
  135. ret = PTR_ERR(clk);
  136. goto rsnd_mix_probe_done;
  137. }
  138. ret = rsnd_mod_init(priv, rsnd_mod_get(mix), &rsnd_mix_ops,
  139. clk, rsnd_mod_get_status, RSND_MOD_MIX, i);
  140. if (ret)
  141. goto rsnd_mix_probe_done;
  142. i++;
  143. }
  144. rsnd_mix_probe_done:
  145. of_node_put(node);
  146. return ret;
  147. }
  148. void rsnd_mix_remove(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(rsnd_mod_get(mix));
  154. }
  155. }