Fix non-integer display_zoom for charcell.
[maemo-rb.git] / firmware / target / hosted / ypr0 / lcd-ypr0.c
blob40528c298aff5d4e517693a82e43fde37e9da1fa
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: lcd-bitmap.c 29248 2011-02-08 20:05:25Z thomasjfox $
10 * Copyright (C) 2011 Lorenzo Miori, Thomas Martitz
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <stdio.h>
25 #include "string.h"
26 #include <linux/fb.h>
27 #include <sys/mman.h>
28 #include <sys/ioctl.h>
30 #include "file.h"
31 #include "debug.h"
32 #include "system.h"
33 #include "screendump.h"
34 #include "lcd.h"
36 static int dev_fd = 0;
37 fb_data *dev_fb = 0;
39 void lcd_shutdown(void)
41 printf("FB closed.");
42 munmap(dev_fb, FRAMEBUFFER_SIZE);
43 close(dev_fd);
46 void lcd_init_device(void)
48 size_t screensize;
49 struct fb_var_screeninfo vinfo;
50 struct fb_fix_screeninfo finfo;
52 /* Open the framebuffer device */
53 dev_fd = open("/dev/fb0", O_RDWR);
54 if (dev_fd == -1) {
55 perror("Error: cannot open framebuffer device");
56 exit(1);
58 printf("The framebuffer device was opened successfully.\n");
60 /* Get the fixed properties */
61 if (ioctl(dev_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
62 perror("Error reading fixed information");
63 exit(2);
66 /* Now we get the settable settings, and we set 16 bit bpp */
67 if (ioctl(dev_fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
68 perror("Error reading variable information");
69 exit(3);
72 vinfo.bits_per_pixel = 16;
74 if (ioctl(dev_fd, FBIOPUT_VSCREENINFO, &vinfo)) {
75 perror("fbset(ioctl)");
76 exit(4);
79 printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
81 /* Figure out the size of the screen in bytes */
82 screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
83 if (screensize != FRAMEBUFFER_SIZE)
85 exit(4);
86 perror("Display and framebuffer mismatch!\n");
89 /* Map the device to memory */
90 dev_fb = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, dev_fd, 0);
91 if ((int)dev_fb == -1) {
92 perror("Error: failed to map framebuffer device to memory");
93 exit(4);
95 printf("The framebuffer device was mapped to memory successfully.\n");