ASoC: rt5682: split i2c driver into separate module
Subsystems (5)
PATCH 1/1 ASoC: rt5682: split i2c driver into separate module
With SND_SOC_AMD_RV_RT5682_MACH using the i2c version of the driver, we can easily get a build failure when I2C is built-in but soundwire is not:
WARNING: unmet direct dependencies detected for SND_SOC_RT5682
Depends on [m]: SOUND [=y] && !UML && SND [=y] && SND_SOC [=y] && (I2C [=y] || SOUNDWIRE [=m]) && (SOUNDWIRE [=m] || !SOUNDWIRE [=m]) && (I2C [=y] || !I2C [=y]) Selected by [y]:
- SND_SOC_AMD_RV_RT5682_MACH [=y] && SOUND [=y] && !UML && SND [=y] && SND_SOC [=y] && SND_SOC_AMD_ACP3x [=y] && I2C [=y] && CROS_EC [=y] Selected by [m]:
- SND_SOC_RT5682_SDW [=m] && SOUND [=y] && !UML && SND [=y] && SND_SOC [=y] && SOUNDWIRE [=m] && (I2C [=y] || !I2C [=y])
Rework the driver to have three separate modules, with the main driver just dealing with the common bits and the actual initialization as part of i2c and sdw specific modules.
The conversion is fairly mechanical to keep it easy to review, i.e. it moves code around with the minimal required renaming and changes.
--- sound/soc/amd/Kconfig | 2 +- sound/soc/codecs/Kconfig | 11 +- sound/soc/codecs/Makefile | 2 + sound/soc/codecs/rt5682-i2c.c | 341 ++++++++++++++ sound/soc/codecs/rt5682-sdw.c | 459 ++++++++++++++++++- sound/soc/codecs/rt5682-sdw.h | 20 - sound/soc/codecs/rt5682.c | 790 ++------------------------------- sound/soc/codecs/rt5682.h | 29 +- sound/soc/intel/boards/Kconfig | 6 +- 9 files changed, 869 insertions(+), 791 deletions(-) create mode 100644 sound/soc/codecs/rt5682-i2c.c delete mode 100644 sound/soc/codecs/rt5682-sdw.h
sound/soc/amd/Kconfig +1 -1
@@ -29,7 +29,7 @@ config SND_SOC_AMD_ACP3x config SND_SOC_AMD_RV_RT5682_MACH tristate "AMD RV support for RT5682" - select SND_SOC_RT5682 + select SND_SOC_RT5682_I2C select SND_SOC_MAX98357A select SND_SOC_CROS_EC_CODEC select I2C_CROS_EC_TUNNEL
sound/soc/codecs/Kconfig +6 -5
@@ -167,7 +167,7 @@ config SND_SOC_ALL_CODECS imply SND_SOC_RT5668 imply SND_SOC_RT5670 imply SND_SOC_RT5677 - imply SND_SOC_RT5682 + imply SND_SOC_RT5682_I2C imply SND_SOC_RT5682_SDW imply SND_SOC_RT700_SDW imply SND_SOC_RT711_SDW
@@ -1135,14 +1135,15 @@ config SND_SOC_RT5677_SPI config SND_SOC_RT5682 tristate - depends on I2C || SOUNDWIRE - depends on SOUNDWIRE || !SOUNDWIRE - depends on I2C || !I2C + +config SND_SOC_RT5682_I2C + tristate + depends on I2C + select SND_SOC_RT5682 config SND_SOC_RT5682_SDW tristate "Realtek RT5682 Codec - SDW" depends on SOUNDWIRE - depends on I2C || !I2C select SND_SOC_RT5682 select REGMAP_SOUNDWIRE
sound/soc/codecs/Makefile +2 -0
@@ -178,6 +178,7 @@ snd-soc-rt5677-objs := rt5677.o snd-soc-rt5677-spi-objs := rt5677-spi.o snd-soc-rt5682-objs := rt5682.o snd-soc-rt5682-sdw-objs := rt5682-sdw.o +snd-soc-rt5682-i2c-objs := rt5682-i2c.o snd-soc-rt700-objs := rt700.o rt700-sdw.o snd-soc-rt711-objs := rt711.o rt711-sdw.o snd-soc-rt715-objs := rt715.o rt715-sdw.o
@@ -479,6 +480,7 @@ obj-$(CONFIG_SND_SOC_RT5670) += snd-soc-rt5670.o obj-$(CONFIG_SND_SOC_RT5677) += snd-soc-rt5677.o obj-$(CONFIG_SND_SOC_RT5677_SPI) += snd-soc-rt5677-spi.o obj-$(CONFIG_SND_SOC_RT5682) += snd-soc-rt5682.o +obj-$(CONFIG_SND_SOC_RT5682_I2C) += snd-soc-rt5682-i2c.o obj-$(CONFIG_SND_SOC_RT5682_SDW) += snd-soc-rt5682-sdw.o obj-$(CONFIG_SND_SOC_RT700) += snd-soc-rt700.o obj-$(CONFIG_SND_SOC_RT711) += snd-soc-rt711.o
sound/soc/codecs/rt5682-i2c.c new file +341 -0
341 lines not on this page · raw message
sound/soc/codecs/rt5682-sdw.c +457 -2
477 lines not on this page · raw message
sound/soc/codecs/rt5682-sdw.h deleted +0 -20
@@ -1,20 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only -* -* rt5682-sdw.h -- RT5682 SDW ALSA SoC audio driver -* -* Copyright 2019 Realtek Semiconductor Corp. -* Author: Oder Chiou <[email protected]> -*/ - -#ifndef __RT5682_SDW_H__ -#define __RT5682_SDW_H__ - -#define RT5682_SDW_ADDR_L 0x3000 -#define RT5682_SDW_ADDR_H 0x3001 -#define RT5682_SDW_DATA_L 0x3004 -#define RT5682_SDW_DATA_H 0x3005 -#define RT5682_SDW_CMD 0x3008 - -#define RT5682_PROBE_TIMEOUT 2000 - -#endif /* __RT5682_SDW_H__ */
sound/soc/codecs/rt5682.c +33 -757
899 lines not on this page · raw message
sound/soc/codecs/rt5682.h +26 -3
@@ -1337,6 +1337,13 @@#define RT5682_SAR_SOUR_BTN (0x3f)#define RT5682_SAR_SOUR_TYPE (0x0) +/* soundwire timeout */ +#define RT5682_PROBE_TIMEOUT 2000 + + +#define RT5682_STEREO_RATES SNDRV_PCM_RATE_8000_192000 +#define RT5682_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ + SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)/* System Clock Source */ enum {
@@ -1420,8 +1427,24 @@ struct rt5682_priv {int rt5682_sel_asrc_clk_src (struct snd_soc_component *component,unsigned int filter_mask,unsigned int clk_src); -int rt5682_sdw_init (struct device *dev,struct regmap *regmap, -struct sdw_slave *slave); -int rt5682_io_init (struct device *dev,struct sdw_slave *slave); + +void rt5682_apply_patch_list (struct rt5682_priv *rt5682,struct device *dev); + +int rt5682_headset_detect (struct snd_soc_component *component,int jack_insert); +void rt5682_jack_detect_handler (struct work_struct *work); + +bool rt5682_volatile_register (struct device *dev,unsigned int reg); +bool rt5682_readable_register (struct device *dev,unsigned int reg); + +int rt5682_register_component (struct device *dev); +void rt5682_calibrate (struct rt5682_priv *rt5682); +void rt5682_reset (struct rt5682_priv *rt5682); + +#define RT5682_REG_NUM 318 +extern const struct reg_default rt5682_reg[RT5682_REG_NUM ]; + +extern const struct snd_soc_dai_ops rt5682_aif1_dai_ops; +extern const struct snd_soc_dai_ops rt5682_aif2_dai_ops; +extern const struct snd_soc_component_driver rt5682_soc_component_dev;#endif /* __RT5682_H__ */
sound/soc/intel/boards/Kconfig +3 -3
@@ -430,7 +430,7 @@ config SND_SOC_INTEL_GLK_RT5682_MAX98357A_MACH depends on I2C && ACPI && GPIOLIB depends on MFD_INTEL_LPSS || COMPILE_TEST depends on SND_HDA_CODEC_HDMI - select SND_SOC_RT5682 + select SND_SOC_RT5682_I2C select SND_SOC_MAX98357A select SND_SOC_DMIC select SND_SOC_HDAC_HDMI
@@ -468,7 +468,7 @@ config SND_SOC_INTEL_SOF_RT5682_MACH depends on SND_HDA_CODEC_HDMI select SND_SOC_MAX98373 select SND_SOC_RT1015 - select SND_SOC_RT5682 + select SND_SOC_RT5682_I2C select SND_SOC_DMIC select SND_SOC_HDAC_HDMI help
@@ -511,7 +511,7 @@ config SND_SOC_INTEL_SOF_CML_RT1011_RT5682_MACH depends on MFD_INTEL_LPSS || COMPILE_TEST depends on SND_HDA_CODEC_HDMI select SND_SOC_RT1011 - select SND_SOC_RT5682 + select SND_SOC_RT5682_I2C select SND_SOC_DMIC select SND_SOC_HDAC_HDMI help
Signature · 1 line
2.26.2
Mark Brown
maintainersound/soc/codecs/rt5682-i2c.c line 4
Quoted 8 lines · Arnd Bergmann
index 000000000000..c891aa80757f
sound/soc/codecs/rt5682-i2c.c new file +4
-0@@ -0,0 +1,341 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* rt5682.c -- RT5682 ALSA SoC audio component driver +*
Please keep the entire comment C++ so things look more intentional.
sound/soc/codecs/rt5682-i2c.c line 39
Quoted 5 lines
sound/soc/codecs/rt5682-i2c.c new file +5
-0+static const char *rt5682_supply_names[RT5682_NUM_SUPPLIES ] = { +"AVDD" , +"MICVDD" , +"VBAT" , +};
I'm *fairly* sure the device needs power even with Soundwire?
sound/soc/codecs/rt5682-i2c.c line 88
Quoted 12 lines
sound/soc/codecs/rt5682-i2c.c new file +11
-0+static void rt5682_jd_check_handler (struct work_struct *work) +{ + struct rt5682_priv *rt5682 = container_of(work, struct rt5682_priv, + jd_check_work.work); +static int rt5682_parse_dt (struct rt5682_priv *rt5682,struct device *dev) +{ + +device_property_read_u32 (dev,"realtek,dmic1-data-pin" , + &rt5682->pdata.dmic1_data_pin); +device_property_read_u32 (dev,"realtek,dmic1-clk-pin" , + &rt5682->pdata.dmic1_clk_pin);
This doesn't look very I2C specific either, nor do chunks of the rest of the code. The usual pattern with this stuff is to have the bus specific code do bus specific stuff like setting up the regmap and then call into a common init function for the shared parts of the chip. I'd expect a bit more unshared code here but not this much.
Quoted 13 lines · Mark Brown
sound/soc/codecs/rt5682-i2c.c line 4
Quoted 8 lines · Arnd Bergmann
index 000000000000..c891aa80757f
sound/soc/codecs/rt5682-i2c.c new file +4
-0@@ -0,0 +1,341 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* rt5682.c -- RT5682 ALSA SoC audio component driver +* Please keep the entire comment C++ so things look more intentional.
That's the kind of change I was trying to avoid by just moving things around, but I've done that now in both files.
Quoted 7 lines
sound/soc/codecs/rt5682-i2c.c line 39
Quoted 5 lines
sound/soc/codecs/rt5682-i2c.c new file +5
-0+static const char *rt5682_supply_names[RT5682_NUM_SUPPLIES ] = { +"AVDD" , +"MICVDD" , +"VBAT" , +};I'm *fairly* sure the device needs power even with Soundwire?
I have no idea how this is done with ACPI. I'm moving it back as an exported symbol. There should probably be some abstraction that handles this in the common part of the driver along with some of the other bits of rt5682_i2c_probe, but really don't want to shake things up too much and would let this be done by whoever needs to add DT support to the soundwire driver in the future and is able to test the changes.
Quoted 5 lines
Quoted 4 lines
sound/soc/codecs/rt5682-i2c.c new file +4
-0+static void rt5682_jd_check_handler (struct work_struct *work) +{ + struct rt5682_priv *rt5682 = container_of(work, struct rt5682_priv, + jd_check_work.work);
Quoted 13 lines
sound/soc/codecs/rt5682-i2c.c line 88
Quoted 7 lines
sound/soc/codecs/rt5682-i2c.c new file +7
-0+static int rt5682_parse_dt (struct rt5682_priv *rt5682,struct device *dev) +{ + +device_property_read_u32 (dev,"realtek,dmic1-data-pin" , + &rt5682->pdata.dmic1_data_pin); +device_property_read_u32 (dev,"realtek,dmic1-clk-pin" , + &rt5682->pdata.dmic1_clk_pin);This doesn't look very I2C specific either, nor do chunks of the rest of the code. The usual pattern with this stuff is to have the bus specific code do bus specific stuff like setting up the regmap and then call into a common init function for the shared parts of the chip. I'd expect a bit more unshared code here but not this much.
Right, I was surprised the soundwire portion does not tie into device tree at all, and none of the other soundwire codecs seem to either and no dts files reference it, though there is some code for the subsystem and a binding.
Arnd
Mark Brown
maintainerQuoted 11 lines · Arnd Bergmann
Quoted 9 lines · Mark Brown
sound/soc/codecs/rt5682-i2c.c line 39
Quoted 5 lines · Arnd Bergmann
sound/soc/codecs/rt5682-i2c.c new file +5
-0+static const char *rt5682_supply_names[RT5682_NUM_SUPPLIES ] = { +"AVDD" , +"MICVDD" , +"VBAT" , +};I'm *fairly* sure the device needs power even with Soundwire?
Quoted 1 line
I have no idea how this is done with ACPI. I'm moving it
There are non-ACPI SoundWire systems - Qualcomm have some systems upstream.
Quoted 7 lines
back as an exported symbol. There should probably be some abstraction that handles this in the common part of the driver along with some of the other bits of
rt5682_i2c_probe, but really don't want to shake things up too much and would let this be done by whoever needs to add DT support to the soundwire driver in the future and is able to test the changes.
Like I say the abstraction is generally just setting up the very basic stuff and calling into a common init function with a few parameters.
Quoted 10 lines
Quoted 5 lines
This doesn't look very I2C specific either, nor do chunks of the rest of the code. The usual pattern with this stuff is to have the bus specific code do bus specific stuff like setting up the regmap and then call into a common init function for the shared parts of the chip. I'd expect a bit more unshared code here but not this much.
Right, I was surprised the soundwire portion does not tie into device tree at all, and none of the other soundwire codecs seem to either and no dts files reference it, though there is some code for the subsystem and a binding.
The stuff that's upstream for DT platforms is for Qualcomm systems where the reference designs are generally fully integrated with Qualcomm components so there's limited overlap. IIRC they also have a fairly unusual system design with a mix of SoundWire and Slimbus usually (that was the case for a while at least).
Quoted 15 lines · Arnd Bergmann
With
SND_SOC_AMD_RV_RT5682_MACHusing the i2c version of the driver, we can easily get a build failure when I2C is built-in but soundwire is not:WARNING: unmet direct dependencies detected for
SND_SOC_RT5682
Depends on [m]: SOUND [=y] && !UML && SND [=y] &&SND_SOC[=y] && (I2C [=y] || SOUNDWIRE [=m]) && (SOUNDWIRE [=m] || !SOUNDWIRE [=m]) && (I2C [=y] || !I2C [=y]) Selected by [y]:
-SND_SOC_AMD_RV_RT5682_MACH[=y] && SOUND [=y] && !UML && SND [=y] &&SND_SOC[=y] &&SND_SOC_AMD_ACP3x[=y] && I2C [=y] &&CROS_EC[=y] Selected by [m]:
-SND_SOC_RT5682_SDW[=m] && SOUND [=y] && !UML && SND [=y] &&SND_SOC[=y] && SOUNDWIRE [=m] && (I2C [=y] || !I2C [=y])Rework the driver to have three separate modules, with the main driver just dealing with the common bits and the actual initialization as part of i2c and sdw specific modules.
Quoted 7 lines
The conversion is fairly mechanical to keep it easy to review, i.e. it moves code around with the minimal required renaming and changes.
Fixes 6b8e4e7db3cd ("ASoC: amd: Add machine driver for Raven based platform")Fixes fd443a20c2f0 ("ASoC: rt5682: fix I2C/Soundwire dependencies")Signed-off-by Arnd Bergmann <[email protected]>
Thanks for this cleanup.