1 // SPDX-License-Identifier: GPL-2.0
3 // Renesas R-Car CMD support
5 // Copyright (C) 2015 Renesas Solutions Corp.
6 // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
14 #define CMD_NAME "cmd"
16 #define rsnd_cmd_nr(priv) ((priv)->cmd_nr)
17 #define for_each_rsnd_cmd(pos, priv, i) \
19 ((i) < rsnd_cmd_nr(priv)) && \
20 ((pos) = (struct rsnd_cmd *)(priv)->cmd + i); \
23 static int rsnd_cmd_init(struct rsnd_mod *mod,
24 struct rsnd_dai_stream *io,
25 struct rsnd_priv *priv)
27 struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
28 struct rsnd_mod *mix = rsnd_io_to_mod_mix(io);
29 struct device *dev = rsnd_priv_to_dev(priv);
31 static const u32 path[] = {
41 if (ARRAY_SIZE(path) < rsnd_mod_id(mod) + 1)
45 struct rsnd_dai *rdai;
47 struct rsnd_dai_stream *tio;
51 * it is assuming that integrater is well understanding about
52 * data path. Here doesn't check impossible connection,
56 for_each_rsnd_dai(rdai, priv, i) {
57 tio = &rdai->playback;
58 src = rsnd_io_to_mod_src(tio);
59 if (mix == rsnd_io_to_mod_mix(tio))
60 data |= path[rsnd_mod_id(src)];
63 src = rsnd_io_to_mod_src(tio);
64 if (mix == rsnd_io_to_mod_mix(tio))
65 data |= path[rsnd_mod_id(src)];
69 struct rsnd_mod *src = rsnd_io_to_mod_src(io);
71 static const u8 cmd_case[] = {
85 data = path[rsnd_mod_id(src)] |
86 cmd_case[rsnd_mod_id(src)] << 16;
89 dev_dbg(dev, "ctu/mix path = 0x%08x\n", data);
91 rsnd_mod_write(mod, CMD_ROUTE_SLCT, data);
92 rsnd_mod_write(mod, CMD_BUSIF_MODE, rsnd_get_busif_shift(io, mod) | 1);
93 rsnd_mod_write(mod, CMD_BUSIF_DALIGN, rsnd_get_dalign(mod, io));
95 rsnd_adg_set_cmd_timsel_gen2(mod, io);
100 static int rsnd_cmd_start(struct rsnd_mod *mod,
101 struct rsnd_dai_stream *io,
102 struct rsnd_priv *priv)
104 rsnd_mod_write(mod, CMD_CTRL, 0x10);
109 static int rsnd_cmd_stop(struct rsnd_mod *mod,
110 struct rsnd_dai_stream *io,
111 struct rsnd_priv *priv)
113 rsnd_mod_write(mod, CMD_CTRL, 0);
118 static struct rsnd_mod_ops rsnd_cmd_ops = {
120 .init = rsnd_cmd_init,
121 .start = rsnd_cmd_start,
122 .stop = rsnd_cmd_stop,
123 .get_status = rsnd_mod_get_status,
126 static struct rsnd_mod *rsnd_cmd_mod_get(struct rsnd_priv *priv, int id)
128 if (WARN_ON(id < 0 || id >= rsnd_cmd_nr(priv)))
131 return rsnd_mod_get((struct rsnd_cmd *)(priv->cmd) + id);
133 int rsnd_cmd_attach(struct rsnd_dai_stream *io, int id)
135 struct rsnd_priv *priv = rsnd_io_to_priv(io);
136 struct rsnd_mod *mod = rsnd_cmd_mod_get(priv, id);
138 return rsnd_dai_connect(mod, io, mod->type);
141 int rsnd_cmd_probe(struct rsnd_priv *priv)
143 struct device *dev = rsnd_priv_to_dev(priv);
144 struct rsnd_cmd *cmd;
147 /* This driver doesn't support Gen1 at this point */
148 if (rsnd_is_gen1(priv))
151 /* same number as DVC */
156 cmd = devm_kcalloc(dev, nr, sizeof(*cmd), GFP_KERNEL);
163 for_each_rsnd_cmd(cmd, priv, i) {
164 ret = rsnd_mod_init(priv, rsnd_mod_get(cmd),
174 void rsnd_cmd_remove(struct rsnd_priv *priv)
176 struct rsnd_cmd *cmd;
179 for_each_rsnd_cmd(cmd, priv, i) {
180 rsnd_mod_quit(rsnd_mod_get(cmd));