sata_nv: propagate ata_pci_device_do_resume return value
[pv_ops_mirror.git] / drivers / video / skeletonfb.c
blobbb96cb65fdaa554204e104d7cb8fb12fd4e33e0f
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/slab.h>
51 #include <linux/delay.h>
52 #include <linux/fb.h>
53 #include <linux/init.h>
56 * This is just simple sample code.
58 * No warranty that it actually compiles.
59 * Even less warranty that it actually works :-)
63 * If your driver supports multiple boards, you should make the
64 * below data types arrays, or allocate them dynamically (using kmalloc()).
65 */
67 /*
68 * This structure defines the hardware state of the graphics card. Normally
69 * you place this in a header file in linux/include/video. This file usually
70 * also includes register information. That allows other driver subsystems
71 * and userland applications the ability to use the same header file to
72 * avoid duplicate work and easy porting of software.
74 struct xxx_par;
77 * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
78 * if we don't use modedb. If we do use modedb see xxxfb_init how to use it
79 * to get a fb_var_screeninfo. Otherwise define a default var as well.
81 static struct fb_fix_screeninfo xxxfb_fix __initdata = {
82 .id = "FB's name",
83 .type = FB_TYPE_PACKED_PIXELS,
84 .visual = FB_VISUAL_PSEUDOCOLOR,
85 .xpanstep = 1,
86 .ypanstep = 1,
87 .ywrapstep = 1,
88 .accel = FB_ACCEL_NONE,
92 * Modern graphical hardware not only supports pipelines but some
93 * also support multiple monitors where each display can have its
94 * its own unique data. In this case each display could be
95 * represented by a separate framebuffer device thus a separate
96 * struct fb_info. Now the struct xxx_par represents the graphics
97 * hardware state thus only one exist per card. In this case the
98 * struct xxx_par for each graphics card would be shared between
99 * every struct fb_info that represents a framebuffer on that card.
100 * This allows when one display changes it video resolution (info->var)
101 * the other displays know instantly. Each display can always be
102 * aware of the entire hardware state that affects it because they share
103 * the same xxx_par struct. The other side of the coin is multiple
104 * graphics cards that pass data around until it is finally displayed
105 * on one monitor. Such examples are the voodoo 1 cards and high end
106 * NUMA graphics servers. For this case we have a bunch of pars, each
107 * one that represents a graphics state, that belong to one struct
108 * fb_info. Their you would want to have *par point to a array of device
109 * states and have each struct fb_ops function deal with all those
110 * states. I hope this covers every possible hardware design. If not
111 * feel free to send your ideas at jsimmons@users.sf.net
115 * If your driver supports multiple boards or it supports multiple
116 * framebuffers, you should make these arrays, or allocate them
117 * dynamically using framebuffer_alloc() and free them with
118 * framebuffer_release().
120 static struct fb_info info;
123 * Each one represents the state of the hardware. Most hardware have
124 * just one hardware state. These here represent the default state(s).
126 static struct xxx_par __initdata current_par;
128 int xxxfb_init(void);
129 int xxxfb_setup(char*);
132 * xxxfb_open - Optional function. Called when the framebuffer is
133 * first accessed.
134 * @info: frame buffer structure that represents a single frame buffer
135 * @user: tell us if the userland (value=1) or the console is accessing
136 * the framebuffer.
138 * This function is the first function called in the framebuffer api.
139 * Usually you don't need to provide this function. The case where it
140 * is used is to change from a text mode hardware state to a graphics
141 * mode state.
143 * Returns negative errno on error, or zero on success.
145 static int xxxfb_open(const struct fb_info *info, int user)
147 return 0;
151 * xxxfb_release - Optional function. Called when the framebuffer
152 * device is closed.
153 * @info: frame buffer structure that represents a single frame buffer
154 * @user: tell us if the userland (value=1) or the console is accessing
155 * the framebuffer.
157 * Thus function is called when we close /dev/fb or the framebuffer
158 * console system is released. Usually you don't need this function.
159 * The case where it is usually used is to go from a graphics state
160 * to a text mode state.
162 * Returns negative errno on error, or zero on success.
164 static int xxxfb_release(const struct fb_info *info, int user)
166 return 0;
170 * xxxfb_check_var - Optional function. Validates a var passed in.
171 * @var: frame buffer variable screen structure
172 * @info: frame buffer structure that represents a single frame buffer
174 * Checks to see if the hardware supports the state requested by
175 * var passed in. This function does not alter the hardware state!!!
176 * This means the data stored in struct fb_info and struct xxx_par do
177 * not change. This includes the var inside of struct fb_info.
178 * Do NOT change these. This function can be called on its own if we
179 * intent to only test a mode and not actually set it. The stuff in
180 * modedb.c is a example of this. If the var passed in is slightly
181 * off by what the hardware can support then we alter the var PASSED in
182 * to what we can do.
184 * For values that are off, this function must round them _up_ to the
185 * next value that is supported by the hardware. If the value is
186 * greater than the highest value supported by the hardware, then this
187 * function must return -EINVAL.
189 * Exception to the above rule: Some drivers have a fixed mode, ie,
190 * the hardware is already set at boot up, and cannot be changed. In
191 * this case, it is more acceptable that this function just return
192 * a copy of the currently working var (info->var). Better is to not
193 * implement this function, as the upper layer will do the copying
194 * of the current var for you.
196 * Note: This is the only function where the contents of var can be
197 * freely adjusted after the driver has been registered. If you find
198 * that you have code outside of this function that alters the content
199 * of var, then you are doing something wrong. Note also that the
200 * contents of info->var must be left untouched at all times after
201 * driver registration.
203 * Returns negative errno on error, or zero on success.
205 static int xxxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
207 /* ... */
208 return 0;
212 * xxxfb_set_par - Optional function. Alters the hardware state.
213 * @info: frame buffer structure that represents a single frame buffer
215 * Using the fb_var_screeninfo in fb_info we set the resolution of the
216 * this particular framebuffer. This function alters the par AND the
217 * fb_fix_screeninfo stored in fb_info. It doesn't not alter var in
218 * fb_info since we are using that data. This means we depend on the
219 * data in var inside fb_info to be supported by the hardware.
221 * This function is also used to recover/restore the hardware to a
222 * known working state.
224 * xxxfb_check_var is always called before xxxfb_set_par to ensure that
225 * the contents of var is always valid.
227 * Again if you can't change the resolution you don't need this function.
229 * However, even if your hardware does not support mode changing,
230 * a set_par might be needed to at least initialize the hardware to
231 * a known working state, especially if it came back from another
232 * process that also modifies the same hardware, such as X.
234 * If this is the case, a combination such as the following should work:
236 * static int xxxfb_check_var(struct fb_var_screeninfo *var,
237 * struct fb_info *info)
239 * *var = info->var;
240 * return 0;
243 * static int xxxfb_set_par(struct fb_info *info)
245 * init your hardware here
248 * Returns negative errno on error, or zero on success.
250 static int xxxfb_set_par(struct fb_info *info)
252 struct xxx_par *par = info->par;
253 /* ... */
254 return 0;
258 * xxxfb_setcolreg - Optional function. Sets a color register.
259 * @regno: Which register in the CLUT we are programming
260 * @red: The red value which can be up to 16 bits wide
261 * @green: The green value which can be up to 16 bits wide
262 * @blue: The blue value which can be up to 16 bits wide.
263 * @transp: If supported, the alpha value which can be up to 16 bits wide.
264 * @info: frame buffer info structure
266 * Set a single color register. The values supplied have a 16 bit
267 * magnitude which needs to be scaled in this function for the hardware.
268 * Things to take into consideration are how many color registers, if
269 * any, are supported with the current color visual. With truecolor mode
270 * no color palettes are supported. Here a pseudo palette is created
271 * which we store the value in pseudo_palette in struct fb_info. For
272 * pseudocolor mode we have a limited color palette. To deal with this
273 * we can program what color is displayed for a particular pixel value.
274 * DirectColor is similar in that we can program each color field. If
275 * we have a static colormap we don't need to implement this function.
277 * Returns negative errno on error, or zero on success.
279 static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
280 unsigned blue, unsigned transp,
281 const struct fb_info *info)
283 if (regno >= 256) /* no. of hw registers */
284 return -EINVAL;
286 * Program hardware... do anything you want with transp
289 /* grayscale works only partially under directcolor */
290 if (info->var.grayscale) {
291 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
292 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
295 /* Directcolor:
296 * var->{color}.offset contains start of bitfield
297 * var->{color}.length contains length of bitfield
298 * {hardwarespecific} contains width of DAC
299 * pseudo_palette[X] is programmed to (X << red.offset) |
300 * (X << green.offset) |
301 * (X << blue.offset)
302 * RAMDAC[X] is programmed to (red, green, blue)
303 * color depth = SUM(var->{color}.length)
305 * Pseudocolor:
306 * var->{color}.offset is 0
307 * var->{color}.length contains width of DAC or the number of unique
308 * colors available (color depth)
309 * pseudo_palette is not used
310 * RAMDAC[X] is programmed to (red, green, blue)
311 * color depth = var->{color}.length
313 * Static pseudocolor:
314 * same as Pseudocolor, but the RAMDAC is not programmed (read-only)
316 * Mono01/Mono10:
317 * Has only 2 values, black on white or white on black (fg on bg),
318 * var->{color}.offset is 0
319 * white = (1 << var->{color}.length) - 1, black = 0
320 * pseudo_palette is not used
321 * RAMDAC does not exist
322 * color depth is always 2
324 * Truecolor:
325 * does not use RAMDAC (usually has 3 of them).
326 * var->{color}.offset contains start of bitfield
327 * var->{color}.length contains length of bitfield
328 * pseudo_palette is programmed to (red << red.offset) |
329 * (green << green.offset) |
330 * (blue << blue.offset) |
331 * (transp << transp.offset)
332 * RAMDAC does not exist
333 * color depth = SUM(var->{color}.length})
335 * The color depth is used by fbcon for choosing the logo and also
336 * for color palette transformation if color depth < 4
338 * As can be seen from the above, the field bits_per_pixel is _NOT_
339 * a criteria for describing the color visual.
341 * A common mistake is assuming that bits_per_pixel <= 8 is pseudocolor,
342 * and higher than that, true/directcolor. This is incorrect, one needs
343 * to look at the fix->visual.
345 * Another common mistake is using bits_per_pixel to calculate the color
346 * depth. The bits_per_pixel field does not directly translate to color
347 * depth. You have to compute for the color depth (using the color
348 * bitfields) and fix->visual as seen above.
352 * This is the point where the color is converted to something that
353 * is acceptable by the hardware.
355 #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
356 red = CNVT_TOHW(red, info->var.red.length);
357 green = CNVT_TOHW(green, info->var.green.length);
358 blue = CNVT_TOHW(blue, info->var.blue.length);
359 transp = CNVT_TOHW(transp, info->var.transp.length);
360 #undef CNVT_TOHW
362 * This is the point where the function feeds the color to the hardware
363 * palette after converting the colors to something acceptable by
364 * the hardware. Note, only FB_VISUAL_DIRECTCOLOR and
365 * FB_VISUAL_PSEUDOCOLOR visuals need to write to the hardware palette.
366 * If you have code that writes to the hardware CLUT, and it's not
367 * any of the above visuals, then you are doing something wrong.
369 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR ||
370 info->fix.visual == FB_VISUAL_TRUECOLOR)
371 write_{red|green|blue|transp}_to_clut();
373 /* This is the point were you need to fill up the contents of
374 * info->pseudo_palette. This structure is used _only_ by fbcon, thus
375 * it only contains 16 entries to match the number of colors supported
376 * by the console. The pseudo_palette is used only if the visual is
377 * in directcolor or truecolor mode. With other visuals, the
378 * pseudo_palette is not used. (This might change in the future.)
380 * The contents of the pseudo_palette is in raw pixel format. Ie, each
381 * entry can be written directly to the framebuffer without any conversion.
382 * The pseudo_palette is (void *). However, if using the generic
383 * drawing functions (cfb_imageblit, cfb_fillrect), the pseudo_palette
384 * must be casted to (u32 *) _regardless_ of the bits per pixel. If the
385 * driver is using its own drawing functions, then it can use whatever
386 * size it wants.
388 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
389 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
390 u32 v;
392 if (regno >= 16)
393 return -EINVAL;
395 v = (red << info->var.red.offset) |
396 (green << info->var.green.offset) |
397 (blue << info->var.blue.offset) |
398 (transp << info->var.transp.offset);
400 ((u32*)(info->pseudo_palette))[regno] = v;
403 /* ... */
404 return 0;
408 * xxxfb_pan_display - NOT a required function. Pans the display.
409 * @var: frame buffer variable screen structure
410 * @info: frame buffer structure that represents a single frame buffer
412 * Pan (or wrap, depending on the `vmode' field) the display using the
413 * `xoffset' and `yoffset' fields of the `var' structure.
414 * If the values don't fit, return -EINVAL.
416 * Returns negative errno on error, or zero on success.
418 static int xxxfb_pan_display(struct fb_var_screeninfo *var,
419 const struct fb_info *info)
422 * If your hardware does not support panning, _do_ _not_ implement this
423 * function. Creating a dummy function will just confuse user apps.
427 * Note that even if this function is fully functional, a setting of
428 * 0 in both xpanstep and ypanstep means that this function will never
429 * get called.
432 /* ... */
433 return 0;
437 * xxxfb_blank - NOT a required function. Blanks the display.
438 * @blank_mode: the blank mode we want.
439 * @info: frame buffer structure that represents a single frame buffer
441 * Blank the screen if blank_mode != FB_BLANK_UNBLANK, else unblank.
442 * Return 0 if blanking succeeded, != 0 if un-/blanking failed due to
443 * e.g. a video mode which doesn't support it.
445 * Implements VESA suspend and powerdown modes on hardware that supports
446 * disabling hsync/vsync:
448 * FB_BLANK_NORMAL = display is blanked, syncs are on.
449 * FB_BLANK_HSYNC_SUSPEND = hsync off
450 * FB_BLANK_VSYNC_SUSPEND = vsync off
451 * FB_BLANK_POWERDOWN = hsync and vsync off
453 * If implementing this function, at least support FB_BLANK_UNBLANK.
454 * Return !0 for any modes that are unimplemented.
457 static int xxxfb_blank(int blank_mode, const struct fb_info *info)
459 /* ... */
460 return 0;
463 /* ------------ Accelerated Functions --------------------- */
466 * We provide our own functions if we have hardware acceleration
467 * or non packed pixel format layouts. If we have no hardware
468 * acceleration, we can use a generic unaccelerated function. If using
469 * a pack pixel format just use the functions in cfb_*.c. Each file
470 * has one of the three different accel functions we support.
474 * xxxfb_fillrect - REQUIRED function. Can use generic routines if
475 * non acclerated hardware and packed pixel based.
476 * Draws a rectangle on the screen.
478 * @info: frame buffer structure that represents a single frame buffer
479 * @region: The structure representing the rectangular region we
480 * wish to draw to.
482 * This drawing operation places/removes a retangle on the screen
483 * depending on the rastering operation with the value of color which
484 * is in the current color depth format.
486 void xxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region)
488 /* Meaning of struct fb_fillrect
490 * @dx: The x and y corrdinates of the upper left hand corner of the
491 * @dy: area we want to draw to.
492 * @width: How wide the rectangle is we want to draw.
493 * @height: How tall the rectangle is we want to draw.
494 * @color: The color to fill in the rectangle with.
495 * @rop: The raster operation. We can draw the rectangle with a COPY
496 * of XOR which provides erasing effect.
501 * xxxfb_copyarea - REQUIRED function. Can use generic routines if
502 * non acclerated hardware and packed pixel based.
503 * Copies one area of the screen to another area.
505 * @info: frame buffer structure that represents a single frame buffer
506 * @area: Structure providing the data to copy the framebuffer contents
507 * from one region to another.
509 * This drawing operation copies a rectangular area from one area of the
510 * screen to another area.
512 void xxxfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
515 * @dx: The x and y coordinates of the upper left hand corner of the
516 * @dy: destination area on the screen.
517 * @width: How wide the rectangle is we want to copy.
518 * @height: How tall the rectangle is we want to copy.
519 * @sx: The x and y coordinates of the upper left hand corner of the
520 * @sy: source area on the screen.
526 * xxxfb_imageblit - REQUIRED function. Can use generic routines if
527 * non acclerated hardware and packed pixel based.
528 * Copies a image from system memory to the screen.
530 * @info: frame buffer structure that represents a single frame buffer
531 * @image: structure defining the image.
533 * This drawing operation draws a image on the screen. It can be a
534 * mono image (needed for font handling) or a color image (needed for
535 * tux).
537 void xxxfb_imageblit(struct fb_info *p, const struct fb_image *image)
540 * @dx: The x and y coordinates of the upper left hand corner of the
541 * @dy: destination area to place the image on the screen.
542 * @width: How wide the image is we want to copy.
543 * @height: How tall the image is we want to copy.
544 * @fg_color: For mono bitmap images this is color data for
545 * @bg_color: the foreground and background of the image to
546 * write directly to the frmaebuffer.
547 * @depth: How many bits represent a single pixel for this image.
548 * @data: The actual data used to construct the image on the display.
549 * @cmap: The colormap used for color images.
553 * The generic function, cfb_imageblit, expects that the bitmap scanlines are
554 * padded to the next byte. Most hardware accelerators may require padding to
555 * the next u16 or the next u32. If that is the case, the driver can specify
556 * this by setting info->pixmap.scan_align = 2 or 4. See a more
557 * comprehensive description of the pixmap below.
562 * xxxfb_cursor - OPTIONAL. If your hardware lacks support
563 * for a cursor, leave this field NULL.
565 * @info: frame buffer structure that represents a single frame buffer
566 * @cursor: structure defining the cursor to draw.
568 * This operation is used to set or alter the properities of the
569 * cursor.
571 * Returns negative errno on error, or zero on success.
573 int xxxfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
576 * @set: Which fields we are altering in struct fb_cursor
577 * @enable: Disable or enable the cursor
578 * @rop: The bit operation we want to do.
579 * @mask: This is the cursor mask bitmap.
580 * @dest: A image of the area we are going to display the cursor.
581 * Used internally by the driver.
582 * @hot: The hot spot.
583 * @image: The actual data for the cursor image.
585 * NOTES ON FLAGS (cursor->set):
587 * FB_CUR_SETIMAGE - the cursor image has changed (cursor->image.data)
588 * FB_CUR_SETPOS - the cursor position has changed (cursor->image.dx|dy)
589 * FB_CUR_SETHOT - the cursor hot spot has changed (cursor->hot.dx|dy)
590 * FB_CUR_SETCMAP - the cursor colors has changed (cursor->fg_color|bg_color)
591 * FB_CUR_SETSHAPE - the cursor bitmask has changed (cursor->mask)
592 * FB_CUR_SETSIZE - the cursor size has changed (cursor->width|height)
593 * FB_CUR_SETALL - everything has changed
595 * NOTES ON ROPs (cursor->rop, Raster Operation)
597 * ROP_XOR - cursor->image.data XOR cursor->mask
598 * ROP_COPY - curosr->image.data AND cursor->mask
600 * OTHER NOTES:
602 * - fbcon only supports a 2-color cursor (cursor->image.depth = 1)
603 * - The fb_cursor structure, @cursor, _will_ always contain valid
604 * fields, whether any particular bitfields in cursor->set is set
605 * or not.
610 * xxxfb_rotate - NOT a required function. If your hardware
611 * supports rotation the whole screen then
612 * you would provide a hook for this.
614 * @info: frame buffer structure that represents a single frame buffer
615 * @angle: The angle we rotate the screen.
617 * This operation is used to set or alter the properities of the
618 * cursor.
620 void xxxfb_rotate(struct fb_info *info, int angle)
622 /* Will be deprecated */
626 * xxxfb_poll - NOT a required function. The purpose of this
627 * function is to provide a way for some process
628 * to wait until a specific hardware event occurs
629 * for the framebuffer device.
631 * @info: frame buffer structure that represents a single frame buffer
632 * @wait: poll table where we store process that await a event.
634 void xxxfb_poll(struct fb_info *info, poll_table *wait)
639 * xxxfb_sync - NOT a required function. Normally the accel engine
640 * for a graphics card take a specific amount of time.
641 * Often we have to wait for the accelerator to finish
642 * its operation before we can write to the framebuffer
643 * so we can have consistent display output.
645 * @info: frame buffer structure that represents a single frame buffer
647 * If the driver has implemented its own hardware-based drawing function,
648 * implementing this function is highly recommended.
650 void xxxfb_sync(struct fb_info *info)
655 * Initialization
658 /* static int __init xxfb_probe (struct device *device) -- for platform devs */
659 static int __init xxxfb_probe(struct pci_dev *dev,
660 const_struct pci_device_id *ent)
662 struct fb_info *info;
663 struct xxx_par *par;
664 struct device = &dev->dev; /* for pci drivers */
665 int cmap_len, retval;
668 * Dynamically allocate info and par
670 info = framebuffer_alloc(sizeof(struct xxx_par), device);
672 if (!info) {
673 /* goto error path */
676 par = info->par;
679 * Here we set the screen_base to the virtual memory address
680 * for the framebuffer. Usually we obtain the resource address
681 * from the bus layer and then translate it to virtual memory
682 * space via ioremap. Consult ioport.h.
684 info->screen_base = framebuffer_virtual_memory;
685 info->fbops = &xxxfb_ops;
686 info->fix = xxxfb_fix; /* this will be the only time xxxfb_fix will be
687 * used, so mark it as __initdata
689 info->pseudo_palette = pseudo_palette; /* The pseudopalette is an
690 * 16-member array
693 * Set up flags to indicate what sort of acceleration your
694 * driver can provide (pan/wrap/copyarea/etc.) and whether it
695 * is a module -- see FBINFO_* in include/linux/fb.h
697 * If your hardware can support any of the hardware accelerated functions
698 * fbcon performance will improve if info->flags is set properly.
700 * FBINFO_HWACCEL_COPYAREA - hardware moves
701 * FBINFO_HWACCEL_FILLRECT - hardware fills
702 * FBINFO_HWACCEL_IMAGEBLIT - hardware mono->color expansion
703 * FBINFO_HWACCEL_YPAN - hardware can pan display in y-axis
704 * FBINFO_HWACCEL_YWRAP - hardware can wrap display in y-axis
705 * FBINFO_HWACCEL_DISABLED - supports hardware accels, but disabled
706 * FBINFO_READS_FAST - if set, prefer moves over mono->color expansion
707 * FBINFO_MISC_TILEBLITTING - hardware can do tile blits
709 * NOTE: These are for fbcon use only.
711 info->flags = FBINFO_DEFAULT;
713 /********************* This stage is optional ******************************/
715 * The struct pixmap is a scratch pad for the drawing functions. This
716 * is where the monochrome bitmap is constructed by the higher layers
717 * and then passed to the accelerator. For drivers that uses
718 * cfb_imageblit, you can skip this part. For those that have a more
719 * rigorous requirement, this stage is needed
722 /* PIXMAP_SIZE should be small enough to optimize drawing, but not
723 * large enough that memory is wasted. A safe size is
724 * (max_xres * max_font_height/8). max_xres is driver dependent,
725 * max_font_height is 32.
727 info->pixmap.addr = kmalloc(PIXMAP_SIZE, GFP_KERNEL);
728 if (!info->pixmap.addr) {
729 /* goto error */
732 info->pixmap.size = PIXMAP_SIZE;
735 * FB_PIXMAP_SYSTEM - memory is in system ram
736 * FB_PIXMAP_IO - memory is iomapped
737 * FB_PIXMAP_SYNC - if set, will call fb_sync() per access to pixmap,
738 * usually if FB_PIXMAP_IO is set.
740 * Currently, FB_PIXMAP_IO is unimplemented.
742 info->pixmap.flags = FB_PIXMAP_SYSTEM;
745 * scan_align is the number of padding for each scanline. It is in bytes.
746 * Thus for accelerators that need padding to the next u32, put 4 here.
748 info->pixmap.scan_align = 4;
751 * buf_align is the amount to be padded for the buffer. For example,
752 * the i810fb needs a scan_align of 2 but expects it to be fed with
753 * dwords, so a buf_align = 4 is required.
755 info->pixmap.buf_align = 4;
757 /* access_align is how many bits can be accessed from the framebuffer
758 * ie. some epson cards allow 16-bit access only. Most drivers will
759 * be safe with u32 here.
761 * NOTE: This field is currently unused.
763 info->pixmap.scan_align = 32
764 /***************************** End optional stage ***************************/
767 * This should give a reasonable default video mode. The following is
768 * done when we can set a video mode.
770 if (!mode_option)
771 mode_option = "640x480@60";
773 retval = fb_find_mode(info->var, info, mode_option, NULL, 0, NULL, 8);
775 if (!retval || retval == 4)
776 return -EINVAL;
778 /* This has to been done !!! */
779 fb_alloc_cmap(info->cmap, cmap_len, 0);
782 * The following is done in the case of having hardware with a static
783 * mode. If we are setting the mode ourselves we don't call this.
785 info->var = xxxfb_var;
788 * For drivers that can...
790 xxxfb_check_var(&info->var, info);
793 * Does a call to fb_set_par() before register_framebuffer needed? This
794 * will depend on you and the hardware. If you are sure that your driver
795 * is the only device in the system, a call to fb_set_par() is safe.
797 * Hardware in x86 systems has a VGA core. Calling set_par() at this
798 * point will corrupt the VGA console, so it might be safer to skip a
799 * call to set_par here and just allow fbcon to do it for you.
801 /* xxxfb_set_par(info); */
803 if (register_framebuffer(info) < 0)
804 return -EINVAL;
805 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
806 info->fix.id);
807 pci_set_drvdata(dev, info); /* or dev_set_drvdata(device, info) */
808 return 0;
812 * Cleanup
814 /* static void __exit xxxfb_remove(struct device *device) */
815 static void __exit xxxfb_remove(struct pci_dev *dev)
817 struct fb_info *info = pci_get_drv_data(dev);
818 /* or dev_get_drv_data(device); */
820 if (info) {
821 unregister_framebuffer(info);
822 fb_dealloc_cmap(&info.cmap);
823 /* ... */
824 framebuffer_release(info);
827 return 0;
830 #if CONFIG_PCI
831 /* For PCI drivers */
832 static struct pci_driver xxxfb_driver = {
833 .name = "xxxfb",
834 .id_table = xxxfb_devices,
835 .probe = xxxfb_probe,
836 .remove = __devexit_p(xxxfb_remove),
837 .suspend = xxxfb_suspend, /* optional */
838 .resume = xxxfb_resume, /* optional */
841 static int __init xxxfb_init(void)
844 * For kernel boot options (in 'video=xxxfb:<options>' format)
846 #ifndef MODULE
847 char *option = NULL;
849 if (fb_get_options("xxxfb", &option))
850 return -ENODEV;
851 xxxfb_setup(option);
852 #endif
854 return pci_register_driver(&xxxfb_driver);
857 static void __exit xxxfb_exit(void)
859 pci_unregister_driver(&xxxfb_driver);
861 #else
862 #include <linux/platform_device.h>
863 /* for platform devices */
864 static struct device_driver xxxfb_driver = {
865 .name = "xxxfb",
866 .bus = &platform_bus_type,
867 .probe = xxxfb_probe,
868 .remove = xxxfb_remove,
869 .suspend = xxxfb_suspend, /* optional */
870 .resume = xxxfb_resume, /* optional */
873 static struct platform_device xxxfb_device = {
874 .name = "xxxfb",
877 static int __init xxxfb_init(void)
879 int ret;
881 * For kernel boot options (in 'video=xxxfb:<options>' format)
883 #ifndef MODULE
884 char *option = NULL;
886 if (fb_get_options("xxxfb", &option))
887 return -ENODEV;
888 xxxfb_setup(option);
889 #endif
890 ret = driver_register(&xxxfb_driver);
892 if (!ret) {
893 ret = platform_device_register(&xxxfb_device);
894 if (ret)
895 driver_unregister(&xxxfb_driver);
898 return ret;
901 static void __exit xxxfb_exit(void)
903 platform_device_unregister(&xxxfb_device);
904 driver_unregister(&xxxfb_driver);
906 #endif
909 * Setup
913 * Only necessary if your driver takes special options,
914 * otherwise we fall back on the generic fb_setup().
916 int __init xxxfb_setup(char *options)
918 /* Parse user speficied options (`video=xxxfb:') */
921 /* ------------------------------------------------------------------------- */
924 * Frame buffer operations
927 static struct fb_ops xxxfb_ops = {
928 .owner = THIS_MODULE,
929 .fb_open = xxxfb_open,
930 .fb_read = xxxfb_read,
931 .fb_write = xxxfb_write,
932 .fb_release = xxxfb_release,
933 .fb_check_var = xxxfb_check_var,
934 .fb_set_par = xxxfb_set_par,
935 .fb_setcolreg = xxxfb_setcolreg,
936 .fb_blank = xxxfb_blank,
937 .fb_pan_display = xxxfb_pan_display,
938 .fb_fillrect = xxxfb_fillrect, /* Needed !!! */
939 .fb_copyarea = xxxfb_copyarea, /* Needed !!! */
940 .fb_imageblit = xxxfb_imageblit, /* Needed !!! */
941 .fb_cursor = xxxfb_cursor, /* Optional !!! */
942 .fb_rotate = xxxfb_rotate,
943 .fb_poll = xxxfb_poll,
944 .fb_sync = xxxfb_sync,
945 .fb_ioctl = xxxfb_ioctl,
946 .fb_mmap = xxxfb_mmap,
949 /* ------------------------------------------------------------------------- */
953 * Modularization
956 module_init(xxxfb_init);
957 module_exit(xxxfb_cleanup);
959 MODULE_LICENSE("GPL");