* [PATCH v2 0/2] Enable USB support (peripheral mode) for Xiaomi Redmi 5A (riva)
@ 2026-09-12 15:18 Reza Kurniawan
2026-09-12 15:18 ` [PATCH v2 1/2] power: supply: bq256xx: Expose VBUS state through extcon Reza Kurniawan
2026-09-12 15:18 ` [PATCH v2 2/2] arm64: dts: qcom: msm8917-xiaomi-riva: Enable USB support (peripheral mode) Reza Kurniawan
0 siblings, 2 replies; 3+ messages in thread
From: Reza Kurniawan @ 2026-09-12 15:18 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>
---
Changes in v2:
- Make extcon feature optional
- Link to v1: https://patch.msgid.link/20260912-riva-usb-v1-0-0acd5cf8c62a@gmail.com
To: Sebastian Reichel <sre@kernel.org>
To: Bjorn Andersson <andersson@kernel.org>
To: Konrad Dybcio <konradybcio@kernel.org>
To: Abel Vesa <abelvesa@kernel.org>
To: Rob Herring <robh@kernel.org>
To: Krzysztof Kozlowski <krzk+dt@kernel.org>
To: Conor Dooley <conor+dt@kernel.org>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-arm-msm@vger.kernel.org
Cc: devicetree@vger.kernel.org
---
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/Kconfig | 1 +
drivers/power/supply/bq256xx_charger.c | 96 ++++++++++++++++++++++--
3 files changed, 105 insertions(+), 9 deletions(-)
---
base-commit: 68142f986ff04b2b70b31db00f719bf690f64a9a
change-id: 20260912-riva-usb-ec9ef25c885c
Best regards,
--
Reza Kurniawan <imkyufie@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2 1/2] power: supply: bq256xx: Expose VBUS state through extcon
2026-09-12 15:18 [PATCH v2 0/2] Enable USB support (peripheral mode) for Xiaomi Redmi 5A (riva) Reza Kurniawan
@ 2026-09-12 15:18 ` Reza Kurniawan
2026-09-12 15:18 ` [PATCH v2 2/2] arm64: dts: qcom: msm8917-xiaomi-riva: Enable USB support (peripheral mode) Reza Kurniawan
1 sibling, 0 replies; 3+ messages in thread
From: Reza Kurniawan @ 2026-09-12 15:18 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/Kconfig | 1 +
drivers/power/supply/bq256xx_charger.c | 96 +++++++++++++++++++++++++++++++---
2 files changed, 89 insertions(+), 8 deletions(-)
diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index b89ef40df..ee7dc5f26 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -850,6 +850,7 @@ config CHARGER_BQ256XX
tristate "TI BQ256XX battery charger driver"
depends on I2C
depends on GPIOLIB || COMPILE_TEST
+ depends on EXTCON || !EXTCON
select REGMAP_I2C
help
Say Y to enable support for the TI BQ256XX battery chargers. The
diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c
index 4b1f81b1e..454bc497b 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,92 @@ 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 const unsigned int bq256xx_usb_extcon_cable[] = {
+ EXTCON_USB,
+ EXTCON_NONE,
+};
+
+static void bq256xx_extcon_update(struct bq256xx_device *bq, bool online)
+{
+ int ret;
+
+ if (!bq->edev)
+ return;
+
+ 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 int bq256xx_extcon_init(struct bq256xx_device *bq)
+{
+ unsigned int charger_status_0;
+ int ret;
+
+ if (!IS_REACHABLE(CONFIG_EXTCON)) {
+ dev_dbg(bq->dev, "Extcon support is disabled\n");
+ return 0;
+ }
+
+ 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 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;
@@ -1743,6 +1817,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 [flat|nested] 3+ messages in thread
* [PATCH v2 2/2] arm64: dts: qcom: msm8917-xiaomi-riva: Enable USB support (peripheral mode)
2026-09-12 15:18 [PATCH v2 0/2] Enable USB support (peripheral mode) for Xiaomi Redmi 5A (riva) Reza Kurniawan
2026-09-12 15:18 ` [PATCH v2 1/2] power: supply: bq256xx: Expose VBUS state through extcon Reza Kurniawan
@ 2026-09-12 15:18 ` Reza Kurniawan
1 sibling, 0 replies; 3+ messages in thread
From: Reza Kurniawan @ 2026-09-12 15:18 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 [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-12 15:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-12 15:18 [PATCH v2 0/2] Enable USB support (peripheral mode) for Xiaomi Redmi 5A (riva) Reza Kurniawan
2026-09-12 15:18 ` [PATCH v2 1/2] power: supply: bq256xx: Expose VBUS state through extcon Reza Kurniawan
2026-09-12 15:18 ` [PATCH v2 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
all inboxes | Powered by JetHome®