diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2013-02-12 08:00:31 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2013-03-26 10:26:03 -0400 |
commit | 03409071ce2751ca124f35edebe4bcad52de22c2 (patch) | |
tree | a4f4f13fafcf8f34d0dc6b67e2ef662c13152f99 /drivers/extcon | |
parent | 8bb9660418e05bb1845ac1a2428444d78e322cc7 (diff) |
extcon: arizona: Factor out magic application
We have a very similar sequence doing magic writes in several places
(one of which missed an update to interlock with the CODEC driver) so
factor it out into a function.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/extcon')
-rw-r--r-- | drivers/extcon/extcon-arizona.c | 91 |
1 files changed, 36 insertions, 55 deletions
diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c index dc357a4051f6..896a923546e0 100644 --- a/drivers/extcon/extcon-arizona.c +++ b/drivers/extcon/extcon-arizona.c | |||
@@ -100,6 +100,39 @@ static const char *arizona_cable[] = { | |||
100 | NULL, | 100 | NULL, |
101 | }; | 101 | }; |
102 | 102 | ||
103 | static void arizona_extcon_do_magic(struct arizona_extcon_info *info, | ||
104 | unsigned int magic) | ||
105 | { | ||
106 | struct arizona *arizona = info->arizona; | ||
107 | unsigned int val; | ||
108 | int ret; | ||
109 | |||
110 | mutex_lock(&arizona->dapm->card->dapm_mutex); | ||
111 | |||
112 | ret = regmap_read(arizona->regmap, ARIZONA_OUTPUT_ENABLES_1, &val); | ||
113 | if (ret != 0) { | ||
114 | dev_err(arizona->dev, "Failed to read output enables: %d\n", | ||
115 | ret); | ||
116 | val = 0; | ||
117 | } | ||
118 | |||
119 | if (!(val & (ARIZONA_OUT1L_ENA | ARIZONA_OUT1R_ENA))) { | ||
120 | ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, | ||
121 | magic); | ||
122 | if (ret != 0) | ||
123 | dev_warn(arizona->dev, "Failed to do magic: %d\n", | ||
124 | ret); | ||
125 | |||
126 | ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, | ||
127 | magic); | ||
128 | if (ret != 0) | ||
129 | dev_warn(arizona->dev, "Failed to do magic: %d\n", | ||
130 | ret); | ||
131 | } | ||
132 | |||
133 | mutex_unlock(&arizona->dapm->card->dapm_mutex); | ||
134 | } | ||
135 | |||
103 | static void arizona_extcon_set_mode(struct arizona_extcon_info *info, int mode) | 136 | static void arizona_extcon_set_mode(struct arizona_extcon_info *info, int mode) |
104 | { | 137 | { |
105 | struct arizona *arizona = info->arizona; | 138 | struct arizona *arizona = info->arizona; |
@@ -484,7 +517,6 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data) | |||
484 | struct arizona *arizona = info->arizona; | 517 | struct arizona *arizona = info->arizona; |
485 | int id_gpio = arizona->pdata.hpdet_id_gpio; | 518 | int id_gpio = arizona->pdata.hpdet_id_gpio; |
486 | int report = ARIZONA_CABLE_HEADPHONE; | 519 | int report = ARIZONA_CABLE_HEADPHONE; |
487 | unsigned int val; | ||
488 | int ret, reading; | 520 | int ret, reading; |
489 | 521 | ||
490 | mutex_lock(&info->lock); | 522 | mutex_lock(&info->lock); |
@@ -539,28 +571,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data) | |||
539 | dev_err(arizona->dev, "Failed to report HP/line: %d\n", | 571 | dev_err(arizona->dev, "Failed to report HP/line: %d\n", |
540 | ret); | 572 | ret); |
541 | 573 | ||
542 | mutex_lock(&arizona->dapm->card->dapm_mutex); | 574 | arizona_extcon_do_magic(info, 0); |
543 | |||
544 | ret = regmap_read(arizona->regmap, ARIZONA_OUTPUT_ENABLES_1, &val); | ||
545 | if (ret != 0) { | ||
546 | dev_err(arizona->dev, "Failed to read output enables: %d\n", | ||
547 | ret); | ||
548 | val = 0; | ||
549 | } | ||
550 | |||
551 | if (!(val & (ARIZONA_OUT1L_ENA | ARIZONA_OUT1R_ENA))) { | ||
552 | ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, 0); | ||
553 | if (ret != 0) | ||
554 | dev_warn(arizona->dev, "Failed to undo magic: %d\n", | ||
555 | ret); | ||
556 | |||
557 | ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, 0); | ||
558 | if (ret != 0) | ||
559 | dev_warn(arizona->dev, "Failed to undo magic: %d\n", | ||
560 | ret); | ||
561 | } | ||
562 | |||
563 | mutex_unlock(&arizona->dapm->card->dapm_mutex); | ||
564 | 575 | ||
565 | done: | 576 | done: |
566 | if (id_gpio) | 577 | if (id_gpio) |
@@ -606,13 +617,7 @@ static void arizona_identify_headphone(struct arizona_extcon_info *info) | |||
606 | if (info->mic) | 617 | if (info->mic) |
607 | arizona_stop_mic(info); | 618 | arizona_stop_mic(info); |
608 | 619 | ||
609 | ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, 0x4000); | 620 | arizona_extcon_do_magic(info, 0x4000); |
610 | if (ret != 0) | ||
611 | dev_warn(arizona->dev, "Failed to do magic: %d\n", ret); | ||
612 | |||
613 | ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, 0x4000); | ||
614 | if (ret != 0) | ||
615 | dev_warn(arizona->dev, "Failed to do magic: %d\n", ret); | ||
616 | 621 | ||
617 | ret = regmap_update_bits(arizona->regmap, | 622 | ret = regmap_update_bits(arizona->regmap, |
618 | ARIZONA_ACCESSORY_DETECT_MODE_1, | 623 | ARIZONA_ACCESSORY_DETECT_MODE_1, |
@@ -653,7 +658,6 @@ err: | |||
653 | static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info) | 658 | static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info) |
654 | { | 659 | { |
655 | struct arizona *arizona = info->arizona; | 660 | struct arizona *arizona = info->arizona; |
656 | unsigned int val; | ||
657 | int ret; | 661 | int ret; |
658 | 662 | ||
659 | dev_dbg(arizona->dev, "Starting identification via HPDET\n"); | 663 | dev_dbg(arizona->dev, "Starting identification via HPDET\n"); |
@@ -665,30 +669,7 @@ static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info) | |||
665 | 669 | ||
666 | arizona_extcon_pulse_micbias(info); | 670 | arizona_extcon_pulse_micbias(info); |
667 | 671 | ||
668 | mutex_lock(&arizona->dapm->card->dapm_mutex); | 672 | arizona_extcon_do_magic(info, 0x4000); |
669 | |||
670 | ret = regmap_read(arizona->regmap, ARIZONA_OUTPUT_ENABLES_1, &val); | ||
671 | if (ret != 0) { | ||
672 | dev_err(arizona->dev, "Failed to read output enables: %d\n", | ||
673 | ret); | ||
674 | val = 0; | ||
675 | } | ||
676 | |||
677 | if (!(val & (ARIZONA_OUT1L_ENA | ARIZONA_OUT1R_ENA))) { | ||
678 | ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, | ||
679 | 0x4000); | ||
680 | if (ret != 0) | ||
681 | dev_warn(arizona->dev, "Failed to do magic: %d\n", | ||
682 | ret); | ||
683 | |||
684 | ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, | ||
685 | 0x4000); | ||
686 | if (ret != 0) | ||
687 | dev_warn(arizona->dev, "Failed to do magic: %d\n", | ||
688 | ret); | ||
689 | } | ||
690 | |||
691 | mutex_unlock(&arizona->dapm->card->dapm_mutex); | ||
692 | 673 | ||
693 | ret = regmap_update_bits(arizona->regmap, | 674 | ret = regmap_update_bits(arizona->regmap, |
694 | ARIZONA_ACCESSORY_DETECT_MODE_1, | 675 | ARIZONA_ACCESSORY_DETECT_MODE_1, |