(sent to pavel already, but now i subscribed suspend-devel, i'll
resend it here).
Hi,
this implements some more fixes / features, against CVS from today.
Index: radeontool.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/suspend/suspend/radeontool.c,v
retrieving revision 1.3
diff -u -p -r1.3 radeontool.c
--- radeontool.c 22 Feb 2006 13:05:40 -0000 1.3
+++ radeontool.c 24 Feb 2006 11:16:36 -0000
@@ -74,13 +74,14 @@ static void radeon_set(unsigned long off
*(volatile unsigned long *)(radeon_cntl_mem+offset) =3D value; =20
}
=20
+#if 0
static void usage(void)
{
printf("usage: radeontool [options] [command]\n");
printf(" light [on|off] - power down the backlight \n");
exit(-1);
}
-
+#endif
=20
/* Ohh, life would be good if we could simply address all memory address=
es */
/* with /dev/mem, then I could write this whole program in perl, */
@@ -130,8 +131,10 @@ void radeon_cmd_light(char *param)
lvds_gen_cntl |=3D RADEON_LVDS_ON;
} else if(strcmp(param,"off") =3D=3D 0) {
lvds_gen_cntl &=3D ~ RADEON_LVDS_ON;
+#if 0
} else {
usage(); =20
+#endif
};
radeon_set(RADEON_LVDS_GEN_CNTL,"RADEON_LVDS_GEN_CNTL",lvds_gen_cntl=
);
}
Index: s2ram.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/suspend/suspend/s2ram.c,v
retrieving revision 1.11
diff -u -p -r1.11 s2ram.c
--- s2ram.c 23 Feb 2006 12:20:26 -0000 1.11
+++ s2ram.c 24 Feb 2006 11:16:37 -0000
@@ -34,8 +34,10 @@ static void half_known(void)
static void radeon_backlight_off(void)
{
/* switch to console 1 first, since we might be in X */
- active_console =3D fgconsole();
- chvt(1);
+ if (!active_console) {
+ active_console =3D fgconsole();
+ chvt(1);
+ }
map_radeon_cntl_mem();
radeon_cmd_light("off");
}
@@ -59,8 +61,10 @@ static void vbe_state_save(void)
/* vbe_state_save (and especially restore) should not happen behind
* X's back, otherwise bad things might happen. So we switch to console=
1.
*/
- active_console =3D fgconsole();
- chvt(1);
+ if (!active_console) {
+ active_console =3D fgconsole();
+ chvt(1);
+ }
vbetool_init();
vbe_buffer =3D __save_state(&size);
}
@@ -293,27 +297,88 @@ void s2ram_resume(void)
chvt(active_console);
}
=20
+void usage(void)
+{
+ printf("Usage: s2ram [-nh] [-fsra]\n"
+ "\n"
+ "Options:\n"
+ " -h, --help: this text.\n"
+ " -n, --test: test if the machine is in the database.\n=
"
+ " returns 0 if known and supported\n"
+ " -f, --force: force suspending, even on unknown "
+ "machines.\n"
+ "\n"
+ "the following options are only available with --force:\n"
+ " -s, --vbe_save: save VBE state before suspending and "
+ "restore after resume.\n"
+ " -r, --radeontool: turn off the backlight on radeons "
+ "before suspending.\n"
+ " -a, --acpi_sleep: set the acpi_sleep parameter before "
+ "suspend\n"
+ " 1=3Ds3_bios, 2=3Ds3_mode, 3=3Dboth\n"
+ "\n");
+ exit(1);
+}
+
int main(int argc, char *argv[])
{
- int i;
+ int i, force =3D 0, vbe_save =3D 0, radeontool =3D 0, acpi_sleep =3D -1=
;
struct option options[] =3D {
- { "test", no_argument, NULL, 'n'},
- { "help", no_argument, NULL, 'h'},
- { NULL, 0, NULL, 0 }
+ { "test", no_argument, NULL, 'n'},
+ { "help", no_argument, NULL, 'h'},
+ { "force", no_argument, NULL, 'f'},
+ { "vbe_save", no_argument, NULL, 's'},
+ { "radeontool", no_argument, NULL, 'r'},
+ { "acpi_sleep", required_argument, NULL, 'a'},
+ { NULL, 0, NULL, 0 }
};
=20
- while ((i =3D getopt_long(argc, argv, "nh", options, NULL)) !=3D -1) {
+ while ((i =3D getopt_long(argc, argv, "nhfsra:", options, NULL)) !=3D -=
1) {
switch (i) {
case 'h':
- printf("Usage: s2ram [-nh]\n");
- exit(1);
+ usage();
break;
case 'n':
test_mode =3D 1;
break;
+ case 'f':
+ force =3D 1;
+ break;
+ case 's':
+ vbe_save =3D 1;
+ break;
+ case 'r':
+ radeontool =3D 1;
+ break;
+ case 'a':
+ acpi_sleep =3D atoi(optarg);
+ break;
}
}
- s2ram_prepare();
+ if (((acpi_sleep > -1) || vbe_save || radeontool) && !force) {
+ printf("acpi_sleep, vbe_save and radeontool parameter "
+ "must be used with --force\n\n");
+ usage();
+ }
+ if (force && test_mode) {
+ printf("force and test mode do not make sense together.\n\n");
+ usage();
+ }
+
+ if (force) {
+ if (acpi_sleep > -1) {
+ if (acpi_sleep < 4)
+ set_acpi_video_mode(acpi_sleep);
+ else
+ printf("acpi_sleep parameter out of rande (0-3), ignored.\n");
+ }
+ if (vbe_save)
+ vbe_state_save();
+ if (radeontool)
+ radeon_backlight_off();
+ } else {
+ s2ram_prepare();
+ }
s2ram_do();
s2ram_resume();
return 0;
the radeontool ifdefs are to make it a bit nicer wrt. usage() etc.
the "if (!active_console)" is needed for the case "vbe_save" && "radeonto=
ol",
otherwise it will not switch back after resume.
Something that is somewhat important is the "user interface", which means
the name of the options. I'd like to integrate this into a maintained
product and one purpose is that i can easily update s2ram to support new
machines and do not have to touch other packages.
If the options change often, this will be much harder :-)
I'll also start working on the whitelist with machine updates and maybe
even nicer code.
--=20
Stefan Seyfried
QA / R&D Team Mobile Devices | "Any ideas, John?"
SUSE LINUX Products GmbH, N=FCrnberg | "Well, surrounding them's out."=20
|