Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1980337pxb; Sat, 23 Jan 2021 12:07:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbygQv6+8F75B0ViDdonJ4yt3l6Afy5OHDaYasVWrKPwZd/+z/K/lovmsN74RIE6xEDVj5 X-Received: by 2002:a17:906:b0c2:: with SMTP id bk2mr104672ejb.223.1611432449245; Sat, 23 Jan 2021 12:07:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611432449; cv=none; d=google.com; s=arc-20160816; b=Q/Melg7Dl6NERBOzNcM9v1mShyW+rmW+POp1sczQjT7GLPvu2GII82LOWRpIT6Jz1u M0wmwaKZk2vc05yQ2z3Qlbwq1NsyoeE913v64vg+L2oy4ZSmwddjbC++V5CdM0BB7qel /ODfmzLRAkrcDCl51EY0RuKQkEruFbC1iSRTfRfDaadl6dDFnC3P3iYTZ3TE/EQuJkpD wmf4dKxJ43TBvxIQtp2TBbywuXzSAOsXiu6Hdzs6tdq7UmLrNpeuN51+eeCxjmtZKOQF oqMzTT1DFVY2YIp27OLWP5ITzCVZ31O60GqeM9jjJA+Hho2p98CbEBAeKrWU37gxZYlG lgIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:autocrypt:from :references:cc:to:subject:sender:dkim-signature; bh=sSFxrwccIA6nA6eNeAwDwFwmaBJAImwDdSSEc08nxvo=; b=HIx6YTRQLSJwo1lhjNvhsaG7KJQxEjmwhuaC8vrLwDHqkdE/UD/o4f4VbwVKJkIz1V 7PNTci1LxGf5iocFjwaXst34VBHcb7bCK3MmSBEgdlu/fnj+7oR6DyYmQNRmXGmmGwzw NIAvK0f99+HUtiC+Y0jo5QzcjHPZHdTzVSQyq59feebHdIxVKCtp9GcodZDZPvPizSjp u0OhZKlVKnbRTH71k7P3+ftq9UsnZCTJVe/0XclcdQlyjjZJw24giYZExaCNMFpBYStI 7xaY8y/BBcmvhRJ41AAeBwS9x9GjwDhNUxRKxNIn2m/07SElB7NxZFG3GT1LqqpWomuJ 4DVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=X1OcpTSe; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw21si5282322edb.275.2021.01.23.12.07.06; Sat, 23 Jan 2021 12:07:29 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=X1OcpTSe; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726402AbhAWUDO (ORCPT + 99 others); Sat, 23 Jan 2021 15:03:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726487AbhAWUCg (ORCPT ); Sat, 23 Jan 2021 15:02:36 -0500 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADF5AC06174A; Sat, 23 Jan 2021 12:01:54 -0800 (PST) Received: by mail-oi1-x233.google.com with SMTP id m13so2281109oig.8; Sat, 23 Jan 2021 12:01:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=sSFxrwccIA6nA6eNeAwDwFwmaBJAImwDdSSEc08nxvo=; b=X1OcpTSe4jCAu1BTSEqa/voi3MK8NDHanLQlKLKFyO85c1T51mxMr4qtF2GRHlZuLh 68qcsF/b1z3z+MY6x8H9xzdyM/26yAtVBqsTibndgDtonLC8uwhPAQYwsr052jO5nH71 X+jLunUSbqwp+IiV4qUd5mZZ66uqcjLuEcFmKKaAtB8ab1c9pVSfYcKeYt0KRn90WVHX gb2SIsrqRPiKvcW7JGZ4Slqvo7EUJiDx3GfrCG6QwMiXG4gfxqv9NVScLuoAfanPSdtq 3KMPRRrcAZDpiZBZoVcC989vqOHggxzL90Itl68UU9to2sJs878TgQrd//ItFQzaoSor B9xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=sSFxrwccIA6nA6eNeAwDwFwmaBJAImwDdSSEc08nxvo=; b=Yhlxx5CAmM4TJIPNUbnysr8djfKOg2mx8i1tfnR21UIbECzGRuiAvnbbquPXsnEM6k +c2I+4Nyoxhpn2F59iDjn/yTUR+CCq4RgW1RE1X5GfdkMWmikVp+GJNulyKiJPS4nFDo 7smrTG3MsrpZR9nuUjVT5jgm7E1Lt1RUjMwVAzThen3RkubmVFqxeNbnGuivgopvURMr dnSJ+nWdrrMRq/etbGmBhILs5qZXQ42QimK2AyNfhosbn/AzodZMgpG5Nm9QQFmddTj7 V5NRrZkOEAvwhkNDJj+0krhyEjzRUq/ALQnqz53cfW2mxJXyoBR3OQyNzmn3xipBqSOw yU6g== X-Gm-Message-State: AOAM533IIKF5U1CkerMU4E/YyS7k7AC2KoHWOCZgM6UrVGo3dvfaexyw kHk8Hxw8xHgkCdew7PPcajvgqGxc+ZGq8g== X-Received: by 2002:aca:b909:: with SMTP id j9mr7105871oif.113.1611432113820; Sat, 23 Jan 2021 12:01:53 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id q26sm1022836otg.28.2021.01.23.12.01.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 23 Jan 2021 12:01:53 -0800 (PST) Sender: Guenter Roeck Subject: Re: [PATCH] usb: typec: tcpm: Create legacy PDOs for PD2 connection To: Kyle Tso , heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210115163311.391332-1-kyletso@google.com> From: Guenter Roeck Autocrypt: addr=linux@roeck-us.net; keydata= xsFNBE6H1WcBEACu6jIcw5kZ5dGeJ7E7B2uweQR/4FGxH10/H1O1+ApmcQ9i87XdZQiB9cpN RYHA7RCEK2dh6dDccykQk3bC90xXMPg+O3R+C/SkwcnUak1UZaeK/SwQbq/t0tkMzYDRxfJ7 nyFiKxUehbNF3r9qlJgPqONwX5vJy4/GvDHdddSCxV41P/ejsZ8PykxyJs98UWhF54tGRWFl 7i1xvaDB9lN5WTLRKSO7wICuLiSz5WZHXMkyF4d+/O5ll7yz/o/JxK5vO/sduYDIlFTvBZDh gzaEtNf5tQjsjG4io8E0Yq0ViobLkS2RTNZT8ICq/Jmvl0SpbHRvYwa2DhNsK0YjHFQBB0FX IdhdUEzNefcNcYvqigJpdICoP2e4yJSyflHFO4dr0OrdnGLe1Zi/8Xo/2+M1dSSEt196rXaC kwu2KgIgmkRBb3cp2vIBBIIowU8W3qC1+w+RdMUrZxKGWJ3juwcgveJlzMpMZNyM1jobSXZ0 VHGMNJ3MwXlrEFPXaYJgibcg6brM6wGfX/LBvc/haWw4yO24lT5eitm4UBdIy9pKkKmHHh7s jfZJkB5fWKVdoCv/omy6UyH6ykLOPFugl+hVL2Prf8xrXuZe1CMS7ID9Lc8FaL1ROIN/W8Vk BIsJMaWOhks//7d92Uf3EArDlDShwR2+D+AMon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+qVWZeKEsFKFOkynOs3pVbcbq1pxbhk3TRWCGRU5JolI4ohy/7JV1TVbjiDI HP/aVnm6NC8of26P40Pg8EdAhajZnHHjA7FrJXsy3cyIGqvg9os4rNkUWmrCfLLsZDHD8FnU mDW4+i+XlNFUPUYMrIKi9joBhu18ssf5i5Q= Message-ID: <6a38dedc-ac11-99db-8b7b-4ef5e5e17780@roeck-us.net> Date: Sat, 23 Jan 2021 12:01:51 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210115163311.391332-1-kyletso@google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/15/21 8:33 AM, Kyle Tso wrote: > If the port partner is PD2, the PDOs of the local port should follow the > format defined in PD2 Spec. Dynamically modify the pre-defined PD3 PDOs > and transform them into PD2 format before sending them to the PD2 port > partner. > > Signed-off-by: Kyle Tso I don't like this too much, but I don't have a better idea. Thus, Reviewed-by: Guenter Roeck Guenter > --- > drivers/usb/typec/tcpm/tcpm.c | 62 +++++++++++++++++++++++++++++------ > include/linux/usb/pd.h | 1 + > 2 files changed, 53 insertions(+), 10 deletions(-) > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > index 22a85b396f69..1220ab1ed47d 100644 > --- a/drivers/usb/typec/tcpm/tcpm.c > +++ b/drivers/usb/typec/tcpm/tcpm.c > @@ -911,13 +911,47 @@ static int tcpm_set_pwr_role(struct tcpm_port *port, enum typec_role role) > return 0; > } > > +/* > + * Transform the PDO to be compliant to PD rev2.0. > + * Return 0 if the PDO type is not defined in PD rev2.0. > + * Otherwise, return the converted PDO. > + */ > +static u32 tcpm_forge_legacy_pdo(struct tcpm_port *port, u32 pdo, enum typec_role role) > +{ > + switch (pdo_type(pdo)) { > + case PDO_TYPE_FIXED: > + if (role == TYPEC_SINK) > + return pdo & ~PDO_FIXED_FRS_CURR_MASK; > + else > + return pdo & ~PDO_FIXED_UNCHUNK_EXT; > + case PDO_TYPE_VAR: > + case PDO_TYPE_BATT: > + return pdo; > + case PDO_TYPE_APDO: > + default: > + return 0; > + } > +} > + > static int tcpm_pd_send_source_caps(struct tcpm_port *port) > { > struct pd_message msg; > - int i; > + u32 pdo; > + unsigned int i, nr_pdo = 0; > > memset(&msg, 0, sizeof(msg)); > - if (!port->nr_src_pdo) { > + > + for (i = 0; i < port->nr_src_pdo; i++) { > + if (port->negotiated_rev >= PD_REV30) { > + msg.payload[nr_pdo++] = cpu_to_le32(port->src_pdo[i]); > + } else { > + pdo = tcpm_forge_legacy_pdo(port, port->src_pdo[i], TYPEC_SOURCE); > + if (pdo) > + msg.payload[nr_pdo++] = cpu_to_le32(pdo); > + } > + } > + > + if (!nr_pdo) { > /* No source capabilities defined, sink only */ > msg.header = PD_HEADER_LE(PD_CTRL_REJECT, > port->pwr_role, > @@ -930,10 +964,8 @@ static int tcpm_pd_send_source_caps(struct tcpm_port *port) > port->data_role, > port->negotiated_rev, > port->message_id, > - port->nr_src_pdo); > + nr_pdo); > } > - for (i = 0; i < port->nr_src_pdo; i++) > - msg.payload[i] = cpu_to_le32(port->src_pdo[i]); > > return tcpm_pd_transmit(port, TCPC_TX_SOP, &msg); > } > @@ -941,10 +973,22 @@ static int tcpm_pd_send_source_caps(struct tcpm_port *port) > static int tcpm_pd_send_sink_caps(struct tcpm_port *port) > { > struct pd_message msg; > - int i; > + u32 pdo; > + unsigned int i, nr_pdo = 0; > > memset(&msg, 0, sizeof(msg)); > - if (!port->nr_snk_pdo) { > + > + for (i = 0; i < port->nr_snk_pdo; i++) { > + if (port->negotiated_rev >= PD_REV30) { > + msg.payload[nr_pdo++] = cpu_to_le32(port->snk_pdo[i]); > + } else { > + pdo = tcpm_forge_legacy_pdo(port, port->snk_pdo[i], TYPEC_SINK); > + if (pdo) > + msg.payload[nr_pdo++] = cpu_to_le32(pdo); > + } > + } > + > + if (!nr_pdo) { > /* No sink capabilities defined, source only */ > msg.header = PD_HEADER_LE(PD_CTRL_REJECT, > port->pwr_role, > @@ -957,10 +1001,8 @@ static int tcpm_pd_send_sink_caps(struct tcpm_port *port) > port->data_role, > port->negotiated_rev, > port->message_id, > - port->nr_snk_pdo); > + nr_pdo); > } > - for (i = 0; i < port->nr_snk_pdo; i++) > - msg.payload[i] = cpu_to_le32(port->snk_pdo[i]); > > return tcpm_pd_transmit(port, TCPC_TX_SOP, &msg); > } > diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h > index bb9a782e1411..88f64bce5dea 100644 > --- a/include/linux/usb/pd.h > +++ b/include/linux/usb/pd.h > @@ -225,6 +225,7 @@ enum pd_pdo_type { > #define PDO_FIXED_EXTPOWER BIT(27) /* Externally powered */ > #define PDO_FIXED_USB_COMM BIT(26) /* USB communications capable */ > #define PDO_FIXED_DATA_SWAP BIT(25) /* Data role swap supported */ > +#define PDO_FIXED_UNCHUNK_EXT BIT(24) /* Unchunked Extended Message supported (Source) */ > #define PDO_FIXED_FRS_CURR_MASK (BIT(24) | BIT(23)) /* FR_Swap Current (Sink) */ > #define PDO_FIXED_FRS_CURR_SHIFT 23 > #define PDO_FIXED_VOLT_SHIFT 10 /* 50mV units */ >