Merge branch 'fix/rcar' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[muen/linux.git] / sound / soc / sh / rcar / core.c
index 7fa40fcad59e03135c44677ff2678dc66a1c73b1..2c12ad2b2b3484c973766745238d3ba9dc0b1458 100644 (file)
@@ -843,12 +843,28 @@ static int rsnd_soc_hw_rule_channels(struct snd_pcm_hw_params *params,
                                ir, &ic);
 }
 
-static void rsnd_soc_hw_constraint(struct snd_pcm_runtime *runtime,
-                                  struct snd_soc_dai *dai)
+static struct snd_pcm_hardware rsnd_pcm_hardware = {
+       .info =         SNDRV_PCM_INFO_INTERLEAVED      |
+                       SNDRV_PCM_INFO_MMAP             |
+                       SNDRV_PCM_INFO_MMAP_VALID,
+       .buffer_bytes_max       = 64 * 1024,
+       .period_bytes_min       = 32,
+       .period_bytes_max       = 8192,
+       .periods_min            = 1,
+       .periods_max            = 32,
+       .fifo_size              = 256,
+};
+
+static int rsnd_soc_dai_startup(struct snd_pcm_substream *substream,
+                               struct snd_soc_dai *dai)
 {
        struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
+       struct rsnd_priv *priv = rsnd_rdai_to_priv(rdai);
+       struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
        struct snd_pcm_hw_constraint_list *constraint = &rdai->constraint;
+       struct snd_pcm_runtime *runtime = substream->runtime;
        unsigned int max_channels = rsnd_rdai_channels_get(rdai);
+       int ret;
        int i;
 
        /*
@@ -865,34 +881,26 @@ static void rsnd_soc_hw_constraint(struct snd_pcm_runtime *runtime,
                constraint->count = i + 1;
        }
 
+       snd_soc_set_runtime_hwparams(substream, &rsnd_pcm_hardware);
+
        snd_pcm_hw_constraint_list(runtime, 0,
                                   SNDRV_PCM_HW_PARAM_CHANNELS, constraint);
 
+       snd_pcm_hw_constraint_integer(runtime,
+                                     SNDRV_PCM_HW_PARAM_PERIODS);
+
        /*
         * Sampling Rate / Channel Limitation
         * It depends on Clock Master Mode
         */
-       if (!rsnd_rdai_is_clk_master(rdai))
-               return;
-
-       snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
-                           rsnd_soc_hw_rule_rate, dai,
-                           SNDRV_PCM_HW_PARAM_CHANNELS, -1);
-       snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
-                           rsnd_soc_hw_rule_channels, dai,
-                           SNDRV_PCM_HW_PARAM_RATE, -1);
-}
-
-static int rsnd_soc_dai_startup(struct snd_pcm_substream *substream,
-                               struct snd_soc_dai *dai)
-{
-       struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
-       struct rsnd_priv *priv = rsnd_rdai_to_priv(rdai);
-       struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
-       int ret;
-
-       /* rsnd_io_to_runtime() is not yet enabled here */
-       rsnd_soc_hw_constraint(substream->runtime, dai);
+       if (rsnd_rdai_is_clk_master(rdai)) {
+               snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
+                                   rsnd_soc_hw_rule_rate, dai,
+                                   SNDRV_PCM_HW_PARAM_CHANNELS, -1);
+               snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
+                                   rsnd_soc_hw_rule_channels, dai,
+                                   SNDRV_PCM_HW_PARAM_RATE, -1);
+       }
 
        /*
         * call rsnd_dai_call without spinlock
@@ -1104,31 +1112,6 @@ static int rsnd_dai_probe(struct rsnd_priv *priv)
 /*
  *             pcm ops
  */
