Release 4.12 drivers/iio/inkern.c
  
  
  
/* The industrial I/O core in kernel channel mapping
 *
 * Copyright (c) 2011 Jonathan Cameron
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 */
#include <linux/err.h>
#include <linux/export.h>
#include <linux/slab.h>
#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/iio/iio.h>
#include "iio_core.h"
#include <linux/iio/machine.h>
#include <linux/iio/driver.h>
#include <linux/iio/consumer.h>
struct iio_map_internal {
	
struct iio_dev *indio_dev;
	
struct iio_map *map;
	
struct list_head l;
};
static LIST_HEAD(iio_map_list);
static DEFINE_MUTEX(iio_map_list_lock);
int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps)
{
	int i = 0, ret = 0;
	struct iio_map_internal *mapi;
	if (maps == NULL)
		return 0;
	mutex_lock(&iio_map_list_lock);
	while (maps[i].consumer_dev_name != NULL) {
		mapi = kzalloc(sizeof(*mapi), GFP_KERNEL);
		if (mapi == NULL) {
			ret = -ENOMEM;
			goto error_ret;
		}
		mapi->map = &maps[i];
		mapi->indio_dev = indio_dev;
		list_add(&mapi->l, &iio_map_list);
		i++;
	}
error_ret:
	mutex_unlock(&iio_map_list_lock);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Jonathan Cameron | 127 | 100.00% | 1 | 100.00% | 
| Total | 127 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_map_array_register);
/*
 * Remove all map entries associated with the given iio device
 */
