]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device | |
3 | * | |
4 | * Modified to new api Jan 2001 by James Simmons (jsimmons@transvirtual.com) | |
5 | * | |
6 | * Created 28 Dec 1997 by Geert Uytterhoeven | |
7 | * | |
8 | * | |
9 | * I have started rewriting this driver as a example of the upcoming new API | |
10 | * The primary goal is to remove the console code from fbdev and place it | |
11 | * into fbcon.c. This reduces the code and makes writing a new fbdev driver | |
12 | * easy since the author doesn't need to worry about console internals. It | |
13 | * also allows the ability to run fbdev without a console/tty system on top | |
14 | * of it. | |
15 | * | |
16 | * First the roles of struct fb_info and struct display have changed. Struct | |
17 | * display will go away. The way the the new framebuffer console code will | |
18 | * work is that it will act to translate data about the tty/console in | |
19 | * struct vc_data to data in a device independent way in struct fb_info. Then | |
20 | * various functions in struct fb_ops will be called to store the device | |
21 | * dependent state in the par field in struct fb_info and to change the | |
22 | * hardware to that state. This allows a very clean separation of the fbdev | |
23 | * layer from the console layer. It also allows one to use fbdev on its own | |
24 | * which is a bounus for embedded devices. The reason this approach works is | |
25 | * for each framebuffer device when used as a tty/console device is allocated | |
26 | * a set of virtual terminals to it. Only one virtual terminal can be active | |
27 | * per framebuffer device. We already have all the data we need in struct | |
28 | * vc_data so why store a bunch of colormaps and other fbdev specific data | |
29 | * per virtual terminal. | |
30 | * | |
31 | * As you can see doing this makes the con parameter pretty much useless | |
32 | * for struct fb_ops functions, as it should be. Also having struct | |
33 | * fb_var_screeninfo and other data in fb_info pretty much eliminates the | |
34 | * need for get_fix and get_var. Once all drivers use the fix, var, and cmap | |
35 | * fbcon can be written around these fields. This will also eliminate the | |
36 | * need to regenerate struct fb_var_screeninfo, struct fb_fix_screeninfo | |
37 | * struct fb_cmap every time get_var, get_fix, get_cmap functions are called | |
38 | * as many drivers do now. | |
39 | * | |
40 | * This file is subject to the terms and conditions of the GNU General Public | |
41 | * License. See the file COPYING in the main directory of this archive for | |
42 | * more details. | |
43 | */ | |
44 | ||
45 | #include <linux/module.h> | |
46 | #include <linux/kernel.h> | |
47 | #include <linux/errno.h> | |
48 | #include <linux/string.h> | |
49 | #include <linux/mm.h> | |
50 | #include <linux/tty.h> | |
51 | #include <linux/slab.h> | |
52 | #include <linux/delay.h> | |
53 | #include <linux/fb.h> | |
54 | #include <linux/init.h> | |
55 | ||
56 | /* | |
57 | * This is just simple sample code. | |
58 | * | |
59 | * No warranty that it actually compiles. | |
60 | * Even less warranty that it actually works :-) | |
61 | */ | |
62 | ||
63 | /* | |
64 | * If your driver supports multiple boards, you should make the | |
65 | * below data types arrays, or allocate them dynamically (using kmalloc()). | |
66 | */ | |
67 | ||
68 | /* | |
69 | * This structure defines the hardware state of the graphics card. Normally | |
70 | * you place this in a header file in linux/include/video. This file usually | |
71 | * also includes register information. That allows other driver subsystems | |
72 | * and userland applications the ability to use the same header file to | |
73 | * avoid duplicate work and easy porting of software. | |
74 | */ | |
75 | struct xxx_par; | |
76 | ||
77 | /* | |
78 | * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo | |
79 | * if we don't use modedb. If we do use modedb see xxxfb_init how to use it | |
80 | * to get a fb_var_screeninfo. Otherwise define a default var as well. | |
81 | */ | |
82 | static struct fb_fix_screeninfo xxxfb_fix __initdata = { | |
83 | .id = "FB's name", | |
84 | .type = FB_TYPE_PACKED_PIXELS, | |
85 | .visual = FB_VISUAL_PSEUDOCOLOR, | |
86 | .xpanstep = 1, | |
87 | .ypanstep = 1, | |
88 | .ywrapstep = 1, | |
89 | .accel = FB_ACCEL_NONE, | |
90 | }; | |
91 | ||
92 | /* | |
93 | * Modern graphical hardware not only supports pipelines but some | |
94 | * also support multiple monitors where each display can have its | |
95 | * its own unique data. In this case each display could be | |
96 | * represented by a separate framebuffer device thus a separate | |
97 | * struct fb_info. Now the struct xxx_par represents the graphics | |
98 | * hardware state thus only one exist per card. In this case the | |
99 | * struct xxx_par for each graphics card would be shared between | |
100 | * every struct fb_info that represents a framebuffer on that card. | |
101 | * This allows when one display changes it video resolution (info->var) | |
102 | * the other displays know instantly. Each display can always be | |
103 | * aware of the entire hardware state that affects it because they share | |
104 | * the same xxx_par struct. The other side of the coin is multiple | |
105 | * graphics cards that pass data around until it is finally displayed | |
106 | * on one monitor. Such examples are the voodoo 1 cards and high end | |
107 | * NUMA graphics servers. For this case we have a bunch of pars, each | |
108 | * one that represents a graphics state, that belong to one struct | |
109 | * fb_info. Their you would want to have *par point to a array of device | |
110 | * states and have each struct fb_ops function deal with all those | |
111 | * states. I hope this covers every possible hardware design. If not | |
112 | * feel free to send your ideas at jsimmons@users.sf.net | |
113 | */ | |
114 | ||
115 | /* | |
116 | * If your driver supports multiple boards or it supports multiple | |
117 | * framebuffers, you should make these arrays, or allocate them | |
d911233f AD |
118 | * dynamically using framebuffer_alloc() and free them with |
119 | * framebuffer_release(). | |
1da177e4 LT |
120 | */ |
121 | static struct fb_info info; | |
122 | ||
123 | /* | |
124 | * Each one represents the state of the hardware. Most hardware have | |
125 | * just one hardware state. These here represent the default state(s). | |
126 | */ | |
127 | static struct xxx_par __initdata current_par; | |
128 | ||
129 | int xxxfb_init(void); | |
130 | int xxxfb_setup(char*); | |
131 | ||
132 | /** | |
133 | * xxxfb_open - Optional function. Called when the framebuffer is | |
134 | * first accessed. | |
135 | * @info: frame buffer structure that represents a single frame buffer | |
136 | * @user: tell us if the userland (value=1) or the console is accessing | |
137 | * the framebuffer. | |
138 | * | |
139 | * This function is the first function called in the framebuffer api. | |
140 | * Usually you don't need to provide this function. The case where it | |
141 | * is used is to change from a text mode hardware state to a graphics | |
142 | * mode state. | |
143 | * | |
144 | * Returns negative errno on error, or zero on success. | |
145 | */ | |
146 | static int xxxfb_open(const struct fb_info *info, int user) | |
147 | { | |
148 | return 0; | |
149 | } | |
150 | ||
151 | /** | |
152 | * xxxfb_release - Optional function. Called when the framebuffer | |
153 | * device is closed. | |
154 | * @info: frame buffer structure that represents a single frame buffer | |
155 | * @user: tell us if the userland (value=1) or the console is accessing | |
156 | * the framebuffer. | |
157 | * | |
158 | * Thus function is called when we close /dev/fb or the framebuffer | |
159 | * console system is released. Usually you don't need this function. | |
160 | * The case where it is usually used is to go from a graphics state | |
161 | * to a text mode state. | |
162 | * | |
163 | * Returns negative errno on error, or zero on success. | |
164 | */ | |
165 | static int xxxfb_release(const struct fb_info *info, int user) | |
166 | { | |
167 | return 0; | |
168 | } | |
169 | ||
170 | /** | |
171 | * xxxfb_check_var - Optional function. Validates a var passed in. | |
172 | * @var: frame buffer variable screen structure | |
173 | * @info: frame buffer structure that represents a single frame buffer | |
174 | * | |
175 | * Checks to see if the hardware supports the state requested by | |
176 | * var passed in. This function does not alter the hardware state!!! | |
177 | * This means the data stored in struct fb_info and struct xxx_par do | |
178 | * not change. This includes the var inside of struct fb_info. | |
179 | * Do NOT change these. This function can be called on its own if we | |
180 | * intent to only test a mode and not actually set it. The stuff in | |
181 | * modedb.c is a example of this. If the var passed in is slightly | |
182 | * off by what the hardware can support then we alter the var PASSED in | |
d911233f AD |
183 | * to what we can do. |
184 | * | |
185 | * For values that are off, this function must round them _up_ to the | |
186 | * next value that is supported by the hardware. If the value is | |
187 | * greater than the highest value supported by the hardware, then this | |
188 | * function must return -EINVAL. | |
189 | * | |
190 | * Exception to the above rule: Some drivers have a fixed mode, ie, | |
191 | * the hardware is already set at boot up, and cannot be changed. In | |
192 | * this case, it is more acceptable that this function just return | |
193 | * a copy of the currently working var (info->var). Better is to not | |
194 | * implement this function, as the upper layer will do the copying | |
195 | * of the current var for you. | |
196 | * | |
197 | * Note: This is the only function where the contents of var can be | |
198 | * freely adjusted after the driver has been registered. If you find | |
199 | * that you have code outside of this function that alters the content | |
200 | * of var, then you are doing something wrong. Note also that the | |
201 | * contents of info->var must be left untouched at all times after | |
202 | * driver registration. | |
1da177e4 LT |
203 | * |
204 | * Returns negative errno on error, or zero on success. | |
205 | */ | |
206 | static int xxxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) | |
207 | { | |
1da177e4 LT |
208 | /* ... */ |
209 | return 0; | |
210 | } | |
211 | ||
212 | /** | |
213 | * xxxfb_set_par - Optional function. Alters the hardware state. | |
214 | * @info: frame buffer structure that represents a single frame buffer | |
215 | * | |
216 | * Using the fb_var_screeninfo in fb_info we set the resolution of the | |
217 | * this particular framebuffer. This function alters the par AND the | |
218 | * fb_fix_screeninfo stored in fb_info. It doesn't not alter var in | |
219 | * fb_info since we are using that data. This means we depend on the | |
220 | * data in var inside fb_info to be supported by the hardware. | |
d911233f AD |
221 | * |
222 | * This function is also used to recover/restore the hardware to a | |
223 | * known working state. | |
224 | * | |
225 | * xxxfb_check_var is always called before xxxfb_set_par to ensure that | |
226 | * the contents of var is always valid. | |
227 | * | |
1da177e4 LT |
228 | * Again if you can't change the resolution you don't need this function. |
229 | * | |
d911233f AD |
230 | * However, even if your hardware does not support mode changing, |
231 | * a set_par might be needed to at least initialize the hardware to | |
232 | * a known working state, especially if it came back from another | |
233 | * process that also modifies the same hardware, such as X. | |
234 | * | |
235 | * If this is the case, a combination such as the following should work: | |
236 | * | |
237 | * static int xxxfb_check_var(struct fb_var_screeninfo *var, | |
238 | * struct fb_info *info) | |
239 | * { | |
240 | * *var = info->var; | |
241 | * return 0; | |
242 | * } | |
243 | * | |
244 | * static int xxxfb_set_par(struct fb_info *info) | |
245 | * { | |
246 | * init your hardware here | |
247 | * } | |
248 | * | |
1da177e4 LT |
249 | * Returns negative errno on error, or zero on success. |
250 | */ | |
251 | static int xxxfb_set_par(struct fb_info *info) | |
252 | { | |
d911233f | 253 | struct xxx_par *par = info->par; |
1da177e4 LT |
254 | /* ... */ |
255 | return 0; | |
256 | } | |
257 | ||
258 | /** | |
259 | * xxxfb_setcolreg - Optional function. Sets a color register. | |
260 | * @regno: Which register in the CLUT we are programming | |
261 | * @red: The red value which can be up to 16 bits wide | |
262 | * @green: The green value which can be up to 16 bits wide | |
263 | * @blue: The blue value which can be up to 16 bits wide. | |
264 | * @transp: If supported, the alpha value which can be up to 16 bits wide. | |
265 | * @info: frame buffer info structure | |
266 | * | |
267 | * Set a single color register. The values supplied have a 16 bit | |
268 | * magnitude which needs to be scaled in this function for the hardware. | |
269 | * Things to take into consideration are how many color registers, if | |
270 | * any, are supported with the current color visual. With truecolor mode | |
271 | * no color palettes are supported. Here a pseudo palette is created | |
272 | * which we store the value in pseudo_palette in struct fb_info. For | |
273 | * pseudocolor mode we have a limited color palette. To deal with this | |
274 | * we can program what color is displayed for a particular pixel value. | |
275 | * DirectColor is similar in that we can program each color field. If | |
276 | * we have a static colormap we don't need to implement this function. | |
277 | * | |
278 | * Returns negative errno on error, or zero on success. | |
279 | */ | |
280 | static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green, | |
281 | unsigned blue, unsigned transp, | |
282 | const struct fb_info *info) | |
283 | { | |
284 | if (regno >= 256) /* no. of hw registers */ | |
285 | return -EINVAL; | |
286 | /* | |
287 | * Program hardware... do anything you want with transp | |
288 | */ | |
289 | ||
290 | /* grayscale works only partially under directcolor */ | |
291 | if (info->var.grayscale) { | |
292 | /* grayscale = 0.30*R + 0.59*G + 0.11*B */ | |
293 | red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8; | |
294 | } | |
295 | ||
296 | /* Directcolor: | |
297 | * var->{color}.offset contains start of bitfield | |
298 | * var->{color}.length contains length of bitfield | |
299 | * {hardwarespecific} contains width of DAC | |
d911233f AD |
300 | * pseudo_palette[X] is programmed to (X << red.offset) | |
301 | * (X << green.offset) | | |
302 | * (X << blue.offset) | |
1da177e4 | 303 | * RAMDAC[X] is programmed to (red, green, blue) |
d911233f | 304 | * color depth = SUM(var->{color}.length) |
1da177e4 LT |
305 | * |
306 | * Pseudocolor: | |
1da177e4 | 307 | * var->{color}.offset is 0 |
d911233f AD |
308 | * var->{color}.length contains width of DAC or the number of unique |
309 | * colors available (color depth) | |
310 | * pseudo_palette is not used | |
311 | * RAMDAC[X] is programmed to (red, green, blue) | |
312 | * color depth = var->{color}.length | |
313 | * | |
314 | * Static pseudocolor: | |
315 | * same as Pseudocolor, but the RAMDAC is not programmed (read-only) | |
316 | * | |
317 | * Mono01/Mono10: | |
318 | * Has only 2 values, black on white or white on black (fg on bg), | |
319 | * var->{color}.offset is 0 | |
320 | * white = (1 << var->{color}.length) - 1, black = 0 | |
321 | * pseudo_palette is not used | |
322 | * RAMDAC does not exist | |
323 | * color depth is always 2 | |
324 | * | |
1da177e4 LT |
325 | * Truecolor: |
326 | * does not use RAMDAC (usually has 3 of them). | |
327 | * var->{color}.offset contains start of bitfield | |
328 | * var->{color}.length contains length of bitfield | |
d911233f AD |
329 | * pseudo_palette is programmed to (red << red.offset) | |
330 | * (green << green.offset) | | |
331 | * (blue << blue.offset) | | |
332 | * (transp << transp.offset) | |
1da177e4 | 333 | * RAMDAC does not exist |
d911233f AD |
334 | * color depth = SUM(var->{color}.length}) |
335 | * | |
336 | * The color depth is used by fbcon for choosing the logo and also | |
337 | * for color palette transformation if color depth < 4 | |
338 | * | |
339 | * As can be seen from the above, the field bits_per_pixel is _NOT_ | |
340 | * a criteria for describing the color visual. | |
341 | * | |
342 | * A common mistake is assuming that bits_per_pixel <= 8 is pseudocolor, | |
343 | * and higher than that, true/directcolor. This is incorrect, one needs | |
344 | * to look at the fix->visual. | |
345 | * | |
346 | * Another common mistake is using bits_per_pixel to calculate the color | |
347 | * depth. The bits_per_pixel field does not directly translate to color | |
348 | * depth. You have to compute for the color depth (using the color | |
349 | * bitfields) and fix->visual as seen above. | |
350 | */ | |
351 | ||
352 | /* | |
353 | * This is the point where the color is converted to something that | |
354 | * is acceptable by the hardware. | |
1da177e4 LT |
355 | */ |
356 | #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16) | |
d911233f AD |
357 | red = CNVT_TOHW(red, info->var.red.length); |
358 | green = CNVT_TOHW(green, info->var.green.length); | |
359 | blue = CNVT_TOHW(blue, info->var.blue.length); | |
360 | transp = CNVT_TOHW(transp, info->var.transp.length); | |
1da177e4 | 361 | #undef CNVT_TOHW |
d911233f AD |
362 | /* |
363 | * This is the point where the function feeds the color to the hardware | |
364 | * palette after converting the colors to something acceptable by | |
365 | * the hardware. Note, only FB_VISUAL_DIRECTCOLOR and | |
366 | * FB_VISUAL_PSEUDOCOLOR visuals need to write to the hardware palette. | |
367 | * If you have code that writes to the hardware CLUT, and it's not | |
368 | * any of the above visuals, then you are doing something wrong. | |
369 | */ | |
370 | if (info->fix.visual == FB_VISUAL_DIRECTCOLOR || | |
371 | info->fix.visual == FB_VISUAL_TRUECOLOR) | |
372 | write_{red|green|blue|transp}_to_clut(); | |
373 | ||
374 | /* This is the point were you need to fill up the contents of | |
375 | * info->pseudo_palette. This structure is used _only_ by fbcon, thus | |
376 | * it only contains 16 entries to match the number of colors supported | |
377 | * by the console. The pseudo_palette is used only if the visual is | |
378 | * in directcolor or truecolor mode. With other visuals, the | |
379 | * pseudo_palette is not used. (This might change in the future.) | |
380 | * | |
381 | * The contents of the pseudo_palette is in raw pixel format. Ie, each | |
382 | * entry can be written directly to the framebuffer without any conversion. | |
383 | * The pseudo_palette is (void *). However, if using the generic | |
384 | * drawing functions (cfb_imageblit, cfb_fillrect), the pseudo_palette | |
385 | * must be casted to (u32 *) _regardless_ of the bits per pixel. If the | |
386 | * driver is using its own drawing functions, then it can use whatever | |
387 | * size it wants. | |
388 | */ | |
389 | if (info->fix.visual == FB_VISUAL_TRUECOLOR || | |
390 | info->fix.visual == FB_VISUAL_DIRECTCOLOR) { | |
391 | u32 v; | |
392 | ||
393 | if (regno >= 16) | |
394 | return -EINVAL; | |
395 | ||
396 | v = (red << info->var.red.offset) | | |
397 | (green << info->var.green.offset) | | |
398 | (blue << info->var.blue.offset) | | |
399 | (transp << info->var.transp.offset); | |
400 | ||
401 | ((u32*)(info->pseudo_palette))[regno] = v; | |
1da177e4 | 402 | } |
d911233f | 403 | |
1da177e4 LT |
404 | /* ... */ |
405 | return 0; | |
406 | } | |
407 | ||
408 | /** | |
409 | * xxxfb_pan_display - NOT a required function. Pans the display. | |
410 | * @var: frame buffer variable screen structure | |
411 | * @info: frame buffer structure that represents a single frame buffer | |
412 | * | |
413 | * Pan (or wrap, depending on the `vmode' field) the display using the | |
414 | * `xoffset' and `yoffset' fields of the `var' structure. | |
415 | * If the values don't fit, return -EINVAL. | |
416 | * | |
417 | * Returns negative errno on error, or zero on success. | |
418 | */ | |
419 | static int xxxfb_pan_display(struct fb_var_screeninfo *var, | |
420 | const struct fb_info *info) | |
421 | { | |
d911233f AD |
422 | /* |
423 | * If your hardware does not support panning, _do_ _not_ implement this | |
424 | * function. Creating a dummy function will just confuse user apps. | |
425 | */ | |
426 | ||
427 | /* | |
428 | * Note that even if this function is fully functional, a setting of | |
429 | * 0 in both xpanstep and ypanstep means that this function will never | |
430 | * get called. | |
431 | */ | |
432 | ||
1da177e4 LT |
433 | /* ... */ |
434 | return 0; | |
435 | } | |
436 | ||
437 | /** | |
438 | * xxxfb_blank - NOT a required function. Blanks the display. | |
439 | * @blank_mode: the blank mode we want. | |
440 | * @info: frame buffer structure that represents a single frame buffer | |
441 | * | |
d911233f AD |
442 | * Blank the screen if blank_mode != FB_BLANK_UNBLANK, else unblank. |
443 | * Return 0 if blanking succeeded, != 0 if un-/blanking failed due to | |
444 | * e.g. a video mode which doesn't support it. | |
1da177e4 | 445 | * |
d911233f AD |
446 | * Implements VESA suspend and powerdown modes on hardware that supports |
447 | * disabling hsync/vsync: | |
448 | * | |
449 | * FB_BLANK_NORMAL = display is blanked, syncs are on. | |
450 | * FB_BLANK_HSYNC_SUSPEND = hsync off | |
451 | * FB_BLANK_VSYNC_SUSPEND = vsync off | |
452 | * FB_BLANK_POWERDOWN = hsync and vsync off | |
453 | * | |
454 | * If implementing this function, at least support FB_BLANK_UNBLANK. | |
455 | * Return !0 for any modes that are unimplemented. | |
1da177e4 LT |
456 | * |
457 | */ | |
458 | static int xxxfb_blank(int blank_mode, const struct fb_info *info) | |
459 | { | |
460 | /* ... */ | |
461 | return 0; | |
462 | } | |
463 | ||
464 | /* ------------ Accelerated Functions --------------------- */ | |
465 | ||
466 | /* | |
467 | * We provide our own functions if we have hardware acceleration | |
468 | * or non packed pixel format layouts. If we have no hardware | |
469 | * acceleration, we can use a generic unaccelerated function. If using | |
470 | * a pack pixel format just use the functions in cfb_*.c. Each file | |
471 | * has one of the three different accel functions we support. | |
472 | */ | |
473 | ||
474 | /** | |
475 | * xxxfb_fillrect - REQUIRED function. Can use generic routines if | |
476 | * non acclerated hardware and packed pixel based. | |
477 | * Draws a rectangle on the screen. | |
478 | * | |
479 | * @info: frame buffer structure that represents a single frame buffer | |
480 | * @region: The structure representing the rectangular region we | |
481 | * wish to draw to. | |
482 | * | |
483 | * This drawing operation places/removes a retangle on the screen | |
484 | * depending on the rastering operation with the value of color which | |
485 | * is in the current color depth format. | |
486 | */ | |
487 | void xxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region) | |
488 | { | |
489 | /* Meaning of struct fb_fillrect | |
490 | * | |
491 | * @dx: The x and y corrdinates of the upper left hand corner of the | |
492 | * @dy: area we want to draw to. | |
493 | * @width: How wide the rectangle is we want to draw. | |
494 | * @height: How tall the rectangle is we want to draw. | |
495 | * @color: The color to fill in the rectangle with. | |
496 | * @rop: The raster operation. We can draw the rectangle with a COPY | |
497 | * of XOR which provides erasing effect. | |
498 | */ | |
499 | } | |
500 | ||
501 | /** | |
502 | * xxxfb_copyarea - REQUIRED function. Can use generic routines if | |
503 | * non acclerated hardware and packed pixel based. | |
504 | * Copies one area of the screen to another area. | |
505 | * | |
506 | * @info: frame buffer structure that represents a single frame buffer | |
507 | * @area: Structure providing the data to copy the framebuffer contents | |
508 | * from one region to another. | |
509 | * | |
510 | * This drawing operation copies a rectangular area from one area of the | |
511 | * screen to another area. | |
512 | */ | |
513 | void xxxfb_copyarea(struct fb_info *p, const struct fb_copyarea *area) | |
514 | { | |
515 | /* | |
516 | * @dx: The x and y coordinates of the upper left hand corner of the | |
517 | * @dy: destination area on the screen. | |
518 | * @width: How wide the rectangle is we want to copy. | |
519 | * @height: How tall the rectangle is we want to copy. | |
520 | * @sx: The x and y coordinates of the upper left hand corner of the | |
521 | * @sy: source area on the screen. | |
522 | */ | |
523 | } | |
524 | ||
525 | ||
526 | /** | |
527 | * xxxfb_imageblit - REQUIRED function. Can use generic routines if | |
528 | * non acclerated hardware and packed pixel based. | |
529 | * Copies a image from system memory to the screen. | |
530 | * | |
531 | * @info: frame buffer structure that represents a single frame buffer | |
532 | * @image: structure defining the image. | |
533 | * | |
534 | * This drawing operation draws a image on the screen. It can be a | |
535 | * mono image (needed for font handling) or a color image (needed for | |
536 | * tux). | |
537 | */ | |
538 | void xxxfb_imageblit(struct fb_info *p, const struct fb_image *image) | |
539 | { | |
540 | /* | |
541 | * @dx: The x and y coordinates of the upper left hand corner of the | |
542 | * @dy: destination area to place the image on the screen. | |
543 | * @width: How wide the image is we want to copy. | |
544 | * @height: How tall the image is we want to copy. | |
545 | * @fg_color: For mono bitmap images this is color data for | |
546 | * @bg_color: the foreground and background of the image to | |
547 | * write directly to the frmaebuffer. | |
548 | * @depth: How many bits represent a single pixel for this image. | |
549 | * @data: The actual data used to construct the image on the display. | |
550 | * @cmap: The colormap used for color images. | |
551 | */ | |
d911233f AD |
552 | |
553 | /* | |
554 | * The generic function, cfb_imageblit, expects that the bitmap scanlines are | |
555 | * padded to the next byte. Most hardware accelerators may require padding to | |
556 | * the next u16 or the next u32. If that is the case, the driver can specify | |
557 | * this by setting info->pixmap.scan_align = 2 or 4. See a more | |
558 | * comprehensive description of the pixmap below. | |
559 | */ | |
1da177e4 LT |
560 | } |
561 | ||
562 | /** | |
c465e05a AD |
563 | * xxxfb_cursor - OPTIONAL. If your hardware lacks support |
564 | * for a cursor, leave this field NULL. | |
1da177e4 LT |
565 | * |
566 | * @info: frame buffer structure that represents a single frame buffer | |
567 | * @cursor: structure defining the cursor to draw. | |
568 | * | |
569 | * This operation is used to set or alter the properities of the | |
570 | * cursor. | |
571 | * | |
572 | * Returns negative errno on error, or zero on success. | |
573 | */ | |
574 | int xxxfb_cursor(struct fb_info *info, struct fb_cursor *cursor) | |
575 | { | |
576 | /* | |
577 | * @set: Which fields we are altering in struct fb_cursor | |
578 | * @enable: Disable or enable the cursor | |
579 | * @rop: The bit operation we want to do. | |
580 | * @mask: This is the cursor mask bitmap. | |
581 | * @dest: A image of the area we are going to display the cursor. | |
582 | * Used internally by the driver. | |
583 | * @hot: The hot spot. | |
584 | * @image: The actual data for the cursor image. | |
585 | * | |
586 | * NOTES ON FLAGS (cursor->set): | |
587 | * | |
588 | * FB_CUR_SETIMAGE - the cursor image has changed (cursor->image.data) | |
589 | * FB_CUR_SETPOS - the cursor position has changed (cursor->image.dx|dy) | |
590 | * FB_CUR_SETHOT - the cursor hot spot has changed (cursor->hot.dx|dy) | |
591 | * FB_CUR_SETCMAP - the cursor colors has changed (cursor->fg_color|bg_color) | |
592 | * FB_CUR_SETSHAPE - the cursor bitmask has changed (cursor->mask) | |
593 | * FB_CUR_SETSIZE - the cursor size has changed (cursor->width|height) | |
594 | * FB_CUR_SETALL - everything has changed | |
595 | * | |
596 | * NOTES ON ROPs (cursor->rop, Raster Operation) | |
597 | * | |
598 | * ROP_XOR - cursor->image.data XOR cursor->mask | |
599 | * ROP_COPY - curosr->image.data AND cursor->mask | |
600 | * | |
601 | * OTHER NOTES: | |
602 | * | |
603 | * - fbcon only supports a 2-color cursor (cursor->image.depth = 1) | |
604 | * - The fb_cursor structure, @cursor, _will_ always contain valid | |
605 | * fields, whether any particular bitfields in cursor->set is set | |
606 | * or not. | |
607 | */ | |
608 | } | |
609 | ||
610 | /** | |
611 | * xxxfb_rotate - NOT a required function. If your hardware | |
612 | * supports rotation the whole screen then | |
613 | * you would provide a hook for this. | |
614 | * | |
615 | * @info: frame buffer structure that represents a single frame buffer | |
616 | * @angle: The angle we rotate the screen. | |
617 | * | |
618 | * This operation is used to set or alter the properities of the | |
619 | * cursor. | |
620 | */ | |
621 | void xxxfb_rotate(struct fb_info *info, int angle) | |
622 | { | |
d911233f | 623 | /* Will be deprecated */ |
1da177e4 LT |
624 | } |
625 | ||
626 | /** | |
627 | * xxxfb_poll - NOT a required function. The purpose of this | |
628 | * function is to provide a way for some process | |
629 | * to wait until a specific hardware event occurs | |
630 | * for the framebuffer device. | |
631 | * | |
632 | * @info: frame buffer structure that represents a single frame buffer | |
633 | * @wait: poll table where we store process that await a event. | |
634 | */ | |
635 | void xxxfb_poll(struct fb_info *info, poll_table *wait) | |
636 | { | |
637 | } | |
638 | ||
639 | /** | |
640 | * xxxfb_sync - NOT a required function. Normally the accel engine | |
641 | * for a graphics card take a specific amount of time. | |
642 | * Often we have to wait for the accelerator to finish | |
643 | * its operation before we can write to the framebuffer | |
644 | * so we can have consistent display output. | |
645 | * | |
646 | * @info: frame buffer structure that represents a single frame buffer | |
d911233f AD |
647 | * |
648 | * If the driver has implemented its own hardware-based drawing function, | |
649 | * implementing this function is highly recommended. | |
1da177e4 LT |
650 | */ |
651 | void xxxfb_sync(struct fb_info *info) | |
652 | { | |
653 | } | |
654 | ||
655 | /* | |
656 | * Initialization | |
657 | */ | |
658 | ||
d911233f AD |
659 | /* static int __init xxfb_probe (struct device *device) -- for platform devs */ |
660 | static int __init xxxfb_probe(struct pci_dev *dev, | |
661 | const_struct pci_device_id *ent) | |
1da177e4 | 662 | { |
d911233f AD |
663 | struct fb_info *info; |
664 | struct xxx_par *par; | |
665 | struct device = &dev->dev; /* for pci drivers */ | |
1da177e4 LT |
666 | int cmap_len, retval; |
667 | ||
668 | /* | |
d911233f | 669 | * Dynamically allocate info and par |
1da177e4 | 670 | */ |
d911233f | 671 | info = framebuffer_alloc(sizeof(struct xxx_par), device); |
1da177e4 | 672 | |
d911233f AD |
673 | if (!info) { |
674 | /* goto error path */ | |
675 | } | |
676 | ||
677 | par = info->par; | |
1da177e4 LT |
678 | |
679 | /* | |
680 | * Here we set the screen_base to the virtual memory address | |
681 | * for the framebuffer. Usually we obtain the resource address | |
682 | * from the bus layer and then translate it to virtual memory | |
683 | * space via ioremap. Consult ioport.h. | |
684 | */ | |
d911233f AD |
685 | info->screen_base = framebuffer_virtual_memory; |
686 | info->fbops = &xxxfb_ops; | |
687 | info->fix = xxxfb_fix; /* this will be the only time xxxfb_fix will be | |
688 | * used, so mark it as __initdata | |
689 | */ | |
690 | info->pseudo_palette = pseudo_palette; /* The pseudopalette is an | |
691 | * 16-member array | |
692 | */ | |
1da177e4 LT |
693 | /* |
694 | * Set up flags to indicate what sort of acceleration your | |
695 | * driver can provide (pan/wrap/copyarea/etc.) and whether it | |
696 | * is a module -- see FBINFO_* in include/linux/fb.h | |
d911233f AD |
697 | * |
698 | * If your hardware can support any of the hardware accelerated functions | |
699 | * fbcon performance will improve if info->flags is set properly. | |
700 | * | |
701 | * FBINFO_HWACCEL_COPYAREA - hardware moves | |
702 | * FBINFO_HWACCEL_FILLRECT - hardware fills | |
703 | * FBINFO_HWACCEL_IMAGEBLIT - hardware mono->color expansion | |
704 | * FBINFO_HWACCEL_YPAN - hardware can pan display in y-axis | |
705 | * FBINFO_HWACCEL_YWRAP - hardware can wrap display in y-axis | |
706 | * FBINFO_HWACCEL_DISABLED - supports hardware accels, but disabled | |
707 | * FBINFO_READS_FAST - if set, prefer moves over mono->color expansion | |
708 | * FBINFO_MISC_TILEBLITTING - hardware can do tile blits | |
709 | * | |
710 | * NOTE: These are for fbcon use only. | |
711 | */ | |
712 | info->flags = FBINFO_DEFAULT; | |
713 | ||
714 | /********************* This stage is optional ******************************/ | |
715 | /* | |
716 | * The struct pixmap is a scratch pad for the drawing functions. This | |
717 | * is where the monochrome bitmap is constructed by the higher layers | |
718 | * and then passed to the accelerator. For drivers that uses | |
719 | * cfb_imageblit, you can skip this part. For those that have a more | |
720 | * rigorous requirement, this stage is needed | |
721 | */ | |
722 | ||
723 | /* PIXMAP_SIZE should be small enough to optimize drawing, but not | |
724 | * large enough that memory is wasted. A safe size is | |
725 | * (max_xres * max_font_height/8). max_xres is driver dependent, | |
726 | * max_font_height is 32. | |
727 | */ | |
728 | info->pixmap.addr = kmalloc(PIXMAP_SIZE, GFP_KERNEL); | |
729 | if (!info->pixmap.addr) { | |
730 | /* goto error */ | |
731 | } | |
732 | ||
733 | info->pixmap.size = PIXMAP_SIZE; | |
734 | ||
735 | /* | |
736 | * FB_PIXMAP_SYSTEM - memory is in system ram | |
737 | * FB_PIXMAP_IO - memory is iomapped | |
738 | * FB_PIXMAP_SYNC - if set, will call fb_sync() per access to pixmap, | |
739 | * usually if FB_PIXMAP_IO is set. | |
740 | * | |
741 | * Currently, FB_PIXMAP_IO is unimplemented. | |
742 | */ | |
743 | info->pixmap.flags = FB_PIXMAP_SYSTEM; | |
744 | ||
745 | /* | |
746 | * scan_align is the number of padding for each scanline. It is in bytes. | |
747 | * Thus for accelerators that need padding to the next u32, put 4 here. | |
1da177e4 | 748 | */ |
d911233f AD |
749 | info->pixmap.scan_align = 4; |
750 | ||
751 | /* | |
752 | * buf_align is the amount to be padded for the buffer. For example, | |
753 | * the i810fb needs a scan_align of 2 but expects it to be fed with | |
754 | * dwords, so a buf_align = 4 is required. | |
755 | */ | |
756 | info->pixmap.buf_align = 4; | |
757 | ||
758 | /* access_align is how many bits can be accessed from the framebuffer | |
759 | * ie. some epson cards allow 16-bit access only. Most drivers will | |
760 | * be safe with u32 here. | |
761 | * | |
762 | * NOTE: This field is currently unused. | |
763 | */ | |
764 | info->pixmap.scan_align = 32 | |
765 | /***************************** End optional stage ***************************/ | |
1da177e4 LT |
766 | |
767 | /* | |
768 | * This should give a reasonable default video mode. The following is | |
769 | * done when we can set a video mode. | |
770 | */ | |
771 | if (!mode_option) | |
772 | mode_option = "640x480@60"; | |
773 | ||
d911233f | 774 | retval = fb_find_mode(info->var, info, mode_option, NULL, 0, NULL, 8); |
1da177e4 LT |
775 | |
776 | if (!retval || retval == 4) | |
777 | return -EINVAL; | |
778 | ||
779 | /* This has to been done !!! */ | |
d911233f | 780 | fb_alloc_cmap(info->cmap, cmap_len, 0); |
1da177e4 LT |
781 | |
782 | /* | |
783 | * The following is done in the case of having hardware with a static | |
784 | * mode. If we are setting the mode ourselves we don't call this. | |
785 | */ | |
d911233f AD |
786 | info->var = xxxfb_var; |
787 | ||
788 | /* | |
789 | * For drivers that can... | |
790 | */ | |
791 | xxxfb_check_var(&info->var, info); | |
792 | ||
793 | /* | |
794 | * Does a call to fb_set_par() before register_framebuffer needed? This | |
795 | * will depend on you and the hardware. If you are sure that your driver | |
796 | * is the only device in the system, a call to fb_set_par() is safe. | |
797 | * | |
798 | * Hardware in x86 systems has a VGA core. Calling set_par() at this | |
799 | * point will corrupt the VGA console, so it might be safer to skip a | |
800 | * call to set_par here and just allow fbcon to do it for you. | |
801 | */ | |
802 | /* xxxfb_set_par(info); */ | |
803 | ||
804 | if (register_framebuffer(info) < 0) | |
1da177e4 | 805 | return -EINVAL; |
d911233f AD |
806 | printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, |
807 | info->fix.id); | |
808 | pci_set_drvdata(dev, info); /* or dev_set_drvdata(device, info) */ | |
1da177e4 LT |
809 | return 0; |
810 | } | |
811 | ||
812 | /* | |
813 | * Cleanup | |
814 | */ | |
d911233f AD |
815 | /* static void __exit xxxfb_remove(struct device *device) */ |
816 | static void __exit xxxfb_remove(struct pci_dev *dev) | |
817 | { | |
818 | struct fb_info *info = pci_get_drv_data(dev); | |
819 | /* or dev_get_drv_data(device); */ | |
820 | ||
821 | if (info) { | |
822 | unregister_framebuffer(info); | |
823 | fb_dealloc_cmap(&info.cmap); | |
824 | /* ... */ | |
825 | framebuffer_release(info); | |
826 | } | |
827 | ||
828 | return 0; | |
829 | } | |
830 | ||
831 | #if CONFIG_PCI | |
832 | /* For PCI drivers */ | |
833 | static struct pci_driver xxxfb_driver = { | |
834 | .name = "xxxfb", | |
835 | .id_table = xxxfb_devices, | |
836 | .probe = xxxfb_probe, | |
837 | .remove = __devexit_p(xxxfb_remove), | |
838 | .suspend = xxxfb_suspend, /* optional */ | |
839 | .resume = xxxfb_resume, /* optional */ | |
840 | }; | |
1da177e4 | 841 | |
d911233f | 842 | static int __init xxxfb_init(void) |
1da177e4 | 843 | { |
d911233f AD |
844 | /* |
845 | * For kernel boot options (in 'video=xxxfb:<options>' format) | |
846 | */ | |
847 | #ifndef MODULE | |
848 | char *option = NULL; | |
1da177e4 | 849 | |
d911233f AD |
850 | if (fb_get_options("xxxfb", &option)) |
851 | return -ENODEV; | |
852 | xxxfb_setup(option); | |
853 | #endif | |
854 | ||
855 | return pci_register_driver(&xxxfb_driver); | |
1da177e4 LT |
856 | } |
857 | ||
d911233f AD |
858 | static void __exit xxxfb_exit(void) |
859 | { | |
860 | pci_unregister_driver(&xxxfb_driver); | |
861 | } | |
862 | #else | |
863 | #include <linux/platform_device.h> | |
864 | /* for platform devices */ | |
865 | static struct device_driver xxxfb_driver = { | |
866 | .name = "xxxfb", | |
867 | .bus = &platform_bus_type, | |
868 | .probe = xxxfb_probe, | |
869 | .remove = xxxfb_remove, | |
870 | .suspend = xxxfb_suspend, /* optional */ | |
871 | .resume = xxxfb_resume, /* optional */ | |
872 | }; | |
873 | ||
874 | static struct platform_device xxxfb_device = { | |
875 | .name = "xxxfb", | |
876 | }; | |
877 | ||
878 | static int __init xxxfb_init(void) | |
879 | { | |
880 | int ret; | |
881 | /* | |
882 | * For kernel boot options (in 'video=xxxfb:<options>' format) | |
883 | */ | |
884 | #ifndef MODULE | |
885 | char *option = NULL; | |
886 | ||
887 | if (fb_get_options("xxxfb", &option)) | |
888 | return -ENODEV; | |
889 | xxxfb_setup(option); | |
890 | #endif | |
891 | ret = driver_register(&xxxfb_driver); | |
892 | ||
893 | if (!ret) { | |
894 | ret = platform_device_register(&xxxfb_device); | |
895 | if (ret) | |
896 | driver_unregister(&xxxfb_driver); | |
897 | } | |
898 | ||
899 | return ret; | |
900 | } | |
901 | ||
902 | static void __exit xxxfb_exit(void) | |
903 | { | |
904 | platform_device_unregister(&xxxfb_device); | |
905 | driver_unregister(&xxxfb_driver); | |
906 | } | |
907 | #endif | |
908 | ||
909 | MODULE_LICENSE("GPL"); | |
910 | module_init(xxxfb_init); | |
911 | module_exit(xxxfb_exit); | |
912 | ||
913 | ||
1da177e4 LT |
914 | /* |
915 | * Setup | |
916 | */ | |
917 | ||
918 | /* | |
919 | * Only necessary if your driver takes special options, | |
920 | * otherwise we fall back on the generic fb_setup(). | |
921 | */ | |
922 | int __init xxxfb_setup(char *options) | |
923 | { | |
924 | /* Parse user speficied options (`video=xxxfb:') */ | |
925 | } | |
926 | ||
927 | /* ------------------------------------------------------------------------- */ | |
928 | ||
929 | /* | |
930 | * Frame buffer operations | |
931 | */ | |
932 | ||
933 | static struct fb_ops xxxfb_ops = { | |
934 | .owner = THIS_MODULE, | |
935 | .fb_open = xxxfb_open, | |
936 | .fb_read = xxxfb_read, | |
937 | .fb_write = xxxfb_write, | |
938 | .fb_release = xxxfb_release, | |
939 | .fb_check_var = xxxfb_check_var, | |
940 | .fb_set_par = xxxfb_set_par, | |
941 | .fb_setcolreg = xxxfb_setcolreg, | |
942 | .fb_blank = xxxfb_blank, | |
943 | .fb_pan_display = xxxfb_pan_display, | |
944 | .fb_fillrect = xxxfb_fillrect, /* Needed !!! */ | |
945 | .fb_copyarea = xxxfb_copyarea, /* Needed !!! */ | |
946 | .fb_imageblit = xxxfb_imageblit, /* Needed !!! */ | |
c465e05a | 947 | .fb_cursor = xxxfb_cursor, /* Optional !!! */ |
1da177e4 LT |
948 | .fb_rotate = xxxfb_rotate, |
949 | .fb_poll = xxxfb_poll, | |
950 | .fb_sync = xxxfb_sync, | |
951 | .fb_ioctl = xxxfb_ioctl, | |
952 | .fb_mmap = xxxfb_mmap, | |
953 | }; | |
954 | ||
955 | /* ------------------------------------------------------------------------- */ | |
956 | ||
957 | ||
958 | /* | |
959 | * Modularization | |
960 | */ | |
961 | ||
962 | module_init(xxxfb_init); | |
963 | module_exit(xxxfb_cleanup); | |
964 | ||
965 | MODULE_LICENSE("GPL"); |