source: rtems/c/src/lib/libbsp/i386/pc386/console/fb_vga.c @ c499856

4.115
Last change on this file since c499856 was 311ba73, checked in by Sebastian Huber <sebastian.huber@…>, on 06/23/13 at 15:50:55

framebuffer: Add and use FRAMEBUFFER_DEVICE_0_NAME

  • Property mode set to 100644
File size: 6.7 KB
Line 
1/*
2 * Copyright (c) 2000 - Rosimildo da Silva ( rdasilva@connecttel.com )
3 *
4 * MODULE DESCRIPTION:
5 * This module implements FB driver for "Bare VGA". It uses the
6 * routines for "bare hardware" found in vgainit.c.
7 *
8 */
9
10#include <stdlib.h>
11#include <stdio.h>
12#include <errno.h>
13#include <sys/types.h>
14#include <pthread.h>
15
16#include <bsp.h>
17#include <bsp/irq.h>
18#include <rtems/libio.h>
19
20#include <rtems/fb.h>
21#include <rtems/framebuffer.h>
22
23/* these routines are defined in vgainit.c.*/
24extern void ega_hwinit( void );
25extern void ega_hwterm( void );
26
27/* mutex attribure */
28pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
29
30/* screen information for the VGA driver */
31static struct fb_var_screeninfo fb_var =
32{
33  .xres                = 640,
34  .yres                = 480,
35  .bits_per_pixel      = 4
36};
37
38static struct fb_fix_screeninfo fb_fix =
39{
40  .smem_start          = (volatile char *)0xA0000,     /* buffer pointer    */
41  .smem_len            = 0x10000,                      /* buffer size       */
42  .type                = FB_TYPE_VGA_PLANES,           /* type of dsplay    */
43  .visual              = FB_VISUAL_PSEUDOCOLOR,        /* color scheme used */
44  .line_length         = 80                            /* chars per line    */
45};
46
47
48static uint16_t red16[] = {
49   0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa,
50   0x5555, 0x5555, 0x5555, 0x5555, 0xffff, 0xffff, 0xffff, 0xffff
51};
52static uint16_t green16[] = {
53   0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa,
54   0x5555, 0x5555, 0xffff, 0xffff, 0x5555, 0x5555, 0xffff, 0xffff
55};
56static uint16_t blue16[] = {
57   0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa,
58   0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff
59};
60
61/* Functionality to support multiple VGA frame buffers can be added easily,
62 * but is not supported at this moment because there is no need for two or
63 * more "classic" VGA adapters.  Multiple frame buffer drivers may be
64 * implemented and If we had implement it they would be named as "/dev/fb0",
65 * "/dev/fb1", "/dev/fb2" and so on.
66 */
67/*
68 * fbvga device driver INITIALIZE entry point.
69 */
70rtems_device_driver frame_buffer_initialize(
71  rtems_device_major_number  major,
72  rtems_device_minor_number  minor,
73  void                      *arg
74)
75{
76  rtems_status_code status;
77
78  printk( "FBVGA -- driver initializing..\n" );
79
80  /*
81   * Register the device
82   */
83  status = rtems_io_register_name (FRAMEBUFFER_DEVICE_0_NAME, major, 0);
84  if (status != RTEMS_SUCCESSFUL) {
85    printk("Error registering " FRAMEBUFFER_DEVICE_0_NAME
86           " FBVGA framebuffer device!\n");
87    rtems_fatal_error_occurred( status );
88  }
89
90  return RTEMS_SUCCESSFUL;
91}
92
93/*
94 * fbvga device driver OPEN entry point
95 */
96rtems_device_driver frame_buffer_open(
97  rtems_device_major_number  major,
98  rtems_device_minor_number  minor,
99  void                      *arg
100)
101{
102  if (pthread_mutex_trylock(&mutex)== 0){
103      /* restore previous state.  for VGA this means return to text mode.
104       * leave out if graphics hardware has been initialized in
105       * frame_buffer_initialize()
106       */
107      ega_hwinit();
108      printk( "FBVGA open called.\n" );
109      return RTEMS_SUCCESSFUL;
110  }
111
112  return RTEMS_UNSATISFIED;
113}
114
115/*
116 * fbvga device driver CLOSE entry point
117 */
118rtems_device_driver frame_buffer_close(
119  rtems_device_major_number  major,
120  rtems_device_minor_number  minor,
121  void                      *arg
122)
123{
124  if (pthread_mutex_unlock(&mutex) == 0){
125    /* restore previous state.  for VGA this means return to text mode.
126     * leave out if graphics hardware has been initialized in
127     * frame_buffer_initialize() */
128    ega_hwterm();
129    printk( "FBVGA close called.\n" );
130    return RTEMS_SUCCESSFUL;
131  }
132
133  return RTEMS_UNSATISFIED;
134}
135
136/*
137 * fbvga device driver READ entry point.
138 */
139rtems_device_driver frame_buffer_read(
140  rtems_device_major_number  major,
141  rtems_device_minor_number  minor,
142  void                      *arg
143)
144{
145  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
146  rw_args->bytes_moved = ((rw_args->offset + rw_args->count) > fb_fix.smem_len ) ? (fb_fix.smem_len - rw_args->offset) : rw_args->count;
147  memcpy(rw_args->buffer, (const void *) (fb_fix.smem_start + rw_args->offset), rw_args->bytes_moved);
148  return RTEMS_SUCCESSFUL;
149}
150
151/*
152 * frame_buffer device driver WRITE entry point.
153 */
154rtems_device_driver frame_buffer_write(
155  rtems_device_major_number  major,
156  rtems_device_minor_number  minor,
157  void                      *arg
158)
159{
160  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
161  rw_args->bytes_moved = ((rw_args->offset + rw_args->count) > fb_fix.smem_len ) ? (fb_fix.smem_len - rw_args->offset) : rw_args->count;
162  memcpy( (void *) (fb_fix.smem_start + rw_args->offset), rw_args->buffer, rw_args->bytes_moved);
163  return RTEMS_SUCCESSFUL;
164}
165
166static int get_fix_screen_info( struct fb_fix_screeninfo *info )
167{
168  *info = fb_fix;
169  return 0;
170}
171
172static int get_var_screen_info( struct fb_var_screeninfo *info )
173{
174  *info =  fb_var;
175  return 0;
176}
177
178static int get_palette( struct fb_cmap *cmap )
179{
180  uint32_t i;
181
182  if ( cmap->start + cmap->len >= 16 )
183    return 1;
184
185  for( i = 0; i < cmap->len; i++ ) {
186    cmap->red[ cmap->start + i ]   = red16[ cmap->start + i ];
187    cmap->green[ cmap->start + i ] = green16[ cmap->start + i ];
188    cmap->blue[ cmap->start + i ]  = blue16[ cmap->start + i ];
189  }
190  return 0;
191}
192
193static int set_palette( struct fb_cmap *cmap )
194{
195  uint32_t i;
196
197  if ( cmap->start + cmap->len >= 16 )
198    return 1;
199
200  for( i = 0; i < cmap->len; i++ ) {
201    red16[ cmap->start + i ] = cmap->red[ cmap->start + i ];
202    green16[ cmap->start + i ] = cmap->green[ cmap->start + i ];
203    blue16[ cmap->start + i ] = cmap->blue[ cmap->start + i ];
204  }
205  return 0;
206}
207
208/*
209 * IOCTL entry point -- This method is called to carry
210 * all services of this interface.
211 */
212rtems_device_driver frame_buffer_control(
213  rtems_device_major_number  major,
214  rtems_device_minor_number  minor,
215  void                      *arg
216)
217{
218  rtems_libio_ioctl_args_t *args = arg;
219
220  printk( "FBVGA ioctl called, cmd=%x\n", args->command  );
221
222  switch( args->command ) {
223    case FBIOGET_FSCREENINFO:
224      args->ioctl_return =  get_fix_screen_info( ( struct fb_fix_screeninfo * ) args->buffer );
225      break;
226    case FBIOGET_VSCREENINFO:
227      args->ioctl_return =  get_var_screen_info( ( struct fb_var_screeninfo * ) args->buffer );
228      break;
229    case FBIOPUT_VSCREENINFO:
230      /* not implemented yet*/
231      args->ioctl_return = -1;
232      return RTEMS_UNSATISFIED;
233    case FBIOGETCMAP:
234      args->ioctl_return =  get_palette( ( struct fb_cmap * ) args->buffer );
235      break;
236    case FBIOPUTCMAP:
237      args->ioctl_return =  set_palette( ( struct fb_cmap * ) args->buffer );
238      break;
239
240    default:
241     args->ioctl_return = 0;
242     break;
243  }
244  return RTEMS_SUCCESSFUL;
245}
Note: See TracBrowser for help on using the repository browser.