Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp357588ybt; Wed, 8 Jul 2020 01:30:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1d5Gy7LNfINpNvUgWUwpMQwySlgtaLbORMFb5T8b89vQXOq4njUwWQjg4iBbGSXVYGfZJ X-Received: by 2002:a05:6402:ca3:: with SMTP id cn3mr67996191edb.64.1594197053488; Wed, 08 Jul 2020 01:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594197053; cv=none; d=google.com; s=arc-20160816; b=mNEfS5YCm943rncD0Je43XDy9pe8wqx8Prs3aPxwAoOfc4tYPI27XmodcpgsSI7De0 Pu2F0yps0f4ZIJaSlOk4FdWXvj+D1TWFarOM6A5XODZR7eJ3hB9DK18bunq7k4lhlIXq 4f85eO25qZRO20NIQeMYvaGDsKYBHTpnieV3sY3WXzZXrbNh6NGxzSnuG6xvjl/W4Ibx GxLvpSWY227LtDDRKEvku+vrJDaviDvBuC9v1y18pN9CDQ0lrlQQdTCV4qQfm5LD8u2U ZJyjOsRpA0TUqvo1wjRO3b3oS711ETiGtF5zcLca6ZsxHqCGMk2/nsyfrNEuuhe0wB2b fhLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=1uv6kbmlO0hEyYsST4okZKcXm+NCBJlrtxwfuLCRV0s=; b=A+AHiH9TCYJEdlJkJLIclKQ2CnZfI5Mqimw/+Oqm3rXMGGfjcPMnL4FHw1/6NMZ3Fx 9GwM9gV0vvSn0F/BiVpckzoQdL9U3yuWmCurg4hxomlXSOsrvuWA+Ms/AkR4Alxqstei 9j1Kr/UlLATU/pn39AjoI+8Tq2I1wcOmAqxWpmk4qgr61fMtj1Z2FI9RJQbaStOxCfGk C2+uke+jVo2ry++9POfshiDu9kMXDUzmgIAsUnYS+QyXsRrIItAKgTJmvICmeLwRl8Ef lbDflcEdruuFWBAY0tN8Uq3+RdBpid8bSAydur9B4C9W4itXdkQVlmn0Wfekr+KnSvHt F64w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YDmQb17J; 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 dg12si16572298edb.81.2020.07.08.01.30.30; Wed, 08 Jul 2020 01:30:53 -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=YDmQb17J; 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 S1727870AbgGHI36 (ORCPT + 99 others); Wed, 8 Jul 2020 04:29:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725789AbgGHI35 (ORCPT ); Wed, 8 Jul 2020 04:29:57 -0400 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D064C08C5DC; Wed, 8 Jul 2020 01:29:57 -0700 (PDT) Received: by mail-il1-x142.google.com with SMTP id a6so21623695ilq.13; Wed, 08 Jul 2020 01:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1uv6kbmlO0hEyYsST4okZKcXm+NCBJlrtxwfuLCRV0s=; b=YDmQb17J7ITLd0DSFM6/ndDEM802ghYJSP/6szbfm197i2t72YsN6fL3Vu4gjQdSsi KCbF5z/fM8iYJW3bPe/yUrvAFMx4yHDgAXY39ZLj+VUmC/hRhPHq6GksJydYpM25pIC/ fuvSH/SARVXA4/JJ9bRb1r2fssGrqoLX9pbh8Nvku+SJ0jj1BLpMZSAilJm8haUXGhPC 0HSChBV2eO0cW9sPVWr1qu9VE6K8ahjsvNKu3IS6xHcvuHAhhTkz1EG99M/6+uoO7d5d vP9zhh/me1AqIw4+xmSQ9Kcla1ZzQt0QtXB/ff22twa5KiQxJkRX/6kC3K6D53DZCKiT F21Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1uv6kbmlO0hEyYsST4okZKcXm+NCBJlrtxwfuLCRV0s=; b=G5IpQUiSpw2nbNFcJsd9oxDtOYaaeMvyN8Yo1DwJfIm1ZORorvEr2tiypmR2lsoYxS /m+stIcjOucY4d2/4DOKA6psfHocO+TMBkwf8iz0T4Y10IntPrMA2aWPsjvYn8FFu/T6 g3LrA8nfgFaOebBr6t09W7moRVh6Ztk/147VpDSVBveENwE2WvYWBhcU1Z5XSWSsES5G fn3p2EF3wWxl4vk41kWSfCt+BFRqywM3vgWE5o7acfLuwNYqv+ufFzUy93bQvCuPqK6w ApiPauWWUbXxUYJRv1PRcGKWZbLUalLyD14oKvX2/VNIkwZkZC2LnlKxgIyyR/IShFVt 6RrQ== X-Gm-Message-State: AOAM532Y1XckW/XcSB1OnqrEt93guyGIVrpixuNXY3LB4jRYcpbkBRgT oHBw6Rj8t1OrH2esGkqDEbQBqOkSrahux3+smww= X-Received: by 2002:a92:98c2:: with SMTP id a63mr38841081ill.246.1594196996887; Wed, 08 Jul 2020 01:29:56 -0700 (PDT) MIME-Version: 1.0 References: <20200707095908.372-1-linux.amoon@gmail.com> <20200707113645.GA27280@kozik-lap> In-Reply-To: <20200707113645.GA27280@kozik-lap> From: Anand Moon Date: Wed, 8 Jul 2020 13:59:46 +0530 Message-ID: Subject: Re: [PATCH v3] phy: samsung: Use readl_poll_timeout function To: Krzysztof Kozlowski Cc: linux-arm-kernel , linux-samsung-soc@vger.kernel.org, Linux Kernel , Kishon Vijay Abraham I , Vinod Koul , Kukjin Kim , Marek Szyprowski Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Krzysztof, On Tue, 7 Jul 2020 at 17:06, Krzysztof Kozlowski wrote: > > On Tue, Jul 07, 2020 at 09:59:08AM +0000, Anand Moon wrote: > > Instead of a busy waiting loop while loop using udelay > > You doubled "loop". > I will fix this in the next version. > > use readl_poll_timeout function to check the condition > > is met or timeout occurs in crport_handshake function. > > Still you did not mention that you convert the function to use sleeping > primitive. You also did not mention whether it is actually allowed in > this context and I am not sure if you investigated it. > OK, I am not sure how to resolve your query. I learned some new things. So here are some points. -- Yes read_poll_timeout internally used might_sleep if sleep_us != 0 under some condition. -- None of the code in phy-exynos5-usbdrd.c is called using kernel synchronization methods like spinlock / mutex. -- I have checked this function is called non atomic context. see below. [ 6.006395] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.013042] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.019646] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.026174] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.032699] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.039246] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.045707] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.052276] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.058760] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.065189] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.071631] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.078033] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.084433] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.090812] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.097102] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.103413] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.109670] exynos5_usb3drd_phy 12500000.phy: Not In atomic context [ 6.115871] exynos5_usb3drd_phy 12500000.phy: Not In atomic context > Best regards, > Krzysztof > > > > > Fixes: d8c80bb3b55b ("phy: exynos5-usbdrd: Calibrate LOS levels for exynos5420/5800") > > Signed-off-by: Anand Moon > > --- > > 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 | 35 +++++++----------------- > > 1 file changed, 10 insertions(+), 25 deletions(-) > > > > diff --git a/drivers/phy/samsung/phy-exynos5-usbdrd.c b/drivers/phy/samsung/phy-exynos5-usbdrd.c > > index e510732afb8b..fa75fa88da33 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,40 +557,24 @@ 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); > > + err = readl_poll_timeout(phy_drd->reg_phy + EXYNOS5_DRD_PHYREG1, > > + result, (result & PHYREG1_CR_ACK), 1, 100); > > + if (err) { > > + dev_err(phy_drd->dev, "CRPORT handshake timeout1 (0x%08x)\n", val); > > return -ETIME; Here return should be -ETIMEDOUT; > > } > > > > - 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); > > + err = readl_poll_timeout(phy_drd->reg_phy + EXYNOS5_DRD_PHYREG1, > > + result, !(result & PHYREG1_CR_ACK), 1, 100); > > + if (err) { > > + dev_err(phy_drd->dev, "CRPORT handshake timeout2 (0x%08x)\n", val); > > return -ETIME; > > } > > Best Regards -Anand