diff options
Diffstat (limited to 'sound/soc/soc-io.c')
-rw-r--r-- | sound/soc/soc-io.c | 64 |
1 files changed, 19 insertions, 45 deletions
diff --git a/sound/soc/soc-io.c b/sound/soc/soc-io.c index aa886cca3ecf..8aa086996866 100644 --- a/sound/soc/soc-io.c +++ b/sound/soc/soc-io.c | |||
@@ -69,9 +69,7 @@ static unsigned int hw_read(struct snd_soc_codec *codec, unsigned int reg) | |||
69 | * snd_soc_codec_set_cache_io: Set up standard I/O functions. | 69 | * snd_soc_codec_set_cache_io: Set up standard I/O functions. |
70 | * | 70 | * |
71 | * @codec: CODEC to configure. | 71 | * @codec: CODEC to configure. |
72 | * @addr_bits: Number of bits of register address data. | 72 | * @map: Register map to write to |
73 | * @data_bits: Number of bits of data per register. | ||
74 | * @control: Control bus used. | ||
75 | * | 73 | * |
76 | * Register formats are frequently shared between many I2C and SPI | 74 | * Register formats are frequently shared between many I2C and SPI |
77 | * devices. In order to promote code reuse the ASoC core provides | 75 | * devices. In order to promote code reuse the ASoC core provides |
@@ -85,60 +83,36 @@ static unsigned int hw_read(struct snd_soc_codec *codec, unsigned int reg) | |||
85 | * volatile registers. | 83 | * volatile registers. |
86 | */ | 84 | */ |
87 | int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, | 85 | int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, |
88 | int addr_bits, int data_bits, | 86 | struct regmap *regmap) |
89 | enum snd_soc_control_type control) | ||
90 | { | 87 | { |
91 | struct regmap_config config; | ||
92 | int ret; | 88 | int ret; |
93 | 89 | ||
94 | memset(&config, 0, sizeof(config)); | 90 | /* Device has made its own regmap arrangements */ |
95 | codec->write = hw_write; | 91 | if (!regmap) |
96 | codec->read = hw_read; | 92 | codec->control_data = dev_get_regmap(codec->dev, NULL); |
93 | else | ||
94 | codec->control_data = regmap; | ||
97 | 95 | ||
98 | config.reg_bits = addr_bits; | 96 | if (IS_ERR(codec->control_data)) |
99 | config.val_bits = data_bits; | 97 | return PTR_ERR(codec->control_data); |
100 | 98 | ||
101 | switch (control) { | 99 | codec->write = hw_write; |
102 | #if IS_ENABLED(CONFIG_REGMAP_I2C) | 100 | codec->read = hw_read; |
103 | case SND_SOC_I2C: | ||
104 | codec->control_data = regmap_init_i2c(to_i2c_client(codec->dev), | ||
105 | &config); | ||
106 | break; | ||
107 | #endif | ||
108 | 101 | ||
109 | #if IS_ENABLED(CONFIG_REGMAP_SPI) | 102 | ret = regmap_get_val_bytes(codec->control_data); |
110 | case SND_SOC_SPI: | 103 | /* Errors are legitimate for non-integer byte |
111 | codec->control_data = regmap_init_spi(to_spi_device(codec->dev), | 104 | * multiples */ |
112 | &config); | 105 | if (ret > 0) |
113 | break; | 106 | codec->val_bytes = ret; |
114 | #endif | ||
115 | 107 | ||
116 | case SND_SOC_REGMAP: | 108 | codec->using_regmap = true; |
117 | /* Device has made its own regmap arrangements */ | ||
118 | codec->using_regmap = true; | ||
119 | if (!codec->control_data) | ||
120 | codec->control_data = dev_get_regmap(codec->dev, NULL); | ||
121 | |||
122 | if (codec->control_data) { | ||
123 | ret = regmap_get_val_bytes(codec->control_data); | ||
124 | /* Errors are legitimate for non-integer byte | ||
125 | * multiples */ | ||
126 | if (ret > 0) | ||
127 | codec->val_bytes = ret; | ||
128 | } | ||
129 | break; | ||
130 | |||
131 | default: | ||
132 | return -EINVAL; | ||
133 | } | ||
134 | 109 | ||
135 | return PTR_ERR_OR_ZERO(codec->control_data); | 110 | return 0; |
136 | } | 111 | } |
137 | EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io); | 112 | EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io); |
138 | #else | 113 | #else |
139 | int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, | 114 | int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, |
140 | int addr_bits, int data_bits, | 115 | struct regmap *regmap) |
141 | enum snd_soc_control_type control) | ||
142 | { | 116 | { |
143 | return -ENOTSUPP; | 117 | return -ENOTSUPP; |
144 | } | 118 | } |