Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2271430ybt; Tue, 16 Jun 2020 01:23:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJym6Z4GM6wxG26vjJrkozsmkuqEPZuoJlbLmmVRwojbxtzDGGP4Fb5qduXgW7MwgYuf2Rl5 X-Received: by 2002:a17:906:940d:: with SMTP id q13mr1668526ejx.534.1592295821235; Tue, 16 Jun 2020 01:23:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592295821; cv=none; d=google.com; s=arc-20160816; b=gOtOazSS0Wi0LZGq8zptw2kMsi3n55LQSzv7pgohf15fDdqrpJXCAvIQfwXX7WA70x fRSsIZLOJ4TaAtsnfOb/w+Ine8H3Tml7h7Be4psmteKvJppLDclmo7Ldz6lRMyB9FcPP d6YKb7sHwE8tNGBhFxob4VK9dLXF5glzli2mAmWMLCuve+zCAnrR5PPG6oQsIWelN6dx eJE6o2Vw1QoCK1T9X/hTILIIGVj3e3LhPCLG51Cim5cSxHaQ6yVHwuTYRP4/K+krOuX7 iHSl1dLX6+9USqVaLwObYyDrwBMW/GNQKKNYkQLjmrVtiXqSGu4li/3s6XdfZ0onO8bi pL8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=TEde+zHBVjL/svKV9brEmKONFUdr6ZjIQ+C8EGhrAtk=; b=lXJoSi7RnJFvZCPGgTSjfVd3I9ONmjrMlOk+V4fbY/tdrrLmHdP85MKz8CtIr7FQyE bMSBSyMJKZX6eGSzJUbst7eUDq8x4LHN+KNJX787so8zE/eyqq7/x+bOg1v37SFJt4Ih u9v1JUHpDAjJu9cNd7M0yT/UKYwV4nhfLiksIg1jVMHxBTp3yxfcsjcqRxhbEFBzqQAH Nk2BaGp63pBmv3Gvc4wMVef7Sg4FSYapOkvMuo0SCmpxBc8Xdnz9TVIq+p9eLuKeeJer Oar59l8kbv9OCu0PlgKb3JS71C681YKDhahI63QDKn5DvjwWLDRWHCzoQM7MsN1lWaVN lUDQ== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ck26si9696587edb.166.2020.06.16.01.23.19; Tue, 16 Jun 2020 01:23:41 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726833AbgFPITe (ORCPT + 99 others); Tue, 16 Jun 2020 04:19:34 -0400 Received: from mga14.intel.com ([192.55.52.115]:6511 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726692AbgFPITd (ORCPT ); Tue, 16 Jun 2020 04:19:33 -0400 IronPort-SDR: iy3MO/pWUsFfvzzKSNoRbd3Pd096OwtLy6cvH14CW9pf/qjFQOaFpdVHA4RAefHrCh3Q1zwt+K p2JEmhZ3s47Q== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2020 01:19:18 -0700 IronPort-SDR: smuYqMfrtPufZWfwP8OF+mIsJDQZQKVDIcypLmurkN1+sKqmofCwwLb1hmIkO1zJjVMmwPUyRl TuipIJK+uaUA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,518,1583222400"; d="scan'208";a="382803214" Received: from kuha.fi.intel.com ([10.237.72.162]) by fmsmga001.fm.intel.com with SMTP; 16 Jun 2020 01:19:15 -0700 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Tue, 16 Jun 2020 11:19:15 +0300 Date: Tue, 16 Jun 2020 11:19:15 +0300 From: Heikki Krogerus To: Prashant Malani Cc: linux-kernel@vger.kernel.org, Benson Leung , Enric Balletbo i Serra , Guenter Roeck Subject: Re: [PATCH 3/4] platform/chrome: typec: Add USB mux control Message-ID: <20200616081915.GI3213128@kuha.fi.intel.com> References: <20200528113607.120841-1-pmalani@chromium.org> <20200528113607.120841-4-pmalani@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200528113607.120841-4-pmalani@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 28, 2020 at 04:36:07AM -0700, Prashant Malani wrote: > Add support to configure various Type C switches appropriately using the > Type C connector class API, when the Chrome OS EC informs the AP that > the USB operating mode has been entered. > > Signed-off-by: Prashant Malani Reviewed-by: Heikki Krogerus > --- > drivers/platform/chrome/cros_ec_typec.c | 100 +++++++++++++++++++++++- > 1 file changed, 97 insertions(+), 3 deletions(-) > > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c > index d69a88464cef..9ebf9abed16f 100644 > --- a/drivers/platform/chrome/cros_ec_typec.c > +++ b/drivers/platform/chrome/cros_ec_typec.c > @@ -14,6 +14,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -30,6 +31,10 @@ struct cros_typec_port { > struct typec_switch *ori_sw; > struct typec_mux *mux; > struct usb_role_switch *role_sw; > + > + /* Variables keeping track of switch state. */ > + struct typec_mux_state state; > + uint8_t mux_flags; > }; > > /* Platform-specific data for the Chrome OS EC Type C controller. */ > @@ -264,6 +269,23 @@ static int cros_typec_add_partner(struct cros_typec_data *typec, int port_num, > return ret; > } > > +static void cros_typec_remove_partner(struct cros_typec_data *typec, > + int port_num) > +{ > + struct cros_typec_port *port = typec->ports[port_num]; > + > + port->state.alt = NULL; > + port->state.mode = TYPEC_STATE_USB; > + port->state.data = NULL; > + > + usb_role_switch_set_role(port->role_sw, USB_ROLE_NONE); > + typec_switch_set(port->ori_sw, TYPEC_ORIENTATION_NONE); > + typec_mux_set(port->mux, &port->state); > + > + typec_unregister_partner(port->partner); > + port->partner = NULL; > +} > + > static void cros_typec_set_port_params_v0(struct cros_typec_data *typec, > int port_num, struct ec_response_usb_pd_control *resp) > { > @@ -317,16 +339,69 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, > } else { > if (!typec->ports[port_num]->partner) > return; > + cros_typec_remove_partner(typec, port_num); > + } > +} > + > +static int cros_typec_get_mux_info(struct cros_typec_data *typec, int port_num, > + struct ec_response_usb_pd_mux_info *resp) > +{ > + struct ec_params_usb_pd_mux_info req = { > + .port = port_num, > + }; > + > + return cros_typec_ec_command(typec, 0, EC_CMD_USB_PD_MUX_INFO, &req, > + sizeof(req), resp, sizeof(*resp)); > +} > + > +static int cros_typec_usb_safe_state(struct cros_typec_port *port) > +{ > + port->state.mode = TYPEC_STATE_SAFE; > + > + return typec_mux_set(port->mux, &port->state); > +} > > - typec_unregister_partner(typec->ports[port_num]->partner); > - typec->ports[port_num]->partner = NULL; > +int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num, > + uint8_t mux_flags) > +{ > + struct cros_typec_port *port = typec->ports[port_num]; > + enum typec_orientation orientation; > + int ret; > + > + if (!port->partner) > + return 0; > + > + if (mux_flags & USB_PD_MUX_POLARITY_INVERTED) > + orientation = TYPEC_ORIENTATION_REVERSE; > + else > + orientation = TYPEC_ORIENTATION_NORMAL; > + > + ret = typec_switch_set(port->ori_sw, orientation); > + if (ret) > + return ret; > + > + port->state.alt = NULL; > + port->state.mode = TYPEC_STATE_USB; > + > + if (mux_flags & USB_PD_MUX_SAFE_MODE) > + ret = cros_typec_usb_safe_state(port); > + else if (mux_flags & USB_PD_MUX_USB_ENABLED) > + ret = typec_mux_set(port->mux, &port->state); > + else { > + dev_info(typec->dev, > + "Unsupported mode requested, mux flags: %x\n", > + mux_flags); > + ret = -ENOTSUPP; > } > + > + return ret; > } > > static int cros_typec_port_update(struct cros_typec_data *typec, int port_num) > { > struct ec_params_usb_pd_control req; > struct ec_response_usb_pd_control_v1 resp; > + struct ec_response_usb_pd_mux_info mux_resp; > int ret; > > if (port_num < 0 || port_num >= typec->num_ports) { > @@ -357,7 +432,26 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num) > cros_typec_set_port_params_v0(typec, port_num, > (struct ec_response_usb_pd_control *) &resp); > > - return 0; > + /* Update the switches if they exist, according to requested state */ > + ret = cros_typec_get_mux_info(typec, port_num, &mux_resp); > + if (ret < 0) { > + dev_warn(typec->dev, > + "Failed to get mux info for port: %d, err = %d\n", > + port_num, ret); > + return 0; > + } > + > + /* No change needs to be made, let's exit early. */ > + if (typec->ports[port_num]->mux_flags == mux_resp.flags) > + return 0; > + > + typec->ports[port_num]->mux_flags = mux_resp.flags; > + ret = cros_typec_configure_mux(typec, port_num, mux_resp.flags); > + if (ret) > + dev_warn(typec->dev, "Configure muxes failed, err = %d\n", ret); > + > + return usb_role_switch_set_role(typec->ports[port_num]->role_sw, > + !!(resp.role & PD_CTRL_RESP_ROLE_DATA)); > } > > static int cros_typec_get_cmd_version(struct cros_typec_data *typec) > -- > 2.27.0.rc0.183.gde8f92d652-goog -- heikki