Release 4.7 drivers/staging/iio/adc/ad7780.c
/*
* AD7170/AD7171 and AD7780/AD7781 SPI ADC driver
*
* Copyright 2011 Analog Devices Inc.
*
* Licensed under the GPL-2.
*/
#include <linux/interrupt.h>
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
#include <linux/spi/spi.h>
#include <linux/regulator/consumer.h>
#include <linux/err.h>
#include <linux/sched.h>
#include <linux/gpio/consumer.h>
#include <linux/module.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/iio/adc/ad_sigma_delta.h>
#define AD7780_RDY BIT(7)
#define AD7780_FILTER BIT(6)
#define AD7780_ERR BIT(5)
#define AD7780_ID1 BIT(4)
#define AD7780_ID0 BIT(3)
#define AD7780_GAIN BIT(2)
#define AD7780_PAT1 BIT(1)
#define AD7780_PAT0 BIT(0)
struct ad7780_chip_info {
struct iio_chan_spec channel;
unsigned int pattern_mask;
unsigned int pattern;
};
struct ad7780_state {
const struct ad7780_chip_info *chip_info;
struct regulator *reg;
struct gpio_desc *powerdown_gpio;
unsigned int gain;
u16 int_vref_mv;
struct ad_sigma_delta sd;
};
enum ad7780_supported_device_ids {
ID_AD7170,
ID_AD7171,
ID_AD7780,
ID_AD7781,
};
static struct ad7780_state *ad_sigma_delta_to_ad7780(struct ad_sigma_delta *sd)
{
return container_of(sd, struct ad7780_state, sd);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
lars-peter clausen | lars-peter clausen | 13 | 54.17% | 1 | 50.00% |
michael hennerich | michael hennerich | 11 | 45.83% | 1 | 50.00% |
| Total | 24 | 100.00% | 2 | 100.00% |
static int ad7780_set_mode(struct ad_sigma_delta *sigma_delta,
enum ad_sigma_delta_mode mode)
{
struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta);
unsigned int val;
switch (mode) {
case AD_SD_MODE_SINGLE:
case AD_SD_MODE_CONTINUOUS:
val = 1;
break;
default:
val = 0;
break;
}
gpiod_set_value(st->powerdown_gpio, val);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
lars-peter clausen | lars-peter clausen | 44 | 68.75% | 1 | 25.00% |
michael hennerich | michael hennerich | 18 | 28.12% | 1 | 25.00% |
alison schofield | alison schofield | 1 | 1.56% | 1 | 25.00% |
dragos bogdan | dragos bogdan | 1 | 1.56% | 1 | 25.00% |
| Total | 64 | 100.00% | 4 | 100.00% |
static int ad7780_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val,
int *val2,
long m)
{
struct ad7780_state *st = iio_priv(indio_dev);
switch (m) {
case IIO_CHAN_INFO_RAW:
return ad_sigma_delta_single_conversion(indio_dev, chan, val);
case IIO_CHAN_INFO_SCALE:
*val = st->int_vref_mv * st->gain;
*val2 = chan->scan_type.realbits - 1;
return IIO_VAL_FRACTIONAL_LOG2;
case IIO_CHAN_INFO_OFFSET:
*val -= (1 << (chan->scan_type.realbits - 1));
return IIO_VAL_INT;
}
return -EINVAL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
michael hennerich | michael hennerich | 68 | 60.71% | 3 | 50.00% |
lars-peter clausen | lars-peter clausen | 43 | 38.39% | 2 | 33.33% |
jonathan cameron | jonathan cameron | 1 | 0.89% | 1 | 16.67% |
| Total | 112 | 100.00% | 6 | 100.00% |
static int ad7780_postprocess_sample(struct ad_sigma_delta *sigma_delta,
unsigned int raw_sample)
{
struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta);
const struct ad7780_chip_info *chip_info = st->chip_info;
if ((raw_sample & AD7780_ERR) ||
((raw_sample & chip_info->pattern_mask) != chip_info->pattern))
return -EIO;
if (raw_sample & AD7780_GAIN)
st->gain = 1;
else
st->gain = 128;
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
lars-peter clausen | lars-peter clausen | 69 | 83.13% | 2 | 50.00% |
michael hennerich | michael hennerich | 14 | 16.87% | 2 | 50.00% |
| Total | 83 | 100.00% | 4 | 100.00% |
static const struct ad_sigma_delta_info ad7780_sigma_delta_info = {
.set_mode = ad7780_set_mode,
.postprocess_sample = ad7780_postprocess_sample,
.has_registers = false,
};
#define AD7780_CHANNEL(bits, wordsize) \
AD_SD_CHANNEL(1, 0, 0, bits, 32, wordsize - bits)
static const struct ad7780_chip_info ad7780_chip_info_tbl[] = {
[ID_AD7170] = {
.channel = AD7780_CHANNEL(12, 24),
.pattern = 0x5,
.pattern_mask = 0x7,
},
[ID_AD7171] = {
.channel = AD7780_CHANNEL(16, 24),
.pattern = 0x5,
.pattern_mask = 0x7,
},
[ID_AD7780] = {
.channel = AD7780_CHANNEL(24, 32),
.pattern = 0x1,
.pattern_mask = 0x3,
},
[ID_AD7781] = {
.channel = AD7780_CHANNEL(20, 32),
.pattern = 0x1,
.pattern_mask = 0x3,
},
};
static const struct iio_info ad7780_info = {
.read_raw = &ad7780_read_raw,
.driver_module = THIS_MODULE,
};
static int ad7780_probe(struct spi_device *spi)
{
struct ad7780_state *st;
struct iio_dev *indio_dev;
int ret, voltage_uv = 0;
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
if (!indio_dev)
return -ENOMEM;
st = iio_priv(indio_dev);
st->gain = 1;
ad_sd_init(&st->sd, indio_dev, spi, &ad7780_sigma_delta_info);
st->reg = devm_regulator_get(&spi->dev, "vcc");
if (!IS_ERR(st->reg)) {
ret = regulator_enable(st->reg);
if (ret)
return ret;
voltage_uv = regulator_get_voltage(st->reg);
}
st->chip_info =
&ad7780_chip_info_tbl[spi_get_device_id(spi)->driver_data];
if (voltage_uv)
st->int_vref_mv = voltage_uv / 1000;
else
dev_warn(&spi->dev, "Reference voltage unspecified\n");
spi_set_drvdata(spi, indio_dev);
indio_dev->dev.parent = &spi->dev;
indio_dev->name = spi_get_device_id(spi)->name;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = &st->chip_info->channel;
indio_dev->num_channels = 1;
indio_dev->info = &ad7780_info;
st->powerdown_gpio = devm_gpiod_get_optional(&spi->dev,
"powerdown",
GPIOD_OUT_LOW);
if (IS_ERR(st->powerdown_gpio)) {
ret = PTR_ERR(st->powerdown_gpio);
dev_err(&spi->dev, "Failed to request powerdown GPIO: %d\n",
ret);
goto error_disable_reg;
}
ret = ad_sd_setup_buffer_and_trigger(indio_dev);
if (ret)
goto error_disable_reg;
ret = iio_device_register(indio_dev);
if (ret)
goto error_cleanup_buffer_and_trigger;
return 0;
error_cleanup_buffer_and_trigger:
ad_sd_cleanup_buffer_and_trigger(indio_dev);
error_disable_reg:
if (!IS_ERR(st->reg))
regulator_disable(st->reg);
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
michael hennerich | michael hennerich | 260 | 76.47% | 3 | 27.27% |
lars-peter clausen | lars-peter clausen | 28 | 8.24% | 2 | 18.18% |
dragos bogdan | dragos bogdan | 24 | 7.06% | 2 | 18.18% |
sachin kamat | sachin kamat | 16 | 4.71% | 1 | 9.09% |
jonathan cameron | jonathan cameron | 11 | 3.24% | 2 | 18.18% |
cristina opriceana | cristina opriceana | 1 | 0.29% | 1 | 9.09% |
| Total | 340 | 100.00% | 11 | 100.00% |
static int ad7780_remove(struct spi_device *spi)
{
struct iio_dev *indio_dev = spi_get_drvdata(spi);
struct ad7780_state *st = iio_priv(indio_dev);
iio_device_unregister(indio_dev);
ad_sd_cleanup_buffer_and_trigger(indio_dev);
if (!IS_ERR(st->reg))
regulator_disable(st->reg);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
michael hennerich | michael hennerich | 52 | 85.25% | 2 | 40.00% |
jonathan cameron | jonathan cameron | 5 | 8.20% | 1 | 20.00% |
lars-peter clausen | lars-peter clausen | 4 | 6.56% | 2 | 40.00% |
| Total | 61 | 100.00% | 5 | 100.00% |
static const struct spi_device_id ad7780_id[] = {
{"ad7170", ID_AD7170},
{"ad7171", ID_AD7171},
{"ad7780", ID_AD7780},
{"ad7781", ID_AD7781},
{}
};
MODULE_DEVICE_TABLE(spi, ad7780_id);
static struct spi_driver ad7780_driver = {
.driver = {
.name = "ad7780",
},
.probe = ad7780_probe,
.remove = ad7780_remove,
.id_table = ad7780_id,
};
module_spi_driver(ad7780_driver);
MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
MODULE_DESCRIPTION("Analog Devices AD7780 and similar ADCs");
MODULE_LICENSE("GPL v2");
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
michael hennerich | michael hennerich | 627 | 58.11% | 3 | 14.29% |
lars-peter clausen | lars-peter clausen | 356 | 32.99% | 6 | 28.57% |
jonathan cameron | jonathan cameron | 38 | 3.52% | 5 | 23.81% |
dragos bogdan | dragos bogdan | 29 | 2.69% | 2 | 9.52% |
sachin kamat | sachin kamat | 16 | 1.48% | 1 | 4.76% |
haneen mohammed | haneen mohammed | 8 | 0.74% | 1 | 4.76% |
paul gortmaker | paul gortmaker | 3 | 0.28% | 1 | 4.76% |
alison schofield | alison schofield | 1 | 0.09% | 1 | 4.76% |
cristina opriceana | cristina opriceana | 1 | 0.09% | 1 | 4.76% |
| Total | 1079 | 100.00% | 21 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.