1 | /* |
---|
2 | ///////////////////////////////////////////////////////////////////////////// |
---|
3 | // $Header$ |
---|
4 | // |
---|
5 | // Copyright (c) 2000 - Rosimildo da Silva ( rdasilva@connecttel.com ) |
---|
6 | // |
---|
7 | // MODULE DESCRIPTION: |
---|
8 | // This module implements the micro FB driver for "Bare VGA". It uses the |
---|
9 | // routines for "bare hardware" that comes with MicroWindows. |
---|
10 | // |
---|
11 | // MODIFICATION/HISTORY: |
---|
12 | // |
---|
13 | // $Log$ |
---|
14 | // Revision 1.3 2004/04/21 16:01:33 ralf |
---|
15 | // Remove duplicate white lines. |
---|
16 | // |
---|
17 | // Revision 1.2 2004/04/21 10:42:44 ralf |
---|
18 | // Remove stray white spaces. |
---|
19 | // |
---|
20 | // Revision 1.1 2000/08/30 08:15:30 joel |
---|
21 | // 2000-08-26 Rosimildo da Silva <rdasilva@connecttel.com> |
---|
22 | // |
---|
23 | // * Major rework of the "/dev/console" driver. |
---|
24 | // * Added termios support for stdin ( keyboard ). |
---|
25 | // * Added ioctls() to support modes similar to Linux( XLATE, |
---|
26 | // RAW, MEDIUMRAW ). |
---|
27 | // * Added Keyboard mapping and handling of the keyboard's leds. |
---|
28 | // * Added Micro FrameBuffer driver ( "/dev/fb0" ) for bare VGA |
---|
29 | // controller ( 16 colors ). |
---|
30 | // * Added PS/2 and Serial mouse support for PC386 BSP. |
---|
31 | // * console/defkeymap.c: New file. |
---|
32 | // * console/fb_vga.c: New file. |
---|
33 | // * console/fb_vga.h: New file. |
---|
34 | // * console/i386kbd.h: New file. |
---|
35 | // * console/kd.h: New file. |
---|
36 | // * console/keyboard.c: New file. |
---|
37 | // * console/keyboard.h: New file. |
---|
38 | // * console/mouse_parser.c: New file. |
---|
39 | // * console/mouse_parser.h: New file. |
---|
40 | // * console/pc_keyb.c: New file. |
---|
41 | // * console/ps2_drv.h: New file. |
---|
42 | // * console/ps2_mouse.c: New file. |
---|
43 | // * console/ps2_mouse.h: New file. |
---|
44 | // * console/serial_mouse.c: New file. |
---|
45 | // * console/serial_mouse.h: New file. |
---|
46 | // * console/vgainit.c: New file. |
---|
47 | // * console/vt.c: New file. |
---|
48 | // * console/Makefile.am: Reflect new files. |
---|
49 | // * console/console.c, console/inch.c, console/outch.c: Console |
---|
50 | // functionality modifications. |
---|
51 | // * startup/Makefile.am: Pick up tty_drv.c and gdb_glue.c |
---|
52 | // |
---|
53 | // |
---|
54 | ///////////////////////////////////////////////////////////////////////////// |
---|
55 | */ |
---|
56 | |
---|
57 | #include <stdlib.h> |
---|
58 | #include <stdio.h> |
---|
59 | #include <errno.h> |
---|
60 | #include <sys/types.h> |
---|
61 | |
---|
62 | #include <bsp.h> |
---|
63 | #include <bsp/irq.h> |
---|
64 | #include <rtems/libio.h> |
---|
65 | |
---|
66 | #include <rtems/mw_fb.h> |
---|
67 | |
---|
68 | /* these routines are defined in the microwindows code. This |
---|
69 | driver is here more as an example of how to implement and |
---|
70 | use the micro FB interface |
---|
71 | */ |
---|
72 | extern void ega_hwinit( void ); |
---|
73 | extern void ega_hwterm( void ); |
---|
74 | |
---|
75 | /* screen information for the VGA driver */ |
---|
76 | static struct fb_screeninfo fb_info = |
---|
77 | { |
---|
78 | 640, 480, /* screen size x, y */ |
---|
79 | 4, /* bits per pixel */ |
---|
80 | 80, /* chars per line */ |
---|
81 | (volatile char *)0xA0000, /* buffer pointer */ |
---|
82 | 0x10000, /* buffer size */ |
---|
83 | FB_TYPE_VGA_PLANES, /* type of dsplay */ |
---|
84 | FB_VISUAL_PSEUDOCOLOR /* color scheme used */ |
---|
85 | }; |
---|
86 | |
---|
87 | static __u16 red16[] = { |
---|
88 | 0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa, |
---|
89 | 0x5555, 0x5555, 0x5555, 0x5555, 0xffff, 0xffff, 0xffff, 0xffff |
---|
90 | }; |
---|
91 | static __u16 green16[] = { |
---|
92 | 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa, |
---|
93 | 0x5555, 0x5555, 0xffff, 0xffff, 0x5555, 0x5555, 0xffff, 0xffff |
---|
94 | }; |
---|
95 | static __u16 blue16[] = { |
---|
96 | 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, |
---|
97 | 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff |
---|
98 | }; |
---|
99 | |
---|
100 | /* |
---|
101 | * fbvga device driver INITIALIZE entry point. |
---|
102 | */ |
---|
103 | rtems_device_driver |
---|
104 | fbvga_initialize( rtems_device_major_number major, |
---|
105 | rtems_device_minor_number minor, |
---|
106 | void *arg) |
---|
107 | { |
---|
108 | rtems_status_code status; |
---|
109 | |
---|
110 | printk( "FBVGA -- driver initializing..\n" ); |
---|
111 | /* |
---|
112 | * Register the device |
---|
113 | */ |
---|
114 | status = rtems_io_register_name ("/dev/fb0", major, 0); |
---|
115 | if (status != RTEMS_SUCCESSFUL) |
---|
116 | { |
---|
117 | printk("Error registering FBVGA device!\n"); |
---|
118 | rtems_fatal_error_occurred( status ); |
---|
119 | } |
---|
120 | return RTEMS_SUCCESSFUL; |
---|
121 | } |
---|
122 | |
---|
123 | /* |
---|
124 | * fbvga device driver OPEN entry point |
---|
125 | */ |
---|
126 | rtems_device_driver |
---|
127 | fbvga_open( rtems_device_major_number major, |
---|
128 | rtems_device_minor_number minor, |
---|
129 | void *arg) |
---|
130 | { |
---|
131 | /* rtems_status_code status; */ |
---|
132 | printk( "FBVGA open called.\n" ); |
---|
133 | return RTEMS_SUCCESSFUL; |
---|
134 | } |
---|
135 | |
---|
136 | /* |
---|
137 | * fbvga device driver CLOSE entry point |
---|
138 | */ |
---|
139 | rtems_device_driver |
---|
140 | fbvga_close(rtems_device_major_number major, |
---|
141 | rtems_device_minor_number minor, |
---|
142 | void *arg) |
---|
143 | { |
---|
144 | printk( "FBVGA close called.\n" ); |
---|
145 | return RTEMS_SUCCESSFUL; |
---|
146 | } |
---|
147 | |
---|
148 | /* |
---|
149 | * fbvga device driver READ entry point. |
---|
150 | * Read characters from the PS/2 mouse. |
---|
151 | */ |
---|
152 | rtems_device_driver |
---|
153 | fbvga_read( rtems_device_major_number major, |
---|
154 | rtems_device_minor_number minor, |
---|
155 | void *arg) |
---|
156 | { |
---|
157 | rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg; |
---|
158 | printk( "FBVGA read called.\n" ); |
---|
159 | rw_args->bytes_moved = 0; |
---|
160 | return RTEMS_SUCCESSFUL; |
---|
161 | } |
---|
162 | |
---|
163 | /* |
---|
164 | * fbvga device driver WRITE entry point. |
---|
165 | * Write characters to the PS/2 mouse. |
---|
166 | */ |
---|
167 | rtems_device_driver |
---|
168 | fbvga_write( rtems_device_major_number major, |
---|
169 | rtems_device_minor_number minor, |
---|
170 | void * arg) |
---|
171 | { |
---|
172 | rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg; |
---|
173 | printk( "FBVGA write called.\n" ); |
---|
174 | rw_args->bytes_moved = 0; |
---|
175 | return RTEMS_SUCCESSFUL; |
---|
176 | } |
---|
177 | |
---|
178 | static int get_screen_info( struct fb_screeninfo *info ) |
---|
179 | { |
---|
180 | *info = fb_info; |
---|
181 | return 0; |
---|
182 | } |
---|
183 | |
---|
184 | static int get_palette( struct fb_cmap *cmap ) |
---|
185 | { |
---|
186 | __u32 i; |
---|
187 | |
---|
188 | if( cmap->start + cmap->len >= 16 ) |
---|
189 | return 1; |
---|
190 | |
---|
191 | for( i = 0; i < cmap->len; i++ ) |
---|
192 | { |
---|
193 | cmap->red[ cmap->start + i ] = red16[ cmap->start + i ]; |
---|
194 | cmap->green[ cmap->start + i ] = green16[ cmap->start + i ]; |
---|
195 | cmap->blue[ cmap->start + i ] = blue16[ cmap->start + i ]; |
---|
196 | } |
---|
197 | return 0; |
---|
198 | } |
---|
199 | |
---|
200 | static int set_palette( struct fb_cmap *cmap ) |
---|
201 | { |
---|
202 | __u32 i; |
---|
203 | |
---|
204 | if( cmap->start + cmap->len >= 16 ) |
---|
205 | return 1; |
---|
206 | |
---|
207 | for( i = 0; i < cmap->len; i++ ) |
---|
208 | { |
---|
209 | red16[ cmap->start + i ] = cmap->red[ cmap->start + i ]; |
---|
210 | green16[ cmap->start + i ] = cmap->green[ cmap->start + i ]; |
---|
211 | blue16[ cmap->start + i ] = cmap->blue[ cmap->start + i ]; |
---|
212 | } |
---|
213 | return 0; |
---|
214 | } |
---|
215 | |
---|
216 | /* |
---|
217 | * IOCTL entry point -- This method is called to carry |
---|
218 | * all services of this interface. |
---|
219 | */ |
---|
220 | rtems_device_driver |
---|
221 | fbvga_control( rtems_device_major_number major, |
---|
222 | rtems_device_minor_number minor, |
---|
223 | void * arg |
---|
224 | ) |
---|
225 | { |
---|
226 | rtems_libio_ioctl_args_t *args = arg; |
---|
227 | printk( "FBVGA ioctl called, cmd=%x\n", args->command ); |
---|
228 | switch( args->command ) |
---|
229 | { |
---|
230 | case FB_SCREENINFO: |
---|
231 | args->ioctl_return = get_screen_info( args->buffer ); |
---|
232 | break; |
---|
233 | case FB_GETPALETTE: |
---|
234 | args->ioctl_return = get_palette( args->buffer ); |
---|
235 | break; |
---|
236 | case FB_SETPALETTE: |
---|
237 | args->ioctl_return = set_palette( args->buffer ); |
---|
238 | break; |
---|
239 | |
---|
240 | /* this function would execute one of the routines of the |
---|
241 | * interface based on the operation requested |
---|
242 | */ |
---|
243 | case FB_EXEC_FUNCTION: |
---|
244 | { |
---|
245 | struct fb_exec_function *env = args->buffer; |
---|
246 | switch( env->func_no ) |
---|
247 | { |
---|
248 | case FB_FUNC_ENTER_GRAPHICS: |
---|
249 | /* enter graphics mode*/ |
---|
250 | ega_hwinit(); |
---|
251 | break; |
---|
252 | |
---|
253 | case FB_FUNC_EXIT_GRAPHICS: |
---|
254 | /* leave graphics mode*/ |
---|
255 | ega_hwterm(); |
---|
256 | break; |
---|
257 | |
---|
258 | case FB_FUNC_IS_DIRTY: |
---|
259 | break; |
---|
260 | |
---|
261 | case FB_FUNC_GET_MODE: |
---|
262 | break; |
---|
263 | |
---|
264 | default: |
---|
265 | break; |
---|
266 | } |
---|
267 | } |
---|
268 | /* no break on purpose */ |
---|
269 | default: |
---|
270 | args->ioctl_return = 0; |
---|
271 | break; |
---|
272 | |
---|
273 | } |
---|
274 | return RTEMS_SUCCESSFUL; |
---|
275 | } |
---|