summaryrefslogtreecommitdiff
path: root/cleopatre/application/pmd
diff options
context:
space:
mode:
authorOlivier Dufour2012-11-14 17:45:02 +0100
committerOlivier Dufour2012-12-21 15:15:45 +0100
commit8c10cce00c2d426af6b9a60bf12444e91c4ba7eb (patch)
treeb30f5c35261a06ebcef69f48bc36c94156250730 /cleopatre/application/pmd
parenta87e735cbe7994e052c220f57d792b6c37a8c98d (diff)
cleo/app/pmd: add a daemon to handle power state changes, closes #2633
pmd polls /proc/pm/suspend_cmd, and triggers the suspend script when the criterias are matched. The criterias are defined and handled by the kernel, pmd only reads the status entry and triggers the script, as it cannot be done from kernel space.
Diffstat (limited to 'cleopatre/application/pmd')
-rw-r--r--cleopatre/application/pmd/.gitignore1
-rw-r--r--cleopatre/application/pmd/Makefile38
-rwxr-xr-xcleopatre/application/pmd/S90pmd38
-rw-r--r--cleopatre/application/pmd/src/pmd.c95
-rwxr-xr-xcleopatre/application/pmd/suspend15
5 files changed, 187 insertions, 0 deletions
diff --git a/cleopatre/application/pmd/.gitignore b/cleopatre/application/pmd/.gitignore
new file mode 100644
index 0000000000..d8bce30689
--- /dev/null
+++ b/cleopatre/application/pmd/.gitignore
@@ -0,0 +1 @@
+pmd
diff --git a/cleopatre/application/pmd/Makefile b/cleopatre/application/pmd/Makefile
new file mode 100644
index 0000000000..0565ed9763
--- /dev/null
+++ b/cleopatre/application/pmd/Makefile
@@ -0,0 +1,38 @@
+BIN=pmd
+OBJPATH=obj
+SRCPATH=src
+
+ifeq ($(CC_FOR_TARGET),) #direct compile
+CC=arm-linux-gcc
+CC_WITH_CFLAGS=$(CC) -I/opt/spidcom/spc300/usr/include -g -Os
+CC_WITHOUT_CFLAGS=$(CC)
+else #compile from buildroot
+CC_WITH_CFLAGS=$(CC)
+CC_WITHOUT_CFLAGS=$(CC_FOR_TARGET)
+endif
+EXTRA_CFLAGS=-MMD
+
+SRCS=$(subst $(SRCPATH)/,,$(wildcard $(SRCPATH)/*.c))
+OBJS=$(addprefix $(OBJPATH)/,$(SRCS:.c=.o))
+DEPS=$(patsubst %o,%d,$(OBJS))
+
+all: $(BIN)
+
+$(BIN): $(OBJS)
+ $(CC_WITHOUT_CFLAGS) -o $@ $(OBJS) $(LIBS)
+
+$(OBJPATH)/%.o: $(SRCPATH)/%.c
+ $(CC_WITH_CFLAGS) $(EXTRA_CFLAGS) -o $@ -c $<
+
+$(OBJS): $(OBJPATH)
+
+$(OBJPATH):
+ mkdir $(OBJPATH)
+
+-include $(DEPS)
+
+.PHONY: all clean
+
+clean:
+ rm -f $(OBJS) $(DEPS) $(BIN)
+ rmdir $(OBJPATH)
diff --git a/cleopatre/application/pmd/S90pmd b/cleopatre/application/pmd/S90pmd
new file mode 100755
index 0000000000..185f301665
--- /dev/null
+++ b/cleopatre/application/pmd/S90pmd
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+# Start the power management daemon...
+#
+
+DAEMON=/usr/bin/pmd
+
+test -f $DAEMON || exit 0
+
+start() {
+ echo "Starting power management daemon..."
+ $DAEMON &
+}
+stop() {
+ echo "Stopping power management daemon..."
+ killall $DAEMON
+}
+restart() {
+ stop
+ start
+}
+
+case "$1" in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ restart)
+ restart
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|restart}"
+ exit 1
+esac
+
+exit $?
diff --git a/cleopatre/application/pmd/src/pmd.c b/cleopatre/application/pmd/src/pmd.c
new file mode 100644
index 0000000000..849b12a47e
--- /dev/null
+++ b/cleopatre/application/pmd/src/pmd.c
@@ -0,0 +1,95 @@
+/*
+ * cleopatre/application/pmd/src/pmd.c
+ *
+ * (C) Copyright 2012 MStar
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+/* Poll period in second. */
+#define PMD_POLL_PERIOD_S 1
+
+/* Number of consecutive positive matches required */
+#define PMD_CONSECUTIVE_CMD_ON 5
+
+/* Proc entry to poll. */
+#define PMD_PROC_FILE "/proc/pm/suspend_cmd"
+
+/* Length to read in the proc entry. */
+#define PMD_PROC_LEN 1
+
+/* Command to call to go into standby mode. */
+#define PMD_SUSPEND_CMD "/usr/bin/suspend"
+
+/* Suspend command values. */
+#define PMD_SUSPEND_OFF '0'
+#define PMD_SUSPEND_ON '1'
+
+/**
+ * Main function. This deamon polls a proc entry to trigger standby mode if
+ * needed.
+ *
+ * \param argc number of arguments.
+ * \param argv arguments pointer.
+ * \return error code.
+ */
+int main(int argc, char **argv)
+{
+ int ret;
+ int fd;
+ int cmd_counter = 0;
+ char cmd;
+
+ fd = open (PMD_PROC_FILE, O_RDWR);
+
+ if (fd == -1)
+ return 1;
+
+ while (1)
+ {
+ /* Read proc from the beginning of the file. */
+ lseek (fd, 0, SEEK_SET);
+ ret = read (fd, &cmd, PMD_PROC_LEN);
+
+ if (ret == -1)
+ break;
+
+ if (cmd == PMD_SUSPEND_ON)
+ {
+ cmd_counter++;
+ if (cmd_counter == PMD_CONSECUTIVE_CMD_ON)
+ {
+ system (PMD_SUSPEND_CMD);
+ cmd_counter = 0;
+ }
+ }
+ else
+ {
+ cmd_counter = 0;
+ }
+
+ sleep (PMD_POLL_PERIOD_S);
+ }
+
+ close (fd);
+
+ return 1;
+}
+
diff --git a/cleopatre/application/pmd/suspend b/cleopatre/application/pmd/suspend
new file mode 100755
index 0000000000..5ce07f8df1
--- /dev/null
+++ b/cleopatre/application/pmd/suspend
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Allow uart to wake system up
+echo enabled > /sys/devices/platform/serial8250/tty\:ttyS0/power/wakeup
+
+# Suspend process
+/etc/init.d/S50plcpost stop
+/etc/init.d/S40network suspend
+/etc/init.d/S31fwwatchd stop
+/etc/init.d/S30plc stop
+echo mem > /sys/power/state
+/etc/init.d/S30plc start
+/etc/init.d/S31fwwatchd start
+/etc/init.d/S40network resume
+/etc/init.d/S50plcpost start