=================================================================== RCS file: /cvs/prex-old/dev/power/pm.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.2.1 diff -u -r1.1.1.1 -r1.1.1.1.2.1 --- prex-old/dev/power/pm.c 2008/06/03 10:38:42 1.1.1.1 +++ prex-old/dev/power/pm.c 2008/08/13 17:12:25 1.1.1.1.2.1 @@ -36,17 +36,16 @@ #include #include #include -#include "dvs.h" +#include /* #define DEBUG_PM 1 */ #ifdef DEBUG_PM -#define pm_printf(fmt, args...) printk("pm: " fmt, ## args) +#define DPRINTF(a) printf a #else -#define pm_printf(fmt...) do {} while (0) +#define DPRINTF(a) #endif - #ifdef CONFIG_PM_POWERSAVE #define DEFAULT_POWER_POLICY PM_POWERSAVE #else @@ -54,7 +53,7 @@ #endif static int pm_open(device_t dev, int mode); -static int pm_ioctl(device_t dev, int cmd, u_long arg); +static int pm_ioctl(device_t dev, u_long cmd, void *arg); static int pm_close(device_t dev); static int pm_init(void); @@ -67,6 +66,9 @@ /* init */ pm_init, }; +/* + * Device I/O table + */ static struct devio pm_io = { /* open */ pm_open, /* close */ pm_close, @@ -100,7 +102,7 @@ { int err; - pm_printf("Suspend system\n"); + DPRINTF(("Suspend system\n")); err = device_broadcast(EVT_SUSPEND, 1); if (err) return err; @@ -114,7 +116,8 @@ int pm_resume(void) { - pm_printf("Resume system\n"); + + DPRINTF(("Resume system\n")); device_broadcast(EVT_RESUME, 1); return 0; } @@ -128,7 +131,9 @@ { int err; - pm_printf("Power off...\n"); +#ifdef DEBUG + printf("power off...\n"); +#endif err = device_broadcast(EVT_SHUTDOWN, 1); if (err) return err; @@ -144,7 +149,9 @@ { int err; - pm_printf("rebooting...\n"); +#ifdef DEBUG + printf("rebooting...\n"); +#endif err = device_broadcast(EVT_SHUTDOWN, 1); if (err) return err; @@ -159,10 +166,10 @@ } /* - * Idle timer handler + * Idle timer handler. */ static void -idle_timeout(u_long dummy) +idle_timeout(void *arg) { irq_lock(); @@ -171,19 +178,20 @@ if (idle_count >= suspend_timeout) pm_suspend(); else - timer_callout(&idle_timer, idle_timeout, 0, 1000); + timer_callout(&idle_timer, 1000, &idle_timeout, NULL); } +#if 0 /* - * Set suspend timer + * Set suspend timer. */ -int +static int pm_settimer(u_long sec) { sched_lock(); if (sec) - timer_callout(&idle_timer, idle_timeout, 0, 1000); + timer_callout(&idle_timer, 1000, &idle_timeout, NULL); else timer_stop(&idle_timer); idle_count = 0; @@ -193,18 +201,22 @@ } /* - * Get power management timer + * Get power management timer. */ -int +static int pm_gettimer(u_long *sec) { *sec = suspend_timeout; return 0; } +#endif /* - * Reload idle timer + * Reload idle timer. + * + * A keyboard or mouse driver will call this routine when + * it detect the user activity like key press or mouse move. */ void pm_active(void) @@ -214,7 +226,7 @@ } /* - * Set power policy + * Set power policy. */ static int pm_setpolicy(int policy) @@ -230,7 +242,7 @@ } /* - * Get current power policy + * Get current power policy. */ int pm_getpolicy(void) @@ -268,14 +280,17 @@ } static int -pm_ioctl(device_t dev, int cmd, u_long arg) +pm_ioctl(device_t dev, u_long cmd, void *arg) { int err = 0; - int policy; + int policy, subcmd; switch (cmd) { case PMIOC_SET_POWER: - switch (arg) { + if (umem_copyin(arg, &subcmd, sizeof(int))) + return EFAULT; + + switch (subcmd) { case POWER_SUSPEND: pm_suspend(); break; @@ -289,12 +304,16 @@ return EINVAL; } break; + case PMIOC_SET_POLICY: - err = pm_setpolicy((int)arg); + if (umem_copyin(arg, &policy, sizeof(int))) + return EFAULT; + err = pm_setpolicy(policy); break; + case PMIOC_GET_POLICY: policy = pm_getpolicy(); - if (umem_copyout(&policy, (int *)arg, sizeof(int))) + if (umem_copyout(&policy, arg, sizeof(int))) return EFAULT; break; default: @@ -319,7 +338,9 @@ suspend_timeout = 0; power_policy = DEFAULT_POWER_POLICY; timer_init(&idle_timer); - printk("pm: Default power policy is %s mode\n", +#ifdef DEBUG + printf("pm: Default power policy is %s mode\n", (power_policy == PM_POWERSAVE) ? "power save" : "performance"); +#endif return 0; }