diff options
Diffstat (limited to 'sound/soc/codecs/cs35l33.c')
| -rw-r--r-- | sound/soc/codecs/cs35l33.c | 255 |
1 files changed, 119 insertions, 136 deletions
diff --git a/sound/soc/codecs/cs35l33.c b/sound/soc/codecs/cs35l33.c index 6df29fa30fb9..98b4d371d931 100644 --- a/sound/soc/codecs/cs35l33.c +++ b/sound/soc/codecs/cs35l33.c @@ -1,14 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * cs35l33.c -- CS35L33 ALSA SoC audio driver * * Copyright 2016 Cirrus Logic, Inc. * * Author: Paul Handrigan <paul.handrigan@cirrus.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/module.h> #include <linux/moduleparam.h> @@ -26,23 +22,20 @@ #include <sound/soc-dapm.h> #include <sound/initval.h> #include <sound/tlv.h> -#include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <sound/cs35l33.h> #include <linux/pm_runtime.h> #include <linux/regulator/consumer.h> #include <linux/regulator/machine.h> -#include <linux/of_gpio.h> #include <linux/of.h> -#include <linux/of_device.h> -#include <linux/of_irq.h> #include "cs35l33.h" +#include "cirrus_legacy.h" #define CS35L33_BOOT_DELAY 50 struct cs35l33_private { - struct snd_soc_codec *codec; + struct snd_soc_component *component; struct cs35l33_pdata pdata; struct regmap *regmap; struct gpio_desc *reset_gpio; @@ -201,8 +194,8 @@ static const struct snd_kcontrol_new cs35l33_snd_controls[] = { static int cs35l33_spkrdrv_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); - struct cs35l33_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct cs35l33_private *priv = snd_soc_component_get_drvdata(component); switch (event) { case SND_SOC_DAPM_POST_PMU: @@ -211,15 +204,15 @@ static int cs35l33_spkrdrv_event(struct snd_soc_dapm_widget *w, priv->amp_cal = true; regmap_update_bits(priv->regmap, CS35L33_CLASSD_CTL, CS35L33_AMP_CAL, 0); - dev_dbg(codec->dev, "Amp calibration done\n"); + dev_dbg(component->dev, "Amp calibration done\n"); } - dev_dbg(codec->dev, "Amp turned on\n"); + dev_dbg(component->dev, "Amp turned on\n"); break; case SND_SOC_DAPM_POST_PMD: - dev_dbg(codec->dev, "Amp turned off\n"); + dev_dbg(component->dev, "Amp turned off\n"); break; default: - dev_err(codec->dev, "Invalid event = 0x%x\n", event); + dev_err(component->dev, "Invalid event = 0x%x\n", event); break; } @@ -229,8 +222,8 @@ static int cs35l33_spkrdrv_event(struct snd_soc_dapm_widget *w, static int cs35l33_sdin_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); - struct cs35l33_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct cs35l33_private *priv = snd_soc_component_get_drvdata(component); unsigned int val; switch (event) { @@ -240,14 +233,14 @@ static int cs35l33_sdin_event(struct snd_soc_dapm_widget *w, val = priv->is_tdm_mode ? 0 : CS35L33_PDN_TDM; regmap_update_bits(priv->regmap, CS35L33_PWRCTL2, CS35L33_PDN_TDM, val); - dev_dbg(codec->dev, "BST turned on\n"); + dev_dbg(component->dev, "BST turned on\n"); break; case SND_SOC_DAPM_POST_PMU: - dev_dbg(codec->dev, "SDIN turned on\n"); + dev_dbg(component->dev, "SDIN turned on\n"); if (!priv->amp_cal) { regmap_update_bits(priv->regmap, CS35L33_CLASSD_CTL, CS35L33_AMP_CAL, CS35L33_AMP_CAL); - dev_dbg(codec->dev, "Amp calibration started\n"); + dev_dbg(component->dev, "Amp calibration started\n"); usleep_range(10000, 11000); } break; @@ -257,10 +250,10 @@ static int cs35l33_sdin_event(struct snd_soc_dapm_widget *w, usleep_range(4000, 4100); regmap_update_bits(priv->regmap, CS35L33_PWRCTL1, CS35L33_PDN_BST, CS35L33_PDN_BST); - dev_dbg(codec->dev, "BST and SDIN turned off\n"); + dev_dbg(component->dev, "BST and SDIN turned off\n"); break; default: - dev_err(codec->dev, "Invalid event = 0x%x\n", event); + dev_err(component->dev, "Invalid event = 0x%x\n", event); } @@ -270,8 +263,8 @@ static int cs35l33_sdin_event(struct snd_soc_dapm_widget *w, static int cs35l33_sdout_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); - struct cs35l33_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct cs35l33_private *priv = snd_soc_component_get_drvdata(component); unsigned int mask = CS35L33_SDOUT_3ST_I2S | CS35L33_PDN_TDM; unsigned int mask2 = CS35L33_SDOUT_3ST_TDM; unsigned int val, val2; @@ -289,15 +282,15 @@ static int cs35l33_sdout_event(struct snd_soc_dapm_widget *w, /* set sdout_3st_tdm */ val2 = CS35L33_SDOUT_3ST_TDM; } - dev_dbg(codec->dev, "SDOUT turned on\n"); + dev_dbg(component->dev, "SDOUT turned on\n"); break; case SND_SOC_DAPM_PRE_PMD: val = CS35L33_SDOUT_3ST_I2S | CS35L33_PDN_TDM; val2 = CS35L33_SDOUT_3ST_TDM; - dev_dbg(codec->dev, "SDOUT turned off\n"); + dev_dbg(component->dev, "SDOUT turned off\n"); break; default: - dev_err(codec->dev, "Invalid event = 0x%x\n", event); + dev_err(component->dev, "Invalid event = 0x%x\n", event); return 0; } @@ -360,11 +353,11 @@ static const struct snd_soc_dapm_route cs35l33_vp_vbst_mon_route[] = { {"VBSTMON", NULL, "MON"}, }; -static int cs35l33_set_bias_level(struct snd_soc_codec *codec, +static int cs35l33_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { unsigned int val; - struct cs35l33_private *priv = snd_soc_codec_get_drvdata(codec); + struct cs35l33_private *priv = snd_soc_component_get_drvdata(component); switch (level) { case SND_SOC_BIAS_ON: @@ -441,19 +434,19 @@ static int cs35l33_get_mclk_coeff(int mclk, int srate) static int cs35l33_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) { - struct snd_soc_codec *codec = codec_dai->codec; - struct cs35l33_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = codec_dai->component; + struct cs35l33_private *priv = snd_soc_component_get_drvdata(component); switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { - case SND_SOC_DAIFMT_CBM_CFM: + case SND_SOC_DAIFMT_CBP_CFP: regmap_update_bits(priv->regmap, CS35L33_ADSP_CTL, CS35L33_MS_MASK, CS35L33_MS_MASK); - dev_dbg(codec->dev, "Audio port in master mode\n"); + dev_dbg(component->dev, "Audio port in master mode\n"); break; - case SND_SOC_DAIFMT_CBS_CFS: + case SND_SOC_DAIFMT_CBC_CFC: regmap_update_bits(priv->regmap, CS35L33_ADSP_CTL, CS35L33_MS_MASK, 0); - dev_dbg(codec->dev, "Audio port in slave mode\n"); + dev_dbg(component->dev, "Audio port in slave mode\n"); break; default: return -EINVAL; @@ -466,11 +459,11 @@ static int cs35l33_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) * closely, it is dsp-a with fsync shifted left by half bclk */ priv->is_tdm_mode = true; - dev_dbg(codec->dev, "Audio port in TDM mode\n"); + dev_dbg(component->dev, "Audio port in TDM mode\n"); break; case SND_SOC_DAIFMT_I2S: priv->is_tdm_mode = false; - dev_dbg(codec->dev, "Audio port in I2S mode\n"); + dev_dbg(component->dev, "Audio port in I2S mode\n"); break; default: return -EINVAL; @@ -483,8 +476,8 @@ static int cs35l33_pcm_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 cs35l33_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct cs35l33_private *priv = snd_soc_component_get_drvdata(component); int sample_size = params_width(params); int coeff = cs35l33_get_mclk_coeff(priv->mclk_int, params_rate(params)); @@ -505,7 +498,7 @@ static int cs35l33_pcm_hw_params(struct snd_pcm_substream *substream, sample_size << CS35L33_AUDIN_RX_DEPTH_SHIFT); } - dev_dbg(codec->dev, "sample rate=%d, bits per sample=%d\n", + dev_dbg(component->dev, "sample rate=%d, bits per sample=%d\n", params_rate(params), params_width(params)); return 0; @@ -532,8 +525,8 @@ static int cs35l33_pcm_startup(struct snd_pcm_substream *substream, static int cs35l33_set_tristate(struct snd_soc_dai *dai, int tristate) { - struct snd_soc_codec *codec = dai->codec; - struct cs35l33_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct cs35l33_private *priv = snd_soc_component_get_drvdata(component); if (tristate) { regmap_update_bits(priv->regmap, CS35L33_PWRCTL2, @@ -553,9 +546,9 @@ static int cs35l33_set_tristate(struct snd_soc_dai *dai, int tristate) static int cs35l33_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) { - struct snd_soc_codec *codec = dai->codec; - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); - struct cs35l33_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component); + struct cs35l33_private *priv = snd_soc_component_get_drvdata(component); unsigned int reg, bit_pos, i; int slot, slot_num; @@ -567,7 +560,7 @@ static int cs35l33_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, if (slot >= 0) { regmap_update_bits(priv->regmap, CS35L33_RX_AUD, CS35L33_X_LOC, slot); - dev_dbg(codec->dev, "Audio starts from slots %d", slot); + dev_dbg(component->dev, "Audio starts from slots %d", slot); } /* @@ -593,7 +586,7 @@ static int cs35l33_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, if (slot_num == 0) { regmap_update_bits(priv->regmap, CS35L33_TX_VMON, CS35L33_X_STATE | CS35L33_X_LOC, slot); - dev_dbg(codec->dev, "VMON enabled in slots %d-%d", + dev_dbg(component->dev, "VMON enabled in slots %d-%d", slot, slot + 1); } @@ -601,7 +594,7 @@ static int cs35l33_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, if (slot_num == 3) { regmap_update_bits(priv->regmap, CS35L33_TX_IMON, CS35L33_X_STATE | CS35L33_X_LOC, slot); - dev_dbg(codec->dev, "IMON enabled in slots %d-%d", + dev_dbg(component->dev, "IMON enabled in slots %d-%d", slot, slot + 1); } @@ -611,7 +604,7 @@ static int cs35l33_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, CS35L33_X_STATE | CS35L33_X_LOC, slot); snd_soc_dapm_add_routes(dapm, &cs35l33_vp_vbst_mon_route[0], 2); - dev_dbg(codec->dev, "VPMON enabled in slots %d", slot); + dev_dbg(component->dev, "VPMON enabled in slots %d", slot); } /* configure VBSTMON_TX_LOC */ @@ -620,7 +613,7 @@ static int cs35l33_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, CS35L33_X_STATE | CS35L33_X_LOC, slot); snd_soc_dapm_add_routes(dapm, &cs35l33_vp_vbst_mon_route[2], 2); - dev_dbg(codec->dev, + dev_dbg(component->dev, "VBSTMON enabled in slots %d", slot); } @@ -638,10 +631,10 @@ static int cs35l33_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, return 0; } -static int cs35l33_codec_set_sysclk(struct snd_soc_codec *codec, +static int cs35l33_component_set_sysclk(struct snd_soc_component *component, int clk_id, int source, unsigned int freq, int dir) { - struct cs35l33_private *cs35l33 = snd_soc_codec_get_drvdata(codec); + struct cs35l33_private *cs35l33 = snd_soc_component_get_drvdata(component); switch (freq) { case CS35L33_MCLK_5644: @@ -663,7 +656,7 @@ static int cs35l33_codec_set_sysclk(struct snd_soc_codec *codec, return -EINVAL; } - dev_dbg(codec->dev, "external mclk freq=%d, internal mclk freq=%d\n", + dev_dbg(component->dev, "external mclk freq=%d, internal mclk freq=%d\n", freq, cs35l33->mclk_int); return 0; @@ -695,15 +688,15 @@ static struct snd_soc_dai_driver cs35l33_dai = { .formats = CS35L33_FORMATS, }, .ops = &cs35l33_ops, - .symmetric_rates = 1, + .symmetric_rate = 1, }; -static int cs35l33_set_hg_data(struct snd_soc_codec *codec, +static int cs35l33_set_hg_data(struct snd_soc_component *component, struct cs35l33_pdata *pdata) { struct cs35l33_hg *hg_config = &pdata->hg_config; - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); - struct cs35l33_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component); + struct cs35l33_private *priv = snd_soc_component_get_drvdata(component); if (hg_config->enable_hg_algo) { regmap_update_bits(priv->regmap, CS35L33_HG_MEMLDO_CTL, @@ -747,20 +740,20 @@ static int cs35l33_set_hg_data(struct snd_soc_codec *codec, return 0; } -static int cs35l33_set_bst_ipk(struct snd_soc_codec *codec, unsigned int bst) +static int cs35l33_set_bst_ipk(struct snd_soc_component *component, unsigned int bst) { - struct cs35l33_private *cs35l33 = snd_soc_codec_get_drvdata(codec); + struct cs35l33_private *cs35l33 = snd_soc_component_get_drvdata(component); int ret = 0, steps = 0; /* Boost current in uA */ if (bst > 3600000 || bst < 1850000) { - dev_err(codec->dev, "Invalid boost current %d\n", bst); + dev_err(component->dev, "Invalid boost current %d\n", bst); ret = -EINVAL; goto err; } if (bst % 15625) { - dev_err(codec->dev, "Current not a multiple of 15625uA (%d)\n", + dev_err(component->dev, "Current not a multiple of 15625uA (%d)\n", bst); ret = -EINVAL; goto err; @@ -778,12 +771,12 @@ err: return ret; } -static int cs35l33_probe(struct snd_soc_codec *codec) +static int cs35l33_probe(struct snd_soc_component *component) { - struct cs35l33_private *cs35l33 = snd_soc_codec_get_drvdata(codec); + struct cs35l33_private *cs35l33 = snd_soc_component_get_drvdata(component); - cs35l33->codec = codec; - pm_runtime_get_sync(codec->dev); + cs35l33->component = component; + pm_runtime_get_sync(component->dev); regmap_update_bits(cs35l33->regmap, CS35L33_PROTECT_CTL, CS35L33_ALIVE_WD_DIS, 0x8); @@ -799,24 +792,24 @@ static int cs35l33_probe(struct snd_soc_codec *codec) cs35l33->pdata.amp_drv_sel << CS35L33_AMP_DRV_SEL_SHIFT); if (cs35l33->pdata.boost_ipk) - cs35l33_set_bst_ipk(codec, cs35l33->pdata.boost_ipk); + cs35l33_set_bst_ipk(component, cs35l33->pdata.boost_ipk); if (cs35l33->enable_soft_ramp) { - snd_soc_update_bits(codec, CS35L33_DAC_CTL, + snd_soc_component_update_bits(component, CS35L33_DAC_CTL, CS35L33_DIGSFT, CS35L33_DIGSFT); - snd_soc_update_bits(codec, CS35L33_DAC_CTL, + snd_soc_component_update_bits(component, CS35L33_DAC_CTL, CS35L33_DSR_RATE, cs35l33->pdata.ramp_rate); } else { - snd_soc_update_bits(codec, CS35L33_DAC_CTL, + snd_soc_component_update_bits(component, CS35L33_DAC_CTL, CS35L33_DIGSFT, 0); } /* update IMON scaling rate if different from default of 0x8 */ if (cs35l33->pdata.imon_adc_scale != 0x8) - snd_soc_update_bits(codec, CS35L33_ADC_CTL, + snd_soc_component_update_bits(component, CS35L33_ADC_CTL, CS35L33_IMON_SCALE, cs35l33->pdata.imon_adc_scale); - cs35l33_set_hg_data(codec, &(cs35l33->pdata)); + cs35l33_set_hg_data(component, &(cs35l33->pdata)); /* * unmask important interrupts that causes the chip to enter @@ -826,26 +819,23 @@ static int cs35l33_probe(struct snd_soc_codec *codec) CS35L33_M_OTE | CS35L33_M_OTW | CS35L33_M_AMP_SHORT | CS35L33_M_CAL_ERR, 0); - pm_runtime_put_sync(codec->dev); + pm_runtime_put_sync(component->dev); return 0; } -static struct snd_soc_codec_driver soc_codec_dev_cs35l33 = { - .probe = cs35l33_probe, - - .set_bias_level = cs35l33_set_bias_level, - .set_sysclk = cs35l33_codec_set_sysclk, - - .component_driver = { - .controls = cs35l33_snd_controls, - .num_controls = ARRAY_SIZE(cs35l33_snd_controls), - .dapm_widgets = cs35l33_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(cs35l33_dapm_widgets), - .dapm_routes = cs35l33_audio_map, - .num_dapm_routes = ARRAY_SIZE(cs35l33_audio_map), - }, - .idle_bias_off = true, +static const struct snd_soc_component_driver soc_component_dev_cs35l33 = { + .probe = cs35l33_probe, + .set_bias_level = cs35l33_set_bias_level, + .set_sysclk = cs35l33_component_set_sysclk, + .controls = cs35l33_snd_controls, + .num_controls = ARRAY_SIZE(cs35l33_snd_controls), + .dapm_widgets = cs35l33_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(cs35l33_dapm_widgets), + .dapm_routes = cs35l33_audio_map, + .num_dapm_routes = ARRAY_SIZE(cs35l33_audio_map), + .use_pmdown_time = 1, + .endianness = 1, }; static const struct regmap_config cs35l33_regmap = { @@ -858,19 +848,19 @@ static const struct regmap_config cs35l33_regmap = { .volatile_reg = cs35l33_volatile_register, .readable_reg = cs35l33_readable_register, .writeable_reg = cs35l33_writeable_register, - .cache_type = REGCACHE_RBTREE, - .use_single_rw = true, + .cache_type = REGCACHE_MAPLE, + .use_single_read = true, + .use_single_write = true, }; -static int __maybe_unused cs35l33_runtime_resume(struct device *dev) +static int cs35l33_runtime_resume(struct device *dev) { struct cs35l33_private *cs35l33 = dev_get_drvdata(dev); int ret; dev_dbg(dev, "%s\n", __func__); - if (cs35l33->reset_gpio) - gpiod_set_value_cansleep(cs35l33->reset_gpio, 0); + gpiod_set_value_cansleep(cs35l33->reset_gpio, 0); ret = regulator_bulk_enable(cs35l33->num_core_supplies, cs35l33->core_supplies); @@ -881,8 +871,7 @@ static int __maybe_unused cs35l33_runtime_resume(struct device *dev) regcache_cache_only(cs35l33->regmap, false); - if (cs35l33->reset_gpio) - gpiod_set_value_cansleep(cs35l33->reset_gpio, 1); + gpiod_set_value_cansleep(cs35l33->reset_gpio, 1); msleep(CS35L33_BOOT_DELAY); @@ -902,7 +891,7 @@ err: return ret; } -static int __maybe_unused cs35l33_runtime_suspend(struct device *dev) +static int cs35l33_runtime_suspend(struct device *dev) { struct cs35l33_private *cs35l33 = dev_get_drvdata(dev); @@ -920,9 +909,7 @@ static int __maybe_unused cs35l33_runtime_suspend(struct device *dev) } static const struct dev_pm_ops cs35l33_pm_ops = { - SET_RUNTIME_PM_OPS(cs35l33_runtime_suspend, - cs35l33_runtime_resume, - NULL) + RUNTIME_PM_OPS(cs35l33_runtime_suspend, cs35l33_runtime_resume, NULL) }; static int cs35l33_get_hg_data(const struct device_node *np, @@ -969,7 +956,7 @@ static int cs35l33_get_hg_data(const struct device_node *np, static irqreturn_t cs35l33_irq_thread(int irq, void *data) { struct cs35l33_private *cs35l33 = data; - struct snd_soc_codec *codec = cs35l33->codec; + struct snd_soc_component *component = cs35l33->component; unsigned int sticky_val1, sticky_val2, current_val, mask1, mask2; regmap_read(cs35l33->regmap, CS35L33_INT_STATUS_2, @@ -991,9 +978,9 @@ static irqreturn_t cs35l33_irq_thread(int irq, void *data) /* handle the interrupts */ if (sticky_val1 & CS35L33_AMP_SHORT) { - dev_crit(codec->dev, "Amp short error\n"); + dev_crit(component->dev, "Amp short error\n"); if (!(current_val & CS35L33_AMP_SHORT)) { - dev_dbg(codec->dev, + dev_dbg(component->dev, "Amp short error release\n"); regmap_update_bits(cs35l33->regmap, CS35L33_AMP_CTL, @@ -1009,13 +996,13 @@ static irqreturn_t cs35l33_irq_thread(int irq, void *data) } if (sticky_val1 & CS35L33_CAL_ERR) { - dev_err(codec->dev, "Cal error\n"); + dev_err(component->dev, "Cal error\n"); /* redo the calibration in next power up */ cs35l33->amp_cal = false; if (!(current_val & CS35L33_CAL_ERR)) { - dev_dbg(codec->dev, "Cal error release\n"); + dev_dbg(component->dev, "Cal error release\n"); regmap_update_bits(cs35l33->regmap, CS35L33_AMP_CTL, CS35L33_CAL_ERR_RLS, 0); @@ -1029,9 +1016,9 @@ static irqreturn_t cs35l33_irq_thread(int irq, void *data) } if (sticky_val1 & CS35L33_OTE) { - dev_crit(codec->dev, "Over temperature error\n"); + dev_crit(component->dev, "Over temperature error\n"); if (!(current_val & CS35L33_OTE)) { - dev_dbg(codec->dev, + dev_dbg(component->dev, "Over temperature error release\n"); regmap_update_bits(cs35l33->regmap, CS35L33_AMP_CTL, CS35L33_OTE_RLS, 0); @@ -1044,9 +1031,9 @@ static irqreturn_t cs35l33_irq_thread(int irq, void *data) } if (sticky_val1 & CS35L33_OTW) { - dev_err(codec->dev, "Over temperature warning\n"); + dev_err(component->dev, "Over temperature warning\n"); if (!(current_val & CS35L33_OTW)) { - dev_dbg(codec->dev, + dev_dbg(component->dev, "Over temperature warning release\n"); regmap_update_bits(cs35l33->regmap, CS35L33_AMP_CTL, CS35L33_OTW_RLS, 0); @@ -1058,21 +1045,21 @@ static irqreturn_t cs35l33_irq_thread(int irq, void *data) } } if (CS35L33_ALIVE_ERR & sticky_val1) - dev_err(codec->dev, "ERROR: ADSPCLK Interrupt\n"); + dev_err(component->dev, "ERROR: ADSPCLK Interrupt\n"); if (CS35L33_MCLK_ERR & sticky_val1) - dev_err(codec->dev, "ERROR: MCLK Interrupt\n"); + dev_err(component->dev, "ERROR: MCLK Interrupt\n"); if (CS35L33_VMON_OVFL & sticky_val2) - dev_err(codec->dev, + dev_err(component->dev, "ERROR: VMON Overflow Interrupt\n"); if (CS35L33_IMON_OVFL & sticky_val2) - dev_err(codec->dev, + dev_err(component->dev, "ERROR: IMON Overflow Interrupt\n"); if (CS35L33_VPMON_OVFL & sticky_val2) - dev_err(codec->dev, + dev_err(component->dev, "ERROR: VPMON Overflow Interrupt\n"); return IRQ_HANDLED; @@ -1122,8 +1109,7 @@ static int cs35l33_of_get_pdata(struct device *dev, return 0; } -static int cs35l33_i2c_probe(struct i2c_client *i2c_client, - const struct i2c_device_id *id) +static int cs35l33_i2c_probe(struct i2c_client *i2c_client) { struct cs35l33_private *cs35l33; struct cs35l33_pdata *pdata = dev_get_platdata(&i2c_client->dev); @@ -1175,7 +1161,7 @@ static int cs35l33_i2c_probe(struct i2c_client *i2c_client, /* We could issue !RST or skip it based on AMP topology */ cs35l33->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev, - "reset-gpios", GPIOD_OUT_HIGH); + "reset", GPIOD_OUT_HIGH); if (IS_ERR(cs35l33->reset_gpio)) { dev_err(&i2c_client->dev, "%s ERROR: Can't get reset GPIO\n", __func__); @@ -1191,24 +1177,24 @@ static int cs35l33_i2c_probe(struct i2c_client *i2c_client, return ret; } - if (cs35l33->reset_gpio) - gpiod_set_value_cansleep(cs35l33->reset_gpio, 1); + gpiod_set_value_cansleep(cs35l33->reset_gpio, 1); msleep(CS35L33_BOOT_DELAY); regcache_cache_only(cs35l33->regmap, false); /* initialize codec */ - ret = regmap_read(cs35l33->regmap, CS35L33_DEVID_AB, ®); - devid = (reg & 0xFF) << 12; - ret = regmap_read(cs35l33->regmap, CS35L33_DEVID_CD, ®); - devid |= (reg & 0xFF) << 4; - ret = regmap_read(cs35l33->regmap, CS35L33_DEVID_E, ®); - devid |= (reg & 0xF0) >> 4; + devid = cirrus_read_device_id(cs35l33->regmap, CS35L33_DEVID_AB); + if (devid < 0) { + ret = devid; + dev_err(&i2c_client->dev, "Failed to read device ID: %d\n", ret); + goto err_enable; + } if (devid != CS35L33_CHIP_ID) { dev_err(&i2c_client->dev, "CS35L33 Device ID (%X). Expected ID %X\n", devid, CS35L33_CHIP_ID); + ret = -EINVAL; goto err_enable; } @@ -1239,10 +1225,10 @@ static int cs35l33_i2c_probe(struct i2c_client *i2c_client, pm_runtime_set_active(&i2c_client->dev); pm_runtime_enable(&i2c_client->dev); - ret = snd_soc_register_codec(&i2c_client->dev, - &soc_codec_dev_cs35l33, &cs35l33_dai, 1); + ret = devm_snd_soc_register_component(&i2c_client->dev, + &soc_component_dev_cs35l33, &cs35l33_dai, 1); if (ret < 0) { - dev_err(&i2c_client->dev, "%s: Register codec failed\n", + dev_err(&i2c_client->dev, "%s: Register component failed\n", __func__); goto err_enable; } @@ -1250,26 +1236,23 @@ static int cs35l33_i2c_probe(struct i2c_client *i2c_client, return 0; err_enable: + gpiod_set_value_cansleep(cs35l33->reset_gpio, 0); + regulator_bulk_disable(cs35l33->num_core_supplies, cs35l33->core_supplies); return ret; } -static int cs35l33_i2c_remove(struct i2c_client *client) +static void cs35l33_i2c_remove(struct i2c_client *client) { struct cs35l33_private *cs35l33 = i2c_get_clientdata(client); - snd_soc_unregister_codec(&client->dev); - - if (cs35l33->reset_gpio) - gpiod_set_value_cansleep(cs35l33->reset_gpio, 0); + gpiod_set_value_cansleep(cs35l33->reset_gpio, 0); pm_runtime_disable(&client->dev); regulator_bulk_disable(cs35l33->num_core_supplies, cs35l33->core_supplies); - - return 0; } static const struct of_device_id cs35l33_of_match[] = { @@ -1279,7 +1262,7 @@ static const struct of_device_id cs35l33_of_match[] = { MODULE_DEVICE_TABLE(of, cs35l33_of_match); static const struct i2c_device_id cs35l33_id[] = { - {"cs35l33", 0}, + {"cs35l33"}, {} }; @@ -1288,7 +1271,7 @@ MODULE_DEVICE_TABLE(i2c, cs35l33_id); static struct i2c_driver cs35l33_i2c_driver = { .driver = { .name = "cs35l33", - .pm = &cs35l33_pm_ops, + .pm = pm_ptr(&cs35l33_pm_ops), .of_match_table = cs35l33_of_match, }, |
