blob: bb96cb65fdaa554204e104d7cb8fb12fd4e33e0f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/slab.h>
51#include <linux/delay.h>
52#include <linux/fb.h>
53#include <linux/init.h>
54
55 /*
56 * This is just simple sample code.
57 *
58 * No warranty that it actually compiles.
59 * Even less warranty that it actually works :-)
60 */
61
62/*
63 * If your driver supports multiple boards, you should make the
64 * below data types arrays, or allocate them dynamically (using kmalloc()).
65 */
66
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.
73 */
74struct xxx_par;
75
76/*
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.
80 */
81static 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,
89};
90
91 /*
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
112 */
113
114 /*
115 * If your driver supports multiple boards or it supports multiple
116 * framebuffers, you should make these arrays, or allocate them
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800117 * dynamically using framebuffer_alloc() and free them with
118 * framebuffer_release().
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 */
120static struct fb_info info;
121
122 /*
123 * Each one represents the state of the hardware. Most hardware have
124 * just one hardware state. These here represent the default state(s).
125 */
126static struct xxx_par __initdata current_par;
127
128int xxxfb_init(void);
129int xxxfb_setup(char*);
130
131/**
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.
137 *
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.
142 *
143 * Returns negative errno on error, or zero on success.
144 */
145static int xxxfb_open(const struct fb_info *info, int user)
146{
147 return 0;
148}
149
150/**
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.
156 *
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.
161 *
162 * Returns negative errno on error, or zero on success.
163 */
164static int xxxfb_release(const struct fb_info *info, int user)
165{
166 return 0;
167}
168
169/**
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
173 *
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
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800182 * to what we can do.
183 *
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.
188 *
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.
195 *
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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 *
203 * Returns negative errno on error, or zero on success.
204 */
205static int xxxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
206{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 /* ... */
208 return 0;
209}
210
211/**
212 * xxxfb_set_par - Optional function. Alters the hardware state.
213 * @info: frame buffer structure that represents a single frame buffer
214 *
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.
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800220 *
221 * This function is also used to recover/restore the hardware to a
222 * known working state.
223 *
224 * xxxfb_check_var is always called before xxxfb_set_par to ensure that
225 * the contents of var is always valid.
226 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 * Again if you can't change the resolution you don't need this function.
228 *
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800229 * 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.
233 *
234 * If this is the case, a combination such as the following should work:
235 *
236 * static int xxxfb_check_var(struct fb_var_screeninfo *var,
237 * struct fb_info *info)
238 * {
239 * *var = info->var;
240 * return 0;
241 * }
242 *
243 * static int xxxfb_set_par(struct fb_info *info)
244 * {
245 * init your hardware here
246 * }
247 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 * Returns negative errno on error, or zero on success.
249 */
250static int xxxfb_set_par(struct fb_info *info)
251{
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800252 struct xxx_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 /* ... */
254 return 0;
255}
256
257/**
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
265 *
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.
276 *
277 * Returns negative errno on error, or zero on success.
278 */
279static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
280 unsigned blue, unsigned transp,
281 const struct fb_info *info)
282{
283 if (regno >= 256) /* no. of hw registers */
284 return -EINVAL;
285 /*
286 * Program hardware... do anything you want with transp
287 */
288
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;
293 }
294
295 /* Directcolor:
296 * var->{color}.offset contains start of bitfield
297 * var->{color}.length contains length of bitfield
298 * {hardwarespecific} contains width of DAC
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800299 * pseudo_palette[X] is programmed to (X << red.offset) |
300 * (X << green.offset) |
301 * (X << blue.offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 * RAMDAC[X] is programmed to (red, green, blue)
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800303 * color depth = SUM(var->{color}.length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 *
305 * Pseudocolor:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 * var->{color}.offset is 0
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800307 * 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
312 *
313 * Static pseudocolor:
314 * same as Pseudocolor, but the RAMDAC is not programmed (read-only)
315 *
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
323 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 * 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
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800328 * pseudo_palette is programmed to (red << red.offset) |
329 * (green << green.offset) |
330 * (blue << blue.offset) |
331 * (transp << transp.offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 * RAMDAC does not exist
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800333 * color depth = SUM(var->{color}.length})
334 *
335 * The color depth is used by fbcon for choosing the logo and also
336 * for color palette transformation if color depth < 4
337 *
338 * As can be seen from the above, the field bits_per_pixel is _NOT_
339 * a criteria for describing the color visual.
340 *
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.
344 *
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.
349 */
350
351 /*
352 * This is the point where the color is converted to something that
353 * is acceptable by the hardware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 */
355#define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800356 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360#undef CNVT_TOHW
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800361 /*
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.
368 */
369 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR ||
370 info->fix.visual == FB_VISUAL_TRUECOLOR)
371 write_{red|green|blue|transp}_to_clut();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800373 /* 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.)
379 *
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.
387 */
388 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
389 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
390 u32 v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800392 if (regno >= 16)
393 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800395 v = (red << info->var.red.offset) |
396 (green << info->var.green.offset) |
397 (blue << info->var.blue.offset) |
398 (transp << info->var.transp.offset);
399
400 ((u32*)(info->pseudo_palette))[regno] = v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 }
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 /* ... */
404 return 0;
405}
406
407/**
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
411 *
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.
415 *
416 * Returns negative errno on error, or zero on success.
417 */
418static int xxxfb_pan_display(struct fb_var_screeninfo *var,
419 const struct fb_info *info)
420{
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800421 /*
422 * If your hardware does not support panning, _do_ _not_ implement this
423 * function. Creating a dummy function will just confuse user apps.
424 */
425
426 /*
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.
430 */
431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 /* ... */
433 return 0;
434}
435
436/**
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
440 *
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800441 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 *
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800445 * Implements VESA suspend and powerdown modes on hardware that supports
446 * disabling hsync/vsync:
447 *
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
452 *
453 * If implementing this function, at least support FB_BLANK_UNBLANK.
454 * Return !0 for any modes that are unimplemented.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 *
456 */
457static int xxxfb_blank(int blank_mode, const struct fb_info *info)
458{
459 /* ... */
460 return 0;
461}
462
463/* ------------ Accelerated Functions --------------------- */
464
465/*
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.
471 */
472
473/**
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.
477 *
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.
481 *
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.
485 */
486void xxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region)
487{
488/* Meaning of struct fb_fillrect
489 *
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.
497 */
498}
499
500/**
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.
504 *
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.
508 *
509 * This drawing operation copies a rectangular area from one area of the
510 * screen to another area.
511 */
512void xxxfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
513{
514/*
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.
521 */
522}
523
524
525/**
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.
529 *
530 * @info: frame buffer structure that represents a single frame buffer
531 * @image: structure defining the image.
532 *
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).
536 */
537void xxxfb_imageblit(struct fb_info *p, const struct fb_image *image)
538{
539/*
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.
550 */
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800551
552/*
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.
558 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559}
560
561/**
Antonino A. Daplasc465e052005-11-07 01:00:35 -0800562 * xxxfb_cursor - OPTIONAL. If your hardware lacks support
563 * for a cursor, leave this field NULL.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 *
565 * @info: frame buffer structure that represents a single frame buffer
566 * @cursor: structure defining the cursor to draw.
567 *
568 * This operation is used to set or alter the properities of the
569 * cursor.
570 *
571 * Returns negative errno on error, or zero on success.
572 */
573int xxxfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
574{
575/*
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.
584 *
585 * NOTES ON FLAGS (cursor->set):
586 *
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
594 *
595 * NOTES ON ROPs (cursor->rop, Raster Operation)
596 *
597 * ROP_XOR - cursor->image.data XOR cursor->mask
598 * ROP_COPY - curosr->image.data AND cursor->mask
599 *
600 * OTHER NOTES:
601 *
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.
606 */
607}
608
609/**
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.
613 *
614 * @info: frame buffer structure that represents a single frame buffer
615 * @angle: The angle we rotate the screen.
616 *
617 * This operation is used to set or alter the properities of the
618 * cursor.
619 */
620void xxxfb_rotate(struct fb_info *info, int angle)
621{
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800622/* Will be deprecated */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623}
624
625/**
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.
630 *
631 * @info: frame buffer structure that represents a single frame buffer
632 * @wait: poll table where we store process that await a event.
633 */
634void xxxfb_poll(struct fb_info *info, poll_table *wait)
635{
636}
637
638/**
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.
644 *
645 * @info: frame buffer structure that represents a single frame buffer
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800646 *
647 * If the driver has implemented its own hardware-based drawing function,
648 * implementing this function is highly recommended.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 */
650void xxxfb_sync(struct fb_info *info)
651{
652}
653
654 /*
655 * Initialization
656 */
657
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800658/* static int __init xxfb_probe (struct device *device) -- for platform devs */
659static int __init xxxfb_probe(struct pci_dev *dev,
660 const_struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661{
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800662 struct fb_info *info;
663 struct xxx_par *par;
664 struct device = &dev->dev; /* for pci drivers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 int cmap_len, retval;
666
667 /*
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800668 * Dynamically allocate info and par
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 */
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800670 info = framebuffer_alloc(sizeof(struct xxx_par), device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800672 if (!info) {
673 /* goto error path */
674 }
675
676 par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
678 /*
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.
683 */
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800684 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
688 */
689 info->pseudo_palette = pseudo_palette; /* The pseudopalette is an
690 * 16-member array
691 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 /*
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
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800696 *
697 * If your hardware can support any of the hardware accelerated functions
698 * fbcon performance will improve if info->flags is set properly.
699 *
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
708 *
709 * NOTE: These are for fbcon use only.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 */
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800711 info->flags = FBINFO_DEFAULT;
712
713/********************* This stage is optional ******************************/
714 /*
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
720 */
721
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.
726 */
727 info->pixmap.addr = kmalloc(PIXMAP_SIZE, GFP_KERNEL);
728 if (!info->pixmap.addr) {
729 /* goto error */
730 }
731
732 info->pixmap.size = PIXMAP_SIZE;
733
734 /*
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.
739 *
740 * Currently, FB_PIXMAP_IO is unimplemented.
741 */
742 info->pixmap.flags = FB_PIXMAP_SYSTEM;
743
744 /*
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.
747 */
748 info->pixmap.scan_align = 4;
749
750 /*
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.
754 */
755 info->pixmap.buf_align = 4;
756
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.
760 *
761 * NOTE: This field is currently unused.
762 */
763 info->pixmap.scan_align = 32
764/***************************** End optional stage ***************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
766 /*
767 * This should give a reasonable default video mode. The following is
768 * done when we can set a video mode.
769 */
770 if (!mode_option)
771 mode_option = "640x480@60";
772
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800773 retval = fb_find_mode(info->var, info, mode_option, NULL, 0, NULL, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
775 if (!retval || retval == 4)
776 return -EINVAL;
777
778 /* This has to been done !!! */
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800779 fb_alloc_cmap(info->cmap, cmap_len, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781 /*
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.
784 */
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800785 info->var = xxxfb_var;
786
787 /*
788 * For drivers that can...
789 */
790 xxxfb_check_var(&info->var, info);
791
792 /*
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.
796 *
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.
800 */
801 /* xxxfb_set_par(info); */
802
803 if (register_framebuffer(info) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 return -EINVAL;
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800805 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) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 return 0;
809}
810
811 /*
812 * Cleanup
813 */
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800814/* static void __exit xxxfb_remove(struct device *device) */
815static void __exit xxxfb_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816{
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800817 struct fb_info *info = pci_get_drv_data(dev);
818 /* or dev_get_drv_data(device); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800820 if (info) {
821 unregister_framebuffer(info);
822 fb_dealloc_cmap(&info.cmap);
823 /* ... */
824 framebuffer_release(info);
825 }
826
827 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828}
829
Antonino A. Daplasd9112332006-01-09 20:53:34 -0800830#if CONFIG_PCI
831/* For PCI drivers */
832static 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 */
839};
840
841static int __init xxxfb_init(void)
842{
843 /*
844 * For kernel boot options (in 'video=xxxfb:<options>' format)
845 */
846#ifndef MODULE
847 char *option = NULL;
848
849 if (fb_get_options("xxxfb", &option))
850 return -ENODEV;
851 xxxfb_setup(option);
852#endif
853
854 return pci_register_driver(&xxxfb_driver);
855}
856
857static void __exit xxxfb_exit(void)
858{
859 pci_unregister_driver(&xxxfb_driver);
860}
861#else
862#include <linux/platform_device.h>
863/* for platform devices */
864static 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 */
871};
872
873static struct platform_device xxxfb_device = {
874 .name = "xxxfb",
875};
876
877static int __init xxxfb_init(void)
878{
879 int ret;
880 /*
881 * For kernel boot options (in 'video=xxxfb:<options>' format)
882 */
883#ifndef MODULE
884 char *option = NULL;
885
886 if (fb_get_options("xxxfb", &option))
887 return -ENODEV;
888 xxxfb_setup(option);
889#endif
890 ret = driver_register(&xxxfb_driver);
891
892 if (!ret) {
893 ret = platform_device_register(&xxxfb_device);
894 if (ret)
895 driver_unregister(&xxxfb_driver);
896 }
897
898 return ret;
899}
900
901static void __exit xxxfb_exit(void)
902{
903 platform_device_unregister(&xxxfb_device);
904 driver_unregister(&xxxfb_driver);
905}
906#endif
907
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 /*
909 * Setup
910 */
911
912/*
913 * Only necessary if your driver takes special options,
914 * otherwise we fall back on the generic fb_setup().
915 */
916int __init xxxfb_setup(char *options)
917{
918 /* Parse user speficied options (`video=xxxfb:') */
919}
920
921/* ------------------------------------------------------------------------- */
922
923 /*
924 * Frame buffer operations
925 */
926
927static 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 !!! */
Antonino A. Daplasc465e052005-11-07 01:00:35 -0800941 .fb_cursor = xxxfb_cursor, /* Optional !!! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 .fb_rotate = xxxfb_rotate,
943 .fb_poll = xxxfb_poll,
944 .fb_sync = xxxfb_sync,
945 .fb_ioctl = xxxfb_ioctl,
946 .fb_mmap = xxxfb_mmap,
947};
948
949/* ------------------------------------------------------------------------- */
950
951
952 /*
953 * Modularization
954 */
955
956module_init(xxxfb_init);
957module_exit(xxxfb_cleanup);
958
959MODULE_LICENSE("GPL");