Added pnd_device.[ch] with basic clock setting support
authorskeezix <skeezix@flotsam-vm.(none)>
Wed, 18 Feb 2009 14:34:45 +0000 (09:34 -0500)
committerskeezix <skeezix@flotsam-vm.(none)>
Wed, 18 Feb 2009 14:34:45 +0000 (09:34 -0500)
include/pnd_device.h
lib/pnd_device.c [new file with mode: 0644]

index 6b05577..87fd6f1 100644 (file)
@@ -9,9 +9,19 @@ extern "C" {
 // do we have a 'minimal' lib yet anywhere formalized? if not, we could
 // attempt to include it here.
 
-// set clock speed
-
-// set LED on
+// for reference material, see the Pandora wiki. Specifically, some good
+// places to look:
+// http://pandorawiki.org/Kernel_interface
+
+/* overall clock speed
+ * WARN: No boundaries are checked, so try to avoid setting clock to 2GHz :)
+ * NOTE: get-clock() is not implemented yet.
+ */
+#define PND_DEVICE_PROC_CLOCK "/proc/pandora/cpu_mhz_max"
+unsigned char pnd_device_set_clock ( unsigned int c ); // returns >0 on success
+unsigned int pnd_device_get_clock ( void ); // not implemented, returns 0
+
+// set one or more LEDs on
 
 // suspend/hibernate/etc
 
diff --git a/lib/pnd_device.c b/lib/pnd_device.c
new file mode 100644 (file)
index 0000000..dc2fecc
--- /dev/null
@@ -0,0 +1,34 @@
+
+#include <stdio.h> /* for FILE etc */
+#include <stdlib.h> /* for malloc */
+#include <string.h>
+
+#include <sys/types.h> /* for open */
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "pnd_device.h"
+
+unsigned char pnd_device_set_clock ( unsigned int c ) {
+  char buffer [ 100 ];
+  int f;
+
+  sprint ( buffer, "%u", c );
+
+  if ( ( f = open ( PND_DEVICE_PROC_CLOCK, O_RDONLY ) ) < 0 ) {
+    return ( 0 );
+  }
+
+  if ( write ( f, buffer, strlen ( buffer ) ) < strlen ( buffer ) ) {
+    return ( 0 );
+  }
+
+  close ( f );
+
+  return ( 1 );
+}
+
+unsigned int pnd_device_get_clock ( void ) {
+  return ( 0 );
+}