power: supply: qti_battery_charger: handle hBoost VMAX_CLAMP notification

The haptics boost can be used to supply either USB or wireless sourcing
mode by the charger firmware, and it needs to notify haptics driver to
clamp the haptics Vmax settings accordingly. Handle the VMAX_CLAMP
notification from charger firmware and notify the haptics driver through
a notifier call.

Change-Id: If06fa8631d9f4dc264b729ccb9fbc7c154ad3f27
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
This commit is contained in:
Fenglin Wu 2022-01-13 12:55:30 +08:00 committed by Anjelique Melendez
parent 10413477c8
commit cdb44b2824
2 changed files with 44 additions and 2 deletions

View File

@ -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];

View File

@ -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 <linux/notifier.h>
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