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.
This commit is contained in:
commit
ecaec47b88
@ -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,
|
int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
|
||||||
struct snd_ctl_elem_value *uncontrol);
|
struct snd_ctl_elem_value *uncontrol);
|
||||||
int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
|
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,
|
struct snd_soc_dapm_widget *snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
|
||||||
const struct snd_soc_dapm_widget *widget);
|
const struct snd_soc_dapm_widget *widget);
|
||||||
struct snd_soc_dapm_widget *snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
|
struct snd_soc_dapm_widget *snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
|
||||||
|
@ -41,6 +41,11 @@ void lpass_macro_pds_exit(struct lpass_macro *pds);
|
|||||||
void lpass_macro_set_codec_version(enum lpass_codec_version version);
|
void lpass_macro_set_codec_version(enum lpass_codec_version version);
|
||||||
enum lpass_codec_version lpass_macro_get_codec_version(void);
|
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)
|
static inline const char *lpass_macro_get_codec_version_string(int version)
|
||||||
{
|
{
|
||||||
switch (version) {
|
switch (version) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-only
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
// Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
|
// Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
|
#include <linux/cleanup.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/io.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);
|
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",
|
.name = "rx_macro",
|
||||||
.reg_bits = 16,
|
.reg_bits = 16,
|
||||||
.val_bits = 32, /* 8 but with 32 bit read/write */
|
.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);
|
struct rx_macro *rx = snd_soc_component_get_drvdata(component);
|
||||||
const struct snd_soc_dapm_widget *widgets;
|
const struct snd_soc_dapm_widget *widgets;
|
||||||
const struct snd_kcontrol_new *controls;
|
const struct snd_kcontrol_new *controls;
|
||||||
unsigned int num_controls;
|
unsigned int num_controls, num_widgets;
|
||||||
int ret, num_widgets;
|
int ret;
|
||||||
|
|
||||||
snd_soc_component_init_regmap(component, rx->regmap);
|
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)
|
static int rx_macro_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct reg_default *reg_defaults;
|
|
||||||
struct device *dev = &pdev->dev;
|
struct device *dev = &pdev->dev;
|
||||||
kernel_ulong_t flags;
|
kernel_ulong_t flags;
|
||||||
struct rx_macro *rx;
|
struct rx_macro *rx;
|
||||||
@ -3803,12 +3803,17 @@ static int rx_macro_probe(struct platform_device *pdev)
|
|||||||
if (IS_ERR(rx->pds))
|
if (IS_ERR(rx->pds))
|
||||||
return PTR_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);
|
base = devm_platform_ioremap_resource(pdev, 0);
|
||||||
if (IS_ERR(base)) {
|
if (IS_ERR(base))
|
||||||
ret = PTR_ERR(base);
|
return PTR_ERR(base);
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
rx->codec_version = lpass_macro_get_codec_version();
|
rx->codec_version = lpass_macro_get_codec_version();
|
||||||
|
struct reg_default *reg_defaults __free(kfree) = NULL;
|
||||||
|
|
||||||
switch (rx->codec_version) {
|
switch (rx->codec_version) {
|
||||||
case LPASS_CODEC_VERSION_1_0:
|
case LPASS_CODEC_VERSION_1_0:
|
||||||
case LPASS_CODEC_VERSION_1_1:
|
case LPASS_CODEC_VERSION_1_1:
|
||||||
@ -3818,10 +3823,8 @@ static int rx_macro_probe(struct platform_device *pdev)
|
|||||||
rx->rxn_reg_stride = 0x80;
|
rx->rxn_reg_stride = 0x80;
|
||||||
def_count = ARRAY_SIZE(rx_defaults) + ARRAY_SIZE(rx_pre_2_5_defaults);
|
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);
|
reg_defaults = kmalloc_array(def_count, sizeof(struct reg_default), GFP_KERNEL);
|
||||||
if (!reg_defaults) {
|
if (!reg_defaults)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
memcpy(®_defaults[0], rx_defaults, sizeof(rx_defaults));
|
memcpy(®_defaults[0], rx_defaults, sizeof(rx_defaults));
|
||||||
memcpy(®_defaults[ARRAY_SIZE(rx_defaults)],
|
memcpy(®_defaults[ARRAY_SIZE(rx_defaults)],
|
||||||
rx_pre_2_5_defaults, sizeof(rx_pre_2_5_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;
|
rx->rxn_reg_stride = 0xc0;
|
||||||
def_count = ARRAY_SIZE(rx_defaults) + ARRAY_SIZE(rx_2_5_defaults);
|
def_count = ARRAY_SIZE(rx_defaults) + ARRAY_SIZE(rx_2_5_defaults);
|
||||||
reg_defaults = kmalloc_array(def_count, sizeof(struct reg_default), GFP_KERNEL);
|
reg_defaults = kmalloc_array(def_count, sizeof(struct reg_default), GFP_KERNEL);
|
||||||
if (!reg_defaults) {
|
if (!reg_defaults)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
memcpy(®_defaults[0], rx_defaults, sizeof(rx_defaults));
|
memcpy(®_defaults[0], rx_defaults, sizeof(rx_defaults));
|
||||||
memcpy(®_defaults[ARRAY_SIZE(rx_defaults)],
|
memcpy(®_defaults[ARRAY_SIZE(rx_defaults)],
|
||||||
rx_2_5_defaults, sizeof(rx_2_5_defaults));
|
rx_2_5_defaults, sizeof(rx_2_5_defaults));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dev_err(dev, "Unsupported Codec version (%d)\n", rx->codec_version);
|
dev_err(dev, "Unsupported Codec version (%d)\n", rx->codec_version);
|
||||||
ret = -EINVAL;
|
return -EINVAL;
|
||||||
goto err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rx_regmap_config.reg_defaults = reg_defaults;
|
struct regmap_config *reg_config __free(kfree) = kmemdup(&rx_regmap_config,
|
||||||
rx_regmap_config.num_reg_defaults = def_count;
|
sizeof(*reg_config),
|
||||||
|
GFP_KERNEL);
|
||||||
|
if (!reg_config)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
rx->regmap = devm_regmap_init_mmio(dev, base, &rx_regmap_config);
|
reg_config->reg_defaults = reg_defaults;
|
||||||
if (IS_ERR(rx->regmap)) {
|
reg_config->num_reg_defaults = def_count;
|
||||||
ret = PTR_ERR(rx->regmap);
|
|
||||||
goto err_ver;
|
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);
|
dev_set_drvdata(dev, rx);
|
||||||
|
|
||||||
@ -3866,7 +3870,7 @@ static int rx_macro_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
ret = clk_prepare_enable(rx->macro);
|
ret = clk_prepare_enable(rx->macro);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_ver;
|
return ret;
|
||||||
|
|
||||||
ret = clk_prepare_enable(rx->dcodec);
|
ret = clk_prepare_enable(rx->dcodec);
|
||||||
if (ret)
|
if (ret)
|
||||||
@ -3912,7 +3916,6 @@ static int rx_macro_probe(struct platform_device *pdev)
|
|||||||
if (ret)
|
if (ret)
|
||||||
goto err_clkout;
|
goto err_clkout;
|
||||||
|
|
||||||
kfree(reg_defaults);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_clkout:
|
err_clkout:
|
||||||
@ -3925,10 +3928,6 @@ err_mclk:
|
|||||||
clk_disable_unprepare(rx->dcodec);
|
clk_disable_unprepare(rx->dcodec);
|
||||||
err_dcodec:
|
err_dcodec:
|
||||||
clk_disable_unprepare(rx->macro);
|
clk_disable_unprepare(rx->macro);
|
||||||
err_ver:
|
|
||||||
kfree(reg_defaults);
|
|
||||||
err:
|
|
||||||
lpass_macro_pds_exit(rx->pds);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -3942,8 +3941,6 @@ static void rx_macro_remove(struct platform_device *pdev)
|
|||||||
clk_disable_unprepare(rx->fsgen);
|
clk_disable_unprepare(rx->fsgen);
|
||||||
clk_disable_unprepare(rx->macro);
|
clk_disable_unprepare(rx->macro);
|
||||||
clk_disable_unprepare(rx->dcodec);
|
clk_disable_unprepare(rx->dcodec);
|
||||||
|
|
||||||
lpass_macro_pds_exit(rx->pds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct of_device_id rx_macro_dt_match[] = {
|
static const struct of_device_id rx_macro_dt_match[] = {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-only
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
// Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
|
// Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
|
#include <linux/cleanup.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/io.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)
|
static int wsa_macro_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct device *dev = &pdev->dev;
|
struct device *dev = &pdev->dev;
|
||||||
struct reg_default *reg_defaults;
|
|
||||||
struct regmap_config *reg_config;
|
|
||||||
struct wsa_macro *wsa;
|
struct wsa_macro *wsa;
|
||||||
kernel_ulong_t flags;
|
kernel_ulong_t flags;
|
||||||
void __iomem *base;
|
void __iomem *base;
|
||||||
@ -2765,6 +2764,8 @@ static int wsa_macro_probe(struct platform_device *pdev)
|
|||||||
return PTR_ERR(base);
|
return PTR_ERR(base);
|
||||||
|
|
||||||
wsa->codec_version = lpass_macro_get_codec_version();
|
wsa->codec_version = lpass_macro_get_codec_version();
|
||||||
|
struct reg_default *reg_defaults __free(kfree) = NULL;
|
||||||
|
|
||||||
switch (wsa->codec_version) {
|
switch (wsa->codec_version) {
|
||||||
case LPASS_CODEC_VERSION_1_0:
|
case LPASS_CODEC_VERSION_1_0:
|
||||||
case LPASS_CODEC_VERSION_1_1:
|
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:
|
case LPASS_CODEC_VERSION_2_1:
|
||||||
wsa->reg_layout = &wsa_codec_v2_1;
|
wsa->reg_layout = &wsa_codec_v2_1;
|
||||||
def_count = ARRAY_SIZE(wsa_defaults) + ARRAY_SIZE(wsa_defaults_v2_1);
|
def_count = ARRAY_SIZE(wsa_defaults) + ARRAY_SIZE(wsa_defaults_v2_1);
|
||||||
reg_defaults = devm_kmalloc_array(dev, def_count,
|
reg_defaults = kmalloc_array(def_count, sizeof(*reg_defaults),
|
||||||
sizeof(*reg_defaults),
|
GFP_KERNEL);
|
||||||
GFP_KERNEL);
|
|
||||||
if (!reg_defaults)
|
if (!reg_defaults)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
memcpy(®_defaults[0], wsa_defaults, sizeof(wsa_defaults));
|
memcpy(®_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:
|
case LPASS_CODEC_VERSION_2_8:
|
||||||
wsa->reg_layout = &wsa_codec_v2_5;
|
wsa->reg_layout = &wsa_codec_v2_5;
|
||||||
def_count = ARRAY_SIZE(wsa_defaults) + ARRAY_SIZE(wsa_defaults_v2_5);
|
def_count = ARRAY_SIZE(wsa_defaults) + ARRAY_SIZE(wsa_defaults_v2_5);
|
||||||
reg_defaults = devm_kmalloc_array(dev, def_count,
|
reg_defaults = kmalloc_array(def_count, sizeof(*reg_defaults),
|
||||||
sizeof(*reg_defaults),
|
GFP_KERNEL);
|
||||||
GFP_KERNEL);
|
|
||||||
if (!reg_defaults)
|
if (!reg_defaults)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
memcpy(®_defaults[0], wsa_defaults, sizeof(wsa_defaults));
|
memcpy(®_defaults[0], wsa_defaults, sizeof(wsa_defaults));
|
||||||
@ -2804,8 +2803,9 @@ static int wsa_macro_probe(struct platform_device *pdev)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
reg_config = devm_kmemdup(dev, &wsa_regmap_config,
|
struct regmap_config *reg_config __free(kfree) = kmemdup(&wsa_regmap_config,
|
||||||
sizeof(*reg_config), GFP_KERNEL);
|
sizeof(*reg_config),
|
||||||
|
GFP_KERNEL);
|
||||||
if (!reg_config)
|
if (!reg_config)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@ -2816,8 +2816,6 @@ static int wsa_macro_probe(struct platform_device *pdev)
|
|||||||
if (IS_ERR(wsa->regmap))
|
if (IS_ERR(wsa->regmap))
|
||||||
return PTR_ERR(wsa->regmap);
|
return PTR_ERR(wsa->regmap);
|
||||||
|
|
||||||
devm_kfree(dev, reg_config);
|
|
||||||
devm_kfree(dev, reg_defaults);
|
|
||||||
dev_set_drvdata(dev, wsa);
|
dev_set_drvdata(dev, wsa);
|
||||||
|
|
||||||
wsa->dev = dev;
|
wsa->dev = dev;
|
||||||
|
@ -3857,7 +3857,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
|
|||||||
*/
|
*/
|
||||||
int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
|
int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
|
||||||
const struct snd_soc_dapm_widget *widget,
|
const struct snd_soc_dapm_widget *widget,
|
||||||
int num)
|
unsigned int num)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user