diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2014-02-17 07:16:56 -0500 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-02-17 20:30:25 -0500 |
commit | 0c2d6964562835501280409cac5d4ee28e07e8c2 (patch) | |
tree | d00f9a8e13c5211f6759ac59642f8928b5c4a67d /sound/soc/codecs/adav80x.c | |
parent | f96a5d3f1c09ce85ac1a90d733ca3585b9f2f70a (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/soc/codecs/adav80x.c')
-rw-r--r-- | sound/soc/codecs/adav80x.c | 117 |
1 files changed, 7 insertions, 110 deletions
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 | ||
867 | static int adav80x_bus_probe(struct device *dev, struct regmap *regmap) | 865 | int 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 | } |
882 | EXPORT_SYMBOL_GPL(adav80x_bus_probe); | ||
885 | 883 | ||
886 | #if defined(CONFIG_SPI_MASTER) | 884 | const struct regmap_config adav80x_regmap_config = { |
887 | static 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 | 896 | EXPORT_SYMBOL_GPL(adav80x_regmap_config); | |
900 | static const struct spi_device_id adav80x_spi_id[] = { | ||
901 | { "adav801", 0 }, | ||
902 | { } | ||
903 | }; | ||
904 | MODULE_DEVICE_TABLE(spi, adav80x_spi_id); | ||
905 | |||
906 | static 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 | |||
912 | static int adav80x_spi_remove(struct spi_device *spi) | ||
913 | { | ||
914 | snd_soc_unregister_codec(dev); | ||
915 | return 0; | ||
916 | } | ||
917 | |||
918 | static 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) | ||
930 | static 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 | |||
942 | static const struct i2c_device_id adav80x_i2c_id[] = { | ||
943 | { "adav803", 0 }, | ||
944 | { } | ||
945 | }; | ||
946 | MODULE_DEVICE_TABLE(i2c, adav80x_i2c_id); | ||
947 | |||
948 | static 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 | |||
955 | static int adav80x_i2c_remove(struct i2c_client *client) | ||
956 | { | ||
957 | snd_soc_unregister_codec(dev); | ||
958 | return 0; | ||
959 | } | ||
960 | |||
961 | static 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 | |||
972 | static 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 | } | ||
988 | module_init(adav80x_init); | ||
989 | |||
990 | static 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 | } | ||
999 | module_exit(adav80x_exit); | ||
1000 | 897 | ||
1001 | MODULE_DESCRIPTION("ASoC ADAV80x driver"); | 898 | MODULE_DESCRIPTION("ASoC ADAV80x driver"); |
1002 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); | 899 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); |