~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/staging/iio/gyro/adis16260_trigger.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#include "adis16260.h"
14
14
 
15
15
/**
16
 
 * adis16260_data_rdy_trig_poll() the event handler for the data rdy trig
17
 
 **/
18
 
static int adis16260_data_rdy_trig_poll(struct iio_dev *dev_info,
19
 
                                       int index,
20
 
                                       s64 timestamp,
21
 
                                       int no_test)
22
 
{
23
 
        struct adis16260_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, &adis16260_data_rdy_trig_poll);
32
 
 
33
 
static IIO_TRIGGER_NAME_ATTR;
34
 
 
35
 
static struct attribute *adis16260_trigger_attrs[] = {
36
 
        &dev_attr_name.attr,
37
 
        NULL,
38
 
};
39
 
 
40
 
static const struct attribute_group adis16260_trigger_attr_group = {
41
 
        .attrs = adis16260_trigger_attrs,
42
 
};
43
 
 
44
 
/**
45
16
 * adis16260_data_rdy_trigger_set_state() set datardy interrupt state
46
17
 **/
47
18
static int adis16260_data_rdy_trigger_set_state(struct iio_trigger *trig,
49
20
{
50
21
        struct adis16260_state *st = trig->private_data;
51
22
        struct iio_dev *indio_dev = st->indio_dev;
52
 
        int ret = 0;
53
23
 
54
24
        dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state);
55
 
        ret = adis16260_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
 
                flush_scheduled_work();
61
 
        } else {
62
 
                iio_add_event_to_list(&iio_event_data_rdy_trig,
63
 
                                      &indio_dev->interrupts[0]->ev_list);
64
 
        }
65
 
        return ret;
66
 
}
67
 
 
68
 
/**
69
 
 * adis16260_trig_try_reen() try renabling irq for data rdy trigger
70
 
 * @trig:       the datardy trigger
71
 
 **/
72
 
static int adis16260_trig_try_reen(struct iio_trigger *trig)
73
 
{
74
 
        struct adis16260_state *st = trig->private_data;
75
 
        enable_irq(st->us->irq);
76
 
        return 0;
 
25
        return adis16260_set_irq(indio_dev, state);
77
26
}
78
27
 
79
28
int adis16260_probe_trigger(struct iio_dev *indio_dev)
81
30
        int ret;
82
31
        struct adis16260_state *st = indio_dev->dev_data;
83
32
 
84
 
        st->trig = iio_allocate_trigger();
85
 
        st->trig->name = kasprintf(GFP_KERNEL,
86
 
                                   "adis16260-dev%d",
87
 
                                   indio_dev->id);
88
 
        if (!st->trig->name) {
 
33
        st->trig = iio_allocate_trigger("%s-dev%d",
 
34
                                        spi_get_device_id(st->us)->name,
 
35
                                        indio_dev->id);
 
36
        if (st->trig == NULL) {
89
37
                ret = -ENOMEM;
 
38
                goto error_ret;
 
39
        }
 
40
 
 
41
        ret = request_irq(st->us->irq,
 
42
                          &iio_trigger_generic_data_rdy_poll,
 
43
                          IRQF_TRIGGER_RISING,
 
44
                          "adis16260",
 
45
                          st->trig);
 
46
        if (ret)
90
47
                goto error_free_trig;
91
 
        }
 
48
 
92
49
        st->trig->dev.parent = &st->us->dev;
93
50
        st->trig->owner = THIS_MODULE;
94
51
        st->trig->private_data = st;
95
52
        st->trig->set_trigger_state = &adis16260_data_rdy_trigger_set_state;
96
 
        st->trig->try_reenable = &adis16260_trig_try_reen;
97
 
        st->trig->control_attrs = &adis16260_trigger_attr_group;
98
53
        ret = iio_trigger_register(st->trig);
99
54
 
100
55
        /* select default trigger */
101
56
        indio_dev->trig = st->trig;
102
57
        if (ret)
103
 
                goto error_free_trig_name;
 
58
                goto error_free_irq;
104
59
 
105
60
        return 0;
106
61
 
107
 
error_free_trig_name:
108
 
        kfree(st->trig->name);
 
62
error_free_irq:
 
63
        free_irq(st->us->irq, st->trig);
109
64
error_free_trig:
110
65
        iio_free_trigger(st->trig);
111
 
 
 
66
error_ret:
112
67
        return ret;
113
68
}
114
69
 
117
72
        struct adis16260_state *state = indio_dev->dev_data;
118
73
 
119
74
        iio_trigger_unregister(state->trig);
120
 
        kfree(state->trig->name);
 
75
        free_irq(state->us->irq, state->trig);
121
76
        iio_free_trigger(state->trig);
122
77
}