/* * Multiplexed I2C bus driver. * * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it> * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it> * Copyright (c) 2009-2010 NSN GmbH & Co KG <michael.lawnick.ext@nsn.com> * * Simplifies access to complex multiplexed I2C bus topologies, by presenting * each multiplexed bus segment as an additional I2C adapter. * Supports multi-level mux'ing (mux behind a mux). * * Based on: * i2c-virt.c from Kumar Gala <galak@kernel.crashing.org> * i2c-virtual.c from Ken Harrenstien, Copyright (c) 2004 Google, Inc. * i2c-virtual.c from Brian Kuschak <bkuschak@yahoo.com> * * This file is licensed under the terms of the GNU General Public * License version 2. This program is licensed "as is" without any * warranty of any kind, whether express or implied.
*/
/* Switch to the right mux port and perform the transfer. */
ret = muxc->select(muxc, priv->chan_id); if (ret >= 0)
ret = __i2c_transfer(parent, msgs, num); if (muxc->deselect)
muxc->deselect(muxc, priv->chan_id);
/* * Walk up the device tree to find an i2c adapter, indicating * that this is an i2c client device. Check all ancestors to * handle mfd devices etc.
*/ for (i2c = dev; i2c; i2c = i2c->parent) { if (i2c->type == &i2c_adapter_type) break;
} if (!i2c) return NULL;
/* Continue up the tree to find the root i2c adapter */
i2c_root = to_i2c_adapter(i2c); while (i2c_parent_is_i2c_adapter(i2c_root))
i2c_root = i2c_parent_is_i2c_adapter(i2c_root);
if (muxc->num_adapters >= muxc->max_adapters) {
dev_err(muxc->dev, "No room for more i2c-mux adapters\n"); return -EINVAL;
}
priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM;
/* Set up private adapter data */
priv->muxc = muxc;
priv->chan_id = chan_id;
/* Need to do algo dynamically because we don't know ahead * of time what sort of physical adapter we'll be dealing with.
*/ if (parent->algo->master_xfer) { if (muxc->mux_locked)
priv->algo.xfer = i2c_mux_master_xfer; else
priv->algo.xfer = __i2c_mux_master_xfer;
} if (parent->algo->master_xfer_atomic)
priv->algo.xfer_atomic = priv->algo.master_xfer;
if (parent->algo->smbus_xfer) { if (muxc->mux_locked)
priv->algo.smbus_xfer = i2c_mux_smbus_xfer; else
priv->algo.smbus_xfer = __i2c_mux_smbus_xfer;
} if (parent->algo->smbus_xfer_atomic)
priv->algo.smbus_xfer_atomic = priv->algo.smbus_xfer;
priv->algo.functionality = i2c_mux_functionality;
/* Now fill out new adapter structure */
snprintf(priv->adap.name, sizeof(priv->adap.name), "i2c-%d-mux (chan_id %d)", i2c_adapter_id(parent), chan_id);
priv->adap.owner = THIS_MODULE;
priv->adap.algo = &priv->algo;
priv->adap.algo_data = priv;
priv->adap.dev.parent = &parent->dev;
priv->adap.retries = parent->retries;
priv->adap.timeout = parent->timeout;
priv->adap.quirks = parent->quirks; if (muxc->mux_locked)
priv->adap.lock_ops = &i2c_mux_lock_ops; else
priv->adap.lock_ops = &i2c_parent_lock_ops;
/* * Try to populate the mux adapter's of_node, expands to * nothing if !CONFIG_OF.
*/ if (muxc->dev->of_node) { struct device_node *dev_node = muxc->dev->of_node; struct device_node *mux_node, *child = NULL;
u32 reg;
/* * Associate the mux channel with an ACPI node.
*/ if (has_acpi_companion(muxc->dev))
acpi_preset_companion(&priv->adap.dev,
ACPI_COMPANION(muxc->dev),
chan_id);
if (force_nr) {
priv->adap.nr = force_nr;
ret = i2c_add_numbered_adapter(&priv->adap); if (ret < 0) {
dev_err(&parent->dev, "failed to add mux-adapter %u as bus %u (error=%d)\n",
chan_id, force_nr, ret); goto err_free_priv;
}
} else {
ret = i2c_add_adapter(&priv->adap); if (ret < 0) {
dev_err(&parent->dev, "failed to add mux-adapter %u (error=%d)\n",
chan_id, ret); goto err_free_priv;
}
}
WARN(sysfs_create_link(&priv->adap.dev.kobj, &muxc->dev->kobj, "mux_device"), "can't create symlink to mux device\n");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.