Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp880661rdg; Fri, 13 Oct 2023 04:14:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHI7B3QUfpexFpLRDkxSJ1iki5Ys7QsB7T5Zy/bKDw0RAux1pO8jouWeXIGhCq3aLZ+3xGb X-Received: by 2002:a05:6a20:54a4:b0:159:b7ba:74bd with SMTP id i36-20020a056a2054a400b00159b7ba74bdmr28179388pzk.50.1697195658130; Fri, 13 Oct 2023 04:14:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697195658; cv=none; d=google.com; s=arc-20160816; b=imS7O5X111FNcVWbSo/YBBQqglCU99tor1ZlF5yrHxnT4btaD5hqVcfV6LDFp84zN4 LGs1HB0GVzKEXWUYi8fa5oeat21YEjvXgHIDc94JfBxDqfIliTBiczRY8b4mjksKhXtT WsjI5AcJLibbu0cYSksulcFycpkbdPD5rSY2ni0YEG0bywGBxNadUyTsmjV2R1bdDUN+ dHC5m5C7gt0Pv6uiVaey2u67ucuPMBSCa471JpH04Ms5pglJYbtIvA/dZOLbbU9qaH0I MB03HKbX34s5DtNcPcA9Gb7Oaf4w/53MP6UGhlT/A6/E7rWpF85hDQBmz8kW68mtsXLU CR2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:organization:message-id:date:subject:cc:to :from:dkim-signature; bh=08noC20/kxWHv/qWQMeDlKc4iIh5pIHQn6/p+atWwZ8=; fh=p4Us0nH/pZzgWGGROh05NqloSDCz5wBo4Fq19laB4RI=; b=ZPa5sS7oG3dld5PABRkhPEhBIQnS6fFbDlF11OvORJ0kaE2cjlZe57QLv/FM3KHJi/ O3EaahblpoviE7nlagN1aIxCnwgollxjZ1v+9OYj1Tof1KgaGjGgFXbeP9vPtoHX8Qgf C4AK1JOtdtYKM+JnikwxyttPy4pBWK5XK4Qi9f0F2ZgLwAnvqfftBbVdT0Nsdh7iwt1M Ru9xKy4AbRjoy/Luzqbf2keUhoFp3PyO80wu7vPJHaKOuB6UelwUkTCtjeQgeVUtvHM+ 3NZ4aWLk1kx9MhdSUhPIOLZiM7hjlJShQhYd6+0KevUK/jglSkAZKSM80CMVZk2GcNuc nlyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b="SCaS/jko"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tq-group.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id l190-20020a6391c7000000b005accbb92b70si626217pge.676.2023.10.13.04.14.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 04:14:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b="SCaS/jko"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tq-group.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 56D888325EAE; Fri, 13 Oct 2023 04:14:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230128AbjJMLOC (ORCPT + 99 others); Fri, 13 Oct 2023 07:14:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229921AbjJMLOB (ORCPT ); Fri, 13 Oct 2023 07:14:01 -0400 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9CDCBE; Fri, 13 Oct 2023 04:13:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1697195638; x=1728731638; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=08noC20/kxWHv/qWQMeDlKc4iIh5pIHQn6/p+atWwZ8=; b=SCaS/jkoB6Cal7Go2uK+MKqa2s8A+ym0ZqmF77T9XPCGx781dYxeLIe/ nCtm7SBgRTqA5sXHCgIxlgm+ceLqhu5tNS3NqYSpjh4yQx7jHHpwG5EoK GK28W8qpbwCHlg/LWBD8ixQwx2n3pVnr0/DHzPNO8ocPx838fwxB73cWT q2zNbbZbmYzsqDAEDandK20RNE2nJMe1rLEdEFjs4bV+tFVwabqomgmxd WkMMDnPcbKKVwEx7B9OPgqL46/hhZ1y0YsV2lUZFBa/6gYLZZUKpyxpY6 Ghu1sF2QC4HxjMC/vemBWBDM2ybM0LG5vlRof+xkPeaX9fKQu1xEdGT8Q 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 13 Oct 2023 04:14:15 -0700 (PDT) Hi, Am Freitag, 13. Oktober 2023, 13:04:48 CEST schrieb Stefan Wahren: > Hi Sean, >=20 > 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. >=20 > does it mean you checked all possible SoCs (BCM2835, BCM2836, BCM2837, > BCM2711, BCM2712) for this change? >=20 > 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=20 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 >=20 > > Signed-off-by: Sean Young > > --- > >=20 > > drivers/pwm/pwm-bcm2835.c | 21 ++++++++++++--------- > > 1 file changed, 12 insertions(+), 9 deletions(-) > >=20 > > 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 { > >=20 > > struct device *dev; > > void __iomem *base; > > struct clk *clk; > >=20 > > + unsigned long rate; > >=20 > > }; > > =20 > > static inline struct bcm2835_pwm *to_bcm2835_pwm(struct pwm_chip *chi= p) > >=20 > > @@ -63,17 +64,11 @@ static int bcm2835_pwm_apply(struct pwm_chip *chip, > > struct pwm_device *pwm,>=20 > > { > > =20 > > struct bcm2835_pwm *pc =3D to_bcm2835_pwm(chip); > >=20 > > - unsigned long rate =3D clk_get_rate(pc->clk); > >=20 > > unsigned long long period_cycles; > > u64 max_period; > > =09 > > u32 val; > >=20 > > - if (!rate) { > > - dev_err(pc->dev, "failed to get clock rate\n"); > > - return -EINVAL; > > - } > > - > >=20 > > /* > > =09 > > * 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 > >=20 > > @@ -88,13 +83,13 @@ static int bcm2835_pwm_apply(struct pwm_chip *chip, > > struct pwm_device *pwm,>=20 > > * <=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) = /=20 rate) > > - 1 > > */ > >=20 > > - max_period =3D DIV_ROUND_UP_ULL((u64)U32_MAX * NSEC_PER_SEC +=20 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;>=20 > > if (state->period > max_period) > > =09 > > return -EINVAL; > > =09 > > /* set period */ > >=20 > > - 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);>=20 > > /* don't accept a period that is too small */ > > if (period_cycles < PERIOD_MIN) > >=20 > > @@ -103,7 +98,7 @@ static int bcm2835_pwm_apply(struct pwm_chip *chip, > > struct pwm_device *pwm,>=20 > > writel(period_cycles, pc->base + PERIOD(pwm->hwpwm)); > > =09 > > /* set duty cycle */ > >=20 > > - val =3D DIV_ROUND_CLOSEST_ULL(state->duty_cycle * rate, NSEC_PER_SEC); > > + val =3D DIV_ROUND_CLOSEST_ULL(state->duty_cycle * pc->rate,=20 NSEC_PER_SEC); > >=20 > > writel(val, pc->base + DUTY(pwm->hwpwm)); > > =09 > > /* set polarity */ > >=20 > > @@ -129,6 +124,7 @@ static const struct pwm_ops bcm2835_pwm_ops =3D { > >=20 > > .request =3D bcm2835_pwm_request, > > .free =3D bcm2835_pwm_free, > > .apply =3D bcm2835_pwm_apply, > >=20 > > + .atomic =3D true, > >=20 > > .owner =3D THIS_MODULE, > > =20 > > }; > >=20 > > @@ -156,6 +152,13 @@ static int bcm2835_pwm_probe(struct platform_device > > *pdev)>=20 > > if (ret) > > =09 > > return ret; > >=20 > > + 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; > > + } > > + > >=20 > > pc->chip.dev =3D &pdev->dev; > > pc->chip.ops =3D &bcm2835_pwm_ops; > > pc->chip.npwm =3D 2; =2D-=20 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/