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