aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/i2c.h
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2012-02-28 07:56:31 -0500
committerWolfram Sang <wsa@the-dreams.de>2013-03-24 05:30:54 -0400
commit5f9296ba21b3c395e53dd84e7ff9578f97f24295 (patch)
treeddc02adbdaa1b703b04aeee9b8d8f1ca13fa2443 /include/linux/i2c.h
parentee5c27440cc24d62ec463cce4c000bb32c5692c7 (diff)
i2c: Add bus recovery infrastructure
Add i2c bus recovery infrastructure to i2c adapters as specified in the i2c protocol Rev. 03 section 3.1.16 titled "Bus clear". http://www.nxp.com/documents/user_manual/UM10204.pdf Sometimes during operation i2c bus hangs and we need to give dummy clocks to slave device to start the transfer again. Now we may have capability in the bus controller to generate these clocks or platform may have gpio pins which can be toggled to generate dummy clocks. This patch supports both. This patch also adds in generic bus recovery routines gpio or scl line based which can be used by bus controller. In addition controller driver may provide its own version of the bus recovery routine. This doesn't support multi-master recovery for now. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> [wsa: changed gpio type to int and minor reformatting] Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'include/linux/i2c.h')
-rw-r--r--include/linux/i2c.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index d0c4db7b4872..2eca3860b77f 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -370,6 +370,45 @@ struct i2c_algorithm {
370 u32 (*functionality) (struct i2c_adapter *); 370 u32 (*functionality) (struct i2c_adapter *);
371}; 371};
372 372
373/**
374 * struct i2c_bus_recovery_info - I2C bus recovery information
375 * @recover_bus: Recover routine. Either pass driver's recover_bus() routine, or
376 * i2c_generic_scl_recovery() or i2c_generic_gpio_recovery().
377 * @get_scl: This gets current value of SCL line. Mandatory for generic SCL
378 * recovery. Used internally for generic GPIO recovery.
379 * @set_scl: This sets/clears SCL line. Mandatory for generic SCL recovery. Used
380 * internally for generic GPIO recovery.
381 * @get_sda: This gets current value of SDA line. Optional for generic SCL
382 * recovery. Used internally, if sda_gpio is a valid GPIO, for generic GPIO
383 * recovery.
384 * @prepare_recovery: This will be called before starting recovery. Platform may
385 * configure padmux here for SDA/SCL line or something else they want.
386 * @unprepare_recovery: This will be called after completing recovery. Platform
387 * may configure padmux here for SDA/SCL line or something else they want.
388 * @scl_gpio: gpio number of the SCL line. Only required for GPIO recovery.
389 * @sda_gpio: gpio number of the SDA line. Only required for GPIO recovery.
390 */
391struct i2c_bus_recovery_info {
392 int (*recover_bus)(struct i2c_adapter *);
393
394 int (*get_scl)(struct i2c_adapter *);
395 void (*set_scl)(struct i2c_adapter *, int val);
396 int (*get_sda)(struct i2c_adapter *);
397
398 void (*prepare_recovery)(struct i2c_bus_recovery_info *bri);
399 void (*unprepare_recovery)(struct i2c_bus_recovery_info *bri);
400
401 /* gpio recovery */
402 int scl_gpio;
403 int sda_gpio;
404};
405
406int i2c_recover_bus(struct i2c_adapter *adap);
407
408/* Generic recovery routines */
409int i2c_generic_gpio_recovery(struct i2c_adapter *adap);
410int i2c_generic_scl_recovery(struct i2c_adapter *adap);
411
373/* 412/*
374 * i2c_adapter is the structure used to identify a physical i2c bus along 413 * i2c_adapter is the structure used to identify a physical i2c bus along
375 * with the access algorithms necessary to access it. 414 * with the access algorithms necessary to access it.
@@ -393,6 +432,8 @@ struct i2c_adapter {
393 432
394 struct mutex userspace_clients_lock; 433 struct mutex userspace_clients_lock;
395 struct list_head userspace_clients; 434 struct list_head userspace_clients;
435
436 struct i2c_bus_recovery_info *bus_recovery_info;
396}; 437};
397#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) 438#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
398 439