ASoC: rsnd: add rsnd_mod_get() macro and use it
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Thu, 10 Sep 2015 07:02:21 +0000 (07:02 +0000)
committerMark Brown <broonie@kernel.org>
Mon, 14 Sep 2015 18:47:31 +0000 (19:47 +0100)
Renesas sound driver has SSI/SRC/DVC/CTU/MIX, and these are controlled
as modules. And these module are member of each modules's private data.
It used own method to get module pointer, but Let's use common method

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/dvc.c
sound/soc/sh/rcar/mix.c
sound/soc/sh/rcar/rsnd.h
sound/soc/sh/rcar/src.c
sound/soc/sh/rcar/ssi.c

index 05498bba5874dbb0fe9fffdb46e26bad0866f045..a3e7c716e1f7283f6ad453ae91c52590b998b516 100644 (file)
@@ -66,7 +66,7 @@ struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id)
        if (WARN_ON(id < 0 || id >= rsnd_ctu_nr(priv)))
                id = 0;
 
-       return &((struct rsnd_ctu *)(priv->ctu) + id)->mod;
+       return rsnd_mod_get((struct rsnd_ctu *)(priv->ctu) + id);
 }
 
 static void rsnd_of_parse_ctu(struct platform_device *pdev,
@@ -150,7 +150,7 @@ int rsnd_ctu_probe(struct platform_device *pdev,
 
                ctu->info = &info->ctu_info[i];
 
-               ret = rsnd_mod_init(priv, &ctu->mod, &rsnd_ctu_ops,
+               ret = rsnd_mod_init(priv, rsnd_mod_get(ctu), &rsnd_ctu_ops,
                                    clk, RSND_MOD_CTU, i);
                if (ret)
                        return ret;
@@ -166,6 +166,6 @@ void rsnd_ctu_remove(struct platform_device *pdev,
        int i;
 
        for_each_rsnd_ctu(ctu, priv, i) {
-               rsnd_mod_quit(&ctu->mod);
+               rsnd_mod_quit(rsnd_mod_get(ctu));
        }
 }
index 57796387d482303bc84c29212dfed167685ae6fe..8d8eee6350c94f43632fcf42a19926613dd38d41 100644 (file)
@@ -282,7 +282,7 @@ struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id)
        if (WARN_ON(id < 0 || id >= rsnd_dvc_nr(priv)))
                id = 0;
 
-       return &((struct rsnd_dvc *)(priv->dvc) + id)->mod;
+       return rsnd_mod_get((struct rsnd_dvc *)(priv->dvc) + id);
 }
 
 static void rsnd_of_parse_dvc(struct platform_device *pdev,
@@ -361,7 +361,7 @@ int rsnd_dvc_probe(struct platform_device *pdev,
 
                dvc->info = &info->dvc_info[i];
 
-               ret = rsnd_mod_init(priv, &dvc->mod, &rsnd_dvc_ops,
+               ret = rsnd_mod_init(priv, rsnd_mod_get(dvc), &rsnd_dvc_ops,
                              clk, RSND_MOD_DVC, i);
                if (ret)
                        return ret;
@@ -377,6 +377,6 @@ void rsnd_dvc_remove(struct platform_device *pdev,
        int i;
 
        for_each_rsnd_dvc(dvc, priv, i) {
-               rsnd_mod_quit(&dvc->mod);
+               rsnd_mod_quit(rsnd_mod_get(dvc));
        }
 }
index 0d5c102db6f5fb6ed54b05e42f97888bdd0c6c20..8544403ffb269fa89ebe5af5b8ee88b2b8dad2da 100644 (file)
@@ -99,7 +99,7 @@ struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id)
        if (WARN_ON(id < 0 || id >= rsnd_mix_nr(priv)))
                id = 0;
 
-       return &((struct rsnd_mix *)(priv->mix) + id)->mod;
+       return rsnd_mod_get((struct rsnd_mix *)(priv->mix) + id);
 }
 
 static void rsnd_of_parse_mix(struct platform_device *pdev,
@@ -179,7 +179,7 @@ int rsnd_mix_probe(struct platform_device *pdev,
 
                mix->info = &info->mix_info[i];
 
-               ret = rsnd_mod_init(priv, &mix->mod, &rsnd_mix_ops,
+               ret = rsnd_mod_init(priv, rsnd_mod_get(mix), &rsnd_mix_ops,
                                    clk, RSND_MOD_MIX, i);
                if (ret)
                        return ret;
@@ -195,6 +195,6 @@ void rsnd_mix_remove(struct platform_device *pdev,
        int i;
 
        for_each_rsnd_mix(mix, priv, i) {
-               rsnd_mod_quit(&mix->mod);
+               rsnd_mod_quit(rsnd_mod_get(mix));
        }
 }
index 6ae8068fae3d9ee028d89f611acda94ad0830162..f35d9cc61686cbfdd866ec97ed8adc44801d91ee 100644 (file)
@@ -331,6 +331,7 @@ struct rsnd_mod {
 #define rsnd_mod_id(mod) ((mod) ? (mod)->id : -1)
 #define rsnd_mod_hw_start(mod) clk_enable((mod)->clk)
 #define rsnd_mod_hw_stop(mod)  clk_disable((mod)->clk)
+#define rsnd_mod_get(ip)       (&(ip)->mod)
 
 int rsnd_mod_init(struct rsnd_priv *priv,
                  struct rsnd_mod *mod,
index 06555a3e8b79cbc65c0127aa937e1784c8125cdf..ca7a20f03c9bf1f9a987fe8108ec38542af51500 100644 (file)
@@ -976,7 +976,7 @@ struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)
        if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv)))
                id = 0;
 
-       return &((struct rsnd_src *)(priv->src) + id)->mod;
+       return rsnd_mod_get((struct rsnd_src *)(priv->src) + id);
 }
 
 static void rsnd_of_parse_src(struct platform_device *pdev,
@@ -1071,7 +1071,7 @@ int rsnd_src_probe(struct platform_device *pdev,
 
                src->info = &info->src_info[i];
 
-               ret = rsnd_mod_init(priv, &src->mod, ops, clk, RSND_MOD_SRC, i);
+               ret = rsnd_mod_init(priv, rsnd_mod_get(src), ops, clk, RSND_MOD_SRC, i);
                if (ret)
                        return ret;
        }
@@ -1086,6 +1086,6 @@ void rsnd_src_remove(struct platform_device *pdev,
        int i;
 
        for_each_rsnd_src(src, priv, i) {
-               rsnd_mod_quit(&src->mod);
+               rsnd_mod_quit(rsnd_mod_get(src));
        }
 }
index d45b9a7e324efb49a5159417232c9f43815ebfed..91712e88405da5e00505a432a42ee08d4172ba98 100644 (file)
@@ -128,6 +128,7 @@ static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
        struct rsnd_priv *priv = rsnd_io_to_priv(io);
        struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
        struct device *dev = rsnd_priv_to_dev(priv);
+       struct rsnd_mod *mod = rsnd_mod_get(ssi);
        int i, j, ret;
        int adg_clk_div_table[] = {
                1, 6, /* see adg.c */
@@ -152,14 +153,14 @@ static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
                        main_rate = rate / adg_clk_div_table[i]
                                * 32 * 2 * ssi_clk_mul_table[j];
 
-                       ret = rsnd_adg_ssi_clk_try_start(&ssi->mod, main_rate);
+                       ret = rsnd_adg_ssi_clk_try_start(mod, main_rate);
                        if (0 == ret) {
                                ssi->cr_clk     = FORCE | SWL_32 |
                                                  SCKD | SWSD | CKDV(j);
 
                                dev_dbg(dev, "%s[%d] outputs %u Hz\n",
-                                       rsnd_mod_name(&ssi->mod),
-                                       rsnd_mod_id(&ssi->mod), rate);
+                                       rsnd_mod_name(mod),
+                                       rsnd_mod_id(mod), rate);
 
                                return 0;
                        }
@@ -172,8 +173,10 @@ static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
 
 static void rsnd_ssi_master_clk_stop(struct rsnd_ssi *ssi)
 {
+       struct rsnd_mod *mod = rsnd_mod_get(ssi);
+
        ssi->cr_clk = 0;
-       rsnd_adg_ssi_clk_stop(&ssi->mod);
+       rsnd_adg_ssi_clk_stop(mod);
 }
 
 static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
@@ -182,11 +185,12 @@ static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
        struct rsnd_priv *priv = rsnd_io_to_priv(io);
        struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
        struct device *dev = rsnd_priv_to_dev(priv);
+       struct rsnd_mod *mod = rsnd_mod_get(ssi);
        u32 cr_mode;
        u32 cr;
 
        if (0 == ssi->usrcnt) {
-               rsnd_mod_hw_start(&ssi->mod);
+               rsnd_mod_hw_start(mod);
 
                if (rsnd_rdai_is_clk_master(rdai)) {
                        struct rsnd_ssi *ssi_parent = rsnd_ssi_parent(ssi);
@@ -198,7 +202,7 @@ static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
                }
        }
 
-       if (rsnd_ssi_is_dma_mode(&ssi->mod)) {
+       if (rsnd_ssi_is_dma_mode(mod)) {
                cr_mode = UIEN | OIEN | /* over/under run */
                          DMEN;         /* DMA : enable DMA */
        } else {
@@ -210,24 +214,25 @@ static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
                cr_mode         |
                EN;
 
-       rsnd_mod_write(&ssi->mod, SSICR, cr);
+       rsnd_mod_write(mod, SSICR, cr);
 
        /* enable WS continue */
        if (rsnd_rdai_is_clk_master(rdai))
-               rsnd_mod_write(&ssi->mod, SSIWSR, CONT);
+               rsnd_mod_write(mod, SSIWSR, CONT);
 
        /* clear error status */
-       rsnd_mod_write(&ssi->mod, SSISR, 0);
+       rsnd_mod_write(mod, SSISR, 0);
 
        ssi->usrcnt++;
 
        dev_dbg(dev, "%s[%d] hw started\n",
-               rsnd_mod_name(&ssi->mod), rsnd_mod_id(&ssi->mod));
+               rsnd_mod_name(mod), rsnd_mod_id(mod));
 }
 
 static void rsnd_ssi_hw_stop(struct rsnd_dai_stream *io, struct rsnd_ssi *ssi)
 {
-       struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod);
+       struct rsnd_mod *mod = rsnd_mod_get(ssi);
+       struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
        struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
        struct device *dev = rsnd_priv_to_dev(priv);
        u32 cr;
@@ -247,15 +252,15 @@ static void rsnd_ssi_hw_stop(struct rsnd_dai_stream *io, struct rsnd_ssi *ssi)
                cr  =   ssi->cr_own     |
                        ssi->cr_clk;
 
-               rsnd_mod_write(&ssi->mod, SSICR, cr | EN);
-               rsnd_ssi_status_check(&ssi->mod, DIRQ);
+               rsnd_mod_write(mod, SSICR, cr | EN);
+               rsnd_ssi_status_check(mod, DIRQ);
 
                /*
                 * disable SSI,
                 * and, wait idle state
                 */
-               rsnd_mod_write(&ssi->mod, SSICR, cr);   /* disabled all */
-               rsnd_ssi_status_check(&ssi->mod, IIRQ);
+               rsnd_mod_write(mod, SSICR, cr); /* disabled all */
+               rsnd_ssi_status_check(mod, IIRQ);
 
                if (rsnd_rdai_is_clk_master(rdai)) {
                        struct rsnd_ssi *ssi_parent = rsnd_ssi_parent(ssi);
@@ -266,13 +271,13 @@ static void rsnd_ssi_hw_stop(struct rsnd_dai_stream *io, struct rsnd_ssi *ssi)
                                rsnd_ssi_master_clk_stop(ssi);
                }
 
-               rsnd_mod_hw_stop(&ssi->mod);
+               rsnd_mod_hw_stop(mod);
 
                ssi->chan = 0;
        }
 
        dev_dbg(dev, "%s[%d] hw stopped\n",
-               rsnd_mod_name(&ssi->mod), rsnd_mod_id(&ssi->mod));
+               rsnd_mod_name(mod), rsnd_mod_id(mod));
 }
 
 /*
@@ -371,7 +376,7 @@ static int rsnd_ssi_hw_params(struct rsnd_mod *mod,
        /* It will be removed on rsnd_ssi_hw_stop */
        ssi->chan = chan;
        if (ssi_parent)
