Skip to contentSkip to conversation

extcon: axp288: Remove unused extcon_nb struct member

PATCH Applied Hans de Goede 3 participants 18 messages Dec 22, 2017 – Jan 5, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 extcon: axp288: Remove unused extcon_nb struct member

Remove the unused extcon_nb struct member.

---
 drivers/extcon/extcon-axp288.c | 1 -
 1 file changed, 1 deletion(-)
drivers/extcon/extcon-axp288.c +0 -1
index 981fba56bc18..ba185e9ebb82 100644
@@ -107,7 +107,6 @@ struct axp288_extcon_info {
 	struct gpio_desc *gpio_mux_cntl;
 	int irq[EXTCON_IRQ_END];
 	struct extcon_dev *edev;
-	struct notifier_block extcon_nb;
 	unsigned int previous_cable;
 };
 
Signature · 1 line
2.14.3
#1 lore raw

PATCH 2/4 extcon: axp288: Remove unused platform data

This is not used / set anywhere in the tree.

---
 drivers/extcon/extcon-axp288.c | 35 +----------------------------------
 include/linux/mfd/axp20x.h     |  5 -----
 2 files changed, 1 insertion(+), 39 deletions(-)
drivers/extcon/extcon-axp288.c +1 -34
index ba185e9ebb82..386afb7d1160 100644
@@ -24,8 +24,6 @@
 #include <linux/notifier.h>
 #include <linux/extcon-provider.h>
 #include <linux/regmap.h>
-#include <linux/gpio.h>
-#include <linux/gpio/consumer.h>
 #include <linux/mfd/axp20x.h>
 
 /* Power source status register */
@@ -79,11 +77,6 @@ enum axp288_extcon_reg {
 	AXP288_BC_DET_STAT_REG		= 0x2f,
 };
 