int iio_map_array_unregister(struct iio_dev *indio_dev)
{
	int ret = -ENODEV;
	struct iio_map_internal *mapi, *next;
	mutex_lock(&iio_map_list_lock);
	list_for_each_entry_safe(mapi, next, &iio_map_list, l) {
		if (indio_dev == mapi->indio_dev) {
			list_del(&mapi->l);
			kfree(mapi);
			ret = 0;
		}
	}
	mutex_unlock(&iio_map_list_lock);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Jonathan Cameron | 60 | 76.92% | 1 | 33.33% | 
| Guenter Roeck | 12 | 15.38% | 1 | 33.33% | 
| Anshul Garg | 6 | 7.69% | 1 | 33.33% | 
| Total | 78 | 100.00% | 3 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_map_array_unregister);
static const struct iio_chan_spec
*iio_chan_spec_from_name(const struct iio_dev *indio_dev, const char *name)
{
	int i;
	const struct iio_chan_spec *chan = NULL;
	for (i = 0; i < indio_dev->num_channels; i++)
		if (indio_dev->channels[i].datasheet_name &&
		    strcmp(name, indio_dev->channels[i].datasheet_name) == 0) {
			chan = &indio_dev->channels[i];
			break;
		}
	return chan;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Jonathan Cameron | 89 | 100.00% | 1 | 100.00% | 
| Total | 89 | 100.00% | 1 | 100.00% | 
#ifdef CONFIG_OF
static int iio_dev_node_match(struct device *dev, void *data)
{
	return dev->of_node == data && dev->type == &iio_device_type;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Guenter Roeck | 27 | 93.10% | 2 | 66.67% | 
| Jonathan Cameron | 2 | 6.90% | 1 | 33.33% | 
| Total | 29 | 100.00% | 3 | 100.00% | 
/**
 * __of_iio_simple_xlate - translate iiospec to the IIO channel index
 * @indio_dev:  pointer to the iio_dev structure
 * @iiospec:    IIO specifier as found in the device tree
 *
 * This is simple translation function, suitable for the most 1:1 mapped
 * channels in IIO chips. This function performs only one sanity check:
 * whether IIO index is less than num_channels (that is specified in the
 * iio_dev).
 */
static int __of_iio_simple_xlate(struct iio_dev *indio_dev,
				const struct of_phandle_args *iiospec)
{
	if (!iiospec->args_count)
		return 0;
	if (iiospec->args[0] >= indio_dev->num_channels) {
		dev_err(&indio_dev->dev, "invalid channel index %u\n",
			iiospec->args[0]);
		return -EINVAL;
	}
	return iiospec->args[0];
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Ivan T. Ivanov | 52 | 73.24% | 1 | 50.00% | 
| Stefan Wahren | 19 | 26.76% | 1 | 50.00% | 
| Total | 71 | 100.00% | 2 | 100.00% | 
static int __of_iio_channel_get(struct iio_channel *channel,
				struct device_node *np, int index)
{
	struct device *idev;
	struct iio_dev *indio_dev;
	int err;
	struct of_phandle_args iiospec;
	err = of_parse_phandle_with_args(np, "io-channels",
					 "#io-channel-cells",
					 index, &iiospec);
	if (err)
		return err;
	idev = bus_find_device(&iio_bus_type, NULL, iiospec.np,
			       iio_dev_node_match);
	of_node_put(iiospec.np);
	if (idev == NULL)
		return -EPROBE_DEFER;
	indio_dev = dev_to_iio_dev(idev);
	channel->indio_dev = indio_dev;
	if (indio_dev->info->of_xlate)
		index = indio_dev->info->of_xlate(indio_dev, &iiospec);
	else
		index = __of_iio_simple_xlate(indio_dev, &iiospec);
	if (index < 0)
		goto err_put;
	channel->channel = &indio_dev->channels[index];
	return 0;
err_put:
	iio_device_put(indio_dev);
	return index;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Guenter Roeck | 74 | 43.02% | 1 | 16.67% | 
| Jonathan Cameron | 48 | 27.91% | 1 | 16.67% | 
| Ivan T. Ivanov | 31 | 18.02% | 1 | 16.67% | 
| Kim (Woogyom) Milo | 19 | 11.05% | 3 | 50.00% | 
| Total | 172 | 100.00% | 6 | 100.00% | 
static struct iio_channel *of_iio_channel_get(struct device_node *np, int index)
{
	struct iio_channel *channel;
	int err;
	if (index < 0)
		return ERR_PTR(-EINVAL);
	channel = kzalloc(sizeof(*channel), GFP_KERNEL);
	if (channel == NULL)
		return ERR_PTR(-ENOMEM);
	err = __of_iio_channel_get(channel, np, index);
	if (err)
		goto err_free_channel;
	return channel;
err_free_channel:
	kfree(channel);
	return ERR_PTR(err);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Guenter Roeck | 97 | 100.00% | 1 | 100.00% | 
| Total | 97 | 100.00% | 1 | 100.00% | 
static struct iio_channel *of_iio_channel_get_by_name(struct device_node *np,
						      const char *name)
{
	struct iio_channel *chan = NULL;
	/* Walk up the tree of devices looking for a matching iio channel */
	while (np) {
		int index = 0;
		/*
                 * For named iio channels, first look up the name in the
                 * "io-channel-names" property.  If it cannot be found, the
                 * index will be an error code, and of_iio_channel_get()
                 * will fail.
                 */
		if (name)
			index = of_property_match_string(np, "io-channel-names",
							 name);
		chan = of_iio_channel_get(np, index);
		if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER)
			break;
		else if (name && index >= 0) {
			pr_err("ERROR: could not get IIO channel %s:%s(%i)\n",
				np->full_name, name ? name : "", index);
			return NULL;
		}
		/*
                 * No matching IIO channel found on this node.
                 * If the parent node has a "io-channel-ranges" property,
                 * then we can try one of its channels.
                 */
		np = np->parent;
		if (np && !of_get_property(np, "io-channel-ranges", NULL))
			return NULL;
	}
	return chan;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Guenter Roeck | 125 | 91.24% | 1 | 33.33% | 
| Johannes Pointner | 8 | 5.84% | 1 | 33.33% | 
| Adam Thomson | 4 | 2.92% | 1 | 33.33% | 
| Total | 137 | 100.00% | 3 | 100.00% | 
static struct iio_channel *of_iio_channel_get_all(struct device *dev)
{
	struct iio_channel *chans;
	int i, mapind, nummaps = 0;
	int ret;
	do {
		ret = of_parse_phandle_with_args(dev->of_node,
						 "io-channels",
						 "#io-channel-cells",
						 nummaps, NULL);
		if (ret < 0)
			break;
	} while (++nummaps);
	if (nummaps == 0)	/* no error, return NULL to search map table */
		return NULL;
	/* NULL terminated array to save passing size */
	chans = kcalloc(nummaps + 1, sizeof(*chans), GFP_KERNEL);
	if (chans == NULL)
		return ERR_PTR(-ENOMEM);
	/* Search for OF matches */
	for (mapind = 0; mapind < nummaps; mapind++) {
		ret = __of_iio_channel_get(&chans[mapind], dev->of_node,
					   mapind);
		if (ret)
			goto error_free_chans;
	}
	return chans;
error_free_chans:
	for (i = 0; i < mapind; i++)
		iio_device_put(chans[i].indio_dev);
	kfree(chans);
	return ERR_PTR(ret);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Guenter Roeck | 183 | 100.00% | 1 | 100.00% | 
| Total | 183 | 100.00% | 1 | 100.00% | 
#else /* CONFIG_OF */
static inline struct iio_channel *
of_iio_channel_get_by_name(struct device_node *np, const char *name)
{
	return NULL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Guenter Roeck | 22 | 100.00% | 1 | 100.00% | 
| Total | 22 | 100.00% | 1 | 100.00% | 
static inline struct iio_channel *of_iio_channel_get_all(struct device *dev)
{
	return NULL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Guenter Roeck | 17 | 100.00% | 1 | 100.00% | 
| Total | 17 | 100.00% | 1 | 100.00% | 
#endif /* CONFIG_OF */
static struct iio_channel *iio_channel_get_sys(const char *name,
					       const char *channel_name)
{
	struct iio_map_internal *c_i = NULL, *c = NULL;
	struct iio_channel *channel;
	int err;
	if (name == NULL && channel_name == NULL)
		return ERR_PTR(-ENODEV);
	/* first find matching entry the channel map */
	mutex_lock(&iio_map_list_lock);
	list_for_each_entry(c_i, &iio_map_list, l) {
		if ((name && strcmp(name, c_i->map->consumer_dev_name) != 0) ||
		    (channel_name &&
		     strcmp(channel_name, c_i->map->consumer_channel) != 0))
			continue;
		c = c_i;
		iio_device_get(c->indio_dev);
		break;
	}
	mutex_unlock(&iio_map_list_lock);
	if (c == NULL)
		return ERR_PTR(-ENODEV);
	channel = kzalloc(sizeof(*channel), GFP_KERNEL);
	if (channel == NULL) {
		err = -ENOMEM;
		goto error_no_mem;
	}
	channel->indio_dev = c->indio_dev;
	if (c->map->adc_channel_label) {
		channel->channel =
			iio_chan_spec_from_name(channel->indio_dev,
						c->map->adc_channel_label);
		if (channel->channel == NULL) {
			err = -EINVAL;
			goto error_no_chan;
		}
	}
	return channel;
error_no_chan:
	kfree(channel);
error_no_mem:
	iio_device_put(c->indio_dev);
	return ERR_PTR(err);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Guenter Roeck | 247 | 100.00% | 1 | 100.00% | 
| Total | 247 | 100.00% | 1 | 100.00% | 
struct iio_channel *iio_channel_get(struct device *dev,
				    const char *channel_name)
{
	const char *name = dev ? dev_name(dev) : NULL;
	struct iio_channel *channel;
	if (dev) {
		channel = of_iio_channel_get_by_name(dev->of_node,
						     channel_name);
		if (channel != NULL)
			return channel;
	}
	return iio_channel_get_sys(name, channel_name);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Guenter Roeck | 70 | 100.00% | 2 | 100.00% | 
| Total | 70 | 100.00% | 2 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_channel_get);
void iio_channel_release(struct iio_channel *channel)
{
	if (!channel)
		return;
	iio_device_put(channel->indio_dev);
	kfree(channel);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Jonathan Cameron | 21 | 75.00% | 2 | 50.00% | 
| Dan Carpenter | 6 | 21.43% | 1 | 25.00% | 
| Lars-Peter Clausen | 1 | 3.57% | 1 | 25.00% | 
| Total | 28 | 100.00% | 4 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_channel_release);
static void devm_iio_channel_free(struct device *dev, void *res)
{
	struct iio_channel *channel = *(struct iio_channel **)res;
	iio_channel_release(channel);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Laxman Dewangan | 34 | 100.00% | 1 | 100.00% | 
| Total | 34 | 100.00% | 1 | 100.00% | 
static int devm_iio_channel_match(struct device *dev, void *res, void *data)
{
	struct iio_channel **r = res;
	if (!r || !*r) {
		WARN_ON(!r || !*r);
		return 0;
	}
	return *r == data;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Laxman Dewangan | 57 | 100.00% | 1 | 100.00% | 
| Total | 57 | 100.00% | 1 | 100.00% | 
struct iio_channel *devm_iio_channel_get(struct device *dev,
					 const char *channel_name)
{
	struct iio_channel **ptr, *channel;
	ptr = devres_alloc(devm_iio_channel_free, sizeof(*ptr), GFP_KERNEL);
	if (!ptr)
		return ERR_PTR(-ENOMEM);
	channel = iio_channel_get(dev, channel_name);
	if (IS_ERR(channel)) {
		devres_free(ptr);
		return channel;
	}
	*ptr = channel;
	devres_add(dev, ptr);
	return channel;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Laxman Dewangan | 94 | 100.00% | 1 | 100.00% | 
| Total | 94 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(devm_iio_channel_get);
void devm_iio_channel_release(struct device *dev, struct iio_channel *channel)
{
	WARN_ON(devres_release(dev, devm_iio_channel_free,
			       devm_iio_channel_match, channel));
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Laxman Dewangan | 29 | 100.00% | 1 | 100.00% | 
| Total | 29 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(devm_iio_channel_release);
struct iio_channel *iio_channel_get_all(struct device *dev)
{
	const char *name;
	struct iio_channel *chans;
	struct iio_map_internal *c = NULL;
	int nummaps = 0;
	int mapind = 0;
	int i, ret;
	if (dev == NULL)
		return ERR_PTR(-EINVAL);
	chans = of_iio_channel_get_all(dev);
	if (chans)
		return chans;
	name = dev_name(dev);
	mutex_lock(&iio_map_list_lock);
	/* first count the matching maps */
	list_for_each_entry(c, &iio_map_list, l)
		if (name && strcmp(name, c->map->consumer_dev_name) != 0)
			continue;
		else
			nummaps++;
	if (nummaps == 0) {
		ret = -ENODEV;
		goto error_ret;
	}
	/* NULL terminated array to save passing size */
	chans = kzalloc(sizeof(*chans)*(nummaps + 1), GFP_KERNEL);
	if (chans == NULL) {
		ret = -ENOMEM;
		goto error_ret;
	}
	/* for each map fill in the chans element */
	list_for_each_entry(c, &iio_map_list, l) {
		if (name && strcmp(name, c->map->consumer_dev_name) != 0)
			continue;
		chans[mapind].indio_dev = c->indio_dev;
		chans[mapind].data = c->map->consumer_data;
		chans[mapind].channel =
			iio_chan_spec_from_name(chans[mapind].indio_dev,
						c->map->adc_channel_label);
		if (chans[mapind].channel == NULL) {
			ret = -EINVAL;
			goto error_free_chans;
		}
		iio_device_get(chans[mapind].indio_dev);
		mapind++;
	}
	if (mapind == 0) {
		ret = -ENODEV;
		goto error_free_chans;
	}
	mutex_unlock(&iio_map_list_lock);
	return chans;
error_free_chans:
	for (i = 0; i < nummaps; i++)
		iio_device_put(chans[i].indio_dev);
	kfree(chans);
error_ret:
	mutex_unlock(&iio_map_list_lock);
	return ERR_PTR(ret);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Jonathan Cameron | 309 | 89.31% | 3 | 42.86% | 
| Guenter Roeck | 29 | 8.38% | 2 | 28.57% | 
| Dan Carpenter | 6 | 1.73% | 1 | 14.29% | 
| Lars-Peter Clausen | 2 | 0.58% | 1 | 14.29% | 
| Total | 346 | 100.00% | 7 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_channel_get_all);
void iio_channel_release_all(struct iio_channel *channels)
{
	struct iio_channel *chan = &channels[0];
	while (chan->indio_dev) {
		iio_device_put(chan->indio_dev);
		chan++;
	}
	kfree(channels);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Jonathan Cameron | 43 | 97.73% | 2 | 66.67% | 
| Lars-Peter Clausen | 1 | 2.27% | 1 | 33.33% | 
| Total | 44 | 100.00% | 3 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_channel_release_all);
static void devm_iio_channel_free_all(struct device *dev, void *res)
{
	struct iio_channel *channels = *(struct iio_channel **)res;
	iio_channel_release_all(channels);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Laxman Dewangan | 34 | 100.00% | 1 | 100.00% | 
| Total | 34 | 100.00% | 1 | 100.00% | 
struct iio_channel *devm_iio_channel_get_all(struct device *dev)
{
	struct iio_channel **ptr, *channels;
	ptr = devres_alloc(devm_iio_channel_free_all, sizeof(*ptr), GFP_KERNEL);
	if (!ptr)
		return ERR_PTR(-ENOMEM);
	channels = iio_channel_get_all(dev);
	if (IS_ERR(channels)) {
		devres_free(ptr);
		return channels;
	}
	*ptr = channels;
	devres_add(dev, ptr);
	return channels;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Laxman Dewangan | 87 | 100.00% | 1 | 100.00% | 
| Total | 87 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(devm_iio_channel_get_all);
void devm_iio_channel_release_all(struct device *dev,
				  struct iio_channel *channels)
{
	WARN_ON(devres_release(dev, devm_iio_channel_free_all,
			       devm_iio_channel_match, channels));
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Laxman Dewangan | 29 | 100.00% | 1 | 100.00% | 
| Total | 29 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(devm_iio_channel_release_all);
static int iio_channel_read(struct iio_channel *chan, int *val, int *val2,
	enum iio_chan_info_enum info)
{
	int unused;
	int vals[INDIO_MAX_RAW_ELEMENTS];
	int ret;
	int val_len = 2;
	if (val2 == NULL)
		val2 = &unused;
	if (!iio_channel_has_info(chan->channel, info))
		return -EINVAL;
	if (chan->indio_dev->info->read_raw_multi) {
		ret = chan->indio_dev->info->read_raw_multi(chan->indio_dev,
					chan->channel, INDIO_MAX_RAW_ELEMENTS,
					vals, &val_len, info);
		*val = vals[0];
		*val2 = vals[1];
	} else
		ret = chan->indio_dev->info->read_raw(chan->indio_dev,
					chan->channel, val, val2, info);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Srinivas Pandruvada | 76 | 50.00% | 1 | 33.33% | 
| Lars-Peter Clausen | 60 | 39.47% | 1 | 33.33% | 
| Fabien Proriol | 16 | 10.53% | 1 | 33.33% | 
| Total | 152 | 100.00% | 3 | 100.00% | 
int iio_read_channel_raw(struct iio_channel *chan, int *val)
{
	int ret;
	mutex_lock(&chan->indio_dev->info_exist_lock);
	if (chan->indio_dev->info == NULL) {
		ret = -ENODEV;
		goto err_unlock;
	}
	ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_RAW);
err_unlock:
	mutex_unlock(&chan->indio_dev->info_exist_lock);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Jonathan Cameron | 48 | 64.00% | 2 | 66.67% | 
| Lars-Peter Clausen | 27 | 36.00% | 1 | 33.33% | 
| Total | 75 | 100.00% | 3 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_read_channel_raw);
int iio_read_channel_average_raw(struct iio_channel *chan, int *val)
{
	int ret;
	mutex_lock(&chan->indio_dev->info_exist_lock);
	if (chan->indio_dev->info == NULL) {
		ret = -ENODEV;
		goto err_unlock;
	}
	ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_AVERAGE_RAW);
err_unlock:
	mutex_unlock(&chan->indio_dev->info_exist_lock);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Sebastian Reichel | 75 | 100.00% | 1 | 100.00% | 
| Total | 75 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_read_channel_average_raw);
static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
	int raw, int *processed, unsigned int scale)
{
	int scale_type, scale_val, scale_val2, offset;
	s64 raw64 = raw;
	int ret;
	ret = iio_channel_read(chan, &offset, NULL, IIO_CHAN_INFO_OFFSET);
	if (ret >= 0)
		raw64 += offset;
	scale_type = iio_channel_read(chan, &scale_val, &scale_val2,
					IIO_CHAN_INFO_SCALE);
	if (scale_type < 0) {
		/*
                 * Just pass raw values as processed if no scaling is
                 * available.
                 */
		*processed = raw;
		return 0;
	}
	switch (scale_type) {
	case IIO_VAL_INT:
		*processed = raw64 * scale_val;
		break;
	case IIO_VAL_INT_PLUS_MICRO:
		if (scale_val2 < 0)
			*processed = -raw64 * scale_val;
		else
			*processed = raw64 * scale_val;
		*processed += div_s64(raw64 * (s64)scale_val2 * scale,
				      1000000LL);
		break;
	case IIO_VAL_INT_PLUS_NANO:
		if (scale_val2 < 0)
			*processed = -raw64 * scale_val;
		else
			*processed = raw64 * scale_val;
		*processed += div_s64(raw64 * (s64)scale_val2 * scale,
				      1000000000LL);
		break;
	case IIO_VAL_FRACTIONAL:
		*processed = div_s64(raw64 * (s64)scale_val * scale,
				     scale_val2);
		break;
	case IIO_VAL_FRACTIONAL_LOG2:
		*processed = (raw64 * (s64)scale_val * scale) >> scale_val2;
		break;
	default:
		return -EINVAL;
	}
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Lars-Peter Clausen | 236 | 95.55% | 2 | 40.00% | 
| Linus Walleij | 9 | 3.64% | 1 | 20.00% | 
| Michael Hennerich | 1 | 0.40% | 1 | 20.00% | 
| Alexandre Belloni | 1 | 0.40% | 1 | 20.00% | 
| Total | 247 | 100.00% | 5 | 100.00% | 
int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
	int *processed, unsigned int scale)
{
	int ret;
	mutex_lock(&chan->indio_dev->info_exist_lock);
	if (chan->indio_dev->info == NULL) {
		ret = -ENODEV;
		goto err_unlock;
	}
	ret = iio_convert_raw_to_processed_unlocked(chan, raw, processed,
							scale);
err_unlock:
	mutex_unlock(&chan->indio_dev->info_exist_lock);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Lars-Peter Clausen | 76 | 92.68% | 1 | 50.00% | 
| Jonathan Cameron | 6 | 7.32% | 1 | 50.00% | 
| Total | 82 | 100.00% | 2 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_convert_raw_to_processed);
static int iio_read_channel_attribute(struct iio_channel *chan,
				      int *val, int *val2,
				      enum iio_chan_info_enum attribute)
{
	int ret;
	mutex_lock(&chan->indio_dev->info_exist_lock);
	if (chan->indio_dev->info == NULL) {
		ret = -ENODEV;
		goto err_unlock;
	}
	ret = iio_channel_read(chan, val, val2, attribute);
err_unlock:
	mutex_unlock(&chan->indio_dev->info_exist_lock);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Matthew Ranostay | 84 | 100.00% | 1 | 100.00% | 
| Total | 84 | 100.00% | 1 | 100.00% | 
int iio_read_channel_offset(struct iio_channel *chan, int *val, int *val2)
{
	return iio_read_channel_attribute(chan, val, val2, IIO_CHAN_INFO_OFFSET);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Matthew Ranostay | 30 | 100.00% | 1 | 100.00% | 
| Total | 30 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_read_channel_offset);
int iio_read_channel_processed(struct iio_channel *chan, int *val)
{
	int ret;
	mutex_lock(&chan->indio_dev->info_exist_lock);
	if (chan->indio_dev->info == NULL) {
		ret = -ENODEV;
		goto err_unlock;
	}
	if (iio_channel_has_info(chan->channel, IIO_CHAN_INFO_PROCESSED)) {
		ret = iio_channel_read(chan, val, NULL,
				       IIO_CHAN_INFO_PROCESSED);
	} else {
		ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_RAW);
		if (ret < 0)
			goto err_unlock;
		ret = iio_convert_raw_to_processed_unlocked(chan, *val, val, 1);
	}
err_unlock:
	mutex_unlock(&chan->indio_dev->info_exist_lock);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Lars-Peter Clausen | 98 | 77.17% | 1 | 33.33% | 
| Jonathan Cameron | 28 | 22.05% | 1 | 33.33% | 
| Kim (Woogyom) Milo | 1 | 0.79% | 1 | 33.33% | 
| Total | 127 | 100.00% | 3 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_read_channel_processed);
int iio_read_channel_scale(struct iio_channel *chan, int *val, int *val2)
{
	return iio_read_channel_attribute(chan, val, val2, IIO_CHAN_INFO_SCALE);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Jonathan Cameron | 28 | 93.33% | 2 | 66.67% | 
| Matthew Ranostay | 2 | 6.67% | 1 | 33.33% | 
| Total | 30 | 100.00% | 3 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_read_channel_scale);
static int iio_channel_read_avail(struct iio_channel *chan,
				  const int **vals, int *type, int *length,
				  enum iio_chan_info_enum info)
{
	if (!iio_channel_has_available(chan->channel, info))
		return -EINVAL;
	return chan->indio_dev->info->read_avail(chan->indio_dev, chan->channel,
						 vals, type, length, info);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Peter Rosin | 71 | 100.00% | 1 | 100.00% | 
| Total | 71 | 100.00% | 1 | 100.00% | 
int iio_read_avail_channel_raw(struct iio_channel *chan,
			       const int **vals, int *length)
{
	int ret;
	int type;
	mutex_lock(&chan->indio_dev->info_exist_lock);
	if (!chan->indio_dev->info) {
		ret = -ENODEV;
		goto err_unlock;
	}
	ret = iio_channel_read_avail(chan,
				     vals, &type, length, IIO_CHAN_INFO_RAW);
err_unlock:
	mutex_unlock(&chan->indio_dev->info_exist_lock);
	if (ret >= 0 && type != IIO_VAL_INT) {
		/* raw values are assumed to be IIO_VAL_INT */
		ret = -EINVAL;
		goto err_unlock;
	}
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Peter Rosin | 107 | 100.00% | 1 | 100.00% | 
| Total | 107 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_read_avail_channel_raw);
static int iio_channel_read_max(struct iio_channel *chan,
				int *val, int *val2, int *type,
				enum iio_chan_info_enum info)
{
	int unused;
	const int *vals;
	int length;
	int ret;
	if (!val2)
		val2 = &unused;
	ret = iio_channel_read_avail(chan, &vals, type, &length, info);
	switch (ret) {
	case IIO_AVAIL_RANGE:
		switch (*type) {
		case IIO_VAL_INT:
			*val = vals[2];
			break;
		default:
			*val = vals[4];
			*val2 = vals[5];
		}
		return 0;
	case IIO_AVAIL_LIST:
		if (length <= 0)
			return -EINVAL;
		switch (*type) {
		case IIO_VAL_INT:
			*val = vals[--length];
			while (length) {
				if (vals[--length] > *val)
					*val = vals[length];
			}
			break;
		default:
			/* FIXME: learn about max for other iio values */
			return -EINVAL;
		}
		return 0;
	default:
		return ret;
	}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Peter Rosin | 187 | 100.00% | 1 | 100.00% | 
| Total | 187 | 100.00% | 1 | 100.00% | 
int iio_read_max_channel_raw(struct iio_channel *chan, int *val)
{
	int ret;
	int type;
	mutex_lock(&chan->indio_dev->info_exist_lock);
	if (!chan->indio_dev->info) {
		ret = -ENODEV;
		goto err_unlock;
	}
	ret = iio_channel_read_max(chan, val, NULL, &type, IIO_CHAN_INFO_RAW);
err_unlock:
	mutex_unlock(&chan->indio_dev->info_exist_lock);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Peter Rosin | 80 | 100.00% | 1 | 100.00% | 
| Total | 80 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_read_max_channel_raw);
int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type)
{
	int ret = 0;
	/* Need to verify underlying driver has not gone away */
	mutex_lock(&chan->indio_dev->info_exist_lock);
	if (chan->indio_dev->info == NULL) {
		ret = -ENODEV;
		goto err_unlock;
	}
	*type = chan->channel->type;
err_unlock:
	mutex_unlock(&chan->indio_dev->info_exist_lock);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Jonathan Cameron | 75 | 100.00% | 2 | 100.00% | 
| Total | 75 | 100.00% | 2 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_get_channel_type);
static int iio_channel_write(struct iio_channel *chan, int val, int val2,
			     enum iio_chan_info_enum info)
{
	return chan->indio_dev->info->write_raw(chan->indio_dev,
						chan->channel, val, val2, info);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Dmitry Baryshkov | 45 | 100.00% | 1 | 100.00% | 
| Total | 45 | 100.00% | 1 | 100.00% | 
int iio_write_channel_raw(struct iio_channel *chan, int val)
{
	int ret;
	mutex_lock(&chan->indio_dev->info_exist_lock);
	if (chan->indio_dev->info == NULL) {
		ret = -ENODEV;
		goto err_unlock;
	}
	ret = iio_channel_write(chan, val, 0, IIO_CHAN_INFO_RAW);
err_unlock:
	mutex_unlock(&chan->indio_dev->info_exist_lock);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Dmitry Baryshkov | 74 | 100.00% | 1 | 100.00% | 
| Total | 74 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(iio_write_channel_raw);
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Jonathan Cameron | 988 | 25.76% | 4 | 12.12% | 
| Guenter Roeck | 916 | 23.89% | 4 | 12.12% | 
| Lars-Peter Clausen | 511 | 13.32% | 3 | 9.09% | 
| Peter Rosin | 455 | 11.86% | 1 | 3.03% | 
| Laxman Dewangan | 384 | 10.01% | 2 | 6.06% | 
| Dmitry Baryshkov | 124 | 3.23% | 1 | 3.03% | 
| Matthew Ranostay | 121 | 3.16% | 1 | 3.03% | 
| Ivan T. Ivanov | 84 | 2.19% | 1 | 3.03% | 
| Sebastian Reichel | 80 | 2.09% | 1 | 3.03% | 
| Srinivas Pandruvada | 76 | 1.98% | 1 | 3.03% | 
| Kim (Woogyom) Milo | 20 | 0.52% | 4 | 12.12% | 
| Stefan Wahren | 19 | 0.50% | 1 | 3.03% | 
| Fabien Proriol | 16 | 0.42% | 1 | 3.03% | 
| Dan Carpenter | 12 | 0.31% | 2 | 6.06% | 
| Linus Walleij | 9 | 0.23% | 1 | 3.03% | 
| Johannes Pointner | 8 | 0.21% | 1 | 3.03% | 
| Anshul Garg | 6 | 0.16% | 1 | 3.03% | 
| Adam Thomson | 4 | 0.10% | 1 | 3.03% | 
| Michael Hennerich | 1 | 0.03% | 1 | 3.03% | 
| Alexandre Belloni | 1 | 0.03% | 1 | 3.03% | 
| Total | 3835 | 100.00% | 33 | 100.00% | 
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.