Lines Matching full:atr
12 #include <linux/i2c-atr.h>
40 * @atr: The parent I2C ATR
50 struct i2c_atr *atr; member
62 * struct i2c_atr - The I2C ATR instance
64 * @dev: The device that owns the I2C ATR instance
69 * @max_adapters: Maximum number of adapters this I2C ATR can have
137 struct i2c_atr *atr = chan->atr; in i2c_atr_map_msgs() local
161 dev_err(atr->dev, "client 0x%02x not mapped!\n", in i2c_atr_map_msgs()
196 struct i2c_atr *atr = chan->atr; in i2c_atr_master_xfer() local
197 struct i2c_adapter *parent = atr->parent; in i2c_atr_master_xfer()
224 struct i2c_atr *atr = chan->atr; in i2c_atr_smbus_xfer() local
225 struct i2c_adapter *parent = atr->parent; in i2c_atr_smbus_xfer()
230 dev_err(atr->dev, "client 0x%02x not mapped!\n", addr); in i2c_atr_smbus_xfer()
241 struct i2c_adapter *parent = chan->atr->parent; in i2c_atr_functionality()
249 struct i2c_atr *atr = chan->atr; in i2c_atr_lock_bus() local
251 mutex_lock(&atr->lock); in i2c_atr_lock_bus()
257 struct i2c_atr *atr = chan->atr; in i2c_atr_trylock_bus() local
259 return mutex_trylock(&atr->lock); in i2c_atr_trylock_bus()
265 struct i2c_atr *atr = chan->atr; in i2c_atr_unlock_bus() local
267 mutex_unlock(&atr->lock); in i2c_atr_unlock_bus()
276 static int i2c_atr_reserve_alias(struct i2c_atr *atr) in i2c_atr_reserve_alias() argument
280 spin_lock(&atr->alias_mask_lock); in i2c_atr_reserve_alias()
282 idx = find_first_zero_bit(atr->alias_use_mask, atr->num_aliases); in i2c_atr_reserve_alias()
283 if (idx >= atr->num_aliases) { in i2c_atr_reserve_alias()
284 spin_unlock(&atr->alias_mask_lock); in i2c_atr_reserve_alias()
285 dev_err(atr->dev, "failed to find a free alias\n"); in i2c_atr_reserve_alias()
289 set_bit(idx, atr->alias_use_mask); in i2c_atr_reserve_alias()
291 spin_unlock(&atr->alias_mask_lock); in i2c_atr_reserve_alias()
293 return atr->aliases[idx]; in i2c_atr_reserve_alias()
296 static void i2c_atr_release_alias(struct i2c_atr *atr, u16 alias) in i2c_atr_release_alias() argument
300 spin_lock(&atr->alias_mask_lock); in i2c_atr_release_alias()
302 for (idx = 0; idx < atr->num_aliases; ++idx) { in i2c_atr_release_alias()
303 if (atr->aliases[idx] == alias) { in i2c_atr_release_alias()
304 clear_bit(idx, atr->alias_use_mask); in i2c_atr_release_alias()
305 spin_unlock(&atr->alias_mask_lock); in i2c_atr_release_alias()
310 spin_unlock(&atr->alias_mask_lock); in i2c_atr_release_alias()
313 dev_warn(atr->dev, "Unable to find mapped alias\n"); in i2c_atr_release_alias()
320 struct i2c_atr *atr = chan->atr; in i2c_atr_attach_client() local
325 ret = i2c_atr_reserve_alias(atr); in i2c_atr_attach_client()
337 ret = atr->ops->attach_client(atr, chan->chan_id, client, alias); in i2c_atr_attach_client()
341 dev_dbg(atr->dev, "chan%u: client 0x%02x mapped at alias 0x%02x (%s)\n", in i2c_atr_attach_client()
353 i2c_atr_release_alias(atr, alias); in i2c_atr_attach_client()
362 struct i2c_atr *atr = chan->atr; in i2c_atr_detach_client() local
365 atr->ops->detach_client(atr, chan->chan_id, client); in i2c_atr_detach_client()
370 dev_warn(atr->dev, "Unable to find address mapping\n"); in i2c_atr_detach_client()
374 i2c_atr_release_alias(atr, c2a->alias); in i2c_atr_detach_client()
376 dev_dbg(atr->dev, in i2c_atr_detach_client()
387 struct i2c_atr *atr = container_of(nb, struct i2c_atr, i2c_nb); in i2c_atr_bus_notifier_call() local
398 for (chan_id = 0; chan_id < atr->max_adapters; ++chan_id) { in i2c_atr_bus_notifier_call()
399 if (client->adapter == atr->adapter[chan_id]) in i2c_atr_bus_notifier_call()
403 if (chan_id == atr->max_adapters) in i2c_atr_bus_notifier_call()
410 dev_err(atr->dev, in i2c_atr_bus_notifier_call()
426 static int i2c_atr_parse_alias_pool(struct i2c_atr *atr) in i2c_atr_parse_alias_pool() argument
428 struct device *dev = atr->dev; in i2c_atr_parse_alias_pool()
485 atr->num_aliases = num_aliases; in i2c_atr_parse_alias_pool()
486 atr->aliases = aliases16; in i2c_atr_parse_alias_pool()
487 atr->alias_use_mask = alias_use_mask; in i2c_atr_parse_alias_pool()
489 dev_dbg(dev, "i2c-alias-pool has %zu aliases", atr->num_aliases); in i2c_atr_parse_alias_pool()
503 struct i2c_atr *atr; in i2c_atr_new() local
512 atr = kzalloc(struct_size(atr, adapter, max_adapters), GFP_KERNEL); in i2c_atr_new()
513 if (!atr) in i2c_atr_new()
516 mutex_init(&atr->lock); in i2c_atr_new()
517 spin_lock_init(&atr->alias_mask_lock); in i2c_atr_new()
519 atr->parent = parent; in i2c_atr_new()
520 atr->dev = dev; in i2c_atr_new()
521 atr->ops = ops; in i2c_atr_new()
522 atr->max_adapters = max_adapters; in i2c_atr_new()
525 atr->algo.master_xfer = i2c_atr_master_xfer; in i2c_atr_new()
527 atr->algo.smbus_xfer = i2c_atr_smbus_xfer; in i2c_atr_new()
528 atr->algo.functionality = i2c_atr_functionality; in i2c_atr_new()
530 ret = i2c_atr_parse_alias_pool(atr); in i2c_atr_new()
534 atr->i2c_nb.notifier_call = i2c_atr_bus_notifier_call; in i2c_atr_new()
535 ret = bus_register_notifier(&i2c_bus_type, &atr->i2c_nb); in i2c_atr_new()
539 return atr; in i2c_atr_new()
542 bitmap_free(atr->alias_use_mask); in i2c_atr_new()
543 kfree(atr->aliases); in i2c_atr_new()
545 mutex_destroy(&atr->lock); in i2c_atr_new()
546 kfree(atr); in i2c_atr_new()
552 void i2c_atr_delete(struct i2c_atr *atr) in i2c_atr_delete() argument
556 for (i = 0; i < atr->max_adapters; ++i) in i2c_atr_delete()
557 WARN_ON(atr->adapter[i]); in i2c_atr_delete()
559 bus_unregister_notifier(&i2c_bus_type, &atr->i2c_nb); in i2c_atr_delete()
560 bitmap_free(atr->alias_use_mask); in i2c_atr_delete()
561 kfree(atr->aliases); in i2c_atr_delete()
562 mutex_destroy(&atr->lock); in i2c_atr_delete()
563 kfree(atr); in i2c_atr_delete()
567 int i2c_atr_add_adapter(struct i2c_atr *atr, u32 chan_id, in i2c_atr_add_adapter() argument
571 struct i2c_adapter *parent = atr->parent; in i2c_atr_add_adapter()
572 struct device *dev = atr->dev; in i2c_atr_add_adapter()
577 if (chan_id >= atr->max_adapters) { in i2c_atr_add_adapter()
578 dev_err(dev, "No room for more i2c-atr adapters\n"); in i2c_atr_add_adapter()
582 if (atr->adapter[chan_id]) { in i2c_atr_add_adapter()
594 chan->atr = atr; in i2c_atr_add_adapter()
599 snprintf(chan->adap.name, sizeof(chan->adap.name), "i2c-%d-atr-%d", in i2c_atr_add_adapter()
602 chan->adap.algo = &atr->algo; in i2c_atr_add_adapter()
617 atr_node = device_get_named_child_node(dev, "i2c-atr"); in i2c_atr_add_adapter()
631 atr->adapter[chan_id] = &chan->adap; in i2c_atr_add_adapter()
635 dev_err(dev, "failed to add atr-adapter %u (error=%d)\n", in i2c_atr_add_adapter()
645 dev_warn(dev, "can't create symlink to atr device\n"); in i2c_atr_add_adapter()
650 dev_dbg(dev, "Added ATR child bus %d\n", i2c_adapter_id(&chan->adap)); in i2c_atr_add_adapter()
662 void i2c_atr_del_adapter(struct i2c_atr *atr, u32 chan_id) in i2c_atr_del_adapter() argument
668 struct device *dev = atr->dev; in i2c_atr_del_adapter()
670 adap = atr->adapter[chan_id]; in i2c_atr_del_adapter()
677 dev_dbg(dev, "Removing ATR child bus %d\n", i2c_adapter_id(adap)); in i2c_atr_del_adapter()
686 atr->adapter[chan_id] = NULL; in i2c_atr_del_adapter()
695 void i2c_atr_set_driver_data(struct i2c_atr *atr, void *data) in i2c_atr_set_driver_data() argument
697 atr->priv = data; in i2c_atr_set_driver_data()
701 void *i2c_atr_get_driver_data(struct i2c_atr *atr) in i2c_atr_get_driver_data() argument
703 return atr->priv; in i2c_atr_get_driver_data()