diff options
Diffstat (limited to 'sound/soc/codecs/cs4271.c')
| -rw-r--r-- | sound/soc/codecs/cs4271.c | 131 |
1 files changed, 63 insertions, 68 deletions
diff --git a/sound/soc/codecs/cs4271.c b/sound/soc/codecs/cs4271.c index 849fdb2cb260..77dfc83a3c01 100644 --- a/sound/soc/codecs/cs4271.c +++ b/sound/soc/codecs/cs4271.c @@ -1,31 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * CS4271 ASoC codec driver * * Copyright (c) 2010 Alexander Sverdlin <subaparts@yandex.ru> * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * * This driver support CS4271 codec being master or slave, working * in control port mode, connected either via SPI or I2C. * The data format accepted is I2S or left-justified. * DAPM support not implemented. */ +#include <linux/clk.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/delay.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/of.h> -#include <linux/of_device.h> -#include <linux/of_gpio.h> #include <linux/regulator/consumer.h> #include <sound/pcm.h> #include <sound/soc.h> @@ -170,12 +160,11 @@ struct cs4271_private { /* Current sample rate for de-emphasis control */ int rate; /* GPIO driving Reset pin, if any */ - int gpio_nreset; - /* GPIO that disable serial bus, if any */ - int gpio_disable; + struct gpio_desc *reset; /* enable soft reset workaround */ bool enable_soft_reset; struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; + struct clk *clk; }; static const struct snd_soc_dapm_widget cs4271_dapm_widgets[] = { @@ -222,11 +211,11 @@ static int cs4271_set_dai_fmt(struct snd_soc_dai *codec_dai, int ret; switch (format & SND_SOC_DAIFMT_MASTER_MASK) { - case SND_SOC_DAIFMT_CBS_CFS: - cs4271->master = 0; + case SND_SOC_DAIFMT_CBC_CFC: + cs4271->master = false; break; - case SND_SOC_DAIFMT_CBM_CFM: - cs4271->master = 1; + case SND_SOC_DAIFMT_CBP_CFP: + cs4271->master = true; val |= CS4271_MODE1_MASTER; break; default: @@ -289,7 +278,7 @@ static int cs4271_set_deemph(struct snd_soc_component *component) static int cs4271_get_deemph(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); struct cs4271_private *cs4271 = snd_soc_component_get_drvdata(component); ucontrol->value.integer.value[0] = cs4271->deemph; @@ -299,7 +288,7 @@ static int cs4271_get_deemph(struct snd_kcontrol *kcontrol, static int cs4271_put_deemph(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); struct cs4271_private *cs4271 = snd_soc_component_get_drvdata(component); cs4271->deemph = ucontrol->value.integer.value[0]; @@ -343,7 +332,7 @@ static struct cs4271_clk_cfg cs4271_clk_tab[] = { {0, CS4271_MODE1_MODE_4X, 256, CS4271_MODE1_DIV_2}, }; -#define CS4171_NR_RATIOS ARRAY_SIZE(cs4271_clk_tab) +#define CS4271_NR_RATIOS ARRAY_SIZE(cs4271_clk_tab) static int cs4271_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, @@ -365,9 +354,9 @@ static int cs4271_hw_params(struct snd_pcm_substream *substream, */ if ((substream->stream == SNDRV_PCM_STREAM_PLAYBACK && - !dai->capture_active) || + !snd_soc_dai_stream_active(dai, SNDRV_PCM_STREAM_CAPTURE)) || (substream->stream == SNDRV_PCM_STREAM_CAPTURE && - !dai->playback_active)) { + !snd_soc_dai_stream_active(dai, SNDRV_PCM_STREAM_PLAYBACK))) { ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2, CS4271_MODE2_PDN, CS4271_MODE2_PDN); @@ -392,13 +381,13 @@ static int cs4271_hw_params(struct snd_pcm_substream *substream, val = CS4271_MODE1_MODE_4X; ratio = cs4271->mclk / cs4271->rate; - for (i = 0; i < CS4171_NR_RATIOS; i++) + for (i = 0; i < CS4271_NR_RATIOS; i++) if ((cs4271_clk_tab[i].master == cs4271->master) && (cs4271_clk_tab[i].speed_mode == val) && (cs4271_clk_tab[i].ratio == ratio)) break; - if (i == CS4171_NR_RATIOS) { + if (i == CS4271_NR_RATIOS) { dev_err(component->dev, "Invalid sample rate\n"); return -EINVAL; } @@ -490,19 +479,17 @@ static struct snd_soc_dai_driver cs4271_dai = { .formats = CS4271_PCM_FORMATS, }, .ops = &cs4271_dai_ops, - .symmetric_rates = 1, + .symmetric_rate = 1, }; static int cs4271_reset(struct snd_soc_component *component) { struct cs4271_private *cs4271 = snd_soc_component_get_drvdata(component); - if (gpio_is_valid(cs4271->gpio_nreset)) { - gpio_direction_output(cs4271->gpio_nreset, 0); - mdelay(1); - gpio_set_value(cs4271->gpio_nreset, 1); - mdelay(1); - } + gpiod_direction_output(cs4271->reset, 1); + mdelay(1); + gpiod_set_value(cs4271->reset, 0); + mdelay(1); return 0; } @@ -520,6 +507,7 @@ static int cs4271_soc_suspend(struct snd_soc_component *component) return ret; regcache_mark_dirty(cs4271->regmap); + clk_disable_unprepare(cs4271->clk); regulator_bulk_disable(ARRAY_SIZE(cs4271->supplies), cs4271->supplies); return 0; @@ -537,6 +525,12 @@ static int cs4271_soc_resume(struct snd_soc_component *component) return ret; } + ret = clk_prepare_enable(cs4271->clk); + if (ret) { + dev_err(component->dev, "Failed to enable clk: %d\n", ret); + return ret; + } + /* Do a proper reset after power up */ cs4271_reset(component); @@ -572,19 +566,12 @@ static int cs4271_component_probe(struct snd_soc_component *component) struct cs4271_private *cs4271 = snd_soc_component_get_drvdata(component); struct cs4271_platform_data *cs4271plat = component->dev->platform_data; int ret; - bool amutec_eq_bmutec = false; + bool amutec_eq_bmutec; -#ifdef CONFIG_OF - if (of_match_device(cs4271_dt_ids, component->dev)) { - if (of_get_property(component->dev->of_node, - "cirrus,amutec-eq-bmutec", NULL)) - amutec_eq_bmutec = true; - - if (of_get_property(component->dev->of_node, - "cirrus,enable-soft-reset", NULL)) - cs4271->enable_soft_reset = true; - } -#endif + amutec_eq_bmutec = of_property_read_bool(component->dev->of_node, + "cirrus,amutec-eq-bmutec"); + cs4271->enable_soft_reset = of_property_read_bool(component->dev->of_node, + "cirrus,enable-soft-reset"); ret = regulator_bulk_enable(ARRAY_SIZE(cs4271->supplies), cs4271->supplies); @@ -598,22 +585,30 @@ static int cs4271_component_probe(struct snd_soc_component *component) cs4271->enable_soft_reset = cs4271plat->enable_soft_reset; } + ret = clk_prepare_enable(cs4271->clk); + if (ret) { + dev_err(component->dev, "Failed to enable clk: %d\n", ret); + goto err_disable_regulators; + } + /* Reset codec */ cs4271_reset(component); ret = regcache_sync(cs4271->regmap); if (ret < 0) - return ret; + goto err_disable_clk; ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2, CS4271_MODE2_PDN | CS4271_MODE2_CPEN, CS4271_MODE2_PDN | CS4271_MODE2_CPEN); if (ret < 0) - return ret; + goto err_disable_clk; + ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2, CS4271_MODE2_PDN, 0); if (ret < 0) - return ret; + goto err_disable_clk; + /* Power-up sequence requires 85 uS */ udelay(85); @@ -623,18 +618,24 @@ static int cs4271_component_probe(struct snd_soc_component *component) CS4271_MODE2_MUTECAEQUB); return 0; + +err_disable_clk: + clk_disable_unprepare(cs4271->clk); +err_disable_regulators: + regulator_bulk_disable(ARRAY_SIZE(cs4271->supplies), cs4271->supplies); + return ret; } static void cs4271_component_remove(struct snd_soc_component *component) { struct cs4271_private *cs4271 = snd_soc_component_get_drvdata(component); - if (gpio_is_valid(cs4271->gpio_nreset)) - /* Set codec to the reset state */ - gpio_set_value(cs4271->gpio_nreset, 0); + /* Set codec to the reset state */ + gpiod_set_value(cs4271->reset, 1); regcache_mark_dirty(cs4271->regmap); regulator_bulk_disable(ARRAY_SIZE(cs4271->supplies), cs4271->supplies); + clk_disable_unprepare(cs4271->clk); }; static const struct snd_soc_component_driver soc_component_dev_cs4271 = { @@ -651,13 +652,11 @@ static const struct snd_soc_component_driver soc_component_dev_cs4271 = { .idle_bias_on = 1, .use_pmdown_time = 1, .endianness = 1, - .non_legacy_dai_naming = 1, }; static int cs4271_common_probe(struct device *dev, struct cs4271_private **c) { - struct cs4271_platform_data *cs4271plat = dev->platform_data; struct cs4271_private *cs4271; int i, ret; @@ -665,19 +664,15 @@ static int cs4271_common_probe(struct device *dev, if (!cs4271) return -ENOMEM; - if (of_match_device(cs4271_dt_ids, dev)) - cs4271->gpio_nreset = - of_get_named_gpio(dev->of_node, "reset-gpio", 0); + cs4271->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS); + if (IS_ERR(cs4271->reset)) + return dev_err_probe(dev, PTR_ERR(cs4271->reset), + "error retrieving RESET GPIO\n"); + gpiod_set_consumer_name(cs4271->reset, "CS4271 Reset"); - if (cs4271plat) - cs4271->gpio_nreset = cs4271plat->gpio_nreset; - - if (gpio_is_valid(cs4271->gpio_nreset)) { - ret = devm_gpio_request(dev, cs4271->gpio_nreset, - "CS4271 Reset"); - if (ret < 0) - return ret; - } + cs4271->clk = devm_clk_get_optional(dev, "mclk"); + if (IS_ERR(cs4271->clk)) + return dev_err_probe(dev, PTR_ERR(cs4271->clk), "Failed to get mclk\n"); for (i = 0; i < ARRAY_SIZE(supply_names); i++) cs4271->supplies[i].supply = supply_names[i]; @@ -699,8 +694,8 @@ const struct regmap_config cs4271_regmap_config = { .reg_defaults = cs4271_reg_defaults, .num_reg_defaults = ARRAY_SIZE(cs4271_reg_defaults), - .cache_type = REGCACHE_RBTREE, - + .cache_type = REGCACHE_FLAT, + .val_bits = 8, .volatile_reg = cs4271_volatile_reg, }; EXPORT_SYMBOL_GPL(cs4271_regmap_config); |
