summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2024-07-04 18:41:03 +0100
committerMark Brown <broonie@kernel.org>2024-07-04 18:41:03 +0100
commitecaec47b88d63d9f83947038334a1c8096f378d5 (patch)
tree8d7475562887921fa7f4a3cf20d28e1c346ddf63
parentcabf0b0cff07bc8d6e80ab6a8f8a127a2708147b (diff)
parent67820eb9f4895791da46df42ff7942dfc1353bb2 (diff)
ASoC: codecs: lpass-rx-macro: Few code cleanups
Merge series from Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>: Improve a bit the Qualcomm LPASS RX macro driver and align similar parts of code with LPASS WSA macro driver for consistency. No external dependencies.
-rw-r--r--include/sound/soc-dapm.h2
-rw-r--r--sound/soc/codecs/lpass-macro-common.h5
-rw-r--r--sound/soc/codecs/lpass-rx-macro.c63
-rw-r--r--sound/soc/codecs/lpass-wsa-macro.c22
-rw-r--r--sound/soc/soc-dapm.c2
5 files changed, 47 insertions, 47 deletions
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index 667ecd4daa68..12cd7b5a2202 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -457,7 +457,7 @@ int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *uncontrol);
int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
- const struct snd_soc_dapm_widget *widget, int num);
+ const struct snd_soc_dapm_widget *widget, unsigned int num);
struct snd_soc_dapm_widget *snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
const struct snd_soc_dapm_widget *widget);
struct snd_soc_dapm_widget *snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
diff --git a/sound/soc/codecs/lpass-macro-common.h b/sound/soc/codecs/lpass-macro-common.h
index 3aa9737f2737..21cb30ab706d 100644
--- a/sound/soc/codecs/lpass-macro-common.h
+++ b/sound/soc/codecs/lpass-macro-common.h
@@ -41,6 +41,11 @@ void lpass_macro_pds_exit(struct lpass_macro *pds);
void lpass_macro_set_codec_version(enum lpass_codec_version version);
enum lpass_codec_version lpass_macro_get_codec_version(void);
+static inline void lpass_macro_pds_exit_action(void *pds)
+{
+ lpass_macro_pds_exit(pds);
+}
+
static inline const char *lpass_macro_get_codec_version_string(int version)
{
switch (version) {
diff --git a/sound/soc/codecs/lpass-rx-macro.c b/sound/soc/codecs/lpass-rx-macro.c
index d47c49c90de3..ce42749660c8 100644
--- a/sound/soc/codecs/lpass-rx-macro.c
+++ b/sound/soc/codecs/lpass-rx-macro.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
+#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/io.h>
@@ -1662,7 +1663,7 @@ static bool rx_is_readable_register(struct device *dev, unsigned int reg)
return rx_is_rw_register(dev, reg);
}
-static struct regmap_config rx_regmap_config = {
+static const struct regmap_config rx_regmap_config = {
.name = "rx_macro",
.reg_bits = 16,
.val_bits = 32, /* 8 but with 32 bit read/write */
@@ -3611,8 +3612,8 @@ static int rx_macro_component_probe(struct snd_soc_component *component)
struct rx_macro *rx = snd_soc_component_get_drvdata(component);
const struct snd_soc_dapm_widget *widgets;
const struct snd_kcontrol_new *controls;
- unsigned int num_controls;
- int ret, num_widgets;
+ unsigned int num_controls, num_widgets;
+ int ret;
snd_soc_component_init_regmap(component, rx->regmap);
@@ -3764,7 +3765,6 @@ static const struct snd_soc_component_driver rx_macro_component_drv = {
static int rx_macro_probe(struct platform_device *pdev)
{
- struct reg_default *reg_defaults;
struct device *dev = &pdev->dev;
kernel_ulong_t flags;
struct rx_macro *rx;
@@ -3803,12 +3803,17 @@ static int rx_macro_probe(struct platform_device *pdev)
if (IS_ERR(rx->pds))
return PTR_ERR(rx->pds);
+ ret = devm_add_action_or_reset(dev, lpass_macro_pds_exit_action, rx->pds);
+ if (ret)
+ return ret;
+
base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base)) {
- ret = PTR_ERR(base);
- goto err;
- }
+ if (IS_ERR(base))
+ return PTR_ERR(base);
+
rx->codec_version = lpass_macro_get_codec_version();
+ struct reg_default *reg_defaults __free(kfree) = NULL;
+
switch (rx->codec_version) {
case LPASS_CODEC_VERSION_1_0:
case LPASS_CODEC_VERSION_1_1:
@@ -3818,10 +3823,8 @@ static int rx_macro_probe(struct platform_device *pdev)
rx->rxn_reg_stride = 0x80;
def_count = ARRAY_SIZE(rx_defaults) + ARRAY_SIZE(rx_pre_2_5_defaults);
reg_defaults = kmalloc_array(def_count, sizeof(struct reg_default), GFP_KERNEL);
- if (!reg_defaults) {
- ret = -ENOMEM;
- goto err;
- }
+ if (!reg_defaults)
+ return -ENOMEM;
memcpy(&reg_defaults[0], rx_defaults, sizeof(rx_defaults));
memcpy(&reg_defaults[ARRAY_SIZE(rx_defaults)],
rx_pre_2_5_defaults, sizeof(rx_pre_2_5_defaults));
@@ -3833,28 +3836,29 @@ static int rx_macro_probe(struct platform_device *pdev)
rx->rxn_reg_stride = 0xc0;
def_count = ARRAY_SIZE(rx_defaults) + ARRAY_SIZE(rx_2_5_defaults);
reg_defaults = kmalloc_array(def_count, sizeof(struct reg_default), GFP_KERNEL);
- if (!reg_defaults) {
- ret = -ENOMEM;
- goto err;
- }
+ if (!reg_defaults)
+ return -ENOMEM;
memcpy(&reg_defaults[0], rx_defaults, sizeof(rx_defaults));
memcpy(&reg_defaults[ARRAY_SIZE(rx_defaults)],
rx_2_5_defaults, sizeof(rx_2_5_defaults));
break;
default:
dev_err(dev, "Unsupported Codec version (%d)\n", rx->codec_version);
- ret = -EINVAL;
- goto err;
+ return -EINVAL;
}
- rx_regmap_config.reg_defaults = reg_defaults;
- rx_regmap_config.num_reg_defaults = def_count;
+ struct regmap_config *reg_config __free(kfree) = kmemdup(&rx_regmap_config,
+ sizeof(*reg_config),
+ GFP_KERNEL);
+ if (!reg_config)
+ return -ENOMEM;
- rx->regmap = devm_regmap_init_mmio(dev, base, &rx_regmap_config);
- if (IS_ERR(rx->regmap)) {
- ret = PTR_ERR(rx->regmap);
- goto err_ver;
- }
+ reg_config->reg_defaults = reg_defaults;
+ reg_config->num_reg_defaults = def_count;
+
+ rx->regmap = devm_regmap_init_mmio(dev, base, reg_config);
+ if (IS_ERR(rx->regmap))
+ return PTR_ERR(rx->regmap);
dev_set_drvdata(dev, rx);
@@ -3866,7 +3870,7 @@ static int rx_macro_probe(struct platform_device *pdev)
ret = clk_prepare_enable(rx->macro);
if (ret)
- goto err_ver;
+ return ret;
ret = clk_prepare_enable(rx->dcodec);
if (ret)
@@ -3912,7 +3916,6 @@ static int rx_macro_probe(struct platform_device *pdev)
if (ret)
goto err_clkout;
- kfree(reg_defaults);
return 0;
err_clkout:
@@ -3925,10 +3928,6 @@ err_mclk:
clk_disable_unprepare(rx->dcodec);
err_dcodec:
clk_disable_unprepare(rx->macro);
-err_ver:
- kfree(reg_defaults);
-err:
- lpass_macro_pds_exit(rx->pds);
return ret;
}
@@ -3942,8 +3941,6 @@ static void rx_macro_remove(struct platform_device *pdev)
clk_disable_unprepare(rx->fsgen);
clk_disable_unprepare(rx->macro);
clk_disable_unprepare(rx->dcodec);
-
- lpass_macro_pds_exit(rx->pds);
}
static const struct of_device_id rx_macro_dt_match[] = {
diff --git a/sound/soc/codecs/lpass-wsa-macro.c b/sound/soc/codecs/lpass-wsa-macro.c
index b4e7139bac61..73a588289408 100644
--- a/sound/soc/codecs/lpass-wsa-macro.c
+++ b/sound/soc/codecs/lpass-wsa-macro.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
+#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/io.h>
@@ -2725,8 +2726,6 @@ static const struct snd_soc_component_driver wsa_macro_component_drv = {
static int wsa_macro_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct reg_default *reg_defaults;
- struct regmap_config *reg_config;
struct wsa_macro *wsa;
kernel_ulong_t flags;
void __iomem *base;
@@ -2765,6 +2764,8 @@ static int wsa_macro_probe(struct platform_device *pdev)
return PTR_ERR(base);
wsa->codec_version = lpass_macro_get_codec_version();
+ struct reg_default *reg_defaults __free(kfree) = NULL;
+
switch (wsa->codec_version) {
case LPASS_CODEC_VERSION_1_0:
case LPASS_CODEC_VERSION_1_1:
@@ -2773,9 +2774,8 @@ static int wsa_macro_probe(struct platform_device *pdev)
case LPASS_CODEC_VERSION_2_1:
wsa->reg_layout = &wsa_codec_v2_1;
def_count = ARRAY_SIZE(wsa_defaults) + ARRAY_SIZE(wsa_defaults_v2_1);
- reg_defaults = devm_kmalloc_array(dev, def_count,
- sizeof(*reg_defaults),
- GFP_KERNEL);
+ reg_defaults = kmalloc_array(def_count, sizeof(*reg_defaults),
+ GFP_KERNEL);
if (!reg_defaults)
return -ENOMEM;
memcpy(&reg_defaults[0], wsa_defaults, sizeof(wsa_defaults));
@@ -2789,9 +2789,8 @@ static int wsa_macro_probe(struct platform_device *pdev)
case LPASS_CODEC_VERSION_2_8:
wsa->reg_layout = &wsa_codec_v2_5;
def_count = ARRAY_SIZE(wsa_defaults) + ARRAY_SIZE(wsa_defaults_v2_5);
- reg_defaults = devm_kmalloc_array(dev, def_count,
- sizeof(*reg_defaults),
- GFP_KERNEL);
+ reg_defaults = kmalloc_array(def_count, sizeof(*reg_defaults),
+ GFP_KERNEL);
if (!reg_defaults)
return -ENOMEM;
memcpy(&reg_defaults[0], wsa_defaults, sizeof(wsa_defaults));
@@ -2804,8 +2803,9 @@ static int wsa_macro_probe(struct platform_device *pdev)
return -EINVAL;
}
- reg_config = devm_kmemdup(dev, &wsa_regmap_config,
- sizeof(*reg_config), GFP_KERNEL);
+ struct regmap_config *reg_config __free(kfree) = kmemdup(&wsa_regmap_config,
+ sizeof(*reg_config),
+ GFP_KERNEL);
if (!reg_config)
return -ENOMEM;
@@ -2816,8 +2816,6 @@ static int wsa_macro_probe(struct platform_device *pdev)
if (IS_ERR(wsa->regmap))
return PTR_ERR(wsa->regmap);
- devm_kfree(dev, reg_config);
- devm_kfree(dev, reg_defaults);
dev_set_drvdata(dev, wsa);
wsa->dev = dev;
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 16dad4a45443..32cc90d09bc2 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -3857,7 +3857,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
*/
int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
const struct snd_soc_dapm_widget *widget,
- int num)
+ unsigned int num)
{
int i;
int ret = 0;