i2c_new_device

I want to access the power ic in a loadable kernel module:

Cause I want to use ..
           i2c_smbus_write_byte_data(i2c_power, 0xaddr, data);
.. I need an i2c_client.

What I did is:

struct i2c_adapter *i2cdev1;
struct i2c_client *i2c_power;
struct i2c_board_info *power_board;

{
...
  i2cdev1=i2c_get_adapter(1);
  i2c_power = i2c_new_device(i2cdev1,power_board);
}

but how to fill the 2c_board_info struct ?
something like this lets crash the module during insmod
  power_board->flags = 0;

Other way asked? How to get i2c running with i2c_smbus_write_byte_data

2008/10/31 <arno.steffen@web.de>

Other way asked? How to get i2c running with i2c_smbus_write_byte_data

The i2c-tools has some simple programs that you can use as an example, for instance i2cget shows how to read from an i2c device

http://www.lm-sensors.org/browser/i2c-tools/trunk/tools/i2cget.c

Thanks, but this is - AFAIK userspace code.
I am writing a kernel module accessing an I2c device...

I want to access the power ic in a loadable kernel module:

I'm more of a newbie on this, please do not trust all my words.

Cause I want to use ..
           i2c_smbus_write_byte_data(i2c_power, 0xaddr, data);
.. I need an i2c_client.

What I did is:

struct i2c_adapter *i2cdev1;
struct i2c_client *i2c_power;
struct i2c_board_info *power_board;

{
...
  i2cdev1=i2c_get_adapter(1);
  i2c_power = i2c_new_device(i2cdev1,power_board);
}

AFAIK, you should not call i2c_new_device directly in your i2c client
code. Moreover, i2c_board_info should be declared in board support code.
This is done in DaVinci-evm code like:

.
.
.
static struct i2c_board_info __initdata i2c_info = {
  {
    I2C_BOARD_INFO("pcf857x", 0x38),
    .type = "pcf8574",
    .platform_data = &pcf_data_u2,
  },
  {
    I2C_BOARD_INFO("pcf857x", 0x39),
    .type = "pcf8574",
    .platform_data = &pcf_data_u18,
  },
};
.
.
.

Then you should register this info in your board_init code with:

i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));

After this point i2c devices will be probed if a driver is registered
for the given name. If this not works for you(it didn't for me), then
you may try registering your client and driver in your code instead of
using i2c_board_info structure. AFAIR, tlv320aic33 code does this. Also
rtc drivers are relatively easy to read, but they only register
i2c_client not the drivers.

Regards,
Caglar