lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Yw8frAv2pMfjmE0U@kuha.fi.intel.com>
Date:   Wed, 31 Aug 2022 11:45:32 +0300
From:   Heikki Krogerus <heikki.krogerus@...ux.intel.com>
To:     Prashant Malani <pmalani@...omium.org>
Cc:     linux-kernel@...r.kernel.org, chrome-platform@...ts.linux.dev,
        bleung@...omium.org, Guenter Roeck <groeck@...omium.org>
Subject: Re: [PATCH] platform/chrome: cros_ec_typec: Register partner PDOs

On Tue, Aug 30, 2022 at 08:20:18PM +0000, Prashant Malani wrote:
> The ChromeOS EC exports partner source/sink cap PDOs (Power Data
> Objects) to the application processor (AP). Use this information
> to register USB PD (Power Delivery) capabilities with the
> USB Type-C Power Delivery device class.
> 
> Cc: Heikki Krogerus <heikki.krogerus@...ux.intel.com>
> Signed-off-by: Prashant Malani <pmalani@...omium.org>

This looks good to me. One nitpick below. With that fixed, FWIW:

Reviewed-by: Heikki Krogerus <heikki.krogerus@...ux.intel.com>

Will you later register also the port PDOs?

> ---
>  drivers/platform/chrome/cros_ec_typec.c | 56 +++++++++++++++++++++++++
>  1 file changed, 56 insertions(+)
> 
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 00208ffbe2e7..f84bf9659a0f 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -73,6 +73,11 @@ struct cros_typec_port {
>  	struct ec_response_typec_discovery *disc_data;
>  	struct list_head partner_mode_list;
>  	struct list_head plug_mode_list;
> +
> +	/* PDO-related structs */
> +	struct usb_power_delivery *partner_pd;
> +	struct usb_power_delivery_capabilities *partner_src_caps;
> +	struct usb_power_delivery_capabilities *partner_sink_caps;
>  };
>  
>  /* Platform-specific data for the Chrome OS EC Type C controller. */
> @@ -253,6 +258,14 @@ static void cros_typec_remove_partner(struct cros_typec_data *typec,
>  
>  	cros_typec_unregister_altmodes(typec, port_num, true);
>  
> +	typec_partner_set_usb_power_delivery(port->partner, NULL);
> +	usb_power_delivery_unregister_capabilities(port->partner_sink_caps);
> +	port->partner_sink_caps = NULL;
> +	usb_power_delivery_unregister_capabilities(port->partner_src_caps);
> +	port->partner_src_caps = NULL;
> +	usb_power_delivery_unregister(port->partner_pd);
> +	port->partner_pd = NULL;
> +
>  	cros_typec_usb_disconnect_state(port);
>  	port->mux_flags = USB_PD_MUX_NONE;
>  
> @@ -939,6 +952,46 @@ static int cros_typec_send_clear_event(struct cros_typec_data *typec, int port_n
>  			   sizeof(req), NULL, 0);
>  }
>  
> +static void cros_typec_register_partner_pdos(struct cros_typec_data *typec,
> +					     struct ec_response_typec_status *resp, int port_num)
> +{
> +	struct usb_power_delivery_capabilities_desc caps_desc = {};
> +	struct usb_power_delivery_desc desc = {
> +		.revision = (le16_to_cpu(resp->sop_revision) & 0xff00) >> 4,
> +	};
> +	struct cros_typec_port *port = typec->ports[port_num];
> +
> +	if (!port->partner || port->partner_pd)
> +		return;
> +
> +	/* If no caps are available, don't bother creating a device. */
> +	if (!resp->source_cap_count && !resp->sink_cap_count)
> +		return;
> +
> +	port->partner_pd = usb_power_delivery_register(NULL, &desc);
> +	if (IS_ERR(port->partner_pd)) {
> +		dev_warn(typec->dev, "Failed to register partner PD device, port: %d\n", port_num);
> +		return;
> +	}
> +
> +	typec_partner_set_usb_power_delivery(port->partner, port->partner_pd);
> +
> +	memcpy(caps_desc.pdo, resp->source_cap_pdos, sizeof(u32) * resp->source_cap_count);
> +	caps_desc.role = TYPEC_SOURCE;
> +	port->partner_src_caps = usb_power_delivery_register_capabilities(port->partner_pd,
> +									  &caps_desc);
> +	if (IS_ERR(port->partner_src_caps))
> +		dev_warn(typec->dev, "Failed to register source caps, port: %d\n", port_num);
> +
> +	memset(&caps_desc, 0, sizeof(caps_desc));
> +	memcpy(caps_desc.pdo, resp->sink_cap_pdos, sizeof(u32) * resp->sink_cap_count);
> +	caps_desc.role = TYPEC_SINK;
> +	port->partner_sink_caps = usb_power_delivery_register_capabilities(port->partner_pd,
> +									   &caps_desc);
> +	if (IS_ERR(port->partner_sink_caps))
> +		dev_warn(typec->dev, "Failed to register sink caps, port: %d\n", port_num);
> +}
> +
>  static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num)
>  {
>  	struct ec_response_typec_status resp;
> @@ -986,6 +1039,8 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
>  		}
>  		if (resp.sop_connected)
>  			typec_set_pwr_opmode(typec->ports[port_num]->port, TYPEC_PWR_MODE_PD);
> +
> +		cros_typec_register_partner_pdos(typec, &resp, port_num);
>  	}
>  
>  	if (resp.events & PD_STATUS_EVENT_SOP_PRIME_DISC_DONE &&
> @@ -1006,6 +1061,7 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
>  					 "Failed SOP Disc event clear, port: %d\n", port_num);
>  		}
>  	}
> +
>  }

I'm guessing that extra newline was just a typo.

thanks,

-- 
heikki

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