Skip to content

nfc: nxp-nci: Turn the ST54L's NFC mode on after init - #131

Merged
derekross merged 3 commits into
derekross:omamobilefrom
W4HO-ham:tegu-nfc-st54l-mode
Oct 30, 2026
Merged

derekross merged 3 commits into
derekross:omamobilefrom
W4HO-ham:tegu-nfc-st54l-mode

Conversation

@W4HO-ham

@W4HO-ham W4HO-ham commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

This fixes the ST54L going silent on the Pixel 9a (derekross/omarchy-mobile#132). Stacked on #100; only the last commit is new.

About 2-3 s after init with no discovery running, the controller stopped answering on I2C until a power cycle. Tonight's tests ruled out the set-config, quick retries (the closed #128), forcing the clock pad on, runtime PM and the interrupt. ST's own HAL (platform/hardware/st/nfc, hal_wrapper.cc) does one more step after CORE_INIT: PROP_NFC_MODE_SET on (2f 02 02 02 01), then CORE_INIT again once the controller has reset. This does the same from post_setup, with a proprietary op for the response. The second CORE_INIT uses the NCI 2.0 form, because nci_core_init() sends 1.x and the ST54L rejects that as a syntax error (that was the -71 at power-on in the first try).

Tested on the palmtop: polling starts 3, 10, 30, 60 s and 3 minutes after power-on with no NACK, and stopping the poll loop no longer times out. Across two RTC-woken s2idle cycles, one with the adapter powered off around the sleep and one left powered, polling started again 20 s after the wake. That run used this patch on #119's tree, which has the reference clock patch the 9a needs; on #100's branch alone the clock pad has no consumer. The module is now the palmtop's boot NFC driver. checkpatch --strict is clean and it builds W=1 clean.

Phone

The palmtop, booted with this head's nxp-nci.ko as the boot NFC driver (release 7.3.0-rc6-omamobile-tegu-s2mpg15-m1-g991042e2eff3-dirty, core.c blob c96704ddd480). The module is built out of tree against that kernel's build directory and installed under /lib/modules/$(uname -r)/updates/nfc/.

phone-smoke: tegu

Kernel 7.3.0-rc6-omamobile-tegu-s2mpg15-m1-g991042e2eff3-dirty, tools at 34778a2, 2026-10-29T16:56Z.

Check Result Detail
boot (required) ok kernel 7.3.0-rc6-omamobile-tegu-s2mpg15-m1-g991042e2eff3-dirty, slot b, up 77s
storage guard (required) ok 62 partitions; only userdata and slot B's boot images writable
root (required) ok ext4 on userdata, 19G free
kernel health (required) ok no oops or BUG; 0 WARN, 306 error lines in dmesg
systemd units ok none failed
USB gadget (required) ok bound to 11210000.usb
display ok card1-DSI-1 connected, 1080x2424
GPU ok render node on panthor
session (required) ok Hyprland and the Omarchy shell running
lock ok PAM file present, the shell can lock (passwordPam true, locked false)
touch ok Synaptics TouchComm Touchscreen
buttons ok gpio-keys
Wi-Fi ok wlan0 on brcmfmac, link up
Bluetooth ok hci0, powered true
battery ok 90% Unknown, 32 °C
sound cards ok googleteguaocsn
sensors ok Accelerometer AmbientLight Proximity
cameras ok 3 listed by libcamera
thermal ok hottest zone 42 °C

Packages: hyprland 0.56.2-5.1, libcamera 0.7.2-4.22, mesa 1:26.2.4-1.4, omacam 0.3.3-1, omamobile-apps 0.2.0-1, omamobile-audio 0.4.1-1, omamobile-device-tegu 0.2.0-1, omamobile-fingerprint 0.1.8-1, omamobile-firstboot 0.1.0-1, omamobile-gnss 0.2.1-1, omamobile-keyring 20261013-1, omamobile-mirror 0.1.1-1, omamobile-modem 0.1.4-1, omamobile-omarchy 0.1.12-1, omamobile-owl-widgets 0.1.1-1, omamobile-sensors 0.2.1-1, omamobile-shell 0.2.36-1, omarchy 4.0.6-1

The ST54L in the Google Pixel 9a speaks plain NCI over I2C with an
enable line and an interrupt, the transport the nxp-nci driver
implements, rather than the NDLC framing of ST's ST21NFCB family
(st,st21nfcb-i2c), whose initialisation timed out on it. Add it as a
compatible with nxp,nxp-nci-i2c as the fallback.

Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
@W4HO-ham

Copy link
Copy Markdown
Contributor Author

With this driver as the boot driver on the palmtop (fresh boot, screen on, neard polling): a contactless payment card held on the upper back showed up in neard within 4 s as a Type 4A tag, ISO-DEP, ReadOnly false (/org/neard/nfc0/tag389). A first try a minute earlier saw nothing; I restarted the poll loop and the card was placed higher the second time, so I can't say which of the two mattered. No NDEF, as expected of a payment card.

@derekross

Copy link
Copy Markdown
Owner

Thank you, @W4HO-ham. This is a really good find. The A/B/C table on derekross/omarchy-mobile#132 is what settled it: the same NACK at 3 s with no sleep at all, with and without the set-config, with and without quick retries. And the fix follows ST's own HAL instead of a workaround. The card read this morning with this driver as the boot driver is good news too.

The checks pass on today's omamobile: a clean merge, sign-offs, prefixes, checkpatch --strict, the W=1 build of core.c, and CI's dt_binding_check. The Pixel 7 Pro's NFC uses st-nci, and this touches neither that driver nor net/nfc, so nothing changes there. The new step sits behind info->st54l, which is set only for st,st54l.

A few things before it merges:

  1. Please wait for the controller's CORE_RESET_NTF instead of sleeping 200 ms. In hal_wrapper.cc, the HAL sends PROP_NFC_MODE_SET with a 500 ms timer. On the response it does nothing ("wait for core_reset_ntf or timer timeout"), and it sends CORE_INIT only once the NTF arrives. So ST allows the reset more than 200 ms. If the NTF arrives late here, it lands while the CORE_INIT request is pending. The core's nci_core_reset_ntf_packet() calls nci_req_complete(ndev, NCI_STATUS_OK) unconditionally (net/nfc/nci/ntf.c), so the NTF would complete the CORE_INIT request. CORE_INIT's real response would then complete the SET_CONFIG request, and so on, every request one response off. The NCI core already gives you a way to wait for it. Complete the request from the proprietary response only on a failure, and on success leave it pending, so the core's reset-NTF handler completes it. nci_prop_cmd()'s 5 s timeout bounds the wait:

    static int nxp_nci_st54l_mode_rsp(struct nci_dev *ndev, struct sk_buff *skb)
    {
    	u8 status = skb->len ? skb->data[0] : NCI_STATUS_SYNTAX_ERROR;
    
    	/* on success the request ends with the controller's CORE_RESET_NTF */
    	if (status != NCI_STATUS_OK)
    		nci_req_complete(ndev, status);
    
    	return 0;
    }

    Then the msleep(200) goes. Before you switch, please check one thing with echo 'file net/nfc/nci/* +p' > /sys/kernel/debug/dynamic_debug/control: does every power-on (neard off and on, not only the first after boot) log the nci_ver 0x.., config_status 0x.. line after the mode command? If the controller ever skips the reset, this version would time out on that open, and I'd rather know that now.

  2. Leave other nxp-nci parts as they are, by construction. post_setup is gated, but the new prop_ops table applies to every nxp-nci device. In practice nothing sends an NXP part a proprietary command with OID 0x02. Still, one line keeps their behaviour exactly as it is today: in the response handler, if (!info->st54l) return -ENOTSUPP;. The core then logs "unsupported rsp opcode" as it does now.

  3. Which file was tested. The kernel release in the 10-28 runs (without this fix) and in the 10-29 runs (with it) is the same, 7.3.0-rc6-omamobile-tegu-s2mpg15-m1-g991042e2eff3-dirty, so the release can't tell the two builds apart. Could you post the blob id of the core.c you built (git hash-object drivers/nfc/nxp-nci/core.c in that tree)? This head's is 77fc35b61da5. If they match, the card read and the idle and sleep tests count for this commit. After the change in point 1, one short re-run is enough: power-on, polling at 3 s and at 30 s, and one card.

  4. This PR carries nfc: nxp-nci: the ST54L (Pixel 9a) reads cards #100. Merging this one lands nfc: nxp-nci: the ST54L (Pixel 9a) reads cards #100's two commits as well, so nfc: nxp-nci: the ST54L (Pixel 9a) reads cards #100's open points apply here. Your 13:30 run answers the first one in substance, once the blob id above matches. The second one is still open: a public source for the set-config values (0xa1, 0xa2, 0x80 and TOTAL_DURATION). The third, -EOPNOTSUPP from nxp_nci_fw_download() for the ST54L, is still only a suggestion. My plan is to merge this PR and close nfc: nxp-nci: the ST54L (Pixel 9a) reads cards #100, so the series lands in one piece, unless you'd rather I merge nfc: nxp-nci: the ST54L (Pixel 9a) reads cards #100 first. If I do that, this branch needs a rebase afterwards, because the commits get new ids. The tegu stack (arm64: dts: exynos: google: zumapro-tegu: Add the fuel gauge and USB-C port controller #119 and the draft Bring-up, not for merge: USB-C host mode on the Pixel 9a #127) carries its own copies of nfc: nxp-nci: the ST54L (Pixel 9a) reads cards #100's commits, so whichever lands second needs a rebase too.

Two small things:

  • The commit message has a broken line ("...in the NCI 2.0 form" / "nci_core_init() doesn't send"). Please reflow it. Could the HAL link point at a commit instead of refs/heads/main, so it doesn't move?
  • A question, not a request: hal_wrapper_close() sends PROP_NFC_MODE_SET again with the close mode before it shuts the I2C layer. Does the 9a's node have an enable GPIO, so nxp_nci_close() really puts the chip in its cold mode? If it doesn't, the controller might stay in NFC mode while neard has it powered off.

Please also paste a tools/phone-smoke report from the palmtop on this build into the description.

Thanks again. A controller that goes quiet two seconds after init is the kind of bug that eats a week, and you tracked it down in a night.

@W4HO-ham

Copy link
Copy Markdown
Contributor Author

Thanks for the careful read. All of it is in at 40ae7c0 (the branch is force-pushed, same three commits):

  1. CORE_RESET_NTF ends the request. The response handler completes the request only on a failure status; on success it leaves it pending and nci_core_reset_ntf_packet() completes it, bounded by nci_prop_cmd()'s 5 s timeout. The msleep(200) is gone. Your check: this kernel has no CONFIG_DYNAMIC_DEBUG, so I couldn't log the nci_ver/config_status line, but the timing says the same thing. If the controller ever skipped the reset, the power-on would take 5 s (the timeout) and fail; instead six power-ons in a row (neard off and on, not only the first after boot) each completed in 55-60 ms (one at 160 ms), no NACK, no timeout, and polling started at 3 s and at 30 s after a power-on. The log is in the omarchy-mobile tree as logs/tegu-review-20261029/nfc-ntf-test.out (not committed; I'll quote it in the plan).
  2. Other NXP parts: if (!info->st54l) return -ENOTSUPP; at the top of the response handler, so the core logs "unsupported rsp opcode" for them as before. checkpatch warns about ENOTSUPP, but it's what nci_prop_rsp_packet()'s caller compares against (net/nfc/nci/rsp.c), so EOPNOTSUPP wouldn't produce that log.
  3. Which file was tested. The 10-28/10-29 runs were on core.c blob 77fc35b61da5, your head's, so they count for that commit. The re-run above is on this head's blob c96704ddd480. The card read on this head waits for the owner's hand (this afternoon); I'll add it here when it's done.
  4. nfc: nxp-nci: the ST54L (Pixel 9a) reads cards #100: merging this and closing nfc: nxp-nci: the ST54L (Pixel 9a) reads cards #100 is fine with me; I'll rebase arm64: dts: exynos: google: zumapro-tegu: Add the fuel gauge and USB-C port controller #119 and Bring-up, not for merge: USB-C host mode on the Pixel 9a #127 afterwards. The public source for the set-config values is still open; I haven't found one, and I'd rather say so than cite something that doesn't show them. The -EOPNOTSUPP from nxp_nci_fw_download() I'll leave as it is unless you want it in this series.

Small things: the message is reflowed, and the HAL link now points at commit 91b182c6f6ef of platform/hardware/st/nfc. On the enable GPIO: the 9a's node has enable-gpios (a line on another bank, gpio-6 "enable"), and nxp_nci_close() drives it low through the I2C phy's cold mode, so the chip is reset at power-off. The separate nfc-chip-enable hog on gpa0-1 stays high; it's the chip's power enable, not VEN.

The smoke report from the boot with this module as the boot driver is in the description.

@derekross

Copy link
Copy Markdown
Owner

Thank you, @W4HO-ham. Everything I asked for is in, and the timing argument for the reset is a good substitute for the debug line: a skipped reset would show up as a failed open after 5 s, and six power-ons at about 60 ms rule that out.

I went through the new head against each point:

  1. The reset notification. The response handler now completes the request only on a failure, so on success the controller's CORE_RESET_NTF completes it through the core, within nci_prop_cmd()'s 5 s. I also checked the opposite order, in case the notification ever arrives before the response. That's safe too: the core sends the next command only after the mode response comes in, and that response completes nothing on success, so CORE_INIT can't be answered by the wrong packet.
  2. Other NXP parts. The -ENOTSUPP at the top is right, and you're right about checkpatch: nci_rsp_packet() compares against -ENOTSUPP to log "unsupported rsp opcode", so EOPNOTSUPP would change the log. Behaviour for every other nxp-nci part is the same as today.
  3. The tested file. Thank you for the blob ids. The 10-28/10-29 runs count for the first version, and the re-run for this head's c96704ddd480. The smoke report in the description looks good.
  4. nfc: nxp-nci: the ST54L (Pixel 9a) reads cards #100. Agreed: I'll merge this PR and close nfc: nxp-nci: the ST54L (Pixel 9a) reads cards #100, and thanks for taking the rebase of arm64: dts: exynos: google: zumapro-tegu: Add the fuel gauge and USB-C port controller #119 and Bring-up, not for merge: USB-C host mode on the Pixel 9a #127 afterwards.

The checks pass on today's omamobile, including CI's binding check, and the HAL link now points at a fixed commit (the same file I read last time, with the 500 ms timer and "wait for core_reset_ntf").

A source for the set-config values. I think I found a public one for three of the four. Google's AOSP tree for the Pixel 7 and 7 Pro has the same three values in CORE_CONF_PROP in its ST HAL configuration:
https://android.googlesource.com/device/google/pantah/+/b9712d3e5c48fb58c93aad8b00fd77629ec77a28/nfc/libnfc-hal-st.conf#153
(20, 02, 0a, 03, a1, 01, 1e, a2, 01, 19, 80, 01, 01, which is a CORE_SET_CONFIG with exactly your 0xa1, 0xa2 and 0x80). If you agree it's the same configuration, a Link: to it in the second commit's message would close that point, since the commit lands with this PR. I didn't find TOTAL_DURATION 500 ms in a public file. Where did that value come from? If it came from a log of stock on your phone, saying so in the message is fine. Neither of these holds up the merge.

The one thing I'm waiting for is the card read on this head that you mentioned. Once it's posted here, I'll merge.

Thanks again. The fix is small, follows ST's own sequence, and the history of how you got there is all on the record.

@W4HO-ham

Copy link
Copy Markdown
Contributor Author

Thanks. Agreed on all four, and on the opposite-order case: the mode response completes nothing on success, so a notification that arrives first can't answer the wrong request.

The pantah libnfc-hal-st.conf line is the same configuration: 20, 02, 0a, 03, a1, 01, 1e, a2, 01, 19, 80, 01, 01 is a CORE_SET_CONFIG with exactly the three proprietary values the second commit sends, and the 9a's own HAL configuration in its factory image (vendor/etc/nfc/libnfc-hal-st.conf, CORE_CONF_PROP) has the identical bytes, so the public file stands in for it. I'll add the Link: to the second commit's message with the next rewrite of this branch (I can't force-push from here today); if you merge before that, please add it at merge.

TOTAL_DURATION 500 ms isn't in either HAL file. It's the NFC stack's default poll-loop duration (libnfc-nci's NFA_DM_DISC_DURATION_POLL, 500 ms), which the stack sends as TOTAL_DURATION in its own CORE_SET_CONFIG when polling starts, and which neard doesn't send; the driver's set-config carries it so the controller polls at stock's cadence. The message should say that rather than "as the 9a's HAL configuration sets", and it will with the same rewrite.

