usb: typec: ucsi: add callback for connector status updates
authorDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Thu, 11 Apr 2024 04:49:53 +0000 (07:49 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 18 Apr 2024 14:47:23 +0000 (16:47 +0200)
Allow UCSI glue driver to perform addtional work to update connector
status. For example, it might check the cable orientation.  This call is
performed after reading new connector statatus, so the platform driver
can peek at new connection status bits.

The callback is called both when registering the port and when the
connector change event is being handled.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20240411-ucsi-orient-aware-v2-1-d4b1cb22a33f@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/ucsi/ucsi.c
drivers/usb/typec/ucsi/ucsi.h

index 36e1b191f87dce848b97e708a525d875de2f7151..4d8910992a574d708e77ee4e19814572d4154df7 100644 (file)
@@ -1199,6 +1199,9 @@ static void ucsi_handle_connector_change(struct work_struct *work)
 
        trace_ucsi_connector_change(con->num, &con->status);
 
+       if (ucsi->ops->connector_status)
+               ucsi->ops->connector_status(con);
+
        role = !!(con->status.flags & UCSI_CONSTAT_PWR_DIR);
 
        if (con->status.change & UCSI_CONSTAT_POWER_DIR_CHANGE) {
@@ -1590,6 +1593,9 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
        }
        ret = 0; /* ucsi_send_command() returns length on success */
 
+       if (ucsi->ops->connector_status)
+               ucsi->ops->connector_status(con);
+
        switch (UCSI_CONSTAT_PARTNER_TYPE(con->status.flags)) {
        case UCSI_CONSTAT_PARTNER_TYPE_UFP:
        case UCSI_CONSTAT_PARTNER_TYPE_CABLE_AND_UFP:
index 2caf2969668c7aec79d461cce41cab67246d630f..3e1241e38f3c43c57d99d76d641b28dda7bfac19 100644 (file)
@@ -16,6 +16,7 @@
 
 struct ucsi;
 struct ucsi_altmode;
+struct ucsi_connector;
 struct dentry;
 
 /* UCSI offsets (Bytes) */
@@ -59,6 +60,7 @@ struct dentry;
  * @sync_write: Blocking write operation
  * @async_write: Non-blocking write operation
  * @update_altmodes: Squashes duplicate DP altmodes
+ * @connector_status: Updates connector status, called holding connector lock
  *
  * Read and write routines for UCSI interface. @sync_write must wait for the
  * Command Completion Event from the PPM before returning, and @async_write must
@@ -73,6 +75,7 @@ struct ucsi_operations {
                           const void *val, size_t val_len);
        bool (*update_altmodes)(struct ucsi *ucsi, struct ucsi_altmode *orig,
                                struct ucsi_altmode *updated);
+       void (*connector_status)(struct ucsi_connector *con);
 };
 
 struct ucsi *ucsi_create(struct device *dev, const struct ucsi_operations *ops);