Merge branch 'stable/bug-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git...
[pandora-kernel.git] / arch / arm / mach-omap2 / omap_hwmod.c
index 1a0dd56..e282e35 100644 (file)
  * - Open Core Protocol Specification 2.2
  *
  * To do:
- * - pin mux handling
  * - handle IO mapping
  * - bus throughput & module latency measurement code
  *
 #include "cm44xx.h"
 #include "prm2xxx_3xxx.h"
 #include "prm44xx.h"
+#include "mux.h"
 
 /* Maximum microseconds to wait for OMAP module to softreset */
 #define MAX_MODULE_SOFTRESET_WAIT      10000
 /* omap_hwmod_list contains all registered struct omap_hwmods */
 static LIST_HEAD(omap_hwmod_list);
 
-static DEFINE_MUTEX(omap_hwmod_mutex);
-
 /* mpu_oh: used to add/remove MPU initiator from sleepdep list */
 static struct omap_hwmod *mpu_oh;
 
@@ -395,7 +393,8 @@ static int _enable_wakeup(struct omap_hwmod *oh, u32 *v)
        u32 wakeup_mask;
 
        if (!oh->class->sysc ||
-           !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
+           !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
+             (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)))
                return -EINVAL;
 
        if (!oh->class->sysc->sysc_fields) {
@@ -407,6 +406,9 @@ static int _enable_wakeup(struct omap_hwmod *oh, u32 *v)
 
        *v |= wakeup_mask;
 
+       if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
+               _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
+
        /* XXX test pwrdm_get_wken for this hwmod's subsystem */
 
        oh->_int_flags |= _HWMOD_WAKEUP_ENABLED;
@@ -426,7 +428,8 @@ static int _disable_wakeup(struct omap_hwmod *oh, u32 *v)
        u32 wakeup_mask;
 
        if (!oh->class->sysc ||
-           !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
+           !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
+             (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)))
                return -EINVAL;
 
        if (!oh->class->sysc->sysc_fields) {
@@ -438,6 +441,9 @@ static int _disable_wakeup(struct omap_hwmod *oh, u32 *v)
 
        *v &= ~wakeup_mask;
 
+       if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
+               _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART, v);
+
        /* XXX test pwrdm_get_wken for this hwmod's subsystem */
 
        oh->_int_flags &= ~_HWMOD_WAKEUP_ENABLED;
@@ -834,6 +840,10 @@ static void _idle_sysc(struct omap_hwmod *oh)
                _set_master_standbymode(oh, idlemode, &v);
        }
 
+       /* If slave is in SMARTIDLE, also enable wakeup */
+       if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
+               _enable_wakeup(oh, &v);
+
        _write_sysconfig(v, oh);
 }
 
@@ -872,7 +882,6 @@ static void _shutdown_sysc(struct omap_hwmod *oh)
  * @name: find an omap_hwmod by name
  *
  * Return a pointer to an omap_hwmod by name, or NULL if not found.
- * Caller must hold omap_hwmod_mutex.
  */
 static struct omap_hwmod *_lookup(const char *name)
 {
@@ -1220,7 +1229,9 @@ static int _enable(struct omap_hwmod *oh)
             oh->_state == _HWMOD_STATE_DISABLED) && oh->rst_lines_cnt == 1)
                _deassert_hardreset(oh, oh->rst_lines[0].name);
 
-       /* XXX mux balls */
+       /* Mux pins for device runtime if populated */
+       if (oh->mux)
+               omap_hwmod_mux(oh->mux, _HWMOD_STATE_ENABLED);
 
        _add_initiator_dep(oh, mpu_oh);
        _enable_clocks(oh);
@@ -1236,6 +1247,7 @@ static int _enable(struct omap_hwmod *oh)
                        _enable_sysc(oh);
                }
        } else {
+               _disable_clocks(oh);
                pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n",
                         oh->name, r);
        }
@@ -1266,6 +1278,10 @@ static int _idle(struct omap_hwmod *oh)
        _del_initiator_dep(oh, mpu_oh);
        _disable_clocks(oh);
 
+       /* Mux pins for device idle if populated */
+       if (oh->mux)
+               omap_hwmod_mux(oh->mux, _HWMOD_STATE_IDLE);
+
        oh->_state = _HWMOD_STATE_IDLE;
 
        return 0;
