i2c: move locking operations to their own struct
authorPeter Rosin <peda@axentia.se>
Thu, 25 Aug 2016 21:07:01 +0000 (23:07 +0200)
committerWolfram Sang <wsa@the-dreams.de>
Tue, 30 Aug 2016 20:56:14 +0000 (22:56 +0200)
This makes it trivial to constify them, so do that.

Signed-off-by: Peter Rosin <peda@axentia.se>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
drivers/gpu/drm/drm_dp_helper.c
drivers/i2c/i2c-core.c
drivers/i2c/i2c-mux.c
include/linux/i2c.h

index eae5ef963cb790d261a5093aa8b8d72671b25e86..2bd064493ae7ce09cf39a47f8ce7e2786bc2567a 100644 (file)
@@ -790,6 +790,12 @@ static void unlock_bus(struct i2c_adapter *i2c, unsigned int flags)
        mutex_unlock(&i2c_to_aux(i2c)->hw_mutex);
 }
 
+static const struct i2c_lock_operations drm_dp_i2c_lock_ops = {
+       .lock_bus = lock_bus,
+       .trylock_bus = trylock_bus,
+       .unlock_bus = unlock_bus,
+};
+
 /**
  * drm_dp_aux_init() - minimally initialise an aux channel
  * @aux: DisplayPort AUX channel
@@ -807,9 +813,7 @@ void drm_dp_aux_init(struct drm_dp_aux *aux)
        aux->ddc.algo_data = aux;
        aux->ddc.retries = 3;
 
-       aux->ddc.lock_bus = lock_bus;
-       aux->ddc.trylock_bus = trylock_bus;
-       aux->ddc.unlock_bus = unlock_bus;
+       aux->ddc.lock_ops = &drm_dp_i2c_lock_ops;
 }
 EXPORT_SYMBOL(drm_dp_aux_init);
 
index 05794423e01ff55be3f37a4ce27490541601daef..0722713e59103a0234f7f97106fe37119af35294 100644 (file)
@@ -1768,6 +1768,12 @@ static int __process_new_adapter(struct device_driver *d, void *data)
        return i2c_do_add_adapter(to_i2c_driver(d), data);
 }
 
+static const struct i2c_lock_operations i2c_adapter_lock_ops = {
+       .lock_bus =    i2c_adapter_lock_bus,
+       .trylock_bus = i2c_adapter_trylock_bus,
+       .unlock_bus =  i2c_adapter_unlock_bus,
+};
+
 static int i2c_register_adapter(struct i2c_adapter *adap)
 {
        int res = -EINVAL;
@@ -1787,11 +1793,8 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
                goto out_list;
        }
 
-       if (!adap->lock_bus) {
-               adap->lock_bus = i2c_adapter_lock_bus;
-               adap->trylock_bus = i2c_adapter_trylock_bus;
-               adap->unlock_bus = i2c_adapter_unlock_bus;
-       }
+       if (!adap->lock_ops)
+               adap->lock_ops = &i2c_adapter_lock_ops;
 
        rt_mutex_init(&adap->bus_lock);
        rt_mutex_init(&adap->mux_lock);
index 90f59c08875098ab70228314a10a6fca01c186de..83768e85a919cb5c6eb60af01ce5918027600962 100644 (file)
@@ -267,6 +267,18 @@ struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent,
 }
 EXPORT_SYMBOL_GPL(i2c_mux_alloc);
 
+static const struct i2c_lock_operations i2c_mux_lock_ops = {
+       .lock_bus =    i2c_mux_lock_bus,
+       .trylock_bus = i2c_mux_trylock_bus,
+       .unlock_bus =  i2c_mux_unlock_bus,
+};
+
+static const struct i2c_lock_operations i2c_parent_lock_ops = {
+       .lock_bus =    i2c_parent_lock_bus,
+       .trylock_bus = i2c_parent_trylock_bus,
+       .unlock_bus =  i2c_parent_unlock_bus,
+};
+
 int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
                        u32 force_nr, u32 chan_id,
                        unsigned int class)
@@ -316,15 +328,10 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
        priv->adap.retries = parent->retries;
        priv->adap.timeout = parent->timeout;
        priv->adap.quirks = parent->quirks;
-       if (muxc->mux_locked) {
-               priv->adap.lock_bus = i2c_mux_lock_bus;
-               priv->adap.trylock_bus = i2c_mux_trylock_bus;
-               priv->adap.unlock_bus = i2c_mux_unlock_bus;
-       } else {
-               priv->adap.lock_bus = i2c_parent_lock_bus;
-               priv->adap.trylock_bus = i2c_parent_trylock_bus;
-               priv->adap.unlock_bus = i2c_parent_unlock_bus;
-       }
+       if (muxc->mux_locked)
+               priv->adap.lock_ops = &i2c_mux_lock_ops;
+       else
+               priv->adap.lock_ops = &i2c_parent_lock_ops;
 
        /* Sanity check on class */
        if (i2c_mux_parent_classes(parent) & class)
