ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / video / q40fb.c
1 /* 
2  * linux/drivers/video/q40fb.c -- Q40 frame buffer device
3  *
4  * Copyright (C) 2001 
5  *
6  *      Richard Zidlicky <Richard.Zidlicky@stud.informatik.uni-erlangen.de>
7  *
8  *  This file is subject to the terms and conditions of the GNU General Public
9  *  License. See the file COPYING in the main directory of this archive for
10  *  more details.
11  */
12
13 #include <linux/kernel.h>
14 #include <linux/errno.h>
15 #include <linux/string.h>
16 #include <linux/mm.h>
17 #include <linux/tty.h>
18 #include <linux/slab.h>
19 #include <linux/delay.h>
20 #include <linux/interrupt.h>
21
22 #include <asm/uaccess.h>
23 #include <asm/setup.h>
24 #include <asm/segment.h>
25 #include <asm/system.h>
26 #include <asm/q40_master.h>
27 #include <linux/fb.h>
28 #include <linux/module.h>
29 #include <asm/pgtable.h>
30
31 #define Q40_PHYS_SCREEN_ADDR 0xFE800000
32
33 static u32 pseudo_palette[17];
34 static struct fb_info fb_info;
35
36 static struct fb_fix_screeninfo q40fb_fix __initdata = {
37         .id             = "Q40",
38         .smem_len       = 1024*1024,
39         .type           = FB_TYPE_PACKED_PIXELS,
40         .visual         = FB_VISUAL_TRUECOLOR,
41         .line_length    = 1024*2,
42         .accel          = FB_ACCEL_NONE,
43 };
44
45 static struct fb_var_screeninfo q40fb_var __initdata = {
46         .xres           = 1024,
47         .yres           = 512,
48         .xres_virtual   = 1024,
49         .yres_virtual   = 512,
50         .bits_per_pixel = 16,
51         .red            = {6, 5, 0}, 
52         .green          = {11, 5, 0},
53         .blue           = {0, 6, 0},
54         .activate       = FB_ACTIVATE_NOW,
55         .height         = 230,
56         .width          = 300,
57         .vmode          = FB_VMODE_NONINTERLACED,
58 };
59
60 /* frame buffer operations */
61 int q40fb_init(void);
62
63 static int q40fb_setcolreg(unsigned regno, unsigned red, unsigned green,
64                            unsigned blue, unsigned transp,
65                            struct fb_info *info);
66
67 static struct fb_ops q40fb_ops = {
68         .owner          = THIS_MODULE,
69         .fb_setcolreg   = q40fb_setcolreg,
70         .fb_fillrect    = cfb_fillrect,
71         .fb_copyarea    = cfb_copyarea,
72         .fb_imageblit   = cfb_imageblit,
73         .fb_cursor      = soft_cursor,
74 };
75
76 static int q40fb_setcolreg(unsigned regno, unsigned red, unsigned green,
77                            unsigned blue, unsigned transp,
78                            struct fb_info *info)
79 {
80     /*
81      *  Set a single color register. The values supplied have a 16 bit
82      *  magnitude.
83      *  Return != 0 for invalid regno.
84      */
85   
86     red>>=11;
87     green>>=11;
88     blue>>=10;
89
90     if (regno < 16) {
91         ((u16 *)info->pseudo_palette)[regno] = ((red & 31) <<6) |
92                                                ((green & 31) << 11) |
93                                                (blue & 63);
94     }
95     return 0;
96 }
97
98 int q40fb_init(void)
99 {
100         if ( !MACH_IS_Q40)
101           return -ENXIO;
102
103         /* mapped in q40/config.c */
104         q40fb_fix.smem_start = Q40_PHYS_SCREEN_ADDR;
105         
106         fb_info.var = q40fb_var;
107         fb_info.fix = q40fb_fix;
108         fb_info.fbops = &q40fb_ops;
109         fb_info.flags = FBINFO_FLAG_DEFAULT;  /* not as module for now */
110         fb_info.pseudo_palette = pseudo_palette;        
111         fb_info.screen_base = (char *) q40fb_fix.smem_start;
112
113         fb_alloc_cmap(&fb_info.cmap, 16, 0);
114
115         master_outb(3, DISPLAY_CONTROL_REG);
116
117         if (register_framebuffer(&fb_info) < 0) {
118                 printk(KERN_ERR "Unable to register Q40 frame buffer\n");
119                 return -EINVAL;
120         }
121
122         printk(KERN_INFO "fb%d: Q40 frame buffer alive and kicking !\n",
123                fb_info.node);
124         return 0;
125 }
126
127 MODULE_LICENSE("GPL");