Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2967075ybh; Mon, 16 Mar 2020 13:09:37 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvn5NteTrg8EEsy9we6eXQCMOw+PrQJGUdVdxC0enjGv0g5b530TpurzAik7kpIneCTBGYB X-Received: by 2002:a9d:3b8b:: with SMTP id k11mr722644otc.245.1584389377296; Mon, 16 Mar 2020 13:09:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584389377; cv=none; d=google.com; s=arc-20160816; b=mn8hayTDcme4ZNQwGjHl2zQr4PkucGUNBXvgypNmHhb8cGYAT5DBkgVBoDKoqyrefn OtdXCN6P1tSCQQV1C/lMM2FqBtNCvN5TNPwht0RV8rAAPPMfyTUKStntMoFLe4cuaEWf IEXUrjlBSUlE9rtHeLnqgal6cLkcb2Lc8SXOnwgytEVCoeaJU7uK7SM1hqFPCeUcUFrv mCnpFH4w7z4tkrulu/Z/7xNr+aU6bybaXaNBvHYB1i63uflmjgkIjjIBOpDKfa9YmgZ8 ijg75xpGj9xho7WEGq0nMkWHBKdtAANOVlhp938/ZMbBm2XcuNfH1Sw+ucmsQ1E1AKa0 tpDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=TXYTnR2RSdF9ZUbls3vNbNnwKPqZaGBmx3h0m/8kkBg=; b=c+ouPx6xovMmkaF/tyXvL02Gszs2LtLwZly2FJvO0LBEAcpPtS3ZU5xkmwd0kFlkNn 649P/lelQF4AUuNkWFpJ7B+E433KyVd7JM2Cvo4ukYJ2n1fi3REult/t3rfowX55lw7u lHBqvbLW34kBbEO840XTeF1F5ez/eUJtF5oHKGLsRwyFPOVNIPta1pwG2gYcdBOfVD3E dJxQzmmFSFB7uofmAeClYKWsx7+xL1KCT/qOZzZ8l/BPFWYyOPl00cIrG6TRrPHD3bmq nHVU+4LqQiQwa3nkKwP3VY8L0dYMwvh6F8FAo7nU/3z26EdOuQRwAIBRCW8lmpOOVB5z /P/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Vi1FEP2X; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m4si520045otn.175.2020.03.16.13.09.25; Mon, 16 Mar 2020 13:09:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Vi1FEP2X; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732522AbgCPUI4 (ORCPT + 99 others); Mon, 16 Mar 2020 16:08:56 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:43733 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732436AbgCPUI4 (ORCPT ); Mon, 16 Mar 2020 16:08:56 -0400 Received: by mail-qt1-f196.google.com with SMTP id l13so15405395qtv.10 for ; Mon, 16 Mar 2020 13:08:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TXYTnR2RSdF9ZUbls3vNbNnwKPqZaGBmx3h0m/8kkBg=; b=Vi1FEP2X8iumt4miyUdQxGMiF8UPkzZijZCE/bPHiPCrbN8HCoMo5LQjm1AYLc0vhI Nk6SB3B3sb8rkKyTNCCwCrJq8TcobPuH1V3tvvJ/4dqJYkXLFN07vQa/THT+UgYPlto9 Spg0URM0FOkLWHiz/Q35IoeW49cEPIDFVXQXw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TXYTnR2RSdF9ZUbls3vNbNnwKPqZaGBmx3h0m/8kkBg=; b=XaPROH6Oiss/Xs7fIjCHdRFC9Gl/PIArkIHZeX17t88qzLCfVhuvLWOTjCz6hkts8K 8xtxHBpINoGhfyFAr59uyBq3tDZJq4uDMJoHDQg97sUeUWkqowCzKSROLO84TYJsVjpu U2SQOexVw2SZMadAjB9pQ+/ZDkAxxDAxNH9+IbGO5HIh3VfJS7sFGK9I4Uo4IF0LoPM9 NDqFkGvzyJdi6JVFMPwlQ/1xbjJGubabl8hIO2OUQuGHT6QeIkc5YGw5GZk2qGznsuHm yyFNK9tRfCLIUcUK5Sk0QlJDUnm3dSMKNNbfa2C+psc2ccIyrkfokJsfEZIOQU9URjZi mrOw== X-Gm-Message-State: ANhLgQ3SYFxI14z5QDt+tcONoKqm6oVq+pPhzekxmdcFJZ0LXR7YLWx2 VrdEcI3DndYY/+nooMosAT8XRzhNg74/HJyGW0Qt3uIJ X-Received: by 2002:ac8:140c:: with SMTP id k12mr1875447qtj.117.1584389333039; Mon, 16 Mar 2020 13:08:53 -0700 (PDT) MIME-Version: 1.0 References: <20200316090021.52148-1-pmalani@chromium.org> <20200316090021.52148-5-pmalani@chromium.org> In-Reply-To: <20200316090021.52148-5-pmalani@chromium.org> From: Prashant Malani Date: Mon, 16 Mar 2020 13:08:41 -0700 Message-ID: Subject: Re: [PATCH v5 4/4] platform/chrome: typec: Update port info from EC To: Linux Kernel Mailing List Cc: Jon Flatley , Benson Leung , Enric Balletbo i Serra , Guenter Roeck , Heikki Krogerus Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding Heikki (missed in the initial email) On Mon, Mar 16, 2020 at 2:01 AM Prashant Malani wrote: > > After registering the ports at probe, get the current port information > from EC and update the Type C connector class ports accordingly. > > Co-developed-by: Jon Flatley > Signed-off-by: Prashant Malani > --- > > Changes in v5: > - No changes. > > Changes in v4: > - No changes > > Changes in v3: > - No changes. > > Changes in v2: > - No changes. > > drivers/platform/chrome/cros_ec_typec.c | 89 ++++++++++++++++++++++++- > 1 file changed, 88 insertions(+), 1 deletion(-) > > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c > index 9f692eb78b322..874269c070739 100644 > --- a/drivers/platform/chrome/cros_ec_typec.c > +++ b/drivers/platform/chrome/cros_ec_typec.c > @@ -172,6 +172,81 @@ static int cros_typec_ec_command(struct cros_typec_data *typec, > 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) > +{ > + struct typec_port *port = typec->ports[port_num]; > + enum typec_orientation polarity; > + > + if (!resp->enabled) > + polarity = TYPEC_ORIENTATION_NONE; > + else if (!resp->polarity) > + polarity = TYPEC_ORIENTATION_NORMAL; > + else > + polarity = TYPEC_ORIENTATION_REVERSE; > + > + typec_set_pwr_role(port, resp->role ? TYPEC_SOURCE : TYPEC_SINK); > + typec_set_orientation(port, polarity); > +} > + > +static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, > + int port_num, struct ec_response_usb_pd_control_v1 *resp) > +{ > + struct typec_port *port = typec->ports[port_num]; > + enum typec_orientation polarity; > + > + if (!(resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED)) > + polarity = TYPEC_ORIENTATION_NONE; > + else if (!resp->polarity) > + polarity = TYPEC_ORIENTATION_NORMAL; > + else > + polarity = TYPEC_ORIENTATION_REVERSE; > + typec_set_orientation(port, polarity); > + typec_set_data_role(port, resp->role & PD_CTRL_RESP_ROLE_DATA ? > + TYPEC_HOST : TYPEC_DEVICE); > + typec_set_pwr_role(port, resp->role & PD_CTRL_RESP_ROLE_POWER ? > + TYPEC_SOURCE : TYPEC_SINK); > + typec_set_vconn_role(port, resp->role & PD_CTRL_RESP_ROLE_VCONN ? > + TYPEC_SOURCE : TYPEC_SINK); > +} > + > +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; > + int ret; > + > + if (port_num < 0 || port_num >= typec->num_ports) { > + dev_err(typec->dev, "cannot get status for invalid port %d\n", > + port_num); > + return -EINVAL; > + } > + > + req.port = port_num; > + req.role = USB_PD_CTRL_ROLE_NO_CHANGE; > + req.mux = USB_PD_CTRL_MUX_NO_CHANGE; > + req.swap = USB_PD_CTRL_SWAP_NONE; > + > + ret = cros_typec_ec_command(typec, typec->cmd_ver, > + EC_CMD_USB_PD_CONTROL, &req, sizeof(req), > + &resp, sizeof(resp)); > + if (ret < 0) > + return ret; > + > + dev_dbg(typec->dev, "Enabled %d: 0x%hhx\n", port_num, resp.enabled); > + dev_dbg(typec->dev, "Role %d: 0x%hhx\n", port_num, resp.role); > + dev_dbg(typec->dev, "Polarity %d: 0x%hhx\n", port_num, resp.polarity); > + dev_dbg(typec->dev, "State %d: %s\n", port_num, resp.state); > + > + if (typec->cmd_ver == 1) > + cros_typec_set_port_params_v1(typec, port_num, &resp); > + else > + cros_typec_set_port_params_v0(typec, port_num, > + (struct ec_response_usb_pd_control *) &resp); > + > + return 0; > +} > + > static int cros_typec_get_cmd_version(struct cros_typec_data *typec) > { > struct ec_params_get_cmd_versions_v1 req_v1; > @@ -218,7 +293,7 @@ static int cros_typec_probe(struct platform_device *pdev) > struct device *dev = &pdev->dev; > struct cros_typec_data *typec; > struct ec_response_usb_pd_ports resp; > - int ret; > + int ret, i; > > typec = devm_kzalloc(dev, sizeof(*typec), GFP_KERNEL); > if (!typec) > @@ -251,7 +326,19 @@ static int cros_typec_probe(struct platform_device *pdev) > if (ret < 0) > return ret; > > + for (i = 0; i < typec->num_ports; i++) { > + ret = cros_typec_port_update(typec, i); > + if (ret < 0) > + goto unregister_ports; > + } > + > return 0; > + > +unregister_ports: > + for (i = 0; i < typec->num_ports; i++) > + if (typec->ports[i]) > + typec_unregister_port(typec->ports[i]); > + return ret; > } > > static struct platform_driver cros_typec_driver = { > -- > 2.25.1.481.gfbce0eb801-goog >