From nobody Wed Nov 13 03:57:34 2024 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 4Xp8dY0Kyhz5d5x2 for ; Wed, 13 Nov 2024 03:58:09 +0000 (UTC) (envelope-from darius@dons.net.au) Received: from midget.dons.net.au (midget.dons.net.au [IPv6:2403:580d:ae98:0:225:90ff:fe47:39b4]) by mx1.freebsd.org (Postfix) with ESMTP id 4Xp8dT2m7kz3y7b for ; Wed, 13 Nov 2024 03:58:05 +0000 (UTC) (envelope-from darius@dons.net.au) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=dons.net.au header.s=default header.b=SlMqvNoM; spf=pass (mx1.freebsd.org: domain of darius@dons.net.au designates 2403:580d:ae98:0:225:90ff:fe47:39b4 as permitted sender) smtp.mailfrom=darius@dons.net.au; dmarc=pass (policy=quarantine) header.from=dons.net.au Received: from smtpclient.apple (unknown [IPv6:2001:44b8:1d2:8900:e90b:1a29:9ed9:195]) by midget.dons.net.au (Postfix) with ESMTPSA id 1F3FD72E799; Wed, 13 Nov 2024 14:27:52 +1030 (ACDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dons.net.au; s=default; t=1731470273; bh=v+QerYHWdoIsp6mRr+gAsG2p68QTwvOXMQcZdWYPvU4=; h=From:Date:Subject:To; b=SlMqvNoMlghk5upP0PERVdzGTI3J306w90iC0KlJIBJ/TVblNJa+Fc/OrfixH8ySD IF+AUszns4FQJl1c5UQWHIKdgQ/o2bz/k2NwjisP8vrVWDORjc172WKmBGms43fx96 2JPMHHIDPSdu4s6xQHgV1rlRUh/CUIkojVnAuIV+WTVl0qdDM/LSQ8944P+xoTJOHg IY9JuwnOW+6ii60BmVgzFWh0z/Bd89tTVj+HnUTl6Uu627vHHnX/fnnTCjaf7LatSx pNnmd4QbTo2CMj+wyUiNTVklbizSIDLrYt+W+2eQnRh9ss3qJSPva56GekVCt0tkAe Wvagx7Cl4CRsQ== From: Daniel O'Connor Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable 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 (Mac OS X Mail 16.0 \(3776.700.51\)) Date: Wed, 13 Nov 2024 14:27:34 +1030 Subject: I2C on Raspberry Pi 4B has wrong clock rate? Message-Id: To: freebsd-arm@freebsd.org X-Mailer: Apple Mail (2.3776.700.51) X-Rspamd-Action: no action X-Rspamd-Server: midget.dons.net.au X-Spam-Status: No, score=0.90 X-Spamd-Result: default: False [-2.80 / 15.00]; SUBJECT_ENDS_QUESTION(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.998]; DMARC_POLICY_ALLOW(-0.50)[dons.net.au,quarantine]; R_DKIM_ALLOW(-0.20)[dons.net.au:s=default]; R_SPF_ALLOW(-0.20)[+mx]; ONCE_RECEIVED(0.10)[]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_TRACE(0.00)[dons.net.au:+]; RCPT_COUNT_ONE(0.00)[1]; FROM_HAS_DN(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ASN(0.00)[asn:4764, ipnet:2403:5800::/27, country:AU]; TO_DN_NONE(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_ONE(0.00)[1]; MLMMJ_DEST(0.00)[freebsd-arm@freebsd.org]; APPLE_MAILER_COMMON(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+] X-Rspamd-Queue-Id: 4Xp8dT2m7kz3y7b X-Spamd-Bar: -- Hi, I have an RPi4B with (currently) FreeBSD 13.1 on it which has a PiJuice = (https://github.com/PiSupply/PiJuice/tree/master) hat on it as a mini = UPS. This has an I2C interface which emulates an RTC at 0x68 as well as has = its own control/status at 0x14. If I boot up Linux this is detected fine, eg doconnor@rpitest:~ $ i2cdetect -l i2c-0 i2c i2c-22-mux (chan_id 0) I2C = adapter i2c-1 i2c bcm2835 (i2c@7e804000) I2C = adapter i2c-10 i2c i2c-22-mux (chan_id 1) I2C = adapter i2c-20 i2c fef04500.i2c I2C = adapter i2c-21 i2c fef09500.i2c I2C = adapter i2c-22 i2c bcm2835 (i2c@7e205000) I2C = adapter doconnor@rpitest:~ $ i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- 10: -- -- -- -- 14 -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- doconnor@rpitest:~ $ i2ctransfer -y 1 w1@0x14 0x40 r1 0x34 And the logic analyser I have sniffing the bus shows what I expect: i2c-1: Address write: 14 i2c-1: ACK i2c-1: Data write: 40 i2c-1: ACK i2c-1: Start repeat i2c-1: Read i2c-1: Address read: 14 i2c-1: ACK i2c-1: Data read: 34 i2c-1: NACK i2c-1: Stop I checked using a 'scope and the bus appears to be running at about = 40kHz (bit weird, but OK..) However on FreeBSD it looks like the I2C bus is not working correctly, I = have modified config.txt as per = https://lists.freebsd.org/pipermail/freebsd-arm/2021-May/023713.html = (otherwise the bus hangs). Most of the time scanning fails, if I spam it I get: [rpi13 3:41] ~ >while [ 1 ]; do sudo i2c -m tr -s 2>/dev/null | grep -v none done Scanning I2C devices on /dev/iic0: 68 Scanning I2C devices on /dev/iic0: 68 Scanning I2C devices on /dev/iic0: 68 Scanning I2C devices on /dev/iic0: 14 Scanning I2C devices on /dev/iic0: 15 Scanning I2C devices on /dev/iic0: 68 Scanning I2C devices on /dev/iic0: 14 68 .. ie 15 is definitely wrong, "14 68" is what I would expect. If I try and read the pijuice firmware version: [rpi13 3:45] ~ >while ! sudo i2c -m tr -a 0x14 -d r -c 1 -o 0xfd; do done i2c: ioctl(I2CRDWR) failed: Input/output error i2c: ioctl(I2CRDWR) failed: Input/output error i2c: ioctl(I2CRDWR) failed: Input/output error i2c: ioctl(I2CRDWR) failed: Input/output error i2c: ioctl(I2CRDWR) failed: Input/output error i2c: ioctl(I2CRDWR) failed: Input/output error i2c: ioctl(I2CRDWR) failed: Input/output error i2c: ioctl(I2CRDWR) failed: Input/output error 17 ie it fails often and also usually gets the wrong answer (should be 1.6) Checking with the 'scope shows the bus running at about 200kHz however = sysctl says it should be 100kHz: [rpi13 3:54] ~ >sysctl dev.iichb dev.iichb.0.debug: 0 dev.iichb.0.rise_edge_delay: 48 dev.iichb.0.fall_edge_delay: 48 dev.iichb.0.clock_stretch: 64 dev.iichb.0.frequency: 100000 dev.iichb.0.%parent: simplebus0 dev.iichb.0.%pnpinfo: name=3Di2c@7e804000 compat=3Dbrcm,bcm2711-i2c dev.iichb.0.%location: dev.iichb.0.%driver: iichb dev.iichb.0.%desc: BCM2708/2835 BSC controller dev.iichb.%parent: twsi I tried setting the frequency but it does not 'stick': [rpi13 3:56] ~ >sudo sysctl dev.iichb.0.frequency=3D10000 dev.iichb.0.frequency: 100000 -> 100000 Does anyone have suggestions for what I can try? Thanks. -- Daniel O'Connor "The nice thing about standards is that there are so many of them to choose from." -- Andrew Tanenbaum