Skip to contentSkip to conversation

ARM: qcom: msm8974-hammerhead: add USB OTG support

PATCH In review Brian Masney 4 participants 16 messages Nov 1, 2018 – Dec 7, 2018

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

v2 cover ARM: qcom: msm8974-hammerhead: add USB OTG support

This patch set adds USB OTG support for the LG Nexus 5 (hammerhead) phone.

Changes in v2:
- Reworked patches to use gpio hogging as suggested in the bq24190 device tree documentation.
- bq24190_charger: changed to use a switch instead of an if as requested by Sebastian Reichel.
- bq24190_charger dt-bindings: added usb-otg-vbus to example.

Brian Masney (5):
dt-bindings: power: supply: bq24190_charger: add bq24192 and
usb-otg-vbus
power: supply: bq24190_charger: add extcon support for USB OTG
pinctrl: qcom: spmi-gpio: fix gpio-hog related boot issues
ARM: dts: qcom: msm8974: add gpio-ranges
ARM: dts: qcom: msm8974-hammerhead: add USB OTG support

Jonathan Marek (2):
power: supply: bq24190_charger: add support for bq24192 variant
power: supply: bq24190_charger: add of_match for usb-otg-vbus
regulator

 .../bindings/power/supply/bq24190.txt         |  9 +++
 .../qcom-msm8974-lge-nexus5-hammerhead.dts    | 60 +++++++++++++++++++
 arch/arm/boot/dts/qcom-msm8974.dtsi           | 11 ++++
 arch/arm/boot/dts/qcom-pm8941.dtsi            |  1 +
 drivers/pinctrl/qcom/pinctrl-spmi-gpio.c      | 21 +++++--
 drivers/power/supply/bq24190_charger.c        | 48 ++++++++++++++-
 6 files changed, 143 insertions(+), 7 deletions(-)
Signature · 1 line
2.17.2
#1 lore raw

PATCH v2 1/7 dt-bindings: power: supply: bq24190_charger: add bq24192 and usb-otg-vbus

Add support for the ti,bq24192 variant and a child node for the usb-otg-vbus regulator.

---
 .../devicetree/bindings/power/supply/bq24190.txt         | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/power/supply/bq24190.txt +9 -0
index 9e517d307070..c8ac028bd3c7 100644
@@ -3,6 +3,7 @@ TI BQ24190 Li-Ion Battery Charger
 Required properties:
 - compatible: contains one of the following:
     * "ti,bq24190"
+    * "ti,bq24192"
     * "ti,bq24192i"
 - reg: integer, I2C address of the charger.
 - interrupts[-extended]: configuration for charger INT pin.
@@ -19,6 +20,12 @@ Optional properties:
 - ti,system-minimum-microvolt: when power is connected and the battery is below
   minimum system voltage, the system will be regulated above this setting.
 
+child nodes:
+- usb-otg-vbus:
+  Usage: optional
+  Description: Regulator that is used to control the VBUS voltage direction for
+               either USB host mode or for charging on the OTG port.
+
 Notes:
 - Some circuit boards wire the chip's "OTG" pin high (enabling 500mA default
   charge current on USB SDP ports, among other features). To simulate this on
@@ -39,6 +46,8 @@ Example:
 		interrupts-extended = <&gpiochip 10 IRQ_TYPE_EDGE_FALLING>;
 		monitored-battery = <&bat>;
 		ti,system-minimum-microvolt = <3200000>;
+
+		usb_otg_vbus: usb-otg-vbus { };
 	};
 
 	&twl_gpio {
Signature · 1 line
2.17.2
#4 lore raw

PATCH v2 2/7 power: supply: bq24190_charger: add support for bq24192 variant

In reply to Brian Masney

From: Jonathan Marek <[email protected]>

This patch adds support for the bq24192 variant to bq24190_charger.

[[email protected]: Changed if statement to a switch based on feedback from Sebastian Reichel.]

---
 drivers/power/supply/bq24190_charger.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/power/supply/bq24190_charger.c +8 -2
index b58df04d03b3..44d3aff32885 100644
@@ -1637,8 +1637,12 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)
 	if (ret < 0)
 		return ret;
 
