blob: dbceda1e67eaba530687b131bdfddb014d86181d [file] [log] [blame]
Barry Song2919fa52010-10-27 21:44:17 -04001/*
2 * ADE7759 Active Energy Metering IC with di/dt Sensor Interface Driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/irq.h>
Barry Song2919fa52010-10-27 21:44:17 -040011#include <linux/delay.h>
12#include <linux/mutex.h>
13#include <linux/device.h>
14#include <linux/kernel.h>
15#include <linux/spi/spi.h>
16#include <linux/slab.h>
17#include <linux/sysfs.h>
18#include <linux/list.h>
Paul Gortmaker99c97852011-07-03 15:49:50 -040019#include <linux/module.h>
Barry Song2919fa52010-10-27 21:44:17 -040020
Jonathan Cameron06458e22012-04-25 15:54:58 +010021#include <linux/iio/iio.h>
22#include <linux/iio/sysfs.h>
Barry Song2919fa52010-10-27 21:44:17 -040023#include "meter.h"
24#include "ade7759.h"
25
Jonathan Cameron3859fac2011-02-11 14:07:42 +000026static int ade7759_spi_write_reg_8(struct device *dev,
Barry Song2919fa52010-10-27 21:44:17 -040027 u8 reg_address,
28 u8 val)
29{
30 int ret;
Lars-Peter Clausen196b59c2012-05-12 15:39:54 +020031 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
Jonathan Cameronafc2ff02011-06-27 13:07:55 +010032 struct ade7759_state *st = iio_priv(indio_dev);
Barry Song2919fa52010-10-27 21:44:17 -040033
34 mutex_lock(&st->buf_lock);
35 st->tx[0] = ADE7759_WRITE_REG(reg_address);
36 st->tx[1] = val;
37
38 ret = spi_write(st->us, st->tx, 2);
39 mutex_unlock(&st->buf_lock);
40
41 return ret;
42}
43
44static int ade7759_spi_write_reg_16(struct device *dev,
45 u8 reg_address,
46 u16 value)
47{
48 int ret;
Lars-Peter Clausen196b59c2012-05-12 15:39:54 +020049 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
Jonathan Cameronafc2ff02011-06-27 13:07:55 +010050 struct ade7759_state *st = iio_priv(indio_dev);
Barry Song2919fa52010-10-27 21:44:17 -040051
52 mutex_lock(&st->buf_lock);
53 st->tx[0] = ADE7759_WRITE_REG(reg_address);
54 st->tx[1] = (value >> 8) & 0xFF;
55 st->tx[2] = value & 0xFF;
Jonathan Cameron3859fac2011-02-11 14:07:42 +000056 ret = spi_write(st->us, st->tx, 3);
Barry Song2919fa52010-10-27 21:44:17 -040057 mutex_unlock(&st->buf_lock);
58
59 return ret;
60}
61
62static int ade7759_spi_read_reg_8(struct device *dev,
63 u8 reg_address,
64 u8 *val)
65{
Lars-Peter Clausen196b59c2012-05-12 15:39:54 +020066 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
Jonathan Cameronafc2ff02011-06-27 13:07:55 +010067 struct ade7759_state *st = iio_priv(indio_dev);
Barry Song2919fa52010-10-27 21:44:17 -040068 int ret;
Barry Song2919fa52010-10-27 21:44:17 -040069
Jonathan Cameron3859fac2011-02-11 14:07:42 +000070 ret = spi_w8r8(st->us, ADE7759_READ_REG(reg_address));
71 if (ret < 0) {
Barry Song2919fa52010-10-27 21:44:17 -040072 dev_err(&st->us->dev, "problem when reading 8 bit register 0x%02X",
73 reg_address);
Jonathan Cameron3859fac2011-02-11 14:07:42 +000074 return ret;
Barry Song2919fa52010-10-27 21:44:17 -040075 }
Jonathan Cameron3859fac2011-02-11 14:07:42 +000076 *val = ret;
Barry Song2919fa52010-10-27 21:44:17 -040077
Jonathan Cameron3859fac2011-02-11 14:07:42 +000078 return 0;
Barry Song2919fa52010-10-27 21:44:17 -040079}
80
81static int ade7759_spi_read_reg_16(struct device *dev,
82 u8 reg_address,
83 u16 *val)
84{
Lars-Peter Clausen196b59c2012-05-12 15:39:54 +020085 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
Jonathan Cameronafc2ff02011-06-27 13:07:55 +010086 struct ade7759_state *st = iio_priv(indio_dev);
Barry Song2919fa52010-10-27 21:44:17 -040087 int ret;
Barry Song2919fa52010-10-27 21:44:17 -040088
Lars-Peter Clausen23590742013-09-27 16:34:29 +020089 ret = spi_w8r16be(st->us, ADE7759_READ_REG(reg_address));
Jonathan Cameron3859fac2011-02-11 14:07:42 +000090 if (ret < 0) {
Barry Song2919fa52010-10-27 21:44:17 -040091 dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X",
Jonathan Cameron3859fac2011-02-11 14:07:42 +000092 reg_address);
93 return ret;
Barry Song2919fa52010-10-27 21:44:17 -040094 }
Barry Song2919fa52010-10-27 21:44:17 -040095
Jonathan Cameron3859fac2011-02-11 14:07:42 +000096 *val = ret;
Jonathan Cameron3859fac2011-02-11 14:07:42 +000097
98 return 0;
Barry Song2919fa52010-10-27 21:44:17 -040099}
100
101static int ade7759_spi_read_reg_40(struct device *dev,
102 u8 reg_address,
103 u64 *val)
104{
Lars-Peter Clausen196b59c2012-05-12 15:39:54 +0200105 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
Jonathan Cameronafc2ff02011-06-27 13:07:55 +0100106 struct ade7759_state *st = iio_priv(indio_dev);
Barry Song2919fa52010-10-27 21:44:17 -0400107 int ret;
108 struct spi_transfer xfers[] = {
109 {
110 .tx_buf = st->tx,
111 .rx_buf = st->rx,
112 .bits_per_word = 8,
113 .len = 6,
114 },
115 };
116
117 mutex_lock(&st->buf_lock);
118 st->tx[0] = ADE7759_READ_REG(reg_address);
Zachary Warren56ae98a2014-11-22 22:19:31 +1100119 memset(&st->tx[1], 0, 5);
Barry Song2919fa52010-10-27 21:44:17 -0400120
Lars-Peter Clausenad6c46b2013-01-09 17:31:00 +0000121 ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
Barry Song2919fa52010-10-27 21:44:17 -0400122 if (ret) {
123 dev_err(&st->us->dev, "problem when reading 40 bit register 0x%02X",
124 reg_address);
125 goto error_ret;
126 }
127 *val = ((u64)st->rx[1] << 32) | (st->rx[2] << 24) |
128 (st->rx[3] << 16) | (st->rx[4] << 8) | st->rx[5];
129
130error_ret:
131 mutex_unlock(&st->buf_lock);
132 return ret;
133}
134
135static ssize_t ade7759_read_8bit(struct device *dev,
136 struct device_attribute *attr,
137 char *buf)
138{
139 int ret;
140 u8 val = 0;
141 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
142
143 ret = ade7759_spi_read_reg_8(dev, this_attr->address, &val);
144 if (ret)
145 return ret;
146
147 return sprintf(buf, "%u\n", val);
148}
149
150static ssize_t ade7759_read_16bit(struct device *dev,
151 struct device_attribute *attr,
152 char *buf)
153{
154 int ret;
155 u16 val = 0;
156 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
157
158 ret = ade7759_spi_read_reg_16(dev, this_attr->address, &val);
159 if (ret)
160 return ret;
161
162 return sprintf(buf, "%u\n", val);
163}
164
165static ssize_t ade7759_read_40bit(struct device *dev,
166 struct device_attribute *attr,
167 char *buf)
168{
169 int ret;
170 u64 val = 0;
171 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
172
173 ret = ade7759_spi_read_reg_40(dev, this_attr->address, &val);
174 if (ret)
175 return ret;
176
177 return sprintf(buf, "%llu\n", val);
178}
179
180static ssize_t ade7759_write_8bit(struct device *dev,
181 struct device_attribute *attr,
182 const char *buf,
183 size_t len)
184{
185 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
186 int ret;
Jingoo Hane5e26dd2013-08-20 03:31:00 +0100187 u8 val;
Barry Song2919fa52010-10-27 21:44:17 -0400188
Jingoo Hane5e26dd2013-08-20 03:31:00 +0100189 ret = kstrtou8(buf, 10, &val);
Barry Song2919fa52010-10-27 21:44:17 -0400190 if (ret)
191 goto error_ret;
192 ret = ade7759_spi_write_reg_8(dev, this_attr->address, val);
193
194error_ret:
195 return ret ? ret : len;
196}
197
198static ssize_t ade7759_write_16bit(struct device *dev,
199 struct device_attribute *attr,
200 const char *buf,
201 size_t len)
202{
203 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
204 int ret;
Jingoo Hane5e26dd2013-08-20 03:31:00 +0100205 u16 val;
Barry Song2919fa52010-10-27 21:44:17 -0400206
Jingoo Hane5e26dd2013-08-20 03:31:00 +0100207 ret = kstrtou16(buf, 10, &val);
Barry Song2919fa52010-10-27 21:44:17 -0400208 if (ret)
209 goto error_ret;
210 ret = ade7759_spi_write_reg_16(dev, this_attr->address, val);
211
212error_ret:
213 return ret ? ret : len;
214}
215
216static int ade7759_reset(struct device *dev)
217{
218 int ret;
219 u16 val;
Darshana Padmadasb0604712014-09-30 20:22:58 +0530220
Devendra Naga1e716a12015-01-02 04:02:55 -0500221 ret = ade7759_spi_read_reg_16(dev,
Barry Song2919fa52010-10-27 21:44:17 -0400222 ADE7759_MODE,
223 &val);
Devendra Naga1e716a12015-01-02 04:02:55 -0500224 if (ret < 0)
225 return ret;
226
Barry Song2919fa52010-10-27 21:44:17 -0400227 val |= 1 << 6; /* Software Chip Reset */
Aya Mahfouz838ec192015-02-27 15:08:38 +0200228 return ade7759_spi_write_reg_16(dev,
Barry Song2919fa52010-10-27 21:44:17 -0400229 ADE7759_MODE,
230 val);
Barry Song2919fa52010-10-27 21:44:17 -0400231}
232
Barry Song2919fa52010-10-27 21:44:17 -0400233static IIO_DEV_ATTR_AENERGY(ade7759_read_40bit, ADE7759_AENERGY);
234static IIO_DEV_ATTR_CFDEN(S_IWUSR | S_IRUGO,
235 ade7759_read_16bit,
236 ade7759_write_16bit,
237 ADE7759_CFDEN);
238static IIO_DEV_ATTR_CFNUM(S_IWUSR | S_IRUGO,
239 ade7759_read_8bit,
240 ade7759_write_8bit,
241 ADE7759_CFNUM);
242static IIO_DEV_ATTR_CHKSUM(ade7759_read_8bit, ADE7759_CHKSUM);
243static IIO_DEV_ATTR_PHCAL(S_IWUSR | S_IRUGO,
244 ade7759_read_16bit,
245 ade7759_write_16bit,
246 ADE7759_PHCAL);
247static IIO_DEV_ATTR_APOS(S_IWUSR | S_IRUGO,
248 ade7759_read_16bit,
249 ade7759_write_16bit,
250 ADE7759_APOS);
251static IIO_DEV_ATTR_SAGCYC(S_IWUSR | S_IRUGO,
252 ade7759_read_8bit,
253 ade7759_write_8bit,
254 ADE7759_SAGCYC);
255static IIO_DEV_ATTR_SAGLVL(S_IWUSR | S_IRUGO,
256 ade7759_read_8bit,
257 ade7759_write_8bit,
258 ADE7759_SAGLVL);
259static IIO_DEV_ATTR_LINECYC(S_IWUSR | S_IRUGO,
260 ade7759_read_8bit,
261 ade7759_write_8bit,
262 ADE7759_LINECYC);
263static IIO_DEV_ATTR_LENERGY(ade7759_read_40bit, ADE7759_LENERGY);
264static IIO_DEV_ATTR_PGA_GAIN(S_IWUSR | S_IRUGO,
265 ade7759_read_8bit,
266 ade7759_write_8bit,
267 ADE7759_GAIN);
268static IIO_DEV_ATTR_ACTIVE_POWER_GAIN(S_IWUSR | S_IRUGO,
269 ade7759_read_16bit,
270 ade7759_write_16bit,
271 ADE7759_APGAIN);
272static IIO_DEV_ATTR_CH_OFF(1, S_IWUSR | S_IRUGO,
273 ade7759_read_8bit,
274 ade7759_write_8bit,
275 ADE7759_CH1OS);
276static IIO_DEV_ATTR_CH_OFF(2, S_IWUSR | S_IRUGO,
277 ade7759_read_8bit,
278 ade7759_write_8bit,
279 ADE7759_CH2OS);
280
281static int ade7759_set_irq(struct device *dev, bool enable)
282{
283 int ret;
284 u8 irqen;
Darshana Padmadasb0604712014-09-30 20:22:58 +0530285
Barry Song2919fa52010-10-27 21:44:17 -0400286 ret = ade7759_spi_read_reg_8(dev, ADE7759_IRQEN, &irqen);
287 if (ret)
288 goto error_ret;
289
290 if (enable)
291 irqen |= 1 << 3; /* Enables an interrupt when a data is
292 present in the waveform register */
293 else
294 irqen &= ~(1 << 3);
295
296 ret = ade7759_spi_write_reg_8(dev, ADE7759_IRQEN, irqen);
Barry Song2919fa52010-10-27 21:44:17 -0400297
298error_ret:
299 return ret;
300}
301
302/* Power down the device */
Jonathan Cameron3859fac2011-02-11 14:07:42 +0000303static int ade7759_stop_device(struct device *dev)
Barry Song2919fa52010-10-27 21:44:17 -0400304{
Devendra Naga1e716a12015-01-02 04:02:55 -0500305 int ret;
Barry Song2919fa52010-10-27 21:44:17 -0400306 u16 val;
Jonathan Cameron3859fac2011-02-11 14:07:42 +0000307
Devendra Naga1e716a12015-01-02 04:02:55 -0500308 ret = ade7759_spi_read_reg_16(dev,
Barry Song2919fa52010-10-27 21:44:17 -0400309 ADE7759_MODE,
310 &val);
Devendra Naga1e716a12015-01-02 04:02:55 -0500311 if (ret < 0) {
312 dev_err(dev, "unable to power down the device, error: %d\n",
313 ret);
314 return ret;
315 }
316
Barry Song2919fa52010-10-27 21:44:17 -0400317 val |= 1 << 4; /* AD converters can be turned off */
Barry Song2919fa52010-10-27 21:44:17 -0400318
Jonathan Cameron3859fac2011-02-11 14:07:42 +0000319 return ade7759_spi_write_reg_16(dev, ADE7759_MODE, val);
Barry Song2919fa52010-10-27 21:44:17 -0400320}
321
Jonathan Cameronafc2ff02011-06-27 13:07:55 +0100322static int ade7759_initial_setup(struct iio_dev *indio_dev)
Barry Song2919fa52010-10-27 21:44:17 -0400323{
324 int ret;
Jonathan Cameronafc2ff02011-06-27 13:07:55 +0100325 struct ade7759_state *st = iio_priv(indio_dev);
326 struct device *dev = &indio_dev->dev;
Barry Song2919fa52010-10-27 21:44:17 -0400327
328 /* use low spi speed for init */
329 st->us->mode = SPI_MODE_3;
330 spi_setup(st->us);
331
332 /* Disable IRQ */
333 ret = ade7759_set_irq(dev, false);
334 if (ret) {
335 dev_err(dev, "disable irq failed");
336 goto err_ret;
337 }
338
339 ade7759_reset(dev);
340 msleep(ADE7759_STARTUP_DELAY);
341
342err_ret:
343 return ret;
344}
345
346static ssize_t ade7759_read_frequency(struct device *dev,
347 struct device_attribute *attr,
348 char *buf)
349{
Jonathan Cameron3859fac2011-02-11 14:07:42 +0000350 int ret;
Barry Song2919fa52010-10-27 21:44:17 -0400351 u16 t;
352 int sps;
Darshana Padmadasb0604712014-09-30 20:22:58 +0530353
Barry Song2919fa52010-10-27 21:44:17 -0400354 ret = ade7759_spi_read_reg_16(dev,
355 ADE7759_MODE,
356 &t);
357 if (ret)
358 return ret;
359
360 t = (t >> 3) & 0x3;
361 sps = 27900 / (1 + t);
362
Jonathan Cameron3859fac2011-02-11 14:07:42 +0000363 return sprintf(buf, "%d\n", sps);
Barry Song2919fa52010-10-27 21:44:17 -0400364}
365
366static ssize_t ade7759_write_frequency(struct device *dev,
367 struct device_attribute *attr,
368 const char *buf,
369 size_t len)
370{
Lars-Peter Clausen196b59c2012-05-12 15:39:54 +0200371 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
Jonathan Cameronafc2ff02011-06-27 13:07:55 +0100372 struct ade7759_state *st = iio_priv(indio_dev);
Jingoo Hane5e26dd2013-08-20 03:31:00 +0100373 u16 val;
Barry Song2919fa52010-10-27 21:44:17 -0400374 int ret;
375 u16 reg, t;
376
Jingoo Hane5e26dd2013-08-20 03:31:00 +0100377 ret = kstrtou16(buf, 10, &val);
Barry Song2919fa52010-10-27 21:44:17 -0400378 if (ret)
379 return ret;
Dan Carpenter50d4b302012-08-18 09:48:00 +0100380 if (val == 0)
381 return -EINVAL;
Barry Song2919fa52010-10-27 21:44:17 -0400382
383 mutex_lock(&indio_dev->mlock);
384
Haneen Mohammed5db48512015-03-13 20:47:22 +0300385 t = 27900 / val;
Barry Song2919fa52010-10-27 21:44:17 -0400386 if (t > 0)
387 t--;
388
389 if (t > 1)
390 st->us->max_speed_hz = ADE7759_SPI_SLOW;
391 else
392 st->us->max_speed_hz = ADE7759_SPI_FAST;
393
Jonathan Cameron3859fac2011-02-11 14:07:42 +0000394 ret = ade7759_spi_read_reg_16(dev, ADE7759_MODE, &reg);
Barry Song2919fa52010-10-27 21:44:17 -0400395 if (ret)
396 goto out;
397
398 reg &= ~(3 << 13);
399 reg |= t << 13;
400
Jonathan Cameron3859fac2011-02-11 14:07:42 +0000401 ret = ade7759_spi_write_reg_16(dev, ADE7759_MODE, reg);
Barry Song2919fa52010-10-27 21:44:17 -0400402
403out:
404 mutex_unlock(&indio_dev->mlock);
405
406 return ret ? ret : len;
407}
408static IIO_DEV_ATTR_TEMP_RAW(ade7759_read_8bit);
Jonathan Cameron322c9562011-09-14 13:01:23 +0100409static IIO_CONST_ATTR(in_temp_offset, "70 C");
410static IIO_CONST_ATTR(in_temp_scale, "1 C");
Barry Song2919fa52010-10-27 21:44:17 -0400411
412static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
413 ade7759_read_frequency,
414 ade7759_write_frequency);
415
Barry Song2919fa52010-10-27 21:44:17 -0400416static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("27900 14000 7000 3500");
417
Barry Song2919fa52010-10-27 21:44:17 -0400418static struct attribute *ade7759_attributes[] = {
Jonathan Cameron322c9562011-09-14 13:01:23 +0100419 &iio_dev_attr_in_temp_raw.dev_attr.attr,
420 &iio_const_attr_in_temp_offset.dev_attr.attr,
421 &iio_const_attr_in_temp_scale.dev_attr.attr,
Barry Song2919fa52010-10-27 21:44:17 -0400422 &iio_dev_attr_sampling_frequency.dev_attr.attr,
423 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
Barry Song2919fa52010-10-27 21:44:17 -0400424 &iio_dev_attr_phcal.dev_attr.attr,
425 &iio_dev_attr_cfden.dev_attr.attr,
426 &iio_dev_attr_aenergy.dev_attr.attr,
427 &iio_dev_attr_cfnum.dev_attr.attr,
428 &iio_dev_attr_apos.dev_attr.attr,
429 &iio_dev_attr_sagcyc.dev_attr.attr,
430 &iio_dev_attr_saglvl.dev_attr.attr,
431 &iio_dev_attr_linecyc.dev_attr.attr,
432 &iio_dev_attr_lenergy.dev_attr.attr,
433 &iio_dev_attr_chksum.dev_attr.attr,
434 &iio_dev_attr_pga_gain.dev_attr.attr,
435 &iio_dev_attr_active_power_gain.dev_attr.attr,
436 &iio_dev_attr_choff_1.dev_attr.attr,
437 &iio_dev_attr_choff_2.dev_attr.attr,
438 NULL,
439};
440
441static const struct attribute_group ade7759_attribute_group = {
442 .attrs = ade7759_attributes,
443};
444
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100445static const struct iio_info ade7759_info = {
446 .attrs = &ade7759_attribute_group,
447 .driver_module = THIS_MODULE,
448};
449
Bill Pemberton4ae1c612012-11-19 13:21:57 -0500450static int ade7759_probe(struct spi_device *spi)
Barry Song2919fa52010-10-27 21:44:17 -0400451{
Jonathan Cameron3859fac2011-02-11 14:07:42 +0000452 int ret;
Jonathan Cameronafc2ff02011-06-27 13:07:55 +0100453 struct ade7759_state *st;
454 struct iio_dev *indio_dev;
455
456 /* setup the industrialio driver allocated elements */
Sachin Kamatb67637a2013-09-11 10:55:00 +0100457 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
458 if (!indio_dev)
459 return -ENOMEM;
Barry Song2919fa52010-10-27 21:44:17 -0400460 /* this is only used for removal purposes */
Jonathan Cameronafc2ff02011-06-27 13:07:55 +0100461 spi_set_drvdata(spi, indio_dev);
Barry Song2919fa52010-10-27 21:44:17 -0400462
Jonathan Cameronafc2ff02011-06-27 13:07:55 +0100463 st = iio_priv(indio_dev);
Barry Song2919fa52010-10-27 21:44:17 -0400464 st->us = spi;
465 mutex_init(&st->buf_lock);
Jonathan Cameronafc2ff02011-06-27 13:07:55 +0100466 indio_dev->name = spi->dev.driver->name;
467 indio_dev->dev.parent = &spi->dev;
468 indio_dev->info = &ade7759_info;
469 indio_dev->modes = INDIO_DIRECT_MODE;
Barry Song2919fa52010-10-27 21:44:17 -0400470
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100471 /* Get the device into a sane initial state */
472 ret = ade7759_initial_setup(indio_dev);
473 if (ret)
Sachin Kamatb67637a2013-09-11 10:55:00 +0100474 return ret;
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100475
Cristina Opriceanada294612015-03-12 19:10:31 +0200476 return iio_device_register(indio_dev);
Barry Song2919fa52010-10-27 21:44:17 -0400477}
478
479/* fixme, confirm ordering in this function */
Bill Pemberton447d4f22012-11-19 13:26:37 -0500480static int ade7759_remove(struct spi_device *spi)
Barry Song2919fa52010-10-27 21:44:17 -0400481{
Jonathan Cameronafc2ff02011-06-27 13:07:55 +0100482 struct iio_dev *indio_dev = spi_get_drvdata(spi);
Barry Song2919fa52010-10-27 21:44:17 -0400483
Jonathan Camerond2fffd62011-10-14 14:46:58 +0100484 iio_device_unregister(indio_dev);
Lars-Peter Clausene854bcc2012-09-22 09:56:00 +0100485 ade7759_stop_device(&indio_dev->dev);
Barry Song2919fa52010-10-27 21:44:17 -0400486
Lars-Peter Clausene854bcc2012-09-22 09:56:00 +0100487 return 0;
Barry Song2919fa52010-10-27 21:44:17 -0400488}
489
490static struct spi_driver ade7759_driver = {
491 .driver = {
492 .name = "ade7759",
493 .owner = THIS_MODULE,
494 },
495 .probe = ade7759_probe,
Bill Pembertone543acf2012-11-19 13:21:38 -0500496 .remove = ade7759_remove,
Barry Song2919fa52010-10-27 21:44:17 -0400497};
Lars-Peter Clausenae6ae6f2011-11-16 10:13:39 +0100498module_spi_driver(ade7759_driver);
Barry Song2919fa52010-10-27 21:44:17 -0400499
500MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
501MODULE_DESCRIPTION("Analog Devices ADE7759 Active Energy Metering IC Driver");
502MODULE_LICENSE("GPL v2");
Lars-Peter Clausen55e43902011-11-16 08:53:31 +0100503MODULE_ALIAS("spi:ad7759");