-enum axp288_mux_select {
-	EXTCON_GPIO_MUX_SEL_PMIC = 0,
-	EXTCON_GPIO_MUX_SEL_SOC,
-};
-
 enum axp288_extcon_irq {
 	VBUS_FALLING_IRQ = 0,
 	VBUS_RISING_IRQ,
@@ -104,7 +97,6 @@ struct axp288_extcon_info {
 	struct device *dev;
 	struct regmap *regmap;
 	struct regmap_irq_chip_data *regmap_irqc;
-	struct gpio_desc *gpio_mux_cntl;
 	int irq[EXTCON_IRQ_END];
 	struct extcon_dev *edev;
 	unsigned int previous_cable;
@@ -196,15 +188,6 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
 	}
 
 no_vbus:
-	/*
-	 * If VBUS is absent Connect D+/D- lines to PMIC for BC
-	 * detection. Else connect them to SOC for USB communication.
-	 */
-	if (info->gpio_mux_cntl)
-		gpiod_set_value(info->gpio_mux_cntl,
-			vbus_attach ? EXTCON_GPIO_MUX_SEL_SOC
-					: EXTCON_GPIO_MUX_SEL_PMIC);
-
 	extcon_set_state_sync(info->edev, info->previous_cable, false);
 	if (info->previous_cable == EXTCON_CHG_USB_SDP)
 		extcon_set_state_sync(info->edev, EXTCON_USB, false);
@@ -252,8 +235,7 @@ static int axp288_extcon_probe(struct platform_device *pdev)
 {
 	struct axp288_extcon_info *info;
 	struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
-	struct axp288_extcon_pdata *pdata = pdev->dev.platform_data;
-	int ret, i, pirq, gpio;
+	int ret, i, pirq;
 
 	info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
 	if (!info)
@@ -263,8 +245,6 @@ static int axp288_extcon_probe(struct platform_device *pdev)
 	info->regmap = axp20x->regmap;
 	info->regmap_irqc = axp20x->regmap_irqc;
 	info->previous_cable = EXTCON_NONE;
-	if (pdata)
-		info->gpio_mux_cntl = pdata->gpio_mux_cntl;
 
 	platform_set_drvdata(pdev, info);
 
@@ -285,19 +265,6 @@ static int axp288_extcon_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	/* Set up gpio control for USB Mux */
-	if (info->gpio_mux_cntl) {
-		gpio = desc_to_gpio(info->gpio_mux_cntl);
-		ret = devm_gpio_request(&pdev->dev, gpio, "USB_MUX");
-		if (ret < 0) {
-			dev_err(&pdev->dev,
-				"failed to request the gpio=%d\n", gpio);
-			return ret;
-		}
-		gpiod_direction_output(info->gpio_mux_cntl,
-						EXTCON_GPIO_MUX_SEL_PMIC);
-	}
-
 	for (i = 0; i < EXTCON_IRQ_END; i++) {
 		pirq = platform_get_irq(pdev, i);
 		info->irq[i] = regmap_irq_get_virq(info->regmap_irqc, pirq);
include/linux/mfd/axp20x.h +0 -5
index 78dc85365c4f..080798f17ece 100644
@@ -645,11 +645,6 @@ struct axp20x_dev {
 	const struct regmap_irq_chip	*regmap_irq_chip;
 };
 
-struct axp288_extcon_pdata {
-	/* GPIO pin control to switch D+/D- lines b/w PMIC and SOC */
-	struct gpio_desc *gpio_mux_cntl;
-};
-
 /* generic helper function for reading 9-16 bit wide regs */
 static inline int axp20x_read_variable_width(struct regmap *regmap,
 	unsigned int reg, unsigned int width)
Signature · 1 line
2.14.3
maintainer Reviewed-by on v1 2/4
#2 lore raw

Re: [PATCH 2/4] extcon: axp288: Remove unused platform data

+ MFD Maintainer (Lee Jones <[email protected]>)

Hi Hans,

You better to use the scripts/get_maintainer.pl for the mailing list. I added the MFD maintainer.

This patch looks good to me.

Best Regards,
Chanwoo Choi

Quoted 113 lines · Hans de Goede

This is not used / set anywhere in the tree.

---
 drivers/extcon/extcon-axp288.c | 35 +----------------------------------
 include/linux/mfd/axp20x.h     |  5 -----
 2 files changed, 1 insertion(+), 39 deletions(-)
drivers/extcon/extcon-axp288.c +1 -34
index ba185e9ebb82..386afb7d1160 100644
@@ -24,8 +24,6 @@
 #include <linux/notifier.h>
 #include <linux/extcon-provider.h>
 #include <linux/regmap.h>
-#include <linux/gpio.h>
-#include <linux/gpio/consumer.h>
 #include <linux/mfd/axp20x.h>
 
 /* Power source status register */
@@ -79,11 +77,6 @@ enum axp288_extcon_reg {
 	AXP288_BC_DET_STAT_REG		= 0x2f,
 };
 
-enum axp288_mux_select {
-	EXTCON_GPIO_MUX_SEL_PMIC = 0,
-	EXTCON_GPIO_MUX_SEL_SOC,
-};
-
 enum axp288_extcon_irq {
 	VBUS_FALLING_IRQ = 0,
 	VBUS_RISING_IRQ,
@@ -104,7 +97,6 @@ struct axp288_extcon_info {
 	struct device *dev;
 	struct regmap *regmap;
 	struct regmap_irq_chip_data *regmap_irqc;
-	struct gpio_desc *gpio_mux_cntl;
 	int irq[EXTCON_IRQ_END];
 	struct extcon_dev *edev;
 	unsigned int previous_cable;
@@ -196,15 +188,6 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
 	}
 
 no_vbus:
-	/*
-	 * If VBUS is absent Connect D+/D- lines to PMIC for BC
-	 * detection. Else connect them to SOC for USB communication.
-	 */
-	if (info->gpio_mux_cntl)
-		gpiod_set_value(info->gpio_mux_cntl,
-			vbus_attach ? EXTCON_GPIO_MUX_SEL_SOC
-					: EXTCON_GPIO_MUX_SEL_PMIC);
-
 	extcon_set_state_sync(info->edev, info->previous_cable, false);
 	if (info->previous_cable == EXTCON_CHG_USB_SDP)
 		extcon_set_state_sync(info->edev, EXTCON_USB, false);
@@ -252,8 +235,7 @@ static int axp288_extcon_probe(struct platform_device *pdev)
 {
 	struct axp288_extcon_info *info;
 	struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
-	struct axp288_extcon_pdata *pdata = pdev->dev.platform_data;
-	int ret, i, pirq, gpio;
+	int ret, i, pirq;
 
 	info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
 	if (!info)
@@ -263,8 +245,6 @@ static int axp288_extcon_probe(struct platform_device *pdev)
 	info->regmap = axp20x->regmap;
 	info->regmap_irqc = axp20x->regmap_irqc;
 	info->previous_cable = EXTCON_NONE;
-	if (pdata)
-		info->gpio_mux_cntl = pdata->gpio_mux_cntl;
 
 	platform_set_drvdata(pdev, info);
 
@@ -285,19 +265,6 @@ static int axp288_extcon_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	/* Set up gpio control for USB Mux */
-	if (info->gpio_mux_cntl) {
-		gpio = desc_to_gpio(info->gpio_mux_cntl);
-		ret = devm_gpio_request(&pdev->dev, gpio, "USB_MUX");
-		if (ret < 0) {
-			dev_err(&pdev->dev,
-				"failed to request the gpio=%d\n", gpio);
-			return ret;
-		}
-		gpiod_direction_output(info->gpio_mux_cntl,
-						EXTCON_GPIO_MUX_SEL_PMIC);
-	}
-
 	for (i = 0; i < EXTCON_IRQ_END; i++) {
 		pirq = platform_get_irq(pdev, i);
 		info->irq[i] = regmap_irq_get_virq(info->regmap_irqc, pirq);
include/linux/mfd/axp20x.h +0 -5
index 78dc85365c4f..080798f17ece 100644
@@ -645,11 +645,6 @@ struct axp20x_dev {
 	const struct regmap_irq_chip	*regmap_irq_chip;
 };
 
-struct axp288_extcon_pdata {
-	/* GPIO pin control to switch D+/D- lines b/w PMIC and SOC */
-	struct gpio_desc *gpio_mux_cntl;
-};
-
 /* generic helper function for reading 9-16 bit wide regs */
 static inline int axp20x_read_variable_width(struct regmap *regmap,
 	unsigned int reg, unsigned int width)
Acked-by
#3 lore raw

Re: [PATCH 2/4] extcon: axp288: Remove unused platform data

Quoted 7 lines · Chanwoo Choi

+ MFD Maintainer (Lee Jones <[email protected]>)

Hi Hans,

You better to use the scripts/get_maintainer.pl for the mailing list. I added the MFD maintainer.

Quoted 14 lines

This patch looks good to me.

Best Regards,
Chanwoo Choi

Quoted 6 lines · Hans de Goede

This is not used / set anywhere in the tree.

---
 drivers/extcon/extcon-axp288.c | 35 +----------------------------------
 include/linux/mfd/axp20x.h     |  5 -----
Signature · 4 lines
Lee Jones
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
maintainer
#4 lore raw

Re: [PATCH 2/4] extcon: axp288: Remove unused platform data

Dear Lee,

Quoted 17 lines · Lee Jones
Quoted 15 lines · Chanwoo Choi

+ MFD Maintainer (Lee Jones <[email protected]>)

Hi Hans,

You better to use the scripts/get_maintainer.pl for the mailing list. I added the MFD maintainer.

This patch looks good to me.

Best Regards,
Chanwoo Choi

On 2017년 12월 22일 21:36, Hans de Goede wrote:

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

This is not used / set anywhere in the tree.

---
 drivers/extcon/extcon-axp288.c | 35 +----------------------------------
 include/linux/mfd/axp20x.h     |  5 -----

I already made the immutable branch[1] for both mfd and extcon.
[1] https://lkml.org/lkml/2017/12/15/133

I added the additional patch for 'include/linux/mfd/axp20x.h'
If you want to need to apply it on mfd tree, please apply them of immutable branch.

The following changes since commit 4fbd8d194f06c8a3fd2af1ce560ddb31f7ec8323:

Linux 4.15-rc1 (2017-11-26 16:01:47 -0800)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git ib-extcon-mfd-4.16

for you to fetch changes up to 9bf317e900a19a857eb9921c9441a92e89f40415:

extcon: axp288: Remove unused platform data (2018-01-03 10:11:02 +0900)

----------------------------------------------------------------
Arvind Yadav (1):
extcon: axp288:: Handle return value of platform_get_irq

Benson Leung (1):
extcon: usbc-cros-ec: add support to notify USB type cables.

Hans de Goede (2):
extcon: axp288: Remove unused extcon_nb struct member
extcon: axp288: Remove unused platform data

 drivers/extcon/extcon-axp288.c       |  39 +---------
 drivers/extcon/extcon-usbc-cros-ec.c | 142 ++++++++++++++++++++++++++++++++++-
 include/linux/mfd/axp20x.h           |   5 --
 include/linux/mfd/cros_ec_commands.h |  17 +++++
 4 files changed, 159 insertions(+), 44 deletions(-)
Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
#5 lore raw

Re: [PATCH 2/4] extcon: axp288: Remove unused platform data

Quoted 37 lines · Chanwoo Choi

Dear Lee,

Quoted 17 lines · Lee Jones
Quoted 15 lines · Chanwoo Choi

+ MFD Maintainer (Lee Jones <[email protected]>)

Hi Hans,

You better to use the scripts/get_maintainer.pl for the mailing list. I added the MFD maintainer.

This patch looks good to me.

Best Regards,
Chanwoo Choi

On 2017년 12월 22일 21:36, Hans de Goede wrote:

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

This is not used / set anywhere in the tree.

---
 drivers/extcon/extcon-axp288.c | 35 +----------------------------------
 include/linux/mfd/axp20x.h     |  5 -----

I already made the immutable branch[1] for both mfd and extcon.
[1] https://lkml.org/lkml/2017/12/15/133

I added the additional patch for 'include/linux/mfd/axp20x.h'
If you want to need to apply it on mfd tree, please apply them of immutable branch.

Quoted 7 lines

The following changes since commit 4fbd8d194f06c8a3fd2af1ce560ddb31f7ec8323:

Linux 4.15-rc1 (2017-11-26 16:01:47 -0800)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git ib-extcon-mfd-4.16

How is this possible? ib-extcon-mfd-4.16 is already immutable.

I believe you should have created a new tag:

ib-extcon-mfd-4.16-1

... based on ib-extcon-mfd-4.16.

Quoted 21 lines

for you to fetch changes up to 9bf317e900a19a857eb9921c9441a92e89f40415:

extcon: axp288: Remove unused platform data (2018-01-03 10:11:02 +0900)

----------------------------------------------------------------
Arvind Yadav (1):
extcon: axp288:: Handle return value of platform_get_irq

Benson Leung (1):
extcon: usbc-cros-ec: add support to notify USB type cables.

Hans de Goede (2):
extcon: axp288: Remove unused extcon_nb struct member
extcon: axp288: Remove unused platform data

 drivers/extcon/extcon-axp288.c       |  39 +---------
 drivers/extcon/extcon-usbc-cros-ec.c | 142 ++++++++++++++++++++++++++++++++++-
 include/linux/mfd/axp20x.h           |   5 --
 include/linux/mfd/cros_ec_commands.h |  17 +++++
 4 files changed, 159 insertions(+), 44 deletions(-)
Signature · 4 lines
Lee Jones
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
maintainer
#6 lore raw

Re: [PATCH 2/4] extcon: axp288: Remove unused platform data

Quoted 47 lines · Lee Jones
Quoted 37 lines · Chanwoo Choi

Dear Lee,

Quoted 17 lines · Lee Jones
Quoted 15 lines · Chanwoo Choi

+ MFD Maintainer (Lee Jones <[email protected]>)

Hi Hans,

You better to use the scripts/get_maintainer.pl for the mailing list. I added the MFD maintainer.

This patch looks good to me.

Best Regards,
Chanwoo Choi

On 2017년 12월 22일 21:36, Hans de Goede wrote:

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

This is not used / set anywhere in the tree.

---
 drivers/extcon/extcon-axp288.c | 35 +----------------------------------
 include/linux/mfd/axp20x.h     |  5 -----

I already made the immutable branch[1] for both mfd and extcon.
[1] https://lkml.org/lkml/2017/12/15/133

I added the additional patch for 'include/linux/mfd/axp20x.h'
If you want to need to apply it on mfd tree, please apply them of immutable branch.

Quoted 7 lines

The following changes since commit 4fbd8d194f06c8a3fd2af1ce560ddb31f7ec8323:

Linux 4.15-rc1 (2017-11-26 16:01:47 -0800)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git ib-extcon-mfd-4.16

Quoted 7 lines

How is this possible? ib-extcon-mfd-4.16 is already immutable.

I believe you should have created a new tag:

ib-extcon-mfd-4.16-1

... based on ib-extcon-mfd-4.16.

You're right.
I make the new immutable branch (ib-extcon-mfd-4.16-1) as following:

The following changes since commit c7eb47f9e45226571be31212f6efd4b307d3b59d:

extcon: usbc-cros-ec: add support to notify USB type cables. (2017-12-15 17:21:49 +0900)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git tags/ib-extcon-mfd-4.16-1

for you to fetch changes up to 9bf317e900a19a857eb9921c9441a92e89f40415:

extcon: axp288: Remove unused platform data (2018-01-03 10:11:02 +0900)

----------------------------------------------------------------
Immutable branch for both MFD and EXTCON tree.

----------------------------------------------------------------
Arvind Yadav (1):
extcon: axp288:: Handle return value of platform_get_irq

Hans de Goede (2):
extcon: axp288: Remove unused extcon_nb struct member
extcon: axp288: Remove unused platform data

 drivers/extcon/extcon-axp288.c | 39 ++++-----------------------------------
 include/linux/mfd/axp20x.h     |  5 -----
 2 files changed, 4 insertions(+), 40 deletions(-)
Quoted 23 lines
Quoted 22 lines

for you to fetch changes up to 9bf317e900a19a857eb9921c9441a92e89f40415:

extcon: axp288: Remove unused platform data (2018-01-03 10:11:02 +0900)

----------------------------------------------------------------
Arvind Yadav (1):
extcon: axp288:: Handle return value of platform_get_irq

Benson Leung (1):
extcon: usbc-cros-ec: add support to notify USB type cables.

Hans de Goede (2):
extcon: axp288: Remove unused extcon_nb struct member
extcon: axp288: Remove unused platform data

 drivers/extcon/extcon-axp288.c       |  39 +---------
 drivers/extcon/extcon-usbc-cros-ec.c | 142 ++++++++++++++++++++++++++++++++++-
 include/linux/mfd/axp20x.h           |   5 --
 include/linux/mfd/cros_ec_commands.h |  17 +++++
 4 files changed, 159 insertions(+), 44 deletions(-)
Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
#7 lore raw

Re: [PATCH 2/4] extcon: axp288: Remove unused platform data

Quoted 19 lines

The following changes since commit c7eb47f9e45226571be31212f6efd4b307d3b59d:

extcon: usbc-cros-ec: add support to notify USB type cables. (2017-12-15 17:21:49 +0900)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git tags/ib-extcon-mfd-4.16-1

for you to fetch changes up to 9bf317e900a19a857eb9921c9441a92e89f40415:

extcon: axp288: Remove unused platform data (2018-01-03 10:11:02 +0900)

----------------------------------------------------------------
Immutable branch for both MFD and EXTCON tree.

----------------------------------------------------------------
Arvind Yadav (1):
extcon: axp288:: Handle return value of platform_get_irq

Quoted 7 lines

Hans de Goede (2):
extcon: axp288: Remove unused extcon_nb struct member
extcon: axp288: Remove unused platform data

 drivers/extcon/extcon-axp288.c | 39 ++++-----------------------------------
 include/linux/mfd/axp20x.h     |  5 -----
 2 files changed, 4 insertions(+), 40 deletions(-)

Pulled, thanks Chanwoo.

Signature · 4 lines
Lee Jones
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#8 lore raw

PATCH 3/4 extcon: axp288: Redo charger type dection a couple of seconds after probe()

In reply to Hans de Goede

The axp288 extcon code depends on other drivers to do things like mux the data lines, enable/disable vbus based on the id-pin, etc.

Sometimes the BIOS has not set these things up correctly resulting in the initial charger cable type detection giving a wrong result and we end up not charging or charging at only 0.5A.

This commit starts a second charger-detection cycle a couple of seconds after the first one finishes, giving the other drivers time to load and do their thing.

---
 drivers/extcon/extcon-axp288.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
drivers/extcon/extcon-axp288.c +30 -2
index 386afb7d1160..cc7c35c7ff02 100644
@@ -1,6 +1,7 @@
 /*
  * extcon-axp288.c - X-Power AXP288 PMIC extcon cable detection driver
  *
+ * Copyright (C) 2016-2017 Hans de Goede <[email protected]>
  * Copyright (C) 2015 Intel Corporation
  * Author: Ramakrishna Pallala <[email protected]>
  *
@@ -97,9 +98,11 @@ struct axp288_extcon_info {
 	struct device *dev;
 	struct regmap *regmap;
 	struct regmap_irq_chip_data *regmap_irqc;
+	struct delayed_work det_work;
 	int irq[EXTCON_IRQ_END];
 	struct extcon_dev *edev;
 	unsigned int previous_cable;
+	bool first_detect_done;
 };
 
 /* Power up/down reason string array */
@@ -137,6 +140,25 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
 	regmap_write(info->regmap, AXP288_PS_BOOT_REASON_REG, clear_mask);
 }
 
+static void axp288_chrg_detect_complete(struct axp288_extcon_info *info)
+{
+	/*
+	 * We depend on other drivers to do things like mux the data lines,
+	 * enable/disable vbus based on the id-pin, etc. Sometimes the BIOS has
+	 * not set these things up correctly resulting in the initial charger
+	 * cable type detection giving a wrong result and we end up not charging
+	 * or charging at only 0.5A.
+	 *
+	 * So we schedule a second cable type detection after 2 seconds to
+	 * give the other drivers time to load and do their thing.
+	 */
+	if (!info->first_detect_done) {
+		queue_delayed_work(system_wq, &info->det_work,
+				   msecs_to_jiffies(2000));
+		info->first_detect_done = true;
+	}
+}
+
 static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
 {
 	int ret, stat, cfg, pwr_stat;
@@ -201,6 +223,8 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
 		info->previous_cable = cable;
 	}
 
+	axp288_chrg_detect_complete(info);
+
 	return 0;
 
 dev_det_ret:
@@ -222,8 +246,11 @@ static irqreturn_t axp288_extcon_isr(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
-static void axp288_extcon_enable(struct axp288_extcon_info *info)
+static void axp288_extcon_det_work(struct work_struct *work)
 {
+	struct axp288_extcon_info *info =
+		container_of(work, struct axp288_extcon_info, det_work.work);
+
 	regmap_update_bits(info->regmap, AXP288_BC_GLOBAL_REG,
 						BC_GLOBAL_RUN, 0);
 	/* Enable the charger detection logic */
@@ -245,6 +272,7 @@ static int axp288_extcon_probe(struct platform_device *pdev)
 	info->regmap = axp20x->regmap;
 	info->regmap_irqc = axp20x->regmap_irqc;
 	info->previous_cable = EXTCON_NONE;
+	INIT_DELAYED_WORK(&info->det_work, axp288_extcon_det_work);
 
 	platform_set_drvdata(pdev, info);
 
@@ -287,7 +315,7 @@ static int axp288_extcon_probe(struct platform_device *pdev)
 	}
 
 	/* Start charger cable type detection */
-	axp288_extcon_enable(info);
+	queue_delayed_work(system_wq, &info->det_work, 0);
 
 	return 0;
 }
Signature · 1 line
2.14.3
maintainer
#9 lore raw

Re: [PATCH 3/4] extcon: axp288: Redo charger type dection a couple of seconds after probe()

Hi Hans,

s/dection/detection on patch title.

Quoted 29 lines · Hans de Goede

The axp288 extcon code depends on other drivers to do things like mux the data lines, enable/disable vbus based on the id-pin, etc.

Sometimes the BIOS has not set these things up correctly resulting in the initial charger cable type detection giving a wrong result and we end up not charging or charging at only 0.5A.

This commit starts a second charger-detection cycle a couple of seconds after the first one finishes, giving the other drivers time to load and do their thing.

---
 drivers/extcon/extcon-axp288.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
drivers/extcon/extcon-axp288.c +1 -0
index 386afb7d1160..cc7c35c7ff02 100644
@@ -1,6 +1,7 @@
 /*
  * extcon-axp288.c - X-Power AXP288 PMIC extcon cable detection driver
  *
+ * Copyright (C) 2016-2017 Hans de Goede <[email protected]>
  * Copyright (C) 2015 Intel Corporation
  * Author: Ramakrishna Pallala <[email protected]>
  *

drivers/extcon/extcon-axp288.c struct axp288_extcon_info { · line 105

Quoted 8 lines
drivers/extcon/extcon-axp288.c +2 -0
@@ -97,9 +98,11 @@ struct axp288_extcon_info {
 	struct device *dev;
 	struct regmap *regmap;
 	struct regmap_irq_chip_data *regmap_irqc;
+	struct delayed_work det_work;
 	int irq[EXTCON_IRQ_END];
 	struct extcon_dev *edev;
 	unsigned int previous_cable;
+	bool first_detect_done;

The first_detect_done is used only one time in the axp288_handle_chrg_det_event(). The other function don't use it. So, you better to define and use 'static bool first_detect_done' in the axp288_handle_chrg_det_event() instead of defining the 'first_detect_done' in the struct axp288_extcon_info.

Quoted 15 lines
drivers/extcon/extcon-axp288.c +8 -0
 };
 
 /* Power up/down reason string array */
@@ -137,6 +140,25 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
 	regmap_write(info->regmap, AXP288_PS_BOOT_REASON_REG, clear_mask);
 }
 
+static void axp288_chrg_detect_complete(struct axp288_extcon_info *info)
+{
+	/*
+	 * We depend on other drivers to do things like mux the data lines,
+	 * enable/disable vbus based on the id-pin, etc. Sometimes the BIOS has
+	 * not set these things up correctly resulting in the initial charger
+	 * cable type detection giving a wrong result and we end up not charging
+	 * or charging at only 0.5A.

drivers/extcon/extcon-axp288.c static void axp288_extcon_log_rsi(struct axp288_extcon_info *info) · line 160

Quoted 10 lines
drivers/extcon/extcon-axp288.c +10 -0
+	 *
+	 * So we schedule a second cable type detection after 2 seconds to
+	 * give the other drivers time to load and do their thing.
+	 */
+	if (!info->first_detect_done) {
+		queue_delayed_work(system_wq, &info->det_work,
+				   msecs_to_jiffies(2000));
+		info->first_detect_done = true;
+	}
+}

The axp288_chrg_detect_complete() is only used in the axp288_handle_chrg_det_event() and axp288_chrg_detect_complete() is not a complicate. I think that you don't need to make the separate function. I'd like you to add the

drivers/extcon/extcon-axp288.c static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) · line 226

Quoted 9 lines
drivers/extcon/extcon-axp288.c +2 -0
+
 static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
 {
 	int ret, stat, cfg, pwr_stat;
@@ -201,6 +223,8 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
 		info->previous_cable = cable;
 	}
 
+	axp288_chrg_detect_complete(info);

As I commented, you better to add the code directly instead of separate function.

Quoted 35 lines
drivers/extcon/extcon-axp288.c +7 -2
+
 	return 0;
 
 dev_det_ret:
@@ -222,8 +246,11 @@ static irqreturn_t axp288_extcon_isr(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
-static void axp288_extcon_enable(struct axp288_extcon_info *info)
+static void axp288_extcon_det_work(struct work_struct *work)
 {
+	struct axp288_extcon_info *info =
+		container_of(work, struct axp288_extcon_info, det_work.work);
+
 	regmap_update_bits(info->regmap, AXP288_BC_GLOBAL_REG,
 						BC_GLOBAL_RUN, 0);
 	/* Enable the charger detection logic */
@@ -245,6 +272,7 @@ static int axp288_extcon_probe(struct platform_device *pdev)
 	info->regmap = axp20x->regmap;
 	info->regmap_irqc = axp20x->regmap_irqc;
 	info->previous_cable = EXTCON_NONE;
+	INIT_DELAYED_WORK(&info->det_work, axp288_extcon_det_work);
 
 	platform_set_drvdata(pdev, info);
 
@@ -287,7 +315,7 @@ static int axp288_extcon_probe(struct platform_device *pdev)
 	}
 
 	/* Start charger cable type detection */
-	axp288_extcon_enable(info);
+	queue_delayed_work(system_wq, &info->det_work, 0);
 
 	return 0;
 }
Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
#10 lore raw

Re: [PATCH 3/4] extcon: axp288: Redo charger type dection a couple of seconds after probe()

Hi,

Quoted 3 lines · Chanwoo Choi

Hi Hans,

s/dection/detection on patch title.

Thank you for all the reviews.

I've fixed the typo in my personal tree.

Quoted 35 lines · Hans de Goede
Quoted 34 lines

The axp288 extcon code depends on other drivers to do things like mux the data lines, enable/disable vbus based on the id-pin, etc.

Sometimes the BIOS has not set these things up correctly resulting in the initial charger cable type detection giving a wrong result and we end up not charging or charging at only 0.5A.

This commit starts a second charger-detection cycle a couple of seconds after the first one finishes, giving the other drivers time to load and do their thing.

---
  drivers/extcon/extcon-axp288.c | 32 ++++++++++++++++++++++++++++++--
  1 file changed, 30 insertions(+), 2 deletions(-)
drivers/extcon/extcon-axp288.c +2 -0
index 386afb7d1160..cc7c35c7ff02 100644
@@ -1,6 +1,7 @@
  /*
   * extcon-axp288.c - X-Power AXP288 PMIC extcon cable detection driver
   *
+ * Copyright (C) 2016-2017 Hans de Goede <[email protected]>
   * Copyright (C) 2015 Intel Corporation
   * Author: Ramakrishna Pallala <[email protected]>
   *
@@ -97,9 +98,11 @@ struct axp288_extcon_info {
  	struct device *dev;
  	struct regmap *regmap;
  	struct regmap_irq_chip_data *regmap_irqc;
+	struct delayed_work det_work;
  	int irq[EXTCON_IRQ_END];
Quoted 8 lines

drivers/extcon/extcon-axp288.c struct axp288_extcon_info { · line 105

Quoted 3 lines
drivers/extcon/extcon-axp288.c +1 -0
  	struct extcon_dev *edev;
  	unsigned int previous_cable;
+	bool first_detect_done;

The first_detect_done is used only one time in the axp288_handle_chrg_det_event(). The other function don't use it. So, you better to define and use 'static bool first_detect_done' in the axp288_handle_chrg_det_event() instead of defining the 'first_detect_done' in the struct axp288_extcon_info.

But what if a device has 2 axp288 PMICs (unlikely I know) then only the first one to check this will do the re-detect 2 seconds later, unless they race, which is bad in itself too.

In general using static function variables is a bad idea and should be avoided, it does not work when their are multiple instances of the device and it is racy. So sorry but I'm not going to make this change.

Quoted 39 lines
Quoted 16 lines
drivers/extcon/extcon-axp288.c +8 -0
  };
 
  /* Power up/down reason string array */
@@ -137,6 +140,25 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
  	regmap_write(info->regmap, AXP288_PS_BOOT_REASON_REG, clear_mask);
  }
 
+static void axp288_chrg_detect_complete(struct axp288_extcon_info *info)
+{
+	/*
+	 * We depend on other drivers to do things like mux the data lines,
+	 * enable/disable vbus based on the id-pin, etc. Sometimes the BIOS has
+	 * not set these things up correctly resulting in the initial charger
+	 * cable type detection giving a wrong result and we end up not charging
+	 * or charging at only 0.5A.

drivers/extcon/extcon-axp288.c static void axp288_extcon_log_rsi(struct axp288_extcon_info *info) · line 160

Quoted 10 lines
drivers/extcon/extcon-axp288.c +10 -0
+	 *
+	 * So we schedule a second cable type detection after 2 seconds to
+	 * give the other drivers time to load and do their thing.
+	 */
+	if (!info->first_detect_done) {
+		queue_delayed_work(system_wq, &info->det_work,
+				   msecs_to_jiffies(2000));
+		info->first_detect_done = true;
+	}
+}

The axp288_chrg_detect_complete() is only used in the axp288_handle_chrg_det_event() and axp288_chrg_detect_complete() is not a complicate. I think that you don't need to make the separate function. I'd like you to add the

Quoted 8 lines
drivers/extcon/extcon-axp288.c +1 -0
+
  static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
  {
  	int ret, stat, cfg, pwr_stat;
@@ -201,6 +223,8 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
  		info->previous_cable = cable;
  	}
 
Quoted 3 lines

drivers/extcon/extcon-axp288.c static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) · line 226

Quoted 1 line
drivers/extcon/extcon-axp288.c +1 -0
+	axp288_chrg_detect_complete(info);

As I commented, you better to add the code directly instead of separate function.

I would prefer to keep this as a separate function, that keeps the main flow of the axp288_handle_chrg_det_event function a lot more readable IMHO.

axp288_handle_chrg_det_event already has a non trivial code flow adding more conditional code to it only makes it harder to read.

But if you insist I can move the code inside the function for v2. Note that this will not make a difference for the code generated by the compiler, the compiler will auto-inline it anyways.

Quoted 29 lines
Quoted 29 lines
drivers/extcon/extcon-axp288.c +6 -1
+
  	return 0;
 
  dev_det_ret:
@@ -222,8 +246,11 @@ static irqreturn_t axp288_extcon_isr(int irq, void *data)
  	return IRQ_HANDLED;
  }
 
