Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 1 | /* |
| 2 | * AD7152 capacitive sensor driver supporting AD7152/3 |
| 3 | * |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 4 | * Copyright 2010-2011a Analog Devices Inc. |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 5 | * |
| 6 | * Licensed under the GPL-2 or later. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/interrupt.h> |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 10 | #include <linux/device.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/sysfs.h> |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 14 | #include <linux/i2c.h> |
Paul Gortmaker | 99c9785 | 2011-07-03 15:49:50 -0400 | [diff] [blame] | 15 | #include <linux/module.h> |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 16 | #include <linux/delay.h> |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 17 | |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 18 | #include <linux/iio/iio.h> |
| 19 | #include <linux/iio/sysfs.h> |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 20 | |
| 21 | /* |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 22 | * TODO: Check compliance of calibbias with abi (units) |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 23 | */ |
| 24 | /* |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 25 | * AD7152 registers definition |
| 26 | */ |
| 27 | |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 28 | #define AD7152_REG_STATUS 0 |
| 29 | #define AD7152_REG_CH1_DATA_HIGH 1 |
| 30 | #define AD7152_REG_CH2_DATA_HIGH 3 |
| 31 | #define AD7152_REG_CH1_OFFS_HIGH 5 |
| 32 | #define AD7152_REG_CH2_OFFS_HIGH 7 |
| 33 | #define AD7152_REG_CH1_GAIN_HIGH 9 |
| 34 | #define AD7152_REG_CH1_SETUP 11 |
| 35 | #define AD7152_REG_CH2_GAIN_HIGH 12 |
| 36 | #define AD7152_REG_CH2_SETUP 14 |
| 37 | #define AD7152_REG_CFG 15 |
| 38 | #define AD7152_REG_RESEVERD 16 |
| 39 | #define AD7152_REG_CAPDAC_POS 17 |
| 40 | #define AD7152_REG_CAPDAC_NEG 18 |
| 41 | #define AD7152_REG_CFG2 26 |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 42 | |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 43 | /* Status Register Bit Designations (AD7152_REG_STATUS) */ |
| 44 | #define AD7152_STATUS_RDY1 (1 << 0) |
| 45 | #define AD7152_STATUS_RDY2 (1 << 1) |
| 46 | #define AD7152_STATUS_C1C2 (1 << 2) |
| 47 | #define AD7152_STATUS_PWDN (1 << 7) |
| 48 | |
| 49 | /* Setup Register Bit Designations (AD7152_REG_CHx_SETUP) */ |
| 50 | #define AD7152_SETUP_CAPDIFF (1 << 5) |
| 51 | #define AD7152_SETUP_RANGE_2pF (0 << 6) |
| 52 | #define AD7152_SETUP_RANGE_0_5pF (1 << 6) |
| 53 | #define AD7152_SETUP_RANGE_1pF (2 << 6) |
| 54 | #define AD7152_SETUP_RANGE_4pF (3 << 6) |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 55 | #define AD7152_SETUP_RANGE(x) ((x) << 6) |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 56 | |
| 57 | /* Config Register Bit Designations (AD7152_REG_CFG) */ |
| 58 | #define AD7152_CONF_CH2EN (1 << 3) |
| 59 | #define AD7152_CONF_CH1EN (1 << 4) |
| 60 | #define AD7152_CONF_MODE_IDLE (0 << 0) |
| 61 | #define AD7152_CONF_MODE_CONT_CONV (1 << 0) |
| 62 | #define AD7152_CONF_MODE_SINGLE_CONV (2 << 0) |
| 63 | #define AD7152_CONF_MODE_OFFS_CAL (5 << 0) |
| 64 | #define AD7152_CONF_MODE_GAIN_CAL (6 << 0) |
| 65 | |
| 66 | /* Capdac Register Bit Designations (AD7152_REG_CAPDAC_XXX) */ |
| 67 | #define AD7152_CAPDAC_DACEN (1 << 7) |
| 68 | #define AD7152_CAPDAC_DACP(x) ((x) & 0x1F) |
| 69 | |
Michael Hennerich | c3b7915 | 2011-09-02 17:25:30 +0100 | [diff] [blame] | 70 | /* CFG2 Register Bit Designations (AD7152_REG_CFG2) */ |
| 71 | #define AD7152_CFG2_OSR(x) (((x) & 0x3) << 4) |
| 72 | |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 73 | enum { |
| 74 | AD7152_DATA, |
| 75 | AD7152_OFFS, |
| 76 | AD7152_GAIN, |
| 77 | AD7152_SETUP |
| 78 | }; |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 79 | |
| 80 | /* |
Masanari Iida | e3c5be2 | 2014-04-22 12:23:00 +0100 | [diff] [blame] | 81 | * struct ad7152_chip_info - chip specific information |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 82 | */ |
| 83 | |
| 84 | struct ad7152_chip_info { |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 85 | struct i2c_client *client; |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 86 | /* |
| 87 | * Capacitive channel digital filter setup; |
| 88 | * conversion time/update rate setup per channel |
| 89 | */ |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 90 | u8 filter_rate_setup; |
| 91 | u8 setup[2]; |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 92 | }; |
| 93 | |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 94 | static inline ssize_t ad7152_start_calib(struct device *dev, |
| 95 | struct device_attribute *attr, |
| 96 | const char *buf, |
| 97 | size_t len, |
| 98 | u8 regval) |
| 99 | { |
Lars-Peter Clausen | d30a7f9 | 2012-05-12 15:39:45 +0200 | [diff] [blame] | 100 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 101 | struct ad7152_chip_info *chip = iio_priv(indio_dev); |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 102 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); |
| 103 | bool doit; |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 104 | int ret, timeout = 10; |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 105 | |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 106 | ret = strtobool(buf, &doit); |
| 107 | if (ret < 0) |
| 108 | return ret; |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 109 | |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 110 | if (!doit) |
| 111 | return 0; |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 112 | |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 113 | if (this_attr->address == 0) |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 114 | regval |= AD7152_CONF_CH1EN; |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 115 | else |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 116 | regval |= AD7152_CONF_CH2EN; |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 117 | |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 118 | mutex_lock(&indio_dev->mlock); |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 119 | ret = i2c_smbus_write_byte_data(chip->client, AD7152_REG_CFG, regval); |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 120 | if (ret < 0) { |
| 121 | mutex_unlock(&indio_dev->mlock); |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 122 | return ret; |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 123 | } |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 124 | |
| 125 | do { |
| 126 | mdelay(20); |
| 127 | ret = i2c_smbus_read_byte_data(chip->client, AD7152_REG_CFG); |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 128 | if (ret < 0) { |
| 129 | mutex_unlock(&indio_dev->mlock); |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 130 | return ret; |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 131 | } |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 132 | } while ((ret == regval) && timeout--); |
| 133 | |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 134 | mutex_unlock(&indio_dev->mlock); |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 135 | return len; |
| 136 | } |
| 137 | static ssize_t ad7152_start_offset_calib(struct device *dev, |
| 138 | struct device_attribute *attr, |
| 139 | const char *buf, |
| 140 | size_t len) |
| 141 | { |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 142 | return ad7152_start_calib(dev, attr, buf, len, |
| 143 | AD7152_CONF_MODE_OFFS_CAL); |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 144 | } |
| 145 | static ssize_t ad7152_start_gain_calib(struct device *dev, |
| 146 | struct device_attribute *attr, |
| 147 | const char *buf, |
| 148 | size_t len) |
| 149 | { |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 150 | return ad7152_start_calib(dev, attr, buf, len, |
| 151 | AD7152_CONF_MODE_GAIN_CAL); |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | static IIO_DEVICE_ATTR(in_capacitance0_calibbias_calibration, |
| 155 | S_IWUSR, NULL, ad7152_start_offset_calib, 0); |
| 156 | static IIO_DEVICE_ATTR(in_capacitance1_calibbias_calibration, |
| 157 | S_IWUSR, NULL, ad7152_start_offset_calib, 1); |
| 158 | static IIO_DEVICE_ATTR(in_capacitance0_calibscale_calibration, |
| 159 | S_IWUSR, NULL, ad7152_start_gain_calib, 0); |
| 160 | static IIO_DEVICE_ATTR(in_capacitance1_calibscale_calibration, |
| 161 | S_IWUSR, NULL, ad7152_start_gain_calib, 1); |
| 162 | |
Michael Hennerich | fe55a17 | 2011-09-02 17:25:31 +0100 | [diff] [blame] | 163 | /* Values are Update Rate (Hz), Conversion Time (ms) + 1*/ |
Michael Hennerich | c3b7915 | 2011-09-02 17:25:30 +0100 | [diff] [blame] | 164 | static const unsigned char ad7152_filter_rate_table[][2] = { |
Michael Hennerich | fe55a17 | 2011-09-02 17:25:31 +0100 | [diff] [blame] | 165 | {200, 5 + 1}, {50, 20 + 1}, {20, 50 + 1}, {17, 60 + 1}, |
Michael Hennerich | c3b7915 | 2011-09-02 17:25:30 +0100 | [diff] [blame] | 166 | }; |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 167 | |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 168 | static ssize_t ad7152_show_filter_rate_setup(struct device *dev, |
| 169 | struct device_attribute *attr, |
| 170 | char *buf) |
| 171 | { |
Lars-Peter Clausen | d30a7f9 | 2012-05-12 15:39:45 +0200 | [diff] [blame] | 172 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 173 | struct ad7152_chip_info *chip = iio_priv(indio_dev); |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 174 | |
Michael Hennerich | c3b7915 | 2011-09-02 17:25:30 +0100 | [diff] [blame] | 175 | return sprintf(buf, "%d\n", |
| 176 | ad7152_filter_rate_table[chip->filter_rate_setup][0]); |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | static ssize_t ad7152_store_filter_rate_setup(struct device *dev, |
| 180 | struct device_attribute *attr, |
| 181 | const char *buf, |
| 182 | size_t len) |
| 183 | { |
Lars-Peter Clausen | d30a7f9 | 2012-05-12 15:39:45 +0200 | [diff] [blame] | 184 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 185 | struct ad7152_chip_info *chip = iio_priv(indio_dev); |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 186 | u8 data; |
Michael Hennerich | c3b7915 | 2011-09-02 17:25:30 +0100 | [diff] [blame] | 187 | int ret, i; |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 188 | |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 189 | ret = kstrtou8(buf, 10, &data); |
| 190 | if (ret < 0) |
| 191 | return ret; |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 192 | |
Michael Hennerich | c3b7915 | 2011-09-02 17:25:30 +0100 | [diff] [blame] | 193 | for (i = 0; i < ARRAY_SIZE(ad7152_filter_rate_table); i++) |
| 194 | if (data >= ad7152_filter_rate_table[i][0]) |
| 195 | break; |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 196 | |
Michael Hennerich | c3b7915 | 2011-09-02 17:25:30 +0100 | [diff] [blame] | 197 | if (i >= ARRAY_SIZE(ad7152_filter_rate_table)) |
| 198 | i = ARRAY_SIZE(ad7152_filter_rate_table) - 1; |
| 199 | |
| 200 | mutex_lock(&indio_dev->mlock); |
| 201 | ret = i2c_smbus_write_byte_data(chip->client, |
| 202 | AD7152_REG_CFG2, AD7152_CFG2_OSR(i)); |
| 203 | if (ret < 0) { |
| 204 | mutex_unlock(&indio_dev->mlock); |
| 205 | return ret; |
| 206 | } |
| 207 | |
| 208 | chip->filter_rate_setup = i; |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 209 | mutex_unlock(&indio_dev->mlock); |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 210 | |
| 211 | return len; |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 212 | } |
| 213 | |
Michael Hennerich | c3b7915 | 2011-09-02 17:25:30 +0100 | [diff] [blame] | 214 | static IIO_DEV_ATTR_SAMP_FREQ(S_IRUGO | S_IWUSR, |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 215 | ad7152_show_filter_rate_setup, |
| 216 | ad7152_store_filter_rate_setup); |
| 217 | |
Michael Hennerich | c3b7915 | 2011-09-02 17:25:30 +0100 | [diff] [blame] | 218 | static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("200 50 20 17"); |
| 219 | |
Michael Hennerich | 9b72441 | 2011-09-02 17:25:28 +0100 | [diff] [blame] | 220 | static IIO_CONST_ATTR(in_capacitance_scale_available, |
| 221 | "0.000061050 0.000030525 0.000015263 0.000007631"); |
| 222 | |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 223 | static struct attribute *ad7152_attributes[] = { |
Michael Hennerich | c3b7915 | 2011-09-02 17:25:30 +0100 | [diff] [blame] | 224 | &iio_dev_attr_sampling_frequency.dev_attr.attr, |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 225 | &iio_dev_attr_in_capacitance0_calibbias_calibration.dev_attr.attr, |
| 226 | &iio_dev_attr_in_capacitance1_calibbias_calibration.dev_attr.attr, |
| 227 | &iio_dev_attr_in_capacitance0_calibscale_calibration.dev_attr.attr, |
| 228 | &iio_dev_attr_in_capacitance1_calibscale_calibration.dev_attr.attr, |
Michael Hennerich | 9b72441 | 2011-09-02 17:25:28 +0100 | [diff] [blame] | 229 | &iio_const_attr_in_capacitance_scale_available.dev_attr.attr, |
Michael Hennerich | c3b7915 | 2011-09-02 17:25:30 +0100 | [diff] [blame] | 230 | &iio_const_attr_sampling_frequency_available.dev_attr.attr, |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 231 | NULL, |
| 232 | }; |
| 233 | |
| 234 | static const struct attribute_group ad7152_attribute_group = { |
| 235 | .attrs = ad7152_attributes, |
| 236 | }; |
| 237 | |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 238 | static const u8 ad7152_addresses[][4] = { |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 239 | { AD7152_REG_CH1_DATA_HIGH, AD7152_REG_CH1_OFFS_HIGH, |
| 240 | AD7152_REG_CH1_GAIN_HIGH, AD7152_REG_CH1_SETUP }, |
| 241 | { AD7152_REG_CH2_DATA_HIGH, AD7152_REG_CH2_OFFS_HIGH, |
| 242 | AD7152_REG_CH2_GAIN_HIGH, AD7152_REG_CH2_SETUP }, |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 243 | }; |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 244 | |
Michael Hennerich | 9b72441 | 2011-09-02 17:25:28 +0100 | [diff] [blame] | 245 | /* Values are nano relative to pf base. */ |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 246 | static const int ad7152_scale_table[] = { |
Michael Hennerich | 9b72441 | 2011-09-02 17:25:28 +0100 | [diff] [blame] | 247 | 30525, 7631, 15263, 61050 |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 248 | }; |
| 249 | |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 250 | static int ad7152_write_raw(struct iio_dev *indio_dev, |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 251 | struct iio_chan_spec const *chan, |
| 252 | int val, |
| 253 | int val2, |
| 254 | long mask) |
| 255 | { |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 256 | struct ad7152_chip_info *chip = iio_priv(indio_dev); |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 257 | int ret, i; |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 258 | |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 259 | mutex_lock(&indio_dev->mlock); |
| 260 | |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 261 | switch (mask) { |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 262 | case IIO_CHAN_INFO_CALIBSCALE: |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 263 | if (val != 1) { |
| 264 | ret = -EINVAL; |
| 265 | goto out; |
| 266 | } |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 267 | |
| 268 | val = (val2 * 1024) / 15625; |
| 269 | |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 270 | ret = i2c_smbus_write_word_data(chip->client, |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 271 | ad7152_addresses[chan->channel][AD7152_GAIN], |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 272 | swab16(val)); |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 273 | if (ret < 0) |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 274 | goto out; |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 275 | |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 276 | ret = 0; |
| 277 | break; |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 278 | |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 279 | case IIO_CHAN_INFO_CALIBBIAS: |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 280 | if ((val < 0) | (val > 0xFFFF)) { |
| 281 | ret = -EINVAL; |
| 282 | goto out; |
| 283 | } |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 284 | ret = i2c_smbus_write_word_data(chip->client, |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 285 | ad7152_addresses[chan->channel][AD7152_OFFS], |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 286 | swab16(val)); |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 287 | if (ret < 0) |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 288 | goto out; |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 289 | |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 290 | ret = 0; |
| 291 | break; |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 292 | case IIO_CHAN_INFO_SCALE: |
Cristina Moraru | e6e65f9 | 2015-10-20 22:55:43 +0300 | [diff] [blame] | 293 | if (val) { |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 294 | ret = -EINVAL; |
| 295 | goto out; |
| 296 | } |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 297 | for (i = 0; i < ARRAY_SIZE(ad7152_scale_table); i++) |
Michael Hennerich | 9b72441 | 2011-09-02 17:25:28 +0100 | [diff] [blame] | 298 | if (val2 == ad7152_scale_table[i]) |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 299 | break; |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 300 | |
| 301 | chip->setup[chan->channel] &= ~AD7152_SETUP_RANGE_4pF; |
| 302 | chip->setup[chan->channel] |= AD7152_SETUP_RANGE(i); |
| 303 | |
| 304 | ret = i2c_smbus_write_byte_data(chip->client, |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 305 | ad7152_addresses[chan->channel][AD7152_SETUP], |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 306 | chip->setup[chan->channel]); |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 307 | if (ret < 0) |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 308 | goto out; |
| 309 | |
| 310 | ret = 0; |
| 311 | break; |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 312 | default: |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 313 | ret = -EINVAL; |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 314 | } |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 315 | |
| 316 | out: |
| 317 | mutex_unlock(&indio_dev->mlock); |
| 318 | return ret; |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 319 | } |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 320 | static int ad7152_read_raw(struct iio_dev *indio_dev, |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 321 | struct iio_chan_spec const *chan, |
| 322 | int *val, int *val2, |
| 323 | long mask) |
| 324 | { |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 325 | struct ad7152_chip_info *chip = iio_priv(indio_dev); |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 326 | int ret; |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 327 | u8 regval = 0; |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 328 | |
| 329 | mutex_lock(&indio_dev->mlock); |
| 330 | |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 331 | switch (mask) { |
Jonathan Cameron | e33e075 | 2012-04-15 17:41:26 +0100 | [diff] [blame] | 332 | case IIO_CHAN_INFO_RAW: |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 333 | /* First set whether in differential mode */ |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 334 | |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 335 | regval = chip->setup[chan->channel]; |
| 336 | |
| 337 | if (chan->differential) |
| 338 | chip->setup[chan->channel] |= AD7152_SETUP_CAPDIFF; |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 339 | else |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 340 | chip->setup[chan->channel] &= ~AD7152_SETUP_CAPDIFF; |
| 341 | |
| 342 | if (regval != chip->setup[chan->channel]) { |
| 343 | ret = i2c_smbus_write_byte_data(chip->client, |
| 344 | ad7152_addresses[chan->channel][AD7152_SETUP], |
| 345 | chip->setup[chan->channel]); |
| 346 | if (ret < 0) |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 347 | goto out; |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 348 | } |
| 349 | /* Make sure the channel is enabled */ |
| 350 | if (chan->channel == 0) |
| 351 | regval = AD7152_CONF_CH1EN; |
| 352 | else |
| 353 | regval = AD7152_CONF_CH2EN; |
| 354 | |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 355 | /* Trigger a single read */ |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 356 | regval |= AD7152_CONF_MODE_SINGLE_CONV; |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 357 | ret = i2c_smbus_write_byte_data(chip->client, AD7152_REG_CFG, |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 358 | regval); |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 359 | if (ret < 0) |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 360 | goto out; |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 361 | |
Michael Hennerich | c3b7915 | 2011-09-02 17:25:30 +0100 | [diff] [blame] | 362 | msleep(ad7152_filter_rate_table[chip->filter_rate_setup][1]); |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 363 | /* Now read the actual register */ |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 364 | ret = i2c_smbus_read_word_data(chip->client, |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 365 | ad7152_addresses[chan->channel][AD7152_DATA]); |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 366 | if (ret < 0) |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 367 | goto out; |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 368 | *val = swab16(ret); |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 369 | |
Michael Hennerich | fe55a17 | 2011-09-02 17:25:31 +0100 | [diff] [blame] | 370 | if (chan->differential) |
| 371 | *val -= 0x8000; |
| 372 | |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 373 | ret = IIO_VAL_INT; |
| 374 | break; |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 375 | case IIO_CHAN_INFO_CALIBSCALE: |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 376 | |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 377 | ret = i2c_smbus_read_word_data(chip->client, |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 378 | ad7152_addresses[chan->channel][AD7152_GAIN]); |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 379 | if (ret < 0) |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 380 | goto out; |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 381 | /* 1 + gain_val / 2^16 */ |
| 382 | *val = 1; |
| 383 | *val2 = (15625 * swab16(ret)) / 1024; |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 384 | |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 385 | ret = IIO_VAL_INT_PLUS_MICRO; |
| 386 | break; |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 387 | case IIO_CHAN_INFO_CALIBBIAS: |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 388 | ret = i2c_smbus_read_word_data(chip->client, |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 389 | ad7152_addresses[chan->channel][AD7152_OFFS]); |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 390 | if (ret < 0) |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 391 | goto out; |
Michael Hennerich | 2b8cb40 | 2011-09-02 17:25:27 +0100 | [diff] [blame] | 392 | *val = swab16(ret); |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 393 | |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 394 | ret = IIO_VAL_INT; |
| 395 | break; |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 396 | case IIO_CHAN_INFO_SCALE: |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 397 | ret = i2c_smbus_read_byte_data(chip->client, |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 398 | ad7152_addresses[chan->channel][AD7152_SETUP]); |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 399 | if (ret < 0) |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 400 | goto out; |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 401 | *val = 0; |
| 402 | *val2 = ad7152_scale_table[ret >> 6]; |
| 403 | |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 404 | ret = IIO_VAL_INT_PLUS_NANO; |
| 405 | break; |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 406 | default: |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 407 | ret = -EINVAL; |
Peter Senna Tschudin | 73327b4 | 2012-09-28 10:57:00 +0100 | [diff] [blame] | 408 | } |
Michael Hennerich | bb90cf8 | 2011-09-02 17:25:29 +0100 | [diff] [blame] | 409 | out: |
| 410 | mutex_unlock(&indio_dev->mlock); |
| 411 | return ret; |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 412 | } |
Michael Hennerich | 9b72441 | 2011-09-02 17:25:28 +0100 | [diff] [blame] | 413 | |
| 414 | static int ad7152_write_raw_get_fmt(struct iio_dev *indio_dev, |
| 415 | struct iio_chan_spec const *chan, |
| 416 | long mask) |
| 417 | { |
| 418 | switch (mask) { |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 419 | case IIO_CHAN_INFO_SCALE: |
Michael Hennerich | 9b72441 | 2011-09-02 17:25:28 +0100 | [diff] [blame] | 420 | return IIO_VAL_INT_PLUS_NANO; |
| 421 | default: |
| 422 | return IIO_VAL_INT_PLUS_MICRO; |
| 423 | } |
| 424 | } |
| 425 | |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 426 | static const struct iio_info ad7152_info = { |
| 427 | .attrs = &ad7152_attribute_group, |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 428 | .read_raw = &ad7152_read_raw, |
| 429 | .write_raw = &ad7152_write_raw, |
Michael Hennerich | 9b72441 | 2011-09-02 17:25:28 +0100 | [diff] [blame] | 430 | .write_raw_get_fmt = &ad7152_write_raw_get_fmt, |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 431 | .driver_module = THIS_MODULE, |
| 432 | }; |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 433 | |
| 434 | static const struct iio_chan_spec ad7152_channels[] = { |
| 435 | { |
| 436 | .type = IIO_CAPACITANCE, |
| 437 | .indexed = 1, |
| 438 | .channel = 0, |
Jonathan Cameron | c24e97b | 2013-02-27 19:38:12 +0000 | [diff] [blame] | 439 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | |
| 440 | BIT(IIO_CHAN_INFO_CALIBSCALE) | |
| 441 | BIT(IIO_CHAN_INFO_CALIBBIAS) | |
| 442 | BIT(IIO_CHAN_INFO_SCALE), |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 443 | }, { |
| 444 | .type = IIO_CAPACITANCE, |
Michael Hennerich | 15e3276 | 2011-09-02 17:25:47 +0100 | [diff] [blame] | 445 | .differential = 1, |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 446 | .indexed = 1, |
Michael Hennerich | 15e3276 | 2011-09-02 17:25:47 +0100 | [diff] [blame] | 447 | .channel = 0, |
| 448 | .channel2 = 2, |
Jonathan Cameron | c24e97b | 2013-02-27 19:38:12 +0000 | [diff] [blame] | 449 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | |
| 450 | BIT(IIO_CHAN_INFO_CALIBSCALE) | |
| 451 | BIT(IIO_CHAN_INFO_CALIBBIAS) | |
| 452 | BIT(IIO_CHAN_INFO_SCALE), |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 453 | }, { |
| 454 | .type = IIO_CAPACITANCE, |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 455 | .indexed = 1, |
Michael Hennerich | 15e3276 | 2011-09-02 17:25:47 +0100 | [diff] [blame] | 456 | .channel = 1, |
Jonathan Cameron | c24e97b | 2013-02-27 19:38:12 +0000 | [diff] [blame] | 457 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | |
| 458 | BIT(IIO_CHAN_INFO_CALIBSCALE) | |
| 459 | BIT(IIO_CHAN_INFO_CALIBBIAS) | |
| 460 | BIT(IIO_CHAN_INFO_SCALE), |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 461 | }, { |
| 462 | .type = IIO_CAPACITANCE, |
| 463 | .differential = 1, |
| 464 | .indexed = 1, |
| 465 | .channel = 1, |
| 466 | .channel2 = 3, |
Jonathan Cameron | c24e97b | 2013-02-27 19:38:12 +0000 | [diff] [blame] | 467 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | |
| 468 | BIT(IIO_CHAN_INFO_CALIBSCALE) | |
| 469 | BIT(IIO_CHAN_INFO_CALIBBIAS) | |
| 470 | BIT(IIO_CHAN_INFO_SCALE), |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 471 | } |
| 472 | }; |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 473 | /* |
| 474 | * device probe and remove |
| 475 | */ |
| 476 | |
Bill Pemberton | 4ae1c61 | 2012-11-19 13:21:57 -0500 | [diff] [blame] | 477 | static int ad7152_probe(struct i2c_client *client, |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 478 | const struct i2c_device_id *id) |
| 479 | { |
| 480 | int ret = 0; |
Jonathan Cameron | f4c794a | 2011-06-27 13:07:22 +0100 | [diff] [blame] | 481 | struct ad7152_chip_info *chip; |
| 482 | struct iio_dev *indio_dev; |
| 483 | |
Sachin Kamat | 538ee7c | 2013-08-24 20:24:00 +0100 | [diff] [blame] | 484 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); |
| 485 | if (!indio_dev) |
| 486 | return -ENOMEM; |
Jonathan Cameron | f4c794a | 2011-06-27 13:07:22 +0100 | [diff] [blame] | 487 | chip = iio_priv(indio_dev); |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 488 | /* this is only used for device removal purposes */ |
Jonathan Cameron | f4c794a | 2011-06-27 13:07:22 +0100 | [diff] [blame] | 489 | i2c_set_clientdata(client, indio_dev); |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 490 | |
| 491 | chip->client = client; |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 492 | |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 493 | /* Establish that the iio_dev is a child of the i2c device */ |
Jonathan Cameron | f4c794a | 2011-06-27 13:07:22 +0100 | [diff] [blame] | 494 | indio_dev->name = id->name; |
| 495 | indio_dev->dev.parent = &client->dev; |
| 496 | indio_dev->info = &ad7152_info; |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 497 | indio_dev->channels = ad7152_channels; |
Jonathan Cameron | 4050f49 | 2011-09-02 17:25:24 +0100 | [diff] [blame] | 498 | if (id->driver_data == 0) |
| 499 | indio_dev->num_channels = ARRAY_SIZE(ad7152_channels); |
| 500 | else |
Jonathan Cameron | ea993a5 | 2011-09-02 17:25:25 +0100 | [diff] [blame] | 501 | indio_dev->num_channels = 2; |
Jonathan Cameron | 3995f91 | 2011-09-02 17:25:23 +0100 | [diff] [blame] | 502 | indio_dev->num_channels = ARRAY_SIZE(ad7152_channels); |
Jonathan Cameron | f4c794a | 2011-06-27 13:07:22 +0100 | [diff] [blame] | 503 | indio_dev->modes = INDIO_DIRECT_MODE; |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 504 | |
Ioana Ciornei | 252fb58 | 2015-10-02 13:37:48 +0300 | [diff] [blame] | 505 | ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev); |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 506 | if (ret) |
Sachin Kamat | 538ee7c | 2013-08-24 20:24:00 +0100 | [diff] [blame] | 507 | return ret; |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 508 | |
| 509 | dev_err(&client->dev, "%s capacitive sensor registered\n", id->name); |
| 510 | |
| 511 | return 0; |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 512 | } |
| 513 | |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 514 | static const struct i2c_device_id ad7152_id[] = { |
| 515 | { "ad7152", 0 }, |
Jonathan Cameron | 4050f49 | 2011-09-02 17:25:24 +0100 | [diff] [blame] | 516 | { "ad7153", 1 }, |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 517 | {} |
| 518 | }; |
| 519 | |
| 520 | MODULE_DEVICE_TABLE(i2c, ad7152_id); |
| 521 | |
| 522 | static struct i2c_driver ad7152_driver = { |
| 523 | .driver = { |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 524 | .name = KBUILD_MODNAME, |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 525 | }, |
| 526 | .probe = ad7152_probe, |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 527 | .id_table = ad7152_id, |
| 528 | }; |
Lars-Peter Clausen | 6e5af18 | 2011-11-16 10:13:38 +0100 | [diff] [blame] | 529 | module_i2c_driver(ad7152_driver); |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 530 | |
| 531 | MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); |
Michael Hennerich | e566429 | 2011-09-02 17:25:26 +0100 | [diff] [blame] | 532 | MODULE_DESCRIPTION("Analog Devices AD7152/3 capacitive sensor driver"); |
Barry Song | a20ebd9 | 2010-10-27 21:43:54 -0400 | [diff] [blame] | 533 | MODULE_LICENSE("GPL v2"); |