* [PATCH 0/2] arm64: qcom: Add SMBLite charger support for PM4125
@ 2026-11-24 9:15 Raj Aryan
2026-11-24 9:15 ` [PATCH 1/2] dt-bindings: power: supply: Add qcom,pm4125-charger binding Raj Aryan
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Raj Aryan @ 2026-11-24 9:15 UTC (permalink / raw)
To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Casey Connolly, Liam Girdwood, Mark Brown
Cc: linux-pm, devicetree, linux-kernel, linux-arm-msm, Rakesh Kota,
Raj Aryan
The PM4125 PMIC, used on the Qualcomm CQ2390 platform (cocos),
integrates the SMBLite switch-mode battery charger IP. The existing
qcom_smbx charger driver only supports the SMB2 charger IP found on
PMI8998 and PM660, so PM4125 currently has no charger support at
all.
SMBLite is a reduced-feature variant of SMB2: it shares the same
SPMI bus and overall driver model, but uses a different register base
layout (five separate SPMI peripheral bases instead of a single base
with fixed offsets), a different battery-overvoltage status
register, SOC-based recharge instead of VBAT-based recharge, and a
different JEITA configuration sequence.
This series extends the existing qcom_smbx driver to support both chip
types side by side, selecting the correct register bases and handling
logic based on chip->type. This keeps a single driver and power-supply
class device covering both SMB2 and SMBLite hardware.
This series:
- Adds the qcom,pm4125-charger devicetree binding, covering both
PM4125 and PM2250 (which share the same SMBLite IP)
- Extends qcom_smbx to add SMBLite register support, JEITA
threshold configuration, and SOC-based recharge, while preserving
all existing SMB2 (PMI8998/PM660) behavior
Signed-off-by: Rakesh Kota <rakesh.kota@oss.qualcomm.com>
Signed-off-by: Raj Aryan <raj.aryan@oss.qualcomm.com>
---
Raj Aryan (2):
dt-bindings: power: supply: Add qcom,pm4125-charger binding
power: supply: qcom_smbx: Add SMBLite charger support
.../bindings/power/supply/qcom,pm4125-charger.yaml | 109 ++
drivers/power/supply/qcom_smbx.c | 1094 ++++++++++++++++++--
2 files changed, 1090 insertions(+), 113 deletions(-)
---
base-commit: f1ac44c32cba88ad65dcecd4a279661d14e93651
change-id: 20260827-smblite-charger-for-pm4125-d3168a705520
prerequisite-message-id: 20261111-shikra-qusb2-charger-det-v1-0-5a9d919c66b5@oss.qualcomm.com
prerequisite-patch-id: 7e516155b3e55cfdf0e368296b467c6d89565b9d
prerequisite-patch-id: 85a40d3799c93e0ff515f7ae2f9642435acea45a
Best regards,
--
Raj Aryan <raj.aryan@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] dt-bindings: power: supply: Add qcom,pm4125-charger binding
2026-11-24 9:15 [PATCH 0/2] arm64: qcom: Add SMBLite charger support for PM4125 Raj Aryan
@ 2026-11-24 9:15 ` Raj Aryan
2026-11-24 9:26 ` sashiko-bot
2026-11-24 9:55 ` Krzysztof Kozlowski
2026-11-24 9:15 ` [PATCH 2/2] power: supply: qcom_smbx: Add SMBLite charger support Raj Aryan
2026-11-24 9:48 ` [PATCH 0/2] arm64: qcom: Add SMBLite charger support for PM4125 Krzysztof Kozlowski
2 siblings, 2 replies; 7+ messages in thread
From: Raj Aryan @ 2026-11-24 9:15 UTC (permalink / raw)
To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Casey Connolly, Liam Girdwood, Mark Brown
Cc: linux-pm, devicetree, linux-kernel, linux-arm-msm, Rakesh Kota,
Raj Aryan
Add YAML devicetree binding for the Qualcomm SMBLite switch-mode
battery charger found on the PM4125 PMIC.
SMBLite is a reduced-feature charger IP sharing a common SPMI
interface with the SMB2 family (PMI8998, PM660) but using separate
SPMI peripheral bases for CHGR, DCDC, USB, MISC and BATIF blocks.
The binding covers:
- compatible string: qcom,pm4125-charger
- reg property for the CHGR peripheral base address
- Four interrupts: usb-plugin, bat-ov, wdog-bark and
usbin-icl-change
- Two IIO channels: usbin_v (USB input voltage via ADC5_USB_IN_V_16)
and usbin_i (USB input current via ADC5_USB_IN_I)
- Optional JEITA soft and hard threshold configuration as raw
16-bit ADC comparator values written to BATIF ADC comparator
registers
- Optional monitored-battery phandle for battery parameters such
as float voltage and charge termination current
Signed-off-by: Raj Aryan <raj.aryan@oss.qualcomm.com>
Signed-off-by: Rakesh Kota <rakesh.kota@oss.qualcomm.com>
---
.../bindings/power/supply/qcom,pm4125-charger.yaml | 109 +++++++++++++++++++++
1 file changed, 109 insertions(+)
diff --git a/Documentation/devicetree/bindings/power/supply/qcom,pm4125-charger.yaml b/Documentation/devicetree/bindings/power/supply/qcom,pm4125-charger.yaml
new file mode 100644
index 000000000000..5651b428b0a1
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/supply/qcom,pm4125-charger.yaml
@@ -0,0 +1,109 @@
+# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/power/supply/qcom,pm4125-charger.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm PM4125 SMBLite Switch-Mode Battery Charger
+
+maintainers:
+ - Raj Aryan <raj.aryan@oss.qualcomm.com>
+ - Rakesh Kota <rakesh.kota@oss.qualcomm.com>
+
+description: |
+ The Qualcomm SMBLite is a switch-mode battery charger IP found on
+ the entry-level Qualcomm PM4125 PMIC. It exposes five separate
+ SPMI peripheral bases for CHGR, DCDC, USB, MISC and BATIF blocks and
+ supports USB input current limiting, JEITA temperature protection,
+ battery overvoltage detection and a hardware watchdog.
+
+properties:
+ compatible:
+ const: qcom,pm4125-charger
+
+ reg:
+ maxItems: 1
+ description: Base address of the CHGR SPMI peripheral (e.g. 0x1000).
+
+ interrupts:
+ maxItems: 4
+
+ interrupt-names:
+ items:
+ - const: usb-plugin
+ - const: bat-ov
+ - const: wdog-bark
+ - const: usbin-icl-change
+
+ io-channels:
+ minItems: 1
+ maxItems: 2
+ description: |
+ IIO ADC channels used by the charger. usbin_v is the USB input
+ voltage channel (ADC5_USB_IN_V_16). usbin_i is the USB input
+ current channel (ADC5_USB_IN_I).
+
+ io-channel-names:
+ minItems: 1
+ items:
+ - const: usbin_v
+ - const: usbin_i
+
+ monitored-battery: true
+
+ qcom,jeita-soft-thresholds:
+ $ref: /schemas/types.yaml#/definitions/uint32-array
+ minItems: 2
+ maxItems: 2
+ description: |
+ JEITA soft temperature thresholds (COOL, WARM) as raw 16-bit ADC
+ comparator values written to the BATIF ADC comparator registers.
+ Example: <0x5314 0x25e3> for COOL=15°C, WARM=45°C.
+
+ qcom,jeita-hard-thresholds:
+ $ref: /schemas/types.yaml#/definitions/uint32-array
+ minItems: 2
+ maxItems: 2
+ description: |
+ JEITA hard temperature thresholds (COLD, HOT) as raw 16-bit ADC
+ comparator values written to the BATIF ADC comparator registers.
+ Example: <0x58cd 0x20b8> for COLD=0°C, HOT=60°C.
+
+required:
+ - compatible
+ - reg
+ - interrupts
+ - interrupt-names
+ - io-channels
+ - io-channel-names
+
+allOf:
+ - $ref: power-supply.yaml#
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/irq.h>
+ #include <dt-bindings/iio/qcom,spmi-vadc.h>
+
+ pm4125_charger: charger@1000 {
+ compatible = "qcom,pm4125-charger";
+ reg = <0x1000>;
+
+ interrupts = <0x0 0x13 0x0 IRQ_TYPE_EDGE_BOTH>,
+ <0x0 0x12 0x3 IRQ_TYPE_EDGE_BOTH>,
+ <0x0 0x16 0x1 IRQ_TYPE_EDGE_RISING>,
+ <0x0 0x13 0x6 IRQ_TYPE_EDGE_RISING>;
+ interrupt-names = "usb-plugin",
+ "bat-ov",
+ "wdog-bark",
+ "usbin-icl-change";
+
+ io-channels = <&pm4125_vadc ADC5_USB_IN_V_16>,
+ <&pm4125_vadc ADC5_USB_IN_I>;
+ io-channel-names = "usbin_v", "usbin_i";
+
+ qcom,jeita-soft-thresholds = <0x5314 0x25e3>; /* COOL, WARM */
+ qcom,jeita-hard-thresholds = <0x58cd 0x20b8>; /* COLD, HOT */
+ };
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] power: supply: qcom_smbx: Add SMBLite charger support
2026-11-24 9:15 [PATCH 0/2] arm64: qcom: Add SMBLite charger support for PM4125 Raj Aryan
2026-11-24 9:15 ` [PATCH 1/2] dt-bindings: power: supply: Add qcom,pm4125-charger binding Raj Aryan
@ 2026-11-24 9:15 ` Raj Aryan
2026-11-24 9:32 ` sashiko-bot
2026-11-24 9:48 ` [PATCH 0/2] arm64: qcom: Add SMBLite charger support for PM4125 Krzysztof Kozlowski
2 siblings, 1 reply; 7+ messages in thread
From: Raj Aryan @ 2026-11-24 9:15 UTC (permalink / raw)
To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Casey Connolly, Liam Girdwood, Mark Brown
Cc: linux-pm, devicetree, linux-kernel, linux-arm-msm, Rakesh Kota,
Raj Aryan
Extend the qcom_smbx charger driver to support the SMBLite charger
IP found on the PM4125 PMIC while retaining full support for the
existing SMB2 hardware (PMI8998, PM660).
SMBLite differs from SMB2 in several ways, all handled via explicit
chip->type guards:
- Five separate SPMI peripheral bases (CHGR, DCDC, USB, MISC,
BATIF) instead of SMB2's single base with fixed offsets
- Different BAT_OV, USB online, ICL and watchdog pet registers
- SOC-based recharge instead of SMB2's VBAT-based recharge
- A masked JEITA enable write matching downstream behaviour
- No CURRENT_NOW support via usbin_i
Signed-off-by: Raj Aryan <raj.aryan@oss.qualcomm.com>
Signed-off-by: Rakesh Kota <rakesh.kota@oss.qualcomm.com>
---
drivers/power/supply/qcom_smbx.c | 1094 ++++++++++++++++++++++++++++++++++----
1 file changed, 981 insertions(+), 113 deletions(-)
diff --git a/drivers/power/supply/qcom_smbx.c b/drivers/power/supply/qcom_smbx.c
index 52bb5a6eb145..54b2942e2f5a 100644
--- a/drivers/power/supply/qcom_smbx.c
+++ b/drivers/power/supply/qcom_smbx.c
@@ -4,8 +4,9 @@
* Copyright (c) 2023, Linaro Ltd.
* Author: Casey Connolly <casey.connolly@linaro.org>
*
- * This driver is for the switch-mode battery charger and boost
- * hardware found in pmi8998 and related PMICs.
+ * This driver supports the switch-mode battery charger found in:
+ * - PMI8998 / PM660 (SMB2 IP)
+ * - PM4125 (SMBLite IP)
*/
#include <linux/bits.h>
@@ -20,8 +21,22 @@
#include <linux/of.h>
#include <linux/power_supply.h>
#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
#include <linux/types.h>
#include <linux/workqueue.h>
+#include <linux/pm_wakeup.h>
+
+/* PMIC IP types */
+enum smb_type {
+ SMB2, /* PMI8998, PM660 - SMB2 IP */
+ SMBLITE, /* PM4125 - SMBLite IP */
+};
+
+enum connector_type {
+ CONNECTOR_TYPE_UNKNOWN,
+ CONNECTOR_TYPE_TYPEC,
+ CONNECTOR_TYPE_MICRO_USB,
+};
/* clang-format off */
#define BATTERY_CHARGER_STATUS_1 0x06
@@ -355,6 +370,137 @@
#define SMB2_FLOAT_VOLTAGE_MIN_UV 3487500
#define SMB2_FLOAT_VOLTAGE_MAX_UV 4920000
#define SMB2_FLOAT_VOLTAGE_STEP_UV 7500
+
+/* ================================================================
+ * SMBLite specific registers and base addresses
+ * Source: downstream smblite-reg.h (qpnp-smblite driver)
+ * ================================================================
+ */
+/* SMBLite peripheral base addresses (PM4125) */
+#define SMBLITE_CHGR_BASE 0x1000
+#define SMBLITE_DCDC_BASE 0x1100
+#define SMBLITE_BATIF_BASE 0x1200
+#define SMBLITE_USBIN_BASE 0x1300
+#define SMBLITE_TYPEC_BASE 0x1500
+#define SMBLITE_MISC_BASE 0x1600
+
+/* ---- SMBLITE CHGR registers (chg_base offsets) ---- */
+
+#define SMBLITE_BATTERY_CHARGER_STATUS_1 0x06
+#define SMBLITE_CHGR_IBAT_STATUS 0x0A
+#define SMBLITE_CHARGER_VBAT_STATUS 0x08
+#define SMBLITE_CHGR_VFLT_STATUS 0x0B
+#define SMBLITE_BAT_OV_BIT BIT(7)
+
+#define SMBLITE_CHARGING_ENABLE_CMD 0x46
+#define SMBLITE_CHARGING_ENABLE_CMD_BIT BIT(0)
+
+#define SMBLITE_CHGR_FAST_CHARGE_CURRENT_CFG 0x54
+#define SMBLITE_CHGR_FLOAT_VOLTAGE_CFG 0x58
+/*
+ * chg_base + 0x60 = CHGR_TERM_CFG_REG (termination current config).
+ * SMBLite has NO pre-charge current register at this offset.
+ * Do NOT write pre-charge current to 0x60.
+ */
+#define SMBLITE_CHGR_CHG_TERM_CFG 0x60
+
+#define SMBLITE_CHGR_RECHG_CFG 0x70
+#define SMBLITE_RECHG_MASK GENMASK(7, 6)
+#define SMBLITE_VBAT_BASED_RECHG_BIT BIT(7)
+#define SMBLITE_CHGR_RECHG_SOC_THD_CFG 0x74
+#define SMBLITE_CHGR_CHG_INHIBIT_CFG 0x78
+
+#define SMBLITE_ICL_MAX_STATUS 0x06
+#define SMBLITE_ICL_STATUS 0x09
+
+#define SMBLITE_POWER_PATH_STATUS 0x0B
+#define SMBLITE_VALID_INPUT_POWER_SOURCE_BIT BIT(7)
+#define SMBLITE_USE_USBIN_BIT BIT(5)
+
+#define SMBLITE_DCDC_OTG_CFG 0x56
+#define SMBLITE_DCDC_OTG_EN_SRC_CFG_BIT BIT(0)
+
+#define SMBLITE_DCDC_LDO_CFG 0x70
+#define SMBLITE_LDO_MODE_BIT BIT(0)
+
+#define SMBLITE_BATIF_BPD_CFG 0x60
+#define SMBLITE_BATIF_JEITA_EN_CFG 0x7F
+
+#define SMBLITE_BATIF_JEITA_COMP_STATUS 0x0C
+#define SMBLITE_JEITA_ADC_THOT_AFP_BIT BIT(5)
+#define SMBLITE_JEITA_ADC_THOT_BIT BIT(4)
+#define SMBLITE_JEITA_ADC_WARM_BIT BIT(3)
+#define SMBLITE_JEITA_ADC_COOL_BIT BIT(2)
+#define SMBLITE_JEITA_ADC_TCOLD_BIT BIT(1)
+#define SMBLITE_JEITA_ADC_TCOLD_AFP_BIT BIT(0)
+
+#define SMBLITE_JEITA_HOT_THRESHOLD_CFG 0x84
+#define SMBLITE_JEITA_WARM_THRESHOLD_CFG 0x86
+#define SMBLITE_JEITA_COOL_THRESHOLD_CFG 0x88
+#define SMBLITE_JEITA_COLD_THRESHOLD_CFG 0x8A
+
+#define SMBLITE_APSD_STATUS 0x0A
+#define SMBLITE_APSD_RESULT_STATUS 0x0B
+#define SMBLITE_APSD_RESULT_STATUS_MASK GENMASK(6, 0)
+#define SMBLITE_CMD_APSD 0x45
+#define SMBLITE_USB_APSD_EN 0x44
+#define SMBLITE_USB_APSD_CFG 0x46
+#define SMBLITE_USBIN_QC23_EN 0x48
+#define SMBLITE_HVDCP_EN_BIT BIT(2)
+
+#define SMBLITE_USBIN_ICL_OPTIONS 0x50
+#define SMBLITE_USBIN_MODE_CHG_BIT BIT(2)
+#define SMBLITE_USB51_MODE_BIT BIT(1)
+
+#define SMBLITE_USBIN_CURRENT_LIMIT_CFG 0x52
+#define SMBLITE_USBIN_INPUT_SUSPEND 0x54
+#define SMBLITE_SUSPEND_ON_COLLAPSE_USBIN_BIT BIT(7)
+
+#define SMBLITE_USBIN_AICL_OPTIONS_CFG 0x60
+#define SMBLITE_USBIN_AICL_EN_BIT BIT(7)
+#define SMBLITE_USBIN_AICL_START_AT_MAX BIT(4)
+
+#define SMBLITE_TYPEC_U_USB_CFG 0x70
+#define SMBLITE_EN_MICRO_USB_MODE_BIT BIT(0)
+
+#define SMBLITE_LEGACY_CABLE_STATUS 0x0D
+#define SMBLITE_TYPEC_LEGACY_CABLE_STATUS_BIT BIT(1)
+
+#define SMBLITE_TYPE_C_MODE_CFG 0x44
+#define SMBLITE_TYPE_C_EXIT_STATE_CFG 0x50
+
+#define EN_TRY_SNK_BIT BIT(4)
+#define EN_TRY_SRC_BIT BIT(3)
+#define EN_SRC_ONLY_BIT BIT(2)
+#define EN_SNK_ONLY_BIT BIT(1)
+#define SEL_SRC_UPPER_REF_BIT BIT(2)
+
+#define SMBLITE_MISC_AICL_RERUN_CFG 0x54
+#define SMBLITE_USBIN_AICL_PERIODIC_RERUN_EN_BIT BIT(5)
+#define SMBLITE_USBIN_AICL_RERUN_TIME_MASK GENMASK(1, 0)
+#define SMBLITE_AICL_RERUN_TIME_12S_VAL 0x01
+
+#define SMBLITE_WD_CFG 0x58
+#define SMBLITE_BITE_WDOG_DISABLE_CHARGING_CFG_BIT BIT(7)
+#define SMBLITE_BARK_WDOG_INT_EN_BIT BIT(4)
+#define SMBLITE_WDOG_TIMER_EN_ON_PLUGIN_BIT BIT(1)
+#define SMBLITE_WDOG_TIMER_EN_BIT BIT(0)
+#define SMBLITE_SNARL_BARK_BITE_WD_CFG 0x59
+#define SMBLITE_BARK_BITE_WDOG_PET 0x5A
+#define SMBLITE_BARK_BITE_WDOG_PET_BIT BIT(0)
+#define SMBLITE_BARK_WDOG_TIMEOUT_MASK GENMASK(5, 4) /* 0x30 */
+#define SMBLITE_BITE_WDOG_TIMEOUT_MASK GENMASK(7, 6) /* 0xC0 */
+#define SMBLITE_BITE_WDOG_TIMEOUT_8S 0x3
+#define SMBLITE_BITE_WDOG_TIMEOUT_SHIFT 6
+
+#define SMBLITE_ICL_STEP_UA 100000
+#define SMBLITE_FCC_STEP_UA 100000
+#define SMBLITE_ICL_MAX_UA 2000000
+#define SMBLITE_FCC_MAX_UA 2000000
+#define SMBLITE_FV_STEP_UV 20000
+#define SMBLITE_FV_MIN_UV 3600000
+#define SMBLITE_FV_MAX_UV 4600000
+
/* clang-format on */
enum charger_status {
@@ -368,6 +514,17 @@ enum charger_status {
DISABLE_CHARGE,
};
+enum smblite_charger_status {
+ SMBLITE_INHIBIT_CHARGE = 0,
+ SMBLITE_TRICKLE_CHARGE,
+ SMBLITE_PRE_CHARGE,
+ SMBLITE_FULLON_CHARGE,
+ SMBLITE_TAPER_CHARGE,
+ SMBLITE_TERMINATE_CHARGE,
+ SMBLITE_CHARGING_PAUSED,
+ SMBLITE_CHARGING_DISABLED,
+};
+
struct smb_init_register {
u16 addr;
u8 mask;
@@ -377,6 +534,8 @@ struct smb_init_register {
/**
* struct smb_chip - smb chip structure
* @dev: Device reference for power_supply
+ * @type: PMIC IP type (SMB2 or SMBLITE)
+ * @connector_type: Connector type detected at probe (SMBLITE only)
* @name: The platform device name
* @base: Base address for smb registers
* @regmap: Register map
@@ -387,10 +546,23 @@ struct smb_init_register {
* @wakeup_enabled: If the cable IRQ will cause a wakeup
* @usb_in_i_chan: USB_IN current measurement channel
* @usb_in_v_chan: USB_IN voltage measurement channel
+ * @temp_chan: Charger temperature channel (optional)
* @chg_psy: Charger power supply instance
+ * @vbus_reg: Optional VBUS regulator
+ * @ldo_mode: True if operating in LDO mode (SMBLITE only)
+ * @icl_step_ua: ICL step size in uA
+ * @fcc_step_ua: FCC step size in uA
+ * @icl_max_ua: Maximum ICL in uA
+ * @fcc_max_ua: Maximum FCC in uA
+ * @charge_status: Cached POWER_SUPPLY_STATUS_* value
+ * @charge_done: True when charge has terminated
+ * @usb_type: USB type reported by external charger detection
+ * @usb_type_override: True when @usb_type should override APSD reporting
*/
struct smb_chip {
struct device *dev;
+ enum smb_type type;
+ enum connector_type connector_type;
const char *name;
unsigned int base;
struct regmap *regmap;
@@ -403,8 +575,19 @@ struct smb_chip {
struct iio_channel *usb_in_i_chan;
struct iio_channel *usb_in_v_chan;
+ struct iio_channel *temp_chan;
struct power_supply *chg_psy;
+ struct regulator *vbus_reg;
+ bool ldo_mode;
+ unsigned int icl_step_ua;
+ unsigned int fcc_step_ua;
+ unsigned int icl_max_ua;
+ unsigned int fcc_max_ua;
+ int charge_status;
+ bool charge_done;
+ enum power_supply_usb_type usb_type;
+ bool usb_type_override;
};
static enum power_supply_property smb_properties[] = {
@@ -419,19 +602,49 @@ static enum power_supply_property smb_properties[] = {
POWER_SUPPLY_PROP_USB_TYPE,
};
+static enum power_supply_property smblite_properties[] = {
+ POWER_SUPPLY_PROP_MANUFACTURER,
+ POWER_SUPPLY_PROP_MODEL_NAME,
+ POWER_SUPPLY_PROP_CURRENT_MAX,
+ POWER_SUPPLY_PROP_VOLTAGE_NOW,
+ POWER_SUPPLY_PROP_STATUS,
+ POWER_SUPPLY_PROP_HEALTH,
+ POWER_SUPPLY_PROP_ONLINE,
+ POWER_SUPPLY_PROP_CHARGE_TYPE,
+ POWER_SUPPLY_PROP_USB_TYPE,
+};
+
+/*
+ * smb_get_prop_usb_online - check whether a valid USB input is present.
+ *
+ * SMB2 (0x60B): P_PATH_USE_USBIN BIT(4) && VALID_INPUT BIT(0)
+ * SMBLite (dcdc_base + 0x0B = 0x110B):
+ * VALID_INPUT_POWER_SOURCE_STS BIT(7) && USE_USBIN BIT(5)
+ */
static int smb_get_prop_usb_online(struct smb_chip *chip, int *val)
{
unsigned int stat;
+ u16 reg;
int rc;
- rc = regmap_read(chip->regmap, chip->base + POWER_PATH_STATUS, &stat);
+ if (chip->type == SMBLITE)
+ reg = SMBLITE_DCDC_BASE + SMBLITE_POWER_PATH_STATUS;
+ else
+ reg = chip->base + POWER_PATH_STATUS;
+
+ rc = regmap_read(chip->regmap, reg, &stat);
if (rc < 0) {
dev_err(chip->dev, "Couldn't read power path status: %d\n", rc);
return rc;
}
- *val = (stat & P_PATH_USE_USBIN_BIT) &&
- (stat & P_PATH_VALID_INPUT_POWER_SOURCE_STS_BIT);
+ if (chip->type == SMBLITE)
+ *val = (stat & SMBLITE_VALID_INPUT_POWER_SOURCE_BIT) &&
+ (stat & SMBLITE_USE_USBIN_BIT);
+ else
+ *val = (stat & P_PATH_USE_USBIN_BIT) &&
+ (stat & P_PATH_VALID_INPUT_POWER_SOURCE_STS_BIT);
+
return 0;
}
@@ -442,6 +655,7 @@ static int smb_get_prop_usb_online(struct smb_chip *chip, int *val)
static int smb_apsd_get_charger_type(struct smb_chip *chip, int *val)
{
unsigned int apsd_stat, stat;
+ u16 apsd_reg, result_reg;
int usb_online = 0;
int rc;
@@ -451,7 +665,15 @@ static int smb_apsd_get_charger_type(struct smb_chip *chip, int *val)
return rc;
}
- rc = regmap_read(chip->regmap, chip->base + APSD_STATUS, &apsd_stat);
+ if (chip->type == SMBLITE) {
+ apsd_reg = SMBLITE_USBIN_BASE + SMBLITE_APSD_STATUS;
+ result_reg = SMBLITE_USBIN_BASE + SMBLITE_APSD_RESULT_STATUS;
+ } else {
+ apsd_reg = APSD_STATUS;
+ result_reg = APSD_RESULT_STATUS;
+ }
+
+ rc = regmap_read(chip->regmap, apsd_reg, &apsd_stat);
if (rc < 0) {
dev_err(chip->dev, "Failed to read apsd status, rc = %d", rc);
return rc;
@@ -461,7 +683,7 @@ static int smb_apsd_get_charger_type(struct smb_chip *chip, int *val)
return -EAGAIN;
}
- rc = regmap_read(chip->regmap, chip->base + APSD_RESULT_STATUS, &stat);
+ rc = regmap_read(chip->regmap, result_reg, &stat);
if (rc < 0) {
dev_err(chip->dev, "Failed to read apsd result, rc = %d", rc);
return rc;
@@ -479,11 +701,33 @@ static int smb_apsd_get_charger_type(struct smb_chip *chip, int *val)
return 0;
}
+static unsigned int smb_usb_type_current_ua(enum power_supply_usb_type usb_type)
+{
+ switch (usb_type) {
+ case POWER_SUPPLY_USB_TYPE_CDP:
+ return CDP_CURRENT_UA;
+ case POWER_SUPPLY_USB_TYPE_DCP:
+ return DCP_CURRENT_UA;
+ case POWER_SUPPLY_USB_TYPE_SDP:
+ default:
+ return SDP_CURRENT_UA;
+ }
+}
+
+/*
+ * smb_get_prop_status - report POWER_SUPPLY_STATUS_* for the battery.
+ *
+ * BAT_OV detection:
+ * SMB2: BATTERY_CHARGER_STATUS_2 (chip->base + 0x07), BIT(5)
+ * SMBLite: CHARGER_VBAT_STATUS_REG (chg_base + 0x08 = 0x1008), BIT(7)
+ *
+ * Charger status enum differs between IPs -- handled by dedicated branches.
+ */
static int smb_get_prop_status(struct smb_chip *chip, int *val)
{
- unsigned char stat[2];
- int usb_online = 0;
- int rc;
+ unsigned int chg_status, stat_batov;
+ u16 chg_status_reg, reg_batov;
+ int usb_online = 0, rc;
rc = smb_get_prop_usb_online(chip, &usb_online);
if (!usb_online) {
@@ -491,65 +735,142 @@ static int smb_get_prop_status(struct smb_chip *chip, int *val)
return rc;
}
- rc = regmap_bulk_read(chip->regmap,
- chip->base + BATTERY_CHARGER_STATUS_1, &stat, 2);
+ if (chip->type == SMBLITE) {
+ chg_status_reg = SMBLITE_CHGR_BASE + SMBLITE_BATTERY_CHARGER_STATUS_1;
+ reg_batov = SMBLITE_CHGR_BASE + SMBLITE_CHARGER_VBAT_STATUS;
+ } else {
+ chg_status_reg = chip->base + BATTERY_CHARGER_STATUS_1;
+ reg_batov = chip->base + BATTERY_CHARGER_STATUS_2;
+ }
+
+ rc = regmap_read(chip->regmap, reg_batov, &stat_batov);
if (rc < 0) {
- dev_err(chip->dev, "Failed to read charging status ret=%d\n",
- rc);
+ dev_err(chip->dev, "Failed to read bat-ov status ret=%d\n", rc);
return rc;
}
- if (stat[1] & CHARGER_ERROR_STATUS_BAT_OV_BIT) {
- *val = POWER_SUPPLY_STATUS_NOT_CHARGING;
- return 0;
+ /* Check BAT_OV -- different register/bit per IP */
+ if (chip->type == SMBLITE) {
+ if (stat_batov & SMBLITE_BAT_OV_BIT) {
+ *val = POWER_SUPPLY_STATUS_NOT_CHARGING;
+ chip->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
+ chip->charge_done = false;
+ return 0;
+ }
+ } else {
+ if (stat_batov & CHARGER_ERROR_STATUS_BAT_OV_BIT) {
+ *val = POWER_SUPPLY_STATUS_NOT_CHARGING;
+ chip->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
+ chip->charge_done = false;
+ return 0;
+ }
}
- stat[0] = stat[0] & BATTERY_CHARGER_STATUS_MASK;
-
- switch (stat[0]) {
- case TRICKLE_CHARGE:
- case PRE_CHARGE:
- case FAST_CHARGE:
- case FULLON_CHARGE:
- case TAPER_CHARGE:
- *val = POWER_SUPPLY_STATUS_CHARGING;
- return rc;
- case DISABLE_CHARGE:
- *val = POWER_SUPPLY_STATUS_NOT_CHARGING;
- return rc;
- case TERMINATE_CHARGE:
- case INHIBIT_CHARGE:
- *val = POWER_SUPPLY_STATUS_FULL;
- return rc;
- default:
- *val = POWER_SUPPLY_STATUS_UNKNOWN;
+ rc = regmap_read(chip->regmap, chg_status_reg, &chg_status);
+ if (rc < 0) {
+ dev_err(chip->dev, "Failed to read charging status ret=%d\n", rc);
return rc;
}
+
+ chg_status &= BATTERY_CHARGER_STATUS_MASK;
+
+ if (chip->type == SMBLITE) {
+ switch (chg_status) {
+ case SMBLITE_TRICKLE_CHARGE:
+ case SMBLITE_PRE_CHARGE:
+ case SMBLITE_FULLON_CHARGE:
+ case SMBLITE_TAPER_CHARGE:
+ *val = POWER_SUPPLY_STATUS_CHARGING;
+ chip->charge_status = POWER_SUPPLY_STATUS_CHARGING;
+ chip->charge_done = false;
+ break;
+ case SMBLITE_TERMINATE_CHARGE:
+ *val = POWER_SUPPLY_STATUS_FULL;
+ chip->charge_status = POWER_SUPPLY_STATUS_FULL;
+ chip->charge_done = true;
+ break;
+ case SMBLITE_INHIBIT_CHARGE:
+ case SMBLITE_CHARGING_PAUSED:
+ case SMBLITE_CHARGING_DISABLED:
+ *val = POWER_SUPPLY_STATUS_NOT_CHARGING;
+ chip->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
+ chip->charge_done = false;
+ break;
+ default:
+ *val = POWER_SUPPLY_STATUS_UNKNOWN;
+ chip->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
+ chip->charge_done = false;
+ break;
+ }
+ } else {
+ switch (chg_status) {
+ case TRICKLE_CHARGE:
+ case PRE_CHARGE:
+ case FAST_CHARGE:
+ case FULLON_CHARGE:
+ case TAPER_CHARGE:
+ *val = POWER_SUPPLY_STATUS_CHARGING;
+ chip->charge_status = POWER_SUPPLY_STATUS_CHARGING;
+ chip->charge_done = false;
+ break;
+ case DISABLE_CHARGE:
+ *val = POWER_SUPPLY_STATUS_NOT_CHARGING;
+ chip->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
+ chip->charge_done = false;
+ break;
+ case TERMINATE_CHARGE:
+ case INHIBIT_CHARGE:
+ *val = POWER_SUPPLY_STATUS_FULL;
+ chip->charge_status = POWER_SUPPLY_STATUS_FULL;
+ chip->charge_done = true;
+ break;
+ default:
+ *val = POWER_SUPPLY_STATUS_UNKNOWN;
+ chip->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
+ chip->charge_done = false;
+ break;
+ }
+ }
+
+ return 0;
}
static inline int smb_get_current_limit(struct smb_chip *chip,
unsigned int *val)
{
- int rc = regmap_read(chip->regmap, chip->base + ICL_STATUS, val);
+ u16 reg;
+ int rc;
+
+ if (chip->type == SMBLITE)
+ reg = SMBLITE_DCDC_BASE + SMBLITE_ICL_STATUS;
+ else
+ reg = chip->base + ICL_STATUS;
+ rc = regmap_read(chip->regmap, reg, val);
if (rc >= 0)
- *val *= CURRENT_SCALE_FACTOR;
+ *val *= chip->icl_step_ua;
return rc;
}
static int smb_set_current_limit(struct smb_chip *chip, unsigned int val)
{
unsigned char val_raw;
+ u16 reg;
- if (val > 4800000) {
- dev_err(chip->dev,
- "Can't set current limit higher than 4800000uA");
+ if (val > chip->icl_max_ua) {
+ dev_err(chip->dev, "Can't set current limit higher than %duA",
+ chip->icl_max_ua);
return -EINVAL;
}
- val_raw = val / CURRENT_SCALE_FACTOR;
- return regmap_write(chip->regmap, chip->base + USBIN_CURRENT_LIMIT_CFG,
- val_raw);
+ val_raw = val / chip->icl_step_ua;
+
+ if (chip->type == SMBLITE)
+ reg = SMBLITE_USBIN_BASE + SMBLITE_USBIN_CURRENT_LIMIT_CFG;
+ else
+ reg = chip->base + USBIN_CURRENT_LIMIT_CFG;
+
+ return regmap_write(chip->regmap, reg, val_raw);
}
static void smb_status_change_work(struct work_struct *work)
@@ -562,8 +883,17 @@ static void smb_status_change_work(struct work_struct *work)
chip = container_of(work, struct smb_chip, status_change_work.work);
smb_get_prop_usb_online(chip, &usb_online);
- if (!usb_online)
+ if (!usb_online) {
+ chip->usb_type_override = false;
+ chip->usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN;
return;
+ }
+
+ if (chip->type == SMBLITE && chip->usb_type_override) {
+ smb_set_current_limit(chip, smb_usb_type_current_ua(chip->usb_type));
+ power_supply_changed(chip->chg_psy);
+ return;
+ }
for (count = 0; count < 3; count++) {
dev_dbg(chip->dev, "get charger type retry %d\n", count);
@@ -579,27 +909,16 @@ static void smb_status_change_work(struct work_struct *work)
}
if (rc < 0) {
- rc = regmap_update_bits(chip->regmap, chip->base + CMD_APSD,
- APSD_RERUN_BIT, APSD_RERUN_BIT);
+ if (chip->type != SMBLITE)
+ rc = regmap_update_bits(chip->regmap, chip->base + CMD_APSD,
+ APSD_RERUN_BIT, APSD_RERUN_BIT);
schedule_delayed_work(&chip->status_change_work,
msecs_to_jiffies(1000));
dev_dbg(chip->dev, "get charger type failed, rerun apsd\n");
return;
}
- switch (charger_type) {
- case POWER_SUPPLY_USB_TYPE_CDP:
- current_ua = CDP_CURRENT_UA;
- break;
- case POWER_SUPPLY_USB_TYPE_DCP:
- current_ua = DCP_CURRENT_UA;
- break;
- case POWER_SUPPLY_USB_TYPE_SDP:
- default:
- current_ua = SDP_CURRENT_UA;
- break;
- }
-
+ current_ua = smb_usb_type_current_ua(charger_type);
smb_set_current_limit(chip, current_ua);
power_supply_changed(chip->chg_psy);
}
@@ -610,6 +929,11 @@ static int smb_get_iio_chan(struct smb_chip *chip, struct iio_channel *chan,
int rc;
union power_supply_propval status;
+ if (!chan) {
+ *val = 0;
+ return 0;
+ }
+
rc = power_supply_get_property(chip->chg_psy, POWER_SUPPLY_PROP_STATUS,
&status);
if (rc < 0 || status.intval != POWER_SUPPLY_STATUS_CHARGING) {
@@ -625,11 +949,48 @@ static int smb_get_iio_chan(struct smb_chip *chip, struct iio_channel *chan,
return iio_read_channel_processed(chan, val);
}
+/*
+ * smb_get_prop_health - battery health based on temperature status.
+ *
+ * SMBLite: BATTERY_TEMP_STATUS_REG = batif_base + 0x0C (smblite-reg.h)
+ * SMB2: BATTERY_CHARGER_STATUS_2 = chip->base + 0x07
+ */
static int smb_get_prop_health(struct smb_chip *chip, int *val)
{
int rc;
unsigned int stat;
+ if (chip->type == SMBLITE) {
+ rc = regmap_read(chip->regmap,
+ SMBLITE_BATIF_BASE + SMBLITE_BATIF_JEITA_COMP_STATUS,
+ &stat);
+ if (rc < 0) {
+ dev_err(chip->dev,
+ "Couldn't read SMBLITE JEITA status rc=%d\n", rc);
+ return rc;
+ }
+ if (stat & (SMBLITE_JEITA_ADC_THOT_AFP_BIT |
+ SMBLITE_JEITA_ADC_THOT_BIT)) {
+ *val = POWER_SUPPLY_HEALTH_OVERHEAT;
+ return 0;
+ }
+ if (stat & (SMBLITE_JEITA_ADC_TCOLD_AFP_BIT |
+ SMBLITE_JEITA_ADC_TCOLD_BIT)) {
+ *val = POWER_SUPPLY_HEALTH_COLD;
+ return 0;
+ }
+ if (stat & SMBLITE_JEITA_ADC_WARM_BIT) {
+ *val = POWER_SUPPLY_HEALTH_WARM;
+ return 0;
+ }
+ if (stat & SMBLITE_JEITA_ADC_COOL_BIT) {
+ *val = POWER_SUPPLY_HEALTH_COOL;
+ return 0;
+ }
+ *val = POWER_SUPPLY_HEALTH_GOOD;
+ return 0;
+ }
+
rc = regmap_read(chip->regmap, chip->base + BATTERY_CHARGER_STATUS_2,
&stat);
if (rc < 0) {
@@ -669,6 +1030,8 @@ static int smb_get_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_CURRENT_MAX:
return smb_get_current_limit(chip, &val->intval);
case POWER_SUPPLY_PROP_CURRENT_NOW:
+ if (chip->type == SMBLITE)
+ return -EOPNOTSUPP;
return smb_get_iio_chan(chip, chip->usb_in_i_chan,
&val->intval);
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
@@ -681,7 +1044,32 @@ static int smb_get_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_HEALTH:
return smb_get_prop_health(chip, &val->intval);
case POWER_SUPPLY_PROP_USB_TYPE:
+ if (chip->type == SMBLITE && chip->usb_type_override) {
+ int usb_online = 0;
+
+ smb_get_prop_usb_online(chip, &usb_online);
+ if (usb_online) {
+ val->intval = chip->usb_type;
+ return 0;
+ }
+ }
return smb_apsd_get_charger_type(chip, &val->intval);
+ case POWER_SUPPLY_PROP_CHARGE_TYPE:
+ if (chip->type != SMBLITE)
+ return -EOPNOTSUPP;
+ switch (chip->charge_status) {
+ case POWER_SUPPLY_STATUS_FULL:
+ val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
+ break;
+ case POWER_SUPPLY_STATUS_CHARGING:
+ val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD;
+ break;
+ default:
+ val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN;
+ break;
+ }
+
+ return 0;
default:
dev_err(chip->dev, "invalid property: %d\n", psp);
return -EINVAL;
@@ -696,10 +1084,34 @@ static int smb_set_property(struct power_supply *psy,
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
+ if (chip->type == SMBLITE)
+ return -EINVAL;
return regmap_update_bits(chip->regmap, chip->base + USBIN_CMD_IL,
USBIN_SUSPEND_BIT, !val->intval);
case POWER_SUPPLY_PROP_CURRENT_MAX:
return smb_set_current_limit(chip, val->intval);
+ case POWER_SUPPLY_PROP_USB_TYPE:
+ if (chip->type != SMBLITE)
+ return -EOPNOTSUPP;
+ switch (val->intval) {
+ case POWER_SUPPLY_USB_TYPE_UNKNOWN:
+ chip->usb_type_override = false;
+ chip->usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN;
+ break;
+ case POWER_SUPPLY_USB_TYPE_SDP:
+ case POWER_SUPPLY_USB_TYPE_CDP:
+ case POWER_SUPPLY_USB_TYPE_DCP:
+ chip->usb_type = val->intval;
+ chip->usb_type_override = true;
+ smb_set_current_limit(chip,
+ smb_usb_type_current_ua(chip->usb_type));
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ power_supply_changed(chip->chg_psy);
+ return 0;
default:
dev_err(chip->dev, "No setter for property: %d\n", psp);
return -EINVAL;
@@ -709,44 +1121,93 @@ static int smb_set_property(struct power_supply *psy,
static int smb_property_is_writable(struct power_supply *psy,
enum power_supply_property psp)
{
+ struct smb_chip *chip = power_supply_get_drvdata(psy);
+
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
+ return chip->type != SMBLITE;
case POWER_SUPPLY_PROP_CURRENT_MAX:
return 1;
+ case POWER_SUPPLY_PROP_USB_TYPE:
+ return chip->type == SMBLITE;
default:
return 0;
}
}
+/*
+ * smb_handle_batt_overvoltage - IRQ handler for battery overvoltage.
+ *
+ * SMB2: chip->base + BATTERY_CHARGER_STATUS_2 (offset 0x07), BIT(5)
+ * SMBLite: SMBLITE_CHGR_BASE + SMBLITE_CHARGER_VBAT_STATUS (0x1008), BIT(7)
+ */
static irqreturn_t smb_handle_batt_overvoltage(int irq, void *data)
{
struct smb_chip *chip = data;
unsigned int status;
+ u16 reg;
+ u8 bit;
int rc;
- rc = regmap_read(chip->regmap,
- chip->base + BATTERY_CHARGER_STATUS_2, &status);
+ if (chip->type == SMBLITE) {
+ reg = SMBLITE_CHGR_BASE + SMBLITE_CHARGER_VBAT_STATUS;
+ bit = SMBLITE_BAT_OV_BIT;
+ } else {
+ reg = chip->base + BATTERY_CHARGER_STATUS_2;
+ bit = CHARGER_ERROR_STATUS_BAT_OV_BIT;
+ }
+
+ rc = regmap_read(chip->regmap, reg, &status);
if (rc < 0) {
dev_err(chip->dev, "Couldn't read charger status: %d\n", rc);
return IRQ_HANDLED;
}
- if (status & CHARGER_ERROR_STATUS_BAT_OV_BIT) {
- /* The hardware stops charging automatically */
+ if (status & bit)
dev_err(chip->dev, "battery overvoltage detected\n");
- }
power_supply_changed(chip->chg_psy);
return IRQ_HANDLED;
}
+/*
+ * smb_handle_usb_plugin - IRQ handler for USB plug/unplug events.
+ *
+ * SMBLite: if the charger shows INHIBIT_CHARGE (0x00) right after plug,
+ * toggle the charging enable bit (chg_base + 0x46) to kick-start charging.
+ * SMB2: simply schedules the status work.
+ */
static irqreturn_t smb_handle_usb_plugin(int irq, void *data)
{
struct smb_chip *chip = data;
+ int usb_online = 0;
power_supply_changed(chip->chg_psy);
+ smb_get_prop_usb_online(chip, &usb_online);
+ if (!usb_online)
+ goto schedule_work;
+
+ if (chip->type == SMBLITE) {
+ unsigned int chgr_status = 0;
+ u16 chgr_reg = SMBLITE_CHGR_BASE + SMBLITE_BATTERY_CHARGER_STATUS_1;
+ u16 chgen_reg = SMBLITE_CHGR_BASE + SMBLITE_CHARGING_ENABLE_CMD;
+
+ regmap_read(chip->regmap, chgr_reg, &chgr_status);
+
+ if ((chgr_status & BATTERY_CHARGER_STATUS_MASK) ==
+ SMBLITE_INHIBIT_CHARGE) {
+ regmap_update_bits(chip->regmap, chgen_reg,
+ SMBLITE_CHARGING_ENABLE_CMD_BIT, 0);
+ usleep_range(10000, 10100);
+ regmap_update_bits(chip->regmap, chgen_reg,
+ SMBLITE_CHARGING_ENABLE_CMD_BIT,
+ SMBLITE_CHARGING_ENABLE_CMD_BIT);
+ }
+ }
+
+schedule_work:
schedule_delayed_work(&chip->status_change_work,
msecs_to_jiffies(1500));
@@ -762,21 +1223,205 @@ static irqreturn_t smb_handle_usb_icl_change(int irq, void *data)
return IRQ_HANDLED;
}
+/*
+ * smb_handle_wdog_bark - pet the watchdog after a bark interrupt.
+ *
+ * SMB2: MISC base 0x600 + 0x43 = 0x643
+ * SMBLite: MISC base 0x1600 + 0x5A = 0x165A (per smblite-reg.h)
+ *
+ * NOTE: downstream qpnp-smblite enables the watchdog (WD_CFG bits
+ * WDOG_TIMER_EN_ON_PLUGIN + BARK_WDOG_INT_EN + BITE_WDOG_DISABLE_CHARGING).
+ * The wdog-bark IRQ is registered here to pet it; the watchdog config itself
+ * is written in smblite_init_seq[].
+ */
static irqreturn_t smb_handle_wdog_bark(int irq, void *data)
{
struct smb_chip *chip = data;
+ u16 reg;
int rc;
power_supply_changed(chip->chg_psy);
- rc = regmap_write(chip->regmap, chip->base + BARK_BITE_WDOG_PET,
- BARK_BITE_WDOG_PET_BIT);
+ if (chip->type == SMBLITE)
+ reg = SMBLITE_MISC_BASE + SMBLITE_BARK_BITE_WDOG_PET;
+ else
+ reg = chip->base + BARK_BITE_WDOG_PET;
+
+ rc = regmap_write(chip->regmap, reg, BARK_BITE_WDOG_PET_BIT);
if (rc < 0)
dev_err(chip->dev, "Couldn't pet the dog rc=%d\n", rc);
return IRQ_HANDLED;
}
+/* ================================================================
+ * SMBLite-specific initialisation helpers
+ * ================================================================
+ */
+static int smblite_detect_connector_type(struct smb_chip *chip)
+{
+ unsigned int val;
+ int rc;
+
+ if (chip->type != SMBLITE)
+ return 0;
+
+ rc = regmap_read(chip->regmap,
+ SMBLITE_TYPEC_BASE + SMBLITE_TYPEC_U_USB_CFG, &val);
+ if (rc < 0) {
+ dev_err(chip->dev, "Failed to read connector type: %d\n", rc);
+ return rc;
+ }
+
+ chip->connector_type = (val & SMBLITE_EN_MICRO_USB_MODE_BIT) ?
+ CONNECTOR_TYPE_MICRO_USB : CONNECTOR_TYPE_TYPEC;
+ dev_info(chip->dev, "%s connector detected\n",
+ chip->connector_type == CONNECTOR_TYPE_TYPEC ?
+ "Type-C" : "Micro-USB");
+ return 0;
+}
+
+static int smblite_init_typec(struct smb_chip *chip)
+{
+ unsigned int val;
+ int rc;
+
+ if (chip->type != SMBLITE)
+ return 0;
+ if (chip->connector_type != CONNECTOR_TYPE_TYPEC)
+ return 0;
+
+ rc = regmap_read(chip->regmap,
+ SMBLITE_TYPEC_BASE + SMBLITE_LEGACY_CABLE_STATUS, &val);
+ if (rc < 0)
+ return rc;
+
+ if (val & SMBLITE_TYPEC_LEGACY_CABLE_STATUS_BIT) {
+ dev_dbg(chip->dev, "Resetting legacy cable detection\n");
+ rc = regmap_update_bits(chip->regmap,
+ SMBLITE_TYPEC_BASE + SMBLITE_TYPE_C_MODE_CFG,
+ EN_TRY_SNK_BIT | EN_SNK_ONLY_BIT, 0);
+ if (rc < 0)
+ return rc;
+ msleep(50);
+ }
+
+ rc = regmap_update_bits(chip->regmap,
+ SMBLITE_TYPEC_BASE + SMBLITE_TYPE_C_MODE_CFG,
+ EN_TRY_SNK_BIT | EN_SNK_ONLY_BIT,
+ EN_TRY_SNK_BIT);
+ if (rc < 0)
+ return rc;
+
+ return regmap_update_bits(chip->regmap,
+ SMBLITE_TYPEC_BASE + SMBLITE_TYPE_C_EXIT_STATE_CFG,
+ SEL_SRC_UPPER_REF_BIT, SEL_SRC_UPPER_REF_BIT);
+}
+
+static int smblite_write_jeita_16(struct smb_chip *chip, u16 addr, u16 val)
+{
+ u8 buf[2];
+
+ buf[0] = (val >> 8) & 0xff;
+ buf[1] = val & 0xff;
+ return regmap_bulk_write(chip->regmap, addr, buf, 2);
+}
+
+static void smblite_program_jeita_thresholds(struct smb_chip *chip)
+{
+ u32 soft[2], hard[2];
+ int rc;
+
+ if (chip->type != SMBLITE || !chip->dev->of_node)
+ return;
+
+ rc = of_property_read_u32_array(chip->dev->of_node,
+ "qcom,jeita-soft-thresholds",
+ soft, ARRAY_SIZE(soft));
+ if (rc) {
+ dev_info(chip->dev, "No qcom,jeita-soft-thresholds in DT\n");
+ return;
+ }
+
+ rc = of_property_read_u32_array(chip->dev->of_node,
+ "qcom,jeita-hard-thresholds",
+ hard, ARRAY_SIZE(hard));
+ if (rc) {
+ dev_info(chip->dev, "No qcom,jeita-hard-thresholds in DT\n");
+ return;
+ }
+
+ smblite_write_jeita_16(chip,
+ SMBLITE_BATIF_BASE + SMBLITE_JEITA_COOL_THRESHOLD_CFG, soft[0]);
+ smblite_write_jeita_16(chip,
+ SMBLITE_BATIF_BASE + SMBLITE_JEITA_WARM_THRESHOLD_CFG, soft[1]);
+ smblite_write_jeita_16(chip,
+ SMBLITE_BATIF_BASE + SMBLITE_JEITA_COLD_THRESHOLD_CFG, hard[0]);
+ smblite_write_jeita_16(chip,
+ SMBLITE_BATIF_BASE + SMBLITE_JEITA_HOT_THRESHOLD_CFG, hard[1]);
+
+ dev_dbg(chip->dev,
+ "JEITA: COOL=0x%04x WARM=0x%04x COLD=0x%04x HOT=0x%04x\n",
+ soft[0] & 0xffff, soft[1] & 0xffff,
+ hard[0] & 0xffff, hard[1] & 0xffff);
+}
+
+/*
+ * smblite_enable_jeita - enable JEITA hardware comparators.
+ *
+ * Downstream smblite_init_hw() uses a masked write on
+ * CHGR_FAST_CHARGE_SAFETY_TIMER_CFG_REG (chg_base + 0x90):
+ * mask = 0x0B (bits [3:1] = timer select, bit[0] = enable)
+ * val = 0x0A (FAST_CHARGE_SAFETY_TIMER_768_MIN | enable)
+ * Use regmap_update_bits to touch only those bits.
+ */
+static int smblite_enable_jeita(struct smb_chip *chip)
+{
+ if (chip->type != SMBLITE)
+ return 0;
+
+ return regmap_update_bits(chip->regmap,
+ SMBLITE_CHGR_BASE + 0x90,
+ 0x0B, 0x0A);
+}
+
+static int smblite_detect_ldo_mode(struct smb_chip *chip)
+{
+ unsigned int val;
+ int rc;
+
+ if (chip->type != SMBLITE)
+ return 0;
+
+ rc = regmap_read(chip->regmap,
+ SMBLITE_DCDC_BASE + SMBLITE_DCDC_LDO_CFG, &val);
+ if (rc < 0)
+ return rc;
+
+ chip->ldo_mode = !!(val & SMBLITE_LDO_MODE_BIT);
+ dev_info(chip->dev, "Operating in %s mode\n",
+ chip->ldo_mode ? "LDO" : "switching");
+ return 0;
+}
+
+static int smblite_init_hw_specific(struct smb_chip *chip)
+{
+ int rc;
+
+ if (chip->type != SMBLITE)
+ return 0;
+
+ rc = smblite_detect_ldo_mode(chip);
+ if (rc < 0)
+ return rc;
+
+ rc = smblite_detect_connector_type(chip);
+ if (rc < 0)
+ return rc;
+
+ return smblite_init_typec(chip);
+}
+
static const struct power_supply_desc smb_psy_desc = {
.name = "pmi8998_charger",
.type = POWER_SUPPLY_TYPE_USB,
@@ -897,33 +1542,164 @@ static const struct smb_init_register smb_init_seq[] = {
.val = 1000000 / CURRENT_SCALE_FACTOR },
};
+/* ================================================================
+ * SMBLite init sequence (PM4125)
+ * All addresses are absolute (peripheral_base + offset).
+ *
+ * Modelled strictly after downstream smblite_init_hw() in qpnp-smblite.c.
+ * Key differences from SMB2:
+ * - CHARGING_ENABLE_CMD is at chg_base + 0x46 (not 0x42)
+ * - Watchdog IS enabled (downstream enables it with specific timeout bits)
+ * - No pre-charge current register at 0x60 (that is CHGR_TERM_CFG_REG)
+ * - AICL enable bit is BIT(7) in usbin_base + 0x60
+ * - Suspend-on-collapse is in usbin_base + 0x54 BIT(7)
+ * ================================================================
+ */
+static const struct smb_init_register smblite_init_seq[] = {
+ /* AICL: periodic rerun every 12 s (misc_base + 0x54) */
+ { .addr = SMBLITE_MISC_BASE + SMBLITE_MISC_AICL_RERUN_CFG,
+ .mask = SMBLITE_USBIN_AICL_PERIODIC_RERUN_EN_BIT |
+ SMBLITE_USBIN_AICL_RERUN_TIME_MASK,
+ .val = SMBLITE_USBIN_AICL_PERIODIC_RERUN_EN_BIT |
+ SMBLITE_AICL_RERUN_TIME_12S_VAL },
+ /* Enable AICL (usbin_base + 0x60) */
+ { .addr = SMBLITE_USBIN_BASE + SMBLITE_USBIN_AICL_OPTIONS_CFG,
+ .mask = SMBLITE_USBIN_AICL_EN_BIT | SMBLITE_USBIN_AICL_START_AT_MAX,
+ .val = SMBLITE_USBIN_AICL_EN_BIT },
+ /* Suspend on collapse (usbin_base + 0x54 BIT(7)) */
+ { .addr = SMBLITE_USBIN_BASE + SMBLITE_USBIN_INPUT_SUSPEND,
+ .mask = SMBLITE_SUSPEND_ON_COLLAPSE_USBIN_BIT,
+ .val = SMBLITE_SUSPEND_ON_COLLAPSE_USBIN_BIT },
+ /* VBUS under software control (dcdc_base + 0x56) */
+ { .addr = SMBLITE_DCDC_BASE + SMBLITE_DCDC_OTG_CFG,
+ .mask = SMBLITE_DCDC_OTG_EN_SRC_CFG_BIT,
+ .val = 0 },
+ /*
+ * Watchdog config (misc_base + 0x59):
+ * Bark timeout = 16 s (ilog2(16/16)=0 << shift), bite timeout = 8 s.
+ * Matches downstream DEFAULT_WD_BARK_TIME=16.
+ */
+ { .addr = SMBLITE_MISC_BASE + SMBLITE_SNARL_BARK_BITE_WD_CFG,
+ .mask = SMBLITE_BARK_WDOG_TIMEOUT_MASK | SMBLITE_BITE_WDOG_TIMEOUT_MASK, /* 0xF0 */
+ .val = (SMBLITE_BITE_WDOG_TIMEOUT_8S << SMBLITE_BITE_WDOG_TIMEOUT_SHIFT) }, /* 0xC0 */
+ /*
+ * Enable watchdog: WDOG_TIMER_EN_ON_PLUGIN + BARK_WDOG_INT_EN
+ * + BITE_WDOG_DISABLE_CHARGING (misc_base + 0x58)
+ * Matches downstream WD_CFG_REG enable sequence.
+ */
+ { .addr = SMBLITE_MISC_BASE + SMBLITE_WD_CFG,
+ .mask = SMBLITE_WDOG_TIMER_EN_BIT | SMBLITE_WDOG_TIMER_EN_ON_PLUGIN_BIT |
+ SMBLITE_BARK_WDOG_INT_EN_BIT |
+ SMBLITE_BITE_WDOG_DISABLE_CHARGING_CFG_BIT,
+ .val = SMBLITE_WDOG_TIMER_EN_ON_PLUGIN_BIT |
+ SMBLITE_BARK_WDOG_INT_EN_BIT |
+ SMBLITE_BITE_WDOG_DISABLE_CHARGING_CFG_BIT },
+ /* Enable charging (chg_base + 0x46) */
+ { .addr = SMBLITE_CHGR_BASE + SMBLITE_CHARGING_ENABLE_CMD,
+ .mask = SMBLITE_CHARGING_ENABLE_CMD_BIT,
+ .val = SMBLITE_CHARGING_ENABLE_CMD_BIT },
+ /* SDP: 500 mA USB 2.0 (usbin_base + 0x50) */
+ { .addr = SMBLITE_USBIN_BASE + SMBLITE_USBIN_ICL_OPTIONS,
+ .mask = SMBLITE_USB51_MODE_BIT | SMBLITE_USBIN_MODE_CHG_BIT,
+ .val = SMBLITE_USB51_MODE_BIT },
+ /* Disable HVDCP (usbin_base + 0x48) */
+ { .addr = SMBLITE_USBIN_BASE + SMBLITE_USBIN_QC23_EN,
+ .mask = SMBLITE_HVDCP_EN_BIT,
+ .val = 0 },
+ /* Fast-charge current 1.5 A (chg_base + 0x54) */
+ { .addr = SMBLITE_CHGR_BASE + SMBLITE_CHGR_FAST_CHARGE_CURRENT_CFG,
+ .mask = FAST_CHARGE_CURRENT_SETTING_MASK,
+ .val = 1500000 / SMBLITE_FCC_STEP_UA },
+};
+
static int smb_init_hw(struct smb_chip *chip)
{
- int rc, i;
+ const struct smb_init_register *init_seq;
+ int seq_len, rc, i;
- for (i = 0; i < ARRAY_SIZE(smb_init_seq); i++) {
- dev_dbg(chip->dev, "%d: Writing 0x%02x to 0x%02x\n", i,
- smb_init_seq[i].val, smb_init_seq[i].addr);
- rc = regmap_update_bits(chip->regmap,
- chip->base + smb_init_seq[i].addr,
- smb_init_seq[i].mask,
- smb_init_seq[i].val);
+ rc = smblite_init_hw_specific(chip);
+ if (rc < 0)
+ return rc;
+
+ if (chip->type == SMBLITE) {
+ init_seq = smblite_init_seq;
+ seq_len = ARRAY_SIZE(smblite_init_seq);
+ } else {
+ init_seq = smb_init_seq;
+ seq_len = ARRAY_SIZE(smb_init_seq);
+ }
+
+ for (i = 0; i < seq_len; i++) {
+ /*
+ * SMB2: addresses in smb_init_seq are relative offsets;
+ * prepend chip->base (read from DT "reg").
+ * SMBLite: addresses in smblite_init_seq are already absolute.
+ */
+ u32 addr = (chip->type == SMB2) ?
+ (chip->base + init_seq[i].addr) :
+ init_seq[i].addr;
+
+ dev_dbg(chip->dev, "%d: Writing 0x%02x to 0x%04x\n", i,
+ init_seq[i].val, addr);
+
+ rc = regmap_update_bits(chip->regmap, addr,
+ init_seq[i].mask,
+ init_seq[i].val);
if (rc < 0)
return dev_err_probe(chip->dev, rc,
"%s: init command %d failed\n",
__func__, i);
}
+ /*
+ * SMBLite vendor bring-up register writes.
+ * These are undocumented initialisation values derived from the
+ * downstream qpnp-smblite driver. They are SMBLITE-only.
+ */
+ if (chip->type == SMBLITE) {
+ regmap_write(chip->regmap,
+ SMBLITE_CHGR_BASE + SMBLITE_CHGR_FLOAT_VOLTAGE_CFG, 0x2F);
+ regmap_write(chip->regmap,
+ SMBLITE_BATIF_BASE + SMBLITE_BATIF_BPD_CFG, 0x00);
+ regmap_write(chip->regmap,
+ SMBLITE_BATIF_BASE + SMBLITE_BATIF_JEITA_EN_CFG, 0x00);
+ regmap_write(chip->regmap,
+ SMBLITE_CHGR_BASE + SMBLITE_CHGR_CHG_INHIBIT_CFG, 0x00);
+ regmap_write(chip->regmap,
+ SMBLITE_CHGR_BASE + SMBLITE_CHGR_RECHG_CFG, 0xC2);
+ /* SOC recharge threshold = 250 (0xFA) -- aligned with
+ * SOC-based recharge strategy set at SMBLITE_CHGR_RECHG_CFG=0xC2
+ */
+ regmap_write(chip->regmap,
+ SMBLITE_CHGR_BASE + SMBLITE_CHGR_RECHG_SOC_THD_CFG, 0xFA);
+ regmap_write(chip->regmap,
+ SMBLITE_CHGR_BASE + SMBLITE_CHGR_CHG_TERM_CFG, 0x80);
+ regmap_write(chip->regmap,
+ SMBLITE_USBIN_BASE + SMBLITE_USB_APSD_EN, 0x10);
+ regmap_write(chip->regmap,
+ SMBLITE_USBIN_BASE + SMBLITE_USB_APSD_CFG, 0x00);
+ /* 0x130c, 0x1340: no documented register at this offset */
+ regmap_write(chip->regmap,
+ SMBLITE_CHGR_BASE + SMBLITE_CHGR_IBAT_STATUS, 0xc1);
+ regmap_write(chip->regmap,
+ SMBLITE_CHGR_BASE + SMBLITE_CHGR_VFLT_STATUS, 0x82);
+ }
+
return 0;
}
static void smb_restore_charge_enable(void *data)
{
struct smb_chip *chip = data;
+ u16 reg;
int rc;
- rc = regmap_update_bits(chip->regmap,
- chip->base + CHARGING_ENABLE_CMD,
+ if (chip->type == SMBLITE)
+ reg = SMBLITE_CHGR_BASE + SMBLITE_CHARGING_ENABLE_CMD;
+ else
+ reg = chip->base + CHARGING_ENABLE_CMD;
+
+ rc = regmap_update_bits(chip->regmap, reg,
CHARGING_ENABLE_CMD_BIT,
chip->initial_charge_enable);
if (rc < 0)
@@ -959,6 +1735,7 @@ static int smb_probe(struct platform_device *pdev)
unsigned int charge_enable;
unsigned int float_voltage_sel;
int float_voltage_uv;
+ const char *pmic_name;
int rc, irq;
chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
@@ -966,31 +1743,73 @@ static int smb_probe(struct platform_device *pdev)
return -ENOMEM;
chip->dev = &pdev->dev;
- chip->name = pdev->name;
+
+ pmic_name = device_get_match_data(&pdev->dev);
+ if (!pmic_name)
+ return -EINVAL;
+ chip->name = pmic_name;
+
+ if (strcmp(pmic_name, "pm4125") == 0) {
+ chip->type = SMBLITE;
+ chip->icl_step_ua = SMBLITE_ICL_STEP_UA;
+ chip->fcc_step_ua = SMBLITE_FCC_STEP_UA;
+ chip->icl_max_ua = SMBLITE_ICL_MAX_UA;
+ chip->fcc_max_ua = SMBLITE_FCC_MAX_UA;
+ /* Use the charger peripheral as the base for SMBLite accesses. */
+ chip->base = SMBLITE_CHGR_BASE;
+ } else {
+ /* SMB2: PMI8998, PM660 */
+ chip->type = SMB2;
+ chip->icl_step_ua = CURRENT_SCALE_FACTOR;
+ chip->fcc_step_ua = CURRENT_SCALE_FACTOR;
+ chip->icl_max_ua = 4800000;
+ chip->fcc_max_ua = 4800000;
+ rc = device_property_read_u32(chip->dev, "reg", &chip->base);
+ if (rc < 0)
+ return dev_err_probe(chip->dev, rc,
+ "Couldn't read base address\n");
+ }
chip->regmap = dev_get_regmap(pdev->dev.parent, NULL);
if (!chip->regmap)
return dev_err_probe(chip->dev, -ENODEV,
"failed to locate the regmap\n");
- rc = device_property_read_u32(chip->dev, "reg", &chip->base);
- if (rc < 0)
- return dev_err_probe(chip->dev, rc,
- "Couldn't read base address\n");
-
+ /*
+ * IIO channels:
+ * usbin_v -- voltage, supported by both SMB2 and SMBLite
+ * usbin_i -- current, SMB2 only (not in downstream smblite)
+ * chg_temp -- optional on both
+ */
chip->usb_in_v_chan = devm_iio_channel_get(chip->dev, "usbin_v");
- if (IS_ERR(chip->usb_in_v_chan))
- return dev_err_probe(chip->dev, PTR_ERR(chip->usb_in_v_chan),
- "Couldn't get usbin_v IIO channel\n");
-
- chip->usb_in_i_chan = devm_iio_channel_get(chip->dev, "usbin_i");
- if (IS_ERR(chip->usb_in_i_chan)) {
- return dev_err_probe(chip->dev, PTR_ERR(chip->usb_in_i_chan),
- "Couldn't get usbin_i IIO channel\n");
+ if (IS_ERR(chip->usb_in_v_chan)) {
+ rc = PTR_ERR(chip->usb_in_v_chan);
+ if (rc == -EPROBE_DEFER)
+ return rc;
+ dev_info(chip->dev,
+ "usbin_v IIO channel not available, rc=%d\n", rc);
+ chip->usb_in_v_chan = NULL;
}
- rc = regmap_read(chip->regmap, chip->base + CHARGING_ENABLE_CMD,
- &charge_enable);
+ chip->temp_chan = devm_iio_channel_get(chip->dev, "chg_temp");
+ if (IS_ERR(chip->temp_chan))
+ chip->temp_chan = NULL;
+
+ if (chip->type != SMBLITE) {
+ chip->usb_in_i_chan = devm_iio_channel_get(chip->dev, "usbin_i");
+ if (IS_ERR(chip->usb_in_i_chan))
+ return dev_err_probe(chip->dev,
+ PTR_ERR(chip->usb_in_i_chan),
+ "Couldn't get usbin_i IIO channel\n");
+ }
+
+ if (chip->type == SMBLITE)
+ rc = regmap_read(chip->regmap,
+ SMBLITE_CHGR_BASE + SMBLITE_CHARGING_ENABLE_CMD,
+ &charge_enable);
+ else
+ rc = regmap_read(chip->regmap, chip->base + CHARGING_ENABLE_CMD,
+ &charge_enable);
if (rc < 0)
return dev_err_probe(chip->dev, rc,
"Couldn't read charging state\n");
@@ -1005,6 +1824,11 @@ static int smb_probe(struct platform_device *pdev)
if (rc < 0)
return rc;
+ if (chip->type == SMBLITE) {
+ smblite_program_jeita_thresholds(chip);
+ smblite_enable_jeita(chip);
+ }
+
supply_config.drv_data = chip;
supply_config.fwnode = dev_fwnode(&pdev->dev);
@@ -1012,6 +1836,12 @@ static int smb_probe(struct platform_device *pdev)
if (!desc)
return -ENOMEM;
memcpy(desc, &smb_psy_desc, sizeof(smb_psy_desc));
+
+ if (chip->type == SMBLITE) {
+ desc->properties = smblite_properties;
+ desc->num_properties = ARRAY_SIZE(smblite_properties);
+ }
+
desc->name =
devm_kasprintf(chip->dev, GFP_KERNEL, "%s-charger",
(const char *)device_get_match_data(chip->dev));
@@ -1025,9 +1855,11 @@ static int smb_probe(struct platform_device *pdev)
"failed to register power supply\n");
rc = power_supply_get_battery_info(chip->chg_psy, &chip->batt_info);
- if (rc)
- return dev_err_probe(chip->dev, rc,
- "Failed to get battery info\n");
+ if (rc || !chip->batt_info) {
+ dev_warn(chip->dev,
+ "No battery info, skipping float voltage configuration\n");
+ chip->batt_info = NULL;
+ }
rc = devm_delayed_work_autocancel(chip->dev, &chip->status_change_work,
smb_status_change_work);
@@ -1035,6 +1867,9 @@ static int smb_probe(struct platform_device *pdev)
return dev_err_probe(chip->dev, rc,
"Failed to init status change work\n");
+ if (!chip->batt_info)
+ goto init_irqs;
+
if (power_supply_battery_info_has_prop(chip->batt_info,
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX)) {
float_voltage_uv =
@@ -1043,27 +1878,50 @@ static int smb_probe(struct platform_device *pdev)
POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN)) {
float_voltage_uv = chip->batt_info->voltage_max_design_uv;
} else {
- dev_warn(chip->dev, "No battery float voltage; preserving hardware setting\n");
- goto skip_float_voltage;
+ dev_warn(chip->dev,
+ "No battery float voltage; preserving hardware setting\n");
+ goto init_irqs;
+ }
+
+ if (chip->type == SMBLITE) {
+ if (float_voltage_uv < SMBLITE_FV_MIN_UV ||
+ float_voltage_uv > SMBLITE_FV_MAX_UV)
+ return dev_err_probe(chip->dev, -EINVAL,
+ "float voltage %d uV outside %d-%d uV\n",
+ float_voltage_uv, SMBLITE_FV_MIN_UV,
+ SMBLITE_FV_MAX_UV);
+
+ float_voltage_sel = (float_voltage_uv - SMBLITE_FV_MIN_UV) /
+ SMBLITE_FV_STEP_UV;
+
+ rc = regmap_write(chip->regmap,
+ SMBLITE_CHGR_BASE +
+ SMBLITE_CHGR_FLOAT_VOLTAGE_CFG,
+ float_voltage_sel);
+ } else {
+ if (float_voltage_uv < SMB2_FLOAT_VOLTAGE_MIN_UV ||
+ float_voltage_uv > SMB2_FLOAT_VOLTAGE_MAX_UV)
+ return dev_err_probe(chip->dev, -EINVAL,
+ "float voltage %d uV outside %d-%d uV\n",
+ float_voltage_uv,
+ SMB2_FLOAT_VOLTAGE_MIN_UV,
+ SMB2_FLOAT_VOLTAGE_MAX_UV);
+
+ float_voltage_sel =
+ (float_voltage_uv - SMB2_FLOAT_VOLTAGE_MIN_UV) /
+ SMB2_FLOAT_VOLTAGE_STEP_UV;
+
+ rc = regmap_update_bits(chip->regmap,
+ chip->base + FLOAT_VOLTAGE_CFG,
+ FLOAT_VOLTAGE_SETTING_MASK,
+ float_voltage_sel);
}
- if (float_voltage_uv < SMB2_FLOAT_VOLTAGE_MIN_UV ||
- float_voltage_uv > SMB2_FLOAT_VOLTAGE_MAX_UV)
- return dev_err_probe(chip->dev, -EINVAL,
- "float voltage %d uV outside %d-%d uV\n",
- float_voltage_uv,
- SMB2_FLOAT_VOLTAGE_MIN_UV,
- SMB2_FLOAT_VOLTAGE_MAX_UV);
-
- float_voltage_sel =
- (float_voltage_uv - SMB2_FLOAT_VOLTAGE_MIN_UV) /
- SMB2_FLOAT_VOLTAGE_STEP_UV;
- rc = regmap_update_bits(chip->regmap, chip->base + FLOAT_VOLTAGE_CFG,
- FLOAT_VOLTAGE_SETTING_MASK, float_voltage_sel);
if (rc < 0)
return dev_err_probe(chip->dev, rc, "Couldn't set vbat max\n");
-skip_float_voltage:
+init_irqs:
+
rc = smb_init_irq(chip, &irq, "bat-ov", smb_handle_batt_overvoltage);
if (rc < 0)
return rc;
@@ -1087,6 +1945,15 @@ static int smb_probe(struct platform_device *pdev)
if (rc < 0)
return dev_err_probe(chip->dev, rc, "Couldn't set wake irq\n");
+ chip->vbus_reg = devm_regulator_get_optional(chip->dev, "vbus");
+ if (IS_ERR(chip->vbus_reg)) {
+ rc = PTR_ERR(chip->vbus_reg);
+ if (rc == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+ dev_warn(chip->dev, "vbus regulator not found, ignoring\n");
+ chip->vbus_reg = NULL;
+ }
+
devm_remove_action(chip->dev, smb_restore_charge_enable, chip);
platform_set_drvdata(pdev, chip);
@@ -1100,6 +1967,7 @@ static int smb_probe(struct platform_device *pdev)
static const struct of_device_id smb_match_id_table[] = {
{ .compatible = "qcom,pmi8998-charger", .data = "pmi8998" },
{ .compatible = "qcom,pm660-charger", .data = "pm660" },
+ { .compatible = "qcom,pm4125-charger", .data = "pm4125" },
{ /* sentinal */ }
};
MODULE_DEVICE_TABLE(of, smb_match_id_table);
@@ -1115,6 +1983,6 @@ static struct platform_driver qcom_spmi_smb = {
module_platform_driver(qcom_spmi_smb);
MODULE_AUTHOR("Casey Connolly <casey.connolly@linaro.org>");
-MODULE_DESCRIPTION("Qualcomm SMB2 Charger Driver");
+MODULE_DESCRIPTION("Qualcomm SMB2/SMBLite charger driver");
MODULE_LICENSE("GPL");
MODULE_IMPORT_NS("IIO_CONSUMER");
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] dt-bindings: power: supply: Add qcom,pm4125-charger binding
2026-11-24 9:15 ` [PATCH 1/2] dt-bindings: power: supply: Add qcom,pm4125-charger binding Raj Aryan
@ 2026-11-24 9:26 ` sashiko-bot
2026-11-24 9:55 ` Krzysztof Kozlowski
1 sibling, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-24 9:26 UTC (permalink / raw)
To: Raj Aryan; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] dt-bindings: power: supply: example lacks parent pmic node
and has unused label
- [Low] dt-bindings: power: supply: redundant word binding in commit
subject
- [Low] dt-bindings: power: supply: fixed-entry arrays lack per-entry
items list
- [Low] dt-bindings: power: supply: qcom,pm4125-charger missing from
qcom,spmi-pmic.yaml
--
commit 45ce3860e319677782a8540cf93046fcf2b07086
Author: Raj Aryan <raj.aryan@oss.qualcomm.com>
dt-bindings: power: supply: Add qcom,pm4125-charger binding
This commit adds a YAML Devicetree binding schema for the Qualcomm SMBLite
switch-mode battery charger found on the PM4125 PMIC.
> dt-bindings: power: supply: Add qcom,pm4125-charger binding
[Severity: Low]
The dt-bindings: prefix already indicates that this adds a binding, so the
trailing word "binding" in the subject can be dropped ("dt-bindings: power:
supply: Add qcom,pm4125-charger").
> diff --git a/Documentation/devicetree/bindings/power/supply/qcom,pm4125-charger.yaml b/Documentation/devicetree/bindings/power/supply/qcom,pm4125-charger.yaml
> new file mode 100644
> index 0000000000000..5651b428b0a11
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/power/supply/qcom,pm4125-charger.yaml
> @@ -0,0 +1,109 @@
> +# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/power/supply/qcom,pm4125-charger.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Qualcomm PM4125 SMBLite Switch-Mode Battery Charger
[ ... ]
> +properties:
> + compatible:
> + const: qcom,pm4125-charger
[Severity: Low]
Should this schema be referenced under ^charger@[0-9a-f]+$ in
Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml (or folded into
Documentation/devicetree/bindings/power/supply/qcom,pmi8998-charger.yaml)?
qcom,spmi-pmic.yaml validates ^charger@[0-9a-f]+$ child nodes against a
closed oneOf list and sets additionalProperties: false, so any SPMI PMIC
node containing a qcom,pm4125-charger child node will fail dtbs_check.
[ ... ]
> + io-channels:
> + minItems: 1
> + maxItems: 2
> + description: |
> + IIO ADC channels used by the charger. usbin_v is the USB input
> + voltage channel (ADC5_USB_IN_V_16). usbin_i is the USB input
> + current channel (ADC5_USB_IN_I).
> +
> + io-channel-names:
> + minItems: 1
> + items:
> + - const: usbin_v
> + - const: usbin_i
> +
> + monitored-battery: true
> +
> + qcom,jeita-soft-thresholds:
> + $ref: /schemas/types.yaml#/definitions/uint32-array
> + minItems: 2
> + maxItems: 2
> + description: |
> + JEITA soft temperature thresholds (COOL, WARM) as raw 16-bit ADC
> + comparator values written to the BATIF ADC comparator registers.
> + Example: <0x5314 0x25e3> for COOL=15°C, WARM=45°C.
> +
> + qcom,jeita-hard-thresholds:
> + $ref: /schemas/types.yaml#/definitions/uint32-array
> + minItems: 2
> + maxItems: 2
> + description: |
> + JEITA hard temperature thresholds (COLD, HOT) as raw 16-bit ADC
> + comparator values written to the BATIF ADC comparator registers.
> + Example: <0x58cd 0x20b8> for COLD=0°C, HOT=60°C.
[Severity: Low]
Should io-channels, qcom,jeita-soft-thresholds, and
qcom,jeita-hard-thresholds use an items list with per-entry descriptions
instead of maxItems and free-form descriptions enumerating the entries?
In addition, the JEITA thresholds encode raw 16-bit ADC register values in
uint32-array without a maximum: 0xffff bound, rather than using the
standard alert-celsius and operating-range-celsius properties from
battery.yaml via monitored-battery.
[ ... ]
> +examples:
> + - |
> + #include <dt-bindings/interrupt-controller/irq.h>
> + #include <dt-bindings/iio/qcom,spmi-vadc.h>
> +
> + pm4125_charger: charger@1000 {
> + compatible = "qcom,pm4125-charger";
> + reg = <0x1000>;
[Severity: Medium]
Does this example pass make dt_binding_check?
Top-level example nodes default to #address-cells = <1> and
#size-cells = <1>, so a single-cell reg = <0x1000> without an enclosing
pmic node specifying #address-cells = <1> and #size-cells = <0> triggers a
dtc reg_format error. The pm4125_charger label is also unused, which fails
the unused-labels check.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-smblite-charger-for-pm4125-v1-0-2132c9f0601f@oss.qualcomm.com?part=1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] power: supply: qcom_smbx: Add SMBLite charger support
2026-11-24 9:15 ` [PATCH 2/2] power: supply: qcom_smbx: Add SMBLite charger support Raj Aryan
@ 2026-11-24 9:32 ` sashiko-bot
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-24 9:32 UTC (permalink / raw)
To: Raj Aryan; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 13 potential
issues to consider:
- [High] power: supply: qcom_smbx: missing chip->base in
smb_apsd_get_charger_type()
- [High] power: supply: qcom_smbx: wrong register written in
smblite_enable_jeita()
- [High] power: supply: qcom_smbx: unsafe 4.54V float voltage write in
smb_init_hw()
- [High] power: supply: qcom_smbx: watchdog disables charging during
system suspend
- [Medium] power: supply: qcom_smbx: invalid status and rechg writes in
smb_init_hw()
- [Medium] power: supply: qcom_smbx: stale charge_status in
smb_get_property()
- [Medium] power: supply: qcom_smbx: missing SMBLite rerun in
smb_status_change_work()
- [Medium] power: supply: qcom_smbx: unused resources and ABI mismatches
in smb_probe()
- [Medium] power: supply: qcom_smbx: missing BAT_OV check in
smb_get_prop_health()
- [Medium] power: supply: qcom_smbx: watchdog left armed on probe
failure or unbind
- [Medium] power: supply: qcom_smbx: stale usb_type_override on replug
in smb_handle_usb_plugin()
- [Medium] power: supply: qcom_smbx: race on usb_type_override and ICL
in smb_status_change_work()
- [Medium] power: supply: qcom_smbx: smblite_init_typec() clobbers
Type-C peripheral at 0x1500
--
commit 2884aa25bff648d3cce68c70d47efa2d6630bb25
Author: Raj Aryan <raj.aryan@oss.qualcomm.com>
power: supply: qcom_smbx: Add SMBLite charger support
This commit extends the qcom_smbx charger driver to support the SMBLite
charger block found on the PM4125 PMIC alongside existing SMB2 PMICs.
> diff --git a/drivers/power/supply/qcom_smbx.c b/drivers/power/supply/qcom_smbx.c
> index 52bb5a6eb145d..54b2942e2f5ad 100644
> --- a/drivers/power/supply/qcom_smbx.c
> +++ b/drivers/power/supply/qcom_smbx.c
[ ... ]
> @@ -451,7 +665,15 @@ static int smb_apsd_get_charger_type(struct smb_chip *chip, int *val)
> return rc;
> }
>
> - rc = regmap_read(chip->regmap, chip->base + APSD_STATUS, &apsd_stat);
> + if (chip->type == SMBLITE) {
> + apsd_reg = SMBLITE_USBIN_BASE + SMBLITE_APSD_STATUS;
> + result_reg = SMBLITE_USBIN_BASE + SMBLITE_APSD_RESULT_STATUS;
> + } else {
> + apsd_reg = APSD_STATUS;
> + result_reg = APSD_RESULT_STATUS;
> + }
> +
> + rc = regmap_read(chip->regmap, apsd_reg, &apsd_stat);
[Severity: High]
Does the else branch omit chip->base when computing apsd_reg and
result_reg?
On SMB2 (PMI8998 and PM660), APSD_STATUS (0x307) and APSD_RESULT_STATUS
(0x308) are offsets relative to chip->base (0x1000). Reading bare 0x0307
and 0x0308 breaks APSD charger type detection and POWER_SUPPLY_PROP_USB_TYPE
on existing SMB2 devices, and causes smb_status_change_work() to spin in a
1 Hz retry loop without setting the input current limit.
[ ... ]
> @@ -562,8 +883,17 @@ static void smb_status_change_work(struct work_struct *work)
> chip = container_of(work, struct smb_chip, status_change_work.work);
>
> smb_get_prop_usb_online(chip, &usb_online);
> - if (!usb_online)
> + if (!usb_online) {
> + chip->usb_type_override = false;
> + chip->usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN;
> return;
> + }
> +
> + if (chip->type == SMBLITE && chip->usb_type_override) {
> + smb_set_current_limit(chip, smb_usb_type_current_ua(chip->usb_type));
> + power_supply_changed(chip->chg_psy);
> + return;
> + }
>
> for (count = 0; count < 3; count++) {
> dev_dbg(chip->dev, "get charger type retry %d\n", count);
> @@ -579,27 +909,16 @@ static void smb_status_change_work(struct work_struct *work)
> }
>
> if (rc < 0) {
> - rc = regmap_update_bits(chip->regmap, chip->base + CMD_APSD,
> - APSD_RERUN_BIT, APSD_RERUN_BIT);
> + if (chip->type != SMBLITE)
> + rc = regmap_update_bits(chip->regmap, chip->base + CMD_APSD,
> + APSD_RERUN_BIT, APSD_RERUN_BIT);
> schedule_delayed_work(&chip->status_change_work,
> msecs_to_jiffies(1000));
> dev_dbg(chip->dev, "get charger type failed, rerun apsd\n");
> return;
> }
[Severity: Medium]
Should SMBLite trigger an APSD rerun via SMBLITE_USBIN_BASE +
SMBLITE_CMD_APSD here instead of skipping the write?
When smb_apsd_get_charger_type() returns -EAGAIN after three retries,
skipping the rerun command leaves SMBLITE_CMD_APSD unused while
status_change_work reschedules itself every second waiting for APSD to
complete.
> - switch (charger_type) {
> - case POWER_SUPPLY_USB_TYPE_CDP:
> - current_ua = CDP_CURRENT_UA;
> - break;
> - case POWER_SUPPLY_USB_TYPE_DCP:
> - current_ua = DCP_CURRENT_UA;
> - break;
> - case POWER_SUPPLY_USB_TYPE_SDP:
> - default:
> - current_ua = SDP_CURRENT_UA;
> - break;
> - }
> -
> + current_ua = smb_usb_type_current_ua(charger_type);
> smb_set_current_limit(chip, current_ua);
> power_supply_changed(chip->chg_psy);
> }
[Severity: Medium]
Can smb_status_change_work() race with smb_set_property() and overwrite an
active usb_type_override current limit?
kworker (status_change_work) CPU1 (smb_set_property)
---------------------------- -----------------------
if (chip->usb_type_override)
/* false */
for (count = 0; count < 3; ...)
msleep(100)
case POWER_SUPPLY_PROP_USB_TYPE:
chip->usb_type = ..._DCP;
chip->usb_type_override = true;
smb_set_current_limit(chip, 1500000);
smb_set_current_limit(chip,
current_ua) <-- overwrites 1.5 A with APSD limit
Nothing serializes chip->usb_type_override, chip->usb_type, and
smb_set_current_limit() between smb_set_property() and
smb_status_change_work(). In addition, setting POWER_SUPPLY_PROP_USB_TYPE
to POWER_SUPPLY_USB_TYPE_UNKNOWN in smb_set_property() clears
chip->usb_type_override without updating the hardware current limit or
rescheduling status_change_work.
[ ... ]
> @@ -625,11 +949,48 @@ static int smb_get_iio_chan(struct smb_chip *chip, struct iio_channel *chan,
> return iio_read_channel_processed(chan, val);
> }
>
> +/*
> + * smb_get_prop_health - battery health based on temperature status.
> + *
> + * SMBLite: BATTERY_TEMP_STATUS_REG = batif_base + 0x0C (smblite-reg.h)
> + * SMB2: BATTERY_CHARGER_STATUS_2 = chip->base + 0x07
> + */
> static int smb_get_prop_health(struct smb_chip *chip, int *val)
> {
> int rc;
> unsigned int stat;
>
> + if (chip->type == SMBLITE) {
> + rc = regmap_read(chip->regmap,
> + SMBLITE_BATIF_BASE + SMBLITE_BATIF_JEITA_COMP_STATUS,
> + &stat);
> + if (rc < 0) {
> + dev_err(chip->dev,
> + "Couldn't read SMBLITE JEITA status rc=%d\n", rc);
> + return rc;
> + }
> + if (stat & (SMBLITE_JEITA_ADC_THOT_AFP_BIT |
> + SMBLITE_JEITA_ADC_THOT_BIT)) {
> + *val = POWER_SUPPLY_HEALTH_OVERHEAT;
> + return 0;
> + }
> + if (stat & (SMBLITE_JEITA_ADC_TCOLD_AFP_BIT |
> + SMBLITE_JEITA_ADC_TCOLD_BIT)) {
> + *val = POWER_SUPPLY_HEALTH_COLD;
> + return 0;
> + }
> + if (stat & SMBLITE_JEITA_ADC_WARM_BIT) {
> + *val = POWER_SUPPLY_HEALTH_WARM;
> + return 0;
> + }
> + if (stat & SMBLITE_JEITA_ADC_COOL_BIT) {
> + *val = POWER_SUPPLY_HEALTH_COOL;
> + return 0;
> + }
> + *val = POWER_SUPPLY_HEALTH_GOOD;
> + return 0;
> + }
[Severity: Medium]
Does the SMBLite path in smb_get_prop_health() miss battery overvoltage
faults?
Unlike the SMB2 path below it, which checks CHARGER_ERROR_STATUS_BAT_OV_BIT
and reports POWER_SUPPLY_HEALTH_OVERVOLTAGE, the SMBLite branch never checks
SMBLITE_BAT_OV_BIT in SMBLITE_CHGR_BASE + SMBLITE_CHARGER_VBAT_STATUS, so
POWER_SUPPLY_PROP_HEALTH reports POWER_SUPPLY_HEALTH_GOOD during an active
overvoltage event.
[ ... ]
> @@ -681,7 +1044,32 @@ static int smb_get_property(struct power_supply *psy,
> case POWER_SUPPLY_PROP_HEALTH:
> return smb_get_prop_health(chip, &val->intval);
> case POWER_SUPPLY_PROP_USB_TYPE:
> + if (chip->type == SMBLITE && chip->usb_type_override) {
> + int usb_online = 0;
> +
> + smb_get_prop_usb_online(chip, &usb_online);
> + if (usb_online) {
> + val->intval = chip->usb_type;
> + return 0;
> + }
> + }
> return smb_apsd_get_charger_type(chip, &val->intval);
> + case POWER_SUPPLY_PROP_CHARGE_TYPE:
> + if (chip->type != SMBLITE)
> + return -EOPNOTSUPP;
> + switch (chip->charge_status) {
> + case POWER_SUPPLY_STATUS_FULL:
> + val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
> + break;
> + case POWER_SUPPLY_STATUS_CHARGING:
> + val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD;
> + break;
> + default:
> + val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN;
> + break;
> + }
> +
> + return 0;
[Severity: Medium]
Can POWER_SUPPLY_PROP_CHARGE_TYPE report stale state from
chip->charge_status?
smb_get_property() does not refresh the hardware state before reading
chip->charge_status, and smb_get_prop_status() returns early when
!usb_online without updating chip->charge_status:
drivers/power/supply/qcom_smbx.c:smb_get_prop_status() {
rc = smb_get_prop_usb_online(chip, &usb_online);
if (!usb_online) {
*val = POWER_SUPPLY_STATUS_DISCHARGING;
return rc;
}
}
After unplugging a charger while charging, POWER_SUPPLY_PROP_STATUS reports
POWER_SUPPLY_STATUS_DISCHARGING while POWER_SUPPLY_PROP_CHARGE_TYPE stays
stuck at POWER_SUPPLY_CHARGE_TYPE_STANDARD.
[ ... ]
> @@ -709,44 +1121,93 @@ static int smb_set_property(struct power_supply *psy,
> static int smb_property_is_writable(struct power_supply *psy,
> enum power_supply_property psp)
> {
> + struct smb_chip *chip = power_supply_get_drvdata(psy);
> +
> switch (psp) {
> case POWER_SUPPLY_PROP_STATUS:
> + return chip->type != SMBLITE;
> case POWER_SUPPLY_PROP_CURRENT_MAX:
> return 1;
> + case POWER_SUPPLY_PROP_USB_TYPE:
> + return chip->type == SMBLITE;
> default:
> return 0;
> }
> }
[ ... ]
> static irqreturn_t smb_handle_usb_plugin(int irq, void *data)
> {
> struct smb_chip *chip = data;
> + int usb_online = 0;
>
> power_supply_changed(chip->chg_psy);
> + smb_get_prop_usb_online(chip, &usb_online);
>
> + if (!usb_online)
> + goto schedule_work;
[Severity: Medium]
Does leaving chip->usb_type_override set on unplug cause a stale USB type
and current limit to be applied if a cable is replugged within 1500 ms?
When a charger is unplugged, smb_handle_usb_plugin() leaves
chip->usb_type_override set until status_change_work runs 1500 ms later.
If a different cable (for example, a 500 mA SDP host port after a 1.5 A DCP
charger) is connected before that 1500 ms timer fires, usb_online is true
when status_change_work runs, so the !usb_online reset is skipped and the
previous charger's current limit is programmed onto the new port.
[ ... ]
> static irqreturn_t smb_handle_wdog_bark(int irq, void *data)
> {
> struct smb_chip *chip = data;
> + u16 reg;
> int rc;
>
> power_supply_changed(chip->chg_psy);
>
> - rc = regmap_write(chip->regmap, chip->base + BARK_BITE_WDOG_PET,
> - BARK_BITE_WDOG_PET_BIT);
> + if (chip->type == SMBLITE)
> + reg = SMBLITE_MISC_BASE + SMBLITE_BARK_BITE_WDOG_PET;
> + else
> + reg = chip->base + BARK_BITE_WDOG_PET;
> +
> + rc = regmap_write(chip->regmap, reg, BARK_BITE_WDOG_PET_BIT);
> if (rc < 0)
> dev_err(chip->dev, "Couldn't pet the dog rc=%d\n", rc);
>
> return IRQ_HANDLED;
> }
[ ... ]
> +static int smblite_init_typec(struct smb_chip *chip)
> +{
> + unsigned int val;
> + int rc;
> +
> + if (chip->type != SMBLITE)
> + return 0;
> + if (chip->connector_type != CONNECTOR_TYPE_TYPEC)
> + return 0;
> +
> + rc = regmap_read(chip->regmap,
> + SMBLITE_TYPEC_BASE + SMBLITE_LEGACY_CABLE_STATUS, &val);
> + if (rc < 0)
> + return rc;
> +
> + if (val & SMBLITE_TYPEC_LEGACY_CABLE_STATUS_BIT) {
> + dev_dbg(chip->dev, "Resetting legacy cable detection\n");
> + rc = regmap_update_bits(chip->regmap,
> + SMBLITE_TYPEC_BASE + SMBLITE_TYPE_C_MODE_CFG,
> + EN_TRY_SNK_BIT | EN_SNK_ONLY_BIT, 0);
> + if (rc < 0)
> + return rc;
> + msleep(50);
> + }
> +
> + rc = regmap_update_bits(chip->regmap,
> + SMBLITE_TYPEC_BASE + SMBLITE_TYPE_C_MODE_CFG,
> + EN_TRY_SNK_BIT | EN_SNK_ONLY_BIT,
> + EN_TRY_SNK_BIT);
> + if (rc < 0)
> + return rc;
> +
> + return regmap_update_bits(chip->regmap,
> + SMBLITE_TYPEC_BASE + SMBLITE_TYPE_C_EXIT_STATE_CFG,
> + SEL_SRC_UPPER_REF_BIT, SEL_SRC_UPPER_REF_BIT);
> +}
[Severity: Medium]
Does smblite_init_typec() overwrite registers owned by the PM4125 Type-C
driver at 0x1500?
On PM4125, the SPMI Type-C peripheral at 0x1500 is a separate devicetree
node (typec@1500) managed by qcom_pmic_typec, which controls
TYPE_C_MODE_CFG (0x1544) and TYPE_C_EXIT_STATE_CFG (0x1550) under
pmic_typec_port->lock. Modifying 0x1544 and 0x1550 directly through the
parent PMIC regmap during charger probe clobbers the TCPM port state if
qcom_pmic_typec has already started.
[ ... ]
> +/*
> + * smblite_enable_jeita - enable JEITA hardware comparators.
> + *
> + * Downstream smblite_init_hw() uses a masked write on
> + * CHGR_FAST_CHARGE_SAFETY_TIMER_CFG_REG (chg_base + 0x90):
> + * mask = 0x0B (bits [3:1] = timer select, bit[0] = enable)
> + * val = 0x0A (FAST_CHARGE_SAFETY_TIMER_768_MIN | enable)
> + * Use regmap_update_bits to touch only those bits.
> + */
> +static int smblite_enable_jeita(struct smb_chip *chip)
> +{
> + if (chip->type != SMBLITE)
> + return 0;
> +
> + return regmap_update_bits(chip->regmap,
> + SMBLITE_CHGR_BASE + 0x90,
> + 0x0B, 0x0A);
> +}
[Severity: High]
Does smblite_enable_jeita() write to the fast-charge safety timer register
(SMBLITE_CHGR_BASE + 0x90) instead of SMBLITE_BATIF_BASE +
SMBLITE_BATIF_JEITA_EN_CFG (0x127F)?
On SMB2, offset 0x90 in the charger block is JEITA_EN_CFG, whereas on
SMBLite JEITA enable is in BATIF at SMBLITE_BATIF_BASE +
SMBLITE_BATIF_JEITA_EN_CFG (0x127F), which smb_init_hw() explicitly clears
to 0x00. Because 0x127F is never re-enabled, hardware JEITA thermal
protection and SMBLITE_BATIF_JEITA_COMP_STATUS health reporting remain
disabled (and even for the safety timer at 0x1090, val 0x0A clears bit 0).
Also, smb_probe() calls smblite_enable_jeita() unconditionally even when
the DT threshold properties are absent, and ignores the return values of
both smblite_enable_jeita() and smblite_write_jeita_16().
[ ... ]
> + /*
> + * Enable watchdog: WDOG_TIMER_EN_ON_PLUGIN + BARK_WDOG_INT_EN
> + * + BITE_WDOG_DISABLE_CHARGING (misc_base + 0x58)
> + * Matches downstream WD_CFG_REG enable sequence.
> + */
> + { .addr = SMBLITE_MISC_BASE + SMBLITE_WD_CFG,
> + .mask = SMBLITE_WDOG_TIMER_EN_BIT | SMBLITE_WDOG_TIMER_EN_ON_PLUGIN_BIT |
> + SMBLITE_BARK_WDOG_INT_EN_BIT |
> + SMBLITE_BITE_WDOG_DISABLE_CHARGING_CFG_BIT,
> + .val = SMBLITE_WDOG_TIMER_EN_ON_PLUGIN_BIT |
> + SMBLITE_BARK_WDOG_INT_EN_BIT |
> + SMBLITE_BITE_WDOG_DISABLE_CHARGING_CFG_BIT },
[Severity: High]
Will the SMBLite watchdog bite and disable charging 24 seconds after the
system enters suspend?
smblite_init_seq enables the watchdog on plugin with a 16-second bark
timeout, an 8-second bite timeout, and
SMBLITE_BITE_WDOG_DISABLE_CHARGING_CFG_BIT set, but the driver defines no
PM suspend/resume callbacks to disable the watchdog during suspend and only
marks cable_irq as a wake IRQ. When the system suspends while plugged in,
wdog-bark is not serviced and the watchdog disables charging after 24
seconds. While awake, smb_handle_wdog_bark() also calls
power_supply_changed() on every 16-second bark, causing unnecessary
pm_stay_awake() wakeups and userspace uevents even when nothing changed.
[ ... ]
> + /*
> + * SMBLite vendor bring-up register writes.
> + * These are undocumented initialisation values derived from the
> + * downstream qpnp-smblite driver. They are SMBLITE-only.
> + */
> + if (chip->type == SMBLITE) {
> + regmap_write(chip->regmap,
> + SMBLITE_CHGR_BASE + SMBLITE_CHGR_FLOAT_VOLTAGE_CFG, 0x2F);
> + regmap_write(chip->regmap,
> + SMBLITE_BATIF_BASE + SMBLITE_BATIF_BPD_CFG, 0x00);
> + regmap_write(chip->regmap,
> + SMBLITE_BATIF_BASE + SMBLITE_BATIF_JEITA_EN_CFG, 0x00);
> + regmap_write(chip->regmap,
> + SMBLITE_CHGR_BASE + SMBLITE_CHGR_CHG_INHIBIT_CFG, 0x00);
> + regmap_write(chip->regmap,
> + SMBLITE_CHGR_BASE + SMBLITE_CHGR_RECHG_CFG, 0xC2);
> + /* SOC recharge threshold = 250 (0xFA) -- aligned with
> + * SOC-based recharge strategy set at SMBLITE_CHGR_RECHG_CFG=0xC2
> + */
> + regmap_write(chip->regmap,
> + SMBLITE_CHGR_BASE + SMBLITE_CHGR_RECHG_SOC_THD_CFG, 0xFA);
> + regmap_write(chip->regmap,
> + SMBLITE_CHGR_BASE + SMBLITE_CHGR_CHG_TERM_CFG, 0x80);
> + regmap_write(chip->regmap,
> + SMBLITE_USBIN_BASE + SMBLITE_USB_APSD_EN, 0x10);
> + regmap_write(chip->regmap,
> + SMBLITE_USBIN_BASE + SMBLITE_USB_APSD_CFG, 0x00);
> + /* 0x130c, 0x1340: no documented register at this offset */
> + regmap_write(chip->regmap,
> + SMBLITE_CHGR_BASE + SMBLITE_CHGR_IBAT_STATUS, 0xc1);
> + regmap_write(chip->regmap,
> + SMBLITE_CHGR_BASE + SMBLITE_CHGR_VFLT_STATUS, 0x82);
> + }
[Severity: Medium]
Why does smb_init_hw() write 0xc1 and 0x82 to the read-only charger status
registers SMBLITE_CHGR_IBAT_STATUS (0x100A) and SMBLITE_CHGR_VFLT_STATUS
(0x100B)?
The comment right above those writes mentions USBIN offsets 0x130c and
0x1340, whereas the code writes to read-only CHGR status registers 0x100A
and 0x100B. Also, writing 0xC2 to SMBLITE_CHGR_RECHG_CFG sets
SMBLITE_VBAT_BASED_RECHG_BIT (BIT(7)), which contradicts the comment and
commit message stating that SOC-based recharge is selected, and none of the
regmap_write() calls in this block check for errors.
>
> return 0;
> }
>
> static void smb_restore_charge_enable(void *data)
> {
> struct smb_chip *chip = data;
> + u16 reg;
> int rc;
>
> - rc = regmap_update_bits(chip->regmap,
> - chip->base + CHARGING_ENABLE_CMD,
> + if (chip->type == SMBLITE)
> + reg = SMBLITE_CHGR_BASE + SMBLITE_CHARGING_ENABLE_CMD;
> + else
> + reg = chip->base + CHARGING_ENABLE_CMD;
> +
> + rc = regmap_update_bits(chip->regmap, reg,
> CHARGING_ENABLE_CMD_BIT,
> chip->initial_charge_enable);
> if (rc < 0)
[Severity: Medium]
Does smb_restore_charge_enable() leave the SMBLite hardware watchdog armed
if smb_probe() fails after smb_init_hw() or if the driver is unbound?
smblite_init_seq enables SMBLITE_WD_CFG with
SMBLITE_BITE_WDOG_DISABLE_CHARGING_CFG_BIT set, but
smb_restore_charge_enable() only restores SMBLITE_CHARGING_ENABLE_CMD (and
is removed before probe returns). Without the wdog-bark handler running to
pet the watchdog, it will bite 24 seconds after USB plugin and disable
charging in hardware.
[ ... ]
> @@ -1025,9 +1855,11 @@ static int smb_probe(struct platform_device *pdev)
> "failed to register power supply\n");
>
> rc = power_supply_get_battery_info(chip->chg_psy, &chip->batt_info);
> - if (rc)
> - return dev_err_probe(chip->dev, rc,
> - "Failed to get battery info\n");
> + if (rc || !chip->batt_info) {
> + dev_warn(chip->dev,
> + "No battery info, skipping float voltage configuration\n");
> + chip->batt_info = NULL;
> + }
>
> rc = devm_delayed_work_autocancel(chip->dev, &chip->status_change_work,
> smb_status_change_work);
> @@ -1035,6 +1867,9 @@ static int smb_probe(struct platform_device *pdev)
> return dev_err_probe(chip->dev, rc,
> "Failed to init status change work\n");
>
> + if (!chip->batt_info)
> + goto init_irqs;
> +
> if (power_supply_battery_info_has_prop(chip->batt_info,
> POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX)) {
> float_voltage_uv =
> @@ -1043,27 +1878,50 @@ static int smb_probe(struct platform_device *pdev)
> POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN)) {
> float_voltage_uv = chip->batt_info->voltage_max_design_uv;
> } else {
> - dev_warn(chip->dev, "No battery float voltage; preserving hardware setting\n");
> - goto skip_float_voltage;
> + dev_warn(chip->dev,
> + "No battery float voltage; preserving hardware setting\n");
> + goto init_irqs;
> + }
[Severity: High]
Does skipping float voltage configuration here leave SMBLite charging
enabled at 4.54 V?
In smb_init_hw(), the SMBLite path enables charging at 1.5 A and
unconditionally writes 0x2F (3600000 + 47 * 20000 = 4540000 uV) to
SMBLITE_CHGR_FLOAT_VOLTAGE_CFG before smb_probe() reads the battery info.
If monitored-battery is omitted, has no voltage property, or
power_supply_get_battery_info() fails, jumping to init_irqs does not
preserve the hardware setting—it leaves the charger active at 4.54 V, which
can overcharge standard 4.2 V / 4.35 V / 4.4 V Li-ion cells. Downgrading
power_supply_get_battery_info() errors to a warning also masks real errors
such as -ENOMEM or malformed battery DT nodes on both SMB2 and SMBLite.
[ ... ]
> @@ -1087,6 +1945,15 @@ static int smb_probe(struct platform_device *pdev)
> if (rc < 0)
> return dev_err_probe(chip->dev, rc, "Couldn't set wake irq\n");
>
> + chip->vbus_reg = devm_regulator_get_optional(chip->dev, "vbus");
> + if (IS_ERR(chip->vbus_reg)) {
> + rc = PTR_ERR(chip->vbus_reg);
> + if (rc == -EPROBE_DEFER)
> + return -EPROBE_DEFER;
> + dev_warn(chip->dev, "vbus regulator not found, ignoring\n");
> + chip->vbus_reg = NULL;
> + }
> +
> devm_remove_action(chip->dev, smb_restore_charge_enable, chip);
[Severity: Medium]
Why does smb_probe() request a "vbus" regulator and a "chg_temp" IIO
channel that are never used anywhere in the driver?
Neither resource is documented in the DT bindings, and because
devm_regulator_get_optional() returns ERR_PTR(-ENODEV) when vbus-supply is
absent, every board prints a false "vbus regulator not found, ignoring"
warning at boot (or can return -EPROBE_DEFER after IRQs are already live).
Conversely, the PM4125 binding documents the "usbin_i" IIO channel, which
smb_probe() skips on SMBLite, and smb_property_is_writable() marks
POWER_SUPPLY_PROP_USB_TYPE writable in sysfs even though
Documentation/ABI/testing/sysfs-class-power defines usb_type as read-only
for USB charger supplies (in-kernel callers of power_supply_set_property()
do not check property_is_writeable()). The struct smb_chip fields
ldo_mode, fcc_step_ua, fcc_max_ua, and charge_done are also written but
never read.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-smblite-charger-for-pm4125-v1-0-2132c9f0601f@oss.qualcomm.com?part=2
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] arm64: qcom: Add SMBLite charger support for PM4125
2026-11-24 9:15 [PATCH 0/2] arm64: qcom: Add SMBLite charger support for PM4125 Raj Aryan
2026-11-24 9:15 ` [PATCH 1/2] dt-bindings: power: supply: Add qcom,pm4125-charger binding Raj Aryan
2026-11-24 9:15 ` [PATCH 2/2] power: supply: qcom_smbx: Add SMBLite charger support Raj Aryan
@ 2026-11-24 9:48 ` Krzysztof Kozlowski
2 siblings, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-24 9:48 UTC (permalink / raw)
To: Raj Aryan, Sebastian Reichel, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Casey Connolly, Liam Girdwood, Mark Brown
Cc: linux-pm, devicetree, linux-kernel, linux-arm-msm, Rakesh Kota
On 24/11/2026 10:15, Raj Aryan wrote:
> The PM4125 PMIC, used on the Qualcomm CQ2390 platform (cocos),
> integrates the SMBLite switch-mode battery charger IP. The existing
> qcom_smbx charger driver only supports the SMB2 charger IP found on
> PMI8998 and PM660, so PM4125 currently has no charger support at
> all.
>
> SMBLite is a reduced-feature variant of SMB2: it shares the same
> SPMI bus and overall driver model, but uses a different register base
> layout (five separate SPMI peripheral bases instead of a single base
> with fixed offsets), a different battery-overvoltage status
> register, SOC-based recharge instead of VBAT-based recharge, and a
> different JEITA configuration sequence.
>
> This series extends the existing qcom_smbx driver to support both chip
> types side by side, selecting the correct register bases and handling
> logic based on chip->type. This keeps a single driver and power-supply
> class device covering both SMB2 and SMBLite hardware.
>
Why do you have unexplained/unlinked dependencies here? Why dependencies
in the first place. Does it mean this is not reviewable?
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] dt-bindings: power: supply: Add qcom,pm4125-charger binding
2026-11-24 9:15 ` [PATCH 1/2] dt-bindings: power: supply: Add qcom,pm4125-charger binding Raj Aryan
2026-11-24 9:26 ` sashiko-bot
@ 2026-11-24 9:55 ` Krzysztof Kozlowski
1 sibling, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-24 9:55 UTC (permalink / raw)
To: Raj Aryan, Sebastian Reichel, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Casey Connolly, Liam Girdwood, Mark Brown
Cc: linux-pm, devicetree, linux-kernel, linux-arm-msm, Rakesh Kota
On 24/11/2026 10:15, Raj Aryan wrote:
> Add YAML devicetree binding for the Qualcomm SMBLite switch-mode
YAML devicetree binding, you hit combo... Drop YAML.
A nit, subject: drop second/last, redundant "bindings". The
"dt-bindings" prefix is already stating that these are bindings.
See also:
https://elixir.bootlin.com/linux/v7.1-rc7/source/Documentation/devicetree/bindings/submitting-patches.rst#L23
> battery charger found on the PM4125 PMIC.
>
> SMBLite is a reduced-feature charger IP sharing a common SPMI
> interface with the SMB2 family (PMI8998, PM660) but using separate
> SPMI peripheral bases for CHGR, DCDC, USB, MISC and BATIF blocks.
>
> The binding covers:
Do not explain what the patch is doing. We can read the diff. Please
read submitting patches or look at other commits to learn what is
supposed to be here.
>
> - compatible string: qcom,pm4125-charger
> - reg property for the CHGR peripheral base address
> - Four interrupts: usb-plugin, bat-ov, wdog-bark and
> usbin-icl-change
> - Two IIO channels: usbin_v (USB input voltage via ADC5_USB_IN_V_16)
> and usbin_i (USB input current via ADC5_USB_IN_I)
> - Optional JEITA soft and hard threshold configuration as raw
> 16-bit ADC comparator values written to BATIF ADC comparator
> registers
> - Optional monitored-battery phandle for battery parameters such
> as float voltage and charge termination current
...
> +
> +maintainers:
> + - Raj Aryan <raj.aryan@oss.qualcomm.com>
> + - Rakesh Kota <rakesh.kota@oss.qualcomm.com>
> +
> +description: |
> + The Qualcomm SMBLite is a switch-mode battery charger IP found on
> + the entry-level Qualcomm PM4125 PMIC. It exposes five separate
> + SPMI peripheral bases for CHGR, DCDC, USB, MISC and BATIF blocks and
> + supports USB input current limiting, JEITA temperature protection,
> + battery overvoltage detection and a hardware watchdog.
> +
> +properties:
> + compatible:
> + const: qcom,pm4125-charger
> +
> + reg:
> + maxItems: 1
> + description: Base address of the CHGR SPMI peripheral (e.g. 0x1000).
Drop description.
> +
> + interrupts:
> + maxItems: 4
> +
> + interrupt-names:
> + items:
> + - const: usb-plugin
> + - const: bat-ov
> + - const: wdog-bark
> + - const: usbin-icl-change
> +
> + io-channels:
> + minItems: 1
> + maxItems: 2
Why is this flexible?
> + description: |
> + IIO ADC channels used by the charger. usbin_v is the USB input
> + voltage channel (ADC5_USB_IN_V_16). usbin_i is the USB input
> + current channel (ADC5_USB_IN_I).
> +
> + io-channel-names:
> + minItems: 1
> + items:
> + - const: usbin_v
> + - const: usbin_i
> +
> + monitored-battery: true
> +
> + qcom,jeita-soft-thresholds:
> + $ref: /schemas/types.yaml#/definitions/uint32-array
> + minItems: 2
> + maxItems: 2
> + description: |
> + JEITA soft temperature thresholds (COOL, WARM) as raw 16-bit ADC
> + comparator values written to the BATIF ADC comparator registers.
> + Example: <0x5314 0x25e3> for COOL=15°C, WARM=45°C.
> +
> + qcom,jeita-hard-thresholds:
> + $ref: /schemas/types.yaml#/definitions/uint32-array
> + minItems: 2
> + maxItems: 2
> + description: |
> + JEITA hard temperature thresholds (COLD, HOT) as raw 16-bit ADC
> + comparator values written to the BATIF ADC comparator registers.
> + Example: <0x58cd 0x20b8> for COLD=0°C, HOT=60°C.
Express temperatures with proper units.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-24 9:56 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 9:15 [PATCH 0/2] arm64: qcom: Add SMBLite charger support for PM4125 Raj Aryan
2026-11-24 9:15 ` [PATCH 1/2] dt-bindings: power: supply: Add qcom,pm4125-charger binding Raj Aryan
2026-11-24 9:26 ` sashiko-bot
2026-11-24 9:55 ` Krzysztof Kozlowski
2026-11-24 9:15 ` [PATCH 2/2] power: supply: qcom_smbx: Add SMBLite charger support Raj Aryan
2026-11-24 9:32 ` sashiko-bot
2026-11-24 9:48 ` [PATCH 0/2] arm64: qcom: Add SMBLite charger support for PM4125 Krzysztof Kozlowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox