Skip to content

Commit 83cbc69

Browse files
Prashant MalaniEnric Balletbo i Serra
authored andcommitted
platform/chrome: cros_ec_typec: Use workqueue for port update
Use a work queue to call the port update routines, instead of doing it directly in the PD notifier callback. This will prevent other drivers with PD notifier callbacks from being blocked on the port update routine completing. Signed-off-by: Prashant Malani <pmalani@chromium.org> Reviewed-by: Guenter Roeck <groeck@chromium.org> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
1 parent bdc4094 commit 83cbc69

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct cros_typec_data {
5858
/* Array of ports, indexed by port number. */
5959
struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS];
6060
struct notifier_block nb;
61+
struct work_struct port_work;
6162
};
6263

6364
static int cros_typec_parse_port_props(struct typec_capability *cap,
@@ -619,18 +620,24 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
619620
return 0;
620621
}
621622

622-
static int cros_ec_typec_event(struct notifier_block *nb,
623-
unsigned long host_event, void *_notify)
623+
static void cros_typec_port_work(struct work_struct *work)
624624
{
625-
struct cros_typec_data *typec = container_of(nb, struct cros_typec_data,
626-
nb);
625+
struct cros_typec_data *typec = container_of(work, struct cros_typec_data, port_work);
627626
int ret, i;
628627

629628
for (i = 0; i < typec->num_ports; i++) {
630629
ret = cros_typec_port_update(typec, i);
631630
if (ret < 0)
632631
dev_warn(typec->dev, "Update failed for port: %d\n", i);
633632
}
633+
}
634+
635+
static int cros_ec_typec_event(struct notifier_block *nb,
636+
unsigned long host_event, void *_notify)
637+
{
638+
struct cros_typec_data *typec = container_of(nb, struct cros_typec_data, nb);
639+
640+
schedule_work(&typec->port_work);
634641

635642
return NOTIFY_OK;
636643
}
@@ -689,6 +696,12 @@ static int cros_typec_probe(struct platform_device *pdev)
689696
if (ret < 0)
690697
return ret;
691698

699+
INIT_WORK(&typec->port_work, cros_typec_port_work);
700+
701+
/*
702+
* Safe to call port update here, since we haven't registered the
703+
* PD notifier yet.
704+
*/
692705
for (i = 0; i < typec->num_ports; i++) {
693706
ret = cros_typec_port_update(typec, i);
694707
if (ret < 0)

0 commit comments

Comments
 (0)