2012-02-16 03:48:01 +08:00
|
|
|
/*
|
|
|
|
* Industrial I/O in kernel consumer interface
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
#ifndef _IIO_INKERN_CONSUMER_H_
|
2012-08-17 23:57:00 +08:00
|
|
|
#define _IIO_INKERN_CONSUMER_H_
|
2012-04-25 22:54:58 +08:00
|
|
|
#include <linux/iio/types.h>
|
2012-02-16 03:48:01 +08:00
|
|
|
|
|
|
|
struct iio_dev;
|
|
|
|
struct iio_chan_spec;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct iio_channel - everything needed for a consumer to use a channel
|
|
|
|
* @indio_dev: Device on which the channel exists.
|
|
|
|
* @channel: Full description of the channel.
|
2012-07-01 03:06:00 +08:00
|
|
|
* @data: Data about the channel used by consumer.
|
2012-02-16 03:48:01 +08:00
|
|
|
*/
|
|
|
|
struct iio_channel {
|
|
|
|
struct iio_dev *indio_dev;
|
|
|
|
const struct iio_chan_spec *channel;
|
2012-07-01 03:06:00 +08:00
|
|
|
void *data;
|
2012-02-16 03:48:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* iio_channel_get() - get description of all that is needed to access channel.
|
|
|
|
* @name: Unique name of the device as provided in the iio_map
|
|
|
|
* with which the desired provider to consumer mapping
|
|
|
|
* was registered.
|
|
|
|
* @consumer_channel: Unique name to identify the channel on the consumer
|
|
|
|
* side. This typically describes the channels use within
|
|
|
|
* the consumer. E.g. 'battery_voltage'
|
|
|
|
*/
|
2012-05-02 04:04:24 +08:00
|
|
|
struct iio_channel *iio_channel_get(const char *name,
|
|
|
|
const char *consumer_channel);
|
2012-02-16 03:48:01 +08:00
|
|
|
|
|
|
|
/**
|
2012-05-02 04:04:24 +08:00
|
|
|
* iio_channel_release() - release channels obtained via iio_channel_get
|
2012-02-16 03:48:01 +08:00
|
|
|
* @chan: The channel to be released.
|
|
|
|
*/
|
2012-05-02 04:04:24 +08:00
|
|
|
void iio_channel_release(struct iio_channel *chan);
|
2012-02-16 03:48:01 +08:00
|
|
|
|
|
|
|
/**
|
2012-05-02 04:04:24 +08:00
|
|
|
* iio_channel_get_all() - get all channels associated with a client
|
2012-02-16 03:48:01 +08:00
|
|
|
* @name: name of consumer device.
|
|
|
|
*
|
|
|
|
* Returns an array of iio_channel structures terminated with one with
|
|
|
|
* null iio_dev pointer.
|
|
|
|
* This function is used by fairly generic consumers to get all the
|
|
|
|
* channels registered as having this consumer.
|
|
|
|
*/
|
2012-05-02 04:04:24 +08:00
|
|
|
struct iio_channel *iio_channel_get_all(const char *name);
|
2012-02-16 03:48:01 +08:00
|
|
|
|
|
|
|
/**
|
2012-05-02 04:04:24 +08:00
|
|
|
* iio_channel_release_all() - reverse iio_channel_get_all
|
2012-02-16 03:48:01 +08:00
|
|
|
* @chan: Array of channels to be released.
|
|
|
|
*/
|
2012-05-02 04:04:24 +08:00
|
|
|
void iio_channel_release_all(struct iio_channel *chan);
|
2012-02-16 03:48:01 +08:00
|
|
|
|
|
|
|
/**
|
2012-05-02 04:04:24 +08:00
|
|
|
* iio_read_channel_raw() - read from a given channel
|
2012-09-17 20:17:00 +08:00
|
|
|
* @chan: The channel being queried.
|
2012-02-16 03:48:01 +08:00
|
|
|
* @val: Value read back.
|
|
|
|
*
|
|
|
|
* Note raw reads from iio channels are in adc counts and hence
|
|
|
|
* scale will need to be applied if standard units required.
|
|
|
|
*/
|
2012-05-02 04:04:24 +08:00
|
|
|
int iio_read_channel_raw(struct iio_channel *chan,
|
|
|
|
int *val);
|
2012-02-16 03:48:01 +08:00
|
|
|
|
2012-09-17 20:17:00 +08:00
|
|
|
/**
|
|
|
|
* iio_read_channel_processed() - read processed value from a given channel
|
|
|
|
* @chan: The channel being queried.
|
|
|
|
* @val: Value read back.
|
|
|
|
*
|
|
|
|
* Returns an error code or 0.
|
|
|
|
*
|
|
|
|
* This function will read a processed value from a channel. A processed value
|
|
|
|
* means that this value will have the correct unit and not some device internal
|
|
|
|
* representation. If the device does not support reporting a processed value
|
|
|
|
* the function will query the raw value and the channels scale and offset and
|
|
|
|
* do the appropriate transformation.
|
|
|
|
*/
|
|
|
|
int iio_read_channel_processed(struct iio_channel *chan, int *val);
|
|
|
|
|
2012-02-16 03:48:01 +08:00
|
|
|
/**
|
2012-05-02 04:04:24 +08:00
|
|
|
* iio_get_channel_type() - get the type of a channel
|
2012-02-16 03:48:01 +08:00
|
|
|
* @channel: The channel being queried.
|
|
|
|
* @type: The type of the channel.
|
|
|
|
*
|
|
|
|
* returns the enum iio_chan_type of the channel
|
|
|
|
*/
|
2012-05-02 04:04:24 +08:00
|
|
|
int iio_get_channel_type(struct iio_channel *channel,
|
|
|
|
enum iio_chan_type *type);
|
2012-02-16 03:48:01 +08:00
|
|
|
|
|
|
|
/**
|
2012-05-02 04:04:24 +08:00
|
|
|
* iio_read_channel_scale() - read the scale value for a channel
|
2012-09-17 20:17:00 +08:00
|
|
|
* @chan: The channel being queried.
|
2012-02-16 03:48:01 +08:00
|
|
|
* @val: First part of value read back.
|
|
|
|
* @val2: Second part of value read back.
|
|
|
|
*
|
|
|
|
* Note returns a description of what is in val and val2, such
|
|
|
|
* as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val
|
|
|
|
* + val2/1e6
|
|
|
|
*/
|
2012-05-02 04:04:24 +08:00
|
|
|
int iio_read_channel_scale(struct iio_channel *chan, int *val,
|
|
|
|
int *val2);
|
2012-02-16 03:48:01 +08:00
|
|
|
|
2012-09-17 20:17:00 +08:00
|
|
|
/**
|
|
|
|
* iio_convert_raw_to_processed() - Converts a raw value to a processed value
|
|
|
|
* @chan: The channel being queried
|
|
|
|
* @raw: The raw IIO to convert
|
|
|
|
* @processed: The result of the conversion
|
|
|
|
* @scale: Scale factor to apply during the conversion
|
|
|
|
*
|
|
|
|
* Returns an error code or 0.
|
|
|
|
*
|
|
|
|
* This function converts a raw value to processed value for a specific channel.
|
|
|
|
* A raw value is the device internal representation of a sample and the value
|
|
|
|
* returned by iio_read_channel_raw, so the unit of that value is device
|
|
|
|
* depended. A processed value on the other hand is value has a normed unit
|
|
|
|
* according with the IIO specification.
|
|
|
|
*
|
|
|
|
* The scale factor allows to increase the precession of the returned value. For
|
|
|
|
* a scale factor of 1 the function will return the result in the normal IIO
|
|
|
|
* unit for the channel type. E.g. millivolt for voltage channels, if you want
|
|
|
|
* nanovolts instead pass 1000 as the scale factor.
|
|
|
|
*/
|
|
|
|
int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
|
|
|
|
int *processed, unsigned int scale);
|
|
|
|
|
2012-02-16 03:48:01 +08:00
|
|
|
#endif
|