From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 57D40CDB47E for ; Fri, 13 Oct 2023 11:14:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5W/H23/MGjH8g2Imc9cKP6e9llSPqlU/tpLyxxeXoug=; b=KV08603R4wJaYL oHLByPBa75LMAOHl33WH58Pl3Hm12YhjpPRqxbCfNJMtGKISjbEx9BtgEh27qM3f+z8YZZg04jR8v Mc3HZmbjLCKj4wyxJDT1xpm84GPBp6U6o3sH1B2OdHkNXkbSqwib/muUMv6HfLy17/qBDGscZx3+b vdvDFhw5OhU1HTqq7eUEkZoCKKdJdp5EN0Yq7BaWkfeavOtN1w96A5i8VwChi+sJKSdixvlnmjXS7 Pxxryutud9xf4t/oelr5Wi52L65Hqda6IE4z1Jqf8b8Re9uyTYQbAngEghZLFBw9SQh0T1Lsmytwr HCaFwiuvpcebhybgdSPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qrG7H-003IFA-00; Fri, 13 Oct 2023 11:14:03 +0000 Received: from mx1.tq-group.com ([93.104.207.81]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qrG7C-003IEc-39; Fri, 13 Oct 2023 11:14:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1697195639; x=1728731639; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=08noC20/kxWHv/qWQMeDlKc4iIh5pIHQn6/p+atWwZ8=; b=J5sX3y232r/ZAmXGKXRqfiRZQb9k0xpWZKU19Tg4TUFvYtBiOndbuGV0 3WWe00NMhPwpeNmhRQ8Y4+RcTO0JrBFKf3MyrvDtGhYQBcyWq/jvzR8LY rlKTVlUAoeC6Tu/VCjnA500vuvh/3ihPhX23kYA8pltbEkcTGAM+HzmZO VBDFFWWbE6C4WzF7zb802/S41ZUJxXNymMKl94iG6lRXcqVPDACCCYCwI NBcnqHygBluPiIXGa8q1EobxTLC5xI9B/FquM+vfsFnv0fTj8zHT2OZ/5 ir/CEUrHSecDvfJarZUMxw7wu5VFh42OGgIzItjjaB8x2xv5Kj9c02Skg Q==; X-IronPort-AV: E=Sophos;i="6.03,222,1694728800"; d="scan'208";a="33452337" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 13 Oct 2023 13:13:55 +0200 Received: from steina-w.localnet (steina-w.tq-net.de [10.123.53.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by vtuxmail01.tq-net.de (Postfix) with ESMTPSA id B1314280082; Fri, 13 Oct 2023 13:13:49 +0200 (CEST) From: Alexander Stein To: Sean Young , linux-media@vger.kernel.org, Ivaylo Dimitrov , Thierry Reding , Uwe =?ISO-8859-1?Q?Kleine=2DK=F6nig?= , Florian Fainelli , Ray Jui , Scott Branden , Broadcom internal kernel review list , Stefan Wahren Cc: linux-pwm@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/3] pwm: bcm2835: allow pwm driver to be used in atomic context Date: Fri, 13 Oct 2023 13:13:50 +0200 Message-ID: <5203415.ElGaqSPkdT@steina-w> Organization: TQ-Systems GmbH In-Reply-To: <84429d39-aa54-462d-85cd-c5d06a614a0e@gmx.net> References: <6ce73b2688f059e7169935699044104cf37b2425.1697193646.git.sean@mess.org> <84429d39-aa54-462d-85cd-c5d06a614a0e@gmx.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231013_041359_419218_895FAACB X-CRM114-Status: GOOD ( 24.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, Am Freitag, 13. Oktober 2023, 13:04:48 CEST schrieb Stefan Wahren: > Hi Sean, > = > Am 13.10.23 um 12:46 schrieb Sean Young: > > clk_get_rate() may do a mutex lock. Since the clock rate cannot change = on > > an rpi, simply fetch it once. > = > does it mean you checked all possible SoCs (BCM2835, BCM2836, BCM2837, > BCM2711, BCM2712) for this change? > = > Is it impossible that the real clock can never be influenced by turbo > mode like SPI? Assuming the clock can change, which I would, then a clock notifier seems = appropriate. See [1] for an example. Best regards, Alexander [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ commit/?id=3D90ad2cbe88c22d0215225ab9594eeead0eb24fde > Best regards > = > > Signed-off-by: Sean Young > > --- > > = > > drivers/pwm/pwm-bcm2835.c | 21 ++++++++++++--------- > > 1 file changed, 12 insertions(+), 9 deletions(-) > > = > > diff --git a/drivers/pwm/pwm-bcm2835.c b/drivers/pwm/pwm-bcm2835.c > > index bdfc2a5ec0d6..59ea154dd657 100644 > > --- a/drivers/pwm/pwm-bcm2835.c > > +++ b/drivers/pwm/pwm-bcm2835.c > > @@ -28,6 +28,7 @@ struct bcm2835_pwm { > > = > > struct device *dev; > > void __iomem *base; > > struct clk *clk; > > = > > + unsigned long rate; > > = > > }; > > = > > static inline struct bcm2835_pwm *to_bcm2835_pwm(struct pwm_chip *chi= p) > > = > > @@ -63,17 +64,11 @@ static int bcm2835_pwm_apply(struct pwm_chip *chip, > > struct pwm_device *pwm,> = > > { > > = > > struct bcm2835_pwm *pc =3D to_bcm2835_pwm(chip); > > = > > - unsigned long rate =3D clk_get_rate(pc->clk); > > = > > unsigned long long period_cycles; > > u64 max_period; > > = > > u32 val; > > = > > - if (!rate) { > > - dev_err(pc->dev, "failed to get clock rate\n"); > > - return -EINVAL; > > - } > > - > > = > > /* > > = > > * period_cycles must be a 32 bit value, so period * rate / > > NSEC_PER_SEC > > * must be <=3D U32_MAX. As U32_MAX * NSEC_PER_SEC < U64_MAX the > > = > > @@ -88,13 +83,13 @@ static int bcm2835_pwm_apply(struct pwm_chip *chip, > > struct pwm_device *pwm,> = > > * <=3D> period < ((U32_MAX * NSEC_PER_SEC + NSEC_PER_SEC/2) / rate > > * <=3D> period <=3D ceil((U32_MAX * NSEC_PER_SEC + NSEC_PER_SEC/2) = / = rate) > > - 1 > > */ > > = > > - max_period =3D DIV_ROUND_UP_ULL((u64)U32_MAX * NSEC_PER_SEC + = NSEC_PER_SEC > > / 2, rate) - 1; + max_period =3D DIV_ROUND_UP_ULL((u64)U32_MAX * > > NSEC_PER_SEC + NSEC_PER_SEC / 2, pc->rate) - 1;> = > > if (state->period > max_period) > > = > > return -EINVAL; > > = > > /* set period */ > > = > > - period_cycles =3D DIV_ROUND_CLOSEST_ULL(state->period * rate, > > NSEC_PER_SEC); + period_cycles =3D DIV_ROUND_CLOSEST_ULL(state->period * > > pc->rate, NSEC_PER_SEC);> = > > /* don't accept a period that is too small */ > > if (period_cycles < PERIOD_MIN) > > = > > @@ -103,7 +98,7 @@ static int bcm2835_pwm_apply(struct pwm_chip *chip, > > struct pwm_device *pwm,> = > > writel(period_cycles, pc->base + PERIOD(pwm->hwpwm)); > > = > > /* set duty cycle */ > > = > > - val =3D DIV_ROUND_CLOSEST_ULL(state->duty_cycle * rate, NSEC_PER_SEC); > > + val =3D DIV_ROUND_CLOSEST_ULL(state->duty_cycle * pc->rate, = NSEC_PER_SEC); > > = > > writel(val, pc->base + DUTY(pwm->hwpwm)); > > = > > /* set polarity */ > > = > > @@ -129,6 +124,7 @@ static const struct pwm_ops bcm2835_pwm_ops =3D { > > = > > .request =3D bcm2835_pwm_request, > > .free =3D bcm2835_pwm_free, > > .apply =3D bcm2835_pwm_apply, > > = > > + .atomic =3D true, > > = > > .owner =3D THIS_MODULE, > > = > > }; > > = > > @@ -156,6 +152,13 @@ static int bcm2835_pwm_probe(struct platform_device > > *pdev)> = > > if (ret) > > = > > return ret; > > = > > + pc->rate =3D clk_get_rate(pc->clk); > > + if (!pc->rate) { > > + dev_err(pc->dev, "failed to get clock rate\n"); > > + ret =3D -EINVAL; > > + goto add_fail; > > + } > > + > > = > > pc->chip.dev =3D &pdev->dev; > > pc->chip.ops =3D &bcm2835_pwm_ops; > > pc->chip.npwm =3D 2; -- = TQ-Systems GmbH | M=FChlstra=DFe 2, Gut Delling | 82229 Seefeld, Germany Amtsgericht M=FCnchen, HRB 105018 Gesch=E4ftsf=FChrer: Detlef Schneider, R=FCdiger Stahl, Stefan Schneider http://www.tq-group.com/ _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel