diff options
Diffstat (limited to 'sound/soc/codecs/wm8741.c')
-rw-r--r-- | sound/soc/codecs/wm8741.c | 391 |
1 files changed, 187 insertions, 204 deletions
diff --git a/sound/soc/codecs/wm8741.c b/sound/soc/codecs/wm8741.c index b9ea8904ad4b..25af901fe813 100644 --- a/sound/soc/codecs/wm8741.c +++ b/sound/soc/codecs/wm8741.c | |||
@@ -24,31 +24,25 @@ | |||
24 | #include <sound/pcm.h> | 24 | #include <sound/pcm.h> |
25 | #include <sound/pcm_params.h> | 25 | #include <sound/pcm_params.h> |
26 | #include <sound/soc.h> | 26 | #include <sound/soc.h> |
27 | #include <sound/soc-dapm.h> | ||
28 | #include <sound/initval.h> | 27 | #include <sound/initval.h> |
29 | #include <sound/tlv.h> | 28 | #include <sound/tlv.h> |
30 | 29 | ||
31 | #include "wm8741.h" | 30 | #include "wm8741.h" |
32 | 31 | ||
33 | static struct snd_soc_codec *wm8741_codec; | ||
34 | struct snd_soc_codec_device soc_codec_dev_wm8741; | ||
35 | |||
36 | #define WM8741_NUM_SUPPLIES 2 | 32 | #define WM8741_NUM_SUPPLIES 2 |
37 | static const char *wm8741_supply_names[WM8741_NUM_SUPPLIES] = { | 33 | static const char *wm8741_supply_names[WM8741_NUM_SUPPLIES] = { |
38 | "AVDD", | 34 | "AVDD", |
39 | "DVDD", | 35 | "DVDD", |
40 | }; | 36 | }; |
41 | 37 | ||
42 | #define WM8741_NUM_RATES 4 | 38 | #define WM8741_NUM_RATES 6 |
43 | 39 | ||
44 | /* codec private data */ | 40 | /* codec private data */ |
45 | struct wm8741_priv { | 41 | struct wm8741_priv { |
46 | struct snd_soc_codec codec; | 42 | enum snd_soc_control_type control_type; |
47 | u16 reg_cache[WM8741_REGISTER_COUNT]; | ||
48 | struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES]; | 43 | struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES]; |
49 | unsigned int sysclk; | 44 | unsigned int sysclk; |
50 | unsigned int rate_constraint_list[WM8741_NUM_RATES]; | 45 | struct snd_pcm_hw_constraint_list *sysclk_constraints; |
51 | struct snd_pcm_hw_constraint_list rate_constraint; | ||
52 | }; | 46 | }; |
53 | 47 | ||
54 | static const u16 wm8741_reg_defaults[WM8741_REGISTER_COUNT] = { | 48 | static const u16 wm8741_reg_defaults[WM8741_REGISTER_COUNT] = { |
@@ -99,10 +93,11 @@ static const struct snd_soc_dapm_route intercon[] = { | |||
99 | 93 | ||
100 | static int wm8741_add_widgets(struct snd_soc_codec *codec) | 94 | static int wm8741_add_widgets(struct snd_soc_codec *codec) |
101 | { | 95 | { |
102 | snd_soc_dapm_new_controls(codec, wm8741_dapm_widgets, | 96 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
103 | ARRAY_SIZE(wm8741_dapm_widgets)); | ||
104 | 97 | ||
105 | snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); | 98 | snd_soc_dapm_new_controls(dapm, wm8741_dapm_widgets, |
99 | ARRAY_SIZE(wm8741_dapm_widgets)); | ||
100 | snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon)); | ||
106 | 101 | ||
107 | return 0; | 102 | return 0; |
108 | } | 103 | } |
@@ -111,10 +106,84 @@ static struct { | |||
111 | int value; | 106 | int value; |
112 | int ratio; | 107 | int ratio; |
113 | } lrclk_ratios[WM8741_NUM_RATES] = { | 108 | } lrclk_ratios[WM8741_NUM_RATES] = { |
114 | { 1, 256 }, | 109 | { 1, 128 }, |
115 | { 2, 384 }, | 110 | { 2, 192 }, |
116 | { 3, 512 }, | 111 | { 3, 256 }, |
117 | { 4, 768 }, | 112 | { 4, 384 }, |
113 | { 5, 512 }, | ||
114 | { 6, 768 }, | ||
115 | }; | ||
116 | |||
117 | static unsigned int rates_11289[] = { | ||
118 | 44100, 88235, | ||
119 | }; | ||
120 | |||
121 | static struct snd_pcm_hw_constraint_list constraints_11289 = { | ||
122 | .count = ARRAY_SIZE(rates_11289), | ||
123 | .list = rates_11289, | ||
124 | }; | ||
125 | |||
126 | static unsigned int rates_12288[] = { | ||
127 | 32000, 48000, 96000, | ||
128 | }; | ||
129 | |||
130 | static struct snd_pcm_hw_constraint_list constraints_12288 = { | ||
131 | .count = ARRAY_SIZE(rates_12288), | ||
132 | .list = rates_12288, | ||
133 | }; | ||
134 | |||
135 | static unsigned int rates_16384[] = { | ||
136 | 32000, | ||
137 | }; | ||
138 | |||
139 | static struct snd_pcm_hw_constraint_list constraints_16384 = { | ||
140 | .count = ARRAY_SIZE(rates_16384), | ||
141 | .list = rates_16384, | ||
142 | }; | ||
143 | |||
144 | static unsigned int rates_16934[] = { | ||
145 | 44100, 88235, | ||
146 | }; | ||
147 | |||
148 | static struct snd_pcm_hw_constraint_list constraints_16934 = { | ||
149 | .count = ARRAY_SIZE(rates_16934), | ||
150 | .list = rates_16934, | ||
151 | }; | ||
152 | |||
153 | static unsigned int rates_18432[] = { | ||
154 | 48000, 96000, | ||
155 | }; | ||
156 | |||
157 | static struct snd_pcm_hw_constraint_list constraints_18432 = { | ||
158 | .count = ARRAY_SIZE(rates_18432), | ||
159 | .list = rates_18432, | ||
160 | }; | ||
161 | |||
162 | static unsigned int rates_22579[] = { | ||
163 | 44100, 88235, 1764000 | ||
164 | }; | ||
165 | |||
166 | static struct snd_pcm_hw_constraint_list constraints_22579 = { | ||
167 | .count = ARRAY_SIZE(rates_22579), | ||
168 | .list = rates_22579, | ||
169 | }; | ||
170 | |||
171 | static unsigned int rates_24576[] = { | ||
172 | 32000, 48000, 96000, 192000 | ||
173 | }; | ||
174 | |||
175 | static struct snd_pcm_hw_constraint_list constraints_24576 = { | ||
176 | .count = ARRAY_SIZE(rates_24576), | ||
177 | .list = rates_24576, | ||
178 | }; | ||
179 | |||
180 | static unsigned int rates_36864[] = { | ||
181 | 48000, 96000, 19200 | ||
182 | }; | ||
183 | |||
184 | static struct snd_pcm_hw_constraint_list constraints_36864 = { | ||
185 | .count = ARRAY_SIZE(rates_36864), | ||
186 | .list = rates_36864, | ||
118 | }; | 187 | }; |
119 | 188 | ||
120 | 189 | ||
@@ -135,7 +204,7 @@ static int wm8741_startup(struct snd_pcm_substream *substream, | |||
135 | 204 | ||
136 | snd_pcm_hw_constraint_list(substream->runtime, 0, | 205 | snd_pcm_hw_constraint_list(substream->runtime, 0, |
137 | SNDRV_PCM_HW_PARAM_RATE, | 206 | SNDRV_PCM_HW_PARAM_RATE, |
138 | &wm8741->rate_constraint); | 207 | wm8741->sysclk_constraints); |
139 | 208 | ||
140 | return 0; | 209 | return 0; |
141 | } | 210 | } |
@@ -145,8 +214,7 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream, | |||
145 | struct snd_soc_dai *dai) | 214 | struct snd_soc_dai *dai) |
146 | { | 215 | { |
147 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 216 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
148 | struct snd_soc_device *socdev = rtd->socdev; | 217 | struct snd_soc_codec *codec = rtd->codec; |
149 | struct snd_soc_codec *codec = socdev->card->codec; | ||
150 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); | 218 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); |
151 | u16 iface = snd_soc_read(codec, WM8741_FORMAT_CONTROL) & 0x1FC; | 219 | u16 iface = snd_soc_read(codec, WM8741_FORMAT_CONTROL) & 0x1FC; |
152 | int i; | 220 | int i; |
@@ -196,47 +264,52 @@ static int wm8741_set_dai_sysclk(struct snd_soc_dai *codec_dai, | |||
196 | { | 264 | { |
197 | struct snd_soc_codec *codec = codec_dai->codec; | 265 | struct snd_soc_codec *codec = codec_dai->codec; |
198 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); | 266 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); |
199 | unsigned int val; | ||
200 | int i; | ||
201 | 267 | ||
202 | dev_dbg(codec->dev, "wm8741_set_dai_sysclk info: freq=%dHz\n", freq); | 268 | dev_dbg(codec->dev, "wm8741_set_dai_sysclk info: freq=%dHz\n", freq); |
203 | 269 | ||
204 | wm8741->sysclk = freq; | 270 | switch (freq) { |
205 | 271 | case 11289600: | |
206 | wm8741->rate_constraint.count = 0; | 272 | wm8741->sysclk_constraints = &constraints_11289; |
207 | 273 | wm8741->sysclk = freq; | |
208 | for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) { | 274 | return 0; |
209 | dev_dbg(codec->dev, "index = %d, ratio = %d, freq = %d", | 275 | |
210 | i, lrclk_ratios[i].ratio, freq); | 276 | case 12288000: |
211 | 277 | wm8741->sysclk_constraints = &constraints_12288; | |
212 | val = freq / lrclk_ratios[i].ratio; | 278 | wm8741->sysclk = freq; |
213 | /* Check that it's a standard rate since core can't | 279 | return 0; |
214 | * cope with others and having the odd rates confuses | 280 | |
215 | * constraint matching. | 281 | case 16384000: |
216 | */ | 282 | wm8741->sysclk_constraints = &constraints_16384; |
217 | switch (val) { | 283 | wm8741->sysclk = freq; |
218 | case 32000: | 284 | return 0; |
219 | case 44100: | 285 | |
220 | case 48000: | 286 | case 16934400: |
221 | case 64000: | 287 | wm8741->sysclk_constraints = &constraints_16934; |
222 | case 88200: | 288 | wm8741->sysclk = freq; |
223 | case 96000: | 289 | return 0; |
224 | dev_dbg(codec->dev, "Supported sample rate: %dHz\n", | 290 | |
225 | val); | 291 | case 18432000: |
226 | wm8741->rate_constraint_list[i] = val; | 292 | wm8741->sysclk_constraints = &constraints_18432; |
227 | wm8741->rate_constraint.count++; | 293 | wm8741->sysclk = freq; |
228 | break; | 294 | return 0; |
229 | default: | 295 | |
230 | dev_dbg(codec->dev, "Skipping sample rate: %dHz\n", | 296 | case 22579200: |
231 | val); | 297 | case 33868800: |
232 | } | 298 | wm8741->sysclk_constraints = &constraints_22579; |
299 | wm8741->sysclk = freq; | ||
300 | return 0; | ||
301 | |||
302 | case 24576000: | ||
303 | wm8741->sysclk_constraints = &constraints_24576; | ||
304 | wm8741->sysclk = freq; | ||
305 | return 0; | ||
306 | |||
307 | case 36864000: | ||
308 | wm8741->sysclk_constraints = &constraints_36864; | ||
309 | wm8741->sysclk = freq; | ||
310 | return 0; | ||
233 | } | 311 | } |
234 | 312 | return -EINVAL; | |
235 | /* Need at least one supported rate... */ | ||
236 | if (wm8741->rate_constraint.count == 0) | ||
237 | return -EINVAL; | ||
238 | |||
239 | return 0; | ||
240 | } | 313 | } |
241 | 314 | ||
242 | static int wm8741_set_dai_fmt(struct snd_soc_dai *codec_dai, | 315 | static int wm8741_set_dai_fmt(struct snd_soc_dai *codec_dai, |
@@ -314,8 +387,8 @@ static struct snd_soc_dai_ops wm8741_dai_ops = { | |||
314 | .set_fmt = wm8741_set_dai_fmt, | 387 | .set_fmt = wm8741_set_dai_fmt, |
315 | }; | 388 | }; |
316 | 389 | ||
317 | struct snd_soc_dai wm8741_dai = { | 390 | static struct snd_soc_dai_driver wm8741_dai = { |
318 | .name = "WM8741", | 391 | .name = "wm8741", |
319 | .playback = { | 392 | .playback = { |
320 | .stream_name = "Playback", | 393 | .stream_name = "Playback", |
321 | .channels_min = 2, /* Mono modes not yet supported */ | 394 | .channels_min = 2, /* Mono modes not yet supported */ |
@@ -325,13 +398,10 @@ struct snd_soc_dai wm8741_dai = { | |||
325 | }, | 398 | }, |
326 | .ops = &wm8741_dai_ops, | 399 | .ops = &wm8741_dai_ops, |
327 | }; | 400 | }; |
328 | EXPORT_SYMBOL_GPL(wm8741_dai); | ||
329 | 401 | ||
330 | #ifdef CONFIG_PM | 402 | #ifdef CONFIG_PM |
331 | static int wm8741_resume(struct platform_device *pdev) | 403 | static int wm8741_resume(struct snd_soc_codec *codec) |
332 | { | 404 | { |
333 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
334 | struct snd_soc_codec *codec = socdev->card->codec; | ||
335 | u16 *cache = codec->reg_cache; | 405 | u16 *cache = codec->reg_cache; |
336 | int i; | 406 | int i; |
337 | 407 | ||
@@ -348,189 +418,103 @@ static int wm8741_resume(struct platform_device *pdev) | |||
348 | #define wm8741_resume NULL | 418 | #define wm8741_resume NULL |
349 | #endif | 419 | #endif |
350 | 420 | ||
351 | static int wm8741_probe(struct platform_device *pdev) | 421 | static int wm8741_probe(struct snd_soc_codec *codec) |
352 | { | 422 | { |
353 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 423 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); |
354 | struct snd_soc_codec *codec; | ||
355 | int ret = 0; | 424 | int ret = 0; |
356 | 425 | ||
357 | if (wm8741_codec == NULL) { | 426 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8741->control_type); |
358 | dev_err(&pdev->dev, "Codec device not registered\n"); | 427 | if (ret != 0) { |
359 | return -ENODEV; | 428 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
429 | return ret; | ||
360 | } | 430 | } |
361 | 431 | ||
362 | socdev->card->codec = wm8741_codec; | 432 | ret = wm8741_reset(codec); |
363 | codec = wm8741_codec; | ||
364 | |||
365 | /* register pcms */ | ||
366 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
367 | if (ret < 0) { | 433 | if (ret < 0) { |
368 | dev_err(codec->dev, "failed to create pcms: %d\n", ret); | 434 | dev_err(codec->dev, "Failed to issue reset\n"); |
369 | goto pcm_err; | 435 | return ret; |
370 | } | 436 | } |
371 | 437 | ||
438 | /* Change some default settings - latch VU */ | ||
439 | snd_soc_update_bits(codec, WM8741_DACLLSB_ATTENUATION, | ||
440 | WM8741_UPDATELL, WM8741_UPDATELL); | ||
441 | snd_soc_update_bits(codec, WM8741_DACLMSB_ATTENUATION, | ||
442 | WM8741_UPDATELM, WM8741_UPDATELM); | ||
443 | snd_soc_update_bits(codec, WM8741_DACRLSB_ATTENUATION, | ||
444 | WM8741_UPDATERL, WM8741_UPDATERL); | ||
445 | snd_soc_update_bits(codec, WM8741_DACRLSB_ATTENUATION, | ||
446 | WM8741_UPDATERM, WM8741_UPDATERM); | ||
447 | |||
372 | snd_soc_add_controls(codec, wm8741_snd_controls, | 448 | snd_soc_add_controls(codec, wm8741_snd_controls, |
373 | ARRAY_SIZE(wm8741_snd_controls)); | 449 | ARRAY_SIZE(wm8741_snd_controls)); |
374 | wm8741_add_widgets(codec); | 450 | wm8741_add_widgets(codec); |
375 | 451 | ||
452 | dev_dbg(codec->dev, "Successful registration\n"); | ||
376 | return ret; | 453 | return ret; |
377 | |||
378 | pcm_err: | ||
379 | return ret; | ||
380 | } | ||
381 | |||
382 | static int wm8741_remove(struct platform_device *pdev) | ||
383 | { | ||
384 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
385 | |||
386 | snd_soc_free_pcms(socdev); | ||
387 | snd_soc_dapm_free(socdev); | ||
388 | |||
389 | return 0; | ||
390 | } | 454 | } |
391 | 455 | ||
392 | struct snd_soc_codec_device soc_codec_dev_wm8741 = { | 456 | static struct snd_soc_codec_driver soc_codec_dev_wm8741 = { |
393 | .probe = wm8741_probe, | 457 | .probe = wm8741_probe, |
394 | .remove = wm8741_remove, | ||
395 | .resume = wm8741_resume, | 458 | .resume = wm8741_resume, |
459 | .reg_cache_size = ARRAY_SIZE(wm8741_reg_defaults), | ||
460 | .reg_word_size = sizeof(u16), | ||
461 | .reg_cache_default = wm8741_reg_defaults, | ||
396 | }; | 462 | }; |
397 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8741); | ||
398 | 463 | ||
399 | static int wm8741_register(struct wm8741_priv *wm8741, | 464 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
400 | enum snd_soc_control_type control) | 465 | static int wm8741_i2c_probe(struct i2c_client *i2c, |
466 | const struct i2c_device_id *id) | ||
401 | { | 467 | { |
402 | int ret; | 468 | struct wm8741_priv *wm8741; |
403 | struct snd_soc_codec *codec = &wm8741->codec; | 469 | int ret, i; |
404 | int i; | ||
405 | |||
406 | if (wm8741_codec) { | ||
407 | dev_err(codec->dev, "Another WM8741 is registered\n"); | ||
408 | return -EINVAL; | ||
409 | } | ||
410 | |||
411 | mutex_init(&codec->mutex); | ||
412 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
413 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
414 | |||
415 | snd_soc_codec_set_drvdata(codec, wm8741); | ||
416 | codec->name = "WM8741"; | ||
417 | codec->owner = THIS_MODULE; | ||
418 | codec->bias_level = SND_SOC_BIAS_OFF; | ||
419 | codec->set_bias_level = NULL; | ||
420 | codec->dai = &wm8741_dai; | ||
421 | codec->num_dai = 1; | ||
422 | codec->reg_cache_size = WM8741_REGISTER_COUNT; | ||
423 | codec->reg_cache = &wm8741->reg_cache; | ||
424 | |||
425 | wm8741->rate_constraint.list = &wm8741->rate_constraint_list[0]; | ||
426 | wm8741->rate_constraint.count = | ||
427 | ARRAY_SIZE(wm8741->rate_constraint_list); | ||
428 | |||
429 | memcpy(codec->reg_cache, wm8741_reg_defaults, | ||
430 | sizeof(wm8741->reg_cache)); | ||
431 | 470 | ||
432 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); | 471 | wm8741 = kzalloc(sizeof(struct wm8741_priv), GFP_KERNEL); |
433 | if (ret != 0) { | 472 | if (wm8741 == NULL) |
434 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | 473 | return -ENOMEM; |
435 | goto err; | ||
436 | } | ||
437 | 474 | ||
438 | for (i = 0; i < ARRAY_SIZE(wm8741->supplies); i++) | 475 | for (i = 0; i < ARRAY_SIZE(wm8741->supplies); i++) |
439 | wm8741->supplies[i].supply = wm8741_supply_names[i]; | 476 | wm8741->supplies[i].supply = wm8741_supply_names[i]; |
440 | 477 | ||
441 | ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8741->supplies), | 478 | ret = regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8741->supplies), |
442 | wm8741->supplies); | 479 | wm8741->supplies); |
443 | if (ret != 0) { | 480 | if (ret != 0) { |
444 | dev_err(codec->dev, "Failed to request supplies: %d\n", ret); | 481 | dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); |
445 | goto err; | 482 | goto err; |
446 | } | 483 | } |
447 | 484 | ||
448 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8741->supplies), | 485 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8741->supplies), |
449 | wm8741->supplies); | 486 | wm8741->supplies); |
450 | if (ret != 0) { | 487 | if (ret != 0) { |
451 | dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); | 488 | dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); |
452 | goto err_get; | 489 | goto err_get; |
453 | } | 490 | } |
454 | 491 | ||
455 | ret = wm8741_reset(codec); | 492 | i2c_set_clientdata(i2c, wm8741); |
456 | if (ret < 0) { | 493 | wm8741->control_type = SND_SOC_I2C; |
457 | dev_err(codec->dev, "Failed to issue reset\n"); | ||
458 | goto err_enable; | ||
459 | } | ||
460 | |||
461 | wm8741_dai.dev = codec->dev; | ||
462 | |||
463 | /* Change some default settings - latch VU */ | ||
464 | wm8741->reg_cache[WM8741_DACLLSB_ATTENUATION] |= WM8741_UPDATELL; | ||
465 | wm8741->reg_cache[WM8741_DACLMSB_ATTENUATION] |= WM8741_UPDATELM; | ||
466 | wm8741->reg_cache[WM8741_DACRLSB_ATTENUATION] |= WM8741_UPDATERL; | ||
467 | wm8741->reg_cache[WM8741_DACRLSB_ATTENUATION] |= WM8741_UPDATERM; | ||
468 | |||
469 | wm8741_codec = codec; | ||
470 | |||
471 | ret = snd_soc_register_codec(codec); | ||
472 | if (ret != 0) { | ||
473 | dev_err(codec->dev, "Failed to register codec: %d\n", ret); | ||
474 | return ret; | ||
475 | } | ||
476 | |||
477 | ret = snd_soc_register_dai(&wm8741_dai); | ||
478 | if (ret != 0) { | ||
479 | dev_err(codec->dev, "Failed to register DAI: %d\n", ret); | ||
480 | snd_soc_unregister_codec(codec); | ||
481 | return ret; | ||
482 | } | ||
483 | 494 | ||
484 | dev_dbg(codec->dev, "Successful registration\n"); | 495 | ret = snd_soc_register_codec(&i2c->dev, |
485 | return 0; | 496 | &soc_codec_dev_wm8741, &wm8741_dai, 1); |
497 | if (ret < 0) | ||
498 | goto err_enable; | ||
499 | return ret; | ||
486 | 500 | ||
487 | err_enable: | 501 | err_enable: |
488 | regulator_bulk_disable(ARRAY_SIZE(wm8741->supplies), wm8741->supplies); | 502 | regulator_bulk_disable(ARRAY_SIZE(wm8741->supplies), wm8741->supplies); |
489 | 503 | ||
490 | err_get: | 504 | err_get: |
491 | regulator_bulk_free(ARRAY_SIZE(wm8741->supplies), wm8741->supplies); | 505 | regulator_bulk_free(ARRAY_SIZE(wm8741->supplies), wm8741->supplies); |
492 | |||
493 | err: | 506 | err: |
494 | kfree(wm8741); | 507 | kfree(wm8741); |
495 | return ret; | 508 | return ret; |
496 | } | 509 | } |
497 | 510 | ||
498 | static void wm8741_unregister(struct wm8741_priv *wm8741) | 511 | static int wm8741_i2c_remove(struct i2c_client *client) |
499 | { | ||
500 | regulator_bulk_free(ARRAY_SIZE(wm8741->supplies), wm8741->supplies); | ||
501 | |||
502 | snd_soc_unregister_dai(&wm8741_dai); | ||
503 | snd_soc_unregister_codec(&wm8741->codec); | ||
504 | kfree(wm8741); | ||
505 | wm8741_codec = NULL; | ||
506 | } | ||
507 | |||
508 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
509 | static __devinit int wm8741_i2c_probe(struct i2c_client *i2c, | ||
510 | const struct i2c_device_id *id) | ||
511 | { | ||
512 | struct wm8741_priv *wm8741; | ||
513 | struct snd_soc_codec *codec; | ||
514 | |||
515 | wm8741 = kzalloc(sizeof(struct wm8741_priv), GFP_KERNEL); | ||
516 | if (wm8741 == NULL) | ||
517 | return -ENOMEM; | ||
518 | |||
519 | codec = &wm8741->codec; | ||
520 | codec->hw_write = (hw_write_t)i2c_master_send; | ||
521 | |||
522 | i2c_set_clientdata(i2c, wm8741); | ||
523 | codec->control_data = i2c; | ||
524 | |||
525 | codec->dev = &i2c->dev; | ||
526 | |||
527 | return wm8741_register(wm8741, SND_SOC_I2C); | ||
528 | } | ||
529 | |||
530 | static __devexit int wm8741_i2c_remove(struct i2c_client *client) | ||
531 | { | 512 | { |
532 | struct wm8741_priv *wm8741 = i2c_get_clientdata(client); | 513 | struct wm8741_priv *wm8741 = i2c_get_clientdata(client); |
533 | wm8741_unregister(wm8741); | 514 | |
515 | snd_soc_unregister_codec(&client->dev); | ||
516 | regulator_bulk_free(ARRAY_SIZE(wm8741->supplies), wm8741->supplies); | ||
517 | kfree(i2c_get_clientdata(client)); | ||
534 | return 0; | 518 | return 0; |
535 | } | 519 | } |
536 | 520 | ||
@@ -540,29 +524,28 @@ static const struct i2c_device_id wm8741_i2c_id[] = { | |||
540 | }; | 524 | }; |
541 | MODULE_DEVICE_TABLE(i2c, wm8741_i2c_id); | 525 | MODULE_DEVICE_TABLE(i2c, wm8741_i2c_id); |
542 | 526 | ||
543 | |||
544 | static struct i2c_driver wm8741_i2c_driver = { | 527 | static struct i2c_driver wm8741_i2c_driver = { |
545 | .driver = { | 528 | .driver = { |
546 | .name = "WM8741", | 529 | .name = "wm8741-codec", |
547 | .owner = THIS_MODULE, | 530 | .owner = THIS_MODULE, |
548 | }, | 531 | }, |
549 | .probe = wm8741_i2c_probe, | 532 | .probe = wm8741_i2c_probe, |
550 | .remove = __devexit_p(wm8741_i2c_remove), | 533 | .remove = wm8741_i2c_remove, |
551 | .id_table = wm8741_i2c_id, | 534 | .id_table = wm8741_i2c_id, |
552 | }; | 535 | }; |
553 | #endif | 536 | #endif |
554 | 537 | ||
555 | static int __init wm8741_modinit(void) | 538 | static int __init wm8741_modinit(void) |
556 | { | 539 | { |
557 | int ret; | 540 | int ret = 0; |
541 | |||
558 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 542 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
559 | ret = i2c_add_driver(&wm8741_i2c_driver); | 543 | ret = i2c_add_driver(&wm8741_i2c_driver); |
560 | if (ret != 0) { | 544 | if (ret != 0) |
561 | printk(KERN_ERR "Failed to register WM8741 I2C driver: %d\n", | 545 | pr_err("Failed to register WM8741 I2C driver: %d\n", ret); |
562 | ret); | ||
563 | } | ||
564 | #endif | 546 | #endif |
565 | return 0; | 547 | |
548 | return ret; | ||
566 | } | 549 | } |
567 | module_init(wm8741_modinit); | 550 | module_init(wm8741_modinit); |
568 | 551 | ||