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