@@ -46,6 +46,8 @@ struct i2c_client;
46
46
struct i2c_driver ;
47
47
union i2c_smbus_data ;
48
48
struct i2c_board_info ;
49
+ enum i2c_slave_event ;
50
+ typedef int (* i2c_slave_cb_t )(struct i2c_client * , enum i2c_slave_event , u8 * );
49
51
50
52
struct module ;
51
53
@@ -209,6 +211,8 @@ struct i2c_driver {
209
211
* @irq: indicates the IRQ generated by this device (if any)
210
212
* @detected: member of an i2c_driver.clients list or i2c-core's
211
213
* userspace_devices list
214
+ * @slave_cb: Callback when I2C slave mode of an adapter is used. The adapter
215
+ * calls it to pass on slave events to the slave driver.
212
216
*
213
217
* An i2c_client identifies a single device (i.e. chip) connected to an
214
218
* i2c bus. The behaviour exposed to Linux is defined by the driver
@@ -224,6 +228,7 @@ struct i2c_client {
224
228
struct device dev ; /* the device structure */
225
229
int irq ; /* irq issued by device */
226
230
struct list_head detected ;
231
+ i2c_slave_cb_t slave_cb ; /* callback for slave mode */
227
232
};
228
233
#define to_i2c_client (d ) container_of(d, struct i2c_client, dev)
229
234
@@ -246,6 +251,25 @@ static inline void i2c_set_clientdata(struct i2c_client *dev, void *data)
246
251
dev_set_drvdata (& dev -> dev , data );
247
252
}
248
253
254
+ /* I2C slave support */
255
+
256
+ enum i2c_slave_event {
257
+ I2C_SLAVE_REQ_READ_START ,
258
+ I2C_SLAVE_REQ_READ_END ,
259
+ I2C_SLAVE_REQ_WRITE_START ,
260
+ I2C_SLAVE_REQ_WRITE_END ,
261
+ I2C_SLAVE_STOP ,
262
+ };
263
+
264
+ extern int i2c_slave_register (struct i2c_client * client , i2c_slave_cb_t slave_cb );
265
+ extern int i2c_slave_unregister (struct i2c_client * client );
266
+
267
+ static inline int i2c_slave_event (struct i2c_client * client ,
268
+ enum i2c_slave_event event , u8 * val )
269
+ {
270
+ return client -> slave_cb (client , event , val );
271
+ }
272
+
249
273
/**
250
274
* struct i2c_board_info - template for device creation
251
275
* @type: chip type, to initialize i2c_client.name
@@ -352,6 +376,8 @@ i2c_register_board_info(int busnum, struct i2c_board_info const *info,
352
376
* into I2C transfers instead.
353
377
* @functionality: Return the flags that this algorithm/adapter pair supports
354
378
* from the I2C_FUNC_* flags.
379
+ * @reg_slave: Register given client to I2C slave mode of this adapter
380
+ * @unreg_slave: Unregister given client from I2C slave mode of this adapter
355
381
*
356
382
* The following structs are for those who like to implement new bus drivers:
357
383
* i2c_algorithm is the interface to a class of hardware solutions which can
@@ -377,6 +403,9 @@ struct i2c_algorithm {
377
403
378
404
/* To determine what the adapter supports */
379
405
u32 (* functionality ) (struct i2c_adapter * );
406
+
407
+ int (* reg_slave )(struct i2c_client * client );
408
+ int (* unreg_slave )(struct i2c_client * client );
380
409
};
381
410
382
411
/**
0 commit comments