Skip to content

Commit

Permalink
staging:iio:meter:ade7758: Update trigger to the new API
Browse files Browse the repository at this point in the history
Update trigger to the new API.
Add file comment/license header.

Some backporting needed to keep the driver building all the way
through the core changes.

Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Michael Hennerich authored and Greg Kroah-Hartman committed May 19, 2011
1 parent faf290e commit 69c272c
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions drivers/staging/iio/meter/ade7758_trigger.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* ADE7758 Poly Phase Multifunction Energy Metering IC driver
*
* Copyright 2010-2011 Analog Devices Inc.
*
* Licensed under the GPL-2.
*/

#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/mutex.h>
Expand All @@ -19,20 +27,10 @@ static irqreturn_t ade7758_data_rdy_trig_poll(int irq, void *private)
{
disable_irq_nosync(irq);
iio_trigger_poll(private, iio_get_time_ns());

return IRQ_HANDLED;
}

static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL);

static struct attribute *ade7758_trigger_attrs[] = {
&dev_attr_name.attr,
NULL,
};

static const struct attribute_group ade7758_trigger_attr_group = {
.attrs = ade7758_trigger_attrs,
};

/**
* ade7758_data_rdy_trigger_set_state() set datardy interrupt state
**/
Expand All @@ -53,6 +51,7 @@ static int ade7758_data_rdy_trigger_set_state(struct iio_trigger *trig,
static int ade7758_trig_try_reen(struct iio_trigger *trig)
{
struct ade7758_state *st = trig->private_data;

enable_irq(st->us->irq);
/* irq reenabled so success! */
return 0;
Expand All @@ -62,48 +61,51 @@ int ade7758_probe_trigger(struct iio_dev *indio_dev)
{
int ret;
struct ade7758_state *st = indio_dev->dev_data;
char *name;

name = kasprintf(GFP_KERNEL,
"%s-dev%d",
spi_get_device_id(st->us)->name,
indio_dev->id);
if (name == NULL) {
ret = -ENOMEM;
goto error_ret;
}

st->trig = iio_allocate_trigger();
st->trig = iio_allocate_trigger_named(name);
if (st->trig == NULL) {
ret = -ENOMEM;
goto error_ret;
goto error_free_name;
}

ret = request_irq(st->us->irq,
ade7758_data_rdy_trig_poll,
IRQF_TRIGGER_FALLING, "ade7758",
IRQF_TRIGGER_LOW,
spi_get_device_id(st->us)->name,
st->trig);
if (ret)
goto error_free_trig;

st->trig->name = kasprintf(GFP_KERNEL,
"ade7758-dev%d",
indio_dev->id);
if (!st->trig->name) {
ret = -ENOMEM;
goto error_free_irq;
}
st->trig->dev.parent = &st->us->dev;
st->trig->owner = THIS_MODULE;
st->trig->private_data = st;
st->trig->set_trigger_state = &ade7758_data_rdy_trigger_set_state;
st->trig->try_reenable = &ade7758_trig_try_reen;
st->trig->control_attrs = &ade7758_trigger_attr_group;
ret = iio_trigger_register(st->trig);

/* select default trigger */
indio_dev->trig = st->trig;
if (ret)
goto error_free_trig_name;
goto error_free_irq;

return 0;

error_free_trig_name:
kfree(st->trig->name);
error_free_irq:
free_irq(st->us->irq, st->trig);
error_free_trig:
iio_free_trigger(st->trig);
error_free_name:
kfree(name);
error_ret:
return ret;
}
Expand Down

0 comments on commit 69c272c

Please sign in to comment.