source: rtems/bsps/arm/gumstix/fb/fb.c @ a3fe23c

5
Last change on this file since a3fe23c was 720ebc0, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 25, 2018 at 8:49:53 AM

bsp/gumstix: Move fb.c to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 6.3 KB
Line 
1 /*
2 *  By Yang Xi <hiyangxi@gmail.com>.
3 *
4 *  The license and distribution terms for this file may be
5 *  found in the file LICENSE in this distribution or at
6 *  http://www.rtems.org/license/LICENSE.
7 */
8
9#include <stdlib.h>
10#include <stdio.h>
11#include <errno.h>
12#include <sys/types.h>
13#include <pthread.h>
14#include <string.h>
15
16#include <pxa255.h>
17#include <bsp.h>
18#include <rtems/libio.h>
19#include <rtems/bspIo.h>
20
21#include <rtems.h>
22#include <rtems/inttypes.h>
23#include <rtems/fb.h>
24#include <rtems/framebuffer.h>
25
26#define SCREEN_WIDTH 640
27#define SCREEN_HEIGHT 480
28#define BPP 16
29#define LCD_DMA_POINTER (0xa0000000 + 62*(1<<20) + 0x1000)
30#define LCD_BUFFER_SIZE (SCREEN_WIDTH*SCREEN_HEIGHT*2)
31
32/* mutex attribure */
33pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
34
35static struct fb_var_screeninfo fb_var =
36  {
37    .xres = SCREEN_WIDTH,
38    .yres = SCREEN_HEIGHT,
39    .bits_per_pixel = BPP
40  };
41
42static struct fb_fix_screeninfo fb_fix =
43  {
44    .smem_start = (volatile char *)LCD_DMA_POINTER,
45    .smem_len = LCD_BUFFER_SIZE,
46    .type = FB_TYPE_PACKED_PIXELS,
47    .visual = FB_VISUAL_TRUECOLOR,
48    .line_length = SCREEN_WIDTH * (BPP/8)
49  };
50
51static uint16_t red16[] = {
52   0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa,
53   0x5555, 0x5555, 0x5555, 0x5555, 0xffff, 0xffff, 0xffff, 0xffff
54};
55static uint16_t green16[] = {
56   0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa,
57   0x5555, 0x5555, 0xffff, 0xffff, 0x5555, 0x5555, 0xffff, 0xffff
58};
59static uint16_t blue16[] = {
60   0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa,
61   0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff
62};
63
64static void enable_fbskyeye(void)
65{
66  LCCR1 &= ~LCCR1_PPL;
67  LCCR1 |= (SCREEN_WIDTH -1 ) & LCCR1_PPL;
68  LCCR2 &= ~LCCR2_LPP;
69  LCCR2 |= (SCREEN_HEIGHT/2 -1) & LCCR2_LPP;
70  LCCR3 &= ~LCCR3_BPP;
71  LCCR3 |= 4<<24;
72  FDADR0 = LCD_DMA_POINTER - 0x1000;
73  LCCR0 |= LCCR0_ENB;
74}
75
76
77static void disable_fbskyeye(void)
78{
79  LCCR0 &= ~LCCR0_ENB;
80}
81
82static int get_fix_screen_info( struct fb_fix_screeninfo *info )
83{
84  *info = fb_fix;
85  return 0;
86}
87
88static int get_var_screen_info( struct fb_var_screeninfo *info )
89{
90  *info = fb_var;
91  return 0;
92}
93
94rtems_device_driver
95frame_buffer_initialize(rtems_device_major_number major,
96                    rtems_device_minor_number minor,
97                    void                      *arg)
98{
99  rtems_status_code status;
100
101  printk( "FBSKYEYE -- driver initializing..\n" );
102  /*
103   * Register the device
104   */
105  status = rtems_io_register_name (FRAMEBUFFER_DEVICE_0_NAME, major, 0);
106  if (status != RTEMS_SUCCESSFUL)
107    {
108      printk("Error registering FBSKYEYE device!\n");
109      rtems_fatal_error_occurred( status );
110    }
111  return RTEMS_SUCCESSFUL;
112}
113
114
115rtems_device_driver
116frame_buffer_open( rtems_device_major_number major,
117               rtems_device_minor_number minor,
118               void                      *arg)
119{
120  if (pthread_mutex_trylock(&mutex)== 0){
121      /* restore previous state.  for VGA this means return to text mode.
122       * leave out if graphics hardware has been initialized in
123       * frame_buffer_initialize()
124       */
125     printk( "FBSKYEYE open called.\n" );
126     enable_fbskyeye();
127     return RTEMS_SUCCESSFUL;
128  }
129
130  return RTEMS_UNSATISFIED;
131}
132
133
134rtems_device_driver
135frame_buffer_close(rtems_device_major_number major,
136               rtems_device_minor_number minor,
137               void                      *arg)
138{
139  if (pthread_mutex_unlock(&mutex) == 0){
140    /* restore previous state.  for VGA this means return to text mode.
141     * leave out if graphics hardware has been initialized in
142     * frame_buffer_initialize() */
143    printk( "fbskyeye close called.\n" );
144    disable_fbskyeye();
145    return RTEMS_SUCCESSFUL;
146  }
147
148  return RTEMS_UNSATISFIED;
149}
150
151rtems_device_driver
152frame_buffer_read( rtems_device_major_number major,
153               rtems_device_minor_number minor,
154               void                      *arg)
155{
156  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
157  rw_args->bytes_moved = ((rw_args->offset + rw_args->count) > fb_fix.smem_len ) ? (fb_fix.smem_len - rw_args->offset) : rw_args->count;
158  memcpy(rw_args->buffer, (const void *) (fb_fix.smem_start + rw_args->offset), rw_args->bytes_moved);
159  return RTEMS_SUCCESSFUL;
160}
161
162rtems_device_driver
163frame_buffer_write( rtems_device_major_number major,
164                rtems_device_minor_number minor,
165                void                    * arg)
166{
167  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
168  rw_args->bytes_moved = ((rw_args->offset + rw_args->count) > fb_fix.smem_len ) ? (fb_fix.smem_len - rw_args->offset) : rw_args->count;
169  memcpy( (void *) (fb_fix.smem_start + rw_args->offset), rw_args->buffer, rw_args->bytes_moved);
170  return RTEMS_SUCCESSFUL;
171}
172
173static int get_palette( struct fb_cmap *cmap )
174{
175  uint32_t i;
176
177  if ( cmap->start + cmap->len >= 16 )
178    return 1;
179
180  for( i = 0; i < cmap->len; i++ ) {
181    cmap->red[ cmap->start + i ]   = red16[ cmap->start + i ];
182    cmap->green[ cmap->start + i ] = green16[ cmap->start + i ];
183    cmap->blue[ cmap->start + i ]  = blue16[ cmap->start + i ];
184  }
185  return 0;
186}
187
188static int set_palette( struct fb_cmap *cmap )
189{
190  uint32_t i;
191
192  if ( cmap->start + cmap->len >= 16 )
193    return 1;
194
195  for( i = 0; i < cmap->len; i++ ) {
196    red16[ cmap->start + i ] = cmap->red[ cmap->start + i ];
197    green16[ cmap->start + i ] = cmap->green[ cmap->start + i ];
198    blue16[ cmap->start + i ] = cmap->blue[ cmap->start + i ];
199  }
200  return 0;
201}
202
203
204rtems_device_driver
205frame_buffer_control( rtems_device_major_number major,
206                  rtems_device_minor_number minor,
207                  void                      * arg
208                  )
209{
210  rtems_libio_ioctl_args_t *args = arg;
211  printk(
212    "FBSKYEYE ioctl called, cmd=%" PRIdioctl_command_t "\n",
213    args->command
214  );
215  switch( args->command )
216    {
217    case FBIOGET_FSCREENINFO:
218      args->ioctl_return =  get_fix_screen_info( ( struct fb_fix_screeninfo * ) args->buffer );
219      break;
220    case FBIOGET_VSCREENINFO:
221      args->ioctl_return =  get_var_screen_info( ( struct fb_var_screeninfo * ) args->buffer );
222      break;
223    case FBIOPUT_VSCREENINFO:
224      /* not implemented yet*/
225      args->ioctl_return = -1;
226      return RTEMS_UNSATISFIED;
227    case FBIOGETCMAP:
228      args->ioctl_return =  get_palette( ( struct fb_cmap * ) args->buffer );
229      break;
230    case FBIOPUTCMAP:
231      args->ioctl_return =  set_palette( ( struct fb_cmap * ) args->buffer );
232      break;
233    default:
234      args->ioctl_return = 0;
235      break;
236
237    }
238  return RTEMS_SUCCESSFUL;
239}
Note: See TracBrowser for help on using the repository browser.