nmk_i2c_xfer(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

🌸 NAME 🌸

okay so bestie, nmk_i2c_xfer(9) β€” from the Kernel API Manual β€” is literally the I2C transfer function used by the kernel framework. iconic. πŸ’–


✨ SYNOPSIS ✨

int nmk_i2c_xfer (struct i2c_adapter *i2c_adap , struct i2c_msg msgs[] ,
int num_msgs );

πŸŽ€ ARGUMENTS πŸŽ€

  • i2c_adap β€” adapter pointer to the controller, aka the whole vibe check for which controller we're talking to. πŸ¦‹
  • msgs β€” pointer to data to be written. yes, that's the description; no cap. πŸ’…
  • num_msgs β€” number of messages to be executed. slay the count. ✨

πŸ¦‹ DESCRIPTION πŸ¦‹

this is the function called by the generic kernel i2c_transfer or i2c_smbus...() API calls. and lowkey important: this code is protected by the semaphore set in the kernel i2c_transfer function. periodt. πŸ‘‘


πŸ’… NOTE πŸ’…

πŸ’– READ TRANSFER πŸ’–

we impose a restriction, bestie: the first message has to be the index message for any read transaction. fr fr. 😭

  • a no index is coded as '0',
  • 2byte big endian index is coded as '3' !!! msg[0].buf holds the actual index.

this is compatible with generic messages of smbus emulator that send a one byte index.

example: an I2C transaction to read 2 bytes from index 0:

idx = 0; msg[0].addr = client->addr; msg[0].flags = 0x0; msg[0].len = 1; msg[0].buf = idx;

msg[1].addr = client->addr; msg[1].flags = I2C_M_RD; msg[1].len = 2;
msg[1].buf = rd_buff i2c_transfer(adap, msg, 2);

πŸ¦‹ WRITE TRANSFER πŸ¦‹

the I2C standard interface interprets all data as payload. if you want to emulate an SMBUS write transaction, put the index as first byte(or first and second) in the payload. πŸŽ€

example: an I2C transaction to write 2 bytes from index 1:

wr_buff[0] = 0x1; wr_buff[1] = 0x23; wr_buff[2] = 0x46; msg[0].flags = 0x0; msg[0].len = 3; msg[0].buf = wr_buff; i2c_transfer(adap, msg, 1);

to read or write a block of data (multiple bytes) using SMBUS emulation, please use the i2c_smbus_read_i2c_block_data or i2c_smbus_write_i2c_block_data API. that's the move. πŸ’…βœ¨


πŸ‘‘ SEE ALSO πŸ‘‘

kernel file ./drivers/i2c/busses/i2c-nomadik.c struct i2c_vendor_data(9), struct i2c_nmk_client(9), struct nmk_i2c_dev(9), flush_i2c_fifo(9), disable_all_interrupts(9), clear_all_interrupts(9), init_hw(9), load_i2c_mcr_reg(9), setup_i2c_controller(9), read_i2c(9), write_i2c(9), nmk_i2c_xfer_one(9), disable_interrupts(9), i2c_irq_handler(9). go read, bestie. 🌈

🫢 source/version: ./drivers/i2c/busses Β· date: October 2026 Β· page: nmk_i2c_xfer(9) β€” bye bestie, go slay those transfers πŸ’–βœ¨
πŸ“¦ where this page comes from