Skip to contentSkip to conversation

usb: typec: ucsi: Preliminary support for alternate modes

PATCH New Heikki Krogerus 1 participant 1 message Feb 6, 2019 USB

lore
Share & tools
lore
#0 lore raw

PATCH 4/5 usb: typec: ucsi: Preliminary support for alternate modes

Hi Ajay,

Quoted 46 lines · Ajay Gupta
Quoted 19 lines
(quoted diff) +19 -0
+static int ucsi_register_altmode(struct ucsi_connector *con,
+				 struct typec_altmode_desc *desc,
+				 u8 recipient)
+{
+	struct typec_altmode *alt;
+	int ret;
+	int i;
+
+	switch (recipient) {
+	case UCSI_RECIPIENT_CON:
+		i = ucsi_next_altmode(con->port_altmode);
+		if (i < 0) {
+			ret = i;
+			goto err;
+		}
+
+		desc->mode = ucsi_altmode_next_mode(con->port_altmode,
+						    desc->svid);
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+		alt = typec_port_register_altmode(con->port, desc);
+		if (IS_ERR(alt)) {
+			ret = PTR_ERR(alt);
+			goto err;
+		}
+
+		con->port_altmode[i] = alt;
+		break;
+	case UCSI_RECIPIENT_SOP:
+		i = ucsi_next_altmode(con->partner_altmode);

We are seeing duplicate partner altmode devices getting created when we set "active" file from 1->0->1 Please add a check here to see if altmode device already exists.

[...]

        case UCSI_RECIPIENT_SOP:
                /* check to see if partner altmode already exists */
                if (ucsi_altmode_found(con->partner_altmode, desc))
                        break;

                i = ucsi_next_altmode(con->partner_altmode);
	 if (i < 0) {

[...]

static bool ucsi_altmode_found(struct typec_altmode **alt,
struct typec_altmode_desc *desc)

Quoted 12 lines
{
        int i;

        for (i = 0; i < UCSI_MAX_ALTMODES; i++) {
                if (!alt[i])
                        return false;
                if (alt[i]->svid == desc->svid && alt[i]->vdo == desc->vdo)
                        return true;
        }

        return false;
}

OK. I'll prepare new version later this week.

thanks,