2019-05-30 07:57:44 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2016-02-11 21:49:54 +08:00
|
|
|
/*
|
|
|
|
* ADS1015 - Texas Instruments Analog-to-Digital Converter
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016, Intel Corporation.
|
|
|
|
*
|
|
|
|
* IIO driver for ADS1015 ADC 7-bit I2C slave address:
|
|
|
|
* * 0x48 - ADDR connected to Ground
|
|
|
|
* * 0x49 - ADDR connected to Vdd
|
|
|
|
* * 0x4A - ADDR connected to SDA
|
|
|
|
* * 0x4B - ADDR connected to SCL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
2017-07-20 23:24:27 +08:00
|
|
|
#include <linux/irq.h>
|
2016-02-11 21:49:54 +08:00
|
|
|
#include <linux/i2c.h>
|
2019-12-06 01:46:37 +08:00
|
|
|
#include <linux/property.h>
|
2016-02-11 21:49:54 +08:00
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/pm_runtime.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
|
|
|
|
#include <linux/iio/iio.h>
|
|
|
|
#include <linux/iio/types.h>
|
|
|
|
#include <linux/iio/sysfs.h>
|
2017-07-20 23:24:27 +08:00
|
|
|
#include <linux/iio/events.h>
|
2016-02-11 21:49:54 +08:00
|
|
|
#include <linux/iio/buffer.h>
|
|
|
|
#include <linux/iio/triggered_buffer.h>
|
|
|
|
#include <linux/iio/trigger_consumer.h>
|
|
|
|
|
|
|
|
#define ADS1015_DRV_NAME "ads1015"
|
|
|
|
|
2019-12-06 01:46:36 +08:00
|
|
|
#define ADS1015_CHANNELS 8
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
#define ADS1015_CONV_REG 0x00
|
|
|
|
#define ADS1015_CFG_REG 0x01
|
2017-07-20 23:24:27 +08:00
|
|
|
#define ADS1015_LO_THRESH_REG 0x02
|
|
|
|
#define ADS1015_HI_THRESH_REG 0x03
|
2016-02-11 21:49:54 +08:00
|
|
|
|
2017-07-20 23:24:27 +08:00
|
|
|
#define ADS1015_CFG_COMP_QUE_SHIFT 0
|
|
|
|
#define ADS1015_CFG_COMP_LAT_SHIFT 2
|
|
|
|
#define ADS1015_CFG_COMP_POL_SHIFT 3
|
|
|
|
#define ADS1015_CFG_COMP_MODE_SHIFT 4
|
2016-02-11 21:49:54 +08:00
|
|
|
#define ADS1015_CFG_DR_SHIFT 5
|
|
|
|
#define ADS1015_CFG_MOD_SHIFT 8
|
|
|
|
#define ADS1015_CFG_PGA_SHIFT 9
|
|
|
|
#define ADS1015_CFG_MUX_SHIFT 12
|
|
|
|
|
2017-07-20 23:24:27 +08:00
|
|
|
#define ADS1015_CFG_COMP_QUE_MASK GENMASK(1, 0)
|
|
|
|
#define ADS1015_CFG_COMP_LAT_MASK BIT(2)
|
2017-08-24 08:22:57 +08:00
|
|
|
#define ADS1015_CFG_COMP_POL_MASK BIT(3)
|
2017-07-20 23:24:27 +08:00
|
|
|
#define ADS1015_CFG_COMP_MODE_MASK BIT(4)
|
2016-02-11 21:49:54 +08:00
|
|
|
#define ADS1015_CFG_DR_MASK GENMASK(7, 5)
|
|
|
|
#define ADS1015_CFG_MOD_MASK BIT(8)
|
|
|
|
#define ADS1015_CFG_PGA_MASK GENMASK(11, 9)
|
|
|
|
#define ADS1015_CFG_MUX_MASK GENMASK(14, 12)
|
|
|
|
|
2017-07-20 23:24:27 +08:00
|
|
|
/* Comparator queue and disable field */
|
|
|
|
#define ADS1015_CFG_COMP_DISABLE 3
|
|
|
|
|
|
|
|
/* Comparator polarity field */
|
|
|
|
#define ADS1015_CFG_COMP_POL_LOW 0
|
|
|
|
#define ADS1015_CFG_COMP_POL_HIGH 1
|
|
|
|
|
|
|
|
/* Comparator mode field */
|
|
|
|
#define ADS1015_CFG_COMP_MODE_TRAD 0
|
|
|
|
#define ADS1015_CFG_COMP_MODE_WINDOW 1
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
/* device operating modes */
|
|
|
|
#define ADS1015_CONTINUOUS 0
|
|
|
|
#define ADS1015_SINGLESHOT 1
|
|
|
|
|
|
|
|
#define ADS1015_SLEEP_DELAY_MS 2000
|
|
|
|
#define ADS1015_DEFAULT_PGA 2
|
|
|
|
#define ADS1015_DEFAULT_DATA_RATE 4
|
|
|
|
#define ADS1015_DEFAULT_CHAN 0
|
|
|
|
|
2022-03-29 03:47:23 +08:00
|
|
|
struct ads1015_chip_data {
|
|
|
|
struct iio_chan_spec const *channels;
|
|
|
|
int num_channels;
|
|
|
|
const struct iio_info *info;
|
|
|
|
const int *data_rate;
|
2022-03-29 03:47:25 +08:00
|
|
|
const int data_rate_len;
|
|
|
|
const int *scale;
|
|
|
|
const int scale_len;
|
2022-03-29 03:47:23 +08:00
|
|
|
bool has_comparator;
|
2016-05-16 13:18:46 +08:00
|
|
|
};
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
enum ads1015_channels {
|
|
|
|
ADS1015_AIN0_AIN1 = 0,
|
|
|
|
ADS1015_AIN0_AIN3,
|
|
|
|
ADS1015_AIN1_AIN3,
|
|
|
|
ADS1015_AIN2_AIN3,
|
|
|
|
ADS1015_AIN0,
|
|
|
|
ADS1015_AIN1,
|
|
|
|
ADS1015_AIN2,
|
|
|
|
ADS1015_AIN3,
|
|
|
|
ADS1015_TIMESTAMP,
|
|
|
|
};
|
|
|
|
|
2022-03-29 03:47:23 +08:00
|
|
|
static const int ads1015_data_rate[] = {
|
2016-02-11 21:49:54 +08:00
|
|
|
128, 250, 490, 920, 1600, 2400, 3300, 3300
|
|
|
|
};
|
|
|
|
|
2022-03-29 03:47:23 +08:00
|
|
|
static const int ads1115_data_rate[] = {
|
2016-05-16 13:18:46 +08:00
|
|
|
8, 16, 32, 64, 128, 250, 475, 860
|
|
|
|
};
|
|
|
|
|
2017-07-20 23:24:18 +08:00
|
|
|
/*
|
|
|
|
* Translation from PGA bits to full-scale positive and negative input voltage
|
|
|
|
* range in mV
|
|
|
|
*/
|
2022-03-29 03:47:25 +08:00
|
|
|
static const int ads1015_fullscale_range[] = {
|
2017-07-20 23:24:18 +08:00
|
|
|
6144, 4096, 2048, 1024, 512, 256, 256, 256
|
2016-02-11 21:49:54 +08:00
|
|
|
};
|
|
|
|
|
2022-03-29 03:47:25 +08:00
|
|
|
static const int ads1015_scale[] = { /* 12bit ADC */
|
|
|
|
256, 11,
|
|
|
|
512, 11,
|
|
|
|
1024, 11,
|
|
|
|
2048, 11,
|
|
|
|
4096, 11,
|
|
|
|
6144, 11
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int ads1115_scale[] = { /* 16bit ADC */
|
|
|
|
256, 15,
|
|
|
|
512, 15,
|
|
|
|
1024, 15,
|
|
|
|
2048, 15,
|
|
|
|
4096, 15,
|
|
|
|
6144, 15
|
|
|
|
};
|
|
|
|
|
2017-07-20 23:24:27 +08:00
|
|
|
/*
|
|
|
|
* Translation from COMP_QUE field value to the number of successive readings
|
|
|
|
* exceed the threshold values before an interrupt is generated
|
|
|
|
*/
|
|
|
|
static const int ads1015_comp_queue[] = { 1, 2, 4 };
|
|
|
|
|
|
|
|
static const struct iio_event_spec ads1015_events[] = {
|
|
|
|
{
|
|
|
|
.type = IIO_EV_TYPE_THRESH,
|
|
|
|
.dir = IIO_EV_DIR_RISING,
|
|
|
|
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
|
|
|
|
BIT(IIO_EV_INFO_ENABLE),
|
|
|
|
}, {
|
|
|
|
.type = IIO_EV_TYPE_THRESH,
|
|
|
|
.dir = IIO_EV_DIR_FALLING,
|
|
|
|
.mask_separate = BIT(IIO_EV_INFO_VALUE),
|
|
|
|
}, {
|
|
|
|
.type = IIO_EV_TYPE_THRESH,
|
|
|
|
.dir = IIO_EV_DIR_EITHER,
|
|
|
|
.mask_separate = BIT(IIO_EV_INFO_ENABLE) |
|
|
|
|
BIT(IIO_EV_INFO_PERIOD),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-03-29 03:47:22 +08:00
|
|
|
/*
|
|
|
|
* Compile-time check whether _fitbits can accommodate up to _testbits
|
|
|
|
* bits. Returns _fitbits on success, fails to compile otherwise.
|
|
|
|
*
|
|
|
|
* The test works such that it multiplies constant _fitbits by constant
|
|
|
|
* double-negation of size of a non-empty structure, i.e. it multiplies
|
|
|
|
* constant _fitbits by constant 1 in each successful compilation case.
|
|
|
|
* The non-empty structure may contain C11 _Static_assert(), make use of
|
|
|
|
* this and place the kernel variant of static assert in there, so that
|
|
|
|
* it performs the compile-time check for _testbits <= _fitbits. Note
|
|
|
|
* that it is not possible to directly use static_assert in compound
|
|
|
|
* statements, hence this convoluted construct.
|
|
|
|
*/
|
|
|
|
#define FIT_CHECK(_testbits, _fitbits) \
|
|
|
|
( \
|
|
|
|
(_fitbits) * \
|
|
|
|
!!sizeof(struct { \
|
|
|
|
static_assert((_testbits) <= (_fitbits)); \
|
|
|
|
int pad; \
|
|
|
|
}) \
|
|
|
|
)
|
|
|
|
|
2022-03-29 03:47:20 +08:00
|
|
|
#define ADS1015_V_CHAN(_chan, _addr, _realbits, _shift, _event_spec, _num_event_specs) { \
|
2016-02-11 21:49:54 +08:00
|
|
|
.type = IIO_VOLTAGE, \
|
|
|
|
.indexed = 1, \
|
|
|
|
.address = _addr, \
|
|
|
|
.channel = _chan, \
|
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
|
|
|
|
BIT(IIO_CHAN_INFO_SCALE) | \
|
|
|
|
BIT(IIO_CHAN_INFO_SAMP_FREQ), \
|
2022-03-29 03:47:25 +08:00
|
|
|
.info_mask_shared_by_all_available = \
|
|
|
|
BIT(IIO_CHAN_INFO_SCALE) | \
|
|
|
|
BIT(IIO_CHAN_INFO_SAMP_FREQ), \
|
2016-02-11 21:49:54 +08:00
|
|
|
.scan_index = _addr, \
|
|
|
|
.scan_type = { \
|
|
|
|
.sign = 's', \
|
2022-03-29 03:47:19 +08:00
|
|
|
.realbits = (_realbits), \
|
2022-03-29 03:47:22 +08:00
|
|
|
.storagebits = FIT_CHECK((_realbits) + (_shift), 16), \
|
2022-03-29 03:47:19 +08:00
|
|
|
.shift = (_shift), \
|
2016-02-11 21:49:54 +08:00
|
|
|
.endianness = IIO_CPU, \
|
|
|
|
}, \
|
2022-03-29 03:47:20 +08:00
|
|
|
.event_spec = (_event_spec), \
|
|
|
|
.num_event_specs = (_num_event_specs), \
|
2016-05-18 06:02:03 +08:00
|
|
|
.datasheet_name = "AIN"#_chan, \
|
2016-02-11 21:49:54 +08:00
|
|
|
}
|
|
|
|
|
2022-03-29 03:47:20 +08:00
|
|
|
#define ADS1015_V_DIFF_CHAN(_chan, _chan2, _addr, _realbits, _shift, _event_spec, _num_event_specs) { \
|
2016-02-11 21:49:54 +08:00
|
|
|
.type = IIO_VOLTAGE, \
|
|
|
|
.differential = 1, \
|
|
|
|
.indexed = 1, \
|
|
|
|
.address = _addr, \
|
|
|
|
.channel = _chan, \
|
|
|
|
.channel2 = _chan2, \
|
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
|
|
|
|
BIT(IIO_CHAN_INFO_SCALE) | \
|
|
|
|
BIT(IIO_CHAN_INFO_SAMP_FREQ), \
|
2022-03-29 03:47:25 +08:00
|
|
|
.info_mask_shared_by_all_available = \
|
|
|
|
BIT(IIO_CHAN_INFO_SCALE) | \
|
|
|
|
BIT(IIO_CHAN_INFO_SAMP_FREQ), \
|
2016-02-11 21:49:54 +08:00
|
|
|
.scan_index = _addr, \
|
|
|
|
.scan_type = { \
|
|
|
|
.sign = 's', \
|
2022-03-29 03:47:19 +08:00
|
|
|
.realbits = (_realbits), \
|
2022-03-29 03:47:22 +08:00
|
|
|
.storagebits = FIT_CHECK((_realbits) + (_shift), 16), \
|
2022-03-29 03:47:19 +08:00
|
|
|
.shift = (_shift), \
|
2016-05-16 13:18:46 +08:00
|
|
|
.endianness = IIO_CPU, \
|
|
|
|
}, \
|
2022-03-29 03:47:20 +08:00
|
|
|
.event_spec = (_event_spec), \
|
|
|
|
.num_event_specs = (_num_event_specs), \
|
2016-05-18 06:02:03 +08:00
|
|
|
.datasheet_name = "AIN"#_chan"-AIN"#_chan2, \
|
2016-05-16 13:18:46 +08:00
|
|
|
}
|
|
|
|
|
2019-12-06 01:46:36 +08:00
|
|
|
struct ads1015_channel_data {
|
|
|
|
bool enabled;
|
|
|
|
unsigned int pga;
|
|
|
|
unsigned int data_rate;
|
|
|
|
};
|
|
|
|
|
2017-07-20 23:24:27 +08:00
|
|
|
struct ads1015_thresh_data {
|
|
|
|
unsigned int comp_queue;
|
|
|
|
int high_thresh;
|
|
|
|
int low_thresh;
|
|
|
|
};
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
struct ads1015_data {
|
|
|
|
struct regmap *regmap;
|
|
|
|
/*
|
|
|
|
* Protects ADC ops, e.g: concurrent sysfs/buffered
|
|
|
|
* data reads, configuration updates
|
|
|
|
*/
|
|
|
|
struct mutex lock;
|
|
|
|
struct ads1015_channel_data channel_data[ADS1015_CHANNELS];
|
2016-05-16 13:18:46 +08:00
|
|
|
|
2017-07-20 23:24:27 +08:00
|
|
|
unsigned int event_channel;
|
|
|
|
unsigned int comp_mode;
|
|
|
|
struct ads1015_thresh_data thresh_data[ADS1015_CHANNELS];
|
|
|
|
|
2022-03-29 03:47:24 +08:00
|
|
|
const struct ads1015_chip_data *chip;
|
2017-07-20 23:24:20 +08:00
|
|
|
/*
|
|
|
|
* Set to true when the ADC is switched to the continuous-conversion
|
|
|
|
* mode and exits from a power-down state. This flag is used to avoid
|
|
|
|
* getting the stale result from the conversion register.
|
|
|
|
*/
|
|
|
|
bool conv_invalid;
|
2016-02-11 21:49:54 +08:00
|
|
|
};
|
|
|
|
|
2017-07-20 23:24:27 +08:00
|
|
|
static bool ads1015_event_channel_enabled(struct ads1015_data *data)
|
|
|
|
{
|
|
|
|
return (data->event_channel != ADS1015_CHANNELS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ads1015_event_channel_enable(struct ads1015_data *data, int chan,
|
|
|
|
int comp_mode)
|
|
|
|
{
|
|
|
|
WARN_ON(ads1015_event_channel_enabled(data));
|
|
|
|
|
|
|
|
data->event_channel = chan;
|
|
|
|
data->comp_mode = comp_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ads1015_event_channel_disable(struct ads1015_data *data, int chan)
|
|
|
|
{
|
|
|
|
data->event_channel = ADS1015_CHANNELS;
|
|
|
|
}
|
|
|
|
|
2022-03-29 03:47:18 +08:00
|
|
|
static const struct regmap_range ads1015_writeable_ranges[] = {
|
|
|
|
regmap_reg_range(ADS1015_CFG_REG, ADS1015_HI_THRESH_REG),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct regmap_access_table ads1015_writeable_table = {
|
|
|
|
.yes_ranges = ads1015_writeable_ranges,
|
|
|
|
.n_yes_ranges = ARRAY_SIZE(ads1015_writeable_ranges),
|
|
|
|
};
|
2016-02-11 21:49:54 +08:00
|
|
|
|
|
|
|
static const struct regmap_config ads1015_regmap_config = {
|
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 16,
|
2017-07-20 23:24:27 +08:00
|
|
|
.max_register = ADS1015_HI_THRESH_REG,
|
2022-03-29 03:47:18 +08:00
|
|
|
.wr_table = &ads1015_writeable_table,
|
2016-02-11 21:49:54 +08:00
|
|
|
};
|
|
|
|
|
2022-03-29 03:47:21 +08:00
|
|
|
static const struct regmap_range tla2024_writeable_ranges[] = {
|
|
|
|
regmap_reg_range(ADS1015_CFG_REG, ADS1015_CFG_REG),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct regmap_access_table tla2024_writeable_table = {
|
|
|
|
.yes_ranges = tla2024_writeable_ranges,
|
|
|
|
.n_yes_ranges = ARRAY_SIZE(tla2024_writeable_ranges),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct regmap_config tla2024_regmap_config = {
|
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 16,
|
|
|
|
.max_register = ADS1015_CFG_REG,
|
|
|
|
.wr_table = &tla2024_writeable_table,
|
|
|
|
};
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
static const struct iio_chan_spec ads1015_channels[] = {
|
2022-03-29 03:47:20 +08:00
|
|
|
ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 12, 4,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
|
|
|
ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 12, 4,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
|
|
|
ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 12, 4,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
|
|
|
ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 12, 4,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
|
|
|
ADS1015_V_CHAN(0, ADS1015_AIN0, 12, 4,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
|
|
|
ADS1015_V_CHAN(1, ADS1015_AIN1, 12, 4,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
|
|
|
ADS1015_V_CHAN(2, ADS1015_AIN2, 12, 4,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
|
|
|
ADS1015_V_CHAN(3, ADS1015_AIN3, 12, 4,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
2016-02-11 21:49:54 +08:00
|
|
|
IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP),
|
|
|
|
};
|
|
|
|
|
2016-05-16 13:18:46 +08:00
|
|
|
static const struct iio_chan_spec ads1115_channels[] = {
|
2022-03-29 03:47:20 +08:00
|
|
|
ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 16, 0,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
|
|
|
ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 16, 0,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
|
|
|
ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 16, 0,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
|
|
|
ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 16, 0,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
|
|
|
ADS1015_V_CHAN(0, ADS1015_AIN0, 16, 0,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
|
|
|
ADS1015_V_CHAN(1, ADS1015_AIN1, 16, 0,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
|
|
|
ADS1015_V_CHAN(2, ADS1015_AIN2, 16, 0,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
|
|
|
ADS1015_V_CHAN(3, ADS1015_AIN3, 16, 0,
|
|
|
|
ads1015_events, ARRAY_SIZE(ads1015_events)),
|
2016-05-16 13:18:46 +08:00
|
|
|
IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP),
|
|
|
|
};
|
|
|
|
|
2022-03-29 03:47:21 +08:00
|
|
|
static const struct iio_chan_spec tla2024_channels[] = {
|
|
|
|
ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 12, 4, NULL, 0),
|
|
|
|
ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 12, 4, NULL, 0),
|
|
|
|
ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 12, 4, NULL, 0),
|
|
|
|
ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 12, 4, NULL, 0),
|
|
|
|
ADS1015_V_CHAN(0, ADS1015_AIN0, 12, 4, NULL, 0),
|
|
|
|
ADS1015_V_CHAN(1, ADS1015_AIN1, 12, 4, NULL, 0),
|
|
|
|
ADS1015_V_CHAN(2, ADS1015_AIN2, 12, 4, NULL, 0),
|
|
|
|
ADS1015_V_CHAN(3, ADS1015_AIN3, 12, 4, NULL, 0),
|
|
|
|
IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP),
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-08-03 13:04:05 +08:00
|
|
|
#ifdef CONFIG_PM
|
2016-02-11 21:49:54 +08:00
|
|
|
static int ads1015_set_power_state(struct ads1015_data *data, bool on)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct device *dev = regmap_get_device(data->regmap);
|
|
|
|
|
|
|
|
if (on) {
|
2021-05-17 00:20:59 +08:00
|
|
|
ret = pm_runtime_resume_and_get(dev);
|
2016-02-11 21:49:54 +08:00
|
|
|
} else {
|
|
|
|
pm_runtime_mark_last_busy(dev);
|
|
|
|
ret = pm_runtime_put_autosuspend(dev);
|
|
|
|
}
|
|
|
|
|
2017-07-20 23:24:21 +08:00
|
|
|
return ret < 0 ? ret : 0;
|
2016-02-11 21:49:54 +08:00
|
|
|
}
|
|
|
|
|
2020-08-03 13:04:05 +08:00
|
|
|
#else /* !CONFIG_PM */
|
|
|
|
|
|
|
|
static int ads1015_set_power_state(struct ads1015_data *data, bool on)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !CONFIG_PM */
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
static
|
|
|
|
int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val)
|
|
|
|
{
|
2022-03-29 03:47:24 +08:00
|
|
|
const int *data_rate = data->chip->data_rate;
|
2017-08-24 16:25:51 +08:00
|
|
|
int ret, pga, dr, dr_old, conv_time;
|
2017-07-20 23:24:22 +08:00
|
|
|
unsigned int old, mask, cfg;
|
2016-02-11 21:49:54 +08:00
|
|
|
|
|
|
|
if (chan < 0 || chan >= ADS1015_CHANNELS)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2017-07-20 23:24:22 +08:00
|
|
|
ret = regmap_read(data->regmap, ADS1015_CFG_REG, &old);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
pga = data->channel_data[chan].pga;
|
|
|
|
dr = data->channel_data[chan].data_rate;
|
2017-07-20 23:24:22 +08:00
|
|
|
mask = ADS1015_CFG_MUX_MASK | ADS1015_CFG_PGA_MASK |
|
|
|
|
ADS1015_CFG_DR_MASK;
|
|
|
|
cfg = chan << ADS1015_CFG_MUX_SHIFT | pga << ADS1015_CFG_PGA_SHIFT |
|
|
|
|
dr << ADS1015_CFG_DR_SHIFT;
|
2016-02-11 21:49:54 +08:00
|
|
|
|
2017-07-20 23:24:27 +08:00
|
|
|
if (ads1015_event_channel_enabled(data)) {
|
|
|
|
mask |= ADS1015_CFG_COMP_QUE_MASK | ADS1015_CFG_COMP_MODE_MASK;
|
|
|
|
cfg |= data->thresh_data[chan].comp_queue <<
|
|
|
|
ADS1015_CFG_COMP_QUE_SHIFT |
|
|
|
|
data->comp_mode <<
|
|
|
|
ADS1015_CFG_COMP_MODE_SHIFT;
|
|
|
|
}
|
|
|
|
|
2017-07-20 23:24:22 +08:00
|
|
|
cfg = (old & ~mask) | (cfg & mask);
|
2017-08-24 16:25:51 +08:00
|
|
|
if (old != cfg) {
|
|
|
|
ret = regmap_write(data->regmap, ADS1015_CFG_REG, cfg);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
data->conv_invalid = true;
|
|
|
|
}
|
|
|
|
if (data->conv_invalid) {
|
|
|
|
dr_old = (old & ADS1015_CFG_DR_MASK) >> ADS1015_CFG_DR_SHIFT;
|
2022-03-29 03:47:24 +08:00
|
|
|
conv_time = DIV_ROUND_UP(USEC_PER_SEC, data_rate[dr_old]);
|
|
|
|
conv_time += DIV_ROUND_UP(USEC_PER_SEC, data_rate[dr]);
|
2017-08-25 13:39:16 +08:00
|
|
|
conv_time += conv_time / 10; /* 10% internal clock inaccuracy */
|
2016-02-11 21:49:54 +08:00
|
|
|
usleep_range(conv_time, conv_time + 1);
|
2017-07-20 23:24:20 +08:00
|
|
|
data->conv_invalid = false;
|
2016-02-11 21:49:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return regmap_read(data->regmap, ADS1015_CONV_REG, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t ads1015_trigger_handler(int irq, void *p)
|
|
|
|
{
|
|
|
|
struct iio_poll_func *pf = p;
|
|
|
|
struct iio_dev *indio_dev = pf->indio_dev;
|
|
|
|
struct ads1015_data *data = iio_priv(indio_dev);
|
2021-05-02 01:01:10 +08:00
|
|
|
/* Ensure natural alignment of timestamp */
|
|
|
|
struct {
|
|
|
|
s16 chan;
|
|
|
|
s64 timestamp __aligned(8);
|
|
|
|
} scan;
|
2016-02-11 21:49:54 +08:00
|
|
|
int chan, ret, res;
|
|
|
|
|
2021-05-02 01:01:10 +08:00
|
|
|
memset(&scan, 0, sizeof(scan));
|
2016-02-11 21:49:54 +08:00
|
|
|
|
|
|
|
mutex_lock(&data->lock);
|
|
|
|
chan = find_first_bit(indio_dev->active_scan_mask,
|
|
|
|
indio_dev->masklength);
|
|
|
|
ret = ads1015_get_adc_result(data, chan, &res);
|
|
|
|
if (ret < 0) {
|
|
|
|
mutex_unlock(&data->lock);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2021-05-02 01:01:10 +08:00
|
|
|
scan.chan = res;
|
2016-02-11 21:49:54 +08:00
|
|
|
mutex_unlock(&data->lock);
|
|
|
|
|
2021-05-02 01:01:10 +08:00
|
|
|
iio_push_to_buffers_with_timestamp(indio_dev, &scan,
|
2016-03-10 02:05:49 +08:00
|
|
|
iio_get_time_ns(indio_dev));
|
2016-02-11 21:49:54 +08:00
|
|
|
|
|
|
|
err:
|
|
|
|
iio_trigger_notify_done(indio_dev->trig);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2017-07-20 23:24:18 +08:00
|
|
|
static int ads1015_set_scale(struct ads1015_data *data,
|
|
|
|
struct iio_chan_spec const *chan,
|
2016-02-11 21:49:54 +08:00
|
|
|
int scale, int uscale)
|
|
|
|
{
|
2017-07-20 23:24:23 +08:00
|
|
|
int i;
|
2017-07-20 23:24:18 +08:00
|
|
|
int fullscale = div_s64((scale * 1000000LL + uscale) <<
|
|
|
|
(chan->scan_type.realbits - 1), 1000000);
|
2016-02-11 21:49:54 +08:00
|
|
|
|
2017-07-20 23:24:18 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(ads1015_fullscale_range); i++) {
|
|
|
|
if (ads1015_fullscale_range[i] == fullscale) {
|
2017-07-20 23:24:23 +08:00
|
|
|
data->channel_data[chan->address].pga = i;
|
|
|
|
return 0;
|
2016-02-11 21:49:54 +08:00
|
|
|
}
|
2017-07-20 23:24:18 +08:00
|
|
|
}
|
2016-02-11 21:49:54 +08:00
|
|
|
|
2017-07-20 23:24:23 +08:00
|
|
|
return -EINVAL;
|
2016-02-11 21:49:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ads1015_set_data_rate(struct ads1015_data *data, int chan, int rate)
|
|
|
|
{
|
2017-07-20 23:24:17 +08:00
|
|
|
int i;
|
2016-02-11 21:49:54 +08:00
|
|
|
|
2022-03-29 03:47:25 +08:00
|
|
|
for (i = 0; i < data->chip->data_rate_len; i++) {
|
2022-03-29 03:47:24 +08:00
|
|
|
if (data->chip->data_rate[i] == rate) {
|
2017-07-20 23:24:17 +08:00
|
|
|
data->channel_data[chan].data_rate = i;
|
|
|
|
return 0;
|
2016-02-11 21:49:54 +08:00
|
|
|
}
|
2017-07-20 23:24:17 +08:00
|
|
|
}
|
2016-02-11 21:49:54 +08:00
|
|
|
|
2017-07-20 23:24:17 +08:00
|
|
|
return -EINVAL;
|
2016-02-11 21:49:54 +08:00
|
|
|
}
|
|
|
|
|
2022-03-29 03:47:25 +08:00
|
|
|
static int ads1015_read_avail(struct iio_dev *indio_dev,
|
|
|
|
struct iio_chan_spec const *chan,
|
|
|
|
const int **vals, int *type, int *length,
|
|
|
|
long mask)
|
|
|
|
{
|
|
|
|
struct ads1015_data *data = iio_priv(indio_dev);
|
|
|
|
|
|
|
|
if (chan->type != IIO_VOLTAGE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
switch (mask) {
|
|
|
|
case IIO_CHAN_INFO_SCALE:
|
|
|
|
*type = IIO_VAL_FRACTIONAL_LOG2;
|
|
|
|
*vals = data->chip->scale;
|
|
|
|
*length = data->chip->scale_len;
|
|
|
|
return IIO_AVAIL_LIST;
|
|
|
|
case IIO_CHAN_INFO_SAMP_FREQ:
|
|
|
|
*type = IIO_VAL_INT;
|
|
|
|
*vals = data->chip->data_rate;
|
|
|
|
*length = data->chip->data_rate_len;
|
|
|
|
return IIO_AVAIL_LIST;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
static int ads1015_read_raw(struct iio_dev *indio_dev,
|
|
|
|
struct iio_chan_spec const *chan, int *val,
|
|
|
|
int *val2, long mask)
|
|
|
|
{
|
|
|
|
int ret, idx;
|
|
|
|
struct ads1015_data *data = iio_priv(indio_dev);
|
|
|
|
|
|
|
|
mutex_lock(&data->lock);
|
|
|
|
switch (mask) {
|
2021-11-04 16:24:11 +08:00
|
|
|
case IIO_CHAN_INFO_RAW:
|
2017-07-20 23:24:26 +08:00
|
|
|
ret = iio_device_claim_direct_mode(indio_dev);
|
|
|
|
if (ret)
|
2016-02-11 21:49:54 +08:00
|
|
|
break;
|
|
|
|
|
2017-07-20 23:24:27 +08:00
|
|
|
if (ads1015_event_channel_enabled(data) &&
|
|
|
|
data->event_channel != chan->address) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto release_direct;
|
|
|
|
}
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
ret = ads1015_set_power_state(data, true);
|
|
|
|
if (ret < 0)
|
2017-07-20 23:24:26 +08:00
|
|
|
goto release_direct;
|
2016-02-11 21:49:54 +08:00
|
|
|
|
|
|
|
ret = ads1015_get_adc_result(data, chan->address, val);
|
|
|
|
if (ret < 0) {
|
|
|
|
ads1015_set_power_state(data, false);
|
2017-07-20 23:24:26 +08:00
|
|
|
goto release_direct;
|
2016-02-11 21:49:54 +08:00
|
|
|
}
|
|
|
|
|
2021-11-04 16:24:11 +08:00
|
|
|
*val = sign_extend32(*val >> chan->scan_type.shift,
|
|
|
|
chan->scan_type.realbits - 1);
|
2016-02-11 21:49:54 +08:00
|
|
|
|
|
|
|
ret = ads1015_set_power_state(data, false);
|
|
|
|
if (ret < 0)
|
2017-07-20 23:24:26 +08:00
|
|
|
goto release_direct;
|
2016-02-11 21:49:54 +08:00
|
|
|
|
|
|
|
ret = IIO_VAL_INT;
|
2017-07-20 23:24:26 +08:00
|
|
|
release_direct:
|
|
|
|
iio_device_release_direct_mode(indio_dev);
|
2016-02-11 21:49:54 +08:00
|
|
|
break;
|
|
|
|
case IIO_CHAN_INFO_SCALE:
|
|
|
|
idx = data->channel_data[chan->address].pga;
|
2017-07-20 23:24:18 +08:00
|
|
|
*val = ads1015_fullscale_range[idx];
|
|
|
|
*val2 = chan->scan_type.realbits - 1;
|
|
|
|
ret = IIO_VAL_FRACTIONAL_LOG2;
|
2016-02-11 21:49:54 +08:00
|
|
|
break;
|
|
|
|
case IIO_CHAN_INFO_SAMP_FREQ:
|
|
|
|
idx = data->channel_data[chan->address].data_rate;
|
2022-03-29 03:47:24 +08:00
|
|
|
*val = data->chip->data_rate[idx];
|
2016-02-11 21:49:54 +08:00
|
|
|
ret = IIO_VAL_INT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mutex_unlock(&data->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ads1015_write_raw(struct iio_dev *indio_dev,
|
|
|
|
struct iio_chan_spec const *chan, int val,
|
|
|
|
int val2, long mask)
|
|
|
|
{
|
|
|
|
struct ads1015_data *data = iio_priv(indio_dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&data->lock);
|
|
|
|
switch (mask) {
|
|
|
|
case IIO_CHAN_INFO_SCALE:
|
2017-07-20 23:24:18 +08:00
|
|
|
ret = ads1015_set_scale(data, chan, val, val2);
|
2016-02-11 21:49:54 +08:00
|
|
|
break;
|
|
|
|
case IIO_CHAN_INFO_SAMP_FREQ:
|
|
|
|
ret = ads1015_set_data_rate(data, chan->address, val);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mutex_unlock(&data->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-07-20 23:24:27 +08:00
|
|
|
static int ads1015_read_event(struct iio_dev *indio_dev,
|
|
|
|
const struct iio_chan_spec *chan, enum iio_event_type type,
|
|
|
|
enum iio_event_direction dir, enum iio_event_info info, int *val,
|
|
|
|
int *val2)
|
|
|
|
{
|
|
|
|
struct ads1015_data *data = iio_priv(indio_dev);
|
|
|
|
int ret;
|
|
|
|
unsigned int comp_queue;
|
|
|
|
int period;
|
|
|
|
int dr;
|
|
|
|
|
|
|
|
mutex_lock(&data->lock);
|
|
|
|
|
|
|
|
switch (info) {
|
|
|
|
case IIO_EV_INFO_VALUE:
|
|
|
|
*val = (dir == IIO_EV_DIR_RISING) ?
|
|
|
|
data->thresh_data[chan->address].high_thresh :
|
|
|
|
data->thresh_data[chan->address].low_thresh;
|
|
|
|
ret = IIO_VAL_INT;
|
|
|
|
break;
|
|
|
|
case IIO_EV_INFO_PERIOD:
|
|
|
|
dr = data->channel_data[chan->address].data_rate;
|
|
|
|
comp_queue = data->thresh_data[chan->address].comp_queue;
|
|
|
|
period = ads1015_comp_queue[comp_queue] *
|
2022-03-29 03:47:24 +08:00
|
|
|
USEC_PER_SEC / data->chip->data_rate[dr];
|
2017-07-20 23:24:27 +08:00
|
|
|
|
|
|
|
*val = period / USEC_PER_SEC;
|
|
|
|
*val2 = period % USEC_PER_SEC;
|
|
|
|
ret = IIO_VAL_INT_PLUS_MICRO;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&data->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ads1015_write_event(struct iio_dev *indio_dev,
|
|
|
|
const struct iio_chan_spec *chan, enum iio_event_type type,
|
|
|
|
enum iio_event_direction dir, enum iio_event_info info, int val,
|
|
|
|
int val2)
|
|
|
|
{
|
|
|
|
struct ads1015_data *data = iio_priv(indio_dev);
|
2022-03-29 03:47:24 +08:00
|
|
|
const int *data_rate = data->chip->data_rate;
|
2017-07-20 23:24:27 +08:00
|
|
|
int realbits = chan->scan_type.realbits;
|
|
|
|
int ret = 0;
|
|
|
|
long long period;
|
|
|
|
int i;
|
|
|
|
int dr;
|
|
|
|
|
|
|
|
mutex_lock(&data->lock);
|
|
|
|
|
|
|
|
switch (info) {
|
|
|
|
case IIO_EV_INFO_VALUE:
|
|
|
|
if (val >= 1 << (realbits - 1) || val < -1 << (realbits - 1)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (dir == IIO_EV_DIR_RISING)
|
|
|
|
data->thresh_data[chan->address].high_thresh = val;
|
|
|
|
else
|
|
|
|
data->thresh_data[chan->address].low_thresh = val;
|
|
|
|
break;
|
|
|
|
case IIO_EV_INFO_PERIOD:
|
|
|
|
dr = data->channel_data[chan->address].data_rate;
|
|
|
|
period = val * USEC_PER_SEC + val2;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ads1015_comp_queue) - 1; i++) {
|
|
|
|
if (period <= ads1015_comp_queue[i] *
|
2022-03-29 03:47:24 +08:00
|
|
|
USEC_PER_SEC / data_rate[dr])
|
2017-07-20 23:24:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
data->thresh_data[chan->address].comp_queue = i;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&data->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ads1015_read_event_config(struct iio_dev *indio_dev,
|
|
|
|
const struct iio_chan_spec *chan, enum iio_event_type type,
|
|
|
|
enum iio_event_direction dir)
|
|
|
|
{
|
|
|
|
struct ads1015_data *data = iio_priv(indio_dev);
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
mutex_lock(&data->lock);
|
|
|
|
if (data->event_channel == chan->address) {
|
|
|
|
switch (dir) {
|
|
|
|
case IIO_EV_DIR_RISING:
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
case IIO_EV_DIR_EITHER:
|
|
|
|
ret = (data->comp_mode == ADS1015_CFG_COMP_MODE_WINDOW);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&data->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ads1015_enable_event_config(struct ads1015_data *data,
|
|
|
|
const struct iio_chan_spec *chan, int comp_mode)
|
|
|
|
{
|
|
|
|
int low_thresh = data->thresh_data[chan->address].low_thresh;
|
|
|
|
int high_thresh = data->thresh_data[chan->address].high_thresh;
|
|
|
|
int ret;
|
|
|
|
unsigned int val;
|
|
|
|
|
|
|
|
if (ads1015_event_channel_enabled(data)) {
|
|
|
|
if (data->event_channel != chan->address ||
|
|
|
|
(data->comp_mode == ADS1015_CFG_COMP_MODE_TRAD &&
|
|
|
|
comp_mode == ADS1015_CFG_COMP_MODE_WINDOW))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (comp_mode == ADS1015_CFG_COMP_MODE_TRAD) {
|
|
|
|
low_thresh = max(-1 << (chan->scan_type.realbits - 1),
|
|
|
|
high_thresh - 1);
|
|
|
|
}
|
|
|
|
ret = regmap_write(data->regmap, ADS1015_LO_THRESH_REG,
|
|
|
|
low_thresh << chan->scan_type.shift);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = regmap_write(data->regmap, ADS1015_HI_THRESH_REG,
|
|
|
|
high_thresh << chan->scan_type.shift);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = ads1015_set_power_state(data, true);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ads1015_event_channel_enable(data, chan->address, comp_mode);
|
|
|
|
|
|
|
|
ret = ads1015_get_adc_result(data, chan->address, &val);
|
|
|
|
if (ret) {
|
|
|
|
ads1015_event_channel_disable(data, chan->address);
|
|
|
|
ads1015_set_power_state(data, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ads1015_disable_event_config(struct ads1015_data *data,
|
|
|
|
const struct iio_chan_spec *chan, int comp_mode)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!ads1015_event_channel_enabled(data))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (data->event_channel != chan->address)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (data->comp_mode == ADS1015_CFG_COMP_MODE_TRAD &&
|
|
|
|
comp_mode == ADS1015_CFG_COMP_MODE_WINDOW)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = regmap_update_bits(data->regmap, ADS1015_CFG_REG,
|
|
|
|
ADS1015_CFG_COMP_QUE_MASK,
|
|
|
|
ADS1015_CFG_COMP_DISABLE <<
|
|
|
|
ADS1015_CFG_COMP_QUE_SHIFT);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ads1015_event_channel_disable(data, chan->address);
|
|
|
|
|
|
|
|
return ads1015_set_power_state(data, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ads1015_write_event_config(struct iio_dev *indio_dev,
|
|
|
|
const struct iio_chan_spec *chan, enum iio_event_type type,
|
|
|
|
enum iio_event_direction dir, int state)
|
|
|
|
{
|
|
|
|
struct ads1015_data *data = iio_priv(indio_dev);
|
|
|
|
int ret;
|
|
|
|
int comp_mode = (dir == IIO_EV_DIR_EITHER) ?
|
|
|
|
ADS1015_CFG_COMP_MODE_WINDOW : ADS1015_CFG_COMP_MODE_TRAD;
|
|
|
|
|
|
|
|
mutex_lock(&data->lock);
|
|
|
|
|
|
|
|
/* Prevent from enabling both buffer and event at a time */
|
|
|
|
ret = iio_device_claim_direct_mode(indio_dev);
|
|
|
|
if (ret) {
|
|
|
|
mutex_unlock(&data->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
ret = ads1015_enable_event_config(data, chan, comp_mode);
|
|
|
|
else
|
|
|
|
ret = ads1015_disable_event_config(data, chan, comp_mode);
|
|
|
|
|
|
|
|
iio_device_release_direct_mode(indio_dev);
|
|
|
|
mutex_unlock(&data->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t ads1015_event_handler(int irq, void *priv)
|
|
|
|
{
|
|
|
|
struct iio_dev *indio_dev = priv;
|
|
|
|
struct ads1015_data *data = iio_priv(indio_dev);
|
|
|
|
int val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Clear the latched ALERT/RDY pin */
|
|
|
|
ret = regmap_read(data->regmap, ADS1015_CONV_REG, &val);
|
|
|
|
if (ret)
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
|
|
|
if (ads1015_event_channel_enabled(data)) {
|
|
|
|
enum iio_event_direction dir;
|
|
|
|
u64 code;
|
|
|
|
|
|
|
|
dir = data->comp_mode == ADS1015_CFG_COMP_MODE_TRAD ?
|
|
|
|
IIO_EV_DIR_RISING : IIO_EV_DIR_EITHER;
|
|
|
|
code = IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, data->event_channel,
|
|
|
|
IIO_EV_TYPE_THRESH, dir);
|
|
|
|
iio_push_event(indio_dev, code, iio_get_time_ns(indio_dev));
|
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
static int ads1015_buffer_preenable(struct iio_dev *indio_dev)
|
|
|
|
{
|
2017-07-20 23:24:27 +08:00
|
|
|
struct ads1015_data *data = iio_priv(indio_dev);
|
|
|
|
|
|
|
|
/* Prevent from enabling both buffer and event at a time */
|
|
|
|
if (ads1015_event_channel_enabled(data))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
return ads1015_set_power_state(iio_priv(indio_dev), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ads1015_buffer_postdisable(struct iio_dev *indio_dev)
|
|
|
|
{
|
|
|
|
return ads1015_set_power_state(iio_priv(indio_dev), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct iio_buffer_setup_ops ads1015_buffer_setup_ops = {
|
|
|
|
.preenable = ads1015_buffer_preenable,
|
|
|
|
.postdisable = ads1015_buffer_postdisable,
|
|
|
|
.validate_scan_mask = &iio_validate_scan_mask_onehot,
|
|
|
|
};
|
|
|
|
|
2017-01-22 01:03:00 +08:00
|
|
|
static const struct iio_info ads1015_info = {
|
2022-03-29 03:47:25 +08:00
|
|
|
.read_avail = ads1015_read_avail,
|
2016-05-16 13:18:46 +08:00
|
|
|
.read_raw = ads1015_read_raw,
|
|
|
|
.write_raw = ads1015_write_raw,
|
2017-07-20 23:24:27 +08:00
|
|
|
.read_event_value = ads1015_read_event,
|
|
|
|
.write_event_value = ads1015_write_event,
|
|
|
|
.read_event_config = ads1015_read_event_config,
|
|
|
|
.write_event_config = ads1015_write_event_config,
|
2016-02-11 21:49:54 +08:00
|
|
|
};
|
|
|
|
|
2022-03-29 03:47:21 +08:00
|
|
|
static const struct iio_info tla2024_info = {
|
2022-03-29 03:47:25 +08:00
|
|
|
.read_avail = ads1015_read_avail,
|
2022-03-29 03:47:21 +08:00
|
|
|
.read_raw = ads1015_read_raw,
|
|
|
|
.write_raw = ads1015_write_raw,
|
|
|
|
};
|
|
|
|
|
2019-12-06 01:46:37 +08:00
|
|
|
static int ads1015_client_get_channels_config(struct i2c_client *client)
|
2016-02-11 21:49:54 +08:00
|
|
|
{
|
2016-08-17 02:43:37 +08:00
|
|
|
struct iio_dev *indio_dev = i2c_get_clientdata(client);
|
|
|
|
struct ads1015_data *data = iio_priv(indio_dev);
|
2019-12-06 01:46:37 +08:00
|
|
|
struct device *dev = &client->dev;
|
|
|
|
struct fwnode_handle *node;
|
|
|
|
int i = -1;
|
2016-02-11 21:49:54 +08:00
|
|
|
|
2019-12-06 01:46:37 +08:00
|
|
|
device_for_each_child_node(dev, node) {
|
2016-02-11 21:49:54 +08:00
|
|
|
u32 pval;
|
|
|
|
unsigned int channel;
|
|
|
|
unsigned int pga = ADS1015_DEFAULT_PGA;
|
|
|
|
unsigned int data_rate = ADS1015_DEFAULT_DATA_RATE;
|
|
|
|
|
2019-12-06 01:46:37 +08:00
|
|
|
if (fwnode_property_read_u32(node, "reg", &pval)) {
|
|
|
|
dev_err(dev, "invalid reg on %pfw\n", node);
|
2016-02-11 21:49:54 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel = pval;
|
|
|
|
if (channel >= ADS1015_CHANNELS) {
|
2019-12-06 01:46:37 +08:00
|
|
|
dev_err(dev, "invalid channel index %d on %pfw\n",
|
2017-07-19 05:43:08 +08:00
|
|
|
channel, node);
|
2016-02-11 21:49:54 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-12-06 01:46:37 +08:00
|
|
|
if (!fwnode_property_read_u32(node, "ti,gain", &pval)) {
|
2016-02-11 21:49:54 +08:00
|
|
|
pga = pval;
|
|
|
|
if (pga > 6) {
|
2019-12-06 01:46:37 +08:00
|
|
|
dev_err(dev, "invalid gain on %pfw\n", node);
|
|
|
|
fwnode_handle_put(node);
|
2016-02-11 21:49:54 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 01:46:37 +08:00
|
|
|
if (!fwnode_property_read_u32(node, "ti,datarate", &pval)) {
|
2016-02-11 21:49:54 +08:00
|
|
|
data_rate = pval;
|
|
|
|
if (data_rate > 7) {
|
2019-12-06 01:46:37 +08:00
|
|
|
dev_err(dev, "invalid data_rate on %pfw\n", node);
|
|
|
|
fwnode_handle_put(node);
|
2016-02-11 21:49:54 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data->channel_data[channel].pga = pga;
|
|
|
|
data->channel_data[channel].data_rate = data_rate;
|
2019-12-06 01:46:37 +08:00
|
|
|
|
|
|
|
i++;
|
2016-02-11 21:49:54 +08:00
|
|
|
}
|
|
|
|
|
2019-12-06 01:46:37 +08:00
|
|
|
return i < 0 ? -EINVAL : 0;
|
2016-02-11 21:49:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ads1015_get_channels_config(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
unsigned int k;
|
|
|
|
|
|
|
|
struct iio_dev *indio_dev = i2c_get_clientdata(client);
|
|
|
|
struct ads1015_data *data = iio_priv(indio_dev);
|
|
|
|
|
2019-12-06 01:46:37 +08:00
|
|
|
if (!ads1015_client_get_channels_config(client))
|
2016-02-11 21:49:54 +08:00
|
|
|
return;
|
2019-12-06 01:46:37 +08:00
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
/* fallback on default configuration */
|
|
|
|
for (k = 0; k < ADS1015_CHANNELS; ++k) {
|
|
|
|
data->channel_data[k].pga = ADS1015_DEFAULT_PGA;
|
|
|
|
data->channel_data[k].data_rate = ADS1015_DEFAULT_DATA_RATE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-20 23:24:24 +08:00
|
|
|
static int ads1015_set_conv_mode(struct ads1015_data *data, int mode)
|
|
|
|
{
|
|
|
|
return regmap_update_bits(data->regmap, ADS1015_CFG_REG,
|
|
|
|
ADS1015_CFG_MOD_MASK,
|
|
|
|
mode << ADS1015_CFG_MOD_SHIFT);
|
|
|
|
}
|
|
|
|
|
2022-11-19 06:36:44 +08:00
|
|
|
static int ads1015_probe(struct i2c_client *client)
|
2016-02-11 21:49:54 +08:00
|
|
|
{
|
2022-11-19 06:36:44 +08:00
|
|
|
const struct i2c_device_id *id = i2c_client_get_device_id(client);
|
2022-03-29 03:47:23 +08:00
|
|
|
const struct ads1015_chip_data *chip;
|
2016-02-11 21:49:54 +08:00
|
|
|
struct iio_dev *indio_dev;
|
|
|
|
struct ads1015_data *data;
|
|
|
|
int ret;
|
2017-07-20 23:24:27 +08:00
|
|
|
int i;
|
2016-02-11 21:49:54 +08:00
|
|
|
|
2022-03-29 03:47:23 +08:00
|
|
|
chip = device_get_match_data(&client->dev);
|
|
|
|
if (!chip)
|
|
|
|
chip = (const struct ads1015_chip_data *)id->driver_data;
|
|
|
|
if (!chip)
|
|
|
|
return dev_err_probe(&client->dev, -EINVAL, "Unknown chip\n");
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
|
|
|
|
if (!indio_dev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
data = iio_priv(indio_dev);
|
|
|
|
i2c_set_clientdata(client, indio_dev);
|
|
|
|
|
|
|
|
mutex_init(&data->lock);
|
|
|
|
|
|
|
|
indio_dev->name = ADS1015_DRV_NAME;
|
|
|
|
indio_dev->modes = INDIO_DIRECT_MODE;
|
|
|
|
|
2022-03-29 03:47:23 +08:00
|
|
|
indio_dev->channels = chip->channels;
|
|
|
|
indio_dev->num_channels = chip->num_channels;
|
|
|
|
indio_dev->info = chip->info;
|
2022-03-29 03:47:24 +08:00
|
|
|
data->chip = chip;
|
2017-07-20 23:24:27 +08:00
|
|
|
data->event_channel = ADS1015_CHANNELS;
|
2022-03-29 03:47:23 +08:00
|
|
|
|
2017-07-20 23:24:27 +08:00
|
|
|
/*
|
|
|
|
* Set default lower and upper threshold to min and max value
|
|
|
|
* respectively.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ADS1015_CHANNELS; i++) {
|
|
|
|
int realbits = indio_dev->channels[i].scan_type.realbits;
|
|
|
|
|
|
|
|
data->thresh_data[i].low_thresh = -1 << (realbits - 1);
|
|
|
|
data->thresh_data[i].high_thresh = (1 << (realbits - 1)) - 1;
|
|
|
|
}
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
/* we need to keep this ABI the same as used by hwmon ADS1015 driver */
|
|
|
|
ads1015_get_channels_config(client);
|
|
|
|
|
2022-03-29 03:47:23 +08:00
|
|
|
data->regmap = devm_regmap_init_i2c(client, chip->has_comparator ?
|
|
|
|
&ads1015_regmap_config :
|
|
|
|
&tla2024_regmap_config);
|
2016-02-11 21:49:54 +08:00
|
|
|
if (IS_ERR(data->regmap)) {
|
|
|
|
dev_err(&client->dev, "Failed to allocate register map\n");
|
|
|
|
return PTR_ERR(data->regmap);
|
|
|
|
}
|
|
|
|
|
2017-07-20 23:24:25 +08:00
|
|
|
ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL,
|
|
|
|
ads1015_trigger_handler,
|
|
|
|
&ads1015_buffer_setup_ops);
|
2016-02-11 21:49:54 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "iio triggered buffer setup failed\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2017-07-20 23:24:19 +08:00
|
|
|
|
2022-03-29 03:47:23 +08:00
|
|
|
if (client->irq && chip->has_comparator) {
|
2017-07-20 23:24:27 +08:00
|
|
|
unsigned long irq_trig =
|
|
|
|
irqd_get_trigger_type(irq_get_irq_data(client->irq));
|
|
|
|
unsigned int cfg_comp_mask = ADS1015_CFG_COMP_QUE_MASK |
|
|
|
|
ADS1015_CFG_COMP_LAT_MASK | ADS1015_CFG_COMP_POL_MASK;
|
|
|
|
unsigned int cfg_comp =
|
|
|
|
ADS1015_CFG_COMP_DISABLE << ADS1015_CFG_COMP_QUE_SHIFT |
|
|
|
|
1 << ADS1015_CFG_COMP_LAT_SHIFT;
|
|
|
|
|
|
|
|
switch (irq_trig) {
|
|
|
|
case IRQF_TRIGGER_LOW:
|
2017-08-24 08:22:57 +08:00
|
|
|
cfg_comp |= ADS1015_CFG_COMP_POL_LOW <<
|
|
|
|
ADS1015_CFG_COMP_POL_SHIFT;
|
2017-07-20 23:24:27 +08:00
|
|
|
break;
|
|
|
|
case IRQF_TRIGGER_HIGH:
|
2017-08-24 08:22:57 +08:00
|
|
|
cfg_comp |= ADS1015_CFG_COMP_POL_HIGH <<
|
|
|
|
ADS1015_CFG_COMP_POL_SHIFT;
|
2017-07-20 23:24:27 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = regmap_update_bits(data->regmap, ADS1015_CFG_REG,
|
|
|
|
cfg_comp_mask, cfg_comp);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = devm_request_threaded_irq(&client->dev, client->irq,
|
|
|
|
NULL, ads1015_event_handler,
|
|
|
|
irq_trig | IRQF_ONESHOT,
|
|
|
|
client->name, indio_dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-07-20 23:24:24 +08:00
|
|
|
ret = ads1015_set_conv_mode(data, ADS1015_CONTINUOUS);
|
2017-07-20 23:24:19 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2017-07-20 23:24:20 +08:00
|
|
|
data->conv_invalid = true;
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
ret = pm_runtime_set_active(&client->dev);
|
|
|
|
if (ret)
|
2017-07-20 23:24:25 +08:00
|
|
|
return ret;
|
2016-02-11 21:49:54 +08:00
|
|
|
pm_runtime_set_autosuspend_delay(&client->dev, ADS1015_SLEEP_DELAY_MS);
|
|
|
|
pm_runtime_use_autosuspend(&client->dev);
|
|
|
|
pm_runtime_enable(&client->dev);
|
|
|
|
|
|
|
|
ret = iio_device_register(indio_dev);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "Failed to register IIO device\n");
|
2017-07-20 23:24:25 +08:00
|
|
|
return ret;
|
2016-02-11 21:49:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-08-15 16:02:30 +08:00
|
|
|
static void ads1015_remove(struct i2c_client *client)
|
2016-02-11 21:49:54 +08:00
|
|
|
{
|
|
|
|
struct iio_dev *indio_dev = i2c_get_clientdata(client);
|
|
|
|
struct ads1015_data *data = iio_priv(indio_dev);
|
2022-05-15 23:59:23 +08:00
|
|
|
int ret;
|
2016-02-11 21:49:54 +08:00
|
|
|
|
|
|
|
iio_device_unregister(indio_dev);
|
|
|
|
|
|
|
|
pm_runtime_disable(&client->dev);
|
|
|
|
pm_runtime_set_suspended(&client->dev);
|
|
|
|
|
|
|
|
/* power down single shot mode */
|
2022-05-15 23:59:23 +08:00
|
|
|
ret = ads1015_set_conv_mode(data, ADS1015_SINGLESHOT);
|
|
|
|
if (ret)
|
|
|
|
dev_warn(&client->dev, "Failed to power down (%pe)\n",
|
|
|
|
ERR_PTR(ret));
|
2016-02-11 21:49:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int ads1015_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
|
|
|
|
struct ads1015_data *data = iio_priv(indio_dev);
|
|
|
|
|
2017-07-20 23:24:24 +08:00
|
|
|
return ads1015_set_conv_mode(data, ADS1015_SINGLESHOT);
|
2016-02-11 21:49:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ads1015_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
|
|
|
|
struct ads1015_data *data = iio_priv(indio_dev);
|
2017-07-20 23:24:20 +08:00
|
|
|
int ret;
|
2016-02-11 21:49:54 +08:00
|
|
|
|
2017-07-20 23:24:24 +08:00
|
|
|
ret = ads1015_set_conv_mode(data, ADS1015_CONTINUOUS);
|
2017-07-20 23:24:20 +08:00
|
|
|
if (!ret)
|
|
|
|
data->conv_invalid = true;
|
|
|
|
|
|
|
|
return ret;
|
2016-02-11 21:49:54 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const struct dev_pm_ops ads1015_pm_ops = {
|
|
|
|
SET_RUNTIME_PM_OPS(ads1015_runtime_suspend,
|
|
|
|
ads1015_runtime_resume, NULL)
|
|
|
|
};
|
|
|
|
|
2022-03-29 03:47:23 +08:00
|
|
|
static const struct ads1015_chip_data ads1015_data = {
|
|
|
|
.channels = ads1015_channels,
|
|
|
|
.num_channels = ARRAY_SIZE(ads1015_channels),
|
|
|
|
.info = &ads1015_info,
|
|
|
|
.data_rate = ads1015_data_rate,
|
2022-03-29 03:47:25 +08:00
|
|
|
.data_rate_len = ARRAY_SIZE(ads1015_data_rate),
|
|
|
|
.scale = ads1015_scale,
|
|
|
|
.scale_len = ARRAY_SIZE(ads1015_scale),
|
2022-03-29 03:47:23 +08:00
|
|
|
.has_comparator = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ads1015_chip_data ads1115_data = {
|
|
|
|
.channels = ads1115_channels,
|
|
|
|
.num_channels = ARRAY_SIZE(ads1115_channels),
|
2022-03-29 03:47:25 +08:00
|
|
|
.info = &ads1015_info,
|
2022-03-29 03:47:23 +08:00
|
|
|
.data_rate = ads1115_data_rate,
|
2022-03-29 03:47:25 +08:00
|
|
|
.data_rate_len = ARRAY_SIZE(ads1115_data_rate),
|
|
|
|
.scale = ads1115_scale,
|
|
|
|
.scale_len = ARRAY_SIZE(ads1115_scale),
|
2022-03-29 03:47:23 +08:00
|
|
|
.has_comparator = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ads1015_chip_data tla2024_data = {
|
|
|
|
.channels = tla2024_channels,
|
|
|
|
.num_channels = ARRAY_SIZE(tla2024_channels),
|
|
|
|
.info = &tla2024_info,
|
|
|
|
.data_rate = ads1015_data_rate,
|
2022-03-29 03:47:25 +08:00
|
|
|
.data_rate_len = ARRAY_SIZE(ads1015_data_rate),
|
|
|
|
.scale = ads1015_scale,
|
|
|
|
.scale_len = ARRAY_SIZE(ads1015_scale),
|
2022-03-29 03:47:23 +08:00
|
|
|
.has_comparator = false,
|
|
|
|
};
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
static const struct i2c_device_id ads1015_id[] = {
|
2022-03-29 03:47:23 +08:00
|
|
|
{ "ads1015", (kernel_ulong_t)&ads1015_data },
|
|
|
|
{ "ads1115", (kernel_ulong_t)&ads1115_data },
|
|
|
|
{ "tla2024", (kernel_ulong_t)&tla2024_data },
|
2016-02-11 21:49:54 +08:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, ads1015_id);
|
|
|
|
|
2017-03-15 12:45:00 +08:00
|
|
|
static const struct of_device_id ads1015_of_match[] = {
|
2022-03-29 03:47:23 +08:00
|
|
|
{ .compatible = "ti,ads1015", .data = &ads1015_data },
|
|
|
|
{ .compatible = "ti,ads1115", .data = &ads1115_data },
|
|
|
|
{ .compatible = "ti,tla2024", .data = &tla2024_data },
|
2017-03-15 12:45:00 +08:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, ads1015_of_match);
|
|
|
|
|
2016-02-11 21:49:54 +08:00
|
|
|
static struct i2c_driver ads1015_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = ADS1015_DRV_NAME,
|
2017-03-15 12:45:00 +08:00
|
|
|
.of_match_table = ads1015_of_match,
|
2016-02-11 21:49:54 +08:00
|
|
|
.pm = &ads1015_pm_ops,
|
|
|
|
},
|
2023-05-16 04:50:48 +08:00
|
|
|
.probe = ads1015_probe,
|
2016-02-11 21:49:54 +08:00
|
|
|
.remove = ads1015_remove,
|
|
|
|
.id_table = ads1015_id,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_i2c_driver(ads1015_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>");
|
|
|
|
MODULE_DESCRIPTION("Texas Instruments ADS1015 ADC driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|