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