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); \
40 static int rsnd_src_set_route_if_gen1(struct rsnd_priv *priv,
42 struct rsnd_dai *rdai,
43 struct rsnd_dai_stream *io)
45 struct scu_route_config {
68 if (!rsnd_is_gen1(priv))
71 id = rsnd_mod_id(mod);
72 if (id < 0 || id > ARRAY_SIZE(routes))
78 val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2;
79 val = val << routes[id].shift;
80 mask = routes[id].mask << routes[id].shift;
82 rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val);
89 if (8 == id) /* SRU8 is very special */
92 val = (id + 1) << shift;
96 rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val);
99 rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val);
102 rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val);
109 static int rsnd_scu_rate_ctrl(struct rsnd_priv *priv,
110 struct rsnd_mod *mod,
111 struct rsnd_dai *rdai,
112 struct rsnd_dai_stream *io)
114 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
115 u32 adinr = runtime->channels;
117 switch (runtime->sample_bits) {
128 rsnd_mod_write(mod, SRC_ADINR, adinr);
133 static int rsnd_scu_transfer_start(struct rsnd_priv *priv,
134 struct rsnd_mod *mod,
135 struct rsnd_dai *rdai,
136 struct rsnd_dai_stream *io)
138 int id = rsnd_mod_id(mod);
141 if (rsnd_is_gen1(priv)) {
143 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, val, val);
146 rsnd_mod_write(mod, BUSIF_MODE, 1);
151 bool rsnd_scu_hpbif_is_enable(struct rsnd_mod *mod)
153 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
154 u32 flags = rsnd_scu_mode_flags(scu);
156 return !!(flags & RSND_SCU_USE_HPBIF);
159 static int rsnd_scu_start(struct rsnd_mod *mod,
160 struct rsnd_dai *rdai,
161 struct rsnd_dai_stream *io)
163 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
164 struct device *dev = rsnd_priv_to_dev(priv);
168 * SCU will be used if it has RSND_SCU_USE_HPBIF flags
170 if (!rsnd_scu_hpbif_is_enable(mod)) {
171 /* it use PIO transter */
172 dev_dbg(dev, "%s%d is not used\n",
173 rsnd_mod_name(mod), rsnd_mod_id(mod));
178 /* it use DMA transter */
180 ret = rsnd_src_set_route_if_gen1(priv, mod, rdai, io);
184 ret = rsnd_scu_rate_ctrl(priv, mod, rdai, io);
188 ret = rsnd_scu_transfer_start(priv, mod, rdai, io);
192 dev_dbg(dev, "%s%d start\n", rsnd_mod_name(mod), rsnd_mod_id(mod));
197 static struct rsnd_mod_ops rsnd_scu_ops = {
199 .start = rsnd_scu_start,
202 struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id)
204 BUG_ON(id < 0 || id >= rsnd_scu_nr(priv));
206 return &((struct rsnd_scu *)(priv->scu) + id)->mod;
209 int rsnd_scu_probe(struct platform_device *pdev,
210 struct rcar_snd_info *info,
211 struct rsnd_priv *priv)
213 struct device *dev = rsnd_priv_to_dev(priv);
214 struct rsnd_scu *scu;
220 nr = info->scu_info_nr;
221 scu = devm_kzalloc(dev, sizeof(*scu) * nr, GFP_KERNEL);
223 dev_err(dev, "SCU allocate failed\n");
230 for_each_rsnd_scu(scu, priv, i) {
231 rsnd_mod_init(priv, &scu->mod,
233 scu->info = &info->scu_info[i];
235 dev_dbg(dev, "SCU%d probed\n", i);
237 dev_dbg(dev, "scu probed\n");
242 void rsnd_scu_remove(struct platform_device *pdev,
243 struct rsnd_priv *priv)