Lines Matching +full:data +full:- +full:bus
2 * I2C multiplexer driver for PCA9541 bus master selector
6 * Author: Guenter Roeck <linux@roeck-us.net>
11 * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it>
12 * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it>
23 #include <linux/i2c-mux.h>
29 * The PCA9541 is a bus master selector. It supports two I2C masters connected
30 * to a single slave bus.
32 * Before each bus transaction, a master has to acquire bus ownership. After the
33 * transaction is complete, bus ownership has to be released. This fits well
36 * single-channel I2C bus multiplexer.
38 * This driver assumes that the two bus masters are controlled by two different
67 #define ARB_TIMEOUT (HZ / 8) /* 125 ms until forcing bus ownership */
101 struct i2c_adapter *adap = client->adapter; in pca9541_reg_write()
102 union i2c_smbus_data data = { .byte = val }; in pca9541_reg_write() local
104 return __i2c_smbus_xfer(adap, client->addr, client->flags, in pca9541_reg_write()
106 I2C_SMBUS_BYTE_DATA, &data); in pca9541_reg_write()
115 struct i2c_adapter *adap = client->adapter; in pca9541_reg_read()
116 union i2c_smbus_data data; in pca9541_reg_read() local
119 ret = __i2c_smbus_xfer(adap, client->addr, client->flags, in pca9541_reg_read()
121 I2C_SMBUS_BYTE_DATA, &data); in pca9541_reg_read()
123 return ret ?: data.byte; in pca9541_reg_read()
130 /* Release bus. Also reset NTESTON and BUSINIT if it was set. */
142 * Arbitration is defined as a two-step process. A bus master can only activate
143 * the slave bus if it owns it; otherwise it has to request ownership first.
144 * This multi-step process ensures that access contention is resolved
147 * Bus Ownership Other master Action
149 * ----------------------------------------------------
150 * off - yes wait for arbitration timeout or
153 * off yes no turn on bus
154 * on yes - done
155 * on no - wait for arbitration timeout or
156 * for other master to release bus
158 * The main contention point occurs if the slave bus is off and both masters
160 * the slave bus, believing that it owns it. The other master will request
161 * bus ownership. Result is that the bus is turned on, and master which did
162 * _not_ own the slave bus before ends up owning it.
175 * 0 : bus not acquired
176 * 1 : bus acquired
181 struct pca9541 *data = i2c_mux_priv(muxc); in pca9541_arbitrate() local
191 * Bus is off. Request ownership or turn it on unless in pca9541_arbitrate()
196 || time_is_before_eq_jiffies(data->arb_timeout)) { in pca9541_arbitrate()
199 * or arbitration timeout expired. Take the bus. in pca9541_arbitrate()
205 data->select_timeout = SELECT_DELAY_SHORT; in pca9541_arbitrate()
211 data->select_timeout = SELECT_DELAY_LONG * 2; in pca9541_arbitrate()
215 * Bus is on, and we own it. We are done with acquisition. in pca9541_arbitrate()
226 * Other master owns the bus. in pca9541_arbitrate()
230 data->select_timeout = SELECT_DELAY_LONG; in pca9541_arbitrate()
231 if (time_is_before_eq_jiffies(data->arb_timeout)) { in pca9541_arbitrate()
232 /* Time is up, take the bus and reset it. */ in pca9541_arbitrate()
239 /* Request bus ownership if needed */ in pca9541_arbitrate()
251 struct pca9541 *data = i2c_mux_priv(muxc); in pca9541_select_chan() local
252 struct i2c_client *client = data->client; in pca9541_select_chan()
257 data->arb_timeout = jiffies + ARB_TIMEOUT; in pca9541_select_chan()
258 /* force bus ownership after this time */ in pca9541_select_chan()
265 if (data->select_timeout == SELECT_DELAY_SHORT) in pca9541_select_chan()
266 udelay(data->select_timeout); in pca9541_select_chan()
268 msleep(data->select_timeout / 1000); in pca9541_select_chan()
271 return -ETIMEDOUT; in pca9541_select_chan()
276 struct pca9541 *data = i2c_mux_priv(muxc); in pca9541_release_chan() local
277 struct i2c_client *client = data->client; in pca9541_release_chan()
288 struct i2c_adapter *adap = client->adapter; in pca9541_probe()
290 struct pca9541 *data; in pca9541_probe() local
294 return -ENODEV; in pca9541_probe()
298 * We have to lock the I2C segment before releasing the bus. in pca9541_probe()
306 muxc = i2c_mux_alloc(adap, &client->dev, 1, sizeof(*data), in pca9541_probe()
310 return -ENOMEM; in pca9541_probe()
312 data = i2c_mux_priv(muxc); in pca9541_probe()
313 data->client = client; in pca9541_probe()
321 dev_info(&client->dev, "registered master selector for I2C %s\n", in pca9541_probe()
322 client->name); in pca9541_probe()
346 MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");