162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci *  Modified to new api Jan 2001 by James Simmons (jsimmons@transvirtual.com)
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci *  Created 28 Dec 1997 by Geert Uytterhoeven
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci *  I have started rewriting this driver as a example of the upcoming new API
1062306a36Sopenharmony_ci *  The primary goal is to remove the console code from fbdev and place it
1162306a36Sopenharmony_ci *  into fbcon.c. This reduces the code and makes writing a new fbdev driver
1262306a36Sopenharmony_ci *  easy since the author doesn't need to worry about console internals. It
1362306a36Sopenharmony_ci *  also allows the ability to run fbdev without a console/tty system on top
1462306a36Sopenharmony_ci *  of it.
1562306a36Sopenharmony_ci *
1662306a36Sopenharmony_ci *  First the roles of struct fb_info and struct display have changed. Struct
1762306a36Sopenharmony_ci *  display will go away. The way the new framebuffer console code will
1862306a36Sopenharmony_ci *  work is that it will act to translate data about the tty/console in
1962306a36Sopenharmony_ci *  struct vc_data to data in a device independent way in struct fb_info. Then
2062306a36Sopenharmony_ci *  various functions in struct fb_ops will be called to store the device
2162306a36Sopenharmony_ci *  dependent state in the par field in struct fb_info and to change the
2262306a36Sopenharmony_ci *  hardware to that state. This allows a very clean separation of the fbdev
2362306a36Sopenharmony_ci *  layer from the console layer. It also allows one to use fbdev on its own
2462306a36Sopenharmony_ci *  which is a bounus for embedded devices. The reason this approach works is
2562306a36Sopenharmony_ci *  for each framebuffer device when used as a tty/console device is allocated
2662306a36Sopenharmony_ci *  a set of virtual terminals to it. Only one virtual terminal can be active
2762306a36Sopenharmony_ci *  per framebuffer device. We already have all the data we need in struct
2862306a36Sopenharmony_ci *  vc_data so why store a bunch of colormaps and other fbdev specific data
2962306a36Sopenharmony_ci *  per virtual terminal.
3062306a36Sopenharmony_ci *
3162306a36Sopenharmony_ci *  As you can see doing this makes the con parameter pretty much useless
3262306a36Sopenharmony_ci *  for struct fb_ops functions, as it should be. Also having struct
3362306a36Sopenharmony_ci *  fb_var_screeninfo and other data in fb_info pretty much eliminates the
3462306a36Sopenharmony_ci *  need for get_fix and get_var. Once all drivers use the fix, var, and cmap
3562306a36Sopenharmony_ci *  fbcon can be written around these fields. This will also eliminate the
3662306a36Sopenharmony_ci *  need to regenerate struct fb_var_screeninfo, struct fb_fix_screeninfo
3762306a36Sopenharmony_ci *  struct fb_cmap every time get_var, get_fix, get_cmap functions are called
3862306a36Sopenharmony_ci *  as many drivers do now.
3962306a36Sopenharmony_ci *
4062306a36Sopenharmony_ci *  This file is subject to the terms and conditions of the GNU General Public
4162306a36Sopenharmony_ci *  License. See the file COPYING in the main directory of this archive for
4262306a36Sopenharmony_ci *  more details.
4362306a36Sopenharmony_ci */
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci#include <linux/aperture.h>
4662306a36Sopenharmony_ci#include <linux/module.h>
4762306a36Sopenharmony_ci#include <linux/kernel.h>
4862306a36Sopenharmony_ci#include <linux/errno.h>
4962306a36Sopenharmony_ci#include <linux/string.h>
5062306a36Sopenharmony_ci#include <linux/mm.h>
5162306a36Sopenharmony_ci#include <linux/slab.h>
5262306a36Sopenharmony_ci#include <linux/delay.h>
5362306a36Sopenharmony_ci#include <linux/fb.h>
5462306a36Sopenharmony_ci#include <linux/init.h>
5562306a36Sopenharmony_ci#include <linux/pci.h>
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci    /*
5862306a36Sopenharmony_ci     *  This is just simple sample code.
5962306a36Sopenharmony_ci     *
6062306a36Sopenharmony_ci     *  No warranty that it actually compiles.
6162306a36Sopenharmony_ci     *  Even less warranty that it actually works :-)
6262306a36Sopenharmony_ci     */
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci/*
6562306a36Sopenharmony_ci * Driver data
6662306a36Sopenharmony_ci */
6762306a36Sopenharmony_cistatic char *mode_option;
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci/*
7062306a36Sopenharmony_ci *  If your driver supports multiple boards, you should make the
7162306a36Sopenharmony_ci *  below data types arrays, or allocate them dynamically (using kmalloc()).
7262306a36Sopenharmony_ci */
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci/*
7562306a36Sopenharmony_ci * This structure defines the hardware state of the graphics card. Normally
7662306a36Sopenharmony_ci * you place this in a header file in linux/include/video. This file usually
7762306a36Sopenharmony_ci * also includes register information. That allows other driver subsystems
7862306a36Sopenharmony_ci * and userland applications the ability to use the same header file to
7962306a36Sopenharmony_ci * avoid duplicate work and easy porting of software.
8062306a36Sopenharmony_ci */
8162306a36Sopenharmony_cistruct xxx_par;
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci/*
8462306a36Sopenharmony_ci * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
8562306a36Sopenharmony_ci * if we don't use modedb. If we do use modedb see xxxfb_init how to use it
8662306a36Sopenharmony_ci * to get a fb_var_screeninfo. Otherwise define a default var as well.
8762306a36Sopenharmony_ci */
8862306a36Sopenharmony_cistatic const struct fb_fix_screeninfo xxxfb_fix = {
8962306a36Sopenharmony_ci	.id =		"FB's name",
9062306a36Sopenharmony_ci	.type =		FB_TYPE_PACKED_PIXELS,
9162306a36Sopenharmony_ci	.visual =	FB_VISUAL_PSEUDOCOLOR,
9262306a36Sopenharmony_ci	.xpanstep =	1,
9362306a36Sopenharmony_ci	.ypanstep =	1,
9462306a36Sopenharmony_ci	.ywrapstep =	1,
9562306a36Sopenharmony_ci	.accel =	FB_ACCEL_NONE,
9662306a36Sopenharmony_ci};
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci    /*
9962306a36Sopenharmony_ci     * 	Modern graphical hardware not only supports pipelines but some
10062306a36Sopenharmony_ci     *  also support multiple monitors where each display can have
10162306a36Sopenharmony_ci     *  its own unique data. In this case each display could be
10262306a36Sopenharmony_ci     *  represented by a separate framebuffer device thus a separate
10362306a36Sopenharmony_ci     *  struct fb_info. Now the struct xxx_par represents the graphics
10462306a36Sopenharmony_ci     *  hardware state thus only one exist per card. In this case the
10562306a36Sopenharmony_ci     *  struct xxx_par for each graphics card would be shared between
10662306a36Sopenharmony_ci     *  every struct fb_info that represents a framebuffer on that card.
10762306a36Sopenharmony_ci     *  This allows when one display changes it video resolution (info->var)
10862306a36Sopenharmony_ci     *  the other displays know instantly. Each display can always be
10962306a36Sopenharmony_ci     *  aware of the entire hardware state that affects it because they share
11062306a36Sopenharmony_ci     *  the same xxx_par struct. The other side of the coin is multiple
11162306a36Sopenharmony_ci     *  graphics cards that pass data around until it is finally displayed
11262306a36Sopenharmony_ci     *  on one monitor. Such examples are the voodoo 1 cards and high end
11362306a36Sopenharmony_ci     *  NUMA graphics servers. For this case we have a bunch of pars, each
11462306a36Sopenharmony_ci     *  one that represents a graphics state, that belong to one struct
11562306a36Sopenharmony_ci     *  fb_info. Their you would want to have *par point to a array of device
11662306a36Sopenharmony_ci     *  states and have each struct fb_ops function deal with all those
11762306a36Sopenharmony_ci     *  states. I hope this covers every possible hardware design. If not
11862306a36Sopenharmony_ci     *  feel free to send your ideas at jsimmons@users.sf.net
11962306a36Sopenharmony_ci     */
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci    /*
12262306a36Sopenharmony_ci     *  If your driver supports multiple boards or it supports multiple
12362306a36Sopenharmony_ci     *  framebuffers, you should make these arrays, or allocate them
12462306a36Sopenharmony_ci     *  dynamically using framebuffer_alloc() and free them with
12562306a36Sopenharmony_ci     *  framebuffer_release().
12662306a36Sopenharmony_ci     */
12762306a36Sopenharmony_cistatic struct fb_info info;
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci    /*
13062306a36Sopenharmony_ci     * Each one represents the state of the hardware. Most hardware have
13162306a36Sopenharmony_ci     * just one hardware state. These here represent the default state(s).
13262306a36Sopenharmony_ci     */
13362306a36Sopenharmony_cistatic struct xxx_par __initdata current_par;
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci/**
13662306a36Sopenharmony_ci *	xxxfb_open - Optional function. Called when the framebuffer is
13762306a36Sopenharmony_ci *		     first accessed.
13862306a36Sopenharmony_ci *	@info: frame buffer structure that represents a single frame buffer
13962306a36Sopenharmony_ci *	@user: tell us if the userland (value=1) or the console is accessing
14062306a36Sopenharmony_ci *	       the framebuffer.
14162306a36Sopenharmony_ci *
14262306a36Sopenharmony_ci *	This function is the first function called in the framebuffer api.
14362306a36Sopenharmony_ci *	Usually you don't need to provide this function. The case where it
14462306a36Sopenharmony_ci *	is used is to change from a text mode hardware state to a graphics
14562306a36Sopenharmony_ci * 	mode state.
14662306a36Sopenharmony_ci *
14762306a36Sopenharmony_ci *	Returns negative errno on error, or zero on success.
14862306a36Sopenharmony_ci */
14962306a36Sopenharmony_cistatic int xxxfb_open(struct fb_info *info, int user)
15062306a36Sopenharmony_ci{
15162306a36Sopenharmony_ci    return 0;
15262306a36Sopenharmony_ci}
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci/**
15562306a36Sopenharmony_ci *	xxxfb_release - Optional function. Called when the framebuffer
15662306a36Sopenharmony_ci *			device is closed.
15762306a36Sopenharmony_ci *	@info: frame buffer structure that represents a single frame buffer
15862306a36Sopenharmony_ci *	@user: tell us if the userland (value=1) or the console is accessing
15962306a36Sopenharmony_ci *	       the framebuffer.
16062306a36Sopenharmony_ci *
16162306a36Sopenharmony_ci *	Thus function is called when we close /dev/fb or the framebuffer
16262306a36Sopenharmony_ci *	console system is released. Usually you don't need this function.
16362306a36Sopenharmony_ci *	The case where it is usually used is to go from a graphics state
16462306a36Sopenharmony_ci *	to a text mode state.
16562306a36Sopenharmony_ci *
16662306a36Sopenharmony_ci *	Returns negative errno on error, or zero on success.
16762306a36Sopenharmony_ci */
16862306a36Sopenharmony_cistatic int xxxfb_release(struct fb_info *info, int user)
16962306a36Sopenharmony_ci{
17062306a36Sopenharmony_ci    return 0;
17162306a36Sopenharmony_ci}
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci/**
17462306a36Sopenharmony_ci *      xxxfb_check_var - Optional function. Validates a var passed in.
17562306a36Sopenharmony_ci *      @var: frame buffer variable screen structure
17662306a36Sopenharmony_ci *      @info: frame buffer structure that represents a single frame buffer
17762306a36Sopenharmony_ci *
17862306a36Sopenharmony_ci *	Checks to see if the hardware supports the state requested by
17962306a36Sopenharmony_ci *	var passed in. This function does not alter the hardware state!!!
18062306a36Sopenharmony_ci *	This means the data stored in struct fb_info and struct xxx_par do
18162306a36Sopenharmony_ci *      not change. This includes the var inside of struct fb_info.
18262306a36Sopenharmony_ci *	Do NOT change these. This function can be called on its own if we
18362306a36Sopenharmony_ci *	intent to only test a mode and not actually set it. The stuff in
18462306a36Sopenharmony_ci *	modedb.c is a example of this. If the var passed in is slightly
18562306a36Sopenharmony_ci *	off by what the hardware can support then we alter the var PASSED in
18662306a36Sopenharmony_ci *	to what we can do.
18762306a36Sopenharmony_ci *
18862306a36Sopenharmony_ci *      For values that are off, this function must round them _up_ to the
18962306a36Sopenharmony_ci *      next value that is supported by the hardware.  If the value is
19062306a36Sopenharmony_ci *      greater than the highest value supported by the hardware, then this
19162306a36Sopenharmony_ci *      function must return -EINVAL.
19262306a36Sopenharmony_ci *
19362306a36Sopenharmony_ci *      Exception to the above rule:  Some drivers have a fixed mode, ie,
19462306a36Sopenharmony_ci *      the hardware is already set at boot up, and cannot be changed.  In
19562306a36Sopenharmony_ci *      this case, it is more acceptable that this function just return
19662306a36Sopenharmony_ci *      a copy of the currently working var (info->var). Better is to not
19762306a36Sopenharmony_ci *      implement this function, as the upper layer will do the copying
19862306a36Sopenharmony_ci *      of the current var for you.
19962306a36Sopenharmony_ci *
20062306a36Sopenharmony_ci *      Note:  This is the only function where the contents of var can be
20162306a36Sopenharmony_ci *      freely adjusted after the driver has been registered. If you find
20262306a36Sopenharmony_ci *      that you have code outside of this function that alters the content
20362306a36Sopenharmony_ci *      of var, then you are doing something wrong.  Note also that the
20462306a36Sopenharmony_ci *      contents of info->var must be left untouched at all times after
20562306a36Sopenharmony_ci *      driver registration.
20662306a36Sopenharmony_ci *
20762306a36Sopenharmony_ci *	Returns negative errno on error, or zero on success.
20862306a36Sopenharmony_ci */
20962306a36Sopenharmony_cistatic int xxxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
21062306a36Sopenharmony_ci{
21162306a36Sopenharmony_ci    /* ... */
21262306a36Sopenharmony_ci    return 0;
21362306a36Sopenharmony_ci}
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_ci/**
21662306a36Sopenharmony_ci *      xxxfb_set_par - Optional function. Alters the hardware state.
21762306a36Sopenharmony_ci *      @info: frame buffer structure that represents a single frame buffer
21862306a36Sopenharmony_ci *
21962306a36Sopenharmony_ci *	Using the fb_var_screeninfo in fb_info we set the resolution of the
22062306a36Sopenharmony_ci *	this particular framebuffer. This function alters the par AND the
22162306a36Sopenharmony_ci *	fb_fix_screeninfo stored in fb_info. It doesn't not alter var in
22262306a36Sopenharmony_ci *	fb_info since we are using that data. This means we depend on the
22362306a36Sopenharmony_ci *	data in var inside fb_info to be supported by the hardware.
22462306a36Sopenharmony_ci *
22562306a36Sopenharmony_ci *      This function is also used to recover/restore the hardware to a
22662306a36Sopenharmony_ci *      known working state.
22762306a36Sopenharmony_ci *
22862306a36Sopenharmony_ci *	xxxfb_check_var is always called before xxxfb_set_par to ensure that
22962306a36Sopenharmony_ci *      the contents of var is always valid.
23062306a36Sopenharmony_ci *
23162306a36Sopenharmony_ci *	Again if you can't change the resolution you don't need this function.
23262306a36Sopenharmony_ci *
23362306a36Sopenharmony_ci *      However, even if your hardware does not support mode changing,
23462306a36Sopenharmony_ci *      a set_par might be needed to at least initialize the hardware to
23562306a36Sopenharmony_ci *      a known working state, especially if it came back from another
23662306a36Sopenharmony_ci *      process that also modifies the same hardware, such as X.
23762306a36Sopenharmony_ci *
23862306a36Sopenharmony_ci *      If this is the case, a combination such as the following should work:
23962306a36Sopenharmony_ci *
24062306a36Sopenharmony_ci *      static int xxxfb_check_var(struct fb_var_screeninfo *var,
24162306a36Sopenharmony_ci *                                struct fb_info *info)
24262306a36Sopenharmony_ci *      {
24362306a36Sopenharmony_ci *              *var = info->var;
24462306a36Sopenharmony_ci *              return 0;
24562306a36Sopenharmony_ci *      }
24662306a36Sopenharmony_ci *
24762306a36Sopenharmony_ci *      static int xxxfb_set_par(struct fb_info *info)
24862306a36Sopenharmony_ci *      {
24962306a36Sopenharmony_ci *              init your hardware here
25062306a36Sopenharmony_ci *      }
25162306a36Sopenharmony_ci *
25262306a36Sopenharmony_ci *	Returns negative errno on error, or zero on success.
25362306a36Sopenharmony_ci */
25462306a36Sopenharmony_cistatic int xxxfb_set_par(struct fb_info *info)
25562306a36Sopenharmony_ci{
25662306a36Sopenharmony_ci    struct xxx_par *par = info->par;
25762306a36Sopenharmony_ci    /* ... */
25862306a36Sopenharmony_ci    return 0;
25962306a36Sopenharmony_ci}
26062306a36Sopenharmony_ci
26162306a36Sopenharmony_ci/**
26262306a36Sopenharmony_ci *  	xxxfb_setcolreg - Optional function. Sets a color register.
26362306a36Sopenharmony_ci *      @regno: Which register in the CLUT we are programming
26462306a36Sopenharmony_ci *      @red: The red value which can be up to 16 bits wide
26562306a36Sopenharmony_ci *	@green: The green value which can be up to 16 bits wide
26662306a36Sopenharmony_ci *	@blue:  The blue value which can be up to 16 bits wide.
26762306a36Sopenharmony_ci *	@transp: If supported, the alpha value which can be up to 16 bits wide.
26862306a36Sopenharmony_ci *      @info: frame buffer info structure
26962306a36Sopenharmony_ci *
27062306a36Sopenharmony_ci *  	Set a single color register. The values supplied have a 16 bit
27162306a36Sopenharmony_ci *  	magnitude which needs to be scaled in this function for the hardware.
27262306a36Sopenharmony_ci *	Things to take into consideration are how many color registers, if
27362306a36Sopenharmony_ci *	any, are supported with the current color visual. With truecolor mode
27462306a36Sopenharmony_ci *	no color palettes are supported. Here a pseudo palette is created
27562306a36Sopenharmony_ci *	which we store the value in pseudo_palette in struct fb_info. For
27662306a36Sopenharmony_ci *	pseudocolor mode we have a limited color palette. To deal with this
27762306a36Sopenharmony_ci *	we can program what color is displayed for a particular pixel value.
27862306a36Sopenharmony_ci *	DirectColor is similar in that we can program each color field. If
27962306a36Sopenharmony_ci *	we have a static colormap we don't need to implement this function.
28062306a36Sopenharmony_ci *
28162306a36Sopenharmony_ci *	Returns negative errno on error, or zero on success.
28262306a36Sopenharmony_ci */
28362306a36Sopenharmony_cistatic int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
28462306a36Sopenharmony_ci			   unsigned blue, unsigned transp,
28562306a36Sopenharmony_ci			   struct fb_info *info)
28662306a36Sopenharmony_ci{
28762306a36Sopenharmony_ci    if (regno >= 256)  /* no. of hw registers */
28862306a36Sopenharmony_ci       return -EINVAL;
28962306a36Sopenharmony_ci    /*
29062306a36Sopenharmony_ci     * Program hardware... do anything you want with transp
29162306a36Sopenharmony_ci     */
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ci    /* grayscale works only partially under directcolor */
29462306a36Sopenharmony_ci    if (info->var.grayscale) {
29562306a36Sopenharmony_ci       /* grayscale = 0.30*R + 0.59*G + 0.11*B */
29662306a36Sopenharmony_ci       red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
29762306a36Sopenharmony_ci    }
29862306a36Sopenharmony_ci
29962306a36Sopenharmony_ci    /* Directcolor:
30062306a36Sopenharmony_ci     *   var->{color}.offset contains start of bitfield
30162306a36Sopenharmony_ci     *   var->{color}.length contains length of bitfield
30262306a36Sopenharmony_ci     *   {hardwarespecific} contains width of DAC
30362306a36Sopenharmony_ci     *   pseudo_palette[X] is programmed to (X << red.offset) |
30462306a36Sopenharmony_ci     *                                      (X << green.offset) |
30562306a36Sopenharmony_ci     *                                      (X << blue.offset)
30662306a36Sopenharmony_ci     *   RAMDAC[X] is programmed to (red, green, blue)
30762306a36Sopenharmony_ci     *   color depth = SUM(var->{color}.length)
30862306a36Sopenharmony_ci     *
30962306a36Sopenharmony_ci     * Pseudocolor:
31062306a36Sopenharmony_ci     *    var->{color}.offset is 0 unless the palette index takes less than
31162306a36Sopenharmony_ci     *                        bits_per_pixel bits and is stored in the upper
31262306a36Sopenharmony_ci     *                        bits of the pixel value
31362306a36Sopenharmony_ci     *    var->{color}.length is set so that 1 << length is the number of
31462306a36Sopenharmony_ci     *                        available palette entries
31562306a36Sopenharmony_ci     *    pseudo_palette is not used
31662306a36Sopenharmony_ci     *    RAMDAC[X] is programmed to (red, green, blue)
31762306a36Sopenharmony_ci     *    color depth = var->{color}.length
31862306a36Sopenharmony_ci     *
31962306a36Sopenharmony_ci     * Static pseudocolor:
32062306a36Sopenharmony_ci     *    same as Pseudocolor, but the RAMDAC is not programmed (read-only)
32162306a36Sopenharmony_ci     *
32262306a36Sopenharmony_ci     * Mono01/Mono10:
32362306a36Sopenharmony_ci     *    Has only 2 values, black on white or white on black (fg on bg),
32462306a36Sopenharmony_ci     *    var->{color}.offset is 0
32562306a36Sopenharmony_ci     *    white = (1 << var->{color}.length) - 1, black = 0
32662306a36Sopenharmony_ci     *    pseudo_palette is not used
32762306a36Sopenharmony_ci     *    RAMDAC does not exist
32862306a36Sopenharmony_ci     *    color depth is always 2
32962306a36Sopenharmony_ci     *
33062306a36Sopenharmony_ci     * Truecolor:
33162306a36Sopenharmony_ci     *    does not use RAMDAC (usually has 3 of them).
33262306a36Sopenharmony_ci     *    var->{color}.offset contains start of bitfield
33362306a36Sopenharmony_ci     *    var->{color}.length contains length of bitfield
33462306a36Sopenharmony_ci     *    pseudo_palette is programmed to (red << red.offset) |
33562306a36Sopenharmony_ci     *                                    (green << green.offset) |
33662306a36Sopenharmony_ci     *                                    (blue << blue.offset) |
33762306a36Sopenharmony_ci     *                                    (transp << transp.offset)
33862306a36Sopenharmony_ci     *    RAMDAC does not exist
33962306a36Sopenharmony_ci     *    color depth = SUM(var->{color}.length})
34062306a36Sopenharmony_ci     *
34162306a36Sopenharmony_ci     *  The color depth is used by fbcon for choosing the logo and also
34262306a36Sopenharmony_ci     *  for color palette transformation if color depth < 4
34362306a36Sopenharmony_ci     *
34462306a36Sopenharmony_ci     *  As can be seen from the above, the field bits_per_pixel is _NOT_
34562306a36Sopenharmony_ci     *  a criteria for describing the color visual.
34662306a36Sopenharmony_ci     *
34762306a36Sopenharmony_ci     *  A common mistake is assuming that bits_per_pixel <= 8 is pseudocolor,
34862306a36Sopenharmony_ci     *  and higher than that, true/directcolor.  This is incorrect, one needs
34962306a36Sopenharmony_ci     *  to look at the fix->visual.
35062306a36Sopenharmony_ci     *
35162306a36Sopenharmony_ci     *  Another common mistake is using bits_per_pixel to calculate the color
35262306a36Sopenharmony_ci     *  depth.  The bits_per_pixel field does not directly translate to color
35362306a36Sopenharmony_ci     *  depth. You have to compute for the color depth (using the color
35462306a36Sopenharmony_ci     *  bitfields) and fix->visual as seen above.
35562306a36Sopenharmony_ci     */
35662306a36Sopenharmony_ci
35762306a36Sopenharmony_ci    /*
35862306a36Sopenharmony_ci     * This is the point where the color is converted to something that
35962306a36Sopenharmony_ci     * is acceptable by the hardware.
36062306a36Sopenharmony_ci     */
36162306a36Sopenharmony_ci#define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
36262306a36Sopenharmony_ci    red = CNVT_TOHW(red, info->var.red.length);
36362306a36Sopenharmony_ci    green = CNVT_TOHW(green, info->var.green.length);
36462306a36Sopenharmony_ci    blue = CNVT_TOHW(blue, info->var.blue.length);
36562306a36Sopenharmony_ci    transp = CNVT_TOHW(transp, info->var.transp.length);
36662306a36Sopenharmony_ci#undef CNVT_TOHW
36762306a36Sopenharmony_ci    /*
36862306a36Sopenharmony_ci     * This is the point where the function feeds the color to the hardware
36962306a36Sopenharmony_ci     * palette after converting the colors to something acceptable by
37062306a36Sopenharmony_ci     * the hardware. Note, only FB_VISUAL_DIRECTCOLOR and
37162306a36Sopenharmony_ci     * FB_VISUAL_PSEUDOCOLOR visuals need to write to the hardware palette.
37262306a36Sopenharmony_ci     * If you have code that writes to the hardware CLUT, and it's not
37362306a36Sopenharmony_ci     * any of the above visuals, then you are doing something wrong.
37462306a36Sopenharmony_ci     */
37562306a36Sopenharmony_ci    if (info->fix.visual == FB_VISUAL_DIRECTCOLOR ||
37662306a36Sopenharmony_ci	info->fix.visual == FB_VISUAL_TRUECOLOR)
37762306a36Sopenharmony_ci	    write_{red|green|blue|transp}_to_clut();
37862306a36Sopenharmony_ci
37962306a36Sopenharmony_ci    /* This is the point were you need to fill up the contents of
38062306a36Sopenharmony_ci     * info->pseudo_palette. This structure is used _only_ by fbcon, thus
38162306a36Sopenharmony_ci     * it only contains 16 entries to match the number of colors supported
38262306a36Sopenharmony_ci     * by the console. The pseudo_palette is used only if the visual is
38362306a36Sopenharmony_ci     * in directcolor or truecolor mode.  With other visuals, the
38462306a36Sopenharmony_ci     * pseudo_palette is not used. (This might change in the future.)
38562306a36Sopenharmony_ci     *
38662306a36Sopenharmony_ci     * The contents of the pseudo_palette is in raw pixel format.  Ie, each
38762306a36Sopenharmony_ci     * entry can be written directly to the framebuffer without any conversion.
38862306a36Sopenharmony_ci     * The pseudo_palette is (void *).  However, if using the generic
38962306a36Sopenharmony_ci     * drawing functions (cfb_imageblit, cfb_fillrect), the pseudo_palette
39062306a36Sopenharmony_ci     * must be casted to (u32 *) _regardless_ of the bits per pixel. If the
39162306a36Sopenharmony_ci     * driver is using its own drawing functions, then it can use whatever
39262306a36Sopenharmony_ci     * size it wants.
39362306a36Sopenharmony_ci     */
39462306a36Sopenharmony_ci    if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
39562306a36Sopenharmony_ci	info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
39662306a36Sopenharmony_ci	    u32 v;
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_ci	    if (regno >= 16)
39962306a36Sopenharmony_ci		    return -EINVAL;
40062306a36Sopenharmony_ci
40162306a36Sopenharmony_ci	    v = (red << info->var.red.offset) |
40262306a36Sopenharmony_ci		    (green << info->var.green.offset) |
40362306a36Sopenharmony_ci		    (blue << info->var.blue.offset) |
40462306a36Sopenharmony_ci		    (transp << info->var.transp.offset);
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ci	    ((u32*)(info->pseudo_palette))[regno] = v;
40762306a36Sopenharmony_ci    }
40862306a36Sopenharmony_ci
40962306a36Sopenharmony_ci    /* ... */
41062306a36Sopenharmony_ci    return 0;
41162306a36Sopenharmony_ci}
41262306a36Sopenharmony_ci
41362306a36Sopenharmony_ci/**
41462306a36Sopenharmony_ci *      xxxfb_pan_display - NOT a required function. Pans the display.
41562306a36Sopenharmony_ci *      @var: frame buffer variable screen structure
41662306a36Sopenharmony_ci *      @info: frame buffer structure that represents a single frame buffer
41762306a36Sopenharmony_ci *
41862306a36Sopenharmony_ci *	Pan (or wrap, depending on the `vmode' field) the display using the
41962306a36Sopenharmony_ci *  	`xoffset' and `yoffset' fields of the `var' structure.
42062306a36Sopenharmony_ci *  	If the values don't fit, return -EINVAL.
42162306a36Sopenharmony_ci *
42262306a36Sopenharmony_ci *      Returns negative errno on error, or zero on success.
42362306a36Sopenharmony_ci */
42462306a36Sopenharmony_cistatic int xxxfb_pan_display(struct fb_var_screeninfo *var,
42562306a36Sopenharmony_ci			     struct fb_info *info)
42662306a36Sopenharmony_ci{
42762306a36Sopenharmony_ci    /*
42862306a36Sopenharmony_ci     * If your hardware does not support panning, _do_ _not_ implement this
42962306a36Sopenharmony_ci     * function. Creating a dummy function will just confuse user apps.
43062306a36Sopenharmony_ci     */
43162306a36Sopenharmony_ci
43262306a36Sopenharmony_ci    /*
43362306a36Sopenharmony_ci     * Note that even if this function is fully functional, a setting of
43462306a36Sopenharmony_ci     * 0 in both xpanstep and ypanstep means that this function will never
43562306a36Sopenharmony_ci     * get called.
43662306a36Sopenharmony_ci     */
43762306a36Sopenharmony_ci
43862306a36Sopenharmony_ci    /* ... */
43962306a36Sopenharmony_ci    return 0;
44062306a36Sopenharmony_ci}
44162306a36Sopenharmony_ci
44262306a36Sopenharmony_ci/**
44362306a36Sopenharmony_ci *      xxxfb_blank - NOT a required function. Blanks the display.
44462306a36Sopenharmony_ci *      @blank_mode: the blank mode we want.
44562306a36Sopenharmony_ci *      @info: frame buffer structure that represents a single frame buffer
44662306a36Sopenharmony_ci *
44762306a36Sopenharmony_ci *      Blank the screen if blank_mode != FB_BLANK_UNBLANK, else unblank.
44862306a36Sopenharmony_ci *      Return 0 if blanking succeeded, != 0 if un-/blanking failed due to
44962306a36Sopenharmony_ci *      e.g. a video mode which doesn't support it.
45062306a36Sopenharmony_ci *
45162306a36Sopenharmony_ci *      Implements VESA suspend and powerdown modes on hardware that supports
45262306a36Sopenharmony_ci *      disabling hsync/vsync:
45362306a36Sopenharmony_ci *
45462306a36Sopenharmony_ci *      FB_BLANK_NORMAL = display is blanked, syncs are on.
45562306a36Sopenharmony_ci *      FB_BLANK_HSYNC_SUSPEND = hsync off
45662306a36Sopenharmony_ci *      FB_BLANK_VSYNC_SUSPEND = vsync off
45762306a36Sopenharmony_ci *      FB_BLANK_POWERDOWN =  hsync and vsync off
45862306a36Sopenharmony_ci *
45962306a36Sopenharmony_ci *      If implementing this function, at least support FB_BLANK_UNBLANK.
46062306a36Sopenharmony_ci *      Return !0 for any modes that are unimplemented.
46162306a36Sopenharmony_ci *
46262306a36Sopenharmony_ci */
46362306a36Sopenharmony_cistatic int xxxfb_blank(int blank_mode, struct fb_info *info)
46462306a36Sopenharmony_ci{
46562306a36Sopenharmony_ci    /* ... */
46662306a36Sopenharmony_ci    return 0;
46762306a36Sopenharmony_ci}
46862306a36Sopenharmony_ci
46962306a36Sopenharmony_ci/* ------------ Accelerated Functions --------------------- */
47062306a36Sopenharmony_ci
47162306a36Sopenharmony_ci/*
47262306a36Sopenharmony_ci * We provide our own functions if we have hardware acceleration
47362306a36Sopenharmony_ci * or non packed pixel format layouts. If we have no hardware
47462306a36Sopenharmony_ci * acceleration, we can use a generic unaccelerated function. If using
47562306a36Sopenharmony_ci * a pack pixel format just use the functions in cfb_*.c. Each file
47662306a36Sopenharmony_ci * has one of the three different accel functions we support.
47762306a36Sopenharmony_ci */
47862306a36Sopenharmony_ci
47962306a36Sopenharmony_ci/**
48062306a36Sopenharmony_ci *      xxxfb_fillrect - REQUIRED function. Can use generic routines if
48162306a36Sopenharmony_ci *		 	 non acclerated hardware and packed pixel based.
48262306a36Sopenharmony_ci *			 Draws a rectangle on the screen.
48362306a36Sopenharmony_ci *
48462306a36Sopenharmony_ci *      @info: frame buffer structure that represents a single frame buffer
48562306a36Sopenharmony_ci *	@region: The structure representing the rectangular region we
48662306a36Sopenharmony_ci *		 wish to draw to.
48762306a36Sopenharmony_ci *
48862306a36Sopenharmony_ci *	This drawing operation places/removes a retangle on the screen
48962306a36Sopenharmony_ci *	depending on the rastering operation with the value of color which
49062306a36Sopenharmony_ci *	is in the current color depth format.
49162306a36Sopenharmony_ci */
49262306a36Sopenharmony_civoid xxxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region)
49362306a36Sopenharmony_ci{
49462306a36Sopenharmony_ci/*	Meaning of struct fb_fillrect
49562306a36Sopenharmony_ci *
49662306a36Sopenharmony_ci *	@dx: The x and y corrdinates of the upper left hand corner of the
49762306a36Sopenharmony_ci *	@dy: area we want to draw to.
49862306a36Sopenharmony_ci *	@width: How wide the rectangle is we want to draw.
49962306a36Sopenharmony_ci *	@height: How tall the rectangle is we want to draw.
50062306a36Sopenharmony_ci *	@color:	The color to fill in the rectangle with.
50162306a36Sopenharmony_ci *	@rop: The raster operation. We can draw the rectangle with a COPY
50262306a36Sopenharmony_ci *	      of XOR which provides erasing effect.
50362306a36Sopenharmony_ci */
50462306a36Sopenharmony_ci}
50562306a36Sopenharmony_ci
50662306a36Sopenharmony_ci/**
50762306a36Sopenharmony_ci *      xxxfb_copyarea - REQUIRED function. Can use generic routines if
50862306a36Sopenharmony_ci *                       non acclerated hardware and packed pixel based.
50962306a36Sopenharmony_ci *                       Copies one area of the screen to another area.
51062306a36Sopenharmony_ci *
51162306a36Sopenharmony_ci *      @info: frame buffer structure that represents a single frame buffer
51262306a36Sopenharmony_ci *      @area: Structure providing the data to copy the framebuffer contents
51362306a36Sopenharmony_ci *	       from one region to another.
51462306a36Sopenharmony_ci *
51562306a36Sopenharmony_ci *      This drawing operation copies a rectangular area from one area of the
51662306a36Sopenharmony_ci *	screen to another area.
51762306a36Sopenharmony_ci */
51862306a36Sopenharmony_civoid xxxfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
51962306a36Sopenharmony_ci{
52062306a36Sopenharmony_ci/*
52162306a36Sopenharmony_ci *      @dx: The x and y coordinates of the upper left hand corner of the
52262306a36Sopenharmony_ci *	@dy: destination area on the screen.
52362306a36Sopenharmony_ci *      @width: How wide the rectangle is we want to copy.
52462306a36Sopenharmony_ci *      @height: How tall the rectangle is we want to copy.
52562306a36Sopenharmony_ci *      @sx: The x and y coordinates of the upper left hand corner of the
52662306a36Sopenharmony_ci *      @sy: source area on the screen.
52762306a36Sopenharmony_ci */
52862306a36Sopenharmony_ci}
52962306a36Sopenharmony_ci
53062306a36Sopenharmony_ci
53162306a36Sopenharmony_ci/**
53262306a36Sopenharmony_ci *      xxxfb_imageblit - REQUIRED function. Can use generic routines if
53362306a36Sopenharmony_ci *                        non acclerated hardware and packed pixel based.
53462306a36Sopenharmony_ci *                        Copies a image from system memory to the screen.
53562306a36Sopenharmony_ci *
53662306a36Sopenharmony_ci *      @info: frame buffer structure that represents a single frame buffer
53762306a36Sopenharmony_ci *	@image:	structure defining the image.
53862306a36Sopenharmony_ci *
53962306a36Sopenharmony_ci *      This drawing operation draws a image on the screen. It can be a
54062306a36Sopenharmony_ci *	mono image (needed for font handling) or a color image (needed for
54162306a36Sopenharmony_ci *	tux).
54262306a36Sopenharmony_ci */
54362306a36Sopenharmony_civoid xxxfb_imageblit(struct fb_info *p, const struct fb_image *image)
54462306a36Sopenharmony_ci{
54562306a36Sopenharmony_ci/*
54662306a36Sopenharmony_ci *      @dx: The x and y coordinates of the upper left hand corner of the
54762306a36Sopenharmony_ci *	@dy: destination area to place the image on the screen.
54862306a36Sopenharmony_ci *      @width: How wide the image is we want to copy.
54962306a36Sopenharmony_ci *      @height: How tall the image is we want to copy.
55062306a36Sopenharmony_ci *      @fg_color: For mono bitmap images this is color data for
55162306a36Sopenharmony_ci *      @bg_color: the foreground and background of the image to
55262306a36Sopenharmony_ci *		   write directly to the frmaebuffer.
55362306a36Sopenharmony_ci *	@depth:	How many bits represent a single pixel for this image.
55462306a36Sopenharmony_ci *	@data: The actual data used to construct the image on the display.
55562306a36Sopenharmony_ci *	@cmap: The colormap used for color images.
55662306a36Sopenharmony_ci */
55762306a36Sopenharmony_ci
55862306a36Sopenharmony_ci/*
55962306a36Sopenharmony_ci * The generic function, cfb_imageblit, expects that the bitmap scanlines are
56062306a36Sopenharmony_ci * padded to the next byte.  Most hardware accelerators may require padding to
56162306a36Sopenharmony_ci * the next u16 or the next u32.  If that is the case, the driver can specify
56262306a36Sopenharmony_ci * this by setting info->pixmap.scan_align = 2 or 4.  See a more
56362306a36Sopenharmony_ci * comprehensive description of the pixmap below.
56462306a36Sopenharmony_ci */
56562306a36Sopenharmony_ci}
56662306a36Sopenharmony_ci
56762306a36Sopenharmony_ci/**
56862306a36Sopenharmony_ci *	xxxfb_cursor - 	OPTIONAL. If your hardware lacks support
56962306a36Sopenharmony_ci *			for a cursor, leave this field NULL.
57062306a36Sopenharmony_ci *
57162306a36Sopenharmony_ci *      @info: frame buffer structure that represents a single frame buffer
57262306a36Sopenharmony_ci *	@cursor: structure defining the cursor to draw.
57362306a36Sopenharmony_ci *
57462306a36Sopenharmony_ci *      This operation is used to set or alter the properities of the
57562306a36Sopenharmony_ci *	cursor.
57662306a36Sopenharmony_ci *
57762306a36Sopenharmony_ci *	Returns negative errno on error, or zero on success.
57862306a36Sopenharmony_ci */
57962306a36Sopenharmony_ciint xxxfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
58062306a36Sopenharmony_ci{
58162306a36Sopenharmony_ci/*
58262306a36Sopenharmony_ci *      @set: 	Which fields we are altering in struct fb_cursor
58362306a36Sopenharmony_ci *	@enable: Disable or enable the cursor
58462306a36Sopenharmony_ci *      @rop: 	The bit operation we want to do.
58562306a36Sopenharmony_ci *      @mask:  This is the cursor mask bitmap.
58662306a36Sopenharmony_ci *      @dest:  A image of the area we are going to display the cursor.
58762306a36Sopenharmony_ci *		Used internally by the driver.
58862306a36Sopenharmony_ci *      @hot:	The hot spot.
58962306a36Sopenharmony_ci *	@image:	The actual data for the cursor image.
59062306a36Sopenharmony_ci *
59162306a36Sopenharmony_ci *      NOTES ON FLAGS (cursor->set):
59262306a36Sopenharmony_ci *
59362306a36Sopenharmony_ci *      FB_CUR_SETIMAGE - the cursor image has changed (cursor->image.data)
59462306a36Sopenharmony_ci *      FB_CUR_SETPOS   - the cursor position has changed (cursor->image.dx|dy)
59562306a36Sopenharmony_ci *      FB_CUR_SETHOT   - the cursor hot spot has changed (cursor->hot.dx|dy)
59662306a36Sopenharmony_ci *      FB_CUR_SETCMAP  - the cursor colors has changed (cursor->fg_color|bg_color)
59762306a36Sopenharmony_ci *      FB_CUR_SETSHAPE - the cursor bitmask has changed (cursor->mask)
59862306a36Sopenharmony_ci *      FB_CUR_SETSIZE  - the cursor size has changed (cursor->width|height)
59962306a36Sopenharmony_ci *      FB_CUR_SETALL   - everything has changed
60062306a36Sopenharmony_ci *
60162306a36Sopenharmony_ci *      NOTES ON ROPs (cursor->rop, Raster Operation)
60262306a36Sopenharmony_ci *
60362306a36Sopenharmony_ci *      ROP_XOR         - cursor->image.data XOR cursor->mask
60462306a36Sopenharmony_ci *      ROP_COPY        - curosr->image.data AND cursor->mask
60562306a36Sopenharmony_ci *
60662306a36Sopenharmony_ci *      OTHER NOTES:
60762306a36Sopenharmony_ci *
60862306a36Sopenharmony_ci *      - fbcon only supports a 2-color cursor (cursor->image.depth = 1)
60962306a36Sopenharmony_ci *      - The fb_cursor structure, @cursor, _will_ always contain valid
61062306a36Sopenharmony_ci *        fields, whether any particular bitfields in cursor->set is set
61162306a36Sopenharmony_ci *        or not.
61262306a36Sopenharmony_ci */
61362306a36Sopenharmony_ci}
61462306a36Sopenharmony_ci
61562306a36Sopenharmony_ci/**
61662306a36Sopenharmony_ci *	xxxfb_sync - NOT a required function. Normally the accel engine
61762306a36Sopenharmony_ci *		     for a graphics card take a specific amount of time.
61862306a36Sopenharmony_ci *		     Often we have to wait for the accelerator to finish
61962306a36Sopenharmony_ci *		     its operation before we can write to the framebuffer
62062306a36Sopenharmony_ci *		     so we can have consistent display output.
62162306a36Sopenharmony_ci *
62262306a36Sopenharmony_ci *      @info: frame buffer structure that represents a single frame buffer
62362306a36Sopenharmony_ci *
62462306a36Sopenharmony_ci *      If the driver has implemented its own hardware-based drawing function,
62562306a36Sopenharmony_ci *      implementing this function is highly recommended.
62662306a36Sopenharmony_ci */
62762306a36Sopenharmony_ciint xxxfb_sync(struct fb_info *info)
62862306a36Sopenharmony_ci{
62962306a36Sopenharmony_ci	return 0;
63062306a36Sopenharmony_ci}
63162306a36Sopenharmony_ci
63262306a36Sopenharmony_ci    /*
63362306a36Sopenharmony_ci     *  Frame buffer operations
63462306a36Sopenharmony_ci     */
63562306a36Sopenharmony_ci
63662306a36Sopenharmony_cistatic const struct fb_ops xxxfb_ops = {
63762306a36Sopenharmony_ci	.owner		= THIS_MODULE,
63862306a36Sopenharmony_ci	.fb_open	= xxxfb_open,
63962306a36Sopenharmony_ci	.fb_read	= xxxfb_read,
64062306a36Sopenharmony_ci	.fb_write	= xxxfb_write,
64162306a36Sopenharmony_ci	.fb_release	= xxxfb_release,
64262306a36Sopenharmony_ci	.fb_check_var	= xxxfb_check_var,
64362306a36Sopenharmony_ci	.fb_set_par	= xxxfb_set_par,
64462306a36Sopenharmony_ci	.fb_setcolreg	= xxxfb_setcolreg,
64562306a36Sopenharmony_ci	.fb_blank	= xxxfb_blank,
64662306a36Sopenharmony_ci	.fb_pan_display	= xxxfb_pan_display,
64762306a36Sopenharmony_ci	.fb_fillrect	= xxxfb_fillrect, 	/* Needed !!! */
64862306a36Sopenharmony_ci	.fb_copyarea	= xxxfb_copyarea,	/* Needed !!! */
64962306a36Sopenharmony_ci	.fb_imageblit	= xxxfb_imageblit,	/* Needed !!! */
65062306a36Sopenharmony_ci	.fb_cursor	= xxxfb_cursor,		/* Optional !!! */
65162306a36Sopenharmony_ci	.fb_sync	= xxxfb_sync,
65262306a36Sopenharmony_ci	.fb_ioctl	= xxxfb_ioctl,
65362306a36Sopenharmony_ci	.fb_mmap	= xxxfb_mmap,
65462306a36Sopenharmony_ci};
65562306a36Sopenharmony_ci
65662306a36Sopenharmony_ci/* ------------------------------------------------------------------------- */
65762306a36Sopenharmony_ci
65862306a36Sopenharmony_ci    /*
65962306a36Sopenharmony_ci     *  Initialization
66062306a36Sopenharmony_ci     */
66162306a36Sopenharmony_ci
66262306a36Sopenharmony_ci/* static int __init xxfb_probe (struct platform_device *pdev) -- for platform devs */
66362306a36Sopenharmony_cistatic int xxxfb_probe(struct pci_dev *dev, const struct pci_device_id *ent)
66462306a36Sopenharmony_ci{
66562306a36Sopenharmony_ci    struct fb_info *info;
66662306a36Sopenharmony_ci    struct xxx_par *par;
66762306a36Sopenharmony_ci    struct device *device = &dev->dev; /* or &pdev->dev */
66862306a36Sopenharmony_ci    int cmap_len, retval;
66962306a36Sopenharmony_ci
67062306a36Sopenharmony_ci    /*
67162306a36Sopenharmony_ci     * Remove firmware-based drivers that create resource conflicts.
67262306a36Sopenharmony_ci     */
67362306a36Sopenharmony_ci    retval = aperture_remove_conflicting_pci_devices(pdev, "xxxfb");
67462306a36Sopenharmony_ci    if (retval)
67562306a36Sopenharmony_ci	    return retval;
67662306a36Sopenharmony_ci
67762306a36Sopenharmony_ci    /*
67862306a36Sopenharmony_ci     * Dynamically allocate info and par
67962306a36Sopenharmony_ci     */
68062306a36Sopenharmony_ci    info = framebuffer_alloc(sizeof(struct xxx_par), device);
68162306a36Sopenharmony_ci
68262306a36Sopenharmony_ci    if (!info) {
68362306a36Sopenharmony_ci	    /* goto error path */
68462306a36Sopenharmony_ci    }
68562306a36Sopenharmony_ci
68662306a36Sopenharmony_ci    par = info->par;
68762306a36Sopenharmony_ci
68862306a36Sopenharmony_ci    /*
68962306a36Sopenharmony_ci     * Here we set the screen_base to the virtual memory address
69062306a36Sopenharmony_ci     * for the framebuffer. Usually we obtain the resource address
69162306a36Sopenharmony_ci     * from the bus layer and then translate it to virtual memory
69262306a36Sopenharmony_ci     * space via ioremap. Consult ioport.h.
69362306a36Sopenharmony_ci     */
69462306a36Sopenharmony_ci    info->screen_base = framebuffer_virtual_memory;
69562306a36Sopenharmony_ci    info->fbops = &xxxfb_ops;
69662306a36Sopenharmony_ci    info->fix = xxxfb_fix;
69762306a36Sopenharmony_ci    info->pseudo_palette = pseudo_palette; /* The pseudopalette is an
69862306a36Sopenharmony_ci					    * 16-member array
69962306a36Sopenharmony_ci					    */
70062306a36Sopenharmony_ci    /*
70162306a36Sopenharmony_ci     * Set up flags to indicate what sort of acceleration your
70262306a36Sopenharmony_ci     * driver can provide (pan/wrap/copyarea/etc.) and whether it
70362306a36Sopenharmony_ci     * is a module -- see FBINFO_* in include/linux/fb.h
70462306a36Sopenharmony_ci     *
70562306a36Sopenharmony_ci     * If your hardware can support any of the hardware accelerated functions
70662306a36Sopenharmony_ci     * fbcon performance will improve if info->flags is set properly.
70762306a36Sopenharmony_ci     *
70862306a36Sopenharmony_ci     * FBINFO_HWACCEL_COPYAREA - hardware moves
70962306a36Sopenharmony_ci     * FBINFO_HWACCEL_FILLRECT - hardware fills
71062306a36Sopenharmony_ci     * FBINFO_HWACCEL_IMAGEBLIT - hardware mono->color expansion
71162306a36Sopenharmony_ci     * FBINFO_HWACCEL_YPAN - hardware can pan display in y-axis
71262306a36Sopenharmony_ci     * FBINFO_HWACCEL_YWRAP - hardware can wrap display in y-axis
71362306a36Sopenharmony_ci     * FBINFO_HWACCEL_DISABLED - supports hardware accels, but disabled
71462306a36Sopenharmony_ci     * FBINFO_READS_FAST - if set, prefer moves over mono->color expansion
71562306a36Sopenharmony_ci     * FBINFO_MISC_TILEBLITTING - hardware can do tile blits
71662306a36Sopenharmony_ci     *
71762306a36Sopenharmony_ci     * NOTE: These are for fbcon use only.
71862306a36Sopenharmony_ci     */
71962306a36Sopenharmony_ci    info->flags = 0;
72062306a36Sopenharmony_ci
72162306a36Sopenharmony_ci/********************* This stage is optional ******************************/
72262306a36Sopenharmony_ci     /*
72362306a36Sopenharmony_ci     * The struct pixmap is a scratch pad for the drawing functions. This
72462306a36Sopenharmony_ci     * is where the monochrome bitmap is constructed by the higher layers
72562306a36Sopenharmony_ci     * and then passed to the accelerator.  For drivers that uses
72662306a36Sopenharmony_ci     * cfb_imageblit, you can skip this part.  For those that have a more
72762306a36Sopenharmony_ci     * rigorous requirement, this stage is needed
72862306a36Sopenharmony_ci     */
72962306a36Sopenharmony_ci
73062306a36Sopenharmony_ci    /* PIXMAP_SIZE should be small enough to optimize drawing, but not
73162306a36Sopenharmony_ci     * large enough that memory is wasted.  A safe size is
73262306a36Sopenharmony_ci     * (max_xres * max_font_height/8). max_xres is driver dependent,
73362306a36Sopenharmony_ci     * max_font_height is 32.
73462306a36Sopenharmony_ci     */
73562306a36Sopenharmony_ci    info->pixmap.addr = kmalloc(PIXMAP_SIZE, GFP_KERNEL);
73662306a36Sopenharmony_ci    if (!info->pixmap.addr) {
73762306a36Sopenharmony_ci	    /* goto error */
73862306a36Sopenharmony_ci    }
73962306a36Sopenharmony_ci
74062306a36Sopenharmony_ci    info->pixmap.size = PIXMAP_SIZE;
74162306a36Sopenharmony_ci
74262306a36Sopenharmony_ci    /*
74362306a36Sopenharmony_ci     * FB_PIXMAP_SYSTEM - memory is in system ram
74462306a36Sopenharmony_ci     * FB_PIXMAP_IO     - memory is iomapped
74562306a36Sopenharmony_ci     * FB_PIXMAP_SYNC   - if set, will call fb_sync() per access to pixmap,
74662306a36Sopenharmony_ci     *                    usually if FB_PIXMAP_IO is set.
74762306a36Sopenharmony_ci     *
74862306a36Sopenharmony_ci     * Currently, FB_PIXMAP_IO is unimplemented.
74962306a36Sopenharmony_ci     */
75062306a36Sopenharmony_ci    info->pixmap.flags = FB_PIXMAP_SYSTEM;
75162306a36Sopenharmony_ci
75262306a36Sopenharmony_ci    /*
75362306a36Sopenharmony_ci     * scan_align is the number of padding for each scanline.  It is in bytes.
75462306a36Sopenharmony_ci     * Thus for accelerators that need padding to the next u32, put 4 here.
75562306a36Sopenharmony_ci     */
75662306a36Sopenharmony_ci    info->pixmap.scan_align = 4;
75762306a36Sopenharmony_ci
75862306a36Sopenharmony_ci    /*
75962306a36Sopenharmony_ci     * buf_align is the amount to be padded for the buffer. For example,
76062306a36Sopenharmony_ci     * the i810fb needs a scan_align of 2 but expects it to be fed with
76162306a36Sopenharmony_ci     * dwords, so a buf_align = 4 is required.
76262306a36Sopenharmony_ci     */
76362306a36Sopenharmony_ci    info->pixmap.buf_align = 4;
76462306a36Sopenharmony_ci
76562306a36Sopenharmony_ci    /* access_align is how many bits can be accessed from the framebuffer
76662306a36Sopenharmony_ci     * ie. some epson cards allow 16-bit access only.  Most drivers will
76762306a36Sopenharmony_ci     * be safe with u32 here.
76862306a36Sopenharmony_ci     *
76962306a36Sopenharmony_ci     * NOTE: This field is currently unused.
77062306a36Sopenharmony_ci     */
77162306a36Sopenharmony_ci    info->pixmap.access_align = 32;
77262306a36Sopenharmony_ci/***************************** End optional stage ***************************/
77362306a36Sopenharmony_ci
77462306a36Sopenharmony_ci    /*
77562306a36Sopenharmony_ci     * This should give a reasonable default video mode. The following is
77662306a36Sopenharmony_ci     * done when we can set a video mode.
77762306a36Sopenharmony_ci     */
77862306a36Sopenharmony_ci    if (!mode_option)
77962306a36Sopenharmony_ci	mode_option = "640x480@60";
78062306a36Sopenharmony_ci
78162306a36Sopenharmony_ci    retval = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
78262306a36Sopenharmony_ci
78362306a36Sopenharmony_ci    if (!retval || retval == 4)
78462306a36Sopenharmony_ci	return -EINVAL;
78562306a36Sopenharmony_ci
78662306a36Sopenharmony_ci    /* This has to be done! */
78762306a36Sopenharmony_ci    if (fb_alloc_cmap(&info->cmap, cmap_len, 0))
78862306a36Sopenharmony_ci	return -ENOMEM;
78962306a36Sopenharmony_ci
79062306a36Sopenharmony_ci    /*
79162306a36Sopenharmony_ci     * The following is done in the case of having hardware with a static
79262306a36Sopenharmony_ci     * mode. If we are setting the mode ourselves we don't call this.
79362306a36Sopenharmony_ci     */
79462306a36Sopenharmony_ci    info->var = xxxfb_var;
79562306a36Sopenharmony_ci
79662306a36Sopenharmony_ci    /*
79762306a36Sopenharmony_ci     * For drivers that can...
79862306a36Sopenharmony_ci     */
79962306a36Sopenharmony_ci    xxxfb_check_var(&info->var, info);
80062306a36Sopenharmony_ci
80162306a36Sopenharmony_ci    /*
80262306a36Sopenharmony_ci     * Does a call to fb_set_par() before register_framebuffer needed?  This
80362306a36Sopenharmony_ci     * will depend on you and the hardware.  If you are sure that your driver
80462306a36Sopenharmony_ci     * is the only device in the system, a call to fb_set_par() is safe.
80562306a36Sopenharmony_ci     *
80662306a36Sopenharmony_ci     * Hardware in x86 systems has a VGA core.  Calling set_par() at this
80762306a36Sopenharmony_ci     * point will corrupt the VGA console, so it might be safer to skip a
80862306a36Sopenharmony_ci     * call to set_par here and just allow fbcon to do it for you.
80962306a36Sopenharmony_ci     */
81062306a36Sopenharmony_ci    /* xxxfb_set_par(info); */
81162306a36Sopenharmony_ci
81262306a36Sopenharmony_ci    if (register_framebuffer(info) < 0) {
81362306a36Sopenharmony_ci	fb_dealloc_cmap(&info->cmap);
81462306a36Sopenharmony_ci	return -EINVAL;
81562306a36Sopenharmony_ci    }
81662306a36Sopenharmony_ci    fb_info(info, "%s frame buffer device\n", info->fix.id);
81762306a36Sopenharmony_ci    pci_set_drvdata(dev, info); /* or platform_set_drvdata(pdev, info) */
81862306a36Sopenharmony_ci    return 0;
81962306a36Sopenharmony_ci}
82062306a36Sopenharmony_ci
82162306a36Sopenharmony_ci    /*
82262306a36Sopenharmony_ci     *  Cleanup
82362306a36Sopenharmony_ci     */
82462306a36Sopenharmony_ci/* static void xxxfb_remove(struct platform_device *pdev) */
82562306a36Sopenharmony_cistatic void xxxfb_remove(struct pci_dev *dev)
82662306a36Sopenharmony_ci{
82762306a36Sopenharmony_ci	struct fb_info *info = pci_get_drvdata(dev);
82862306a36Sopenharmony_ci	/* or platform_get_drvdata(pdev); */
82962306a36Sopenharmony_ci
83062306a36Sopenharmony_ci	if (info) {
83162306a36Sopenharmony_ci		unregister_framebuffer(info);
83262306a36Sopenharmony_ci		fb_dealloc_cmap(&info->cmap);
83362306a36Sopenharmony_ci		/* ... */
83462306a36Sopenharmony_ci		framebuffer_release(info);
83562306a36Sopenharmony_ci	}
83662306a36Sopenharmony_ci}
83762306a36Sopenharmony_ci
83862306a36Sopenharmony_ci#ifdef CONFIG_PCI
83962306a36Sopenharmony_ci#ifdef CONFIG_PM
84062306a36Sopenharmony_ci/**
84162306a36Sopenharmony_ci *	xxxfb_suspend - Optional but recommended function. Suspend the device.
84262306a36Sopenharmony_ci *	@dev: PCI device
84362306a36Sopenharmony_ci *	@msg: the suspend event code.
84462306a36Sopenharmony_ci *
84562306a36Sopenharmony_ci *      See Documentation/driver-api/pm/devices.rst for more information
84662306a36Sopenharmony_ci */
84762306a36Sopenharmony_cistatic int xxxfb_suspend(struct device *dev)
84862306a36Sopenharmony_ci{
84962306a36Sopenharmony_ci	struct fb_info *info = dev_get_drvdata(dev);
85062306a36Sopenharmony_ci	struct xxxfb_par *par = info->par;
85162306a36Sopenharmony_ci
85262306a36Sopenharmony_ci	/* suspend here */
85362306a36Sopenharmony_ci	return 0;
85462306a36Sopenharmony_ci}
85562306a36Sopenharmony_ci
85662306a36Sopenharmony_ci/**
85762306a36Sopenharmony_ci *	xxxfb_resume - Optional but recommended function. Resume the device.
85862306a36Sopenharmony_ci *	@dev: PCI device
85962306a36Sopenharmony_ci *
86062306a36Sopenharmony_ci *      See Documentation/driver-api/pm/devices.rst for more information
86162306a36Sopenharmony_ci */
86262306a36Sopenharmony_cistatic int xxxfb_resume(struct device *dev)
86362306a36Sopenharmony_ci{
86462306a36Sopenharmony_ci	struct fb_info *info = dev_get_drvdata(dev);
86562306a36Sopenharmony_ci	struct xxxfb_par *par = info->par;
86662306a36Sopenharmony_ci
86762306a36Sopenharmony_ci	/* resume here */
86862306a36Sopenharmony_ci	return 0;
86962306a36Sopenharmony_ci}
87062306a36Sopenharmony_ci#else
87162306a36Sopenharmony_ci#define xxxfb_suspend NULL
87262306a36Sopenharmony_ci#define xxxfb_resume NULL
87362306a36Sopenharmony_ci#endif /* CONFIG_PM */
87462306a36Sopenharmony_ci
87562306a36Sopenharmony_cistatic const struct pci_device_id xxxfb_id_table[] = {
87662306a36Sopenharmony_ci	{ PCI_VENDOR_ID_XXX, PCI_DEVICE_ID_XXX,
87762306a36Sopenharmony_ci	  PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
87862306a36Sopenharmony_ci	  PCI_CLASS_MASK, 0 },
87962306a36Sopenharmony_ci	{ 0, }
88062306a36Sopenharmony_ci};
88162306a36Sopenharmony_ci
88262306a36Sopenharmony_cistatic SIMPLE_DEV_PM_OPS(xxxfb_pm_ops, xxxfb_suspend, xxxfb_resume);
88362306a36Sopenharmony_ci
88462306a36Sopenharmony_ci/* For PCI drivers */
88562306a36Sopenharmony_cistatic struct pci_driver xxxfb_driver = {
88662306a36Sopenharmony_ci	.name =		"xxxfb",
88762306a36Sopenharmony_ci	.id_table =	xxxfb_id_table,
88862306a36Sopenharmony_ci	.probe =	xxxfb_probe,
88962306a36Sopenharmony_ci	.remove =	xxxfb_remove,
89062306a36Sopenharmony_ci	.driver.pm =	xxxfb_pm_ops, /* optional but recommended */
89162306a36Sopenharmony_ci};
89262306a36Sopenharmony_ci
89362306a36Sopenharmony_ciMODULE_DEVICE_TABLE(pci, xxxfb_id_table);
89462306a36Sopenharmony_ci
89562306a36Sopenharmony_cistatic int __init xxxfb_init(void)
89662306a36Sopenharmony_ci{
89762306a36Sopenharmony_ci	/*
89862306a36Sopenharmony_ci	 *  For kernel boot options (in 'video=xxxfb:<options>' format)
89962306a36Sopenharmony_ci	 */
90062306a36Sopenharmony_ci#ifndef MODULE
90162306a36Sopenharmony_ci	char *option = NULL;
90262306a36Sopenharmony_ci
90362306a36Sopenharmony_ci	if (fb_get_options("xxxfb", &option))
90462306a36Sopenharmony_ci		return -ENODEV;
90562306a36Sopenharmony_ci	xxxfb_setup(option);
90662306a36Sopenharmony_ci#endif
90762306a36Sopenharmony_ci
90862306a36Sopenharmony_ci	return pci_register_driver(&xxxfb_driver);
90962306a36Sopenharmony_ci}
91062306a36Sopenharmony_ci
91162306a36Sopenharmony_cistatic void __exit xxxfb_exit(void)
91262306a36Sopenharmony_ci{
91362306a36Sopenharmony_ci	pci_unregister_driver(&xxxfb_driver);
91462306a36Sopenharmony_ci}
91562306a36Sopenharmony_ci#else /* non PCI, platform drivers */
91662306a36Sopenharmony_ci#include <linux/platform_device.h>
91762306a36Sopenharmony_ci/* for platform devices */
91862306a36Sopenharmony_ci
91962306a36Sopenharmony_ci#ifdef CONFIG_PM
92062306a36Sopenharmony_ci/**
92162306a36Sopenharmony_ci *	xxxfb_suspend - Optional but recommended function. Suspend the device.
92262306a36Sopenharmony_ci *	@dev: platform device
92362306a36Sopenharmony_ci *	@msg: the suspend event code.
92462306a36Sopenharmony_ci *
92562306a36Sopenharmony_ci *      See Documentation/driver-api/pm/devices.rst for more information
92662306a36Sopenharmony_ci */
92762306a36Sopenharmony_cistatic int xxxfb_suspend(struct platform_device *dev, pm_message_t msg)
92862306a36Sopenharmony_ci{
92962306a36Sopenharmony_ci	struct fb_info *info = platform_get_drvdata(dev);
93062306a36Sopenharmony_ci	struct xxxfb_par *par = info->par;
93162306a36Sopenharmony_ci
93262306a36Sopenharmony_ci	/* suspend here */
93362306a36Sopenharmony_ci	return 0;
93462306a36Sopenharmony_ci}
93562306a36Sopenharmony_ci
93662306a36Sopenharmony_ci/**
93762306a36Sopenharmony_ci *	xxxfb_resume - Optional but recommended function. Resume the device.
93862306a36Sopenharmony_ci *	@dev: platform device
93962306a36Sopenharmony_ci *
94062306a36Sopenharmony_ci *      See Documentation/driver-api/pm/devices.rst for more information
94162306a36Sopenharmony_ci */
94262306a36Sopenharmony_cistatic int xxxfb_resume(struct platform_dev *dev)
94362306a36Sopenharmony_ci{
94462306a36Sopenharmony_ci	struct fb_info *info = platform_get_drvdata(dev);
94562306a36Sopenharmony_ci	struct xxxfb_par *par = info->par;
94662306a36Sopenharmony_ci
94762306a36Sopenharmony_ci	/* resume here */
94862306a36Sopenharmony_ci	return 0;
94962306a36Sopenharmony_ci}
95062306a36Sopenharmony_ci#else
95162306a36Sopenharmony_ci#define xxxfb_suspend NULL
95262306a36Sopenharmony_ci#define xxxfb_resume NULL
95362306a36Sopenharmony_ci#endif /* CONFIG_PM */
95462306a36Sopenharmony_ci
95562306a36Sopenharmony_cistatic struct platform_device_driver xxxfb_driver = {
95662306a36Sopenharmony_ci	.probe = xxxfb_probe,
95762306a36Sopenharmony_ci	.remove = xxxfb_remove,
95862306a36Sopenharmony_ci	.suspend = xxxfb_suspend, /* optional but recommended */
95962306a36Sopenharmony_ci	.resume = xxxfb_resume,   /* optional but recommended */
96062306a36Sopenharmony_ci	.driver = {
96162306a36Sopenharmony_ci		.name = "xxxfb",
96262306a36Sopenharmony_ci	},
96362306a36Sopenharmony_ci};
96462306a36Sopenharmony_ci
96562306a36Sopenharmony_cistatic struct platform_device *xxxfb_device;
96662306a36Sopenharmony_ci
96762306a36Sopenharmony_ci#ifndef MODULE
96862306a36Sopenharmony_ci    /*
96962306a36Sopenharmony_ci     *  Setup
97062306a36Sopenharmony_ci     */
97162306a36Sopenharmony_ci
97262306a36Sopenharmony_ci/*
97362306a36Sopenharmony_ci * Only necessary if your driver takes special options,
97462306a36Sopenharmony_ci * otherwise we fall back on the generic fb_setup().
97562306a36Sopenharmony_ci */
97662306a36Sopenharmony_cistatic int __init xxxfb_setup(char *options)
97762306a36Sopenharmony_ci{
97862306a36Sopenharmony_ci    /* Parse user specified options (`video=xxxfb:') */
97962306a36Sopenharmony_ci}
98062306a36Sopenharmony_ci#endif /* MODULE */
98162306a36Sopenharmony_ci
98262306a36Sopenharmony_cistatic int __init xxxfb_init(void)
98362306a36Sopenharmony_ci{
98462306a36Sopenharmony_ci	int ret;
98562306a36Sopenharmony_ci	/*
98662306a36Sopenharmony_ci	 *  For kernel boot options (in 'video=xxxfb:<options>' format)
98762306a36Sopenharmony_ci	 */
98862306a36Sopenharmony_ci#ifndef MODULE
98962306a36Sopenharmony_ci	char *option = NULL;
99062306a36Sopenharmony_ci#endif
99162306a36Sopenharmony_ci
99262306a36Sopenharmony_ci	if (fb_modesetting_disabled("xxxfb"))
99362306a36Sopenharmony_ci		return -ENODEV;
99462306a36Sopenharmony_ci
99562306a36Sopenharmony_ci#ifndef MODULE
99662306a36Sopenharmony_ci	if (fb_get_options("xxxfb", &option))
99762306a36Sopenharmony_ci		return -ENODEV;
99862306a36Sopenharmony_ci	xxxfb_setup(option);
99962306a36Sopenharmony_ci#endif
100062306a36Sopenharmony_ci	ret = platform_driver_register(&xxxfb_driver);
100162306a36Sopenharmony_ci
100262306a36Sopenharmony_ci	if (!ret) {
100362306a36Sopenharmony_ci		xxxfb_device = platform_device_register_simple("xxxfb", 0,
100462306a36Sopenharmony_ci								NULL, 0);
100562306a36Sopenharmony_ci
100662306a36Sopenharmony_ci		if (IS_ERR(xxxfb_device)) {
100762306a36Sopenharmony_ci			platform_driver_unregister(&xxxfb_driver);
100862306a36Sopenharmony_ci			ret = PTR_ERR(xxxfb_device);
100962306a36Sopenharmony_ci		}
101062306a36Sopenharmony_ci	}
101162306a36Sopenharmony_ci
101262306a36Sopenharmony_ci	return ret;
101362306a36Sopenharmony_ci}
101462306a36Sopenharmony_ci
101562306a36Sopenharmony_cistatic void __exit xxxfb_exit(void)
101662306a36Sopenharmony_ci{
101762306a36Sopenharmony_ci	platform_device_unregister(xxxfb_device);
101862306a36Sopenharmony_ci	platform_driver_unregister(&xxxfb_driver);
101962306a36Sopenharmony_ci}
102062306a36Sopenharmony_ci#endif /* CONFIG_PCI */
102162306a36Sopenharmony_ci
102262306a36Sopenharmony_ci/* ------------------------------------------------------------------------- */
102362306a36Sopenharmony_ci
102462306a36Sopenharmony_ci
102562306a36Sopenharmony_ci    /*
102662306a36Sopenharmony_ci     *  Modularization
102762306a36Sopenharmony_ci     */
102862306a36Sopenharmony_ci
102962306a36Sopenharmony_cimodule_init(xxxfb_init);
103062306a36Sopenharmony_cimodule_exit(xxxfb_exit);
103162306a36Sopenharmony_ci
103262306a36Sopenharmony_ciMODULE_LICENSE("GPL");
1033