-	if (v != BQ24190_REG_VPRS_PN_24190 &&
-	    v != BQ24190_REG_VPRS_PN_24192I) {
+	switch (v) {
+	case BQ24190_REG_VPRS_PN_24190:
+	case BQ24190_REG_VPRS_PN_24192:
+	case BQ24190_REG_VPRS_PN_24192I:
+		break;
+	default:
 		dev_err(bdi->dev, "Error unknown model: 0x%02x\n", v);
 		return -ENODEV;
 	}
@@ -1931,6 +1935,7 @@ static const struct dev_pm_ops bq24190_pm_ops = {
 
 static const struct i2c_device_id bq24190_i2c_ids[] = {
 	{ "bq24190" },
+	{ "bq24192" },
 	{ "bq24192i" },
 	{ },
 };
@@ -1939,6 +1944,7 @@ MODULE_DEVICE_TABLE(i2c, bq24190_i2c_ids);
 #ifdef CONFIG_OF
 static const struct of_device_id bq24190_of_match[] = {
 	{ .compatible = "ti,bq24190", },
+	{ .compatible = "ti,bq24192", },
 	{ .compatible = "ti,bq24192i", },
 	{ },
 };
Signature · 1 line
2.17.2
#6 lore raw

PATCH v2 3/7 power: supply: bq24190_charger: add of_match for usb-otg-vbus regulator

In reply to Brian Masney

From: Jonathan Marek <[email protected]>

This patch adds an of_match for the usb-otg-vbus regulator to bq24190_charger.

---
 drivers/power/supply/bq24190_charger.c | 1 +
 1 file changed, 1 insertion(+)
drivers/power/supply/bq24190_charger.c +1 -0
index 44d3aff32885..9e7f3e33458a 100644
@@ -577,6 +577,7 @@ static const struct regulator_ops bq24190_vbus_ops = {
 
 static const struct regulator_desc bq24190_vbus_desc = {
 	.name = "usb_otg_vbus",
+	.of_match = "usb-otg-vbus",
 	.type = REGULATOR_VOLTAGE,
 	.owner = THIS_MODULE,
 	.ops = &bq24190_vbus_ops,
Signature · 1 line
2.17.2
#8 lore raw

PATCH v2 4/7 power: supply: bq24190_charger: add extcon support for USB OTG

In reply to Brian Masney

Add extcon support so that we can notify USB drivers of cable state changes. Based on work from Jonathan Marek. USB OTG was tested on a LG Nexus 5 (hammerhead) phone.

---
 drivers/power/supply/bq24190_charger.c | 37 +++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
drivers/power/supply/bq24190_charger.c +36 -1
index 9e7f3e33458a..4e64e6ac95c5 100644
@@ -21,6 +21,7 @@
 #include <linux/workqueue.h>
 #include <linux/gpio.h>
 #include <linux/i2c.h>
+#include <linux/extcon-provider.h>
 
 #define	BQ24190_MANUFACTURER	"Texas Instruments"
 
@@ -159,6 +160,7 @@
 struct bq24190_dev_info {
 	struct i2c_client		*client;
 	struct device			*dev;
+	struct extcon_dev		*edev;
 	struct power_supply		*charger;
 	struct power_supply		*battery;
 	struct delayed_work		input_current_limit_work;
@@ -174,6 +176,11 @@ struct bq24190_dev_info {
 	u8				watchdog;
 };
 
+static const unsigned int bq24190_usb_extcon_cable[] = {
+	EXTCON_USB,
+	EXTCON_NONE,
+};
+
 /*
  * The tables below provide a 2-way mapping for the value that goes in
  * the register field and the real-world value that it represents.
@@ -1528,6 +1535,20 @@ static const struct power_supply_desc bq24190_battery_desc = {
 	.property_is_writeable	= bq24190_battery_property_is_writeable,
 };
 
+static int bq24190_configure_usb_otg(struct bq24190_dev_info *bdi, u8 ss_reg)
+{
+	bool otg_enabled;
+	int ret;
+
+	otg_enabled = !!(ss_reg & BQ24190_REG_SS_VBUS_STAT_MASK);
+	ret = extcon_set_state_sync(bdi->edev, EXTCON_USB, otg_enabled);
+	if (ret < 0)
+		dev_err(bdi->dev, "Can't set extcon state to %d: %d\n",
+			otg_enabled, ret);
+
+	return ret;
+}
+
 static void bq24190_check_status(struct bq24190_dev_info *bdi)
 {
 	const u8 battery_mask_ss = BQ24190_REG_SS_CHRG_STAT_MASK;
@@ -1597,8 +1618,10 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi)
 		bdi->ss_reg = ss_reg;
 	}
 
-	if (alert_charger || alert_battery)
+	if (alert_charger || alert_battery) {
 		power_supply_changed(bdi->charger);
+		bq24190_configure_usb_otg(bdi, ss_reg);
+	}
 	if (alert_battery && bdi->battery)
 		power_supply_changed(bdi->battery);
 
@@ -1732,6 +1755,14 @@ static int bq24190_probe(struct i2c_client *client,
 		return -EINVAL;
 	}
 
+	bdi->edev = devm_extcon_dev_allocate(dev, bq24190_usb_extcon_cable);
+	if (IS_ERR(bdi->edev))
+		return PTR_ERR(bdi->edev);
+
+	ret = devm_extcon_dev_register(dev, bdi->edev);
+	if (ret < 0)
+		return ret;
+
 	pm_runtime_enable(dev);
 	pm_runtime_use_autosuspend(dev);
 	pm_runtime_set_autosuspend_delay(dev, 600);
@@ -1778,6 +1809,10 @@ static int bq24190_probe(struct i2c_client *client,
 		goto out_charger;
 	}
 
+	ret = bq24190_configure_usb_otg(bdi, bdi->ss_reg);
+	if (ret < 0)
+		goto out_charger;
+
 	ret = bq24190_sysfs_create_group(bdi);
 	if (ret < 0) {
 		dev_err(dev, "Can't create sysfs entries\n");
Signature · 1 line
2.17.2
#10 lore raw

PATCH v2 5/7 pinctrl: qcom: spmi-gpio: fix gpio-hog related boot issues

In reply to Brian Masney

When attempting to setup up a gpio hog, device probing would repeatedly fail with -EPROBE_DEFERED errors. It was caused by a circular dependency between the gpio and pinctrl frameworks. If the gpio-ranges property is present in device tree, then the gpio framework will handle the gpio pin registration and eliminate the circular dependency.

See Christian Lamparter's commit a86caa9ba5d7 ("pinctrl: msm: fix gpio-hog related boot issues") for a detailed commit message that explains the issue in much more detail. The code comment in this commit came from Christian's commit.

---
 drivers/pinctrl/qcom/pinctrl-spmi-gpio.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
drivers/pinctrl/qcom/pinctrl-spmi-gpio.c +17 -4
index a29efbe08f48..4c1ff9a1d156 100644
@@ -1028,10 +1028,23 @@ static int pmic_gpio_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	ret = gpiochip_add_pin_range(&state->chip, dev_name(dev), 0, 0, npins);
-	if (ret) {
-		dev_err(dev, "failed to add pin range\n");
-		goto err_range;
+	/*
+	 * For DeviceTree-supported systems, the gpio core checks the
+	 * pinctrl's device node for the "gpio-ranges" property.
+	 * If it is present, it takes care of adding the pin ranges
+	 * for the driver. In this case the driver can skip ahead.
+	 *
+	 * In order to remain compatible with older, existing DeviceTree
+	 * files which don't set the "gpio-ranges" property or systems that
+	 * utilize ACPI the driver has to call gpiochip_add_pin_range().
+	 */
+	if (!of_property_read_bool(dev->of_node, "gpio-ranges")) {
+		ret = gpiochip_add_pin_range(&state->chip, dev_name(dev), 0, 0,
+					     npins);
+		if (ret) {
+			dev_err(dev, "failed to add pin range\n");
+			goto err_range;
+		}
 	}
 
 	return 0;
Signature · 1 line
2.17.2
#13 lore raw

PATCH v2 6/7 ARM: dts: qcom: msm8974: add gpio-ranges

In reply to Brian Masney

This adds the gpio-ranges property to pm8941_gpios so that the GPIO pins are initialized by the GPIO framework and not pinctrl. This fixes a circular dependency so GPIO hogging can be used on this board.

---
 arch/arm/boot/dts/qcom-pm8941.dtsi | 1 +
 1 file changed, 1 insertion(+)
arch/arm/boot/dts/qcom-pm8941.dtsi +1 -0
index 2515c5c217ac..9a91b758f7aa 100644
@@ -63,6 +63,7 @@
 			compatible = "qcom,pm8941-gpio", "qcom,spmi-gpio";
 			reg = <0xc000>;
 			gpio-controller;
+			gpio-ranges = <&pm8941_gpios 0 0 36>;
 			#gpio-cells = <2>;
 			interrupts = <0 0xc0 0 IRQ_TYPE_NONE>,
 				     <0 0xc1 0 IRQ_TYPE_NONE>,
Signature · 1 line
2.17.2
#15 lore raw

PATCH v2 7/7 ARM: dts: qcom: msm8974-hammerhead: add USB OTG support

In reply to Brian Masney

Add the device tree bindings for USB OTG support. Driver was tested using on a LG Nexus 5 (hammerhead) phone. This patch is based on work from Jonathan Marek and from the other msm8974 devices.

---
 .../qcom-msm8974-lge-nexus5-hammerhead.dts    | 60 +++++++++++++++++++
 arch/arm/boot/dts/qcom-msm8974.dtsi           | 11 ++++
 2 files changed, 71 insertions(+)
arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts +60 -0
index ed8f064d0895..f67ab43956dc 100644
@@ -242,6 +242,16 @@
 			};
 		};
 
+		i2c1_pins: i2c1 {
+			mux {
+				pins = "gpio2", "gpio3";
+				function = "blsp_i2c1";
+
+				drive-strength = <2>;
+				bias-disable;
+			};
+		};
+
 		i2c3_pins: i2c3 {
 			mux {
 				pins = "gpio10", "gpio11";
@@ -343,6 +353,24 @@
 		};
 	};
 
+	i2c@f9923000 {
+		status = "ok";
+		pinctrl-names = "default";
+		pinctrl-0 = <&i2c1_pins>;
+		clock-frequency = <100000>;
+		qcom,src-freq = <50000000>;
+
+		charger: bq24192@6b {
+			compatible = "ti,bq24192";
+			reg = <0x6b>;
+			interrupts-extended = <&spmi_bus 0 0xd5 0 IRQ_TYPE_EDGE_FALLING>;
+
+			omit-battery-class;
+
+			usb_otg_vbus: usb-otg-vbus { };
+		};
+	};
+
 	i2c@f9925000 {
 		status = "ok";
 		pinctrl-names = "default";
@@ -360,6 +388,31 @@
 			amstaos,proximity-diodes = <0>;
 		};
 	};
+
+	usb@f9a55000 {
+		status = "ok";
+
+		phys = <&usb_hs1_phy>;
+		phy-select = <&tcsr 0xb000 0>;
+
+		extcon = <&charger>, <&usb_id>;
+		vbus-supply = <&usb_otg_vbus>;
+
+		hnp-disable;
+		srp-disable;
+		adp-disable;
+
+		ulpi {
+			phy@a {
+				status = "ok";
+
+				v1p8-supply = <&pm8941_l6>;
+				v3p3-supply = <&pm8941_l24>;
+
+				qcom,init-seq = /bits/ 8 <0x1 0x64>;
+			};
+		};
+	};
 };
 
 &spmi_bus {
@@ -372,6 +425,13 @@
 				bias-pull-up;
 				power-source = <PM8941_GPIO_S3>;
 			};
+
+			otg {
+				gpio-hog;
+				gpios = <35 GPIO_ACTIVE_HIGH>;
+				output-high;
+				line-name = "otg-gpio";
+			};
 		};
 	};
 };
