ASoC: ssm2602: Split SPI and I2C code into different modules
Subsystems (3)
Lars-Peter Clausen
maintainerPATCH 1/4 ASoC: ssm2602: Split SPI and I2C code into different modules
There are a few known (minor) problems with having the support code for both I2C and SPI in the same module:
* We need to be extra careful to make sure to not build the driver into the kernel if one of the subsystems is build as a module (Currently only SPI can be build as a module).
* The module init path error handling is rather ugly. E.g. what should be done if either the SPI or the I2C driver fails to register? Most drivers that implement SPI and I2C in the same module currently fallback to undefined behavior in that case. Splitting the the driver into two modules, one for each bus allows the registration of the other bus driver to continue without problems if one of them fails.
This patch splits the AD193X driver into 3 modules. One core module that implements the device logic, but is independent of the bus method used. And one module for SPI and I2C each that registers the drivers and sets up the regmap struct for the bus.
While we are at it also cleanup the include section of the ssm2602 driver and remove unneeded includes.
--- sound/soc/blackfin/Kconfig | 3 +- sound/soc/codecs/Kconfig | 11 ++- sound/soc/codecs/Makefile | 4 ++ sound/soc/codecs/ssm2602-i2c.c | 57 +++++++++++++++ sound/soc/codecs/ssm2602-spi.c | 41 +++++++++++ sound/soc/codecs/ssm2602.c | 158 ++++++----------------------------------- sound/soc/codecs/ssm2602.h | 14 ++++ 7 files changed, 148 insertions(+), 140 deletions(-) create mode 100644 sound/soc/codecs/ssm2602-i2c.c create mode 100644 sound/soc/codecs/ssm2602-spi.c
sound/soc/blackfin/Kconfig +2 -1
@@ -14,7 +14,8 @@ config SND_BF5XX_SOC_SSM2602 depends on SND_BF5XX_I2S && SND_SOC_I2C_AND_SPI select SND_BF5XX_SOC_I2S if !BF60x select SND_BF6XX_SOC_I2S if BF60x - select SND_SOC_SSM2602 + select SND_SOC_SSM2602_SPI if SPI_MASTER + select SND_SOC_SSM2602_I2C if I2C help Say Y if you want to add support for the Analog Devices SSM2602 Audio Codec Add-On Card.
sound/soc/codecs/Kconfig +10 -1
@@ -70,7 +70,8 @@ config SND_SOC_ALL_CODECS select SND_SOC_SN95031 if INTEL_SCU_IPC select SND_SOC_SPDIF select SND_SOC_SSM2518 if I2C - select SND_SOC_SSM2602 if SND_SOC_I2C_AND_SPI + select SND_SOC_SSM2602_SPI if SPI_MASTER + select SND_SOC_SSM2602_I2C if I2C select SND_SOC_STA32X if I2C select SND_SOC_STA529 if I2C select SND_SOC_STAC9766 if SND_SOC_AC97_BUS
@@ -361,6 +362,14 @@ config SND_SOC_SSM2518 config SND_SOC_SSM2602 tristate +config SND_SOC_SSM2602_SPI + select SND_SOC_SSM2602 + tristate + +config SND_SOC_SSM2602_I2C + select SND_SOC_SSM2602 + tristate + config SND_SOC_STA32X tristate
sound/soc/codecs/Makefile +4 -0
@@ -59,6 +59,8 @@ snd-soc-spdif-tx-objs := spdif_transmitter.o snd-soc-spdif-rx-objs := spdif_receiver.o snd-soc-ssm2518-objs := ssm2518.o snd-soc-ssm2602-objs := ssm2602.o +snd-soc-ssm2602-spi-objs := ssm2602-spi.o +snd-soc-ssm2602-i2c-objs := ssm2602-i2c.o snd-soc-sta32x-objs := sta32x.o snd-soc-sta529-objs := sta529.o snd-soc-stac9766-objs := stac9766.o
@@ -190,6 +192,8 @@ obj-$(CONFIG_SND_SOC_SN95031) +=snd-soc-sn95031.o obj-$(CONFIG_SND_SOC_SPDIF) += snd-soc-spdif-rx.o snd-soc-spdif-tx.o obj-$(CONFIG_SND_SOC_SSM2518) += snd-soc-ssm2518.o obj-$(CONFIG_SND_SOC_SSM2602) += snd-soc-ssm2602.o +obj-$(CONFIG_SND_SOC_SSM2602_SPI) += snd-soc-ssm2602-spi.o +obj-$(CONFIG_SND_SOC_SSM2602_I2C) += snd-soc-ssm2602-i2c.o obj-$(CONFIG_SND_SOC_STA32X) += snd-soc-sta32x.o obj-$(CONFIG_SND_SOC_STA529) += snd-soc-sta529.o obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o
sound/soc/codecs/ssm2602-i2c.c new file +57 -0
57 lines not on this page · raw message
sound/soc/codecs/ssm2602-spi.c new file +41 -0
41 lines not on this page · raw message
sound/soc/codecs/ssm2602.c +20 -138
227 lines not on this page · raw message
sound/soc/codecs/ssm2602.h +14 -0
@@ -28,6 +28,20 @@#ifndef _SSM2602_H#define _SSM2602_H +#include <linux/regmap.h> + +struct device ; + +enum ssm2602_type { +SSM2602 , +SSM2604 , +}; + +extern const struct regmap_config ssm2602_regmap_config; + +int ssm2602_probe (struct device *dev,enum ssm2602_type type, +struct regmap *regmap); +/* SSM2602 Codec Register definitions */ #define SSM2602_LINVOL 0x00
Signature · 1 line
1.8.0
Lars-Peter Clausen
maintainerPATCH 2/4 ASoC: ad193x: Split SPI and I2C code into different modules
There are a few known (minor) problems with having the support code for both I2C and SPI in the same module:
* We need to be extra careful to make sure to not build the driver into the kernel if one of the subsystems is build as a module (Currently only SPI can be build as a module).
* The module init path error handling is rather ugly. E.g. what should be done if either the SPI or the I2C driver fails to register? Most drivers that implement SPI and I2C in the same module currently fallback to undefined behavior in that case. Splitting the the driver into two modules, one for each bus, allows the registration of the other bus driver to continue without problems if one of them fails.
This patch splits the AD193X driver into 3 modules. One core module that implements the device logic, but is independent of the bus method used. And one module for SPI and I2C each that registers the drivers and sets up the regmap struct for the bus.
--- sound/soc/blackfin/Kconfig | 3 +- sound/soc/codecs/Kconfig | 11 +++- sound/soc/codecs/Makefile | 4 ++ sound/soc/codecs/ad193x-i2c.c | 54 ++++++++++++++++ sound/soc/codecs/ad193x-spi.c | 48 +++++++++++++++ sound/soc/codecs/ad193x.c | 140 +++++------------------------------------- sound/soc/codecs/ad193x.h | 7 +++ 7 files changed, 140 insertions(+), 127 deletions(-) create mode 100644 sound/soc/codecs/ad193x-i2c.c create mode 100644 sound/soc/codecs/ad193x-spi.c
sound/soc/blackfin/Kconfig +2 -1
@@ -68,7 +68,8 @@ config SND_BF5XX_SOC_AD193X tristate "SoC AD193X Audio support for Blackfin" depends on SND_BF5XX_I2S && SND_SOC_I2C_AND_SPI select SND_BF5XX_SOC_I2S - select SND_SOC_AD193X + select SND_SOC_AD193X_I2C if I2C + select SND_SOC_AD193X_SPI if SPI_MASTER help Say Y if you want to add support for AD193X codec on Blackfin. This driver supports AD1936, AD1937, AD1938 and AD1939.
sound/soc/codecs/Kconfig +10 -1
@@ -18,7 +18,8 @@ config SND_SOC_ALL_CODECS select SND_SOC_AB8500_CODEC if ABX500_CORE select SND_SOC_AC97_CODEC if SND_SOC_AC97_BUS select SND_SOC_AD1836 if SPI_MASTER - select SND_SOC_AD193X if SND_SOC_I2C_AND_SPI + select SND_SOC_AD193X_SPI if SPI_MASTER + select SND_SOC_AD193X_I2C if I2C select SND_SOC_AD1980 if SND_SOC_AC97_BUS select SND_SOC_AD73311 select SND_SOC_ADAU1373 if I2C
@@ -187,6 +188,14 @@ config SND_SOC_AD1836 config SND_SOC_AD193X tristate +config SND_SOC_AD193X_SPI + tristate + select SND_SOC_AD193X + +config SND_SOC_AD193X_I2C + tristate + select SND_SOC_AD193X + config SND_SOC_AD1980 tristate
sound/soc/codecs/Makefile +4 -0
@@ -3,6 +3,8 @@ snd-soc-ab8500-codec-objs := ab8500-codec.o snd-soc-ac97-objs := ac97.o snd-soc-ad1836-objs := ad1836.o snd-soc-ad193x-objs := ad193x.o +snd-soc-ad193x-spi-objs := ad193x-spi.o +snd-soc-ad193x-i2c-objs := ad193x-i2c.o snd-soc-ad1980-objs := ad1980.o snd-soc-ad73311-objs := ad73311.o snd-soc-adau1701-objs := adau1701.o
@@ -137,6 +139,8 @@ obj-$(CONFIG_SND_SOC_AB8500_CODEC) += snd-soc-ab8500-codec.o obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o obj-$(CONFIG_SND_SOC_AD1836) += snd-soc-ad1836.o obj-$(CONFIG_SND_SOC_AD193X) += snd-soc-ad193x.o +obj-$(CONFIG_SND_SOC_AD193X_SPI) += snd-soc-ad193x-spi.o +obj-$(CONFIG_SND_SOC_AD193X_I2C) += snd-soc-ad193x-i2c.o obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o obj-$(CONFIG_SND_SOC_ADAU1373) += snd-soc-adau1373.o
sound/soc/codecs/ad193x-i2c.c new file +54 -0
54 lines not on this page · raw message
sound/soc/codecs/ad193x-spi.c new file +48 -0
48 lines not on this page · raw message
sound/soc/codecs/ad193x.c +15 -125
187 lines not on this page · raw message
sound/soc/codecs/ad193x.h +7 -0
@@ -9,6 +9,13 @@#ifndef __AD193X_H__#define __AD193X_H__ +#include <linux/regmap.h> + +struct device ; + +extern const struct regmap_config ad193x_regmap_config; +int ad193x_probe (struct device *dev,struct regmap *regmap); +#define AD193X_PLL_CLK_CTRL0 0x00#define AD193X_PLL_POWERDOWN 0x01#define AD193X_PLL_INPUT_MASK 0x6
Signature · 1 line
1.8.0
Mark Brown
maintainerRe: [PATCH 2/4] ASoC: ad193x: Split SPI and I2C code into different modules
Quoted 2 lines · Lars-Peter Clausen
kernel if one of the subsystems is build as a module (Currently only SPI can be build as a module).
Same issue again here. You're also going right up to the 80 column limit here and...
Quoted 6 lines
* The module init path error handling is rather ugly. E.g. what should be done if either the SPI or the I2C driver fails to register? Most drivers that implement SPI and I2C in the same module currently fallback to undefined behavior in that case. Splitting the the driver into two modules, one for each bus, allows the registration of the other bus driver to continue without problems if one of them fails.
...and something is messed up here, looks like tab/space confusion.
Applied with fixups to the changelog.
Lars-Peter Clausen
maintainerPATCH 3/4 ASoC: adav80x: Use devm_kzalloc()
In reply to Lars-Peter ClausenUse devm_kzalloc() to allocate the device state struct. Saves use from having to free it manually on the error path and in the remove callback.
Now that the adav80x_bus_probe() function is only a call to snd_soc_unregister_codec() also inline that.
--- sound/soc/codecs/adav80x.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-)
sound/soc/codecs/adav80x.c +6 -16
@@ -872,27 +872,15 @@ static int adav80x_bus_probe(struct device *dev, struct regmap *regmap)if (IS_ERR (regmap))return PTR_ERR (regmap); - adav80x =kzalloc (sizeof (*adav80x),GFP_KERNEL ); + adav80x =devm_kzalloc (dev,sizeof (*adav80x),GFP_KERNEL );if (!adav80x)return -ENOMEM ; -dev_set_drvdata (dev, adav80x); adav80x->regmap = regmap; - ret =snd_soc_register_codec (dev, &adav80x_codec_driver, +return snd_soc_register_codec (dev, &adav80x_codec_driver, adav80x_dais,ARRAY_SIZE (adav80x_dais)); -if (ret) -kfree (adav80x); - -return ret; -} - -static int adav80x_bus_remove (struct device *dev) -{ -snd_soc_unregister_codec (dev); -kfree (dev_get_drvdata (dev)); -return 0 ; }#if defined(CONFIG_SPI_MASTER )
@@ -923,7 +911,8 @@ static int adav80x_spi_probe(struct spi_device *spi)static int adav80x_spi_remove (struct spi_device *spi) { -return adav80x_bus_remove (&spi->dev); +snd_soc_unregister_codec (dev); +return 0 ; }static struct spi_driver adav80x_spi_driver = {
@@ -965,7 +954,8 @@ static int adav80x_i2c_probe(struct i2c_client *client,static int adav80x_i2c_remove (struct i2c_client *client) { -return adav80x_bus_remove (&client->dev); +snd_soc_unregister_codec (dev); +return 0 ; }static struct i2c_driver adav80x_i2c_driver = {
Signature · 1 line
1.8.0
Re: [PATCH 3/4] ASoC: adav80x: Use devm_kzalloc()
Quoted 5 lines · Lars-Peter Clausen
Use
devm_kzalloc()to allocate the device state struct. Saves use from having to free it manually on the error path and in the remove callback.Now that the
adav80x_bus_probe()function is only a call tosnd_soc_unregister_codec()also inline that.
Applied, thanks.
Lars-Peter Clausen
maintainerPATCH 4/4 ASoC: adav80x: Split SPI and I2C code into different modules
In reply to Lars-Peter ClausenThere are a few known (minor) problems with having the support code for both I2C and SPI in the same module:
* We need to be extra careful to make sure to not build the driver into the kernel if one of the subsystems is build as a module (Currently only SPI can be build as a module).
* The module init path error handling is rather ugly. E.g. what should be done if either the SPI or the I2C driver fails to register. Most drivers that implement SPI and I2C in the same module currently fallback to undefined behavior in that case. Splitting the the driver into two modules, one for each bus, allows the registration of the other bus drive to continue without problems if one of them fails.
This patch splits the ADAV80X driver into 3 modules. One core module that implements the device logic, but is independent of the bus method used. And one module for SPI and I2C each that registers the drivers and sets up the regmap struct for the bus.
--- sound/soc/blackfin/Kconfig | 3 +- sound/soc/codecs/Kconfig | 11 ++++- sound/soc/codecs/Makefile | 4 ++ sound/soc/codecs/adav801.c | 53 ++++++++++++++++++++ sound/soc/codecs/adav803.c | 50 +++++++++++++++++++ sound/soc/codecs/adav80x.c | 117 +++------------------------------------------ sound/soc/codecs/adav80x.h | 7 +++ 7 files changed, 133 insertions(+), 112 deletions(-) create mode 100644 sound/soc/codecs/adav801.c create mode 100644 sound/soc/codecs/adav803.c
sound/soc/blackfin/Kconfig +2 -1
@@ -47,7 +47,8 @@ config SND_SOC_BFIN_EVAL_ADAV80X tristate "Support for the EVAL-ADAV80X boards on Blackfin eval boards" depends on SND_BF5XX_I2S && SND_SOC_I2C_AND_SPI select SND_BF5XX_SOC_I2S - select SND_SOC_ADAV80X + select SND_SOC_ADAV801 if SPI_MASTER + select SND_SOC_ADAV803 if I2C help Say Y if you want to add support for the Analog Devices EVAL-ADAV801 or EVAL-ADAV803 board connected to one of the Blackfin evaluation boards
sound/soc/codecs/Kconfig +10 -1
@@ -23,7 +23,8 @@ config SND_SOC_ALL_CODECS select SND_SOC_AD1980 if SND_SOC_AC97_BUS select SND_SOC_AD73311 select SND_SOC_ADAU1373 if I2C - select SND_SOC_ADAV80X if SND_SOC_I2C_AND_SPI + select SND_SOC_ADAV801 if SPI_MASTER + select SND_SOC_ADAV803 if I2C select SND_SOC_ADAU1701 if I2C select SND_SOC_ADS117X select SND_SOC_AK4104 if SPI_MASTER
@@ -213,6 +214,14 @@ config SND_SOC_ADAU1373 config SND_SOC_ADAV80X tristate +config SND_SOC_ADAV801 + tristate + select SND_SOC_ADAV80X + +config SND_SOC_ADAV803 + tristate + select SND_SOC_ADAV80X + config SND_SOC_ADS117X tristate
sound/soc/codecs/Makefile +4 -0
@@ -10,6 +10,8 @@ snd-soc-ad73311-objs := ad73311.o snd-soc-adau1701-objs := adau1701.o snd-soc-adau1373-objs := adau1373.o snd-soc-adav80x-objs := adav80x.o +snd-soc-adav801-objs := adav801.o +snd-soc-adav803-objs := adav803.o snd-soc-ads117x-objs := ads117x.o snd-soc-ak4104-objs := ak4104.o snd-soc-ak4535-objs := ak4535.o
@@ -146,6 +148,8 @@ obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o obj-$(CONFIG_SND_SOC_ADAU1373) += snd-soc-adau1373.o obj-$(CONFIG_SND_SOC_ADAU1701) += snd-soc-adau1701.o obj-$(CONFIG_SND_SOC_ADAV80X) += snd-soc-adav80x.o +obj-$(CONFIG_SND_SOC_ADAV801) += snd-soc-adav801.o +obj-$(CONFIG_SND_SOC_ADAV803) += snd-soc-adav803.o obj-$(CONFIG_SND_SOC_ADS117X) += snd-soc-ads117x.o obj-$(CONFIG_SND_SOC_AK4104) += snd-soc-ak4104.o obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o
sound/soc/codecs/adav801.c new file +53 -0
53 lines not on this page · raw message
sound/soc/codecs/adav803.c new file +50 -0
50 lines not on this page · raw message
sound/soc/codecs/adav80x.c +7 -110
150 lines not on this page · raw message
sound/soc/codecs/adav80x.h +7 -0
@@ -9,6 +9,13 @@#ifndef _ADAV80X_H#define _ADAV80X_H +#include <linux/regmap.h> + +struct device ; + +extern const struct regmap_config adav80x_regmap_config; +int adav80x_bus_probe (struct device *dev,struct regmap *regmap); +enum adav80x_pll_src {ADAV80X_PLL_SRC_XIN , ADAV80X_PLL_SRC_XTAL,
Signature · 1 line
1.8.0
Re: [PATCH 4/4] ASoC: adav80x: Split SPI and I2C code into different modules
Quoted 2 lines · Lars-Peter Clausen
There are a few known (minor) problems with having the support code for both I2C and SPI in the same module:
Applied, thanks.
Mark Brown
maintainerQuoted 5 lines · Lars-Peter Clausen
There are a few known (minor) problems with having the support code for both I2C and SPI in the same module:
* We need to be extra careful to make sure to not build the driver into the kernel if one of the subsystems is build as a module (Currently only SPI can be build as a module).
I2C not SPI.
Quoted 4 lines
This patch splits the AD193X driver into 3 modules. One core module that implements the device logic, but is independent of the bus method used. And one module for SPI and I2C each that registers the drivers and sets up the regmap struct for the bus.
No it doesn't, it splits the ssm2602 driver.
Quoted 9 lines
Signed-off-by Lars-Peter Clausen <[email protected]>--- sound/soc/blackfin/Kconfig | 3 +- sound/soc/codecs/Kconfig | 11 ++- sound/soc/codecs/Makefile | 4 ++ sound/soc/codecs/ssm2602-i2c.c | 57 +++++++++++++++ sound/soc/codecs/ssm2602-spi.c | 41 +++++++++++ sound/soc/codecs/ssm2602.c | 158 ++++++----------------------------------- sound/soc/codecs/ssm2602.h | 14 ++++
There also seem to be a bunch of arch/blackfin references to do this - they should stay OK due to the select but it might be worth updating them.
I'll apply this with the commit log edited.