Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6c3d713e authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Mark Brown
Browse files

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 I2C
      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.

Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent 38dbfb59
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -68,7 +68,8 @@ config SND_BF5XX_SOC_AD193X
	tristate "SoC AD193X Audio support for Blackfin"
	depends on SND_BF5XX_I2S
	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.
+10 −1
Original line number Diff line number Diff line
@@ -16,7 +16,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
@@ -182,6 +183,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

+4 −0
Original line number Diff line number Diff line
@@ -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
@@ -134,6 +136,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
+54 −0
Original line number Diff line number Diff line
/*
 * AD1936/AD1937 audio driver
 *
 * Copyright 2014 Analog Devices Inc.
 *
 * Licensed under the GPL-2.
 */

#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/regmap.h>

#include <sound/soc.h>

#include "ad193x.h"

static const struct i2c_device_id ad193x_id[] = {
	{ "ad1936", 0 },
	{ "ad1937", 0 },
	{ }
};
MODULE_DEVICE_TABLE(i2c, ad193x_id);

static int ad193x_i2c_probe(struct i2c_client *client,
			    const struct i2c_device_id *id)
{
	struct regmap_config config;

	config = ad193x_regmap_config;
	config.val_bits = 8;
	config.reg_bits = 8;

	return ad193x_probe(&client->dev, devm_regmap_init_i2c(client, &config));
}

static int ad193x_i2c_remove(struct i2c_client *client)
{
	snd_soc_unregister_codec(&client->dev);
	return 0;
}

static struct i2c_driver ad193x_i2c_driver = {
	.driver = {
		.name = "ad193x",
	},
	.probe    = ad193x_i2c_probe,
	.remove   = ad193x_i2c_remove,
	.id_table = ad193x_id,
};
module_i2c_driver(ad193x_i2c_driver);

MODULE_DESCRIPTION("ASoC AD1936/AD1937 audio CODEC driver");
MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
MODULE_LICENSE("GPL");
+48 −0
Original line number Diff line number Diff line
/*
 * AD1938/AD1939 audio driver
 *
 * Copyright 2014 Analog Devices Inc.
 *
 * Licensed under the GPL-2.
 */

#include <linux/module.h>
#include <linux/spi/spi.h>
#include <linux/regmap.h>

#include <sound/soc.h>

#include "ad193x.h"

static int ad193x_spi_probe(struct spi_device *spi)
{
	struct regmap_config config;

	config = ad193x_regmap_config;
	config.val_bits = 8;
	config.reg_bits = 16;
	config.read_flag_mask = 0x09;
	config.write_flag_mask = 0x08;

	return ad193x_probe(&spi->dev, devm_regmap_init_spi(spi, &config));
}

static int ad193x_spi_remove(struct spi_device *spi)
{
	snd_soc_unregister_codec(&spi->dev);
	return 0;
}

static struct spi_driver ad193x_spi_driver = {
	.driver = {
		.name	= "ad193x",
		.owner	= THIS_MODULE,
	},
	.probe		= ad193x_spi_probe,
	.remove		= ad193x_spi_remove,
};
module_spi_driver(ad193x_spi_driver);

MODULE_DESCRIPTION("ASoC AD1938/AD1939 audio CODEC driver");
MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
MODULE_LICENSE("GPL");
Loading