ARM: OMAP: Add function to request a timer by capability
authorJon Hunter <jon-hunter@ti.com>
Thu, 6 Sep 2012 20:28:00 +0000 (15:28 -0500)
committerJon Hunter <jon-hunter@ti.com>
Fri, 2 Nov 2012 18:16:29 +0000 (13:16 -0500)
Currently OMAP timers can be requested by requesting any available or by a
numerical device ID. If a specific timer is required because it has a particular
capability, such as can interrupt the on-chip DSP in addition to the ARM CPU,
then the user needs to know the device ID of the timer with this feature.
Therefore, add a new API called omap_dm_timer_request_by_cap() that allows
drivers to request a timer by capability.

Signed-off-by: Jon Hunter <jon-hunter@ti.com>
arch/arm/plat-omap/dmtimer.c
arch/arm/plat-omap/include/plat/dmtimer.h

index 938b50a33439b092202de715e81267b18b5f73cb..2574b86ad2dc29547b67b7880156d5b1c4ab2d9d 100644 (file)
@@ -237,6 +237,58 @@ struct omap_dm_timer *omap_dm_timer_request_specific(int id)
 }
 EXPORT_SYMBOL_GPL(omap_dm_timer_request_specific);
 
+/**
+ * omap_dm_timer_request_by_cap - Request a timer by capability
+ * @cap:       Bit mask of capabilities to match
+ *
+ * Find a timer based upon capabilities bit mask. Callers of this function
+ * should use the definitions found in the plat/dmtimer.h file under the
+ * comment "timer capabilities used in hwmod database". Returns pointer to
+ * timer handle on success and a NULL pointer on failure.
+ */
+struct omap_dm_timer *omap_dm_timer_request_by_cap(u32 cap)
+{
+       struct omap_dm_timer *timer = NULL, *t;
+       unsigned long flags;
+
+       if (!cap)
+               return NULL;
+
+       spin_lock_irqsave(&dm_timer_lock, flags);
+       list_for_each_entry(t, &omap_timer_list, node) {
+               if ((!t->reserved) && ((t->capability & cap) == cap)) {
+                       /*
+                        * If timer is not NULL, we have already found one timer
+                        * but it was not an exact match because it had more
+                        * capabilites that what was required. Therefore,
+                        * unreserve the last timer found and see if this one
+                        * is a better match.
+                        */
+                       if (timer)
+                               timer->reserved = 0;
+
+                       timer = t;
+                       timer->reserved = 1;
+
+                       /* Exit loop early if we find an exact match */
+                       if (t->capability == cap)
+                               break;
+               }
+       }
+       spin_unlock_irqrestore(&dm_timer_lock, flags);
+
+       if (timer && omap_dm_timer_prepare(timer)) {
+               timer->reserved = 0;
+               timer = NULL;
+       }
+
+       if (!timer)
+               pr_debug("%s: timer request failed!\n", __func__);
+
+       return timer;
+}
+EXPORT_SYMBOL_GPL(omap_dm_timer_request_by_cap);
+
 int omap_dm_timer_free(struct omap_dm_timer *timer)
 {
        if (unlikely(!timer))
index 85868e98c11cd4ce4466da49669ee4cafc41c29f..348f855d3dabb25d0ea3b73b5f9ae0cdf7448b45 100644 (file)
@@ -99,6 +99,7 @@ struct dmtimer_platform_data {
 int omap_dm_timer_reserve_systimer(int id);
 struct omap_dm_timer *omap_dm_timer_request(void);
 struct omap_dm_timer *omap_dm_timer_request_specific(int timer_id);
+struct omap_dm_timer *omap_dm_timer_request_by_cap(u32 cap);
 int omap_dm_timer_free(struct omap_dm_timer *timer);
 void omap_dm_timer_enable(struct omap_dm_timer *timer);
 void omap_dm_timer_disable(struct omap_dm_timer *timer);