]> Pileus Git - ~andy/linux/blobdiff - drivers/extcon/extcon-arizona.c
Merge tag 'f2fs-for-3.9' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk...
[~andy/linux] / drivers / extcon / extcon-arizona.c
index 2ad0e4a35a237a63a8ac3bbd336b36f433c94431..dc357a4051f6d79aa5497ee0883c903d0baf97ac 100644 (file)
@@ -56,6 +56,7 @@ struct arizona_extcon_info {
        struct delayed_work hpdet_work;
 
        bool hpdet_active;
+       bool hpdet_done;
 
        int num_hpdet_res;
        unsigned int hpdet_res[3];
@@ -394,7 +395,6 @@ static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading)
 {
        struct arizona *arizona = info->arizona;
        int id_gpio = arizona->pdata.hpdet_id_gpio;
-       int ret;
 
        /*
         * If we're using HPDET for accessory identification we need
@@ -451,6 +451,10 @@ static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading)
                        info->hpdet_res[0], info->hpdet_res[1],
                        info->hpdet_res[2]);
 
+
+               /* Take the headphone impedance for the main report */
+               *reading = info->hpdet_res[0];
+
                /*
                 * Either the two grounds measure differently or we
                 * measure the mic as high impedance.
@@ -459,16 +463,7 @@ static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading)
                    (id_gpio && info->hpdet_res[2] > 10)) {
                        dev_dbg(arizona->dev, "Detected mic\n");
                        info->mic = true;
-                       ret = extcon_set_cable_state_(&info->edev,
-                                                     ARIZONA_CABLE_MICROPHONE,
-                                                     true);
-                       if (ret != 0) {
-                               dev_err(arizona->dev,
-                                       "Failed to report mic: %d\n", ret);
-                       }
-
-                       /* Take the headphone impedance for the main report */
-                       *reading = info->hpdet_res[1];
+                       info->detecting = true;
                } else {
                        dev_dbg(arizona->dev, "Detected headphone\n");
                }
@@ -489,6 +484,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
        struct arizona *arizona = info->arizona;
        int id_gpio = arizona->pdata.hpdet_id_gpio;
        int report = ARIZONA_CABLE_HEADPHONE;
+       unsigned int val;
        int ret, reading;
 
        mutex_lock(&info->lock);
@@ -543,13 +539,28 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
                dev_err(arizona->dev, "Failed to report HP/line: %d\n",
                        ret);
 
-       ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, 0);
-       if (ret != 0)
-               dev_warn(arizona->dev, "Failed to undo magic: %d\n", ret);
+       mutex_lock(&arizona->dapm->card->dapm_mutex);
 
-       ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, 0);
-       if (ret != 0)
-               dev_warn(arizona->dev, "Failed to undo magic: %d\n", ret);
+       ret = regmap_read(arizona->regmap, ARIZONA_OUTPUT_ENABLES_1, &val);
+       if (ret != 0) {
+               dev_err(arizona->dev, "Failed to read output enables: %d\n",
+                       ret);
+               val = 0;
+       }
+
+       if (!(val & (ARIZONA_OUT1L_ENA | ARIZONA_OUT1R_ENA))) {
+               ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, 0);
+               if (ret != 0)
+                       dev_warn(arizona->dev, "Failed to undo magic: %d\n",
+                                ret);
+
+               ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, 0);
+               if (ret != 0)
+                       dev_warn(arizona->dev, "Failed to undo magic: %d\n",
+                                ret);
+       }
+
+       mutex_unlock(&arizona->dapm->card->dapm_mutex);
 
 done:
        if (id_gpio)
@@ -569,6 +580,8 @@ done:
                info->hpdet_active = false;
        }
 
+       info->hpdet_done = true;
+
 out:
        mutex_unlock(&info->lock);
 
@@ -580,6 +593,9 @@ static void arizona_identify_headphone(struct arizona_extcon_info *info)
        struct arizona *arizona = info->arizona;
        int ret;
 
+       if (info->hpdet_done)
+               return;
+
        dev_dbg(arizona->dev, "Starting HPDET\n");
 
        /* Make sure we keep the device enabled during the measurement */
@@ -637,6 +653,7 @@ err:
 static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
 {
        struct arizona *arizona = info->arizona;
+       unsigned int val;
        int ret;
 
        dev_dbg(arizona->dev, "Starting identification via HPDET\n");
@@ -648,13 +665,30 @@ static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
 
        arizona_extcon_pulse_micbias(info);
 
-       ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, 0x4000);
-       if (ret != 0)
-               dev_warn(arizona->dev, "Failed to do magic: %d\n", ret);
+       mutex_lock(&arizona->dapm->card->dapm_mutex);
 
-       ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, 0x4000);
-       if (ret != 0)
-               dev_warn(arizona->dev, "Failed to do magic: %d\n", ret);
+       ret = regmap_read(arizona->regmap, ARIZONA_OUTPUT_ENABLES_1, &val);
+       if (ret != 0) {
+               dev_err(arizona->dev, "Failed to read output enables: %d\n",
+                       ret);
+               val = 0;
+       }
+
+       if (!(val & (ARIZONA_OUT1L_ENA | ARIZONA_OUT1R_ENA))) {
+               ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000,
+                                        0x4000);
+               if (ret != 0)
+                       dev_warn(arizona->dev, "Failed to do magic: %d\n",
+                                ret);
+
+               ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000,
+                                        0x4000);
+               if (ret != 0)
+                       dev_warn(arizona->dev, "Failed to do magic: %d\n",
+                                ret);
+       }
+
+       mutex_unlock(&arizona->dapm->card->dapm_mutex);
 
        ret = regmap_update_bits(arizona->regmap,
                                 ARIZONA_ACCESSORY_DETECT_MODE_1,
@@ -888,6 +922,7 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
                for (i = 0; i < ARRAY_SIZE(info->hpdet_res); i++)
                        info->hpdet_res[i] = 0;
                info->mic = false;
+               info->hpdet_done = false;
 
                for (i = 0; i < ARIZONA_NUM_BUTTONS; i++)
                        input_report_key(info->input,
@@ -905,6 +940,13 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
                                   ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB);
        }
 
+       /* Clear trig_sts to make sure DCVDD is not forced up */
+       regmap_write(arizona->regmap, ARIZONA_AOD_WKUP_AND_TRIG,
+                    ARIZONA_MICD_CLAMP_FALL_TRIG_STS |
+                    ARIZONA_MICD_CLAMP_RISE_TRIG_STS |
+                    ARIZONA_JD1_FALL_TRIG_STS |
+                    ARIZONA_JD1_RISE_TRIG_STS);
+
        mutex_unlock(&info->lock);
 
        pm_runtime_mark_last_busy(info->dev);