cmd.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Renesas R-Car CMD support
  3. *
  4. * Copyright (C) 2015 Renesas Solutions Corp.
  5. * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include "rsnd.h"
  12. struct rsnd_cmd {
  13. struct rsnd_mod mod;
  14. };
  15. #define CMD_NAME "cmd"
  16. #define rsnd_cmd_nr(priv) ((priv)->cmd_nr)
  17. #define for_each_rsnd_cmd(pos, priv, i) \
  18. for ((i) = 0; \
  19. ((i) < rsnd_cmd_nr(priv)) && \
  20. ((pos) = (struct rsnd_cmd *)(priv)->cmd + i); \
  21. i++)
  22. static int rsnd_cmd_init(struct rsnd_mod *mod,
  23. struct rsnd_dai_stream *io,
  24. struct rsnd_priv *priv)
  25. {
  26. struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
  27. struct rsnd_mod *mix = rsnd_io_to_mod_mix(io);
  28. struct device *dev = rsnd_priv_to_dev(priv);
  29. u32 data;
  30. if (!mix && !dvc)
  31. return 0;
  32. if (mix) {
  33. struct rsnd_dai *rdai;
  34. struct rsnd_mod *src;
  35. struct rsnd_dai_stream *tio;
  36. int i;
  37. u32 path[] = {
  38. [0] = 0,
  39. [1] = 1 << 0,
  40. [2] = 0,
  41. [3] = 0,
  42. [4] = 0,
  43. [5] = 1 << 8
  44. };
  45. /*
  46. * it is assuming that integrater is well understanding about
  47. * data path. Here doesn't check impossible connection,
  48. * like src2 + src5
  49. */
  50. data = 0;
  51. for_each_rsnd_dai(rdai, priv, i) {
  52. tio = &rdai->playback;
  53. src = rsnd_io_to_mod_src(tio);
  54. if (mix == rsnd_io_to_mod_mix(tio))
  55. data |= path[rsnd_mod_id(src)];
  56. tio = &rdai->capture;
  57. src = rsnd_io_to_mod_src(tio);
  58. if (mix == rsnd_io_to_mod_mix(tio))
  59. data |= path[rsnd_mod_id(src)];
  60. }
  61. } else {
  62. struct rsnd_mod *src = rsnd_io_to_mod_src(io);
  63. u32 path[] = {
  64. [0] = 0x30000,
  65. [1] = 0x30001,
  66. [2] = 0x40000,
  67. [3] = 0x10000,
  68. [4] = 0x20000,
  69. [5] = 0x40100
  70. };
  71. data = path[rsnd_mod_id(src)];
  72. }
  73. dev_dbg(dev, "ctu/mix path = 0x%08x", data);
  74. rsnd_mod_write(mod, CMD_ROUTE_SLCT, data);
  75. rsnd_mod_write(mod, CMD_BUSIF_DALIGN, rsnd_get_dalign(mod, io));
  76. rsnd_adg_set_cmd_timsel_gen2(mod, io);
  77. return 0;
  78. }
  79. static int rsnd_cmd_start(struct rsnd_mod *mod,
  80. struct rsnd_dai_stream *io,
  81. struct rsnd_priv *priv)
  82. {
  83. rsnd_mod_write(mod, CMD_CTRL, 0x10);
  84. return 0;
  85. }
  86. static int rsnd_cmd_stop(struct rsnd_mod *mod,
  87. struct rsnd_dai_stream *io,
  88. struct rsnd_priv *priv)
  89. {
  90. rsnd_mod_write(mod, CMD_CTRL, 0);
  91. return 0;
  92. }
  93. static struct rsnd_mod_ops rsnd_cmd_ops = {
  94. .name = CMD_NAME,
  95. .init = rsnd_cmd_init,
  96. .start = rsnd_cmd_start,
  97. .stop = rsnd_cmd_stop,
  98. };
  99. int rsnd_cmd_attach(struct rsnd_dai_stream *io, int id)
  100. {
  101. struct rsnd_priv *priv = rsnd_io_to_priv(io);
  102. struct rsnd_mod *mod = rsnd_cmd_mod_get(priv, id);
  103. return rsnd_dai_connect(mod, io, mod->type);
  104. }
  105. struct rsnd_mod *rsnd_cmd_mod_get(struct rsnd_priv *priv, int id)
  106. {
  107. if (WARN_ON(id < 0 || id >= rsnd_cmd_nr(priv)))
  108. id = 0;
  109. return rsnd_mod_get((struct rsnd_cmd *)(priv->cmd) + id);
  110. }
  111. int rsnd_cmd_probe(struct rsnd_priv *priv)
  112. {
  113. struct device *dev = rsnd_priv_to_dev(priv);
  114. struct rsnd_cmd *cmd;
  115. int i, nr, ret;
  116. /* This driver doesn't support Gen1 at this point */
  117. if (rsnd_is_gen1(priv))
  118. return 0;
  119. /* same number as DVC */
  120. nr = priv->dvc_nr;
  121. if (!nr)
  122. return 0;
  123. cmd = devm_kzalloc(dev, sizeof(*cmd) * nr, GFP_KERNEL);
  124. if (!cmd)
  125. return -ENOMEM;
  126. priv->cmd_nr = nr;
  127. priv->cmd = cmd;
  128. for_each_rsnd_cmd(cmd, priv, i) {
  129. ret = rsnd_mod_init(priv, rsnd_mod_get(cmd),
  130. &rsnd_cmd_ops, NULL,
  131. rsnd_mod_get_status, RSND_MOD_CMD, i);
  132. if (ret)
  133. return ret;
  134. }
  135. return 0;
  136. }
  137. void rsnd_cmd_remove(struct rsnd_priv *priv)
  138. {
  139. struct rsnd_cmd *cmd;
  140. int i;
  141. for_each_rsnd_cmd(cmd, priv, i) {
  142. rsnd_mod_quit(rsnd_mod_get(cmd));
  143. }
  144. }