Article 51W9Q How to find i2c_client if I have i2c bus id and i2c slave address?

How to find i2c_client if I have i2c bus id and i2c slave address?

by
DeanAnderson
from LinuxQuestions.org on (#51W9Q)
Hi
I need to unregister any device which occupy i2c address. This one doesn't work as i2c_new_device returns -EBUSY:

Code:struct my_data{
struct i2c_client *client;
struct i2c_adapter *adap;
};

int force_reset(u8 command, u8 byte)
{
int ret;
struct mydata sdata;

sdata.adap = i2c_get_adapter(1);
if (sdata.adap == NULL) {
pr_alert("%s error (1)\n", __func__);
return -ENODEV;
}

sdata.client = i2c_new_device(sdata.adap, &info);

if (!sdata.client || !sdata.client->dev.driver)
{
pr_alert("%s error (2)\n", __func__);
return -ENODEV;
}

ret = i2c_smbus_write_byte_data(sdata.client, command, byte);

i2c_unregister_device(sdata.client);
sdata->client = NULL;
sdata->adap = NULL;

return ret;
}Before requesting i2c_new_device I have to do i2c_unregister_device. But how I can find i2c_client* pointer if I have i2c_adapter pointer and address???latest?d=yIl2AUoC8zA latest?i=bLkauLYavgs:O1UqlnVfW-k:F7zBnMy latest?i=bLkauLYavgs:O1UqlnVfW-k:V_sGLiP latest?d=qj6IDK7rITs latest?i=bLkauLYavgs:O1UqlnVfW-k:gIN9vFwbLkauLYavgs
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments