drivers/iio/industrialio-backend.c

Source file repositories/reference/linux-study-clean/drivers/iio/industrialio-backend.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/industrialio-backend.c
Extension
.c
Size
32652 bytes
Lines
1144
Domain
Driver Families
Bucket
drivers/iio
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern 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

static const struct file_operations iio_backend_debugfs_reg_fops = {
	.open = simple_open,
	.read = iio_backend_debugfs_read_reg,
	.write = iio_backend_debugfs_write_reg,
};

static ssize_t iio_backend_debugfs_read_name(struct file *file,
					     char __user *userbuf,
					     size_t count, loff_t *ppos)
{
	struct iio_backend *back = file->private_data;
	char name[128];
	int len;

	len = scnprintf(name, sizeof(name), "%s\n", back->name);

	return simple_read_from_buffer(userbuf, count, ppos, name, len);
}

static const struct file_operations iio_backend_debugfs_name_fops = {
	.open = simple_open,
	.read = iio_backend_debugfs_read_name,
};

/**
 * iio_backend_debugfs_add - Add debugfs interfaces for Backends
 * @back: Backend device
 * @indio_dev: IIO device
 */
void iio_backend_debugfs_add(struct iio_backend *back,
			     struct iio_dev *indio_dev)
{
	struct dentry *d = iio_get_debugfs_dentry(indio_dev);
	struct dentry *back_d;
	char name[128];

	if (!IS_ENABLED(CONFIG_DEBUG_FS) || !d)
		return;
	if (!back->ops->debugfs_reg_access && !back->name)
		return;

	snprintf(name, sizeof(name), "backend%d", back->idx);

	back_d = debugfs_create_dir(name, d);
	if (IS_ERR(back_d))
		return;

	if (back->ops->debugfs_reg_access)
		debugfs_create_file("direct_reg_access", 0600, back_d, back,
				    &iio_backend_debugfs_reg_fops);

	if (back->name)
		debugfs_create_file("name", 0400, back_d, back,
				    &iio_backend_debugfs_name_fops);
}
EXPORT_SYMBOL_NS_GPL(iio_backend_debugfs_add, "IIO_BACKEND");

/**
 * iio_backend_debugfs_print_chan_status - Print channel status
 * @back: Backend device
 * @chan: Channel number
 * @buf: Buffer where to print the status
 * @len: Available space
 *
 * One usecase where this is useful is for testing test tones in a digital
 * interface and "ask" the backend to dump more details on why a test tone might
 * have errors.
 *
 * RETURNS:
 * Number of copied bytes on success, negative error code on failure.
 */
ssize_t iio_backend_debugfs_print_chan_status(struct iio_backend *back,
					      unsigned int chan, char *buf,
					      size_t len)
{
	if (!IS_ENABLED(CONFIG_DEBUG_FS))
		return -ENODEV;

	return iio_backend_op_call(back, debugfs_print_chan_status, chan, buf,
				   len);
}
EXPORT_SYMBOL_NS_GPL(iio_backend_debugfs_print_chan_status, "IIO_BACKEND");

/**
 * iio_backend_chan_enable - Enable a backend channel
 * @back: Backend device
 * @chan: Channel number
 *
 * RETURNS:
 * 0 on success, negative error number on failure.

Annotation

Implementation Notes