Commit 2aecc5b9 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Jonathan Cameron

staging:iio:trigger:bfintmr: Only enable timer when necessary

This patch hooks up the set_trigger_state callback for the blackfin timer
trigger driver and only enables the timer when a trigger consumer requests it to
be enabled. There really is no reason to keep the timer running and generate
interrupts if nobody is listening to them.
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 37812d2e
...@@ -57,12 +57,28 @@ struct bfin_tmr_state { ...@@ -57,12 +57,28 @@ struct bfin_tmr_state {
int irq; int irq;
}; };
static int iio_bfin_tmr_set_state(struct iio_trigger *trig, bool state)
{
struct bfin_tmr_state *st = trig->private_data;
if (get_gptimer_period(st->t->id) == 0)
return -EINVAL;
if (state)
enable_gptimers(st->t->bit);
else
disable_gptimers(st->t->bit);
return 0;
}
static ssize_t iio_bfin_tmr_frequency_store(struct device *dev, static ssize_t iio_bfin_tmr_frequency_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count) struct device_attribute *attr, const char *buf, size_t count)
{ {
struct iio_trigger *trig = to_iio_trigger(dev); struct iio_trigger *trig = to_iio_trigger(dev);
struct bfin_tmr_state *st = trig->private_data; struct bfin_tmr_state *st = trig->private_data;
long val; long val;
bool enabled;
int ret; int ret;
ret = strict_strtoul(buf, 10, &val); ret = strict_strtoul(buf, 10, &val);
...@@ -74,6 +90,9 @@ static ssize_t iio_bfin_tmr_frequency_store(struct device *dev, ...@@ -74,6 +90,9 @@ static ssize_t iio_bfin_tmr_frequency_store(struct device *dev,
goto error_ret; goto error_ret;
} }
enabled = get_enabled_gptimers() & st->t->bit;
if (enabled)
disable_gptimers(st->t->bit); disable_gptimers(st->t->bit);
if (!val) if (!val)
...@@ -87,6 +106,8 @@ static ssize_t iio_bfin_tmr_frequency_store(struct device *dev, ...@@ -87,6 +106,8 @@ static ssize_t iio_bfin_tmr_frequency_store(struct device *dev,
set_gptimer_period(st->t->id, val); set_gptimer_period(st->t->id, val);
set_gptimer_pwidth(st->t->id, 1); set_gptimer_pwidth(st->t->id, 1);
if (enabled)
enable_gptimers(st->t->bit); enable_gptimers(st->t->bit);
error_ret: error_ret:
...@@ -127,7 +148,6 @@ static const struct attribute_group *iio_bfin_tmr_trigger_attr_groups[] = { ...@@ -127,7 +148,6 @@ static const struct attribute_group *iio_bfin_tmr_trigger_attr_groups[] = {
NULL NULL
}; };
static irqreturn_t iio_bfin_tmr_trigger_isr(int irq, void *devid) static irqreturn_t iio_bfin_tmr_trigger_isr(int irq, void *devid)
{ {
struct bfin_tmr_state *st = devid; struct bfin_tmr_state *st = devid;
...@@ -151,6 +171,7 @@ static int iio_bfin_tmr_get_number(int irq) ...@@ -151,6 +171,7 @@ static int iio_bfin_tmr_get_number(int irq)
static const struct iio_trigger_ops iio_bfin_tmr_trigger_ops = { static const struct iio_trigger_ops iio_bfin_tmr_trigger_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.set_trigger_state = iio_bfin_tmr_set_state,
}; };
static int __devinit iio_bfin_tmr_trigger_probe(struct platform_device *pdev) static int __devinit iio_bfin_tmr_trigger_probe(struct platform_device *pdev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment