| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device | 
|  | 3 | * | 
|  | 4 | *  Modified to new api Jan 2001 by James Simmons (jsimmons@transvirtual.com) | 
|  | 5 | * | 
|  | 6 | *  Created 28 Dec 1997 by Geert Uytterhoeven | 
|  | 7 | * | 
|  | 8 | * | 
|  | 9 | *  I have started rewriting this driver as a example of the upcoming new API | 
|  | 10 | *  The primary goal is to remove the console code from fbdev and place it | 
|  | 11 | *  into fbcon.c. This reduces the code and makes writing a new fbdev driver | 
|  | 12 | *  easy since the author doesn't need to worry about console internals. It | 
|  | 13 | *  also allows the ability to run fbdev without a console/tty system on top | 
|  | 14 | *  of it. | 
|  | 15 | * | 
|  | 16 | *  First the roles of struct fb_info and struct display have changed. Struct | 
|  | 17 | *  display will go away. The way the the new framebuffer console code will | 
|  | 18 | *  work is that it will act to translate data about the tty/console in | 
|  | 19 | *  struct vc_data to data in a device independent way in struct fb_info. Then | 
|  | 20 | *  various functions in struct fb_ops will be called to store the device | 
|  | 21 | *  dependent state in the par field in struct fb_info and to change the | 
|  | 22 | *  hardware to that state. This allows a very clean separation of the fbdev | 
|  | 23 | *  layer from the console layer. It also allows one to use fbdev on its own | 
|  | 24 | *  which is a bounus for embedded devices. The reason this approach works is | 
|  | 25 | *  for each framebuffer device when used as a tty/console device is allocated | 
|  | 26 | *  a set of virtual terminals to it. Only one virtual terminal can be active | 
|  | 27 | *  per framebuffer device. We already have all the data we need in struct | 
|  | 28 | *  vc_data so why store a bunch of colormaps and other fbdev specific data | 
|  | 29 | *  per virtual terminal. | 
|  | 30 | * | 
|  | 31 | *  As you can see doing this makes the con parameter pretty much useless | 
|  | 32 | *  for struct fb_ops functions, as it should be. Also having struct | 
|  | 33 | *  fb_var_screeninfo and other data in fb_info pretty much eliminates the | 
|  | 34 | *  need for get_fix and get_var. Once all drivers use the fix, var, and cmap | 
|  | 35 | *  fbcon can be written around these fields. This will also eliminate the | 
|  | 36 | *  need to regenerate struct fb_var_screeninfo, struct fb_fix_screeninfo | 
|  | 37 | *  struct fb_cmap every time get_var, get_fix, get_cmap functions are called | 
|  | 38 | *  as many drivers do now. | 
|  | 39 | * | 
|  | 40 | *  This file is subject to the terms and conditions of the GNU General Public | 
|  | 41 | *  License. See the file COPYING in the main directory of this archive for | 
|  | 42 | *  more details. | 
|  | 43 | */ | 
|  | 44 |  | 
|  | 45 | #include <linux/module.h> | 
|  | 46 | #include <linux/kernel.h> | 
|  | 47 | #include <linux/errno.h> | 
|  | 48 | #include <linux/string.h> | 
|  | 49 | #include <linux/mm.h> | 
|  | 50 | #include <linux/tty.h> | 
|  | 51 | #include <linux/slab.h> | 
|  | 52 | #include <linux/delay.h> | 
|  | 53 | #include <linux/fb.h> | 
|  | 54 | #include <linux/init.h> | 
|  | 55 |  | 
|  | 56 | /* | 
|  | 57 | *  This is just simple sample code. | 
|  | 58 | * | 
|  | 59 | *  No warranty that it actually compiles. | 
|  | 60 | *  Even less warranty that it actually works :-) | 
|  | 61 | */ | 
|  | 62 |  | 
|  | 63 | /* | 
|  | 64 | *  If your driver supports multiple boards, you should make the | 
|  | 65 | *  below data types arrays, or allocate them dynamically (using kmalloc()). | 
|  | 66 | */ | 
|  | 67 |  | 
|  | 68 | /* | 
|  | 69 | * This structure defines the hardware state of the graphics card. Normally | 
|  | 70 | * you place this in a header file in linux/include/video. This file usually | 
|  | 71 | * also includes register information. That allows other driver subsystems | 
|  | 72 | * and userland applications the ability to use the same header file to | 
|  | 73 | * avoid duplicate work and easy porting of software. | 
|  | 74 | */ | 
|  | 75 | struct xxx_par; | 
|  | 76 |  | 
|  | 77 | /* | 
|  | 78 | * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo | 
|  | 79 | * if we don't use modedb. If we do use modedb see xxxfb_init how to use it | 
|  | 80 | * to get a fb_var_screeninfo. Otherwise define a default var as well. | 
|  | 81 | */ | 
|  | 82 | static struct fb_fix_screeninfo xxxfb_fix __initdata = { | 
|  | 83 | .id =		"FB's name", | 
|  | 84 | .type =		FB_TYPE_PACKED_PIXELS, | 
|  | 85 | .visual =	FB_VISUAL_PSEUDOCOLOR, | 
|  | 86 | .xpanstep =	1, | 
|  | 87 | .ypanstep =	1, | 
|  | 88 | .ywrapstep =	1, | 
|  | 89 | .accel =	FB_ACCEL_NONE, | 
|  | 90 | }; | 
|  | 91 |  | 
|  | 92 | /* | 
|  | 93 | * 	Modern graphical hardware not only supports pipelines but some | 
|  | 94 | *  also support multiple monitors where each display can have its | 
|  | 95 | *  its own unique data. In this case each display could be | 
|  | 96 | *  represented by a separate framebuffer device thus a separate | 
|  | 97 | *  struct fb_info. Now the struct xxx_par represents the graphics | 
|  | 98 | *  hardware state thus only one exist per card. In this case the | 
|  | 99 | *  struct xxx_par for each graphics card would be shared between | 
|  | 100 | *  every struct fb_info that represents a framebuffer on that card. | 
|  | 101 | *  This allows when one display changes it video resolution (info->var) | 
|  | 102 | *  the other displays know instantly. Each display can always be | 
|  | 103 | *  aware of the entire hardware state that affects it because they share | 
|  | 104 | *  the same xxx_par struct. The other side of the coin is multiple | 
|  | 105 | *  graphics cards that pass data around until it is finally displayed | 
|  | 106 | *  on one monitor. Such examples are the voodoo 1 cards and high end | 
|  | 107 | *  NUMA graphics servers. For this case we have a bunch of pars, each | 
|  | 108 | *  one that represents a graphics state, that belong to one struct | 
|  | 109 | *  fb_info. Their you would want to have *par point to a array of device | 
|  | 110 | *  states and have each struct fb_ops function deal with all those | 
|  | 111 | *  states. I hope this covers every possible hardware design. If not | 
|  | 112 | *  feel free to send your ideas at jsimmons@users.sf.net | 
|  | 113 | */ | 
|  | 114 |  | 
|  | 115 | /* | 
|  | 116 | *  If your driver supports multiple boards or it supports multiple | 
|  | 117 | *  framebuffers, you should make these arrays, or allocate them | 
|  | 118 | *  dynamically (using kmalloc()). | 
|  | 119 | */ | 
|  | 120 | static 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 | */ | 
|  | 126 | static struct xxx_par __initdata current_par; | 
|  | 127 |  | 
|  | 128 | int xxxfb_init(void); | 
|  | 129 | int 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 | */ | 
|  | 145 | static 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 | */ | 
|  | 164 | static 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 | 
|  | 182 | *	to what we can do. If the hardware doesn't support mode change | 
|  | 183 | * 	a -EINVAL will be returned by the upper layers. You don't need to | 
|  | 184 | *	implement this function then. If you hardware doesn't support | 
|  | 185 | *	changing the resolution then this function is not needed. In this | 
|  | 186 | *	case the driver woudl just provide a var that represents the static | 
|  | 187 | *	state the screen is in. | 
|  | 188 | * | 
|  | 189 | *	Returns negative errno on error, or zero on success. | 
|  | 190 | */ | 
|  | 191 | static int xxxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) | 
|  | 192 | { | 
|  | 193 | const struct xxx_par *par = (const struct xxx_par *) info->par; | 
|  | 194 | /* ... */ | 
|  | 195 | return 0; | 
|  | 196 | } | 
|  | 197 |  | 
|  | 198 | /** | 
|  | 199 | *      xxxfb_set_par - Optional function. Alters the hardware state. | 
|  | 200 | *      @info: frame buffer structure that represents a single frame buffer | 
|  | 201 | * | 
|  | 202 | *	Using the fb_var_screeninfo in fb_info we set the resolution of the | 
|  | 203 | *	this particular framebuffer. This function alters the par AND the | 
|  | 204 | *	fb_fix_screeninfo stored in fb_info. It doesn't not alter var in | 
|  | 205 | *	fb_info since we are using that data. This means we depend on the | 
|  | 206 | *	data in var inside fb_info to be supported by the hardware. | 
|  | 207 | *	xxxfb_check_var is always called before xxxfb_set_par to ensure this. | 
|  | 208 | *	Again if you can't change the resolution you don't need this function. | 
|  | 209 | * | 
|  | 210 | *	Returns negative errno on error, or zero on success. | 
|  | 211 | */ | 
|  | 212 | static int xxxfb_set_par(struct fb_info *info) | 
|  | 213 | { | 
|  | 214 | struct xxx_par *par = (struct xxx_par *) info->par; | 
|  | 215 | /* ... */ | 
|  | 216 | return 0; | 
|  | 217 | } | 
|  | 218 |  | 
|  | 219 | /** | 
|  | 220 | *  	xxxfb_setcolreg - Optional function. Sets a color register. | 
|  | 221 | *      @regno: Which register in the CLUT we are programming | 
|  | 222 | *      @red: The red value which can be up to 16 bits wide | 
|  | 223 | *	@green: The green value which can be up to 16 bits wide | 
|  | 224 | *	@blue:  The blue value which can be up to 16 bits wide. | 
|  | 225 | *	@transp: If supported, the alpha value which can be up to 16 bits wide. | 
|  | 226 | *      @info: frame buffer info structure | 
|  | 227 | * | 
|  | 228 | *  	Set a single color register. The values supplied have a 16 bit | 
|  | 229 | *  	magnitude which needs to be scaled in this function for the hardware. | 
|  | 230 | *	Things to take into consideration are how many color registers, if | 
|  | 231 | *	any, are supported with the current color visual. With truecolor mode | 
|  | 232 | *	no color palettes are supported. Here a pseudo palette is created | 
|  | 233 | *	which we store the value in pseudo_palette in struct fb_info. For | 
|  | 234 | *	pseudocolor mode we have a limited color palette. To deal with this | 
|  | 235 | *	we can program what color is displayed for a particular pixel value. | 
|  | 236 | *	DirectColor is similar in that we can program each color field. If | 
|  | 237 | *	we have a static colormap we don't need to implement this function. | 
|  | 238 | * | 
|  | 239 | *	Returns negative errno on error, or zero on success. | 
|  | 240 | */ | 
|  | 241 | static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green, | 
|  | 242 | unsigned blue, unsigned transp, | 
|  | 243 | const struct fb_info *info) | 
|  | 244 | { | 
|  | 245 | if (regno >= 256)  /* no. of hw registers */ | 
|  | 246 | return -EINVAL; | 
|  | 247 | /* | 
|  | 248 | * Program hardware... do anything you want with transp | 
|  | 249 | */ | 
|  | 250 |  | 
|  | 251 | /* grayscale works only partially under directcolor */ | 
|  | 252 | if (info->var.grayscale) { | 
|  | 253 | /* grayscale = 0.30*R + 0.59*G + 0.11*B */ | 
|  | 254 | red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8; | 
|  | 255 | } | 
|  | 256 |  | 
|  | 257 | /* Directcolor: | 
|  | 258 | *   var->{color}.offset contains start of bitfield | 
|  | 259 | *   var->{color}.length contains length of bitfield | 
|  | 260 | *   {hardwarespecific} contains width of DAC | 
|  | 261 | *   cmap[X] is programmed to (X << red.offset) | (X << green.offset) | (X << blue.offset) | 
|  | 262 | *   RAMDAC[X] is programmed to (red, green, blue) | 
|  | 263 | * | 
|  | 264 | * Pseudocolor: | 
|  | 265 | *    uses offset = 0 && length = DAC register width. | 
|  | 266 | *    var->{color}.offset is 0 | 
|  | 267 | *    var->{color}.length contains widht of DAC | 
|  | 268 | *    cmap is not used | 
|  | 269 | *    DAC[X] is programmed to (red, green, blue) | 
|  | 270 | * Truecolor: | 
|  | 271 | *    does not use RAMDAC (usually has 3 of them). | 
|  | 272 | *    var->{color}.offset contains start of bitfield | 
|  | 273 | *    var->{color}.length contains length of bitfield | 
|  | 274 | *    cmap is programmed to (red << red.offset) | (green << green.offset) | | 
|  | 275 | *                      (blue << blue.offset) | (transp << transp.offset) | 
|  | 276 | *    RAMDAC does not exist | 
|  | 277 | */ | 
|  | 278 | #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16) | 
|  | 279 | switch (info->fix.visual) { | 
|  | 280 | case FB_VISUAL_TRUECOLOR: | 
|  | 281 | case FB_VISUAL_PSEUDOCOLOR: | 
|  | 282 | red = CNVT_TOHW(red, info->var.red.length); | 
|  | 283 | green = CNVT_TOHW(green, info->var.green.length); | 
|  | 284 | blue = CNVT_TOHW(blue, info->var.blue.length); | 
|  | 285 | transp = CNVT_TOHW(transp, info->var.transp.length); | 
|  | 286 | break; | 
|  | 287 | case FB_VISUAL_DIRECTCOLOR: | 
|  | 288 | /* example here assumes 8 bit DAC. Might be different | 
|  | 289 | * for your hardware */ | 
|  | 290 | red = CNVT_TOHW(red, 8); | 
|  | 291 | green = CNVT_TOHW(green, 8); | 
|  | 292 | blue = CNVT_TOHW(blue, 8); | 
|  | 293 | /* hey, there is bug in transp handling... */ | 
|  | 294 | transp = CNVT_TOHW(transp, 8); | 
|  | 295 | break; | 
|  | 296 | } | 
|  | 297 | #undef CNVT_TOHW | 
|  | 298 | /* Truecolor has hardware independent palette */ | 
|  | 299 | if (info->fix.visual == FB_VISUAL_TRUECOLOR) { | 
|  | 300 | u32 v; | 
|  | 301 |  | 
|  | 302 | if (regno >= 16) | 
|  | 303 | return -EINVAL; | 
|  | 304 |  | 
|  | 305 | v = (red << info->var.red.offset) | | 
|  | 306 | (green << info->var.green.offset) | | 
|  | 307 | (blue << info->var.blue.offset) | | 
|  | 308 | (transp << info->var.transp.offset); | 
|  | 309 |  | 
|  | 310 | switch (info->var.bits_per_pixel) { | 
|  | 311 | case 8: | 
|  | 312 | /* Yes some hand held devices have this. */ | 
|  | 313 | ((u8*)(info->pseudo_palette))[regno] = v; | 
|  | 314 | break; | 
|  | 315 | case 16: | 
|  | 316 | ((u16*)(info->pseudo_palette))[regno] = v; | 
|  | 317 | break; | 
|  | 318 | case 24: | 
|  | 319 | case 32: | 
|  | 320 | ((u32*)(info->pseudo_palette))[regno] = v; | 
|  | 321 | break; | 
|  | 322 | } | 
|  | 323 | return 0; | 
|  | 324 | } | 
|  | 325 | /* ... */ | 
|  | 326 | return 0; | 
|  | 327 | } | 
|  | 328 |  | 
|  | 329 | /** | 
|  | 330 | *      xxxfb_pan_display - NOT a required function. Pans the display. | 
|  | 331 | *      @var: frame buffer variable screen structure | 
|  | 332 | *      @info: frame buffer structure that represents a single frame buffer | 
|  | 333 | * | 
|  | 334 | *	Pan (or wrap, depending on the `vmode' field) the display using the | 
|  | 335 | *  	`xoffset' and `yoffset' fields of the `var' structure. | 
|  | 336 | *  	If the values don't fit, return -EINVAL. | 
|  | 337 | * | 
|  | 338 | *      Returns negative errno on error, or zero on success. | 
|  | 339 | */ | 
|  | 340 | static int xxxfb_pan_display(struct fb_var_screeninfo *var, | 
|  | 341 | const struct fb_info *info) | 
|  | 342 | { | 
|  | 343 | /* ... */ | 
|  | 344 | return 0; | 
|  | 345 | } | 
|  | 346 |  | 
|  | 347 | /** | 
|  | 348 | *      xxxfb_blank - NOT a required function. Blanks the display. | 
|  | 349 | *      @blank_mode: the blank mode we want. | 
|  | 350 | *      @info: frame buffer structure that represents a single frame buffer | 
|  | 351 | * | 
|  | 352 | *      Blank the screen if blank_mode != 0, else unblank. Return 0 if | 
|  | 353 | *      blanking succeeded, != 0 if un-/blanking failed due to e.g. a | 
|  | 354 | *      video mode which doesn't support it. Implements VESA suspend | 
|  | 355 | *      and powerdown modes on hardware that supports disabling hsync/vsync: | 
|  | 356 | *      blank_mode == 2: suspend vsync | 
|  | 357 | *      blank_mode == 3: suspend hsync | 
|  | 358 | *      blank_mode == 4: powerdown | 
|  | 359 | * | 
|  | 360 | *      Returns negative errno on error, or zero on success. | 
|  | 361 | * | 
|  | 362 | */ | 
|  | 363 | static int xxxfb_blank(int blank_mode, const struct fb_info *info) | 
|  | 364 | { | 
|  | 365 | /* ... */ | 
|  | 366 | return 0; | 
|  | 367 | } | 
|  | 368 |  | 
|  | 369 | /* ------------ Accelerated Functions --------------------- */ | 
|  | 370 |  | 
|  | 371 | /* | 
|  | 372 | * We provide our own functions if we have hardware acceleration | 
|  | 373 | * or non packed pixel format layouts. If we have no hardware | 
|  | 374 | * acceleration, we can use a generic unaccelerated function. If using | 
|  | 375 | * a pack pixel format just use the functions in cfb_*.c. Each file | 
|  | 376 | * has one of the three different accel functions we support. | 
|  | 377 | */ | 
|  | 378 |  | 
|  | 379 | /** | 
|  | 380 | *      xxxfb_fillrect - REQUIRED function. Can use generic routines if | 
|  | 381 | *		 	 non acclerated hardware and packed pixel based. | 
|  | 382 | *			 Draws a rectangle on the screen. | 
|  | 383 | * | 
|  | 384 | *      @info: frame buffer structure that represents a single frame buffer | 
|  | 385 | *	@region: The structure representing the rectangular region we | 
|  | 386 | *		 wish to draw to. | 
|  | 387 | * | 
|  | 388 | *	This drawing operation places/removes a retangle on the screen | 
|  | 389 | *	depending on the rastering operation with the value of color which | 
|  | 390 | *	is in the current color depth format. | 
|  | 391 | */ | 
|  | 392 | void xxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region) | 
|  | 393 | { | 
|  | 394 | /*	Meaning of struct fb_fillrect | 
|  | 395 | * | 
|  | 396 | *	@dx: The x and y corrdinates of the upper left hand corner of the | 
|  | 397 | *	@dy: area we want to draw to. | 
|  | 398 | *	@width: How wide the rectangle is we want to draw. | 
|  | 399 | *	@height: How tall the rectangle is we want to draw. | 
|  | 400 | *	@color:	The color to fill in the rectangle with. | 
|  | 401 | *	@rop: The raster operation. We can draw the rectangle with a COPY | 
|  | 402 | *	      of XOR which provides erasing effect. | 
|  | 403 | */ | 
|  | 404 | } | 
|  | 405 |  | 
|  | 406 | /** | 
|  | 407 | *      xxxfb_copyarea - REQUIRED function. Can use generic routines if | 
|  | 408 | *                       non acclerated hardware and packed pixel based. | 
|  | 409 | *                       Copies one area of the screen to another area. | 
|  | 410 | * | 
|  | 411 | *      @info: frame buffer structure that represents a single frame buffer | 
|  | 412 | *      @area: Structure providing the data to copy the framebuffer contents | 
|  | 413 | *	       from one region to another. | 
|  | 414 | * | 
|  | 415 | *      This drawing operation copies a rectangular area from one area of the | 
|  | 416 | *	screen to another area. | 
|  | 417 | */ | 
|  | 418 | void xxxfb_copyarea(struct fb_info *p, const struct fb_copyarea *area) | 
|  | 419 | { | 
|  | 420 | /* | 
|  | 421 | *      @dx: The x and y coordinates of the upper left hand corner of the | 
|  | 422 | *	@dy: destination area on the screen. | 
|  | 423 | *      @width: How wide the rectangle is we want to copy. | 
|  | 424 | *      @height: How tall the rectangle is we want to copy. | 
|  | 425 | *      @sx: The x and y coordinates of the upper left hand corner of the | 
|  | 426 | *      @sy: source area on the screen. | 
|  | 427 | */ | 
|  | 428 | } | 
|  | 429 |  | 
|  | 430 |  | 
|  | 431 | /** | 
|  | 432 | *      xxxfb_imageblit - REQUIRED function. Can use generic routines if | 
|  | 433 | *                        non acclerated hardware and packed pixel based. | 
|  | 434 | *                        Copies a image from system memory to the screen. | 
|  | 435 | * | 
|  | 436 | *      @info: frame buffer structure that represents a single frame buffer | 
|  | 437 | *	@image:	structure defining the image. | 
|  | 438 | * | 
|  | 439 | *      This drawing operation draws a image on the screen. It can be a | 
|  | 440 | *	mono image (needed for font handling) or a color image (needed for | 
|  | 441 | *	tux). | 
|  | 442 | */ | 
|  | 443 | void xxxfb_imageblit(struct fb_info *p, const struct fb_image *image) | 
|  | 444 | { | 
|  | 445 | /* | 
|  | 446 | *      @dx: The x and y coordinates of the upper left hand corner of the | 
|  | 447 | *	@dy: destination area to place the image on the screen. | 
|  | 448 | *      @width: How wide the image is we want to copy. | 
|  | 449 | *      @height: How tall the image is we want to copy. | 
|  | 450 | *      @fg_color: For mono bitmap images this is color data for | 
|  | 451 | *      @bg_color: the foreground and background of the image to | 
|  | 452 | *		   write directly to the frmaebuffer. | 
|  | 453 | *	@depth:	How many bits represent a single pixel for this image. | 
|  | 454 | *	@data: The actual data used to construct the image on the display. | 
|  | 455 | *	@cmap: The colormap used for color images. | 
|  | 456 | */ | 
|  | 457 | } | 
|  | 458 |  | 
|  | 459 | /** | 
| Antonino A. Daplas | c465e05 | 2005-11-07 01:00:35 -0800 | [diff] [blame] | 460 | *	xxxfb_cursor - 	OPTIONAL. If your hardware lacks support | 
|  | 461 | *			for a cursor, leave this field NULL. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | * | 
|  | 463 | *      @info: frame buffer structure that represents a single frame buffer | 
|  | 464 | *	@cursor: structure defining the cursor to draw. | 
|  | 465 | * | 
|  | 466 | *      This operation is used to set or alter the properities of the | 
|  | 467 | *	cursor. | 
|  | 468 | * | 
|  | 469 | *	Returns negative errno on error, or zero on success. | 
|  | 470 | */ | 
|  | 471 | int xxxfb_cursor(struct fb_info *info, struct fb_cursor *cursor) | 
|  | 472 | { | 
|  | 473 | /* | 
|  | 474 | *      @set: 	Which fields we are altering in struct fb_cursor | 
|  | 475 | *	@enable: Disable or enable the cursor | 
|  | 476 | *      @rop: 	The bit operation we want to do. | 
|  | 477 | *      @mask:  This is the cursor mask bitmap. | 
|  | 478 | *      @dest:  A image of the area we are going to display the cursor. | 
|  | 479 | *		Used internally by the driver. | 
|  | 480 | *      @hot:	The hot spot. | 
|  | 481 | *	@image:	The actual data for the cursor image. | 
|  | 482 | * | 
|  | 483 | *      NOTES ON FLAGS (cursor->set): | 
|  | 484 | * | 
|  | 485 | *      FB_CUR_SETIMAGE - the cursor image has changed (cursor->image.data) | 
|  | 486 | *      FB_CUR_SETPOS   - the cursor position has changed (cursor->image.dx|dy) | 
|  | 487 | *      FB_CUR_SETHOT   - the cursor hot spot has changed (cursor->hot.dx|dy) | 
|  | 488 | *      FB_CUR_SETCMAP  - the cursor colors has changed (cursor->fg_color|bg_color) | 
|  | 489 | *      FB_CUR_SETSHAPE - the cursor bitmask has changed (cursor->mask) | 
|  | 490 | *      FB_CUR_SETSIZE  - the cursor size has changed (cursor->width|height) | 
|  | 491 | *      FB_CUR_SETALL   - everything has changed | 
|  | 492 | * | 
|  | 493 | *      NOTES ON ROPs (cursor->rop, Raster Operation) | 
|  | 494 | * | 
|  | 495 | *      ROP_XOR         - cursor->image.data XOR cursor->mask | 
|  | 496 | *      ROP_COPY        - curosr->image.data AND cursor->mask | 
|  | 497 | * | 
|  | 498 | *      OTHER NOTES: | 
|  | 499 | * | 
|  | 500 | *      - fbcon only supports a 2-color cursor (cursor->image.depth = 1) | 
|  | 501 | *      - The fb_cursor structure, @cursor, _will_ always contain valid | 
|  | 502 | *        fields, whether any particular bitfields in cursor->set is set | 
|  | 503 | *        or not. | 
|  | 504 | */ | 
|  | 505 | } | 
|  | 506 |  | 
|  | 507 | /** | 
|  | 508 | *	xxxfb_rotate -  NOT a required function. If your hardware | 
|  | 509 | *			supports rotation the whole screen then | 
|  | 510 | *			you would provide a hook for this. | 
|  | 511 | * | 
|  | 512 | *      @info: frame buffer structure that represents a single frame buffer | 
|  | 513 | *	@angle: The angle we rotate the screen. | 
|  | 514 | * | 
|  | 515 | *      This operation is used to set or alter the properities of the | 
|  | 516 | *	cursor. | 
|  | 517 | */ | 
|  | 518 | void xxxfb_rotate(struct fb_info *info, int angle) | 
|  | 519 | { | 
|  | 520 | } | 
|  | 521 |  | 
|  | 522 | /** | 
|  | 523 | *	xxxfb_poll - NOT a required function. The purpose of this | 
|  | 524 | *		     function is to provide a way for some process | 
|  | 525 | *		     to wait until a specific hardware event occurs | 
|  | 526 | *		     for the framebuffer device. | 
|  | 527 | * | 
|  | 528 | *      @info: frame buffer structure that represents a single frame buffer | 
|  | 529 | *	@wait: poll table where we store process that await a event. | 
|  | 530 | */ | 
|  | 531 | void xxxfb_poll(struct fb_info *info, poll_table *wait) | 
|  | 532 | { | 
|  | 533 | } | 
|  | 534 |  | 
|  | 535 | /** | 
|  | 536 | *	xxxfb_sync - NOT a required function. Normally the accel engine | 
|  | 537 | *		     for a graphics card take a specific amount of time. | 
|  | 538 | *		     Often we have to wait for the accelerator to finish | 
|  | 539 | *		     its operation before we can write to the framebuffer | 
|  | 540 | *		     so we can have consistent display output. | 
|  | 541 | * | 
|  | 542 | *      @info: frame buffer structure that represents a single frame buffer | 
|  | 543 | */ | 
|  | 544 | void xxxfb_sync(struct fb_info *info) | 
|  | 545 | { | 
|  | 546 | } | 
|  | 547 |  | 
|  | 548 | /* | 
|  | 549 | *  Initialization | 
|  | 550 | */ | 
|  | 551 |  | 
|  | 552 | int __init xxxfb_init(void) | 
|  | 553 | { | 
|  | 554 | int cmap_len, retval; | 
|  | 555 |  | 
|  | 556 | /* | 
|  | 557 | *  For kernel boot options (in 'video=xxxfb:<options>' format) | 
|  | 558 | */ | 
|  | 559 | #ifndef MODULE | 
|  | 560 | char *option = NULL; | 
|  | 561 |  | 
|  | 562 | if (fb_get_options("xxxfb", &option)) | 
|  | 563 | return -ENODEV; | 
|  | 564 | xxxfb_setup(option); | 
|  | 565 | #endif | 
|  | 566 |  | 
|  | 567 | /* | 
|  | 568 | * Here we set the screen_base to the virtual memory address | 
|  | 569 | * for the framebuffer. Usually we obtain the resource address | 
|  | 570 | * from the bus layer and then translate it to virtual memory | 
|  | 571 | * space via ioremap. Consult ioport.h. | 
|  | 572 | */ | 
|  | 573 | info.screen_base = framebuffer_virtual_memory; | 
|  | 574 | info.fbops = &xxxfb_ops; | 
|  | 575 | info.fix = xxxfb_fix; | 
|  | 576 | info.pseudo_palette = pseudo_palette; | 
|  | 577 |  | 
|  | 578 | /* | 
|  | 579 | * Set up flags to indicate what sort of acceleration your | 
|  | 580 | * driver can provide (pan/wrap/copyarea/etc.) and whether it | 
|  | 581 | * is a module -- see FBINFO_* in include/linux/fb.h | 
|  | 582 | */ | 
|  | 583 | info.flags = FBINFO_DEFAULT; | 
|  | 584 | info.par = current_par; | 
|  | 585 |  | 
|  | 586 | /* | 
|  | 587 | * This should give a reasonable default video mode. The following is | 
|  | 588 | * done when we can set a video mode. | 
|  | 589 | */ | 
|  | 590 | if (!mode_option) | 
|  | 591 | mode_option = "640x480@60"; | 
|  | 592 |  | 
|  | 593 | retval = fb_find_mode(&info.var, &info, mode_option, NULL, 0, NULL, 8); | 
|  | 594 |  | 
|  | 595 | if (!retval || retval == 4) | 
|  | 596 | return -EINVAL; | 
|  | 597 |  | 
|  | 598 | /* This has to been done !!! */ | 
|  | 599 | fb_alloc_cmap(&info.cmap, cmap_len, 0); | 
|  | 600 |  | 
|  | 601 | /* | 
|  | 602 | * The following is done in the case of having hardware with a static | 
|  | 603 | * mode. If we are setting the mode ourselves we don't call this. | 
|  | 604 | */ | 
|  | 605 | info.var = xxxfb_var; | 
|  | 606 |  | 
|  | 607 | if (register_framebuffer(&info) < 0) | 
|  | 608 | return -EINVAL; | 
|  | 609 | printk(KERN_INFO "fb%d: %s frame buffer device\n", info.node, | 
|  | 610 | info.fix.id); | 
|  | 611 | return 0; | 
|  | 612 | } | 
|  | 613 |  | 
|  | 614 | /* | 
|  | 615 | *  Cleanup | 
|  | 616 | */ | 
|  | 617 |  | 
|  | 618 | static void __exit xxxfb_cleanup(void) | 
|  | 619 | { | 
|  | 620 | /* | 
|  | 621 | *  If your driver supports multiple boards, you should unregister and | 
|  | 622 | *  clean up all instances. | 
|  | 623 | */ | 
|  | 624 |  | 
|  | 625 | unregister_framebuffer(info); | 
|  | 626 | fb_dealloc_cmap(&info.cmap); | 
|  | 627 | /* ... */ | 
|  | 628 | } | 
|  | 629 |  | 
|  | 630 | /* | 
|  | 631 | *  Setup | 
|  | 632 | */ | 
|  | 633 |  | 
|  | 634 | /* | 
|  | 635 | * Only necessary if your driver takes special options, | 
|  | 636 | * otherwise we fall back on the generic fb_setup(). | 
|  | 637 | */ | 
|  | 638 | int __init xxxfb_setup(char *options) | 
|  | 639 | { | 
|  | 640 | /* Parse user speficied options (`video=xxxfb:') */ | 
|  | 641 | } | 
|  | 642 |  | 
|  | 643 | /* ------------------------------------------------------------------------- */ | 
|  | 644 |  | 
|  | 645 | /* | 
|  | 646 | *  Frame buffer operations | 
|  | 647 | */ | 
|  | 648 |  | 
|  | 649 | static struct fb_ops xxxfb_ops = { | 
|  | 650 | .owner		= THIS_MODULE, | 
|  | 651 | .fb_open	= xxxfb_open, | 
|  | 652 | .fb_read	= xxxfb_read, | 
|  | 653 | .fb_write	= xxxfb_write, | 
|  | 654 | .fb_release	= xxxfb_release, | 
|  | 655 | .fb_check_var	= xxxfb_check_var, | 
|  | 656 | .fb_set_par	= xxxfb_set_par, | 
|  | 657 | .fb_setcolreg	= xxxfb_setcolreg, | 
|  | 658 | .fb_blank	= xxxfb_blank, | 
|  | 659 | .fb_pan_display	= xxxfb_pan_display, | 
|  | 660 | .fb_fillrect	= xxxfb_fillrect, 	/* Needed !!! */ | 
|  | 661 | .fb_copyarea	= xxxfb_copyarea,	/* Needed !!! */ | 
|  | 662 | .fb_imageblit	= xxxfb_imageblit,	/* Needed !!! */ | 
| Antonino A. Daplas | c465e05 | 2005-11-07 01:00:35 -0800 | [diff] [blame] | 663 | .fb_cursor	= xxxfb_cursor,		/* Optional !!! */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | .fb_rotate	= xxxfb_rotate, | 
|  | 665 | .fb_poll	= xxxfb_poll, | 
|  | 666 | .fb_sync	= xxxfb_sync, | 
|  | 667 | .fb_ioctl	= xxxfb_ioctl, | 
|  | 668 | .fb_mmap	= xxxfb_mmap, | 
|  | 669 | }; | 
|  | 670 |  | 
|  | 671 | /* ------------------------------------------------------------------------- */ | 
|  | 672 |  | 
|  | 673 |  | 
|  | 674 | /* | 
|  | 675 | *  Modularization | 
|  | 676 | */ | 
|  | 677 |  | 
|  | 678 | module_init(xxxfb_init); | 
|  | 679 | module_exit(xxxfb_cleanup); | 
|  | 680 |  | 
|  | 681 | MODULE_LICENSE("GPL"); |