8340e7c9 |
1 | /* |
2 | * picorestore - clean up after an omapfb program crash |
3 | * |
4 | * Copyright (c) GraÅžvydas "notaz" Ignotas, 2010 |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions are met: |
8 | * * Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * * Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * * Neither the name of the organization nor the |
14 | * names of its contributors may be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
20 | * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
28 | |
be672de7 |
29 | #include <stdio.h> |
30 | #include <sys/types.h> |
31 | #include <sys/stat.h> |
32 | #include <fcntl.h> |
33 | #include <unistd.h> |
34 | #include <sys/ioctl.h> |
35 | #include <linux/fb.h> |
c7eb229a |
36 | #include <linux/omapfb.h> |
be672de7 |
37 | #include <linux/kd.h> |
38 | |
39 | int main() |
40 | { |
41 | struct fb_var_screeninfo fbvar; |
739e1043 |
42 | struct omapfb_plane_info pi; |
43 | struct omapfb_mem_info mi; |
be672de7 |
44 | int ret, fbdev, kbdfd; |
be672de7 |
45 | |
46 | fbdev = open("/dev/fb0", O_RDWR); |
47 | if (fbdev == -1) { |
c7eb229a |
48 | perror("open fb0"); |
49 | goto end_fb0; |
be672de7 |
50 | } |
51 | |
52 | ret = ioctl(fbdev, FBIOGET_VSCREENINFO, &fbvar); |
53 | if (ret == -1) { |
54 | perror("FBIOGET_VSCREENINFO ioctl"); |
c7eb229a |
55 | goto end_fb0; |
be672de7 |
56 | } |
57 | |
58 | if (fbvar.yoffset != 0) { |
59 | printf("fixing yoffset.. "); |
60 | fbvar.yoffset = 0; |
61 | ret = ioctl(fbdev, FBIOPAN_DISPLAY, &fbvar); |
62 | if (ret < 0) |
63 | perror("ioctl FBIOPAN_DISPLAY"); |
64 | else |
65 | printf("ok\n"); |
66 | } |
67 | |
c7eb229a |
68 | end_fb0: |
69 | if (fbdev >= 0) |
70 | close(fbdev); |
71 | |
72 | fbdev = open("/dev/fb1", O_RDWR); |
73 | if (fbdev == -1) { |
74 | perror("open fb1"); |
75 | goto end_fb1; |
76 | } |
77 | |
739e1043 |
78 | ret = ioctl(fbdev, OMAPFB_QUERY_PLANE, &pi); |
79 | ret |= ioctl(fbdev, OMAPFB_QUERY_MEM, &mi); |
c7eb229a |
80 | if (ret != 0) |
81 | perror("QUERY_*"); |
82 | |
83 | pi.enabled = 0; |
739e1043 |
84 | ret = ioctl(fbdev, OMAPFB_SETUP_PLANE, &pi); |
c7eb229a |
85 | if (ret != 0) |
86 | perror("SETUP_PLANE"); |
87 | |
88 | mi.size = 0; |
739e1043 |
89 | ret = ioctl(fbdev, OMAPFB_SETUP_MEM, &mi); |
c7eb229a |
90 | if (ret != 0) |
91 | perror("SETUP_MEM"); |
92 | |
93 | end_fb1: |
94 | if (fbdev >= 0) |
95 | close(fbdev); |
be672de7 |
96 | |
234f07f4 |
97 | kbdfd = open("/dev/tty", O_RDWR); |
98 | if (kbdfd == -1) { |
99 | perror("open /dev/tty"); |
100 | return 1; |
101 | } |
be672de7 |
102 | |
234f07f4 |
103 | if (ioctl(kbdfd, KDSETMODE, KD_TEXT) == -1) |
104 | perror("KDSETMODE KD_TEXT"); |
be672de7 |
105 | |
234f07f4 |
106 | close(kbdfd); |
be672de7 |
107 | |
108 | return 0; |
109 | } |