Devicetree
 help / color / mirror / Atom feed
* [PATCH 0/2] Enable USB support (peripheral mode) for Xiaomi Redmi 5A (riva)
@ 2026-09-12 12:27 Reza Kurniawan
  2026-09-12 12:27 ` [PATCH 1/2] power: supply: bq256xx: Expose VBUS state through extcon Reza Kurniawan
  2026-09-12 12:27 ` [PATCH 2/2] arm64: dts: qcom: msm8917-xiaomi-riva: Enable USB support (peripheral mode) Reza Kurniawan
  0 siblings, 2 replies; 4+ messages in thread
From: Reza Kurniawan @ 2026-09-12 12:27 UTC (permalink / raw)
  To: Sebastian Reichel, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-pm, linux-kernel, linux-arm-msm, devicetree, Reza Kurniawan

The purpose of this series is to enable the device to act as a USB peripheral.
It enables USB-related DT nodes (controller and PHY) and modifies the
charger driver (BQ256XX) to expose its VBUS state through extcon.

Driver change is required since the device has its VBUS connected to the
charger IC, which means cable connection/disconnection events must be fed
from the charger IC, to the controller driver to dynamically enable/disable
the USB gadget functionality.

Signed-off-by: Reza Kurniawan <imkyufie@gmail.com>
---
Reza Kurniawan (2):
      power: supply: bq256xx: Expose VBUS state through extcon
      arm64: dts: qcom: msm8917-xiaomi-riva: Enable USB support (peripheral mode)

 arch/arm64/boot/dts/qcom/msm8917-xiaomi-riva.dts | 17 ++++-
 drivers/power/supply/bq256xx_charger.c           | 88 +++++++++++++++++++++---
 2 files changed, 96 insertions(+), 9 deletions(-)
---
base-commit: 68142f986ff04b2b70b31db00f719bf690f64a9a
change-id: 20260912-riva-usb-ec9ef25c885c

Best regards,
--  
Reza Kurniawan <imkyufie@gmail.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] power: supply: bq256xx: Expose VBUS state through extcon
  2026-09-12 12:27 [PATCH 0/2] Enable USB support (peripheral mode) for Xiaomi Redmi 5A (riva) Reza Kurniawan
