usb: typec: ucsi: add support for separate DP altmode devices
Subsystems (2)
PATCH v3 1/1 usb: typec: ucsi: add support for separate DP altmode devices
From: 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.
---
Original discussion on this issue is at [1]
Change from v2->v3
- Fix review comments from Heikki
- Moved the function to squash altmode table to ucsi_ccg.c
- Moved updates to UCSI_SET_NEW_CAM and UCSI_GET_CURRENT_CAM to ucsi_ccg.c
- Modified ucsi.c to collect all the altmode first and then register
1. https://marc.info/?l=linux-usb&m=154905866830998&w=2
drivers/usb/typec/ucsi/ucsi.c | 66 +++++++++-- drivers/usb/typec/ucsi/ucsi.h | 8 ++ drivers/usb/typec/ucsi/ucsi_ccg.c | 178 +++++++++++++++++++++++++++++- 3 files changed, 239 insertions(+), 13 deletions(-)
drivers/usb/typec/ucsi/ucsi.c +54 -12
@@ -346,12 +346,17 @@ static int ucsi_register_altmodes(struct ucsi_connector *con, u8 recipient)int max_altmodes =UCSI_MAX_ALTMODES ;struct typec_altmode_desc desc;struct ucsi_altmode alt[2 ]; +struct ucsi_altmode orig[UCSI_MAX_ALTMODES ]; +struct ucsi_altmode updated[UCSI_MAX_ALTMODES ]; +struct ucsi *ucsi = con->ucsi; +bool multi_dp = false;struct ucsi_control ctrl;int num =1 ;int ret;int len;int j;int i; +int k =0 ;if (!(con->ucsi->cap.features &UCSI_CAP_ALT_MODE_DETAILS ))return 0 ;
@@ -362,35 +367,72 @@ static int ucsi_register_altmodes(struct ucsi_connector *con, u8 recipient)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;) {memset (alt,0 ,sizeof (alt));UCSI_CMD_GET_ALTERNATE_MODES (ctrl, recipient, con->num, i,1 ); len =ucsi_run_command (con->ucsi, &ctrl, alt,sizeof (alt)); -if (len <=0 ) +/* 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) +break ; +/* * This code is requesting one alt mode at a time, but some PPMs * may still return two. If that happens both alt modes need be -* registered and the offset for the next alt mode has to be +* saved and the offset for the next alt mode has to be * incremented. */ num = len /sizeof (alt[0 ]); i += num;for (j =0 ; j < num; j++) { -if (!alt[j].svid) -return 0 ; - -memset (&desc,0 ,sizeof (desc)); - desc.vdo = alt[j].mid; - desc.svid = alt[j].svid; - desc.roles =TYPEC_PORT_DRD ; +if (!alt[j].svid) { +/* break out of outer loop and register */ + i = max_altmodes; +break ; + } + + orig[k].mid = alt[j].mid; + orig[k].svid = alt[j].svid; + k++; + } + } - ret =ucsi_register_altmode (con, &desc, recipient); -if (ret) -return ret; +/* Update the original altmode table as some ppms may report +* multiple DP altmodes. +*/ +if (recipient ==UCSI_RECIPIENT_CON && ucsi->ppm && + ucsi->ppm->update_altmodes) + multi_dp = ucsi->ppm->update_altmodes (ucsi->ppm, 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 ;
drivers/usb/typec/ucsi/ucsi.h +8 -0
@@ -231,6 +231,11 @@ struct ucsi_control {#define UCSI_ERROR_DEAD_BATTERY BIT(5)#define UCSI_ERROR_CONTRACT_NEGOTIATION_FAIL BIT(6) +#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_CONNETOR_MASK (0x7)/* Data structure filled by PPM in response to GET_CAPABILITY command. */ struct ucsi_capability {u32 attributes;
@@ -363,11 +368,14 @@ struct ucsi_data {* @data: memory location to the UCSI data structures * @cmd: UCSI command execution routine * @sync: Refresh UCSI mailbox (the data structures) +* @update_altmodes: Squashes duplicate DP altmodes */ struct ucsi_ppm {struct ucsi_data *data;int (*cmd)(struct ucsi_ppm *,struct ucsi_control *);int (*sync)(struct ucsi_ppm *); +bool (*update_altmodes)(struct ucsi_ppm *ppm,struct ucsi_altmode *orig, +struct ucsi_altmode *updated); };struct ucsi *ucsi_register_ppm (struct device *dev,struct ucsi_ppm *ppm);
drivers/usb/typec/ucsi/ucsi_ccg.c +177 -1
222 lines not on this page · raw message
Signature · 1 line
2.17.1