Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Lars-Peter Clausen and committed by
Jonathan Cameron
2aecc5b9 37812d2e

+24 -3
+24 -3
drivers/staging/iio/trigger/iio-trig-bfin-timer.c
··· 57 57 int irq; 58 58 }; 59 59 60 + static int iio_bfin_tmr_set_state(struct iio_trigger *trig, bool state) 61 + { 62 + struct bfin_tmr_state *st = trig->private_data; 63 + 64 + if (get_gptimer_period(st->t->id) == 0) 65 + return -EINVAL; 66 + 67 + if (state) 68 + enable_gptimers(st->t->bit); 69 + else 70 + disable_gptimers(st->t->bit); 71 + 72 + return 0; 73 + } 74 + 60 75 static ssize_t iio_bfin_tmr_frequency_store(struct device *dev, 61 76 struct device_attribute *attr, const char *buf, size_t count) 62 77 { 63 78 struct iio_trigger *trig = to_iio_trigger(dev); 64 79 struct bfin_tmr_state *st = trig->private_data; 65 80 long val; 81 + bool enabled; 66 82 int ret; 67 83 68 84 ret = strict_strtoul(buf, 10, &val); ··· 90 74 goto error_ret; 91 75 } 92 76 93 - disable_gptimers(st->t->bit); 77 + enabled = get_enabled_gptimers() & st->t->bit; 78 + 79 + if (enabled) 80 + disable_gptimers(st->t->bit); 94 81 95 82 if (!val) 96 83 goto error_ret; ··· 106 87 107 88 set_gptimer_period(st->t->id, val); 108 89 set_gptimer_pwidth(st->t->id, 1); 109 - enable_gptimers(st->t->bit); 90 + 91 + if (enabled) 92 + enable_gptimers(st->t->bit); 110 93 111 94 error_ret: 112 95 return ret ? ret : count; ··· 148 127 NULL 149 128 }; 150 129 151 - 152 130 static irqreturn_t iio_bfin_tmr_trigger_isr(int irq, void *devid) 153 131 { 154 132 struct bfin_tmr_state *st = devid; ··· 171 151 172 152 static const struct iio_trigger_ops iio_bfin_tmr_trigger_ops = { 173 153 .owner = THIS_MODULE, 154 + .set_trigger_state = iio_bfin_tmr_set_state, 174 155 }; 175 156 176 157 static int __devinit iio_bfin_tmr_trigger_probe(struct platform_device *pdev)