1 #include <linux/kernel.h>
2 #include <linux/errno.h>
3 #include <linux/string.h>
6 #include <linux/malloc.h>
7 #include <linux/delay.h>
8 #include <linux/interrupt.h>
10 #include <asm/uaccess.h>
11 #include <asm/setup.h>
12 #include <asm/segment.h>
13 #include <asm/system.h>
14 /*#include <asm/irq.h>*/
15 #include <asm/q40_master.h>
17 #include <linux/module.h>
18 #include <asm/pgtable.h>
20 #include <video/fbcon.h>
21 #include <video/fbcon-cfb16.h>
23 #define FBIOSETSCROLLMODE 0x4611
25 #define Q40_PHYS_SCREEN_ADDR 0xFE800000
26 static unsigned long q40_screen_addr
;
28 static u16 fbcon_cmap_cfb16
[16];
30 /* frame buffer operations */
32 static int q40fb_get_fix(struct fb_fix_screeninfo
*fix
, int con
,
33 struct fb_info
*info
);
34 static int q40fb_get_var(struct fb_var_screeninfo
*var
, int con
,
35 struct fb_info
*info
);
36 static int q40fb_set_var(struct fb_var_screeninfo
*var
, int con
,
37 struct fb_info
*info
);
38 static int q40fb_get_cmap(struct fb_cmap
*cmap
,int kspc
,int con
,
39 struct fb_info
*info
);
40 static int q40fb_set_cmap(struct fb_cmap
*cmap
,int kspc
,int con
,
41 struct fb_info
*info
);
42 static int q40fb_ioctl(struct inode
*inode
, struct file
*file
,
43 unsigned int cmd
, unsigned long arg
, int con
,
44 struct fb_info
*info
);
46 static int q40con_switch(int con
, struct fb_info
*info
);
47 static int q40con_updatevar(int con
, struct fb_info
*info
);
48 static void q40con_blank(int blank
, struct fb_info
*info
);
50 static void q40fb_set_disp(int con
, struct fb_info
*info
);
52 static struct display disp
[MAX_NR_CONSOLES
];
53 static struct fb_info fb_info
;
54 static struct fb_ops q40fb_ops
= {
56 fb_get_fix
: q40fb_get_fix
,
57 fb_get_var
: q40fb_get_var
,
58 fb_set_var
: q40fb_set_var
,
59 fb_get_cmap
: q40fb_get_cmap
,
60 fb_set_cmap
: q40fb_set_cmap
,
61 fb_ioctl
: q40fb_ioctl
,
66 static char q40fb_name
[]="Q40";
68 static int q40fb_get_fix(struct fb_fix_screeninfo
*fix
, int con
,
71 memset(fix
, 0, sizeof(struct fb_fix_screeninfo
));
73 strcpy(fix
->id
,"Q40");
74 fix
->smem_start
=q40_screen_addr
;
75 fix
->smem_len
=1024*1024;
76 fix
->type
=FB_TYPE_PACKED_PIXELS
;
78 fix
->visual
=FB_VISUAL_TRUECOLOR
; /* good approximation so far ..*/;
82 fix
->line_length
=1024*2;
84 /* no mmio,accel ...*/
90 static int q40fb_get_var(struct fb_var_screeninfo
*var
, int con
,
93 memset(var
, 0, sizeof(struct fb_var_screeninfo
));
97 var
->xres_virtual
=1024;
98 var
->yres_virtual
=512;
101 var
->bits_per_pixel
=16;
104 var
->activate
=FB_ACTIVATE_NOW
;
105 var
->height
=230; /* approx for my 17" monitor, more important */
106 var
->width
=300; /* than the absolute values is the unusual aspect ratio*/
108 var
->red
.offset
=6; /*6*/
110 var
->green
.offset
=11; /*11*/
114 var
->transp
.length
=0;
122 var
->vmode
=FB_VMODE_NONINTERLACED
;
128 static int q40fb_set_var(struct fb_var_screeninfo
*var
, int con
,
129 struct fb_info
*info
)
135 if(var
->xres_virtual
!=1024)
137 if(var
->yres_virtual
!=512)
143 if(var
->bits_per_pixel
!=16)
145 if(var
->grayscale
!=0)
149 if(var
->activate
!=FB_ACTIVATE_NOW
)
153 if(var
->left_margin
!=0)
155 if(var
->right_margin
!=0)
157 if(var
->hsync_len
!=0)
159 if(var
->vsync_len
!=0)
163 if(var
->vmode
!=FB_VMODE_NONINTERLACED
)
170 static int q40_getcolreg(unsigned regno
, unsigned *red
, unsigned *green
,
171 unsigned *blue
, unsigned *transp
,
172 struct fb_info
*info
)
175 * Read a single color register and split it into colors/transparent.
176 * The return values must have a 16 bit magnitude.
177 * Return != 0 for invalid regno.
179 if (regno
>=16) return 1;
182 *green
= ((fbcon_cmap_cfb16
[regno
]>>11) & 31)<<11;
183 *red
= ((fbcon_cmap_cfb16
[regno
]>>6) & 31)<<11;
184 *blue
= ((fbcon_cmap_cfb16
[regno
]) & 63)<<10;
189 static int q40_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
190 unsigned blue
, unsigned transp
,
191 const struct fb_info
*info
)
194 * Set a single color register. The values supplied have a 16 bit
196 * Return != 0 for invalid regno.
204 fbcon_cmap_cfb16
[regno
] = ((red
& 31) <<6) |
205 ((green
& 31) << 11) |
211 static int q40fb_get_cmap(struct fb_cmap
*cmap
, int kspc
, int con
,
212 struct fb_info
*info
)
215 if (con
== currcon
) /* current console? */
216 return fb_get_cmap(cmap
, kspc
, q40_getcolreg
, info
);
217 else if (fb_display
[con
].cmap
.len
) /* non default colormap? */
218 fb_copy_cmap(&fb_display
[con
].cmap
, cmap
, kspc
? 0 : 2);
220 fb_copy_cmap(fb_default_cmap(1<<fb_display
[con
].var
.bits_per_pixel
),
224 printk(KERN_ERR
"get cmap not supported\n");
230 static int q40fb_set_cmap(struct fb_cmap
*cmap
, int kspc
, int con
,
231 struct fb_info
*info
)
236 if (!fb_display
[con
].cmap
.len
) { /* no colormap allocated? */
237 if ((err
= fb_alloc_cmap(&fb_display
[con
].cmap
,
238 1<<fb_display
[con
].var
.bits_per_pixel
,
242 if (con
== currcon
) /* current console? */
243 return fb_set_cmap(cmap
, kspc
, q40_setcolreg
, info
);
245 fb_copy_cmap(cmap
, &fb_display
[con
].cmap
, kspc
? 0 : 1);
248 printk(KERN_ERR
"set cmap not supported\n");
254 static int q40fb_ioctl(struct inode
*inode
, struct file
*file
,
255 unsigned int cmd
, unsigned long arg
, int con
,
256 struct fb_info
*info
)
260 struct display
*display
;
263 display
= &fb_display
[con
];
267 if (cmd
== FBIOSETSCROLLMODE
)
269 i
= verify_area(VERIFY_READ
, (void *)arg
, sizeof(unsigned long));
272 copy_from_user(&i
, (void *)arg
, sizeof(unsigned long));
273 display
->scrollmode
= i
;
275 q40_updatescrollmode(display
);
282 static void q40fb_set_disp(int con
, struct fb_info
*info
)
284 struct fb_fix_screeninfo fix
;
285 struct display
*display
;
287 q40fb_get_fix(&fix
, con
, info
);
290 display
= &fb_display
[con
];
296 display
->screen_base
= fix
.smem_start
;
297 display
->visual
= fix
.visual
;
298 display
->type
= fix
.type
;
299 display
->type_aux
= fix
.type_aux
;
300 display
->ypanstep
= fix
.ypanstep
;
301 display
->ywrapstep
= fix
.ywrapstep
;
302 display
->can_soft_blank
= 0;
303 display
->inverse
= 0;
304 display
->line_length
= fix
.line_length
;
306 display
->scrollmode
= SCROLL_YREDRAW
;
308 #ifdef FBCON_HAS_CFB16
309 display
->dispsw
= &fbcon_cfb16
;
310 disp
->dispsw_data
= fbcon_cmap_cfb16
;
312 display
->dispsw
= &fbcon_dummy
;
322 q40_screen_addr
= kernel_map(Q40_PHYS_SCREEN_ADDR
, 1024*1024,
323 KERNELMAP_NO_COPYBACK
, NULL
);
325 q40_screen_addr
= Q40_PHYS_SCREEN_ADDR
; /* mapped in q40/config.c */
328 fb_info
.changevar
=NULL
;
329 strcpy(&fb_info
.modename
[0],q40fb_name
);
330 fb_info
.fontname
[0]=0;
332 fb_info
.switch_con
=&q40con_switch
;
333 fb_info
.updatevar
=&q40con_updatevar
;
334 fb_info
.blank
=&q40con_blank
;
336 fb_info
.fbops
= &q40fb_ops
;
337 fb_info
.flags
= FBINFO_FLAG_DEFAULT
; /* not as module for now */
339 master_outb(3,DISPLAY_CONTROL_REG
);
341 q40fb_get_var(&disp
[0].var
, 0, &fb_info
);
342 q40fb_set_disp(-1, &fb_info
);
344 if (register_framebuffer(&fb_info
) < 0) {
345 printk(KERN_ERR
"unable to register Q40 frame buffer\n");
349 printk(KERN_INFO
"fb%d: Q40 frame buffer alive and kicking !\n",
350 GET_FB_IDX(fb_info
.node
));
355 static int q40con_switch(int con
, struct fb_info
*info
)
363 static int q40con_updatevar(int con
, struct fb_info
*info
)
368 static void q40con_blank(int blank
, struct fb_info
*info
)