diff options
Diffstat (limited to 'sound/soc/codecs/wm9712.c')
| -rw-r--r-- | sound/soc/codecs/wm9712.c | 170 |
1 files changed, 84 insertions, 86 deletions
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c index 1a3e1797994a..83cd42fa0c28 100644 --- a/sound/soc/codecs/wm9712.c +++ b/sound/soc/codecs/wm9712.c @@ -1,17 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * wm9712.c -- ALSA Soc WM9712 codec support * * Copyright 2006-12 Wolfson Microelectronics PLC. * Author: Liam Girdwood <lrg@slimlogic.co.uk> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. */ #include <linux/init.h> #include <linux/slab.h> +#include <linux/mfd/wm97xx.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/device.h> @@ -19,6 +16,8 @@ #include <sound/core.h> #include <sound/pcm.h> #include <sound/ac97_codec.h> +#include <sound/ac97/codec.h> +#include <sound/ac97/compat.h> #include <sound/initval.h> #include <sound/soc.h> #include <sound/tlv.h> @@ -30,6 +29,7 @@ struct wm9712_priv { struct snd_ac97 *ac97; unsigned int hp_mixer[2]; struct mutex lock; + struct wm97xx_platform_data *mfd_pdata; }; static const struct reg_default wm9712_reg_defaults[] = { @@ -86,7 +86,7 @@ static const struct regmap_config wm9712_regmap_config = { .reg_stride = 2, .val_bits = 16, .max_register = 0x7e, - .cache_type = REGCACHE_RBTREE, + .cache_type = REGCACHE_MAPLE, .volatile_reg = wm9712_volatile_reg, @@ -215,14 +215,14 @@ static const unsigned int wm9712_mixer_mute_regs[] = { static int wm9712_hp_mixer_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); - struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_to_dapm(kcontrol); + struct snd_soc_component *component = snd_soc_dapm_to_component(dapm); + struct wm9712_priv *wm9712 = snd_soc_component_get_drvdata(component); unsigned int val = ucontrol->value.integer.value[0]; struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; unsigned int mixer, mask, shift, old; - struct snd_soc_dapm_update update = { 0 }; + struct snd_soc_dapm_update update = {}; bool change; mixer = mc->shift >> 8; @@ -259,9 +259,9 @@ static int wm9712_hp_mixer_put(struct snd_kcontrol *kcontrol, static int wm9712_hp_mixer_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); - struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_to_dapm(kcontrol); + struct snd_soc_component *component = snd_soc_dapm_to_component(dapm); + struct wm9712_priv *wm9712 = snd_soc_component_get_drvdata(component); struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; unsigned int shift, mixer; @@ -275,13 +275,9 @@ static int wm9712_hp_mixer_get(struct snd_kcontrol *kcontrol, return 0; } -#define WM9712_HP_MIXER_CTRL(xname, xmixer, xshift) { \ - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ - .info = snd_soc_info_volsw, \ - .get = wm9712_hp_mixer_get, .put = wm9712_hp_mixer_put, \ - .private_value = SOC_SINGLE_VALUE(SND_SOC_NOPM, \ - (xmixer << 8) | xshift, 1, 0, 0) \ -} +#define WM9712_HP_MIXER_CTRL(xname, xmixer, xshift) \ + SOC_SINGLE_EXT(xname, SND_SOC_NOPM, ((xmixer) << 8) | (xshift), \ + 1, 0, wm9712_hp_mixer_get, wm9712_hp_mixer_put) /* Left Headphone Mixers */ static const struct snd_kcontrol_new wm9712_hpl_mixer_controls[] = { @@ -523,33 +519,33 @@ static const struct snd_soc_dapm_route wm9712_audio_map[] = { static int ac97_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct snd_soc_codec *codec = dai->codec; + struct snd_soc_component *component = dai->component; int reg; struct snd_pcm_runtime *runtime = substream->runtime; - snd_soc_update_bits(codec, AC97_EXTENDED_STATUS, 0x1, 0x1); + snd_soc_component_update_bits(component, AC97_EXTENDED_STATUS, 0x1, 0x1); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) reg = AC97_PCM_FRONT_DAC_RATE; else reg = AC97_PCM_LR_ADC_RATE; - return snd_soc_write(codec, reg, runtime->rate); + return snd_soc_component_write(component, reg, runtime->rate); } static int ac97_aux_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct snd_soc_codec *codec = dai->codec; + struct snd_soc_component *component = dai->component; struct snd_pcm_runtime *runtime = substream->runtime; - snd_soc_update_bits(codec, AC97_EXTENDED_STATUS, 0x1, 0x1); - snd_soc_update_bits(codec, AC97_PCI_SID, 0x8000, 0x8000); + snd_soc_component_update_bits(component, AC97_EXTENDED_STATUS, 0x1, 0x1); + snd_soc_component_update_bits(component, AC97_PCI_SID, 0x8000, 0x8000); if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) return -ENODEV; - return snd_soc_write(codec, AC97_PCM_SURR_DAC_RATE, runtime->rate); + return snd_soc_component_write(component, AC97_PCM_SURR_DAC_RATE, runtime->rate); } #define WM9712_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ @@ -593,7 +589,7 @@ static struct snd_soc_dai_driver wm9712_dai[] = { } }; -static int wm9712_set_bias_level(struct snd_soc_codec *codec, +static int wm9712_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { switch (level) { @@ -601,20 +597,21 @@ static int wm9712_set_bias_level(struct snd_soc_codec *codec, case SND_SOC_BIAS_PREPARE: break; case SND_SOC_BIAS_STANDBY: - snd_soc_write(codec, AC97_POWERDOWN, 0x0000); + snd_soc_component_write(component, AC97_POWERDOWN, 0x0000); break; case SND_SOC_BIAS_OFF: /* disable everything including AC link */ - snd_soc_write(codec, AC97_EXTENDED_MSTATUS, 0xffff); - snd_soc_write(codec, AC97_POWERDOWN, 0xffff); + snd_soc_component_write(component, AC97_EXTENDED_MSTATUS, 0xffff); + snd_soc_component_write(component, AC97_POWERDOWN, 0xffff); break; } return 0; } -static int wm9712_soc_resume(struct snd_soc_codec *codec) +static int wm9712_soc_resume(struct snd_soc_component *component) { - struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); + struct wm9712_priv *wm9712 = snd_soc_component_get_drvdata(component); + struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component); int ret; ret = snd_ac97_reset(wm9712->ac97, true, WM9712_VENDOR_ID, @@ -622,69 +619,76 @@ static int wm9712_soc_resume(struct snd_soc_codec *codec) if (ret < 0) return ret; - snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY); + snd_soc_dapm_force_bias_level(dapm, SND_SOC_BIAS_STANDBY); if (ret == 0) - regcache_sync(codec->component.regmap); + snd_soc_component_cache_sync(component); return ret; } -static int wm9712_soc_probe(struct snd_soc_codec *codec) +static int wm9712_soc_probe(struct snd_soc_component *component) { - struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); + struct wm9712_priv *wm9712 = snd_soc_component_get_drvdata(component); struct regmap *regmap; - int ret; - - wm9712->ac97 = snd_soc_new_ac97_codec(codec, WM9712_VENDOR_ID, - WM9712_VENDOR_ID_MASK); - if (IS_ERR(wm9712->ac97)) { - ret = PTR_ERR(wm9712->ac97); - dev_err(codec->dev, "Failed to register AC97 codec: %d\n", ret); - return ret; - } - regmap = regmap_init_ac97(wm9712->ac97, &wm9712_regmap_config); - if (IS_ERR(regmap)) { - ret = PTR_ERR(regmap); - goto err_free_ac97_codec; + if (wm9712->mfd_pdata) { + wm9712->ac97 = wm9712->mfd_pdata->ac97; + regmap = wm9712->mfd_pdata->regmap; + } else if (IS_ENABLED(CONFIG_SND_SOC_AC97_BUS)) { + int ret; + + wm9712->ac97 = snd_soc_new_ac97_component(component, WM9712_VENDOR_ID, + WM9712_VENDOR_ID_MASK); + if (IS_ERR(wm9712->ac97)) { + ret = PTR_ERR(wm9712->ac97); + dev_err(component->dev, + "Failed to register AC97 codec: %d\n", ret); + return ret; + } + + regmap = regmap_init_ac97(wm9712->ac97, &wm9712_regmap_config); + if (IS_ERR(regmap)) { + snd_soc_free_ac97_component(wm9712->ac97); + return PTR_ERR(regmap); + } + } else { + return -ENXIO; } - snd_soc_codec_init_regmap(codec, regmap); + snd_soc_component_init_regmap(component, regmap); /* set alc mux to none */ - snd_soc_update_bits(codec, AC97_VIDEO, 0x3000, 0x3000); + snd_soc_component_update_bits(component, AC97_VIDEO, 0x3000, 0x3000); return 0; -err_free_ac97_codec: - snd_soc_free_ac97_codec(wm9712->ac97); - return ret; } -static int wm9712_soc_remove(struct snd_soc_codec *codec) +static void wm9712_soc_remove(struct snd_soc_component *component) { - struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); + struct wm9712_priv *wm9712 = snd_soc_component_get_drvdata(component); - snd_soc_codec_exit_regmap(codec); - snd_soc_free_ac97_codec(wm9712->ac97); - return 0; + if (IS_ENABLED(CONFIG_SND_SOC_AC97_BUS) && !wm9712->mfd_pdata) { + snd_soc_component_exit_regmap(component); + snd_soc_free_ac97_component(wm9712->ac97); + } } -static const struct snd_soc_codec_driver soc_codec_dev_wm9712 = { - .probe = wm9712_soc_probe, - .remove = wm9712_soc_remove, - .resume = wm9712_soc_resume, - .set_bias_level = wm9712_set_bias_level, - .suspend_bias_off = true, - - .component_driver = { - .controls = wm9712_snd_ac97_controls, - .num_controls = ARRAY_SIZE(wm9712_snd_ac97_controls), - .dapm_widgets = wm9712_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(wm9712_dapm_widgets), - .dapm_routes = wm9712_audio_map, - .num_dapm_routes = ARRAY_SIZE(wm9712_audio_map), - }, +static const struct snd_soc_component_driver soc_component_dev_wm9712 = { + .probe = wm9712_soc_probe, + .remove = wm9712_soc_remove, + .resume = wm9712_soc_resume, + .set_bias_level = wm9712_set_bias_level, + .controls = wm9712_snd_ac97_controls, + .num_controls = ARRAY_SIZE(wm9712_snd_ac97_controls), + .dapm_widgets = wm9712_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(wm9712_dapm_widgets), + .dapm_routes = wm9712_audio_map, + .num_dapm_routes = ARRAY_SIZE(wm9712_audio_map), + .suspend_bias_off = 1, + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, }; static int wm9712_probe(struct platform_device *pdev) @@ -697,28 +701,22 @@ static int wm9712_probe(struct platform_device *pdev) mutex_init(&wm9712->lock); + wm9712->mfd_pdata = dev_get_platdata(&pdev->dev); platform_set_drvdata(pdev, wm9712); - return snd_soc_register_codec(&pdev->dev, - &soc_codec_dev_wm9712, wm9712_dai, ARRAY_SIZE(wm9712_dai)); -} - -static int wm9712_remove(struct platform_device *pdev) -{ - snd_soc_unregister_codec(&pdev->dev); - return 0; + return devm_snd_soc_register_component(&pdev->dev, + &soc_component_dev_wm9712, wm9712_dai, ARRAY_SIZE(wm9712_dai)); } -static struct platform_driver wm9712_codec_driver = { +static struct platform_driver wm9712_component_driver = { .driver = { .name = "wm9712-codec", }, .probe = wm9712_probe, - .remove = wm9712_remove, }; -module_platform_driver(wm9712_codec_driver); +module_platform_driver(wm9712_component_driver); MODULE_DESCRIPTION("ASoC WM9711/WM9712 driver"); MODULE_AUTHOR("Liam Girdwood"); |
