Skip to content

Commit 3dfa743

Browse files
charleskeepaxchanwoochoi
authored andcommitted
extcon: arizona: Invert logic of check in arizona_hpdet_do_id
Invert the check of hpdet_acc_id at the top of arizona_hpdet_do_id to reduce the identation within the function. Signed-off-by: Charles Keepax <[email protected]> Signed-off-by: Chanwoo Choi <[email protected]>
1 parent 8267ebc commit 3dfa743

File tree

1 file changed

+45
-47
lines changed

1 file changed

+45
-47
lines changed

drivers/extcon/extcon-arizona.c

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -533,67 +533,65 @@ static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading,
533533
struct arizona *arizona = info->arizona;
534534
int id_gpio = arizona->pdata.hpdet_id_gpio;
535535

536+
if (!arizona->pdata.hpdet_acc_id)
537+
return 0;
538+
536539
/*
537540
* If we're using HPDET for accessory identification we need
538541
* to take multiple measurements, step through them in sequence.
539542
*/
540-
if (arizona->pdata.hpdet_acc_id) {
541-
info->hpdet_res[info->num_hpdet_res++] = *reading;
543+
info->hpdet_res[info->num_hpdet_res++] = *reading;
542544

543-
/* Only check the mic directly if we didn't already ID it */
544-
if (id_gpio && info->num_hpdet_res == 1) {
545-
dev_dbg(arizona->dev, "Measuring mic\n");
546-
547-
regmap_update_bits(arizona->regmap,
548-
ARIZONA_ACCESSORY_DETECT_MODE_1,
549-
ARIZONA_ACCDET_MODE_MASK |
550-
ARIZONA_ACCDET_SRC,
551-
ARIZONA_ACCDET_MODE_HPR |
552-
info->micd_modes[0].src);
545+
/* Only check the mic directly if we didn't already ID it */
546+
if (id_gpio && info->num_hpdet_res == 1) {
547+
dev_dbg(arizona->dev, "Measuring mic\n");
553548

554-
gpio_set_value_cansleep(id_gpio, 1);
549+
regmap_update_bits(arizona->regmap,
550+
ARIZONA_ACCESSORY_DETECT_MODE_1,
551+
ARIZONA_ACCDET_MODE_MASK |
552+
ARIZONA_ACCDET_SRC,
553+
ARIZONA_ACCDET_MODE_HPR |
554+
info->micd_modes[0].src);
555555

556-
regmap_update_bits(arizona->regmap,
557-
ARIZONA_HEADPHONE_DETECT_1,
558-
ARIZONA_HP_POLL, ARIZONA_HP_POLL);
559-
return -EAGAIN;
560-
}
556+
gpio_set_value_cansleep(id_gpio, 1);
561557

562-
/* OK, got both. Now, compare... */
563-
dev_dbg(arizona->dev, "HPDET measured %d %d\n",
564-
info->hpdet_res[0], info->hpdet_res[1]);
558+
regmap_update_bits(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
559+
ARIZONA_HP_POLL, ARIZONA_HP_POLL);
560+
return -EAGAIN;
561+
}
565562

566-
/* Take the headphone impedance for the main report */
567-
*reading = info->hpdet_res[0];
563+
/* OK, got both. Now, compare... */
564+
dev_dbg(arizona->dev, "HPDET measured %d %d\n",
565+
info->hpdet_res[0], info->hpdet_res[1]);
568566

569-
/* Sometimes we get false readings due to slow insert */
570-
if (*reading >= ARIZONA_HPDET_MAX && !info->hpdet_retried) {
571-
dev_dbg(arizona->dev, "Retrying high impedance\n");
572-
info->num_hpdet_res = 0;
573-
info->hpdet_retried = true;
574-
arizona_start_hpdet_acc_id(info);
575-
pm_runtime_put(info->dev);
576-
return -EAGAIN;
577-
}
567+
/* Take the headphone impedance for the main report */
568+
*reading = info->hpdet_res[0];
578569

579-
/*
580-
* If we measure the mic as high impedance
581-
*/
582-
if (!id_gpio || info->hpdet_res[1] > 50) {
583-
dev_dbg(arizona->dev, "Detected mic\n");
584-
*mic = true;
585-
info->detecting = true;
586-
} else {
587-
dev_dbg(arizona->dev, "Detected headphone\n");
588-
}
570+
/* Sometimes we get false readings due to slow insert */
571+
if (*reading >= ARIZONA_HPDET_MAX && !info->hpdet_retried) {
572+
dev_dbg(arizona->dev, "Retrying high impedance\n");
573+
info->num_hpdet_res = 0;
574+
info->hpdet_retried = true;
575+
arizona_start_hpdet_acc_id(info);
576+
pm_runtime_put(info->dev);
577+
return -EAGAIN;
578+
}
589579

590-
/* Make sure everything is reset back to the real polarity */
591-
regmap_update_bits(arizona->regmap,
592-
ARIZONA_ACCESSORY_DETECT_MODE_1,
593-
ARIZONA_ACCDET_SRC,
594-
info->micd_modes[0].src);
580+
/*
581+
* If we measure the mic as high impedance
582+
*/
583+
if (!id_gpio || info->hpdet_res[1] > 50) {
584+
dev_dbg(arizona->dev, "Detected mic\n");
585+
*mic = true;
586+
info->detecting = true;
587+
} else {
588+
dev_dbg(arizona->dev, "Detected headphone\n");
595589
}
596590

591+
/* Make sure everything is reset back to the real polarity */
592+
regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
593+
ARIZONA_ACCDET_SRC, info->micd_modes[0].src);
594+
597595
return 0;
598596
}
599597

0 commit comments

Comments
 (0)