]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/apmd/apmd-3.2.2/h6300_suspend_fix.patch
h6300 suspend fix for apm userspace tools. h6300 can currently only suspend by using...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / apmd / apmd-3.2.2 / h6300_suspend_fix.patch
1 diff -Naur apmd-3.2.2.old/apmd.c apmd-3.2.2.orig/apmd.c
2 --- apmd-3.2.2.old/apmd.c       2006-11-05 01:09:14.000000000 +0200
3 +++ apmd-3.2.2.orig/apmd.c      2006-11-05 01:52:32.000000000 +0200
4 @@ -537,7 +537,7 @@
5                 /* Do it fast */
6                 last_marked_time = time(0);
7                 last_marked_content = apmi->battery_percentage;
8 -               ioctl(apmd_fd, APM_IOC_SUSPEND, NULL);
9 +               apm_suspend(apmd_fd);
10                 break;
11         case APMD_START:
12                 /* Initialise */
13 diff -Naur apmd-3.2.2.old/apmlib.c apmd-3.2.2.orig/apmlib.c
14 --- apmd-3.2.2.old/apmlib.c     2006-11-05 01:09:14.000000000 +0200
15 +++ apmd-3.2.2.orig/apmlib.c    2006-11-05 01:50:58.000000000 +0200
16 @@ -35,6 +35,66 @@
17  
18  #define BACKWARD_COMPAT 1
19  
20 +#define SUSPEND_METHOD__NOT_DEFINED            -1
21 +#define SUSPEND_METHOD__APM_IOCTL              0
22 +#define SUSPEND_METHOD__ECHO_SYS_POWER_STATE   1
23 +
24 +static int suspend_method_to_use       = SUSPEND_METHOD__NOT_DEFINED;
25 +
26 +/*
27 + * Check from the some of the search strings is available in 
28 + * /proc/cpuinfo (harware type for example)
29 + * 
30 + * Return 1 if available, 0 if not found
31 + */
32 +int is_key_in_proc_cpuinfo(char *devlist[])
33 +{
34 +       FILE*   curFd;
35 +       char    curBuffer[2048];
36 +       size_t  curBCount;
37 +       char*   curFound;
38 +       int     retVal;
39 +
40 +       // let's assume by default that string does not found
41 +       retVal  = 0;
42 +       /* read to /proc/cpuinfo to buffer */
43 +       curFd           = fopen("/proc/cpuinfo", "r");
44 +       curBCount       = fread(curBuffer, 1, sizeof(curBuffer), curFd);
45 +       fclose(curFd);
46 +       if (curBCount > 0) {
47 +               /* make sure text in buffer is terminated */
48 +               curBuffer[curBCount] = '\0';
49 +               while((*devlist != NULL)) {
50 +                       curFound        = strstr(curBuffer, *devlist);
51 +                       if (curFound != NULL) {
52 +                               // matched to one of the search keywords
53 +                               retVal  = 1;
54 +                               break;
55 +                       }
56 +                       *devlist++;
57 +               }
58 +       }
59 +       return retVal;
60 +}
61 +
62 +int check_suspend_method(void)
63 +{
64 +       if (suspend_method_to_use == SUSPEND_METHOD__NOT_DEFINED)
65 +       {
66 +               char *curDevArr[]       = {"HP iPAQ h6300", 0};
67 +
68 +               // not checked yet, check now
69 +               if (is_key_in_proc_cpuinfo(curDevArr)) {
70 +                       suspend_method_to_use   = SUSPEND_METHOD__ECHO_SYS_POWER_STATE;
71 +                       printf("Using 'echo mem > sys/power/state' to suspend.\n");
72 +               }
73 +               else {
74 +                       suspend_method_to_use   = SUSPEND_METHOD__APM_IOCTL;
75 +                       printf("Using apm ioctl to suspend\n");
76 +               }
77 +       }
78 +       return suspend_method_to_use;
79 +}
80  
81  /*
82   * Return a string describing an APM event. From p. 16 of the Intel/Microsoft
83 @@ -388,7 +448,11 @@
84  int apm_suspend(int fd)
85  {
86      sync();
87 -    return ioctl(fd, APM_IOC_SUSPEND, NULL) < 0 ? -errno : 0;
88 +    if (check_suspend_method() == SUSPEND_METHOD__ECHO_SYS_POWER_STATE)
89 +       return system("echo mem > /sys/power/state");
90 +    else 
91 +       return ioctl(fd, APM_IOC_SUSPEND, NULL) < 0 ? -errno : 0;
92 +       
93  }
94  
95  
96 @@ -398,7 +462,10 @@
97  int apm_standby(int fd)
98  {
99      sync();
100 -    return ioctl(fd, APM_IOC_STANDBY, NULL);
101 +    if (check_suspend_method() == SUSPEND_METHOD__ECHO_SYS_POWER_STATE)
102 +       return system("echo mem > /sys/power/state");
103 +    else
104 +       return ioctl(fd, APM_IOC_STANDBY, NULL);
105  }
106  
107