ASoC: make ops a pointer in 'struct snd_soc_dai'
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / sound / soc / fsl / fsl_ssi.c
index 157a7895ffa1befbb2427b121f0bb493c0190b3d..0fddd437a7c9e5b329336ce16027dd0dc37892b4 100644 (file)
@@ -266,7 +266,8 @@ static irqreturn_t fsl_ssi_isr(int irq, void *dev_id)
  * If this is the first stream open, then grab the IRQ and program most of
  * the SSI registers.
  */
-static int fsl_ssi_startup(struct snd_pcm_substream *substream)
+static int fsl_ssi_startup(struct snd_pcm_substream *substream,
+                          struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct fsl_ssi_private *ssi_private = rtd->dai->cpu_dai->private_data;
@@ -399,7 +400,7 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream)
 }
 
 /**
- * fsl_ssi_prepare: prepare the SSI.
+ * fsl_ssi_hw_params - program the sample size
  *
  * Most of the SSI registers have been programmed in the startup function,
  * but the word length must be programmed here.  Unfortunately, programming
@@ -411,19 +412,19 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream)
  * Note: The SxCCR.DC and SxCCR.PM bits are only used if the SSI is the
  * clock master.
  */
-static int fsl_ssi_prepare(struct snd_pcm_substream *substream)
+static int fsl_ssi_hw_params(struct snd_pcm_substream *substream,
+       struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *cpu_dai)
 {
-       struct snd_pcm_runtime *runtime = substream->runtime;
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct fsl_ssi_private *ssi_private = rtd->dai->cpu_dai->private_data;
-
-       struct ccsr_ssi __iomem *ssi = ssi_private->ssi;
+       struct fsl_ssi_private *ssi_private = cpu_dai->private_data;
 
        if (substream == ssi_private->first_stream) {
+               struct ccsr_ssi __iomem *ssi = ssi_private->ssi;
+               unsigned int sample_size =
+                       snd_pcm_format_width(params_format(hw_params));
                u32 wl;
 
                /* The SSI should always be disabled at this points (SSIEN=0) */
-               wl = CCSR_SSI_SxCCR_WL(snd_pcm_format_width(runtime->format));
+               wl = CCSR_SSI_SxCCR_WL(sample_size);
 
                /* In synchronous mode, the SSI uses STCCR for capture */
                clrsetbits_be32(&ssi->stccr, CCSR_SSI_SxCCR_WL_MASK, wl);
@@ -441,7 +442,8 @@ static int fsl_ssi_prepare(struct snd_pcm_substream *substream)
  * The DMA channel is in external master start and pause mode, which
  * means the SSI completely controls the flow of data.
  */
-static int fsl_ssi_trigger(struct snd_pcm_substream *substream, int cmd)
+static int fsl_ssi_trigger(struct snd_pcm_substream *substream, int cmd,
+                          struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct fsl_ssi_private *ssi_private = rtd->dai->cpu_dai->private_data;
@@ -490,7 +492,8 @@ static int fsl_ssi_trigger(struct snd_pcm_substream *substream, int cmd)
  *
  * Shutdown the SSI if there are no other substreams open.
  */
-static void fsl_ssi_shutdown(struct snd_pcm_substream *substream)
+static void fsl_ssi_shutdown(struct snd_pcm_substream *substream,
+                            struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct fsl_ssi_private *ssi_private = rtd->dai->cpu_dai->private_data;
@@ -559,6 +562,15 @@ static int fsl_ssi_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int format)
 /**
  * fsl_ssi_dai_template: template CPU DAI for the SSI
  */
+static struct snd_soc_dai_ops fsl_ssi_dai_ops = {
+       .startup        = fsl_ssi_startup,
+       .hw_params      = fsl_ssi_hw_params,
+       .shutdown       = fsl_ssi_shutdown,
+       .trigger        = fsl_ssi_trigger,
+       .set_sysclk     = fsl_ssi_set_sysclk,
+       .set_fmt        = fsl_ssi_set_fmt,
+};
+
 static struct snd_soc_dai fsl_ssi_dai_template = {
        .playback = {
                /* The SSI does not support monaural audio. */
@@ -573,16 +585,7 @@ static struct snd_soc_dai fsl_ssi_dai_template = {
                .rates = FSLSSI_I2S_RATES,
                .formats = FSLSSI_I2S_FORMATS,
        },
-       .ops = {
-               .startup = fsl_ssi_startup,
-               .prepare = fsl_ssi_prepare,
-               .shutdown = fsl_ssi_shutdown,
-               .trigger = fsl_ssi_trigger,
-       },
-       .dai_ops = {
-               .set_sysclk = fsl_ssi_set_sysclk,
-               .set_fmt = fsl_ssi_set_fmt,
-       },
+       .ops = &fsl_ssi_dai_ops,
 };
 
 /**
@@ -671,6 +674,14 @@ struct snd_soc_dai *fsl_ssi_create_dai(struct fsl_ssi_info *ssi_info)
        fsl_ssi_dai->private_data = ssi_private;
        fsl_ssi_dai->name = ssi_private->name;
        fsl_ssi_dai->id = ssi_info->id;
+       fsl_ssi_dai->dev = ssi_info->dev;
+
+       ret = snd_soc_register_dai(fsl_ssi_dai);
+       if (ret != 0) {
+               dev_err(ssi_info->dev, "failed to register DAI: %d\n", ret);
+               kfree(fsl_ssi_dai);
+               return NULL;
+       }
 
        return fsl_ssi_dai;
 }
@@ -688,6 +699,8 @@ void fsl_ssi_destroy_dai(struct snd_soc_dai *fsl_ssi_dai)
 
        device_remove_file(ssi_private->dev, &ssi_private->dev_attr);
 
+       snd_soc_unregister_dai(&ssi_private->cpu_dai);
+
        kfree(ssi_private);
 }
 EXPORT_SYMBOL_GPL(fsl_ssi_destroy_dai);