summaryrefslogtreecommitdiff
path: root/cleopatre
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
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')
-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
-rw-r--r--cleopatre/buildroot/package/Config.in1
-rw-r--r--cleopatre/buildroot/package/pmd/Config.in7
-rw-r--r--cleopatre/buildroot/package/pmd/pmd.mk76
-rw-r--r--cleopatre/buildroot/target/device/Spidcom/mse500_defconfig1
-rwxr-xr-xcleopatre/buildroot/target/device/Spidcom/target_skeleton/etc/init.d/S40network16
-rw-r--r--cleopatre/linux-2.6.25.10-spc300/drivers/net/arm/synop3504.c13
11 files changed, 300 insertions, 1 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
diff --git a/cleopatre/buildroot/package/Config.in b/cleopatre/buildroot/package/Config.in
index cd3ea5e4cc..1c5eea8482 100644
--- a/cleopatre/buildroot/package/Config.in
+++ b/cleopatre/buildroot/package/Config.in
@@ -232,6 +232,7 @@ if BR2_TARGET_SPIDCOM
source "package/spidapp/Config.in"
source "package/plcd/Config.in"
source "package/plcdrv/Config.in"
+source "package/pmd/Config.in"
endif
source "package/portmap/Config.in"
source "package/pppd/Config.in"
diff --git a/cleopatre/buildroot/package/pmd/Config.in b/cleopatre/buildroot/package/pmd/Config.in
new file mode 100644
index 0000000000..c22dcc952a
--- /dev/null
+++ b/cleopatre/buildroot/package/pmd/Config.in
@@ -0,0 +1,7 @@
+config BR2_PACKAGE_PMD
+ depends on BR2_TARGET_SPIDCOM_MSE500
+ bool "pmd"
+ help
+ Help program for power management deamon.
+
+ http://www.spidcom.com
diff --git a/cleopatre/buildroot/package/pmd/pmd.mk b/cleopatre/buildroot/package/pmd/pmd.mk
new file mode 100644
index 0000000000..a0cf1788e4
--- /dev/null
+++ b/cleopatre/buildroot/package/pmd/pmd.mk
@@ -0,0 +1,76 @@
+#############################################################
+#
+# pmd (Deamon to handle power management).
+#
+#############################################################
+# Copyright (C) 2012 by MStar
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Library 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
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library 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
+#
+
+PMD_VERSION:=0.0.1
+PMD_SITE:=$(BASE_DIR)/../application/pmd
+PMD_NAME:=pmd-$(PMD_VERSION)
+PMD_DIR:=$(BUILD_DIR)/pmd-$(PMD_VERSION)
+
+pmd-source:
+
+$(PMD_DIR)/.unpacked:
+ ln -s $(PMD_SITE) $(PMD_DIR)
+ touch $(PMD_DIR)/.unpacked
+
+$(PMD_DIR)/.configured: $(PMD_DIR)/.unpacked
+ touch $(PMD_DIR)/.configured
+
+$(PMD_DIR)/pmd: $(PMD_DIR)/.configured
+ (cd $(PMD_DIR); $(TARGET_CONFIGURE_OPTS) $(MAKE))
+
+$(TARGET_DIR)/usr/bin/pmd: $(PMD_DIR)/pmd
+ mkdir -p $(TARGET_DIR)/usr/bin
+ cp $< $@
+
+$(TARGET_DIR)/usr/bin/suspend: $(PMD_DIR)/suspend
+ mkdir -p $(TARGET_DIR)/usr/bin
+ cp $< $@
+
+$(TARGET_DIR)/etc/init.d/S90pmd: $(PMD_DIR)/S90pmd
+ mkdir -p $(TARGET_DIR)/etc/init.d
+ cp $< $@
+
+pmd: uclibc $(TARGET_DIR)/usr/bin/pmd \
+ $(TARGET_DIR)/usr/bin/suspend \
+ $(TARGET_DIR)/etc/init.d/S90pmd \
+
+pmd-clean:
+ rm -f $(TARGET_DIR)/usr/bin/pmd
+ rm -f $(TARGET_DIR)/usr/bin/suspend
+ rm -f $(TARGET_DIR)/etc/init.d/S90pmd
+ -$(MAKE) -C $(PMD_DIR) clean
+
+pmd-dirclean:
+ rm -f $(PMD_DIR)
+
+# We declare $(PMD_DIR)/pmd rule as PHONY to force compilation
+.PHONY: $(PMD_DIR)/pmd
+
+#############################################################
+#
+# Toplevel Makefile options
+#
+#############################################################
+ifeq ($(strip $(BR2_PACKAGE_PMD)),y)
+TARGETS+=pmd
+endif
diff --git a/cleopatre/buildroot/target/device/Spidcom/mse500_defconfig b/cleopatre/buildroot/target/device/Spidcom/mse500_defconfig
index f6ba182c9a..849cce721e 100644
--- a/cleopatre/buildroot/target/device/Spidcom/mse500_defconfig
+++ b/cleopatre/buildroot/target/device/Spidcom/mse500_defconfig
@@ -400,6 +400,7 @@ BR2_PACKAGE_LIBSPID=y
BR2_PACKAGE_SPIDAPP=y
BR2_PACKAGE_PLCD=y
BR2_PACKAGE_PLCDRV=y
+BR2_PACKAGE_PMD=y
#
# portmap requires a toolchain with 'Enable RPC' selected
diff --git a/cleopatre/buildroot/target/device/Spidcom/target_skeleton/etc/init.d/S40network b/cleopatre/buildroot/target/device/Spidcom/target_skeleton/etc/init.d/S40network
index 311d0809dd..865eed4c5d 100755
--- a/cleopatre/buildroot/target/device/Spidcom/target_skeleton/etc/init.d/S40network
+++ b/cleopatre/buildroot/target/device/Spidcom/target_skeleton/etc/init.d/S40network
@@ -13,6 +13,14 @@ stop() {
/sbin/ifdown -a
}
+suspend() {
+ /sbin/ifdown plc0
+}
+
+resume() {
+ /sbin/ifup plc0
+}
+
restart() {
stop
start
@@ -25,11 +33,17 @@ case "$1" in
stop)
stop
;;
+ suspend)
+ suspend
+ ;;
+ resume)
+ resume
+ ;;
restart|reload)
restart
;;
*)
- echo $"Usage: $0 {start|stop|restart}"
+ echo $"Usage: $0 {start|stop|restart|suspend}"
exit 1
esac
diff --git a/cleopatre/linux-2.6.25.10-spc300/drivers/net/arm/synop3504.c b/cleopatre/linux-2.6.25.10-spc300/drivers/net/arm/synop3504.c
index 25ca3b4727..a09f3ac396 100644
--- a/cleopatre/linux-2.6.25.10-spc300/drivers/net/arm/synop3504.c
+++ b/cleopatre/linux-2.6.25.10-spc300/drivers/net/arm/synop3504.c
@@ -58,6 +58,9 @@
#ifdef CONFIG_CHIP_FEATURE_SRAM
#include <asm/arch/ips/sram.h>
#endif
+#ifdef CONFIG_PM
+#include <asm/arch/spc300-pm.h>
+#endif
#include "synop3504_hw.h"
#include "synop3504.h"
@@ -1299,6 +1302,16 @@ static void synop3504_handle_link_change(struct net_device *dev)
SynopsysSetMiiClkCap(synop, 1000);
priv->speed = 0;
priv->duplex = -1;
+
+#ifdef CONFIG_PM
+ //Request standby mode
+ spc300_pm_request_suspend();
+ }
+ else
+ {
+ //Clear standby mode request
+ spc300_pm_clear_suspend();
+#endif
}
priv->link = phydev->link;