linux/drivers/iio/industrialio-core.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * The industrial I/O core
 *
 * Copyright (c) 2008 Jonathan Cameron
 *
 * Based on elements of hwmon and input subsystems.
 */

#define pr_fmt(fmt)

#include <linux/anon_inodes.h>
#include <linux/cdev.h>
#include <linux/cleanup.h>
#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/fs.h>
#include <linux/idr.h>
#include <linux/kdev_t.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/poll.h>
#include <linux/property.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/wait.h>

#include <linux/iio/buffer.h>
#include <linux/iio/buffer_impl.h>
#include <linux/iio/events.h>
#include <linux/iio/iio-opaque.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>

#include "iio_core.h"
#include "iio_core_trigger.h"

/* IDA to assign each registered device a unique id */
static DEFINE_IDA(iio_ida);

static dev_t iio_devt;

#define IIO_DEV_MAX
const struct bus_type iio_bus_type =;
EXPORT_SYMBOL();

static struct dentry *iio_debugfs_dentry;

static const char * const iio_direction[] =;

static const char * const iio_chan_type_name_spec[] =;

static const char * const iio_modifier_names[] =;

/* relies on pairs of these shared then separate */
static const char * const iio_chan_info_postfix[] =;
/**
 * iio_device_id() - query the unique ID for the device
 * @indio_dev:		Device structure whose ID is being queried
 *
 * The IIO device ID is a unique index used for example for the naming
 * of the character device /dev/iio\:device[ID].
 *
 * Returns: Unique ID for the device.
 */
int iio_device_id(struct iio_dev *indio_dev)
{}
EXPORT_SYMBOL_GPL();

/**
 * iio_buffer_enabled() - helper function to test if the buffer is enabled
 * @indio_dev:		IIO device structure for device
 *
 * Returns: True, if the buffer is enabled.
 */
bool iio_buffer_enabled(struct iio_dev *indio_dev)
{}
EXPORT_SYMBOL_GPL();

#if defined(CONFIG_DEBUG_FS)
/*
 * There's also a CONFIG_DEBUG_FS guard in include/linux/iio/iio.h for
 * iio_get_debugfs_dentry() to make it inline if CONFIG_DEBUG_FS is undefined
 */
struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
{}
EXPORT_SYMBOL_GPL();
#endif

/**
 * iio_find_channel_from_si() - get channel from its scan index
 * @indio_dev:		device
 * @si:			scan index to match
 *
 * Returns:
 * Constant pointer to iio_chan_spec, if scan index matches, NULL on failure.
 */
const struct iio_chan_spec
*iio_find_channel_from_si(struct iio_dev *indio_dev, int si)
{}

/* This turns up an awful lot */
ssize_t iio_read_const_attr(struct device *dev,
			    struct device_attribute *attr,
			    char *buf)
{}
EXPORT_SYMBOL();

/**
 * iio_device_set_clock() - Set current timestamping clock for the device
 * @indio_dev: IIO device structure containing the device
 * @clock_id: timestamping clock POSIX identifier to set.
 *
 * Returns: 0 on success, or a negative error code.
 */
int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)
{}
EXPORT_SYMBOL();

/**
 * iio_device_get_clock() - Retrieve current timestamping clock for the device
 * @indio_dev: IIO device structure containing the device
 *
 * Returns: Clock ID of the current timestamping clock for the device.
 */
clockid_t iio_device_get_clock(const struct iio_dev *indio_dev)
{}
EXPORT_SYMBOL();

/**
 * iio_get_time_ns() - utility function to get a time stamp for events etc
 * @indio_dev: device
 *
 * Returns: Timestamp of the event in nanoseconds.
 */
s64 iio_get_time_ns(const struct iio_dev *indio_dev)
{}
EXPORT_SYMBOL();

static int __init iio_init(void)
{}

static void __exit iio_exit(void)
{}

#if defined(CONFIG_DEBUG_FS)
static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf,
			      size_t count, loff_t *ppos)
{}

static ssize_t iio_debugfs_write_reg(struct file *file,
		     const char __user *userbuf, size_t count, loff_t *ppos)
{}

static const struct file_operations iio_debugfs_reg_fops =;

static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
{}

