diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-09-10 21:25:41 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-09-10 23:26:05 -0400 |
commit | 499926246ec77d64b028a953f7a79e941e36b802 (patch) | |
tree | 0f9b9cc0e3f210635be3d74cf8e900331bdf2c15 /sound | |
parent | 6a58870df89b1941dc9a47e5ccb3c91bffad5b03 (diff) |
ASoC: wm8900: Convert to direct regmap API usage
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/soc/codecs/wm8900.c | 148 |
1 files changed, 90 insertions, 58 deletions
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c index 5f7a78ea518c..5bc877b916eb 100644 --- a/sound/soc/codecs/wm8900.c +++ b/sound/soc/codecs/wm8900.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/delay.h> | 23 | #include <linux/delay.h> |
24 | #include <linux/pm.h> | 24 | #include <linux/pm.h> |
25 | #include <linux/i2c.h> | 25 | #include <linux/i2c.h> |
26 | #include <linux/regmap.h> | ||
26 | #include <linux/spi/spi.h> | 27 | #include <linux/spi/spi.h> |
27 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
28 | #include <sound/core.h> | 29 | #include <sound/core.h> |
@@ -137,7 +138,7 @@ | |||
137 | #define WM8900_LRC_MASK 0x03ff | 138 | #define WM8900_LRC_MASK 0x03ff |
138 | 139 | ||
139 | struct wm8900_priv { | 140 | struct wm8900_priv { |
140 | enum snd_soc_control_type control_type; | 141 | struct regmap *regmap; |
141 | 142 | ||
142 | u32 fll_in; /* FLL input frequency */ | 143 | u32 fll_in; /* FLL input frequency */ |
143 | u32 fll_out; /* FLL output frequency */ | 144 | u32 fll_out; /* FLL output frequency */ |
@@ -147,54 +148,77 @@ struct wm8900_priv { | |||
147 | * wm8900 register cache. We can't read the entire register space and we | 148 | * wm8900 register cache. We can't read the entire register space and we |
148 | * have slow control buses so we cache the registers. | 149 | * have slow control buses so we cache the registers. |
149 | */ | 150 | */ |
150 | static const u16 wm8900_reg_defaults[WM8900_MAXREG] = { | 151 | static const struct reg_default wm8900_reg_defaults[] = { |
151 | 0x8900, 0x0000, | 152 | { 1, 0x0000 }, |
152 | 0xc000, 0x0000, | 153 | { 2, 0xc000 }, |
153 | 0x4050, 0x4000, | 154 | { 3, 0x0000 }, |
154 | 0x0008, 0x0000, | 155 | { 4, 0x4050 }, |
155 | 0x0040, 0x0040, | 156 | { 5, 0x4000 }, |
156 | 0x1004, 0x00c0, | 157 | { 6, 0x0008 }, |
157 | 0x00c0, 0x0000, | 158 | { 7, 0x0000 }, |
158 | 0x0100, 0x00c0, | 159 | { 8, 0x0040 }, |
159 | 0x00c0, 0x0000, | 160 | { 9, 0x0040 }, |
160 | 0xb001, 0x0000, | 161 | { 10, 0x1004 }, |
161 | 0x0000, 0x0044, | 162 | { 11, 0x00c0 }, |
162 | 0x004c, 0x004c, | 163 | { 12, 0x00c0 }, |
163 | 0x0044, 0x0044, | 164 | { 13, 0x0000 }, |
164 | 0x0000, 0x0044, | 165 | { 14, 0x0100 }, |
165 | 0x0000, 0x0000, | 166 | { 15, 0x00c0 }, |
166 | 0x0002, 0x0000, | 167 | { 16, 0x00c0 }, |
167 | 0x0000, 0x0000, | 168 | { 17, 0x0000 }, |
168 | 0x0000, 0x0000, | 169 | { 18, 0xb001 }, |
169 | 0x0008, 0x0000, | 170 | { 19, 0x0000 }, |
170 | 0x0000, 0x0008, | 171 | { 20, 0x0000 }, |
171 | 0x0097, 0x0100, | 172 | { 21, 0x0044 }, |
172 | 0x0000, 0x0000, | 173 | { 22, 0x004c }, |
173 | 0x0050, 0x0050, | 174 | { 23, 0x004c }, |
174 | 0x0055, 0x0055, | 175 | { 24, 0x0044 }, |
175 | 0x0055, 0x0000, | 176 | { 25, 0x0044 }, |
176 | 0x0000, 0x0079, | 177 | { 26, 0x0000 }, |
177 | 0x0079, 0x0079, | 178 | { 27, 0x0044 }, |
178 | 0x0079, 0x0000, | 179 | { 28, 0x0000 }, |
179 | /* Remaining registers all zero */ | 180 | { 29, 0x0000 }, |
181 | { 30, 0x0002 }, | ||
182 | { 31, 0x0000 }, | ||
183 | { 32, 0x0000 }, | ||
184 | { 33, 0x0000 }, | ||
185 | { 34, 0x0000 }, | ||
186 | { 35, 0x0000 }, | ||
187 | { 36, 0x0008 }, | ||
188 | { 37, 0x0000 }, | ||
189 | { 38, 0x0000 }, | ||
190 | { 39, 0x0008 }, | ||
191 | { 40, 0x0097 }, | ||
192 | { 41, 0x0100 }, | ||
193 | { 42, 0x0000 }, | ||
194 | { 43, 0x0000 }, | ||
195 | { 44, 0x0050 }, | ||
196 | { 45, 0x0050 }, | ||
197 | { 46, 0x0055 }, | ||
198 | { 47, 0x0055 }, | ||
199 | { 48, 0x0055 }, | ||
200 | { 49, 0x0000 }, | ||
201 | { 50, 0x0000 }, | ||
202 | { 51, 0x0079 }, | ||
203 | { 52, 0x0079 }, | ||
204 | { 53, 0x0079 }, | ||
205 | { 54, 0x0079 }, | ||
206 | { 55, 0x0000 }, | ||
180 | }; | 207 | }; |
181 | 208 | ||
182 | static int wm8900_volatile_register(struct snd_soc_codec *codec, unsigned int reg) | 209 | static bool wm8900_volatile_register(struct device *dev, unsigned int reg) |
183 | { | 210 | { |
184 | switch (reg) { | 211 | switch (reg) { |
185 | case WM8900_REG_ID: | 212 | case WM8900_REG_ID: |
186 | return 1; | 213 | return true; |
187 | default: | 214 | default: |
188 | return 0; | 215 | return false; |
189 | } | 216 | } |
190 | } | 217 | } |
191 | 218 | ||
192 | static void wm8900_reset(struct snd_soc_codec *codec) | 219 | static void wm8900_reset(struct snd_soc_codec *codec) |
193 | { | 220 | { |
194 | snd_soc_write(codec, WM8900_REG_RESET, 0); | 221 | snd_soc_write(codec, WM8900_REG_RESET, 0); |
195 | |||
196 | memcpy(codec->reg_cache, wm8900_reg_defaults, | ||
197 | sizeof(wm8900_reg_defaults)); | ||
198 | } | 222 | } |
199 | 223 | ||
200 | static int wm8900_hp_event(struct snd_soc_dapm_widget *w, | 224 | static int wm8900_hp_event(struct snd_soc_dapm_widget *w, |
@@ -1119,13 +1143,16 @@ static int wm8900_suspend(struct snd_soc_codec *codec) | |||
1119 | static int wm8900_resume(struct snd_soc_codec *codec) | 1143 | static int wm8900_resume(struct snd_soc_codec *codec) |
1120 | { | 1144 | { |
1121 | struct wm8900_priv *wm8900 = snd_soc_codec_get_drvdata(codec); | 1145 | struct wm8900_priv *wm8900 = snd_soc_codec_get_drvdata(codec); |
1122 | u16 *cache; | 1146 | int ret; |
1123 | int i, ret; | ||
1124 | |||
1125 | cache = kmemdup(codec->reg_cache, sizeof(wm8900_reg_defaults), | ||
1126 | GFP_KERNEL); | ||
1127 | 1147 | ||
1128 | wm8900_reset(codec); | 1148 | wm8900_reset(codec); |
1149 | |||
1150 | ret = regcache_sync(wm8900->regmap); | ||
1151 | if (ret != 0) { | ||
1152 | dev_err(codec->dev, "Failed to restore cache: %d\n", ret); | ||
1153 | return ret; | ||
1154 | } | ||
1155 | |||
1129 | wm8900_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 1156 | wm8900_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
1130 | 1157 | ||
1131 | /* Restart the FLL? */ | 1158 | /* Restart the FLL? */ |
@@ -1139,27 +1166,18 @@ static int wm8900_resume(struct snd_soc_codec *codec) | |||
1139 | ret = wm8900_set_fll(codec, 0, fll_in, fll_out); | 1166 | ret = wm8900_set_fll(codec, 0, fll_in, fll_out); |
1140 | if (ret != 0) { | 1167 | if (ret != 0) { |
1141 | dev_err(codec->dev, "Failed to restart FLL\n"); | 1168 | dev_err(codec->dev, "Failed to restart FLL\n"); |
1142 | kfree(cache); | ||
1143 | return ret; | 1169 | return ret; |
1144 | } | 1170 | } |
1145 | } | 1171 | } |
1146 | 1172 | ||
1147 | if (cache) { | ||
1148 | for (i = 0; i < WM8900_MAXREG; i++) | ||
1149 | snd_soc_write(codec, i, cache[i]); | ||
1150 | kfree(cache); | ||
1151 | } else | ||
1152 | dev_err(codec->dev, "Unable to allocate register cache\n"); | ||
1153 | |||
1154 | return 0; | 1173 | return 0; |
1155 | } | 1174 | } |
1156 | 1175 | ||
1157 | static int wm8900_probe(struct snd_soc_codec *codec) | 1176 | static int wm8900_probe(struct snd_soc_codec *codec) |
1158 | { | 1177 | { |
1159 | struct wm8900_priv *wm8900 = snd_soc_codec_get_drvdata(codec); | ||
1160 | int ret = 0, reg; | 1178 | int ret = 0, reg; |
1161 | 1179 | ||
1162 | ret = snd_soc_codec_set_cache_io(codec, 8, 16, wm8900->control_type); | 1180 | ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP); |
1163 | if (ret != 0) { | 1181 | if (ret != 0) { |
1164 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | 1182 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
1165 | return ret; | 1183 | return ret; |
@@ -1207,10 +1225,6 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8900 = { | |||
1207 | .suspend = wm8900_suspend, | 1225 | .suspend = wm8900_suspend, |
1208 | .resume = wm8900_resume, | 1226 | .resume = wm8900_resume, |
1209 | .set_bias_level = wm8900_set_bias_level, | 1227 | .set_bias_level = wm8900_set_bias_level, |
1210 | .volatile_register = wm8900_volatile_register, | ||
1211 | .reg_cache_size = ARRAY_SIZE(wm8900_reg_defaults), | ||
1212 | .reg_word_size = sizeof(u16), | ||
1213 | .reg_cache_default = wm8900_reg_defaults, | ||
1214 | 1228 | ||
1215 | .controls = wm8900_snd_controls, | 1229 | .controls = wm8900_snd_controls, |
1216 | .num_controls = ARRAY_SIZE(wm8900_snd_controls), | 1230 | .num_controls = ARRAY_SIZE(wm8900_snd_controls), |
@@ -1220,6 +1234,18 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8900 = { | |||
1220 | .num_dapm_routes = ARRAY_SIZE(wm8900_dapm_routes), | 1234 | .num_dapm_routes = ARRAY_SIZE(wm8900_dapm_routes), |
1221 | }; | 1235 | }; |
1222 | 1236 | ||
1237 | static const struct regmap_config wm8900_regmap = { | ||
1238 | .reg_bits = 8, | ||
1239 | .val_bits = 16, | ||
1240 | .max_register = WM8900_MAXREG, | ||
1241 | |||
1242 | .reg_defaults = wm8900_reg_defaults, | ||
1243 | .num_reg_defaults = ARRAY_SIZE(wm8900_reg_defaults), | ||
1244 | .cache_type = REGCACHE_RBTREE, | ||
1245 | |||
1246 | .volatile_reg = wm8900_volatile_register, | ||
1247 | }; | ||
1248 | |||
1223 | #if defined(CONFIG_SPI_MASTER) | 1249 | #if defined(CONFIG_SPI_MASTER) |
1224 | static int __devinit wm8900_spi_probe(struct spi_device *spi) | 1250 | static int __devinit wm8900_spi_probe(struct spi_device *spi) |
1225 | { | 1251 | { |
@@ -1231,7 +1257,10 @@ static int __devinit wm8900_spi_probe(struct spi_device *spi) | |||
1231 | if (wm8900 == NULL) | 1257 | if (wm8900 == NULL) |
1232 | return -ENOMEM; | 1258 | return -ENOMEM; |
1233 | 1259 | ||
1234 | wm8900->control_type = SND_SOC_SPI; | 1260 | wm8900->regmap = devm_regmap_init_spi(spi, &wm8900_regmap); |
1261 | if (IS_ERR(wm8900->regmap)) | ||
1262 | return PTR_ERR(wm8900->regmap); | ||
1263 | |||
1235 | spi_set_drvdata(spi, wm8900); | 1264 | spi_set_drvdata(spi, wm8900); |
1236 | 1265 | ||
1237 | ret = snd_soc_register_codec(&spi->dev, | 1266 | ret = snd_soc_register_codec(&spi->dev, |
@@ -1268,8 +1297,11 @@ static __devinit int wm8900_i2c_probe(struct i2c_client *i2c, | |||
1268 | if (wm8900 == NULL) | 1297 | if (wm8900 == NULL) |
1269 | return -ENOMEM; | 1298 | return -ENOMEM; |
1270 | 1299 | ||
1300 | wm8900->regmap = devm_regmap_init_i2c(i2c, &wm8900_regmap); | ||
1301 | if (IS_ERR(wm8900->regmap)) | ||
1302 | return PTR_ERR(wm8900->regmap); | ||
1303 | |||
1271 | i2c_set_clientdata(i2c, wm8900); | 1304 | i2c_set_clientdata(i2c, wm8900); |
1272 | wm8900->control_type = SND_SOC_I2C; | ||
1273 | 1305 | ||
1274 | ret = snd_soc_register_codec(&i2c->dev, | 1306 | ret = snd_soc_register_codec(&i2c->dev, |
1275 | &soc_codec_dev_wm8900, &wm8900_dai, 1); | 1307 | &soc_codec_dev_wm8900, &wm8900_dai, 1); |