cmd.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. u32 path[] = {
  31. [1] = 1 << 0,
  32. [5] = 1 << 8,
  33. [6] = 1 << 12,
  34. [9] = 1 << 15,
  35. };
  36. if (!mix && !dvc)
  37. return 0;
  38. if (ARRAY_SIZE(path) < rsnd_mod_id(mod) + 1)
  39. return -ENXIO;
  40. if (mix) {
  41. struct rsnd_dai *rdai;
  42. struct rsnd_mod *src;
  43. struct rsnd_dai_stream *tio;
  44. int i;
  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. u8 cmd_case[] = {
  64. [0] = 0x3,
  65. [1] = 0x3,
  66. [2] = 0x4,
  67. [3] = 0x1,
  68. [4] = 0x2,
  69. [5] = 0x4,
  70. [6] = 0x1,
  71. [9] = 0x2,
  72. };
  73. if (unlikely(!src))
  74. return -EIO;
  75. data = path[rsnd_mod_id(src)] |
  76. cmd_case[rsnd_mod_id(src)] << 16;
  77. }
  78. dev_dbg(dev, "ctu/mix path = 0x%08x", data);
  79. rsnd_mod_write(mod, CMD_ROUTE_SLCT, data);
  80. rsnd_mod_write(mod, CMD_BUSIF_DALIGN, rsnd_get_dalign(mod, io));
  81. rsnd_adg_set_cmd_timsel_gen2(mod, io);
  82. return 0;
  83. }
  84. static int rsnd_cmd_start(struct rsnd_mod *mod,
  85. struct rsnd_dai_stream *io,
  86. struct rsnd_priv *priv)
  87. {
  88. rsnd_mod_write(mod, CMD_CTRL, 0x10);
  89. return 0;
  90. }
  91. static int rsnd_cmd_stop(struct rsnd_mod *mod,
  92. struct rsnd_dai_stream *io,
  93. struct rsnd_priv *priv)
  94. {
  95. rsnd_mod_write(mod, CMD_CTRL, 0);
  96. return 0;
  97. }
  98. static struct rsnd_mod_ops rsnd_cmd_ops = {
  99. .name = CMD_NAME,
  100. .init = rsnd_cmd_init,
  101. .start = rsnd_cmd_start,
  102. .stop = rsnd_cmd_stop,
  103. };
  104. int rsnd_cmd_attach(struct rsnd_dai_stream *io, int id)
  105. {
  106. struct rsnd_priv *priv = rsnd_io_to_priv(io);
  107. struct rsnd_mod *mod = rsnd_cmd_mod_get(priv, id);
  108. return rsnd_dai_connect(mod, io, mod->type);
  109. }
  110. struct rsnd_mod *rsnd_cmd_mod_get(struct rsnd_priv *priv, int id)
  111. {
  112. if (WARN_ON(id < 0 || id >= rsnd_cmd_nr(priv)))
  113. id = 0;
  114. return rsnd_mod_get((struct rsnd_cmd *)(priv->cmd) + id);
  115. }
  116. int rsnd_cmd_probe(struct rsnd_priv *priv)
  117. {
  118. struct device *dev = rsnd_priv_to_dev(priv);
  119. struct rsnd_cmd *cmd;
  120. int i, nr, ret;
  121. /* This driver doesn't support Gen1 at this point */
  122. if (rsnd_is_gen1(priv))
  123. return 0;
  124. /* same number as DVC */
  125. nr = priv->dvc_nr;
  126. if (!nr)
  127. return 0;
  128. cmd = devm_kzalloc(dev, sizeof(*cmd) * nr, GFP_KERNEL);
  129. if (!cmd)
  130. return -ENOMEM;
  131. priv->cmd_nr = nr;
  132. priv->cmd = cmd;
  133. for_each_rsnd_cmd(cmd, priv, i) {
  134. ret = rsnd_mod_init(priv, rsnd_mod_get(cmd),
  135. &rsnd_cmd_ops, NULL,
  136. rsnd_mod_get_status, RSND_MOD_CMD, i);
  137. if (ret)
  138. return ret;
  139. }
  140. return 0;
  141. }
  142. void rsnd_cmd_remove(struct rsnd_priv *priv)
  143. {
  144. struct rsnd_cmd *cmd;
  145. int i;
  146. for_each_rsnd_cmd(cmd, priv, i) {
  147. rsnd_mod_quit(rsnd_mod_get(cmd));
  148. }
  149. }