Linux I2C Stack & Single-Arg probe()
Derive why a shared two-wire bus requires open-drain wired-AND pads and external pull-up resistors, trace how Linux 6.12 separates SoC i2c_adapter controllers from Device Tree i2c_client peripherals, and bind a sensor driver using the single-argument probe() contract.
What you'll learn
- Compare
i2c_adapter/i2c_algorithmcontroller drivers against Device-Tree-matchedi2c_client/i2c_drivermodules. - Construct a Linux 6.12 single-argument
.probe(struct i2c_client *client)driver withof_match_tableandid_table. - Audit i.MX6ULL
I2C1IOMUXC open-drain (ODE) andSIONpad flags for reliableACK/clock stretching.
Adapter-Core-Client Topology, Device Tree Binding & Single-Arg probe()
Trace the three-column kernel object graph in Figure 1.2b. During boot, drivers/i2c/busses/i2c-imx.c binds &i2c1, configures IFDR for clock-frequency = <100000> (9 clocks/byte = 90 us/byte), and registers struct i2c_adapter. Immediately inside i2c_register_adapter(), of_i2c_register_devices() walks every child node of &i2c1, validates that reg = <0x1e> fits in a 7-bit address (0x03..0x77, never pre-shifted to 8-bit 0x3c!), and allocates struct i2c_client (client->addr = 0x1e, client->adapter = &i2c1). Note that creating struct i2c_client from Device Tree does not yet touch the physical wire—bus traffic happens only when .probe() runs!
Why do older out-of-tree I2C drivers fail to compile on Linux 6.12 LTS? Prior to Linux 6.3/6.6, struct i2c_driver carried a legacy two-argument int (*probe)(struct i2c_client *client, const struct i2c_device_id *id) alongside a transitional .probe_new pointer. Because Device Tree drivers match via .driver.of_match_table (of_device_get_match_data(&client->dev)) rather than legacy board-file id tables, mainline removed .probe_new and converted .probe permanently to int (*probe)(struct i2c_client *client) (if a driver still needs its i2c_device_id entry, it calls i2c_client_get_device_id(client)). Never cast a two-argument function pointer to silence the compiler—that causes Undefined Behavior (CFI panic on hardened kernels)!
Figure 1.2b. How Linux 6.12 decouples the SoC i2c_adapter controller (left) from Device Tree i2c_client instantiation (center) and portable single-argument i2c_driver modules (right).
| Instantiation / Access Path | Where 7-Bit Address Lives | Kernel Driver Binds? | Engineering Use Case |
|---|---|---|---|
Device Tree child (ap3216c@1e) | Board .dts (reg = <0x1e>) | Yes (of_match_table) | Production standard on ARM/RISC-V |
i2c_new_client_device(adap, &info) | Parent C driver (i2c_board_info) | Yes (id_table / fwnode) | Dynamic daughterboards / PMIC sub-cells |
Sysfs new_device (echo name 0x1e) | User-space shell command | Yes (id_table) | Bench bring-up before updating .dts |
Raw /dev/i2c-N (i2c-dev ioctl) | User-space C / i2cdetect | No (UU if driver bound!) | Hardware diagnostics & one-off tooling |
Examine the Device Tree fragment and matching Linux 6.12 client driver below. Notice how 0x4001b8b0 sets both SION and ODE on I2C1_SCL/I2C1_SDA, reg = <0x1e> passes the unshifted 7-bit address, and module_i2c_driver(ap3216c_driver) replaces boilerplate module_init()/module_exit() functions.
learner@ksa:~/gl-e06/m01-l02$ bat -H 4 -H 10 -H 16 -H 17 imx6ull_i2c1_ap3216c.dtsi File: imx6ull_i2c1_ap3216c.dtsi /* Linux 6.12 Device Tree fragment for I2C1 and one light sensor */ pinctrl_i2c1: i2c1grp { fsl,pins = < MX6UL_PAD_UART4_TX_DATA__I2C1_SCL 0x4001b8b0 MX6UL_PAD_UART4_RX_DATA__I2C1_SDA 0x4001b8b0 >; }; &i2c1 { clock-frequency = <100000>; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_i2c1>; status = "okay"; ap3216c@1e { compatible = "liteon,ap3216c"; reg = <0x1e>; }; };- 0x4001b8b0 enables bit 30 (SION input loopback) and bit 11 (ODE open-drain) so slave ACK and clock stretching work safely.
- 100 kHz Standard mode: 9 SCL clocks per byte (8 data + 1 ACK) = 90 microseconds per byte.
- compatible string matched against ap3216c_driver.driver.of_match_table.
- Unshifted 7-bit I2C address 0x1e stored directly in client->addr.
learner@ksa:~/gl-e06/m01-l02$ bat -H 5 -H 17 -H 22 -H 27 ap3216c_bind.c File: ap3216c_bind.c #include <linux/i2c.h> #include <linux/module.h> #include <linux/of.h> static int ap3216c_probe(struct i2c_client *client) { struct ap3216c_dev *dev = devm_kzalloc(&client->dev, sizeof(*dev), GFP_KERNEL); if (!dev) return -ENOMEM; dev->client = client; i2c_set_clientdata(client, dev); return 0; } static const struct of_device_id ap3216c_of_match[] = { { .compatible = "liteon,ap3216c" }, { } }; MODULE_DEVICE_TABLE(of, ap3216c_of_match); static const struct i2c_device_id ap3216c_id[] = { { "ap3216c" }, { } }; static struct i2c_driver ap3216c_driver = { .driver = { .name = "ap3216c", .of_match_table = ap3216c_of_match }, .probe = ap3216c_probe, .id_table = ap3216c_id, }; module_i2c_driver(ap3216c_driver); MODULE_LICENSE("GPL");- Linux 6.12 passes only struct i2c_client *; call i2c_client_get_device_id(client) if legacy ID data is needed.
- Primary Device Tree binding table exported to depmod via MODULE_DEVICE_TABLE(of, ...).
- Retain id_table so sysfs new_device bench instantiation still matches.
- Assign single-argument probe directly to .probe; .probe_new was removed in Linux 6.6+.
i2c_driver(9) GL-E06 Quick Reference i2c_driver(9) NAME i2c_driver - Linux 6.12 I2C client driver registration and single-arg probe SYNOPSIS #include <linux/i2c.h> module_i2c_driver(driver); int (*probe)(struct i2c_client *client); void (*remove)(struct i2c_client *client); DESCRIPTION Binds a peripheral driver to DT-instantiated i2c_client devices via .driver.of_match_table and .id_table. Linux 6.12 removed the old two-arg probe(client, id) and .probe_new fields. FLAGS I2C_CLIENT_TEN 10-bit addressing mode (default 0 = 7-bit address 0x03..0x77). ERRORS ENODEV No matching DT compatible or i2c_device_id entry found. EIO / ETIMEDOUT: Missing pull-up, wrong address, or SION/ODE pad misconfig. Kernel Systems Academy Lesson 1.2 i2c_driver(9) GL-E06 quick reference · full manual page: man 9 i2c_driver Modeling of_match_table Precedence and Pad Bitfield Guards in ISO C11
In i2c_probe_match.c, we model the I2C core's single-argument binding and IOMUXC electrical invariants in strict ISO C11. ap_probe_single_arg() matches client->compatible against ap_of_match[], rejects invalid > 0x7F 7-bit addresses (catching the classic 0x1e << 1 = 0x3c datasheet mistake when someone shifts an address above 0x3F), attaches client->drvdata, and verifies both bit 30 (SION == 1) and bit 11 (ODE == 1) in 0x4001b8b0.
learner@ksa:~/gl-e06/m01-l02$ bat -H 30 -H 45 -H 46 i2c_probe_match.c File: i2c_probe_match.c #define _POSIX_C_SOURCE 200809L #include <fcntl.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> struct ksa_of_device_id { const char *compatible; uint32_t chip_id; }; struct ksa_i2c_client { uint16_t addr; const char *name; const char *compatible; void *drvdata; }; struct ap_priv { uint32_t chip_id; uint32_t pad_cfg; }; static const struct ksa_of_device_id ap_of_match[] = { {"liteon,ap3216c", 0x3216U}, {NULL, 0U} }; static int ap_probe_single_arg(struct ksa_i2c_client *client) { uint32_t matched_id = 0U; for (size_t i = 0; ap_of_match[i].compatible != NULL; ++i) { if (strcmp(client->compatible, ap_of_match[i].compatible) == 0) { matched_id = ap_of_match[i].chip_id; break; } } if (matched_id == 0U || client->addr > 0x7FU) return -1; static struct ap_priv priv; priv.chip_id = matched_id; priv.pad_cfg = 0x4001b8b0U; client->drvdata = &priv; int sion = (priv.pad_cfg >> 30) & 1U; int ode = (priv.pad_cfg >> 11) & 1U; if (!sion || !ode) return -1; return 0; } int main(void) { struct ksa_i2c_client dev = {.addr = 0x1EU, .name = "ap3216c", .compatible = "liteon,ap3216c", .drvdata = NULL}; if (ap_probe_single_arg(&dev) != 0) return EXIT_FAILURE; struct ap_priv *p = (struct ap_priv *)dev.drvdata; int fd = open("/tmp/ksa_e06_i2c_bind", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0600); if (fd < 0) return EXIT_FAILURE; (void)write(fd, "1-001e\n", 7); close(fd); unlink("/tmp/ksa_e06_i2c_bind"); printf("addr=0x%02x chip=0x%x pad=0x%08x sion=%u ode=%u\n", dev.addr, p->chip_id, p->pad_cfg, (p->pad_cfg >> 30) & 1U, (p->pad_cfg >> 11) & 1U); return EXIT_SUCCESS; }- Single-argument probe receives struct ksa_i2c_client * and resolves chip metadata from of_match_table.
- Auditing bits 30 (SION) and 11 (ODE) of 0x4001b8b0 catches push-pull GPIO pad copy-paste errors.
Running the I2C Binding and Pad Auditor
Compile and run i2c_probe_match.c below. Notice the 1-001e bus-address naming written in strace—matching /sys/bus/i2c/devices/1-001e (<adapter>-<4-hex-addr>) on target Linux systems—and verify sion=1 ode=1.
learner@ksa:~/gl-e06/m01-l02gcc -std=c11 -Wall -Wextra -Werror -fdiagnostics-color=always i2c_probe_match.c -o i2c_probe_matchlearner@ksa:~/gl-e06/m01-l02./i2c_probe_matchaddr=0x1e chip=0x3216 pad=0x4001b8b0 sion=1 ode=1learner@ksa:~/gl-e06/m01-l02echo $?0learner@ksa:~/gl-e06/m01-l02ls -A --color=alwaysi2c_probe_matchi2c_probe_match.clearner@ksa:~/gl-e06/m01-l02learner@ksa:~/gl-e06/m01-l02strace -e trace=openat,write,unlink,close \./i2c_probe_matchopenat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3close(3) = 0openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3close(3) = 0openat(AT_FDCWD, "/tmp/ksa_e06_i2c_bind", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0600) = 3write(3, "1-001e\n", 7) = 7close(3) = 0unlink("/tmp/ksa_e06_i2c_bind") = 0write(1, "addr=0x1e chip=0x3216 pad=0x4001"..., 50) = 50+++ exited with 0 +++Host Proof vs Hardware Bus Sign-Off & Next Step
Running i2c_probe_match on x86_64 (7.0.0-42-generic) proves of_match_table string matching, 7-bit 0x1e range validation, and SION/ODE bitmask extraction in user-space memory. Remember two target-only behaviors when bringing up a real board: first, of_i2c_register_devices() creates /sys/bus/i2c/devices/1-001e solely from the .dtb even if the sensor is unsoldered (i2cdetect -y 0 shows UU as soon as a driver binds, meaning "in use by kernel driver", not "hardware verified"!); second, physical SDA/SCL RC rise times (<= 1000 ns at 100 kHz, <= 300 ns at 400 kHz) and 9th-clock ACK levels must be verified on the Cortex-A7 target under Linux 6.12 LTS. Now that ap3216c_probe() holds a bound struct i2c_client *, how do we read a multi-byte register block without another driver hijacking the bus mid-read? Later: Lesson m01-l03 builds atomic two-message Repeated-START transactions via i2c_transfer().
Common Production Pitfalls
warning: Symptom: Out-of-tree i2c_driver fails to build on Linux 6.12 with incompatible pointer type on .probe or struct i2c_driver has no member named 'probe_new'. Root Cause: Copying pre-6.3 two-argument probe(struct i2c_client *, const struct i2c_device_id *) or .probe_new boilerplate removed in Linux 6.6+. Fix: Use static int my_probe(struct i2c_client *client) assigned directly to .probe (and call i2c_client_get_device_id(client) only if ID-table data is needed).
warning: Symptom: i2cdetect -y 0 times out (-ETIMEDOUT) or sensor transactions fail with -ENXIO / corrupted ACK bits on I2C1 despite soldered 4.7 kOhm pull-ups. Root Cause: pinctrl_i2c1 copied a push-pull GPIO/UART pad word (0x10b0 or 0x4001b0b0) lacking ODE (bit 11) or SION (bit 30), causing push-pull contention during slave ACK or blinding i2c-imx to SCL clock stretching. Fix: Configure both I2C1_SCL and I2C1_SDA pads with 0x4001b8b0 in Device Tree.
Practice & Retrieval
Guided Practice: Auditing a Faulty Pad Word (0x4001b0b0)
Given a board revision whose Device Tree accidentally specifies 0x4001b0b0 instead of 0x4001b8b0 on I2C1_SDA, extract (0x4001b0b0 >> 30) & 1 (SION = 1) and (0x4001b0b0 >> 11) & 1 (ODE = 0). Explain electrically what happens on clock 9 when i2c-imx releases SDA high (3.3 V push-pull!) while AP3216C pulls SDA to 0 V to acknowledge 0x1e.
Independent Practice: Fast-Mode (400 kHz) Pull-Up Resistor Sizing
I2C Fast mode (400 kHz) tightens maximum 30% -> 70% rise time from 1000 ns down to 300 ns. Using t_r = 0.847 * R_pull * C_bus, compute the maximum legal R_pull in ohms for C_bus = 100 pF (~3,542 Ohm -> standard 3.3 kOhm) and C_bus = 200 pF (~1,771 Ohm -> standard 1.8 kOhm), and add a helper in a scratch copy of i2c_probe_match.c that rejects (clock_hz == 400000 && r_pull_ohm > max_ohm).
Key takeaways
- I2C shares two wires (
SCL,SDA) via open-drain (wired-AND) physics: devices pull low only and rely on external pull-ups (~4.7 kOhm) for sub-microsecond rise times. - On
i.MX6ULL,0x4001b8b0setsSION(bit 30) andODE(bit 11) so slaveACKand clock stretching never fight push-pull drivers. Linux 6.12splits SoC bus controllers (struct i2c_adapter/i2c_algorithmini2c-imx.c) from portable peripheral modules (struct i2c_client/struct i2c_driver).- Device Tree child nodes (
reg = <0x1e>) instantiatestruct i2c_clientautomatically and bind viaof_match_tableto single-argument.probe(struct i2c_client *client). Later: Lessonm01-l03executes atomicRepeated-STARTregister bursts viai2c_transfer(). - Linux 6.12 enforces the single-argument
.probe(struct i2c_client *client)signature, replacing legacy two-argument.probeand.probe_new. - i.MX6ULL
I2C1pad muxing (0x4001b8b0) requiresSIONand Open-Drain Enable (ODE) for reliable wired-ANDACKand clock stretching. - Linux decouples SoC
I2Cbus controllers (struct i2c_adapter/i2c_algorithmini2c-imx.c) from peripheral drivers (struct i2c_client/struct i2c_driver). - Linux 6.12 enforces the single-argument
.probe(struct i2c_client *client)signature, replacing legacy two-argument.probeand.probe_new.