-static struct snd_pcm_hardware rsnd_pcm_hardware = {
-       .info =         SNDRV_PCM_INFO_INTERLEAVED      |
-                       SNDRV_PCM_INFO_MMAP             |
-                       SNDRV_PCM_INFO_MMAP_VALID,
-       .buffer_bytes_max       = 64 * 1024,
-       .period_bytes_min       = 32,
-       .period_bytes_max       = 8192,
-       .periods_min            = 1,
-       .periods_max            = 32,
-       .fifo_size              = 256,
-};
-
-static int rsnd_pcm_open(struct snd_pcm_substream *substream)
-{
-       struct snd_pcm_runtime *runtime = substream->runtime;
-       int ret = 0;
-
-       snd_soc_set_runtime_hwparams(substream, &rsnd_pcm_hardware);
-
-       ret = snd_pcm_hw_constraint_integer(runtime,
-                                           SNDRV_PCM_HW_PARAM_PERIODS);
-
-       return ret;
-}
-
 static int rsnd_hw_params(struct snd_pcm_substream *substream,
                         struct snd_pcm_hw_params *hw_params)
 {
@@ -1158,7 +1141,6 @@ static snd_pcm_uframes_t rsnd_pointer(struct snd_pcm_substream *substream)
 }
 
 static struct snd_pcm_ops rsnd_pcm_ops = {
-       .open           = rsnd_pcm_open,
        .ioctl          = snd_pcm_lib_ioctl,
        .hw_params      = rsnd_hw_params,
        .hw_free        = snd_pcm_lib_free_pages,
@@ -1168,11 +1150,10 @@ static struct snd_pcm_ops rsnd_pcm_ops = {
 /*
  *             snd_kcontrol
  */
-#define kcontrol_to_cfg(kctrl) ((struct rsnd_kctrl_cfg *)kctrl->private_value)
 static int rsnd_kctrl_info(struct snd_kcontrol *kctrl,
                           struct snd_ctl_elem_info *uinfo)
 {
-       struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
+       struct rsnd_kctrl_cfg *cfg = snd_kcontrol_chip(kctrl);
 
        if (cfg->texts) {
                uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
@@ -1198,7 +1179,7 @@ static int rsnd_kctrl_info(struct snd_kcontrol *kctrl,
 static int rsnd_kctrl_get(struct snd_kcontrol *kctrl,
                          struct snd_ctl_elem_value *uc)
 {
-       struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
+       struct rsnd_kctrl_cfg *cfg = snd_kcontrol_chip(kctrl);
        int i;
 
        for (i = 0; i < cfg->size; i++)
@@ -1213,8 +1194,7 @@ static int rsnd_kctrl_get(struct snd_kcontrol *kctrl,
 static int rsnd_kctrl_put(struct snd_kcontrol *kctrl,
                          struct snd_ctl_elem_value *uc)
 {
-       struct rsnd_mod *mod = snd_kcontrol_chip(kctrl);
-       struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
+       struct rsnd_kctrl_cfg *cfg = snd_kcontrol_chip(kctrl);
        int i, change = 0;
 
        if (!cfg->accept(cfg->io))
@@ -1231,7 +1211,7 @@ static int rsnd_kctrl_put(struct snd_kcontrol *kctrl,
        }
 
        if (change && cfg->update)
-               cfg->update(cfg->io, mod);
+               cfg->update(cfg->io, cfg->mod);
 
        return change;
 }
@@ -1283,14 +1263,13 @@ int rsnd_kctrl_new(struct rsnd_mod *mod,
                .index          = rtd->num,
                .get            = rsnd_kctrl_get,
                .put            = rsnd_kctrl_put,
-               .private_value  = (unsigned long)cfg,
        };
        int ret;
 
        if (size > RSND_MAX_CHANNELS)
                return -EINVAL;
 
-       kctrl = snd_ctl_new1(&knew, mod);
+       kctrl = snd_ctl_new1(&knew, cfg);
        if (!kctrl)
                return -ENOMEM;
 
@@ -1306,6 +1285,7 @@ int rsnd_kctrl_new(struct rsnd_mod *mod,
        cfg->card       = card;
        cfg->kctrl      = kctrl;
        cfg->io         = io;
+       cfg->mod        = mod;
 
        return 0;
 }