Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp587073ybz; Wed, 15 Apr 2020 14:36:34 -0700 (PDT) X-Google-Smtp-Source: APiQypIvBCtVNeovaDYcAfdnucdSxzMRCWvoXhygLrR9TNF/Goos546DZOpH7DWQs0fDMnDlijGo X-Received: by 2002:a17:907:6fc:: with SMTP id yh28mr7152678ejb.326.1586986593867; Wed, 15 Apr 2020 14:36:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586986593; cv=none; d=google.com; s=arc-20160816; b=oIAL48cU11F1kTNnkMKbeZ6AvdcW0ZhF46ODNO6fqqJ5FGshuP0ont4rqwgXw7lIWz dcmHTjG95DAedwaH9MCT9oM0/52ApwofhMkhU5bU1RCpgDvWTXDAUItAXn4akCbS0Lka Xu+lT7kHdAFsYAyg1fUKypTQDxMgGhG7usUsXVa8x9NI/YdE3Ja1cLmTijMbYCdA+ctk gTtvF4GIMDOpBc3oZj6wsBfaZgP8cLtV6JSgeRhHl99orMbCVrU+R34Bu28ESgO/vl9B iLWNUw/SHSvk5XTLU2l0/4Ig4+sVnJdW+K5IHz1NNVn04xYt4nR2gjG1+g5JnNiA5Omy dsOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=O95JCLOfMRm1pj9u2XPk6B6/cdfFlfQ5EUlR99bqthQ=; b=uOSpryQao+FI0B/6wbLTN9p0zExwAVTr+57Up2sZgJCsco0o6pKIrIIxBKIvrPL1WC KRdHhWkxKfxAFxtCcHNmN0KDcYFcYLjkfyVCsXrhjS2k5eJI7n45gUR5BtEivbL+WFZf Y24Y1Q9htrSijU6XBCHvF9jW7R3bIk0E5ng3iHk6enz+t/6kOKL7MNe14cCbhm+UIy0C YDF2CU8PxFm7qXCWU6+sIaJWXLMUIpLJ/mTk/ygRla1TcCy+5lPnJqzYw4Qskm5fKy73 iQX8HYkwMP8BoilSqTRV00tKb9nf3IDdUMNIjDQUydg9Q6ljyBCxx12qpK48M1UyskBf uXdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 31si10985530edp.496.2020.04.15.14.36.10; Wed, 15 Apr 2020 14:36:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389182AbgDNOIq (ORCPT + 99 others); Tue, 14 Apr 2020 10:08:46 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:44010 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389175AbgDNOIi (ORCPT ); Tue, 14 Apr 2020 10:08:38 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 0E9FB2A18CF Subject: Re: [PATCH v3 3/3] platform/chrome: typec: Register port partner To: Prashant Malani , linux-kernel@vger.kernel.org Cc: heikki.krogerus@linux.intel.com, Jon Flatley , Benson Leung , Guenter Roeck References: <20200410002316.202107-1-pmalani@chromium.org> <20200410002316.202107-4-pmalani@chromium.org> From: Enric Balletbo i Serra Message-ID: <025802e6-207c-305a-8146-3c07a3f36bb4@collabora.com> Date: Tue, 14 Apr 2020 16:08:32 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200410002316.202107-4-pmalani@chromium.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Prashant, Thank you for your patch. On 10/4/20 2:23, Prashant Malani wrote: > Register (and unregister) the port partner when a connect (and > disconnect) is detected. > > Co-developed-by: Jon Flatley > Signed-off-by: Prashant Malani > --- > > Changes in v3: > - No changes. > > Changes in v2: > - Fixed error pointer return value. > > drivers/platform/chrome/cros_ec_typec.c | 48 +++++++++++++++++++++++++ > 1 file changed, 48 insertions(+) > > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c > index 56ded09a60ffb..304e0b20f279b 100644 > --- a/drivers/platform/chrome/cros_ec_typec.c > +++ b/drivers/platform/chrome/cros_ec_typec.c > @@ -22,6 +22,9 @@ struct cros_typec_port { > struct typec_port *port; > /* Initial capabilities for the port. */ > struct typec_capability caps; > + struct typec_partner *partner; > + /* Port partner PD identity info. */ > + struct usb_pd_identity p_identity; > }; > > /* Platform-specific data for the Chrome OS EC Type C controller. */ > @@ -190,6 +193,30 @@ static int cros_typec_ec_command(struct cros_typec_data *typec, > return ret; > } > > +static int cros_typec_add_partner(struct cros_typec_data *typec, int port_num, > + bool pd_en) > +{ > + struct cros_typec_port *port = typec->ports[port_num]; > + struct typec_partner_desc p_desc = { > + .usb_pd = pd_en, > + }; > + int ret = 0; > + > + /* > + * Fill an initial PD identity, which will then be updated with info > + * from the EC. > + */ > + p_desc.identity = &port->p_identity; > + > + port->partner = typec_register_partner(port->port, &p_desc); > + if (IS_ERR_OR_NULL(port->partner)) { > + ret = PTR_ERR(port->partner); If you're checking for IS_ERR_OR_NULL that means that port->partner can be NULL, so PTR_ERR(NULL) is 0 returning something that you don't really want. But looking at the typec_register_partner, NULL is not an option as returns a handle to the partner on success or ERR_PTR on failure. So, the code should just do: if (IS_ERR(port->partner)) return PTR_ERR(port->partner); And AFAICS you don't need to set port->partner to NULL. Can you double check this? Thanks, Enric > + port->partner = NULL; > + } > + > + return ret; > +} > + > static void cros_typec_set_port_params_v0(struct cros_typec_data *typec, > int port_num, struct ec_response_usb_pd_control *resp) > { > @@ -212,6 +239,8 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, > { > struct typec_port *port = typec->ports[port_num]->port; > enum typec_orientation polarity; > + bool pd_en; > + int ret; > > if (!(resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED)) > polarity = TYPEC_ORIENTATION_NONE; > @@ -226,6 +255,25 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, > TYPEC_SOURCE : TYPEC_SINK); > typec_set_vconn_role(port, resp->role & PD_CTRL_RESP_ROLE_VCONN ? > TYPEC_SOURCE : TYPEC_SINK); > + > + /* Register/remove partners when a connect/disconnect occurs. */ > + if (resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED) { > + if (typec->ports[port_num]->partner) > + return; > + > + pd_en = resp->enabled & PD_CTRL_RESP_ENABLED_PD_CAPABLE; > + ret = cros_typec_add_partner(typec, port_num, pd_en); > + if (!ret) > + dev_warn(typec->dev, > + "Failed to register partner on port: %d\n", > + port_num); > + } else { > + if (!typec->ports[port_num]->partner) > + return; > + > + typec_unregister_partner(typec->ports[port_num]->partner); > + typec->ports[port_num]->partner = NULL; > + } > } > > static int cros_typec_port_update(struct cros_typec_data *typec, int port_num) >