0085-tpa6130a2-Add-headphone-switch-control.patch 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. From 669d4b324d47078cffaa557b8fe7ab13ff484cbe Mon Sep 17 00:00:00 2001
  2. From: Jan Grulich <jan@grulich.eu>
  3. Date: Mon, 24 Aug 2015 16:02:34 +0100
  4. Subject: [PATCH 085/381] tpa6130a2: Add headphone switch control
  5. Signed-off-by: Jan Grulich <jan@grulich.eu>
  6. ---
  7. sound/soc/codecs/tpa6130a2.c | 29 ++++++++++++++++++++++++++---
  8. 1 file changed, 26 insertions(+), 3 deletions(-)
  9. --- a/sound/soc/codecs/tpa6130a2.c
  10. +++ b/sound/soc/codecs/tpa6130a2.c
  11. @@ -4,6 +4,7 @@
  12. * Copyright (C) Nokia Corporation
  13. *
  14. * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
  15. + * Modified: Jan Grulich <jan@grulich.eu>
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License
  19. @@ -52,6 +53,8 @@ struct tpa6130a2_data {
  20. enum tpa_model id;
  21. };
  22. +static void tpa6130a2_channel_enable(u8 channel, int enable);
  23. +
  24. static int tpa6130a2_i2c_read(int reg)
  25. {
  26. struct tpa6130a2_data *data;
  27. @@ -189,7 +192,7 @@ exit:
  28. }
  29. static int tpa6130a2_get_volsw(struct snd_kcontrol *kcontrol,
  30. - struct snd_ctl_elem_value *ucontrol)
  31. + struct snd_ctl_elem_value *ucontrol)
  32. {
  33. struct soc_mixer_control *mc =
  34. (struct soc_mixer_control *)kcontrol->private_value;
  35. @@ -218,7 +221,7 @@ static int tpa6130a2_get_volsw(struct sn
  36. }
  37. static int tpa6130a2_put_volsw(struct snd_kcontrol *kcontrol,
  38. - struct snd_ctl_elem_value *ucontrol)
  39. + struct snd_ctl_elem_value *ucontrol)
  40. {
  41. struct soc_mixer_control *mc =
  42. (struct soc_mixer_control *)kcontrol->private_value;
  43. @@ -255,8 +258,22 @@ static int tpa6130a2_put_volsw(struct sn
  44. return 1;
  45. }
  46. +static int tpa6130a2_put_hp_sw(struct snd_kcontrol *kcontrol,
  47. + struct snd_ctl_elem_value *ucontrol)
  48. +{
  49. + int enable = ucontrol->value.integer.value[0];
  50. + unsigned int state;
  51. +
  52. + state = (tpa6130a2_read(TPA6130A2_REG_VOL_MUTE) & 0x80) == 0;
  53. + if (state == enable)
  54. + return 0; /* No change */
  55. +
  56. + tpa6130a2_channel_enable(TPA6130A2_HP_EN_R | TPA6130A2_HP_EN_L, enable);
  57. + return 1; /* Changed */
  58. +}
  59. +
  60. /*
  61. - * TPA6130 volume. From -59.5 to 4 dB with increasing step size when going
  62. + * TPA6130 volume. From -59.5 to +4.0 dB with increasing step size when going
  63. * down in gain.
  64. */
  65. static const DECLARE_TLV_DB_RANGE(tpa6130_tlv,
  66. @@ -277,6 +294,9 @@ static const struct snd_kcontrol_new tpa
  67. TPA6130A2_REG_VOL_MUTE, 0, 0x3f, 0,
  68. tpa6130a2_get_volsw, tpa6130a2_put_volsw,
  69. tpa6130_tlv),
  70. + SOC_SINGLE_EXT("TPA6130A2 Headphone Playback Switch",
  71. + TPA6130A2_REG_VOL_MUTE, 7, 1, 1,
  72. + tpa6130a2_get_volsw, tpa6130a2_put_hp_sw),
  73. };
  74. static const DECLARE_TLV_DB_RANGE(tpa6140_tlv,
  75. @@ -290,6 +310,9 @@ static const struct snd_kcontrol_new tpa
  76. TPA6130A2_REG_VOL_MUTE, 1, 0x1f, 0,
  77. tpa6130a2_get_volsw, tpa6130a2_put_volsw,
  78. tpa6140_tlv),
  79. + SOC_SINGLE_EXT("TPA6140A2 Headphone Playback Switch",
  80. + TPA6130A2_REG_VOL_MUTE, 7, 1, 1,
  81. + tpa6130a2_get_volsw, tpa6130a2_put_hp_sw),
  82. };
  83. /*