extcon: arizona: Add support for select accessory detect mode when headphone detection
authorInha Song <ideal.song@samsung.com>
Mon, 4 May 2015 04:42:13 +0000 (13:42 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Tue, 19 May 2015 07:39:05 +0000 (16:39 +0900)
This patch add support for select accessory detect mode to HPDETL or HPDETR.
Arizona provides a headphone detection circuit on the HPDETL and HPDETR pins
to measure the impedance of an external load connected to the headphone.

Depending on board design, headphone detect pins can change to HPDETR or HPDETL.

Signed-off-by: Inha Song <ideal.song@samsung.com>
Acked-by: Lee Jones <lee@kernel.org>
Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
drivers/extcon/extcon-arizona.c
include/dt-bindings/mfd/arizona.h
include/linux/mfd/arizona/pdata.h

index 5e08c358649b43d9d510f2de4caa542f8b229fd4..1ec06b4b48759bd0e86e95aa1edb7013fd7bfdcc 100644 (file)
 #include <linux/mfd/arizona/core.h>
 #include <linux/mfd/arizona/pdata.h>
 #include <linux/mfd/arizona/registers.h>
+#include <dt-bindings/mfd/arizona.h>
 
 #define ARIZONA_MAX_MICD_RANGE 8
 
-#define ARIZONA_ACCDET_MODE_MIC 0
-#define ARIZONA_ACCDET_MODE_HPL 1
-#define ARIZONA_ACCDET_MODE_HPR 2
-
 #define ARIZONA_MICD_CLAMP_MODE_JDL      0x4
 #define ARIZONA_MICD_CLAMP_MODE_JDH      0x5
 #define ARIZONA_MICD_CLAMP_MODE_JDL_GP5H 0x9
@@ -671,9 +668,9 @@ static void arizona_identify_headphone(struct arizona_extcon_info *info)
        ret = regmap_update_bits(arizona->regmap,
                                 ARIZONA_ACCESSORY_DETECT_MODE_1,
                                 ARIZONA_ACCDET_MODE_MASK,
-                                ARIZONA_ACCDET_MODE_HPL);
+                                arizona->pdata.hpdet_channel);
        if (ret != 0) {
-               dev_err(arizona->dev, "Failed to set HPDETL mode: %d\n", ret);
+               dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret);
                goto err;
        }
 
@@ -723,9 +720,9 @@ static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
                                 ARIZONA_ACCESSORY_DETECT_MODE_1,
                                 ARIZONA_ACCDET_SRC | ARIZONA_ACCDET_MODE_MASK,
                                 info->micd_modes[0].src |
-                                ARIZONA_ACCDET_MODE_HPL);
+                                arizona->pdata.hpdet_channel);
        if (ret != 0) {
-               dev_err(arizona->dev, "Failed to set HPDETL mode: %d\n", ret);
+               dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret);
                goto err;
        }
 
@@ -1121,6 +1118,26 @@ static void arizona_micd_set_level(struct arizona *arizona, int index,
        regmap_update_bits(arizona->regmap, reg, mask, level);
 }
 
+static int arizona_extcon_of_get_pdata(struct arizona *arizona)
+{
+       struct arizona_pdata *pdata = &arizona->pdata;
+       unsigned int val = ARIZONA_ACCDET_MODE_HPL;
+
+       of_property_read_u32(arizona->dev->of_node, "wlf,hpdet-channel", &val);
+       switch (val) {
+       case ARIZONA_ACCDET_MODE_HPL:
+       case ARIZONA_ACCDET_MODE_HPR:
+               pdata->hpdet_channel = val;
+               break;
+       default:
+               dev_err(arizona->dev,
+                       "Wrong wlf,hpdet-channel DT value %d\n", val);
+               pdata->hpdet_channel = ARIZONA_ACCDET_MODE_HPL;
+       }
+
+       return 0;
+}
+
 static int arizona_extcon_probe(struct platform_device *pdev)
 {
        struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
@@ -1138,6 +1155,11 @@ static int arizona_extcon_probe(struct platform_device *pdev)
        if (!info)
                return -ENOMEM;
 
+       if (IS_ENABLED(CONFIG_OF)) {
+               if (!dev_get_platdata(arizona->dev))
+                       arizona_extcon_of_get_pdata(arizona);
+       }
+
        info->micvdd = devm_regulator_get(&pdev->dev, "MICVDD");
        if (IS_ERR(info->micvdd)) {
                ret = PTR_ERR(info->micvdd);
index c7af7c7ef793240dc55a3b4aa0182d41a93f328d..fee48e62403611331e6de8a41cab5a59c58a4547 100644 (file)
@@ -90,4 +90,8 @@
 #define ARIZONA_INMODE_SE   1
 #define ARIZONA_INMODE_DMIC 2
 
+#define ARIZONA_ACCDET_MODE_MIC 0
+#define ARIZONA_ACCDET_MODE_HPL 1
+#define ARIZONA_ACCDET_MODE_HPR 2
+
 #endif
index 1789cb0f4f170171d4e37fc20192906a44a4eb44..aa5c48b0675514222880a73d16a75518d661c8c8 100644 (file)
@@ -121,6 +121,9 @@ struct arizona_pdata {
        /** GPIO used for mic isolation with HPDET */
        int hpdet_id_gpio;
 
+       /** Channel to use for headphone detection */
+       unsigned int hpdet_channel;
+
        /** Extra debounce timeout used during initial mic detection (ms) */
        int micd_detect_debounce;