blob: 6d92b845620629fbfe7b9353b449ac741fa7b420 [file] [log] [blame]
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -08001/*
2 * linux/drivers/video/console/fbcon_ud.c -- Software Rotation - 90 degrees
3 *
4 * Copyright (C) 2005 Antonino Daplas <adaplas @pol.net>
5 *
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
8 * more details.
9 */
10
11#include <linux/config.h>
12#include <linux/module.h>
13#include <linux/string.h>
14#include <linux/fb.h>
15#include <linux/vt_kern.h>
16#include <linux/console.h>
17#include <asm/types.h>
18#include "fbcon.h"
19#include "fbcon_rotate.h"
20
21/*
22 * Rotation 90 degrees
23 */
24
25static inline void cw_update_attr(u8 *dst, u8 *src, int attribute,
26 struct vc_data *vc)
27{
28 int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2;
29 int width = (vc->vc_font.height + 7) >> 3;
30 u8 c, t = 0, msk = ~(0xff >> offset);
31
32 for (i = 0; i < vc->vc_font.width; i++) {
33 for (j = 0; j < width; j++) {
34 c = *src;
35 if (attribute & FBCON_ATTRIBUTE_UNDERLINE && !j)
36 c |= msk;
37 if (attribute & FBCON_ATTRIBUTE_BOLD && i)
38 c |= *(src-width);
39 if (attribute & FBCON_ATTRIBUTE_REVERSE)
40 c = ~c;
41 src++;
42 *dst++ = c;
43 t = c;
44 }
45 }
46}
47
48
49static void cw_bmove(struct vc_data *vc, struct fb_info *info, int sy,
50 int sx, int dy, int dx, int height, int width)
51{
Antonino A. Daplasab767202005-11-13 16:06:32 -080052 struct fbcon_ops *ops = info->fbcon_par;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -080053 struct fb_copyarea area;
Antonino A. Daplasab767202005-11-13 16:06:32 -080054 u32 vxres = GETVXRES(ops->p->scrollmode, info);
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -080055
56 area.sx = vxres - ((sy + height) * vc->vc_font.height);
57 area.sy = sx * vc->vc_font.width;
58 area.dx = vxres - ((dy + height) * vc->vc_font.height);
59 area.dy = dx * vc->vc_font.width;
60 area.width = height * vc->vc_font.height;
61 area.height = width * vc->vc_font.width;
62
63 info->fbops->fb_copyarea(info, &area);
64}
65
66static void cw_clear(struct vc_data *vc, struct fb_info *info, int sy,
67 int sx, int height, int width)
68{
Antonino A. Daplasab767202005-11-13 16:06:32 -080069 struct fbcon_ops *ops = info->fbcon_par;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -080070 struct fb_fillrect region;
71 int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
Antonino A. Daplasab767202005-11-13 16:06:32 -080072 u32 vxres = GETVXRES(ops->p->scrollmode, info);
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -080073
74 region.color = attr_bgcol_ec(bgshift,vc);
75 region.dx = vxres - ((sy + height) * vc->vc_font.height);
76 region.dy = sx * vc->vc_font.width;
77 region.height = width * vc->vc_font.width;
78 region.width = height * vc->vc_font.height;
79 region.rop = ROP_COPY;
80
81 info->fbops->fb_fillrect(info, &region);
82}
83
84static inline void cw_putcs_aligned(struct vc_data *vc, struct fb_info *info,
85 const u16 *s, u32 attr, u32 cnt,
86 u32 d_pitch, u32 s_pitch, u32 cellsize,
87 struct fb_image *image, u8 *buf, u8 *dst)
88{
89 struct fbcon_ops *ops = info->fbcon_par;
90 u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
91 u32 idx = (vc->vc_font.height + 7) >> 3;
92 u8 *src;
93
94 while (cnt--) {
95 src = ops->fontbuffer + (scr_readw(s++) & charmask)*cellsize;
96
97 if (attr) {
98 cw_update_attr(buf, src, attr, vc);
99 src = buf;
100 }
101
102 if (likely(idx == 1))
103 __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
104 vc->vc_font.width);
105 else
106 fb_pad_aligned_buffer(dst, d_pitch, src, idx,
107 vc->vc_font.width);
108
109 dst += d_pitch * vc->vc_font.width;
110 }
111
112 info->fbops->fb_imageblit(info, image);
113}
114
115static void cw_putcs(struct vc_data *vc, struct fb_info *info,
116 const unsigned short *s, int count, int yy, int xx,
117 int fg, int bg)
118{
119 struct fb_image image;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800120 struct fbcon_ops *ops = info->fbcon_par;
121 u32 width = (vc->vc_font.height + 7)/8;
122 u32 cellsize = width * vc->vc_font.width;
123 u32 maxcnt = info->pixmap.size/cellsize;
124 u32 scan_align = info->pixmap.scan_align - 1;
125 u32 buf_align = info->pixmap.buf_align - 1;
126 u32 cnt, pitch, size;
127 u32 attribute = get_attribute(info, scr_readw(s));
128 u8 *dst, *buf = NULL;
Antonino A. Daplasab767202005-11-13 16:06:32 -0800129 u32 vxres = GETVXRES(ops->p->scrollmode, info);
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800130
131 if (!ops->fontbuffer)
132 return;
133
134 image.fg_color = fg;
135 image.bg_color = bg;
136 image.dx = vxres - ((yy + 1) * vc->vc_font.height);
137 image.dy = xx * vc->vc_font.width;
138 image.width = vc->vc_font.height;
139 image.depth = 1;
140
141 if (attribute) {
142 buf = kmalloc(cellsize, GFP_KERNEL);
143 if (!buf)
144 return;
145 }
146
147 while (count) {
148 if (count > maxcnt)
149 cnt = maxcnt;
150 else
151 cnt = count;
152
153 image.height = vc->vc_font.width * cnt;
154 pitch = ((image.width + 7) >> 3) + scan_align;
155 pitch &= ~scan_align;
156 size = pitch * image.height + buf_align;
157 size &= ~buf_align;
158 dst = fb_get_buffer_offset(info, &info->pixmap, size);
159 image.data = dst;
160 cw_putcs_aligned(vc, info, s, attribute, cnt, pitch,
161 width, cellsize, &image, buf, dst);
162 image.dy += image.height;
163 count -= cnt;
164 s += cnt;
165 }
166
167 /* buf is always NULL except when in monochrome mode, so in this case
168 it's a gain to check buf against NULL even though kfree() handles
169 NULL pointers just fine */
170 if (unlikely(buf))
171 kfree(buf);
172
173}
174
175static void cw_clear_margins(struct vc_data *vc, struct fb_info *info,
176 int bottom_only)
177{
178 unsigned int cw = vc->vc_font.width;
179 unsigned int ch = vc->vc_font.height;
180 unsigned int rw = info->var.yres - (vc->vc_cols*cw);
181 unsigned int bh = info->var.xres - (vc->vc_rows*ch);
182 unsigned int rs = info->var.yres - rw;
183 struct fb_fillrect region;
184 int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
185
186 region.color = attr_bgcol_ec(bgshift,vc);
187 region.rop = ROP_COPY;
188
189 if (rw && !bottom_only) {
190 region.dx = 0;
191 region.dy = info->var.yoffset + rs;
192 region.height = rw;
193 region.width = info->var.xres_virtual;
194 info->fbops->fb_fillrect(info, &region);
195 }
196
197 if (bh) {
198 region.dx = info->var.xoffset;
199 region.dy = info->var.yoffset;
200 region.height = info->var.yres;
201 region.width = bh;
202 info->fbops->fb_fillrect(info, &region);
203 }
204}
205
206static void cw_cursor(struct vc_data *vc, struct fb_info *info,
207 struct display *p, int mode, int softback_lines,
208 int fg, int bg)
209{
210 struct fb_cursor cursor;
211 struct fbcon_ops *ops = (struct fbcon_ops *) info->fbcon_par;
212 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
213 int w = (vc->vc_font.height + 7) >> 3, c;
214 int y = real_y(p, vc->vc_y);
215 int attribute, use_sw = (vc->vc_cursor_type & 0x10);
216 int err = 1, dx, dy;
217 char *src;
218 u32 vxres = GETVXRES(p->scrollmode, info);
219
220 if (!ops->fontbuffer)
221 return;
222
223 cursor.set = 0;
224
225 if (softback_lines) {
226 if (y + softback_lines >= vc->vc_rows) {
227 mode = CM_ERASE;
228 ops->cursor_flash = 0;
229 return;
230 } else
231 y += softback_lines;
232 }
233
234 c = scr_readw((u16 *) vc->vc_pos);
235 attribute = get_attribute(info, c);
236 src = ops->fontbuffer + ((c & charmask) * (w * vc->vc_font.width));
237
238 if (ops->cursor_state.image.data != src ||
239 ops->cursor_reset) {
240 ops->cursor_state.image.data = src;
241 cursor.set |= FB_CUR_SETIMAGE;
242 }
243
244 if (attribute) {
245 u8 *dst;
246
247 dst = kmalloc(w * vc->vc_font.width, GFP_ATOMIC);
248 if (!dst)
249 return;
250 kfree(ops->cursor_data);
251 ops->cursor_data = dst;
252 cw_update_attr(dst, src, attribute, vc);
253 src = dst;
254 }
255
256 if (ops->cursor_state.image.fg_color != fg ||
257 ops->cursor_state.image.bg_color != bg ||
258 ops->cursor_reset) {
259 ops->cursor_state.image.fg_color = fg;
260 ops->cursor_state.image.bg_color = bg;
261 cursor.set |= FB_CUR_SETCMAP;
262 }
263
264 if (ops->cursor_state.image.height != vc->vc_font.width ||
265 ops->cursor_state.image.width != vc->vc_font.height ||
266 ops->cursor_reset) {
267 ops->cursor_state.image.height = vc->vc_font.width;
268 ops->cursor_state.image.width = vc->vc_font.height;
269 cursor.set |= FB_CUR_SETSIZE;
270 }
271
272 dx = vxres - ((y * vc->vc_font.height) + vc->vc_font.height);
273 dy = vc->vc_x * vc->vc_font.width;
274
275 if (ops->cursor_state.image.dx != dx ||
276 ops->cursor_state.image.dy != dy ||
277 ops->cursor_reset) {
278 ops->cursor_state.image.dx = dx;
279 ops->cursor_state.image.dy = dy;
280 cursor.set |= FB_CUR_SETPOS;
281 }
282
283 if (ops->cursor_state.hot.x || ops->cursor_state.hot.y ||
284 ops->cursor_reset) {
285 ops->cursor_state.hot.x = cursor.hot.y = 0;
286 cursor.set |= FB_CUR_SETHOT;
287 }
288
289 if (cursor.set & FB_CUR_SETSIZE ||
290 vc->vc_cursor_type != p->cursor_shape ||
291 ops->cursor_state.mask == NULL ||
292 ops->cursor_reset) {
293 char *tmp, *mask = kmalloc(w*vc->vc_font.width, GFP_ATOMIC);
294 int cur_height, size, i = 0;
295 int width = (vc->vc_font.width + 7)/8;
296
297 if (!mask)
298 return;
299
300 tmp = kmalloc(width * vc->vc_font.height, GFP_ATOMIC);
301
302 if (!tmp) {
303 kfree(mask);
304 return;
305 }
306
307 kfree(ops->cursor_state.mask);
308 ops->cursor_state.mask = mask;
309
310 p->cursor_shape = vc->vc_cursor_type;
311 cursor.set |= FB_CUR_SETSHAPE;
312
313 switch (p->cursor_shape & CUR_HWMASK) {
314 case CUR_NONE:
315 cur_height = 0;
316 break;
317 case CUR_UNDERLINE:
318 cur_height = (vc->vc_font.height < 10) ? 1 : 2;
319 break;
320 case CUR_LOWER_THIRD:
321 cur_height = vc->vc_font.height/3;
322 break;
323 case CUR_LOWER_HALF:
324 cur_height = vc->vc_font.height >> 1;
325 break;
326 case CUR_TWO_THIRDS:
327 cur_height = (vc->vc_font.height << 1)/3;
328 break;
329 case CUR_BLOCK:
330 default:
331 cur_height = vc->vc_font.height;
332 break;
333 }
334
335 size = (vc->vc_font.height - cur_height) * width;
336 while (size--)
337 tmp[i++] = 0;
338 size = cur_height * width;
339 while (size--)
340 tmp[i++] = 0xff;
341 memset(mask, 0, w * vc->vc_font.width);
342 rotate_cw(tmp, mask, vc->vc_font.width, vc->vc_font.height);
343 kfree(tmp);
344 }
345
346 switch (mode) {
347 case CM_ERASE:
348 ops->cursor_state.enable = 0;
349 break;
350 case CM_DRAW:
351 case CM_MOVE:
352 default:
353 ops->cursor_state.enable = (use_sw) ? 0 : 1;
354 break;
355 }
356
357 cursor.image.data = src;
358 cursor.image.fg_color = ops->cursor_state.image.fg_color;
359 cursor.image.bg_color = ops->cursor_state.image.bg_color;
360 cursor.image.dx = ops->cursor_state.image.dx;
361 cursor.image.dy = ops->cursor_state.image.dy;
362 cursor.image.height = ops->cursor_state.image.height;
363 cursor.image.width = ops->cursor_state.image.width;
364 cursor.hot.x = ops->cursor_state.hot.x;
365 cursor.hot.y = ops->cursor_state.hot.y;
366 cursor.mask = ops->cursor_state.mask;
367 cursor.enable = ops->cursor_state.enable;
368 cursor.image.depth = 1;
369 cursor.rop = ROP_XOR;
370
371 if (info->fbops->fb_cursor)
372 err = info->fbops->fb_cursor(info, &cursor);
373
374 if (err)
375 soft_cursor(info, &cursor);
376
377 ops->cursor_reset = 0;
378}
379
380int cw_update_start(struct fb_info *info)
381{
382 struct fbcon_ops *ops = info->fbcon_par;
Antonino A. Daplasab767202005-11-13 16:06:32 -0800383 u32 vxres = GETVXRES(ops->p->scrollmode, info);
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800384 u32 xoffset;
385 int err;
386
387 xoffset = vxres - (info->var.xres + ops->var.yoffset);
388 ops->var.yoffset = ops->var.xoffset;
389 ops->var.xoffset = xoffset;
390 err = fb_pan_display(info, &ops->var);
391 ops->var.xoffset = info->var.xoffset;
392 ops->var.yoffset = info->var.yoffset;
393 ops->var.vmode = info->var.vmode;
394 return err;
395}
396
397void fbcon_rotate_cw(struct fbcon_ops *ops)
398{
399 ops->bmove = cw_bmove;
400 ops->clear = cw_clear;
401 ops->putcs = cw_putcs;
402 ops->clear_margins = cw_clear_margins;
403 ops->cursor = cw_cursor;
404 ops->update_start = cw_update_start;
405}
406EXPORT_SYMBOL(fbcon_rotate_cw);
407
408MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
409MODULE_DESCRIPTION("Console Rotation (90 degrees) Support");
410MODULE_LICENSE("GPL");