Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device
0003  *
0004  *  Modified to new api Jan 2001 by James Simmons (jsimmons@transvirtual.com)
0005  *
0006  *  Created 28 Dec 1997 by Geert Uytterhoeven
0007  *
0008  *
0009  *  I have started rewriting this driver as a example of the upcoming new API
0010  *  The primary goal is to remove the console code from fbdev and place it
0011  *  into fbcon.c. This reduces the code and makes writing a new fbdev driver
0012  *  easy since the author doesn't need to worry about console internals. It
0013  *  also allows the ability to run fbdev without a console/tty system on top 
0014  *  of it. 
0015  *
0016  *  First the roles of struct fb_info and struct display have changed. Struct
0017  *  display will go away. The way the new framebuffer console code will
0018  *  work is that it will act to translate data about the tty/console in 
0019  *  struct vc_data to data in a device independent way in struct fb_info. Then
0020  *  various functions in struct fb_ops will be called to store the device 
0021  *  dependent state in the par field in struct fb_info and to change the 
0022  *  hardware to that state. This allows a very clean separation of the fbdev
0023  *  layer from the console layer. It also allows one to use fbdev on its own
0024  *  which is a bounus for embedded devices. The reason this approach works is  
0025  *  for each framebuffer device when used as a tty/console device is allocated
0026  *  a set of virtual terminals to it. Only one virtual terminal can be active 
0027  *  per framebuffer device. We already have all the data we need in struct 
0028  *  vc_data so why store a bunch of colormaps and other fbdev specific data
0029  *  per virtual terminal. 
0030  *
0031  *  As you can see doing this makes the con parameter pretty much useless
0032  *  for struct fb_ops functions, as it should be. Also having struct  
0033  *  fb_var_screeninfo and other data in fb_info pretty much eliminates the 
0034  *  need for get_fix and get_var. Once all drivers use the fix, var, and cmap
0035  *  fbcon can be written around these fields. This will also eliminate the
0036  *  need to regenerate struct fb_var_screeninfo, struct fb_fix_screeninfo
0037  *  struct fb_cmap every time get_var, get_fix, get_cmap functions are called
0038  *  as many drivers do now. 
0039  *
0040  *  This file is subject to the terms and conditions of the GNU General Public
0041  *  License. See the file COPYING in the main directory of this archive for
0042  *  more details.
0043  */
0044 
0045 #include <linux/module.h>
0046 #include <linux/kernel.h>
0047 #include <linux/errno.h>
0048 #include <linux/string.h>
0049 #include <linux/mm.h>
0050 #include <linux/slab.h>
0051 #include <linux/delay.h>
0052 #include <linux/fb.h>
0053 #include <linux/init.h>
0054 #include <linux/pci.h>
0055 
0056     /*
0057      *  This is just simple sample code.
0058      *
0059      *  No warranty that it actually compiles.
0060      *  Even less warranty that it actually works :-)
0061      */
0062 
0063 /*
0064  * Driver data
0065  */
0066 static char *mode_option;
0067 
0068 /*
0069  *  If your driver supports multiple boards, you should make the  
0070  *  below data types arrays, or allocate them dynamically (using kmalloc()). 
0071  */ 
0072 
0073 /* 
0074  * This structure defines the hardware state of the graphics card. Normally
0075  * you place this in a header file in linux/include/video. This file usually
0076  * also includes register information. That allows other driver subsystems
0077  * and userland applications the ability to use the same header file to 
0078  * avoid duplicate work and easy porting of software. 
0079  */
0080 struct xxx_par;
0081 
0082 /*
0083  * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
0084  * if we don't use modedb. If we do use modedb see xxxfb_init how to use it
0085  * to get a fb_var_screeninfo. Otherwise define a default var as well. 
0086  */
0087 static const struct fb_fix_screeninfo xxxfb_fix = {
0088     .id =       "FB's name", 
0089     .type =     FB_TYPE_PACKED_PIXELS,
0090     .visual =   FB_VISUAL_PSEUDOCOLOR,
0091     .xpanstep = 1,
0092     .ypanstep = 1,
0093     .ywrapstep =    1, 
0094     .accel =    FB_ACCEL_NONE,
0095 };
0096 
0097     /*
0098      *  Modern graphical hardware not only supports pipelines but some 
0099      *  also support multiple monitors where each display can have
0100      *  its own unique data. In this case each display could be  
0101      *  represented by a separate framebuffer device thus a separate 
0102      *  struct fb_info. Now the struct xxx_par represents the graphics
0103      *  hardware state thus only one exist per card. In this case the 
0104      *  struct xxx_par for each graphics card would be shared between 
0105      *  every struct fb_info that represents a framebuffer on that card. 
0106      *  This allows when one display changes it video resolution (info->var) 
0107      *  the other displays know instantly. Each display can always be
0108      *  aware of the entire hardware state that affects it because they share
0109      *  the same xxx_par struct. The other side of the coin is multiple
0110      *  graphics cards that pass data around until it is finally displayed
0111      *  on one monitor. Such examples are the voodoo 1 cards and high end
0112      *  NUMA graphics servers. For this case we have a bunch of pars, each
0113      *  one that represents a graphics state, that belong to one struct 
0114      *  fb_info. Their you would want to have *par point to a array of device
0115      *  states and have each struct fb_ops function deal with all those 
0116      *  states. I hope this covers every possible hardware design. If not
0117      *  feel free to send your ideas at jsimmons@users.sf.net 
0118      */
0119 
0120     /*
0121      *  If your driver supports multiple boards or it supports multiple 
0122      *  framebuffers, you should make these arrays, or allocate them 
0123      *  dynamically using framebuffer_alloc() and free them with
0124      *  framebuffer_release().
0125      */ 
0126 static struct fb_info info;
0127 
0128     /* 
0129      * Each one represents the state of the hardware. Most hardware have
0130      * just one hardware state. These here represent the default state(s). 
0131      */
0132 static struct xxx_par __initdata current_par;
0133 
0134 /**
0135  *  xxxfb_open - Optional function. Called when the framebuffer is
0136  *           first accessed.
0137  *  @info: frame buffer structure that represents a single frame buffer
0138  *  @user: tell us if the userland (value=1) or the console is accessing
0139  *         the framebuffer. 
0140  *
0141  *  This function is the first function called in the framebuffer api.
0142  *  Usually you don't need to provide this function. The case where it 
0143  *  is used is to change from a text mode hardware state to a graphics
0144  *  mode state. 
0145  *
0146  *  Returns negative errno on error, or zero on success.
0147  */
0148 static int xxxfb_open(struct fb_info *info, int user)
0149 {
0150     return 0;
0151 }
0152 
0153 /**
0154  *  xxxfb_release - Optional function. Called when the framebuffer 
0155  *          device is closed. 
0156  *  @info: frame buffer structure that represents a single frame buffer
0157  *  @user: tell us if the userland (value=1) or the console is accessing
0158  *         the framebuffer. 
0159  *  
0160  *  Thus function is called when we close /dev/fb or the framebuffer 
0161  *  console system is released. Usually you don't need this function.
0162  *  The case where it is usually used is to go from a graphics state
0163  *  to a text mode state.
0164  *
0165  *  Returns negative errno on error, or zero on success.
0166  */
0167 static int xxxfb_release(struct fb_info *info, int user)
0168 {
0169     return 0;
0170 }
0171 
0172 /**
0173  *      xxxfb_check_var - Optional function. Validates a var passed in. 
0174  *      @var: frame buffer variable screen structure
0175  *      @info: frame buffer structure that represents a single frame buffer 
0176  *
0177  *  Checks to see if the hardware supports the state requested by
0178  *  var passed in. This function does not alter the hardware state!!! 
0179  *  This means the data stored in struct fb_info and struct xxx_par do 
0180  *      not change. This includes the var inside of struct fb_info. 
0181  *  Do NOT change these. This function can be called on its own if we
0182  *  intent to only test a mode and not actually set it. The stuff in 
0183  *  modedb.c is a example of this. If the var passed in is slightly 
0184  *  off by what the hardware can support then we alter the var PASSED in
0185  *  to what we can do.
0186  *
0187  *      For values that are off, this function must round them _up_ to the
0188  *      next value that is supported by the hardware.  If the value is
0189  *      greater than the highest value supported by the hardware, then this
0190  *      function must return -EINVAL.
0191  *
0192  *      Exception to the above rule:  Some drivers have a fixed mode, ie,
0193  *      the hardware is already set at boot up, and cannot be changed.  In
0194  *      this case, it is more acceptable that this function just return
0195  *      a copy of the currently working var (info->var). Better is to not
0196  *      implement this function, as the upper layer will do the copying
0197  *      of the current var for you.
0198  *
0199  *      Note:  This is the only function where the contents of var can be
0200  *      freely adjusted after the driver has been registered. If you find
0201  *      that you have code outside of this function that alters the content
0202  *      of var, then you are doing something wrong.  Note also that the
0203  *      contents of info->var must be left untouched at all times after
0204  *      driver registration.
0205  *
0206  *  Returns negative errno on error, or zero on success.
0207  */
0208 static int xxxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
0209 {
0210     /* ... */
0211     return 0;       
0212 }
0213 
0214 /**
0215  *      xxxfb_set_par - Optional function. Alters the hardware state.
0216  *      @info: frame buffer structure that represents a single frame buffer
0217  *
0218  *  Using the fb_var_screeninfo in fb_info we set the resolution of the
0219  *  this particular framebuffer. This function alters the par AND the
0220  *  fb_fix_screeninfo stored in fb_info. It doesn't not alter var in 
0221  *  fb_info since we are using that data. This means we depend on the
0222  *  data in var inside fb_info to be supported by the hardware. 
0223  *
0224  *      This function is also used to recover/restore the hardware to a
0225  *      known working state.
0226  *
0227  *  xxxfb_check_var is always called before xxxfb_set_par to ensure that
0228  *      the contents of var is always valid.
0229  *
0230  *  Again if you can't change the resolution you don't need this function.
0231  *
0232  *      However, even if your hardware does not support mode changing,
0233  *      a set_par might be needed to at least initialize the hardware to
0234  *      a known working state, especially if it came back from another
0235  *      process that also modifies the same hardware, such as X.
0236  *
0237  *      If this is the case, a combination such as the following should work:
0238  *
0239  *      static int xxxfb_check_var(struct fb_var_screeninfo *var,
0240  *                                struct fb_info *info)
0241  *      {
0242  *              *var = info->var;
0243  *              return 0;
0244  *      }
0245  *
0246  *      static int xxxfb_set_par(struct fb_info *info)
0247  *      {
0248  *              init your hardware here
0249  *      }
0250  *
0251  *  Returns negative errno on error, or zero on success.
0252  */
0253 static int xxxfb_set_par(struct fb_info *info)
0254 {
0255     struct xxx_par *par = info->par;
0256     /* ... */
0257     return 0;   
0258 }
0259 
0260 /**
0261  *      xxxfb_setcolreg - Optional function. Sets a color register.
0262  *      @regno: Which register in the CLUT we are programming 
0263  *      @red: The red value which can be up to 16 bits wide 
0264  *  @green: The green value which can be up to 16 bits wide 
0265  *  @blue:  The blue value which can be up to 16 bits wide.
0266  *  @transp: If supported, the alpha value which can be up to 16 bits wide.
0267  *      @info: frame buffer info structure
0268  * 
0269  *      Set a single color register. The values supplied have a 16 bit
0270  *      magnitude which needs to be scaled in this function for the hardware. 
0271  *  Things to take into consideration are how many color registers, if
0272  *  any, are supported with the current color visual. With truecolor mode
0273  *  no color palettes are supported. Here a pseudo palette is created
0274  *  which we store the value in pseudo_palette in struct fb_info. For
0275  *  pseudocolor mode we have a limited color palette. To deal with this
0276  *  we can program what color is displayed for a particular pixel value.
0277  *  DirectColor is similar in that we can program each color field. If
0278  *  we have a static colormap we don't need to implement this function. 
0279  * 
0280  *  Returns negative errno on error, or zero on success.
0281  */
0282 static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
0283                unsigned blue, unsigned transp,
0284                struct fb_info *info)
0285 {
0286     if (regno >= 256)  /* no. of hw registers */
0287        return -EINVAL;
0288     /*
0289      * Program hardware... do anything you want with transp
0290      */
0291 
0292     /* grayscale works only partially under directcolor */
0293     if (info->var.grayscale) {
0294        /* grayscale = 0.30*R + 0.59*G + 0.11*B */
0295        red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
0296     }
0297 
0298     /* Directcolor:
0299      *   var->{color}.offset contains start of bitfield
0300      *   var->{color}.length contains length of bitfield
0301      *   {hardwarespecific} contains width of DAC
0302      *   pseudo_palette[X] is programmed to (X << red.offset) |
0303      *                                      (X << green.offset) |
0304      *                                      (X << blue.offset)
0305      *   RAMDAC[X] is programmed to (red, green, blue)
0306      *   color depth = SUM(var->{color}.length)
0307      *
0308      * Pseudocolor:
0309      *    var->{color}.offset is 0 unless the palette index takes less than
0310      *                        bits_per_pixel bits and is stored in the upper
0311      *                        bits of the pixel value
0312      *    var->{color}.length is set so that 1 << length is the number of
0313      *                        available palette entries
0314      *    pseudo_palette is not used
0315      *    RAMDAC[X] is programmed to (red, green, blue)
0316      *    color depth = var->{color}.length
0317      *
0318      * Static pseudocolor:
0319      *    same as Pseudocolor, but the RAMDAC is not programmed (read-only)
0320      *
0321      * Mono01/Mono10:
0322      *    Has only 2 values, black on white or white on black (fg on bg),
0323      *    var->{color}.offset is 0
0324      *    white = (1 << var->{color}.length) - 1, black = 0
0325      *    pseudo_palette is not used
0326      *    RAMDAC does not exist
0327      *    color depth is always 2
0328      *
0329      * Truecolor:
0330      *    does not use RAMDAC (usually has 3 of them).
0331      *    var->{color}.offset contains start of bitfield
0332      *    var->{color}.length contains length of bitfield
0333      *    pseudo_palette is programmed to (red << red.offset) |
0334      *                                    (green << green.offset) |
0335      *                                    (blue << blue.offset) |
0336      *                                    (transp << transp.offset)
0337      *    RAMDAC does not exist
0338      *    color depth = SUM(var->{color}.length})
0339      *
0340      *  The color depth is used by fbcon for choosing the logo and also
0341      *  for color palette transformation if color depth < 4
0342      *
0343      *  As can be seen from the above, the field bits_per_pixel is _NOT_
0344      *  a criteria for describing the color visual.
0345      *
0346      *  A common mistake is assuming that bits_per_pixel <= 8 is pseudocolor,
0347      *  and higher than that, true/directcolor.  This is incorrect, one needs
0348      *  to look at the fix->visual.
0349      *
0350      *  Another common mistake is using bits_per_pixel to calculate the color
0351      *  depth.  The bits_per_pixel field does not directly translate to color
0352      *  depth. You have to compute for the color depth (using the color
0353      *  bitfields) and fix->visual as seen above.
0354      */
0355 
0356     /*
0357      * This is the point where the color is converted to something that
0358      * is acceptable by the hardware.
0359      */
0360 #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
0361     red = CNVT_TOHW(red, info->var.red.length);
0362     green = CNVT_TOHW(green, info->var.green.length);
0363     blue = CNVT_TOHW(blue, info->var.blue.length);
0364     transp = CNVT_TOHW(transp, info->var.transp.length);
0365 #undef CNVT_TOHW
0366     /*
0367      * This is the point where the function feeds the color to the hardware
0368      * palette after converting the colors to something acceptable by
0369      * the hardware. Note, only FB_VISUAL_DIRECTCOLOR and
0370      * FB_VISUAL_PSEUDOCOLOR visuals need to write to the hardware palette.
0371      * If you have code that writes to the hardware CLUT, and it's not
0372      * any of the above visuals, then you are doing something wrong.
0373      */
0374     if (info->fix.visual == FB_VISUAL_DIRECTCOLOR ||
0375     info->fix.visual == FB_VISUAL_TRUECOLOR)
0376         write_{red|green|blue|transp}_to_clut();
0377 
0378     /* This is the point were you need to fill up the contents of
0379      * info->pseudo_palette. This structure is used _only_ by fbcon, thus
0380      * it only contains 16 entries to match the number of colors supported
0381      * by the console. The pseudo_palette is used only if the visual is
0382      * in directcolor or truecolor mode.  With other visuals, the
0383      * pseudo_palette is not used. (This might change in the future.)
0384      *
0385      * The contents of the pseudo_palette is in raw pixel format.  Ie, each
0386      * entry can be written directly to the framebuffer without any conversion.
0387      * The pseudo_palette is (void *).  However, if using the generic
0388      * drawing functions (cfb_imageblit, cfb_fillrect), the pseudo_palette
0389      * must be casted to (u32 *) _regardless_ of the bits per pixel. If the
0390      * driver is using its own drawing functions, then it can use whatever
0391      * size it wants.
0392      */
0393     if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
0394     info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
0395         u32 v;
0396 
0397         if (regno >= 16)
0398             return -EINVAL;
0399 
0400         v = (red << info->var.red.offset) |
0401             (green << info->var.green.offset) |
0402             (blue << info->var.blue.offset) |
0403             (transp << info->var.transp.offset);
0404 
0405         ((u32*)(info->pseudo_palette))[regno] = v;
0406     }
0407 
0408     /* ... */
0409     return 0;
0410 }
0411 
0412 /**
0413  *      xxxfb_pan_display - NOT a required function. Pans the display.
0414  *      @var: frame buffer variable screen structure
0415  *      @info: frame buffer structure that represents a single frame buffer
0416  *
0417  *  Pan (or wrap, depending on the `vmode' field) the display using the
0418  *      `xoffset' and `yoffset' fields of the `var' structure.
0419  *      If the values don't fit, return -EINVAL.
0420  *
0421  *      Returns negative errno on error, or zero on success.
0422  */
0423 static int xxxfb_pan_display(struct fb_var_screeninfo *var,
0424                  struct fb_info *info)
0425 {
0426     /*
0427      * If your hardware does not support panning, _do_ _not_ implement this
0428      * function. Creating a dummy function will just confuse user apps.
0429      */
0430 
0431     /*
0432      * Note that even if this function is fully functional, a setting of
0433      * 0 in both xpanstep and ypanstep means that this function will never
0434      * get called.
0435      */
0436 
0437     /* ... */
0438     return 0;
0439 }
0440 
0441 /**
0442  *      xxxfb_blank - NOT a required function. Blanks the display.
0443  *      @blank_mode: the blank mode we want. 
0444  *      @info: frame buffer structure that represents a single frame buffer
0445  *
0446  *      Blank the screen if blank_mode != FB_BLANK_UNBLANK, else unblank.
0447  *      Return 0 if blanking succeeded, != 0 if un-/blanking failed due to
0448  *      e.g. a video mode which doesn't support it.
0449  *
0450  *      Implements VESA suspend and powerdown modes on hardware that supports
0451  *      disabling hsync/vsync:
0452  *
0453  *      FB_BLANK_NORMAL = display is blanked, syncs are on.
0454  *      FB_BLANK_HSYNC_SUSPEND = hsync off
0455  *      FB_BLANK_VSYNC_SUSPEND = vsync off
0456  *      FB_BLANK_POWERDOWN =  hsync and vsync off
0457  *
0458  *      If implementing this function, at least support FB_BLANK_UNBLANK.
0459  *      Return !0 for any modes that are unimplemented.
0460  *
0461  */
0462 static int xxxfb_blank(int blank_mode, struct fb_info *info)
0463 {
0464     /* ... */
0465     return 0;
0466 }
0467 
0468 /* ------------ Accelerated Functions --------------------- */
0469 
0470 /*
0471  * We provide our own functions if we have hardware acceleration
0472  * or non packed pixel format layouts. If we have no hardware 
0473  * acceleration, we can use a generic unaccelerated function. If using
0474  * a pack pixel format just use the functions in cfb_*.c. Each file 
0475  * has one of the three different accel functions we support.
0476  */
0477 
0478 /**
0479  *      xxxfb_fillrect - REQUIRED function. Can use generic routines if 
0480  *           non acclerated hardware and packed pixel based.
0481  *           Draws a rectangle on the screen.       
0482  *
0483  *      @info: frame buffer structure that represents a single frame buffer
0484  *  @region: The structure representing the rectangular region we 
0485  *       wish to draw to.
0486  *
0487  *  This drawing operation places/removes a retangle on the screen 
0488  *  depending on the rastering operation with the value of color which
0489  *  is in the current color depth format.
0490  */
0491 void xxxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region)
0492 {
0493 /*  Meaning of struct fb_fillrect
0494  *
0495  *  @dx: The x and y corrdinates of the upper left hand corner of the 
0496  *  @dy: area we want to draw to. 
0497  *  @width: How wide the rectangle is we want to draw.
0498  *  @height: How tall the rectangle is we want to draw.
0499  *  @color: The color to fill in the rectangle with. 
0500  *  @rop: The raster operation. We can draw the rectangle with a COPY
0501  *        of XOR which provides erasing effect. 
0502  */
0503 }
0504 
0505 /**
0506  *      xxxfb_copyarea - REQUIRED function. Can use generic routines if
0507  *                       non acclerated hardware and packed pixel based.
0508  *                       Copies one area of the screen to another area.
0509  *
0510  *      @info: frame buffer structure that represents a single frame buffer
0511  *      @area: Structure providing the data to copy the framebuffer contents
0512  *         from one region to another.
0513  *
0514  *      This drawing operation copies a rectangular area from one area of the
0515  *  screen to another area.
0516  */
0517 void xxxfb_copyarea(struct fb_info *p, const struct fb_copyarea *area) 
0518 {
0519 /*
0520  *      @dx: The x and y coordinates of the upper left hand corner of the
0521  *  @dy: destination area on the screen.
0522  *      @width: How wide the rectangle is we want to copy.
0523  *      @height: How tall the rectangle is we want to copy.
0524  *      @sx: The x and y coordinates of the upper left hand corner of the
0525  *      @sy: source area on the screen.
0526  */
0527 }
0528 
0529 
0530 /**
0531  *      xxxfb_imageblit - REQUIRED function. Can use generic routines if
0532  *                        non acclerated hardware and packed pixel based.
0533  *                        Copies a image from system memory to the screen. 
0534  *
0535  *      @info: frame buffer structure that represents a single frame buffer
0536  *  @image: structure defining the image.
0537  *
0538  *      This drawing operation draws a image on the screen. It can be a 
0539  *  mono image (needed for font handling) or a color image (needed for
0540  *  tux). 
0541  */
0542 void xxxfb_imageblit(struct fb_info *p, const struct fb_image *image) 
0543 {
0544 /*
0545  *      @dx: The x and y coordinates of the upper left hand corner of the
0546  *  @dy: destination area to place the image on the screen.
0547  *      @width: How wide the image is we want to copy.
0548  *      @height: How tall the image is we want to copy.
0549  *      @fg_color: For mono bitmap images this is color data for     
0550  *      @bg_color: the foreground and background of the image to
0551  *         write directly to the frmaebuffer.
0552  *  @depth: How many bits represent a single pixel for this image.
0553  *  @data: The actual data used to construct the image on the display.
0554  *  @cmap: The colormap used for color images.   
0555  */
0556 
0557 /*
0558  * The generic function, cfb_imageblit, expects that the bitmap scanlines are
0559  * padded to the next byte.  Most hardware accelerators may require padding to
0560  * the next u16 or the next u32.  If that is the case, the driver can specify
0561  * this by setting info->pixmap.scan_align = 2 or 4.  See a more
0562  * comprehensive description of the pixmap below.
0563  */
0564 }
0565 
0566 /**
0567  *  xxxfb_cursor -  OPTIONAL. If your hardware lacks support
0568  *          for a cursor, leave this field NULL.
0569  *
0570  *      @info: frame buffer structure that represents a single frame buffer
0571  *  @cursor: structure defining the cursor to draw.
0572  *
0573  *      This operation is used to set or alter the properities of the
0574  *  cursor.
0575  *
0576  *  Returns negative errno on error, or zero on success.
0577  */
0578 int xxxfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
0579 {
0580 /*
0581  *      @set:   Which fields we are altering in struct fb_cursor 
0582  *  @enable: Disable or enable the cursor 
0583  *      @rop:   The bit operation we want to do. 
0584  *      @mask:  This is the cursor mask bitmap. 
0585  *      @dest:  A image of the area we are going to display the cursor.
0586  *      Used internally by the driver.   
0587  *      @hot:   The hot spot. 
0588  *  @image: The actual data for the cursor image.
0589  *
0590  *      NOTES ON FLAGS (cursor->set):
0591  *
0592  *      FB_CUR_SETIMAGE - the cursor image has changed (cursor->image.data)
0593  *      FB_CUR_SETPOS   - the cursor position has changed (cursor->image.dx|dy)
0594  *      FB_CUR_SETHOT   - the cursor hot spot has changed (cursor->hot.dx|dy)
0595  *      FB_CUR_SETCMAP  - the cursor colors has changed (cursor->fg_color|bg_color)
0596  *      FB_CUR_SETSHAPE - the cursor bitmask has changed (cursor->mask)
0597  *      FB_CUR_SETSIZE  - the cursor size has changed (cursor->width|height)
0598  *      FB_CUR_SETALL   - everything has changed
0599  *
0600  *      NOTES ON ROPs (cursor->rop, Raster Operation)
0601  *
0602  *      ROP_XOR         - cursor->image.data XOR cursor->mask
0603  *      ROP_COPY        - curosr->image.data AND cursor->mask
0604  *
0605  *      OTHER NOTES:
0606  *
0607  *      - fbcon only supports a 2-color cursor (cursor->image.depth = 1)
0608  *      - The fb_cursor structure, @cursor, _will_ always contain valid
0609  *        fields, whether any particular bitfields in cursor->set is set
0610  *        or not.
0611  */
0612 }
0613 
0614 /**
0615  *  xxxfb_sync - NOT a required function. Normally the accel engine 
0616  *           for a graphics card take a specific amount of time.
0617  *           Often we have to wait for the accelerator to finish
0618  *           its operation before we can write to the framebuffer
0619  *           so we can have consistent display output. 
0620  *
0621  *      @info: frame buffer structure that represents a single frame buffer
0622  *
0623  *      If the driver has implemented its own hardware-based drawing function,
0624  *      implementing this function is highly recommended.
0625  */
0626 int xxxfb_sync(struct fb_info *info)
0627 {
0628     return 0;
0629 }
0630 
0631     /*
0632      *  Frame buffer operations
0633      */
0634 
0635 static const struct fb_ops xxxfb_ops = {
0636     .owner      = THIS_MODULE,
0637     .fb_open    = xxxfb_open,
0638     .fb_read    = xxxfb_read,
0639     .fb_write   = xxxfb_write,
0640     .fb_release = xxxfb_release,
0641     .fb_check_var   = xxxfb_check_var,
0642     .fb_set_par = xxxfb_set_par,
0643     .fb_setcolreg   = xxxfb_setcolreg,
0644     .fb_blank   = xxxfb_blank,
0645     .fb_pan_display = xxxfb_pan_display,
0646     .fb_fillrect    = xxxfb_fillrect,   /* Needed !!! */
0647     .fb_copyarea    = xxxfb_copyarea,   /* Needed !!! */
0648     .fb_imageblit   = xxxfb_imageblit,  /* Needed !!! */
0649     .fb_cursor  = xxxfb_cursor,     /* Optional !!! */
0650     .fb_sync    = xxxfb_sync,
0651     .fb_ioctl   = xxxfb_ioctl,
0652     .fb_mmap    = xxxfb_mmap,
0653 };
0654 
0655 /* ------------------------------------------------------------------------- */
0656 
0657     /*
0658      *  Initialization
0659      */
0660 
0661 /* static int __init xxfb_probe (struct platform_device *pdev) -- for platform devs */
0662 static int xxxfb_probe(struct pci_dev *dev, const struct pci_device_id *ent)
0663 {
0664     struct fb_info *info;
0665     struct xxx_par *par;
0666     struct device *device = &dev->dev; /* or &pdev->dev */
0667     int cmap_len, retval;   
0668    
0669     /*
0670      * Dynamically allocate info and par
0671      */
0672     info = framebuffer_alloc(sizeof(struct xxx_par), device);
0673 
0674     if (!info) {
0675         /* goto error path */
0676     }
0677 
0678     par = info->par;
0679 
0680     /* 
0681      * Here we set the screen_base to the virtual memory address
0682      * for the framebuffer. Usually we obtain the resource address
0683      * from the bus layer and then translate it to virtual memory
0684      * space via ioremap. Consult ioport.h. 
0685      */
0686     info->screen_base = framebuffer_virtual_memory;
0687     info->fbops = &xxxfb_ops;
0688     info->fix = xxxfb_fix;
0689     info->pseudo_palette = pseudo_palette; /* The pseudopalette is an
0690                         * 16-member array
0691                         */
0692     /*
0693      * Set up flags to indicate what sort of acceleration your
0694      * driver can provide (pan/wrap/copyarea/etc.) and whether it
0695      * is a module -- see FBINFO_* in include/linux/fb.h
0696      *
0697      * If your hardware can support any of the hardware accelerated functions
0698      * fbcon performance will improve if info->flags is set properly.
0699      *
0700      * FBINFO_HWACCEL_COPYAREA - hardware moves
0701      * FBINFO_HWACCEL_FILLRECT - hardware fills
0702      * FBINFO_HWACCEL_IMAGEBLIT - hardware mono->color expansion
0703      * FBINFO_HWACCEL_YPAN - hardware can pan display in y-axis
0704      * FBINFO_HWACCEL_YWRAP - hardware can wrap display in y-axis
0705      * FBINFO_HWACCEL_DISABLED - supports hardware accels, but disabled
0706      * FBINFO_READS_FAST - if set, prefer moves over mono->color expansion
0707      * FBINFO_MISC_TILEBLITTING - hardware can do tile blits
0708      *
0709      * NOTE: These are for fbcon use only.
0710      */
0711     info->flags = FBINFO_DEFAULT;
0712 
0713 /********************* This stage is optional ******************************/
0714      /*
0715      * The struct pixmap is a scratch pad for the drawing functions. This
0716      * is where the monochrome bitmap is constructed by the higher layers
0717      * and then passed to the accelerator.  For drivers that uses
0718      * cfb_imageblit, you can skip this part.  For those that have a more
0719      * rigorous requirement, this stage is needed
0720      */
0721 
0722     /* PIXMAP_SIZE should be small enough to optimize drawing, but not
0723      * large enough that memory is wasted.  A safe size is
0724      * (max_xres * max_font_height/8). max_xres is driver dependent,
0725      * max_font_height is 32.
0726      */
0727     info->pixmap.addr = kmalloc(PIXMAP_SIZE, GFP_KERNEL);
0728     if (!info->pixmap.addr) {
0729         /* goto error */
0730     }
0731 
0732     info->pixmap.size = PIXMAP_SIZE;
0733 
0734     /*
0735      * FB_PIXMAP_SYSTEM - memory is in system ram
0736      * FB_PIXMAP_IO     - memory is iomapped
0737      * FB_PIXMAP_SYNC   - if set, will call fb_sync() per access to pixmap,
0738      *                    usually if FB_PIXMAP_IO is set.
0739      *
0740      * Currently, FB_PIXMAP_IO is unimplemented.
0741      */
0742     info->pixmap.flags = FB_PIXMAP_SYSTEM;
0743 
0744     /*
0745      * scan_align is the number of padding for each scanline.  It is in bytes.
0746      * Thus for accelerators that need padding to the next u32, put 4 here.
0747      */
0748     info->pixmap.scan_align = 4;
0749 
0750     /*
0751      * buf_align is the amount to be padded for the buffer. For example,
0752      * the i810fb needs a scan_align of 2 but expects it to be fed with
0753      * dwords, so a buf_align = 4 is required.
0754      */
0755     info->pixmap.buf_align = 4;
0756 
0757     /* access_align is how many bits can be accessed from the framebuffer
0758      * ie. some epson cards allow 16-bit access only.  Most drivers will
0759      * be safe with u32 here.
0760      *
0761      * NOTE: This field is currently unused.
0762      */
0763     info->pixmap.access_align = 32;
0764 /***************************** End optional stage ***************************/
0765 
0766     /*
0767      * This should give a reasonable default video mode. The following is
0768      * done when we can set a video mode. 
0769      */
0770     if (!mode_option)
0771     mode_option = "640x480@60";     
0772 
0773     retval = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
0774   
0775     if (!retval || retval == 4)
0776     return -EINVAL;         
0777 
0778     /* This has to be done! */
0779     if (fb_alloc_cmap(&info->cmap, cmap_len, 0))
0780     return -ENOMEM;
0781     
0782     /* 
0783      * The following is done in the case of having hardware with a static 
0784      * mode. If we are setting the mode ourselves we don't call this. 
0785      */ 
0786     info->var = xxxfb_var;
0787 
0788     /*
0789      * For drivers that can...
0790      */
0791     xxxfb_check_var(&info->var, info);
0792 
0793     /*
0794      * Does a call to fb_set_par() before register_framebuffer needed?  This
0795      * will depend on you and the hardware.  If you are sure that your driver
0796      * is the only device in the system, a call to fb_set_par() is safe.
0797      *
0798      * Hardware in x86 systems has a VGA core.  Calling set_par() at this
0799      * point will corrupt the VGA console, so it might be safer to skip a
0800      * call to set_par here and just allow fbcon to do it for you.
0801      */
0802     /* xxxfb_set_par(info); */
0803 
0804     if (register_framebuffer(info) < 0) {
0805     fb_dealloc_cmap(&info->cmap);
0806     return -EINVAL;
0807     }
0808     fb_info(info, "%s frame buffer device\n", info->fix.id);
0809     pci_set_drvdata(dev, info); /* or platform_set_drvdata(pdev, info) */
0810     return 0;
0811 }
0812 
0813     /*
0814      *  Cleanup
0815      */
0816 /* static void xxxfb_remove(struct platform_device *pdev) */
0817 static void xxxfb_remove(struct pci_dev *dev)
0818 {
0819     struct fb_info *info = pci_get_drvdata(dev);
0820     /* or platform_get_drvdata(pdev); */
0821 
0822     if (info) {
0823         unregister_framebuffer(info);
0824         fb_dealloc_cmap(&info->cmap);
0825         /* ... */
0826         framebuffer_release(info);
0827     }
0828 }
0829 
0830 #ifdef CONFIG_PCI
0831 #ifdef CONFIG_PM
0832 /**
0833  *  xxxfb_suspend - Optional but recommended function. Suspend the device.
0834  *  @dev: PCI device
0835  *  @msg: the suspend event code.
0836  *
0837  *      See Documentation/driver-api/pm/devices.rst for more information
0838  */
0839 static int xxxfb_suspend(struct device *dev)
0840 {
0841     struct fb_info *info = dev_get_drvdata(dev);
0842     struct xxxfb_par *par = info->par;
0843 
0844     /* suspend here */
0845     return 0;
0846 }
0847 
0848 /**
0849  *  xxxfb_resume - Optional but recommended function. Resume the device.
0850  *  @dev: PCI device
0851  *
0852  *      See Documentation/driver-api/pm/devices.rst for more information
0853  */
0854 static int xxxfb_resume(struct device *dev)
0855 {
0856     struct fb_info *info = dev_get_drvdata(dev);
0857     struct xxxfb_par *par = info->par;
0858 
0859     /* resume here */
0860     return 0;
0861 }
0862 #else
0863 #define xxxfb_suspend NULL
0864 #define xxxfb_resume NULL
0865 #endif /* CONFIG_PM */
0866 
0867 static const struct pci_device_id xxxfb_id_table[] = {
0868     { PCI_VENDOR_ID_XXX, PCI_DEVICE_ID_XXX,
0869       PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
0870       PCI_CLASS_MASK, 0 },
0871     { 0, }
0872 };
0873 
0874 static SIMPLE_DEV_PM_OPS(xxxfb_pm_ops, xxxfb_suspend, xxxfb_resume);
0875 
0876 /* For PCI drivers */
0877 static struct pci_driver xxxfb_driver = {
0878     .name =     "xxxfb",
0879     .id_table = xxxfb_id_table,
0880     .probe =    xxxfb_probe,
0881     .remove =   xxxfb_remove,
0882     .driver.pm =    xxxfb_pm_ops, /* optional but recommended */
0883 };
0884 
0885 MODULE_DEVICE_TABLE(pci, xxxfb_id_table);
0886 
0887 static int __init xxxfb_init(void)
0888 {
0889     /*
0890      *  For kernel boot options (in 'video=xxxfb:<options>' format)
0891      */
0892 #ifndef MODULE
0893     char *option = NULL;
0894 
0895     if (fb_get_options("xxxfb", &option))
0896         return -ENODEV;
0897     xxxfb_setup(option);
0898 #endif
0899 
0900     return pci_register_driver(&xxxfb_driver);
0901 }
0902 
0903 static void __exit xxxfb_exit(void)
0904 {
0905     pci_unregister_driver(&xxxfb_driver);
0906 }
0907 #else /* non PCI, platform drivers */
0908 #include <linux/platform_device.h>
0909 /* for platform devices */
0910 
0911 #ifdef CONFIG_PM
0912 /**
0913  *  xxxfb_suspend - Optional but recommended function. Suspend the device.
0914  *  @dev: platform device
0915  *  @msg: the suspend event code.
0916  *
0917  *      See Documentation/driver-api/pm/devices.rst for more information
0918  */
0919 static int xxxfb_suspend(struct platform_device *dev, pm_message_t msg)
0920 {
0921     struct fb_info *info = platform_get_drvdata(dev);
0922     struct xxxfb_par *par = info->par;
0923 
0924     /* suspend here */
0925     return 0;
0926 }
0927 
0928 /**
0929  *  xxxfb_resume - Optional but recommended function. Resume the device.
0930  *  @dev: platform device
0931  *
0932  *      See Documentation/driver-api/pm/devices.rst for more information
0933  */
0934 static int xxxfb_resume(struct platform_dev *dev)
0935 {
0936     struct fb_info *info = platform_get_drvdata(dev);
0937     struct xxxfb_par *par = info->par;
0938 
0939     /* resume here */
0940     return 0;
0941 }
0942 #else
0943 #define xxxfb_suspend NULL
0944 #define xxxfb_resume NULL
0945 #endif /* CONFIG_PM */
0946 
0947 static struct platform_device_driver xxxfb_driver = {
0948     .probe = xxxfb_probe,
0949     .remove = xxxfb_remove,
0950     .suspend = xxxfb_suspend, /* optional but recommended */
0951     .resume = xxxfb_resume,   /* optional but recommended */
0952     .driver = {
0953         .name = "xxxfb",
0954     },
0955 };
0956 
0957 static struct platform_device *xxxfb_device;
0958 
0959 #ifndef MODULE
0960     /*
0961      *  Setup
0962      */
0963 
0964 /*
0965  * Only necessary if your driver takes special options,
0966  * otherwise we fall back on the generic fb_setup().
0967  */
0968 static int __init xxxfb_setup(char *options)
0969 {
0970     /* Parse user specified options (`video=xxxfb:') */
0971 }
0972 #endif /* MODULE */
0973 
0974 static int __init xxxfb_init(void)
0975 {
0976     int ret;
0977     /*
0978      *  For kernel boot options (in 'video=xxxfb:<options>' format)
0979      */
0980 #ifndef MODULE
0981     char *option = NULL;
0982 
0983     if (fb_get_options("xxxfb", &option))
0984         return -ENODEV;
0985     xxxfb_setup(option);
0986 #endif
0987     ret = platform_driver_register(&xxxfb_driver);
0988 
0989     if (!ret) {
0990         xxxfb_device = platform_device_register_simple("xxxfb", 0,
0991                                 NULL, 0);
0992 
0993         if (IS_ERR(xxxfb_device)) {
0994             platform_driver_unregister(&xxxfb_driver);
0995             ret = PTR_ERR(xxxfb_device);
0996         }
0997     }
0998 
0999     return ret;
1000 }
1001 
1002 static void __exit xxxfb_exit(void)
1003 {
1004     platform_device_unregister(xxxfb_device);
1005     platform_driver_unregister(&xxxfb_driver);
1006 }
1007 #endif /* CONFIG_PCI */
1008 
1009 /* ------------------------------------------------------------------------- */
1010 
1011 
1012     /*
1013      *  Modularization
1014      */
1015 
1016 module_init(xxxfb_init);
1017 module_exit(xxxfb_exit);
1018 
1019 MODULE_LICENSE("GPL");