2 * pslash - a lightweight framebuffer splashscreen for embedded devices.
4 * Copyright (c) 2006 Matthew Allum <mallum@o-hand.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
20 /* Globals, needed for signal handling */
21 static int ConsoleFd = -1;
22 static int VTNum = -1;
23 static int VTNumInitial = -1;
24 static int Visible = 1;
29 DBG("mark, visible:%i", Visible);
33 /* Allow Switch Away */
34 if (ioctl (ConsoleFd, VT_RELDISP, 1) < 0)
35 perror("Error cannot switch away from console");
39 * We likely now want to signal the main loop as to exit
40 * and we've now likely switched to the X tty. Note, this
41 * seems to happen anyway atm due to select() call getting
42 * a signal interuption error - not sure if this is really
48 if (ioctl (ConsoleFd, VT_RELDISP, VT_ACKACQ))
49 perror ("Error can't acknowledge VT switch");
51 /* FIXME: need to schedule repaint some how ? */
56 psplash_console_ignore_switches (void)
59 struct vt_mode vt_mode;
61 if (ioctl(ConsoleFd, VT_GETMODE, &vt_mode) < 0)
63 perror("Error VT_SETMODE failed");
67 act.sa_handler = SIG_IGN;
68 sigemptyset (&act.sa_mask);
70 sigaction (SIGUSR1, &act, 0);
72 vt_mode.mode = VT_AUTO;
76 if (ioctl(ConsoleFd, VT_SETMODE, &vt_mode) < 0)
77 perror("Error VT_SETMODE failed");
81 psplash_console_handle_switches (void)
84 struct vt_mode vt_mode;
86 if (ioctl(ConsoleFd, VT_GETMODE, &vt_mode) < 0)
88 perror("Error VT_SETMODE failed");
92 act.sa_handler = vt_request;
93 sigemptyset (&act.sa_mask);
95 sigaction (SIGUSR1, &act, 0);
97 vt_mode.mode = VT_PROCESS;
98 vt_mode.relsig = SIGUSR1;
99 vt_mode.acqsig = SIGUSR1;
101 if (ioctl(ConsoleFd, VT_SETMODE, &vt_mode) < 0)
102 perror("Error VT_SETMODE failed");
106 psplash_console_switch (void)
110 struct vt_stat vt_state;
112 if ((fd = open("/dev/tty0",O_WRONLY,0)) < 0)
114 perror("Error Cannot open /dev/tty0");
118 /* Find next free terminal */
119 if ((ioctl(fd, VT_OPENQRY, &VTNum) < 0))
121 perror("Error unable to find a free virtual terminal");
128 sprintf(vtname,"/dev/tty%d", VTNum);
130 if ((ConsoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) < 0)
132 fprintf(stderr, "Error cannot open %s: %s\n", vtname, strerror(errno));
136 if (ioctl(ConsoleFd, VT_GETSTATE, &vt_state) == 0)
137 VTNumInitial = vt_state.v_active;
139 /* Switch to new free terminal */
141 psplash_console_ignore_switches ();
143 if (ioctl(ConsoleFd, VT_ACTIVATE, VTNum) != 0)
144 perror("Error VT_ACTIVATE failed");
146 if (ioctl(ConsoleFd, VT_WAITACTIVE, VTNum) != 0)
147 perror("Error VT_WAITACTIVE failed\n");
149 psplash_console_handle_switches ();
151 if (ioctl(ConsoleFd, KDSETMODE, KD_GRAPHICS) < 0)
152 perror("Error KDSETMODE KD_GRAPHICS failed\n");
158 psplash_console_reset (void)
161 struct vt_stat vt_state;
166 /* Back to text mode */
167 ioctl(ConsoleFd, KDSETMODE, KD_TEXT);
169 psplash_console_ignore_switches ();
171 /* Attempt to switch back to initial console if were still active */
172 ioctl (ConsoleFd, VT_GETSTATE, &vt_state);
174 if (VTNum == vt_state.v_active)
176 if (VTNumInitial > -1)
178 ioctl (ConsoleFd, VT_ACTIVATE, VTNumInitial);
179 ioctl (ConsoleFd, VT_WAITACTIVE, VTNumInitial);
188 if ((fd = open ("/dev/tty0", O_RDWR|O_NDELAY, 0)) >= 0)
190 ioctl (fd, VT_DISALLOCATE, VTNum);