summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/i386/pc386/console/fb_vga.c
blob: 57e45097f55fb425fa9f828bec807aee57db1569 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*
/////////////////////////////////////////////////////////////////////////////
// $Header$
//
// Copyright (c) 2000 - Rosimildo da Silva ( rdasilva@connecttel.com )
//
// MODULE DESCRIPTION:
// This module implements the micro FB driver for "Bare VGA". It uses the
// routines for "bare hardware" that comes with MicroWindows.
//
// MODIFICATION/HISTORY:
//
// $Log$
// Revision 1.2  2004/04/21 10:42:44  ralf
// Remove stray white spaces.
//
// Revision 1.1  2000/08/30 08:15:30  joel
// 2000-08-26  Rosimildo da Silva  <rdasilva@connecttel.com>
//
// 	* Major rework of the "/dev/console" driver.
// 	* Added termios support for stdin ( keyboard ).
// 	* Added ioctls() to support modes similar to Linux( XLATE,
// 	RAW, MEDIUMRAW ).
// 	* Added Keyboard mapping and handling of the keyboard's leds.
// 	* Added Micro FrameBuffer driver ( "/dev/fb0" ) for bare VGA
// 	controller ( 16 colors ).
// 	* Added PS/2 and Serial mouse support for PC386 BSP.
// 	* console/defkeymap.c: New file.
// 	* console/fb_vga.c: New file.
// 	* console/fb_vga.h: New file.
// 	* console/i386kbd.h: New file.
// 	* console/kd.h: New file.
// 	* console/keyboard.c: New file.
// 	* console/keyboard.h: New file.
// 	* console/mouse_parser.c: New file.
// 	* console/mouse_parser.h: New file.
// 	* console/pc_keyb.c: New file.
// 	* console/ps2_drv.h: New file.
// 	* console/ps2_mouse.c: New file.
// 	* console/ps2_mouse.h: New file.
// 	* console/serial_mouse.c: New file.
// 	* console/serial_mouse.h: New file.
// 	* console/vgainit.c: New file.
// 	* console/vt.c: New file.
// 	* console/Makefile.am: Reflect new files.
// 	* console/console.c, console/inch.c, console/outch.c: Console
// 	functionality modifications.
// 	* startup/Makefile.am: Pick up tty_drv.c and gdb_glue.c
//
//
/////////////////////////////////////////////////////////////////////////////
*/

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>

#include <bsp.h>
#include <irq.h>
#include <rtems/libio.h>

#include <rtems/mw_fb.h>

/* these routines are defined in the microwindows code. This
   driver is here more as an example of how to implement and
   use the micro FB interface
*/
extern void ega_hwinit( void );
extern void ega_hwterm( void );

/* screen information for the VGA driver */
static struct fb_screeninfo fb_info =
{
   640, 480,                     /* screen size x, y  */
   4,                            /* bits per pixel    */
   80,                           /* chars per line    */
   (volatile char *)0xA0000,     /* buffer pointer    */
   0x10000,                      /* buffer size       */
   FB_TYPE_VGA_PLANES,           /* type of dsplay    */
	FB_VISUAL_PSEUDOCOLOR         /* color scheme used */
};

static __u16 red16[] = {
    0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa,
    0x5555, 0x5555, 0x5555, 0x5555, 0xffff, 0xffff, 0xffff, 0xffff
};
static __u16 green16[] = {
    0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa,
    0x5555, 0x5555, 0xffff, 0xffff, 0x5555, 0x5555, 0xffff, 0xffff
};
static __u16 blue16[] = {
    0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa,
    0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff
};

/*
 * fbvga device driver INITIALIZE entry point.
 */
rtems_device_driver
fbvga_initialize(  rtems_device_major_number major,
                   rtems_device_minor_number minor,
                   void                      *arg)
{
   rtems_status_code status;

  printk( "FBVGA -- driver initializing..\n" );
  /*
   * Register the device
   */
  status = rtems_io_register_name ("/dev/fb0", major, 0);
  if (status != RTEMS_SUCCESSFUL)
  {
      printk("Error registering FBVGA device!\n");
      rtems_fatal_error_occurred( status );
  }
  return RTEMS_SUCCESSFUL;
}

