/* * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device * * Modified to new api Jan 2001 by James Simmons (jsimmons@transvirtual.com) * * Created 28 Dec 1997 by Geert Uytterhoeven * * * I have started rewriting this driver as a example of the upcoming new API * The primary goal is to remove the console code from fbdev and place it * into fbcon.c. This reduces the code and makes writing a new fbdev driver * easy since the author doesn't need to worry about console internals. It * also allows the ability to run fbdev without a console/tty system on top * of it. * * First the roles of struct fb_info and struct display have changed. Struct * display will go away. The way the new framebuffer console code will * work is that it will act to translate data about the tty/console in * struct vc_data to data in a device independent way in struct fb_info. Then * various functions in struct fb_ops will be called to store the device * dependent state in the par field in struct fb_info and to change the * hardware to that state. This allows a very clean separation of the fbdev * layer from the console layer. It also allows one to use fbdev on its own * which is a bounus for embedded devices. The reason this approach works is * for each framebuffer device when used as a tty/console device is allocated * a set of virtual terminals to it. Only one virtual terminal can be active * per framebuffer device. We already have all the data we need in struct * vc_data so why store a bunch of colormaps and other fbdev specific data * per virtual terminal. * * As you can see doing this makes the con parameter pretty much useless * for struct fb_ops functions, as it should be. Also having struct * fb_var_screeninfo and other data in fb_info pretty much eliminates the * need for get_fix and get_var. Once all drivers use the fix, var, and cmap * fbcon can be written around these fields. This will also eliminate the * need to regenerate struct fb_var_screeninfo, struct fb_fix_screeninfo * struct fb_cmap every time get_var, get_fix, get_cmap functions are called * as many drivers do now. * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive for * more details. */ #include <linux/aperture.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/errno.h>#include <linux/string.h>#include <linux/mm.h>#include <linux/slab.h>#include <linux/delay.h>#include <linux/fb.h>#include <linux/init.h>#include <linux/pci.h> /* * This is just simple sample code. * * No warranty that it actually compiles. * Even less warranty that it actually works :-) */ /* * Driver data */static char *mode_option; /* * If your driver supports multiple boards, you should make the * below data types arrays, or allocate them dynamically (using kmalloc()). */ /* * This structure defines the hardware state of the graphics card. Normally * you place this in a header file in linux/include/video. This file usually * also includes register information. That allows other driver subsystems * and userland applications the ability to use the same header file to * avoid duplicate work and easy porting of software. */struct xxx_par; /* * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo * if we don't use modedb. If we do use modedb see xxxfb_init how to use it * to get a fb_var_screeninfo. Otherwise define a default var as well. */static const struct fb_fix_screeninfo xxxfb_fix = { .id = "FB's name", .type = FB_TYPE_PACKED_PIXELS, .visual = FB_VISUAL_PSEUDOCOLOR, .xpanstep = 1, .ypanstep = 1, .ywrapstep = 1, .accel = FB_ACCEL_NONE,}; /* * Modern graphical hardware not only supports pipelines but some * also support multiple monitors where each display can have * its own unique data. In this case each display could be * represented by a separate framebuffer device thus a separate * struct fb_info. Now the struct xxx_par represents the graphics * hardware state thus only one exist per card. In this case the * struct xxx_par for each graphics card would be shared between * every struct fb_info that represents a framebuffer on that card. * This allows when one display changes it video resolution (info->var) * the other displays know instantly. Each display can always be * aware of the entire hardware state that affects it because they share * the same xxx_par struct. The other side of the coin is multiple * graphics cards that pass data around until it is finally displayed * on one monitor. Such examples are the voodoo 1 cards and high end * NUMA graphics servers. For this case we have a bunch of pars, each * one that represents a graphics state, that belong to one struct * fb_info. Their you would want to have *par point to a array of device * states and have each struct fb_ops function deal with all those * states. I hope this covers every possible hardware design. If not * feel free to send your ideas at jsimmons@users.sf.net */ /* * If your driver supports multiple boards or it supports multiple * framebuffers, you should make these arrays, or allocate them * dynamically using framebuffer_alloc() and free them with * framebuffer_release(). */static struct fb_info info; /* * Each one represents the state of the hardware. Most hardware have * just one hardware state. These here represent the default state(s). */static struct xxx_par __initdata current_par; /** * xxxfb_open - Optional function. Called when the framebuffer is * first accessed. * @info: frame buffer structure that represents a single frame buffer * @user: tell us if the userland (value=1) or the console is accessing * the framebuffer. * * This function is the first function called in the framebuffer api. * Usually you don't need to provide this function. The case where it * is used is to change from a text mode hardware state to a graphics * mode state. * * Returns negative errno on error, or zero on success. */static int xxxfb_open(struct fb_info *info, int user){ return 0;} /** * xxxfb_release - Optional function. Called when the framebuffer * device is closed. * @info: frame buffer structure that represents a single frame buffer * @user: tell us if the userland (value=1) or the console is accessing * the framebuffer. * * Thus function is called when we close /dev/fb or the framebuffer * console system is released. Usually you don't need this function. * The case where it is usually used is to go from a graphics state * to a text mode state. * * Returns negative errno on error, or zero on success. */static int xxxfb_release(struct fb_info *info, int user){ return 0;} /** * xxxfb_check_var - Optional function. Validates a var passed in. * @var: frame buffer variable screen structure * @info: frame buffer structure that represents a single frame buffer * * Checks to see if the hardware supports the state requested by * var passed in. This function does not alter the hardware state!!! * This means the data stored in struct fb_info and struct xxx_par do * not change. This includes the var inside of struct fb_info. * Do NOT change these. This function can be called on its own if we * intent to only test a mode and not actually set it. The stuff in * modedb.c is a example of this. If the var passed in is slightly * off by what the hardware can support then we alter the var PASSED in * to what we can do. * * For values that are off, this function must round them _up_ to the * next value that is supported by the hardware. If the value is * greater than the highest value supported by the hardware, then this * function must return -EINVAL. * * Exception to the above rule: Some drivers have a fixed mode, ie, * the hardware is already set at boot up, and cannot be changed. In * this case, it is more acceptable that this function just return * a copy of the currently working var (info->var). Better is to not * implement this function, as the upper layer will do the copying * of the current var for you. * * Note: This is the only function where the contents of var can be * freely adjusted after the driver has been registered. If you find * that you have code outside of this function that alters the content * of var, then you are doing something wrong. Note also that the * contents of info->var must be left untouched at all times after * driver registration. * * Returns negative errno on error, or zero on success. */static int xxxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info){ /* ... */ return 0;} /** * xxxfb_set_par - Optional function. Alters the hardware state. * @info: frame buffer structure that represents a single frame buffer * * Using the fb_var_screeninfo in fb_info we set the resolution of the * this particular framebuffer. This function alters the par AND the * fb_fix_screeninfo stored in fb_info. It doesn't not alter var in * fb_info since we are using that data. This means we depend on the * data in var inside fb_info to be supported by the hardware. * * This function is also used to recover/restore the hardware to a * known working state. * * xxxfb_check_var is always called before xxxfb_set_par to ensure that * the contents of var is always valid. * * Again if you can't change the resolution you don't need this function. * * However, even if your hardware does not support mode changing, * a set_par might be needed to at least initialize the hardware to * a known working state, especially if it came back from another * process that also modifies the same hardware, such as X. * * If this is the case, a combination such as the following should work: * * static int xxxfb_check_var(struct fb_var_screeninfo *var, * struct fb_info *info) * { * *var = info->var; * return 0; * } * * static int xxxfb_set_par(struct fb_info *info) * { * init your hardware here * } * * Returns negative errno on error, or zero on success. */static int xxxfb_set_par(struct fb_info *info){ struct xxx_par *par = info->par; /* ... */ return 0;} /** * xxxfb_setcolreg - Optional function. Sets a color register. * @regno: Which register in the CLUT we are programming * @red: The red value which can be up to 16 bits wide * @green: The green value which can be up to 16 bits wide * @blue: The blue value which can be up to 16 bits wide. * @transp: If supported, the alpha value which can be up to 16 bits wide. * @info: frame buffer info structure * * Set a single color register. The values supplied have a 16 bit * magnitude which needs to be scaled in this function for the hardware. * Things to take into consideration are how many color registers, if * any, are supported with the current color visual. With truecolor mode * no color palettes are supported. Here a pseudo palette is created * which we store the value in pseudo_palette in struct fb_info. For * pseudocolor mode we have a limited color palette. To deal with this * we can program what color is displayed for a particular pixel value. * DirectColor is similar in that we can program each color field. If * we have a static colormap we don't need to implement this function. * * Returns negative errno on error, or zero on success. */static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *info){ if (regno >= 256) /* no. of hw registers */ return -EINVAL; /* * Program hardware... do anything you want with transp */ /* grayscale works only partially under directcolor */ if (info->var.grayscale) { /* grayscale = 0.30*R + 0.59*G + 0.11*B */ red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8; } /* Directcolor: * var->{color}.offset contains start of bitfield * var->{color}.length contains length of bitfield * {hardwarespecific} contains width of DAC * pseudo_palette[X] is programmed to (X << red.offset) | * (X << green.offset) | * (X << blue.offset) * RAMDAC[X] is programmed to (red, green, blue) * color depth = SUM(var->{color}.length) * * Pseudocolor: * var->{color}.offset is 0 unless the palette index takes less than * bits_per_pixel bits and is stored in the upper * bits of the pixel value * var->{color}.length is set so that 1 << length is the number of * available palette entries * pseudo_palette is not used * RAMDAC[X] is programmed to (red, green, blue) * color depth = var->{color}.length * * Static pseudocolor: * same as Pseudocolor, but the RAMDAC is not programmed (read-only) * * Mono01/Mono10: * Has only 2 values, black on white or white on black (fg on bg), * var->{color}.offset is 0 * white = (1 << var->{color}.length) - 1, black = 0 * pseudo_palette is not used * RAMDAC does not exist * color depth is always 2 * * Truecolor: * does not use RAMDAC (usually has 3 of them). * var->{color}.offset contains start of bitfield * var->{color}.length contains length of bitfield * pseudo_palette is programmed to (red << red.offset) | * (green << green.offset) | * (blue << blue.offset) | * (transp << transp.offset) * RAMDAC does not exist * color depth = SUM(var->{color}.length}) * * The color depth is used by fbcon for choosing the logo and also * for color palette transformation if color depth < 4 * * As can be seen from the above, the field bits_per_pixel is _NOT_ * a criteria for describing the color visual. * * A common mistake is assuming that bits_per_pixel <= 8 is pseudocolor, * and higher than that, true/directcolor. This is incorrect, one needs * to look at the fix->visual. * * Another common mistake is using bits_per_pixel to calculate the color * depth. The bits_per_pixel field does not directly translate to color * depth. You have to compute for the color depth (using the color * bitfields) and fix->visual as seen above. */ /* * This is the point where the color is converted to something that * is acceptable by the hardware. */#define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16) red = CNVT_TOHW(red, info->var.red.length); green = CNVT_TOHW(green, info->var.green.length); blue = CNVT_TOHW(blue, info->var.blue.length); transp = CNVT_TOHW(transp, info->var.transp.length);#undef CNVT_TOHW /* * This is the point where the function feeds the color to the hardware * palette after converting the colors to something acceptable by * the hardware. Note, only FB_VISUAL_DIRECTCOLOR and * FB_VISUAL_PSEUDOCOLOR visuals need to write to the hardware palette. * If you have code that writes to the hardware CLUT, and it's not * any of the above visuals, then you are doing something wrong. */ if (info->fix.visual == FB_VISUAL_DIRECTCOLOR || info->fix.visual == FB_VISUAL_TRUECOLOR) write_{red|green|blue|transp}_to_clut(); /* This is the point were you need to fill up the contents of * info->pseudo_palette. This structure is used _only_ by fbcon, thus * it only contains 16 entries to match the number of colors supported * by the console. The pseudo_palette is used only if the visual is * in directcolor or truecolor mode. With other visuals, the * pseudo_palette is not used. (This might change in the future.) * * The contents of the pseudo_palette is in raw pixel format. Ie, each * entry can be written directly to the framebuffer without any conversion. * The pseudo_palette is (void *). However, if using the generic * drawing functions (cfb_imageblit, cfb_fillrect), the pseudo_palette * must be casted to (u32 *) _regardless_ of the bits per pixel. If the * driver is using its own drawing functions, then it can use whatever * size it wants. */ if (info->fix.visual == FB_VISUAL_TRUECOLOR || info->fix.visual == FB_VISUAL_DIRECTCOLOR) { u32 v; if (regno >= 16) return -EINVAL; v = (red << info->var.red.offset) | (green << info->var.green.offset) | (blue << info->var.blue.offset) | (transp << info->var.transp.offset); ((u32*)(info->pseudo_palette))[regno] = v; } /* ... */ return 0;} /** * xxxfb_pan_display - NOT a required function. Pans the display. * @var: frame buffer variable screen structure * @info: frame buffer structure that represents a single frame buffer * * Pan (or wrap, depending on the `vmode' field) the display using the * `xoffset' and `yoffset' fields of the `var' structure. * If the values don't fit, return -EINVAL. * * Returns negative errno on error, or zero on success. */static int xxxfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info){ /* * If your hardware does not support panning, _do_ _not_ implement this * function. Creating a dummy function will just confuse user apps. */ /* * Note that even if this function is fully functional, a setting of * 0 in both xpanstep and ypanstep means that this function will never * get called. */ /* ... */ return 0;} /** * xxxfb_blank - NOT a required function. Blanks the display. * @blank_mode: the blank mode we want. * @info: frame buffer structure that represents a single frame buffer * * Blank the screen if blank_mode != FB_BLANK_UNBLANK, else unblank. * Return 0 if blanking succeeded, != 0 if un-/blanking failed due to * e.g. a video mode which doesn't support it. * * Implements VESA suspend and powerdown modes on hardware that supports * disabling hsync/vsync: * * FB_BLANK_NORMAL = display is blanked, syncs are on. * FB_BLANK_HSYNC_SUSPEND = hsync off * FB_BLANK_VSYNC_SUSPEND = vsync off * FB_BLANK_POWERDOWN = hsync and vsync off * * If implementing this function, at least support FB_BLANK_UNBLANK. * Return !0 for any modes that are unimplemented. * */static int xxxfb_blank(int blank_mode, struct fb_info *info){ /* ... */ return 0;} /* ------------ Accelerated Functions --------------------- */ /* * We provide our own functions if we have hardware acceleration * or non packed pixel format layouts. If we have no hardware * acceleration, we can use a generic unaccelerated function. If using * a pack pixel format just use the functions in cfb_*.c. Each file * has one of the three different accel functions we support. */ /** * xxxfb_fillrect - REQUIRED function. Can use generic routines if * non acclerated hardware and packed pixel based. * Draws a rectangle on the screen. * * @info: frame buffer structure that represents a single frame buffer * @region: The structure representing the rectangular region we * wish to draw to. * * This drawing operation places/removes a retangle on the screen * depending on the rastering operation with the value of color which * is in the current color depth format. */void xxxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region){/* Meaning of struct fb_fillrect * * @dx: The x and y corrdinates of the upper left hand corner of the * @dy: area we want to draw to. * @width: How wide the rectangle is we want to draw. * @height: How tall the rectangle is we want to draw. * @color: The color to fill in the rectangle with.Lines 1–500 of 1032. Load more
/* * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device * * Modified to new api Jan 2001 by James Simmons (jsimmons@transvirtual.com) * * Created 28 Dec 1997 by Geert Uytterhoeven * * * I have started rewriting this driver as a example of the upcoming new API * The primary goal is to remove the console code from fbdev and place it * into fbcon.c. This reduces the code and makes writing a new fbdev driver * easy since the author doesn't need to worry about console internals. It * also allows the ability to run fbdev without a console/tty system on top * of it. * * First the roles of struct fb_info and struct display have changed. Struct * display will go away. The way the new framebuffer console code will * work is that it will act to translate data about the tty/console in * struct vc_data to data in a device independent way in struct fb_info. Then * various functions in struct fb_ops will be called to store the device * dependent state in the par field in struct fb_info and to change the * hardware to that state. This allows a very clean separation of the fbdev * layer from the console layer. It also allows one to use fbdev on its own * which is a bounus for embedded devices. The reason this approach works is * for each framebuffer device when used as a tty/console device is allocated * a set of virtual terminals to it. Only one virtual terminal can be active * per framebuffer device. We already have all the data we need in struct * vc_data so why store a bunch of colormaps and other fbdev specific data * per virtual terminal. * * As you can see doing this makes the con parameter pretty much useless * for struct fb_ops functions, as it should be. Also having struct * fb_var_screeninfo and other data in fb_info pretty much eliminates the * need for get_fix and get_var. Once all drivers use the fix, var, and cmap * fbcon can be written around these fields. This will also eliminate the * need to regenerate struct fb_var_screeninfo, struct fb_fix_screeninfo * struct fb_cmap every time get_var, get_fix, get_cmap functions are called * as many drivers do now. * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive for * more details. */ #include <linux/aperture.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/string.h> #include <linux/mm.h> #include <linux/slab.h> #include <linux/delay.h> #include <linux/fb.h> #include <linux/init.h> #include <linux/pci.h> /* * This is just simple sample code. * * No warranty that it actually compiles. * Even less warranty that it actually works :-) */ /* * Driver data */ static char *mode_option; /* * If your driver supports multiple boards, you should make the * below data types arrays, or allocate them dynamically (using kmalloc()). */ /* * This structure defines the hardware state of the graphics card. Normally * you place this in a header file in linux/include/video. This file usually * also includes register information. That allows other driver subsystems * and userland applications the ability to use the same header file to * avoid duplicate work and easy porting of software. */ struct xxx_par; /* * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo * if we don't use modedb. If we do use modedb see xxxfb_init how to use it * to get a fb_var_screeninfo. Otherwise define a default var as well. */ static const struct fb_fix_screeninfo xxxfb_fix = { .id = "FB's name", .type = FB_TYPE_PACKED_PIXELS, .visual = FB_VISUAL_PSEUDOCOLOR, .xpanstep = 1, .ypanstep = 1, .ywrapstep = 1, .accel = FB_ACCEL_NONE, }; /* * Modern graphical hardware not only supports pipelines but some * also support multiple monitors where each display can have * its own unique data. In this case each display could be * represented by a separate framebuffer device thus a separate * struct fb_info. Now the struct xxx_par represents the graphics * hardware state thus only one exist per card. In this case the * struct xxx_par for each graphics card would be shared between * every struct fb_info that represents a framebuffer on that card. * This allows when one display changes it video resolution (info->var) * the other displays know instantly. Each display can always be * aware of the entire hardware state that affects it because they share * the same xxx_par struct. The other side of the coin is multiple * graphics cards that pass data around until it is finally displayed * on one monitor. Such examples are the voodoo 1 cards and high end * NUMA graphics servers. For this case we have a bunch of pars, each * one that represents a graphics state, that belong to one struct * fb_info. Their you would want to have *par point to a array of device * states and have each struct fb_ops function deal with all those * states. I hope this covers every possible hardware design. If not * feel free to send your ideas at jsimmons@users.sf.net */ /* * If your driver supports multiple boards or it supports multiple * framebuffers, you should make these arrays, or allocate them * dynamically using framebuffer_alloc() and free them with * framebuffer_release(). */ static struct fb_info info; /* * Each one represents the state of the hardware. Most hardware have * just one hardware state. These here represent the default state(s). */ static struct xxx_par __initdata current_par; /** * xxxfb_open - Optional function. Called when the framebuffer is * first accessed. * @info: frame buffer structure that represents a single frame buffer * @user: tell us if the userland (value=1) or the console is accessing * the framebuffer. * * This function is the first function called in the framebuffer api. * Usually you don't need to provide this function. The case where it * is used is to change from a text mode hardware state to a graphics * mode state. * * Returns negative errno on error, or zero on success. */ static int xxxfb_open(struct fb_info *info, int user) { return 0; } /** * xxxfb_release - Optional function. Called when the framebuffer * device is closed. * @info: frame buffer structure that represents a single frame buffer * @user: tell us if the userland (value=1) or the console is accessing * the framebuffer. * * Thus function is called when we close /dev/fb or the framebuffer * console system is released. Usually you don't need this function. * The case where it is usually used is to go from a graphics state * to a text mode state. * * Returns negative errno on error, or zero on success. */ static int xxxfb_release(struct fb_info *info, int user) { return 0; } /** * xxxfb_check_var - Optional function. Validates a var passed in. * @var: frame buffer variable screen structure * @info: frame buffer structure that represents a single frame buffer * * Checks to see if the hardware supports the state requested by * var passed in. This function does not alter the hardware state!!! * This means the data stored in struct fb_info and struct xxx_par do * not change. This includes the var inside of struct fb_info. * Do NOT change these. This function can be called on its own if we * intent to only test a mode and not actually set it. The stuff in * modedb.c is a example of this. If the var passed in is slightly * off by what the hardware can support then we alter the var PASSED in * to what we can do. * * For values that are off, this function must round them _up_ to the * next value that is supported by the hardware. If the value is * greater than the highest value supported by the hardware, then this * function must return -EINVAL. * * Exception to the above rule: Some drivers have a fixed mode, ie, * the hardware is already set at boot up, and cannot be changed. In * this case, it is more acceptable that this function just return * a copy of the currently working var (info->var). Better is to not * implement this function, as the upper layer will do the copying * of the current var for you. * * Note: This is the only function where the contents of var can be * freely adjusted after the driver has been registered. If you find * that you have code outside of this function that alters the content * of var, then you are doing something wrong. Note also that the * contents of info->var must be left untouched at all times after * driver registration. * * Returns negative errno on error, or zero on success. */ static int xxxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) { /* ... */ return 0; } /** * xxxfb_set_par - Optional function. Alters the hardware state. * @info: frame buffer structure that represents a single frame buffer * * Using the fb_var_screeninfo in fb_info we set the resolution of the * this particular framebuffer. This function alters the par AND the * fb_fix_screeninfo stored in fb_info. It doesn't not alter var in * fb_info since we are using that data. This means we depend on the * data in var inside fb_info to be supported by the hardware. * * This function is also used to recover/restore the hardware to a * known working state. * * xxxfb_check_var is always called before xxxfb_set_par to ensure that * the contents of var is always valid. * * Again if you can't change the resolution you don't need this function. * * However, even if your hardware does not support mode changing, * a set_par might be needed to at least initialize the hardware to * a known working state, especially if it came back from another * process that also modifies the same hardware, such as X. * * If this is the case, a combination such as the following should work: * * static int xxxfb_check_var(struct fb_var_screeninfo *var, * struct fb_info *info) * { * *var = info->var; * return 0; * } * * static int xxxfb_set_par(struct fb_info *info) * { * init your hardware here * } * * Returns negative errno on error, or zero on success. */ static int xxxfb_set_par(struct fb_info *info) { struct xxx_par *par = info->par; /* ... */ return 0; } /** * xxxfb_setcolreg - Optional function. Sets a color register. * @regno: Which register in the CLUT we are programming * @red: The red value which can be up to 16 bits wide * @green: The green value which can be up to 16 bits wide * @blue: The blue value which can be up to 16 bits wide. * @transp: If supported, the alpha value which can be up to 16 bits wide. * @info: frame buffer info structure * * Set a single color register. The values supplied have a 16 bit * magnitude which needs to be scaled in this function for the hardware. * Things to take into consideration are how many color registers, if * any, are supported with the current color visual. With truecolor mode * no color palettes are supported. Here a pseudo palette is created * which we store the value in pseudo_palette in struct fb_info. For * pseudocolor mode we have a limited color palette. To deal with this * we can program what color is displayed for a particular pixel value. * DirectColor is similar in that we can program each color field. If * we have a static colormap we don't need to implement this function. * * Returns negative errno on error, or zero on success. */ static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *info) { if (regno >= 256) /* no. of hw registers */ return -EINVAL; /* * Program hardware... do anything you want with transp */ /* grayscale works only partially under directcolor */ if (info->var.grayscale) { /* grayscale = 0.30*R + 0.59*G + 0.11*B */ red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8; } /* Directcolor: * var->{color}.offset contains start of bitfield * var->{color}.length contains length of bitfield * {hardwarespecific} contains width of DAC * pseudo_palette[X] is programmed to (X << red.offset) | * (X << green.offset) | * (X << blue.offset) * RAMDAC[X] is programmed to (red, green, blue) * color depth = SUM(var->{color}.length) * * Pseudocolor: * var->{color}.offset is 0 unless the palette index takes less than * bits_per_pixel bits and is stored in the upper * bits of the pixel value * var->{color}.length is set so that 1 << length is the number of * available palette entries * pseudo_palette is not used * RAMDAC[X] is programmed to (red, green, blue) * color depth = var->{color}.length * * Static pseudocolor: * same as Pseudocolor, but the RAMDAC is not programmed (read-only) * * Mono01/Mono10: * Has only 2 values, black on white or white on black (fg on bg), * var->{color}.offset is 0 * white = (1 << var->{color}.length) - 1, black = 0 * pseudo_palette is not used * RAMDAC does not exist * color depth is always 2 * * Truecolor: * does not use RAMDAC (usually has 3 of them). * var->{color}.offset contains start of bitfield * var->{color}.length contains length of bitfield * pseudo_palette is programmed to (red << red.offset) | * (green << green.offset) | * (blue << blue.offset) | * (transp << transp.offset) * RAMDAC does not exist * color depth = SUM(var->{color}.length}) * * The color depth is used by fbcon for choosing the logo and also * for color palette transformation if color depth < 4 * * As can be seen from the above, the field bits_per_pixel is _NOT_ * a criteria for describing the color visual. * * A common mistake is assuming that bits_per_pixel <= 8 is pseudocolor, * and higher than that, true/directcolor. This is incorrect, one needs * to look at the fix->visual. * * Another common mistake is using bits_per_pixel to calculate the color * depth. The bits_per_pixel field does not directly translate to color * depth. You have to compute for the color depth (using the color * bitfields) and fix->visual as seen above. */ /* * This is the point where the color is converted to something that * is acceptable by the hardware. */ #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16) red = CNVT_TOHW(red, info->var.red.length); green = CNVT_TOHW(green, info->var.green.length); blue = CNVT_TOHW(blue, info->var.blue.length); transp = CNVT_TOHW(transp, info->var.transp.length); #undef CNVT_TOHW /* * This is the point where the function feeds the color to the hardware * palette after converting the colors to something acceptable by * the hardware. Note, only FB_VISUAL_DIRECTCOLOR and * FB_VISUAL_PSEUDOCOLOR visuals need to write to the hardware palette. * If you have code that writes to the hardware CLUT, and it's not * any of the above visuals, then you are doing something wrong. */ if (info->fix.visual == FB_VISUAL_DIRECTCOLOR || info->fix.visual == FB_VISUAL_TRUECOLOR) write_{red|green|blue|transp}_to_clut(); /* This is the point were you need to fill up the contents of * info->pseudo_palette. This structure is used _only_ by fbcon, thus * it only contains 16 entries to match the number of colors supported * by the console. The pseudo_palette is used only if the visual is * in directcolor or truecolor mode. With other visuals, the * pseudo_palette is not used. (This might change in the future.) * * The contents of the pseudo_palette is in raw pixel format. Ie, each * entry can be written directly to the framebuffer without any conversion. * The pseudo_palette is (void *). However, if using the generic * drawing functions (cfb_imageblit, cfb_fillrect), the pseudo_palette * must be casted to (u32 *) _regardless_ of the bits per pixel. If the * driver is using its own drawing functions, then it can use whatever * size it wants. */ if (info->fix.visual == FB_VISUAL_TRUECOLOR || info->fix.visual == FB_VISUAL_DIRECTCOLOR) { u32 v; if (regno >= 16) return -EINVAL; v = (red << info->var.red.offset) | (green << info->var.green.offset) | (blue << info->var.blue.offset) | (transp << info->var.transp.offset); ((u32*)(info->pseudo_palette))[regno] = v; } /* ... */ return 0; } /** * xxxfb_pan_display - NOT a required function. Pans the display. * @var: frame buffer variable screen structure * @info: frame buffer structure that represents a single frame buffer * * Pan (or wrap, depending on the `vmode' field) the display using the * `xoffset' and `yoffset' fields of the `var' structure. * If the values don't fit, return -EINVAL. * * Returns negative errno on error, or zero on success. */ static int xxxfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) { /* * If your hardware does not support panning, _do_ _not_ implement this * function. Creating a dummy function will just confuse user apps. */ /* * Note that even if this function is fully functional, a setting of * 0 in both xpanstep and ypanstep means that this function will never * get called. */ /* ... */ return 0; } /** * xxxfb_blank - NOT a required function. Blanks the display. * @blank_mode: the blank mode we want. * @info: frame buffer structure that represents a single frame buffer * * Blank the screen if blank_mode != FB_BLANK_UNBLANK, else unblank. * Return 0 if blanking succeeded, != 0 if un-/blanking failed due to * e.g. a video mode which doesn't support it. * * Implements VESA suspend and powerdown modes on hardware that supports * disabling hsync/vsync: * * FB_BLANK_NORMAL = display is blanked, syncs are on. * FB_BLANK_HSYNC_SUSPEND = hsync off * FB_BLANK_VSYNC_SUSPEND = vsync off * FB_BLANK_POWERDOWN = hsync and vsync off * * If implementing this function, at least support FB_BLANK_UNBLANK. * Return !0 for any modes that are unimplemented. * */ static int xxxfb_blank(int blank_mode, struct fb_info *info) { /* ... */ return 0; } /* ------------ Accelerated Functions --------------------- */ /* * We provide our own functions if we have hardware acceleration * or non packed pixel format layouts. If we have no hardware * acceleration, we can use a generic unaccelerated function. If using * a pack pixel format just use the functions in cfb_*.c. Each file * has one of the three different accel functions we support. */ /** * xxxfb_fillrect - REQUIRED function. Can use generic routines if * non acclerated hardware and packed pixel based. * Draws a rectangle on the screen. * * @info: frame buffer structure that represents a single frame buffer * @region: The structure representing the rectangular region we * wish to draw to. * * This drawing operation places/removes a retangle on the screen * depending on the rastering operation with the value of color which * is in the current color depth format. */ void xxxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region) { /* Meaning of struct fb_fillrect * * @dx: The x and y corrdinates of the upper left hand corner of the * @dy: area we want to draw to. * @width: How wide the rectangle is we want to draw. * @height: How tall the rectangle is we want to draw. * @color: The color to fill in the rectangle with.