From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D74D2C325C for ; Wed, 22 Apr 2026 04:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776833390; cv=none; b=rTk+sxW8H2ZMr64lq2vC4DpNW4V8PxeuIuxR9kzj/xJMMhfkWL6V01R1DtAM29gLZhBRfy5Cr0GPmFv0t6mG67oO1WthHEi7t5s92p8/dpVbhkbPzjBo2K2lnwW7/GZTcSsoa5BlmIStP4qxCOJgMxj/Y9zCqojFXUHCSR81WI0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776833390; c=relaxed/simple; bh=amoFYOXNj6ai1aoDXuC/QErgGvTREL0GtwLWXrsqXcg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gSbJl5KHUJ0wfXrM534IWHxgJ8HztbNhk3piVkQr5fWC/ddjI3k5lv/myB8JRfy4egEYpuy0h61XRDzvEkjyFEBjtxQsH+vrMthA++z0XKTv82r0MBVPQ/sUOeo7S0N/TX5x0YpmAPBpBMvq26cu9/6ED5RDO8wwT+LKNVtZTJA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=snu.ac.kr; spf=pass smtp.mailfrom=snu.ac.kr; dkim=pass (1024-bit key) header.d=snu.ac.kr header.i=@snu.ac.kr header.b=G8K0zuPy; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=snu.ac.kr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=snu.ac.kr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=snu.ac.kr header.i=@snu.ac.kr header.b="G8K0zuPy" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2b23fcf90b2so48265595ad.3 for ; Tue, 21 Apr 2026 21:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=snu.ac.kr; s=google; t=1776833383; x=1777438183; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=9eH4zus6aRXEsE79ZbJPuyaxQ8dOTtTmwWEdDWPv4Bs=; b=G8K0zuPyRoYkvUe1EhM8NUBt1tHMZNeAVQzrApmScGaRhFM7njB6UGnaiwfwgjAmOC CM73MJ+rbWI/NlfQLPlC7w4OxNmWIlX7X9NVAyUEiqmLc542HHFo2nkiuN4fSCkHC/uE ZFe0ocnFcZvmT9r1j3UIMsYh4NgRt3RkXEwE4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776833383; x=1777438183; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9eH4zus6aRXEsE79ZbJPuyaxQ8dOTtTmwWEdDWPv4Bs=; b=AZipVMMZ9o2Oci1JPxASSHOXZpsXDUxG7p7rtAwmeRtctGcB+2PSdBe/AS2cdc9eZq XOrPr5ek5B4YVgweEENIyqAwbvPQjCCsREM+39zZL3s97KYBX1QN6BDpdw4Vj11RSQwJ 7ZuQ7EtB3br59DWIckvoZvIApdouzCQ6TfR6s8vodFWSJlF/phuZmgsKoRsb/9FoKtzu ekJ+7jr96lw3oSz2tQj84yAAY/9NET+aa8+0AoBbbc7UP/U96Jdra1/3YbqLUQZmeVc6 Gee/mtV8M/DUEAJkWJayvQNvfxw+34m+yUys+zXTwkKwHOKxgVaTRoAPs9GFWYXOMhCr 5W5w== X-Forwarded-Encrypted: i=1; AFNElJ9RqGsqQPRcUFETMaGbHDsgAo51ISoAhAlOT3Sq6LHTxfHhglbMT4FbAr/B4ul+OF+krUujPdetPf++T9k=@vger.kernel.org X-Gm-Message-State: AOJu0YxoUWVNHnbw+9KtGBMdKpwuoIkWvvqV+AjdeNSXV62kkun0d8UE O70LJOC4dlQVbGUgfnQ37gZW2fSH0DtbB97vF9VQlR24BhnMknNfDtaJgTmLduaMGwQ= X-Gm-Gg: AeBDies44NXiv0riLboXE1I3Yj8iCQHLs3L0Wm2g+pdKxYwMR7g60cC113uNHoNadr5 Yp1qlEreuRwkYBZEDq9nRiECmdx0jOvnH4oJDAeGir1+PrUaydi326eBF5W5pZ67JQ2NBK7bw8w hXTbsnYB1zFB0+scfo+2HkzTCTzArmqUylN9NyADv+DQ6uYKsMut5nzxfa8ZFX0v5Fg2gzSyw21 vOVLPDiosbiAbVl7+ecNDLof1pKydRe0DfYonhS9ad1gYPbe1VEZ9Z6mc2uge+k45jq0SRPqm6i RzE5OvG1ZGM5VzG0UWU6fsrh4O4FAYfTLAHqcU+Q911kOJ2wAn+ORHjKjcQv9T+Vs688/kpU7zF PhGgOIyffLQ5op6t6CUO3wcsWNFQ3lewtuTan0qnRKSP+fcc7N/0K1ZKO8Z5HvA07THzHdE4eCK /htBTy9DWMPcIAFjo2I1jRQmr4C9rnhTZ2MFRb/5Gxl9KhkrchwpBcAnXaHWSW+HmLHeBeBJtXu w== X-Received: by 2002:a17:902:f9cf:b0:2b2:50e1:f104 with SMTP id d9443c01a7336-2b5f9e64c18mr142624095ad.3.1776833383473; Tue, 21 Apr 2026 21:49:43 -0700 (PDT) Received: from localhost (nunu.snu.ac.kr. [147.46.112.82]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b5fab208d4sm160434605ad.55.2026.04.21.21.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2026 21:49:43 -0700 (PDT) Date: Wed, 22 Apr 2026 13:49:40 +0900 From: Sangyun Kim To: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= Cc: nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] pwm: atmel-tcb: Cache clock rates and mark chip as atomic Message-ID: <20260422044940.tse3ek7jlv3x2dbt@nunu> References: <20260415093433.2359955-1-sangyun.kim@snu.ac.kr> <20260419080838.3192357-1-sangyun.kim@snu.ac.kr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Tue, Apr 21, 2026 at 01:40:55 PM +0200, Uwe Kleine-König wrote: >Hello Sangyun, Hi Uwe, Thanks for the review. > >On Sun, Apr 19, 2026 at 05:08:38PM +0900, Sangyun Kim wrote: >> @@ -438,16 +441,33 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev) >> if (err) >> goto err_gclk; >> >> + err = clk_rate_exclusive_get(tcbpwmc->clk); >> + if (err) >> + goto err_disable_clk; >> + >> + err = clk_rate_exclusive_get(tcbpwmc->slow_clk); >> + if (err) >> + goto err_clk_unlock; >> + >> + tcbpwmc->rate = clk_get_rate(tcbpwmc->clk); >> + tcbpwmc->slow_rate = clk_get_rate(tcbpwmc->slow_clk); >> + > >Only one concern left: clk_get_rate() should only be called on enabled >clocks. I don't know the architecture details and how expensive it is to >have .clk enabled (or if it's enabled anyhow). > >If you're ok, I'd squash the following diff into your patch: That makes sense. clk_get_rate() should indeed only be used on enabled clocks, and your change is the simplest way to ensure correctness while respecting the clk API constraints. I’m happy with squashing your diff into my patch. > >diff --git a/drivers/pwm/pwm-atmel-tcb.c b/drivers/pwm/pwm-atmel-tcb.c >index 1a2832f1ace2..3d30aeab507e 100644 >--- a/drivers/pwm/pwm-atmel-tcb.c >+++ b/drivers/pwm/pwm-atmel-tcb.c >@@ -437,13 +437,17 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev) > tcbpwmc->channel = channel; > tcbpwmc->width = config->counter_width; > >- err = clk_prepare_enable(tcbpwmc->slow_clk); >+ err = clk_prepare_enable(tcbpwmc->clk); > if (err) > goto err_gclk; > >+ err = clk_prepare_enable(tcbpwmc->slow_clk); >+ if (err) >+ goto err_disable_clk;; >+ > err = clk_rate_exclusive_get(tcbpwmc->clk); > if (err) >- goto err_disable_clk; >+ goto err_disable_slow_clk; > > err = clk_rate_exclusive_get(tcbpwmc->slow_clk); > if (err) >@@ -469,6 +473,9 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev) > clk_rate_exclusive_put(tcbpwmc->clk); > > err_disable_clk: >+ clk_disable_unprepare(tcbpwmc->clk); >+ >+err_disable_slow_clk: > clk_disable_unprepare(tcbpwmc->slow_clk); > > err_gclk: >@@ -492,6 +499,7 @@ static void atmel_tcb_pwm_remove(struct platform_device *pdev) > > clk_rate_exclusive_put(tcbpwmc->slow_clk); > clk_rate_exclusive_put(tcbpwmc->clk); >+ clk_disable_unprepare(tcbpwmc->clk); > clk_disable_unprepare(tcbpwmc->slow_clk); > clk_put(tcbpwmc->gclk); > clk_put(tcbpwmc->clk); > > >This has the downside that clk is kept enabled the whole driver >lifetime, but that's the easiest way to make your fix honor the clk API >constraints. This allows to fast-track the patch fixing the sleeping >function called from invalid context issue and the optimisation can then >be addressed with more time during the next development cycles. Keeping the clock enabled for the driver lifetime is acceptable for now to fast-track the fix, and we can revisit potential optimizations in a follow-up patch. Thanks again for the suggestion. > >Best regards >Uwe Best regards, Sangyun