@ 2026-09-12 12:27 ` Reza Kurniawan
  2026-09-12 12:37   ` sashiko-bot
  2026-09-12 12:27 ` [PATCH 2/2] arm64: dts: qcom: msm8917-xiaomi-riva: Enable USB support (peripheral mode) Reza Kurniawan
  1 sibling, 1 reply; 4+ messages in thread
From: Reza Kurniawan @ 2026-09-12 12:27 UTC (permalink / raw)
  To: Sebastian Reichel, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-pm, linux-kernel, linux-arm-msm, devicetree, Reza Kurniawan

Useful for USB controllers needing to sense VBUS state changes. This is
needed for devices like Xiaomi Redmi 5A (riva) that doesn't have its VBUS
session comparator wired directly to the USB connector pin to automatically
enable certain USB functions upon the presence of a USB power input.

Signed-off-by: Reza Kurniawan <imkyufie@gmail.com>
---
 drivers/power/supply/bq256xx_charger.c | 88 ++++++++++++++++++++++++++++++----
 1 file changed, 80 insertions(+), 8 deletions(-)

diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c
index 4b1f81b1e..46b036be3 100644
--- a/drivers/power/supply/bq256xx_charger.c
+++ b/drivers/power/supply/bq256xx_charger.c
@@ -16,6 +16,7 @@
 #include <linux/moduleparam.h>
 #include <linux/slab.h>
 #include <linux/acpi.h>
+#include <linux/extcon-provider.h>
 
 #define BQ256XX_MANUFACTURER "Texas Instruments"
 
@@ -209,6 +210,7 @@ enum bq256xx_id {
  * @client: i2c client structure
  * @regmap: register map structure
  * @dev: device structure
+ * @edev: extcon device registered to report vbus state changes
  * @charger: power supply registered for the charger
  * @battery: power supply registered for the battery
  * @lock: mutex lock structure
@@ -229,6 +231,7 @@ enum bq256xx_id {
 struct bq256xx_device {
 	struct i2c_client *client;
 	struct device *dev;
+	struct extcon_dev *edev;
 	struct power_supply *charger;
 	struct power_supply *battery;
 	struct mutex lock;
@@ -1164,8 +1167,14 @@ static int bq256xx_get_charger_property(struct power_supply *psy,
 	return ret;
 }
 
-static bool bq256xx_state_changed(struct bq256xx_device *bq,
-				  struct bq256xx_state *new_state)
+enum bq256xx_state_change {
+	CHANGED_NONE,
+	CHANGED_VBUS,
+	CHANGED_OTHER
+};
+
+static enum bq256xx_state_change bq256xx_state_changed(struct bq256xx_device *bq,
+						       struct bq256xx_state *new_state)
 {
 	struct bq256xx_state old_state;
 
@@ -1173,27 +1182,50 @@ static bool bq256xx_state_changed(struct bq256xx_device *bq,
 	old_state = bq->state;
 	mutex_unlock(&bq->lock);
 
-	return memcmp(&old_state, new_state, sizeof(struct bq256xx_state)) != 0;
+	if (new_state->online != old_state.online)
+		return CHANGED_VBUS;
+
+	if (memcmp(&old_state, new_state, sizeof(struct bq256xx_state)) != 0)
+		return CHANGED_OTHER;
+
+	return CHANGED_NONE;
+}
+
+static void bq256xx_extcon_update(struct bq256xx_device *bq, bool online)
+{
+	int ret;
+
+	ret = extcon_set_state_sync(bq->edev, EXTCON_USB, online);
+	if (ret)
+		dev_err(bq->dev, "Failed to update extcon state: %d\n", ret);
 }
 
 static irqreturn_t bq256xx_irq_handler_thread(int irq, void *private)
 {
 	struct bq256xx_device *bq = private;
 	struct bq256xx_state state;
+	enum bq256xx_state_change changed;
 	int ret;
 
 	ret = bq256xx_get_state(bq, &state);
 	if (ret < 0)
 		goto irq_out;
 
-	if (!bq256xx_state_changed(bq, &state))
+	changed = bq256xx_state_changed(bq, &state);
+	switch (changed) {
+	case CHANGED_NONE:
 		goto irq_out;
 
-	mutex_lock(&bq->lock);
-	bq->state = state;
-	mutex_unlock(&bq->lock);
+	case CHANGED_VBUS:
+		bq256xx_extcon_update(bq, state.online);
+		fallthrough;
+	case CHANGED_OTHER:
+		mutex_lock(&bq->lock);
+		bq->state = state;
+		mutex_unlock(&bq->lock);
 
-	power_supply_changed(bq->charger);
+		power_supply_changed(bq->charger);
+	}
 
 irq_out:
 	return IRQ_HANDLED;
@@ -1554,6 +1586,40 @@ static int bq256xx_power_supply_init(struct bq256xx_device *bq,
 	return 0;
 }
 
+static const unsigned int bq256xx_usb_extcon_cable[] = {
+	EXTCON_USB,
+	EXTCON_NONE,
+};
+
+static int bq256xx_extcon_init(struct bq256xx_device *bq)
+{
+	unsigned int charger_status_0;
+	int ret;
+
+	bq->edev = devm_extcon_dev_allocate(bq->dev, bq256xx_usb_extcon_cable);
+	if (IS_ERR(bq->edev)) {
+		dev_err(bq->dev, "Failed to allocate extcon device\n");
+		return PTR_ERR(bq->edev);
+	}
+
+	ret = devm_extcon_dev_register(bq->dev, bq->edev);
+	if (ret < 0) {
+		dev_err(bq->dev, "Failed to register extcon device\n");
+		return ret;
+	}
+
+	ret = regmap_read(bq->regmap, BQ256XX_CHARGER_STATUS_0,
+			  &charger_status_0);
+	if (ret) {
+		dev_err(bq->dev, "Failed to read charger status\n");
+		return ret;
+	}
+
+	bq256xx_extcon_update(bq, !!(charger_status_0 & BQ256XX_PG_STAT_MASK));
+
+	return 0;
+}
+
 static int bq256xx_hw_init(struct bq256xx_device *bq)
 {
 	struct power_supply_battery_info *bat_info;
@@ -1743,6 +1809,12 @@ static int bq256xx_probe(struct i2c_client *client)
 	if (!IS_ERR_OR_NULL(bq->usb3_phy))
 		usb_register_notifier(bq->usb3_phy, &bq->usb_nb);
 
+	ret = bq256xx_extcon_init(bq);
+	if (ret) {
+		dev_err(dev, "Failed to register extcon device\n");
+		return ret;
+	}
+
 	if (client->irq) {
 		ret = devm_request_threaded_irq(dev, client->irq, NULL,
 						bq256xx_irq_handler_thread,

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] arm64: dts: qcom: msm8917-xiaomi-riva: Enable USB support (peripheral mode)
  2026-09-12 12:27 [PATCH 0/2] Enable USB support (peripheral mode) for Xiaomi Redmi 5A (riva) Reza Kurniawan
  2026-09-12 12:27 ` [PATCH 1/2] power: supply: bq256xx: Expose VBUS state through extcon Reza Kurniawan
