2 * Renesas R-Car SCU support
4 * Copyright (C) 2013 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.
14 struct rsnd_scu_platform_info *info; /* rcar_snd.h */
18 #define rsnd_scu_mode_flags(p) ((p)->info->flags)
23 #define OTBL_24 (0 << 16)
24 #define OTBL_22 (2 << 16)
25 #define OTBL_20 (4 << 16)
26 #define OTBL_18 (6 << 16)
27 #define OTBL_16 (8 << 16)
30 #define rsnd_mod_to_scu(_mod) \
31 container_of((_mod), struct rsnd_scu, mod)
33 #define for_each_rsnd_scu(pos, priv, i) \
35 ((i) < rsnd_scu_nr(priv)) && \
36 ((pos) = (struct rsnd_scu *)(priv)->scu + i); \
39 static int rsnd_scu_set_route(struct rsnd_priv *priv,
41 struct rsnd_dai *rdai,
42 struct rsnd_dai_stream *io)
44 struct scu_route_config {
67 if (!rsnd_is_gen1(priv))
70 id = rsnd_mod_id(mod);
71 if (id < 0 || id > ARRAY_SIZE(routes))
77 val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2;
78 val = val << routes[id].shift;
79 mask = routes[id].mask << routes[id].shift;
81 rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val);
88 if (8 == id) /* SRU8 is very special */
91 val = (id + 1) << shift;
95 rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val);
98 rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val);
101 rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val);
108 static int rsnd_scu_set_mode(struct rsnd_priv *priv,
109 struct rsnd_mod *mod,
110 struct rsnd_dai *rdai,
111 struct rsnd_dai_stream *io)
113 int id = rsnd_mod_id(mod);
116 if (rsnd_is_gen1(priv)) {
118 rsnd_mod_bset(mod, SRC_CTRL, val, val);
124 static int rsnd_scu_set_hpbif(struct rsnd_priv *priv,
125 struct rsnd_mod *mod,
126 struct rsnd_dai *rdai,
127 struct rsnd_dai_stream *io)
129 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
130 u32 adinr = runtime->channels;
132 switch (runtime->sample_bits) {
143 rsnd_mod_write(mod, BUSIF_MODE, 1);
144 rsnd_mod_write(mod, BUSIF_ADINR, adinr);
149 static int rsnd_scu_start(struct rsnd_mod *mod,
150 struct rsnd_dai *rdai,
151 struct rsnd_dai_stream *io)
153 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
154 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
155 struct device *dev = rsnd_priv_to_dev(priv);
156 u32 flags = rsnd_scu_mode_flags(scu);
160 * SCU will be used if it has RSND_SCU_USE_HPBIF flags
162 if (!(flags & RSND_SCU_USE_HPBIF)) {
163 /* it use PIO transter */
164 dev_dbg(dev, "%s%d is not used\n",
165 rsnd_mod_name(mod), rsnd_mod_id(mod));
170 /* it use DMA transter */
171 ret = rsnd_scu_set_route(priv, mod, rdai, io);
175 ret = rsnd_scu_set_mode(priv, mod, rdai, io);
179 ret = rsnd_scu_set_hpbif(priv, mod, rdai, io);
183 dev_dbg(dev, "%s%d start\n", rsnd_mod_name(mod), rsnd_mod_id(mod));
188 static struct rsnd_mod_ops rsnd_scu_ops = {
190 .start = rsnd_scu_start,
193 struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id)
195 BUG_ON(id < 0 || id >= rsnd_scu_nr(priv));
197 return &((struct rsnd_scu *)(priv->scu) + id)->mod;
200 int rsnd_scu_probe(struct platform_device *pdev,
201 struct rcar_snd_info *info,
202 struct rsnd_priv *priv)
204 struct device *dev = rsnd_priv_to_dev(priv);
205 struct rsnd_scu *scu;
211 nr = info->scu_info_nr;
212 scu = devm_kzalloc(dev, sizeof(*scu) * nr, GFP_KERNEL);
214 dev_err(dev, "SCU allocate failed\n");
221 for_each_rsnd_scu(scu, priv, i) {
222 rsnd_mod_init(priv, &scu->mod,
224 scu->info = &info->scu_info[i];
226 dev_dbg(dev, "SCU%d probed\n", i);
228 dev_dbg(dev, "scu probed\n");
233 void rsnd_scu_remove(struct platform_device *pdev,
234 struct rsnd_priv *priv)