Skip to content

Commit

Permalink
power: supply: surface_battery: Fix battery event handling
Browse files Browse the repository at this point in the history
[ Upstream commit e633f33 ]

The battery subsystem of the Surface Aggregator Module EC requires us to
register the battery notifier with instance ID 0. However, battery
events are actually sent with the instance ID corresponding to the
device, which is nonzero. Thus, the strict-matching approach doesn't
work here and will discard events that the driver is expected to handle.

To fix this we have to fall back on notifier matching by target-category
only and have to manually check the instance ID in the notifier
callback.

Fixes: 167f77f ("power: supply: Add battery driver for Surface Aggregator Module")
Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
qzed authored and gregkh committed Jul 20, 2021
1 parent 73a14f6 commit 0f0fd04
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions drivers/power/supply/surface_battery.c
Expand Up @@ -345,6 +345,16 @@ static u32 spwr_notify_bat(struct ssam_event_notifier *nf, const struct ssam_eve
struct spwr_battery_device *bat = container_of(nf, struct spwr_battery_device, notif);
int status;

/*
* We cannot use strict matching when registering the notifier as the
* EC expects us to register it against instance ID 0. Strict matching
* would thus drop events, as those may have non-zero instance IDs in
* this subsystem. So we need to check the instance ID of the event
* here manually.
*/
if (event->instance_id != bat->sdev->uid.instance)
return 0;

dev_dbg(&bat->sdev->dev, "power event (cid = %#04x, iid = %#04x, tid = %#04x)\n",
event->command_id, event->instance_id, event->target_id);

Expand Down Expand Up @@ -720,8 +730,8 @@ static void spwr_battery_init(struct spwr_battery_device *bat, struct ssam_devic
bat->notif.base.fn = spwr_notify_bat;
bat->notif.event.reg = registry;
bat->notif.event.id.target_category = sdev->uid.category;
bat->notif.event.id.instance = 0;
bat->notif.event.mask = SSAM_EVENT_MASK_STRICT;
bat->notif.event.id.instance = 0; /* need to register with instance 0 */
bat->notif.event.mask = SSAM_EVENT_MASK_TARGET;
bat->notif.event.flags = SSAM_EVENT_SEQUENCED;

bat->psy_desc.name = bat->name;
Expand Down

0 comments on commit 0f0fd04

Please sign in to comment.