From nobody Sun Dec 22 22:52:59 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DEFAE75428 for ; Tue, 3 Oct 2023 05:50:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230192AbjJCFu6 (ORCPT ); Tue, 3 Oct 2023 01:50:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229920AbjJCFu4 (ORCPT ); Tue, 3 Oct 2023 01:50:56 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E609B8 for ; Mon, 2 Oct 2023 22:50:53 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-99bf3f59905so80744466b.3 for ; Mon, 02 Oct 2023 22:50:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696312252; x=1696917052; darn=vger.kernel.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7sWvUIyND0HCDU8OZGMQLwzLFIpQw7QMWwwvBYPky4c=; b=kyRW2dBv5Dk8hsOphlGDKwhsLOKGHfYBETgvTG7ZdLzZ8X9eCRfch9zLc6gb8qyRLI ZZaqMi7eItSWCpzzt75eU7u71RtYBYf5xvWOOY+IBfNywAqtzVV7FS7ldrODwsbFldBN GvA31RmwooXYCtTjGyt4UyXN4NmhwITDlN3+z9B5IZiP2E23MPCQW5ExebTIq0IPObg4 ipetdvRlNMSHK35ZdwyUPgca/R3Qo2Gr8jSspl+5lJGp1N6t5fOhvx/T+mTeFG173xrD s2/hTo6IYFFJqP21aITiwW5LaOVfft8UHl9NS4nOv+4Bnu03mRyknv7ehjWZdeVNdHH/ PYaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696312252; x=1696917052; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7sWvUIyND0HCDU8OZGMQLwzLFIpQw7QMWwwvBYPky4c=; b=TDC9ytZJEJXdE9x7J/3u/nNSSHwK6O8yybHklyvsiYWTrnguGt1XqeefdSrO1n2G0q yhd9X61t8BUg7Dn13r2sphqZROCciVJ8Q0dRYvuRUvbe1Os4NWNY0jfposYQwoFZWn1a +5dtBq6yHP5hvLRn4dl2YNjDjh1btkBANTyY35sFK/w5qB4K0X/RtBuyqwp42Daz7ISB OdMdCwmwmO6gaAlMx6FqPv2qO8Z2gWREL7S8xf1GqG4EiWOkB7oYx7i6s3R5loiJ9+wN lwr4wnoqtP48TuWbz8QY7CSYGmy9gsC3tbsPHZxuPHnWEqWa4WLb7D2vKTkDYgLM+jRe m+pA== X-Gm-Message-State: AOJu0YyBbxgGOlj0nkvEKTcbRJOYRvsJXQcMABeJ3NX7ewH+W9odInWT QBZ/QscQd6CJAmkaC8LRfPA= X-Google-Smtp-Source: AGHT+IEJpzQKuJnMxwVfMYNj0wbtWnCHpVww0VaY8cLi4FAsB17jAMdiN90/mks0QrfBECy50a/5wA== X-Received: by 2002:a17:907:1dcc:b0:9ae:406c:3425 with SMTP id og12-20020a1709071dcc00b009ae406c3425mr13112083ejc.0.1696312251468; Mon, 02 Oct 2023 22:50:51 -0700 (PDT) Received: from localhost.localdomain ([95.43.220.235]) by smtp.gmail.com with ESMTPSA id kj6-20020a170907764600b009ad88839665sm441309ejc.70.2023.10.02.22.50.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Oct 2023 22:50:51 -0700 (PDT) From: Ivaylo Dimitrov To: daniel.lezcano@linaro.org, tglx@linutronix.de, linux-kernel@vger.kernel.org Cc: tony@atomide.com, sean@mess.org, Ivaylo Dimitrov Subject: [PATCH] drivers/clocksource/timer-ti-dm: Don't call clk_get_rate() in stop function Date: Tue, 3 Oct 2023 08:50:20 +0300 Message-Id: <1696312220-11550-1-git-send-email-ivo.g.dimitrov.75@gmail.com> X-Mailer: git-send-email 1.9.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" clk_get_rate() might sleep, and that prevents dm-timer based PWM from being used from atomic context. Fix that by getting fclk rate in probe() and using a notifier in case rate changes. Fixes: af04aa856e93 ("ARM: OMAP: Move dmtimer driver out of plat-omap to dr= ivers under clocksource") Signed-off-by: Ivaylo Dimitrov Reviewed-by: Tony Lindgren --- drivers/clocksource/timer-ti-dm.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/drivers/clocksource/timer-ti-dm.c b/drivers/clocksource/timer-= ti-dm.c index 09ab29c..5f60f6b 100644 --- a/drivers/clocksource/timer-ti-dm.c +++ b/drivers/clocksource/timer-ti-dm.c @@ -140,6 +140,8 @@ struct dmtimer { struct platform_device *pdev; struct list_head node; struct notifier_block nb; + struct notifier_block fclk_nb; + unsigned long fclk_rate; }; =20 static u32 omap_reserved_systimers; @@ -253,8 +255,7 @@ static inline void __omap_dm_timer_enable_posted(struct= dmtimer *timer) timer->posted =3D OMAP_TIMER_POSTED; } =20 -static inline void __omap_dm_timer_stop(struct dmtimer *timer, - unsigned long rate) +static inline void __omap_dm_timer_stop(struct dmtimer *timer) { u32 l; =20 @@ -269,7 +270,7 @@ static inline void __omap_dm_timer_stop(struct dmtimer = *timer, * Wait for functional clock period x 3.5 to make sure that * timer is stopped */ - udelay(3500000 / rate + 1); + udelay(3500000 / timer->fclk_rate + 1); #endif } =20 @@ -348,6 +349,21 @@ static int omap_timer_context_notifier(struct notifier= _block *nb, return NOTIFY_OK; } =20 +static int omap_timer_fclk_notifier(struct notifier_block *nb, + unsigned long event, void *data) +{ + struct clk_notifier_data *clk_data =3D data; + struct dmtimer *timer =3D container_of(nb, struct dmtimer, fclk_nb); + + switch (event) { + case POST_RATE_CHANGE: + timer->fclk_rate =3D clk_data->new_rate; + return NOTIFY_OK; + default: + return NOTIFY_DONE; + } +} + static int omap_dm_timer_reset(struct dmtimer *timer) { u32 l, timeout =3D 100000; @@ -754,7 +770,6 @@ static int omap_dm_timer_stop(struct omap_dm_timer *coo= kie) { struct dmtimer *timer; struct device *dev; - unsigned long rate =3D 0; =20 timer =3D to_dmtimer(cookie); if (unlikely(!timer)) @@ -762,10 +777,7 @@ static int omap_dm_timer_stop(struct omap_dm_timer *co= okie) =20 dev =3D &timer->pdev->dev; =20 - if (!timer->omap1) - rate =3D clk_get_rate(timer->fclk); - - __omap_dm_timer_stop(timer, rate); + __omap_dm_timer_stop(timer); =20 pm_runtime_put_sync(dev); =20 @@ -1124,6 +1136,14 @@ static int omap_dm_timer_probe(struct platform_devic= e *pdev) timer->fclk =3D devm_clk_get(dev, "fck"); if (IS_ERR(timer->fclk)) return PTR_ERR(timer->fclk); + + timer->fclk_nb.notifier_call =3D omap_timer_fclk_notifier; + ret =3D devm_clk_notifier_register(dev, timer->fclk, + &timer->fclk_nb); + if (ret) + return ret; + + timer->fclk_rate =3D clk_get_rate(timer->fclk); } else { timer->fclk =3D ERR_PTR(-ENODEV); } --=20 1.9.1