From patchwork Wed May 22 18:31:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10956469 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD4CA1708 for ; Wed, 22 May 2019 18:33:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E8211FFD8 for ; Wed, 22 May 2019 18:33:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 918DB1FFE4; Wed, 22 May 2019 18:33:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AA0D1FFD8 for ; Wed, 22 May 2019 18:33:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729565AbfEVSdj (ORCPT ); Wed, 22 May 2019 14:33:39 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:33538 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729483AbfEVSdi (ORCPT ); Wed, 22 May 2019 14:33:38 -0400 Received: by mail-pg1-f194.google.com with SMTP id h17so1760396pgv.0; Wed, 22 May 2019 11:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+s+DmZIyyyo+qkPPae5sUO6k73P9MlEz1b0ln8T2CEM=; b=r+8UnKWWKQu3xDRM6dqq6H2tx3R1LmjWojpjKqrUh6GPjkJUY6MZoP6748LjDguJCc 2E5RbdyAJn98t0m91DEX/iVmGS6TXVVGp5frSHuMhkdlyDCPo3NJl142OJsa9FWk8Ojj lhoQDHuFMtcElYn4Qq6ndtAplQDO9SAn7vG+QQw8wgpWLkfln2XUwKhNvjIuwDJwKRvm UR6FPDcPdOqOFduxfl/1KkuwbWHR2S14P0d6RkJSINwfm8F77rxPyWee0KUMNaCr2L1A UOWnHrrDpIer9G4ZCJBQkK2CESnWQw/30JhYPl1WZ2LI07Gj18WoEOqADXlOXAfYoTg/ 6ZZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+s+DmZIyyyo+qkPPae5sUO6k73P9MlEz1b0ln8T2CEM=; b=ic7NFKQO5wQvDNZUIxeZrAX6806CdBNG7B2bLG8vusROZMgjG1XkP+svSNcERIupB0 XzZTNrl+lqMbNqlZj9yRidkLk0yejnqf1irvqvbXcGECTueRVwmeGtTYszDd+Vw++Qax c43O5Co//7hYWxfiNKB3HRvVUQEeMZ1iINoyztA1bjhk6/x6NyIp2w8aklqLLuZazb11 EOX4MU+AoTaXjS0QXAIjQE/ZMlu6gERL0orK8pDrOoNjZdicUdQQ4aaN/eFLPPUhRE+q f3JgT4CLCaGypArNkLbT7TM04BZhzYdzqkLHdmZwqu2ak1QpttPf/BO7CEL9I+L7P+J1 ke+w== X-Gm-Message-State: APjAAAUx8C/tInix8/bAa97VNNsmzeX4RQJQpqwAX5KEDSNaoTHttvkm s81ZMyB1ojgKhQqnpeMWgS5wr/61ITQ= X-Google-Smtp-Source: APXvYqy126bYA6YOJMC0w/jX7oEZuowWtzQPG1iadAoJ5sDno3uSMLsYfnkBphFc+dHo4NW4r9QIMA== X-Received: by 2002:aa7:8683:: with SMTP id d3mr52001783pfo.145.1558550018258; Wed, 22 May 2019 11:33:38 -0700 (PDT) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id c76sm46138294pfc.43.2019.05.22.11.33.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:33:37 -0700 (PDT) From: Ajay Gupta X-Google-Original-From: Ajay Gupta To: heikki.krogerus@linux.intel.com, wsa@the-dreams.de Cc: linux-usb@vger.kernel.org, linux-i2c@vger.kernel.org, Ajay Gupta Subject: [PATCH v3 1/5] i2c: nvidia-gpu: refactor master_xfer Date: Wed, 22 May 2019 11:31:38 -0700 Message-Id: <20190522183142.11061-2-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522183142.11061-1-ajayg@nvidia.com> References: <20190522183142.11061-1-ajayg@nvidia.com> X-NVConfidentiality: public Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ajay Gupta Added a local variable "send_stop" to simplify "goto" statements. The "send_stop" handles below two case 1) When first i2c start fails and so i2c stop is not sent before exiting 2) When i2c stop failed after all transfers and we do not need to send another stop before exiting. Signed-off-by: Ajay Gupta Reviewed-by: Wolfram Sang --- Changes from v2->v3: None drivers/i2c/busses/i2c-nvidia-gpu.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c b/drivers/i2c/busses/i2c-nvidia-gpu.c index 1c8f708f212b..2d9561ec2320 100644 --- a/drivers/i2c/busses/i2c-nvidia-gpu.c +++ b/drivers/i2c/busses/i2c-nvidia-gpu.c @@ -169,6 +169,7 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap, { struct gpu_i2c_dev *i2cd = i2c_get_adapdata(adap); int status, status2; + bool send_stop = true; int i, j; /* @@ -182,37 +183,41 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap, /* gpu_i2c_read has implicit start */ status = gpu_i2c_read(i2cd, msgs[i].buf, msgs[i].len); if (status < 0) - goto stop; + goto exit; } else { u8 addr = i2c_8bit_addr_from_msg(msgs + i); status = gpu_i2c_start(i2cd); if (status < 0) { if (i == 0) - return status; - goto stop; + send_stop = false; + goto exit; } status = gpu_i2c_write(i2cd, addr); if (status < 0) - goto stop; + goto exit; for (j = 0; j < msgs[i].len; j++) { status = gpu_i2c_write(i2cd, msgs[i].buf[j]); if (status < 0) - goto stop; + goto exit; } } } status = gpu_i2c_stop(i2cd); - if (status < 0) - return status; + if (status < 0) { + send_stop = false; + goto exit; + } return i; -stop: - status2 = gpu_i2c_stop(i2cd); - if (status2 < 0) - dev_err(i2cd->dev, "i2c stop failed %d\n", status2); +exit: + if (send_stop) { + status2 = gpu_i2c_stop(i2cd); + if (status2 < 0) + dev_err(i2cd->dev, "i2c stop failed %d\n", status2); + } return status; } From patchwork Wed May 22 18:31:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10956471 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 40A1C912 for ; Wed, 22 May 2019 18:33:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31DB21FFD8 for ; Wed, 22 May 2019 18:33:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2600B1FFE4; Wed, 22 May 2019 18:33:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBB281FFD8 for ; Wed, 22 May 2019 18:33:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729641AbfEVSdk (ORCPT ); Wed, 22 May 2019 14:33:40 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40577 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729483AbfEVSdk (ORCPT ); Wed, 22 May 2019 14:33:40 -0400 Received: by mail-pf1-f196.google.com with SMTP id u17so1765175pfn.7; Wed, 22 May 2019 11:33:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YoK+jgaU1pOd7oo6QR907tculPG9SXxwXBTXzfSOuBU=; b=iVQsKyeUq9yL72EEQ5/lIWNKVEYgwxL46XN72hG1z90cliDdCSSaFbPRYr7i2UvzhV c2/sTQ672TaJNo2sEsO3aUsTVep/rFYYD/zVRDzfrmaXYTCqBVdrmq7o+CgmW482gI0P ItEcFRbWySaEkXHksrenbAh92Ylir10djOsh+YgaLwQ1Fo0NJS03yITVMeRyaEKL3x6B l1zFW3Bi6KNObiNjbAwPQDVrvtHbYOg7B4gaAY4f3If9MhILgxY6gmYqD1VtHztyiZCW WsyfHc2uBSgEy2ctPijhVZzKvArlg8KeXqokRHRfy3hKOBLsxHRtpFfsPPTcRdCqHnxP +n6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YoK+jgaU1pOd7oo6QR907tculPG9SXxwXBTXzfSOuBU=; b=hO9zt7scV33R3on5Cev3UMwJTkz5YwExmGQaiHMOH/XXhgxXFvTfe2FeV7miJ2cMpX 4KJNKU4NgdpD9Ff6YJ6r40Dwb0t9YpJZRszd+zw2uqJnP4LpXAwKIwcQLXL5S31IIqbz VvhFQmhzvrE3tGVXQNS18hmthB3BO28O0LV3BkYmQpwKBJ87UMXo1y3/v7atKqy4H22k zl5NmQZ4ErxUqm6wbLbgMqGUM2FqCWnguq0U1MAcY3dzWdhvJwNOuhSznUp1gmPVChGb Mv3e5VEKy5jc9FbAlbqbB1dYIBtaMzUtyYQlD/zjntG7OwCM8sVj5hk3n0gu/QieN2ca YobA== X-Gm-Message-State: APjAAAUYVi31F06WiWFl7cbqeBcfRchDlH0/AfVq7fZ8iID8wCWE32AB Uu/PCVmwvb9/LYtoieYlIKc= X-Google-Smtp-Source: APXvYqx/BBjjG2Eu83fRK1vK1iv/YqOnWWwzLpg801zivaQ+9i7m+QApV1UJub6N+MTqG4oSwpqA3Q== X-Received: by 2002:a62:ed09:: with SMTP id u9mr98806615pfh.23.1558550019516; Wed, 22 May 2019 11:33:39 -0700 (PDT) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id c76sm46138294pfc.43.2019.05.22.11.33.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:33:38 -0700 (PDT) From: Ajay Gupta X-Google-Original-From: Ajay Gupta To: heikki.krogerus@linux.intel.com, wsa@the-dreams.de Cc: linux-usb@vger.kernel.org, linux-i2c@vger.kernel.org, Ajay Gupta Subject: [PATCH v3 2/5] i2c: nvidia-gpu: add runtime pm support Date: Wed, 22 May 2019 11:31:39 -0700 Message-Id: <20190522183142.11061-3-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522183142.11061-1-ajayg@nvidia.com> References: <20190522183142.11061-1-ajayg@nvidia.com> X-NVConfidentiality: public Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ajay Gupta Enable runtime pm support with autosuspend delay of three second. This is to make sure I2C client device Cypress CCGx has completed all transaction. Signed-off-by: Ajay Gupta --- Changes from v1->v2: - Added __maybe_unused in gpu_i2c_suspend to avoid warning when CONFIG_PM is disabled. drivers/i2c/busses/i2c-nvidia-gpu.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c b/drivers/i2c/busses/i2c-nvidia-gpu.c index 2d9561ec2320..28fee85135ac 100644 --- a/drivers/i2c/busses/i2c-nvidia-gpu.c +++ b/drivers/i2c/busses/i2c-nvidia-gpu.c @@ -176,6 +176,7 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap, * The controller supports maximum 4 byte read due to known * limitation of sending STOP after every read. */ + pm_runtime_get_sync(i2cd->dev); for (i = 0; i < num; i++) { if (msgs[i].flags & I2C_M_RD) { /* program client address before starting read */ @@ -211,6 +212,8 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap, goto exit; } + pm_runtime_mark_last_busy(i2cd->dev); + pm_runtime_put_autosuspend(i2cd->dev); return i; exit: if (send_stop) { @@ -218,6 +221,8 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap, if (status2 < 0) dev_err(i2cd->dev, "i2c stop failed %d\n", status2); } + pm_runtime_mark_last_busy(i2cd->dev); + pm_runtime_put_autosuspend(i2cd->dev); return status; } @@ -337,6 +342,11 @@ static int gpu_i2c_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto del_adapter; } + pm_runtime_set_autosuspend_delay(&pdev->dev, 3000); + pm_runtime_use_autosuspend(&pdev->dev); + pm_runtime_put_autosuspend(&pdev->dev); + pm_runtime_allow(&pdev->dev); + return 0; del_adapter: @@ -350,10 +360,16 @@ static void gpu_i2c_remove(struct pci_dev *pdev) { struct gpu_i2c_dev *i2cd = dev_get_drvdata(&pdev->dev); + pm_runtime_get_noresume(i2cd->dev); i2c_del_adapter(&i2cd->adapter); pci_free_irq_vectors(pdev); } +static __maybe_unused int gpu_i2c_suspend(struct device *dev) +{ + return 0; +} + static __maybe_unused int gpu_i2c_resume(struct device *dev) { struct gpu_i2c_dev *i2cd = dev_get_drvdata(dev); @@ -362,7 +378,8 @@ static __maybe_unused int gpu_i2c_resume(struct device *dev) return 0; } -static UNIVERSAL_DEV_PM_OPS(gpu_i2c_driver_pm, NULL, gpu_i2c_resume, NULL); +static UNIVERSAL_DEV_PM_OPS(gpu_i2c_driver_pm, gpu_i2c_suspend, gpu_i2c_resume, + NULL); static struct pci_driver gpu_i2c_driver = { .name = "nvidia-gpu", From patchwork Wed May 22 18:31:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10956475 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EEB361708 for ; Wed, 22 May 2019 18:33:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFA3D1FFD8 for ; Wed, 22 May 2019 18:33:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0E231FFD9; Wed, 22 May 2019 18:33:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AC351FFE5 for ; Wed, 22 May 2019 18:33:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729649AbfEVSdm (ORCPT ); Wed, 22 May 2019 14:33:42 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:34182 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729483AbfEVSdl (ORCPT ); Wed, 22 May 2019 14:33:41 -0400 Received: by mail-pf1-f196.google.com with SMTP id n19so1785387pfa.1; Wed, 22 May 2019 11:33:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u0JGhVsoc2MieyAr4lI6AVHWnT0CzecbZjFmC3a/a7E=; b=Hzyvgh/5GPSYJz6KYvOnHjJyMEoteMMbFd0k2Q45/NMf6+2GwQx09TpMLxMj32qrgL jhGY0l0+iiprx8tjNBJA5r9K/O837k3585n54DWZOE0iYf6A2DI7DLcJEgl4TeMXNk3q +JlXVUXEm+jDWKVCaiN5tHJjewqcVV7aHvL0NryIrRpKQkt/3gkPSptPubWfLyMMRPqV Y0j+Jb2H3TmjzzqJbB0MCv518XFMrGhJHgjKJ81ZKuUaSAn1b8XiLcKHvKvQ4jyCNdsw OaHuE2FLpa03A5H+adfZcthvefxtQTepRm8gMfUDV/mF5L1P5eWMoM63Pubp9kF7fxGi 0xYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=u0JGhVsoc2MieyAr4lI6AVHWnT0CzecbZjFmC3a/a7E=; b=OFaS2mrY/AykAqunRbAnY5kWy5mK9PcnRsMfoA13mZM/aOV1NM81TSEYN/jn2/6jn7 PLPZVgpv6WV1sQ5DOWcCAEC6COJjOO+6TuXv21J3RSu8f2X812snYeRyQkUODKMmOHeT LGBKLsNu7iQu5fQipuG6x2E0j4sUdJMZkZFFKrAfZDBRegnIAQBeWXX/KmWAsbkTShBl x5bIhU6V3WCK4pTvDCIQ3JBRhhS56BrVJQ8T4ge29V6Wzvi91qQ+gdc/k9ti7gV/A1+y ZVYVr4APEYDv9vppyNIxNtf6xiPUNv9c+vYDR3OXYZxsjmnz/qEGNMtcXH0FyeUXkSNl 4wnA== X-Gm-Message-State: APjAAAWA0kKnVp9HjpEyTdwDLlKHgY+NIX+kIfWhqKTkxOfJkxAFP7Db k1Hok40k8AYSNLESN3V/J0o= X-Google-Smtp-Source: APXvYqzvKyopck+vjCQshKq33RMAQc4ughKea+gQ6y0DA1xVZG0e2Uv0gbsZfc1FLRQ8zsPxJoJWxw== X-Received: by 2002:a62:7a8f:: with SMTP id v137mr96739769pfc.243.1558550020553; Wed, 22 May 2019 11:33:40 -0700 (PDT) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id c76sm46138294pfc.43.2019.05.22.11.33.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:33:39 -0700 (PDT) From: Ajay Gupta X-Google-Original-From: Ajay Gupta To: heikki.krogerus@linux.intel.com, wsa@the-dreams.de Cc: linux-usb@vger.kernel.org, linux-i2c@vger.kernel.org, Ajay Gupta Subject: [PATCH v3 3/5] usb: typec: ucsi: ccg: enable runtime pm support Date: Wed, 22 May 2019 11:31:40 -0700 Message-Id: <20190522183142.11061-4-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522183142.11061-1-ajayg@nvidia.com> References: <20190522183142.11061-1-ajayg@nvidia.com> X-NVConfidentiality: public Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ajay Gupta The change enables runtime pm support to UCSI CCG driver. Added ucsi_resume() function to enable notification after system reusme. Exported both ucsi_resume() and ucsi_send_command() symbols in ucsi.c for modular build. Signed-off-by: Ajay Gupta --- Changes from v2->v3 : None - Fixed comments from Heikki by adding ucsi_resume() in ucsi.c and used it from ucsi_ccg.c - Also removed ucsi_ccg_runtime_idle() and ucsi_ccg_suspend() which were stubs and not needed. - We still need stub fucntion ucsi_ccg_runtime_suspend for runtime pm functionality drivers/usb/typec/ucsi/ucsi.c | 10 ++++++++ drivers/usb/typec/ucsi/ucsi.h | 1 + drivers/usb/typec/ucsi/ucsi_ccg.c | 38 +++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 7850b851cecd..ba288b964dc8 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -206,7 +206,17 @@ int ucsi_send_command(struct ucsi *ucsi, struct ucsi_control *ctrl, return ret; } +EXPORT_SYMBOL_GPL(ucsi_send_command); +int ucsi_resume(struct ucsi *ucsi) +{ + struct ucsi_control ctrl; + + /* Restore UCSI notification enable mask after system resume */ + UCSI_CMD_SET_NTFY_ENABLE(ctrl, UCSI_ENABLE_NTFY_ALL); + return ucsi_send_command(ucsi, &ctrl, NULL, 0); +} +EXPORT_SYMBOL_GPL(ucsi_resume); /* -------------------------------------------------------------------------- */ void ucsi_altmode_update_active(struct ucsi_connector *con) diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 1e2981aef629..de87d0b8319d 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -430,6 +430,7 @@ int ucsi_send_command(struct ucsi *ucsi, struct ucsi_control *ctrl, void *retval, size_t size); void ucsi_altmode_update_active(struct ucsi_connector *con); +int ucsi_resume(struct ucsi *ucsi); #if IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE) struct typec_altmode * diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index 9d46aa9e4e35..b15bc6c29c46 100644 --- a/drivers/usb/typec/ucsi/ucsi_ccg.c +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include "ucsi.h" @@ -210,6 +212,7 @@ static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len) if (quirks && quirks->max_read_len) max_read_len = quirks->max_read_len; + pm_runtime_get_sync(uc->dev); while (rem_len > 0) { msgs[1].buf = &data[len - rem_len]; rlen = min_t(u16, rem_len, max_read_len); @@ -218,12 +221,14 @@ static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len) status = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); if (status < 0) { dev_err(uc->dev, "i2c_transfer failed %d\n", status); + pm_runtime_put_sync(uc->dev); return status; } rab += rlen; rem_len -= rlen; } + pm_runtime_put_sync(uc->dev); return 0; } @@ -249,13 +254,16 @@ static int ccg_write(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len) msgs[0].len = len + sizeof(rab); msgs[0].buf = buf; + pm_runtime_get_sync(uc->dev); status = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); if (status < 0) { dev_err(uc->dev, "i2c_transfer failed %d\n", status); + pm_runtime_put_sync(uc->dev); kfree(buf); return status; } + pm_runtime_put_sync(uc->dev); kfree(buf); return 0; } @@ -1134,6 +1142,10 @@ static int ucsi_ccg_probe(struct i2c_client *client, if (status) dev_err(uc->dev, "cannot create sysfs group: %d\n", status); + pm_runtime_set_active(uc->dev); + pm_runtime_enable(uc->dev); + pm_runtime_idle(uc->dev); + return 0; } @@ -1143,6 +1155,7 @@ static int ucsi_ccg_remove(struct i2c_client *client) cancel_work_sync(&uc->work); ucsi_unregister_ppm(uc->ucsi); + pm_runtime_disable(uc->dev); free_irq(uc->irq, uc); sysfs_remove_group(&uc->dev->kobj, &ucsi_ccg_attr_group); @@ -1155,9 +1168,34 @@ static const struct i2c_device_id ucsi_ccg_device_id[] = { }; MODULE_DEVICE_TABLE(i2c, ucsi_ccg_device_id); +static int ucsi_ccg_resume(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct ucsi_ccg *uc = i2c_get_clientdata(client); + + return ucsi_resume(uc->ucsi); +} + +static int ucsi_ccg_runtime_suspend(struct device *dev) +{ + return 0; +} + +static int ucsi_ccg_runtime_resume(struct device *dev) +{ + return 0; +} + +static const struct dev_pm_ops ucsi_ccg_pm = { + .resume = ucsi_ccg_resume, + .runtime_suspend = ucsi_ccg_runtime_suspend, + .runtime_resume = ucsi_ccg_runtime_resume, +}; + static struct i2c_driver ucsi_ccg_driver = { .driver = { .name = "ucsi_ccg", + .pm = &ucsi_ccg_pm, }, .probe = ucsi_ccg_probe, .remove = ucsi_ccg_remove, From patchwork Wed May 22 18:31:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10956473 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4A9FF912 for ; Wed, 22 May 2019 18:33:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A9961FFD8 for ; Wed, 22 May 2019 18:33:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EB6B1FFE4; Wed, 22 May 2019 18:33:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C140B1FFD8 for ; Wed, 22 May 2019 18:33:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729654AbfEVSdm (ORCPT ); Wed, 22 May 2019 14:33:42 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35955 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729642AbfEVSdm (ORCPT ); Wed, 22 May 2019 14:33:42 -0400 Received: by mail-pf1-f194.google.com with SMTP id v80so1779604pfa.3; Wed, 22 May 2019 11:33:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bgPRiLK8QP/T5A6kfBoroSy+Bu11YHpBXlua43RT2NQ=; b=e+zPn32QXsKPmQ/7D7bECU/4Az9Hi7QfN7JUxfpYiZNM/ZWteTYirGa1cuujwH0GA2 qmFs0G/rmN+nVCjSx4fXLYmK1M/pCFtw/Yp04DPbrLoUu5kNF63NGh72ZGo25u58n5L3 LWyJtrvxlHsJTXY+ygdXESdVjU5mkFQNHQWEHNse+BYi3NzNNHF9cDz3iiVkQ8q64A93 jNRwh8N0XGq80voL5w7Uj4QFjkix1GH9K6AZUgT1Vs3xNpXO8jHRojtS02SJRbLaj/Mn ZZwMidin+kCTaiYxG16ZXOw/3ZwhPeZ5AEim/y//AAzUFNE7xna972/Pc94e7LNk/El8 6tXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bgPRiLK8QP/T5A6kfBoroSy+Bu11YHpBXlua43RT2NQ=; b=Um/xAJ8Lnjp6RDtSkLj16pOJP5h/rGcuuV8x9OOO/9FicBODZQSykehdOWBjduwF69 5hjKSeAf7uO0OWQ2VUsVPA44aMtEUcKKmdfghTtR3kIEso1cTuhA3pgWMYB/AWrfHUgS 5XJ+buQtAmMeapF9d4h4mzlOscBhq5YgxdN9GQoCEi6qkfEgTKLlNb0zkRbh0aoqydL7 o60jH0djAYWsIKeK7sOQEZ3gaHj6pCJjhxAulurHTfSesjHuCDrOK2Fhk1fzBFKrXg0k 4BJeSiKRj54I+26BjQWH1zqeP6Z+MRPLwoLx+CXY/fYtvbq7aWup7M7o5H9ppo6prd8f NM/w== X-Gm-Message-State: APjAAAVenpITvNp9GKdwF9ObHgimNOD67E/0S7tPUMtdL6iXIVhNGFs3 DKUKle9v2U69ld1A8tDLiDM= X-Google-Smtp-Source: APXvYqySi/2VfSyiJpm9ocnmBKgk7wbm8qrON+qxkyhUdf+dq/G4EHWrXsTsqoSMaOl0zk87rkwYSg== X-Received: by 2002:a62:1ec3:: with SMTP id e186mr51257253pfe.197.1558550021595; Wed, 22 May 2019 11:33:41 -0700 (PDT) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id c76sm46138294pfc.43.2019.05.22.11.33.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:33:40 -0700 (PDT) From: Ajay Gupta X-Google-Original-From: Ajay Gupta To: heikki.krogerus@linux.intel.com, wsa@the-dreams.de Cc: linux-usb@vger.kernel.org, linux-i2c@vger.kernel.org, Ajay Gupta Subject: [PATCH v3 4/5] i2c: nvidia-gpu: resume ccgx i2c client Date: Wed, 22 May 2019 11:31:41 -0700 Message-Id: <20190522183142.11061-5-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522183142.11061-1-ajayg@nvidia.com> References: <20190522183142.11061-1-ajayg@nvidia.com> X-NVConfidentiality: public Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ajay Gupta Cypress USB Type-C CCGx controller firmware version 3.1.10 (which is being used in many NVIDIA GPU cards) has known issue of not triggering interrupt when a USB device is hot plugged to runtime resume the controller. If any GPU card gets latest kernel with runtime pm support but does not get latest fixed firmware then also it should continue to work and therefore a workaround is required to check for any connector change event The workaround is to request runtime resume of i2c client which is UCSI Cypress CCGx driver. CCG driver will call the ISR for any connector change event only if NVIDIA GPU has old CCG firmware with the known issue. Signed-off-by: Ajay Gupta Acked-by: Wolfram Sang --- Changes from v2->v3: None drivers/i2c/busses/i2c-nvidia-gpu.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c b/drivers/i2c/busses/i2c-nvidia-gpu.c index 28fee85135ac..957b39c9760f 100644 --- a/drivers/i2c/busses/i2c-nvidia-gpu.c +++ b/drivers/i2c/busses/i2c-nvidia-gpu.c @@ -51,6 +51,7 @@ struct gpu_i2c_dev { void __iomem *regs; struct i2c_adapter adapter; struct i2c_board_info *gpu_ccgx_ucsi; + struct i2c_client *ccgx_client; }; static void gpu_enable_i2c_bus(struct gpu_i2c_dev *i2cd) @@ -271,8 +272,6 @@ static const struct property_entry ccgx_props[] = { static int gpu_populate_client(struct gpu_i2c_dev *i2cd, int irq) { - struct i2c_client *ccgx_client; - i2cd->gpu_ccgx_ucsi = devm_kzalloc(i2cd->dev, sizeof(*i2cd->gpu_ccgx_ucsi), GFP_KERNEL); @@ -284,8 +283,8 @@ static int gpu_populate_client(struct gpu_i2c_dev *i2cd, int irq) i2cd->gpu_ccgx_ucsi->addr = 0x8; i2cd->gpu_ccgx_ucsi->irq = irq; i2cd->gpu_ccgx_ucsi->properties = ccgx_props; - ccgx_client = i2c_new_device(&i2cd->adapter, i2cd->gpu_ccgx_ucsi); - if (!ccgx_client) + i2cd->ccgx_client = i2c_new_device(&i2cd->adapter, i2cd->gpu_ccgx_ucsi); + if (!i2cd->ccgx_client) return -ENODEV; return 0; @@ -375,6 +374,13 @@ static __maybe_unused int gpu_i2c_resume(struct device *dev) struct gpu_i2c_dev *i2cd = dev_get_drvdata(dev); gpu_enable_i2c_bus(i2cd); + /* + * Runtime resume ccgx client so that it can see for any + * connector change event. Old ccg firmware has known + * issue of not triggering interrupt when a device is + * connected to runtime resume the controller. + */ + pm_request_resume(&i2cd->ccgx_client->dev); return 0; } From patchwork Wed May 22 18:31:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10956477 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4113A912 for ; Wed, 22 May 2019 18:33:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31D1A1FFD8 for ; Wed, 22 May 2019 18:33:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25F6A1FFE4; Wed, 22 May 2019 18:33:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F50B1FFD8 for ; Wed, 22 May 2019 18:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729656AbfEVSdo (ORCPT ); Wed, 22 May 2019 14:33:44 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:43380 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729642AbfEVSdo (ORCPT ); Wed, 22 May 2019 14:33:44 -0400 Received: by mail-pl1-f195.google.com with SMTP id gn7so1468479plb.10; Wed, 22 May 2019 11:33:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BhC9WeOPHtKzs6wF/OAOSfwtaNdebLL5sTld3iXl2vA=; b=u4UVkg2qDwlJs0wutP15S/yEDnSRvjLFKvMXuG50ItWQg6l9czyfVvSfq66iI8rS30 FdQPsjNufE+neb4C1mU4tGxRM18rLTpAIYxYUebQkFbBeWU0bXILiycRxZU4mSCF+BIY TE6F2aj6ZZtYdjCbByb+z/PHTtk4y/oisgvk5G32HPDaFVILHJ6lCsl61JaEZUcI3g3Q ml6k91j67m21yHA2RVbxB3iUFGxIzhjBlW34jyvoBsqkZ5Uaa1Veybv+b68h1i4Gboei zSnCDknBdqoBPZM3MWdd1r7oFb/udC4JvZU7RbqDLpr36P9WTWWPdluVx06ot+RQH6U9 2EUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BhC9WeOPHtKzs6wF/OAOSfwtaNdebLL5sTld3iXl2vA=; b=ZwXQzXQzKSBYcw6FYb+eNegtv9TTwkZ4hpLJzrL6G9ieRnEBKiTNMgHlwqE3YiVYBP 6RAVQYf48baDLKm0eqeRSlAMHIOpfMXMWrev9WJS//tsHG/BQnzeGbdObMNvGxjof5ne fMsvNXieDayE3VwJZo+G3AO8f83Lfr4P60z93rfJut7vOX8pXgJ8fwPhMoGCM5gpWX0O VIHWzlfjzv/geH8+Bqp/xIV3TTJaBnDdKu+vNRlI05bxKpUwtYhWnNr8UDaX8zc8m1Kn ZXjiDa5oOoEkUSkPNPLCCQwAxtTV+vNP1dAIz3S3mzTmgckLLc9IFOJBAOfjzve92DBL O0cw== X-Gm-Message-State: APjAAAUruQv0PlCcuYnjW1uL5tHNhaqrSiHUH8SkU2G495dLZoSUr+RU xVqT3h4Dj0GQWDn4QZ6eEUw= X-Google-Smtp-Source: APXvYqyuRpl17Tc/hzadvQGMSbZ69rhjVIhec/Fiw4ulJqhce5s3pg9qU3IKhYH6lQOFOSgZeTSXFQ== X-Received: by 2002:a17:902:f081:: with SMTP id go1mr44935634plb.211.1558550022639; Wed, 22 May 2019 11:33:42 -0700 (PDT) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id c76sm46138294pfc.43.2019.05.22.11.33.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:33:41 -0700 (PDT) From: Ajay Gupta X-Google-Original-From: Ajay Gupta To: heikki.krogerus@linux.intel.com, wsa@the-dreams.de Cc: linux-usb@vger.kernel.org, linux-i2c@vger.kernel.org, Ajay Gupta Subject: [PATCH v3 5/5] usb: typec: ucsi: ccg: add runtime pm workaround Date: Wed, 22 May 2019 11:31:42 -0700 Message-Id: <20190522183142.11061-6-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522183142.11061-1-ajayg@nvidia.com> References: <20190522183142.11061-1-ajayg@nvidia.com> X-NVConfidentiality: public Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ajay Gupta Cypress USB Type-C CCGx controller firmware version 3.1.10 (which is being used in many NVIDIA GPU cards) has known issue of not triggering interrupt when a USB device is hot plugged to runtime resume the controller. If any GPU card gets latest kernel with runtime pm support but does not get latest fixed firmware then also it should continue to work and therefore a workaround is required to check for any connector change event. The workaround is that i2c bus driver will call pm_request_resume() to runtime resume ucsi_ccg driver. CCG driver will call the ISR for any connector change event for NVIDIA GPU card and only if it has old CCG firmware with the known issue. Signed-off-by: Ajay Gupta --- Changes from v2->v3: None drivers/usb/typec/ucsi/ucsi_ccg.c | 80 +++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index b15bc6c29c46..a5b81c011148 100644 --- a/drivers/usb/typec/ucsi/ucsi_ccg.c +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c @@ -109,12 +109,21 @@ struct version_format { __le16 build; u8 patch; u8 ver; +#define CCG_VERSION_PATCH(x) ((x) << 16) +#define CCG_VERSION(x) ((x) << 24) #define CCG_VERSION_MIN_SHIFT (0) #define CCG_VERSION_MIN_MASK (0xf << CCG_VERSION_MIN_SHIFT) #define CCG_VERSION_MAJ_SHIFT (4) #define CCG_VERSION_MAJ_MASK (0xf << CCG_VERSION_MAJ_SHIFT) } __packed; +/* + * Firmware version 3.1.10 or earlier, built for NVIDIA has known issue + * of missing interrupt when a device is connected for runtime resume + */ +#define CCG_FW_BUILD_NVIDIA (('n' << 8) | 'v') +#define CCG_OLD_FW_VERSION (CCG_VERSION(0x31) | CCG_VERSION_PATCH(10)) + struct version_info { struct version_format base; struct version_format app; @@ -172,6 +181,7 @@ struct ucsi_ccg { struct ccg_dev_info info; /* version info for boot, primary and secondary */ struct version_info version[FW2 + 1]; + u32 fw_version; /* CCG HPI communication flags */ unsigned long flags; #define RESET_PENDING 0 @@ -185,6 +195,8 @@ struct ucsi_ccg { /* fw build with vendor information */ u16 fw_build; + bool run_isr; /* flag to call ISR routine during resume */ + struct work_struct pm_work; }; static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len) @@ -212,6 +224,18 @@ static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len) if (quirks && quirks->max_read_len) max_read_len = quirks->max_read_len; + if (uc->fw_build == CCG_FW_BUILD_NVIDIA && + uc->fw_version <= CCG_OLD_FW_VERSION) { + mutex_lock(&uc->lock); + /* + * Do not schedule pm_work to run ISR in + * ucsi_ccg_runtime_resume() after pm_runtime_get_sync() + * since we are already in ISR path. + */ + uc->run_isr = false; + mutex_unlock(&uc->lock); + } + pm_runtime_get_sync(uc->dev); while (rem_len > 0) { msgs[1].buf = &data[len - rem_len]; @@ -254,6 +278,18 @@ static int ccg_write(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len) msgs[0].len = len + sizeof(rab); msgs[0].buf = buf; + if (uc->fw_build == CCG_FW_BUILD_NVIDIA && + uc->fw_version <= CCG_OLD_FW_VERSION) { + mutex_lock(&uc->lock); + /* + * Do not schedule pm_work to run ISR in + * ucsi_ccg_runtime_resume() after pm_runtime_get_sync() + * since we are already in ISR path. + */ + uc->run_isr = false; + mutex_unlock(&uc->lock); + } + pm_runtime_get_sync(uc->dev); status = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); if (status < 0) { @@ -383,6 +419,13 @@ static irqreturn_t ccg_irq_handler(int irq, void *data) return IRQ_HANDLED; } +static void ccg_pm_workaround_work(struct work_struct *pm_work) +{ + struct ucsi_ccg *uc = container_of(pm_work, struct ucsi_ccg, pm_work); + + ucsi_notify(uc->ucsi); +} + static int get_fw_info(struct ucsi_ccg *uc) { int err; @@ -392,6 +435,9 @@ static int get_fw_info(struct ucsi_ccg *uc) if (err < 0) return err; + uc->fw_version = CCG_VERSION(uc->version[FW2].app.ver) | + CCG_VERSION_PATCH(uc->version[FW2].app.patch); + err = ccg_read(uc, CCGX_RAB_DEVICE_MODE, (u8 *)(&uc->info), sizeof(uc->info)); if (err < 0) @@ -740,11 +786,12 @@ static bool ccg_check_fw_version(struct ucsi_ccg *uc, const char *fw_name, } /* compare input version with FWCT version */ - cur_version = le16_to_cpu(app->build) | app->patch << 16 | - app->ver << 24; + cur_version = le16_to_cpu(app->build) | CCG_VERSION_PATCH(app->patch) | + CCG_VERSION(app->ver); - new_version = le16_to_cpu(fw_cfg.app.build) | fw_cfg.app.patch << 16 | - fw_cfg.app.ver << 24; + new_version = le16_to_cpu(fw_cfg.app.build) | + CCG_VERSION_PATCH(fw_cfg.app.patch) | + CCG_VERSION(fw_cfg.app.ver); if (!ccg_check_vendor_version(uc, app, &fw_cfg)) goto out_release_firmware; @@ -1084,8 +1131,10 @@ static int ucsi_ccg_probe(struct i2c_client *client, uc->ppm.sync = ucsi_ccg_sync; uc->dev = dev; uc->client = client; + uc->run_isr = true; mutex_init(&uc->lock); INIT_WORK(&uc->work, ccg_update_firmware); + INIT_WORK(&uc->pm_work, ccg_pm_workaround_work); /* Only fail FW flashing when FW build information is not provided */ status = device_property_read_u16(dev, "ccgx,firmware-build", @@ -1153,6 +1202,7 @@ static int ucsi_ccg_remove(struct i2c_client *client) { struct ucsi_ccg *uc = i2c_get_clientdata(client); + cancel_work_sync(&uc->pm_work); cancel_work_sync(&uc->work); ucsi_unregister_ppm(uc->ucsi); pm_runtime_disable(uc->dev); @@ -1183,6 +1233,28 @@ static int ucsi_ccg_runtime_suspend(struct device *dev) static int ucsi_ccg_runtime_resume(struct device *dev) { + struct i2c_client *client = to_i2c_client(dev); + struct ucsi_ccg *uc = i2c_get_clientdata(client); + bool schedule = true; + + /* + * Firmware version 3.1.10 or earlier, built for NVIDIA has known issue + * of missing interrupt when a device is connected for runtime resume. + * Schedule a work to call ISR as a workaround. + */ + if (uc->fw_build == CCG_FW_BUILD_NVIDIA && + uc->fw_version <= CCG_OLD_FW_VERSION) { + mutex_lock(&uc->lock); + if (!uc->run_isr) { + uc->run_isr = true; + schedule = false; + } + mutex_unlock(&uc->lock); + + if (schedule) + schedule_work(&uc->pm_work); + } + return 0; }