usb: typec: ucsi driver changes
Subsystems (2)
Heikki Krogerus
maintainercover usb: typec: ucsi driver changes
Hi,
I'm sending these two patches separately (instead of together with other USB Type-C patches). They only affect the UCSI drivers.
The first filters out bogus Connector Change Notifications (interrupts) on some platforms, and the second makes sure the DisplayPort alternate mode is exposed and handled properly with GPU cards from NVIDIA.
thanks,
Ajay Gupta (1):
usb: typec: ucsi: add support for separate DP altmode devices
Heikki Krogerus (1):
usb: typec: ucsi: Store the notification mask
drivers/usb/typec/ucsi/ucsi.c | 94 ++++++++++++++- drivers/usb/typec/ucsi/ucsi.h | 14 +++ drivers/usb/typec/ucsi/ucsi_ccg.c | 191 +++++++++++++++++++++++++++++- 3 files changed, 292 insertions(+), 7 deletions(-)
Signature · 1 line
2.24.1
Heikki Krogerus
maintainerPATCH 1/2 usb: typec: ucsi: Store the notification mask
The driver needs to ignore any Connector Change Events before the Connector Change Indication notifications have actually been enabled. This adds a check to ucsi_connector_change() function to make sure the function does not try to process the event unless the Connector Change notifications have been enabled.
It is quite common that the firmware representing the "PPM" (Platform Policy Manager) starts generating Connector Change notifications even when only the Command Completion notifications are enabled.
--- drivers/usb/typec/ucsi/ucsi.c | 15 ++++++++++----- drivers/usb/typec/ucsi/ucsi.h | 3 +++ 2 files changed, 13 insertions(+), 5 deletions(-)
drivers/usb/typec/ucsi/ucsi.c +10 -5
@@ -189,7 +189,7 @@ int ucsi_resume(struct ucsi *ucsi)u64 command;/* Restore UCSI notification enable mask after system resume */ - command =UCSI_SET_NOTIFICATION_ENABLE |UCSI_ENABLE_NTFY_ALL ; + command =UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy;return ucsi_send_command (ucsi, command,NULL ,0 ); }
@@ -589,6 +589,11 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num) {struct ucsi_connector *con = &ucsi->connector[num -1 ]; +if (!(ucsi->ntfy &UCSI_ENABLE_NTFY_CONNECTOR_CHANGE )) { +dev_dbg (ucsi->dev,"Bogus connetor change event\n" ); +return ; + } +if (!test_and_set_bit (EVENT_PENDING , &ucsi->flags))schedule_work (&con->work); }
@@ -656,7 +661,7 @@ static int ucsi_role_cmd(struct ucsi_connector *con, u64 command)ucsi_reset_ppm (con->ucsi);mutex_unlock (&con->ucsi->ppm_lock); - c =UCSI_SET_NOTIFICATION_ENABLE |UCSI_ENABLE_NTFY_ALL ; + c =UCSI_SET_NOTIFICATION_ENABLE | con->ucsi->ntfy;ucsi_send_command (con->ucsi, c,NULL ,0 );ucsi_reset_connector (con, true);
@@ -925,8 +930,8 @@ int ucsi_init(struct ucsi *ucsi) }/* Enable basic notifications */ - command =UCSI_SET_NOTIFICATION_ENABLE ; - command |=UCSI_ENABLE_NTFY_CMD_COMPLETE |UCSI_ENABLE_NTFY_ERROR ; + ucsi->ntfy =UCSI_ENABLE_NTFY_CMD_COMPLETE |UCSI_ENABLE_NTFY_ERROR ; + command =UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy; ret =ucsi_run_command (ucsi, command,NULL ,0 );if (ret <0 ) goto err_reset;
@@ -943,7 +948,7 @@ int ucsi_init(struct ucsi *ucsi) }/* Enable all notifications */ - command =UCSI_SET_NOTIFICATION_ENABLE |UCSI_ENABLE_NTFY_ALL ; + command =UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy; ret =ucsi_run_command (ucsi, command,NULL ,0 );if (ret <0 ) goto err_unregister;
drivers/usb/typec/ucsi/ucsi.h +3 -0
@@ -269,6 +269,9 @@ struct ucsi {/* PPM Communication lock */ struct mutex ppm_lock; +/* The latest "Notification Enable" bits (SET_NOTIFICATION_ENABLE) */ +u64 ntfy; +/* PPM communication flags */ unsigned long flags;#define EVENT_PENDING 0
Signature · 1 line
2.24.1
Heikki Krogerus
maintainerPATCH 2/2 usb: typec: ucsi: add support for separate DP altmode devices
In reply to Heikki KrogerusFrom: Ajay Gupta <[email protected]>
CCGx controller used on NVIDIA GPU card has two separate display altmode for two DP pin assignments. UCSI specification doesn't prohibits using separate display altmode.
Current UCSI Type-C framework expects only one display altmode for all DP pin assignment. This patch squashes two separate display altmode into single altmode to support controllers with separate display altmode. We first read all the alternate modes of connector and then run through it to know if there are separate display altmodes. If so, it prepares a new port altmode set after squashing two or more separate altmodes into one.
--- drivers/usb/typec/ucsi/ucsi.c | 79 ++++++++++++ drivers/usb/typec/ucsi/ucsi.h | 11 ++ drivers/usb/typec/ucsi/ucsi_ccg.c | 191 +++++++++++++++++++++++++++++- 3 files changed, 279 insertions(+), 2 deletions(-)
drivers/usb/typec/ucsi/ucsi.c +79 -0
@@ -318,6 +318,82 @@ static int ucsi_register_altmode(struct ucsi_connector *con,return ret; } +static int +ucsi_register_altmodes_nvidia (struct ucsi_connector *con,u8 recipient) +{ +int max_altmodes =UCSI_MAX_ALTMODES ; +struct typec_altmode_desc desc; +struct ucsi_altmode alt; +struct ucsi_altmode orig[UCSI_MAX_ALTMODES ]; +struct ucsi_altmode updated[UCSI_MAX_ALTMODES ]; +struct ucsi *ucsi = con->ucsi; +bool multi_dp = false; +u64 command; +int ret; +int len; +int i; +int k =0 ; + +if (recipient ==UCSI_RECIPIENT_CON ) + max_altmodes = con->ucsi->cap.num_alt_modes; + +memset (orig,0 ,sizeof (orig)); +memset (updated,0 ,sizeof (updated)); + +/* First get all the alternate modes */ +for (i =0 ; i < max_altmodes; i++) { +memset (&alt,0 ,sizeof (alt)); + command =UCSI_GET_ALTERNATE_MODES ; + command |=UCSI_GET_ALTMODE_RECIPIENT (recipient); + command |=UCSI_GET_ALTMODE_CONNECTOR_NUMBER (con->num); + command |=UCSI_GET_ALTMODE_OFFSET (i); + len =ucsi_run_command (con->ucsi, command, &alt,sizeof (alt)); +/* +* We are collecting all altmodes first and then registering. +* Some type-C device will return zero length data beyond last +* alternate modes. We should not return if length is zero. +*/ +if (len <0 ) +return len; + +/* We got all altmodes, now break out and register them */ +if (!len || !alt.svid) +break ; + + orig[k].mid = alt.mid; + orig[k].svid = alt.svid; + k++; + } +/* +* Update the original altmode table as some ppms may report +* multiple DP altmodes. +*/ +if (recipient ==UCSI_RECIPIENT_CON ) + multi_dp = ucsi->ops->update_altmodes (ucsi, orig, updated); + +/* now register altmodes */ +for (i =0 ; i < max_altmodes; i++) { +memset (&desc,0 ,sizeof (desc)); +if (multi_dp && recipient ==UCSI_RECIPIENT_CON ) { + desc.svid = updated[i].svid; + desc.vdo = updated[i].mid; + }else { + desc.svid = orig[i].svid; + desc.vdo = orig[i].mid; + } + desc.roles =TYPEC_PORT_DRD ; + +if (!desc.svid) +return 0 ; + + ret =ucsi_register_altmode (con, &desc, recipient); +if (ret) +return ret; + } + +return 0 ; +} +static int ucsi_register_altmodes (struct ucsi_connector *con,u8 recipient) {int max_altmodes =UCSI_MAX_ALTMODES ;
@@ -336,6 +412,9 @@ static int ucsi_register_altmodes(struct ucsi_connector *con, u8 recipient)if (recipient ==UCSI_RECIPIENT_SOP && con->partner_altmode[0 ])return 0 ; +if (con->ucsi->ops->update_altmodes) +return ucsi_register_altmodes_nvidia (con, recipient); +if (recipient ==UCSI_RECIPIENT_CON ) max_altmodes = con->ucsi->cap.num_alt_modes;
drivers/usb/typec/ucsi/ucsi.h +11 -0
@@ -11,6 +11,7 @@/* -------------------------------------------------------------------------- */ struct ucsi ; +struct ucsi_altmode ;/* UCSI offsets (Bytes) */ #define UCSI_VERSION 0
@@ -35,6 +36,7 @@ struct ucsi;* @read: Read operation * @sync_write: Blocking write operation * @async_write: Non-blocking write operation +* @update_altmodes: Squashes duplicate DP altmodes * * 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
@@ -47,6 +49,8 @@ struct ucsi_operations { const void *val, size_t val_len);int (*async_write)(struct ucsi *ucsi,unsigned int offset,const void *val,size_t val_len); +bool (*update_altmodes)(struct ucsi *ucsi,struct ucsi_altmode *orig, +struct ucsi_altmode *updated); };struct ucsi *ucsi_create (struct device *dev,const struct ucsi_operations *ops);
@@ -82,6 +86,7 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num);#define UCSI_GET_ERROR_STATUS 0x13#define UCSI_CONNECTOR_NUMBER (_num_) ((u64)(_num_) << 16) +#define UCSI_COMMAND (_cmd_) ((_cmd_) & 0xff)/* CONNECTOR_RESET command bits */ #define UCSI_CONNECTOR_RESET_HARD BIT(23)/* Deprecated in v1.1 */
@@ -140,6 +145,12 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num);#define UCSI_ERROR_PPM_POLICY_CONFLICT BIT(11)#define UCSI_ERROR_SWAP_REJECTED BIT(12) +#define UCSI_SET_NEW_CAM_ENTER (x) (((x) >> 23) & 0x1) +#define UCSI_SET_NEW_CAM_GET_AM (x) (((x) >> 24) & 0xff) +#define UCSI_SET_NEW_CAM_AM_MASK (0xff << 24) +#define UCSI_SET_NEW_CAM_SET_AM (x) (((x) & 0xff) << 24) +#define UCSI_CMD_CONNECTOR_MASK (0x7) +/* Data structure filled by PPM in response to GET_CAPABILITY command. */ struct ucsi_capability {u32 attributes;
drivers/usb/typec/ucsi/ucsi_ccg.c +189 -2
238 lines not on this page · raw message
Signature · 1 line
2.24.1