-static void axp288_extcon_enable(struct axp288_extcon_info *info)
+static void axp288_extcon_det_work(struct work_struct *work)
  {
+	struct axp288_extcon_info *info =
+		container_of(work, struct axp288_extcon_info, det_work.work);
+
  	regmap_update_bits(info->regmap, AXP288_BC_GLOBAL_REG,
  						BC_GLOBAL_RUN, 0);
  	/* Enable the charger detection logic */
@@ -245,6 +272,7 @@ static int axp288_extcon_probe(struct platform_device *pdev)
  	info->regmap = axp20x->regmap;
  	info->regmap_irqc = axp20x->regmap_irqc;
  	info->previous_cable = EXTCON_NONE;
+	INIT_DELAYED_WORK(&info->det_work, axp288_extcon_det_work);
 
  	platform_set_drvdata(pdev, info);
 
@@ -287,7 +315,7 @@ static int axp288_extcon_probe(struct platform_device *pdev)
  	}
 
Quoted 9 lines

drivers/extcon/extcon-axp288.c static int axp288_extcon_probe(struct platform_device *pdev) · line 321

Quoted 7 lines
drivers/extcon/extcon-axp288.c +1 -1
  	/* Start charger cable type detection */
-	axp288_extcon_enable(info);
+	queue_delayed_work(system_wq, &info->det_work, 0);
 
  	return 0;
  }

