Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp1253083pxa; Fri, 28 Aug 2020 07:51:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEErC6tAsdW2ofWtF87H3K8sWmj+0N2FIh5v4M+SW1I1MSnzjP7+/ES084JkPpbNgm2aRY X-Received: by 2002:a17:906:7492:: with SMTP id e18mr2175404ejl.375.1598626273458; Fri, 28 Aug 2020 07:51:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598626273; cv=none; d=google.com; s=arc-20160816; b=aAKMWYJ/PPhhFNEeWBajHamdM6h6fg3SsiNsLDRLQC+EEhbfWSBZ1LP17n8zToshFm gGhigjA3turVwjPv+wqp3iyQwN++LlGPS37KKYJFcoqFNrL7yBPp1HgQ0TLeukzzWpUS NFrgW/iT9vgZUzDcVs2ETnQI5ApYu60oyuUYpT+haYYb9etntV1Kxed7iBhkeD/PMMwD Rarei7b0iDkTl80mQDiWg45g2Ys+ej39ZcEL+dLyIn3DTgs/Y9f43z7EdCDAkICkIn0R ohNgIL8nhGcUdhRJ1CeA0kmZ5vS+N90omlaep56XAFJ8ojurxHK+j7aAYK8MvOC4uPS7 I7Eg== 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=lcqUUPdr/umD2pWC4NsvVbmxb5fCA12Uxq69aXRfr0o=; b=VR/H69ElFOTos248b6uUGSQ0dH7NJnTTU156ZVTSeprkNKmfDvF4lJPQxJcJwnAgGN Lbz6bOR0scMVKnDeQfpDx7hqYr/i+zB1u2bpxK3eILN65L9nSHHXlLBUtwPo3kFoxNQA fkjkVem00P4Extc6HE3Q6+S7OzHVOIC+HFrEscIrRH0Xzufv43tSPCs8anOOCxf/GyO8 gILhi6j3xdlPIv8AUxLvIMJ0EDjW0nAHFBPVC8c6rsjfsBHyR6wDMpKU15tEh6rBDNRi +qisg2JtLrB7zL3uT1t+jfIkO79fudhoZfMcWMb7yDJ00ciUvlRVogRES3Bpr/Is+PlL SqtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wCNHUCaw; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b14si748012edv.405.2020.08.28.07.50.50; Fri, 28 Aug 2020 07:51:13 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=wCNHUCaw; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726550AbgH1Oty (ORCPT + 99 others); Fri, 28 Aug 2020 10:49:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727912AbgH1Otp (ORCPT ); Fri, 28 Aug 2020 10:49:45 -0400 Received: from mail-vk1-xa43.google.com (mail-vk1-xa43.google.com [IPv6:2607:f8b0:4864:20::a43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45E79C061264 for ; Fri, 28 Aug 2020 07:49:45 -0700 (PDT) Received: by mail-vk1-xa43.google.com with SMTP id t189so298545vka.10 for ; Fri, 28 Aug 2020 07:49:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lcqUUPdr/umD2pWC4NsvVbmxb5fCA12Uxq69aXRfr0o=; b=wCNHUCaw7Le0VGnSa8RivY7ZMCA0au8zTO2M/ds9hsm3vRcIn+K7hH3J7DBnolJ7JA PQbFVEPm6MGnt52tcIGmbqwLVASwQ8l3OL1QFZz8S7XIBhj1a89khlX2dZCGaF5kMsqy +xFFAoXerlNOzQAMzCTV1IAQdikvVjY69ULl+RUQKfrYWAU4XzFnrvh2deIPPlVyezXJ dzqOntNCMIBYKpGNA5nsb71XMvKG4aeu9cggP1/iQrT2XvEscjeFT9O3KqZ1Zq9Uhb/m nacNtbMVtgr+Tx1m1FbuMosKavVETXgnSs9N3nEsMK0rhjXiXVV+kYq3QL9bokAx3WOj j+xw== 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=lcqUUPdr/umD2pWC4NsvVbmxb5fCA12Uxq69aXRfr0o=; b=AO1mL85hXRBfXDI9/XGmjPiE2OFfKpT6K18X0Ufik5z4VXzeRWiiIFASWn1xhdyUz1 laztgOBqL8d/Bxw3fxJyhbVJkE8U8YzaC5RKHtEWXSoYc4Ljpr4BsVhhqfZlLgR/Co8J l80Ne76A7aZlVJXeXF82co2j1uwoK1XHY0OYPsyQHzzWvtUWxWUkrwNLTDBnJg+UYg5b 7UQmSHk0KNe5lEO/XxrANQrDRXo43JzZVsbXem4Tj8mzbToalnpZZL+ouhpjAls2tJh/ ZyxIk4e30CMJFbQxxSwOM/9xt2Ig77kUy8COs0AymKbLr3PGofiVnz1AfQ7FzA/vZv2s ammg== X-Gm-Message-State: AOAM5315RG94SFNwLJp98o963zgaqZX4T50kK1b2epg0SpNlxY8cDwTC GJorgjotahECKyk0hKUa+xE9K1O/i4rxQl6av+tOfQ== X-Received: by 2002:a1f:2cd0:: with SMTP id s199mr1319049vks.25.1598626184206; Fri, 28 Aug 2020 07:49:44 -0700 (PDT) MIME-Version: 1.0 References: <20200825042210.300632-1-badhri@google.com> <20200825042210.300632-3-badhri@google.com> <20200828131214.GH174928@kuha.fi.intel.com> In-Reply-To: <20200828131214.GH174928@kuha.fi.intel.com> From: Badhri Jagan Sridharan Date: Fri, 28 Aug 2020 07:49:08 -0700 Message-ID: Subject: Re: [PATCH 02/14 v2] usb: typec: tcpci: Add support when hidden tx registers are inaccessible To: Heikki Krogerus Cc: Guenter Roeck , Greg Kroah-Hartman , USB , LKML 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 On Fri, Aug 28, 2020 at 6:12 AM Heikki Krogerus wrote: > > Looks like you forgot v1 somewhere :-) Dumb me :P Yeah I was doing the patch numbers manually causing the confusion. Greg was complaining as well. These are all v1. I will re-upload everything as v2. Just noticed that I can use the -v option. > > > On Mon, Aug 24, 2020 at 09:21:58PM -0700, Badhri Jagan Sridharan wrote: > > TCPCI spec forbids direct access of TX_BUF_BYTE_x register. > > The existing version of tcpci driver assumes that those registers > > are directly addressible. Add support for tcpci chips which do > > not support direct access to TX_BUF_BYTE_x registers. TX_BUF_BYTE_x > > can only be accessed by I2C_WRITE_BYTE_COUNT. > > > > Signed-off-by: Badhri Jagan Sridharan > > --- > > drivers/usb/typec/tcpm/tcpci.c | 49 +++++++++++++++++++++++++--------- > > drivers/usb/typec/tcpm/tcpci.h | 8 ++++++ > > 2 files changed, 44 insertions(+), 13 deletions(-) > > > > diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c > > index f57d91fd0e09..90d348caa6a8 100644 > > --- a/drivers/usb/typec/tcpm/tcpci.c > > +++ b/drivers/usb/typec/tcpm/tcpci.c > > @@ -320,8 +320,7 @@ static int tcpci_set_vbus(struct tcpc_dev *tcpc, bool source, bool sink) > > return 0; > > } > > > > -static int tcpci_pd_transmit(struct tcpc_dev *tcpc, > > - enum tcpm_transmit_type type, > > +static int tcpci_pd_transmit(struct tcpc_dev *tcpc, enum tcpm_transmit_type type, > > const struct pd_message *msg) > > That does not look like a relevant change. > > > { > > struct tcpci *tcpci = tcpc_to_tcpci(tcpc); > > @@ -330,23 +329,47 @@ static int tcpci_pd_transmit(struct tcpc_dev *tcpc, > > int ret; > > > > cnt = msg ? pd_header_cnt(header) * 4 : 0; > > - ret = regmap_write(tcpci->regmap, TCPC_TX_BYTE_CNT, cnt + 2); > > - if (ret < 0) > > - return ret; > > + /** > > + * TCPCI spec forbids direct access of TCPC_TX_DATA. > > + * But, since some of the chipsets offer this capability, > > + * it's fair to support both. > > + */ > > + if (!tcpci->data->TX_BUF_BYTE_x_hidden) { > > Couldn't check if the flag is set first? Yes will do ! > > if (tcpci->data->TX_BUF_BYTE_x_hidden) { > ... > > > + ret = regmap_write(tcpci->regmap, TCPC_TX_BYTE_CNT, cnt + 2); > > + if (ret < 0) > > + return ret; > > > > - ret = tcpci_write16(tcpci, TCPC_TX_HDR, header); > > - if (ret < 0) > > - return ret; > > + ret = tcpci_write16(tcpci, TCPC_TX_HDR, header); > > + if (ret < 0) > > + return ret; > > + > > + if (cnt > 0) { > > + ret = regmap_raw_write(tcpci->regmap, TCPC_TX_DATA, &msg->payload, cnt); > > + if (ret < 0) > > + return ret; > > + } > > + } else { > > + u8 buf[TCPC_TRANSMIT_BUFFER_MAX_LEN] = {0,}; > > + u8 pos = 0; > > + > > + /* Payload + header + TCPC_TX_BYTE_CNT */ > > + buf[pos++] = cnt + 2; > > + > > + if (msg) > > + memcpy(&buf[pos], &msg->header, sizeof(msg->header)); > > + > > + pos += sizeof(header); > > + > > + if (cnt > 0) > > + memcpy(&buf[pos], msg->payload, cnt); > > > > - if (cnt > 0) { > > - ret = regmap_raw_write(tcpci->regmap, TCPC_TX_DATA, > > - &msg->payload, cnt); > > + pos += cnt; > > + ret = regmap_raw_write(tcpci->regmap, TCPC_TX_BYTE_CNT, buf, pos); > > if (ret < 0) > > return ret; > > } > > > > - reg = (PD_RETRY_COUNT << TCPC_TRANSMIT_RETRY_SHIFT) | > > - (type << TCPC_TRANSMIT_TYPE_SHIFT); > > + reg = (PD_RETRY_COUNT << TCPC_TRANSMIT_RETRY_SHIFT) | (type << TCPC_TRANSMIT_TYPE_SHIFT); > > ret = regmap_write(tcpci->regmap, TCPC_TRANSMIT, reg); > > if (ret < 0) > > return ret; > > diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h > > index fd26ca35814c..cf9d8b63adcb 100644 > > --- a/drivers/usb/typec/tcpm/tcpci.h > > +++ b/drivers/usb/typec/tcpm/tcpci.h > > @@ -128,9 +128,17 @@ > > #define TCPC_VBUS_VOLTAGE_ALARM_HI_CFG 0x76 > > #define TCPC_VBUS_VOLTAGE_ALARM_LO_CFG 0x78 > > > > +/* I2C_WRITE_BYTE_COUNT + 1 when TX_BUF_BYTE_x is only accessible I2C_WRITE_BYTE_COUNT */ > > +#define TCPC_TRANSMIT_BUFFER_MAX_LEN 31 > > + > > +/* > > + * @TX_BUF_BYTE_x_hidden > > + * optional; Set when TX_BUF_BYTE_x can only be accessed through I2C_WRITE_BYTE_COUNT. > > + */ > > struct tcpci; > > struct tcpci_data { > > struct regmap *regmap; > > + unsigned char TX_BUF_BYTE_x_hidden:1; > > int (*init)(struct tcpci *tcpci, struct tcpci_data *data); > > int (*set_vconn)(struct tcpci *tcpci, struct tcpci_data *data, > > bool enable); > > -- > > 2.28.0.297.g1956fa8f8d-goog > > thanks, > > -- > heikki