1033 lines · c
1/*2 * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device3 *4 * Modified to new api Jan 2001 by James Simmons (jsimmons@transvirtual.com)5 *6 * Created 28 Dec 1997 by Geert Uytterhoeven7 *8 *9 * I have started rewriting this driver as a example of the upcoming new API10 * The primary goal is to remove the console code from fbdev and place it11 * into fbcon.c. This reduces the code and makes writing a new fbdev driver12 * easy since the author doesn't need to worry about console internals. It13 * also allows the ability to run fbdev without a console/tty system on top14 * of it.15 *16 * First the roles of struct fb_info and struct display have changed. Struct17 * display will go away. The way the new framebuffer console code will18 * work is that it will act to translate data about the tty/console in19 * struct vc_data to data in a device independent way in struct fb_info. Then20 * various functions in struct fb_ops will be called to store the device21 * dependent state in the par field in struct fb_info and to change the22 * hardware to that state. This allows a very clean separation of the fbdev23 * layer from the console layer. It also allows one to use fbdev on its own24 * which is a bounus for embedded devices. The reason this approach works is25 * for each framebuffer device when used as a tty/console device is allocated26 * a set of virtual terminals to it. Only one virtual terminal can be active27 * per framebuffer device. We already have all the data we need in struct28 * vc_data so why store a bunch of colormaps and other fbdev specific data29 * per virtual terminal.30 *31 * As you can see doing this makes the con parameter pretty much useless32 * for struct fb_ops functions, as it should be. Also having struct33 * fb_var_screeninfo and other data in fb_info pretty much eliminates the34 * need for get_fix and get_var. Once all drivers use the fix, var, and cmap35 * fbcon can be written around these fields. This will also eliminate the36 * need to regenerate struct fb_var_screeninfo, struct fb_fix_screeninfo37 * struct fb_cmap every time get_var, get_fix, get_cmap functions are called38 * as many drivers do now.39 *40 * This file is subject to the terms and conditions of the GNU General Public41 * License. See the file COPYING in the main directory of this archive for42 * more details.43 */44 45#include <linux/aperture.h>46#include <linux/module.h>47#include <linux/kernel.h>48#include <linux/errno.h>49#include <linux/string.h>50#include <linux/mm.h>51#include <linux/slab.h>52#include <linux/delay.h>53#include <linux/fb.h>54#include <linux/init.h>55#include <linux/pci.h>56 57 /*58 * This is just simple sample code.59 *60 * No warranty that it actually compiles.61 * Even less warranty that it actually works :-)62 */63 64/*65 * Driver data66 */67static char *mode_option;68 69/*70 * If your driver supports multiple boards, you should make the71 * below data types arrays, or allocate them dynamically (using kmalloc()).72 */73 74/*75 * This structure defines the hardware state of the graphics card. Normally76 * you place this in a header file in linux/include/video. This file usually77 * also includes register information. That allows other driver subsystems78 * and userland applications the ability to use the same header file to79 * avoid duplicate work and easy porting of software.80 */81struct xxx_par;82 83/*84 * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo85 * if we don't use modedb. If we do use modedb see xxxfb_init how to use it86 * to get a fb_var_screeninfo. Otherwise define a default var as well.87 */88static const struct fb_fix_screeninfo xxxfb_fix = {89 .id = "FB's name",90 .type = FB_TYPE_PACKED_PIXELS,91 .visual = FB_VISUAL_PSEUDOCOLOR,92 .xpanstep = 1,93 .ypanstep = 1,94 .ywrapstep = 1,95 .accel = FB_ACCEL_NONE,96};97 98 /*99 * Modern graphical hardware not only supports pipelines but some100 * also support multiple monitors where each display can have101 * its own unique data. In this case each display could be102 * represented by a separate framebuffer device thus a separate103 * struct fb_info. Now the struct xxx_par represents the graphics104 * hardware state thus only one exist per card. In this case the105 * struct xxx_par for each graphics card would be shared between106 * every struct fb_info that represents a framebuffer on that card.107 * This allows when one display changes it video resolution (info->var)108 * the other displays know instantly. Each display can always be109 * aware of the entire hardware state that affects it because they share110 * the same xxx_par struct. The other side of the coin is multiple111 * graphics cards that pass data around until it is finally displayed112 * on one monitor. Such examples are the voodoo 1 cards and high end113 * NUMA graphics servers. For this case we have a bunch of pars, each114 * one that represents a graphics state, that belong to one struct115 * fb_info. Their you would want to have *par point to a array of device116 * states and have each struct fb_ops function deal with all those117 * states. I hope this covers every possible hardware design. If not118 * feel free to send your ideas at jsimmons@users.sf.net119 */120 121 /*122 * If your driver supports multiple boards or it supports multiple123 * framebuffers, you should make these arrays, or allocate them124 * dynamically using framebuffer_alloc() and free them with125 * framebuffer_release().126 */127static struct fb_info info;128 129 /*130 * Each one represents the state of the hardware. Most hardware have131 * just one hardware state. These here represent the default state(s).132 */133static struct xxx_par __initdata current_par;134 135/**136 * xxxfb_open - Optional function. Called when the framebuffer is137 * first accessed.138 * @info: frame buffer structure that represents a single frame buffer139 * @user: tell us if the userland (value=1) or the console is accessing140 * the framebuffer.141 *142 * This function is the first function called in the framebuffer api.143 * Usually you don't need to provide this function. The case where it144 * is used is to change from a text mode hardware state to a graphics145 * mode state.146 *147 * Returns negative errno on error, or zero on success.148 */149static int xxxfb_open(struct fb_info *info, int user)150{151 return 0;152}153 154/**155 * xxxfb_release - Optional function. Called when the framebuffer156 * device is closed.157 * @info: frame buffer structure that represents a single frame buffer158 * @user: tell us if the userland (value=1) or the console is accessing159 * the framebuffer.160 *161 * Thus function is called when we close /dev/fb or the framebuffer162 * console system is released. Usually you don't need this function.163 * The case where it is usually used is to go from a graphics state164 * to a text mode state.165 *166 * Returns negative errno on error, or zero on success.167 */168static int xxxfb_release(struct fb_info *info, int user)169{170 return 0;171}172 173/**174 * xxxfb_check_var - Optional function. Validates a var passed in.175 * @var: frame buffer variable screen structure176 * @info: frame buffer structure that represents a single frame buffer177 *178 * Checks to see if the hardware supports the state requested by179 * var passed in. This function does not alter the hardware state!!!180 * This means the data stored in struct fb_info and struct xxx_par do181 * not change. This includes the var inside of struct fb_info.182 * Do NOT change these. This function can be called on its own if we183 * intent to only test a mode and not actually set it. The stuff in184 * modedb.c is a example of this. If the var passed in is slightly185 * off by what the hardware can support then we alter the var PASSED in186 * to what we can do.187 *188 * For values that are off, this function must round them _up_ to the189 * next value that is supported by the hardware. If the value is190 * greater than the highest value supported by the hardware, then this191 * function must return -EINVAL.192 *193 * Exception to the above rule: Some drivers have a fixed mode, ie,194 * the hardware is already set at boot up, and cannot be changed. In195 * this case, it is more acceptable that this function just return196 * a copy of the currently working var (info->var). Better is to not197 * implement this function, as the upper layer will do the copying198 * of the current var for you.199 *200 * Note: This is the only function where the contents of var can be201 * freely adjusted after the driver has been registered. If you find202 * that you have code outside of this function that alters the content203 * of var, then you are doing something wrong. Note also that the204 * contents of info->var must be left untouched at all times after205 * driver registration.206 *207 * Returns negative errno on error, or zero on success.208 */209static int xxxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)210{211 /* ... */212 return 0;213}214 215/**216 * xxxfb_set_par - Optional function. Alters the hardware state.217 * @info: frame buffer structure that represents a single frame buffer218 *219 * Using the fb_var_screeninfo in fb_info we set the resolution of the220 * this particular framebuffer. This function alters the par AND the221 * fb_fix_screeninfo stored in fb_info. It doesn't not alter var in222 * fb_info since we are using that data. This means we depend on the223 * data in var inside fb_info to be supported by the hardware.224 *225 * This function is also used to recover/restore the hardware to a226 * known working state.227 *228 * xxxfb_check_var is always called before xxxfb_set_par to ensure that229 * the contents of var is always valid.230 *231 * Again if you can't change the resolution you don't need this function.232 *233 * However, even if your hardware does not support mode changing,234 * a set_par might be needed to at least initialize the hardware to235 * a known working state, especially if it came back from another236 * process that also modifies the same hardware, such as X.237 *238 * If this is the case, a combination such as the following should work:239 *240 * static int xxxfb_check_var(struct fb_var_screeninfo *var,241 * struct fb_info *info)242 * {243 * *var = info->var;244 * return 0;245 * }246 *247 * static int xxxfb_set_par(struct fb_info *info)248 * {249 * init your hardware here250 * }251 *252 * Returns negative errno on error, or zero on success.253 */254static int xxxfb_set_par(struct fb_info *info)255{256 struct xxx_par *par = info->par;257 /* ... */258 return 0;259}260 261/**262 * xxxfb_setcolreg - Optional function. Sets a color register.263 * @regno: Which register in the CLUT we are programming264 * @red: The red value which can be up to 16 bits wide265 * @green: The green value which can be up to 16 bits wide266 * @blue: The blue value which can be up to 16 bits wide.267 * @transp: If supported, the alpha value which can be up to 16 bits wide.268 * @info: frame buffer info structure269 *270 * Set a single color register. The values supplied have a 16 bit271 * magnitude which needs to be scaled in this function for the hardware.272 * Things to take into consideration are how many color registers, if273 * any, are supported with the current color visual. With truecolor mode274 * no color palettes are supported. Here a pseudo palette is created275 * which we store the value in pseudo_palette in struct fb_info. For276 * pseudocolor mode we have a limited color palette. To deal with this277 * we can program what color is displayed for a particular pixel value.278 * DirectColor is similar in that we can program each color field. If279 * we have a static colormap we don't need to implement this function.280 *281 * Returns negative errno on error, or zero on success.282 */283static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green,284 unsigned blue, unsigned transp,285 struct fb_info *info)286{287 if (regno >= 256) /* no. of hw registers */288 return -EINVAL;289 /*290 * Program hardware... do anything you want with transp291 */292 293 /* grayscale works only partially under directcolor */294 if (info->var.grayscale) {295 /* grayscale = 0.30*R + 0.59*G + 0.11*B */296 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;297 }298 299 /* Directcolor:300 * var->{color}.offset contains start of bitfield301 * var->{color}.length contains length of bitfield302 * {hardwarespecific} contains width of DAC303 * pseudo_palette[X] is programmed to (X << red.offset) |304 * (X << green.offset) |305 * (X << blue.offset)306 * RAMDAC[X] is programmed to (red, green, blue)307 * color depth = SUM(var->{color}.length)308 *309 * Pseudocolor:310 * var->{color}.offset is 0 unless the palette index takes less than311 * bits_per_pixel bits and is stored in the upper312 * bits of the pixel value313 * var->{color}.length is set so that 1 << length is the number of314 * available palette entries315 * pseudo_palette is not used316 * RAMDAC[X] is programmed to (red, green, blue)317 * color depth = var->{color}.length318 *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 0325 * white = (1 << var->{color}.length) - 1, black = 0326 * pseudo_palette is not used327 * RAMDAC does not exist328 * color depth is always 2329 *330 * Truecolor:331 * does not use RAMDAC (usually has 3 of them).332 * var->{color}.offset contains start of bitfield333 * var->{color}.length contains length of bitfield334 * pseudo_palette is programmed to (red << red.offset) |335 * (green << green.offset) |336 * (blue << blue.offset) |337 * (transp << transp.offset)338 * RAMDAC does not exist339 * color depth = SUM(var->{color}.length})340 *341 * The color depth is used by fbcon for choosing the logo and also342 * for color palette transformation if color depth < 4343 *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 needs349 * to look at the fix->visual.350 *351 * Another common mistake is using bits_per_pixel to calculate the color352 * depth. The bits_per_pixel field does not directly translate to color353 * depth. You have to compute for the color depth (using the color354 * bitfields) and fix->visual as seen above.355 */356 357 /*358 * This is the point where the color is converted to something that359 * is acceptable by the hardware.360 */361#define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)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);366#undef CNVT_TOHW367 /*368 * This is the point where the function feeds the color to the hardware369 * palette after converting the colors to something acceptable by370 * the hardware. Note, only FB_VISUAL_DIRECTCOLOR and371 * 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 not373 * 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 of380 * info->pseudo_palette. This structure is used _only_ by fbcon, thus381 * it only contains 16 entries to match the number of colors supported382 * by the console. The pseudo_palette is used only if the visual is383 * in directcolor or truecolor mode. With other visuals, the384 * 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, each387 * entry can be written directly to the framebuffer without any conversion.388 * The pseudo_palette is (void *). However, if using the generic389 * drawing functions (cfb_imageblit, cfb_fillrect), the pseudo_palette390 * must be casted to (u32 *) _regardless_ of the bits per pixel. If the391 * driver is using its own drawing functions, then it can use whatever392 * 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;407 }408 409 /* ... */410 return 0;411}412 413/**414 * xxxfb_pan_display - NOT a required function. Pans the display.415 * @var: frame buffer variable screen structure416 * @info: frame buffer structure that represents a single frame buffer417 *418 * Pan (or wrap, depending on the `vmode' field) the display using the419 * `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 */424static int xxxfb_pan_display(struct fb_var_screeninfo *var,425 struct fb_info *info)426{427 /*428 * If your hardware does not support panning, _do_ _not_ implement this429 * 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 of434 * 0 in both xpanstep and ypanstep means that this function will never435 * get called.436 */437 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 buffer446 *447 * Blank the screen if blank_mode != FB_BLANK_UNBLANK, else unblank.448 * Return 0 if blanking succeeded, != 0 if un-/blanking failed due to449 * e.g. a video mode which doesn't support it.450 *451 * Implements VESA suspend and powerdown modes on hardware that supports452 * disabling hsync/vsync:453 *454 * FB_BLANK_NORMAL = display is blanked, syncs are on.455 * FB_BLANK_HSYNC_SUSPEND = hsync off456 * FB_BLANK_VSYNC_SUSPEND = vsync off457 * FB_BLANK_POWERDOWN = hsync and vsync off458 *459 * If implementing this function, at least support FB_BLANK_UNBLANK.460 * Return !0 for any modes that are unimplemented.461 *462 */463static int xxxfb_blank(int blank_mode, struct fb_info *info)464{465 /* ... */466 return 0;467}468 469/* ------------ Accelerated Functions --------------------- */470 471/*472 * We provide our own functions if we have hardware acceleration473 * or non packed pixel format layouts. If we have no hardware474 * acceleration, we can use a generic unaccelerated function. If using475 * a pack pixel format just use the functions in cfb_*.c. Each file476 * has one of the three different accel functions we support.477 */478 479/**480 * xxxfb_fillrect - REQUIRED function. Can use generic routines if481 * 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 buffer485 * @region: The structure representing the rectangular region we486 * wish to draw to.487 *488 * This drawing operation places/removes a retangle on the screen489 * depending on the rastering operation with the value of color which490 * is in the current color depth format.491 */492void xxxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region)493{494/* Meaning of struct fb_fillrect495 *496 * @dx: The x and y corrdinates of the upper left hand corner of the497 * @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 COPY502 * of XOR which provides erasing effect.503 */504}505 506/**507 * xxxfb_copyarea - REQUIRED function. Can use generic routines if508 * 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 buffer512 * @area: Structure providing the data to copy the framebuffer contents513 * from one region to another.514 *515 * This drawing operation copies a rectangular area from one area of the516 * screen to another area.517 */518void 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 the522 * @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 the526 * @sy: source area on the screen.527 */528}529 530 531/**532 * xxxfb_imageblit - REQUIRED function. Can use generic routines if533 * 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 buffer537 * @image: structure defining the image.538 *539 * This drawing operation draws a image on the screen. It can be a540 * mono image (needed for font handling) or a color image (needed for541 * tux).542 */543void 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 the547 * @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 for551 * @bg_color: the foreground and background of the image to552 * 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 */557 558/*559 * The generic function, cfb_imageblit, expects that the bitmap scanlines are560 * padded to the next byte. Most hardware accelerators may require padding to561 * the next u16 or the next u32. If that is the case, the driver can specify562 * this by setting info->pixmap.scan_align = 2 or 4. See a more563 * comprehensive description of the pixmap below.564 */565}566 567/**568 * xxxfb_cursor - OPTIONAL. If your hardware lacks support569 * for a cursor, leave this field NULL.570 *571 * @info: frame buffer structure that represents a single frame buffer572 * @cursor: structure defining the cursor to draw.573 *574 * This operation is used to set or alter the properities of the575 * cursor.576 *577 * Returns negative errno on error, or zero on success.578 */579int xxxfb_cursor(struct fb_info *info, struct fb_cursor *cursor)580{581/*582 * @set: Which fields we are altering in struct fb_cursor583 * @enable: Disable or enable the cursor584 * @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 changed600 *601 * NOTES ON ROPs (cursor->rop, Raster Operation)602 *603 * ROP_XOR - cursor->image.data XOR cursor->mask604 * ROP_COPY - curosr->image.data AND cursor->mask605 *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 valid610 * fields, whether any particular bitfields in cursor->set is set611 * or not.612 */613}614 615/**616 * xxxfb_sync - NOT a required function. Normally the accel engine617 * for a graphics card take a specific amount of time.618 * Often we have to wait for the accelerator to finish619 * its operation before we can write to the framebuffer620 * so we can have consistent display output.621 *622 * @info: frame buffer structure that represents a single frame buffer623 *624 * If the driver has implemented its own hardware-based drawing function,625 * implementing this function is highly recommended.626 */627int xxxfb_sync(struct fb_info *info)628{629 return 0;630}631 632 /*633 * Frame buffer operations634 */635 636static const struct fb_ops xxxfb_ops = {637 .owner = THIS_MODULE,638 .fb_open = xxxfb_open,639 .fb_read = xxxfb_read,640 .fb_write = xxxfb_write,641 .fb_release = xxxfb_release,642 .fb_check_var = xxxfb_check_var,643 .fb_set_par = xxxfb_set_par,644 .fb_setcolreg = xxxfb_setcolreg,645 .fb_blank = xxxfb_blank,646 .fb_pan_display = xxxfb_pan_display,647 .fb_fillrect = xxxfb_fillrect, /* Needed !!! */648 .fb_copyarea = xxxfb_copyarea, /* Needed !!! */649 .fb_imageblit = xxxfb_imageblit, /* Needed !!! */650 .fb_cursor = xxxfb_cursor, /* Optional !!! */651 .fb_sync = xxxfb_sync,652 .fb_ioctl = xxxfb_ioctl,653 .fb_mmap = xxxfb_mmap,654};655 656/* ------------------------------------------------------------------------- */657 658 /*659 * Initialization660 */661 662/* static int __init xxfb_probe (struct platform_device *pdev) -- for platform devs */663static int xxxfb_probe(struct pci_dev *dev, const struct pci_device_id *ent)664{665 struct fb_info *info;666 struct xxx_par *par;667 struct device *device = &dev->dev; /* or &pdev->dev */668 int cmap_len, retval;669 670 /*671 * Remove firmware-based drivers that create resource conflicts.672 */673 retval = aperture_remove_conflicting_pci_devices(pdev, "xxxfb");674 if (retval)675 return retval;676 677 /*678 * Dynamically allocate info and par679 */680 info = framebuffer_alloc(sizeof(struct xxx_par), device);681 682 if (!info) {683 /* goto error path */684 }685 686 par = info->par;687 688 /*689 * Here we set the screen_base to the virtual memory address690 * for the framebuffer. Usually we obtain the resource address691 * from the bus layer and then translate it to virtual memory692 * space via ioremap. Consult ioport.h.693 */694 info->screen_base = framebuffer_virtual_memory;695 info->fbops = &xxxfb_ops;696 info->fix = xxxfb_fix;697 info->pseudo_palette = pseudo_palette; /* The pseudopalette is an698 * 16-member array699 */700 /*701 * Set up flags to indicate what sort of acceleration your702 * driver can provide (pan/wrap/copyarea/etc.) and whether it703 * is a module -- see FBINFO_* in include/linux/fb.h704 *705 * If your hardware can support any of the hardware accelerated functions706 * fbcon performance will improve if info->flags is set properly.707 *708 * FBINFO_HWACCEL_COPYAREA - hardware moves709 * FBINFO_HWACCEL_FILLRECT - hardware fills710 * FBINFO_HWACCEL_IMAGEBLIT - hardware mono->color expansion711 * FBINFO_HWACCEL_YPAN - hardware can pan display in y-axis712 * FBINFO_HWACCEL_YWRAP - hardware can wrap display in y-axis713 * FBINFO_HWACCEL_DISABLED - supports hardware accels, but disabled714 * FBINFO_READS_FAST - if set, prefer moves over mono->color expansion715 * FBINFO_MISC_TILEBLITTING - hardware can do tile blits716 *717 * NOTE: These are for fbcon use only.718 */719 info->flags = 0;720 721/********************* This stage is optional ******************************/722 /*723 * The struct pixmap is a scratch pad for the drawing functions. This724 * is where the monochrome bitmap is constructed by the higher layers725 * and then passed to the accelerator. For drivers that uses726 * cfb_imageblit, you can skip this part. For those that have a more727 * rigorous requirement, this stage is needed728 */729 730 /* PIXMAP_SIZE should be small enough to optimize drawing, but not731 * large enough that memory is wasted. A safe size is732 * (max_xres * max_font_height/8). max_xres is driver dependent,733 * max_font_height is 32.734 */735 info->pixmap.addr = kmalloc(PIXMAP_SIZE, GFP_KERNEL);736 if (!info->pixmap.addr) {737 /* goto error */738 }739 740 info->pixmap.size = PIXMAP_SIZE;741 742 /*743 * FB_PIXMAP_SYSTEM - memory is in system ram744 * FB_PIXMAP_IO - memory is iomapped745 * FB_PIXMAP_SYNC - if set, will call fb_sync() per access to pixmap,746 * usually if FB_PIXMAP_IO is set.747 *748 * Currently, FB_PIXMAP_IO is unimplemented.749 */750 info->pixmap.flags = FB_PIXMAP_SYSTEM;751 752 /*753 * scan_align is the number of padding for each scanline. It is in bytes.754 * Thus for accelerators that need padding to the next u32, put 4 here.755 */756 info->pixmap.scan_align = 4;757 758 /*759 * buf_align is the amount to be padded for the buffer. For example,760 * the i810fb needs a scan_align of 2 but expects it to be fed with761 * dwords, so a buf_align = 4 is required.762 */763 info->pixmap.buf_align = 4;764 765 /* access_align is how many bits can be accessed from the framebuffer766 * ie. some epson cards allow 16-bit access only. Most drivers will767 * be safe with u32 here.768 *769 * NOTE: This field is currently unused.770 */771 info->pixmap.access_align = 32;772/***************************** End optional stage ***************************/773 774 /*775 * This should give a reasonable default video mode. The following is776 * done when we can set a video mode.777 */778 if (!mode_option)779 mode_option = "640x480@60";780 781 retval = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);782 783 if (!retval || retval == 4)784 return -EINVAL;785 786 /* This has to be done! */787 if (fb_alloc_cmap(&info->cmap, cmap_len, 0))788 return -ENOMEM;789 790 /*791 * The following is done in the case of having hardware with a static792 * mode. If we are setting the mode ourselves we don't call this.793 */794 info->var = xxxfb_var;795 796 /*797 * For drivers that can...798 */799 xxxfb_check_var(&info->var, info);800 801 /*802 * Does a call to fb_set_par() before register_framebuffer needed? This803 * will depend on you and the hardware. If you are sure that your driver804 * is the only device in the system, a call to fb_set_par() is safe.805 *806 * Hardware in x86 systems has a VGA core. Calling set_par() at this807 * point will corrupt the VGA console, so it might be safer to skip a808 * call to set_par here and just allow fbcon to do it for you.809 */810 /* xxxfb_set_par(info); */811 812 if (register_framebuffer(info) < 0) {813 fb_dealloc_cmap(&info->cmap);814 return -EINVAL;815 }816 fb_info(info, "%s frame buffer device\n", info->fix.id);817 pci_set_drvdata(dev, info); /* or platform_set_drvdata(pdev, info) */818 return 0;819}820 821 /*822 * Cleanup823 */824/* static void xxxfb_remove(struct platform_device *pdev) */825static void xxxfb_remove(struct pci_dev *dev)826{827 struct fb_info *info = pci_get_drvdata(dev);828 /* or platform_get_drvdata(pdev); */829 830 if (info) {831 unregister_framebuffer(info);832 fb_dealloc_cmap(&info->cmap);833 /* ... */834 framebuffer_release(info);835 }836}837 838#ifdef CONFIG_PCI839#ifdef CONFIG_PM840/**841 * xxxfb_suspend - Optional but recommended function. Suspend the device.842 * @dev: PCI device843 * @msg: the suspend event code.844 *845 * See Documentation/driver-api/pm/devices.rst for more information846 */847static int xxxfb_suspend(struct device *dev)848{849 struct fb_info *info = dev_get_drvdata(dev);850 struct xxxfb_par *par = info->par;851 852 /* suspend here */853 return 0;854}855 856/**857 * xxxfb_resume - Optional but recommended function. Resume the device.858 * @dev: PCI device859 *860 * See Documentation/driver-api/pm/devices.rst for more information861 */862static int xxxfb_resume(struct device *dev)863{864 struct fb_info *info = dev_get_drvdata(dev);865 struct xxxfb_par *par = info->par;866 867 /* resume here */868 return 0;869}870#else871#define xxxfb_suspend NULL872#define xxxfb_resume NULL873#endif /* CONFIG_PM */874 875static const struct pci_device_id xxxfb_id_table[] = {876 { PCI_VENDOR_ID_XXX, PCI_DEVICE_ID_XXX,877 PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,878 PCI_CLASS_MASK, 0 },879 { 0, }880};881 882static SIMPLE_DEV_PM_OPS(xxxfb_pm_ops, xxxfb_suspend, xxxfb_resume);883 884/* For PCI drivers */885static struct pci_driver xxxfb_driver = {886 .name = "xxxfb",887 .id_table = xxxfb_id_table,888 .probe = xxxfb_probe,889 .remove = xxxfb_remove,890 .driver.pm = xxxfb_pm_ops, /* optional but recommended */891};892 893MODULE_DEVICE_TABLE(pci, xxxfb_id_table);894 895static int __init xxxfb_init(void)896{897 /*898 * For kernel boot options (in 'video=xxxfb:<options>' format)899 */900#ifndef MODULE901 char *option = NULL;902 903 if (fb_get_options("xxxfb", &option))904 return -ENODEV;905 xxxfb_setup(option);906#endif907 908 return pci_register_driver(&xxxfb_driver);909}910 911static void __exit xxxfb_exit(void)912{913 pci_unregister_driver(&xxxfb_driver);914}915#else /* non PCI, platform drivers */916#include <linux/platform_device.h>917/* for platform devices */918 919#ifdef CONFIG_PM920/**921 * xxxfb_suspend - Optional but recommended function. Suspend the device.922 * @dev: platform device923 * @msg: the suspend event code.924 *925 * See Documentation/driver-api/pm/devices.rst for more information926 */927static int xxxfb_suspend(struct platform_device *dev, pm_message_t msg)928{929 struct fb_info *info = platform_get_drvdata(dev);930 struct xxxfb_par *par = info->par;931 932 /* suspend here */933 return 0;934}935 936/**937 * xxxfb_resume - Optional but recommended function. Resume the device.938 * @dev: platform device939 *940 * See Documentation/driver-api/pm/devices.rst for more information941 */942static int xxxfb_resume(struct platform_dev *dev)943{944 struct fb_info *info = platform_get_drvdata(dev);945 struct xxxfb_par *par = info->par;946 947 /* resume here */948 return 0;949}950#else951#define xxxfb_suspend NULL952#define xxxfb_resume NULL953#endif /* CONFIG_PM */954 955static struct platform_device_driver xxxfb_driver = {956 .probe = xxxfb_probe,957 .remove = xxxfb_remove,958 .suspend = xxxfb_suspend, /* optional but recommended */959 .resume = xxxfb_resume, /* optional but recommended */960 .driver = {961 .name = "xxxfb",962 },963};964 965static struct platform_device *xxxfb_device;966 967#ifndef MODULE968 /*969 * Setup970 */971 972/*973 * Only necessary if your driver takes special options,974 * otherwise we fall back on the generic fb_setup().975 */976static int __init xxxfb_setup(char *options)977{978 /* Parse user specified options (`video=xxxfb:') */979}980#endif /* MODULE */981 982static int __init xxxfb_init(void)983{984 int ret;985 /*986 * For kernel boot options (in 'video=xxxfb:<options>' format)987 */988#ifndef MODULE989 char *option = NULL;990#endif991 992 if (fb_modesetting_disabled("xxxfb"))993 return -ENODEV;994 995#ifndef MODULE996 if (fb_get_options("xxxfb", &option))997 return -ENODEV;998 xxxfb_setup(option);999#endif1000 ret = platform_driver_register(&xxxfb_driver);1001 1002 if (!ret) {1003 xxxfb_device = platform_device_register_simple("xxxfb", 0,1004 NULL, 0);1005 1006 if (IS_ERR(xxxfb_device)) {1007 platform_driver_unregister(&xxxfb_driver);1008 ret = PTR_ERR(xxxfb_device);1009 }1010 }1011 1012 return ret;1013}1014 1015static void __exit xxxfb_exit(void)1016{1017 platform_device_unregister(xxxfb_device);1018 platform_driver_unregister(&xxxfb_driver);1019}1020#endif /* CONFIG_PCI */1021 1022/* ------------------------------------------------------------------------- */1023 1024 1025 /*1026 * Modularization1027 */1028 1029module_init(xxxfb_init);1030module_exit(xxxfb_exit);1031 1032MODULE_LICENSE("GPL");1033