Received: by 10.223.176.5 with SMTP id f5csp3338570wra; Mon, 29 Jan 2018 11:58:35 -0800 (PST) X-Google-Smtp-Source: AH8x227i7dAILW8lox4QfHu4APrNvwg6m0ePCsaKgOpul+HcUJ6XqALW0S5s5rEZzkSwnPUyvhuS X-Received: by 10.101.70.201 with SMTP id n9mr16922502pgr.74.1517255915651; Mon, 29 Jan 2018 11:58:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517255915; cv=none; d=google.com; s=arc-20160816; b=O6EmcbeakqomCqyVt90KLbNFTBjJdD/XDHLaISffGdlyGYOz2hOiVhSP/AgY4lBjqX d+FoIW+iYxmamuFMQrUvIpS+mWvPapr47HsLiBjwCFseMDdFElOG8IeS6IPVX39dtDsA kIEllfdWmICTEtVbxWd9PSCUsi+6g0epsd65MTqvy2NWalfRX9X5CgiSswJf5IiRL7zr Ev8kgjKPPs59iz2T+z2BvERp+MmN3leeS2JsHUiLVX1gt3ytfKlXMesUFXvQrxvZGCFB 7R/ljagb+VgpPCVeQwGQEhG2/mFygfbLNPilypKzc3dpyQ2+H3HkwvzBfPVYimxBE8RZ XqBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=NGu0xcdna1KJukUWq2fITNiHputhC/M4PsXfDUsFc1A=; b=jS12MxOSyKwgmhWmuuukFRuIDaIZzuC8C2OY6fnnnFRcM2UiCyqeAuoY94TEzrwnkV WlB6jPvvfDTcUErOwBchPGOgOQwWt24hJ4OFSoaywBvZ2Kr6cU5Sm4spLeM079zVf/Wn gSZGwZeGkU4g1EMLUkOsAcaSDXNI16Z8NLtkyAPb7wbyHTEM+1QQJY+Z6TJdkiIFeVDZ Jft8VJfyhGSSasdVHqNfVf1/364LypoX+XG6O+I3SA0qnjaGiuHzVRcIF6cua/Sh0Xed TcoZQh/l0hOPWclJbrUsW/qQnJ3nv7pvywWyFAa83x7X04TTkchwchbraJvKx8nZbgCb aVeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=bhi1UC7l; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si9948160plv.147.2018.01.29.11.58.21; Mon, 29 Jan 2018 11:58:35 -0800 (PST) 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=fail header.i=@gmail.com header.s=20161025 header.b=bhi1UC7l; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752028AbeA2T55 (ORCPT + 99 others); Mon, 29 Jan 2018 14:57:57 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34842 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751604AbeA2T5z (ORCPT ); Mon, 29 Jan 2018 14:57:55 -0500 Received: by mail-pg0-f68.google.com with SMTP id o13so5298078pgs.2; Mon, 29 Jan 2018 11:57:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=NGu0xcdna1KJukUWq2fITNiHputhC/M4PsXfDUsFc1A=; b=bhi1UC7lvi4xg1biMMVZSCUeXl7IngGCg7jPxqRO28aUQ4bWO0Y3NNnpWPyAAF+j6t zbQr/Q8AY+mHQueHUGu6qD+MKAqWxszAKpy5zK5K48rIl9rc4KMpJiNp/18SVwuWDCx6 cfkbzBGueP83P+xMbc/uKrtb6LAWsrXGM2apvHmolxOP5OOyMdQnClC0vTA+SwvF+Xf/ vbpvpb4QZqpdC1k1OyEdeXy30XfJ2FXH6Dde8VI8mbUNB+3lO8LLE+okva94h5WcOs4U I/f7zFEYA2S9Tp7Danz/q/rCjAxqmKUIFf2e0yamQulxsMXE5mgwwAyjh3ABZYHCf9bt CAOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=NGu0xcdna1KJukUWq2fITNiHputhC/M4PsXfDUsFc1A=; b=FdSp3Apb6hmC98Kj0krTRgZMNwi8i//idGoXHCIKf9KVCqXopnlhrex+MIXE06iw0F +kHaFh0J3vOIG/pxKvWZCyAvI94TjKULI75gH0SsHViHoLa+4yloiZFzKulWaTK7r3iR 9gGn6MoUIaJeCblaybhTA+5+728VWP31Gm/SzTXm/jMaDaRnMr6v8vwOOmB0wBkLhfvx FZTMGguFEZ7LgEM5GJn0+Intt2fcxaQU46JQ4cG39GKhLEkQU/dv4/S7r7gk0UjFC5cZ aN3qmyKRhZlZSHq1GUNhZTHDZLrUyCbzTwYe5mVPU6dQcjYefLnA9xE1w3t+qG06/tKk WJUg== X-Gm-Message-State: AKwxyteYDDZfLQ0Bn3DWUZ9RgVg49Quh9j2MsJ/ARzpAlP9zPjXqklmd /0qJCQkYR0+KJYW4Akbfo9Q= X-Received: by 2002:a17:902:b604:: with SMTP id b4-v6mr7267382pls.32.1517255874812; Mon, 29 Jan 2018 11:57:54 -0800 (PST) Received: from localhost (108-223-40-66.lightspeed.sntcca.sbcglobal.net. [108.223.40.66]) by smtp.gmail.com with ESMTPSA id y14sm28389896pfl.77.2018.01.29.11.57.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jan 2018 11:57:53 -0800 (PST) Date: Mon, 29 Jan 2018 11:57:52 -0800 From: Guenter Roeck To: =?utf-8?B?c2h1ZmFuX2xlZSjmnY7mm7jluIYp?= Cc: Heikki Krogerus , 'Jun Li' , ShuFanLee , =?utf-8?B?Y3lfaHVhbmco6buD5ZWf5Y6fKQ==?= , "linux-kernel@vger.kernel.org" , "linux-usb@vger.kernel.org" Subject: Re: [PATCH] USB TYPEC: RT1711H Type-C Chip Driver Message-ID: <20180129195752.GA24352@roeck-us.net> References: <1515567552-7692-1-git-send-email-leechu729@gmail.com> <20180119082218.GA22976@kuha.fi.intel.com> <25ced79e8ea84908bf6110a613ed81a2@ex1.rt.l> <20180119092413.GB22976@kuha.fi.intel.com> <20180119160235.GA21066@roeck-us.net> <20180122185034.GA26058@roeck-us.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 29, 2018 at 07:19:06AM +0000, shufan_lee(李書帆) wrote: > Hi Guenter, > > We try to use the TCPCI driver on RT1711H and here are some questions. > > Q1. Is current TCPCI driver written according to TypeC Port Controller Interface Specification Revision 1.0 & Version 1.2? Revision 1.0. Note that I did not find revision 1.2, only Revision 1.0 and Revision 2.0 version 1.0. > Q2. Because 0x80~0xFF are vendor defined registers. Some of them are needed to be initialized in tcpci_init for RT1711H (or other chips also). > In the future TCPCI driver, will an initial interface that is called in tcpci_init be released for different vendors to implement. My suggestion would be to provide an API for vendor specific code. > Or, we should directly copy tcpci.c to tcpci_rt1711h.c and add the different parts? That would defeat the purpose. It would be better to implement vendor specific code in tcpci_rt1711h.c and call it from tcpci.c Possible example: struct tcpci_vendor_data { int (*init)(...); int (*irq_handler)(...); ... } static irqreturn_t tcpci_irq(...) { struct tcpci *tcpci = dev_id; ... if (tcpci->vendor_data->irq_handler) { ret = (*tcpci->vendor_data->irq_handler)(...); ... } ... } tcpci_init() { struct tcpci_vendor_data *vendor_data = &tcpci_rt1711h_data; // eg from devicetree compatible property ... if (vendor_data->init) { ret = (*vendor_data->init)(...); if (ret) return ret; } ... } > Q3. If there are IRQs defined in vendor defined registers, will an interface that is called in tcpci_irq be released for different vendors to implement. > So that they can handle their own IRQs first? If there are vendor specific interrupts, I would assume that vendor specific code will have to be called. Either the generic interrupt handler can call vendor specific code, or the vendor specific code handles the interrupt and calls the generic handler. I don't know at this point which one is better. > If the suggestion of Q2 is to copy tcpci.c to tcpci_rt1711h.c, then Q3 will not be a problem. > Q4. According to TCPCI Specification Revision 1.0, we should set DRP = 1 and role to Rp/Rp or Rd/Rd and set LOOK4CONNECTION command to start toggle. > So we modify the tcpci_start_drp_toggling in TCPCI driver as following. Here we write Rd/Rd and DRP = 0 simultaneously so that Rd/Rd takes effect. > Then we write DRP = 1 and set LOOK4CONNECTION command to start toggling. > SGTM. > static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc, > enum typec_cc_status cc) > { > +int ret = 0; > struct tcpci *tcpci = tcpc_to_tcpci(tcpc); > -unsigned int reg = TCPC_ROLE_CTRL_DRP; > +u32 reg = (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) | > +(TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT); > > switch (cc) { > default: > @@ -125,8 +672,19 @@ static int tcpci_start_drp_toggling(stru > TCPC_ROLE_CTRL_RP_VAL_SHIFT); > break; > } > - > -return regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg); > +ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg); > +if (ret < 0) > +return ret; > +mdelay(1); That is bad; you don't want to hold up teh system for that much. Try to use usleep_range(). > +reg |= TCPC_ROLE_CTRL_DRP; > +ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg); > +if (ret < 0) > +return ret; > +ret = regmap_write(tcpci->regmap, TCPC_COMMAND, > +TCPC_CMD_LOOK4CONNECTION); > +if (ret < 0) > +return ret; > +return 0; > } > > Q5. The tcpci_set_vbus in TCPCI driver uses command to control Sink/Source VBUS. > If our chip does not support power path, i.e. Sink & Source are controlled by other charger IC. Our chip will do nothing while setting these commands. > In the future TCPCI driver, will a framework be applied to notify these events. i.g. power_supply or notifier. > I would think so. Note that the driver is, at this point, fair game to change to make it work with your chip. The only condition is that a standard chip should still work, ie you should not make any changes which would cause the driver to _only_ work with your chip. Everything else is fair game. Thanks, Guenter