static void iio_device_register_debugfs(struct iio_dev *indio_dev)
{}
#else
static void iio_device_register_debugfs(struct iio_dev *indio_dev)
{
}

static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
{
}
#endif /* CONFIG_DEBUG_FS */

static ssize_t iio_read_channel_ext_info(struct device *dev,
				     struct device_attribute *attr,
				     char *buf)
{}

static ssize_t iio_write_channel_ext_info(struct device *dev,
				     struct device_attribute *attr,
				     const char *buf, size_t len)
{}

ssize_t iio_enum_available_read(struct iio_dev *indio_dev,
	uintptr_t priv, const struct iio_chan_spec *chan, char *buf)
{}
EXPORT_SYMBOL_GPL();

ssize_t iio_enum_read(struct iio_dev *indio_dev,
	uintptr_t priv, const struct iio_chan_spec *chan, char *buf)
{}
EXPORT_SYMBOL_GPL();

ssize_t iio_enum_write(struct iio_dev *indio_dev,
	uintptr_t priv, const struct iio_chan_spec *chan, const char *buf,
	size_t len)
{}
EXPORT_SYMBOL_GPL();

static const struct iio_mount_matrix iio_mount_idmatrix =;

static int iio_setup_mount_idmatrix(const struct device *dev,
				    struct iio_mount_matrix *matrix)
{}

ssize_t iio_show_mount_matrix(struct iio_dev *indio_dev, uintptr_t priv,
			      const struct iio_chan_spec *chan, char *buf)
{}
EXPORT_SYMBOL_GPL();

/**
 * iio_read_mount_matrix() - retrieve iio device mounting matrix from
 *                           device "mount-matrix" property
 * @dev:	device the mounting matrix property is assigned to
 * @matrix:	where to store retrieved matrix
 *
 * If device is assigned no mounting matrix property, a default 3x3 identity
 * matrix will be filled in.
 *
 * Returns: 0 if success, or a negative error code on failure.
 */
int iio_read_mount_matrix(struct device *dev, struct iio_mount_matrix *matrix)
{}
EXPORT_SYMBOL();

static ssize_t __iio_format_value(char *buf, size_t offset, unsigned int type,
				  int size, const int *vals)
{}

/**
 * iio_format_value() - Formats a IIO value into its string representation
 * @buf:	The buffer to which the formatted value gets written
 *		which is assumed to be big enough (i.e. PAGE_SIZE).
 * @type:	One of the IIO_VAL_* constants. This decides how the val
 *		and val2 parameters are formatted.
 * @size:	Number of IIO value entries contained in vals
 * @vals:	Pointer to the values, exact meaning depends on the
 *		type parameter.
 *
 * Returns:
 * 0 by default, a negative number on failure or the total number of characters
 * written for a type that belongs to the IIO_VAL_* constant.
 */
ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals)
{}
EXPORT_SYMBOL_GPL();

ssize_t do_iio_read_channel_label(struct iio_dev *indio_dev,
				  const struct iio_chan_spec *c,
				  char *buf)
{}

static ssize_t iio_read_channel_label(struct device *dev,
				      struct device_attribute *attr,
				      char *buf)
{}

static ssize_t iio_read_channel_info(struct device *dev,
				     struct device_attribute *attr,
				     char *buf)
{}

static ssize_t iio_format_list(char *buf, const int *vals, int type, int length,
			       const char *prefix, const char *suffix)
{}

static ssize_t iio_format_avail_list(char *buf, const int *vals,
				     int type, int length)
{}

static ssize_t iio_format_avail_range(char *buf, const int *vals, int type)
{}

static ssize_t iio_read_channel_info_avail(struct device *dev,
					   struct device_attribute *attr,
					   char *buf)
{}

/**
 * __iio_str_to_fixpoint() - Parse a fixed-point number from a string
 * @str: The string to parse
 * @fract_mult: Multiplier for the first decimal place, should be a power of 10
 * @integer: The integer part of the number
 * @fract: The fractional part of the number
 * @scale_db: True if this should parse as dB
 *
 * Returns:
 * 0 on success, or a negative error code if the string could not be parsed.
 */
static int __iio_str_to_fixpoint(const char *str, int fract_mult,
				 int *integer, int *fract, bool scale_db)
{}

