Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 1 | /* |
| 2 | * AD5624R, AD5644R, AD5664R Digital to analog convertors spi driver |
| 3 | * |
Michael Hennerich | 14f88f1 | 2011-03-09 16:01:45 +0100 | [diff] [blame] | 4 | * Copyright 2010-2011 Analog Devices Inc. |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 5 | * |
Michael Hennerich | 14f88f1 | 2011-03-09 16:01:45 +0100 | [diff] [blame] | 6 | * Licensed under the GPL-2. |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/interrupt.h> |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 10 | #include <linux/fs.h> |
| 11 | #include <linux/device.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/spi/spi.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/sysfs.h> |
Michael Hennerich | 14f88f1 | 2011-03-09 16:01:45 +0100 | [diff] [blame] | 16 | #include <linux/regulator/consumer.h> |
Paul Gortmaker | 99c9785 | 2011-07-03 15:49:50 -0400 | [diff] [blame] | 17 | #include <linux/module.h> |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 18 | |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 19 | #include <linux/iio/iio.h> |
| 20 | #include <linux/iio/sysfs.h> |
Lars-Peter Clausen | cadb695 | 2012-06-04 11:36:19 +0200 | [diff] [blame] | 21 | |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 22 | #include "ad5624r.h" |
| 23 | |
Michael Hennerich | df9cd10 | 2010-11-19 15:16:44 +0100 | [diff] [blame] | 24 | static int ad5624r_spi_write(struct spi_device *spi, |
| 25 | u8 cmd, u8 addr, u16 val, u8 len) |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 26 | { |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 27 | u32 data; |
| 28 | u8 msg[3]; |
| 29 | |
| 30 | /* |
Michael Hennerich | 14f88f1 | 2011-03-09 16:01:45 +0100 | [diff] [blame] | 31 | * The input shift register is 24 bits wide. The first two bits are |
| 32 | * don't care bits. The next three are the command bits, C2 to C0, |
| 33 | * followed by the 3-bit DAC address, A2 to A0, and then the |
| 34 | * 16-, 14-, 12-bit data-word. The data-word comprises the 16-, |
| 35 | * 14-, 12-bit input code followed by 0, 2, or 4 don't care bits, |
| 36 | * for the AD5664R, AD5644R, and AD5624R, respectively. |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 37 | */ |
| 38 | data = (0 << 22) | (cmd << 19) | (addr << 16) | (val << (16 - len)); |
| 39 | msg[0] = data >> 16; |
| 40 | msg[1] = data >> 8; |
| 41 | msg[2] = data; |
| 42 | |
Michael Hennerich | df9cd10 | 2010-11-19 15:16:44 +0100 | [diff] [blame] | 43 | return spi_write(spi, msg, 3); |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 44 | } |
| 45 | |
Lars-Peter Clausen | 275de9f | 2011-11-15 16:31:24 +0100 | [diff] [blame] | 46 | static int ad5624r_read_raw(struct iio_dev *indio_dev, |
| 47 | struct iio_chan_spec const *chan, |
| 48 | int *val, |
| 49 | int *val2, |
| 50 | long m) |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 51 | { |
Jonathan Cameron | 3ff2420 | 2011-06-27 13:07:31 +0100 | [diff] [blame] | 52 | struct ad5624r_state *st = iio_priv(indio_dev); |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 53 | |
Lars-Peter Clausen | 275de9f | 2011-11-15 16:31:24 +0100 | [diff] [blame] | 54 | switch (m) { |
| 55 | case IIO_CHAN_INFO_SCALE: |
Lars-Peter Clausen | 14229e87 | 2013-09-28 10:31:00 +0100 | [diff] [blame] | 56 | *val = st->vref_mv; |
| 57 | *val2 = chan->scan_type.realbits; |
| 58 | return IIO_VAL_FRACTIONAL_LOG2; |
Lars-Peter Clausen | 275de9f | 2011-11-15 16:31:24 +0100 | [diff] [blame] | 59 | } |
| 60 | return -EINVAL; |
| 61 | } |
| 62 | |
| 63 | static int ad5624r_write_raw(struct iio_dev *indio_dev, |
| 64 | struct iio_chan_spec const *chan, |
| 65 | int val, |
| 66 | int val2, |
| 67 | long mask) |
| 68 | { |
| 69 | struct ad5624r_state *st = iio_priv(indio_dev); |
| 70 | int ret; |
| 71 | |
| 72 | switch (mask) { |
Jonathan Cameron | 09f4eb4 | 2012-04-15 17:41:19 +0100 | [diff] [blame] | 73 | case IIO_CHAN_INFO_RAW: |
Lars-Peter Clausen | 275de9f | 2011-11-15 16:31:24 +0100 | [diff] [blame] | 74 | if (val >= (1 << chan->scan_type.realbits) || val < 0) |
| 75 | return -EINVAL; |
| 76 | |
| 77 | return ad5624r_spi_write(st->us, |
| 78 | AD5624R_CMD_WRITE_INPUT_N_UPDATE_N, |
| 79 | chan->address, val, |
| 80 | chan->scan_type.shift); |
| 81 | default: |
| 82 | ret = -EINVAL; |
| 83 | } |
| 84 | |
| 85 | return -EINVAL; |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 86 | } |
| 87 | |
Lars-Peter Clausen | 66eb905 | 2012-06-04 11:36:16 +0200 | [diff] [blame] | 88 | static const char * const ad5624r_powerdown_modes[] = { |
| 89 | "1kohm_to_gnd", |
| 90 | "100kohm_to_gnd", |
| 91 | "three_state" |
| 92 | }; |
| 93 | |
| 94 | static int ad5624r_get_powerdown_mode(struct iio_dev *indio_dev, |
| 95 | const struct iio_chan_spec *chan) |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 96 | { |
Jonathan Cameron | 3ff2420 | 2011-06-27 13:07:31 +0100 | [diff] [blame] | 97 | struct ad5624r_state *st = iio_priv(indio_dev); |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 98 | |
Lars-Peter Clausen | 66eb905 | 2012-06-04 11:36:16 +0200 | [diff] [blame] | 99 | return st->pwr_down_mode; |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 100 | } |
| 101 | |
Lars-Peter Clausen | 66eb905 | 2012-06-04 11:36:16 +0200 | [diff] [blame] | 102 | static int ad5624r_set_powerdown_mode(struct iio_dev *indio_dev, |
| 103 | const struct iio_chan_spec *chan, unsigned int mode) |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 104 | { |
Jonathan Cameron | 3ff2420 | 2011-06-27 13:07:31 +0100 | [diff] [blame] | 105 | struct ad5624r_state *st = iio_priv(indio_dev); |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 106 | |
Lars-Peter Clausen | 66eb905 | 2012-06-04 11:36:16 +0200 | [diff] [blame] | 107 | st->pwr_down_mode = mode; |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 108 | |
Lars-Peter Clausen | 66eb905 | 2012-06-04 11:36:16 +0200 | [diff] [blame] | 109 | return 0; |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Lars-Peter Clausen | 66eb905 | 2012-06-04 11:36:16 +0200 | [diff] [blame] | 112 | static const struct iio_enum ad5624r_powerdown_mode_enum = { |
| 113 | .items = ad5624r_powerdown_modes, |
| 114 | .num_items = ARRAY_SIZE(ad5624r_powerdown_modes), |
| 115 | .get = ad5624r_get_powerdown_mode, |
| 116 | .set = ad5624r_set_powerdown_mode, |
| 117 | }; |
| 118 | |
| 119 | static ssize_t ad5624r_read_dac_powerdown(struct iio_dev *indio_dev, |
| 120 | uintptr_t private, const struct iio_chan_spec *chan, char *buf) |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 121 | { |
Jonathan Cameron | 3ff2420 | 2011-06-27 13:07:31 +0100 | [diff] [blame] | 122 | struct ad5624r_state *st = iio_priv(indio_dev); |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 123 | |
Michael Hennerich | 14f88f1 | 2011-03-09 16:01:45 +0100 | [diff] [blame] | 124 | return sprintf(buf, "%d\n", |
Lars-Peter Clausen | 66eb905 | 2012-06-04 11:36:16 +0200 | [diff] [blame] | 125 | !!(st->pwr_down_mask & (1 << chan->channel))); |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 126 | } |
| 127 | |
Lars-Peter Clausen | 66eb905 | 2012-06-04 11:36:16 +0200 | [diff] [blame] | 128 | static ssize_t ad5624r_write_dac_powerdown(struct iio_dev *indio_dev, |
| 129 | uintptr_t private, const struct iio_chan_spec *chan, const char *buf, |
| 130 | size_t len) |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 131 | { |
Lars-Peter Clausen | 2490594 | 2012-06-04 11:36:23 +0200 | [diff] [blame] | 132 | bool pwr_down; |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 133 | int ret; |
Jonathan Cameron | 3ff2420 | 2011-06-27 13:07:31 +0100 | [diff] [blame] | 134 | struct ad5624r_state *st = iio_priv(indio_dev); |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 135 | |
Lars-Peter Clausen | 2490594 | 2012-06-04 11:36:23 +0200 | [diff] [blame] | 136 | ret = strtobool(buf, &pwr_down); |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 137 | if (ret) |
| 138 | return ret; |
| 139 | |
Lars-Peter Clausen | 2490594 | 2012-06-04 11:36:23 +0200 | [diff] [blame] | 140 | if (pwr_down) |
Lars-Peter Clausen | 66eb905 | 2012-06-04 11:36:16 +0200 | [diff] [blame] | 141 | st->pwr_down_mask |= (1 << chan->channel); |
Michael Hennerich | 14f88f1 | 2011-03-09 16:01:45 +0100 | [diff] [blame] | 142 | else |
Lars-Peter Clausen | 2490594 | 2012-06-04 11:36:23 +0200 | [diff] [blame] | 143 | st->pwr_down_mask &= ~(1 << chan->channel); |
Michael Hennerich | 14f88f1 | 2011-03-09 16:01:45 +0100 | [diff] [blame] | 144 | |
Michael Hennerich | df9cd10 | 2010-11-19 15:16:44 +0100 | [diff] [blame] | 145 | ret = ad5624r_spi_write(st->us, AD5624R_CMD_POWERDOWN_DAC, 0, |
Michael Hennerich | 14f88f1 | 2011-03-09 16:01:45 +0100 | [diff] [blame] | 146 | (st->pwr_down_mode << 4) | |
| 147 | st->pwr_down_mask, 16); |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 148 | |
| 149 | return ret ? ret : len; |
| 150 | } |
| 151 | |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 152 | static const struct iio_info ad5624r_info = { |
Lars-Peter Clausen | 275de9f | 2011-11-15 16:31:24 +0100 | [diff] [blame] | 153 | .write_raw = ad5624r_write_raw, |
| 154 | .read_raw = ad5624r_read_raw, |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 155 | .driver_module = THIS_MODULE, |
| 156 | }; |
| 157 | |
Lars-Peter Clausen | 66eb905 | 2012-06-04 11:36:16 +0200 | [diff] [blame] | 158 | static const struct iio_chan_spec_ext_info ad5624r_ext_info[] = { |
| 159 | { |
| 160 | .name = "powerdown", |
| 161 | .read = ad5624r_read_dac_powerdown, |
| 162 | .write = ad5624r_write_dac_powerdown, |
Jonathan Cameron | 3704432 | 2013-09-08 14:57:00 +0100 | [diff] [blame] | 163 | .shared = IIO_SEPARATE, |
Lars-Peter Clausen | 66eb905 | 2012-06-04 11:36:16 +0200 | [diff] [blame] | 164 | }, |
Jonathan Cameron | 3704432 | 2013-09-08 14:57:00 +0100 | [diff] [blame] | 165 | IIO_ENUM("powerdown_mode", IIO_SHARED_BY_TYPE, |
| 166 | &ad5624r_powerdown_mode_enum), |
Lars-Peter Clausen | 66eb905 | 2012-06-04 11:36:16 +0200 | [diff] [blame] | 167 | IIO_ENUM_AVAILABLE("powerdown_mode", &ad5624r_powerdown_mode_enum), |
| 168 | { }, |
| 169 | }; |
| 170 | |
| 171 | #define AD5624R_CHANNEL(_chan, _bits) { \ |
| 172 | .type = IIO_VOLTAGE, \ |
| 173 | .indexed = 1, \ |
| 174 | .output = 1, \ |
| 175 | .channel = (_chan), \ |
Jonathan Cameron | 8b68634 | 2013-02-27 19:11:22 +0000 | [diff] [blame] | 176 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ |
| 177 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ |
Lars-Peter Clausen | 66eb905 | 2012-06-04 11:36:16 +0200 | [diff] [blame] | 178 | .address = (_chan), \ |
| 179 | .scan_type = IIO_ST('u', (_bits), 16, 16 - (_bits)), \ |
| 180 | .ext_info = ad5624r_ext_info, \ |
| 181 | } |
| 182 | |
| 183 | #define DECLARE_AD5624R_CHANNELS(_name, _bits) \ |
| 184 | const struct iio_chan_spec _name##_channels[] = { \ |
| 185 | AD5624R_CHANNEL(0, _bits), \ |
| 186 | AD5624R_CHANNEL(1, _bits), \ |
| 187 | AD5624R_CHANNEL(2, _bits), \ |
| 188 | AD5624R_CHANNEL(3, _bits), \ |
| 189 | } |
| 190 | |
| 191 | static DECLARE_AD5624R_CHANNELS(ad5624r, 12); |
| 192 | static DECLARE_AD5624R_CHANNELS(ad5644r, 14); |
| 193 | static DECLARE_AD5624R_CHANNELS(ad5664r, 16); |
| 194 | |
| 195 | static const struct ad5624r_chip_info ad5624r_chip_info_tbl[] = { |
| 196 | [ID_AD5624R3] = { |
| 197 | .channels = ad5624r_channels, |
| 198 | .int_vref_mv = 1250, |
| 199 | }, |
| 200 | [ID_AD5624R5] = { |
| 201 | .channels = ad5624r_channels, |
| 202 | .int_vref_mv = 2500, |
| 203 | }, |
| 204 | [ID_AD5644R3] = { |
| 205 | .channels = ad5644r_channels, |
| 206 | .int_vref_mv = 1250, |
| 207 | }, |
| 208 | [ID_AD5644R5] = { |
| 209 | .channels = ad5644r_channels, |
| 210 | .int_vref_mv = 2500, |
| 211 | }, |
| 212 | [ID_AD5664R3] = { |
| 213 | .channels = ad5664r_channels, |
| 214 | .int_vref_mv = 1250, |
| 215 | }, |
| 216 | [ID_AD5664R5] = { |
| 217 | .channels = ad5664r_channels, |
| 218 | .int_vref_mv = 2500, |
| 219 | }, |
| 220 | }; |
| 221 | |
Greg Kroah-Hartman | fc52692 | 2012-12-21 13:21:43 -0800 | [diff] [blame] | 222 | static int ad5624r_probe(struct spi_device *spi) |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 223 | { |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 224 | struct ad5624r_state *st; |
Jonathan Cameron | 3ff2420 | 2011-06-27 13:07:31 +0100 | [diff] [blame] | 225 | struct iio_dev *indio_dev; |
Michael Hennerich | 14f88f1 | 2011-03-09 16:01:45 +0100 | [diff] [blame] | 226 | int ret, voltage_uv = 0; |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 227 | |
Sachin Kamat | 7523823 | 2013-08-19 12:38:00 +0100 | [diff] [blame] | 228 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); |
| 229 | if (!indio_dev) |
| 230 | return -ENOMEM; |
Jonathan Cameron | 3ff2420 | 2011-06-27 13:07:31 +0100 | [diff] [blame] | 231 | st = iio_priv(indio_dev); |
Sachin Kamat | 7523823 | 2013-08-19 12:38:00 +0100 | [diff] [blame] | 232 | st->reg = devm_regulator_get(&spi->dev, "vcc"); |
Jonathan Cameron | 26a5479 | 2011-08-30 12:41:19 +0100 | [diff] [blame] | 233 | if (!IS_ERR(st->reg)) { |
| 234 | ret = regulator_enable(st->reg); |
| 235 | if (ret) |
Sachin Kamat | 7523823 | 2013-08-19 12:38:00 +0100 | [diff] [blame] | 236 | return ret; |
Jonathan Cameron | 26a5479 | 2011-08-30 12:41:19 +0100 | [diff] [blame] | 237 | |
Axel Lin | 8434e78 | 2012-12-14 12:07:00 +0000 | [diff] [blame] | 238 | ret = regulator_get_voltage(st->reg); |
| 239 | if (ret < 0) |
| 240 | goto error_disable_reg; |
| 241 | |
| 242 | voltage_uv = ret; |
Jonathan Cameron | 26a5479 | 2011-08-30 12:41:19 +0100 | [diff] [blame] | 243 | } |
| 244 | |
Jonathan Cameron | 3ff2420 | 2011-06-27 13:07:31 +0100 | [diff] [blame] | 245 | spi_set_drvdata(spi, indio_dev); |
Michael Hennerich | 14f88f1 | 2011-03-09 16:01:45 +0100 | [diff] [blame] | 246 | st->chip_info = |
| 247 | &ad5624r_chip_info_tbl[spi_get_device_id(spi)->driver_data]; |
| 248 | |
| 249 | if (voltage_uv) |
| 250 | st->vref_mv = voltage_uv / 1000; |
| 251 | else |
| 252 | st->vref_mv = st->chip_info->int_vref_mv; |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 253 | |
| 254 | st->us = spi; |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 255 | |
Jonathan Cameron | 3ff2420 | 2011-06-27 13:07:31 +0100 | [diff] [blame] | 256 | indio_dev->dev.parent = &spi->dev; |
| 257 | indio_dev->name = spi_get_device_id(spi)->name; |
| 258 | indio_dev->info = &ad5624r_info; |
| 259 | indio_dev->modes = INDIO_DIRECT_MODE; |
Lars-Peter Clausen | 275de9f | 2011-11-15 16:31:24 +0100 | [diff] [blame] | 260 | indio_dev->channels = st->chip_info->channels; |
| 261 | indio_dev->num_channels = AD5624R_DAC_CHANNELS; |
Jonathan Cameron | 3ff2420 | 2011-06-27 13:07:31 +0100 | [diff] [blame] | 262 | |
Jonathan Cameron | 3e39440 | 2011-08-30 12:41:18 +0100 | [diff] [blame] | 263 | ret = ad5624r_spi_write(spi, AD5624R_CMD_INTERNAL_REFER_SETUP, 0, |
| 264 | !!voltage_uv, 16); |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 265 | if (ret) |
Jonathan Cameron | 26a5479 | 2011-08-30 12:41:19 +0100 | [diff] [blame] | 266 | goto error_disable_reg; |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 267 | |
Jonathan Cameron | 3e39440 | 2011-08-30 12:41:18 +0100 | [diff] [blame] | 268 | ret = iio_device_register(indio_dev); |
Michael Hennerich | 14f88f1 | 2011-03-09 16:01:45 +0100 | [diff] [blame] | 269 | if (ret) |
Jonathan Cameron | 26a5479 | 2011-08-30 12:41:19 +0100 | [diff] [blame] | 270 | goto error_disable_reg; |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 271 | |
| 272 | return 0; |
| 273 | |
Michael Hennerich | 14f88f1 | 2011-03-09 16:01:45 +0100 | [diff] [blame] | 274 | error_disable_reg: |
Jonathan Cameron | 26a5479 | 2011-08-30 12:41:19 +0100 | [diff] [blame] | 275 | if (!IS_ERR(st->reg)) |
| 276 | regulator_disable(st->reg); |
Michael Hennerich | 14f88f1 | 2011-03-09 16:01:45 +0100 | [diff] [blame] | 277 | |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 278 | return ret; |
| 279 | } |
| 280 | |
Greg Kroah-Hartman | fc52692 | 2012-12-21 13:21:43 -0800 | [diff] [blame] | 281 | static int ad5624r_remove(struct spi_device *spi) |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 282 | { |
Jonathan Cameron | 3ff2420 | 2011-06-27 13:07:31 +0100 | [diff] [blame] | 283 | struct iio_dev *indio_dev = spi_get_drvdata(spi); |
| 284 | struct ad5624r_state *st = iio_priv(indio_dev); |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 285 | |
Jonathan Cameron | d2fffd6 | 2011-10-14 14:46:58 +0100 | [diff] [blame] | 286 | iio_device_unregister(indio_dev); |
Sachin Kamat | 7523823 | 2013-08-19 12:38:00 +0100 | [diff] [blame] | 287 | if (!IS_ERR(st->reg)) |
Jonathan Cameron | 26a5479 | 2011-08-30 12:41:19 +0100 | [diff] [blame] | 288 | regulator_disable(st->reg); |
Michael Hennerich | 14f88f1 | 2011-03-09 16:01:45 +0100 | [diff] [blame] | 289 | |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 290 | return 0; |
| 291 | } |
| 292 | |
Michael Hennerich | ece30c1 | 2010-11-19 15:16:45 +0100 | [diff] [blame] | 293 | static const struct spi_device_id ad5624r_id[] = { |
Michael Hennerich | 14f88f1 | 2011-03-09 16:01:45 +0100 | [diff] [blame] | 294 | {"ad5624r3", ID_AD5624R3}, |
| 295 | {"ad5644r3", ID_AD5644R3}, |
| 296 | {"ad5664r3", ID_AD5664R3}, |
| 297 | {"ad5624r5", ID_AD5624R5}, |
| 298 | {"ad5644r5", ID_AD5644R5}, |
| 299 | {"ad5664r5", ID_AD5664R5}, |
Michael Hennerich | ece30c1 | 2010-11-19 15:16:45 +0100 | [diff] [blame] | 300 | {} |
| 301 | }; |
Lars-Peter Clausen | 55e4390 | 2011-11-16 08:53:31 +0100 | [diff] [blame] | 302 | MODULE_DEVICE_TABLE(spi, ad5624r_id); |
Michael Hennerich | ece30c1 | 2010-11-19 15:16:45 +0100 | [diff] [blame] | 303 | |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 304 | static struct spi_driver ad5624r_driver = { |
| 305 | .driver = { |
Michael Hennerich | 24d6050 | 2010-11-19 15:16:46 +0100 | [diff] [blame] | 306 | .name = "ad5624r", |
| 307 | .owner = THIS_MODULE, |
| 308 | }, |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 309 | .probe = ad5624r_probe, |
Greg Kroah-Hartman | fc52692 | 2012-12-21 13:21:43 -0800 | [diff] [blame] | 310 | .remove = ad5624r_remove, |
Michael Hennerich | ece30c1 | 2010-11-19 15:16:45 +0100 | [diff] [blame] | 311 | .id_table = ad5624r_id, |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 312 | }; |
Lars-Peter Clausen | ae6ae6f | 2011-11-16 10:13:39 +0100 | [diff] [blame] | 313 | module_spi_driver(ad5624r_driver); |
Barry Song | 6790e29 | 2010-10-27 21:44:07 -0400 | [diff] [blame] | 314 | |
| 315 | MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); |
| 316 | MODULE_DESCRIPTION("Analog Devices AD5624/44/64R DAC spi driver"); |
| 317 | MODULE_LICENSE("GPL v2"); |