drivers/i2c/i2c-atr.c

Source file repositories/reference/linux-study-clean/drivers/i2c/i2c-atr.c

File Facts

System
Linux kernel
Corpus path
drivers/i2c/i2c-atr.c
Extension
.c
Size
23630 bytes
Lines
946
Domain
Driver Families
Bucket
drivers/i2c
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct i2c_atr_alias_pair {
	struct list_head node;
	bool fixed;
	u16 addr;
	u16 alias;
};

/**
 * struct i2c_atr_alias_pool - Pool of client aliases available for an ATR.
 * @size:     Total number of aliases
 * @shared:   Indicates if this alias pool is shared by multiple channels
 *
 * @lock:     Lock protecting @aliases and @use_mask
 * @use_mask: Mask of used aliases
 * @aliases:  Array of aliases, must hold exactly @size elements
 */
struct i2c_atr_alias_pool {
	size_t size;
	bool shared;

	/* Protects aliases and use_mask */
	spinlock_t lock;
	unsigned long *use_mask;
	u16 aliases[] __counted_by(size);
};

/**
 * struct i2c_atr_chan - Data for a channel.
 * @adap:            The &struct i2c_adapter for the channel
 * @atr:             The parent I2C ATR
 * @chan_id:         The ID of this channel
 * @alias_pairs_lock: Mutex protecting @alias_pairs
 * @alias_pairs_lock_key: Lock key for @alias_pairs_lock
 * @alias_pairs:     List of @struct i2c_atr_alias_pair containing the
 *                   assigned aliases
 * @alias_pool:      Pool of available client aliases
 *
 * @orig_addrs_lock: Mutex protecting @orig_addrs
 * @orig_addrs_lock_key: Lock key for @orig_addrs_lock
 * @orig_addrs:      Buffer used to store the original addresses during transmit
 * @orig_addrs_size: Size of @orig_addrs
 */
struct i2c_atr_chan {
	struct i2c_adapter adap;
	struct i2c_atr *atr;
	u32 chan_id;

	/* Lock alias_pairs during attach/detach */
	struct mutex alias_pairs_lock;
	struct lock_class_key alias_pairs_lock_key;
	struct list_head alias_pairs;
	struct i2c_atr_alias_pool *alias_pool;

	/* Lock orig_addrs during xfer */
	struct mutex orig_addrs_lock;
	struct lock_class_key orig_addrs_lock_key;
	u16 *orig_addrs;
	unsigned int orig_addrs_size;
};

/**
 * struct i2c_atr - The I2C ATR instance
 * @parent:    The parent &struct i2c_adapter
 * @dev:       The device that owns the I2C ATR instance
 * @ops:       &struct i2c_atr_ops
 * @priv:      Private driver data, set with i2c_atr_set_driver_data()
 * @algo:      The &struct i2c_algorithm for adapters
 * @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
 */
struct i2c_atr {
	struct i2c_adapter *parent;
	struct device *dev;
	const struct i2c_atr_ops *ops;

	void *priv;

	struct i2c_algorithm algo;
	/* lock for the I2C bus segment (see struct i2c_lock_operations) */
	struct mutex lock;
	struct lock_class_key lock_key;
	int max_adapters;
	u32 flags;

	struct i2c_atr_alias_pool *alias_pool;

Annotation

Implementation Notes