From patchwork Fri May 17 16:38:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10948237 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 8081D112C for ; Fri, 17 May 2019 16:39:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6FD1428113 for ; Fri, 17 May 2019 16:39:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6430F2835B; Fri, 17 May 2019 16:39:52 +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 04A9528113 for ; Fri, 17 May 2019 16:39:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727235AbfEQQjv (ORCPT ); Fri, 17 May 2019 12:39:51 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:45406 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725933AbfEQQju (ORCPT ); Fri, 17 May 2019 12:39:50 -0400 Received: by mail-pf1-f193.google.com with SMTP id s11so3921367pfm.12; Fri, 17 May 2019 09:39:50 -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=+3+oWi1hLvJXUHSpDcp4CGSVtkvFd6CNLTfoiSB3WnA=; b=tHQsW2hHa8S8NsjuWim9VjYx0EE0w2Fa51p91v51nMqFIhJ9Uo52XDIc3ZK1MiVbWj pE7GIix+z5uZFfIi4CKFhdi1uqHy0n932OD3Sa98IDAFY4LEsFRxZ5onUhvrBYvjsX56 fxvbt4W509L5mfNNHLD6WL+fsZrrTgKbl7idJ4hLAeuZeVf4ZuEksvu9R+fdnGnld2xX WR3UG0MQ+P3K1y/Ex9MDYw4+VuoN6i7Bzs+8CM1lD+H/9L3WldHyvzmCg0WStHFM2MNx nEAeSRDmj7ZbOucfwY+a9GohLplE/Pbip/W2dStr+0gE7ufirxJUIFuW0TWzLdTA/v1+ x1uA== 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=+3+oWi1hLvJXUHSpDcp4CGSVtkvFd6CNLTfoiSB3WnA=; b=Aopljoluu8VFtjQtk4lzNACAQSIq+Pl9euAK7sfYbgHg2n6dw/cMQo9029Egvb6S7V 4LS7qzSfUmtiX++FnhzTxTspJvWTbVDeG+F5etH2c2wrQED1n4xDzO28TN8lWA3V2GJD sFBg35JiIE4rSaArEtsPZozPOV6I66PneTRBtxaVfnboPXOWxSXJw1l9eWgz95heEvYN HkL1tfxXkkPF4kgJANLYQ3rp10RqMNMiWnEj93PSbGmFywRaS1+VtB3lG5pUGWhQWWIg GhOhTUduupLmYRNklo7wFTpRIMJAUmhNO56i94ym/j8f1Pc8IbtsVn/VLAjZ2thFzIy3 G/rQ== X-Gm-Message-State: APjAAAV4mS+xXkRiETHLTh03yLAxDgNgNy1d4FK71ursq4OLeoOh3gk/ sx6h2FklCEyHToexMfJd1XUbh/M7F9U= X-Google-Smtp-Source: APXvYqy4Sxcq6orWONxLA0cA5KoPl3Czd8m8wJPQ+dZD8eqBnIVBOdM1ZvV9oywaxlA4e9oHSMYGhA== X-Received: by 2002:aa7:8e59:: with SMTP id d25mr60769270pfr.24.1558111190095; Fri, 17 May 2019 09:39:50 -0700 (PDT) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id z7sm10513791pgh.81.2019.05.17.09.39.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 May 2019 09:39:49 -0700 (PDT) From: Ajay Gupta X-Google-Original-From: Ajay Gupta To: heikki.krogerus@linux.intel.com Cc: linux-usb@vger.kernel.org, linux-i2c@vger.kernel.org, Ajay Gupta Subject: [PATCH 1/4] i2c: nvidia-gpu: add runtime pm support Date: Fri, 17 May 2019 09:38:15 -0700 Message-Id: <20190517163818.5007-2-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190517163818.5007-1-ajayg@nvidia.com> References: <20190517163818.5007-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 --- drivers/i2c/busses/i2c-nvidia-gpu.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c b/drivers/i2c/busses/i2c-nvidia-gpu.c index 1c8f708f212b..9d347583f8dc 100644 --- a/drivers/i2c/busses/i2c-nvidia-gpu.c +++ b/drivers/i2c/busses/i2c-nvidia-gpu.c @@ -175,6 +175,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 */ @@ -189,7 +190,7 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap, status = gpu_i2c_start(i2cd); if (status < 0) { if (i == 0) - return status; + goto exit; goto stop; } @@ -206,13 +207,18 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap, } status = gpu_i2c_stop(i2cd); if (status < 0) - return status; + goto exit; + pm_runtime_mark_last_busy(i2cd->dev); + pm_runtime_put_autosuspend(i2cd->dev); return i; stop: status2 = gpu_i2c_stop(i2cd); if (status2 < 0) dev_err(i2cd->dev, "i2c stop failed %d\n", status2); +exit: + pm_runtime_mark_last_busy(i2cd->dev); + pm_runtime_put_autosuspend(i2cd->dev); return status; } @@ -332,6 +338,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: @@ -345,10 +356,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 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); @@ -357,7 +374,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 May 17 16:38:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10948239 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 38B6A1390 for ; Fri, 17 May 2019 16:39:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2788028346 for ; Fri, 17 May 2019 16:39:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BACD2835B; Fri, 17 May 2019 16:39:54 +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 9C80128113 for ; Fri, 17 May 2019 16:39:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727245AbfEQQjw (ORCPT ); Fri, 17 May 2019 12:39:52 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:37739 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725933AbfEQQjw (ORCPT ); Fri, 17 May 2019 12:39:52 -0400 Received: by mail-pl1-f196.google.com with SMTP id p15so3602438pll.4; Fri, 17 May 2019 09:39:51 -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=uEPK1kmOZF0+H+xCVSAoMHj+XaOnB47qnOGPzlP8xsg=; b=KtUgrEEjTO1NShqtGMC0j4hcn0lELm0vTHgxg/ZWgcNLBaAjUbnxGXx5fZag6yR7OU kzpLhEtn+e3rgvTzHz+PVsJVA6ghowhW/Xrjtpm2ugBluju65FaQ0ed2PyQaUeFTfhU6 vHJriEvThyyD9lxByFEd06MkAb9bhZOMeUQkrDW5ke1udmdJdJflMduRG9vnSBGvk8uu 2P+72cPdzzUE+tS84LAG4EZDcXnHuuQZA/C6fkMFygJTzHNhrMLF3MSGoj0YWGRFOzVc +GeRyHIl7Yk9V7n6tCMhCpB1hO5oWmcWP2ZmhDUoIAouYaNb2HrpEDzLP4fiQLXIJ/mv y6MA== 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=uEPK1kmOZF0+H+xCVSAoMHj+XaOnB47qnOGPzlP8xsg=; b=OiSW6HdkwBLxqGLv7msWLxslQR6eV5kLqc4QAhrhC2U4FT6U7n7vt+eXuZ1qYukZXr nB3hrIt5aMM3vsvxmYCoeLmri/lJRfBtcriWaaFvG0agkahhU1gF6qFNRtUmKSBJ/k9n t5ySCX50U3mei+BHGbIXxkWe8I66RmZ7mKgadxX36kBzusjYVTeMLP+6Dq4nhzU123rq P6ExHk4E6rM4BMLVmDo3STYqVGO6L0obvoZ6P9uL2aGSBU1buQ7ePYF1C6shMhCjbq/N 0ftIgPHn0S87p+eNwHzXkXi//ddf5lNXtAOzhJ05UND18za9rYJVdm5RMny2wFZHX8SU jzcA== X-Gm-Message-State: APjAAAVeF6/Z54HqNKtyjUYzc4RljD7prEKQWd3etK5foy/4qlfK6IgT IiRSjmOcVhYWZVKRtytjark= X-Google-Smtp-Source: APXvYqzH/wnGjms2ZbvksF7DDT6B6aottXrJdd5MhL71xiENBdbVeEnLRGAiexd+gBqLEBA3BUPiaw== X-Received: by 2002:a17:902:6b49:: with SMTP id g9mr6169163plt.298.1558111191191; Fri, 17 May 2019 09:39:51 -0700 (PDT) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id z7sm10513791pgh.81.2019.05.17.09.39.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 May 2019 09:39:50 -0700 (PDT) From: Ajay Gupta X-Google-Original-From: Ajay Gupta To: heikki.krogerus@linux.intel.com Cc: linux-usb@vger.kernel.org, linux-i2c@vger.kernel.org, Ajay Gupta Subject: [PATCH 2/4] usb: typec: ucsi: ccg: enable runtime pm support Date: Fri, 17 May 2019 09:38:16 -0700 Message-Id: <20190517163818.5007-3-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190517163818.5007-1-ajayg@nvidia.com> References: <20190517163818.5007-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. ucsi_send_command() is used in resume path and so exported ucsi_send_command() symbol in ucsi.c for modular build. Signed-off-by: Ajay Gupta --- drivers/usb/typec/ucsi/ucsi.c | 1 + drivers/usb/typec/ucsi/ucsi_ccg.c | 60 +++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 7850b851cecd..e9454134d399 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -206,6 +206,7 @@ int ucsi_send_command(struct ucsi *ucsi, struct ucsi_control *ctrl, return ret; } +EXPORT_SYMBOL_GPL(ucsi_send_command); /* -------------------------------------------------------------------------- */ diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index 9d46aa9e4e35..cc7094ecda2d 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,56 @@ static const struct i2c_device_id ucsi_ccg_device_id[] = { }; MODULE_DEVICE_TABLE(i2c, ucsi_ccg_device_id); +static int ucsi_ccg_suspend(struct device *dev) +{ + return 0; +} + +static int ucsi_ccg_resume(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct ucsi_ccg *uc = i2c_get_clientdata(client); + struct ucsi *ucsi = uc->ucsi; + struct ucsi_control c; + int ret; + + /* restore UCSI notification enable mask */ + UCSI_CMD_SET_NTFY_ENABLE(c, UCSI_ENABLE_NTFY_ALL); + ret = ucsi_send_command(ucsi, &c, NULL, 0); + if (ret < 0) { + dev_err(uc->dev, "%s: failed to set notification enable - %d\n", + __func__, ret); + } + return 0; +} + +static int ucsi_ccg_runtime_suspend(struct device *dev) +{ + return 0; +} + +static int ucsi_ccg_runtime_resume(struct device *dev) +{ + return 0; +} + +static int ucsi_ccg_runtime_idle(struct device *dev) +{ + return 0; +} + +static const struct dev_pm_ops ucsi_ccg_pm = { + .suspend = ucsi_ccg_suspend, + .resume = ucsi_ccg_resume, + .runtime_suspend = ucsi_ccg_runtime_suspend, + .runtime_resume = ucsi_ccg_runtime_resume, + .runtime_idle = ucsi_ccg_runtime_idle, +}; + 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 May 17 16:38:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10948241 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 9A8551515 for ; Fri, 17 May 2019 16:39:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8938128113 for ; Fri, 17 May 2019 16:39:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D94E2835B; Fri, 17 May 2019 16:39:54 +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 201DD28113 for ; Fri, 17 May 2019 16:39:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727253AbfEQQjx (ORCPT ); Fri, 17 May 2019 12:39:53 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:44643 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727237AbfEQQjw (ORCPT ); Fri, 17 May 2019 12:39:52 -0400 Received: by mail-pf1-f196.google.com with SMTP id g9so3922716pfo.11; Fri, 17 May 2019 09:39:52 -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=Q14eH62D0Ig9mZ2azyQBuSLX07GFb0agZ0N0YeEOvXA=; b=e1bM/Cy+CbXxaDQfeGMKL9WT+JguvdyFAqk2HG4/YhYzQUOm1x5F/oVJfwRjJ4ioaX 3RmsZtLkjQjxJ608cOQUURkvjEKiJDETxEXrP0gvrVSk09CHH4n2Pp8UhloZ6Bltl0nS cT3Mwe5V2actK4xucvpxDS2o8CUq9QMjGs8bcXGsnh6C5lUV0criQmw0NpAg5v4TXmEr Fyj1rFvKIvK3kE38t75BgAdt57q53KovXqnK2k//KGGOVa96MgJiJUIcrVEHdwQ0QFSH 8MVFeNl0+RH62NNgMLX4hB9AAzwDiQqMVUu2LaMGm3W4q7A3VeU1waLSs0zHXa4WIeO3 FYpg== 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=Q14eH62D0Ig9mZ2azyQBuSLX07GFb0agZ0N0YeEOvXA=; b=NBqn3jUFhvapAmURd1RsbVZUhflxY5voSms5ddKvJGpn+0JaEtTHfzVsrcDx+9PWkt wNEjeo/Sc3svFGzmJVNBkmsVfgdEAi6MLo+1vutm5T+82mAUq2e3RAm8SNVIO5kq2yLd W4IIs/Ank8diduMnvPolS4d1IbrT/JgB32OWgAL+ZUXFL9mXbVGg0qZA+jj9YoOvK83Y BZYhcc7TgcPCZb0nKD8XuDfPXQoJrVFzfFu//jqgsICeh/wQ8BD4DmZWBoQHyXVVMeff z9oxUjAb/dC9clXuvse+UwV6bR6Ve4VVE00x6xoEF67UodRpGDpWtNz8DM7Ojh4n0xA7 S9YA== X-Gm-Message-State: APjAAAUfKReJQfLJa1Ekqn7pxeZZ+5yD7ERxil7+fM4trF7BUKxogukF tcMJsKYcVXvlKkV4GPBUnOo= X-Google-Smtp-Source: APXvYqwZqII6gNj9l7/yGspFdjDzVxor8OzxgE+HBMgtmFJvLqVnfRb6GWaKOpYS2wSFCwMPGdAkDQ== X-Received: by 2002:a65:644e:: with SMTP id s14mr58676886pgv.290.1558111192168; Fri, 17 May 2019 09:39:52 -0700 (PDT) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id z7sm10513791pgh.81.2019.05.17.09.39.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 May 2019 09:39:51 -0700 (PDT) From: Ajay Gupta X-Google-Original-From: Ajay Gupta To: heikki.krogerus@linux.intel.com Cc: linux-usb@vger.kernel.org, linux-i2c@vger.kernel.org, Ajay Gupta Subject: [PATCH 3/4] i2c: nvidia-gpu: resume ccgx i2c client Date: Fri, 17 May 2019 09:38:17 -0700 Message-Id: <20190517163818.5007-4-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190517163818.5007-1-ajayg@nvidia.com> References: <20190517163818.5007-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 (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. Many of these cards may get latest kernel but may not get latest fixed firmware so a workaround 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 --- drivers/i2c/busses/i2c-nvidia-gpu.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c b/drivers/i2c/busses/i2c-nvidia-gpu.c index 9d347583f8dc..2f72135a547b 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) @@ -267,8 +268,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); @@ -280,8 +279,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; @@ -371,6 +370,12 @@ 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 May 17 16:38:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10948243 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 553F9112C for ; Fri, 17 May 2019 16:39:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4424328113 for ; Fri, 17 May 2019 16:39:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 387372835B; Fri, 17 May 2019 16:39:56 +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 9B61C28113 for ; Fri, 17 May 2019 16:39:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727264AbfEQQjy (ORCPT ); Fri, 17 May 2019 12:39:54 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:36613 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727237AbfEQQjy (ORCPT ); Fri, 17 May 2019 12:39:54 -0400 Received: by mail-pf1-f194.google.com with SMTP id v80so3946671pfa.3; Fri, 17 May 2019 09:39:53 -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=IkIop0wlT6STh2CVqqcB9iKGB/gJvvYoK9sMpq9U66I=; b=a8e2EMJkN4l/+1U+KYSaRB6MwDh23KKj97Vgj1ivPCuLFnO8xcNVBkKVI64d4gUZkZ ON+bST5piNp9vESgFQVPN5w9cLsthC9AP2il6Q64mJ4sEo0v7H8Hz4dDtOWp/K3LPLaR SM/T4ihNEYGIzhwd6/VUX1UlBURQrbs3ckib45Gy+BK/5S5liLQ85g2mRunMZmov/Re2 MzOn3Gu8OgkcmwvNXu00kIVg3obWuraSH9F+NpIR9IJz9QlQgiJAU8h3nc06j3DZSYwF ILhJ3aFaNRH6T2U0AWK8sG6jTCOy0Kk4DSMhmXc3hoSWfTrSFvkOVqQfmQG0+RLtNpiR Fluw== 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=IkIop0wlT6STh2CVqqcB9iKGB/gJvvYoK9sMpq9U66I=; b=oKU9L05/iKkpFKTAfga4j1jqBtGqQzAeMglqblk3YbYkTxny6vHnXgoEBm5f/4Sw3G JhKePf1DSK1VBKCQHRIfgLS3sphm/Cp2HYCZ3lBMVSI1y1tYE4EaGHr/8JV8B/0HCRQu nyYV1/NH/6W788l2awAJwTCa1EjXuqkNGSd4Vkc1XQRyPCtR0lqK3sMZZ5tv+cShjZlN hp/WB8CcBlJg70fcaKufGq2rK65YK1LR7Fu4oYX5Fx76yM4c1VDSDi+43jFQEI538b+2 armxCicWhdBbym7teRFk0MZzdGX0gbuVYxF4sTEKa89d9reaE5/nGFPG/ty5dYcp7+az MTSA== X-Gm-Message-State: APjAAAUQYpPvQudb4cW7gI3VZRZSTriz7jFDqXd+1h34WQuQfzfE8RY+ 5iwjgVxYrvzrJNKCa7HscrA= X-Google-Smtp-Source: APXvYqzgQ2BNhj+fc1Up2U78LUK3IpqGAGF3jx5sm1x10OgBAdWaDp26uDNN5C0ulYssz0jODM6RAw== X-Received: by 2002:a63:b00e:: with SMTP id h14mr54198637pgf.321.1558111193132; Fri, 17 May 2019 09:39:53 -0700 (PDT) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id z7sm10513791pgh.81.2019.05.17.09.39.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 May 2019 09:39:52 -0700 (PDT) From: Ajay Gupta X-Google-Original-From: Ajay Gupta To: heikki.krogerus@linux.intel.com Cc: linux-usb@vger.kernel.org, linux-i2c@vger.kernel.org, Ajay Gupta Subject: [PATCH 4/4] usb: typec: ucsi: ccg: add runtime pm workaround Date: Fri, 17 May 2019 09:38:18 -0700 Message-Id: <20190517163818.5007-5-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190517163818.5007-1-ajayg@nvidia.com> References: <20190517163818.5007-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 verson 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. Many of these cards may get latest kernel but may not get latest fixed firmware so 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 only if NVIDIA GPU has old CCG firmware with the known issue. Signed-off-by: Ajay Gupta --- drivers/usb/typec/ucsi/ucsi_ccg.c | 78 +++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index cc7094ecda2d..3457e112fdbc 100644 --- a/drivers/usb/typec/ucsi/ucsi_ccg.c +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c @@ -109,6 +109,8 @@ 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) @@ -172,6 +174,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 +188,10 @@ 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; + u16 old_fw_build; + u32 old_fw_version; }; static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len) @@ -212,6 +219,17 @@ 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->old_fw_build == uc->fw_build && + uc->fw_version <= uc->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 +272,17 @@ 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->old_fw_build == uc->fw_build && + uc->fw_version <= uc->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 +412,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 +428,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 +779,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 +1124,16 @@ 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); + + /* Firmware version 3.1.10 or earlier, built for NVIDIA has known issue + * of missing interrupt when a device is connected for runtime resume + */ + uc->old_fw_build = ('n' << 8) | 'v'; + uc->old_fw_version = CCG_VERSION(0x31) | CCG_VERSION_PATCH(10); /* Only fail FW flashing when FW build information is not provided */ status = device_property_read_u16(dev, "ccgx,firmware-build", @@ -1153,6 +1201,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); @@ -1198,6 +1247,27 @@ 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 "old_fw_version" 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->old_fw_build == uc->fw_build && + uc->fw_version <= uc->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; }