The card read on this head is the one thing left; it needs the owner's hand and is queued for when he's back today.

@W4HO-ham

Copy link
Copy Markdown
Contributor Author

The card read on this head (core.c blob c96704ddd480, the boot driver in updates/nfc), 2026-10-30 morning on the palmtop: a contactless payment card held on the upper back was found within a 60 s initiator poll (nfctool: Targets found for nfc0, Tags: [ tag0 ]), no I2C NAKs, the usual unknown ntf 0x107 the only kernel line.

It took three tries to get there, and the reason is worth recording for #100: on this boot the NFC clock pad (PMU 0x3e84) was off. The palmtop now boots from its device package, and the hand script that used to set the pad at boot no longer runs, while the driver still came up over I2C and answered every NCI command, so neard reported Powered and Polling with nothing ever found. Setting the pad (tegu-nfc-clkpad extpad=1: 0x3e84 read 0x00000000, written 0x00010000) and rebinding the driver made the very next poll find the card. So a controller that talks NCI but never sees a tag is the clock pad, and #100's in-driver handling is what removes the trap.

@derekross

Copy link
Copy Markdown
Owner

Thank you, @W4HO-ham, for the card read on this head. That was the last thing I was waiting for, and the clock pad story is worth having on the record for the 9a. Before I merge, the second commit's message needs the two changes from your reply: TOTAL_DURATION 500 ms is libnfc-nci's default poll duration rather than something the 9a's HAL configuration sets, and a Link: to the pantah libnfc-hal-st.conf line. You offered to let me add them at merge, so I'll make exactly those two edits on your branch, keeping your sign-off, and merge; I'll close #100 as landed here.

