1 From 85ca6b17e2bb96b19caac3b02c003d670b66de96 Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Sun, 28 Jun 2020 17:52:28 +0200
4 Subject: ASoC: rt5670: Add new gpio1_is_ext_spk_en quirk and enable it on the Lenovo Miix 2 10
6 From: Hans de Goede <hdegoede@redhat.com>
8 commit 85ca6b17e2bb96b19caac3b02c003d670b66de96 upstream.
10 The Lenovo Miix 2 10 has a keyboard dock with extra speakers in the dock.
11 Rather then the ACL5672's GPIO1 pin being used as IRQ to the CPU, it is
12 actually used to enable the amplifier for these speakers
13 (the IRQ to the CPU comes directly from the jack-detect switch).
15 Add a quirk for having an ext speaker-amplifier enable pin on GPIO1
16 and replace the Lenovo Miix 2 10's dmi_system_id table entry's wrong
17 GPIO_DEV quirk (which needs to be renamed to GPIO1_IS_IRQ) with the
18 new RT5670_GPIO1_IS_EXT_SPK_EN quirk, so that we enable the external
19 speaker-amplifier as necessary.
21 Also update the ident field for the dmi_system_id table entry, the
22 Miix models are not Thinkpads.
24 Fixes: 67e03ff3f32f ("ASoC: codecs: rt5670: add Thinkpad Tablet 10 quirk")
25 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
26 BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1786723
27 Link: https://lore.kernel.org/r/20200628155231.71089-4-hdegoede@redhat.com
28 Signed-off-by: Mark Brown <broonie@kernel.org>
29 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
32 include/sound/rt5670.h | 1
33 sound/soc/codecs/rt5670.c | 71 ++++++++++++++++++++++++++++++++++++----------
34 2 files changed, 57 insertions(+), 15 deletions(-)
36 --- a/include/sound/rt5670.h
37 +++ b/include/sound/rt5670.h
38 @@ -15,6 +15,7 @@ struct rt5670_platform_data {
42 + bool gpio1_is_ext_spk_en;
45 unsigned int dmic1_data_pin;
46 --- a/sound/soc/codecs/rt5670.c
47 +++ b/sound/soc/codecs/rt5670.c
50 #include "rt5670-dsp.h"
52 -#define RT5670_DEV_GPIO BIT(0)
53 -#define RT5670_IN2_DIFF BIT(1)
54 -#define RT5670_DMIC_EN BIT(2)
55 -#define RT5670_DMIC1_IN2P BIT(3)
56 -#define RT5670_DMIC1_GPIO6 BIT(4)
57 -#define RT5670_DMIC1_GPIO7 BIT(5)
58 -#define RT5670_DMIC2_INR BIT(6)
59 -#define RT5670_DMIC2_GPIO8 BIT(7)
60 -#define RT5670_DMIC3_GPIO5 BIT(8)
61 -#define RT5670_JD_MODE1 BIT(9)
62 -#define RT5670_JD_MODE2 BIT(10)
63 -#define RT5670_JD_MODE3 BIT(11)
64 +#define RT5670_DEV_GPIO BIT(0)
65 +#define RT5670_IN2_DIFF BIT(1)
66 +#define RT5670_DMIC_EN BIT(2)
67 +#define RT5670_DMIC1_IN2P BIT(3)
68 +#define RT5670_DMIC1_GPIO6 BIT(4)
69 +#define RT5670_DMIC1_GPIO7 BIT(5)
70 +#define RT5670_DMIC2_INR BIT(6)
71 +#define RT5670_DMIC2_GPIO8 BIT(7)
72 +#define RT5670_DMIC3_GPIO5 BIT(8)
73 +#define RT5670_JD_MODE1 BIT(9)
74 +#define RT5670_JD_MODE2 BIT(10)
75 +#define RT5670_JD_MODE3 BIT(11)
76 +#define RT5670_GPIO1_IS_EXT_SPK_EN BIT(12)
78 static unsigned long rt5670_quirk;
79 static unsigned int quirk_override;
80 @@ -1504,6 +1505,33 @@ static int rt5670_hp_event(struct snd_so
84 +static int rt5670_spk_event(struct snd_soc_dapm_widget *w,
85 + struct snd_kcontrol *kcontrol, int event)
87 + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
88 + struct rt5670_priv *rt5670 = snd_soc_component_get_drvdata(component);
90 + if (!rt5670->pdata.gpio1_is_ext_spk_en)
94 + case SND_SOC_DAPM_POST_PMU:
95 + regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL2,
96 + RT5670_GP1_OUT_MASK, RT5670_GP1_OUT_HI);
99 + case SND_SOC_DAPM_PRE_PMD:
100 + regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL2,
101 + RT5670_GP1_OUT_MASK, RT5670_GP1_OUT_LO);
111 static int rt5670_bst1_event(struct snd_soc_dapm_widget *w,
112 struct snd_kcontrol *kcontrol, int event)
114 @@ -1917,7 +1945,9 @@ static const struct snd_soc_dapm_widget
117 static const struct snd_soc_dapm_widget rt5672_specific_dapm_widgets[] = {
118 - SND_SOC_DAPM_PGA("SPO Amp", SND_SOC_NOPM, 0, 0, NULL, 0),
119 + SND_SOC_DAPM_PGA_E("SPO Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
120 + rt5670_spk_event, SND_SOC_DAPM_PRE_PMD |
121 + SND_SOC_DAPM_POST_PMU),
122 SND_SOC_DAPM_OUTPUT("SPOLP"),
123 SND_SOC_DAPM_OUTPUT("SPOLN"),
124 SND_SOC_DAPM_OUTPUT("SPORP"),
125 @@ -2901,14 +2931,14 @@ static const struct dmi_system_id dmi_pl
128 .callback = rt5670_quirk_cb,
129 - .ident = "Lenovo Thinkpad Tablet 10",
130 + .ident = "Lenovo Miix 2 10",
132 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
133 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Miix 2 10"),
135 .driver_data = (unsigned long *)(RT5670_DMIC_EN |
138 + RT5670_GPIO1_IS_EXT_SPK_EN |
142 @@ -2956,6 +2986,10 @@ static int rt5670_i2c_probe(struct i2c_c
143 rt5670->pdata.dev_gpio = true;
144 dev_info(&i2c->dev, "quirk dev_gpio\n");
146 + if (rt5670_quirk & RT5670_GPIO1_IS_EXT_SPK_EN) {
147 + rt5670->pdata.gpio1_is_ext_spk_en = true;
148 + dev_info(&i2c->dev, "quirk GPIO1 is external speaker enable\n");
150 if (rt5670_quirk & RT5670_IN2_DIFF) {
151 rt5670->pdata.in2_diff = true;
152 dev_info(&i2c->dev, "quirk IN2_DIFF\n");
153 @@ -3054,6 +3088,13 @@ static int rt5670_i2c_probe(struct i2c_c
154 regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL2,
155 RT5670_GP1_PF_MASK, RT5670_GP1_PF_OUT);
158 + if (rt5670->pdata.gpio1_is_ext_spk_en) {
159 + regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL1,
160 + RT5670_GP1_PIN_MASK, RT5670_GP1_PIN_GPIO1);
161 + regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL2,
162 + RT5670_GP1_PF_MASK, RT5670_GP1_PF_OUT);
165 if (rt5670->pdata.jd_mode) {
166 regmap_update_bits(rt5670->regmap, RT5670_GLB_CLK,