From 5588ab110a0bfdeb5c249554969ab7be31516906 Mon Sep 17 00:00:00 2001 From: Richard Fitzgerald Date: Thu, 11 May 2017 10:20:50 +0100 Subject: [PATCH] extcon: madera: Skip HPDET ranges less than external resistance There is no point in running HPDET ranges that measure impedances lower than the external series resistance. Change-Id: I4e084d306d069a0ef049a22011653694744ca6b0 Signed-off-by: Richard Fitzgerald --- drivers/extcon/extcon-madera.c | 26 +++++++++++++++++++++++--- include/linux/extcon/extcon-madera.h | 1 + 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/drivers/extcon/extcon-madera.c b/drivers/extcon/extcon-madera.c index 7edfc75d44c6..4c7b10249a6b 100644 --- a/drivers/extcon/extcon-madera.c +++ b/drivers/extcon/extcon-madera.c @@ -1556,7 +1556,9 @@ void madera_hpdet_restart(struct madera_extcon *info) MADERA_MICD_ENA_MASK, 0); regmap_update_bits(madera->regmap, MADERA_HEADPHONE_DETECT_1, - MADERA_HP_IMPEDANCE_RANGE_MASK | MADERA_HP_POLL, 0); + MADERA_HP_IMPEDANCE_RANGE_MASK | MADERA_HP_POLL, + info->hpdet_init_range << + MADERA_HP_IMPEDANCE_RANGE_SHIFT); switch (madera->type) { case CS47L35: @@ -1617,7 +1619,9 @@ void madera_hpdet_stop(struct madera_extcon *info) madera_hpdet_stop_micd(info); regmap_update_bits(madera->regmap, MADERA_HEADPHONE_DETECT_1, - MADERA_HP_IMPEDANCE_RANGE_MASK | MADERA_HP_POLL, 0); + MADERA_HP_IMPEDANCE_RANGE_MASK | MADERA_HP_POLL, + info->hpdet_init_range << + MADERA_HP_IMPEDANCE_RANGE_SHIFT); switch (madera->type) { case CS47L35: @@ -2821,7 +2825,7 @@ static int madera_extcon_probe(struct platform_device *pdev) struct madera_extcon *info; unsigned int debounce_val, analog_val; int jack_irq_fall, jack_irq_rise; - int ret, mode; + int ret, mode, i; /* quick exit if Madera irqchip driver hasn't completed probe */ if (!madera->irq_dev) { @@ -3039,6 +3043,22 @@ static int madera_extcon_probe(struct platform_device *pdev) } } + /* Skip any HPDET ranges less than the external resistance */ + for (i = 0; i < info->num_hpdet_ranges; ++i) { + if (madera_ohm_to_hohm(info->hpdet_ranges[i].max) >= + pdata->hpdet_ext_res_x100) { + info->hpdet_init_range = i; + break; + } + } + if (i == info->num_hpdet_ranges) { + dev_err(&pdev->dev, + "No possible range for external resistance %u.%02u\n", + pdata->hpdet_ext_res_x100 / 100, + pdata->hpdet_ext_res_x100 % 100); + goto err_input; + } + if (info->pdata->jd_use_jd2) { jack_irq_rise = MADERA_IRQ_MICD_CLAMP_RISE; jack_irq_fall = MADERA_IRQ_MICD_CLAMP_FALL; diff --git a/include/linux/extcon/extcon-madera.h b/include/linux/extcon/extcon-madera.h index a9ea89d1a451..407c6df7d46e 100644 --- a/include/linux/extcon/extcon-madera.h +++ b/include/linux/extcon/extcon-madera.h @@ -77,6 +77,7 @@ struct madera_extcon { const struct madera_hpdet_calibration_data *hpdet_ranges; int num_hpdet_ranges; + unsigned int hpdet_init_range; const struct madera_hpdet_trims *hpdet_trims; int micd_mode; -- 2.20.1