aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2014-02-17 07:16:56 -0500
committerMark Brown <broonie@linaro.org>2014-02-17 20:30:25 -0500
commit0c2d6964562835501280409cac5d4ee28e07e8c2 (patch)
treed00f9a8e13c5211f6759ac59642f8928b5c4a67d /sound
parentf96a5d3f1c09ce85ac1a90d733ca3585b9f2f70a (diff)
ASoC: adav80x: 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 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>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/blackfin/Kconfig3
-rw-r--r--sound/soc/codecs/Kconfig11
-rw-r--r--sound/soc/codecs/Makefile4
-rw-r--r--sound/soc/codecs/adav801.c53
-rw-r--r--sound/soc/codecs/adav803.c50
-rw-r--r--sound/soc/codecs/adav80x.c117
-rw-r--r--sound/soc/codecs/adav80x.h7
7 files changed, 133 insertions, 112 deletions
diff --git a/sound/soc/blackfin/Kconfig b/sound/soc/blackfin/Kconfig
index 54f74f8cbb75..18abd884d84f 100644
--- a/sound/soc/blackfin/Kconfig
+++ b/sound/soc/blackfin/Kconfig
@@ -47,7 +47,8 @@ config SND_SOC_BFIN_EVAL_ADAV80X
47 tristate "Support for the EVAL-ADAV80X boards on Blackfin eval boards" 47 tristate "Support for the EVAL-ADAV80X boards on Blackfin eval boards"
48 depends on SND_BF5XX_I2S && (SPI_MASTER || I2C) 48 depends on SND_BF5XX_I2S && (SPI_MASTER || I2C)
49 select SND_BF5XX_SOC_I2S 49 select SND_BF5XX_SOC_I2S
50 select SND_SOC_ADAV80X 50 select SND_SOC_ADAV801 if SPI_MASTER
51 select SND_SOC_ADAV803 if I2C
51 help 52 help
52 Say Y if you want to add support for the Analog Devices EVAL-ADAV801 or 53 Say Y if you want to add support for the Analog Devices EVAL-ADAV801 or
53 EVAL-ADAV803 board connected to one of the Blackfin evaluation boards 54 EVAL-ADAV803 board connected to one of the Blackfin evaluation boards
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 983d087aa92a..9556321c7b8b 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -20,7 +20,8 @@ config SND_SOC_ALL_CODECS
20 select SND_SOC_AD1980 if SND_SOC_AC97_BUS 20 select SND_SOC_AD1980 if SND_SOC_AC97_BUS
21 select SND_SOC_AD73311 21 select SND_SOC_AD73311
22 select SND_SOC_ADAU1373 if I2C 22 select SND_SOC_ADAU1373 if I2C
23 select SND_SOC_ADAV80X if SND_SOC_I2C_AND_SPI 23 select SND_SOC_ADAV801 if SPI_MASTER
24 select SND_SOC_ADAV803 if I2C
24 select SND_SOC_ADAU1701 if I2C 25 select SND_SOC_ADAU1701 if I2C
25 select SND_SOC_ADS117X 26 select SND_SOC_ADS117X
26 select SND_SOC_AK4104 if SPI_MASTER 27 select SND_SOC_AK4104 if SPI_MASTER
@@ -198,6 +199,14 @@ config SND_SOC_ADAU1373
198config SND_SOC_ADAV80X 199config SND_SOC_ADAV80X
199 tristate 200 tristate
200 201
202config SND_SOC_ADAV801
203 tristate
204 select SND_SOC_ADAV80X
205
206config SND_SOC_ADAV803
207 tristate
208 select SND_SOC_ADAV80X
209
201config SND_SOC_ADS117X 210config SND_SOC_ADS117X
202 tristate 211 tristate
203 212
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index bc126764a44d..1b2c6eca863f 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -8,6 +8,8 @@ snd-soc-ad73311-objs := ad73311.o
8snd-soc-adau1701-objs := adau1701.o 8snd-soc-adau1701-objs := adau1701.o
9snd-soc-adau1373-objs := adau1373.o 9snd-soc-adau1373-objs := adau1373.o
10snd-soc-adav80x-objs := adav80x.o 10snd-soc-adav80x-objs := adav80x.o
11snd-soc-adav801-objs := adav801.o
12snd-soc-adav803-objs := adav803.o
11snd-soc-ads117x-objs := ads117x.o 13snd-soc-ads117x-objs := ads117x.o
12snd-soc-ak4104-objs := ak4104.o 14snd-soc-ak4104-objs := ak4104.o
13snd-soc-ak4535-objs := ak4535.o 15snd-soc-ak4535-objs := ak4535.o
@@ -139,6 +141,8 @@ obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o
139obj-$(CONFIG_SND_SOC_ADAU1373) += snd-soc-adau1373.o 141obj-$(CONFIG_SND_SOC_ADAU1373) += snd-soc-adau1373.o
140obj-$(CONFIG_SND_SOC_ADAU1701) += snd-soc-adau1701.o 142obj-$(CONFIG_SND_SOC_ADAU1701) += snd-soc-adau1701.o
141obj-$(CONFIG_SND_SOC_ADAV80X) += snd-soc-adav80x.o 143obj-$(CONFIG_SND_SOC_ADAV80X) += snd-soc-adav80x.o
144obj-$(CONFIG_SND_SOC_ADAV801) += snd-soc-adav801.o
145obj-$(CONFIG_SND_SOC_ADAV803) += snd-soc-adav803.o
142obj-$(CONFIG_SND_SOC_ADS117X) += snd-soc-ads117x.o 146obj-$(CONFIG_SND_SOC_ADS117X) += snd-soc-ads117x.o
143obj-$(CONFIG_SND_SOC_AK4104) += snd-soc-ak4104.o 147obj-$(CONFIG_SND_SOC_AK4104) += snd-soc-ak4104.o
144obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o 148obj-$(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
index 000000000000..790fce33ab10
--- /dev/null
+++ b/sound/soc/codecs/adav801.c
@@ -0,0 +1,53 @@
1/*
2 * ADAV801 audio driver
3 *
4 * Copyright 2014 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2.
7 */
8
9#include <linux/module.h>
10#include <linux/spi/spi.h>
11#include <linux/regmap.h>
12
13#include <sound/soc.h>
14
15#include "adav80x.h"
16
17static const struct spi_device_id adav80x_spi_id[] = {
18 { "adav801", 0 },
19 { }
20};
21MODULE_DEVICE_TABLE(spi, adav80x_spi_id);
22
23static int adav80x_spi_probe(struct spi_device *spi)
24{
25 struct regmap_config config;
26
27 config = adav80x_regmap_config;
28 config.read_flag_mask = 0x01;
29
30 return adav80x_bus_probe(&spi->dev, devm_regmap_init_spi(spi, &config));
31}
32
33static int adav80x_spi_remove(struct spi_device *spi)
34{
35 snd_soc_unregister_codec(&spi->dev);
36 return 0;
37}
38
39static struct spi_driver adav80x_spi_driver = {
40 .driver = {
41 .name = "adav801",
42 .owner = THIS_MODULE,
43 },
44 .probe = adav80x_spi_probe,
45 .remove = adav80x_spi_remove,
46 .id_table = adav80x_spi_id,
47};
48module_spi_driver(adav80x_spi_driver);
49
50MODULE_DESCRIPTION("ASoC ADAV801 driver");
51MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
52MODULE_AUTHOR("Yi Li <yi.li@analog.com>>");
53MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/adav803.c b/sound/soc/codecs/adav803.c
new file mode 100644
index 000000000000..66d9fce34e62
--- /dev/null
+++ b/sound/soc/codecs/adav803.c
@@ -0,0 +1,50 @@
1/*
2 * ADAV803 audio driver
3 *
4 * Copyright 2014 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2.
7 */
8
9#include <linux/module.h>
10#include <linux/i2c.h>
11#include <linux/regmap.h>
12
13#include <sound/soc.h>
14
15#include "adav80x.h"
16
17static const struct i2c_device_id adav803_id[] = {
18 { "adav803", 0 },
19 { }
20};
21MODULE_DEVICE_TABLE(i2c, adav803_id);
22
23static int adav803_probe(struct i2c_client *client,
24 const struct i2c_device_id *id)
25{
26 return adav80x_bus_probe(&client->dev,
27 devm_regmap_init_i2c(client, &adav80x_regmap_config));
28}
29
30static int adav803_remove(struct i2c_client *client)
31{
32 snd_soc_unregister_codec(&client->dev);
33 return 0;
34}
35
36static struct i2c_driver adav803_driver = {
37 .driver = {
38 .name = "adav803",
39 .owner = THIS_MODULE,
40 },
41 .probe = adav803_probe,
42 .remove = adav803_remove,
43 .id_table = adav803_id,
44};
45module_i2c_driver(adav803_driver);
46
47MODULE_DESCRIPTION("ASoC ADAV803 driver");
48MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
49MODULE_AUTHOR("Yi Li <yi.li@analog.com>>");
50MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/adav80x.c b/sound/soc/codecs/adav80x.c
index a4bd051c5430..09d560962e8d 100644
--- a/sound/soc/codecs/adav80x.c
+++ b/sound/soc/codecs/adav80x.c
@@ -8,17 +8,15 @@
8 * Licensed under the GPL-2 or later. 8 * Licensed under the GPL-2 or later.
9 */ 9 */
10 10
11#include <linux/init.h>
12#include <linux/module.h> 11#include <linux/module.h>
13#include <linux/kernel.h> 12#include <linux/kernel.h>
14#include <linux/i2c.h> 13#include <linux/regmap.h>
15#include <linux/spi/spi.h>
16#include <linux/slab.h> 14#include <linux/slab.h>
17#include <sound/core.h> 15
18#include <sound/pcm.h> 16#include <sound/pcm.h>
19#include <sound/pcm_params.h> 17#include <sound/pcm_params.h>
20#include <sound/tlv.h>
21#include <sound/soc.h> 18#include <sound/soc.h>
19#include <sound/tlv.h>
22 20
23#include "adav80x.h" 21#include "adav80x.h"
24 22
@@ -864,10 +862,9 @@ static struct snd_soc_codec_driver adav80x_codec_driver = {
864 .num_dapm_routes = ARRAY_SIZE(adav80x_dapm_routes), 862 .num_dapm_routes = ARRAY_SIZE(adav80x_dapm_routes),
865}; 863};
866 864
867static int adav80x_bus_probe(struct device *dev, struct regmap *regmap) 865int adav80x_bus_probe(struct device *dev, struct regmap *regmap)
868{ 866{
869 struct adav80x *adav80x; 867 struct adav80x *adav80x;
870 int ret;
871 868
872 if (IS_ERR(regmap)) 869 if (IS_ERR(regmap))
873 return PTR_ERR(regmap); 870 return PTR_ERR(regmap);
@@ -882,9 +879,9 @@ static int adav80x_bus_probe(struct device *dev, struct regmap *regmap)
882 return snd_soc_register_codec(dev, &adav80x_codec_driver, 879 return snd_soc_register_codec(dev, &adav80x_codec_driver,
883 adav80x_dais, ARRAY_SIZE(adav80x_dais)); 880 adav80x_dais, ARRAY_SIZE(adav80x_dais));
884} 881}
882EXPORT_SYMBOL_GPL(adav80x_bus_probe);
885 883
886#if defined(CONFIG_SPI_MASTER) 884const struct regmap_config adav80x_regmap_config = {
887static const struct regmap_config adav80x_spi_regmap_config = {
888 .val_bits = 8, 885 .val_bits = 8,
889 .pad_bits = 1, 886 .pad_bits = 1,
890 .reg_bits = 7, 887 .reg_bits = 7,
@@ -896,107 +893,7 @@ static const struct regmap_config adav80x_spi_regmap_config = {
896 .reg_defaults = adav80x_reg_defaults, 893 .reg_defaults = adav80x_reg_defaults,
897 .num_reg_defaults = ARRAY_SIZE(adav80x_reg_defaults), 894 .num_reg_defaults = ARRAY_SIZE(adav80x_reg_defaults),
898}; 895};
899 896EXPORT_SYMBOL_GPL(adav80x_regmap_config);
900static const struct spi_device_id adav80x_spi_id[] = {
901 { "adav801", 0 },
902 { }
903};
904MODULE_DEVICE_TABLE(spi, adav80x_spi_id);
905
906static int adav80x_spi_probe(struct spi_device *spi)
907{
908 return adav80x_bus_probe(&spi->dev,
909 devm_regmap_init_spi(spi, &adav80x_spi_regmap_config));
910}
911
912static int adav80x_spi_remove(struct spi_device *spi)
913{
914 snd_soc_unregister_codec(dev);
915 return 0;
916}
917
918static struct spi_driver adav80x_spi_driver = {
919 .driver = {
920 .name = "adav801",
921 .owner = THIS_MODULE,
922 },
923 .probe = adav80x_spi_probe,
924 .remove = adav80x_spi_remove,
925 .id_table = adav80x_spi_id,
926};
927#endif
928
929#if IS_ENABLED(CONFIG_I2C)
930static const struct regmap_config adav80x_i2c_regmap_config = {
931 .val_bits = 8,
932 .pad_bits = 1,
933 .reg_bits = 7,
934
935 .max_register = ADAV80X_PLL_OUTE,
936
937 .cache_type = REGCACHE_RBTREE,
938 .reg_defaults = adav80x_reg_defaults,
939 .num_reg_defaults = ARRAY_SIZE(adav80x_reg_defaults),
940};
941
942static const struct i2c_device_id adav80x_i2c_id[] = {
943 { "adav803", 0 },
944 { }
945};
946MODULE_DEVICE_TABLE(i2c, adav80x_i2c_id);
947
948static int adav80x_i2c_probe(struct i2c_client *client,
949 const struct i2c_device_id *id)
950{
951 return adav80x_bus_probe(&client->dev,
952 devm_regmap_init_i2c(client, &adav80x_i2c_regmap_config));
953}
954
955static int adav80x_i2c_remove(struct i2c_client *client)
956{
957 snd_soc_unregister_codec(dev);
958 return 0;
959}
960
961static struct i2c_driver adav80x_i2c_driver = {
962 .driver = {
963 .name = "adav803",
964 .owner = THIS_MODULE,
965 },
966 .probe = adav80x_i2c_probe,
967 .remove = adav80x_i2c_remove,
968 .id_table = adav80x_i2c_id,
969};
970#endif
971
972static int __init adav80x_init(void)
973{
974 int ret = 0;
975
976#if IS_ENABLED(CONFIG_I2C)
977 ret = i2c_add_driver(&adav80x_i2c_driver);
978 if (ret)
979 return ret;
980#endif
981
982#if defined(CONFIG_SPI_MASTER)
983 ret = spi_register_driver(&adav80x_spi_driver);
984#endif
985
986 return ret;
987}
988module_init(adav80x_init);
989
990static void __exit adav80x_exit(void)
991{
992#if IS_ENABLED(CONFIG_I2C)
993 i2c_del_driver(&adav80x_i2c_driver);
994#endif
995#if defined(CONFIG_SPI_MASTER)
996 spi_unregister_driver(&adav80x_spi_driver);
997#endif
998}
999module_exit(adav80x_exit);
1000 897
1001MODULE_DESCRIPTION("ASoC ADAV80x driver"); 898MODULE_DESCRIPTION("ASoC ADAV80x driver");
1002MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); 899MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
diff --git a/sound/soc/codecs/adav80x.h b/sound/soc/codecs/adav80x.h
index adb0fc76d4e3..8a1d7c09dca5 100644
--- a/sound/soc/codecs/adav80x.h
+++ b/sound/soc/codecs/adav80x.h
@@ -9,6 +9,13 @@
9#ifndef _ADAV80X_H 9#ifndef _ADAV80X_H
10#define _ADAV80X_H 10#define _ADAV80X_H
11 11
12#include <linux/regmap.h>
13
14struct device;
15
16extern const struct regmap_config adav80x_regmap_config;
17int adav80x_bus_probe(struct device *dev, struct regmap *regmap);
18
12enum adav80x_pll_src { 19enum adav80x_pll_src {
13 ADAV80X_PLL_SRC_XIN, 20 ADAV80X_PLL_SRC_XIN,
14 ADAV80X_PLL_SRC_XTAL, 21 ADAV80X_PLL_SRC_XTAL,