ASoC: rsnd: add CTU basic support
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Thu, 25 Feb 2016 05:53:00 +0000 (05:53 +0000)
committerMark Brown <broonie@kernel.org>
Sat, 5 Mar 2016 04:27:27 +0000 (13:27 +0900)
This patch adds Renesas R-Car sound CTU (= Channel Transfer Unit)
very basic support, but not yet enough feature at this point.
Because CTU support needs more complex channel function for
each modules.
To avoid complex patch reviewing, this patch picked up very basic
part only.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sh/rcar/ctu.c
sound/soc/sh/rcar/rsnd.h

index a10d0f7b73fa82ff51596ec0f4bef1aba90edef1..784515afefaffe71033b668a2d29db6c5c8f5c16 100644 (file)
@@ -14,6 +14,7 @@
 
 struct rsnd_ctu {
        struct rsnd_mod mod;
+       int channels;
 };
 
 #define rsnd_ctu_nr(priv) ((priv)->ctu_nr)
@@ -23,6 +24,9 @@ struct rsnd_ctu {
                     ((pos) = (struct rsnd_ctu *)(priv)->ctu + i);      \
             i++)
 
+#define rsnd_mod_to_ctu(_mod)  \
+       container_of((_mod), struct rsnd_ctu, mod)
+
 #define rsnd_ctu_get(priv, id) ((struct rsnd_ctu *)(priv->ctu) + id)
 
 static void rsnd_ctu_activation(struct rsnd_mod *mod)
@@ -37,6 +41,13 @@ static void rsnd_ctu_halt(struct rsnd_mod *mod)
        rsnd_mod_write(mod, CTU_SWRSR, 0);
 }
 
+int rsnd_ctu_converted_channel(struct rsnd_mod *mod)
+{
+       struct rsnd_ctu *ctu = rsnd_mod_to_ctu(mod);
+
+       return ctu->channels;
+}
+
 static int rsnd_ctu_probe_(struct rsnd_mod *mod,
                           struct rsnd_dai_stream *io,
                           struct rsnd_priv *priv)
@@ -116,11 +127,49 @@ static int rsnd_ctu_quit(struct rsnd_mod *mod,
        return 0;
 }
 
+static int rsnd_ctu_hw_params(struct rsnd_mod *mod,
+                             struct rsnd_dai_stream *io,
+                             struct snd_pcm_substream *substream,
+                             struct snd_pcm_hw_params *fe_params)
+{
+       struct rsnd_ctu *ctu = rsnd_mod_to_ctu(mod);
+       struct snd_soc_pcm_runtime *fe = substream->private_data;
+
+       /*
+        * CTU assumes that it is used under DPCM if user want to use
+        * channel transfer. Then, CTU should be FE.
+        * And then, this function will be called *after* BE settings.
+        * this means, each BE already has fixuped hw_params.
+        * see
+        *      dpcm_fe_dai_hw_params()
+        *      dpcm_be_dai_hw_params()
+        */
+       ctu->channels = 0;
+       if (fe->dai_link->dynamic) {
+               struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
+               struct device *dev = rsnd_priv_to_dev(priv);
+               struct snd_soc_dpcm *dpcm;
+               struct snd_pcm_hw_params *be_params;
+               int stream = substream->stream;
+
+               list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
+                       be_params = &dpcm->hw_params;
+                       if (params_channels(fe_params) != params_channels(be_params))
+                               ctu->channels = params_channels(be_params);
+               }
+
+               dev_dbg(dev, "CTU convert channels %d\n", ctu->channels);
+       }
+
+       return 0;
+}
+
 static struct rsnd_mod_ops rsnd_ctu_ops = {
        .name           = CTU_NAME,
        .probe          = rsnd_ctu_probe_,
        .init           = rsnd_ctu_init,
        .quit           = rsnd_ctu_quit,
+       .hw_params      = rsnd_ctu_hw_params,
 };
 
 struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id)
index 305cc086a0bc35325483539d580cd4e64094ac6b..bbc89bd1e9188e1ceb636d3fdd24454f0568c405 100644 (file)
@@ -638,6 +638,7 @@ unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
  */
 int rsnd_ctu_probe(struct rsnd_priv *priv);
 void rsnd_ctu_remove(struct rsnd_priv *priv);
+int rsnd_ctu_converted_channel(struct rsnd_mod *mod);
 struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id);
 #define rsnd_ctu_of_node(priv)                                         \
        of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,ctu")