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.

25 minfree previewLinux 6.12C11glibc 2.39→ module 1 lab
What you'll learn
  • Compare i2c_adapter/i2c_algorithm controller drivers against Device-Tree-matched i2c_client/i2c_driver modules.
  • Construct a Linux 6.12 single-argument .probe(struct i2c_client *client) driver with of_match_table and id_table.
  • Audit i.MX6ULL I2C1 IOMUXC open-drain (ODE) and SION pad flags for reliable ACK/clock stretching.

Why Two Shared Wires Demand Open-Drain Physics and a Split Driver Stack

Start from the physical board constraint: how can half a dozen sensors share just two PCB traces—Serial Clock (SCL) and Serial Data (SDA)—without burning out each other's output transistors? On a unidirectional push-pull output (such as a standard GPIO LED pin or UART TX), a PMOS transistor actively drives 3.3 V for logic 1 while an NMOS transistor pulls to 0 V (GND) for logic 0. On I2C, however, after the controller clocks out 8 address or data bits, the peripheral must pull SDA low on the 9th clock pulse (ACK = 0)—and a slow peripheral may also hold SCL low (clock stretching) while converting a sample! As Figure 1.2a illustrates, if the SoC pad were configured push-pull (ODE = 0) and drove 3.3 V while the sensor pulled SDA to GND, a low-impedance rail-to-ground short circuit would corrupt the ACK bit and risk pad damage.

I2C solves this electrically with open-drain (wired-AND) signaling:

  1. Pull Low Only, Float High via R_pull: Every device on SCL and SDA disables its upper PMOS transistor (Open-Drain Enable, ODE = 1). Any participant can pull a wire cleanly to 0 V, while logic 1 occurs only when every participant releases the line and external 4.7 kOhm pull-up resistors charge the trace capacitance (C_bus ~= 100 pF) up to 3.3 V. Using t_r = 0.847 * R_pull * C_bus, the SoC's internal 100 kOhm helper pull-up yields t_r ~= 8.47 us—failing the 1.0 us 100 kHz Standard-mode limit by 8x—whereas external 4.7 kOhm resistors achieve a crisp 0.40 us rise!
  2. Input Loopback (SION = 1): Because the SoC controller does not own SCL or SDA exclusively when releasing a line high, i2c-imx must read back the physical pin voltage while driving it to detect slave clock stretching and multi-master arbitration. On i.MX6ULL, setting pad word 0x4001b8b0 enables both ODE (bit 11 = 0x800) and Software Input On (SION, bit 30 = 0x40000000).
  3. Why the Linux kernel Splits Controller from Client: If an AP3216C ambient-light driver poked i.MX6ULL I2C1 registers (0x021A0000) directly, that driver could never compile or run on Raspberry Pi, STM32MP1, or x86_64, and two sensor drivers on I2C1 would overwrite each other's transfers. Instead, Linux 6.12 cleanly separates the SoC bus controller (struct i2c_adapter) from portable peripheral drivers (struct i2c_driver).
fig_m01_l02_a.svg — Open-drain wired-AND bus physics (top-left), 9-clock…

Figure 1.2a. Open-drain wired-AND bus physics (top-left), 9-clock address + ACK timing and RC pull-up sizing (top-right), and exact bitfields of i.MX6ULL I2C pad configuration 0x4001b8b0 (bottom).

mental model: An I2C bus works like a building's internal mail corridor: the mailroom controller (struct i2c_adapter in i2c-imx.c) owns the hallway carts and wire timing, while each office tenant (struct i2c_driver) only knows its 7-bit room number (client->addr) and how to interpret its own sensor registers.

Where it stops working: Unlike queued office mail, I2C transfers execute live on two shared open-drain wires where any peripheral can pull SDA low for ACK or hold SCL low to stretch the clock, requiring hardware SION loopback and ODE pad configuration.

definition (i2c_adapter, i2c_client & Linux 6.12 Single-Argument i2c_driver): In the Linux kernel I2C subsystem, struct i2c_adapter represents one physical SoC bus controller (such as i2c-imx.c at 0x021A0000), paired with struct i2c_algorithm (.master_xfer) to generate START, SCL/SDA bit clocks, and STOP under adapter->bus_lock. struct i2c_client represents one peripheral device at a 7-bit address (reg = <0x1e>) instantiated automatically from Device Tree child nodes (1-001e in sysfs). struct i2c_driver binds portable sensor logic via of_match_table and invokes the mandatory Linux 6.12 single-argument int (*probe)(struct i2c_client *client) callback.

Step through the four-layer bring-up from IOMUXC open-drain pads to single-argument .probe() binding:

ast_m01_l02.svg — Configure I2C pads with 0x4001b8b0 (SION + ODE), let…step 1/4
  1. Step 1. Step 1: Mux I2C1_SCL and I2C1_SDA with 0x4001b8b0 so ODE (bit 11) and SION (bit 30) enable safe wired-AND signaling.
  2. Step 2. Step 2: Host controller driver i2c-imx.c probes &i2c1 and registers struct i2c_adapter + .master_xfer().
  3. Step 3. Step 3: I2C core parses child node ap3216c@1e (reg = <0x1e>) into struct i2c_client (/sys/bus/i2c/devices/1-001e).
  4. Step 4. Step 4: Matching compatible = \"liteon,ap3216c\" invokes Linux 6.12 single-arg ap3216c_probe(struct i2c_client *).

Figure 1.2b. Configure I2C pads with 0x4001b8b0 (SION + ODE), let i2c-imx.c register struct i2c_adapter, declare child reg = <0x1e> in Device Tree, and bind via Linux 6.12 single-arg probe(struct i2c_client *).

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)!

fig_m01_l02_b.svg — How Linux 6.12 decouples the SoC i2c_adapter controller…

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 PathWhere 7-Bit Address LivesKernel 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 commandYes (id_table)Bench bring-up before updating .dts
Raw /dev/i2c-N (i2c-dev ioctl)User-space C / i2cdetectNo (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
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>;        };    };
  1. 0x4001b8b0 enables bit 30 (SION input loopback) and bit 11 (ODE open-drain) so slave ACK and clock stretching work safely.
  2. 100 kHz Standard mode: 9 SCL clocks per byte (8 data + 1 ACK) = 90 microseconds per byte.
  3. compatible string matched against ap3216c_driver.driver.of_match_table.
  4. Unshifted 7-bit I2C address 0x1e stored directly in client->addr.
learner@ksa: ~/gl-e06/m01-l02
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");
  1. Linux 6.12 passes only struct i2c_client *; call i2c_client_get_device_id(client) if legacy ID data is needed.
  2. Primary Device Tree binding table exported to depmod via MODULE_DEVICE_TABLE(of, ...).
  3. Retain id_table so sysfs new_device bench instantiation still matches.
  4. Assign single-argument probe directly to .probe; .probe_new was removed in Linux 6.6+.
i2c_driver(9) at a glance — GL-E06
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
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;    }
  1. Single-argument probe receives struct ksa_i2c_client * and resolves chip metadata from of_match_table.
  2. 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-l02
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-l02
strace — learner@ksa: ~/gl-e06/m01-l02
learner@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).

quiz · 1 of 3

Which callback signature is required for struct i2c_driver.probe in Linux 6.12 LTS?

quiz · 2 of 3

Why must i.MX6ULL I2C1 pad muxing (0x4001b8b0) set both ODE (bit 11) and SION (bit 30)?

quiz · 3 of 3

Retrieval (m01-l01): when snvs_rtc reads SNVS_LPSRTCMR and SNVS_LPSRTCLR once across a 32.768 kHz low-word rollover, what defect occurs?

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, 0x4001b8b0 sets SION (bit 30) and ODE (bit 11) so slave ACK and clock stretching never fight push-pull drivers.
  • Linux 6.12 splits SoC bus controllers (struct i2c_adapter / i2c_algorithm in i2c-imx.c) from portable peripheral modules (struct i2c_client / struct i2c_driver).
  • Device Tree child nodes (reg = <0x1e>) instantiate struct i2c_client automatically and bind via of_match_table to single-argument .probe(struct i2c_client *client). Later: Lesson m01-l03 executes atomic Repeated-START register bursts via i2c_transfer().
  • Linux 6.12 enforces the single-argument .probe(struct i2c_client *client) signature, replacing legacy two-argument .probe and .probe_new.
  • i.MX6ULL I2C1 pad muxing (0x4001b8b0) requires SION and Open-Drain Enable (ODE) for reliable wired-AND ACK and clock stretching.
  • Linux decouples SoC I2C bus controllers (struct i2c_adapter / i2c_algorithm in i2c-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 .probe and .probe_new.
Progress is saved on this device.

search — fzf

0/0 ───────────────────────────────────────────

keyboard shortcuts — less

/
search
f
focus mode
[
previous
]
next
?
help
Esc
close

figure