Commit 77eca00f authored by Mark Brown's avatar Mark Brown

Merge series "ASoC: Intel/rt5640: Add support for HP Elite Pad 1000G2...

Merge series "ASoC: Intel/rt5640: Add support for HP Elite Pad 1000G2 jack-detect" from Hans de Goede <hdegoede@redhat.com>:

Changes in v2:
- Rebase on asoc/for-next
- New patch: "ASoC: Intel: bytct_rt5640: Add a separate "Headset Mic 2"
  DAPM pin for the mic on the 2nd jack"
- Addressed Pierre-Louis' comments about calling
  acpi_dev_add_driver_gpios() twice

Original cover-letter:

The HP Elitepad 1000 G2 tablet has 2 headset jacks:

1. on the dock which uses the output of the codecs built-in HP-amp +
the standard IN2 input which is always used with the headset-jack.

2. on the tablet itself, this uses the line-out of the codec + an external
HP-amp, which gets enabled by the ALC5642 codec's GPIO1 pin; and IN1 for
the headset-mic.

The codec's GPIO1 is also its only IRQ output pin, so this means that
the codec's IRQ cannot be used on this tablet. Instead the jack-detect
is connected directly to GPIOs on the main SoC. The dock has a helper
chip which also detects if a headset-mic is present or not, so there
are 2 GPIOs for the jack-detect status of the dock. The tablet jack
uses a single GPIO which indicates if a jack is present or not.

Differentiating between between headphones vs a headset on the tablet jack
is done by using the usual mic-bias over-current-detection mechanism.

Regards,

Hans

Hans de Goede (6):
  ASoC: rt5640: Move rt5640_disable_jack_detect() up in the rt5640.c
    file
  ASoC: rt5640: Delay requesting IRQ until the machine-drv calls
    set_jack
  ASoC: rt5640: Add optional hp_det_gpio parameter to
    rt5640_detect_headset()
  ASoC: rt5640: Add rt5640_set_ovcd_params() helper
  ASoC: Intel: bytct_rt5640: Add a separate "Headset Mic 2" DAPM pin for
    the mic on the 2nd jack
  ASoC: Intel: bytcr_rt5640: Add support for HP Elite Pad 1000G2
    jack-detect

 sound/soc/codecs/rt5640.c             | 136 ++++++++++++----------
 sound/soc/codecs/rt5640.h             |   6 +
 sound/soc/intel/boards/bytcr_rt5640.c | 158 +++++++++++++++++++++++++-
 3 files changed, 234 insertions(+), 66 deletions(-)

