cs5535-mfgpt: reuse timers that have never been set up
authorJens Rottmann <JRottmann@LiPPERTEmbedded.de>
Wed, 11 Aug 2010 01:03:12 +0000 (18:03 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 11 Aug 2010 15:59:20 +0000 (08:59 -0700)
The MFGPT hardware may be set up only once, therefore
cs5535_mfgpt_free_timer() didn't re-set the timer's "avail" bit.  However
if a timer is freed before it has actually been in use then it may be made
available again.

Signed-off-by: Jens Rottmann <JRottmann@LiPPERTEmbedded.de>
Acked-by: Andres Salomon <dilinger@queued.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jordan Crouse <jordan@cosmicpenguin.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/misc/cs5535-mfgpt.c

index 2d44b3300104eb183f902212bf281849dce00186..6f6218061b0dfff3adc3b5cc862da3162d6b0077 100644 (file)
@@ -211,6 +211,17 @@ EXPORT_SYMBOL_GPL(cs5535_mfgpt_alloc_timer);
  */
 void cs5535_mfgpt_free_timer(struct cs5535_mfgpt_timer *timer)
 {
+       unsigned long flags;
+       uint16_t val;
+
+       /* timer can be made available again only if never set up */
+       val = cs5535_mfgpt_read(timer, MFGPT_REG_SETUP);
+       if (!(val & MFGPT_SETUP_SETUP)) {
+               spin_lock_irqsave(&timer->chip->lock, flags);
+               __set_bit(timer->nr, timer->chip->avail);
+               spin_unlock_irqrestore(&timer->chip->lock, flags);
+       }
+
        kfree(timer);
 }
 EXPORT_SYMBOL_GPL(cs5535_mfgpt_free_timer);