Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[wrt350n-kernel.git] / drivers / video / skeletonfb.c
blob9b707771d7578a5746fb71c1ded1ffaa63ae70b1
1 /*
2 * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device
4 * Modified to new api Jan 2001 by James Simmons (jsimmons@transvirtual.com)
6 * Created 28 Dec 1997 by Geert Uytterhoeven
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.
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.
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.
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.
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>
57 * This is just simple sample code.
59 * No warranty that it actually compiles.
60 * Even less warranty that it actually works :-)
64 * If your driver supports multiple boards, you should make the
65 * below data types arrays, or allocate them dynamically (using kmalloc()).
66 */
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.
75 struct xxx_par;
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.
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,
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
116 * If your driver supports multiple boards or it supports multiple
117 * framebuffers, you should make these arrays, or allocate them
118 * dynamically using framebuffer_alloc() and free them with
119 * framebuffer_release().
121 static struct fb_info info;
124 * Each one represents the state of the hardware. Most hardware have
125 * just one hardware state. These here represent the default state(s).
127 static struct xxx_par __initdata current_par;
129 int xxxfb_init(void);
130 int xxxfb_setup(char*);
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.
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.
144 * Returns negative errno on error, or zero on success.
146 static int xxxfb_open(const struct fb_info *info, int user)
148 return 0;
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.
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.
163 * Returns negative errno on error, or zero on success.
165 static int xxxfb_release(const struct fb_info *info, int user)
167 return 0;
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
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
183 * to what we can do.
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.
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.
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.
204 * Returns negative errno on error, or zero on success.
206 static int xxxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
208 /* ... */
209 return 0;
213 * xxxfb_set_par - Optional function. Alters the hardware state.
214 * @info: frame buffer structure that represents a single frame buffer
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.
222 * This function is also used to recover/restore the hardware to a
223 * known working state.
225 * xxxfb_check_var is always called before xxxfb_set_par to ensure that
226 * the contents of var is always valid.
228 * Again if you can't change the resolution you don't need this function.
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.
235 * If this is the case, a combination such as the following should work:
237 * static int xxxfb_check_var(struct fb_var_screeninfo *var,
238 * struct fb_info *info)
240 * *var = info->var;
241 * return 0;
244 * static int xxxfb_set_par(struct fb_info *info)
246 * init your hardware here
249 * Returns negative errno on error, or zero on success.
251 static int xxxfb_set_par(struct fb_info *info)
253 struct xxx_par *par = info->par;
254 /* ... */
255 return 0;
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
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.
278 * Returns negative errno on error, or zero on success.
280 static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
281 unsigned blue, unsigned transp,
282 const struct fb_info *info)
284 if (regno >= 256) /* no. of hw registers */
285 return -EINVAL;
287 * Program hardware... do anything you want with transp
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;
296 /* Directcolor:
297 * var->{color}.offset contains start of bitfield
298 * var->{color}.length contains length of bitfield
299 * {hardwarespecific} contains width of DAC
300 * pseudo_palette[X] is programmed to (X << red.offset) |
301 * (X << green.offset) |
302 * (X << blue.offset)
303 * RAMDAC[X] is programmed to (red, green, blue)
304 * color depth = SUM(var->{color}.length)
306 * Pseudocolor:
307 * var->{color}.offset is 0
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
314 * Static pseudocolor:
315 * same as Pseudocolor, but the RAMDAC is not programmed (read-only)
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
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
329 * pseudo_palette is programmed to (red << red.offset) |
330 * (green << green.offset) |
331 * (blue << blue.offset) |
332 * (transp << transp.offset)
333 * RAMDAC does not exist
334 * color depth = SUM(var->{color}.length})
336 * The color depth is used by fbcon for choosing the logo and also
337 * for color palette transformation if color depth < 4
339 * As can be seen from the above, the field bits_per_pixel is _NOT_
340 * a criteria for describing the color visual.
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.
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.
353 * This is the point where the color is converted to something that
354 * is acceptable by the hardware.
356 #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
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);
361 #undef CNVT_TOHW
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.
370 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR ||
371 info->fix.visual == FB_VISUAL_TRUECOLOR)
372 write_{red|green|blue|transp}_to_clut();
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.)
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.
389 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
390 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
391 u32 v;
393 if (regno >= 16)
394 return -EINVAL;
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);
401 ((u32*)(info->pseudo_palette))[regno] = v;
404 /* ... */
405 return 0;
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
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.
417 * Returns negative errno on error, or zero on success.
419 static int xxxfb_pan_display(struct fb_var_screeninfo *var,
420 const struct fb_info *info)
423 * If your hardware does not support panning, _do_ _not_ implement this
424 * function. Creating a dummy function will just confuse user apps.
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.
433 /* ... */
434 return 0;
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
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.
446 * Implements VESA suspend and powerdown modes on hardware that supports
447 * disabling hsync/vsync:
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
454 * If implementing this function, at least support FB_BLANK_UNBLANK.
455 * Return !0 for any modes that are unimplemented.
458 static int xxxfb_blank(int blank_mode, const struct fb_info *info)
460 /* ... */
461 return 0;
464 /* ------------ Accelerated Functions --------------------- */
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.
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.
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.
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.
487 void xxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region)
489 /* Meaning of struct fb_fillrect
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.
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.
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.
510 * This drawing operation copies a rectangular area from one area of the
511 * screen to another area.
513 void xxxfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
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.
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.
531 * @info: frame buffer structure that represents a single frame buffer
532 * @image: structure defining the image.
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).
538 void xxxfb_imageblit(struct fb_info *p, const struct fb_image *image)
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.
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.
563 * xxxfb_cursor - OPTIONAL. If your hardware lacks support
564 * for a cursor, leave this field NULL.
566 * @info: frame buffer structure that represents a single frame buffer
567 * @cursor: structure defining the cursor to draw.
569 * This operation is used to set or alter the properities of the
570 * cursor.
572 * Returns negative errno on error, or zero on success.
574 int xxxfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
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.
586 * NOTES ON FLAGS (cursor->set):
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
596 * NOTES ON ROPs (cursor->rop, Raster Operation)
598 * ROP_XOR - cursor->image.data XOR cursor->mask
599 * ROP_COPY - curosr->image.data AND cursor->mask
601 * OTHER NOTES:
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.
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.
615 * @info: frame buffer structure that represents a single frame buffer
616 * @angle: The angle we rotate the screen.
618 * This operation is used to set or alter the properities of the
619 * cursor.
621 void xxxfb_rotate(struct fb_info *info, int angle)
623 /* Will be deprecated */
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.
632 * @info: frame buffer structure that represents a single frame buffer
633 * @wait: poll table where we store process that await a event.
635 void xxxfb_poll(struct fb_info *info, poll_table *wait)
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.
646 * @info: frame buffer structure that represents a single frame buffer
648 * If the driver has implemented its own hardware-based drawing function,
649 * implementing this function is highly recommended.
651 void xxxfb_sync(struct fb_info *info)
656 * Initialization
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)
663 struct fb_info *info;
664 struct xxx_par *par;
665 struct device = &dev->dev; /* for pci drivers */
666 int cmap_len, retval;
669 * Dynamically allocate info and par
671 info = framebuffer_alloc(sizeof(struct xxx_par), device);
673 if (!info) {
674 /* goto error path */
677 par = info->par;
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.
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
690 info->pseudo_palette = pseudo_palette; /* The pseudopalette is an
691 * 16-member array
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
698 * If your hardware can support any of the hardware accelerated functions
699 * fbcon performance will improve if info->flags is set properly.
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
710 * NOTE: These are for fbcon use only.
712 info->flags = FBINFO_DEFAULT;
714 /********************* This stage is optional ******************************/
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
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.
728 info->pixmap.addr = kmalloc(PIXMAP_SIZE, GFP_KERNEL);
729 if (!info->pixmap.addr) {
730 /* goto error */
733 info->pixmap.size = PIXMAP_SIZE;
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.
741 * Currently, FB_PIXMAP_IO is unimplemented.
743 info->pixmap.flags = FB_PIXMAP_SYSTEM;
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.
749 info->pixmap.scan_align = 4;
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.
756 info->pixmap.buf_align = 4;
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.
762 * NOTE: This field is currently unused.
764 info->pixmap.scan_align = 32
765 /***************************** End optional stage ***************************/
768 * This should give a reasonable default video mode. The following is
769 * done when we can set a video mode.
771 if (!mode_option)
772 mode_option = "640x480@60";
774 retval = fb_find_mode(info->var, info, mode_option, NULL, 0, NULL, 8);
776 if (!retval || retval == 4)
777 return -EINVAL;
779 /* This has to been done !!! */
780 fb_alloc_cmap(info->cmap, cmap_len, 0);
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.
786 info->var = xxxfb_var;
789 * For drivers that can...
791 xxxfb_check_var(&info->var, info);
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.
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.
802 /* xxxfb_set_par(info); */
804 if (register_framebuffer(info) < 0)
805 return -EINVAL;
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) */
809 return 0;
813 * Cleanup
815 /* static void __exit xxxfb_remove(struct device *device) */
816 static void __exit xxxfb_remove(struct pci_dev *dev)
818 struct fb_info *info = pci_get_drv_data(dev);
819 /* or dev_get_drv_data(device); */
821 if (info) {
822 unregister_framebuffer(info);
823 fb_dealloc_cmap(&info.cmap);
824 /* ... */
825 framebuffer_release(info);
828 return 0;
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 */
842 static int __init xxxfb_init(void)
845 * For kernel boot options (in 'video=xxxfb:<options>' format)
847 #ifndef MODULE
848 char *option = NULL;
850 if (fb_get_options("xxxfb", &option))
851 return -ENODEV;
852 xxxfb_setup(option);
853 #endif
855 return pci_register_driver(&xxxfb_driver);
858 static void __exit xxxfb_exit(void)
860 pci_unregister_driver(&xxxfb_driver);
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 */
874 static struct platform_device xxxfb_device = {
875 .name = "xxxfb",
878 static int __init xxxfb_init(void)
880 int ret;
882 * For kernel boot options (in 'video=xxxfb:<options>' format)
884 #ifndef MODULE
885 char *option = NULL;
887 if (fb_get_options("xxxfb", &option))
888 return -ENODEV;
889 xxxfb_setup(option);
890 #endif
891 ret = driver_register(&xxxfb_driver);
893 if (!ret) {
894 ret = platform_device_register(&xxxfb_device);
895 if (ret)
896 driver_unregister(&xxxfb_driver);
899 return ret;
902 static void __exit xxxfb_exit(void)
904 platform_device_unregister(&xxxfb_device);
905 driver_unregister(&xxxfb_driver);
907 #endif
909 MODULE_LICENSE("GPL");
910 module_init(xxxfb_init);
911 module_exit(xxxfb_exit);
915 * Setup
919 * Only necessary if your driver takes special options,
920 * otherwise we fall back on the generic fb_setup().
922 int __init xxxfb_setup(char *options)
924 /* Parse user speficied options (`video=xxxfb:') */
927 /* ------------------------------------------------------------------------- */
930 * Frame buffer operations
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 !!! */
947 .fb_cursor = xxxfb_cursor, /* Optional !!! */
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,
955 /* ------------------------------------------------------------------------- */
959 * Modularization
962 module_init(xxxfb_init);
963 module_exit(xxxfb_cleanup);
965 MODULE_LICENSE("GPL");