diff options
Diffstat (limited to 'sound/soc/codecs/max9850.c')
| -rw-r--r-- | sound/soc/codecs/max9850.c | 119 |
1 files changed, 47 insertions, 72 deletions
diff --git a/sound/soc/codecs/max9850.c b/sound/soc/codecs/max9850.c index 0610840733d1..1fcbc64a2771 100644 --- a/sound/soc/codecs/max9850.c +++ b/sound/soc/codecs/max9850.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * max9850.c -- codec driver for max9850 * @@ -6,13 +7,7 @@ * Author: Christian Glindkamp <christian.glindkamp@taskit.de> * * Initial development of this code was funded by - * MICRONIC Computer Systeme GmbH, http://www.mcsberlin.de/ - * - * 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. - * + * MICRONIC Computer Systeme GmbH, https://www.mcsberlin.de/ */ #include <linux/module.h> @@ -32,19 +27,6 @@ struct max9850_priv { unsigned int sysclk; }; -/* max9850 register cache */ -static const struct reg_default max9850_reg[] = { - { 2, 0x0c }, - { 3, 0x00 }, - { 4, 0x00 }, - { 5, 0x00 }, - { 6, 0x00 }, - { 7, 0x00 }, - { 8, 0x00 }, - { 9, 0x00 }, - { 10, 0x00 }, -}; - /* these registers are not used at the moment but provided for the sake of * completeness */ static bool max9850_volatile_register(struct device *dev, unsigned int reg) @@ -52,9 +34,9 @@ static bool max9850_volatile_register(struct device *dev, unsigned int reg) switch (reg) { case MAX9850_STATUSA: case MAX9850_STATUSB: - return 1; + return true; default: - return 0; + return false; } } @@ -130,8 +112,8 @@ static int max9850_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 max9850_priv *max9850 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct max9850_priv *max9850 = snd_soc_component_get_drvdata(component); u64 lrclk_div; u8 sf, da; @@ -139,14 +121,14 @@ static int max9850_hw_params(struct snd_pcm_substream *substream, return -EINVAL; /* lrclk_div = 2^22 * rate / iclk with iclk = mclk / sf */ - sf = (snd_soc_read(codec, MAX9850_CLOCK) >> 2) + 1; + sf = (snd_soc_component_read(component, MAX9850_CLOCK) >> 2) + 1; lrclk_div = (1 << 22); lrclk_div *= params_rate(params); lrclk_div *= sf; do_div(lrclk_div, max9850->sysclk); - snd_soc_write(codec, MAX9850_LRCLK_MSB, (lrclk_div >> 8) & 0x7f); - snd_soc_write(codec, MAX9850_LRCLK_LSB, lrclk_div & 0xff); + snd_soc_component_write(component, MAX9850_LRCLK_MSB, (lrclk_div >> 8) & 0x7f); + snd_soc_component_write(component, MAX9850_LRCLK_LSB, lrclk_div & 0xff); switch (params_width(params)) { case 16: @@ -161,7 +143,7 @@ static int max9850_hw_params(struct snd_pcm_substream *substream, default: return -EINVAL; } - snd_soc_update_bits(codec, MAX9850_DIGITAL_AUDIO, 0x3, da); + snd_soc_component_update_bits(component, MAX9850_DIGITAL_AUDIO, 0x3, da); return 0; } @@ -169,16 +151,16 @@ static int max9850_hw_params(struct snd_pcm_substream *substream, static int max9850_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 max9850_priv *max9850 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = codec_dai->component; + struct max9850_priv *max9850 = snd_soc_component_get_drvdata(component); /* calculate mclk -> iclk divider */ if (freq <= 13000000) - snd_soc_write(codec, MAX9850_CLOCK, 0x0); + snd_soc_component_write(component, MAX9850_CLOCK, 0x0); else if (freq <= 26000000) - snd_soc_write(codec, MAX9850_CLOCK, 0x4); + snd_soc_component_write(component, MAX9850_CLOCK, 0x4); else if (freq <= 40000000) - snd_soc_write(codec, MAX9850_CLOCK, 0x8); + snd_soc_component_write(component, MAX9850_CLOCK, 0x8); else return -EINVAL; @@ -188,15 +170,15 @@ static int max9850_set_dai_sysclk(struct snd_soc_dai *codec_dai, static int max9850_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; u8 da = 0; - /* set master/slave audio interface */ - switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { - case SND_SOC_DAIFMT_CBM_CFM: + /* set clock provider for audio interface */ + switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) { + case SND_SOC_DAIFMT_CBP_CFP: da |= MAX9850_MASTER; break; - case SND_SOC_DAIFMT_CBS_CFS: + case SND_SOC_DAIFMT_CBC_CFC: break; default: return -EINVAL; @@ -234,15 +216,16 @@ static int max9850_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) } /* set da */ - snd_soc_write(codec, MAX9850_DIGITAL_AUDIO, da); + snd_soc_component_write(component, MAX9850_DIGITAL_AUDIO, da); return 0; } -static int max9850_set_bias_level(struct snd_soc_codec *codec, +static int max9850_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { - struct max9850_priv *max9850 = snd_soc_codec_get_drvdata(codec); + struct max9850_priv *max9850 = snd_soc_component_get_drvdata(component); + struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component); int ret; switch (level) { @@ -251,10 +234,10 @@ static int max9850_set_bias_level(struct snd_soc_codec *codec, case SND_SOC_BIAS_PREPARE: 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 = regcache_sync(max9850->regmap); if (ret) { - dev_err(codec->dev, + dev_err(component->dev, "Failed to sync cache: %d\n", ret); return ret; } @@ -289,35 +272,34 @@ static struct snd_soc_dai_driver max9850_dai = { .ops = &max9850_dai_ops, }; -static int max9850_probe(struct snd_soc_codec *codec) +static int max9850_probe(struct snd_soc_component *component) { /* enable zero-detect */ - snd_soc_update_bits(codec, MAX9850_GENERAL_PURPOSE, 1, 1); + snd_soc_component_update_bits(component, MAX9850_GENERAL_PURPOSE, 1, 1); /* enable slew-rate control */ - snd_soc_update_bits(codec, MAX9850_VOLUME, 0x40, 0x40); + snd_soc_component_update_bits(component, MAX9850_VOLUME, 0x40, 0x40); /* set slew-rate 125ms */ - snd_soc_update_bits(codec, MAX9850_CHARGE_PUMP, 0xff, 0xc0); + snd_soc_component_update_bits(component, MAX9850_CHARGE_PUMP, 0xff, 0xc0); return 0; } -static struct snd_soc_codec_driver soc_codec_dev_max9850 = { - .probe = max9850_probe, - .set_bias_level = max9850_set_bias_level, - .suspend_bias_off = true, - - .component_driver = { - .controls = max9850_controls, - .num_controls = ARRAY_SIZE(max9850_controls), - .dapm_widgets = max9850_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(max9850_dapm_widgets), - .dapm_routes = max9850_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(max9850_dapm_routes), - }, +static const struct snd_soc_component_driver soc_component_dev_max9850 = { + .probe = max9850_probe, + .set_bias_level = max9850_set_bias_level, + .controls = max9850_controls, + .num_controls = ARRAY_SIZE(max9850_controls), + .dapm_widgets = max9850_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(max9850_dapm_widgets), + .dapm_routes = max9850_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(max9850_dapm_routes), + .suspend_bias_off = 1, + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, }; -static int max9850_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) +static int max9850_i2c_probe(struct i2c_client *i2c) { struct max9850_priv *max9850; int ret; @@ -333,19 +315,13 @@ static int max9850_i2c_probe(struct i2c_client *i2c, i2c_set_clientdata(i2c, max9850); - ret = snd_soc_register_codec(&i2c->dev, - &soc_codec_dev_max9850, &max9850_dai, 1); + ret = devm_snd_soc_register_component(&i2c->dev, + &soc_component_dev_max9850, &max9850_dai, 1); return ret; } -static int max9850_i2c_remove(struct i2c_client *client) -{ - snd_soc_unregister_codec(&client->dev); - return 0; -} - static const struct i2c_device_id max9850_i2c_id[] = { - { "max9850", 0 }, + { "max9850" }, { } }; MODULE_DEVICE_TABLE(i2c, max9850_i2c_id); @@ -355,7 +331,6 @@ static struct i2c_driver max9850_i2c_driver = { .name = "max9850", }, .probe = max9850_i2c_probe, - .remove = max9850_i2c_remove, .id_table = max9850_i2c_id, }; |
