diff mbox

[v3,1/2] extcon: arizona: Add support for select accessory detect mode when headphone detection

Message ID 1429701801-25287-2-git-send-email-ideal.song@samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

Inha Song April 22, 2015, 11:23 a.m. UTC
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>
---
 drivers/extcon/extcon-arizona.c   | 38 ++++++++++++++++++++++++++++++--------
 include/dt-bindings/mfd/arizona.h |  8 ++++++++
 include/linux/mfd/arizona/pdata.h |  3 +++
 3 files changed, 41 insertions(+), 8 deletions(-)
 create mode 100644 include/dt-bindings/mfd/arizona.h

Comments

Charles Keepax April 25, 2015, 12:50 p.m. UTC | #1
On Wed, Apr 22, 2015 at 08:23:20PM +0900, Inha Song wrote:
> 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>
> ---
>  
> +static int arizona_extcon_of_get_pdata(struct arizona *arizona)
> +{
> +	struct arizona_pdata *pdata = &arizona->pdata;
> +	unsigned int val;

I would rather this is "unsigned int val =
ARIZONA_ACCDET_MODE_HPL;".

> +
> +	of_property_read_u32(arizona->dev->of_node, "wlf,hpdet-channel", &val);

Because this won't fill val if the DT entry isn't present.

> +	switch (val) {

Which means we hit this with val uninitialised.

> +	case ARIZONA_ACCDET_MODE_HPL:
> +	case ARIZONA_ACCDET_MODE_HPR:

So we may select either channel at random.

> +		pdata->hpdet_channel = val;
> +		break;
> +	default:
> +		dev_err(arizona->dev,
> +			"Wrong wlf,hpdet-channel DT value %d\n", val);

Or most likely just print an error but the DT being missing
shouldn't really be an error it is an optional entry.

> +		pdata->hpdet_channel = ARIZONA_ACCDET_MODE_HPL;
> +	}
> +
> +	return 0;
> +}

Thanks,
Charles
Inha Song April 27, 2015, 1:26 a.m. UTC | #2
Hi,

Thanks for your comments :)


On Sat, 25 Apr 2015 13:50:25 +0100
Charles Keepax <ckeepax@opensource.wolfsonmicro.com> wrote:

> On Wed, Apr 22, 2015 at 08:23:20PM +0900, Inha Song wrote:
> > 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>
> > ---
> >  
> > +static int arizona_extcon_of_get_pdata(struct arizona *arizona)
> > +{
> > +	struct arizona_pdata *pdata = &arizona->pdata;
> > +	unsigned int val;
> 
> I would rather this is "unsigned int val =
> ARIZONA_ACCDET_MODE_HPL;".
> 
> > +
> > +	of_property_read_u32(arizona->dev->of_node, "wlf,hpdet-channel", &val);
> 
> Because this won't fill val if the DT entry isn't present.
> 
> > +	switch (val) {
> 
> Which means we hit this with val uninitialised.
> 
> > +	case ARIZONA_ACCDET_MODE_HPL:
> > +	case ARIZONA_ACCDET_MODE_HPR:
> 
> So we may select either channel at random.

Opps, Ok, I will set the default value to ARIZONA_ACCDET_MODE_HPL.

> 
> > +		pdata->hpdet_channel = val;
> > +		break;
> > +	default:
> > +		dev_err(arizona->dev,
> > +			"Wrong wlf,hpdet-channel DT value %d\n", val);
> 
> Or most likely just print an error but the DT being missing
> shouldn't really be an error it is an optional entry.

If the default value is set to ARIZONA_ACCDET_MODE_HPL,
Only the print will be shown, when an invalid value is set by DT.
So, This is a resonable error message.

Best Regards,
Inha Song.

> 
> > +		pdata->hpdet_channel = ARIZONA_ACCDET_MODE_HPL;
> > +	}
> > +
> > +	return 0;
> > +}
> 
> Thanks,
> Charles
diff mbox

Patch

diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
index 63f01c4..d9284af 100644
--- a/drivers/extcon/extcon-arizona.c
+++ b/drivers/extcon/extcon-arizona.c
@@ -32,13 +32,10 @@ 
 #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
@@ -653,9 +650,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;
 	}
 
@@ -705,9 +702,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;
 	}
 
@@ -1103,6 +1100,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;
+
+	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);
@@ -1120,6 +1137,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);
diff --git a/include/dt-bindings/mfd/arizona.h b/include/dt-bindings/mfd/arizona.h
new file mode 100644
index 0000000..9ecff78
--- /dev/null
+++ b/include/dt-bindings/mfd/arizona.h
@@ -0,0 +1,8 @@ 
+#ifndef __DT_BINDINGS_ARIZONA_H__
+#define __DT_BINDINGS_ARIZONA_H__
+
+#define ARIZONA_ACCDET_MODE_MIC 0
+#define ARIZONA_ACCDET_MODE_HPL 1
+#define ARIZONA_ACCDET_MODE_HPR 2
+
+#endif /* __DT_BINDINGS_ARIZONA_H__ */
diff --git a/include/linux/mfd/arizona/pdata.h b/include/linux/mfd/arizona/pdata.h
index 4578c72..2473a67 100644
--- a/include/linux/mfd/arizona/pdata.h
+++ b/include/linux/mfd/arizona/pdata.h
@@ -139,6 +139,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;