Re: [PATCH v4 1/2] platform/chrome: cros_ec_typec: Configure Retimer cable type
From: Prashant Malani
Date: Fri Aug 18 2023 - 13:02:35 EST
Hi Utkarsh,
Sorry I was out on leave, so didnt get to this earlier.
On Jul 17 19:47, Utkarsh Patel wrote:
>
> +/**
> + * cros_typec_get_cable_vdo() - Get Cable VDO of the connected cable
> + * @port: Type-C port data
> + * @svid: Standard or Vendor ID to match
> + *
> + * Returns the Cable VDO if match is found and returns 0 if match is not found.
> + */
> +static int cros_typec_get_cable_vdo(struct cros_typec_port *port, u16 svid)
return type should be u32.
> +{
> + struct list_head *head = &port->plug_mode_list;
> + struct cros_typec_altmode_node *node;
> + u32 ret = 0;
> +
> + list_for_each_entry(node, head, list) {
> + if (node->amode->svid == svid)
> + return node->amode->vdo;
> + }
> +
> + return ret;
> +}
> +
> /*
> * Spoof the VDOs that were likely communicated by the partner for TBT alt
> * mode.
> @@ -432,6 +453,9 @@ static int cros_typec_enable_tbt(struct cros_typec_data *typec,
>
> /* Cable Discover Mode VDO */
> data.cable_mode = TBT_MODE;
> +
> + data.cable_mode |= cros_typec_get_cable_vdo(port, USB_TYPEC_TBT_SID);
> +
> data.cable_mode |= TBT_SET_CABLE_SPEED(pd_ctrl->cable_speed);
>
> if (pd_ctrl->control_flags & USB_PD_CTRL_OPTICAL_CABLE)
> @@ -522,8 +546,10 @@ static int cros_typec_enable_usb4(struct cros_typec_data *typec,
> /* Cable Type */
> if (pd_ctrl->control_flags & USB_PD_CTRL_OPTICAL_CABLE)
> data.eudo |= EUDO_CABLE_TYPE_OPTICAL << EUDO_CABLE_TYPE_SHIFT;
> - else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE)
> + else if (cros_typec_get_cable_vdo(port, USB_TYPEC_TBT_SID) & TBT_CABLE_RETIMER)
> data.eudo |= EUDO_CABLE_TYPE_RE_TIMER << EUDO_CABLE_TYPE_SHIFT;
We shouldn't need to call cros_typec_get_cable_vdo more than once. Either call it once earlier
when you are crafting the data.cable_mode member and then re-use that variable here. Or don't
call it there and just call it here.
> + else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE)
> + data.eudo |= EUDO_CABLE_TYPE_RE_DRIVER << EUDO_CABLE_TYPE_SHIFT;
>
> data.active_link_training = !!(pd_ctrl->control_flags &
> USB_PD_CTRL_ACTIVE_LINK_UNIDIR);
> --
> 2.25.1
>