Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Lars-Peter Clausen and committed by
Mark Brown
0c2d6964 f96a5d3f

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