Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5860857rdb; Sun, 17 Sep 2023 16:21:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwecR6gJY3CqyjhQvDcGCmgWWKyD9L4xMiYD07s1Sv8BxhRjG4W32tU+wQTnOWe4uV6p5w X-Received: by 2002:a05:6830:110e:b0:6b9:cf84:8cdd with SMTP id w14-20020a056830110e00b006b9cf848cddmr8782498otq.24.1694992869644; Sun, 17 Sep 2023 16:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694992869; cv=none; d=google.com; s=arc-20160816; b=hqmcVmDJCm6IKb8OU7exdgWbTgxiW6HOzWGJfxqMgnItIPZKXSiVS7U1SJEBlveWiY Z64dDcDLcjCGglQeQHZRmcqU4LGw8HsiDKo7AimeZkH4j5QBApfUDNUO+52GcfVyycLZ CtPi3Miem1z2p8GTqp50HD6N+n9wdOIYwaBHlkZgAVdsJL/ict8NBxCop+b+wP1viatC Y05cRnhP7s8l52xfZoixAj3T1SDZWtmWpwwVVRMHRpIlR784fvtgt47hXuYXfiSvNlKX 1lY7NadKszdHPppCxVGG6YHDryf9B9fvOTTUhs30XmCNy7y2RQDTvmsPRi8kO7i4Ec3t TbzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=V3y8c1achGK+WQ5g0X4obcawzUgKoXn6NXo4Tvawvo4=; fh=I0Lzq3m/LIxJ51N7jPTHUv8eE5jJdt/R03iLk7hWxA8=; b=MlMN8Xp7UyabvtpNryEZynr/a4bfnHeE1a3r8nr0u51b4ZKON2I2bIvo3FtTDC8vCm 1hK3GKuszSdV9SuoOnhs2AItz/YqMaYIljGvMaGiBytzGYShZTMaPdir53bBpPY8SpDQ 2n9wH+RfI6Qps5JI7wRyUFQZA22Spg5G4WMP+gLsNftyr5FeKQlNz99Sjf04wxlgyQ21 rbGjgxgANoeEOVZ8ee+npkoB4OkhtCEyOxqs238ffDrfxtunVirXto+/pszLLClCKYPM yXxTJxOoOBf5c3ut+CCzr/q/whdxs0tYH7a9pgCVRc5LazekYcVPErY2GxtQ+gG9+Y/m e3bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CctofdMv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id n126-20020a632784000000b0057762236debsi6940146pgn.546.2023.09.17.16.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 16:21:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CctofdMv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id DCA9B81F378D; Sun, 17 Sep 2023 08:29:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235772AbjIQP2B (ORCPT + 99 others); Sun, 17 Sep 2023 11:28:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233257AbjIQP12 (ORCPT ); Sun, 17 Sep 2023 11:27:28 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F05A188; Sun, 17 Sep 2023 08:27:22 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-404573e6c8fso36714015e9.1; Sun, 17 Sep 2023 08:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694964441; x=1695569241; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V3y8c1achGK+WQ5g0X4obcawzUgKoXn6NXo4Tvawvo4=; b=CctofdMvKInfUHMp8wksY8ygDmJKGvzGshQ4iLysJSoFvv9LXkexqJOjtoxBgffCNh RiYvgGNDlKl4AuiLWoTx0ZE9DH1uylh1phz2QAgTndpLybB9DQK8u09AlkRVc2SfmWAd 89b3QGg0U4oZXN13tHycrFDupTt4STrBEhC1X8VZhq9/YGJtvuFuw+MTquF1Ok5Ed6Ee WCs9a64eDFmMOLvHQ9W0cApg558aY6bKlxWEQ9Xt29JV++oCX75vAnK5pu3k0AjevBZT l/zQnGa2GM4lAtWpT9FBj4wqxVvjdh5Nv+yTCLarxquKagaFmdvaUeSNBxn0ipmI5IOH 02kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694964441; x=1695569241; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V3y8c1achGK+WQ5g0X4obcawzUgKoXn6NXo4Tvawvo4=; b=QhnhpUryitCjJUfcmODxzt8PpWU61XNJfO27D57rqRnqJEKNnAw45qJVmfkMxtRs+e bfchqLK0KhuKpP9qpmXp5Y+DicShDo5MqoQ02++4HftI78q9b/GpSY2D7G2aB6LKYhc5 z4yT3LqVrfPYodMqJLmiCOPrY0R38riQCIkiFulv1o/399FVZFbnVSHDa+Yyt6DUDPGE 75Ki1CKlNoPedwBPpkmuYNjuDQKSoH0uoIjM25xMpgPe+E438Xs9s9SrXIkDeJVmtFOR 56mhkIT291Q3Uueqclkz07tkBX7+jSHMenjXCi265KOW988arSwjwR7svqBlUJ/e8MvP q9SA== X-Gm-Message-State: AOJu0YwUNotOW08KxsynRm8NNyCa+Amcp3q+mKM8zR7i0Q3Kw4YhrJ70 pDiazBDTszjMg42O3l1VSxA= X-Received: by 2002:a1c:ed10:0:b0:401:daf2:2737 with SMTP id l16-20020a1ced10000000b00401daf22737mr6521093wmh.30.1694964440875; Sun, 17 Sep 2023 08:27:20 -0700 (PDT) Received: from localhost.localdomain ([5.45.134.53]) by smtp.gmail.com with ESMTPSA id j23-20020a05600c489700b003fe15ac0934sm7388865wmp.1.2023.09.17.08.27.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 08:27:20 -0700 (PDT) From: Abdel Alkuor To: heikki.krogerus@linux.intel.com, krzysztof.kozlowski+dt@linaro.org, bryan.odonoghue@linaro.org Cc: gregkh@linuxfoundation.org, robh+dt@kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org, linux-kernel@vger.kernel.org, abdelalkuor@geotab.com, Abdel Alkuor Subject: [PATCH v5 02/15] USB: typec: Add cmd timeout and response delay Date: Sun, 17 Sep 2023 11:26:26 -0400 Message-Id: <20230917152639.21443-3-alkuor@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230917152639.21443-1-alkuor@gmail.com> References: <20230917152639.21443-1-alkuor@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Sun, 17 Sep 2023 08:29:20 -0700 (PDT) Some commands in tps25750 take longer than 1 second to complete, and some responses need some delay before the result becomes available. Signed-off-by: Abdel Alkuor --- drivers/usb/typec/tipd/core.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 37b56ce75f39..a8aee4e1aeba 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -284,7 +284,8 @@ static void tps6598x_disconnect(struct tps6598x *tps, u32 status) static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd, size_t in_len, u8 *in_data, - size_t out_len, u8 *out_data) + size_t out_len, u8 *out_data, + u32 cmd_timeout_ms, u32 res_delay_ms) { unsigned long timeout; u32 val; @@ -307,8 +308,7 @@ static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd, if (ret < 0) return ret; - /* XXX: Using 1s for now, but it may not be enough for every command. */ - timeout = jiffies + msecs_to_jiffies(1000); + timeout = jiffies + msecs_to_jiffies(cmd_timeout_ms); do { ret = tps6598x_read32(tps, TPS_REG_CMD1, &val); @@ -321,6 +321,9 @@ static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd, return -ETIMEDOUT; } while (val); + /* some commands require delay for the result to be available */ + mdelay(res_delay_ms); + if (out_len) { ret = tps6598x_block_read(tps, TPS_REG_DATA1, out_data, out_len); @@ -354,7 +357,7 @@ static int tps6598x_dr_set(struct typec_port *port, enum typec_data_role role) mutex_lock(&tps->lock); - ret = tps6598x_exec_cmd(tps, cmd, 0, NULL, 0, NULL); + ret = tps6598x_exec_cmd(tps, cmd, 0, NULL, 0, NULL, 1000, 0); if (ret) goto out_unlock; @@ -384,7 +387,7 @@ static int tps6598x_pr_set(struct typec_port *port, enum typec_role role) mutex_lock(&tps->lock); - ret = tps6598x_exec_cmd(tps, cmd, 0, NULL, 0, NULL); + ret = tps6598x_exec_cmd(tps, cmd, 0, NULL, 0, NULL, 1000, 0); if (ret) goto out_unlock; @@ -654,7 +657,10 @@ static int cd321x_switch_power_state(struct tps6598x *tps, u8 target_state) if (state == target_state) return 0; - ret = tps6598x_exec_cmd(tps, "SSPS", sizeof(u8), &target_state, 0, NULL); + ret = tps6598x_exec_cmd(tps, "SSPS", + sizeof(u8), &target_state, + 0, NULL, + 1000, 0); if (ret) return ret; -- 2.34.1