Skip to content

Commit f2437e4

Browse files
Jon Flatleybleungatchromium
authored andcommitted
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: Benson Leung <[email protected]> Co-Developed-by: Prashant Malani <[email protected]> Signed-off-by: Jon Flatley <[email protected]> Signed-off-by: Prashant Malani <[email protected]> Reviewed-by: Sebastian Reichel <[email protected]> Signed-off-by: Benson Leung <[email protected]>
1 parent ec2daf6 commit f2437e4

File tree

2 files changed

+19
-33
lines changed

2 files changed

+19
-33
lines changed

drivers/power/supply/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ config CHARGER_RT9455
659659

660660
config CHARGER_CROS_USBPD
661661
tristate "ChromeOS EC based USBPD charger"
662-
depends on CROS_EC
662+
depends on CROS_USBPD_NOTIFY
663663
default n
664664
help
665665
Say Y here to enable ChromeOS EC based USBPD charger

drivers/power/supply/cros_usbpd-charger.c

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/module.h>
99
#include <linux/platform_data/cros_ec_commands.h>
1010
#include <linux/platform_data/cros_ec_proto.h>
11+
#include <linux/platform_data/cros_usbpd_notify.h>
1112
#include <linux/platform_device.h>
1213
#include <linux/power_supply.h>
1314
#include <linux/slab.h>
@@ -517,32 +518,21 @@ static int cros_usbpd_charger_property_is_writeable(struct power_supply *psy,
517518
}
518519

519520
static int cros_usbpd_charger_ec_event(struct notifier_block *nb,
520-
unsigned long queued_during_suspend,
521+
unsigned long host_event,
521522
void *_notify)
522523
{
523-
struct cros_ec_device *ec_device;
524-
struct charger_data *charger;
525-
u32 host_event;
524+
struct charger_data *charger = container_of(nb, struct charger_data,
525+
notifier);
526526

527-
charger = container_of(nb, struct charger_data, notifier);
528-
ec_device = charger->ec_device;
529-
530-
host_event = cros_ec_get_host_event(ec_device);
531-
if (host_event & EC_HOST_EVENT_MASK(EC_HOST_EVENT_PD_MCU)) {
532-
cros_usbpd_charger_power_changed(charger->ports[0]->psy);
533-
return NOTIFY_OK;
534-
} else {
535-
return NOTIFY_DONE;
536-
}
527+
cros_usbpd_charger_power_changed(charger->ports[0]->psy);
528+
return NOTIFY_OK;
537529
}
538530

539531
static void cros_usbpd_charger_unregister_notifier(void *data)
540532
{
541533
struct charger_data *charger = data;
542-
struct cros_ec_device *ec_device = charger->ec_device;
543534

544-
blocking_notifier_chain_unregister(&ec_device->event_notifier,
545-
&charger->notifier);
535+
cros_usbpd_unregister_notify(&charger->notifier);
546536
}
547537

548538
static int cros_usbpd_charger_probe(struct platform_device *pd)
@@ -676,21 +666,17 @@ static int cros_usbpd_charger_probe(struct platform_device *pd)
676666
goto fail;
677667
}
678668

679-
if (ec_device->mkbp_event_supported) {
680-
/* Get PD events from the EC */
681-
charger->notifier.notifier_call = cros_usbpd_charger_ec_event;
682-
ret = blocking_notifier_chain_register(
683-
&ec_device->event_notifier,
684-
&charger->notifier);
685-
if (ret < 0) {
686-
dev_warn(dev, "failed to register notifier\n");
687-
} else {
688-
ret = devm_add_action_or_reset(dev,
689-
cros_usbpd_charger_unregister_notifier,
690-
charger);
691-
if (ret < 0)
692-
goto fail;
693-
}
669+
/* Get PD events from the EC */
670+
charger->notifier.notifier_call = cros_usbpd_charger_ec_event;
671+
ret = cros_usbpd_register_notify(&charger->notifier);
672+
if (ret < 0) {
673+
dev_warn(dev, "failed to register notifier\n");
674+
} else {
675+
ret = devm_add_action_or_reset(dev,
676+
cros_usbpd_charger_unregister_notifier,
677+
charger);
678+
if (ret < 0)
679+
goto fail;
694680
}
695681

696682
return 0;

0 commit comments

Comments
 (0)