Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1304639
| From | Peter Rosin <peda@lysator.liu.se> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v3 7/8] i2c: muxes always lock the parent adapter |
| Date | 2016-01-08 16:10 +0100 |
| Message-ID | <qOGPV-8rM-47@gated-at.bofh.it> (permalink) |
| References | <qOGPT-8rM-7@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Peter Rosin <peda@axentia.se>
Instead of checking for i2c parent adapters for every lock/unlock, simply
override the locking for muxes to always lock/unlock the parent adapter
directly.
Signed-off-by: Peter Rosin <peda@axentia.se>
---
drivers/i2c/i2c-core.c | 21 +++------------------
drivers/i2c/i2c-mux.c | 27 +++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 34a7748b4652..4683777f81ca 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -963,12 +963,7 @@ static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr)
*/
static void i2c_adapter_lock_bus(struct i2c_adapter *adapter, int flags)
{
- struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter);
-
- if (parent)
- i2c_lock_adapter(parent);
- else
- rt_mutex_lock(&adapter->bus_lock);
+ rt_mutex_lock(&adapter->bus_lock);
}
/**
@@ -977,12 +972,7 @@ static void i2c_adapter_lock_bus(struct i2c_adapter *adapter, int flags)
*/
static int i2c_adapter_trylock_bus(struct i2c_adapter *adapter, int flags)
{
- struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter);
-
- if (parent)
- return parent->trylock_bus(parent, flags);
- else
- return rt_mutex_trylock(&adapter->bus_lock);
+ return rt_mutex_trylock(&adapter->bus_lock);
}
/**
@@ -991,12 +981,7 @@ static int i2c_adapter_trylock_bus(struct i2c_adapter *adapter, int flags)
*/
static void i2c_adapter_unlock_bus(struct i2c_adapter *adapter, int flags)
{
- struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter);
-
- if (parent)
- i2c_unlock_adapter(parent);
- else
- rt_mutex_unlock(&adapter->bus_lock);
+ rt_mutex_unlock(&adapter->bus_lock);
}
static void i2c_dev_set_name(struct i2c_adapter *adap,
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index 9bdebbdcbc61..fcfe51b023c0 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -98,6 +98,30 @@ static unsigned int i2c_mux_parent_classes(struct i2c_adapter *parent)
return class;
}
+static void i2c_parent_lock_bus(struct i2c_adapter *adapter, int flags)
+{
+ struct i2c_mux_priv *priv = adapter->algo_data;
+ struct i2c_adapter *parent = priv->muxc->parent;
+
+ parent->lock_bus(parent, flags);
+}
+
+static int i2c_parent_trylock_bus(struct i2c_adapter *adapter, int flags)
+{
+ struct i2c_mux_priv *priv = adapter->algo_data;
+ struct i2c_adapter *parent = priv->muxc->parent;
+
+ return parent->trylock_bus(parent, flags);
+}
+
+static void i2c_parent_unlock_bus(struct i2c_adapter *adapter, int flags)
+{
+ struct i2c_mux_priv *priv = adapter->algo_data;
+ struct i2c_adapter *parent = priv->muxc->parent;
+
+ parent->unlock_bus(parent, flags);
+}
+
int i2c_mux_reserve_adapters(struct i2c_mux_core *muxc, int adapters)
{
struct i2c_adapter **adapter;
@@ -183,6 +207,9 @@ int i2c_add_mux_adapter(struct i2c_mux_core *muxc,
priv->adap.retries = parent->retries;
priv->adap.timeout = parent->timeout;
priv->adap.quirks = parent->quirks;
+ priv->adap.lock_bus = i2c_parent_lock_bus;
+ priv->adap.trylock_bus = i2c_parent_trylock_bus;
+ priv->adap.unlock_bus = i2c_parent_unlock_bus;
/* Sanity check on class */
if (i2c_mux_parent_classes(parent) & class)
--
2.1.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v3 0/8] i2c mux cleanup and locking update Peter Rosin <peda@lysator.liu.se> - 2016-01-08 16:10 +0100 [PATCH v3 8/8] i2c-mux: relax locking of the top i2c adapter during i2c controlled muxing Peter Rosin <peda@lysator.liu.se> - 2016-01-08 16:10 +0100 [PATCH v3 6/8] i2c: allow adapter drivers to override the adapter locking Peter Rosin <peda@lysator.liu.se> - 2016-01-08 16:10 +0100 [PATCH v3 5/8] i2c-mux: pinctrl: get rid of the driver private struct device pointer Peter Rosin <peda@lysator.liu.se> - 2016-01-08 16:10 +0100 [PATCH v3 3/8] i2c-mux: move the slave side adapter management to i2c_mux_core Peter Rosin <peda@lysator.liu.se> - 2016-01-08 16:10 +0100 [PATCH v3 4/8] i2c-mux: remove the mux dev pointer from the mux per channel data Peter Rosin <peda@lysator.liu.se> - 2016-01-08 16:10 +0100 [PATCH v3 1/8] i2c-mux: add common core data for every mux instance Peter Rosin <peda@lysator.liu.se> - 2016-01-08 16:10 +0100 [PATCH v3 7/8] i2c: muxes always lock the parent adapter Peter Rosin <peda@lysator.liu.se> - 2016-01-08 16:10 +0100 [PATCH v3 2/8] i2c-mux: move select and deselect ops to i2c_mux_core Peter Rosin <peda@lysator.liu.se> - 2016-01-08 16:10 +0100
csiph-web