diff options
Diffstat (limited to 'sound/soc/codecs/sti-sas.c')
| -rw-r--r-- | sound/soc/codecs/sti-sas.c | 122 |
1 files changed, 49 insertions, 73 deletions
diff --git a/sound/soc/codecs/sti-sas.c b/sound/soc/codecs/sti-sas.c index 62c618765224..4ab15be69f3a 100644 --- a/sound/soc/codecs/sti-sas.c +++ b/sound/soc/codecs/sti-sas.c @@ -1,8 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) STMicroelectronics SA 2015 * Authors: Arnaud Pouliquen <arnaud.pouliquen@st.com> * for STMicroelectronics. - * License terms: GNU General Public License (GPL), version 2 */ #include <linux/io.h> @@ -51,14 +51,11 @@ static const struct reg_default stih407_sas_reg_defaults[] = { struct sti_dac_audio { struct regmap *regmap; struct regmap *virt_regmap; - struct regmap_field **field; - struct reset_control *rst; int mclk; }; struct sti_spdif_audio { struct regmap *regmap; - struct regmap_field **field; int mclk; }; @@ -66,10 +63,6 @@ struct sti_spdif_audio { struct sti_sas_dev_data { const struct regmap_config *regmap; const struct snd_soc_dai_ops *dac_ops; /* DAC function callbacks */ - const struct snd_soc_dapm_widget *dapm_widgets; /* dapms declaration */ - const int num_dapm_widgets; /* dapms declaration */ - const struct snd_soc_dapm_route *dapm_routes; /* route declaration */ - const int num_dapm_routes; /* route declaration */ }; /* driver data structure */ @@ -99,14 +92,11 @@ static int sti_sas_write_reg(void *context, unsigned int reg, unsigned int value) { struct sti_sas_data *drvdata = context; - int status; - - status = regmap_write(drvdata->dac.regmap, reg, value); - return status; + return regmap_write(drvdata->dac.regmap, reg, value); } -static int sti_sas_init_sas_registers(struct snd_soc_codec *codec, +static int sti_sas_init_sas_registers(struct snd_soc_component *component, struct sti_sas_data *data) { int ret; @@ -116,35 +106,35 @@ static int sti_sas_init_sas_registers(struct snd_soc_codec *codec, */ /* Initialise bi-phase formatter to disabled */ - ret = snd_soc_update_bits(codec, STIH407_AUDIO_GLUE_CTRL, + ret = snd_soc_component_update_bits(component, STIH407_AUDIO_GLUE_CTRL, SPDIF_BIPHASE_ENABLE_MASK, 0); if (!ret) /* Initialise bi-phase formatter idle value to 0 */ - ret = snd_soc_update_bits(codec, STIH407_AUDIO_GLUE_CTRL, + ret = snd_soc_component_update_bits(component, STIH407_AUDIO_GLUE_CTRL, SPDIF_BIPHASE_IDLE_MASK, 0); if (ret < 0) { - dev_err(codec->dev, "Failed to update SPDIF registers\n"); + dev_err(component->dev, "Failed to update SPDIF registers\n"); return ret; } /* Init DAC configuration */ /* init configuration */ - ret = snd_soc_update_bits(codec, STIH407_AUDIO_DAC_CTRL, + ret = snd_soc_component_update_bits(component, STIH407_AUDIO_DAC_CTRL, STIH407_DAC_STANDBY_MASK, STIH407_DAC_STANDBY_MASK); if (!ret) - ret = snd_soc_update_bits(codec, STIH407_AUDIO_DAC_CTRL, + ret = snd_soc_component_update_bits(component, STIH407_AUDIO_DAC_CTRL, STIH407_DAC_STANDBY_ANA_MASK, STIH407_DAC_STANDBY_ANA_MASK); if (!ret) - ret = snd_soc_update_bits(codec, STIH407_AUDIO_DAC_CTRL, + ret = snd_soc_component_update_bits(component, STIH407_AUDIO_DAC_CTRL, STIH407_DAC_SOFTMUTE_MASK, STIH407_DAC_SOFTMUTE_MASK); if (ret < 0) { - dev_err(codec->dev, "Failed to update DAC registers\n"); + dev_err(component->dev, "Failed to update DAC registers\n"); return ret; } @@ -157,10 +147,10 @@ static int sti_sas_init_sas_registers(struct snd_soc_codec *codec, static int sti_sas_dac_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) { /* Sanity check only */ - if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) { - dev_err(dai->codec->dev, - "%s: ERROR: Unsupporter master mask 0x%x\n", - __func__, fmt & SND_SOC_DAIFMT_MASTER_MASK); + if ((fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) != SND_SOC_DAIFMT_CBC_CFC) { + dev_err(dai->component->dev, + "%s: ERROR: Unsupported clocking 0x%x\n", + __func__, fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK); return -EINVAL; } @@ -183,14 +173,14 @@ static const struct snd_soc_dapm_route stih407_sas_route[] = { static int stih407_sas_dac_mute(struct snd_soc_dai *dai, int mute, int stream) { - struct snd_soc_codec *codec = dai->codec; + struct snd_soc_component *component = dai->component; if (mute) { - return snd_soc_update_bits(codec, STIH407_AUDIO_DAC_CTRL, + return snd_soc_component_update_bits(component, STIH407_AUDIO_DAC_CTRL, STIH407_DAC_SOFTMUTE_MASK, STIH407_DAC_SOFTMUTE_MASK); } else { - return snd_soc_update_bits(codec, STIH407_AUDIO_DAC_CTRL, + return snd_soc_component_update_bits(component, STIH407_AUDIO_DAC_CTRL, STIH407_DAC_SOFTMUTE_MASK, 0); } @@ -202,10 +192,10 @@ static int stih407_sas_dac_mute(struct snd_soc_dai *dai, int mute, int stream) static int sti_sas_spdif_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) { - if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) { - dev_err(dai->codec->dev, - "%s: ERROR: Unsupporter master mask 0x%x\n", - __func__, fmt & SND_SOC_DAIFMT_MASTER_MASK); + if ((fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) != SND_SOC_DAIFMT_CBC_CFC) { + dev_err(dai->component->dev, + "%s: ERROR: Unsupported clocking mask 0x%x\n", + __func__, fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK); return -EINVAL; } @@ -221,19 +211,19 @@ static int sti_sas_spdif_set_fmt(struct snd_soc_dai *dai, static int sti_sas_spdif_trigger(struct snd_pcm_substream *substream, int cmd, struct snd_soc_dai *dai) { - struct snd_soc_codec *codec = dai->codec; + struct snd_soc_component *component = dai->component; switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: - return snd_soc_update_bits(codec, STIH407_AUDIO_GLUE_CTRL, + return snd_soc_component_update_bits(component, STIH407_AUDIO_GLUE_CTRL, SPDIF_BIPHASE_ENABLE_MASK, SPDIF_BIPHASE_ENABLE_MASK); case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: - return snd_soc_update_bits(codec, STIH407_AUDIO_GLUE_CTRL, + return snd_soc_component_update_bits(component, STIH407_AUDIO_GLUE_CTRL, SPDIF_BIPHASE_ENABLE_MASK, 0); default: @@ -260,8 +250,8 @@ static bool sti_sas_volatile_register(struct device *dev, unsigned int reg) static int sti_sas_set_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int freq, int dir) { - struct snd_soc_codec *codec = dai->codec; - struct sti_sas_data *drvdata = dev_get_drvdata(codec->dev); + struct snd_soc_component *component = dai->component; + struct sti_sas_data *drvdata = dev_get_drvdata(component->dev); if (dir == SND_SOC_CLOCK_OUT) return 0; @@ -285,20 +275,20 @@ static int sti_sas_set_sysclk(struct snd_soc_dai *dai, int clk_id, static int sti_sas_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct snd_soc_codec *codec = dai->codec; - struct sti_sas_data *drvdata = dev_get_drvdata(codec->dev); + struct snd_soc_component *component = dai->component; + struct sti_sas_data *drvdata = dev_get_drvdata(component->dev); struct snd_pcm_runtime *runtime = substream->runtime; switch (dai->id) { case STI_SAS_DAI_SPDIF_OUT: if ((drvdata->spdif.mclk / runtime->rate) != 128) { - dev_err(codec->dev, "unexpected mclk-fs ratio\n"); + dev_err(component->dev, "unexpected mclk-fs ratio\n"); return -EINVAL; } break; case STI_SAS_DAI_ANALOG_OUT: if ((drvdata->dac.mclk / runtime->rate) != 256) { - dev_err(codec->dev, "unexpected mclk-fs ratio\n"); + dev_err(component->dev, "unexpected mclk-fs ratio\n"); return -EINVAL; } break; @@ -322,7 +312,7 @@ static const struct regmap_config stih407_sas_regmap = { .reg_defaults = stih407_sas_reg_defaults, .num_reg_defaults = ARRAY_SIZE(stih407_sas_reg_defaults), .volatile_reg = sti_sas_volatile_register, - .cache_type = REGCACHE_RBTREE, + .cache_type = REGCACHE_MAPLE, .reg_read = sti_sas_read_reg, .reg_write = sti_sas_write_reg, }; @@ -330,10 +320,6 @@ static const struct regmap_config stih407_sas_regmap = { static const struct sti_sas_dev_data stih407_data = { .regmap = &stih407_sas_regmap, .dac_ops = &stih407_dac_ops, - .dapm_widgets = stih407_sas_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(stih407_sas_dapm_widgets), - .dapm_routes = stih407_sas_route, - .num_dapm_routes = ARRAY_SIZE(stih407_sas_route), }; static struct snd_soc_dai_driver sti_sas_dai[] = { @@ -375,29 +361,33 @@ static struct snd_soc_dai_driver sti_sas_dai[] = { }; #ifdef CONFIG_PM_SLEEP -static int sti_sas_resume(struct snd_soc_codec *codec) +static int sti_sas_resume(struct snd_soc_component *component) { - struct sti_sas_data *drvdata = dev_get_drvdata(codec->dev); + struct sti_sas_data *drvdata = dev_get_drvdata(component->dev); - return sti_sas_init_sas_registers(codec, drvdata); + return sti_sas_init_sas_registers(component, drvdata); } #else #define sti_sas_resume NULL #endif -static int sti_sas_codec_probe(struct snd_soc_codec *codec) +static int sti_sas_component_probe(struct snd_soc_component *component) { - struct sti_sas_data *drvdata = dev_get_drvdata(codec->dev); - int ret; + struct sti_sas_data *drvdata = dev_get_drvdata(component->dev); - ret = sti_sas_init_sas_registers(codec, drvdata); - - return ret; + return sti_sas_init_sas_registers(component, drvdata); } -static struct snd_soc_codec_driver sti_sas_driver = { - .probe = sti_sas_codec_probe, - .resume = sti_sas_resume, +static const struct snd_soc_component_driver sti_sas_driver = { + .probe = sti_sas_component_probe, + .resume = sti_sas_resume, + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, + .dapm_widgets = stih407_sas_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(stih407_sas_dapm_widgets), + .dapm_routes = stih407_sas_route, + .num_dapm_routes = ARRAY_SIZE(stih407_sas_route), }; static const struct of_device_id sti_sas_dev_match[] = { @@ -407,6 +397,7 @@ static const struct of_device_id sti_sas_dev_match[] = { }, {}, }; +MODULE_DEVICE_TABLE(of, sti_sas_dev_match); static int sti_sas_driver_probe(struct platform_device *pdev) { @@ -451,35 +442,20 @@ static int sti_sas_driver_probe(struct platform_device *pdev) sti_sas_dai[STI_SAS_DAI_ANALOG_OUT].ops = drvdata->dev_data->dac_ops; - /* Set dapms*/ - sti_sas_driver.component_driver.dapm_widgets = drvdata->dev_data->dapm_widgets; - sti_sas_driver.component_driver.num_dapm_widgets = drvdata->dev_data->num_dapm_widgets; - - sti_sas_driver.component_driver.dapm_routes = drvdata->dev_data->dapm_routes; - sti_sas_driver.component_driver.num_dapm_routes = drvdata->dev_data->num_dapm_routes; - /* Store context */ dev_set_drvdata(&pdev->dev, drvdata); - return snd_soc_register_codec(&pdev->dev, &sti_sas_driver, + return devm_snd_soc_register_component(&pdev->dev, &sti_sas_driver, sti_sas_dai, ARRAY_SIZE(sti_sas_dai)); } -static int sti_sas_driver_remove(struct platform_device *pdev) -{ - snd_soc_unregister_codec(&pdev->dev); - - return 0; -} - static struct platform_driver sti_sas_platform_driver = { .driver = { .name = "sti-sas-codec", .of_match_table = sti_sas_dev_match, }, .probe = sti_sas_driver_probe, - .remove = sti_sas_driver_remove, }; module_platform_driver(sti_sas_platform_driver); |
