2 * Renesas R-Car CMD support
4 * Copyright (C) 2015 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
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.
17 #define CMD_NAME "cmd"
19 #define rsnd_cmd_nr(priv) ((priv)->cmd_nr)
20 #define for_each_rsnd_cmd(pos, priv, i) \
22 ((i) < rsnd_cmd_nr(priv)) && \
23 ((pos) = (struct rsnd_cmd *)(priv)->cmd + i); \
26 static int rsnd_cmd_init(struct rsnd_mod *mod,
27 struct rsnd_dai_stream *io,
28 struct rsnd_priv *priv)
30 struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
31 struct rsnd_mod *mix = rsnd_io_to_mod_mix(io);
32 struct device *dev = rsnd_priv_to_dev(priv);
39 struct rsnd_dai *rdai;
41 struct rsnd_dai_stream *tio;
53 * it is assuming that integrater is well understanding about
54 * data path. Here doesn't check impossible connection,
58 for_each_rsnd_dai(rdai, priv, i) {
59 tio = &rdai->playback;
60 src = rsnd_io_to_mod_src(tio);
61 if (mix == rsnd_io_to_mod_mix(tio))
62 data |= path[rsnd_mod_id(src)];
65 src = rsnd_io_to_mod_src(tio);
66 if (mix == rsnd_io_to_mod_mix(tio))
67 data |= path[rsnd_mod_id(src)];
71 struct rsnd_mod *src = rsnd_io_to_mod_src(io);
82 data = path[rsnd_mod_id(src)];
85 dev_dbg(dev, "ctu/mix path = 0x%08x", data);
87 rsnd_mod_write(mod, CMD_ROUTE_SLCT, data);
88 rsnd_mod_write(mod, CMD_BUSIF_DALIGN, rsnd_get_dalign(mod, io));
90 rsnd_adg_set_cmd_timsel_gen2(mod, io);
95 static int rsnd_cmd_start(struct rsnd_mod *mod,
96 struct rsnd_dai_stream *io,
97 struct rsnd_priv *priv)
99 rsnd_mod_write(mod, CMD_CTRL, 0x10);
104 static int rsnd_cmd_stop(struct rsnd_mod *mod,
105 struct rsnd_dai_stream *io,
106 struct rsnd_priv *priv)
108 rsnd_mod_write(mod, CMD_CTRL, 0);
113 static struct rsnd_mod_ops rsnd_cmd_ops = {
115 .init = rsnd_cmd_init,
116 .start = rsnd_cmd_start,
117 .stop = rsnd_cmd_stop,
120 int rsnd_cmd_attach(struct rsnd_dai_stream *io, int id)
122 struct rsnd_priv *priv = rsnd_io_to_priv(io);
123 struct rsnd_mod *mod = rsnd_cmd_mod_get(priv, id);
125 return rsnd_dai_connect(mod, io, mod->type);
128 struct rsnd_mod *rsnd_cmd_mod_get(struct rsnd_priv *priv, int id)
130 if (WARN_ON(id < 0 || id >= rsnd_cmd_nr(priv)))
133 return rsnd_mod_get((struct rsnd_cmd *)(priv->cmd) + id);
136 int rsnd_cmd_probe(struct rsnd_priv *priv)
138 struct device *dev = rsnd_priv_to_dev(priv);
139 struct rsnd_cmd *cmd;
142 /* This driver doesn't support Gen1 at this point */
143 if (rsnd_is_gen1(priv))
146 /* same number as DVC */
151 cmd = devm_kzalloc(dev, sizeof(*cmd) * nr, GFP_KERNEL);
158 for_each_rsnd_cmd(cmd, priv, i) {
159 ret = rsnd_mod_init(priv, rsnd_mod_get(cmd),
161 rsnd_mod_get_status, RSND_MOD_CMD, i);
169 void rsnd_cmd_remove(struct rsnd_priv *priv)
171 struct rsnd_cmd *cmd;
174 for_each_rsnd_cmd(cmd, priv, i) {
175 rsnd_mod_quit(rsnd_mod_get(cmd));