ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / video / maxinefb.c
1 /*
2  *      linux/drivers/video/maxinefb.c
3  *
4  *      DECstation 5000/xx onboard framebuffer support ... derived from:
5  *      "HP300 Topcat framebuffer support (derived from macfb of all things)
6  *      Phil Blundell <philb@gnu.org> 1998", the original code can be
7  *      found in the file hpfb.c in the same directory.
8  *
9  *      DECstation related code Copyright (C) 1999,2000,2001 by
10  *      Michael Engel <engel@unix-ag.org> and
11  *      Karsten Merker <merker@linuxtag.org>.
12  *      This file is subject to the terms and conditions of the GNU General
13  *      Public License.  See the file COPYING in the main directory of this
14  *      archive for more details.
15  *
16  */
17
18 /*
19  * Changes:
20  * 2001/01/27 removed debugging and testing code, fixed fb_ops
21  *            initialization which had caused a crash before,
22  *            general cleanup, first official release (KM)
23  *
24  */
25
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/sched.h>
29 #include <linux/errno.h>
30 #include <linux/string.h>
31 #include <linux/mm.h>
32 #include <linux/tty.h>
33 #include <linux/slab.h>
34 #include <linux/delay.h>
35 #include <linux/init.h>
36 #include <linux/fb.h>
37 #include <video/maxinefb.h>
38
39 /* bootinfo.h defines the machine type values, needed when checking */
40 /* whether are really running on a maxine, KM                       */
41 #include <asm/bootinfo.h>
42
43 static struct fb_info fb_info;
44
45 static struct fb_var_screeninfo maxinefb_defined = {
46         .xres           = 1024,
47         .yres           = 768,
48         .xres_virtual   = 1024,
49         .yres_virtual   = 768,
50         .bits_per_pixel = 8,
51         .red.length     = 8,
52         .green.length   = 8,
53         .blue.length    = 8,
54         .activate       = FB_ACTIVATE_NOW,
55         .height         = -1,
56         .width          = -1,
57         .vmode          = FB_VMODE_NONINTERLACED,
58 };
59
60 static struct fb_fix_screeninfo maxinefb_fix = {
61         .id             = "Maxine onboard graphics 1024x768x8",
62         .smem_len       = (1024*768),
63         .type           = FB_TYPE_PACKED_PIXELS,
64         .visual         = FB_VISUAL_PSEUDOCOLOR,
65         .line_length    = 1024,
66 };
67
68 /* Reference to machine type set in arch/mips/dec/prom/identify.c, KM */
69 extern unsigned long mips_machtype;
70
71 /* Handle the funny Inmos RamDAC/video controller ... */
72
73 void maxinefb_ims332_write_register(int regno, register unsigned int val)
74 {
75         register unsigned char *regs = (char *) MAXINEFB_IMS332_ADDRESS;
76         unsigned char *wptr;
77
78         wptr = regs + 0xa0000 + (regno << 4);
79         *((volatile unsigned int *) (regs)) = (val >> 8) & 0xff00;
80         *((volatile unsigned short *) (wptr)) = val;
81 }
82
83 unsigned int maxinefb_ims332_read_register(int regno)
84 {
85         register unsigned char *regs = (char *) MAXINEFB_IMS332_ADDRESS;
86         unsigned char *rptr;
87         register unsigned int j, k;
88
89         rptr = regs + 0x80000 + (regno << 4);
90         j = *((volatile unsigned short *) rptr);
91         k = *((volatile unsigned short *) regs);
92
93         return (j & 0xffff) | ((k & 0xff00) << 8);
94 }
95
96 /* Set the palette */
97 static int maxinefb_setcolreg(unsigned regno, unsigned red, unsigned green,
98                               unsigned blue, unsigned transp, struct fb_info *info)
99 {
100         /* value to be written into the palette reg. */
101         unsigned long hw_colorvalue = 0;
102
103         red   >>= 8;    /* The cmap fields are 16 bits    */
104         green >>= 8;    /* wide, but the harware colormap */
105         blue  >>= 8;    /* registers are only 8 bits wide */
106
107         hw_colorvalue = (blue << 16) + (green << 8) + (red);
108         
109         maxinefb_ims332_write_register(IMS332_REG_COLOR_PALETTE + regno,
110                                        hw_colorvalue);
111         return 0;
112 }
113
114 static struct fb_ops maxinefb_ops = {
115         .owner          = THIS_MODULE,
116         .fb_setcolreg   = maxinefb_setcolreg,   
117         .fb_fillrect    = cfb_fillrect,
118         .fb_copyarea    = cfb_copyarea,
119         .fb_imageblit   = cfb_imageblit,                
120         .fb_cursor      = soft_cursor,
121 };
122
123 int __init maxinefb_init(void)
124 {
125         volatile unsigned char *fboff;
126         unsigned long fb_start;
127         int i;
128
129         /* Validate we're on the proper machine type */
130         if (mips_machtype != MACH_DS5000_XX) {
131                 return -EINVAL;
132         }
133
134         printk(KERN_INFO "Maxinefb: Personal DECstation detected\n");
135         printk(KERN_INFO "Maxinefb: initializing onboard framebuffer\n");
136
137         /* Framebuffer display memory base address */
138         fb_start = DS5000_xx_ONBOARD_FBMEM_START;
139
140         /* Clear screen */
141         for (fboff = fb_start; fboff < fb_start + 0x1ffff; fboff++)
142                 *fboff = 0x0;
143
144         maxinefb_fix.smem_start = fb_start;
145         
146         /* erase hardware cursor */
147         for (i = 0; i < 512; i++) {
148                 maxinefb_ims332_write_register(IMS332_REG_CURSOR_RAM + i,
149                                                0);
150                 /*
151                    if (i&0x8 == 0)
152                    maxinefb_ims332_write_register (IMS332_REG_CURSOR_RAM + i, 0x0f);
153                    else
154                    maxinefb_ims332_write_register (IMS332_REG_CURSOR_RAM + i, 0xf0);
155                  */
156         }
157
158         fb_info.fbops = &maxinefb_ops;
159         fb_info.screen_base = (char *) maxinefb_fix.smem_start;
160         fb_info.var = maxinefb_defined;
161         fb_info.fix = maxinefb_fix;
162         fb_info.flags = FBINFO_FLAG_DEFAULT;
163
164         fb_alloc_cmap(&fb_info.cmap, 256, 0);
165
166         if (register_framebuffer(&fb_info) < 0)
167                 return 1;
168         return 0;
169 }
170
171 static void __exit maxinefb_exit(void)
172 {
173         unregister_framebuffer(&fb_info);
174 }
175
176 #ifdef MODULE
177 MODULE_LICENSE("GPL");
178 module_init(maxinefb_init);
179 #endif
180 module_exit(maxinefb_exit);
181