From nobody Tue Jul 20 18:12:41 2021 X-Original-To: freebsd-arm@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 2D1291240D57 for ; Tue, 20 Jul 2021 18:12:46 +0000 (UTC) (envelope-from ian@freebsd.org) Received: from outbound5c.ore.mailhop.org (outbound5c.ore.mailhop.org [54.244.192.240]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4GTmz16CLTz3Pfh for ; Tue, 20 Jul 2021 18:12:45 +0000 (UTC) (envelope-from ian@freebsd.org) ARC-Seal: i=1; a=rsa-sha256; t=1626804764; cv=none; d=outbound.mailhop.org; s=arc-outbound20181012; b=C0/wmNAqJ8kTNyKa8B/HcD5B5+ggbYpakxCzsvqnrT29MqlIo8U7NpEcIYEdb2X0UFdhFZu7F/aQ+ u3jhX5rvNVaWPsCty5yNdJOEFznFrAMJpmX6p0lmIbop8i/5cevhKmFd9ECJJ0rEU2m/c1mfBw6u8a xV+REOYsN9n3auQEaA59xSp4c5mONn27CfVjGkbnray9/NDhMVyq0kzNkZG0pqe0lvD/LCcI6/0mnM 5UAYqAFXVNfwLK6Ojp0W+fJ12vA1nxDjkDgxGE3ZnDFk+Pp8MA8dvY1wpgiEtmV6BUspPM5cgWfkxX VTqGbSMubOt53IeWOWjCItmsQ4GJ7dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=arc-outbound20181012; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:to:from:subject:message-id:dkim-signature:from; bh=CnNQTdVllQaTHmmhhZrWRzaB1gAOQLGm14LUKX34BKw=; b=bX4iTMRiR/HJx3HSmzqowRsZsJWYAH8tSb0iRqWO0ig4/YmnCtl4f6vtdaMjN5m9uPbFEVCZv/hyG j9RFbE5omiv+bhPNhqY1bYqOfVoBqxJWMtS0exZ2VZhtNqhg3/9xqtCdv5ZJMcf//wxmwuKHOPSYWw R4YWgorupQgIwpkAN+P/Ny61wOtR4bDRzFpQBwEnGem62jVNGJdLSqpi76DFNM7aPBHwCx2pH1inA3 LS1jZAZzdNAaWvNSXis+b/jffPGqvbpeQ+SeuLNDLB4FOBf64AWTbxXTntRMFclBdlkHyKtauJyGQm dn6ut5YAsKh+TOG+Zy6Vw5+XNwuALYQ== ARC-Authentication-Results: i=1; outbound3.ore.mailhop.org; spf=softfail smtp.mailfrom=freebsd.org smtp.remote-ip=67.177.211.60; dmarc=none header.from=freebsd.org; arc=none header.oldest-pass=0; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=dkim-high; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:to:from:subject:message-id:from; bh=CnNQTdVllQaTHmmhhZrWRzaB1gAOQLGm14LUKX34BKw=; b=abeg3PypcA/mLQ/aUHsax4weaM13gyjwyVJI6Qd4QCHSCFb3yW+T24AEI+l0gFTmnx1Igoo9CBxWE S+XqvJR7SYQuzLNuUcuNL6NLvWSnz+oXBLsreCqETHVt3QcnqQXrYuf0Ls5xi52gIwFc5pLHK/gvcN TN1f1MC6ZT0kuVFxItgoKKmwnTryAiYax7EKKiEQbz2w4o9aZ9v/MJ2NVT8OrU+qyoOx01//kRHfyX VcV6kVs6EnEp78xhCCk9Hvj9zipwvDebD83ySx2Hlw+HdNUDf68IxF/BCyR4OHJ6Vcl5yjAiws9Vcu mID0MS0U216EyTQIXnX2faaGh8V6yHg== X-Originating-IP: 67.177.211.60 X-MHO-RoutePath: aGlwcGll X-MHO-User: 132a9b99-e986-11eb-9168-bf9d68d023b6 X-Report-Abuse-To: https://support.duocircle.com/support/solutions/articles/5000540958-duocircle-standard-smtp-abuse-information X-Mail-Handler: DuoCircle Outbound SMTP Received: from ilsoft.org (c-67-177-211-60.hsd1.co.comcast.net [67.177.211.60]) by outbound3.ore.mailhop.org (Halon) with ESMTPSA id 132a9b99-e986-11eb-9168-bf9d68d023b6; Tue, 20 Jul 2021 18:12:43 +0000 (UTC) Received: from rev (rev [172.22.42.240]) by ilsoft.org (8.15.2/8.15.2) with ESMTP id 16KICfXD019005; Tue, 20 Jul 2021 12:12:41 -0600 (MDT) (envelope-from ian@freebsd.org) Message-ID: Subject: Re: RPI4 Hardware PWM From: Ian Lepore To: Matthew Grooms , freebsd-arm@freebsd.org Date: Tue, 20 Jul 2021 12:12:41 -0600 In-Reply-To: References: <9bb7f3d1-8256-be26-ba87-90946ce1b95f@shrew.net> <05ec75e0-8b9c-e69f-904d-6166337611e0@shrew.net> Content-Type: text/plain; charset="ASCII" X-Mailer: Evolution 3.28.5 FreeBSD GNOME Team List-Id: Porting FreeBSD to ARM processors List-Archive: https://lists.freebsd.org/archives/freebsd-arm List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-arm@freebsd.org Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4GTmz16CLTz3Pfh X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: N On Tue, 2021-07-20 at 12:30 -0500, Matthew Grooms wrote: > On 6/11/2021 9:21 AM, Matthew Grooms wrote: > > On 6/11/2021 9:19 AM, Matthew Grooms wrote: > > > On 6/9/2021 4:16 PM, Matthew Grooms wrote: > > > > On 6/8/2021 4:06 PM, Matthew Grooms wrote: > > > > > Hey All, > > > > > > > > > > I have a project I'm working on that depends on interfacing > > > > > with a > > > > > few sensor modules using both i2c and PWM. I've got the i2c > > > > > devices > > > > > to work correctly, but I'm not sure how to interface with the > > > > > HW > > > > > PWM support of the RPI4. I can see there are settings exposed > > > > > via > > > > > sysctl for Beaglebone systems ... > > > > > > > > > > https://zewaren.net/bbb-pwm.html > > > > > > > > > > I was hoping I'd be able to force GPIO 12 or 13 into ALT0 and > > > > > set > > > > > the duty values via sysctl, but that doesn't seem to be an > > > > > option. > > > > > Any help would be greatly appreciated. > > > > > > > > Replying to myself with a bit more info. I see that there is a > > > > driver available for rpi boards authored by PHK ... > > > > > > > > https://cgit.freebsd.org/src/tree/sys/arm/broadcom/bcm2835/bcm2835_pwm.c > > > > > > > > > > > > > > > > That has notes on RPi2/3 boards, but not mention of RPi4. When > > > > I > > > > load that, I see the following output ... > > > > > > > > Jun 9 18:29:50 generic kernel: pwm0: > > > controller> > > > > mem 0x7e20c000-0x7e20c027 on simplebus0 > > > > Jun 9 18:29:50 generic kernel: pwm0: cannot find Clock Manager > > > > > > > > I assume I'm doing something wrong. Any feedback would be > > > > greatly > > > > appreciated. > > > > > > Hey Everyone, > > > > > > I decided to take a look at the patch that introduced rpi4 > > > support in > > > Linux. I'm pretty out of my depth here but they didn't look all > > > that > > > extensive. One obvious difference that stood out was that the > > > FreeBSD > > > clock manager driver only appears to load for the bcm2835 part > > > while > > > the Linux driver loads for both 2835 and 2711. Adding the > > > following > > > line to the clkman driver allows the pwm driver to load without > > > an > > > error now ... > > > > > > --- bcm2835_clkman.c 2021-06-11 09:06:19.893728000 -0500 > > > +++ bcm2835_clkman.c 2021-06-11 08:50:44.646221000 -0500 > > > @@ -51,6 +51,7 @@ > > > #include > > > > > > static struct ofw_compat_data compat_data[] = { > > > + {"brcm,bcm2711-cprman", 1}, > > > {"brcm,bcm2835-cprman", 1}, > > > {"broadcom,bcm2835-cprman", 1}, > > > {NULL, 0} > > > > > > root@generic:/home/mgrooms # tail -n 1 /var/log/messages > > > Jun 11 08:35:58 generic kernel: pwm0: > > controller> > > > mem 0x7e20c000-0x7e20c027 on simplebus0 > > > > > > Additionally, there appears to be valid sysctl values for the > > > hardware pwm devices now. I'll try testing them out and see if I > > > can > > > determine if they're working as expected and report back. > > > > Woops. I was going to include these for reference: > > > > root@generic:/home/mgrooms # sysctl -a | grep pwm > > dev.pwm.0.mode2: 0 > > dev.pwm.0.ratio2: 2500 > > dev.pwm.0.period2: 10000 > > dev.pwm.0.pwm_freq2: 0 > > dev.pwm.0.mode: 0 > > dev.pwm.0.freq: 125000000 > > dev.pwm.0.ratio: 2500 > > dev.pwm.0.period: 10000 > > dev.pwm.0.pwm_freq: 0 > > dev.pwm.0.%parent: simplebus0 > > dev.pwm.0.%pnpinfo: name=pwm@7e20c000 compat=brcm,bcm2835-pwm > > dev.pwm.0.%location: > > dev.pwm.0.%driver: pwm > > dev.pwm.0.%desc: BCM2708/2835 PWM controller > > dev.pwm.%parent: > > > > Hey everyone. I just wanted to follow up on this. I can confirm that > with that one line patch, hardware pwm appears to be working reliably > on > my rpi4b. Since I struggled to find man pages that explain what > these > values do ( maybe just missed a man page? ), here are some notes I > took: > > /sbin/sysctl dev.gpio.0.pin.12.function=alt0 # set pin to hw pwm > function > /sbin/sysctl dev.pwm.X.mode=1 # 0 = off | 1 = on > /sbin/sysctl dev.pwm.X.freq=1000000 # clock frequency > /sbin/sysctl dev.pwm.X.period=1000 # pwm_freq = freq / > period > /sbin/sysctl dev.pwm.X.ratio=500 # 0 - period = 0 - > 100% > duty cycle > > dev.pwm.0.mode2: 0 > dev.pwm.0.ratio2: 2500 > dev.pwm.0.period2: 10000 > dev.pwm.0.pwm_freq2: 0 > dev.pwm.0.mode: 1 > dev.pwm.0.freq: 1000000 > dev.pwm.0.ratio: 0 > dev.pwm.0.period: 1000 > dev.pwm.0.pwm_freq: 1000 > dev.pwm.0.%parent: simplebus0 > dev.pwm.0.%pnpinfo: name=pwm@7e20c000 compat=brcm,bcm2835-pwm > dev.pwm.0.%location: > dev.pwm.0.%driver: pwm > dev.pwm.0.%desc: BCM2708/2835 PWM controller > dev.pwm.%parent: > > For the above example: A ratio value of 0 would be a 0% duty cycle, > 500 > would be 50% and 1000 would be 100%. Hopefully this helps someone > else > in the future. > > -Matthew > The documentation problem comes from the fact that the rpi pwm driver was written before pwmbus and pwm(8) came along; those are the ones that are documented. The rpi driver really should be changed to fit into the newer pwmbus architecture. But the rpi code doesn't have much in the way of active mantainers. -- Ian