/**
 * iio_str_to_fixpoint() - Parse a fixed-point number from a string
 * @str: The string to parse
 * @fract_mult: Multiplier for the first decimal place, should be a power of 10
 * @integer: The integer part of the number
 * @fract: The fractional part of the number
 *
 * Returns:
 * 0 on success, or a negative error code if the string could not be parsed.
 */
int iio_str_to_fixpoint(const char *str, int fract_mult,
			int *integer, int *fract)
{}
EXPORT_SYMBOL_GPL();

static ssize_t iio_write_channel_info(struct device *dev,
				      struct device_attribute *attr,
				      const char *buf,
				      size_t len)
{}

static
int __iio_device_attr_init(struct device_attribute *dev_attr,
			   const char *postfix,
			   struct iio_chan_spec const *chan,
			   ssize_t (*readfunc)(struct device *dev,
					       struct device_attribute *attr,
					       char *buf),
			   ssize_t (*writefunc)(struct device *dev,
						struct device_attribute *attr,
						const char *buf,
						size_t len),
			   enum iio_shared_by shared_by)
{}

static void __iio_device_attr_deinit(struct device_attribute *dev_attr)
{}

int __iio_add_chan_devattr(const char *postfix,
			   struct iio_chan_spec const *chan,
			   ssize_t (*readfunc)(struct device *dev,
					       struct device_attribute *attr,
					       char *buf),
			   ssize_t (*writefunc)(struct device *dev,
						struct device_attribute *attr,
						const char *buf,
						size_t len),
			   u64 mask,
			   enum iio_shared_by shared_by,
			   struct device *dev,
			   struct iio_buffer *buffer,
			   struct list_head *attr_list)
{}

static int iio_device_add_channel_label(struct iio_dev *indio_dev,
					 struct iio_chan_spec const *chan)
{}

static int iio_device_add_info_mask_type(struct iio_dev *indio_dev,
					 struct iio_chan_spec const *chan,
					 enum iio_shared_by shared_by,
					 const long *infomask)
{}

static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev,
					       struct iio_chan_spec const *chan,
					       enum iio_shared_by shared_by,
					       const long *infomask)
{}

static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
					struct iio_chan_spec const *chan)
{}

/**
 * iio_free_chan_devattr_list() - Free a list of IIO device attributes
 * @attr_list: List of IIO device attributes
 *
 * This function frees the memory allocated for each of the IIO device
 * attributes in the list.
 */
void iio_free_chan_devattr_list(struct list_head *attr_list)
{}

static ssize_t name_show(struct device *dev, struct device_attribute *attr,
			 char *buf)
{}

static DEVICE_ATTR_RO(name);

static ssize_t label_show(struct device *dev, struct device_attribute *attr,
			  char *buf)
{}

static DEVICE_ATTR_RO(label);

static const char * const clock_names[] =;

static ssize_t current_timestamp_clock_show(struct device *dev,
					    struct device_attribute *attr,
					    char *buf)
{}

static ssize_t current_timestamp_clock_store(struct device *dev,
					     struct device_attribute *attr,
					     const char *buf, size_t len)
{}

int iio_device_register_sysfs_group(struct iio_dev *indio_dev,
				    const struct attribute_group *group)
{}

static DEVICE_ATTR_RW(current_timestamp_clock);

static int iio_device_register_sysfs(struct iio_dev *indio_dev)
{}

static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
{}

static void iio_dev_release(struct device *device)
{}

const struct device_type iio_device_type =;

/**
 * iio_device_alloc() - allocate an iio_dev from a driver
 * @parent:		Parent device.
 * @sizeof_priv:	Space to allocate for private structure.
 *
 * Returns:
 * Pointer to allocated iio_dev on success, NULL on failure.
 */
struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
{}
EXPORT_SYMBOL();

/**
 * iio_device_free() - free an iio_dev from a driver
 * @dev:		the iio_dev associated with the device
 */
void iio_device_free(struct iio_dev *dev)
{}
EXPORT_SYMBOL();

static void devm_iio_device_release(void *iio_dev)
{}

/**
 * devm_iio_device_alloc - Resource-managed iio_device_alloc()
 * @parent:		Device to allocate iio_dev for, and parent for this IIO device
 * @sizeof_priv:	Space to allocate for private structure.
 *
 * Managed iio_device_alloc. iio_dev allocated with this function is
 * automatically freed on driver detach.
 *
 * Returns:
 * Pointer to allocated iio_dev on success, NULL on failure.
 */
struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv)
{}
EXPORT_SYMBOL_GPL();

/**
 * iio_chrdev_open() - chrdev file open for buffer access and ioctls
 * @inode:	Inode structure for identifying the device in the file system
 * @filp:	File structure for iio device used to keep and later access
 *		private data
 *
 * Returns: 0 on success or -EBUSY if the device is already opened
 */
static int iio_chrdev_open(struct inode *inode, struct file *filp)
{}

/**
 * iio_chrdev_release() - chrdev file close buffer access and ioctls
 * @inode:	Inode structure pointer for the char device
 * @filp:	File structure pointer for the char device
 *
 * Returns: 0 for successful release.
 */
static int iio_chrdev_release(struct inode *inode, struct file *filp)
{}

void iio_device_ioctl_handler_register(struct iio_dev *indio_dev,
				       struct iio_ioctl_handler *h)
{}

void iio_device_ioctl_handler_unregister(struct iio_ioctl_handler *h)
{}

static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{}

static const struct file_operations iio_buffer_fileops =;

static const struct file_operations iio_event_fileops =;

static int iio_check_unique_scan_index(struct iio_dev *indio_dev)
{}

static int iio_check_extended_name(const struct iio_dev *indio_dev)
{}

static const struct iio_buffer_setup_ops noop_ring_setup_ops;

static void iio_sanity_check_avail_scan_masks(struct iio_dev *indio_dev)
{}

int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
{}
EXPORT_SYMBOL();

/**
 * iio_device_unregister() - unregister a device from the IIO subsystem
 * @indio_dev:		Device structure representing the device.
 */
void iio_device_unregister(struct iio_dev *indio_dev)
{}
EXPORT_SYMBOL();

static void devm_iio_device_unreg(void *indio_dev)
{}

int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev,
			       struct module *this_mod)
{}
EXPORT_SYMBOL_GPL();

/**
 * iio_device_claim_direct_mode - Keep device in direct mode
 * @indio_dev:	the iio_dev associated with the device
 *
 * If the device is in direct mode it is guaranteed to stay
 * that way until iio_device_release_direct_mode() is called.
 *
 * Use with iio_device_release_direct_mode()
 *
 * Returns: 0 on success, -EBUSY on failure.
 */
int iio_device_claim_direct_mode(struct iio_dev *indio_dev)
{}
EXPORT_SYMBOL_GPL();

/**
 * iio_device_release_direct_mode - releases claim on direct mode
 * @indio_dev:	the iio_dev associated with the device
 *
 * Release the claim. Device is no longer guaranteed to stay
 * in direct mode.
 *
 * Use with iio_device_claim_direct_mode()
 */
void iio_device_release_direct_mode(struct iio_dev *indio_dev)
{}
EXPORT_SYMBOL_GPL();

/**
 * iio_device_claim_buffer_mode - Keep device in buffer mode
 * @indio_dev:	the iio_dev associated with the device
 *
 * If the device is in buffer mode it is guaranteed to stay
 * that way until iio_device_release_buffer_mode() is called.
 *
 * Use with iio_device_release_buffer_mode().
 *
 * Returns: 0 on success, -EBUSY on failure.
 */
int iio_device_claim_buffer_mode(struct iio_dev *indio_dev)
{}
EXPORT_SYMBOL_GPL();

/**
 * iio_device_release_buffer_mode - releases claim on buffer mode
 * @indio_dev:	the iio_dev associated with the device
 *
 * Release the claim. Device is no longer guaranteed to stay
 * in buffer mode.
 *
 * Use with iio_device_claim_buffer_mode().
 */
void iio_device_release_buffer_mode(struct iio_dev *indio_dev)
{}
EXPORT_SYMBOL_GPL();

/**
 * iio_device_get_current_mode() - helper function providing read-only access to
 *				   the opaque @currentmode variable
 * @indio_dev:			   IIO device structure for device
 */
int iio_device_get_current_mode(struct iio_dev *indio_dev)
{}
EXPORT_SYMBOL_GPL();

subsys_initcall(iio_init);
module_exit(iio_exit);

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();