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