Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4964307ybb; Tue, 24 Mar 2020 08:28:57 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvgLc+H1akjd9y4SJOFT2LHQXGLH0crdC56M3/S7FzU14l/QvEfea35QX3lHM70uxvyCPw9 X-Received: by 2002:aca:4fc7:: with SMTP id d190mr3813153oib.100.1585063737702; Tue, 24 Mar 2020 08:28:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585063737; cv=none; d=google.com; s=arc-20160816; b=gYmCdMCZ7NvbIaY2kGypOZlgMxanfoJPg3YKQCJfSW7xUoqF3qqQDCxlw9IbJlbxUX me+2nXZNPBV5vxmWPqI8Rd5Lokj9TrUrREFmWYxwxP5Uz2SEk2iMpM8OHIrzT/oi4GYS u8hq2mNTNvcs09LM+EBWdK75yeyj2hUqQ7YZPxZfZtnSV9/X+5JSfOz80/Mc9Gnbp+jy FwdzNrHExpZHdVZMYHzSXs9NXiWyizwTz+DpTNHbDVanruI5dddncIGf9iPpBa08x6dS m1M8X2ABEI0zM7+C9Zeva4RblOjNQzhQ29d28bCV8lzcC6AO63bs3cPEGZt7fE0uoxfJ rsVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=E2bEOe1vPQQEKCYEQkT2qxEpanfkaiuA3rYpUmMBaFA=; b=QN7kfG+PZmHVVCHwB9JPtIeQmQzIBPotvsrOQrgjvmi8noOiDaU/8BegCsXRR80xRJ /3xIYoH/mGCx1v27M+oPIx88sJfEWJyMxWjk6XZ/WAZjJdYUzt5vrRrsYjxu5ZLgQ9mv ye6Qy0oxXrOCUYFTW5wVSwTy+9bGy5CgxRfE8U+3E3vJpus1AMXhM0Jv5W9gXOd8iQVJ yvBHurl8rJ+EdYYfMaQvBdMYYuQQhCW5nvknSwbJNhyrUIiR+U6PLWRy/vS3Xw8bnz2j tT9vrfw2yCl7MIyZQpqMDtxmhxmjD+HLhDCCWLKkOYJWMiijNBOtxbQvWgsP0WHOVXAh U0HA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w12si9447780otq.75.2020.03.24.08.28.45; Tue, 24 Mar 2020 08:28:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727837AbgCXP2Z (ORCPT + 99 others); Tue, 24 Mar 2020 11:28:25 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:46420 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727736AbgCXP2Z (ORCPT ); Tue, 24 Mar 2020 11:28:25 -0400 Received: from 61-220-137-37.hinet-ip.hinet.net ([61.220.137.37] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jGlTX-0000IV-P5; Tue, 24 Mar 2020 15:28:20 +0000 From: Kai-Heng Feng To: ajayg@nvidia.com Cc: Kai-Heng Feng , Wolfram Sang , Andy Shevchenko , linux-i2c@vger.kernel.org (open list:I2C CONTROLLER DRIVER FOR NVIDIA GPU), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3] i2c: nvidia-gpu: Handle timeout correctly in gpu_i2c_check_status() Date: Tue, 24 Mar 2020 23:28:11 +0800 Message-Id: <20200324152812.20231-1-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Nvidia card may come with a "phantom" UCSI device, and its driver gets stuck in probe routine, prevents any system PM operations like suspend. There's an unaccounted case that the target time can equal to jiffies in gpu_i2c_check_status(), let's solve that by using readl_poll_timeout() instead of jiffies comparison functions. Fixes: c71bcdcb42a7 ("i2c: add i2c bus driver for NVIDIA GPU") Suggested-by: Andy Shevchenko Signed-off-by: Kai-Heng Feng --- v3: - Use readl_poll_timeout to make the retry loop simpler. v2: - Use a boolean to make sure the operation is timeout or not. drivers/i2c/busses/i2c-nvidia-gpu.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c b/drivers/i2c/busses/i2c-nvidia-gpu.c index 62e18b4db0ed..f5d25ce00f03 100644 --- a/drivers/i2c/busses/i2c-nvidia-gpu.c +++ b/drivers/i2c/busses/i2c-nvidia-gpu.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -75,20 +76,15 @@ static void gpu_enable_i2c_bus(struct gpu_i2c_dev *i2cd) static int gpu_i2c_check_status(struct gpu_i2c_dev *i2cd) { - unsigned long target = jiffies + msecs_to_jiffies(1000); u32 val; + int ret; - do { - val = readl(i2cd->regs + I2C_MST_CNTL); - if (!(val & I2C_MST_CNTL_CYCLE_TRIGGER)) - break; - if ((val & I2C_MST_CNTL_STATUS) != - I2C_MST_CNTL_STATUS_BUS_BUSY) - break; - usleep_range(500, 600); - } while (time_is_after_jiffies(target)); - - if (time_is_before_jiffies(target)) { + ret = readl_poll_timeout(i2cd->regs + I2C_MST_CNTL, val, + !(val & I2C_MST_CNTL_CYCLE_TRIGGER) || + (val & I2C_MST_CNTL_STATUS) != I2C_MST_CNTL_STATUS_BUS_BUSY, + 500, 1000 * USEC_PER_MSEC); + + if (ret) { dev_err(i2cd->dev, "i2c timeout error %x\n", val); return -ETIMEDOUT; } -- 2.17.1