Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ad799x_ring.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010-2012 Michael Hennerich, Analog Devices Inc.
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>
13 #include <linux/slab.h>
14 #include <linux/kernel.h>
15 #include <linux/list.h>
16 #include <linux/i2c.h>
17 #include <linux/bitops.h>
18 
19 #include <linux/iio/iio.h>
20 #include <linux/iio/buffer.h>
23 
24 #include "ad799x.h"
25 
33 static irqreturn_t ad799x_trigger_handler(int irq, void *p)
34 {
35  struct iio_poll_func *pf = p;
36  struct iio_dev *indio_dev = pf->indio_dev;
37  struct ad799x_state *st = iio_priv(indio_dev);
38  s64 time_ns;
39  __u8 *rxbuf;
40  int b_sent;
41  u8 cmd;
42 
43  rxbuf = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
44  if (rxbuf == NULL)
45  goto out;
46 
47  switch (st->id) {
48  case ad7991:
49  case ad7995:
50  case ad7999:
51  cmd = st->config |
52  (*indio_dev->active_scan_mask << AD799X_CHANNEL_SHIFT);
53  break;
54  case ad7992:
55  case ad7993:
56  case ad7994:
57  cmd = (*indio_dev->active_scan_mask << AD799X_CHANNEL_SHIFT) |
59  break;
60  case ad7997:
61  case ad7998:
63  break;
64  default:
65  cmd = 0;
66  }
67 
69  cmd, bitmap_weight(indio_dev->active_scan_mask,
70  indio_dev->masklength) * 2, rxbuf);
71  if (b_sent < 0)
72  goto done;
73 
74  time_ns = iio_get_time_ns();
75 
76  if (indio_dev->scan_timestamp)
77  memcpy(rxbuf + indio_dev->scan_bytes - sizeof(s64),
78  &time_ns, sizeof(time_ns));
79 
80  iio_push_to_buffer(indio_dev->buffer, rxbuf);
81 done:
82  kfree(rxbuf);
83 out:
84  iio_trigger_notify_done(indio_dev->trig);
85 
86  return IRQ_HANDLED;
87 }
88 
90 {
91  return iio_triggered_buffer_setup(indio_dev, NULL,
92  &ad799x_trigger_handler, NULL);
93 }
94 
95 void ad799x_ring_cleanup(struct iio_dev *indio_dev)
96 {
98 }