]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: codecs: ab8500: Remove suspicious code
authorUwe Kleine-König (The Capable Hub) <u.kleine-koenig@baylibre.com>
Thu, 30 Apr 2026 15:45:24 +0000 (17:45 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 4 May 2026 12:53:14 +0000 (21:53 +0900)
anc_configure() passed values from drvdata->anc_fir_values[],
drvdata->anc_iir_values[] and drvdata->sid_fir_values[] as register
offset to snd_soc_component_read(). The content of these arrays are user
controllable via the component controls "ANC FIR Coefficients", "ANC
IIR Coefficients" and "Sidetone FIR Coefficients" which I assume are
supposed to hold register values, not register offsets.

Without a datasheet for that component and given that before commit
a201aef1a88b ("ASoC: codecs: ab8500: Fix casting of private data") the
arrays overlapped with driver control structures and thus didn't work
properly since 2012, drop that functionality and let someone repair it
who has an actual need for it.

With the core functionally removed several code parts become essentially
unused and are removed, too.

Reported-by: Sashiko (gemini/gemini-3.1-pro-preview)
Link: https://sashiko.dev/#/patchset/20260428192255.2294705-2-u.kleine-koenig%40baylibre.com
Fixes: 679d7abdc754 ("ASoC: codecs: Add AB8500 codec-driver")
Signed-off-by: Uwe Kleine-König (The Capable Hub) <u.kleine-koenig@baylibre.com>
Link: https://patch.msgid.link/20260430154524.338912-2-u.kleine-koenig@baylibre.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/ab8500-codec.c

index 8ab2e60f80b4ffa07599b1a0457c2b34997d5beb..6e8ef9cd1b31a75c5b7f8b8bab26713854c43c2c 100644 (file)
 low before proceeding with the configuration sequence */
 #define AB8500_ANC_SM_DELAY                    2000
 
-#define AB8500_FILTER_CONTROL(xname, xcount, xmin, xmax) \
-{      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
-       .info = filter_control_info, \
-       .get = filter_control_get, .put = filter_control_put, \
-       .private_value = (unsigned long)&(struct filter_control) \
-               {.count = xcount, .min = xmin, .max = xmax} }
-
-struct filter_control {
-       long min, max;
-       unsigned int count;
-       long value[128];
-};
-
 /* Sidetone states */
 static const char * const enum_sid_state[] = {
        "Unconfigured",
@@ -85,45 +72,13 @@ enum sid_state {
        SID_FIR_CONFIGURED = 2,
 };
 
-static const char * const enum_anc_state[] = {
-       "Unconfigured",
-       "Apply FIR and IIR",
-       "FIR and IIR are configured",
-       "Apply FIR",
-       "FIR is configured",
-       "Apply IIR",
-       "IIR is configured"
-};
-enum anc_state {
-       ANC_UNCONFIGURED = 0,
-       ANC_APPLY_FIR_IIR = 1,
-       ANC_FIR_IIR_CONFIGURED = 2,
-       ANC_APPLY_FIR = 3,
-       ANC_FIR_CONFIGURED = 4,
-       ANC_APPLY_IIR = 5,
-       ANC_IIR_CONFIGURED = 6
-};
-
-/* Analog microphones */
-enum amic_idx {
-       AMIC_IDX_1A,
-       AMIC_IDX_1B,
-       AMIC_IDX_2
-};
-
 /* Private data for AB8500 device-driver */
 struct ab8500_codec_drvdata {
        struct regmap *regmap;
        struct mutex ctrl_lock;
 
        /* Sidetone */
-       long *sid_fir_values;
        enum sid_state sid_status;
-
-       /* ANC */
-       long *anc_fir_values;
-       long *anc_iir_values;
-       enum anc_state anc_status;
 };
 
 static inline const char *amic_micbias_str(enum amic_micbias micbias)
@@ -1024,89 +979,6 @@ static const struct snd_soc_dapm_route ab8500_dapm_routes_mic2_vamicx[] = {
        {"MIC2 V-AMICx Enable", NULL, "V-AMIC2"},
 };
 
-/* ANC FIR-coefficients configuration sequence */
-static void anc_fir(struct snd_soc_component *component,
-               unsigned int bnk, unsigned int par, unsigned int val)
-{
-       if (par == 0 && bnk == 0)
-               snd_soc_component_update_bits(component, AB8500_ANCCONF1,
-                       BIT(AB8500_ANCCONF1_ANCFIRUPDATE),
-                       BIT(AB8500_ANCCONF1_ANCFIRUPDATE));
-
-       snd_soc_component_write(component, AB8500_ANCCONF5, val >> 8 & 0xff);
-       snd_soc_component_write(component, AB8500_ANCCONF6, val &  0xff);
-
-       if (par == AB8500_ANC_FIR_COEFFS - 1 && bnk == 1)
-               snd_soc_component_update_bits(component, AB8500_ANCCONF1,
-                       BIT(AB8500_ANCCONF1_ANCFIRUPDATE), 0);
-}
-
-/* ANC IIR-coefficients configuration sequence */
-static void anc_iir(struct snd_soc_component *component, unsigned int bnk,
-               unsigned int par, unsigned int val)
-{
-       if (par == 0) {
-               if (bnk == 0) {
-                       snd_soc_component_update_bits(component, AB8500_ANCCONF1,
-                                       BIT(AB8500_ANCCONF1_ANCIIRINIT),
-                                       BIT(AB8500_ANCCONF1_ANCIIRINIT));
-                       usleep_range(AB8500_ANC_SM_DELAY, AB8500_ANC_SM_DELAY*2);
-                       snd_soc_component_update_bits(component, AB8500_ANCCONF1,
-                                       BIT(AB8500_ANCCONF1_ANCIIRINIT), 0);
-                       usleep_range(AB8500_ANC_SM_DELAY, AB8500_ANC_SM_DELAY*2);
-               } else {
-                       snd_soc_component_update_bits(component, AB8500_ANCCONF1,
-                                       BIT(AB8500_ANCCONF1_ANCIIRUPDATE),
-                                       BIT(AB8500_ANCCONF1_ANCIIRUPDATE));
-               }
-       } else if (par > 3) {
-               snd_soc_component_write(component, AB8500_ANCCONF7, 0);
-               snd_soc_component_write(component, AB8500_ANCCONF8, val >> 16 & 0xff);
-       }
-
-       snd_soc_component_write(component, AB8500_ANCCONF7, val >> 8 & 0xff);
-       snd_soc_component_write(component, AB8500_ANCCONF8, val & 0xff);
-
-       if (par == AB8500_ANC_IIR_COEFFS - 1 && bnk == 1)
-               snd_soc_component_update_bits(component, AB8500_ANCCONF1,
-                       BIT(AB8500_ANCCONF1_ANCIIRUPDATE), 0);
-}
-
-/* ANC IIR-/FIR-coefficients configuration sequence */
-static void anc_configure(struct snd_soc_component *component,
-                       bool apply_fir, bool apply_iir)
-{
-       struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(component->dev);
-       unsigned int bnk, par, val;
-
-       dev_dbg(component->dev, "%s: Enter.\n", __func__);
-
-       if (apply_fir)
-               snd_soc_component_update_bits(component, AB8500_ANCCONF1,
-                       BIT(AB8500_ANCCONF1_ENANC), 0);
-
-       snd_soc_component_update_bits(component, AB8500_ANCCONF1,
-               BIT(AB8500_ANCCONF1_ENANC), BIT(AB8500_ANCCONF1_ENANC));
-
-       if (apply_fir)
-               for (bnk = 0; bnk < AB8500_NR_OF_ANC_COEFF_BANKS; bnk++)
-                       for (par = 0; par < AB8500_ANC_FIR_COEFFS; par++) {
-                               val = snd_soc_component_read(component,
-                                               drvdata->anc_fir_values[par]);
-                               anc_fir(component, bnk, par, val);
-                       }
-
-       if (apply_iir)
-               for (bnk = 0; bnk < AB8500_NR_OF_ANC_COEFF_BANKS; bnk++)
-                       for (par = 0; par < AB8500_ANC_IIR_COEFFS; par++) {
-                               val = snd_soc_component_read(component,
-                                               drvdata->anc_iir_values[par]);
-                               anc_iir(component, bnk, par, val);
-                       }
-
-       dev_dbg(component->dev, "%s: Exit.\n", __func__);
-}
-
 /*
  * Control-events
  */
@@ -1130,7 +1002,7 @@ static int sid_status_control_put(struct snd_kcontrol *kcontrol,
 {
        struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
        struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(component->dev);
-       unsigned int param, sidconf, val;
+       unsigned int param, sidconf;
        int status = 1;
 
        dev_dbg(component->dev, "%s: Enter\n", __func__);
@@ -1159,9 +1031,8 @@ static int sid_status_control_put(struct snd_kcontrol *kcontrol,
        snd_soc_component_write(component, AB8500_SIDFIRADR, 0);
 
        for (param = 0; param < AB8500_SID_FIR_COEFFS; param++) {
-               val = snd_soc_component_read(component, drvdata->sid_fir_values[param]);
-               snd_soc_component_write(component, AB8500_SIDFIRCOEF1, val >> 8 & 0xff);
-               snd_soc_component_write(component, AB8500_SIDFIRCOEF2, val & 0xff);
+               snd_soc_component_write(component, AB8500_SIDFIRCOEF1, 0);
+               snd_soc_component_write(component, AB8500_SIDFIRCOEF2, 0);
        }
 
        snd_soc_component_update_bits(component, AB8500_SIDFIRADR,
@@ -1180,136 +1051,6 @@ out:
        return status;
 }
 
-static int anc_status_control_get(struct snd_kcontrol *kcontrol,
-                               struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
-       struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(component->dev);
-
-       mutex_lock(&drvdata->ctrl_lock);
-       ucontrol->value.enumerated.item[0] = drvdata->anc_status;
-       mutex_unlock(&drvdata->ctrl_lock);
-
-       return 0;
-}
-
-static int anc_status_control_put(struct snd_kcontrol *kcontrol,
-                               struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
-       struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component);
-       struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(component->dev);
-       struct device *dev = component->dev;
-       bool apply_fir, apply_iir;
-       unsigned int req;
-       int status;
-
-       dev_dbg(dev, "%s: Enter.\n", __func__);
-
-       mutex_lock(&drvdata->ctrl_lock);
-
-       req = ucontrol->value.enumerated.item[0];
-       if (req >= ARRAY_SIZE(enum_anc_state)) {
-               status = -EINVAL;
-               goto cleanup;
-       }
-       if (req != ANC_APPLY_FIR_IIR && req != ANC_APPLY_FIR &&
-               req != ANC_APPLY_IIR) {
-               dev_err(dev, "%s: ERROR: Unsupported status to set '%s'!\n",
-                       __func__, enum_anc_state[req]);
-               status = -EINVAL;
-               goto cleanup;
-       }
-       apply_fir = req == ANC_APPLY_FIR || req == ANC_APPLY_FIR_IIR;
-       apply_iir = req == ANC_APPLY_IIR || req == ANC_APPLY_FIR_IIR;
-
-       status = snd_soc_dapm_force_enable_pin(dapm, "ANC Configure Input");
-       if (status < 0) {
-               dev_err(dev,
-                       "%s: ERROR: Failed to enable power (status = %d)!\n",
-                       __func__, status);
-               goto cleanup;
-       }
-       snd_soc_dapm_sync(dapm);
-
-       anc_configure(component, apply_fir, apply_iir);
-
-       if (apply_fir) {
-               if (drvdata->anc_status == ANC_IIR_CONFIGURED)
-                       drvdata->anc_status = ANC_FIR_IIR_CONFIGURED;
-               else if (drvdata->anc_status != ANC_FIR_IIR_CONFIGURED)
-                       drvdata->anc_status =  ANC_FIR_CONFIGURED;
-       }
-       if (apply_iir) {
-               if (drvdata->anc_status == ANC_FIR_CONFIGURED)
-                       drvdata->anc_status = ANC_FIR_IIR_CONFIGURED;
-               else if (drvdata->anc_status != ANC_FIR_IIR_CONFIGURED)
-                       drvdata->anc_status =  ANC_IIR_CONFIGURED;
-       }
-
-       status = snd_soc_dapm_disable_pin(dapm, "ANC Configure Input");
-       snd_soc_dapm_sync(dapm);
-
-cleanup:
-       mutex_unlock(&drvdata->ctrl_lock);
-
-       if (status < 0)
-               dev_err(dev, "%s: Unable to configure ANC! (status = %d)\n",
-                       __func__, status);
-
-       dev_dbg(dev, "%s: Exit.\n", __func__);
-
-       return (status < 0) ? status : 1;
-}
-
-static int filter_control_info(struct snd_kcontrol *kcontrol,
-                       struct snd_ctl_elem_info *uinfo)
-{
-       struct filter_control *fc =
-                       (struct filter_control *)kcontrol->private_value;
-
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
-       uinfo->count = fc->count;
-       uinfo->value.integer.min = fc->min;
-       uinfo->value.integer.max = fc->max;
-
-       return 0;
-}
-
-static int filter_control_get(struct snd_kcontrol *kcontrol,
-                       struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
-       struct ab8500_codec_drvdata *drvdata = snd_soc_component_get_drvdata(component);
-       struct filter_control *fc =
-                       (struct filter_control *)kcontrol->private_value;
-       unsigned int i;
-
-       mutex_lock(&drvdata->ctrl_lock);
-       for (i = 0; i < fc->count; i++)
-               ucontrol->value.integer.value[i] = fc->value[i];
-       mutex_unlock(&drvdata->ctrl_lock);
-
-       return 0;
-}
-
-static int filter_control_put(struct snd_kcontrol *kcontrol,
-               struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
-       struct ab8500_codec_drvdata *drvdata = snd_soc_component_get_drvdata(component);
-       struct filter_control *fc =
-                       (struct filter_control *)kcontrol->private_value;
-       unsigned int i;
-
-       mutex_lock(&drvdata->ctrl_lock);
-       for (i = 0; i < fc->count; i++)
-               fc->value[i] = ucontrol->value.integer.value[i];
-       mutex_unlock(&drvdata->ctrl_lock);
-
-       return 0;
-}
-
 /*
  * Controls - Non-DAPM ASoC
  */
@@ -1597,7 +1338,6 @@ static SOC_ENUM_SINGLE_DECL(soc_enum_bfifomast,
 static SOC_ENUM_SINGLE_EXT_DECL(soc_enum_sidstate, enum_sid_state);
 
 /* ANC */
-static SOC_ENUM_SINGLE_EXT_DECL(soc_enum_ancstate, enum_anc_state);
 
 static struct snd_kcontrol_new ab8500_ctrls[] = {
        /* Charge pump */
@@ -1873,8 +1613,6 @@ static struct snd_kcontrol_new ab8500_ctrls[] = {
                AB8500_FIFOCONF6_BFIFOSAMPLE_MAX, 0),
 
        /* ANC */
-       SOC_ENUM_EXT("ANC Status", soc_enum_ancstate,
-               anc_status_control_get, anc_status_control_put),
        SOC_SINGLE_XR_SX("ANC Warp Delay Shift",
                AB8500_ANCCONF2, 1, AB8500_ANCCONF2_SHIFT,
                AB8500_ANCCONF2_MIN, AB8500_ANCCONF2_MAX, 0),
@@ -1895,21 +1633,6 @@ static struct snd_kcontrol_new ab8500_ctrls[] = {
                AB8500_SIDFIRADR, AB8500_SIDFIRADR_FIRSIDSET, 0),
 };
 
-static struct snd_kcontrol_new ab8500_filter_controls[] = {
-       AB8500_FILTER_CONTROL("ANC FIR Coefficients", AB8500_ANC_FIR_COEFFS,
-               AB8500_ANC_FIR_COEFF_MIN, AB8500_ANC_FIR_COEFF_MAX),
-       AB8500_FILTER_CONTROL("ANC IIR Coefficients", AB8500_ANC_IIR_COEFFS,
-               AB8500_ANC_IIR_COEFF_MIN, AB8500_ANC_IIR_COEFF_MAX),
-       AB8500_FILTER_CONTROL("Sidetone FIR Coefficients",
-                       AB8500_SID_FIR_COEFFS, AB8500_SID_FIR_COEFF_MIN,
-                       AB8500_SID_FIR_COEFF_MAX)
-};
-enum ab8500_filter {
-       AB8500_FILTER_ANC_FIR = 0,
-       AB8500_FILTER_ANC_IIR = 1,
-       AB8500_FILTER_SID_FIR = 2,
-};
-
 /*
  * Extended interface for codec-driver
  */
@@ -2454,7 +2177,6 @@ static int ab8500_codec_probe(struct snd_soc_component *component)
        struct device_node *np = dev->of_node;
        struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(dev);
        struct ab8500_codec_platform_data codec_pdata;
-       struct filter_control *fc;
        int status;
 
        dev_dbg(dev, "%s: Enter.\n", __func__);
@@ -2486,25 +2208,6 @@ static int ab8500_codec_probe(struct snd_soc_component *component)
        snd_soc_component_write(component, AB8500_SHORTCIRCONF,
                      BIT(AB8500_SHORTCIRCONF_HSZCDDIS));
 
-       /* Add filter controls */
-       status = snd_soc_add_component_controls(component, ab8500_filter_controls,
-                               ARRAY_SIZE(ab8500_filter_controls));
-       if (status < 0) {
-               dev_err(dev,
-                       "%s: failed to add ab8500 filter controls (%d).\n",
-                       __func__, status);
-               return status;
-       }
-       fc = (struct filter_control *)
-               ab8500_filter_controls[AB8500_FILTER_ANC_FIR].private_value;
-       drvdata->anc_fir_values = (long *)fc->value;
-       fc = (struct filter_control *)
-               ab8500_filter_controls[AB8500_FILTER_ANC_IIR].private_value;
-       drvdata->anc_iir_values = (long *)fc->value;
-       fc = (struct filter_control *)
-               ab8500_filter_controls[AB8500_FILTER_SID_FIR].private_value;
-       drvdata->sid_fir_values = (long *)fc->value;
-
        snd_soc_dapm_disable_pin(dapm, "ANC Configure Input");
 
        mutex_init(&drvdata->ctrl_lock);
@@ -2538,7 +2241,6 @@ static int ab8500_codec_driver_probe(struct platform_device *pdev)
        if (!drvdata)
                return -ENOMEM;
        drvdata->sid_status = SID_UNCONFIGURED;
-       drvdata->anc_status = ANC_UNCONFIGURED;
        dev_set_drvdata(&pdev->dev, drvdata);
 
        drvdata->regmap = devm_regmap_init(&pdev->dev, NULL, &pdev->dev,