Lines Matching +full:mux +full:- +full:ext +full:- +full:port

4  * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it>
5 * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it>
6 * Copyright (c) 2009-2010 NSN GmbH & Co KG <michael.lawnick.ext@nsn.com>
10 * Supports multi-level mux'ing (mux behind a mux).
13 * i2c-virt.c from Kumar Gala <galak@kernel.crashing.org>
14 * i2c-virtual.c from Ken Harrenstien, Copyright (c) 2004 Google, Inc.
15 * i2c-virtual.c from Brian Kuschak <bkuschak@yahoo.com>
24 #include <linux/i2c-mux.h>
42 struct i2c_mux_priv *priv = adap->algo_data; in __i2c_mux_master_xfer()
43 struct i2c_mux_core *muxc = priv->muxc; in __i2c_mux_master_xfer()
44 struct i2c_adapter *parent = muxc->parent; in __i2c_mux_master_xfer()
47 /* Switch to the right mux port and perform the transfer. */ in __i2c_mux_master_xfer()
49 ret = muxc->select(muxc, priv->chan_id); in __i2c_mux_master_xfer()
52 if (muxc->deselect) in __i2c_mux_master_xfer()
53 muxc->deselect(muxc, priv->chan_id); in __i2c_mux_master_xfer()
61 struct i2c_mux_priv *priv = adap->algo_data; in i2c_mux_master_xfer()
62 struct i2c_mux_core *muxc = priv->muxc; in i2c_mux_master_xfer()
63 struct i2c_adapter *parent = muxc->parent; in i2c_mux_master_xfer()
66 /* Switch to the right mux port and perform the transfer. */ in i2c_mux_master_xfer()
68 ret = muxc->select(muxc, priv->chan_id); in i2c_mux_master_xfer()
71 if (muxc->deselect) in i2c_mux_master_xfer()
72 muxc->deselect(muxc, priv->chan_id); in i2c_mux_master_xfer()
82 struct i2c_mux_priv *priv = adap->algo_data; in __i2c_mux_smbus_xfer()
83 struct i2c_mux_core *muxc = priv->muxc; in __i2c_mux_smbus_xfer()
84 struct i2c_adapter *parent = muxc->parent; in __i2c_mux_smbus_xfer()
87 /* Select the right mux port and perform the transfer. */ in __i2c_mux_smbus_xfer()
89 ret = muxc->select(muxc, priv->chan_id); in __i2c_mux_smbus_xfer()
93 if (muxc->deselect) in __i2c_mux_smbus_xfer()
94 muxc->deselect(muxc, priv->chan_id); in __i2c_mux_smbus_xfer()
104 struct i2c_mux_priv *priv = adap->algo_data; in i2c_mux_smbus_xfer()
105 struct i2c_mux_core *muxc = priv->muxc; in i2c_mux_smbus_xfer()
106 struct i2c_adapter *parent = muxc->parent; in i2c_mux_smbus_xfer()
109 /* Select the right mux port and perform the transfer. */ in i2c_mux_smbus_xfer()
111 ret = muxc->select(muxc, priv->chan_id); in i2c_mux_smbus_xfer()
115 if (muxc->deselect) in i2c_mux_smbus_xfer()
116 muxc->deselect(muxc, priv->chan_id); in i2c_mux_smbus_xfer()
124 struct i2c_mux_priv *priv = adap->algo_data; in i2c_mux_functionality()
125 struct i2c_adapter *parent = priv->muxc->parent; in i2c_mux_functionality()
127 return parent->algo->functionality(parent); in i2c_mux_functionality()
132 struct i2c_mux_priv *priv = adapter->algo_data; in i2c_mux_lock_bus()
133 struct i2c_adapter *parent = priv->muxc->parent; in i2c_mux_lock_bus()
135 rt_mutex_lock_nested(&parent->mux_lock, i2c_adapter_depth(adapter)); in i2c_mux_lock_bus()
143 struct i2c_mux_priv *priv = adapter->algo_data; in i2c_mux_trylock_bus()
144 struct i2c_adapter *parent = priv->muxc->parent; in i2c_mux_trylock_bus()
146 if (!rt_mutex_trylock(&parent->mux_lock)) in i2c_mux_trylock_bus()
152 rt_mutex_unlock(&parent->mux_lock); in i2c_mux_trylock_bus()
158 struct i2c_mux_priv *priv = adapter->algo_data; in i2c_mux_unlock_bus()
159 struct i2c_adapter *parent = priv->muxc->parent; in i2c_mux_unlock_bus()
163 rt_mutex_unlock(&parent->mux_lock); in i2c_mux_unlock_bus()
169 struct i2c_mux_priv *priv = adapter->algo_data; in i2c_parent_lock_bus()
170 struct i2c_adapter *parent = priv->muxc->parent; in i2c_parent_lock_bus()
172 rt_mutex_lock_nested(&parent->mux_lock, i2c_adapter_depth(adapter)); in i2c_parent_lock_bus()
179 struct i2c_mux_priv *priv = adapter->algo_data; in i2c_parent_trylock_bus()
180 struct i2c_adapter *parent = priv->muxc->parent; in i2c_parent_trylock_bus()
182 if (!rt_mutex_trylock(&parent->mux_lock)) in i2c_parent_trylock_bus()
186 rt_mutex_unlock(&parent->mux_lock); in i2c_parent_trylock_bus()
193 struct i2c_mux_priv *priv = adapter->algo_data; in i2c_parent_unlock_bus()
194 struct i2c_adapter *parent = priv->muxc->parent; in i2c_parent_unlock_bus()
197 rt_mutex_unlock(&parent->mux_lock); in i2c_parent_unlock_bus()
210 for (i2c = dev; i2c; i2c = i2c->parent) { in i2c_root_adapter()
211 if (i2c->type == &i2c_adapter_type) in i2c_root_adapter()
240 muxc->priv = &muxc->adapter[max_adapters]; in i2c_mux_alloc()
242 muxc->parent = parent; in i2c_mux_alloc()
243 muxc->dev = dev; in i2c_mux_alloc()
245 muxc->mux_locked = true; in i2c_mux_alloc()
247 muxc->arbitrator = true; in i2c_mux_alloc()
249 muxc->gate = true; in i2c_mux_alloc()
250 muxc->select = select; in i2c_mux_alloc()
251 muxc->deselect = deselect; in i2c_mux_alloc()
252 muxc->max_adapters = max_adapters; in i2c_mux_alloc()
273 struct i2c_adapter *parent = muxc->parent; in i2c_mux_add_adapter()
278 if (muxc->num_adapters >= muxc->max_adapters) { in i2c_mux_add_adapter()
279 dev_err(muxc->dev, "No room for more i2c-mux adapters\n"); in i2c_mux_add_adapter()
280 return -EINVAL; in i2c_mux_add_adapter()
285 return -ENOMEM; in i2c_mux_add_adapter()
288 priv->muxc = muxc; in i2c_mux_add_adapter()
289 priv->chan_id = chan_id; in i2c_mux_add_adapter()
294 if (parent->algo->master_xfer) { in i2c_mux_add_adapter()
295 if (muxc->mux_locked) in i2c_mux_add_adapter()
296 priv->algo.master_xfer = i2c_mux_master_xfer; in i2c_mux_add_adapter()
298 priv->algo.master_xfer = __i2c_mux_master_xfer; in i2c_mux_add_adapter()
300 if (parent->algo->master_xfer_atomic) in i2c_mux_add_adapter()
301 priv->algo.master_xfer_atomic = priv->algo.master_xfer; in i2c_mux_add_adapter()
303 if (parent->algo->smbus_xfer) { in i2c_mux_add_adapter()
304 if (muxc->mux_locked) in i2c_mux_add_adapter()
305 priv->algo.smbus_xfer = i2c_mux_smbus_xfer; in i2c_mux_add_adapter()
307 priv->algo.smbus_xfer = __i2c_mux_smbus_xfer; in i2c_mux_add_adapter()
309 if (parent->algo->smbus_xfer_atomic) in i2c_mux_add_adapter()
310 priv->algo.smbus_xfer_atomic = priv->algo.smbus_xfer; in i2c_mux_add_adapter()
312 priv->algo.functionality = i2c_mux_functionality; in i2c_mux_add_adapter()
315 snprintf(priv->adap.name, sizeof(priv->adap.name), in i2c_mux_add_adapter()
316 "i2c-%d-mux (chan_id %d)", i2c_adapter_id(parent), chan_id); in i2c_mux_add_adapter()
317 priv->adap.owner = THIS_MODULE; in i2c_mux_add_adapter()
318 priv->adap.algo = &priv->algo; in i2c_mux_add_adapter()
319 priv->adap.algo_data = priv; in i2c_mux_add_adapter()
320 priv->adap.dev.parent = &parent->dev; in i2c_mux_add_adapter()
321 priv->adap.retries = parent->retries; in i2c_mux_add_adapter()
322 priv->adap.timeout = parent->timeout; in i2c_mux_add_adapter()
323 priv->adap.quirks = parent->quirks; in i2c_mux_add_adapter()
324 if (muxc->mux_locked) in i2c_mux_add_adapter()
325 priv->adap.lock_ops = &i2c_mux_lock_ops; in i2c_mux_add_adapter()
327 priv->adap.lock_ops = &i2c_parent_lock_ops; in i2c_mux_add_adapter()
330 * Try to populate the mux adapter's of_node, expands to in i2c_mux_add_adapter()
333 if (muxc->dev->of_node) { in i2c_mux_add_adapter()
334 struct device_node *dev_node = muxc->dev->of_node; in i2c_mux_add_adapter()
338 if (muxc->arbitrator) in i2c_mux_add_adapter()
339 mux_node = of_get_child_by_name(dev_node, "i2c-arb"); in i2c_mux_add_adapter()
340 else if (muxc->gate) in i2c_mux_add_adapter()
341 mux_node = of_get_child_by_name(dev_node, "i2c-gate"); in i2c_mux_add_adapter()
343 mux_node = of_get_child_by_name(dev_node, "i2c-mux"); in i2c_mux_add_adapter()
346 /* A "reg" property indicates an old-style DT entry */ in i2c_mux_add_adapter()
355 else if (muxc->arbitrator || muxc->gate) in i2c_mux_add_adapter()
368 priv->adap.dev.of_node = child; in i2c_mux_add_adapter()
373 * Associate the mux channel with an ACPI node. in i2c_mux_add_adapter()
375 if (has_acpi_companion(muxc->dev)) in i2c_mux_add_adapter()
376 acpi_preset_companion(&priv->adap.dev, in i2c_mux_add_adapter()
377 ACPI_COMPANION(muxc->dev), in i2c_mux_add_adapter()
381 priv->adap.nr = force_nr; in i2c_mux_add_adapter()
382 ret = i2c_add_numbered_adapter(&priv->adap); in i2c_mux_add_adapter()
384 dev_err(&parent->dev, in i2c_mux_add_adapter()
385 "failed to add mux-adapter %u as bus %u (error=%d)\n", in i2c_mux_add_adapter()
390 ret = i2c_add_adapter(&priv->adap); in i2c_mux_add_adapter()
392 dev_err(&parent->dev, in i2c_mux_add_adapter()
393 "failed to add mux-adapter %u (error=%d)\n", in i2c_mux_add_adapter()
399 WARN(sysfs_create_link(&priv->adap.dev.kobj, &muxc->dev->kobj, in i2c_mux_add_adapter()
401 "can't create symlink to mux device\n"); in i2c_mux_add_adapter()
403 snprintf(symlink_name, sizeof(symlink_name), "channel-%u", chan_id); in i2c_mux_add_adapter()
404 WARN(sysfs_create_link(&muxc->dev->kobj, &priv->adap.dev.kobj, in i2c_mux_add_adapter()
407 dev_info(&parent->dev, "Added multiplexed i2c bus %d\n", in i2c_mux_add_adapter()
408 i2c_adapter_id(&priv->adap)); in i2c_mux_add_adapter()
410 muxc->adapter[muxc->num_adapters++] = &priv->adap; in i2c_mux_add_adapter()
423 while (muxc->num_adapters) { in i2c_mux_del_adapters()
424 struct i2c_adapter *adap = muxc->adapter[--muxc->num_adapters]; in i2c_mux_del_adapters()
425 struct i2c_mux_priv *priv = adap->algo_data; in i2c_mux_del_adapters()
426 struct device_node *np = adap->dev.of_node; in i2c_mux_del_adapters()
428 muxc->adapter[muxc->num_adapters] = NULL; in i2c_mux_del_adapters()
431 "channel-%u", priv->chan_id); in i2c_mux_del_adapters()
432 sysfs_remove_link(&muxc->dev->kobj, symlink_name); in i2c_mux_del_adapters()
434 sysfs_remove_link(&priv->adap.dev.kobj, "mux_device"); in i2c_mux_del_adapters()