]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - sound/soc/sh/rcar/core.c
Merge branch 'topic/update-bits' of git://git.kernel.org/pub/scm/linux/kernel/git...
[karo-tx-linux.git] / sound / soc / sh / rcar / core.c
index 02b4b085b8d77f57398a13c35214a49445d1ed77..21e13b3a356fbb402cfc7ed6350005f88a483c25 100644 (file)
@@ -138,12 +138,22 @@ struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io,
        return mod->ops->dma_req(io, mod);
 }
 
+u32 *rsnd_mod_get_status(struct rsnd_dai_stream *io,
+                        struct rsnd_mod *mod,
+                        enum rsnd_mod_type type)
+{
+       return &mod->status;
+}
+
 int rsnd_mod_init(struct rsnd_priv *priv,
                  struct rsnd_mod *mod,
-                  struct rsnd_mod_ops *ops,
-                  struct clk *clk,
-                  enum rsnd_mod_type type,
-                  int id)
+                 struct rsnd_mod_ops *ops,
+                 struct clk *clk,
+                 u32* (*get_status)(struct rsnd_dai_stream *io,
+                                    struct rsnd_mod *mod,
+                                    enum rsnd_mod_type type),
+                 enum rsnd_mod_type type,
+                 int id)
 {
        int ret = clk_prepare(clk);
 
@@ -155,6 +165,7 @@ int rsnd_mod_init(struct rsnd_priv *priv,
        mod->type       = type;
        mod->clk        = clk;
        mod->priv       = priv;
+       mod->get_status = get_status;
 
        return ret;
 }
@@ -163,6 +174,7 @@ void rsnd_mod_quit(struct rsnd_mod *mod)
 {
        if (mod->clk)
                clk_unprepare(mod->clk);
+       mod->clk = NULL;
 }
 
 void rsnd_mod_interrupt(struct rsnd_mod *mod,
@@ -218,7 +230,7 @@ int rsnd_get_slot_width(struct rsnd_dai_stream *io)
        int chan = runtime->channels;
 
        /* Multi channel Mode */
-       if (rsnd_ssi_multi_slaves(io))
+       if (rsnd_ssi_multi_slaves_runtime(io))
                chan /= rsnd_get_slot_num(io);
 
        /* TDM Extend Mode needs 8ch */
@@ -324,31 +336,73 @@ u32 rsnd_get_dalign(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
        struct rsnd_priv *priv = rsnd_mod_to_priv(mod);         \
        struct rsnd_mod *mod = (io)->mod[idx];                  \
        struct device *dev = rsnd_priv_to_dev(priv);            \
-       u32 *status = (io)->mod_status + idx;                   \
+       u32 *status = mod->get_status(io, mod, idx);                    \
        u32 mask = 0xF << __rsnd_mod_shift_##func;                      \
        u8 val  = (*status >> __rsnd_mod_shift_##func) & 0xF;           \
        u8 add  = ((val + __rsnd_mod_add_##func) & 0xF);                \
        int ret = 0;                                                    \
        int call = (val == __rsnd_mod_call_##func) && (mod)->ops->func; \
-       *status = (*status & ~mask) +                                   \
-               (add << __rsnd_mod_shift_##func);                       \
+       if (add == 0xF)                                                 \
+               call = 0;                                               \
+       else                                                            \
+               *status = (*status & ~mask) +                           \
+                       (add << __rsnd_mod_shift_##func);               \
        dev_dbg(dev, "%s[%d]\t0x%08x %s\n",                             \
                rsnd_mod_name(mod), rsnd_mod_id(mod),                   \
                *status, call ? #func : "");                            \
        if (call)                                                       \
                ret = (mod)->ops->func(mod, io, param);                 \
+       if (ret)                                                        \
+               dev_dbg(dev, "%s[%d] : rsnd_mod_call error %d\n",       \
+                       rsnd_mod_name(mod), rsnd_mod_id(mod), ret);     \
        ret;                                                            \
 })
 
+static enum rsnd_mod_type rsnd_mod_sequence[][RSND_MOD_MAX] = {
+       {
+               /* CAPTURE */
+               RSND_MOD_AUDMAPP,
+               RSND_MOD_AUDMA,
+               RSND_MOD_DVC,
+               RSND_MOD_MIX,
+               RSND_MOD_CTU,
+               RSND_MOD_CMD,
+               RSND_MOD_SRC,
+               RSND_MOD_SSIU,
+               RSND_MOD_SSIM3,
+               RSND_MOD_SSIM2,
+               RSND_MOD_SSIM1,
+               RSND_MOD_SSIP,
+               RSND_MOD_SSI,
+       }, {
+               /* PLAYBACK */
+               RSND_MOD_AUDMAPP,
+               RSND_MOD_AUDMA,
+               RSND_MOD_SSIM3,
+               RSND_MOD_SSIM2,
+               RSND_MOD_SSIM1,
+               RSND_MOD_SSIP,
+               RSND_MOD_SSI,
+               RSND_MOD_SSIU,
+               RSND_MOD_DVC,
+               RSND_MOD_MIX,
+               RSND_MOD_CTU,
+               RSND_MOD_CMD,
+               RSND_MOD_SRC,
+       },
+};
+
 #define rsnd_dai_call(fn, io, param...)                                \
 ({                                                             \
        struct rsnd_mod *mod;                                   \
+       int type, is_play = rsnd_io_is_play(io);                \
        int ret = 0, i;                                         \
        for (i = 0; i < RSND_MOD_MAX; i++) {                    \
-               mod = (io)->mod[i];                             \
+               type = rsnd_mod_sequence[is_play][i];           \
+               mod = (io)->mod[type];                          \
                if (!mod)                                       \
                        continue;                               \
-               ret |= rsnd_mod_call(i, io, fn, param);         \
+               ret |= rsnd_mod_call(type, io, fn, param);      \
        }                                                       \
        ret;                                                    \
 })
@@ -363,6 +417,9 @@ int rsnd_dai_connect(struct rsnd_mod *mod,
        if (!mod)
                return -EIO;
 
+       if (io->mod[type] == mod)
+               return 0;
+
        if (io->mod[type])
                return -EINVAL;
 
@@ -511,9 +568,16 @@ static int rsnd_soc_dai_trigger(struct snd_pcm_substream *substream, int cmd,
                ret = rsnd_dai_call(start, io, priv);
                if (ret < 0)
                        goto dai_trigger_end;
+
+               ret = rsnd_dai_call(irq, io, priv, 1);
+               if (ret < 0)
+                       goto dai_trigger_end;
+
                break;
        case SNDRV_PCM_TRIGGER_STOP:
-               ret = rsnd_dai_call(stop, io, priv);
+               ret = rsnd_dai_call(irq, io, priv, 0);
+
+               ret |= rsnd_dai_call(stop, io, priv);
 
                ret |= rsnd_dai_call(quit, io, priv);
 
@@ -923,7 +987,7 @@ int rsnd_kctrl_new_m(struct rsnd_mod *mod,
                     int ch_size,
                     u32 max)
 {
-       if (ch_size > RSND_DVC_CHANNELS)
+       if (ch_size > RSND_MAX_CHANNELS)
                return -EINVAL;
 
        _cfg->cfg.max   = max;