diff options
Diffstat (limited to 'Documentation/i2c/writing-clients')
| -rw-r--r-- | Documentation/i2c/writing-clients | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients index 077275722a7c..e94d9c6cc522 100644 --- a/Documentation/i2c/writing-clients +++ b/Documentation/i2c/writing-clients | |||
| @@ -33,8 +33,8 @@ static struct i2c_driver foo_driver = { | |||
| 33 | .command = &foo_command /* may be NULL */ | 33 | .command = &foo_command /* may be NULL */ |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | The name can be chosen freely, and may be upto 40 characters long. Please | 36 | The name field must match the driver name, including the case. It must not |
| 37 | use something descriptive here. | 37 | contain spaces, and may be up to 31 characters long. |
| 38 | 38 | ||
| 39 | Don't worry about the flags field; just put I2C_DF_NOTIFY into it. This | 39 | Don't worry about the flags field; just put I2C_DF_NOTIFY into it. This |
| 40 | means that your driver will be notified when new adapters are found. | 40 | means that your driver will be notified when new adapters are found. |
| @@ -43,9 +43,6 @@ This is almost always what you want. | |||
| 43 | All other fields are for call-back functions which will be explained | 43 | All other fields are for call-back functions which will be explained |
| 44 | below. | 44 | below. |
| 45 | 45 | ||
| 46 | There use to be two additional fields in this structure, inc_use et dec_use, | ||
| 47 | for module usage count, but these fields were obsoleted and removed. | ||
| 48 | |||
| 49 | 46 | ||
| 50 | Extra client data | 47 | Extra client data |
| 51 | ================= | 48 | ================= |
| @@ -58,6 +55,7 @@ be very useful. | |||
| 58 | An example structure is below. | 55 | An example structure is below. |
| 59 | 56 | ||
| 60 | struct foo_data { | 57 | struct foo_data { |
| 58 | struct i2c_client client; | ||
| 61 | struct semaphore lock; /* For ISA access in `sensors' drivers. */ | 59 | struct semaphore lock; /* For ISA access in `sensors' drivers. */ |
| 62 | int sysctl_id; /* To keep the /proc directory entry for | 60 | int sysctl_id; /* To keep the /proc directory entry for |
| 63 | `sensors' drivers. */ | 61 | `sensors' drivers. */ |
| @@ -310,22 +308,15 @@ For now, you can ignore the `flags' parameter. It is there for future use. | |||
| 310 | client structure, even though we cannot fill it completely yet. | 308 | client structure, even though we cannot fill it completely yet. |
| 311 | But it allows us to access several i2c functions safely */ | 309 | But it allows us to access several i2c functions safely */ |
| 312 | 310 | ||
| 313 | /* Note that we reserve some space for foo_data too. If you don't | 311 | if (!(data = kzalloc(sizeof(struct foo_data), GFP_KERNEL))) { |
| 314 | need it, remove it. We do it here to help to lessen memory | ||
| 315 | fragmentation. */ | ||
| 316 | if (! (new_client = kmalloc(sizeof(struct i2c_client) + | ||
| 317 | sizeof(struct foo_data), | ||
| 318 | GFP_KERNEL))) { | ||
| 319 | err = -ENOMEM; | 312 | err = -ENOMEM; |
| 320 | goto ERROR0; | 313 | goto ERROR0; |
| 321 | } | 314 | } |
| 322 | 315 | ||
| 323 | /* This is tricky, but it will set the data to the right value. */ | 316 | new_client = &data->client; |
| 324 | client->data = new_client + 1; | 317 | i2c_set_clientdata(new_client, data); |
| 325 | data = (struct foo_data *) (client->data); | ||
| 326 | 318 | ||
| 327 | new_client->addr = address; | 319 | new_client->addr = address; |
| 328 | new_client->data = data; | ||
| 329 | new_client->adapter = adapter; | 320 | new_client->adapter = adapter; |
| 330 | new_client->driver = &foo_driver; | 321 | new_client->driver = &foo_driver; |
| 331 | new_client->flags = 0; | 322 | new_client->flags = 0; |
| @@ -451,7 +442,7 @@ much simpler than the attachment code, fortunately! | |||
| 451 | release_region(client->addr,LM78_EXTENT); | 442 | release_region(client->addr,LM78_EXTENT); |
| 452 | /* HYBRID SENSORS CHIP ONLY END */ | 443 | /* HYBRID SENSORS CHIP ONLY END */ |
| 453 | 444 | ||
| 454 | kfree(client); /* Frees client data too, if allocated at the same time */ | 445 | kfree(data); |
| 455 | return 0; | 446 | return 0; |
| 456 | } | 447 | } |
| 457 | 448 | ||
| @@ -576,12 +567,12 @@ SMBus communication | |||
| 576 | extern s32 i2c_smbus_write_block_data(struct i2c_client * client, | 567 | extern s32 i2c_smbus_write_block_data(struct i2c_client * client, |
| 577 | u8 command, u8 length, | 568 | u8 command, u8 length, |
| 578 | u8 *values); | 569 | u8 *values); |
| 570 | extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client, | ||
| 571 | u8 command, u8 *values); | ||
| 579 | 572 | ||
| 580 | These ones were removed in Linux 2.6.10 because they had no users, but could | 573 | These ones were removed in Linux 2.6.10 because they had no users, but could |
| 581 | be added back later if needed: | 574 | be added back later if needed: |
| 582 | 575 | ||
| 583 | extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client, | ||
| 584 | u8 command, u8 *values); | ||
| 585 | extern s32 i2c_smbus_read_block_data(struct i2c_client * client, | 576 | extern s32 i2c_smbus_read_block_data(struct i2c_client * client, |
| 586 | u8 command, u8 *values); | 577 | u8 command, u8 *values); |
| 587 | extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client, | 578 | extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client, |
