diff options
Diffstat (limited to 'sound/soc/codecs/cs4270.c')
-rw-r--r-- | sound/soc/codecs/cs4270.c | 105 |
1 files changed, 98 insertions, 7 deletions
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index 7fa09a38762..a32b8226c8a 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c | |||
@@ -18,7 +18,7 @@ | |||
18 | * - The machine driver's 'startup' function must call | 18 | * - The machine driver's 'startup' function must call |
19 | * cs4270_set_dai_sysclk() with the value of MCLK. | 19 | * cs4270_set_dai_sysclk() with the value of MCLK. |
20 | * - Only I2S and left-justified modes are supported | 20 | * - Only I2S and left-justified modes are supported |
21 | * - Power management is not supported | 21 | * - Power management is supported |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
@@ -27,6 +27,7 @@ | |||
27 | #include <sound/soc.h> | 27 | #include <sound/soc.h> |
28 | #include <sound/initval.h> | 28 | #include <sound/initval.h> |
29 | #include <linux/i2c.h> | 29 | #include <linux/i2c.h> |
30 | #include <linux/delay.h> | ||
30 | 31 | ||
31 | #include "cs4270.h" | 32 | #include "cs4270.h" |
32 | 33 | ||
@@ -56,6 +57,7 @@ | |||
56 | #define CS4270_FIRSTREG 0x01 | 57 | #define CS4270_FIRSTREG 0x01 |
57 | #define CS4270_LASTREG 0x08 | 58 | #define CS4270_LASTREG 0x08 |
58 | #define CS4270_NUMREGS (CS4270_LASTREG - CS4270_FIRSTREG + 1) | 59 | #define CS4270_NUMREGS (CS4270_LASTREG - CS4270_FIRSTREG + 1) |
60 | #define CS4270_I2C_INCR 0x80 | ||
59 | 61 | ||
60 | /* Bit masks for the CS4270 registers */ | 62 | /* Bit masks for the CS4270 registers */ |
61 | #define CS4270_CHIPID_ID 0xF0 | 63 | #define CS4270_CHIPID_ID 0xF0 |
@@ -64,6 +66,8 @@ | |||
64 | #define CS4270_PWRCTL_PDN_ADC 0x20 | 66 | #define CS4270_PWRCTL_PDN_ADC 0x20 |
65 | #define CS4270_PWRCTL_PDN_DAC 0x02 | 67 | #define CS4270_PWRCTL_PDN_DAC 0x02 |
66 | #define CS4270_PWRCTL_PDN 0x01 | 68 | #define CS4270_PWRCTL_PDN 0x01 |
69 | #define CS4270_PWRCTL_PDN_ALL \ | ||
70 | (CS4270_PWRCTL_PDN_ADC | CS4270_PWRCTL_PDN_DAC | CS4270_PWRCTL_PDN) | ||
67 | #define CS4270_MODE_SPEED_MASK 0x30 | 71 | #define CS4270_MODE_SPEED_MASK 0x30 |
68 | #define CS4270_MODE_1X 0x00 | 72 | #define CS4270_MODE_1X 0x00 |
69 | #define CS4270_MODE_2X 0x10 | 73 | #define CS4270_MODE_2X 0x10 |
@@ -109,6 +113,7 @@ struct cs4270_private { | |||
109 | unsigned int mclk; /* Input frequency of the MCLK pin */ | 113 | unsigned int mclk; /* Input frequency of the MCLK pin */ |
110 | unsigned int mode; /* The mode (I2S or left-justified) */ | 114 | unsigned int mode; /* The mode (I2S or left-justified) */ |
111 | unsigned int slave_mode; | 115 | unsigned int slave_mode; |
116 | unsigned int manual_mute; | ||
112 | }; | 117 | }; |
113 | 118 | ||
114 | /** | 119 | /** |
@@ -295,7 +300,7 @@ static int cs4270_fill_cache(struct snd_soc_codec *codec) | |||
295 | s32 length; | 300 | s32 length; |
296 | 301 | ||
297 | length = i2c_smbus_read_i2c_block_data(i2c_client, | 302 | length = i2c_smbus_read_i2c_block_data(i2c_client, |
298 | CS4270_FIRSTREG | 0x80, CS4270_NUMREGS, cache); | 303 | CS4270_FIRSTREG | CS4270_I2C_INCR, CS4270_NUMREGS, cache); |
299 | 304 | ||
300 | if (length != CS4270_NUMREGS) { | 305 | if (length != CS4270_NUMREGS) { |
301 | dev_err(codec->dev, "i2c read failure, addr=0x%x\n", | 306 | dev_err(codec->dev, "i2c read failure, addr=0x%x\n", |
@@ -453,7 +458,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, | |||
453 | } | 458 | } |
454 | 459 | ||
455 | /** | 460 | /** |
456 | * cs4270_mute - enable/disable the CS4270 external mute | 461 | * cs4270_dai_mute - enable/disable the CS4270 external mute |
457 | * @dai: the SOC DAI | 462 | * @dai: the SOC DAI |
458 | * @mute: 0 = disable mute, 1 = enable mute | 463 | * @mute: 0 = disable mute, 1 = enable mute |
459 | * | 464 | * |
@@ -462,21 +467,52 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, | |||
462 | * board does not have the MUTEA or MUTEB pins connected to such circuitry, | 467 | * board does not have the MUTEA or MUTEB pins connected to such circuitry, |
463 | * then this function will do nothing. | 468 | * then this function will do nothing. |
464 | */ | 469 | */ |
465 | static int cs4270_mute(struct snd_soc_dai *dai, int mute) | 470 | static int cs4270_dai_mute(struct snd_soc_dai *dai, int mute) |
466 | { | 471 | { |
467 | struct snd_soc_codec *codec = dai->codec; | 472 | struct snd_soc_codec *codec = dai->codec; |
473 | struct cs4270_private *cs4270 = codec->private_data; | ||
468 | int reg6; | 474 | int reg6; |
469 | 475 | ||
470 | reg6 = snd_soc_read(codec, CS4270_MUTE); | 476 | reg6 = snd_soc_read(codec, CS4270_MUTE); |
471 | 477 | ||
472 | if (mute) | 478 | if (mute) |
473 | reg6 |= CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B; | 479 | reg6 |= CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B; |
474 | else | 480 | else { |
475 | reg6 &= ~(CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B); | 481 | reg6 &= ~(CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B); |
482 | reg6 |= cs4270->manual_mute; | ||
483 | } | ||
476 | 484 | ||
477 | return snd_soc_write(codec, CS4270_MUTE, reg6); | 485 | return snd_soc_write(codec, CS4270_MUTE, reg6); |
478 | } | 486 | } |
479 | 487 | ||
488 | /** | ||
489 | * cs4270_soc_put_mute - put callback for the 'Master Playback switch' | ||
490 | * alsa control. | ||
491 | * @kcontrol: mixer control | ||
492 | * @ucontrol: control element information | ||
493 | * | ||
494 | * This function basically passes the arguments on to the generic | ||
495 | * snd_soc_put_volsw() function and saves the mute information in | ||
496 | * our private data structure. This is because we want to prevent | ||
497 | * cs4270_dai_mute() neglecting the user's decision to manually | ||
498 | * mute the codec's output. | ||
499 | * | ||
500 | * Returns 0 for success. | ||
501 | */ | ||
502 | static int cs4270_soc_put_mute(struct snd_kcontrol *kcontrol, | ||
503 | struct snd_ctl_elem_value *ucontrol) | ||
504 | { | ||
505 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
506 | struct cs4270_private *cs4270 = codec->private_data; | ||
507 | int left = !ucontrol->value.integer.value[0]; | ||
508 | int right = !ucontrol->value.integer.value[1]; | ||
509 | |||
510 | cs4270->manual_mute = (left ? CS4270_MUTE_DAC_A : 0) | | ||
511 | (right ? CS4270_MUTE_DAC_B : 0); | ||
512 | |||
513 | return snd_soc_put_volsw(kcontrol, ucontrol); | ||
514 | } | ||
515 | |||
480 | /* A list of non-DAPM controls that the CS4270 supports */ | 516 | /* A list of non-DAPM controls that the CS4270 supports */ |
481 | static const struct snd_kcontrol_new cs4270_snd_controls[] = { | 517 | static const struct snd_kcontrol_new cs4270_snd_controls[] = { |
482 | SOC_DOUBLE_R("Master Playback Volume", | 518 | SOC_DOUBLE_R("Master Playback Volume", |
@@ -486,7 +522,9 @@ static const struct snd_kcontrol_new cs4270_snd_controls[] = { | |||
486 | SOC_SINGLE("Zero Cross Switch", CS4270_TRANS, 5, 1, 0), | 522 | SOC_SINGLE("Zero Cross Switch", CS4270_TRANS, 5, 1, 0), |
487 | SOC_SINGLE("Popguard Switch", CS4270_MODE, 0, 1, 1), | 523 | SOC_SINGLE("Popguard Switch", CS4270_MODE, 0, 1, 1), |
488 | SOC_SINGLE("Auto-Mute Switch", CS4270_MUTE, 5, 1, 0), | 524 | SOC_SINGLE("Auto-Mute Switch", CS4270_MUTE, 5, 1, 0), |
489 | SOC_DOUBLE("Master Capture Switch", CS4270_MUTE, 3, 4, 1, 0) | 525 | SOC_DOUBLE("Master Capture Switch", CS4270_MUTE, 3, 4, 1, 1), |
526 | SOC_DOUBLE_EXT("Master Playback Switch", CS4270_MUTE, 0, 1, 1, 1, | ||
527 | snd_soc_get_volsw, cs4270_soc_put_mute), | ||
490 | }; | 528 | }; |
491 | 529 | ||
492 | /* | 530 | /* |
@@ -506,7 +544,7 @@ static struct snd_soc_dai_ops cs4270_dai_ops = { | |||
506 | .hw_params = cs4270_hw_params, | 544 | .hw_params = cs4270_hw_params, |
507 | .set_sysclk = cs4270_set_dai_sysclk, | 545 | .set_sysclk = cs4270_set_dai_sysclk, |
508 | .set_fmt = cs4270_set_dai_fmt, | 546 | .set_fmt = cs4270_set_dai_fmt, |
509 | .digital_mute = cs4270_mute, | 547 | .digital_mute = cs4270_dai_mute, |
510 | }; | 548 | }; |
511 | 549 | ||
512 | struct snd_soc_dai cs4270_dai = { | 550 | struct snd_soc_dai cs4270_dai = { |
@@ -753,6 +791,57 @@ static struct i2c_device_id cs4270_id[] = { | |||
753 | }; | 791 | }; |
754 | MODULE_DEVICE_TABLE(i2c, cs4270_id); | 792 | MODULE_DEVICE_TABLE(i2c, cs4270_id); |
755 | 793 | ||
794 | #ifdef CONFIG_PM | ||
795 | |||
796 | /* This suspend/resume implementation can handle both - a simple standby | ||
797 | * where the codec remains powered, and a full suspend, where the voltage | ||
798 | * domain the codec is connected to is teared down and/or any other hardware | ||
799 | * reset condition is asserted. | ||
800 | * | ||
801 | * The codec's own power saving features are enabled in the suspend callback, | ||
802 | * and all registers are written back to the hardware when resuming. | ||
803 | */ | ||
804 | |||
805 | static int cs4270_i2c_suspend(struct i2c_client *client, pm_message_t mesg) | ||
806 | { | ||
807 | struct cs4270_private *cs4270 = i2c_get_clientdata(client); | ||
808 | struct snd_soc_codec *codec = &cs4270->codec; | ||
809 | int reg = snd_soc_read(codec, CS4270_PWRCTL) | CS4270_PWRCTL_PDN_ALL; | ||
810 | |||
811 | return snd_soc_write(codec, CS4270_PWRCTL, reg); | ||
812 | } | ||
813 | |||
814 | static int cs4270_i2c_resume(struct i2c_client *client) | ||
815 | { | ||
816 | struct cs4270_private *cs4270 = i2c_get_clientdata(client); | ||
817 | struct snd_soc_codec *codec = &cs4270->codec; | ||
818 | int reg; | ||
819 | |||
820 | /* In case the device was put to hard reset during sleep, we need to | ||
821 | * wait 500ns here before any I2C communication. */ | ||
822 | ndelay(500); | ||
823 | |||
824 | /* first restore the entire register cache ... */ | ||
825 | for (reg = CS4270_FIRSTREG; reg <= CS4270_LASTREG; reg++) { | ||
826 | u8 val = snd_soc_read(codec, reg); | ||
827 | |||
828 | if (i2c_smbus_write_byte_data(client, reg, val)) { | ||
829 | dev_err(codec->dev, "i2c write failed\n"); | ||
830 | return -EIO; | ||
831 | } | ||
832 | } | ||
833 | |||
834 | /* ... then disable the power-down bits */ | ||
835 | reg = snd_soc_read(codec, CS4270_PWRCTL); | ||
836 | reg &= ~CS4270_PWRCTL_PDN_ALL; | ||
837 | |||
838 | return snd_soc_write(codec, CS4270_PWRCTL, reg); | ||
839 | } | ||
840 | #else | ||
841 | #define cs4270_i2c_suspend NULL | ||
842 | #define cs4270_i2c_resume NULL | ||
843 | #endif /* CONFIG_PM */ | ||
844 | |||
756 | /* | 845 | /* |
757 | * cs4270_i2c_driver - I2C device identification | 846 | * cs4270_i2c_driver - I2C device identification |
758 | * | 847 | * |
@@ -767,6 +856,8 @@ static struct i2c_driver cs4270_i2c_driver = { | |||
767 | .id_table = cs4270_id, | 856 | .id_table = cs4270_id, |
768 | .probe = cs4270_i2c_probe, | 857 | .probe = cs4270_i2c_probe, |
769 | .remove = cs4270_i2c_remove, | 858 | .remove = cs4270_i2c_remove, |
859 | .suspend = cs4270_i2c_suspend, | ||
860 | .resume = cs4270_i2c_resume, | ||
770 | }; | 861 | }; |
771 | 862 | ||
772 | /* | 863 | /* |