]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
i2c: atr: add static flag
authorCosmin Tanislav <demonsingur@gmail.com>
Wed, 7 May 2025 12:19:13 +0000 (15:19 +0300)
committerWolfram Sang <wsa+renesas@sang-engineering.com>
Thu, 22 May 2025 09:07:05 +0000 (11:07 +0200)
Some I2C ATRs do not support dynamic remapping, only static mapping
of direct children.

Mappings will only be added or removed as a result of devices being
added or removed from a child bus.

The ATR pool will have to be big enough to accommodate all devices
expected to be added to the child buses.

Add a new flag that prevents old mappings to be replaced or new mappings
to be created in the alias finding code paths. That mens adding a flags
parameter to i2c_atr_new() and an i2c_atr_flags enum.

Signed-off-by: Cosmin Tanislav <demonsingur@gmail.com>
Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Reviewed-by: Romain Gantois <romain.gantois@bootlin.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
drivers/i2c/i2c-atr.c
drivers/media/i2c/ds90ub960.c
drivers/misc/ti_fpc202.c
include/linux/i2c-atr.h

index f3fd52588e421212e610ed083a77bac36cd6a61d..19422df0fe374b572e8734bfc4ca5d3df88d3f70 100644 (file)
@@ -106,6 +106,7 @@ struct i2c_atr_chan {
  * @lock:      Lock for the I2C bus segment (see &struct i2c_lock_operations)
  * @lock_key:  Lock key for @lock
  * @max_adapters: Maximum number of adapters this I2C ATR can have
+ * @flags:     Flags for ATR
  * @alias_pool: Optional common pool of available client aliases
  * @i2c_nb:    Notifier for remote client add & del events
  * @adapter:   Array of adapters
@@ -122,6 +123,7 @@ struct i2c_atr {
        struct mutex lock;
        struct lock_class_key lock_key;
        int max_adapters;
+       u32 flags;
 
        struct i2c_atr_alias_pool *alias_pool;
 
@@ -339,12 +341,16 @@ i2c_atr_replace_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr)
 static struct i2c_atr_alias_pair *
 i2c_atr_get_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr)
 {
+       struct i2c_atr *atr = chan->atr;
        struct i2c_atr_alias_pair *c2a;
 
        c2a = i2c_atr_find_mapping_by_addr(chan, addr);
        if (c2a)
                return c2a;
 
+       if (atr->flags & I2C_ATR_F_STATIC)
+               return NULL;
+
        c2a = i2c_atr_create_mapping_by_addr(chan, addr);
        if (c2a)
                return c2a;
@@ -543,7 +549,7 @@ static int i2c_atr_attach_addr(struct i2c_adapter *adapter,
        mutex_lock(&chan->alias_pairs_lock);
 
        c2a = i2c_atr_create_mapping_by_addr(chan, addr);
-       if (!c2a)
+       if (!c2a && !(atr->flags & I2C_ATR_F_STATIC))
                c2a = i2c_atr_replace_mapping_by_addr(chan, addr);
 
        if (!c2a) {
@@ -703,7 +709,8 @@ err_free_alias_pool:
 }
 
 struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev,
-                           const struct i2c_atr_ops *ops, int max_adapters)
+                           const struct i2c_atr_ops *ops, int max_adapters,
+                           u32 flags)
 {
        struct i2c_atr *atr;
        int ret;
@@ -725,6 +732,7 @@ struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev,
        atr->dev = dev;
        atr->ops = ops;
        atr->max_adapters = max_adapters;
+       atr->flags = flags;
 
        if (parent->algo->master_xfer)
                atr->algo.master_xfer = i2c_atr_master_xfer;
index 5a4d5de110bd7ad78746148aa731c68188d89108..94b20ba6cb86fd9f6d4c67c66ae5f85e5611a96c 100644 (file)
@@ -1122,7 +1122,7 @@ static int ub960_init_atr(struct ub960_data *priv)
        struct i2c_adapter *parent_adap = priv->client->adapter;
 
        priv->atr = i2c_atr_new(parent_adap, dev, &ub960_atr_ops,
-                               priv->hw_data->num_rxports);
+                               priv->hw_data->num_rxports, 0);
        if (IS_ERR(priv->atr))
                return PTR_ERR(priv->atr);
 
index b9c9ee4bfc4edba102b3bf7ae33a2b68c19c83ec..f7cde245ac95475a3f78863c4ea1540d8cf3fbd5 100644 (file)
@@ -349,7 +349,7 @@ static int fpc202_probe(struct i2c_client *client)
                goto disable_gpio;
        }
 
-       priv->atr = i2c_atr_new(client->adapter, dev, &fpc202_atr_ops, 2);
+       priv->atr = i2c_atr_new(client->adapter, dev, &fpc202_atr_ops, 2, 0);
        if (IS_ERR(priv->atr)) {
                ret = PTR_ERR(priv->atr);
                dev_err(dev, "failed to create i2c atr err %d\n", ret);
index 1c3a5bcd939fc56f4a6ca1b6a5cc0ac2c17083b7..5aaab1598084952600917dd51bdfb359c68f52f4 100644 (file)
@@ -18,6 +18,19 @@ struct device;
 struct fwnode_handle;
 struct i2c_atr;
 
+/**
+ * enum i2c_atr_flags - Flags for an I2C ATR driver
+ *
+ * @I2C_ATR_F_STATIC: ATR does not support dynamic mapping, use static mapping.
+ *                    Mappings will only be added or removed as a result of
+ *                    devices being added or removed from a child bus.
+ *                    The ATR pool will have to be big enough to accomodate all
+ *                    devices expected to be added to the child buses.
+ */
+enum i2c_atr_flags {
+       I2C_ATR_F_STATIC = BIT(0),
+};
+
 /**
  * struct i2c_atr_ops - Callbacks from ATR to the device driver.
  * @attach_addr: Notify the driver of a new device connected on a child
@@ -65,6 +78,7 @@ struct i2c_atr_adap_desc {
  * @dev:          The device acting as an ATR
  * @ops:          Driver-specific callbacks
  * @max_adapters: Maximum number of child adapters
+ * @flags:        Flags for ATR
  *
  * The new ATR helper is connected to the parent adapter but has no child
  * adapters. Call i2c_atr_add_adapter() to add some.
@@ -74,7 +88,8 @@ struct i2c_atr_adap_desc {
  * Return: pointer to the new ATR helper object, or ERR_PTR
  */
 struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev,
-                           const struct i2c_atr_ops *ops, int max_adapters);
+                           const struct i2c_atr_ops *ops, int max_adapters,
+                           u32 flags);
 
 /**
  * i2c_atr_delete - Delete an I2C ATR helper.