diff --git a/drivers/power/supply/qti_battery_charger.c b/drivers/power/supply/qti_battery_charger.c index 7dcc541e9bfc..fe08fb38ba10 100644 --- a/drivers/power/supply/qti_battery_charger.c +++ b/drivers/power/supply/qti_battery_charger.c @@ -44,6 +44,7 @@ #define BC_WLS_FW_PUSH_BUF_RESP 0x43 #define BC_WLS_FW_GET_VERSION 0x44 #define BC_SHUTDOWN_NOTIFY 0x47 +#define BC_HBOOST_VMAX_CLAMP_NOTIFY 0x79 #define BC_GENERIC_NOTIFY 0x80 /* Generic definitions */ @@ -310,6 +311,20 @@ static const char * const qc_power_supply_usb_type_text[] = { "HVDCP", "HVDCP_3", "HVDCP_3P5" }; +static RAW_NOTIFIER_HEAD(hboost_notifier); + +int register_hboost_event_notifier(struct notifier_block *nb) +{ + return raw_notifier_chain_register(&hboost_notifier, nb); +} +EXPORT_SYMBOL(register_hboost_event_notifier); + +int unregister_hboost_event_notifier(struct notifier_block *nb) +{ + return raw_notifier_chain_unregister(&hboost_notifier, nb); +} +EXPORT_SYMBOL(unregister_hboost_event_notifier); + static int battery_chg_fw_write(struct battery_chg_dev *bcdev, void *data, int len) { @@ -774,15 +789,23 @@ static void handle_notification(struct battery_chg_dev *bcdev, void *data, { struct battery_charger_notify_msg *notify_msg = data; struct psy_state *pst = NULL; + u32 hboost_vmax_mv, notification; if (len != sizeof(*notify_msg)) { pr_err("Incorrect response length %zu\n", len); return; } - pr_debug("notification: %#x\n", notify_msg->notification); + notification = notify_msg->notification; + pr_debug("notification: %#x\n", notification); + if ((notification & 0xffff) == BC_HBOOST_VMAX_CLAMP_NOTIFY) { + hboost_vmax_mv = (notification >> 16) & 0xffff; + raw_notifier_call_chain(&hboost_notifier, VMAX_CLAMP, &hboost_vmax_mv); + pr_debug("hBoost is clamped at %u mV\n", hboost_vmax_mv); + return; + } - switch (notify_msg->notification) { + switch (notification) { case BC_BATTERY_STATUS_GET: case BC_GENERIC_NOTIFY: pst = &bcdev->psy_list[PSY_TYPE_BATTERY]; diff --git a/include/linux/soc/qcom/battery_charger.h b/include/linux/soc/qcom/battery_charger.h index 67660c72acec..47382d8e0d34 100644 --- a/include/linux/soc/qcom/battery_charger.h +++ b/include/linux/soc/qcom/battery_charger.h @@ -1,19 +1,28 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* * Copyright (c) 2020, The Linux Foundation. All rights reserved. + * Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved. */ #ifndef _BATTERY_CHARGER_H #define _BATTERY_CHARGER_H +#include + enum battery_charger_prop { BATTERY_RESISTANCE, BATTERY_CHARGER_PROP_MAX, }; +enum bc_hboost_event { + VMAX_CLAMP, +}; + #if IS_ENABLED(CONFIG_QTI_BATTERY_CHARGER) int qti_battery_charger_get_prop(const char *name, enum battery_charger_prop prop_id, int *val); +int register_hboost_event_notifier(struct notifier_block *nb); +int unregister_hboost_event_notifier(struct notifier_block *nb); #else static inline int qti_battery_charger_get_prop(const char *name, @@ -21,6 +30,16 @@ qti_battery_charger_get_prop(const char *name, { return -EINVAL; } + +static inline int register_hboost_event_notifier(struct notifier_block *nb) +{ + return -EOPNOTSUPP; +} + +static inline int unregister_hboost_event_notifier(struct notifier_block *nb) +{ + return -EOPNOTSUPP; +} #endif #endif