Regards,

Hans

maintainer
#11 lore raw

Re: [PATCH 3/4] extcon: axp288: Redo charger type dection a couple of seconds after probe()

Hi Hans,

Quoted 55 lines · Hans de Goede

Hi,

Quoted 3 lines · Chanwoo Choi

Hi Hans,

s/dection/detection on patch title.

Thank you for all the reviews.

I've fixed the typo in my personal tree.

Quoted 35 lines · Hans de Goede
Quoted 34 lines

The axp288 extcon code depends on other drivers to do things like mux the data lines, enable/disable vbus based on the id-pin, etc.

Sometimes the BIOS has not set these things up correctly resulting in the initial charger cable type detection giving a wrong result and we end up not charging or charging at only 0.5A.

This commit starts a second charger-detection cycle a couple of seconds after the first one finishes, giving the other drivers time to load and do their thing.

---
  drivers/extcon/extcon-axp288.c | 32 ++++++++++++++++++++++++++++++--
  1 file changed, 30 insertions(+), 2 deletions(-)
drivers/extcon/extcon-axp288.c +2 -0
index 386afb7d1160..cc7c35c7ff02 100644
@@ -1,6 +1,7 @@
  /*
   * extcon-axp288.c - X-Power AXP288 PMIC extcon cable detection driver
   *
+ * Copyright (C) 2016-2017 Hans de Goede <[email protected]>
   * Copyright (C) 2015 Intel Corporation
   * Author: Ramakrishna Pallala <[email protected]>
   *
@@ -97,9 +98,11 @@ struct axp288_extcon_info {
      struct device *dev;
      struct regmap *regmap;
      struct regmap_irq_chip_data *regmap_irqc;
+    struct delayed_work det_work;
      int irq[EXTCON_IRQ_END];
Quoted 8 lines

drivers/extcon/extcon-axp288.c struct axp288_extcon_info { · line 105

Quoted 3 lines
drivers/extcon/extcon-axp288.c +1 -0
      struct extcon_dev *edev;
      unsigned int previous_cable;
+    bool first_detect_done;

The first_detect_done is used only one time in the axp288_handle_chrg_det_event(). The other function don't use it. So, you better to define and use 'static bool first_detect_done' in the axp288_handle_chrg_det_event() instead of defining the 'first_detect_done' in the struct axp288_extcon_info.

Quoted 7 lines

But what if a device has 2 axp288 PMICs (unlikely I know) then only the first one to check this will do the re-detect 2 seconds later, unless they race, which is bad in itself too.

In general using static function variables is a bad idea and should be avoided, it does not work when their are multiple instances of the device and it is racy. So sorry but I'm not going to make this change.

You're right. It is my mistake. Please keep your way.

Quoted 44 lines
Quoted 30 lines
Quoted 15 lines
drivers/extcon/extcon-axp288.c +7 -0
  };
    /* Power up/down reason string array */
@@ -137,6 +140,25 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
      regmap_write(info->regmap, AXP288_PS_BOOT_REASON_REG, clear_mask);
  }
  +static void axp288_chrg_detect_complete(struct axp288_extcon_info *info)
+{
+    /*
+     * We depend on other drivers to do things like mux the data lines,
+     * enable/disable vbus based on the id-pin, etc. Sometimes the BIOS has
+     * not set these things up correctly resulting in the initial charger
+     * cable type detection giving a wrong result and we end up not charging
+     * or charging at only 0.5A.

drivers/extcon/extcon-axp288.c static void axp288_extcon_log_rsi(struct axp288_extcon_info *info) · line 159

Quoted 10 lines
drivers/extcon/extcon-axp288.c +10 -0
+     *
+     * So we schedule a second cable type detection after 2 seconds to
+     * give the other drivers time to load and do their thing.
+     */
+    if (!info->first_detect_done) {
+        queue_delayed_work(system_wq, &info->det_work,
+                   msecs_to_jiffies(2000));
+        info->first_detect_done = true;
+    }
+}

The axp288_chrg_detect_complete() is only used in the axp288_handle_chrg_det_event() and axp288_chrg_detect_complete() is not a complicate. I think that you don't need to make the separate function. I'd like you to add the

Quoted 10 lines

drivers/extcon/extcon-axp288.c static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) · line 225

Quoted 8 lines
drivers/extcon/extcon-axp288.c +1 -0
+
  static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
  {
      int ret, stat, cfg, pwr_stat;
@@ -201,6 +223,8 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
          info->previous_cable = cable;
      }
  +    axp288_chrg_detect_complete(info);

As I commented, you better to add the code directly instead of separate function.

I would prefer to keep this as a separate function, that keeps the main flow of the axp288_handle_chrg_det_event function a lot more readable IMHO.

Quoted 6 lines

axp288_handle_chrg_det_event already has a non trivial code flow adding more conditional code to it only makes it harder to read.

But if you insist I can move the code inside the function for v2. Note that this will not make a difference for the code generated by the compiler, the compiler will auto-inline it anyways.

I didn't mention the result from compiler. I focus on the readability. On v1, the developer always check what to do in axp288_chrg_detect_complete() even if this function is used only one time like '__init'. Actually, axp288_chrg_detect_complete() is not complicate and short.

But, I will not be forced because it is not a critical issue.
If you want to keep the separate function, you just send v2 with only fixing the typo.

Quoted 41 lines
Quoted 24 lines
Quoted 24 lines
drivers/extcon/extcon-axp288.c +6 -0
+
      return 0;
    dev_det_ret:
