mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

397 lines
12 KiB

  1. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  2. #
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. # Please add additional copyright information _after_ the line containing
  5. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  6. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  7. #
  8. # ROCK Linux: rock-src/package/rene/cpufreqd/pmu-official.patch
  9. # ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version. A copy of the GNU General Public
  15. # License can be found at Documentation/COPYING.
  16. #
  17. # Many people helped and are helping developing ROCK Linux. Please
  18. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  19. # file for details.
  20. #
  21. # --- ROCK-COPYRIGHT-NOTE-END ---
  22. Author:
  23. Copyright (C) 2003 Rene Rebe (rene@rocklinux.org)
  24. diff -urN cpufreqd-1.0/AUTHORS cpufreqd-1.0-pmu/AUTHORS
  25. --- cpufreqd-1.0/AUTHORS 2003-06-23 11:15:02.000000000 +0200
  26. +++ cpufreqd-1.0-pmu/AUTHORS 2003-07-24 19:58:50.000000000 +0200
  27. @@ -1,2 +1,3 @@
  28. Mattia Dongili <dongili@supereva.it>
  29. George Staikos <staikos@0wned.org>
  30. +Rene Rebe <rene@rocklinux.org>
  31. diff -urN cpufreqd-1.0/Makefile.am cpufreqd-1.0-pmu/Makefile.am
  32. --- cpufreqd-1.0/Makefile.am 2003-06-23 21:35:40.000000000 +0200
  33. +++ cpufreqd-1.0-pmu/Makefile.am 2003-07-24 18:25:15.000000000 +0200
  34. @@ -13,7 +13,8 @@
  35. lib_LTLIBRARIES = \
  36. libsys_acpi.la \
  37. - libsys_apm.la
  38. + libsys_apm.la \
  39. + libsys_pmu.la
  40. libsys_acpi_la_SOURCES=libsys_acpi.c
  41. libsys_acpi_la_LDFLAGS=-module -avoid-version
  42. @@ -21,6 +22,10 @@
  43. libsys_apm_la_SOURCES=libsys_apm.c
  44. libsys_apm_la_LDFLAGS=-module -avoid-version
  45. +libsys_pmu_la_SOURCES=libsys_pmu.c
  46. +libsys_pmu_la_LDFLAGS=-module -avoid-version
  47. +
  48. +
  49. noinst_HEADERS = \
  50. config_parser.h \
  51. cpufreqd.h \
  52. diff -urN cpufreqd-1.0/config_parser.c cpufreqd-1.0-pmu/config_parser.c
  53. --- cpufreqd-1.0/config_parser.c 2003-06-23 11:15:02.000000000 +0200
  54. +++ cpufreqd-1.0-pmu/config_parser.c 2003-07-24 19:59:36.000000000 +0200
  55. @@ -1,6 +1,7 @@
  56. /*
  57. * Copyright (C) 2002-2003 Mattia Dongili<dongili@supereva.it>
  58. * George Staikos <staikos@0wned.org>
  59. + * Rene Rebe <rene@rocklinux.org>
  60. *
  61. * This program is free software; you can redistribute it and/or modify
  62. * it under the terms of the GNU General Public License as published by
  63. @@ -194,7 +195,12 @@
  64. g->poll_interval = 1;
  65. }
  66. } else if (strcmp(name,"pm_type") == 0) {
  67. - g->pm_type = strcmp(value,"apm")==0 ? PM_TYPE_APM : PM_TYPE_ACPI;
  68. + if (strcmp(value,"acpi")==0)
  69. + g->pm_type = PM_TYPE_ACPI;
  70. + else if (strcmp(value,"pmu")==0)
  71. + g->pm_type = PM_TYPE_PMU;
  72. + else
  73. + g->pm_type = PM_TYPE_APM;
  74. } else if (strcmp(name,"pidfile") == 0) {
  75. strncpy(g->pidfile, value, 511);
  76. g->pidfile[511] = 0;
  77. diff -urN cpufreqd-1.0/cpufreqd.conf cpufreqd-1.0-pmu/cpufreqd.conf
  78. --- cpufreqd-1.0/cpufreqd.conf 2003-06-23 14:18:19.000000000 +0200
  79. +++ cpufreqd-1.0-pmu/cpufreqd.conf 2003-07-24 18:35:49.000000000 +0200
  80. @@ -26,7 +26,7 @@
  81. [General]
  82. pidfile=/var/run/cpufreqd.pid
  83. poll_interval=2
  84. - pm_type=acpi # (apm/acpi) (default: apm)
  85. + pm_type=apm # (apm/acpi/pmu) (default: apm)
  86. [Profile]
  87. diff -urN cpufreqd-1.0/main.c cpufreqd-1.0-pmu/main.c
  88. --- cpufreqd-1.0/main.c 2003-06-23 16:53:17.000000000 +0200
  89. +++ cpufreqd-1.0-pmu/main.c 2003-07-24 18:41:45.000000000 +0200
  90. @@ -138,6 +138,9 @@
  91. const char* error; /* pointer to an error message, if any */
  92. switch (configuration->pm_type) {
  93. + case PM_TYPE_PMU:
  94. + snprintf(libsysname, 512, CPUFREQD_LIBDIR"libsys_%s.so", "pmu");
  95. + break;
  96. case PM_TYPE_ACPI:
  97. snprintf(libsysname, 512, CPUFREQD_LIBDIR"libsys_%s.so", "acpi");
  98. break;
  99. diff -urN cpufreqd-1.0/manpages/cpufreqd.1 cpufreqd-1.0-pmu/manpages/cpufreqd.1
  100. --- cpufreqd-1.0/manpages/cpufreqd.1 2003-06-23 20:31:34.000000000 +0200
  101. +++ cpufreqd-1.0-pmu/manpages/cpufreqd.1 2003-07-24 18:38:36.000000000 +0200
  102. @@ -1,5 +1,6 @@
  103. .\" Copyright 2002-2003, George Staikos (staikos@0wned.org)
  104. .\" Mattia Dongili (dongili@supereva.it)
  105. +.\" Rene Rebe (rene@rocklinux.org)
  106. .\" This file may be used subject to the terms and conditions of the
  107. .\" GNU General Public License Version 2, or any later version
  108. .\" at your option, as published by the Free Software Foundation.
  109. @@ -55,6 +56,10 @@
  110. .I /proc/acpi
  111. kernel power management interface (ACPI)
  112. .TP
  113. +.I /proc/pmu
  114. +kernel power management interface (PMU)
  115. +
  116. +.TP
  117. .I /etc/cpufreqd.conf
  118. .B cpufreqd
  119. configuration file
  120. @@ -68,4 +73,5 @@
  121. George Staikos <staikos@0wned.org>
  122. .TP
  123. Mattia Dongili <dongili@supereva.it>
  124. -
  125. +.TP
  126. +Rene Rebe <rene@rocklinux.org>
  127. diff -urN cpufreqd-1.0/manpages/cpufreqd.conf.5 cpufreqd-1.0-pmu/manpages/cpufreqd.conf.5
  128. --- cpufreqd-1.0/manpages/cpufreqd.conf.5 2003-06-23 11:15:02.000000000 +0200
  129. +++ cpufreqd-1.0-pmu/manpages/cpufreqd.conf.5 2003-07-24 18:39:03.000000000 +0200
  130. @@ -1,5 +1,6 @@
  131. .\" Copyright 2002-2003, George Staikos (staikos@0wned.org)
  132. .\" Mattia Dongili (dongili@supereva.it)
  133. +.\" Rene Rebe (rene@rocklinux.org)
  134. .\" This file may be used subject to the terms and conditions of the
  135. .\" GNU General Public License Version 2, or any later version
  136. .\" at your option, as published by the Free Software Foundation.
  137. @@ -65,11 +66,12 @@
  138. .B "pm_type"
  139. Can be either
  140. .B "apm"
  141. -or
  142. -.B "acpi".
  143. +.B "acpi"
  144. +or
  145. +.B "pmu".
  146. Depending on this value
  147. .B cpufreqd
  148. -will try to read from /proc/apm or /proc/acpi. You will need to enable power
  149. +will try to read from /proc/apm, /proc/acpi or /proc/pmu. You will need to enable power
  150. management in you kernel configuration. (default: apm)
  151. .TP
  152. --- cpufreqd-1.0/libsys_pmu.c 1970-01-01 01:00:00.000000000 +0100
  153. +++ cpufreqd-1.0-pmu//libsys_pmu.c 2003-07-25 23:30:37.000000000 +0200
  154. @@ -0,0 +1,197 @@
  155. +/*
  156. + * Copyright (C) 2003 Rene Rebe <rene@rocklinux.org>
  157. + *
  158. + * This program is free software; you can redistribute it and/or modify
  159. + * it under the terms of the GNU General Public License as published by
  160. + * the Free Software Foundation; either version 2 of the License, or
  161. + * (at your option) any later version.
  162. + *
  163. + * This program is distributed in the hope that it will be useful,
  164. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  165. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  166. + * GNU General Public License for more details.
  167. + *
  168. + * You should have received a copy of the GNU General Public License
  169. + * along with this program; if not, write to the Free Software
  170. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  171. + *
  172. + * Based upon the acpi version:
  173. + * Copyright (C) 2002-2003 Mattia Dongili<dongili@supereva.it>
  174. + * George Staikos <staikos@0wned.org>
  175. + */
  176. +#include "cpufreqd.h"
  177. +
  178. +#define DEBUG_PMU 1
  179. +
  180. +char info_file[255];
  181. +char bat_file[255];
  182. +char tag[255];
  183. +char val[255];
  184. +char version[101];
  185. +short int err = 0;
  186. +int bat_num = 0;
  187. +
  188. +int tokenize (FILE *fp, char *t, char *v) {
  189. + char *str, *str2;
  190. + *t = 0; *v = 0;
  191. +
  192. + if (fgets(t, 255, fp) == NULL)
  193. + return EOF;
  194. +
  195. + /* remove trailing newline */
  196. + str = t + strlen (t);
  197. + if (str != t) {
  198. + --str;
  199. + if (*str == '\n')
  200. + *str = 0;
  201. + }
  202. +
  203. + /* search the first ':' - the seperator */
  204. + for (str = t ; str != t + strlen (t); ++str)
  205. + if (*str == ':')
  206. + break;
  207. + str2 = str;
  208. +
  209. + /* skip the ':' and normally present ' ' */
  210. + if (*str == ':')
  211. + ++str;
  212. + if (*str == ' ')
  213. + ++str;
  214. +
  215. + /* the string can not be longer than 255 chars - anyway */
  216. + strncpy (v, str, 255);
  217. +
  218. + /* skip the ':' the pointer should point to */
  219. + if (*str2 == ':')
  220. + --str2;
  221. +
  222. + /* remove trailing spaces from the tag */
  223. + for ( ; str2 != t ; --str2) {
  224. + if ( *str2 == ' ')
  225. + *str2 = 0;
  226. + else
  227. + break;
  228. + }
  229. + return 0;
  230. +}
  231. +
  232. +/* void libsys_init(void)
  233. + *
  234. + * Initialize local variables.
  235. + */
  236. +void libsys_init(void) {
  237. +
  238. + FILE *fp;
  239. +
  240. + snprintf(info_file, 255, "%s/info", PMU_PROC_DIR);
  241. + snprintf(bat_file, 255, "%s/battery_0", PMU_PROC_DIR);
  242. +
  243. + fp = fopen(info_file, "r");
  244. + if (!fp) {
  245. + syslog(LOG_ERR, "libsys_init(): %s: %s\n", info_file, strerror(errno));
  246. + err++;
  247. + return;
  248. + }
  249. +
  250. + while (tokenize(fp, tag, val) != EOF) {
  251. +
  252. + if (strcmp (tag, "PMU driver version") == 0) {
  253. + sprintf (version, "%s - ", val);
  254. + }
  255. + else if (strcmp (tag, "PMU firmware version") == 0) {
  256. + strcat (version, val);
  257. + }
  258. + }
  259. + fclose(fp);
  260. +
  261. +}
  262. +
  263. +/* void libsys_fini (void)
  264. + *
  265. + * Free allocated structures.
  266. + */
  267. +
  268. +void libsys_fini (void) {
  269. +}
  270. +
  271. +/* int scan_system_info(sys_info *s)
  272. + *
  273. + * Reads PMU info and fills the input sys_info struct.
  274. + * Implements the prototype needed by cpufreqd to get
  275. + * info from the PM layer.
  276. + *
  277. + * Returns 0 on success, -1 otherwise
  278. + *
  279. + */
  280. +int scan_system_info(sys_info *s) {
  281. +
  282. + FILE *fp;
  283. +
  284. + float bat_charge = .0;
  285. + float bat_max_charge = .0;
  286. +
  287. + /* check if _init was successful */
  288. + if (err>0)
  289. + return -1;
  290. +
  291. + /* set version information */
  292. + strncpy(s->version, version, 101);
  293. +
  294. + /** /proc/pmu/info **/
  295. + fp = fopen(info_file, "r");
  296. + if (!fp) {
  297. + syslog(LOG_ERR, "libsys_init(): %s: %s\n", info_file, strerror(errno));
  298. + err++;
  299. + return -1;
  300. + }
  301. +
  302. + while (tokenize(fp, tag, val) != EOF) {
  303. +
  304. + if (strcmp (tag, "AC Power") == 0) {
  305. + s->ac = atoi (val);
  306. + }
  307. + else if (strcmp (tag, "Battery count") == 0) {
  308. + s->has_battery = atoi (val);
  309. + }
  310. + }
  311. + fclose(fp);
  312. +
  313. +
  314. + /** /proc/pmu/battery_0 **/
  315. + fp = fopen(bat_file, "r");
  316. + if (!fp) {
  317. + syslog(LOG_ERR, "scan_system_info(): %s: %s\n", bat_file, strerror(errno));
  318. + return(-1);
  319. + }
  320. +
  321. + while (tokenize(fp, tag, val) != EOF) {
  322. + if (strcmp (tag, "charge") == 0) {
  323. + bat_charge = atof (val);
  324. + }
  325. + else if (strcmp (tag, "max_charge") == 0) {
  326. + bat_max_charge = atof (val);
  327. + }
  328. + }
  329. +
  330. + s->battery_percent = 100 * (bat_charge / bat_max_charge);
  331. +
  332. +#ifdef DEBUG_PMU
  333. + syslog(LOG_INFO, "scan_system_info(): battery %s - %d - %s\n",
  334. + s->has_battery?"present":"absent",
  335. + s->battery_percent,
  336. + s->ac?"on-line":"off-line");
  337. +#endif
  338. + return 0;
  339. +}
  340. +
  341. +#ifdef DEBUG_PMU
  342. +int main ()
  343. +{
  344. + sys_info info;
  345. +
  346. + libsys_init();
  347. + scan_system_info (&info);
  348. + return 0;
  349. +}
  350. +#endif
  351. +
  352. --- cpufreqd-1.0/cpufreqd.h 2003-06-23 16:10:48.000000000 +0200
  353. +++ cpufreqd-1.0-pmu/cpufreqd.h 2003-07-25 23:32:42.000000000 +0200
  354. @@ -1,6 +1,7 @@
  355. /*
  356. * Copyright (C) 2002-2003 Mattia Dongili<dongili@supereva.it>
  357. * George Staikos <staikos@0wned.org>
  358. + * Rene Rebe <rene@rocklinux.org>
  359. *
  360. * This program is free software; you can redistribute it and/or modify
  361. * it under the terms of the GNU General Public License as published by
  362. @@ -60,6 +61,7 @@
  363. #define ACPI_PROC_DIR "/proc/acpi/"
  364. #define ACPI_BATTERY_DIR "/proc/acpi/battery/"
  365. #define ACPI_AC_DIR "/proc/acpi/ac_adapter/"
  366. +#define PMU_PROC_DIR "/proc/pmu"
  367. #define CPUFREQ_SYSFS_INTERFACE "/sys/devices/sys/cpu0"
  368. #define CPUFREQ_SYSFS_INTERFACE_POLICY "/sys/devices/sys/cpu0/scaling_governor"
  369. @@ -72,6 +74,7 @@
  370. #define PM_TYPE_APM 0
  371. #define PM_TYPE_ACPI 1
  372. +#define PM_TYPE_PMU 2
  373. typedef struct {
  374. short int min;
  375. @@ -109,9 +112,6 @@
  376. char time[101];
  377. } sys_info;
  378. -#define PM_TYPE_APM 0
  379. -#define PM_TYPE_ACPI 1
  380. -
  381. #define MATCH_AC 4
  382. #define MATCH_BATTERY 2
  383. #define MATCH_PROG 1