One question, not for this PR: the "tegu-nfc-clkpad extpad=1" step writes PMU register 0x3e84. Where does that tool live, and does it go through the kernel's PMU regmap rather than /dev/mem? Userspace PMU access is one of our hard rules. #104 is the proper fix, so that step can go away once it lands.

@W4HO-ham

Copy link
Copy Markdown
Contributor Author

Both edits at merge are fine with me, thanks.

On the clock pad: the tool is a bring-up kernel module, tegu-nfc-clkpad.ko (source in my logs, logs/tegu-nfc-20261026/clkpad/tegu-nfc-clkpad.c, not in a repository), not a userspace write. It takes the kernel's SMC-backed PMU regmap with exynos_get_pmu_regmap() and does one regmap_update_bits() on 0x3e84 (EXTPAD_EN | PAD_EN), reads the register back, logs both values and is removed again; nothing touches /dev/mem. On the palmtop a hand unit runs insmod tegu-nfc-clkpad.ko extpad=1 && rmmod once at boot, between systemd-modules-load and sysinit, so the pad is on before nxp-nci binds; as of this afternoon the unit leaves a hang marker before the write and clears it after. It goes away when #104 lands.

The ST54L answers NCI on nxp-nci's transport and polls, but never
reports a target: in 25 s of discovery with a contactless card held on
the Pixel 9a, no RF_INTF_ACTIVATED_NTF came. ST's HAL sends a
CORE_SET_CONFIG after CORE_INIT (proprietary parameters 0xa1, 0xa2 and
0x80, which the 9a's own HAL configuration sets, and TOTAL_DURATION
500 ms, libnfc-nci's default poll duration, NFA_DM_DISC_DURATION_POLL).
Send the same from post_setup when the device is st,st54l.

Tested on the Pixel 9a (7.3.0-rc6-omamobile-tegu-s2mpg15-m1, with the
same command behind a module parameter in a debug build): the
set-config answers status 0, and the held card activates (ISO-DEP over
NFC-A, 15 activations in 45 s) and neard lists it as a tag.

Link: https://android.googlesource.com/device/google/pantah/+/b9712d3e5c48fb58c93aad8b00fd77629ec77a28/nfc/libnfc-hal-st.conf#153
Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
On the Pixel 9a the ST54L stops answering on I2C about 2-3 s after init
whenever no discovery runs: the next command gets no ACK, retries don't
help, and every NCI request times out until the adapter is powered off
and on. Its clock and the set-config sent after init aren't the cause.

ST's HAL does one more step after CORE_INIT: PROP_NFC_MODE_SET with mode
on (2f 02 02 02 01), after which the controller resets and is
initialised again. Do the same from post_setup, before the set-config:
the mode command, whose request ends with the controller's
CORE_RESET_NTF rather than with its response (the HAL waits for that
notification too; the NCI core completes the request from the
notification, and nci_prop_cmd()'s timeout bounds the wait), then
CORE_INIT again in the NCI 2.0 form, which nci_core_init() doesn't send
(the ST54L rejects the 1.x form as a syntax error). The proprietary
response handler refuses other NXP parts, so their behaviour doesn't
change.

Tested on the Pixel 9a, with the board's reference clock enabled: polling
now starts 3, 10, 30, 60 s and 3 minutes after power-on with no NACK,
where it failed every time from 3 s on, and stopping the poll loop no
longer times out. Across two RTC-woken s2idle cycles (one with the adapter
powered off around the sleep, one left powered) polling started again 20 s
after the wake, with no NACK. With the request ending on the
notification, six power-ons in a row each completed in about 60 ms, and
polling started at 3 s and at 30 s after power-on, with no NACK.

Link: https://android.googlesource.com/platform/hardware/st/nfc/+/91b182c6f6efcfb2b01ce0f77930c6a814314b5c/st21nfc/hal_wrapper.cc
Link: derekross/omarchy-mobile#132
Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
@derekross
derekross force-pushed the tegu-nfc-st54l-mode branch from 40ae7c0 to 46bbbc6 Compare October 30, 2026 20:24
@derekross
derekross merged commit a0948de into derekross:omamobile Oct 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants