How can I resolve the "Failed to acquire I2C client" error in my kernel space I2C DAC implementation

@Middleware & OS How can I use the I2C bus(DAC) in kernel space, I have verified that the I2C adapter and address in kernel space, I expected to get a Successfully acquired i2c client message in my log but still getting the error Failed to acquire I2C client Here's my code
struct i2c_client *client;
struct i2c_adapter *adapter = i2c_get_adapter(1);
struct i2c_board_info info;
strlcpy(info.type, "i2c-dac", I2C_NAME_SIZE);
strlcpy(info.name, "My DAC", I2C_NAME_SIZE);
client = i2c_new_device(adapter, &info);
i2c_put_adapter(adapter);
struct i2c_client *client;
struct i2c_adapter *adapter = i2c_get_adapter(1);
struct i2c_board_info info;
strlcpy(info.type, "i2c-dac", I2C_NAME_SIZE);
strlcpy(info.name, "My DAC", I2C_NAME_SIZE);
client = i2c_new_device(adapter, &info);
i2c_put_adapter(adapter);
3 Replies
RED HAT
RED HAT6mo ago
Hi @Boss lady , make sure that the I2C adapter index 1 is correct and that it corresponds to the correct I2C bus on your hardware. You can check this in the /sys/class/i2c-adapter directory.
Enthernet Code
Enthernet Code6mo ago
@Boss lady check the value returned from the i2c_get_adapter of its correctly obtained, if it returns Null then there's issue with the adapter
Boss lady
Boss lady6mo ago
Thanks @RED HAT I checked /sys/class/i2c-adapter and confirmed that index 1 is correct. I also enabled logging and saw that i2c_get_adapter is returning a valid pointer. The problem seems to be with i2c_new_device.
Want results from more Discord servers?
Add your server