Commit f2437e48 authored by Jon Flatley's avatar Jon Flatley Committed by Benson Leung

power: supply: cros-ec-usbpd-charger: Fix host events

There's a bug on ACPI platforms where host events from the ECPD ACPI
device never make their way to the cros-ec-usbpd-charger driver. This
makes it so the only time the charger driver updates its state is when
user space accesses its sysfs attributes.

Now that these events have been unified into a single notifier chain on
both ACPI and non-ACPI platforms, update the charger driver to use this
new notifier.
Reviewed-by: default avatarBenson Leung <bleung@chromium.org>
Co-Developed-by: default avatarPrashant Malani <pmalani@chromium.org>
Signed-off-by: default avatarJon Flatley <jflat@chromium.org>
Signed-off-by: default avatarPrashant Malani <pmalani@chromium.org>
Reviewed-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: default avatarBenson Leung <bleung@chromium.org>
parent ec2daf6e
...@@ -659,7 +659,7 @@ config CHARGER_RT9455 ...@@ -659,7 +659,7 @@ config CHARGER_RT9455
config CHARGER_CROS_USBPD config CHARGER_CROS_USBPD
tristate "ChromeOS EC based USBPD charger" tristate "ChromeOS EC based USBPD charger"
depends on CROS_EC depends on CROS_USBPD_NOTIFY
default n default n
help help
Say Y here to enable ChromeOS EC based USBPD charger Say Y here to enable ChromeOS EC based USBPD charger
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_data/cros_ec_commands.h> #include <linux/platform_data/cros_ec_commands.h>
#include <linux/platform_data/cros_ec_proto.h> #include <linux/platform_data/cros_ec_proto.h>
#include <linux/platform_data/cros_usbpd_notify.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/power_supply.h> #include <linux/power_supply.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -517,32 +518,21 @@ static int cros_usbpd_charger_property_is_writeable(struct power_supply *psy, ...@@ -517,32 +518,21 @@ static int cros_usbpd_charger_property_is_writeable(struct power_supply *psy,
} }
static int cros_usbpd_charger_ec_event(struct notifier_block *nb, static int cros_usbpd_charger_ec_event(struct notifier_block *nb,
unsigned long queued_during_suspend, unsigned long host_event,
void *_notify) void *_notify)
{ {
struct cros_ec_device *ec_device; struct charger_data *charger = container_of(nb, struct charger_data,
struct charger_data *charger; notifier);
u32 host_event;
charger = container_of(nb, struct charger_data, notifier); cros_usbpd_charger_power_changed(charger->ports[0]->psy);
ec_device = charger->ec_device; return NOTIFY_OK;
host_event = cros_ec_get_host_event(ec_device);
if (host_event & EC_HOST_EVENT_MASK(EC_HOST_EVENT_PD_MCU)) {
cros_usbpd_charger_power_changed(charger->ports[0]->psy);
return NOTIFY_OK;
} else {
return NOTIFY_DONE;
}
} }
static void cros_usbpd_charger_unregister_notifier(void *data) static void cros_usbpd_charger_unregister_notifier(void *data)
{ {
struct charger_data *charger = data; struct charger_data *charger = data;
struct cros_ec_device *ec_device = charger->ec_device;
blocking_notifier_chain_unregister(&ec_device->event_notifier, cros_usbpd_unregister_notify(&charger->notifier);
&charger->notifier);
} }
static int cros_usbpd_charger_probe(struct platform_device *pd) static int cros_usbpd_charger_probe(struct platform_device *pd)
...@@ -676,21 +666,17 @@ static int cros_usbpd_charger_probe(struct platform_device *pd) ...@@ -676,21 +666,17 @@ static int cros_usbpd_charger_probe(struct platform_device *pd)
goto fail; goto fail;
} }
if (ec_device->mkbp_event_supported) { /* Get PD events from the EC */
/* Get PD events from the EC */ charger->notifier.notifier_call = cros_usbpd_charger_ec_event;
charger->notifier.notifier_call = cros_usbpd_charger_ec_event; ret = cros_usbpd_register_notify(&charger->notifier);
ret = blocking_notifier_chain_register( if (ret < 0) {
&ec_device->event_notifier, dev_warn(dev, "failed to register notifier\n");
&charger->notifier); } else {
if (ret < 0) { ret = devm_add_action_or_reset(dev,
dev_warn(dev, "failed to register notifier\n"); cros_usbpd_charger_unregister_notifier,
} else { charger);
ret = devm_add_action_or_reset(dev, if (ret < 0)
cros_usbpd_charger_unregister_notifier, goto fail;
charger);
if (ret < 0)
goto fail;
}
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment