i2c_add_adapter(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– i2c_add_adapter β€” the "just give me a bus number, idc which" move ✨

Okay bestie, so this one lives in the Kernel API Manual (i2c_add_adapter(9)), and it's genuinely one of the cutest little registration functions in the I2C world. Let's get into it πŸŽ€


🌸 SYNOPSIS

int i2c_add_adapter (struct i2c_adapter *adapter );

πŸ¦‹ ARGUMENTS

  • adapter β€” the adapter to add. That's it. That's the whole argument. She's low maintenance πŸ’…

⭐ CONTEXT

can sleep 😴 β€” so like, don't call her from atomic context, she needs her beauty rest. No cap.


✨ DESCRIPTION ✨

Okay so here's the tea πŸ“: this routine is literally how you declare an I2C adapter when its bus number doesn't matter β€” or when its bus number is specified by a dt alias. Both valid, both iconic.

When does the bus number not matter, you ask? Great question, bestie 🫢. Examples of bases: I2C adapters dynamically added by USB links or PCI plugin cards. Those girlies show up whenever they feel like it, so we just let the kernel hand out a number 🌈.

And here's the moment we all came for πŸ‘‘: when this returns zero, a new bus number was allocated and stored in adap->nr, and the specified adapter became available for clients. The bus number goes in, the clients come out, that's the vibe check and she ATE πŸ”₯

Otherwise β€” i.e. if it doesn't return zero β€” a negative errno value is returned. Not a vibe. Handle it 😭

Heads up bestie: int return means you gotta actually check it. Zero = slay, negative errno = go read the error path, periodt πŸ’€

πŸ‘€ SEE ALSO

Kernel file ./drivers/i2c/i2c-core-base.c (go read the source, it's giving main character energy), plus this whole friend group:

🧚 Pro bestie tip: if you actually do care about the bus number, i2c_add_numbered_adapter(9) is right there in the list. Choose your fighter πŸ’œ

πŸŽ€ cute sign-off

This page came from ./drivers/i2c, dated October 2026, and the manual is Kernel API Manual β€” entry i2c_add_adapter(9). Go forth and register your adapters, queen πŸ‘‘πŸ’– iykyk ✨

πŸ“¦ where this page comes from