Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp72811ybh; Mon, 20 Jul 2020 10:37:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8To9ex1Ec6wF3GQhDWY8xWCTyrXsozTpqLm9LyAMe8NaSBrJNOJVo/IjvHP+VZo2bV5+K X-Received: by 2002:a17:906:f88a:: with SMTP id lg10mr21046841ejb.317.1595266663658; Mon, 20 Jul 2020 10:37:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595266663; cv=none; d=google.com; s=arc-20160816; b=okhCOYz80whLm1Gt51HlGLX/2me3uxyudBoNLdXqzxaUvk0+jXHzikDaXqmtxx4oRy eC74jOPOrLIfwE8Bfomk4F7gZBMEIZHidWSLaDTCXD1x/gjJsEGVA4yjD21kKoGc03kQ hj8AvbycqD3RvcoK+X+UI1Aumomj2JyubgUe7/fWhkjZaK7teLXXlq9O7H4yZIhw29yu ttWVeA13jWhUWlWJg2fYIstxl3Kv7GAomd9XhkKm1Zzk31wJY1DsSwzcPjtivFTsBtZ2 iWgsPa0DDsI1WkYGVD1SvDT5HGKkNobmjt6f70dY7qji3lO5j7291OcZDIloURmUM3Gr O+ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=WABzq59H5eUVYxXK83gQCdP2ji4pUab0s2f+SVe9EGI=; b=xGL5mj//hII4KbCG31D5jmemJXp1yvsu7cDvGvyRaN4Pg2G7c6VEYwfuCxB5+9Kqml lCCU4P+O/FaZ7ysocwBSE8ljbiy57wP4khha9KlG9m7YhqL+ElDLwa7Dz7OM4coIhPeq GrOZFR4JDIcn6tu4CXL05ZmTK3iGTP3OwEQXUCVuTEeB/t0ssWK/umwbVANVsK1vH1S1 RvRBfkhSwXIq1bcefYQuV2ZjB3Xv6Vug+stgpBlSNPoudOcErzZNeGBXgzWPK6HR+Kjn RJawgvYSwhNCoDnLeVR6F3pm5ejGFSo0zeg5CXdILZSFsRahfoeEhH04Tsf8VCqRE9qm QymA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KSoBcGlL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw22si10279823ejb.61.2020.07.20.10.37.19; Mon, 20 Jul 2020 10:37:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KSoBcGlL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388142AbgGTRfM (ORCPT + 99 others); Mon, 20 Jul 2020 13:35:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729307AbgGTRfL (ORCPT ); Mon, 20 Jul 2020 13:35:11 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6349C061794; Mon, 20 Jul 2020 10:35:11 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id a9so158487pjd.3; Mon, 20 Jul 2020 10:35:11 -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:mime-version :content-transfer-encoding; bh=WABzq59H5eUVYxXK83gQCdP2ji4pUab0s2f+SVe9EGI=; b=KSoBcGlL4mpyA6z70T5c3zPdITp8j0hU0JwBgNNjrWFX5gJFyC40y/wPD+vC1X5Ajd ACXnjLQu44r8pQzWggycGix7CiwdtpBQnqEs1eCd6mesISSUECDr7flMAuMdzat62+8x UVp1LgUsiBBveXrK+fl3TO3mHwCguR7ltdYZ6QZY3moTWDy0N/o6ECEXEJxW6tMC/j33 XhrUsYk6MvuafN9d4/bh91e4TTBHGYXXYFnnaYS52DipCZ7kkysEwhfFm29RirNivCG0 6Ed4+rxF4UoZP3TZ1H1YfZuoymiKZ9W+OCHT3lfjwd0s0jxHSQGmqL1dhv1qH3T2NjWU 5TGQ== 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:mime-version :content-transfer-encoding; bh=WABzq59H5eUVYxXK83gQCdP2ji4pUab0s2f+SVe9EGI=; b=twKbNESBEusvaKmLqs43on29jSO3YFve6PdEx6oGzJ9fyidy9RaxKuOaVBS8qB/1pu mPp3wrhyPbzYn8LSaMsrAB9QiOLLdy9oORVQM6ZRHHC1fK2qGha3eai129tbxIzv1Y3/ pp7PwWSy1Ol8kpCnc83Do2wyxGjf6MCDbTQeQOFVr6QC93f8iPxGepyK4+10JuJ7fg4Y zjWcq8GEtRpWeL+qrUEWXKnkb7V8mmRxpA3w1qKztH7Bb6urfmd7qieXAGcaYzF6ZM7L GXFYu1MYYnQ4E+uGgPCK/axQgB5Lu0WhwsL+FPh3YgWiceOpmQ2laVE00a85Z0ce7WtA W5Fw== X-Gm-Message-State: AOAM530c6yYf4DjY5JL8Aqp1QOq85kPU2qszmdHiCjsqH0ctgjiY4OX3 6H6b4fhi7uf63Z2gDgCO5/Y= X-Received: by 2002:a17:90b:488:: with SMTP id bh8mr516495pjb.49.1595266511403; Mon, 20 Jul 2020 10:35:11 -0700 (PDT) Received: from localhost.localdomain ([103.51.73.161]) by smtp.gmail.com with ESMTPSA id b22sm175972pju.26.2020.07.20.10.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 10:35:10 -0700 (PDT) From: Anand Moon To: linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kishon Vijay Abraham I , Vinod Koul , Kukjin Kim , Krzysztof Kozlowski , Marek Szyprowski , Anand Moon Subject: [PATCH v5] phy: samsung: Use readl_poll_timeout function Date: Mon, 20 Jul 2020 17:35:02 +0000 Message-Id: <20200720173502.542-1-linux.amoon@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of a busy waiting while loop using udelay use readl_poll_timeout function to check the condition is met or timeout occurs in crport_handshake function. readl_poll_timeout is called in non atomic context so it safe to sleep until the condition is met. Signed-off-by: Anand Moon --- Changes v5: --Fix the indentation, checkpatch warning. --Drop the Fix tags. Changes v4: Rebased on to of patch [0] https://patchwork.kernel.org/patch/11651673/ --Fix the commit message. --Fix the error timeout condition for -ETIMEDOUT Changes v3: --Fix the commit message. --Drop the variable, used the value directly. Changes v2: --used the default timeout values. --Added missing Fixed tags. --- drivers/phy/samsung/phy-exynos5-usbdrd.c | 39 ++++++++---------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/drivers/phy/samsung/phy-exynos5-usbdrd.c b/drivers/phy/samsung/phy-exynos5-usbdrd.c index 7f6279fb4f8f..c45ed9cabc5e 100644 --- a/drivers/phy/samsung/phy-exynos5-usbdrd.c +++ b/drivers/phy/samsung/phy-exynos5-usbdrd.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -556,41 +557,25 @@ static int exynos5_usbdrd_phy_power_off(struct phy *phy) static int crport_handshake(struct exynos5_usbdrd_phy *phy_drd, u32 val, u32 cmd) { - u32 usec = 100; unsigned int result; + int err; writel(val | cmd, phy_drd->reg_phy + EXYNOS5_DRD_PHYREG0); - do { - result = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYREG1); - if (result & PHYREG1_CR_ACK) - break; - - udelay(1); - } while (usec-- > 0); - - if (!usec) { - dev_err(phy_drd->dev, - "CRPORT handshake timeout1 (0x%08x)\n", val); - return -ETIME; + err = readl_poll_timeout(phy_drd->reg_phy + EXYNOS5_DRD_PHYREG1, + result, (result & PHYREG1_CR_ACK), 1, 100); + if (err == -ETIMEDOUT) { + dev_err(phy_drd->dev, "CRPORT handshake timeout1 (0x%08x)\n", val); + return err; } - usec = 100; - writel(val, phy_drd->reg_phy + EXYNOS5_DRD_PHYREG0); - do { - result = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYREG1); - if (!(result & PHYREG1_CR_ACK)) - break; - - udelay(1); - } while (usec-- > 0); - - if (!usec) { - dev_err(phy_drd->dev, - "CRPORT handshake timeout2 (0x%08x)\n", val); - return -ETIME; + err = readl_poll_timeout(phy_drd->reg_phy + EXYNOS5_DRD_PHYREG1, + result, !(result & PHYREG1_CR_ACK), 1, 100); + if (err == -ETIMEDOUT) { + dev_err(phy_drd->dev, "CRPORT handshake timeout2 (0x%08x)\n", val); + return err; } return 0; -- 2.27.0