| 27 | | struct i2c_driver foo_driver |
| 28 | | { |
| 29 | | /* name */ "Foo version 2.3 and later driver", |
| 30 | | /* id */ I2C_DRIVERID_FOO, |
| 31 | | /* flags */ I2C_DF_NOTIFY, |
| 32 | | /* attach_adapter */ &foo_attach_adapter, |
| 33 | | /* detach_client */ &foo_detach_client, |
| 34 | | /* command */ &foo_command, /* May be NULL */ |
| 35 | | /* inc_use */ &foo_inc_use, /* May be NULL */ |
| 36 | | /* dec_use */ &foo_dec_use /* May be NULL */ |
| | 27 | static struct i2c_driver foo_driver = { |
| | 28 | .owner = THIS_MODULE, |
| | 29 | .name = "Foo version 2.3 driver", |
| | 30 | .id = I2C_DRIVERID_FOO, /* usually from i2c-id.h */ |
| | 31 | .flags = I2C_DF_NOTIFY, |
| | 32 | .attach_adapter = &foo_attach_adapter, |
| | 33 | .detach_client = &foo_detach_client, |
| | 34 | .command = &foo_command /* may be NULL */ |
| 53 | | |
| 54 | | Module usage count |
| 55 | | ================== |
| 56 | | |
| 57 | | If your driver can also be compiled as a module, there are moments at |
| 58 | | which the module can not be removed from memory. For example, when you |
| 59 | | are doing a lengthy transaction, or when you create a /proc directory, |
| 60 | | and some process has entered that directory (this last case is the |
| 61 | | main reason why these call-backs were introduced). |
| 62 | | |
| 63 | | To increase or decrease the module usage count, you can use the |
| 64 | | MOD_{INC,DEC}_USE_COUNT macros. They must be called from the module |
| 65 | | which needs to get its usage count changed; that is why each driver |
| 66 | | module has to implement its own callback. |
| 67 | | |
| 68 | | void foo_inc_use (struct i2c_client *client) |
| 69 | | { |
| 70 | | #ifdef MODULE |
| 71 | | MOD_INC_USE_COUNT; |
| 72 | | #endif |
| 73 | | } |
| 74 | | |
| 75 | | void foo_dec_use (struct i2c_client *client) |
| 76 | | { |
| 77 | | #ifdef MODULE |
| 78 | | MOD_DEC_USE_COUNT; |
| 79 | | #endif |
| 80 | | } |
| 81 | | |
| 82 | | Do not call these call-back functions directly; instead, use one of the |
| 83 | | following functions defined in i2c.h: |
| 84 | | void i2c_inc_use_client(struct i2c_client *); |
| 85 | | void i2c_dec_use_client(struct i2c_client *); |
| 86 | | |
| 87 | | You should *not* increase the module count just because a device is |
| 88 | | detected and a client created. This would make it impossible to remove |
| 89 | | an adapter driver! |
| | 51 | There use to be two additional fields in this structure, inc_use et dec_use, |
| | 52 | for module usage count, but these fields were obsoleted and removed. |