--
2.31.1
parents cc64c390 9ba00856
...@@ -2093,7 +2093,7 @@ int rt5640_sel_asrc_clk_src(struct snd_soc_component *component, ...@@ -2093,7 +2093,7 @@ int rt5640_sel_asrc_clk_src(struct snd_soc_component *component,
} }
EXPORT_SYMBOL_GPL(rt5640_sel_asrc_clk_src); EXPORT_SYMBOL_GPL(rt5640_sel_asrc_clk_src);
static void rt5640_enable_micbias1_for_ovcd(struct snd_soc_component *component) void rt5640_enable_micbias1_for_ovcd(struct snd_soc_component *component)
{ {
struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
...@@ -2105,8 +2105,9 @@ static void rt5640_enable_micbias1_for_ovcd(struct snd_soc_component *component) ...@@ -2105,8 +2105,9 @@ static void rt5640_enable_micbias1_for_ovcd(struct snd_soc_component *component)
snd_soc_dapm_sync_unlocked(dapm); snd_soc_dapm_sync_unlocked(dapm);
snd_soc_dapm_mutex_unlock(dapm); snd_soc_dapm_mutex_unlock(dapm);
} }
EXPORT_SYMBOL_GPL(rt5640_enable_micbias1_for_ovcd);
static void rt5640_disable_micbias1_for_ovcd(struct snd_soc_component *component) void rt5640_disable_micbias1_for_ovcd(struct snd_soc_component *component)
{ {
struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
...@@ -2117,6 +2118,7 @@ static void rt5640_disable_micbias1_for_ovcd(struct snd_soc_component *component ...@@ -2117,6 +2118,7 @@ static void rt5640_disable_micbias1_for_ovcd(struct snd_soc_component *component
snd_soc_dapm_sync_unlocked(dapm); snd_soc_dapm_sync_unlocked(dapm);
snd_soc_dapm_mutex_unlock(dapm); snd_soc_dapm_mutex_unlock(dapm);
} }
EXPORT_SYMBOL_GPL(rt5640_disable_micbias1_for_ovcd);
static void rt5640_enable_micbias1_ovcd_irq(struct snd_soc_component *component) static void rt5640_enable_micbias1_ovcd_irq(struct snd_soc_component *component)
{ {
...@@ -2241,7 +2243,7 @@ static void rt5640_button_press_work(struct work_struct *work) ...@@ -2241,7 +2243,7 @@ static void rt5640_button_press_work(struct work_struct *work)
schedule_delayed_work(&rt5640->bp_work, msecs_to_jiffies(BP_POLL_TIME)); schedule_delayed_work(&rt5640->bp_work, msecs_to_jiffies(BP_POLL_TIME));
} }
static int rt5640_detect_headset(struct snd_soc_component *component) int rt5640_detect_headset(struct snd_soc_component *component, struct gpio_desc *hp_det_gpio)
{ {
int i, headset_count = 0, headphone_count = 0; int i, headset_count = 0, headphone_count = 0;
...@@ -2259,8 +2261,13 @@ static int rt5640_detect_headset(struct snd_soc_component *component) ...@@ -2259,8 +2261,13 @@ static int rt5640_detect_headset(struct snd_soc_component *component)
msleep(JACK_SETTLE_TIME); msleep(JACK_SETTLE_TIME);
/* Check the jack is still connected before checking ovcd */ /* Check the jack is still connected before checking ovcd */
if (hp_det_gpio) {
if (gpiod_get_value_cansleep(hp_det_gpio))
return 0;
} else {
if (!rt5640_jack_inserted(component)) if (!rt5640_jack_inserted(component))
return 0; return 0;
}
if (rt5640_micbias1_ovcd(component)) { if (rt5640_micbias1_ovcd(component)) {
/* /*
...@@ -2285,6 +2292,7 @@ static int rt5640_detect_headset(struct snd_soc_component *component) ...@@ -2285,6 +2292,7 @@ static int rt5640_detect_headset(struct snd_soc_component *component)
dev_err(component->dev, "Error detecting headset vs headphones, bad contact?, assuming headphones\n"); dev_err(component->dev, "Error detecting headset vs headphones, bad contact?, assuming headphones\n");
return SND_JACK_HEADPHONE; return SND_JACK_HEADPHONE;
} }
EXPORT_SYMBOL_GPL(rt5640_detect_headset);
static void rt5640_jack_work(struct work_struct *work) static void rt5640_jack_work(struct work_struct *work)
{ {
...@@ -2309,7 +2317,7 @@ static void rt5640_jack_work(struct work_struct *work) ...@@ -2309,7 +2317,7 @@ static void rt5640_jack_work(struct work_struct *work)
/* Jack inserted */ /* Jack inserted */
WARN_ON(rt5640->ovcd_irq_enabled); WARN_ON(rt5640->ovcd_irq_enabled);
rt5640_enable_micbias1_for_ovcd(component); rt5640_enable_micbias1_for_ovcd(component);
status = rt5640_detect_headset(component); status = rt5640_detect_headset(component, NULL);
if (status == SND_JACK_HEADSET) { if (status == SND_JACK_HEADSET) {
/* Enable ovcd IRQ for button press detect. */ /* Enable ovcd IRQ for button press detect. */
rt5640_enable_micbias1_ovcd_irq(component); rt5640_enable_micbias1_ovcd_irq(component);
...@@ -2362,10 +2370,59 @@ static void rt5640_cancel_work(void *data) ...@@ -2362,10 +2370,59 @@ static void rt5640_cancel_work(void *data)
cancel_delayed_work_sync(&rt5640->bp_work); cancel_delayed_work_sync(&rt5640->bp_work);
} }
void rt5640_set_ovcd_params(struct snd_soc_component *component)
{
struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
snd_soc_component_write(component, RT5640_PR_BASE + RT5640_BIAS_CUR4,
0xa800 | rt5640->ovcd_sf);
snd_soc_component_update_bits(component, RT5640_MICBIAS,
RT5640_MIC1_OVTH_MASK | RT5640_MIC1_OVCD_MASK,
rt5640->ovcd_th | RT5640_MIC1_OVCD_EN);
/*
* The over-current-detect is only reliable in detecting the absence
* of over-current, when the mic-contact in the jack is short-circuited,
* the hardware periodically retries if it can apply the bias-current
* leading to the ovcd status flip-flopping 1-0-1 with it being 0 about
* 10% of the time, as we poll the ovcd status bit we might hit that
* 10%, so we enable sticky mode and when checking OVCD we clear the
* status, msleep() a bit and then check to get a reliable reading.
*/
snd_soc_component_update_bits(component, RT5640_IRQ_CTRL2,
RT5640_MB1_OC_STKY_MASK, RT5640_MB1_OC_STKY_EN);
}
EXPORT_SYMBOL_GPL(rt5640_set_ovcd_params);
static void rt5640_disable_jack_detect(struct snd_soc_component *component)
{
struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
/*
* soc_remove_component() force-disables jack and thus rt5640->jack
* could be NULL at the time of driver's module unloading.
*/
if (!rt5640->jack)
return;
free_irq(rt5640->irq, rt5640);
rt5640_cancel_work(rt5640);
if (rt5640->jack->status & SND_JACK_MICROPHONE) {
rt5640_disable_micbias1_ovcd_irq(component);
rt5640_disable_micbias1_for_ovcd(component);
snd_soc_jack_report(rt5640->jack, 0, SND_JACK_BTN_0);
}
rt5640->jack = NULL;
}
static void rt5640_enable_jack_detect(struct snd_soc_component *component, static void rt5640_enable_jack_detect(struct snd_soc_component *component,
struct snd_soc_jack *jack) struct snd_soc_jack *jack)
{ {
struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component); struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
int ret;
/* Select JD-source */ /* Select JD-source */
snd_soc_component_update_bits(component, RT5640_JD_CTRL, snd_soc_component_update_bits(component, RT5640_JD_CTRL,
...@@ -2385,24 +2442,7 @@ static void rt5640_enable_jack_detect(struct snd_soc_component *component, ...@@ -2385,24 +2442,7 @@ static void rt5640_enable_jack_detect(struct snd_soc_component *component,
/* Enabling jd2 in general control 2 */ /* Enabling jd2 in general control 2 */
snd_soc_component_write(component, RT5640_DUMMY2, 0x4001); snd_soc_component_write(component, RT5640_DUMMY2, 0x4001);
snd_soc_component_write(component, RT5640_PR_BASE + RT5640_BIAS_CUR4, rt5640_set_ovcd_params(component);
0xa800 | rt5640->ovcd_sf);
snd_soc_component_update_bits(component, RT5640_MICBIAS,
RT5640_MIC1_OVTH_MASK | RT5640_MIC1_OVCD_MASK,
rt5640->ovcd_th | RT5640_MIC1_OVCD_EN);
/*
* The over-current-detect is only reliable in detecting the absence
* of over-current, when the mic-contact in the jack is short-circuited,
* the hardware periodically retries if it can apply the bias-current
* leading to the ovcd status flip-flopping 1-0-1 with it being 0 about
* 10% of the time, as we poll the ovcd status bit we might hit that
* 10%, so we enable sticky mode and when checking OVCD we clear the
* status, msleep() a bit and then check to get a reliable reading.
*/
snd_soc_component_update_bits(component, RT5640_IRQ_CTRL2,
RT5640_MB1_OC_STKY_MASK, RT5640_MB1_OC_STKY_EN);
/* /*
* All IRQs get or-ed together, so we need the jack IRQ to report 0 * All IRQs get or-ed together, so we need the jack IRQ to report 0
...@@ -2423,32 +2463,19 @@ static void rt5640_enable_jack_detect(struct snd_soc_component *component, ...@@ -2423,32 +2463,19 @@ static void rt5640_enable_jack_detect(struct snd_soc_component *component,
rt5640_enable_micbias1_ovcd_irq(component); rt5640_enable_micbias1_ovcd_irq(component);
} }
enable_irq(rt5640->irq); ret = request_irq(rt5640->irq, rt5640_irq,
/* sync initial jack state */ IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
queue_work(system_long_wq, &rt5640->jack_work); "rt5640", rt5640);
} if (ret) {
dev_warn(component->dev, "Failed to reguest IRQ %d: %d\n", rt5640->irq, ret);
static void rt5640_disable_jack_detect(struct snd_soc_component *component) rt5640->irq = -ENXIO;
{ /* Undo above settings */
struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component); rt5640_disable_jack_detect(component);
/*
* soc_remove_component() force-disables jack and thus rt5640->jack
* could be NULL at the time of driver's module unloading.
*/
if (!rt5640->jack)
return; return;
disable_irq(rt5640->irq);
rt5640_cancel_work(rt5640);
if (rt5640->jack->status & SND_JACK_MICROPHONE) {
rt5640_disable_micbias1_ovcd_irq(component);
rt5640_disable_micbias1_for_ovcd(component);
snd_soc_jack_report(rt5640->jack, 0, SND_JACK_BTN_0);
} }
rt5640->jack = NULL; /* sync initial jack state */
queue_work(system_long_wq, &rt5640->jack_work);
} }
static int rt5640_set_jack(struct snd_soc_component *component, static int rt5640_set_jack(struct snd_soc_component *component,
...@@ -2836,21 +2863,6 @@ static int rt5640_i2c_probe(struct i2c_client *i2c, ...@@ -2836,21 +2863,6 @@ static int rt5640_i2c_probe(struct i2c_client *i2c,
if (ret) if (ret)
return ret; return ret;
if (rt5640->irq) {
/* enabled by rt5640_set_jack() */
ret = devm_request_irq(&i2c->dev, rt5640->irq, rt5640_irq,
IRQF_TRIGGER_RISING | IRQF_NO_AUTOEN |
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
"rt5640", rt5640);
if (ret) {
dev_err(&i2c->dev, "Failed to request IRQ %d: %d\n",
rt5640->irq, ret);
return ret;
}
} else {
rt5640->irq = -ENXIO;
}
return devm_snd_soc_register_component(&i2c->dev, return devm_snd_soc_register_component(&i2c->dev,
&soc_component_dev_rt5640, &soc_component_dev_rt5640,
rt5640_dai, ARRAY_SIZE(rt5640_dai)); rt5640_dai, ARRAY_SIZE(rt5640_dai));
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#define _RT5640_H #define _RT5640_H
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/gpio/consumer.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <dt-bindings/sound/rt5640.h> #include <dt-bindings/sound/rt5640.h>
...@@ -2157,4 +2158,9 @@ int rt5640_dmic_enable(struct snd_soc_component *component, ...@@ -2157,4 +2158,9 @@ int rt5640_dmic_enable(struct snd_soc_component *component,
int rt5640_sel_asrc_clk_src(struct snd_soc_component *component, int rt5640_sel_asrc_clk_src(struct snd_soc_component *component,
unsigned int filter_mask, unsigned int clk_src); unsigned int filter_mask, unsigned int clk_src);
void rt5640_set_ovcd_params(struct snd_soc_component *component);
void rt5640_enable_micbias1_for_ovcd(struct snd_soc_component *component);
void rt5640_disable_micbias1_for_ovcd(struct snd_soc_component *component);
int rt5640_detect_headset(struct snd_soc_component *component, struct gpio_desc *hp_det_gpio);
#endif #endif
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/dmi.h> #include <linux/dmi.h>
#include <linux/gpio/consumer.h>
#include <linux/gpio/machine.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <sound/pcm.h> #include <sound/pcm.h>
...@@ -76,6 +78,7 @@ enum { ...@@ -76,6 +78,7 @@ enum {
#define BYT_RT5640_LINEOUT BIT(25) #define BYT_RT5640_LINEOUT BIT(25)
#define BYT_RT5640_LINEOUT_AS_HP2 BIT(26) #define BYT_RT5640_LINEOUT_AS_HP2 BIT(26)
#define BYT_RT5640_HSMIC2_ON_IN1 BIT(27) #define BYT_RT5640_HSMIC2_ON_IN1 BIT(27)
#define BYT_RT5640_JD_HP_ELITEP_1000G2 BIT(28)
#define BYTCR_INPUT_DEFAULTS \ #define BYTCR_INPUT_DEFAULTS \
(BYT_RT5640_IN3_MAP | \ (BYT_RT5640_IN3_MAP | \
...@@ -89,6 +92,8 @@ enum { ...@@ -89,6 +92,8 @@ enum {
struct byt_rt5640_private { struct byt_rt5640_private {
struct snd_soc_jack jack; struct snd_soc_jack jack;
struct snd_soc_jack jack2;
struct gpio_desc *hsmic_detect;
struct clk *mclk; struct clk *mclk;
struct device *codec_dev; struct device *codec_dev;
}; };
...@@ -141,6 +146,8 @@ static void log_quirks(struct device *dev) ...@@ -141,6 +146,8 @@ static void log_quirks(struct device *dev)
} }
if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV) if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
dev_info(dev, "quirk JD_NOT_INV enabled\n"); dev_info(dev, "quirk JD_NOT_INV enabled\n");
if (byt_rt5640_quirk & BYT_RT5640_JD_HP_ELITEP_1000G2)
dev_info(dev, "quirk JD_HP_ELITEPAD_1000G2 enabled\n");
if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER)
dev_info(dev, "quirk MONO_SPEAKER enabled\n"); dev_info(dev, "quirk MONO_SPEAKER enabled\n");
if (byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS) if (byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS)
...@@ -324,6 +331,7 @@ static int byt_rt5640_event_lineout(struct snd_soc_dapm_widget *w, ...@@ -324,6 +331,7 @@ static int byt_rt5640_event_lineout(struct snd_soc_dapm_widget *w,
static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = { static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
SND_SOC_DAPM_HP("Headphone", NULL), SND_SOC_DAPM_HP("Headphone", NULL),
SND_SOC_DAPM_MIC("Headset Mic", NULL), SND_SOC_DAPM_MIC("Headset Mic", NULL),
SND_SOC_DAPM_MIC("Headset Mic 2", NULL),
SND_SOC_DAPM_MIC("Internal Mic", NULL), SND_SOC_DAPM_MIC("Internal Mic", NULL),
SND_SOC_DAPM_SPK("Speaker", NULL), SND_SOC_DAPM_SPK("Speaker", NULL),
SND_SOC_DAPM_LINE("Line Out", byt_rt5640_event_lineout), SND_SOC_DAPM_LINE("Line Out", byt_rt5640_event_lineout),
...@@ -363,6 +371,12 @@ static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = { ...@@ -363,6 +371,12 @@ static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = {
{"IN3P", NULL, "Internal Mic"}, {"IN3P", NULL, "Internal Mic"},
}; };
static const struct snd_soc_dapm_route byt_rt5640_hsmic2_in1_map[] = {
{"Headset Mic 2", NULL, "Platform Clock"},
{"Headset Mic 2", NULL, "MICBIAS1"},
{"IN1P", NULL, "Headset Mic 2"},
};
static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = { static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
{"ssp2 Tx", NULL, "codec_out0"}, {"ssp2 Tx", NULL, "codec_out0"},
{"ssp2 Tx", NULL, "codec_out1"}, {"ssp2 Tx", NULL, "codec_out1"},
...@@ -422,6 +436,7 @@ static const struct snd_soc_dapm_route byt_rt5640_lineout_map[] = { ...@@ -422,6 +436,7 @@ static const struct snd_soc_dapm_route byt_rt5640_lineout_map[] = {
static const struct snd_kcontrol_new byt_rt5640_controls[] = { static const struct snd_kcontrol_new byt_rt5640_controls[] = {
SOC_DAPM_PIN_SWITCH("Headphone"), SOC_DAPM_PIN_SWITCH("Headphone"),
SOC_DAPM_PIN_SWITCH("Headset Mic"), SOC_DAPM_PIN_SWITCH("Headset Mic"),
SOC_DAPM_PIN_SWITCH("Headset Mic 2"),
SOC_DAPM_PIN_SWITCH("Internal Mic"), SOC_DAPM_PIN_SWITCH("Internal Mic"),
SOC_DAPM_PIN_SWITCH("Speaker"), SOC_DAPM_PIN_SWITCH("Speaker"),
SOC_DAPM_PIN_SWITCH("Line Out"), SOC_DAPM_PIN_SWITCH("Line Out"),
...@@ -438,6 +453,75 @@ static struct snd_soc_jack_pin rt5640_pins[] = { ...@@ -438,6 +453,75 @@ static struct snd_soc_jack_pin rt5640_pins[] = {
}, },
}; };
static struct snd_soc_jack_pin rt5640_pins2[] = {
{
/* The 2nd headset jack uses lineout with an external HP-amp */
.pin = "Line Out",
.mask = SND_JACK_HEADPHONE,
},
{
.pin = "Headset Mic 2",
.mask = SND_JACK_MICROPHONE,
},
};
struct snd_soc_jack_gpio rt5640_jack_gpio = {
.name = "hp-detect",
.report = SND_JACK_HEADSET,
.invert = true,
.debounce_time = 200,
};
struct snd_soc_jack_gpio rt5640_jack2_gpio = {
.name = "hp2-detect",
.report = SND_JACK_HEADSET,
.invert = true,
.debounce_time = 200,
};
static const struct acpi_gpio_params acpi_gpio0 = { 0, 0, false };
static const struct acpi_gpio_params acpi_gpio1 = { 1, 0, false };
static const struct acpi_gpio_params acpi_gpio2 = { 2, 0, false };
static const struct acpi_gpio_mapping byt_rt5640_hp_elitepad_1000g2_gpios[] = {
{ "hp-detect-gpios", &acpi_gpio0, 1, },
{ "headset-mic-detect-gpios", &acpi_gpio1, 1, },
{ "hp2-detect-gpios", &acpi_gpio2, 1, },
{ },
};
int byt_rt5640_hp_elitepad_1000g2_jack1_check(void *data)
{
struct byt_rt5640_private *priv = data;
int jack_status, mic_status;
jack_status = gpiod_get_value_cansleep(rt5640_jack_gpio.desc);
if (jack_status)
return 0;
mic_status = gpiod_get_value_cansleep(priv->hsmic_detect);
if (mic_status)
return SND_JACK_HEADPHONE;
else
return SND_JACK_HEADSET;
}
int byt_rt5640_hp_elitepad_1000g2_jack2_check(void *data)
{
struct snd_soc_component *component = data;
int jack_status, report;
jack_status = gpiod_get_value_cansleep(rt5640_jack2_gpio.desc);
if (jack_status)
return 0;
rt5640_enable_micbias1_for_ovcd(component);
report = rt5640_detect_headset(component, rt5640_jack2_gpio.desc);
rt5640_disable_micbias1_for_ovcd(component);
return report;
}
static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream, static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params) struct snd_pcm_hw_params *params)
{ {
...@@ -649,7 +733,8 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { ...@@ -649,7 +733,8 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = {
BYT_RT5640_MCLK_EN | BYT_RT5640_MCLK_EN |
BYT_RT5640_LINEOUT | BYT_RT5640_LINEOUT |
BYT_RT5640_LINEOUT_AS_HP2 | BYT_RT5640_LINEOUT_AS_HP2 |
BYT_RT5640_HSMIC2_ON_IN1), BYT_RT5640_HSMIC2_ON_IN1 |
BYT_RT5640_JD_HP_ELITEP_1000G2),
}, },
{ /* HP Pavilion x2 10-k0XX, 10-n0XX */ { /* HP Pavilion x2 10-k0XX, 10-n0XX */
.matches = { .matches = {
...@@ -1086,8 +1171,8 @@ static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime) ...@@ -1086,8 +1171,8 @@ static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
if (byt_rt5640_quirk & BYT_RT5640_HSMIC2_ON_IN1) { if (byt_rt5640_quirk & BYT_RT5640_HSMIC2_ON_IN1) {
ret = snd_soc_dapm_add_routes(&card->dapm, ret = snd_soc_dapm_add_routes(&card->dapm,
byt_rt5640_intmic_in1_map, byt_rt5640_hsmic2_in1_map,
ARRAY_SIZE(byt_rt5640_intmic_in1_map)); ARRAY_SIZE(byt_rt5640_hsmic2_in1_map));
if (ret) if (ret)
return ret; return ret;
} }
...@@ -1172,9 +1257,53 @@ static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime) ...@@ -1172,9 +1257,53 @@ static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
snd_soc_component_set_jack(component, &priv->jack, NULL); snd_soc_component_set_jack(component, &priv->jack, NULL);
} }
if (byt_rt5640_quirk & BYT_RT5640_JD_HP_ELITEP_1000G2) {
ret = snd_soc_card_jack_new(card, "Headset",
SND_JACK_HEADSET,
&priv->jack, rt5640_pins,
ARRAY_SIZE(rt5640_pins));
if (ret)
return ret;
ret = snd_soc_card_jack_new(card, "Headset 2",
SND_JACK_HEADSET,
&priv->jack2, rt5640_pins2,
ARRAY_SIZE(rt5640_pins2));
if (ret)
return ret;
rt5640_jack_gpio.data = priv;
rt5640_jack_gpio.gpiod_dev = priv->codec_dev;
rt5640_jack_gpio.jack_status_check = byt_rt5640_hp_elitepad_1000g2_jack1_check;
ret = snd_soc_jack_add_gpios(&priv->jack, 1, &rt5640_jack_gpio);
if (ret)
return ret;
rt5640_set_ovcd_params(component);
rt5640_jack2_gpio.data = component;
rt5640_jack2_gpio.gpiod_dev = priv->codec_dev;
rt5640_jack2_gpio.jack_status_check = byt_rt5640_hp_elitepad_1000g2_jack2_check;
ret = snd_soc_jack_add_gpios(&priv->jack2, 1, &rt5640_jack2_gpio);
if (ret) {
snd_soc_jack_free_gpios(&priv->jack, 1, &rt5640_jack_gpio);
return ret;
}
}
return 0; return 0;
} }
static void byt_rt5640_exit(struct snd_soc_pcm_runtime *runtime)
{
struct snd_soc_card *card = runtime->card;
struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
if (byt_rt5640_quirk & BYT_RT5640_JD_HP_ELITEP_1000G2) {
snd_soc_jack_free_gpios(&priv->jack2, 1, &rt5640_jack2_gpio);
snd_soc_jack_free_gpios(&priv->jack, 1, &rt5640_jack_gpio);
}
}
static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd, static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_hw_params *params) struct snd_pcm_hw_params *params)
{ {
...@@ -1287,6 +1416,7 @@ static struct snd_soc_dai_link byt_rt5640_dais[] = { ...@@ -1287,6 +1416,7 @@ static struct snd_soc_dai_link byt_rt5640_dais[] = {
.dpcm_playback = 1, .dpcm_playback = 1,
.dpcm_capture = 1, .dpcm_capture = 1,
.init = byt_rt5640_init, .init = byt_rt5640_init,
.exit = byt_rt5640_exit,
.ops = &byt_rt5640_be_ssp2_ops, .ops = &byt_rt5640_be_ssp2_ops,
SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform), SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),
}, },
...@@ -1490,10 +1620,24 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev) ...@@ -1490,10 +1620,24 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
return -EPROBE_DEFER; return -EPROBE_DEFER;
priv->codec_dev = get_device(codec_dev); priv->codec_dev = get_device(codec_dev);
if (byt_rt5640_quirk & BYT_RT5640_JD_HP_ELITEP_1000G2) {
acpi_dev_add_driver_gpios(ACPI_COMPANION(priv->codec_dev),
byt_rt5640_hp_elitepad_1000g2_gpios);
priv->hsmic_detect = devm_fwnode_gpiod_get(&pdev->dev, codec_dev->fwnode,
"headset-mic-detect", GPIOD_IN,
"headset-mic-detect");
if (IS_ERR(priv->hsmic_detect)) {
ret_val = PTR_ERR(priv->hsmic_detect);
dev_err_probe(&pdev->dev, ret_val, "getting hsmic-detect GPIO\n");
goto err_device;
}
}
/* Must be called before register_card, also see declaration comment. */ /* Must be called before register_card, also see declaration comment. */
ret_val = byt_rt5640_add_codec_device_props(codec_dev, priv); ret_val = byt_rt5640_add_codec_device_props(codec_dev, priv);
if (ret_val) if (ret_val)
goto err_device; goto err_remove_gpios;
log_quirks(&pdev->dev); log_quirks(&pdev->dev);
...@@ -1597,6 +1741,9 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev) ...@@ -1597,6 +1741,9 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
err: err:
device_remove_software_node(priv->codec_dev); device_remove_software_node(priv->codec_dev);
err_remove_gpios:
if (byt_rt5640_quirk & BYT_RT5640_JD_HP_ELITEP_1000G2)
acpi_dev_remove_driver_gpios(ACPI_COMPANION(priv->codec_dev));
err_device: err_device:
put_device(priv->codec_dev); put_device(priv->codec_dev);
return ret_val; return ret_val;
...@@ -1607,6 +1754,9 @@ static int snd_byt_rt5640_mc_remove(struct platform_device *pdev) ...@@ -1607,6 +1754,9 @@ static int snd_byt_rt5640_mc_remove(struct platform_device *pdev)
struct snd_soc_card *card = platform_get_drvdata(pdev); struct snd_soc_card *card = platform_get_drvdata(pdev);
struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card); struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
if (byt_rt5640_quirk & BYT_RT5640_JD_HP_ELITEP_1000G2)
acpi_dev_remove_driver_gpios(ACPI_COMPANION(priv->codec_dev));
device_remove_software_node(priv->codec_dev); device_remove_software_node(priv->codec_dev);
put_device(priv->codec_dev); put_device(priv->codec_dev);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment