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