@@ -222,8 +246,11 @@ static irqreturn_t axp288_extcon_isr(int irq, void *data)
      return IRQ_HANDLED;
  }
  -static void axp288_extcon_enable(struct axp288_extcon_info *info)
+static void axp288_extcon_det_work(struct work_struct *work)
  {
+    struct axp288_extcon_info *info =
+        container_of(work, struct axp288_extcon_info, det_work.work);
+
      regmap_update_bits(info->regmap, AXP288_BC_GLOBAL_REG,
                          BC_GLOBAL_RUN, 0);
      /* Enable the charger detection logic */
@@ -245,6 +272,7 @@ static int axp288_extcon_probe(struct platform_device *pdev)
      info->regmap = axp20x->regmap;
      info->regmap_irqc = axp20x->regmap_irqc;
      info->previous_cable = EXTCON_NONE;
+    INIT_DELAYED_WORK(&info->det_work, axp288_extcon_det_work);
        platform_set_drvdata(pdev, info);
Quoted 10 lines

drivers/extcon/extcon-axp288.c static int axp288_extcon_probe(struct platform_device *pdev) · line 321

Quoted 8 lines
drivers/extcon/extcon-axp288.c +0 -0
  @@ -287,7 +315,7 @@ static int axp288_extcon_probe(struct platform_device *pdev)
      }
        /* Start charger cable type detection */
drivers/extcon/extcon-axp288.c +1 -1
-    axp288_extcon_enable(info);
+    queue_delayed_work(system_wq, &info->det_work, 0);
        return 0;
  }

Regards,

Hans

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
maintainer
#12 lore raw

Re: [PATCH 3/4] extcon: axp288: Redo charger type dection a couple of seconds after probe()

Hi Hans,

Quoted 119 lines · Chanwoo Choi

Hi Hans,

Quoted 55 lines · Hans de Goede

Hi,

Quoted 3 lines · Chanwoo Choi

Hi Hans,

s/dection/detection on patch title.

Thank you for all the reviews.

I've fixed the typo in my personal tree.

Quoted 35 lines · Hans de Goede
Quoted 34 lines

The axp288 extcon code depends on other drivers to do things like mux the data lines, enable/disable vbus based on the id-pin, etc.

Sometimes the BIOS has not set these things up correctly resulting in the initial charger cable type detection giving a wrong result and we end up not charging or charging at only 0.5A.

This commit starts a second charger-detection cycle a couple of seconds after the first one finishes, giving the other drivers time to load and do their thing.

---
  drivers/extcon/extcon-axp288.c | 32 ++++++++++++++++++++++++++++++--
  1 file changed, 30 insertions(+), 2 deletions(-)
drivers/extcon/extcon-axp288.c +2 -0
index 386afb7d1160..cc7c35c7ff02 100644
@@ -1,6 +1,7 @@
  /*
   * extcon-axp288.c - X-Power AXP288 PMIC extcon cable detection driver
   *
+ * Copyright (C) 2016-2017 Hans de Goede <[email protected]>
   * Copyright (C) 2015 Intel Corporation
   * Author: Ramakrishna Pallala <[email protected]>
   *
@@ -97,9 +98,11 @@ struct axp288_extcon_info {
      struct device *dev;
      struct regmap *regmap;
      struct regmap_irq_chip_data *regmap_irqc;
+    struct delayed_work det_work;
      int irq[EXTCON_IRQ_END];
Quoted 8 lines

drivers/extcon/extcon-axp288.c struct axp288_extcon_info { · line 105

Quoted 3 lines
drivers/extcon/extcon-axp288.c +1 -0
      struct extcon_dev *edev;
      unsigned int previous_cable;
+    bool first_detect_done;

The first_detect_done is used only one time in the axp288_handle_chrg_det_event(). The other function don't use it. So, you better to define and use 'static bool first_detect_done' in the axp288_handle_chrg_det_event() instead of defining the 'first_detect_done' in the struct axp288_extcon_info.

Quoted 7 lines

But what if a device has 2 axp288 PMICs (unlikely I know) then only the first one to check this will do the re-detect 2 seconds later, unless they race, which is bad in itself too.

In general using static function variables is a bad idea and should be avoided, it does not work when their are multiple instances of the device and it is racy. So sorry but I'm not going to make this change.

You're right. It is my mistake. Please keep your way.

Quoted 44 lines
Quoted 30 lines
Quoted 15 lines
drivers/extcon/extcon-axp288.c +7 -0
  };
    /* Power up/down reason string array */
@@ -137,6 +140,25 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
      regmap_write(info->regmap, AXP288_PS_BOOT_REASON_REG, clear_mask);
  }
  +static void axp288_chrg_detect_complete(struct axp288_extcon_info *info)
+{
+    /*
+     * We depend on other drivers to do things like mux the data lines,
+     * enable/disable vbus based on the id-pin, etc. Sometimes the BIOS has
+     * not set these things up correctly resulting in the initial charger
+     * cable type detection giving a wrong result and we end up not charging
+     * or charging at only 0.5A.

drivers/extcon/extcon-axp288.c static void axp288_extcon_log_rsi(struct axp288_extcon_info *info) · line 159

Quoted 10 lines
drivers/extcon/extcon-axp288.c +10 -0
+     *
+     * So we schedule a second cable type detection after 2 seconds to
+     * give the other drivers time to load and do their thing.
+     */
+    if (!info->first_detect_done) {
+        queue_delayed_work(system_wq, &info->det_work,
+                   msecs_to_jiffies(2000));
+        info->first_detect_done = true;
+    }
+}

The axp288_chrg_detect_complete() is only used in the axp288_handle_chrg_det_event() and axp288_chrg_detect_complete() is not a complicate. I think that you don't need to make the separate function. I'd like you to add the

Quoted 10 lines

drivers/extcon/extcon-axp288.c static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) · line 225

Quoted 8 lines
drivers/extcon/extcon-axp288.c +1 -0
+
  static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
  {
      int ret, stat, cfg, pwr_stat;
@@ -201,6 +223,8 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
          info->previous_cable = cable;
      }
  +    axp288_chrg_detect_complete(info);

As I commented, you better to add the code directly instead of separate function.

I would prefer to keep this as a separate function, that keeps the main flow of the axp288_handle_chrg_det_event function a lot more readable IMHO.

Quoted 6 lines

axp288_handle_chrg_det_event already has a non trivial code flow adding more conditional code to it only makes it harder to read.

But if you insist I can move the code inside the function for v2. Note that this will not make a difference for the code generated by the compiler, the compiler will auto-inline it anyways.

Quoted 7 lines

I didn't mention the result from compiler. I focus on the readability. On v1, the developer always check what to do in axp288_chrg_detect_complete() even if this function is used only one time like '__init'. Actually, axp288_chrg_detect_complete() is not complicate and short.

