~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to drivers/staging/iio/imu/adis16300_trigger.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno, Martin Michlmayr
  • Date: 2011-04-06 13:53:30 UTC
  • mfrom: (43.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110406135330-wjufxhd0tvn3zx4z
Tags: 2.6.38-3
[ Ben Hutchings ]
* [ppc64] Add to linux-tools package architectures (Closes: #620124)
* [amd64] Save cr4 to mmu_cr4_features at boot time (Closes: #620284)
* appletalk: Fix bugs introduced when removing use of BKL
* ALSA: Fix yet another race in disconnection
* cciss: Fix lost command issue
* ath9k: Fix kernel panic in AR2427
* ses: Avoid kernel panic when lun 0 is not mapped
* PCI/ACPI: Report ASPM support to BIOS if not disabled from command line

[ Aurelien Jarno ]
* rtlwifi: fix build when PCI is not enabled.

[ Martin Michlmayr ]
* rtlwifi: Eliminate udelay calls with too large values (Closes: #620204)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <linux/interrupt.h>
 
2
#include <linux/irq.h>
 
3
#include <linux/mutex.h>
 
4
#include <linux/device.h>
 
5
#include <linux/kernel.h>
 
6
#include <linux/sysfs.h>
 
7
#include <linux/list.h>
 
8
#include <linux/spi/spi.h>
 
9
 
 
10
#include "../iio.h"
 
11
#include "../sysfs.h"
 
12
#include "../trigger.h"
 
13
#include "adis16300.h"
 
14
 
 
15
/**
 
16
 * adis16300_data_rdy_trig_poll() the event handler for the data rdy trig
 
17
 **/
 
18
static int adis16300_data_rdy_trig_poll(struct iio_dev *dev_info,
 
19
                                       int index,
 
20
                                       s64 timestamp,
 
21
                                       int no_test)
 
22
{
 
23
        struct adis16300_state *st = iio_dev_get_devdata(dev_info);
 
24
        struct iio_trigger *trig = st->trig;
 
25
 
 
26
        iio_trigger_poll(trig, timestamp);
 
27
 
 
28
        return IRQ_HANDLED;
 
29
}
 
30
 
 
31
IIO_EVENT_SH(data_rdy_trig, &adis16300_data_rdy_trig_poll);
 
32
 
 
33
static IIO_TRIGGER_NAME_ATTR;
 
34
 
 
35
static struct attribute *adis16300_trigger_attrs[] = {
 
36
        &dev_attr_name.attr,
 
37
        NULL,
 
38
};
 
39
 
 
40
static const struct attribute_group adis16300_trigger_attr_group = {
 
41
        .attrs = adis16300_trigger_attrs,
 
42
};
 
43
 
 
44
/**
 
45
 * adis16300_data_rdy_trigger_set_state() set datardy interrupt state
 
46
 **/
 
47
static int adis16300_data_rdy_trigger_set_state(struct iio_trigger *trig,
 
48
                                                bool state)
 
49
{
 
50
        struct adis16300_state *st = trig->private_data;
 
51
        struct iio_dev *indio_dev = st->indio_dev;
 
52
        int ret = 0;
 
53
 
 
54
        dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state);
 
55
        ret = adis16300_set_irq(&st->indio_dev->dev, state);
 
56
        if (state == false) {
 
57
                iio_remove_event_from_list(&iio_event_data_rdy_trig,
 
58
                                           &indio_dev->interrupts[0]
 
59
                                           ->ev_list);
 
60
                /* possible quirk with handler currently worked around
 
61
                   by ensuring the work queue is empty */
 
62
                flush_scheduled_work();
 
63
        } else {
 
64
                iio_add_event_to_list(&iio_event_data_rdy_trig,
 
65
                                      &indio_dev->interrupts[0]->ev_list);
 
66
        }
 
67
        return ret;
 
68
}
 
69
 
 
70
/**
 
71
 * adis16300_trig_try_reen() try renabling irq for data rdy trigger
 
72
 * @trig:       the datardy trigger
 
73
 **/
 
74
static int adis16300_trig_try_reen(struct iio_trigger *trig)
 
75
{
 
76
        struct adis16300_state *st = trig->private_data;
 
77
        enable_irq(st->us->irq);
 
78
        /* irq reenabled so success! */
 
79
        return 0;
 
80
}
 
81
 
 
82
int adis16300_probe_trigger(struct iio_dev *indio_dev)
 
83
{
 
84
        int ret;
 
85
        struct adis16300_state *st = indio_dev->dev_data;
 
86
 
 
87
        st->trig = iio_allocate_trigger();
 
88
        st->trig->name = kasprintf(GFP_KERNEL,
 
89
                                   "adis16300-dev%d",
 
90
                                   indio_dev->id);
 
91
        if (!st->trig->name) {
 
92
                ret = -ENOMEM;
 
93
                goto error_free_trig;
 
94
        }
 
95
        st->trig->dev.parent = &st->us->dev;
 
96
        st->trig->owner = THIS_MODULE;
 
97
        st->trig->private_data = st;
 
98
        st->trig->set_trigger_state = &adis16300_data_rdy_trigger_set_state;
 
99
        st->trig->try_reenable = &adis16300_trig_try_reen;
 
100
        st->trig->control_attrs = &adis16300_trigger_attr_group;
 
101
        ret = iio_trigger_register(st->trig);
 
102
 
 
103
        /* select default trigger */
 
104
        indio_dev->trig = st->trig;
 
105
        if (ret)
 
106
                goto error_free_trig_name;
 
107
 
 
108
        return 0;
 
109
 
 
110
error_free_trig_name:
 
111
        kfree(st->trig->name);
 
112
error_free_trig:
 
113
        iio_free_trigger(st->trig);
 
114
 
 
115
        return ret;
 
116
}
 
117
 
 
118
void adis16300_remove_trigger(struct iio_dev *indio_dev)
 
119
{
 
120
        struct adis16300_state *state = indio_dev->dev_data;
 
121
 
 
122
        iio_trigger_unregister(state->trig);
 
123
        kfree(state->trig->name);
 
124
        iio_free_trigger(state->trig);
 
125
}