Merge 3.9-rc5 into staging-next
[deliverable/linux.git] / drivers / staging / iio / adc / ad799x_ring.c
CommitLineData
985dbe77 1/*
f316983f 2 * Copyright (C) 2010-2012 Michael Hennerich, Analog Devices Inc.
985dbe77
MH
3 * Copyright (C) 2008-2010 Jonathan Cameron
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * ad799x_ring.c
10 */
11
12#include <linux/interrupt.h>
985dbe77
MH
13#include <linux/slab.h>
14#include <linux/kernel.h>
985dbe77
MH
15#include <linux/list.h>
16#include <linux/i2c.h>
17#include <linux/bitops.h>
18
06458e27
JC
19#include <linux/iio/iio.h>
20#include <linux/iio/buffer.h>
06458e27 21#include <linux/iio/trigger_consumer.h>
ae3805c3 22#include <linux/iio/triggered_buffer.h>
985dbe77
MH
23
24#include "ad799x.h"
25
985dbe77 26/**
36177c03 27 * ad799x_trigger_handler() bh of trigger launched polling to ring buffer
985dbe77
MH
28 *
29 * Currently there is no option in this driver to disable the saving of
30 * timestamps within the ring.
985dbe77 31 **/
36177c03
JC
32
33static irqreturn_t ad799x_trigger_handler(int irq, void *p)
985dbe77 34{
36177c03 35 struct iio_poll_func *pf = p;
e65bc6ac 36 struct iio_dev *indio_dev = pf->indio_dev;
d8aea29b 37 struct ad799x_state *st = iio_priv(indio_dev);
985dbe77 38 s64 time_ns;
985dbe77 39 int b_sent;
985dbe77
MH
40 u8 cmd;
41
985dbe77
MH
42 switch (st->id) {
43 case ad7991:
44 case ad7995:
45 case ad7999:
550268ca
JC
46 cmd = st->config |
47 (*indio_dev->active_scan_mask << AD799X_CHANNEL_SHIFT);
985dbe77
MH
48 break;
49 case ad7992:
50 case ad7993:
51 case ad7994:
550268ca 52 cmd = (*indio_dev->active_scan_mask << AD799X_CHANNEL_SHIFT) |
1139df53 53 AD7998_CONV_RES_REG;
985dbe77
MH
54 break;
55 case ad7997:
56 case ad7998:
57 cmd = AD7997_8_READ_SEQUENCE | AD7998_CONV_RES_REG;
58 break;
59 default:
60 cmd = 0;
61 }
62
63 b_sent = i2c_smbus_read_i2c_block_data(st->client,
d8dca330 64 cmd, st->transfer_size, st->rx_buf);
985dbe77 65 if (b_sent < 0)
d8dca330 66 goto out;
985dbe77
MH
67
68 time_ns = iio_get_time_ns();
69
fd6487f8 70 if (indio_dev->scan_timestamp)
d8dca330 71 memcpy(st->rx_buf + indio_dev->scan_bytes - sizeof(s64),
a2396dfc 72 &time_ns, sizeof(time_ns));
985dbe77 73
d8dca330 74 iio_push_to_buffers(indio_dev, st->rx_buf);
d22fd9c5
MH
75out:
76 iio_trigger_notify_done(indio_dev->trig);
77
36177c03 78 return IRQ_HANDLED;
985dbe77
MH
79}
80
985dbe77
MH
81int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev)
82{
ae3805c3
LPC
83 return iio_triggered_buffer_setup(indio_dev, NULL,
84 &ad799x_trigger_handler, NULL);
985dbe77
MH
85}
86
87void ad799x_ring_cleanup(struct iio_dev *indio_dev)
88{
ae3805c3 89 iio_triggered_buffer_cleanup(indio_dev);
985dbe77 90}
This page took 0.323685 seconds and 5 git commands to generate.