wm8731.c (af6b7a82fd2416d68bcf46d18d96de9b59e43b06) | wm8731.c (99d422341376443a98ef22d0f0003b3381f32186) |
---|---|
1/* 2 * wm8731.c -- WM8731 ALSA SoC Audio driver 3 * 4 * Copyright 2005 Openedhand Ltd. 5 * Copyright 2006-12 Wolfson Microelectronics, plc 6 * 7 * Author: Richard Purdie <richard@openedhand.com> 8 * --- 11 unchanged lines hidden (view full) --- 20#include <linux/pm.h> 21#include <linux/i2c.h> 22#include <linux/slab.h> 23#include <linux/regmap.h> 24#include <linux/regulator/consumer.h> 25#include <linux/spi/spi.h> 26#include <linux/of_device.h> 27#include <linux/mutex.h> | 1/* 2 * wm8731.c -- WM8731 ALSA SoC Audio driver 3 * 4 * Copyright 2005 Openedhand Ltd. 5 * Copyright 2006-12 Wolfson Microelectronics, plc 6 * 7 * Author: Richard Purdie <richard@openedhand.com> 8 * --- 11 unchanged lines hidden (view full) --- 20#include <linux/pm.h> 21#include <linux/i2c.h> 22#include <linux/slab.h> 23#include <linux/regmap.h> 24#include <linux/regulator/consumer.h> 25#include <linux/spi/spi.h> 26#include <linux/of_device.h> 27#include <linux/mutex.h> |
28#include <linux/clk.h> |
|
28#include <sound/core.h> 29#include <sound/pcm.h> 30#include <sound/pcm_params.h> 31#include <sound/soc.h> 32#include <sound/initval.h> 33#include <sound/tlv.h> 34 35#include "wm8731.h" --- 4 unchanged lines hidden (view full) --- 40 "HPVDD", 41 "DCVDD", 42 "DBVDD", 43}; 44 45/* codec private data */ 46struct wm8731_priv { 47 struct regmap *regmap; | 29#include <sound/core.h> 30#include <sound/pcm.h> 31#include <sound/pcm_params.h> 32#include <sound/soc.h> 33#include <sound/initval.h> 34#include <sound/tlv.h> 35 36#include "wm8731.h" --- 4 unchanged lines hidden (view full) --- 41 "HPVDD", 42 "DCVDD", 43 "DBVDD", 44}; 45 46/* codec private data */ 47struct wm8731_priv { 48 struct regmap *regmap; |
49 struct clk *mclk; |
|
48 struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; 49 const struct snd_pcm_hw_constraint_list *constraints; 50 unsigned int sysclk; 51 int sysclk_type; 52 int playback_fs; 53 bool deemph; 54 55 struct mutex lock; --- 64 unchanged lines hidden (view full) --- 120} 121 122static int wm8731_get_deemph(struct snd_kcontrol *kcontrol, 123 struct snd_ctl_elem_value *ucontrol) 124{ 125 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 126 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 127 | 50 struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; 51 const struct snd_pcm_hw_constraint_list *constraints; 52 unsigned int sysclk; 53 int sysclk_type; 54 int playback_fs; 55 bool deemph; 56 57 struct mutex lock; --- 64 unchanged lines hidden (view full) --- 122} 123 124static int wm8731_get_deemph(struct snd_kcontrol *kcontrol, 125 struct snd_ctl_elem_value *ucontrol) 126{ 127 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 128 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 129 |
128 ucontrol->value.integer.value[0] = wm8731->deemph; | 130 ucontrol->value.enumerated.item[0] = wm8731->deemph; |
129 130 return 0; 131} 132 133static int wm8731_put_deemph(struct snd_kcontrol *kcontrol, 134 struct snd_ctl_elem_value *ucontrol) 135{ 136 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 137 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); | 131 132 return 0; 133} 134 135static int wm8731_put_deemph(struct snd_kcontrol *kcontrol, 136 struct snd_ctl_elem_value *ucontrol) 137{ 138 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 139 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); |
138 int deemph = ucontrol->value.integer.value[0]; | 140 int deemph = ucontrol->value.enumerated.item[0]; |
139 int ret = 0; 140 141 if (deemph > 1) 142 return -EINVAL; 143 144 mutex_lock(&wm8731->lock); 145 if (wm8731->deemph != deemph) { 146 wm8731->deemph = deemph; --- 238 unchanged lines hidden (view full) --- 385 int clk_id, unsigned int freq, int dir) 386{ 387 struct snd_soc_codec *codec = codec_dai->codec; 388 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 389 390 switch (clk_id) { 391 case WM8731_SYSCLK_XTAL: 392 case WM8731_SYSCLK_MCLK: | 141 int ret = 0; 142 143 if (deemph > 1) 144 return -EINVAL; 145 146 mutex_lock(&wm8731->lock); 147 if (wm8731->deemph != deemph) { 148 wm8731->deemph = deemph; --- 238 unchanged lines hidden (view full) --- 387 int clk_id, unsigned int freq, int dir) 388{ 389 struct snd_soc_codec *codec = codec_dai->codec; 390 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 391 392 switch (clk_id) { 393 case WM8731_SYSCLK_XTAL: 394 case WM8731_SYSCLK_MCLK: |
395 if (wm8731->mclk && clk_set_rate(wm8731->mclk, freq)) 396 return -EINVAL; |
|
393 wm8731->sysclk_type = clk_id; 394 break; 395 default: 396 return -EINVAL; 397 } 398 399 switch (freq) { 400 case 0: --- 85 unchanged lines hidden (view full) --- 486 enum snd_soc_bias_level level) 487{ 488 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 489 int ret; 490 u16 reg; 491 492 switch (level) { 493 case SND_SOC_BIAS_ON: | 397 wm8731->sysclk_type = clk_id; 398 break; 399 default: 400 return -EINVAL; 401 } 402 403 switch (freq) { 404 case 0: --- 85 unchanged lines hidden (view full) --- 490 enum snd_soc_bias_level level) 491{ 492 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 493 int ret; 494 u16 reg; 495 496 switch (level) { 497 case SND_SOC_BIAS_ON: |
498 if (wm8731->mclk) 499 clk_prepare_enable(wm8731->mclk); |
|
494 break; 495 case SND_SOC_BIAS_PREPARE: 496 break; 497 case SND_SOC_BIAS_STANDBY: 498 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 499 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies), 500 wm8731->supplies); 501 if (ret != 0) 502 return ret; 503 504 regcache_sync(wm8731->regmap); 505 } 506 507 /* Clear PWROFF, gate CLKOUT, everything else as-is */ 508 reg = snd_soc_read(codec, WM8731_PWR) & 0xff7f; 509 snd_soc_write(codec, WM8731_PWR, reg | 0x0040); 510 break; 511 case SND_SOC_BIAS_OFF: | 500 break; 501 case SND_SOC_BIAS_PREPARE: 502 break; 503 case SND_SOC_BIAS_STANDBY: 504 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 505 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies), 506 wm8731->supplies); 507 if (ret != 0) 508 return ret; 509 510 regcache_sync(wm8731->regmap); 511 } 512 513 /* Clear PWROFF, gate CLKOUT, everything else as-is */ 514 reg = snd_soc_read(codec, WM8731_PWR) & 0xff7f; 515 snd_soc_write(codec, WM8731_PWR, reg | 0x0040); 516 break; 517 case SND_SOC_BIAS_OFF: |
518 if (wm8731->mclk) 519 clk_disable_unprepare(wm8731->mclk); |
|
512 snd_soc_write(codec, WM8731_PWR, 0xffff); 513 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), 514 wm8731->supplies); 515 regcache_mark_dirty(wm8731->regmap); 516 break; 517 } 518 codec->dapm.bias_level = level; 519 return 0; --- 142 unchanged lines hidden (view full) --- 662{ 663 struct wm8731_priv *wm8731; 664 int ret; 665 666 wm8731 = devm_kzalloc(&spi->dev, sizeof(*wm8731), GFP_KERNEL); 667 if (wm8731 == NULL) 668 return -ENOMEM; 669 | 520 snd_soc_write(codec, WM8731_PWR, 0xffff); 521 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), 522 wm8731->supplies); 523 regcache_mark_dirty(wm8731->regmap); 524 break; 525 } 526 codec->dapm.bias_level = level; 527 return 0; --- 142 unchanged lines hidden (view full) --- 670{ 671 struct wm8731_priv *wm8731; 672 int ret; 673 674 wm8731 = devm_kzalloc(&spi->dev, sizeof(*wm8731), GFP_KERNEL); 675 if (wm8731 == NULL) 676 return -ENOMEM; 677 |
678 wm8731->mclk = devm_clk_get(&spi->dev, "mclk"); 679 if (IS_ERR(wm8731->mclk)) { 680 ret = PTR_ERR(wm8731->mclk); 681 if (ret == -ENOENT) { 682 wm8731->mclk = NULL; 683 dev_warn(&spi->dev, "Assuming static MCLK\n"); 684 } else { 685 dev_err(&spi->dev, "Failed to get MCLK: %d\n", 686 ret); 687 return ret; 688 } 689 } 690 |
|
670 mutex_init(&wm8731->lock); 671 672 wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap); 673 if (IS_ERR(wm8731->regmap)) { 674 ret = PTR_ERR(wm8731->regmap); 675 dev_err(&spi->dev, "Failed to allocate register map: %d\n", 676 ret); 677 return ret; --- 35 unchanged lines hidden (view full) --- 713 struct wm8731_priv *wm8731; 714 int ret; 715 716 wm8731 = devm_kzalloc(&i2c->dev, sizeof(struct wm8731_priv), 717 GFP_KERNEL); 718 if (wm8731 == NULL) 719 return -ENOMEM; 720 | 691 mutex_init(&wm8731->lock); 692 693 wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap); 694 if (IS_ERR(wm8731->regmap)) { 695 ret = PTR_ERR(wm8731->regmap); 696 dev_err(&spi->dev, "Failed to allocate register map: %d\n", 697 ret); 698 return ret; --- 35 unchanged lines hidden (view full) --- 734 struct wm8731_priv *wm8731; 735 int ret; 736 737 wm8731 = devm_kzalloc(&i2c->dev, sizeof(struct wm8731_priv), 738 GFP_KERNEL); 739 if (wm8731 == NULL) 740 return -ENOMEM; 741 |
742 wm8731->mclk = devm_clk_get(&i2c->dev, "mclk"); 743 if (IS_ERR(wm8731->mclk)) { 744 ret = PTR_ERR(wm8731->mclk); 745 if (ret == -ENOENT) { 746 wm8731->mclk = NULL; 747 dev_warn(&i2c->dev, "Assuming static MCLK\n"); 748 } else { 749 dev_err(&i2c->dev, "Failed to get MCLK: %d\n", 750 ret); 751 return ret; 752 } 753 } 754 |
|
721 mutex_init(&wm8731->lock); 722 723 wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap); 724 if (IS_ERR(wm8731->regmap)) { 725 ret = PTR_ERR(wm8731->regmap); 726 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 727 ret); 728 return ret; --- 73 unchanged lines hidden --- | 755 mutex_init(&wm8731->lock); 756 757 wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap); 758 if (IS_ERR(wm8731->regmap)) { 759 ret = PTR_ERR(wm8731->regmap); 760 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 761 ret); 762 return ret; --- 73 unchanged lines hidden --- |