From df7d49af42c7cfe92e7d83ab049add76de1cd2a7 Mon Sep 17 00:00:00 2001 From: Sugar Zhang Date: Thu, 11 Jul 2019 19:18:13 +0800 Subject: [PATCH] ASoC: codecs: add support for rk3328 switch to use snd_soc_component. Change-Id: I66ff61c18fe70135fd7ac0569954263743263a3a Signed-off-by: Sugar Zhang --- sound/soc/codecs/Kconfig | 5 +++ sound/soc/codecs/Makefile | 2 + sound/soc/codecs/rk3328_codec.c | 67 ++++++++++++--------------------- 3 files changed, 32 insertions(+), 42 deletions(-) diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index f88924fb5824..3268d4414a7c 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -124,6 +124,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_PCM5102A select SND_SOC_PCM512x_I2C if I2C select SND_SOC_PCM512x_SPI if SPI_MASTER + select SND_SOC_RK3328 select SND_SOC_RT274 if I2C select SND_SOC_RT286 if I2C select SND_SOC_RT298 if I2C @@ -765,6 +766,10 @@ config SND_SOC_PCM512x_SPI select SND_SOC_PCM512x select REGMAP_SPI +config SND_SOC_RK3328 + select REGMAP_MMIO + tristate "Rockchip RK3328 CODEC" + config SND_SOC_RL6231 tristate default y if SND_SOC_RT5514=y diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 7ae7c85e8219..891162d49a3f 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -126,6 +126,7 @@ snd-soc-pcm5102a-objs := pcm5102a.o snd-soc-pcm512x-objs := pcm512x.o snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o snd-soc-pcm512x-spi-objs := pcm512x-spi.o +snd-soc-rk3328-objs := rk3328_codec.o snd-soc-rl6231-objs := rl6231.o snd-soc-rl6347a-objs := rl6347a.o snd-soc-rt1305-objs := rt1305.o @@ -386,6 +387,7 @@ obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o +obj-$(CONFIG_SND_SOC_RK3328) += snd-soc-rk3328.o obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o obj-$(CONFIG_SND_SOC_RL6347A) += snd-soc-rl6347a.o obj-$(CONFIG_SND_SOC_RT1305) += snd-soc-rt1305.o diff --git a/sound/soc/codecs/rk3328_codec.c b/sound/soc/codecs/rk3328_codec.c index 5d8784db4dc5..5a4184acde9f 100644 --- a/sound/soc/codecs/rk3328_codec.c +++ b/sound/soc/codecs/rk3328_codec.c @@ -66,9 +66,9 @@ static const struct reg_default rk3328_codec_reg_defaults[] = { { HPOUT_POP_CTRL, 0x11 }, }; -static int rk3328_codec_reset(struct snd_soc_codec *codec) +static int rk3328_codec_reset(struct snd_soc_component *component) { - struct rk3328_codec_priv *rk3328 = snd_soc_codec_get_drvdata(codec); + struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(component); regmap_write(rk3328->regmap, CODEC_RESET, 0); mdelay(10); @@ -77,11 +77,10 @@ static int rk3328_codec_reset(struct snd_soc_codec *codec) return 0; } -static int rk3328_set_dai_fmt(struct snd_soc_dai *codec_dai, +static int rk3328_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) { - struct snd_soc_codec *codec = codec_dai->codec; - struct rk3328_codec_priv *rk3328 = snd_soc_codec_get_drvdata(codec); + struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(dai->component); unsigned int val = 0; switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { @@ -130,8 +129,7 @@ static void rk3328_analog_output(struct rk3328_codec_priv *rk3328, int mute) static int rk3328_digital_mute(struct snd_soc_dai *dai, int mute) { - struct snd_soc_codec *codec = dai->codec; - struct rk3328_codec_priv *rk3328 = snd_soc_codec_get_drvdata(codec); + struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(dai->component); unsigned int val = 0; if (mute) @@ -144,9 +142,9 @@ static int rk3328_digital_mute(struct snd_soc_dai *dai, int mute) return 0; } -static int rk3328_codec_power_on(struct snd_soc_codec *codec, int wait_ms) +static int rk3328_codec_power_on(struct snd_soc_component *component, int wait_ms) { - struct rk3328_codec_priv *rk3328 = snd_soc_codec_get_drvdata(codec); + struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(component); regmap_update_bits(rk3328->regmap, DAC_PRECHARGE_CTRL, DAC_CHARGE_XCHARGE_MASK, DAC_CHARGE_PRECHARGE); @@ -160,9 +158,9 @@ static int rk3328_codec_power_on(struct snd_soc_codec *codec, int wait_ms) return 0; } -static int rk3328_codec_power_off(struct snd_soc_codec *codec, int wait_ms) +static int rk3328_codec_power_off(struct snd_soc_component *component, int wait_ms) { - struct rk3328_codec_priv *rk3328 = snd_soc_codec_get_drvdata(codec); + struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(component); regmap_update_bits(rk3328->regmap, DAC_PRECHARGE_CTRL, DAC_CHARGE_XCHARGE_MASK, DAC_CHARGE_DISCHARGE); @@ -207,9 +205,9 @@ static struct rk3328_reg_msk_val playback_open_list[] = { #define PLAYBACK_OPEN_LIST_LEN ARRAY_SIZE(playback_open_list) -static int rk3328_codec_open_playback(struct snd_soc_codec *codec) +static int rk3328_codec_open_playback(struct snd_soc_component *component) { - struct rk3328_codec_priv *rk3328 = snd_soc_codec_get_drvdata(codec); + struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(component); int i = 0; regmap_update_bits(rk3328->regmap, DAC_PRECHARGE_CTRL, @@ -263,9 +261,9 @@ static struct rk3328_reg_msk_val playback_close_list[] = { #define PLAYBACK_CLOSE_LIST_LEN ARRAY_SIZE(playback_close_list) -static int rk3328_codec_close_playback(struct snd_soc_codec *codec) +static int rk3328_codec_close_playback(struct snd_soc_component *component) { - struct rk3328_codec_priv *rk3328 = snd_soc_codec_get_drvdata(codec); + struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(component); int i = 0; rk3328_analog_output(rk3328, 0); @@ -293,8 +291,7 @@ static int rk3328_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 rk3328_codec_priv *rk3328 = snd_soc_codec_get_drvdata(codec); + struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(dai->component); unsigned int val = 0; switch (params_format(params)) { @@ -325,20 +322,16 @@ static int rk3328_hw_params(struct snd_pcm_substream *substream, static int rk3328_pcm_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct snd_soc_codec *codec = dai->codec; - - return rk3328_codec_open_playback(codec); + return rk3328_codec_open_playback(dai->component); } static void rk3328_pcm_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct snd_soc_codec *codec = dai->codec; - - rk3328_codec_close_playback(codec); + rk3328_codec_close_playback(dai->component); } -static struct snd_soc_dai_ops rk3328_dai_ops = { +static const struct snd_soc_dai_ops rk3328_dai_ops = { .hw_params = rk3328_hw_params, .set_fmt = rk3328_set_dai_fmt, .digital_mute = rk3328_digital_mute, @@ -374,23 +367,21 @@ static struct snd_soc_dai_driver rk3328_dai[] = { }, }; -static int rk3328_codec_probe(struct snd_soc_codec *codec) +static int rk3328_codec_probe(struct snd_soc_component *component) { - rk3328_codec_reset(codec); - rk3328_codec_power_on(codec, 0); + rk3328_codec_reset(component); + rk3328_codec_power_on(component, 0); return 0; } -static int rk3328_codec_remove(struct snd_soc_codec *codec) +static void rk3328_codec_remove(struct snd_soc_component *component) { - rk3328_codec_close_playback(codec); - rk3328_codec_power_off(codec, 0); - - return 0; + rk3328_codec_close_playback(component); + rk3328_codec_power_off(component, 0); } -static struct snd_soc_codec_driver soc_codec_dev_rk3328 = { +static const struct snd_soc_component_driver soc_codec_dev_rk3328 = { .probe = rk3328_codec_probe, .remove = rk3328_codec_remove, }; @@ -514,24 +505,16 @@ static int rk3328_platform_probe(struct platform_device *pdev) platform_set_drvdata(pdev, rk3328); - return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_rk3328, + return devm_snd_soc_register_component(&pdev->dev, &soc_codec_dev_rk3328, rk3328_dai, ARRAY_SIZE(rk3328_dai)); } -static int rk3328_platform_remove(struct platform_device *pdev) -{ - snd_soc_unregister_codec(&pdev->dev); - return 0; -} - static struct platform_driver rk3328_codec_driver = { .driver = { .name = "rk3328-codec", - .owner = THIS_MODULE, .of_match_table = of_match_ptr(rk3328codec_of_match), }, .probe = rk3328_platform_probe, - .remove = rk3328_platform_remove, }; module_platform_driver(rk3328_codec_driver);