fixed, limit MX Sticks to 800MHz or they overheat and crash
authordavilla <davilla@4pi.com>
Thu, 21 Feb 2013 14:10:13 +0000 (09:10 -0500)
committerTrent Nelson <trent.a.b.nelson@gmail.com>
Mon, 11 Nov 2013 01:33:24 +0000 (20:33 -0500)
do not change scaling_min_freq if mx stick.
change scaling_governor to ondemand to get better cpu freq cycling

xbmc/utils/AMLUtils.cpp
xbmc/utils/AMLUtils.h
xbmc/windowing/egl/EGLNativeTypeAmlogic.cpp
xbmc/windowing/egl/EGLNativeTypeAndroid.cpp

index 4986169..4c0e161 100644 (file)
@@ -97,7 +97,21 @@ bool aml_present()
     if (has_aml)
       CLog::Log(LOGNOTICE, "aml_present, rtn(%d)", rtn);
   }
-  return has_aml;
+  return has_aml == 1;
+}
+
+bool aml_wired_present()
+{
+  static int has_wired = -1;
+  if (has_wired == -1)
+  {
+    char test[64] = {0};
+    if (aml_get_sysfs_str("/sys/class/net/eth0/operstate", test, 63) != -1)
+      has_wired = 1;
+    else
+      has_wired = 0;
+  }
+  return has_wired == 1;
 }
 
 void aml_permissions()
@@ -118,6 +132,7 @@ void aml_permissions()
     system("su -c chmod 666 /sys/class/audiodsp/digital_raw");
     system("su -c chmod 666 /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq");
     system("su -c chmod 666 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq");
+    system("su -c chmod 666 /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor");
     CLog::Log(LOGINFO, "aml_permissions: permissions changed");
   }
 }
@@ -142,19 +157,42 @@ int aml_get_cputype()
   return aml_cputype;
 }
 
-void aml_cpufreq_limit(bool limit)
+void aml_cpufreq_min(bool limit)
+{
+// do not touch scaling_min_freq on android
+#if !defined(TARGET_ANDROID)
+  // only needed for m1/m3 SoCs
+  if (aml_get_cputype() <= 3)
+  {
+    int cpufreq = 300000;
+    if (limit)
+      cpufreq = 600000;
+
+    aml_set_sysfs_int("/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq", cpufreq);
+  }
+#endif
+}
+
+void aml_cpufreq_max(bool limit)
 {
-  int cpufreq = 300000;
-  if (limit)
-    cpufreq = 600000;
+  if (!aml_wired_present() && aml_get_cputype() > 3)
+  {
+    // this is a MX Stick, they cannot substain 1GHz
+    // operation without overheating so limit them to 800MHz.
+    int cpufreq = 1000000;
+    if (limit)
+      cpufreq = 800000;
 
-  aml_set_sysfs_int("/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq", cpufreq);
+    aml_set_sysfs_int("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq", cpufreq);
+    aml_set_sysfs_str("/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor", "ondemand");
+  }
 }
 
 void aml_set_audio_passthrough(bool passthrough)
 {
   if (aml_present())
   {
+    // m1 uses 1, m3 and above uses 2
     int raw = aml_get_cputype() < 3 ? 1:2;
     aml_set_sysfs_int("/sys/class/audiodsp/digital_raw", passthrough ? raw:0);
   }
index 34fe519..5bb2429 100644 (file)
@@ -26,6 +26,8 @@ int aml_get_sysfs_int(const char *path);
 
 bool aml_present();
 void aml_permissions();
+bool aml_wired_present();
 int  aml_get_cputype();
-void aml_cpufreq_limit(bool limit);
+void aml_cpufreq_min(bool limit);
+void aml_cpufreq_max(bool limit);
 void aml_set_audio_passthrough(bool passthrough);
index 71e61ef..6523e1b 100644 (file)
@@ -62,12 +62,15 @@ bool CEGLNativeTypeAmlogic::CheckCompatibility()
 
 void CEGLNativeTypeAmlogic::Initialize()
 {
-  aml_cpufreq_limit(true);
+  aml_permissions();
+  aml_cpufreq_min(true);
+  aml_cpufreq_max(true);
   return;
 }
 void CEGLNativeTypeAmlogic::Destroy()
 {
-  aml_cpufreq_limit(false);
+  aml_cpufreq_min(false);
+  aml_cpufreq_max(false);
   return;
 }
 
index 105e50b..20875af 100644 (file)
  *  <http://www.gnu.org/licenses/>.
  *
  */
+
 #include "system.h"
 #include <EGL/egl.h>
 #include "EGLNativeTypeAndroid.h"
 #include "utils/log.h"
 #include "guilib/gui3d.h"
 #if defined(TARGET_ANDROID)
-#include "android/activity/XBMCApp.h"
+  #include "android/activity/XBMCApp.h"
+  #if defined(HAS_AMLPLAYER) || defined(HAS_LIBAMCODEC)
+    #include "utils/AMLUtils.h"
+  #endif
 #endif
+
 CEGLNativeTypeAndroid::CEGLNativeTypeAndroid()
 {
 }
@@ -45,12 +50,19 @@ void CEGLNativeTypeAndroid::Initialize()
 {
 #if defined(TARGET_ANDROID) && (defined(HAS_AMLPLAYER) || defined(HAS_LIBAMCODEC))
   aml_permissions();
+  aml_cpufreq_min(true);
+  aml_cpufreq_max(true);
 #endif
 
   return;
 }
 void CEGLNativeTypeAndroid::Destroy()
 {
+#if defined(TARGET_ANDROID) && (defined(HAS_AMLPLAYER) || defined(HAS_LIBAMCODEC))
+  aml_cpufreq_min(false);
+  aml_cpufreq_max(false);
+#endif
+
   return;
 }