i2c_add_adapter(9)
π 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:
i2c_verify_client(9)i2c_adapter_lock_bus(9)i2c_adapter_trylock_bus(9)i2c_adapter_unlock_bus(9)i2c_new_client_device(9)i2c_unregister_device(9)i2c_find_device_by_fwnode(9)i2c_new_dummy_device(9)devm_i2c_new_dummy_device(9)i2c_new_ancillary_device(9)i2c_verify_adapter(9)i2c_handle_smbus_host_notify(9)i2c_add_numbered_adapter(9)i2c_del_adapter(9)devm_i2c_add_adapter(9)i2c_find_adapter_by_fwnode(9)i2c_get_adapter_by_fwnode(9)i2c_parse_fw_timings(9)i2c_del_driver(9)__i2c_transfer(9)i2c_transfer(9)i2c_transfer_buffer_flags(9)i2c_get_device_id(9)i2c_client_get_device_id(9)i2c_get_dma_safe_msg_buf(9)i2c_put_dma_safe_msg_buf(9)
π§ 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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms