x86/speculation/mds: Fix documentation typo
[linux/fpc-iii.git] / sound / soc / sh / rcar / cmd.c
blobf1d4fb5668921bfd5eafa024643cfc729c288e1e
1 /*
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.
11 #include "rsnd.h"
13 struct rsnd_cmd {
14 struct rsnd_mod mod;
17 #define CMD_NAME "cmd"
19 #define rsnd_cmd_nr(priv) ((priv)->cmd_nr)
20 #define for_each_rsnd_cmd(pos, priv, i) \
21 for ((i) = 0; \
22 ((i) < rsnd_cmd_nr(priv)) && \
23 ((pos) = (struct rsnd_cmd *)(priv)->cmd + i); \
24 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);
33 u32 data;
34 static const u32 path[] = {
35 [1] = 1 << 0,
36 [5] = 1 << 8,
37 [6] = 1 << 12,
38 [9] = 1 << 15,
41 if (!mix && !dvc)
42 return 0;
44 if (ARRAY_SIZE(path) < rsnd_mod_id(mod) + 1)
45 return -ENXIO;
47 if (mix) {
48 struct rsnd_dai *rdai;
49 struct rsnd_mod *src;
50 struct rsnd_dai_stream *tio;
51 int i;
54 * it is assuming that integrater is well understanding about
55 * data path. Here doesn't check impossible connection,
56 * like src2 + src5
58 data = 0;
59 for_each_rsnd_dai(rdai, priv, i) {
60 tio = &rdai->playback;
61 src = rsnd_io_to_mod_src(tio);
62 if (mix == rsnd_io_to_mod_mix(tio))
63 data |= path[rsnd_mod_id(src)];
65 tio = &rdai->capture;
66 src = rsnd_io_to_mod_src(tio);
67 if (mix == rsnd_io_to_mod_mix(tio))
68 data |= path[rsnd_mod_id(src)];
71 } else {
72 struct rsnd_mod *src = rsnd_io_to_mod_src(io);
74 static const u8 cmd_case[] = {
75 [0] = 0x3,
76 [1] = 0x3,
77 [2] = 0x4,
78 [3] = 0x1,
79 [4] = 0x2,
80 [5] = 0x4,
81 [6] = 0x1,
82 [9] = 0x2,
85 if (unlikely(!src))
86 return -EIO;
88 data = path[rsnd_mod_id(src)] |
89 cmd_case[rsnd_mod_id(src)] << 16;
92 dev_dbg(dev, "ctu/mix path = 0x%08x", data);
94 rsnd_mod_write(mod, CMD_ROUTE_SLCT, data);
95 rsnd_mod_write(mod, CMD_BUSIF_MODE, rsnd_get_busif_shift(io, mod) | 1);
96 rsnd_mod_write(mod, CMD_BUSIF_DALIGN, rsnd_get_dalign(mod, io));
98 rsnd_adg_set_cmd_timsel_gen2(mod, io);
100 return 0;
103 static int rsnd_cmd_start(struct rsnd_mod *mod,
104 struct rsnd_dai_stream *io,
105 struct rsnd_priv *priv)
107 rsnd_mod_write(mod, CMD_CTRL, 0x10);
109 return 0;
112 static int rsnd_cmd_stop(struct rsnd_mod *mod,
113 struct rsnd_dai_stream *io,
114 struct rsnd_priv *priv)
116 rsnd_mod_write(mod, CMD_CTRL, 0);
118 return 0;
121 static struct rsnd_mod_ops rsnd_cmd_ops = {
122 .name = CMD_NAME,
123 .init = rsnd_cmd_init,
124 .start = rsnd_cmd_start,
125 .stop = rsnd_cmd_stop,
128 int rsnd_cmd_attach(struct rsnd_dai_stream *io, int id)
130 struct rsnd_priv *priv = rsnd_io_to_priv(io);
131 struct rsnd_mod *mod = rsnd_cmd_mod_get(priv, id);
133 return rsnd_dai_connect(mod, io, mod->type);
136 struct rsnd_mod *rsnd_cmd_mod_get(struct rsnd_priv *priv, int id)
138 if (WARN_ON(id < 0 || id >= rsnd_cmd_nr(priv)))
139 id = 0;
141 return rsnd_mod_get((struct rsnd_cmd *)(priv->cmd) + id);
144 int rsnd_cmd_probe(struct rsnd_priv *priv)
146 struct device *dev = rsnd_priv_to_dev(priv);
147 struct rsnd_cmd *cmd;
148 int i, nr, ret;
150 /* This driver doesn't support Gen1 at this point */
151 if (rsnd_is_gen1(priv))
152 return 0;
154 /* same number as DVC */
155 nr = priv->dvc_nr;
156 if (!nr)
157 return 0;
159 cmd = devm_kzalloc(dev, sizeof(*cmd) * nr, GFP_KERNEL);
160 if (!cmd)
161 return -ENOMEM;
163 priv->cmd_nr = nr;
164 priv->cmd = cmd;
166 for_each_rsnd_cmd(cmd, priv, i) {
167 ret = rsnd_mod_init(priv, rsnd_mod_get(cmd),
168 &rsnd_cmd_ops, NULL,
169 rsnd_mod_get_status, RSND_MOD_CMD, i);
170 if (ret)
171 return ret;
174 return 0;
177 void rsnd_cmd_remove(struct rsnd_priv *priv)
179 struct rsnd_cmd *cmd;
180 int i;
182 for_each_rsnd_cmd(cmd, priv, i) {
183 rsnd_mod_quit(rsnd_mod_get(cmd));