-               return rsnd_ssi_hw_params(&ssi_parent->mod, io,
+               return rsnd_ssi_hw_params(rsnd_mod_get(ssi_parent), io,
                                          substream, params);
 
        return 0;
@@ -379,12 +384,14 @@ static int rsnd_ssi_hw_params(struct rsnd_mod *mod,
 
 static void rsnd_ssi_record_error(struct rsnd_ssi *ssi, u32 status)
 {
+       struct rsnd_mod *mod = rsnd_mod_get(ssi);
+
        /* under/over flow error */
        if (status & (UIRQ | OIRQ)) {
                ssi->err++;
 
                /* clear error status */
-               rsnd_mod_write(&ssi->mod, SSISR, 0);
+               rsnd_mod_write(mod, SSISR, 0);
        }
 }
 
@@ -656,7 +663,7 @@ struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id)
        if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv)))
                id = 0;
 
-       return &((struct rsnd_ssi *)(priv->ssi) + id)->mod;
+       return rsnd_mod_get((struct rsnd_ssi *)(priv->ssi) + id);
 }
 
 int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
@@ -668,10 +675,12 @@ int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
 
 static void rsnd_ssi_parent_setup(struct rsnd_priv *priv, struct rsnd_ssi *ssi)
 {
-       if (!rsnd_ssi_is_pin_sharing(&ssi->mod))
+       struct rsnd_mod *mod = rsnd_mod_get(ssi);
+
+       if (!rsnd_ssi_is_pin_sharing(mod))
                return;
 
-       switch (rsnd_mod_id(&ssi->mod)) {
+       switch (rsnd_mod_id(mod)) {
        case 1:
        case 2:
                ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 0));
@@ -794,7 +803,8 @@ int rsnd_ssi_probe(struct platform_device *pdev,
                else if (rsnd_ssi_pio_available(ssi))
                        ops = &rsnd_ssi_pio_ops;
 
-               ret = rsnd_mod_init(priv, &ssi->mod, ops, clk, RSND_MOD_SSI, i);
+               ret = rsnd_mod_init(priv, rsnd_mod_get(ssi), ops, clk,
+                                   RSND_MOD_SSI, i);
                if (ret)
                        return ret;
 
@@ -811,6 +821,6 @@ void rsnd_ssi_remove(struct platform_device *pdev,
        int i;
 
        for_each_rsnd_ssi(ssi, priv, i) {
-               rsnd_mod_quit(&ssi->mod);
+               rsnd_mod_quit(rsnd_mod_get(ssi));
        }
 }