summaryrefslogtreecommitdiff
path: root/sound/soc/codecs/wm8737.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs/wm8737.c')
-rw-r--r--sound/soc/codecs/wm8737.c132
1 files changed, 57 insertions, 75 deletions
diff --git a/sound/soc/codecs/wm8737.c b/sound/soc/codecs/wm8737.c
index f0cb1c4afe3c..fee8a37ed1df 100644
--- a/sound/soc/codecs/wm8737.c
+++ b/sound/soc/codecs/wm8737.c
@@ -1,15 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0-only
/*
* wm8737.c -- WM8737 ALSA SoC Audio driver
*
* Copyright 2010 Wolfson Microelectronics plc
*
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
*/
+#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
@@ -20,7 +18,6 @@
#include <linux/regulator/consumer.h>
#include <linux/spi/spi.h>
#include <linux/slab.h>
-#include <linux/of_device.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
@@ -74,9 +71,9 @@ static bool wm8737_volatile(struct device *dev, unsigned int reg)
}
}
-static int wm8737_reset(struct snd_soc_codec *codec)
+static int wm8737_reset(struct snd_soc_component *component)
{
- return snd_soc_write(codec, WM8737_RESET, 0);
+ return snd_soc_component_write(component, WM8737_RESET, 0);
}
static const DECLARE_TLV_DB_RANGE(micboost_tlv,
@@ -170,7 +167,7 @@ SOC_DOUBLE("Polarity Invert Switch", WM8737_ADC_CONTROL, 5, 6, 1, 0),
SOC_SINGLE("3D Switch", WM8737_3D_ENHANCE, 0, 1, 0),
SOC_SINGLE("3D Depth", WM8737_3D_ENHANCE, 1, 15, 0),
SOC_ENUM("3D Low Cut-off", low_3d),
-SOC_ENUM("3D High Cut-off", low_3d),
+SOC_ENUM("3D High Cut-off", high_3d),
SOC_SINGLE_TLV("3D ADC Volume", WM8737_3D_ENHANCE, 7, 1, 1, adc_tlv),
SOC_SINGLE("Noise Gate Switch", WM8737_NOISE_GATE, 0, 1, 0),
@@ -328,8 +325,8 @@ static int wm8737_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
{
- struct snd_soc_codec *codec = dai->codec;
- struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
+ struct snd_soc_component *component = dai->component;
+ struct wm8737_priv *wm8737 = snd_soc_component_get_drvdata(component);
int i;
u16 clocking = 0;
u16 af = 0;
@@ -348,7 +345,7 @@ static int wm8737_hw_params(struct snd_pcm_substream *substream,
}
if (i == ARRAY_SIZE(coeff_div)) {
- dev_err(codec->dev, "%dHz MCLK can't support %dHz\n",
+ dev_err(component->dev, "%dHz MCLK can't support %dHz\n",
wm8737->mclk, params_rate(params));
return -EINVAL;
}
@@ -371,8 +368,8 @@ static int wm8737_hw_params(struct snd_pcm_substream *substream,
return -EINVAL;
}
- snd_soc_update_bits(codec, WM8737_AUDIO_FORMAT, WM8737_WL_MASK, af);
- snd_soc_update_bits(codec, WM8737_CLOCKING,
+ snd_soc_component_update_bits(component, WM8737_AUDIO_FORMAT, WM8737_WL_MASK, af);
+ snd_soc_component_update_bits(component, WM8737_CLOCKING,
WM8737_USB_MODE | WM8737_CLKDIV2 | WM8737_SR_MASK,
clocking);
@@ -382,8 +379,8 @@ static int wm8737_hw_params(struct snd_pcm_substream *substream,
static int wm8737_set_dai_sysclk(struct snd_soc_dai *codec_dai,
int clk_id, unsigned int freq, int dir)
{
- struct snd_soc_codec *codec = codec_dai->codec;
- struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
+ struct snd_soc_component *component = codec_dai->component;
+ struct wm8737_priv *wm8737 = snd_soc_component_get_drvdata(component);
int i;
for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
@@ -394,7 +391,7 @@ static int wm8737_set_dai_sysclk(struct snd_soc_dai *codec_dai,
}
}
- dev_err(codec->dev, "MCLK rate %dHz not supported\n", freq);
+ dev_err(component->dev, "MCLK rate %dHz not supported\n", freq);
return -EINVAL;
}
@@ -403,14 +400,14 @@ static int wm8737_set_dai_sysclk(struct snd_soc_dai *codec_dai,
static int wm8737_set_dai_fmt(struct snd_soc_dai *codec_dai,
unsigned int fmt)
{
- struct snd_soc_codec *codec = codec_dai->codec;
+ struct snd_soc_component *component = codec_dai->component;
u16 af = 0;
switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
- case SND_SOC_DAIFMT_CBM_CFM:
+ case SND_SOC_DAIFMT_CBP_CFP:
af |= WM8737_MS;
break;
- case SND_SOC_DAIFMT_CBS_CFS:
+ case SND_SOC_DAIFMT_CBC_CFC:
break;
default:
return -EINVAL;
@@ -445,16 +442,17 @@ static int wm8737_set_dai_fmt(struct snd_soc_dai *codec_dai,
return -EINVAL;
}
- snd_soc_update_bits(codec, WM8737_AUDIO_FORMAT,
+ snd_soc_component_update_bits(component, WM8737_AUDIO_FORMAT,
WM8737_FORMAT_MASK | WM8737_LRP | WM8737_MS, af);
return 0;
}
-static int wm8737_set_bias_level(struct snd_soc_codec *codec,
+static int wm8737_set_bias_level(struct snd_soc_component *component,
enum snd_soc_bias_level level)
{
- struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
+ struct wm8737_priv *wm8737 = snd_soc_component_get_drvdata(component);
+ struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component);
int ret;
switch (level) {
@@ -463,16 +461,16 @@ static int wm8737_set_bias_level(struct snd_soc_codec *codec,
case SND_SOC_BIAS_PREPARE:
/* VMID at 2*75k */
- snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL,
+ snd_soc_component_update_bits(component, WM8737_MISC_BIAS_CONTROL,
WM8737_VMIDSEL_MASK, 0);
break;
case SND_SOC_BIAS_STANDBY:
- if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
+ if (snd_soc_dapm_get_bias_level(dapm) == SND_SOC_BIAS_OFF) {
ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies),
wm8737->supplies);
if (ret != 0) {
- dev_err(codec->dev,
+ dev_err(component->dev,
"Failed to enable supplies: %d\n",
ret);
return ret;
@@ -481,12 +479,12 @@ static int wm8737_set_bias_level(struct snd_soc_codec *codec,
regcache_sync(wm8737->regmap);
/* Fast VMID ramp at 2*2.5k */
- snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL,
+ snd_soc_component_update_bits(component, WM8737_MISC_BIAS_CONTROL,
WM8737_VMIDSEL_MASK,
2 << WM8737_VMIDSEL_SHIFT);
/* Bring VMID up */
- snd_soc_update_bits(codec, WM8737_POWER_MANAGEMENT,
+ snd_soc_component_update_bits(component, WM8737_POWER_MANAGEMENT,
WM8737_VMID_MASK |
WM8737_VREF_MASK,
WM8737_VMID_MASK |
@@ -496,14 +494,14 @@ static int wm8737_set_bias_level(struct snd_soc_codec *codec,
}
/* VMID at 2*300k */
- snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL,
+ snd_soc_component_update_bits(component, WM8737_MISC_BIAS_CONTROL,
WM8737_VMIDSEL_MASK,
1 << WM8737_VMIDSEL_SHIFT);
break;
case SND_SOC_BIAS_OFF:
- snd_soc_update_bits(codec, WM8737_POWER_MANAGEMENT,
+ snd_soc_component_update_bits(component, WM8737_POWER_MANAGEMENT,
WM8737_VMID_MASK | WM8737_VREF_MASK, 0);
regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies),
@@ -537,30 +535,31 @@ static struct snd_soc_dai_driver wm8737_dai = {
.ops = &wm8737_dai_ops,
};
-static int wm8737_probe(struct snd_soc_codec *codec)
+static int wm8737_probe(struct snd_soc_component *component)
{
- struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
+ struct wm8737_priv *wm8737 = snd_soc_component_get_drvdata(component);
+ struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component);
int ret;
ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies),
wm8737->supplies);
if (ret != 0) {
- dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
+ dev_err(component->dev, "Failed to enable supplies: %d\n", ret);
goto err_get;
}
- ret = wm8737_reset(codec);
+ ret = wm8737_reset(component);
if (ret < 0) {
- dev_err(codec->dev, "Failed to issue reset\n");
+ dev_err(component->dev, "Failed to issue reset\n");
goto err_enable;
}
- snd_soc_update_bits(codec, WM8737_LEFT_PGA_VOLUME, WM8737_LVU,
+ snd_soc_component_update_bits(component, WM8737_LEFT_PGA_VOLUME, WM8737_LVU,
WM8737_LVU);
- snd_soc_update_bits(codec, WM8737_RIGHT_PGA_VOLUME, WM8737_RVU,
+ snd_soc_component_update_bits(component, WM8737_RIGHT_PGA_VOLUME, WM8737_RVU,
WM8737_RVU);
- snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
+ snd_soc_dapm_force_bias_level(dapm, SND_SOC_BIAS_STANDBY);
/* Bias level configuration will have done an extra enable */
regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies), wm8737->supplies);
@@ -573,19 +572,19 @@ err_get:
return ret;
}
-static const struct snd_soc_codec_driver soc_codec_dev_wm8737 = {
- .probe = wm8737_probe,
- .set_bias_level = wm8737_set_bias_level,
- .suspend_bias_off = true,
-
- .component_driver = {
- .controls = wm8737_snd_controls,
- .num_controls = ARRAY_SIZE(wm8737_snd_controls),
- .dapm_widgets = wm8737_dapm_widgets,
- .num_dapm_widgets = ARRAY_SIZE(wm8737_dapm_widgets),
- .dapm_routes = intercon,
- .num_dapm_routes = ARRAY_SIZE(intercon),
- },
+static const struct snd_soc_component_driver soc_component_dev_wm8737 = {
+ .probe = wm8737_probe,
+ .set_bias_level = wm8737_set_bias_level,
+ .controls = wm8737_snd_controls,
+ .num_controls = ARRAY_SIZE(wm8737_snd_controls),
+ .dapm_widgets = wm8737_dapm_widgets,
+ .num_dapm_widgets = ARRAY_SIZE(wm8737_dapm_widgets),
+ .dapm_routes = intercon,
+ .num_dapm_routes = ARRAY_SIZE(intercon),
+ .suspend_bias_off = 1,
+ .idle_bias_on = 1,
+ .use_pmdown_time = 1,
+ .endianness = 1,
};
static const struct of_device_id wm8737_of_match[] = {
@@ -602,14 +601,13 @@ static const struct regmap_config wm8737_regmap = {
.reg_defaults = wm8737_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(wm8737_reg_defaults),
- .cache_type = REGCACHE_RBTREE,
+ .cache_type = REGCACHE_MAPLE,
.volatile_reg = wm8737_volatile,
};
#if IS_ENABLED(CONFIG_I2C)
-static int wm8737_i2c_probe(struct i2c_client *i2c,
- const struct i2c_device_id *id)
+static int wm8737_i2c_probe(struct i2c_client *i2c)
{
struct wm8737_priv *wm8737;
int ret, i;
@@ -635,22 +633,15 @@ static int wm8737_i2c_probe(struct i2c_client *i2c,
i2c_set_clientdata(i2c, wm8737);
- ret = snd_soc_register_codec(&i2c->dev,
- &soc_codec_dev_wm8737, &wm8737_dai, 1);
+ ret = devm_snd_soc_register_component(&i2c->dev,
+ &soc_component_dev_wm8737, &wm8737_dai, 1);
return ret;
}
-static int wm8737_i2c_remove(struct i2c_client *client)
-{
- snd_soc_unregister_codec(&client->dev);
-
- return 0;
-}
-
static const struct i2c_device_id wm8737_i2c_id[] = {
- { "wm8737", 0 },
+ { "wm8737" },
{ }
};
MODULE_DEVICE_TABLE(i2c, wm8737_i2c_id);
@@ -660,8 +651,7 @@ static struct i2c_driver wm8737_i2c_driver = {
.name = "wm8737",
.of_match_table = wm8737_of_match,
},
- .probe = wm8737_i2c_probe,
- .remove = wm8737_i2c_remove,
+ .probe = wm8737_i2c_probe,
.id_table = wm8737_i2c_id,
};
#endif
@@ -693,26 +683,18 @@ static int wm8737_spi_probe(struct spi_device *spi)
spi_set_drvdata(spi, wm8737);
- ret = snd_soc_register_codec(&spi->dev,
- &soc_codec_dev_wm8737, &wm8737_dai, 1);
+ ret = devm_snd_soc_register_component(&spi->dev,
+ &soc_component_dev_wm8737, &wm8737_dai, 1);
return ret;
}
-static int wm8737_spi_remove(struct spi_device *spi)
-{
- snd_soc_unregister_codec(&spi->dev);
-
- return 0;
-}
-
static struct spi_driver wm8737_spi_driver = {
.driver = {
.name = "wm8737",
.of_match_table = wm8737_of_match,
},
.probe = wm8737_spi_probe,
- .remove = wm8737_spi_remove,
};
#endif /* CONFIG_SPI_MASTER */