From nobody Fri Jun 11 14:21:13 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 8D9B57CA7CA for ; Fri, 11 Jun 2021 14:21:13 +0000 (UTC) (envelope-from mgrooms@shrew.net) Received: from mx1.shrew.net (mx1.shrew.net [38.97.5.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4G1jgr6W2vz3M3d for ; Fri, 11 Jun 2021 14:21:12 +0000 (UTC) (envelope-from mgrooms@shrew.net) Received: from mail.shrew.net (mail.shrew.prv [10.24.10.20]) by mx1.shrew.net (8.15.2/8.15.2) with ESMTP id 15BELBlJ017956 for ; Fri, 11 Jun 2021 09:21:11 -0500 (CDT) (envelope-from mgrooms@shrew.net) Received: from [10.22.200.30] (unknown [136.49.68.36]) by mail.shrew.net (Postfix) with ESMTPSA id C2E8D19AC88 for ; Fri, 11 Jun 2021 09:21:06 -0500 (CDT) Subject: Re: RPI4 Hardware PWM To: freebsd-arm@freebsd.org References: <9bb7f3d1-8256-be26-ba87-90946ce1b95f@shrew.net> <05ec75e0-8b9c-e69f-904d-6166337611e0@shrew.net> From: Matthew Grooms Message-ID: Date: Fri, 11 Jun 2021 09:21:13 -0500 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 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 In-Reply-To: <05ec75e0-8b9c-e69f-904d-6166337611e0@shrew.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.shrew.net [10.24.10.10]); Fri, 11 Jun 2021 09:21:12 -0500 (CDT) X-Rspamd-Queue-Id: 4G1jgr6W2vz3M3d X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of mgrooms@shrew.net designates 38.97.5.131 as permitted sender) smtp.mailfrom=mgrooms@shrew.net X-Spamd-Result: default: False [-3.30 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; RBL_DBL_DONT_QUERY_IPS(0.00)[38.97.5.131:from]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_ALLOW(-0.20)[+mx]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[freebsd-arm@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; SPAMHAUS_ZRD(0.00)[38.97.5.131:from:127.0.2.255]; RCVD_COUNT_THREE(0.00)[3]; DMARC_NA(0.00)[shrew.net]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:174, ipnet:38.0.0.0/8, country:US]; RCVD_TLS_LAST(0.00)[]; MAILMAN_DEST(0.00)[freebsd-arm]; RECEIVED_SPAMHAUS_PBL(0.00)[136.49.68.36:received] X-ThisMailContainsUnwantedMimeParts: N 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: >> 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: > 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: -Matthew