Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

i2c-algo-pca: Rework waiting for a free bus

Waiting for a free bus now accepts the timeout value in jiffies and does
proper checking using time_before.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Jean Delvare <khali@linux-fr.org>

authored by

Wolfram Sang and committed by
Jean Delvare
8e99ada8 eff9ec95

+13 -10
+1 -1
arch/sh/boards/board-sh7785lcr.c
··· 229 229 static struct i2c_pca9564_pf_platform_data i2c_platform_data = { 230 230 .gpio = 0, 231 231 .i2c_clock_speed = I2C_PCA_CON_330kHz, 232 - .timeout = 100, 232 + .timeout = HZ, 233 233 }; 234 234 235 235 static struct platform_device i2c_device = {
+10 -7
drivers/i2c/algos/i2c-algo-pca.c
··· 22 22 #include <linux/module.h> 23 23 #include <linux/moduleparam.h> 24 24 #include <linux/delay.h> 25 + #include <linux/jiffies.h> 25 26 #include <linux/init.h> 26 27 #include <linux/errno.h> 27 28 #include <linux/i2c.h> ··· 187 186 int numbytes = 0; 188 187 int state; 189 188 int ret; 190 - int timeout = i2c_adap->timeout; 189 + unsigned long timeout = jiffies + i2c_adap->timeout; 191 190 192 - while ((state = pca_status(adap)) != 0xf8 && timeout--) { 193 - msleep(10); 194 - } 195 - if (state != 0xf8) { 196 - dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state); 197 - return -EAGAIN; 191 + while (pca_status(adap) != 0xf8) { 192 + if (time_before(jiffies, timeout)) { 193 + msleep(10); 194 + } else { 195 + dev_dbg(&i2c_adap->dev, "bus is not idle. status is " 196 + "%#04x\n", state); 197 + return -EAGAIN; 198 + } 198 199 } 199 200 200 201 DEB1("{{{ XFER %d messages\n", num);
+1 -1
drivers/i2c/busses/i2c-pca-isa.c
··· 104 104 .owner = THIS_MODULE, 105 105 .algo_data = &pca_isa_data, 106 106 .name = "PCA9564/PCA9665 ISA Adapter", 107 - .timeout = 100, 107 + .timeout = HZ, 108 108 }; 109 109 110 110 static int __devinit pca_isa_match(struct device *dev, unsigned int id)
+1 -1
include/linux/i2c-pca-platform.h
··· 6 6 * not supplied (negative value), but it 7 7 * cannot exit some error conditions then */ 8 8 int i2c_clock_speed; /* values are defined in linux/i2c-algo-pca.h */ 9 - int timeout; /* timeout = this value * 10us */ 9 + int timeout; /* timeout in jiffies */ 10 10 }; 11 11 12 12 #endif /* I2C_PCA9564_PLATFORM_H */