/*
 * fbvga device driver OPEN entry point
 */
rtems_device_driver
fbvga_open( rtems_device_major_number major,
            rtems_device_minor_number minor,
            void                      *arg)
{
/*  rtems_status_code status; */
  printk( "FBVGA open called.\n" );
  return RTEMS_SUCCESSFUL;
}

/*
 * fbvga device driver CLOSE entry point
 */
rtems_device_driver
fbvga_close(rtems_device_major_number major,
            rtems_device_minor_number minor,
            void                      *arg)
{
  printk( "FBVGA close called.\n" );
  return RTEMS_SUCCESSFUL;
}

/*
 * fbvga device driver READ entry point.
 * Read characters from the PS/2 mouse.
 */
rtems_device_driver
fbvga_read( rtems_device_major_number major,
            rtems_device_minor_number minor,
            void                      *arg)
{
  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
  printk( "FBVGA read called.\n" );
  rw_args->bytes_moved = 0;
  return RTEMS_SUCCESSFUL;
}

/*
 * fbvga device driver WRITE entry point.
 * Write characters to the PS/2 mouse.
 */
rtems_device_driver
fbvga_write( rtems_device_major_number major,
             rtems_device_minor_number minor,
             void                    * arg)
{
  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
  printk( "FBVGA write called.\n" );
  rw_args->bytes_moved = 0;
  return RTEMS_SUCCESSFUL;
}

static int get_screen_info( struct fb_screeninfo *info )
{
  *info = fb_info;
  return 0;
}

static int get_palette( struct fb_cmap *cmap )
{
  __u32 i;

  if( cmap->start + cmap->len >= 16 )
      return 1;

  for( i = 0; i < cmap->len; i++ )
  {
    cmap->red[ cmap->start + i ]   = red16[ cmap->start + i ];
    cmap->green[ cmap->start + i ] = green16[ cmap->start + i ];
    cmap->blue[ cmap->start + i ]  = blue16[ cmap->start + i ];
  }
  return 0;
}

static int set_palette( struct fb_cmap *cmap )
{
  __u32 i;

  if( cmap->start + cmap->len >= 16 )
      return 1;

  for( i = 0; i < cmap->len; i++ )
  {
    red16[ cmap->start + i ] = cmap->red[ cmap->start + i ];
    green16[ cmap->start + i ] = cmap->green[ cmap->start + i ];
    blue16[ cmap->start + i ] = cmap->blue[ cmap->start + i ];
  }
  return 0;
}

/*
 * IOCTL entry point -- This method is called to carry
 * all services of this interface.
 */
rtems_device_driver
fbvga_control( rtems_device_major_number major,
               rtems_device_minor_number minor,
               void                      * arg
)
{
	rtems_libio_ioctl_args_t *args = arg;
   printk( "FBVGA ioctl called, cmd=%x\n", args->command  );
   switch( args->command )
   {
      case FB_SCREENINFO:
      args->ioctl_return =  get_screen_info( args->buffer );
      break;
      case FB_GETPALETTE:
      args->ioctl_return =  get_palette( args->buffer );
      break;
      case FB_SETPALETTE:
      args->ioctl_return =  set_palette( args->buffer );
      break;

      /* this function would execute one of the routines of the
       * interface based on the operation requested
       */
      case FB_EXEC_FUNCTION:
      {
         struct fb_exec_function *env = args->buffer;
         switch( env->func_no )
         {
           case FB_FUNC_ENTER_GRAPHICS:
           /* enter graphics mode*/
           ega_hwinit();
           break;

           case FB_FUNC_EXIT_GRAPHICS:
           /* leave graphics mode*/
           ega_hwterm();
           break;

           case FB_FUNC_IS_DIRTY:
           break;

           case FB_FUNC_GET_MODE:
           break;

           default:
           break;
         }
      }
      /* no break on purpose */
	   default:
      args->ioctl_return = 0;
		break;

   }
   return RTEMS_SUCCESSFUL;
}