But, I will not be forced because it is not a critical issue.
If you want to keep the separate function, you just send v2 with only fixing the typo.

You don't need to send v2. I'll fix the typo and apply your patch v1 As I mentioned, it is not a critical issue. Thanks.

Quoted 44 lines
Quoted 42 lines
Quoted 25 lines
Quoted 25 lines
drivers/extcon/extcon-axp288.c +6 -0
+
      return 0;
    dev_det_ret:
@@ -222,8 +246,11 @@ static irqreturn_t axp288_extcon_isr(int irq, void *data)
      return IRQ_HANDLED;
  }
  -static void axp288_extcon_enable(struct axp288_extcon_info *info)
+static void axp288_extcon_det_work(struct work_struct *work)
  {
+    struct axp288_extcon_info *info =
+        container_of(work, struct axp288_extcon_info, det_work.work);
+
      regmap_update_bits(info->regmap, AXP288_BC_GLOBAL_REG,
                          BC_GLOBAL_RUN, 0);
      /* Enable the charger detection logic */
@@ -245,6 +272,7 @@ static int axp288_extcon_probe(struct platform_device *pdev)
      info->regmap = axp20x->regmap;
      info->regmap_irqc = axp20x->regmap_irqc;
      info->previous_cable = EXTCON_NONE;
+    INIT_DELAYED_WORK(&info->det_work, axp288_extcon_det_work);
        platform_set_drvdata(pdev, info);
Quoted 10 lines

drivers/extcon/extcon-axp288.c static int axp288_extcon_probe(struct platform_device *pdev) · line 321

Quoted 8 lines
drivers/extcon/extcon-axp288.c +0 -0
  @@ -287,7 +315,7 @@ static int axp288_extcon_probe(struct platform_device *pdev)
      }
        /* Start charger cable type detection */
drivers/extcon/extcon-axp288.c +1 -1
-    axp288_extcon_enable(info);
+    queue_delayed_work(system_wq, &info->det_work, 0);
        return 0;
  }

Regards,

Hans

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
#13 lore raw

PATCH 4/4 extcon: axp288: Handle reserved charger-type values better

In reply to Hans de Goede

According to the data sheets all the values not handled in the switch-case are "reserved". Update the dev_warn message to reflect this and set the cable-type to EXTCON_CHG_USB_SDP (so max 500mA current draw) as safe default.

---
 drivers/extcon/extcon-axp288.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/extcon/extcon-axp288.c +2 -2
index cc7c35c7ff02..d60c615f709f 100644
@@ -205,8 +205,8 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
 		cable = EXTCON_CHG_USB_DCP;
 		break;
 	default:
-		dev_warn(info->dev,
-			"disconnect or unknown or ID event\n");
+		dev_warn(info->dev, "unknown (reserved) bc detect result\n");
+		cable = EXTCON_CHG_USB_SDP;
 	}
 
 no_vbus:
Signature · 1 line
2.14.3
maintainer Reviewed-by on v1 4/4
#14 lore raw

Re: [PATCH 4/4] extcon: axp288: Handle reserved charger-type values better

Hi Hans,

Quoted 16 lines · Hans de Goede

According to the data sheets all the values not handled in the switch-case are "reserved". Update the dev_warn message to reflect this and set the cable-type to EXTCON_CHG_USB_SDP (so max 500mA current draw) as safe default.

---
 drivers/extcon/extcon-axp288.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/extcon/extcon-axp288.c +0 -0
index cc7c35c7ff02..d60c615f709f 100644

drivers/extcon/extcon-axp288.c static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) · line 212

Quoted 10 lines
drivers/extcon/extcon-axp288.c +2 -2
@@ -205,8 +205,8 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
 		cable = EXTCON_CHG_USB_DCP;
 		break;
 	default:
-		dev_warn(info->dev,
-			"disconnect or unknown or ID event\n");
+		dev_warn(info->dev, "unknown (reserved) bc detect result\n");
+		cable = EXTCON_CHG_USB_SDP;
 	}
 
 no_vbus:

Looks good to me.

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
maintainer Reviewed-by on v1 1/4
#15 lore raw
In reply to Hans de Goede
Quoted 13 lines · Hans de Goede

Remove the unused extcon_nb struct member.

---
 drivers/extcon/extcon-axp288.c | 1 -
 1 file changed, 1 deletion(-)
drivers/extcon/extcon-axp288.c +0 -0
index 981fba56bc18..ba185e9ebb82 100644

drivers/extcon/extcon-axp288.c struct axp288_extcon_info { · line 112

Quoted 7 lines
drivers/extcon/extcon-axp288.c +0 -1
@@ -107,7 +107,6 @@ struct axp288_extcon_info {
 	struct gpio_desc *gpio_mux_cntl;
 	int irq[EXTCON_IRQ_END];
 	struct extcon_dev *edev;
-	struct notifier_block extcon_nb;
 	unsigned int previous_cable;
 };
 

Looks good to me.

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
maintainer Applied
#16 lore raw
In reply to Hans de Goede

Hi Hans,

Quoted 13 lines · Hans de Goede

Remove the unused extcon_nb struct member.

---
 drivers/extcon/extcon-axp288.c | 1 -
 1 file changed, 1 deletion(-)
drivers/extcon/extcon-axp288.c +0 -0
index 981fba56bc18..ba185e9ebb82 100644

drivers/extcon/extcon-axp288.c struct axp288_extcon_info { · line 112

Quoted 7 lines
drivers/extcon/extcon-axp288.c +0 -1
@@ -107,7 +107,6 @@ struct axp288_extcon_info {
 	struct gpio_desc *gpio_mux_cntl;
 	int irq[EXTCON_IRQ_END];
 	struct extcon_dev *edev;
-	struct notifier_block extcon_nb;
 	unsigned int previous_cable;
 };
 

Applied them(patch1/2/3/4). Thanks.

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
#17 lore raw

Hi,

Quoted 9 lines · Chanwoo Choi

Hi Hans,

Quoted 7 lines · Hans de Goede

Remove the unused extcon_nb struct member.

---
  drivers/extcon/extcon-axp288.c | 1 -
  1 file changed, 1 deletion(-)
Quoted 15 lines

drivers/extcon/extcon-axp288.c struct axp288_extcon_info { · line 112

Quoted 13 lines
drivers/extcon/extcon-axp288.c +0 -1
index 981fba56bc18..ba185e9ebb82 100644
@@ -107,7 +107,6 @@ struct axp288_extcon_info {
  	struct gpio_desc *gpio_mux_cntl;
  	int irq[EXTCON_IRQ_END];
  	struct extcon_dev *edev;
-	struct notifier_block extcon_nb;
  	unsigned int previous_cable;
  };
 

Applied them(patch1/2/3/4). Thanks.

Great, thank you.

Regards,

Hans