usb: typec: ucsi: add support for separate DP altmode devices
Subsystems (2)
PATCH v4 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 v3->v4
- Fix typo CONNETOR -> CONNECTOR
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_CONNECTOR_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
Heikki Krogerus
maintainerQuoted 6 lines · Ajay Gupta
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.
Quoted 7 lines
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.
This patch has still some stylistic issues (like the comments: please use the same style that was used previously in the driver), but besides those, I'm still not sure I understand why couldn't we isolate the solution to ucsi_ccg.c. I have to take a better look at this next week.
I'm sorry this takes so long.
Br,
Signature · 1 line
heikki
Hi Heikki,
Quoted 12 lines
Quoted 11 lines
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.
Quoted 2 lines
This patch has still some stylistic issues (like the comments: please use the same style that was used previously in the driver),
Ok, I will fix them in v5.
Quoted 2 lines
but besides those, I'm still not sure I understand why couldn't we isolate the solution to
ucsi_ccg.c.
Please check my comments at [1] explaining why it can't be isolated to ucsi_ccg.c.
[1] https://marc.info/?l=linux-usb&m=156625373324903&w=2
Thanks
Quoted 9 lines
nvpublic
I have to take a better look at this next week.I'm sorry this takes so long.
Br,
--
heikki