vo_glamo: sub.h was moved to sub directory in c9026cb3210205b07e2e068467a18ee40f9259a3
[mplayer/glamo.git] / drivers / libglamo / os.c
blobaf0bfc993c4fdc00c339d9d4ac93faa2220242d9
1 /*
2 * Library's linux interface.
3 * Currently FIC GTA02 specific.
5 * Copyright (C) 2007 OpenMoko, Inc.
6 * Author: Chia-I Wu <olv@openmoko.org>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 or
11 * (at your option) version 3 of the License.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <sys/mman.h>
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 #include <sys/ioctl.h>
30 #include <unistd.h>
31 #include <fcntl.h>
32 #include <linux/fb.h>
33 #include <errno.h>
35 #include "hw.h"
37 #define FB_SIZE 0x800000
39 static int fd_mem;
40 static int fd_fb;
41 static struct fb_fix_screeninfo fix;
43 volatile unsigned char *glamo_fb;
44 volatile unsigned char *glamo_mmio;
45 int glamo_pitch;
47 #ifndef FB_ACCEL_GLAMO
48 # define FB_ACCEL_GLAMO 50 /* SMedia Glamo */
49 #endif
51 int glamo_os_init(const char *fb_path)
53 if (!fb_path || !*fb_path)
54 fb_path = "/dev/fb0";
56 fd_fb = open(fb_path, O_RDWR | O_SYNC);
57 if (fd_fb < 0)
59 printf("error opening %s: %s\n", fb_path, strerror(errno));
60 return -errno;
63 if (ioctl(fd_fb, FBIOGET_FSCREENINFO, &fix) < 0)
65 printf("error in FBIOGET_FSCREENINFO: %s\n", strerror(errno));
67 close(fd_fb);
68 return -errno;
71 if (fix.accel != FB_ACCEL_GLAMO) {
72 printf("No Glamo chip found or the kerne is old.\n");
73 /* TODO: Bail out, once the FB_ACCEL_GLAMO #define goes
74 * into the kernel. */
77 /* hard-coded */
78 fix.smem_len = FB_SIZE;
79 glamo_pitch = fix.line_length;
81 fd_mem = open("/dev/mem", O_RDWR | O_SYNC);
82 if (fd_mem < 0)
84 printf("error opening mem: %s\n", strerror(errno));
86 close(fd_fb);
87 return -errno;
90 /* TODO: use map_phys_mem and unmap_phys_mem */
91 glamo_fb = mmap(NULL, fix.smem_len, PROT_READ | PROT_WRITE,
92 MAP_SHARED, fd_mem, fix.smem_start);
93 if (glamo_fb == MAP_FAILED)
95 printf("error mmap'ping fb: %s\n", strerror(errno));
97 munmap((void *) glamo_fb, fix.smem_len);
98 close(fd_mem);
99 close(fd_fb);
100 return -errno;
103 /* TODO: use map_phys_mem and unmap_phys_mem */
104 glamo_mmio = mmap(NULL, GLAMO_MMIO_SIZE, PROT_READ | PROT_WRITE,
105 MAP_SHARED, fd_mem, GLAMO_MMIO_BASE);
106 if (glamo_mmio == MAP_FAILED)
108 printf("error mmap'ping mmio: %s\n", strerror(errno));
110 munmap((void *) glamo_fb, fix.smem_len);
111 close(fd_mem);
112 close(fd_fb);
113 return -errno;
116 #if 0
117 printf("fb 0x%08lx (0x%x)\n"
118 "mmio 0x%08x (0x%x)\n",
119 fix.smem_start, fix.smem_len,
120 GLAMO_MMIO_BASE, GLAMO_MMIO_SIZE);
121 #endif
122 return 0;
125 void glamo_os_finish(void)
127 munmap((void *) glamo_mmio, GLAMO_MMIO_SIZE);
128 munmap((void *) glamo_fb, fix.smem_len);
130 close(fd_fb);
131 close(fd_mem);