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