From 98e0d6d0e2204014d8a88c9684f5f4ea4c16e32e Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Mon, 20 Apr 2015 15:37:38 +0200 Subject: [PATCH] kernel: add i2c mangle hook --- kernel/drivers/i2c/i2c-core.c | 22 ++++++++++++---------- kernel/include/linux/i2c.h | 2 ++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/kernel/drivers/i2c/i2c-core.c b/kernel/drivers/i2c/i2c-core.c index 3ad17b6e..dfb3b25f 100644 --- a/kernel/drivers/i2c/i2c-core.c +++ b/kernel/drivers/i2c/i2c-core.c @@ -1072,7 +1072,7 @@ module_exit(i2c_exit); * Note that there is no requirement that each message be sent to * the same slave address, although that is the most common model. */ -int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) +int i2c_transfer2(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) { unsigned long orig_jiffies; int ret, try; @@ -1103,15 +1103,6 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) (msgs[ret].flags & I2C_M_RECV_LEN) ? "+" : ""); } #endif -#if 0 - for (ret = 0; ret < num; ret++) { - printk("i2c master_xfer[%d] %c, addr=0x%02x, " - "len=%d%s, flags=0x%x\n", ret, (msgs[ret].flags & I2C_M_RD) - ? 'R' : 'W', msgs[ret].addr, msgs[ret].len, - (msgs[ret].flags & I2C_M_RECV_LEN) ? "+" : "", - msgs[ret].flags); - } -#endif if (in_atomic() || irqs_disabled()) { ret = mutex_trylock(&adap->bus_lock); @@ -1139,6 +1130,17 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) return -EOPNOTSUPP; } } +EXPORT_SYMBOL(i2c_transfer2); + +int (*i2c_transfer_mangle)(struct i2c_adapter *adap, struct i2c_msg *msgs, int num); +EXPORT_SYMBOL(i2c_transfer_mangle); + +int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) +{ + if (i2c_transfer_mangle) + return i2c_transfer_mangle(adap, msgs, num); + return i2c_transfer2(adap, msgs, num); +} EXPORT_SYMBOL(i2c_transfer); /** diff --git a/kernel/include/linux/i2c.h b/kernel/include/linux/i2c.h index ad57998f..810516cc 100644 --- a/kernel/include/linux/i2c.h +++ b/kernel/include/linux/i2c.h @@ -60,6 +60,8 @@ extern int i2c_master_recv(struct i2c_client *client, char *buf, int count); /* Transfer num messages. */ +extern int (*i2c_transfer_mangle) + (struct i2c_adapter *adap, struct i2c_msg *msgs, int num); extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);