2010-10-01 08:41:51 -06:00
|
|
|
/*
|
|
|
|
* iio/adc/ad799x.c
|
2011-05-18 07:41:52 -06:00
|
|
|
* Copyright (C) 2010-1011 Michael Hennerich, Analog Devices Inc.
|
2010-10-01 08:41:51 -06:00
|
|
|
*
|
|
|
|
* based on iio/adc/max1363
|
|
|
|
* Copyright (C) 2008-2010 Jonathan Cameron
|
|
|
|
*
|
|
|
|
* based on linux/drivers/i2c/chips/max123x
|
|
|
|
* Copyright (C) 2002-2004 Stefan Eletzhofer
|
|
|
|
*
|
|
|
|
* based on linux/drivers/acron/char/pcf8583.c
|
|
|
|
* Copyright (C) 2000 Russell King
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* ad799x.c
|
|
|
|
*
|
|
|
|
* Support for ad7991, ad7995, ad7999, ad7992, ad7993, ad7994, ad7997,
|
|
|
|
* ad7998 and similar chips.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sysfs.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/regulator/consumer.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/err.h>
|
2011-07-03 13:49:50 -06:00
|
|
|
#include <linux/module.h>
|
2010-10-01 08:41:51 -06:00
|
|
|
|
2012-04-25 08:54:58 -06:00
|
|
|
#include <linux/iio/iio.h>
|
|
|
|
#include <linux/iio/sysfs.h>
|
|
|
|
#include <linux/iio/events.h>
|
|
|
|
#include <linux/iio/buffer.h>
|
2011-08-12 10:08:43 -06:00
|
|
|
|
2010-10-01 08:41:51 -06:00
|
|
|
#include "ad799x.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ad799x register access by I2C
|
|
|
|
*/
|
|
|
|
static int ad799x_i2c_read16(struct ad799x_state *st, u8 reg, u16 *data)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = st->client;
|
|
|
|
int ret = 0;
|
|
|
|
|
2013-03-26 12:43:00 -06:00
|
|
|
ret = i2c_smbus_read_word_swapped(client, reg);
|
2010-10-01 08:41:51 -06:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "I2C read error\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-26 12:43:00 -06:00
|
|
|
*data = (u16)ret;
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ad799x_i2c_read8(struct ad799x_state *st, u8 reg, u8 *data)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = st->client;
|
|
|
|
int ret = 0;
|
|
|
|
|
2010-10-06 02:25:49 -06:00
|
|
|
ret = i2c_smbus_read_byte_data(client, reg);
|
2010-10-01 08:41:51 -06:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "I2C read error\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-10-06 02:25:49 -06:00
|
|
|
*data = (u8)ret;
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ad799x_i2c_write16(struct ad799x_state *st, u8 reg, u16 data)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = st->client;
|
|
|
|
int ret = 0;
|
|
|
|
|
2013-03-26 12:43:00 -06:00
|
|
|
ret = i2c_smbus_write_word_swapped(client, reg, data);
|
2010-10-01 08:41:51 -06:00
|
|
|
if (ret < 0)
|
|
|
|
dev_err(&client->dev, "I2C write error\n");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ad799x_i2c_write8(struct ad799x_state *st, u8 reg, u8 data)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = st->client;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ret = i2c_smbus_write_byte_data(client, reg, data);
|
|
|
|
if (ret < 0)
|
|
|
|
dev_err(&client->dev, "I2C write error\n");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-18 10:33:56 -06:00
|
|
|
static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
|
|
|
|
const unsigned long *scan_mask)
|
2010-10-01 08:41:51 -06:00
|
|
|
{
|
2012-06-18 10:33:56 -06:00
|
|
|
struct ad799x_state *st = iio_priv(indio_dev);
|
|
|
|
|
|
|
|
switch (st->id) {
|
|
|
|
case ad7997:
|
|
|
|
case ad7998:
|
|
|
|
return ad799x_i2c_write16(st, AD7998_CONF_REG,
|
|
|
|
st->config | (*scan_mask << AD799X_CHANNEL_SHIFT));
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2010-10-01 08:41:51 -06:00
|
|
|
}
|
|
|
|
|
2011-05-18 07:41:52 -06:00
|
|
|
static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch)
|
2010-10-01 08:41:51 -06:00
|
|
|
{
|
2011-05-18 07:41:52 -06:00
|
|
|
u16 rxbuf;
|
|
|
|
u8 cmd;
|
2010-10-01 08:41:51 -06:00
|
|
|
int ret;
|
|
|
|
|
2011-05-18 07:41:52 -06:00
|
|
|
switch (st->id) {
|
|
|
|
case ad7991:
|
|
|
|
case ad7995:
|
|
|
|
case ad7999:
|
|
|
|
cmd = st->config | ((1 << ch) << AD799X_CHANNEL_SHIFT);
|
|
|
|
break;
|
|
|
|
case ad7992:
|
|
|
|
case ad7993:
|
|
|
|
case ad7994:
|
|
|
|
cmd = (1 << ch) << AD799X_CHANNEL_SHIFT;
|
|
|
|
break;
|
|
|
|
case ad7997:
|
|
|
|
case ad7998:
|
|
|
|
cmd = (ch << AD799X_CHANNEL_SHIFT) | AD7997_8_READ_SINGLE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2010-10-01 08:41:51 -06:00
|
|
|
}
|
|
|
|
|
2011-05-18 07:41:52 -06:00
|
|
|
ret = ad799x_i2c_read16(st, cmd, &rxbuf);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return rxbuf;
|
2010-10-01 08:41:51 -06:00
|
|
|
}
|
|
|
|
|
2011-10-06 10:14:37 -06:00
|
|
|
static int ad799x_read_raw(struct iio_dev *indio_dev,
|
2011-05-18 07:41:52 -06:00
|
|
|
struct iio_chan_spec const *chan,
|
|
|
|
int *val,
|
|
|
|
int *val2,
|
|
|
|
long m)
|
2010-10-01 08:41:51 -06:00
|
|
|
{
|
2011-05-18 07:41:52 -06:00
|
|
|
int ret;
|
2011-10-06 10:14:37 -06:00
|
|
|
struct ad799x_state *st = iio_priv(indio_dev);
|
2011-05-18 07:41:52 -06:00
|
|
|
unsigned int scale_uv;
|
|
|
|
|
|
|
|
switch (m) {
|
2012-04-15 10:41:18 -06:00
|
|
|
case IIO_CHAN_INFO_RAW:
|
2011-10-06 10:14:37 -06:00
|
|
|
mutex_lock(&indio_dev->mlock);
|
|
|
|
if (iio_buffer_enabled(indio_dev))
|
2011-12-05 15:18:24 -07:00
|
|
|
ret = -EBUSY;
|
2011-05-18 07:41:52 -06:00
|
|
|
else
|
2011-09-30 03:05:37 -06:00
|
|
|
ret = ad799x_scan_direct(st, chan->scan_index);
|
2011-10-06 10:14:37 -06:00
|
|
|
mutex_unlock(&indio_dev->mlock);
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
if (ret < 0)
|
2011-05-18 07:41:52 -06:00
|
|
|
return ret;
|
2011-09-30 03:05:32 -06:00
|
|
|
*val = (ret >> chan->scan_type.shift) &
|
|
|
|
RES_MASK(chan->scan_type.realbits);
|
2011-05-18 07:41:52 -06:00
|
|
|
return IIO_VAL_INT;
|
2011-10-26 10:41:36 -06:00
|
|
|
case IIO_CHAN_INFO_SCALE:
|
2011-09-30 03:05:32 -06:00
|
|
|
scale_uv = (st->int_vref_mv * 1000) >> chan->scan_type.realbits;
|
2011-05-18 07:41:52 -06:00
|
|
|
*val = scale_uv / 1000;
|
|
|
|
*val2 = (scale_uv % 1000) * 1000;
|
|
|
|
return IIO_VAL_INT_PLUS_MICRO;
|
2010-10-01 08:41:51 -06:00
|
|
|
}
|
2011-05-18 07:41:52 -06:00
|
|
|
return -EINVAL;
|
2010-10-01 08:41:51 -06:00
|
|
|
}
|
2011-09-30 03:05:33 -06:00
|
|
|
static const unsigned int ad7998_frequencies[] = {
|
|
|
|
[AD7998_CYC_DIS] = 0,
|
|
|
|
[AD7998_CYC_TCONF_32] = 15625,
|
|
|
|
[AD7998_CYC_TCONF_64] = 7812,
|
|
|
|
[AD7998_CYC_TCONF_128] = 3906,
|
|
|
|
[AD7998_CYC_TCONF_512] = 976,
|
|
|
|
[AD7998_CYC_TCONF_1024] = 488,
|
|
|
|
[AD7998_CYC_TCONF_2048] = 244,
|
|
|
|
};
|
2010-10-01 08:41:51 -06:00
|
|
|
static ssize_t ad799x_read_frequency(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
2012-05-12 07:39:42 -06:00
|
|
|
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
|
2011-10-06 10:14:37 -06:00
|
|
|
struct ad799x_state *st = iio_priv(indio_dev);
|
2010-10-01 08:41:51 -06:00
|
|
|
|
2011-09-30 03:05:33 -06:00
|
|
|
int ret;
|
2010-10-01 08:41:51 -06:00
|
|
|
u8 val;
|
|
|
|
ret = ad799x_i2c_read8(st, AD7998_CYCLE_TMR_REG, &val);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
val &= AD7998_CYC_MASK;
|
|
|
|
|
2011-09-30 03:05:33 -06:00
|
|
|
return sprintf(buf, "%u\n", ad7998_frequencies[val]);
|
2010-10-01 08:41:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ad799x_write_frequency(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf,
|
|
|
|
size_t len)
|
|
|
|
{
|
2012-05-12 07:39:42 -06:00
|
|
|
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
|
2011-10-06 10:14:37 -06:00
|
|
|
struct ad799x_state *st = iio_priv(indio_dev);
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
long val;
|
2011-09-30 03:05:33 -06:00
|
|
|
int ret, i;
|
2010-10-01 08:41:51 -06:00
|
|
|
u8 t;
|
|
|
|
|
|
|
|
ret = strict_strtol(buf, 10, &val);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2011-10-06 10:14:37 -06:00
|
|
|
mutex_lock(&indio_dev->mlock);
|
2010-10-01 08:41:51 -06:00
|
|
|
ret = ad799x_i2c_read8(st, AD7998_CYCLE_TMR_REG, &t);
|
|
|
|
if (ret)
|
|
|
|
goto error_ret_mutex;
|
|
|
|
/* Wipe the bits clean */
|
|
|
|
t &= ~AD7998_CYC_MASK;
|
|
|
|
|
2011-09-30 03:05:33 -06:00
|
|
|
for (i = 0; i < ARRAY_SIZE(ad7998_frequencies); i++)
|
|
|
|
if (val == ad7998_frequencies[i])
|
|
|
|
break;
|
|
|
|
if (i == ARRAY_SIZE(ad7998_frequencies)) {
|
2010-10-01 08:41:51 -06:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto error_ret_mutex;
|
|
|
|
}
|
2011-09-30 03:05:33 -06:00
|
|
|
t |= i;
|
2010-10-01 08:41:51 -06:00
|
|
|
ret = ad799x_i2c_write8(st, AD7998_CYCLE_TMR_REG, t);
|
|
|
|
|
|
|
|
error_ret_mutex:
|
2011-10-06 10:14:37 -06:00
|
|
|
mutex_unlock(&indio_dev->mlock);
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
return ret ? ret : len;
|
|
|
|
}
|
|
|
|
|
2011-10-06 10:14:37 -06:00
|
|
|
static int ad799x_read_event_config(struct iio_dev *indio_dev,
|
2011-09-30 03:05:35 -06:00
|
|
|
u64 event_code)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const u8 ad799x_threshold_addresses[][2] = {
|
|
|
|
{ AD7998_DATALOW_CH1_REG, AD7998_DATAHIGH_CH1_REG },
|
|
|
|
{ AD7998_DATALOW_CH2_REG, AD7998_DATAHIGH_CH2_REG },
|
|
|
|
{ AD7998_DATALOW_CH3_REG, AD7998_DATAHIGH_CH3_REG },
|
|
|
|
{ AD7998_DATALOW_CH4_REG, AD7998_DATAHIGH_CH4_REG },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ad799x_write_event_value(struct iio_dev *indio_dev,
|
|
|
|
u64 event_code,
|
|
|
|
int val)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct ad799x_state *st = iio_priv(indio_dev);
|
|
|
|
int direction = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
|
|
|
|
IIO_EV_DIR_FALLING);
|
2012-02-13 02:25:32 -07:00
|
|
|
int number = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
|
2011-09-30 03:05:35 -06:00
|
|
|
|
|
|
|
mutex_lock(&indio_dev->mlock);
|
|
|
|
ret = ad799x_i2c_write16(st,
|
|
|
|
ad799x_threshold_addresses[number][direction],
|
|
|
|
val);
|
|
|
|
mutex_unlock(&indio_dev->mlock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ad799x_read_event_value(struct iio_dev *indio_dev,
|
|
|
|
u64 event_code,
|
|
|
|
int *val)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct ad799x_state *st = iio_priv(indio_dev);
|
|
|
|
int direction = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
|
|
|
|
IIO_EV_DIR_FALLING);
|
2012-02-13 02:25:32 -07:00
|
|
|
int number = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
|
2011-09-30 03:05:35 -06:00
|
|
|
u16 valin;
|
|
|
|
|
|
|
|
mutex_lock(&indio_dev->mlock);
|
|
|
|
ret = ad799x_i2c_read16(st,
|
|
|
|
ad799x_threshold_addresses[number][direction],
|
|
|
|
&valin);
|
|
|
|
mutex_unlock(&indio_dev->mlock);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
*val = valin;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-01 08:41:51 -06:00
|
|
|
static ssize_t ad799x_read_channel_config(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
2012-05-12 07:39:42 -06:00
|
|
|
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
|
2011-10-06 10:14:37 -06:00
|
|
|
struct ad799x_state *st = iio_priv(indio_dev);
|
2011-05-18 07:41:15 -06:00
|
|
|
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
int ret;
|
|
|
|
u16 val;
|
2011-05-18 07:41:15 -06:00
|
|
|
ret = ad799x_i2c_read16(st, this_attr->address, &val);
|
2010-10-01 08:41:51 -06:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return sprintf(buf, "%d\n", val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ad799x_write_channel_config(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf,
|
|
|
|
size_t len)
|
|
|
|
{
|
2012-05-12 07:39:42 -06:00
|
|
|
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
|
2011-10-06 10:14:37 -06:00
|
|
|
struct ad799x_state *st = iio_priv(indio_dev);
|
2011-05-18 07:41:15 -06:00
|
|
|
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
long val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = strict_strtol(buf, 10, &val);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2011-10-06 10:14:37 -06:00
|
|
|
mutex_lock(&indio_dev->mlock);
|
2011-05-18 07:41:15 -06:00
|
|
|
ret = ad799x_i2c_write16(st, this_attr->address, val);
|
2011-10-06 10:14:37 -06:00
|
|
|
mutex_unlock(&indio_dev->mlock);
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
return ret ? ret : len;
|
|
|
|
}
|
|
|
|
|
2011-05-18 07:41:15 -06:00
|
|
|
static irqreturn_t ad799x_event_handler(int irq, void *private)
|
2010-10-01 08:41:51 -06:00
|
|
|
{
|
2011-05-18 07:41:15 -06:00
|
|
|
struct iio_dev *indio_dev = private;
|
2011-06-27 06:07:20 -06:00
|
|
|
struct ad799x_state *st = iio_priv(private);
|
2010-10-01 08:41:51 -06:00
|
|
|
u8 status;
|
2011-05-18 07:41:15 -06:00
|
|
|
int i, ret;
|
2010-10-01 08:41:51 -06:00
|
|
|
|
2011-05-18 07:41:15 -06:00
|
|
|
ret = ad799x_i2c_read8(st, AD7998_ALERT_STAT_REG, &status);
|
|
|
|
if (ret)
|
2012-07-04 10:09:00 -06:00
|
|
|
goto done;
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
if (!status)
|
2012-07-04 10:09:00 -06:00
|
|
|
goto done;
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
ad799x_i2c_write8(st, AD7998_ALERT_STAT_REG, AD7998_ALERT_STAT_CLEAR);
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (status & (1 << i))
|
2011-08-30 05:41:06 -06:00
|
|
|
iio_push_event(indio_dev,
|
2011-05-18 07:41:15 -06:00
|
|
|
i & 0x1 ?
|
2011-09-27 02:56:41 -06:00
|
|
|
IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
|
2011-08-12 10:08:43 -06:00
|
|
|
(i >> 1),
|
|
|
|
IIO_EV_TYPE_THRESH,
|
|
|
|
IIO_EV_DIR_RISING) :
|
2011-09-27 02:56:41 -06:00
|
|
|
IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
|
2011-08-12 10:08:43 -06:00
|
|
|
(i >> 1),
|
|
|
|
IIO_EV_TYPE_THRESH,
|
|
|
|
IIO_EV_DIR_FALLING),
|
2011-05-18 07:41:15 -06:00
|
|
|
iio_get_time_ns());
|
2010-10-01 08:41:51 -06:00
|
|
|
}
|
|
|
|
|
2012-07-04 10:09:00 -06:00
|
|
|
done:
|
2011-05-18 07:41:15 -06:00
|
|
|
return IRQ_HANDLED;
|
2010-10-01 08:41:51 -06:00
|
|
|
}
|
|
|
|
|
2011-09-14 06:01:23 -06:00
|
|
|
static IIO_DEVICE_ATTR(in_voltage0_thresh_both_hyst_raw,
|
2011-05-18 07:41:15 -06:00
|
|
|
S_IRUGO | S_IWUSR,
|
|
|
|
ad799x_read_channel_config,
|
|
|
|
ad799x_write_channel_config,
|
|
|
|
AD7998_HYST_CH1_REG);
|
|
|
|
|
2011-09-14 06:01:23 -06:00
|
|
|
static IIO_DEVICE_ATTR(in_voltage1_thresh_both_hyst_raw,
|
2011-05-18 07:41:15 -06:00
|
|
|
S_IRUGO | S_IWUSR,
|
|
|
|
ad799x_read_channel_config,
|
|
|
|
ad799x_write_channel_config,
|
|
|
|
AD7998_HYST_CH2_REG);
|
|
|
|
|
2011-09-14 06:01:23 -06:00
|
|
|
static IIO_DEVICE_ATTR(in_voltage2_thresh_both_hyst_raw,
|
2011-05-18 07:41:15 -06:00
|
|
|
S_IRUGO | S_IWUSR,
|
|
|
|
ad799x_read_channel_config,
|
|
|
|
ad799x_write_channel_config,
|
|
|
|
AD7998_HYST_CH3_REG);
|
|
|
|
|
2011-09-14 06:01:23 -06:00
|
|
|
static IIO_DEVICE_ATTR(in_voltage3_thresh_both_hyst_raw,
|
2011-05-18 07:41:15 -06:00
|
|
|
S_IRUGO | S_IWUSR,
|
|
|
|
ad799x_read_channel_config,
|
|
|
|
ad799x_write_channel_config,
|
|
|
|
AD7998_HYST_CH4_REG);
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
|
|
|
|
ad799x_read_frequency,
|
|
|
|
ad799x_write_frequency);
|
|
|
|
static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("15625 7812 3906 1953 976 488 244 0");
|
|
|
|
|
|
|
|
static struct attribute *ad7993_4_7_8_event_attributes[] = {
|
2011-09-14 06:01:23 -06:00
|
|
|
&iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr,
|
|
|
|
&iio_dev_attr_in_voltage1_thresh_both_hyst_raw.dev_attr.attr,
|
|
|
|
&iio_dev_attr_in_voltage2_thresh_both_hyst_raw.dev_attr.attr,
|
|
|
|
&iio_dev_attr_in_voltage3_thresh_both_hyst_raw.dev_attr.attr,
|
2010-10-01 08:41:51 -06:00
|
|
|
&iio_dev_attr_sampling_frequency.dev_attr.attr,
|
|
|
|
&iio_const_attr_sampling_frequency_available.dev_attr.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group ad7993_4_7_8_event_attrs_group = {
|
|
|
|
.attrs = ad7993_4_7_8_event_attributes,
|
2011-08-30 05:32:45 -06:00
|
|
|
.name = "events",
|
2010-10-01 08:41:51 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute *ad7992_event_attributes[] = {
|
2011-09-14 06:01:23 -06:00
|
|
|
&iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr,
|
|
|
|
&iio_dev_attr_in_voltage1_thresh_both_hyst_raw.dev_attr.attr,
|
2010-10-01 08:41:51 -06:00
|
|
|
&iio_dev_attr_sampling_frequency.dev_attr.attr,
|
|
|
|
&iio_const_attr_sampling_frequency_available.dev_attr.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group ad7992_event_attrs_group = {
|
|
|
|
.attrs = ad7992_event_attributes,
|
2011-08-30 05:32:45 -06:00
|
|
|
.name = "events",
|
2010-10-01 08:41:51 -06:00
|
|
|
};
|
|
|
|
|
2011-05-18 07:42:37 -06:00
|
|
|
static const struct iio_info ad7991_info = {
|
|
|
|
.read_raw = &ad799x_read_raw,
|
|
|
|
.driver_module = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct iio_info ad7992_info = {
|
|
|
|
.read_raw = &ad799x_read_raw,
|
|
|
|
.event_attrs = &ad7992_event_attrs_group,
|
2011-09-30 03:05:35 -06:00
|
|
|
.read_event_config = &ad799x_read_event_config,
|
|
|
|
.read_event_value = &ad799x_read_event_value,
|
|
|
|
.write_event_value = &ad799x_write_event_value,
|
2011-05-18 07:42:37 -06:00
|
|
|
.driver_module = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct iio_info ad7993_4_7_8_info = {
|
|
|
|
.read_raw = &ad799x_read_raw,
|
|
|
|
.event_attrs = &ad7993_4_7_8_event_attrs_group,
|
2011-09-30 03:05:35 -06:00
|
|
|
.read_event_config = &ad799x_read_event_config,
|
|
|
|
.read_event_value = &ad799x_read_event_value,
|
|
|
|
.write_event_value = &ad799x_write_event_value,
|
2011-05-18 07:42:37 -06:00
|
|
|
.driver_module = THIS_MODULE,
|
2012-06-18 10:33:56 -06:00
|
|
|
.update_scan_mode = ad7997_8_update_scan_mode,
|
2011-05-18 07:42:37 -06:00
|
|
|
};
|
|
|
|
|
2011-09-30 03:05:35 -06:00
|
|
|
#define AD799X_EV_MASK (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | \
|
|
|
|
IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING))
|
|
|
|
|
2010-10-01 08:41:51 -06:00
|
|
|
static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
|
|
|
|
[ad7991] = {
|
2011-09-30 03:05:31 -06:00
|
|
|
.channel = {
|
|
|
|
[0] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 0,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 0,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
|
|
|
},
|
|
|
|
[1] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 1,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 1,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
|
|
|
},
|
|
|
|
[2] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 2,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 2,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
|
|
|
},
|
|
|
|
[3] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 3,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 3,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
|
|
|
},
|
|
|
|
[4] = IIO_CHAN_SOFT_TIMESTAMP(4),
|
|
|
|
},
|
2011-05-18 07:41:52 -06:00
|
|
|
.num_channels = 5,
|
2011-05-18 07:42:37 -06:00
|
|
|
.info = &ad7991_info,
|
2010-10-01 08:41:51 -06:00
|
|
|
},
|
|
|
|
[ad7995] = {
|
2011-09-30 03:05:31 -06:00
|
|
|
.channel = {
|
|
|
|
[0] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 0,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 0,
|
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
|
|
|
},
|
|
|
|
[1] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 1,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 1,
|
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
|
|
|
},
|
|
|
|
[2] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 2,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 2,
|
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
|
|
|
},
|
|
|
|
[3] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 3,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 3,
|
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
|
|
|
},
|
|
|
|
[4] = IIO_CHAN_SOFT_TIMESTAMP(4),
|
|
|
|
},
|
2011-05-18 07:41:52 -06:00
|
|
|
.num_channels = 5,
|
2011-05-18 07:42:37 -06:00
|
|
|
.info = &ad7991_info,
|
2010-10-01 08:41:51 -06:00
|
|
|
},
|
|
|
|
[ad7999] = {
|
2011-09-30 03:05:31 -06:00
|
|
|
.channel = {
|
|
|
|
[0] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 0,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 0,
|
|
|
|
.scan_type = IIO_ST('u', 8, 16, 4),
|
|
|
|
},
|
|
|
|
[1] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 1,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 1,
|
|
|
|
.scan_type = IIO_ST('u', 8, 16, 4),
|
|
|
|
},
|
|
|
|
[2] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 2,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 2,
|
|
|
|
.scan_type = IIO_ST('u', 8, 16, 4),
|
|
|
|
},
|
|
|
|
[3] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 3,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 3,
|
|
|
|
.scan_type = IIO_ST('u', 8, 16, 4),
|
|
|
|
},
|
|
|
|
[4] = IIO_CHAN_SOFT_TIMESTAMP(4),
|
|
|
|
},
|
2011-05-18 07:41:52 -06:00
|
|
|
.num_channels = 5,
|
2011-05-18 07:42:37 -06:00
|
|
|
.info = &ad7991_info,
|
2010-10-01 08:41:51 -06:00
|
|
|
},
|
|
|
|
[ad7992] = {
|
2011-09-30 03:05:31 -06:00
|
|
|
.channel = {
|
|
|
|
[0] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 0,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 0,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[1] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 1,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 1,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[2] = IIO_CHAN_SOFT_TIMESTAMP(2),
|
|
|
|
},
|
2011-05-18 07:41:52 -06:00
|
|
|
.num_channels = 3,
|
2010-10-01 08:41:51 -06:00
|
|
|
.default_config = AD7998_ALERT_EN,
|
2011-05-18 07:42:37 -06:00
|
|
|
.info = &ad7992_info,
|
2010-10-01 08:41:51 -06:00
|
|
|
},
|
|
|
|
[ad7993] = {
|
2011-09-30 03:05:31 -06:00
|
|
|
.channel = {
|
|
|
|
[0] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 0,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 0,
|
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[1] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 1,
|
|
|
|
.scan_index = 1,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[2] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 2,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 2,
|
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[3] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 3,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 3,
|
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[4] = IIO_CHAN_SOFT_TIMESTAMP(4),
|
|
|
|
},
|
2011-05-18 07:41:52 -06:00
|
|
|
.num_channels = 5,
|
2010-10-01 08:41:51 -06:00
|
|
|
.default_config = AD7998_ALERT_EN,
|
2011-05-18 07:42:37 -06:00
|
|
|
.info = &ad7993_4_7_8_info,
|
2010-10-01 08:41:51 -06:00
|
|
|
},
|
|
|
|
[ad7994] = {
|
2011-09-30 03:05:31 -06:00
|
|
|
.channel = {
|
|
|
|
[0] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 0,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 0,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[1] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 1,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 1,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[2] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 2,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 2,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[3] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 3,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 3,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[4] = IIO_CHAN_SOFT_TIMESTAMP(4),
|
|
|
|
},
|
2011-05-18 07:41:52 -06:00
|
|
|
.num_channels = 5,
|
2010-10-01 08:41:51 -06:00
|
|
|
.default_config = AD7998_ALERT_EN,
|
2011-05-18 07:42:37 -06:00
|
|
|
.info = &ad7993_4_7_8_info,
|
2010-10-01 08:41:51 -06:00
|
|
|
},
|
|
|
|
[ad7997] = {
|
2011-09-30 03:05:31 -06:00
|
|
|
.channel = {
|
|
|
|
[0] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 0,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 0,
|
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[1] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 1,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 1,
|
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[2] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 2,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 2,
|
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[3] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 3,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 3,
|
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[4] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 4,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 4,
|
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
|
|
|
},
|
|
|
|
[5] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 5,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 5,
|
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
|
|
|
},
|
|
|
|
[6] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 6,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 6,
|
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
|
|
|
},
|
|
|
|
[7] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 7,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 7,
|
|
|
|
.scan_type = IIO_ST('u', 10, 16, 2),
|
|
|
|
},
|
|
|
|
[8] = IIO_CHAN_SOFT_TIMESTAMP(8),
|
|
|
|
},
|
2011-05-18 07:41:52 -06:00
|
|
|
.num_channels = 9,
|
2010-10-01 08:41:51 -06:00
|
|
|
.default_config = AD7998_ALERT_EN,
|
2011-05-18 07:42:37 -06:00
|
|
|
.info = &ad7993_4_7_8_info,
|
2010-10-01 08:41:51 -06:00
|
|
|
},
|
|
|
|
[ad7998] = {
|
2011-09-30 03:05:31 -06:00
|
|
|
.channel = {
|
|
|
|
[0] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 0,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 0,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[1] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 1,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 1,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[2] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 2,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 2,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[3] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 3,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 3,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
2011-09-30 03:05:35 -06:00
|
|
|
.event_mask = AD799X_EV_MASK,
|
2011-09-30 03:05:31 -06:00
|
|
|
},
|
|
|
|
[4] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 4,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 4,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
|
|
|
},
|
|
|
|
[5] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 5,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 5,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
|
|
|
},
|
|
|
|
[6] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 6,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 6,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
|
|
|
},
|
|
|
|
[7] = {
|
|
|
|
.type = IIO_VOLTAGE,
|
|
|
|
.indexed = 1,
|
|
|
|
.channel = 7,
|
2013-02-27 12:37:47 -07:00
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
2011-09-30 03:05:31 -06:00
|
|
|
.scan_index = 7,
|
|
|
|
.scan_type = IIO_ST('u', 12, 16, 0),
|
|
|
|
},
|
|
|
|
[8] = IIO_CHAN_SOFT_TIMESTAMP(8),
|
|
|
|
},
|
2011-05-18 07:41:52 -06:00
|
|
|
.num_channels = 9,
|
2010-10-01 08:41:51 -06:00
|
|
|
.default_config = AD7998_ALERT_EN,
|
2011-05-18 07:42:37 -06:00
|
|
|
.info = &ad7993_4_7_8_info,
|
2010-10-01 08:41:51 -06:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-11-19 11:21:57 -07:00
|
|
|
static int ad799x_probe(struct i2c_client *client,
|
2010-10-01 08:41:51 -06:00
|
|
|
const struct i2c_device_id *id)
|
|
|
|
{
|
2011-09-02 10:14:40 -06:00
|
|
|
int ret;
|
2010-10-01 08:41:51 -06:00
|
|
|
struct ad799x_platform_data *pdata = client->dev.platform_data;
|
2011-05-18 07:41:53 -06:00
|
|
|
struct ad799x_state *st;
|
2012-04-26 05:35:01 -06:00
|
|
|
struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
|
2011-05-18 07:41:53 -06:00
|
|
|
|
|
|
|
if (indio_dev == NULL)
|
|
|
|
return -ENOMEM;
|
2010-10-01 08:41:51 -06:00
|
|
|
|
2011-05-18 07:41:53 -06:00
|
|
|
st = iio_priv(indio_dev);
|
2010-10-01 08:41:51 -06:00
|
|
|
/* this is only used for device removal purposes */
|
2011-05-18 07:41:53 -06:00
|
|
|
i2c_set_clientdata(client, indio_dev);
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
st->id = id->driver_data;
|
|
|
|
st->chip_info = &ad799x_chip_info_tbl[st->id];
|
|
|
|
st->config = st->chip_info->default_config;
|
|
|
|
|
|
|
|
/* TODO: Add pdata options for filtering and bit delay */
|
|
|
|
|
2013-03-26 12:43:00 -06:00
|
|
|
if (!pdata)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
st->int_vref_mv = pdata->vref_mv;
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
st->reg = regulator_get(&client->dev, "vcc");
|
|
|
|
if (!IS_ERR(st->reg)) {
|
|
|
|
ret = regulator_enable(st->reg);
|
|
|
|
if (ret)
|
|
|
|
goto error_put_reg;
|
|
|
|
}
|
|
|
|
st->client = client;
|
|
|
|
|
2011-05-18 07:41:53 -06:00
|
|
|
indio_dev->dev.parent = &client->dev;
|
|
|
|
indio_dev->name = id->name;
|
2011-05-18 07:42:37 -06:00
|
|
|
indio_dev->info = st->chip_info->info;
|
|
|
|
|
2011-05-18 07:41:53 -06:00
|
|
|
indio_dev->modes = INDIO_DIRECT_MODE;
|
|
|
|
indio_dev->channels = st->chip_info->channel;
|
|
|
|
indio_dev->num_channels = st->chip_info->num_channels;
|
|
|
|
|
|
|
|
ret = ad799x_register_ring_funcs_and_init(indio_dev);
|
2010-10-01 08:41:51 -06:00
|
|
|
if (ret)
|
2011-05-18 07:41:53 -06:00
|
|
|
goto error_disable_reg;
|
2010-10-01 08:41:51 -06:00
|
|
|
|
2011-05-18 07:42:37 -06:00
|
|
|
if (client->irq > 0) {
|
2011-05-18 07:41:15 -06:00
|
|
|
ret = request_threaded_irq(client->irq,
|
|
|
|
NULL,
|
|
|
|
ad799x_event_handler,
|
|
|
|
IRQF_TRIGGER_FALLING |
|
|
|
|
IRQF_ONESHOT,
|
|
|
|
client->name,
|
2011-05-18 07:41:53 -06:00
|
|
|
indio_dev);
|
2010-10-01 08:41:51 -06:00
|
|
|
if (ret)
|
|
|
|
goto error_cleanup_ring;
|
|
|
|
}
|
2011-09-02 10:14:40 -06:00
|
|
|
ret = iio_device_register(indio_dev);
|
|
|
|
if (ret)
|
|
|
|
goto error_free_irq;
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
return 0;
|
2011-05-18 07:41:53 -06:00
|
|
|
|
2011-09-02 10:14:40 -06:00
|
|
|
error_free_irq:
|
|
|
|
free_irq(client->irq, indio_dev);
|
2010-10-01 08:41:51 -06:00
|
|
|
error_cleanup_ring:
|
2011-05-18 07:41:53 -06:00
|
|
|
ad799x_ring_cleanup(indio_dev);
|
2010-10-01 08:41:51 -06:00
|
|
|
error_disable_reg:
|
|
|
|
if (!IS_ERR(st->reg))
|
|
|
|
regulator_disable(st->reg);
|
|
|
|
error_put_reg:
|
|
|
|
if (!IS_ERR(st->reg))
|
|
|
|
regulator_put(st->reg);
|
2012-04-26 05:35:01 -06:00
|
|
|
iio_device_free(indio_dev);
|
2011-05-18 07:41:53 -06:00
|
|
|
|
2010-10-01 08:41:51 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-19 11:26:37 -07:00
|
|
|
static int ad799x_remove(struct i2c_client *client)
|
2010-10-01 08:41:51 -06:00
|
|
|
{
|
2011-05-18 07:41:53 -06:00
|
|
|
struct iio_dev *indio_dev = i2c_get_clientdata(client);
|
|
|
|
struct ad799x_state *st = iio_priv(indio_dev);
|
2010-10-01 08:41:51 -06:00
|
|
|
|
2011-10-14 07:46:58 -06:00
|
|
|
iio_device_unregister(indio_dev);
|
2011-05-18 07:42:37 -06:00
|
|
|
if (client->irq > 0)
|
2011-05-18 07:41:15 -06:00
|
|
|
free_irq(client->irq, indio_dev);
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
ad799x_ring_cleanup(indio_dev);
|
|
|
|
if (!IS_ERR(st->reg)) {
|
|
|
|
regulator_disable(st->reg);
|
|
|
|
regulator_put(st->reg);
|
|
|
|
}
|
2012-04-26 05:35:01 -06:00
|
|
|
iio_device_free(indio_dev);
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id ad799x_id[] = {
|
|
|
|
{ "ad7991", ad7991 },
|
|
|
|
{ "ad7995", ad7995 },
|
|
|
|
{ "ad7999", ad7999 },
|
|
|
|
{ "ad7992", ad7992 },
|
|
|
|
{ "ad7993", ad7993 },
|
|
|
|
{ "ad7994", ad7994 },
|
|
|
|
{ "ad7997", ad7997 },
|
|
|
|
{ "ad7998", ad7998 },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(i2c, ad799x_id);
|
|
|
|
|
|
|
|
static struct i2c_driver ad799x_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "ad799x",
|
|
|
|
},
|
|
|
|
.probe = ad799x_probe,
|
2012-11-19 11:21:38 -07:00
|
|
|
.remove = ad799x_remove,
|
2010-10-01 08:41:51 -06:00
|
|
|
.id_table = ad799x_id,
|
|
|
|
};
|
2011-11-16 02:13:38 -07:00
|
|
|
module_i2c_driver(ad799x_driver);
|
2010-10-01 08:41:51 -06:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
|
|
|
|
MODULE_DESCRIPTION("Analog Devices AD799x ADC");
|
|
|
|
MODULE_LICENSE("GPL v2");
|