arch/arm/boot/dts/qcom-msm8974.dtsi +11 -0
index aba159d5a95a..8294192db9eb 100644
@@ -704,6 +704,17 @@
 			interrupts = <GIC_SPI 208 IRQ_TYPE_LEVEL_HIGH>;
 		};
 
+		i2c@f9923000 {
+			status = "disabled";
+			compatible = "qcom,i2c-qup-v2.1.1";
+			reg = <0xf9923000 0x1000>;
+			interrupts = <0 95 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&gcc GCC_BLSP1_QUP1_I2C_APPS_CLK>, <&gcc GCC_BLSP1_AHB_CLK>;
+			clock-names = "core", "iface";
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+
 		i2c@f9924000 {
 			status = "disabled";
 			compatible = "qcom,i2c-qup-v2.1.1";
Signature · 1 line
2.17.2
maintainer Reviewed-by on v2 1/7
#2 lore raw

Re: [PATCH v2 1/7] dt-bindings: power: supply: bq24190_charger: add bq24192 and usb-otg-vbus

In reply to Brian Masney
Quoted 8 lines · Brian Masney

Add support for the ti,bq24192 variant and a child node for the usb-otg-vbus regulator.

---
 .../devicetree/bindings/power/supply/bq24190.txt         | 9 +++++++++
 1 file changed, 9 insertions(+)
#11 lore raw

Re: [PATCH v2 5/7] pinctrl: qcom: spmi-gpio: fix gpio-hog related boot issues

In reply to Brian Masney
Quoted 6 lines · Brian Masney

When attempting to setup up a gpio hog, device probing would repeatedly fail with -EPROBE_DEFERED errors. It was caused by a circular dependency between the gpio and pinctrl frameworks. If the gpio-ranges property is present in device tree, then the gpio framework will handle the gpio pin registration and eliminate the circular dependency.

Quoted 6 lines

See Christian Lamparter's commit a86caa9ba5d7 ("pinctrl: msm: fix gpio-hog related boot issues") for a detailed commit message that explains the issue in much more detail. The code comment in this commit came from Christian's commit.

No word from Bjorn but I trust my own intuition and applied it.

Björn: shout if it's wrong.

Question: should this also be done for pinctrl-ssbi-gpio.c?

Yours,
Linus Walleij

#12 lore raw

Re: [PATCH v2 5/7] pinctrl: qcom: spmi-gpio: fix gpio-hog related boot issues

Quoted 13 lines · Linus Walleij
Quoted 11 lines · Brian Masney

When attempting to setup up a gpio hog, device probing would repeatedly fail with -EPROBE_DEFERED errors. It was caused by a circular dependency between the gpio and pinctrl frameworks. If the gpio-ranges property is present in device tree, then the gpio framework will handle the gpio pin registration and eliminate the circular dependency.

See Christian Lamparter's commit a86caa9ba5d7 ("pinctrl: msm: fix gpio-hog related boot issues") for a detailed commit message that explains the issue in much more detail. The code comment in this commit came from Christian's commit.

Quoted 7 lines
Quoted 1 line

No word from Bjorn but I trust my own intuition and applied it.

Björn: shout if it's wrong.

Question: should this also be done for pinctrl-ssbi-gpio.c?

Yes, I believe so.

Brian

#3 lore raw

Re: [PATCH v2 1/7] dt-bindings: power: supply: bq24190_charger: add bq24192 and usb-otg-vbus

In reply to Brian Masney

Hi,

Quoted 5 lines · Brian Masney

Add support for the ti,bq24192 variant and a child node for the usb-otg-vbus regulator.

---

Thanks, queued.

-- Sebastian

Quoted 40 lines
 .../devicetree/bindings/power/supply/bq24190.txt         | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/power/supply/bq24190.txt +9 -0
index 9e517d307070..c8ac028bd3c7 100644
@@ -3,6 +3,7 @@ TI BQ24190 Li-Ion Battery Charger
 Required properties:
 - compatible: contains one of the following:
     * "ti,bq24190"
+    * "ti,bq24192"
     * "ti,bq24192i"
 - reg: integer, I2C address of the charger.
 - interrupts[-extended]: configuration for charger INT pin.
@@ -19,6 +20,12 @@ Optional properties:
 - ti,system-minimum-microvolt: when power is connected and the battery is below
   minimum system voltage, the system will be regulated above this setting.
 
+child nodes:
+- usb-otg-vbus:
+  Usage: optional
+  Description: Regulator that is used to control the VBUS voltage direction for
+               either USB host mode or for charging on the OTG port.
+
 Notes:
 - Some circuit boards wire the chip's "OTG" pin high (enabling 500mA default
   charge current on USB SDP ports, among other features). To simulate this on
@@ -39,6 +46,8 @@ Example:
 		interrupts-extended = <&gpiochip 10 IRQ_TYPE_EDGE_FALLING>;
 		monitored-battery = <&bat>;
 		ti,system-minimum-microvolt = <3200000>;
+
+		usb_otg_vbus: usb-otg-vbus { };
 	};
 
 	&twl_gpio {
Signature · 1 line
2.17.2
#5 lore raw

Re: [PATCH v2 2/7] power: supply: bq24190_charger: add support for bq24192 variant

In reply to Brian Masney

Hi,

Quoted 9 lines · Brian Masney

From: Jonathan Marek <[email protected]>

This patch adds support for the bq24192 variant to bq24190_charger.

[[email protected]: Changed if statement to a switch based on feedback from Sebastian Reichel.]

---

Thanks, queued.

-- Sebastian

Quoted 41 lines
 drivers/power/supply/bq24190_charger.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/power/supply/bq24190_charger.c +8 -2
index b58df04d03b3..44d3aff32885 100644
@@ -1637,8 +1637,12 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)
 	if (ret < 0)
 		return ret;
 
-	if (v != BQ24190_REG_VPRS_PN_24190 &&
-	    v != BQ24190_REG_VPRS_PN_24192I) {
+	switch (v) {
+	case BQ24190_REG_VPRS_PN_24190:
+	case BQ24190_REG_VPRS_PN_24192:
+	case BQ24190_REG_VPRS_PN_24192I:
+		break;
+	default:
 		dev_err(bdi->dev, "Error unknown model: 0x%02x\n", v);
 		return -ENODEV;
 	}
@@ -1931,6 +1935,7 @@ static const struct dev_pm_ops bq24190_pm_ops = {
 
 static const struct i2c_device_id bq24190_i2c_ids[] = {
 	{ "bq24190" },
+	{ "bq24192" },
 	{ "bq24192i" },
 	{ },
 };
@@ -1939,6 +1944,7 @@ MODULE_DEVICE_TABLE(i2c, bq24190_i2c_ids);
 #ifdef CONFIG_OF
 static const struct of_device_id bq24190_of_match[] = {
 	{ .compatible = "ti,bq24190", },
+	{ .compatible = "ti,bq24192", },
 	{ .compatible = "ti,bq24192i", },
 	{ },
 };
Signature · 1 line
2.17.2
#7 lore raw

Re: [PATCH v2 3/7] power: supply: bq24190_charger: add of_match for usb-otg-vbus regulator

In reply to Brian Masney

Hi,

Quoted 8 lines · Brian Masney

From: Jonathan Marek <[email protected]>

This patch adds an of_match for the usb-otg-vbus regulator to bq24190_charger.

---

Thanks, queued.

-- Sebastian

Quoted 18 lines
 drivers/power/supply/bq24190_charger.c | 1 +
 1 file changed, 1 insertion(+)
drivers/power/supply/bq24190_charger.c +1 -0
index 44d3aff32885..9e7f3e33458a 100644
@@ -577,6 +577,7 @@ static const struct regulator_ops bq24190_vbus_ops = {
 
 static const struct regulator_desc bq24190_vbus_desc = {
 	.name = "usb_otg_vbus",
+	.of_match = "usb-otg-vbus",
 	.type = REGULATOR_VOLTAGE,
 	.owner = THIS_MODULE,
 	.ops = &bq24190_vbus_ops,
Signature · 1 line
2.17.2
#9 lore raw

Re: [PATCH v2 4/7] power: supply: bq24190_charger: add extcon support for USB OTG

In reply to Brian Masney

Hi,

Quoted 6 lines · Brian Masney

Add extcon support so that we can notify USB drivers of cable state changes. Based on work from Jonathan Marek. USB OTG was tested on a LG Nexus 5 (hammerhead) phone.

---

Thanks, queued.

-- Sebastian

Quoted 97 lines
 drivers/power/supply/bq24190_charger.c | 37 +++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
drivers/power/supply/bq24190_charger.c +36 -1
index 9e7f3e33458a..4e64e6ac95c5 100644
@@ -21,6 +21,7 @@
 #include <linux/workqueue.h>
 #include <linux/gpio.h>
 #include <linux/i2c.h>
+#include <linux/extcon-provider.h>
 
 #define	BQ24190_MANUFACTURER	"Texas Instruments"
 
@@ -159,6 +160,7 @@
 struct bq24190_dev_info {
 	struct i2c_client		*client;
 	struct device			*dev;
+	struct extcon_dev		*edev;
 	struct power_supply		*charger;
 	struct power_supply		*battery;
 	struct delayed_work		input_current_limit_work;
@@ -174,6 +176,11 @@ struct bq24190_dev_info {
 	u8				watchdog;
 };
 
+static const unsigned int bq24190_usb_extcon_cable[] = {
+	EXTCON_USB,
+	EXTCON_NONE,
+};
+
 /*
  * The tables below provide a 2-way mapping for the value that goes in
  * the register field and the real-world value that it represents.
@@ -1528,6 +1535,20 @@ static const struct power_supply_desc bq24190_battery_desc = {
 	.property_is_writeable	= bq24190_battery_property_is_writeable,
 };
 
+static int bq24190_configure_usb_otg(struct bq24190_dev_info *bdi, u8 ss_reg)
+{
+	bool otg_enabled;
+	int ret;
+
+	otg_enabled = !!(ss_reg & BQ24190_REG_SS_VBUS_STAT_MASK);
+	ret = extcon_set_state_sync(bdi->edev, EXTCON_USB, otg_enabled);
+	if (ret < 0)
+		dev_err(bdi->dev, "Can't set extcon state to %d: %d\n",
+			otg_enabled, ret);
+
+	return ret;
+}
+
 static void bq24190_check_status(struct bq24190_dev_info *bdi)
 {
 	const u8 battery_mask_ss = BQ24190_REG_SS_CHRG_STAT_MASK;
@@ -1597,8 +1618,10 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi)
 		bdi->ss_reg = ss_reg;
 	}
 
-	if (alert_charger || alert_battery)
+	if (alert_charger || alert_battery) {
 		power_supply_changed(bdi->charger);
+		bq24190_configure_usb_otg(bdi, ss_reg);
+	}
 	if (alert_battery && bdi->battery)
 		power_supply_changed(bdi->battery);
 
@@ -1732,6 +1755,14 @@ static int bq24190_probe(struct i2c_client *client,
 		return -EINVAL;
 	}
 
+	bdi->edev = devm_extcon_dev_allocate(dev, bq24190_usb_extcon_cable);
+	if (IS_ERR(bdi->edev))
+		return PTR_ERR(bdi->edev);
+
+	ret = devm_extcon_dev_register(dev, bdi->edev);
+	if (ret < 0)
+		return ret;
+
 	pm_runtime_enable(dev);
 	pm_runtime_use_autosuspend(dev);
 	pm_runtime_set_autosuspend_delay(dev, 600);
@@ -1778,6 +1809,10 @@ static int bq24190_probe(struct i2c_client *client,
 		goto out_charger;
 	}
 
+	ret = bq24190_configure_usb_otg(bdi, bdi->ss_reg);
+	if (ret < 0)
+		goto out_charger;
+
 	ret = bq24190_sysfs_create_group(bdi);
 	if (ret < 0) {
 		dev_err(dev, "Can't create sysfs entries\n");
Signature · 1 line
2.17.2
#14 lore raw

Re: [PATCH v2 6/7] ARM: dts: qcom: msm8974: add gpio-ranges

In reply to Brian Masney
Quoted 5 lines · Brian Masney

This adds the gpio-ranges property to pm8941_gpios so that the GPIO pins are initialized by the GPIO framework and not pinctrl. This fixes a circular dependency so GPIO hogging can be used on this board.

Hi Andy,

All of the dependencies for USB have been merged into their respective trees. Patches 6 and 7 in this series are the only two that are outstanding for your consideration.

I know that I'm still waiting for a review from Dmitry regarding the new vibrator driver [1] and we're nearing the end of the development cycle. In case he runs into an issue with that driver, I verified that I can use git am to apply patches 6 and 7 in this series for USB, and the patch for WiFi [2] without the bindings for the vibrator. I'm hoping to get as much of this merged into this kernel development cycle as possible.

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/

Thanks,

Brian