From patchwork Fri Jun 7 16:34:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10982383 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 D80A414B6 for ; Fri, 7 Jun 2019 16:37:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6667289E8 for ; Fri, 7 Jun 2019 16:37:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA58028B04; Fri, 7 Jun 2019 16:37:37 +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 4FCF0289E8 for ; Fri, 7 Jun 2019 16:37:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730893AbfFGQhg (ORCPT ); Fri, 7 Jun 2019 12:37:36 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35589 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728595AbfFGQhg (ORCPT ); Fri, 7 Jun 2019 12:37:36 -0400 Received: by mail-pf1-f193.google.com with SMTP id d126so1507431pfd.2; Fri, 07 Jun 2019 09:37:35 -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=QcjUXz7nVEMbWa87Mu+IjeJIB5ntFwP9kHk2aKWjaXI=; b=a6oicHVL2xwsRWZhYX+ZVKCuTvcsjtLoFODV0F4nMg+2ba8FmPtw5I3/e1exV1ovA8 zSnFoKd2DsYELZRCDlA3hJh38iV/6SdlZFZH0t4AupQRVHg1CfEweKylQpDFJJbJeC8s ml7EF5Py2s7Z2VHDbLkVyyEC9d3kGTJLSWzxuItPC4UWDyXrv62s1vP4bFhPMnCg4isb ujKLWAwlVkuvYcOL1t1tcum2Lqa56HT5FFuCL2mqTCOk00Vig2ScM9ua9IO6nJ/z0p/a q67BRvtmUb2A+OQxI160t58SUOboNr4+ZMsV9MJr7kH2cpMNp1EKyxBYfHc1i7OA/BRH D1Ag== 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=QcjUXz7nVEMbWa87Mu+IjeJIB5ntFwP9kHk2aKWjaXI=; b=tPjiK/vxzNXOuz1aFtgUEL+FK5/MGEw2k9Kn/XT9C50QpHCWCKVLwF6E85DFlzFwv9 qpqWnX7DvInqQBvqKM3i9X3+pJy6TarbC2AUMpLm3oDPH/7aLPK2hjqncUjSMsMjitoh op8yTHsXrUIjA+soLpYw9fpP4Rf9lLoTZu9B5yurMJjgP1KJEuEPRmSlrP1wpxDd/L7I P41phD1zKf9NTjYq7Gfo8N4qFCr6PAlabJCR5SUypOzsmQ0PikwKxzq3+MBQuSqlKIZQ 5A4wLNeTELcYOxDU2OPJZdFd6z2kZ34DmUGXe74Oe0Jz25lS7fvoePe+2LQWzJ1F1ccv oASw== X-Gm-Message-State: APjAAAXAEMjvdhskjnmdMCHPXe28uM5iOz5qHJHgIY2Z4kmanIIrGLRb nzAaipKRfzsfeAO4wZgPbE8= X-Google-Smtp-Source: APXvYqyMeTo3seKVxNORqzGwCsDmn9Cy/xZUmZgPMSSmtepAHTyl1CZv9og0unQJtVw02cB7Zf0phw== X-Received: by 2002:a63:52:: with SMTP id 79mr3624708pga.381.1559925455245; Fri, 07 Jun 2019 09:37:35 -0700 (PDT) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id t2sm1745520pgj.39.2019.06.07.09.37.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jun 2019 09:37:34 -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 v5 1/5] i2c: nvidia-gpu: refactor master_xfer Date: Fri, 7 Jun 2019 09:34:19 -0700 Message-Id: <20190607163423.31860-2-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190607163423.31860-1-ajayg@nvidia.com> References: <20190607163423.31860-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 --- Changes from v4->v5: - Further refactor master_xfer based on Wolfram's comment. drivers/i2c/busses/i2c-nvidia-gpu.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c b/drivers/i2c/busses/i2c-nvidia-gpu.c index 1c8f708f212b..7678a460bf9a 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,40 @@ 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; } } } + send_stop = false; status = gpu_i2c_stop(i2cd); if (status < 0) - return status; - - return i; -stop: - status2 = gpu_i2c_stop(i2cd); - if (status2 < 0) - dev_err(i2cd->dev, "i2c stop failed %d\n", status2); + goto exit; + + status = i; +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 Fri Jun 7 16:34:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10982385 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 E68A814B6 for ; Fri, 7 Jun 2019 16:37:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D53C0289E8 for ; Fri, 7 Jun 2019 16:37:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C944F28B04; Fri, 7 Jun 2019 16:37:38 +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 6CAEF289E8 for ; Fri, 7 Jun 2019 16:37:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730909AbfFGQhh (ORCPT ); Fri, 7 Jun 2019 12:37:37 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40931 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728595AbfFGQhh (ORCPT ); Fri, 7 Jun 2019 12:37:37 -0400 Received: by mail-pg1-f193.google.com with SMTP id d30so1435396pgm.7; Fri, 07 Jun 2019 09:37:36 -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=HwTvlmWdDghlNpnmNUhFKxbXnmDZSk9We4aYnmK+PIU=; b=jzpAthglFHOW66a+yJIVVN0gYCphuCE1GEcOnxiLz4mizZLDnS7hYd6NXusCsqXYdk HJJ7A8NFeXw+StXTMX1ps1uosCg7F4as/7B0OTNbBbz340N5Meei4gbPzrs0zjhn94Xq Qp0aIZ00vVfB2TabxUBDd3DRXk7UQopx0bdAcjKyTiUzTkWs9aRsaVpv2eDRuuBJSH1n TMr+4TPJxN33QDDkIQY32O6dgR/N8aJFkoCSAhymUVOwrYrnTeVrpapaiotjlX7+nFkS dAHUKZnKpfQRQHlUsa6YdXEOGA/cVoJrTphj7J20tRpNsaa/O9Q8l43QVhoTAKpd4Tdo OkJw== 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=HwTvlmWdDghlNpnmNUhFKxbXnmDZSk9We4aYnmK+PIU=; b=OYJCfIU80RiFrgRONxy12EA7DQ45VeehnzS2M5vHA87JcU0X0fZBogl5yhKPILfLMQ LGtCgCJgtzE9IbapVF49nHmeAMaz8CJm4Bqrq7AXNCeeOimg71Z1BT1zscicdk8VbkY8 SCF1tQOWN/uMGhezCKY63nniTIfE7DQhPTC7ZBY8EV+ROY5P3msSzaqF3KqYOkOmKZlo yJFAV/6CWFY++TOroKt8wwew3fDrhfaE5WEZ2ogj6yYsGr8sgIsxCSuJb/y/Lwb3fxMH o6gAirR+PJ5ViENW5DZswYPNi54su5SX/DY2MSwTLP7vH/GspB3EAV0sP7xSBlJTV6SC D09Q== X-Gm-Message-State: APjAAAVgVBIk6onilJLt4jn59ndPEfbGu4+9akKOH6vvPIXtmv1H3UsZ jYOuWWhl4rm2lyzFAuqucKzPWB/a X-Google-Smtp-Source: APXvYqzRNMfGHFsrTNxGBJ+nK8fBGe3LC8akRaph5DYt4XdwDPxHldU0GnsVwJhh/+KKs903SU2e8w== X-Received: by 2002:a63:eb56:: with SMTP id b22mr3562051pgk.81.1559925456436; Fri, 07 Jun 2019 09:37:36 -0700 (PDT) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id t2sm1745520pgj.39.2019.06.07.09.37.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jun 2019 09:37:35 -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 v5 2/5] i2c: nvidia-gpu: add runtime pm support Date: Fri, 7 Jun 2019 09:34:20 -0700 Message-Id: <20190607163423.31860-3-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190607163423.31860-1-ajayg@nvidia.com> References: <20190607163423.31860-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 v4->v5: - Removed extra comments for gpu_i2c_suspend() based on Wolfram's comment. drivers/i2c/busses/i2c-nvidia-gpu.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c b/drivers/i2c/busses/i2c-nvidia-gpu.c index 7678a460bf9a..364244ffb5bf 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 */ @@ -217,6 +218,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; } @@ -336,6 +339,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: @@ -349,10 +357,21 @@ 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); } +/* + * We need gpu_i2c_suspend() even if it is stub, for runtime pm to work + * correctly. Without it, lspci shows runtime pm status as "D0" for the card. + * Documentation/power/pci.txt also insists for driver to provide this. + */ +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); @@ -361,7 +380,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 Fri Jun 7 16:34:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10982387 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 9983A14B6 for ; Fri, 7 Jun 2019 16:37:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88D45289E8 for ; Fri, 7 Jun 2019 16:37:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D38A28B04; Fri, 7 Jun 2019 16:37: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 EDE60289E8 for ; Fri, 7 Jun 2019 16:37:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730919AbfFGQhi (ORCPT ); Fri, 7 Jun 2019 12:37:38 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36636 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728595AbfFGQhi (ORCPT ); Fri, 7 Jun 2019 12:37:38 -0400 Received: by mail-pg1-f196.google.com with SMTP id a3so1445560pgb.3; Fri, 07 Jun 2019 09:37: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=ZGyNaxPMnbiyQ7HvgsUeihHQeuPTaSqjUWUoVJlBAgE=; b=ZJTI7E5QNsvqKxpUhvydY0WD/9ntEPmJY1jNrHTnuLORL9nPyn8jhW2tTlJOMrnMm7 +21sd5c78flinMNhWW2kikrMummcke6h/NdCAG1yM6fNxvl7PI9u2WsIp3YqKvAgjjoS aVj8yL0ctvtVcE1DOd+7KY1WoSlan6JF2fzpnzvV/foZivK0lSjAUYzigDakfC9kzvvG PXIxMQcYBPepCJQAJBaA/jbOVq7VCbswSDEqf1CHRQH6c/OCSDDyXgaiMh7psPx8J+hu MPrHPVt/GwKwDLJGwYRNH+VJ4JS7jAVunsTq1M60oHHRRUybXtcI+im0s4xlJ7JZaWI8 kvfg== 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=ZGyNaxPMnbiyQ7HvgsUeihHQeuPTaSqjUWUoVJlBAgE=; b=a6vzCfEMHSir5pP9YMgbJ9hDIvMdim+iLI5kkDbtWKe2cimg8RSneniOo24diDy5MS QT5dPDFO3FEMwvT5u/N+nNd0XtIvNJNX+5pXizUIQ8uqR/BbjxQeLusgWa26hyjyXW/j oWRkWF8ifXn4nAyV+dCbqWKhUXztzbqIikt/fyN33jpLit91PLb4k4RpDVHCCwfOn2q/ GFFIlosZz0JKrW/5TJ8zz2fLZRiqc5acu/4kcJ3MEiRkhmaWIKbKhyGGE+bdxKVqVnKK AAKbpgArN+m7O5/oprLqPb+aomazhWeVw3cIqshtGPUUG/xDkY5k1U7omzjs1ddxOQ63 EHHw== X-Gm-Message-State: APjAAAUrfBw/1Bg5qFEmWhR0tes5mmiKM883i/cpGx4MN6AmvbjaBHep d8N7asrCpG3LOzMha1zBYGg= X-Google-Smtp-Source: APXvYqzo4hQH92rpEVAaZPMTcPucaqGXqzA8vGRgwF9KZkivM9HfHa5MzReN3Gwo3HIGTPRoqlX86w== X-Received: by 2002:a63:285:: with SMTP id 127mr3405785pgc.200.1559925457551; Fri, 07 Jun 2019 09:37:37 -0700 (PDT) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id t2sm1745520pgj.39.2019.06.07.09.37.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jun 2019 09:37:36 -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 v5 3/5] usb: typec: ucsi: ccg: enable runtime pm support Date: Fri, 7 Jun 2019 09:34:21 -0700 Message-Id: <20190607163423.31860-4-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190607163423.31860-1-ajayg@nvidia.com> References: <20190607163423.31860-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 Acked-by: Heikki Krogerus --- Changes from v4->v5 : None 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 Fri Jun 7 16:34:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10982389 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 A70C815E6 for ; Fri, 7 Jun 2019 16:37:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9663E289E8 for ; Fri, 7 Jun 2019 16:37:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AFB728B04; Fri, 7 Jun 2019 16:37:41 +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 2D2BB289E8 for ; Fri, 7 Jun 2019 16:37:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730930AbfFGQhk (ORCPT ); Fri, 7 Jun 2019 12:37:40 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42852 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730923AbfFGQhj (ORCPT ); Fri, 7 Jun 2019 12:37:39 -0400 Received: by mail-pf1-f196.google.com with SMTP id q10so1484829pff.9; Fri, 07 Jun 2019 09:37: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=dT4VYAJyIXPDSG1SeHDUIuNL89VHe1e73T/Ox4HA8S0=; b=q6vH9CwbwkXnyvbPxvMOCS67K5b1MvAhhhfXtiWCNLIQnXaeLLFmp6Yu6cdonN/uMx pcwL0Xz9Au9iqMbiNWux07vKkOZdyXlk/koamYgG3BNsVtqi6wegpvgzTjHagT4xV4wa lQq7wbkDvS3HO3F33NPTP64iu1U5NYMGkLUmCzWenuoWz+SvuwhDEMd/wY/BYYWtkh1j wYN6qlQHkxTAJLXtACVYSidP0yJdLoSak9JBWggnbQcpfBH+E8IKfxVaCFO9O79QnkXY PXuCOrYPe6LvHJ7R0eykOa9j8XTIndGhRoZ5FHxxyGxSlpOGQg7zgIMtqqoyAlYER4a5 +AyQ== 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=dT4VYAJyIXPDSG1SeHDUIuNL89VHe1e73T/Ox4HA8S0=; b=mgyDzDRrs0K8vIW8N9ENefvhDZV+E0PH8FEZeVRzagPaYnxUT6d/dHCxti+zbgRcNG RjRLuDxkYyN9VfN/Mq8PMYnVVx8NKEGK1iNVP4+16GJYa9Gbr6vtxouresjVU2q6/T8e jLvxfl/lrQvPhoJj+FHwgld2RWM7w8o3Hp+w6L2JFsbT4zCJ67eLal5zMjviamTPR+tl awlGmR4LuhnfciBMcbv2AlGG6KODVyi2ilk8WsO7dGVKa9dd+c0DcTSBdfXY52E7Xmy7 OX81KBRBGEQfJdXNkLQU4sd0QvH2W1ZZLg7VqOYQVnWlmdQ0+dztQJsNCCxDeJh9qyi5 63ag== X-Gm-Message-State: APjAAAUhXa4eVfJDVGkQr9rfdVv4BpBfV+bMmlJZChYqbXXoUDfrmwwg xl6quEqg0YB3RvsKoJhQF0a3/u9Q X-Google-Smtp-Source: APXvYqwRsfjG+RITW1K8ulhAW13XHbXWyhm+zgKcx0Ty7Fa+TCg3pQCdF1gGAK4zMpzQVz/DIJEmgw== X-Received: by 2002:a63:c30e:: with SMTP id c14mr3696785pgd.41.1559925458862; Fri, 07 Jun 2019 09:37:38 -0700 (PDT) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id t2sm1745520pgj.39.2019.06.07.09.37.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jun 2019 09:37: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 v5 4/5] i2c: nvidia-gpu: resume ccgx i2c client Date: Fri, 7 Jun 2019 09:34:22 -0700 Message-Id: <20190607163423.31860-5-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190607163423.31860-1-ajayg@nvidia.com> References: <20190607163423.31860-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 --- Changes from v4->v5: 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 364244ffb5bf..cfc76b5de726 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) @@ -268,8 +269,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); @@ -281,8 +280,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; @@ -377,6 +376,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 Fri Jun 7 16:34:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10982391 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 2963D15E6 for ; Fri, 7 Jun 2019 16:37:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17B11289E8 for ; Fri, 7 Jun 2019 16:37:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C12C28B06; Fri, 7 Jun 2019 16:37: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 5ADFB289E8 for ; Fri, 7 Jun 2019 16:37:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730934AbfFGQhm (ORCPT ); Fri, 7 Jun 2019 12:37:42 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:46118 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730923AbfFGQhl (ORCPT ); Fri, 7 Jun 2019 12:37:41 -0400 Received: by mail-pl1-f193.google.com with SMTP id e5so1018624pls.13; Fri, 07 Jun 2019 09:37: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=8EaCuST2yV57W8sOHU9n8Jlf4i9O08nihXKi/p/Dm/A=; b=k/eCIfwbFK2uhUiIKDWwFrOTF+2cq4ByLcQKdvSU4QomVRwmLX4EndtFEUYjSmauq4 f/hvRG4HRbKKc6Rt2M4NLHcbSyjrZhJk0WhS4P70S7mIc1Smfnr1UtFIqLEdX9oxDNWp AKzZuPtyDYPurh4j7y5ZC8y9T3eErOqHHDrjHZI+pBk+DvkhQXvyKPobtqnoucFKItO+ J96zL6smLC1P+AuWDTfXSM7/8I6IuVvfTNPjwrkvtYcDKQJqBxJXxA+hRH4ZaYQ3A4Dd MQq3bT3MFiuUvJtMxfaFWuehhVnf15+MgjSgQRwSiIzqkLn8+r3OMo6h/Sc3crJUPqyH 74eA== 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=8EaCuST2yV57W8sOHU9n8Jlf4i9O08nihXKi/p/Dm/A=; b=ViffwvtHtF4oPPsrtZtkE+X08DdtCBSdl03vreQ2Qpsz3s2XFqC13Xdeqo4gW3L6vh hEKJmgq7Xf7WMeuYGcIXNccqgfiFXihZJdW22UF6EYNLM3abMTIOqOM6ZF8R3ITyQl9q RD1fHQRBRddEqdCCmyP8Or2tYcGdaMJp8m7Y9YtOTi0nIelvHrHjXXwwkRDwhQOzL4Dr 0Kk2SOyVfTAqgwRVg8Vy3+KXlSeeM8+Qvo77tQ9d6COyE0G3F43ynNkNOz1YjfaF4+xL yJwxCXtqCDe42nf+aLYe5GVzUiGgXJV3IgmCIrxPCxOK9CFRk15IF/vYfJ/WqcLmAjVd vVtQ== X-Gm-Message-State: APjAAAXqzl/r6/2k7W0puZwFZBgSmg9hvtJh7+hhw93u5axJJC3AlVT2 UNCwXjdSKaA8D5mQnxUaesA= X-Google-Smtp-Source: APXvYqyFdBEXFfRrw6Aqk9lL12ImToCH+zj3msHW+oTLSXu/d2k21LXvp51pY9xJsq4aoIA50tw9Wg== X-Received: by 2002:a17:902:b70b:: with SMTP id d11mr57812601pls.84.1559925460737; Fri, 07 Jun 2019 09:37:40 -0700 (PDT) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id t2sm1745520pgj.39.2019.06.07.09.37.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jun 2019 09:37: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 v5 5/5] usb: typec: ucsi: ccg: add runtime pm workaround Date: Fri, 7 Jun 2019 09:34:23 -0700 Message-Id: <20190607163423.31860-6-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190607163423.31860-1-ajayg@nvidia.com> References: <20190607163423.31860-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 Acked-by: Heikki Krogerus --- Changes from v4->v5: 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; }