index 5b4a3cbe5d7dc8a855f71f0db2f2b902bf2f438b..4a4099d3a4b9cf72386c56c2f902f974cd8a3b4c 100644 (file)
@@ -426,6 +426,20 @@ struct i2c_algorithm {
 #endif
 };
 
+/**
+ * struct i2c_lock_operations - represent I2C locking operations
+ * @lock_bus: Get exclusive access to an I2C bus segment
+ * @trylock_bus: Try to get exclusive access to an I2C bus segment
+ * @unlock_bus: Release exclusive access to an I2C bus segment
+ *
+ * The main operations are wrapped by i2c_lock_bus and i2c_unlock_bus.
+ */
+struct i2c_lock_operations {
+       void (*lock_bus)(struct i2c_adapter *, unsigned int flags);
+       int (*trylock_bus)(struct i2c_adapter *, unsigned int flags);
+       void (*unlock_bus)(struct i2c_adapter *, unsigned int flags);
+};
+
 /**
  * struct i2c_timings - I2C timing information
  * @bus_freq_hz: the bus frequency in Hz
@@ -536,6 +550,7 @@ struct i2c_adapter {
        void *algo_data;
 
        /* data fields that are valid for all devices   */
+       const struct i2c_lock_operations *lock_ops;
        struct rt_mutex bus_lock;
        struct rt_mutex mux_lock;
 
@@ -552,10 +567,6 @@ struct i2c_adapter {
 
        struct i2c_bus_recovery_info *bus_recovery_info;
        const struct i2c_adapter_quirks *quirks;
-
-       void (*lock_bus)(struct i2c_adapter *, unsigned int flags);
-       int (*trylock_bus)(struct i2c_adapter *, unsigned int flags);
-       void (*unlock_bus)(struct i2c_adapter *, unsigned int flags);
 };
 #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
 
@@ -597,7 +608,7 @@ int i2c_for_each_dev(void *data, int (*fn)(struct device *, void *));
 static inline void
 i2c_lock_bus(struct i2c_adapter *adapter, unsigned int flags)
 {
-       adapter->lock_bus(adapter, flags);
+       adapter->lock_ops->lock_bus(adapter, flags);
 }
 
 /**
@@ -611,7 +622,7 @@ i2c_lock_bus(struct i2c_adapter *adapter, unsigned int flags)
 static inline int
 i2c_trylock_bus(struct i2c_adapter *adapter, unsigned int flags)
 {
-       return adapter->trylock_bus(adapter, flags);
+       return adapter->lock_ops->trylock_bus(adapter, flags);
 }
 
 /**
@@ -623,7 +634,7 @@ i2c_trylock_bus(struct i2c_adapter *adapter, unsigned int flags)
 static inline void
 i2c_unlock_bus(struct i2c_adapter *adapter, unsigned int flags)
 {
-       adapter->unlock_bus(adapter, flags);
+       adapter->lock_ops->unlock_bus(adapter, flags);
 }
 
 static inline void