xref: /openbmc/linux/drivers/video/fbdev/core/fbcon.h (revision 6523d3b2)
1 /*
2  *  linux/drivers/video/console/fbcon.h -- Low level frame buffer based console driver
3  *
4  *	Copyright (C) 1997 Geert Uytterhoeven
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
8  *  for more details.
9  */
10 
11 #ifndef _VIDEO_FBCON_H
12 #define _VIDEO_FBCON_H
13 
14 #include <linux/types.h>
15 #include <linux/vt_buffer.h>
16 #include <linux/vt_kern.h>
17 
18 #include <asm/io.h>
19 
20 #define FBCON_FLAGS_INIT         1
21 #define FBCON_FLAGS_CURSOR_TIMER 2
22 
23    /*
24     *    This is the interface between the low-level console driver and the
25     *    low-level frame buffer device
26     */
27 
28 struct fbcon_display {
29     /* Filled in by the low-level console driver */
30     const u_char *fontdata;
31     int userfont;                   /* != 0 if fontdata kmalloc()ed */
32     u_short inverse;                /* != 0 text black on white as default */
33     short yscroll;                  /* Hardware scrolling */
34     int vrows;                      /* number of virtual rows */
35     int cursor_shape;
36     int con_rotate;
37     u32 xres_virtual;
38     u32 yres_virtual;
39     u32 height;
40     u32 width;
41     u32 bits_per_pixel;
42     u32 grayscale;
43     u32 nonstd;
44     u32 accel_flags;
45     u32 rotate;
46     struct fb_bitfield red;
47     struct fb_bitfield green;
48     struct fb_bitfield blue;
49     struct fb_bitfield transp;
50     const struct fb_videomode *mode;
51 };
52 
53 struct fbcon_ops {
54 	void (*clear)(struct vc_data *vc, struct fb_info *info, int sy,
55 		      int sx, int height, int width);
56 	void (*putcs)(struct vc_data *vc, struct fb_info *info,
57 		      const unsigned short *s, int count, int yy, int xx,
58 		      int fg, int bg);
59 	void (*clear_margins)(struct vc_data *vc, struct fb_info *info,
60 			      int color, int bottom_only);
61 	void (*cursor)(struct vc_data *vc, struct fb_info *info, int mode,
62 		       int fg, int bg);
63 	int  (*update_start)(struct fb_info *info);
64 	int  (*rotate_font)(struct fb_info *info, struct vc_data *vc);
65 	struct fb_var_screeninfo var;  /* copy of the current fb_var_screeninfo */
66 	struct timer_list cursor_timer; /* Cursor timer */
67 	struct fb_cursor cursor_state;
68 	struct fbcon_display *p;
69 	struct fb_info *info;
70         int    currcon;	                /* Current VC. */
71 	int    cur_blink_jiffies;
72 	int    cursor_flash;
73 	int    cursor_reset;
74 	int    blank_state;
75 	int    graphics;
76 	int    save_graphics; /* for debug enter/leave */
77 	int    flags;
78 	int    rotate;
79 	int    cur_rotate;
80 	char  *cursor_data;
81 	u8    *fontbuffer;
82 	u8    *fontdata;
83 	u8    *cursor_src;
84 	u32    cursor_size;
85 	u32    fd_size;
86 };
87     /*
88      *  Attribute Decoding
89      */
90 
91 /* Color */
92 #define attr_fgcol(fgshift,s)    \
93 	(((s) >> (fgshift)) & 0x0f)
94 #define attr_bgcol(bgshift,s)    \
95 	(((s) >> (bgshift)) & 0x0f)
96 
97 /* Monochrome */
98 #define attr_bold(s) \
99 	((s) & 0x200)
100 #define attr_reverse(s) \
101 	((s) & 0x800)
102 #define attr_underline(s) \
103 	((s) & 0x400)
104 #define attr_blink(s) \
105 	((s) & 0x8000)
106 
107 
108 static inline int mono_col(const struct fb_info *info)
109 {
110 	__u32 max_len;
111 	max_len = max(info->var.green.length, info->var.red.length);
112 	max_len = max(info->var.blue.length, max_len);
113 	return (~(0xfff << max_len)) & 0xff;
114 }
115 
116 static inline int attr_col_ec(int shift, struct vc_data *vc,
117 			      struct fb_info *info, int is_fg)
118 {
119 	int is_mono01;
120 	int col;
121 	int fg;
122 	int bg;
123 
124 	if (!vc)
125 		return 0;
126 
127 	if (vc->vc_can_do_color)
128 		return is_fg ? attr_fgcol(shift,vc->vc_video_erase_char)
129 			: attr_bgcol(shift,vc->vc_video_erase_char);
130 
131 	if (!info)
132 		return 0;
133 
134 	col = mono_col(info);
135 	is_mono01 = info->fix.visual == FB_VISUAL_MONO01;
136 
137 	if (attr_reverse(vc->vc_video_erase_char)) {
138 		fg = is_mono01 ? col : 0;
139 		bg = is_mono01 ? 0 : col;
140 	}
141 	else {
142 		fg = is_mono01 ? 0 : col;
143 		bg = is_mono01 ? col : 0;
144 	}
145 
146 	return is_fg ? fg : bg;
147 }
148 
149 #define attr_bgcol_ec(bgshift, vc, info) attr_col_ec(bgshift, vc, info, 0)
150 #define attr_fgcol_ec(fgshift, vc, info) attr_col_ec(fgshift, vc, info, 1)
151 
152 #ifdef CONFIG_FB_TILEBLITTING
153 extern void fbcon_set_tileops(struct vc_data *vc, struct fb_info *info);
154 #endif
155 extern void fbcon_set_bitops(struct fbcon_ops *ops);
156 extern int  soft_cursor(struct fb_info *info, struct fb_cursor *cursor);
157 
158 #define FBCON_ATTRIBUTE_UNDERLINE 1
159 #define FBCON_ATTRIBUTE_REVERSE   2
160 #define FBCON_ATTRIBUTE_BOLD      4
161 
162 static inline int real_y(struct fbcon_display *p, int ypos)
163 {
164 	int rows = p->vrows;
165 
166 	ypos += p->yscroll;
167 	return ypos < rows ? ypos : ypos - rows;
168 }
169 
170 
171 static inline int get_attribute(struct fb_info *info, u16 c)
172 {
173 	int attribute = 0;
174 
175 	if (fb_get_color_depth(&info->var, &info->fix) == 1) {
176 		if (attr_underline(c))
177 			attribute |= FBCON_ATTRIBUTE_UNDERLINE;
178 		if (attr_reverse(c))
179 			attribute |= FBCON_ATTRIBUTE_REVERSE;
180 		if (attr_bold(c))
181 			attribute |= FBCON_ATTRIBUTE_BOLD;
182 	}
183 
184 	return attribute;
185 }
186 
187 #define FBCON_SWAP(i,r,v) ({ \
188         typeof(r) _r = (r);  \
189         typeof(v) _v = (v);  \
190         (void) (&_r == &_v); \
191         (i == FB_ROTATE_UR || i == FB_ROTATE_UD) ? _r : _v; })
192 
193 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
194 extern void fbcon_set_rotate(struct fbcon_ops *ops);
195 #else
196 #define fbcon_set_rotate(x) do {} while(0)
197 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
198 
199 #endif /* _VIDEO_FBCON_H */
200