diff options
author | Steve Pfetsch <spfetsch@google.com> | 2023-03-11 01:05:51 +0000 |
---|---|---|
committer | Mark Chang <changmark@google.com> | 2023-03-21 02:44:20 +0000 |
commit | 9952de196e851455c075c080bc0310887d645689 (patch) | |
tree | 45538e951c6d4c3ccec2e8f9eb02712db359bbcd | |
parent | dccc8201e4499fc2478428d3f0138636e4af8298 (diff) | |
download | common-9952de196e851455c075c080bc0310887d645689.tar.gz |
goog_touch_interface: Add power supply status
Subscribe GTI to update notifications from the power_supply interface.
Updates are filtered to identify when the USB power supply is attached
as it significantly increases the phone's grounding relative to the
touch sensor. The charger status is routed out through touch_offload
driver status.
Bug: 265278190
Change-Id: I019f45f69bddfc2771df2eff71155e8d0bd857d2
Signed-off-by: Steve Pfetsch <spfetsch@google.com>
-rw-r--r-- | goog_touch_interface.c | 45 | ||||
-rw-r--r-- | goog_touch_interface.h | 5 |
2 files changed, 50 insertions, 0 deletions
diff --git a/goog_touch_interface.c b/goog_touch_interface.c index 9f326f8..4cc7e1f 100644 --- a/goog_touch_interface.c +++ b/goog_touch_interface.c @@ -8,6 +8,7 @@ #include <linux/module.h> #include <linux/input/mt.h> #include <linux/of.h> +#include <linux/power_supply.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> #include <samsung/exynos_drm_connector.h> @@ -1786,6 +1787,7 @@ int goog_get_driver_status(struct goog_touch_interface *gti, driver_cmd->touch_report_rate = gti->report_rate_setting; driver_cmd->noise_state = gti->fw_status.noise_level; driver_cmd->water_mode = gti->fw_status.water_mode; + driver_cmd->charger_state = gti->charger_state; driver_cmd->offload_timestamp = ktime_get(); /* vendor driver overwrite the context */ @@ -1886,6 +1888,9 @@ static void goog_offload_populate_driver_status_channel( ds->contents.water_mode = driver_cmd->context_changed.water_mode; ds->water_mode = driver_cmd->water_mode; + ds->contents.charger_state = driver_cmd->context_changed.charger_state; + ds->charger_state = driver_cmd->charger_state; + ds->contents.offload_timestamp = driver_cmd->context_changed.offload_timestamp; ds->offload_timestamp = driver_cmd->offload_timestamp; } @@ -2203,6 +2208,38 @@ void goog_offload_input_report(void *handle, ATRACE_END(); } +int gti_charger_state_change(struct notifier_block *nb, unsigned long action, + void *data) +{ + struct goog_touch_interface *gti = + (struct goog_touch_interface *)container_of(nb, + struct goog_touch_interface, charger_notifier); + struct power_supply *psy = (struct power_supply *)data; + int ret; + + /* Attempt actual status parsing */ + if (psy && psy->desc->type == POWER_SUPPLY_TYPE_USB) { + union power_supply_propval present_val = { 0 }; + + ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_PRESENT, + &present_val); + if (ret < 0) + GOOG_ERR(gti, + "Error while getting power supply property: %d!\n", + ret); + else if ((u8)present_val.intval != gti->charger_state) { + /* Note: the expected values for present_val.intval are + * 0 and 1. Cast to unsigned byte to ensure the + * comparison is handled in the same variable data type. + */ + gti->context_changed.charger_state = 1; + gti->charger_state = (u8)present_val.intval; + } + } + + return 0; +} + int goog_offload_probe(struct goog_touch_interface *gti) { int ret; @@ -2351,6 +2388,14 @@ int goog_offload_probe(struct goog_touch_interface *gti) GOOG_INFO(gti, "v4l2 W/H=(%lu, %lu), v4l2_enabled=%d.\n", gti->v4l2.width, gti->v4l2.height, gti->v4l2_enabled); + /* Register for charger plugging status */ + gti->charger_notifier.notifier_call = gti_charger_state_change; + ret = power_supply_reg_notifier(>i->charger_notifier); + if (!ret) { + GOOG_ERR(gti, "Failed to register power_supply_reg_notifier!\n"); + goto err_offload_probe; + } + err_offload_probe: return ret; } diff --git a/goog_touch_interface.h b/goog_touch_interface.h index 0b0e2fb..9145538 100644 --- a/goog_touch_interface.h +++ b/goog_touch_interface.h @@ -600,6 +600,8 @@ struct gti_pm { * @slot_bit_changed: bitmap of slot state changed for this input process cycle. * @slot_bit_active: bitmap of active slot during GTI lifecycle. * @dev_id: dev_t used for google interface driver. + * @charger_state: indicates a USB charger is connected. + * @charger_notifier: notifier for power_supply updates. * @irq_index: irq count that handle by GTI. * @input_index: the count of slot bit changed during goog_input_process(). * @vendor_irq_handler: irq handler that register by vendor driver. @@ -681,6 +683,9 @@ struct goog_touch_interface { unsigned long slot_bit_active; dev_t dev_id; + u8 charger_state; + struct notifier_block charger_notifier; + u64 irq_index; u64 input_index; irq_handler_t vendor_irq_handler; |