Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4880670rdb; Fri, 15 Sep 2023 15:38:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZakJjJ2xRLUCxLmq70c9DkwnQKAdqBeCqEVAo38HHAfTUBJyOBzR0lkC4515/SGNis2OY X-Received: by 2002:a05:6a00:2308:b0:68b:c562:da65 with SMTP id h8-20020a056a00230800b0068bc562da65mr3271343pfh.26.1694817481502; Fri, 15 Sep 2023 15:38:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694817481; cv=none; d=google.com; s=arc-20160816; b=NCJLij9V+F6oOLkDO16BAeGfz2DX6E+UZdh7HV62cnjNqHvlfgj+WqJ/5cAjUUaNU8 osX5PmOj9rG7cJtyLJVYO/ID0uCBUiQ6aTXfTa2pxQF/lnQPtOWmk+BBa+ZHV0rEND9Q ilxXaEFmNOIUbAcE4wUd+h0j6h8SJSmdpVbD/n3Il7fMxky28w7HKplaIjOqHerly9oP W7w0VTGk+Qh18ItMwMeoYYR/O9+6U4wddsFaMnkhr0xf1vQobz4Si1itiBPpi3RcbWCI 7X3FkHrKg6soZ+NSzyuaIbEIwvd5yqUQmveOFm/ERo5g/PgxVC/4frdYuEyFn26XSP/Z dZzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+1Xd700hLSDHmonk2L4kjhd7irhNKuoZ07XpBa2OtMg=; fh=jsONyd48T/SBAIgJlYgPqf3lKtg8wU6ujW0IesQqiZM=; b=VViZidG0hbixBYwznDr8We8nRBgDQGc+NTXjrBgT8wuFQN1GN84CwxqPcaCUko9A22 MeaS8L23nXlYUbmlZuYyvRYSJ+EWQDcdQ4CvWgET+jv3ciTcH28WuwsbYMo5ENCDCtGp oKcD5eJ42ogIH8CuppHmH4DZr39dIhK2JVu/5eRrw/NZf+t/+SsGubYNm+fFwJgg5KP9 XxnKKtxXSyLPPIeK0mRa6vm0jPeA8gkoUbPO9eSZcw0hEYp+FhlboAUNCENF7N7hjN6j JsbKu1eo7tuYD+V3p/3dzvjuj3tqMxE/hVSFdt/ca7pRpgjE8zvAczMw7ZevckF8RXDo e5UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Cd9C3N27; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id az1-20020a056a02004100b0056a1ed17deasi3864729pgb.675.2023.09.15.15.38.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 15:38:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Cd9C3N27; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 5441082F08C1; Fri, 15 Sep 2023 06:25:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235324AbjIONZC (ORCPT + 99 others); Fri, 15 Sep 2023 09:25:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235250AbjIONZB (ORCPT ); Fri, 15 Sep 2023 09:25:01 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7BA41FF1; Fri, 15 Sep 2023 06:24:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694784295; x=1726320295; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=xhawzRG3TJlJdNBVQGus4/qbVTl5JLFakyWXXMvo36U=; b=Cd9C3N27LDJ5yjcAGo/07VP1pGuLUWZLNm9liTtx0CX3Z4kKWGJI5JIZ R8icJhzDPtQP6WTUcZV/ErXyFC6EyX1YmEDTcfewXGwMAjfJZPgDElDNr jwhDmPmbhz75IYWvWuNhQLrygt/iJ0Obval+YauMmsBfhcHnkmwG9PKhu 7Q3RwHgtvoLpLzxwwrGXvq3FEBAMwZ6wC9zbLvmwzNxwY4Osr1/0bIev9 W682JVIgv+qn0gUnqujtpD1LvQW9DcPdtrpWl0eaJhGencfh0kNph5Lpi jARH2pUxtJP9an77tdqv3tvW8LhFyrmX8lLdV7c6ho/2cENrh82J6j63Q g==; X-IronPort-AV: E=McAfee;i="6600,9927,10834"; a="443307482" X-IronPort-AV: E=Sophos;i="6.02,149,1688454000"; d="scan'208";a="443307482" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2023 06:23:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10834"; a="780091501" X-IronPort-AV: E=Sophos;i="6.02,149,1688454000"; d="scan'208";a="780091501" Received: from kuha.fi.intel.com ([10.237.72.185]) by orsmga001.jf.intel.com with SMTP; 15 Sep 2023 06:23:22 -0700 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Fri, 15 Sep 2023 16:23:21 +0300 Date: Fri, 15 Sep 2023 16:23:21 +0300 From: Heikki Krogerus To: Javier Carrasco Cc: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bryan O'Donoghue , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: [PATCH v2 1/2] usb: typec: tps6598x: add reset gpio support Message-ID: References: <20230912-topic-tps6598x_reset-v2-0-02a12e2ec50a@wolfvision.net> <20230912-topic-tps6598x_reset-v2-1-02a12e2ec50a@wolfvision.net> <8937c928-1938-4864-08e1-25f88caadb9a@wolfvision.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8937c928-1938-4864-08e1-25f88caadb9a@wolfvision.net> X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 15 Sep 2023 06:25:00 -0700 (PDT) Hi, On Fri, Sep 15, 2023 at 03:17:28PM +0200, Javier Carrasco wrote: > On 15.09.23 14:57, Heikki Krogerus wrote: > > On Fri, Sep 15, 2023 at 02:23:48PM +0200, Javier Carrasco wrote: > >> The TPS6598x PD controller provides an active-high hardware reset input > >> that reinitializes all device settings. If it is not grounded by > >> design, the driver must be able to de-assert it in order to initialize > >> the device. > >> > >> The PD controller is not ready for registration right after the reset > >> de-assertion and a delay must be introduced in that case. According to > >> TI, the delay can reach up to 1000 ms [1], which is in line with the > >> experimental results obtained with a TPS65987D. > >> > >> Add a GPIO descriptor for the reset signal and basic reset management > >> for initialization and suspend/resume. > >> > >> [1] https://e2e.ti.com/support/power-management-group/power-management/ > >> f/power-management-forum/1269856/tps65987d-tps65987d-reset-de-assert- > >> to-normal-operation/4809389#4809389 > >> > >> Signed-off-by: Javier Carrasco > >> Reviewed-by: Bryan O'Donoghue Reviewed-by: Heikki Krogerus > >> --- > >> drivers/usb/typec/tipd/core.c | 20 ++++++++++++++++++++ > >> 1 file changed, 20 insertions(+) > >> > >> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c > >> index 37b56ce75f39..3068ef300073 100644 > >> --- a/drivers/usb/typec/tipd/core.c > >> +++ b/drivers/usb/typec/tipd/core.c > >> @@ -8,6 +8,7 @@ > >> > >> #include > >> #include > >> +#include > >> #include > >> #include > >> #include > >> @@ -43,6 +44,9 @@ > >> /* TPS_REG_SYSTEM_CONF bits */ > >> #define TPS_SYSCONF_PORTINFO(c) ((c) & 7) > >> > >> +/* reset de-assertion to ready for operation */ > >> +#define SETUP_MS 1000 > >> + > >> enum { > >> TPS_PORTINFO_SINK, > >> TPS_PORTINFO_SINK_ACCESSORY, > >> @@ -86,6 +90,7 @@ struct tps6598x { > >> struct mutex lock; /* device lock */ > >> u8 i2c_protocol:1; > >> > >> + struct gpio_desc *reset; > >> struct typec_port *port; > >> struct typec_partner *partner; > >> struct usb_pd_identity partner_identity; > >> @@ -717,6 +722,13 @@ static int tps6598x_probe(struct i2c_client *client) > >> mutex_init(&tps->lock); > >> tps->dev = &client->dev; > >> > >> + tps->reset = devm_gpiod_get_optional(tps->dev, "reset", GPIOD_OUT_LOW); > >> + if (IS_ERR(tps->reset)) > >> + return dev_err_probe(tps->dev, PTR_ERR(tps->reset), > >> + "failed to get reset GPIO\n"); > >> + if (tps->reset) > >> + msleep(SETUP_MS); > >> + > >> tps->regmap = devm_regmap_init_i2c(client, &tps6598x_regmap_config); > >> if (IS_ERR(tps->regmap)) > >> return PTR_ERR(tps->regmap); > >> @@ -892,6 +904,9 @@ static void tps6598x_remove(struct i2c_client *client) > >> tps6598x_disconnect(tps, 0); > >> typec_unregister_port(tps->port); > >> usb_role_switch_put(tps->role_sw); > >> + > >> + if (tps->reset) > >> + gpiod_set_value_cansleep(tps->reset, 1); > > > > Do you need that "if (tps->reset)" in this case? That function is NULL safe, > > right? > > > The function makes use of the VALIDATE_DESC_VOID macro to make it NULL > safe, but this macro also calls pr_warn if the descriptor is NULL and I > do not want to add warnings for an optional property that did not exist > before because it could be confusing. But if that is the desired > behavior, I will remove the checks. No, I don't want noise either. > >> } > >> > >> static int __maybe_unused tps6598x_suspend(struct device *dev) > >> @@ -902,6 +917,8 @@ static int __maybe_unused tps6598x_suspend(struct device *dev) > >> if (tps->wakeup) { > >> disable_irq(client->irq); > >> enable_irq_wake(client->irq); > >> + } else if (tps->reset) { > >> + gpiod_set_value_cansleep(tps->reset, 1); > >> } > >> > >> if (!client->irq) > >> @@ -918,6 +935,9 @@ static int __maybe_unused tps6598x_resume(struct device *dev) > >> if (tps->wakeup) { > >> disable_irq_wake(client->irq); > >> enable_irq(client->irq); > >> + } else if (tps->reset) { > >> + gpiod_set_value_cansleep(tps->reset, 0); > >> + msleep(SETUP_MS); > >> } > >> > >> if (!client->irq) > >> > >> -- > >> 2.39.2 thanks, -- heikki