ASoC: adav80x: Split SPI and I2C code into different modules
authorLars-Peter Clausen <lars@metafoo.de>
Mon, 17 Feb 2014 12:16:56 +0000 (13:16 +0100)
committerMark Brown <broonie@linaro.org>
Tue, 18 Feb 2014 01:30:25 +0000 (10:30 +0900)
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 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.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
sound/soc/blackfin/Kconfig
sound/soc/codecs/Kconfig
sound/soc/codecs/Makefile
sound/soc/codecs/adav801.c [new file with mode: 0644]
sound/soc/codecs/adav803.c [new file with mode: 0644]
sound/soc/codecs/adav80x.c
sound/soc/codecs/adav80x.h

index 54f74f8cbb754a0e66aecc3953fff0c8ba63966c..18abd884d84fd7dd916d9708100a8f02a0370c4e 100644 (file)
@@ -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 && (SPI_MASTER || I2C)
        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
index 983d087aa92aa83125903dc18cd420f57c2009eb..9556321c7b8b6d192a1a3ce2e3ae7dcae322952e 100644 (file)
@@ -20,7 +20,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
@@ -198,6 +199,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
 
index bc126764a44d02cb38b50f3ae74900a9ce490da2..1b2c6eca863fccafba68a1de76046831d5ac231d 100644 (file)
@@ -8,6 +8,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
@@ -139,6 +141,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
diff --git a/sound/soc/codecs/adav801.c b/sound/soc/codecs/adav801.c
new file mode 100644 (file)
index 0000000..790fce3
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * ADAV801 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 "adav80x.h"
+
+static const struct spi_device_id adav80x_spi_id[] = {
+       { "adav801", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(spi, adav80x_spi_id);
+
+static int adav80x_spi_probe(struct spi_device *spi)
+{
+       struct regmap_config config;
+
+       config = adav80x_regmap_config;
+       config.read_flag_mask = 0x01;
+
+       return adav80x_bus_probe(&spi->dev, devm_regmap_init_spi(spi, &config));
+}
+
+static int adav80x_spi_remove(struct spi_device *spi)
+{
+       snd_soc_unregister_codec(&spi->dev);
+       return 0;
+}
+
+static struct spi_driver adav80x_spi_driver = {
+       .driver = {
+               .name   = "adav801",
+               .owner  = THIS_MODULE,
+       },
+       .probe          = adav80x_spi_probe,
+       .remove         = adav80x_spi_remove,
+       .id_table       = adav80x_spi_id,
+};
+module_spi_driver(adav80x_spi_driver);
+
+MODULE_DESCRIPTION("ASoC ADAV801 driver");
+MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
+MODULE_AUTHOR("Yi Li <yi.li@analog.com>>");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/adav803.c b/sound/soc/codecs/adav803.c
new file mode 100644 (file)
index 0000000..66d9fce
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * ADAV803 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 "adav80x.h"
+
+static const struct i2c_device_id adav803_id[] = {
+       { "adav803", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, adav803_id);
+
+static int adav803_probe(struct i2c_client *client,
+                            const struct i2c_device_id *id)
+{
+       return adav80x_bus_probe(&client->dev,
+               devm_regmap_init_i2c(client, &adav80x_regmap_config));
+}
+
+static int adav803_remove(struct i2c_client *client)
+{
+       snd_soc_unregister_codec(&client->dev);
+       return 0;
+}
+
+static struct i2c_driver adav803_driver = {
+       .driver = {
+               .name = "adav803",
+               .owner = THIS_MODULE,
+       },
+       .probe = adav803_probe,
+       .remove = adav803_remove,
+       .id_table = adav803_id,
+};
+module_i2c_driver(adav803_driver);
+
+MODULE_DESCRIPTION("ASoC ADAV803 driver");
+MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
+MODULE_AUTHOR("Yi Li <yi.li@analog.com>>");
+MODULE_LICENSE("GPL");
index a4bd051c543075161b4cf0587d488052d8b278a5..09d560962e8d0c8ff6c5a9d50a3e9362534d107e 100644 (file)
@@ -8,17 +8,15 @@
  * Licensed under the GPL-2 or later.
  */
 
-#include <linux/init.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/i2c.h>
-#include <linux/spi/spi.h>
+#include <linux/regmap.h>
 #include <linux/slab.h>
-#include <sound/core.h>
+
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
-#include <sound/tlv.h>
 #include <sound/soc.h>
+#include <sound/tlv.h>
 
 #include "adav80x.h"
 
@@ -864,10 +862,9 @@ static struct snd_soc_codec_driver adav80x_codec_driver = {
        .num_dapm_routes = ARRAY_SIZE(adav80x_dapm_routes),
 };
 
-static int adav80x_bus_probe(struct device *dev, struct regmap *regmap)
+int adav80x_bus_probe(struct device *dev, struct regmap *regmap)
 {
        struct adav80x *adav80x;
-       int ret;
 
        if (IS_ERR(regmap))
                return PTR_ERR(regmap);
@@ -882,9 +879,9 @@ static int adav80x_bus_probe(struct device *dev, struct regmap *regmap)
        return snd_soc_register_codec(dev, &adav80x_codec_driver,
                adav80x_dais, ARRAY_SIZE(adav80x_dais));
 }
+EXPORT_SYMBOL_GPL(adav80x_bus_probe);
 
-#if defined(CONFIG_SPI_MASTER)
-static const struct regmap_config adav80x_spi_regmap_config = {
+const struct regmap_config adav80x_regmap_config = {
        .val_bits = 8,
        .pad_bits = 1,
        .reg_bits = 7,
@@ -896,107 +893,7 @@ static const struct regmap_config adav80x_spi_regmap_config = {
        .reg_defaults = adav80x_reg_defaults,
        .num_reg_defaults = ARRAY_SIZE(adav80x_reg_defaults),
 };
-
-static const struct spi_device_id adav80x_spi_id[] = {
-       { "adav801", 0 },
-       { }
-};
-MODULE_DEVICE_TABLE(spi, adav80x_spi_id);
-
-static int adav80x_spi_probe(struct spi_device *spi)
-{
-       return adav80x_bus_probe(&spi->dev,
-               devm_regmap_init_spi(spi, &adav80x_spi_regmap_config));
-}
-
-static int adav80x_spi_remove(struct spi_device *spi)
-{
-       snd_soc_unregister_codec(dev);
-       return 0;
-}
-
-static struct spi_driver adav80x_spi_driver = {
-       .driver = {
-               .name   = "adav801",
-               .owner  = THIS_MODULE,
-       },
-       .probe          = adav80x_spi_probe,
-       .remove         = adav80x_spi_remove,
-       .id_table       = adav80x_spi_id,
-};
-#endif
-
-#if IS_ENABLED(CONFIG_I2C)
-static const struct regmap_config adav80x_i2c_regmap_config = {
-       .val_bits = 8,
-       .pad_bits = 1,
-       .reg_bits = 7,
-
-       .max_register = ADAV80X_PLL_OUTE,
-
-       .cache_type = REGCACHE_RBTREE,
-       .reg_defaults = adav80x_reg_defaults,
-       .num_reg_defaults = ARRAY_SIZE(adav80x_reg_defaults),
-};
-
-static const struct i2c_device_id adav80x_i2c_id[] = {
-       { "adav803", 0 },
-       { }
-};
-MODULE_DEVICE_TABLE(i2c, adav80x_i2c_id);
-
-static int adav80x_i2c_probe(struct i2c_client *client,
-                            const struct i2c_device_id *id)
-{
-       return adav80x_bus_probe(&client->dev,
-               devm_regmap_init_i2c(client, &adav80x_i2c_regmap_config));
-}
-
-static int adav80x_i2c_remove(struct i2c_client *client)
-{
-       snd_soc_unregister_codec(dev);
-       return 0;
-}
-
-static struct i2c_driver adav80x_i2c_driver = {
-       .driver = {
-               .name = "adav803",
-               .owner = THIS_MODULE,
-       },
-       .probe = adav80x_i2c_probe,
-       .remove = adav80x_i2c_remove,
-       .id_table = adav80x_i2c_id,
-};
-#endif
-
-static int __init adav80x_init(void)
-{
-       int ret = 0;
-
-#if IS_ENABLED(CONFIG_I2C)
-       ret = i2c_add_driver(&adav80x_i2c_driver);
-       if (ret)
-               return ret;
-#endif
-
-#if defined(CONFIG_SPI_MASTER)
-       ret = spi_register_driver(&adav80x_spi_driver);
-#endif
-
-       return ret;
-}
-module_init(adav80x_init);
-
-static void __exit adav80x_exit(void)
-{
-#if IS_ENABLED(CONFIG_I2C)
-       i2c_del_driver(&adav80x_i2c_driver);
-#endif
-#if defined(CONFIG_SPI_MASTER)
-       spi_unregister_driver(&adav80x_spi_driver);
-#endif
-}
-module_exit(adav80x_exit);
+EXPORT_SYMBOL_GPL(adav80x_regmap_config);
 
 MODULE_DESCRIPTION("ASoC ADAV80x driver");
 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
index adb0fc76d4e3337797d95bcddd14d39251679c9e..8a1d7c09dca537de63720233207f5744fbe3793e 100644 (file)
@@ -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,
This page took 0.032742 seconds and 5 git commands to generate.