Skip to content

Commit 7110f5f

Browse files
Prashant MalaniEnric Balletbo i Serra
authored andcommitted
platform/chrome: cros_ec_typec: Use notifier for updates
Register a listener for the cros-usbpd-notifier, and update port state when a notification comes in. Signed-off-by: Prashant Malani <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Signed-off-by: Enric Balletbo i Serra <[email protected]>
1 parent cf96e28 commit 7110f5f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

drivers/platform/chrome/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ config CROS_EC_SYSFS
217217
config CROS_EC_TYPEC
218218
tristate "ChromeOS EC Type-C Connector Control"
219219
depends on MFD_CROS_EC_DEV && TYPEC
220+
depends on CROS_USBPD_NOTIFY
220221
default MFD_CROS_EC_DEV
221222
help
222223
If you say Y here, you get support for accessing Type C connector

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/of.h>
1212
#include <linux/platform_data/cros_ec_commands.h>
1313
#include <linux/platform_data/cros_ec_proto.h>
14+
#include <linux/platform_data/cros_usbpd_notify.h>
1415
#include <linux/platform_device.h>
1516
#include <linux/usb/typec.h>
1617

@@ -26,6 +27,7 @@ struct cros_typec_data {
2627
struct typec_port *ports[EC_USB_PD_MAX_PORTS];
2728
/* Initial capabilities for each port. */
2829
struct typec_capability *caps[EC_USB_PD_MAX_PORTS];
30+
struct notifier_block nb;
2931
};
3032

3133
static int cros_typec_parse_port_props(struct typec_capability *cap,
@@ -272,6 +274,22 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
272274
return 0;
273275
}
274276

277+
static int cros_ec_typec_event(struct notifier_block *nb,
278+
unsigned long host_event, void *_notify)
279+
{
280+
struct cros_typec_data *typec = container_of(nb, struct cros_typec_data,
281+
nb);
282+
int ret, i;
283+
284+
for (i = 0; i < typec->num_ports; i++) {
285+
ret = cros_typec_port_update(typec, i);
286+
if (ret < 0)
287+
dev_warn(typec->dev, "Update failed for port: %d\n", i);
288+
}
289+
290+
return NOTIFY_OK;
291+
}
292+
275293
#ifdef CONFIG_ACPI
276294
static const struct acpi_device_id cros_typec_acpi_id[] = {
277295
{ "GOOG0014", 0 },
@@ -332,6 +350,11 @@ static int cros_typec_probe(struct platform_device *pdev)
332350
goto unregister_ports;
333351
}
334352

353+
typec->nb.notifier_call = cros_ec_typec_event;
354+
ret = cros_usbpd_register_notify(&typec->nb);
355+
if (ret < 0)
356+
goto unregister_ports;
357+
335358
return 0;
336359

337360
unregister_ports:

0 commit comments

Comments
 (0)