2 * linux/drivers/video/console/fbcon_ud.c -- Software Rotation - 90 degrees
4 * Copyright (C) 2005 Antonino Daplas <adaplas @pol.net>
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive for
11 #include <linux/module.h>
12 #include <linux/string.h>
14 #include <linux/vt_kern.h>
15 #include <linux/console.h>
16 #include <asm/types.h>
18 #include "fbcon_rotate.h"
24 static inline void cw_update_attr(u8
*dst
, u8
*src
, int attribute
,
27 int i
, j
, offset
= (vc
->vc_font
.height
< 10) ? 1 : 2;
28 int width
= (vc
->vc_font
.height
+ 7) >> 3;
29 u8 c
, t
= 0, msk
= ~(0xff >> offset
);
31 for (i
= 0; i
< vc
->vc_font
.width
; i
++) {
32 for (j
= 0; j
< width
; j
++) {
34 if (attribute
& FBCON_ATTRIBUTE_UNDERLINE
&& !j
)
36 if (attribute
& FBCON_ATTRIBUTE_BOLD
&& i
)
38 if (attribute
& FBCON_ATTRIBUTE_REVERSE
)
48 static void cw_bmove(struct vc_data
*vc
, struct fb_info
*info
, int sy
,
49 int sx
, int dy
, int dx
, int height
, int width
)
51 struct fbcon_ops
*ops
= info
->fbcon_par
;
52 struct fb_copyarea area
;
53 u32 vxres
= GETVXRES(ops
->p
->scrollmode
, info
);
55 area
.sx
= vxres
- ((sy
+ height
) * vc
->vc_font
.height
);
56 area
.sy
= sx
* vc
->vc_font
.width
;
57 area
.dx
= vxres
- ((dy
+ height
) * vc
->vc_font
.height
);
58 area
.dy
= dx
* vc
->vc_font
.width
;
59 area
.width
= height
* vc
->vc_font
.height
;
60 area
.height
= width
* vc
->vc_font
.width
;
62 info
->fbops
->fb_copyarea(info
, &area
);
65 static void cw_clear(struct vc_data
*vc
, struct fb_info
*info
, int sy
,
66 int sx
, int height
, int width
)
68 struct fbcon_ops
*ops
= info
->fbcon_par
;
69 struct fb_fillrect region
;
70 int bgshift
= (vc
->vc_hi_font_mask
) ? 13 : 12;
71 u32 vxres
= GETVXRES(ops
->p
->scrollmode
, info
);
73 region
.color
= attr_bgcol_ec(bgshift
,vc
);
74 region
.dx
= vxres
- ((sy
+ height
) * vc
->vc_font
.height
);
75 region
.dy
= sx
* vc
->vc_font
.width
;
76 region
.height
= width
* vc
->vc_font
.width
;
77 region
.width
= height
* vc
->vc_font
.height
;
78 region
.rop
= ROP_COPY
;
80 info
->fbops
->fb_fillrect(info
, ®ion
);
83 static inline void cw_putcs_aligned(struct vc_data
*vc
, struct fb_info
*info
,
84 const u16
*s
, u32 attr
, u32 cnt
,
85 u32 d_pitch
, u32 s_pitch
, u32 cellsize
,
86 struct fb_image
*image
, u8
*buf
, u8
*dst
)
88 struct fbcon_ops
*ops
= info
->fbcon_par
;
89 u16 charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
90 u32 idx
= (vc
->vc_font
.height
+ 7) >> 3;
94 src
= ops
->fontbuffer
+ (scr_readw(s
++) & charmask
)*cellsize
;
97 cw_update_attr(buf
, src
, attr
, vc
);
101 if (likely(idx
== 1))
102 __fb_pad_aligned_buffer(dst
, d_pitch
, src
, idx
,
105 fb_pad_aligned_buffer(dst
, d_pitch
, src
, idx
,
108 dst
+= d_pitch
* vc
->vc_font
.width
;
111 info
->fbops
->fb_imageblit(info
, image
);
114 static void cw_putcs(struct vc_data
*vc
, struct fb_info
*info
,
115 const unsigned short *s
, int count
, int yy
, int xx
,
118 struct fb_image image
;
119 struct fbcon_ops
*ops
= info
->fbcon_par
;
120 u32 width
= (vc
->vc_font
.height
+ 7)/8;
121 u32 cellsize
= width
* vc
->vc_font
.width
;
122 u32 maxcnt
= info
->pixmap
.size
/cellsize
;
123 u32 scan_align
= info
->pixmap
.scan_align
- 1;
124 u32 buf_align
= info
->pixmap
.buf_align
- 1;
125 u32 cnt
, pitch
, size
;
126 u32 attribute
= get_attribute(info
, scr_readw(s
));
127 u8
*dst
, *buf
= NULL
;
128 u32 vxres
= GETVXRES(ops
->p
->scrollmode
, info
);
130 if (!ops
->fontbuffer
)
135 image
.dx
= vxres
- ((yy
+ 1) * vc
->vc_font
.height
);
136 image
.dy
= xx
* vc
->vc_font
.width
;
137 image
.width
= vc
->vc_font
.height
;
141 buf
= kmalloc(cellsize
, GFP_KERNEL
);
152 image
.height
= vc
->vc_font
.width
* cnt
;
153 pitch
= ((image
.width
+ 7) >> 3) + scan_align
;
154 pitch
&= ~scan_align
;
155 size
= pitch
* image
.height
+ buf_align
;
157 dst
= fb_get_buffer_offset(info
, &info
->pixmap
, size
);
159 cw_putcs_aligned(vc
, info
, s
, attribute
, cnt
, pitch
,
160 width
, cellsize
, &image
, buf
, dst
);
161 image
.dy
+= image
.height
;
166 /* buf is always NULL except when in monochrome mode, so in this case
167 it's a gain to check buf against NULL even though kfree() handles
168 NULL pointers just fine */
174 static void cw_clear_margins(struct vc_data
*vc
, struct fb_info
*info
,
177 unsigned int cw
= vc
->vc_font
.width
;
178 unsigned int ch
= vc
->vc_font
.height
;
179 unsigned int rw
= info
->var
.yres
- (vc
->vc_cols
*cw
);
180 unsigned int bh
= info
->var
.xres
- (vc
->vc_rows
*ch
);
181 unsigned int rs
= info
->var
.yres
- rw
;
182 struct fb_fillrect region
;
183 int bgshift
= (vc
->vc_hi_font_mask
) ? 13 : 12;
185 region
.color
= attr_bgcol_ec(bgshift
,vc
);
186 region
.rop
= ROP_COPY
;
188 if (rw
&& !bottom_only
) {
190 region
.dy
= info
->var
.yoffset
+ rs
;
192 region
.width
= info
->var
.xres_virtual
;
193 info
->fbops
->fb_fillrect(info
, ®ion
);
197 region
.dx
= info
->var
.xoffset
;
198 region
.dy
= info
->var
.yoffset
;
199 region
.height
= info
->var
.yres
;
201 info
->fbops
->fb_fillrect(info
, ®ion
);
205 static void cw_cursor(struct vc_data
*vc
, struct fb_info
*info
, int mode
,
206 int softback_lines
, int fg
, int bg
)
208 struct fb_cursor cursor
;
209 struct fbcon_ops
*ops
= info
->fbcon_par
;
210 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
211 int w
= (vc
->vc_font
.height
+ 7) >> 3, c
;
212 int y
= real_y(ops
->p
, vc
->vc_y
);
213 int attribute
, use_sw
= (vc
->vc_cursor_type
& 0x10);
216 u32 vxres
= GETVXRES(ops
->p
->scrollmode
, info
);
218 if (!ops
->fontbuffer
)
223 if (softback_lines
) {
224 if (y
+ softback_lines
>= vc
->vc_rows
) {
226 ops
->cursor_flash
= 0;
232 c
= scr_readw((u16
*) vc
->vc_pos
);
233 attribute
= get_attribute(info
, c
);
234 src
= ops
->fontbuffer
+ ((c
& charmask
) * (w
* vc
->vc_font
.width
));
236 if (ops
->cursor_state
.image
.data
!= src
||
238 ops
->cursor_state
.image
.data
= src
;
239 cursor
.set
|= FB_CUR_SETIMAGE
;
245 dst
= kmalloc(w
* vc
->vc_font
.width
, GFP_ATOMIC
);
248 kfree(ops
->cursor_data
);
249 ops
->cursor_data
= dst
;
250 cw_update_attr(dst
, src
, attribute
, vc
);
254 if (ops
->cursor_state
.image
.fg_color
!= fg
||
255 ops
->cursor_state
.image
.bg_color
!= bg
||
257 ops
->cursor_state
.image
.fg_color
= fg
;
258 ops
->cursor_state
.image
.bg_color
= bg
;
259 cursor
.set
|= FB_CUR_SETCMAP
;
262 if (ops
->cursor_state
.image
.height
!= vc
->vc_font
.width
||
263 ops
->cursor_state
.image
.width
!= vc
->vc_font
.height
||
265 ops
->cursor_state
.image
.height
= vc
->vc_font
.width
;
266 ops
->cursor_state
.image
.width
= vc
->vc_font
.height
;
267 cursor
.set
|= FB_CUR_SETSIZE
;
270 dx
= vxres
- ((y
* vc
->vc_font
.height
) + vc
->vc_font
.height
);
271 dy
= vc
->vc_x
* vc
->vc_font
.width
;
273 if (ops
->cursor_state
.image
.dx
!= dx
||
274 ops
->cursor_state
.image
.dy
!= dy
||
276 ops
->cursor_state
.image
.dx
= dx
;
277 ops
->cursor_state
.image
.dy
= dy
;
278 cursor
.set
|= FB_CUR_SETPOS
;
281 if (ops
->cursor_state
.hot
.x
|| ops
->cursor_state
.hot
.y
||
283 ops
->cursor_state
.hot
.x
= cursor
.hot
.y
= 0;
284 cursor
.set
|= FB_CUR_SETHOT
;
287 if (cursor
.set
& FB_CUR_SETSIZE
||
288 vc
->vc_cursor_type
!= ops
->p
->cursor_shape
||
289 ops
->cursor_state
.mask
== NULL
||
291 char *tmp
, *mask
= kmalloc(w
*vc
->vc_font
.width
, GFP_ATOMIC
);
292 int cur_height
, size
, i
= 0;
293 int width
= (vc
->vc_font
.width
+ 7)/8;
298 tmp
= kmalloc(width
* vc
->vc_font
.height
, GFP_ATOMIC
);
305 kfree(ops
->cursor_state
.mask
);
306 ops
->cursor_state
.mask
= mask
;
308 ops
->p
->cursor_shape
= vc
->vc_cursor_type
;
309 cursor
.set
|= FB_CUR_SETSHAPE
;
311 switch (ops
->p
->cursor_shape
& CUR_HWMASK
) {
316 cur_height
= (vc
->vc_font
.height
< 10) ? 1 : 2;
318 case CUR_LOWER_THIRD
:
319 cur_height
= vc
->vc_font
.height
/3;
322 cur_height
= vc
->vc_font
.height
>> 1;
325 cur_height
= (vc
->vc_font
.height
<< 1)/3;
329 cur_height
= vc
->vc_font
.height
;
333 size
= (vc
->vc_font
.height
- cur_height
) * width
;
336 size
= cur_height
* width
;
339 memset(mask
, 0, w
* vc
->vc_font
.width
);
340 rotate_cw(tmp
, mask
, vc
->vc_font
.width
, vc
->vc_font
.height
);
346 ops
->cursor_state
.enable
= 0;
351 ops
->cursor_state
.enable
= (use_sw
) ? 0 : 1;
355 cursor
.image
.data
= src
;
356 cursor
.image
.fg_color
= ops
->cursor_state
.image
.fg_color
;
357 cursor
.image
.bg_color
= ops
->cursor_state
.image
.bg_color
;
358 cursor
.image
.dx
= ops
->cursor_state
.image
.dx
;
359 cursor
.image
.dy
= ops
->cursor_state
.image
.dy
;
360 cursor
.image
.height
= ops
->cursor_state
.image
.height
;
361 cursor
.image
.width
= ops
->cursor_state
.image
.width
;
362 cursor
.hot
.x
= ops
->cursor_state
.hot
.x
;
363 cursor
.hot
.y
= ops
->cursor_state
.hot
.y
;
364 cursor
.mask
= ops
->cursor_state
.mask
;
365 cursor
.enable
= ops
->cursor_state
.enable
;
366 cursor
.image
.depth
= 1;
367 cursor
.rop
= ROP_XOR
;
369 if (info
->fbops
->fb_cursor
)
370 err
= info
->fbops
->fb_cursor(info
, &cursor
);
373 soft_cursor(info
, &cursor
);
375 ops
->cursor_reset
= 0;
378 static int cw_update_start(struct fb_info
*info
)
380 struct fbcon_ops
*ops
= info
->fbcon_par
;
381 u32 vxres
= GETVXRES(ops
->p
->scrollmode
, info
);
385 xoffset
= vxres
- (info
->var
.xres
+ ops
->var
.yoffset
);
386 ops
->var
.yoffset
= ops
->var
.xoffset
;
387 ops
->var
.xoffset
= xoffset
;
388 err
= fb_pan_display(info
, &ops
->var
);
389 ops
->var
.xoffset
= info
->var
.xoffset
;
390 ops
->var
.yoffset
= info
->var
.yoffset
;
391 ops
->var
.vmode
= info
->var
.vmode
;
395 void fbcon_rotate_cw(struct fbcon_ops
*ops
)
397 ops
->bmove
= cw_bmove
;
398 ops
->clear
= cw_clear
;
399 ops
->putcs
= cw_putcs
;
400 ops
->clear_margins
= cw_clear_margins
;
401 ops
->cursor
= cw_cursor
;
402 ops
->update_start
= cw_update_start
;
404 EXPORT_SYMBOL(fbcon_rotate_cw
);
406 MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
407 MODULE_DESCRIPTION("Console Rotation (90 degrees) Support");
408 MODULE_LICENSE("GPL");