@@ -1324,7 +1340,9 @@ static int _shutdown(struct omap_hwmod *oh)
        }
        /* XXX Should this code also force-disable the optional clocks? */
 
-       /* XXX mux any associated balls to safe mode */
+       /* Mux pins to safe mode or use populated off mode values */
+       if (oh->mux)
+               omap_hwmod_mux(oh->mux, _HWMOD_STATE_DISABLED);
 
        oh->_state = _HWMOD_STATE_DISABLED;
 
@@ -1443,14 +1461,10 @@ static int __init _register(struct omap_hwmod *oh)
            (oh->_state != _HWMOD_STATE_UNKNOWN))
                return -EINVAL;
 
-       mutex_lock(&omap_hwmod_mutex);
-
        pr_debug("omap_hwmod: %s: registering\n", oh->name);
 
-       if (_lookup(oh->name)) {
-               ret = -EEXIST;
-               goto ohr_unlock;
-       }
+       if (_lookup(oh->name))
+               return -EEXIST;
 
        ms_id = _find_mpu_port_index(oh);
        if (!IS_ERR_VALUE(ms_id)) {
@@ -1468,8 +1482,6 @@ static int __init _register(struct omap_hwmod *oh)
 
        ret = 0;
 
-ohr_unlock:
-       mutex_unlock(&omap_hwmod_mutex);
        return ret;
 }
 
@@ -1538,9 +1550,7 @@ struct omap_hwmod *omap_hwmod_lookup(const char *name)
        if (!name)
                return NULL;
 
-       mutex_lock(&omap_hwmod_mutex);
        oh = _lookup(name);
-       mutex_unlock(&omap_hwmod_mutex);
 
        return oh;
 }
@@ -1566,13 +1576,11 @@ int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data),
        if (!fn)
                return -EINVAL;
 
-       mutex_lock(&omap_hwmod_mutex);
        list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
                ret = (*fn)(temp_oh, data);
                if (ret)
                        break;
        }
-       mutex_unlock(&omap_hwmod_mutex);
 
        return ret;
 }
@@ -2112,9 +2120,8 @@ int omap_hwmod_read_hardreset(struct omap_hwmod *oh, const char *name)
  * @fn: callback function pointer to call for each hwmod in class @classname
  * @user: arbitrary context data to pass to the callback function
  *
- * For each omap_hwmod of class @classname, call @fn.  Takes
- * omap_hwmod_mutex to prevent the hwmod list from changing during the
- * iteration.  If the callback function returns something other than
+ * For each omap_hwmod of class @classname, call @fn.
+ * If the callback function returns something other than
  * zero, the iterator is terminated, and the callback function's return
  * value is passed back to the caller.  Returns 0 upon success, -EINVAL
  * if @classname or @fn are NULL, or passes back the error code from @fn.
@@ -2133,8 +2140,6 @@ int omap_hwmod_for_each_by_class(const char *classname,
        pr_debug("omap_hwmod: %s: looking for modules of class %s\n",
                 __func__, classname);
 
-       mutex_lock(&omap_hwmod_mutex);
-
        list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
                if (!strcmp(temp_oh->class->name, classname)) {
                        pr_debug("omap_hwmod: %s: %s: calling callback fn\n",
@@ -2145,8 +2150,6 @@ int omap_hwmod_for_each_by_class(const char *classname,
                }
        }
 
-       mutex_unlock(&omap_hwmod_mutex);
-
        if (ret)
                pr_debug("omap_hwmod: %s: iterator terminated early: %d\n",
                         __func__, ret);
@@ -2193,3 +2196,25 @@ ohsps_unlock:
 
        return ret;
 }
+
+/**
+ * omap_hwmod_get_context_loss_count - get lost context count
+ * @oh: struct omap_hwmod *
+ *
+ * Query the powerdomain of of @oh to get the context loss
+ * count for this device.
+ *
+ * Returns the context loss count of the powerdomain assocated with @oh
+ * upon success, or zero if no powerdomain exists for @oh.
+ */
+u32 omap_hwmod_get_context_loss_count(struct omap_hwmod *oh)
+{
+       struct powerdomain *pwrdm;
+       int ret = 0;
+
+       pwrdm = omap_hwmod_get_pwrdm(oh);
+       if (pwrdm)
+               ret = pwrdm_get_context_loss_count(pwrdm);
+
+       return ret;
+}