@ 2026-09-12 12:27 ` Reza Kurniawan
  1 sibling, 0 replies; 4+ messages in thread
From: Reza Kurniawan @ 2026-09-12 12:27 UTC (permalink / raw)
  To: Sebastian Reichel, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-pm, linux-kernel, linux-arm-msm, devicetree, Reza Kurniawan

Enable USB node and PHY. Since VBUS is wired to the charger IC, also
set extcon of the USB node to inform the USB driver of cable events
emitted by the charger driver.

Signed-off-by: Reza Kurniawan <imkyufie@gmail.com>
---
 arch/arm64/boot/dts/qcom/msm8917-xiaomi-riva.dts | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/qcom/msm8917-xiaomi-riva.dts b/arch/arm64/boot/dts/qcom/msm8917-xiaomi-riva.dts
index 7c323214a..c47aad978 100644
--- a/arch/arm64/boot/dts/qcom/msm8917-xiaomi-riva.dts
+++ b/arch/arm64/boot/dts/qcom/msm8917-xiaomi-riva.dts
@@ -69,7 +69,7 @@ power-monitor@55 {
 		monitored-battery = <&battery>;
 	};
 
-	charger@6b {
+	bq25601_charger: charger@6b {
 		compatible = "ti,bq25601";
 		reg = <0x6b>;
 		interrupts-extended = <&tlmm 61 IRQ_TYPE_EDGE_FALLING>;
@@ -89,3 +89,18 @@ bq25601_int_default: bq25601-int-default-state {
 		bias-pull-up;
 	};
 };
+
+&usb {
+	dr_mode = "peripheral";
+	extcon = <&bq25601_charger>;
+
+	status = "okay";
+};
+
+&usb_hs_phy {
+	vdd-supply = <&pm8937_l2>;
+	vdda1p8-supply = <&pm8937_l7>;
+	vdda3p3-supply = <&pm8937_l13>;
+
+	status = "okay";
+};

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] power: supply: bq256xx: Expose VBUS state through extcon
  2026-09-12 12:27 ` [PATCH 1/2] power: supply: bq256xx: Expose VBUS state through extcon Reza Kurniawan
@ 2026-09-12 12:37   ` sashiko-bot
  0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-09-12 12:37 UTC (permalink / raw)
  To: Reza Kurniawan; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing Kconfig dependency for EXTCON causes build failures, or runtime probe regression when CONFIG_EXTCON is disabled.
--

commit 6faa47b2b9aa55be622397291bdc7fb836f78d0c
Author: Reza Kurniawan <imkyufie@gmail.com>

power: supply: bq256xx: Expose VBUS state through extcon

This commit adds support to report VBUS state changes through the extcon 
subsystem for the bq256xx charger. This allows USB controllers to sense 
power input presence on devices where the VBUS session comparator is not 
directly wired.

> diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c
> index 4b1f81b1ed867..46b036be38dd8 100644
> --- a/drivers/power/supply/bq256xx_charger.c
> +++ b/drivers/power/supply/bq256xx_charger.c

[ ... ]

> @@ -1554,6 +1586,40 @@ static int bq256xx_power_supply_init(struct bq256xx_device *bq,
>  	return 0;
>  }
>  
> +static const unsigned int bq256xx_usb_extcon_cable[] = {
> +	EXTCON_USB,
> +	EXTCON_NONE,
> +};
> +
> +static int bq256xx_extcon_init(struct bq256xx_device *bq)
> +{
> +	unsigned int charger_status_0;
> +	int ret;
> +
> +	bq->edev = devm_extcon_dev_allocate(bq->dev, bq256xx_usb_extcon_cable);
> +	if (IS_ERR(bq->edev)) {
> +		dev_err(bq->dev, "Failed to allocate extcon device\n");
> +		return PTR_ERR(bq->edev);

[Severity: High]
When the extcon configuration is disabled, the dummy inline implementation 
of devm_extcon_dev_allocate in extcon-provider.h returns -ENOSYS. Will 
this cause bq256xx_extcon_init in drivers/power/supply/bq256xx_charger.c 
to immediately return a fatal error on systems without extcon support?

> +	}
> +
> +	ret = devm_extcon_dev_register(bq->dev, bq->edev);

[ ... ]

> @@ -1743,6 +1809,12 @@ static int bq256xx_probe(struct i2c_client *client)
>  	if (!IS_ERR_OR_NULL(bq->usb3_phy))
>  		usb_register_notifier(bq->usb3_phy, &bq->usb_nb);
>  
> +	ret = bq256xx_extcon_init(bq);
> +	if (ret) {
> +		dev_err(dev, "Failed to register extcon device\n");
> +		return ret;

[Severity: High]
Because the -ENOSYS error propagates here, does this unconditionally abort 
the entire driver probe in bq256xx_probe when extcon is disabled?

Since extcon appears to be an optional feature for exposing VBUS state, 
should this missing dependency be handled more gracefully, perhaps by 
treating -ENOSYS as non-fatal or adding a proper dependency in the build 
configuration?

> +	}
> +
>  	if (client->irq) {
>  		ret = devm_request_threaded_irq(dev, client->irq, NULL,
>  						bq256xx_irq_handler_thread,

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260912-riva-usb-v1-0-0acd5cf8c62a@gmail.com?part=1

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-12 12:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-12 12:27 [PATCH 0/2] Enable USB support (peripheral mode) for Xiaomi Redmi 5A (riva) Reza Kurniawan
2026-09-12 12:27 ` [PATCH 1/2] power: supply: bq256xx: Expose VBUS state through extcon Reza Kurniawan
2026-09-12 12:37   ` sashiko-bot
2026-09-12 12:27 ` [PATCH 2/2] arm64: dts: qcom: msm8917-xiaomi-riva: Enable USB support (peripheral mode) Reza Kurniawan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox