summaryrefslogtreecommitdiffstats
path: root/drivers/video/skeletonfb.c
blob: 3f795cd63e985f5d09426e96edcd7a8bda470d08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/*
 * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device
 *
 *  Created 28 Dec 1997 by Geert Uytterhoeven
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file README.legal in the main directory of this archive
 * for more details.
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/tty.h>
#include <linux/malloc.h>
#include <linux/delay.h>
#include <linux/fb.h>

#include "fbcon.h"


    /*
     *  This is just simple sample code.
     *
     *  No warranty that it actually compiles.
     *  Even less warranty that it actually works :-)
     */


struct xxxfb_info {
    /*
     *  Choose _one_ of the two alternatives:
     *
     *    1. Use the generic frame buffer operations (fbgen_*).
     */
    struct fb_info_gen gen;
    /*
     *    2. Provide your own frame buffer operations.
     */
    struct fb_info info;

    /* Here starts the frame buffer device dependent part */
    /* You can use this to store e.g. the board number if you support */
    /* multiple boards */
};


struct xxxfb_par {
    /*
     *  The hardware specific data in this structure uniquely defines a video
     *  mode.
     *
     *  If your hardware supports only one video mode, you can leave it empty.
     */
};


    /*
     *  If your driver supports multiple boards, you should make these arrays,
     *  or allocate them dynamically (using mem_start for builtin drivers, and
     *  kmalloc() for loaded modules).
     */

static struct xxxfb_info fb_info;
static struct xxxfb_par current_par;
static int current_par_valid = 0;
static struct display disp;

static struct fb_var_screeninfo default_var;

static int currcon = 0;
static int inverse = 0;


/* ------------------- chipset specific functions -------------------------- */


static void xxx_detect(void)
{
    /*
     *  This function should detect the current video mode settings and store
     *  it as the default video mode
     */

    /* ... */
    xxx_get_par(&par);
    xxx_encode_var(&default_var, &par);
}

static int xxx_encode_fix(struct fb_fix_screeninfo *fix, struct xxxfb_par *par,
			  const struct fb_info *fb_info)
{
    /*
     *  This function should fill in the 'fix' structure based on the values
     *  in the `par' structure.
     */

    /* ... */
    return 0;
}

static int xxx_decode_var(struct fb_var_screeninfo *var, struct xxxfb_par *par,
			  const struct fb_info *fb_info)
{
    /*
     *  Get the video params out of 'var'. If a value doesn't fit, round it up,
     *  if it's too big, return -EINVAL.
     *
     *  Suggestion: Round up in the following order: bits_per_pixel, xres,
     *  yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
     *  bitfields, horizontal timing, vertical timing.
     */

    /* ... */

    /* pixclock in picos, htotal in pixels, vtotal in scanlines */
    if (!fbmon_valid_timings(pixclock, htotal, vtotal, info))
	    return -EINVAL;

    return 0;
}

static int xxx_encode_var(struct fb_var_screeninfo *var, struct xxxfb_par *par,
			  const struct fb_info *fb_info)
{
    /*
     *  Fill the 'var' structure based on the values in 'par' and maybe other
     *  values read out of the hardware.
     */

    /* ... */
    return 0;
}

static void xxx_get_par(struct xxxfb_par *par, const struct fb_info *fb_info)
{
    /*
     *  Fill the hardware's 'par' structure.
     */

    if (current_par_valid)
	*par = current_par;
    else {
	/* ... */
    }
}

static void xxx_set_par(struct xxxfb_par *par, const struct fb_info *fb_info)
{
    /*
     *  Set the hardware according to 'par'.
     */

    current_par = *par;
    current_par_valid = 1;
    /* ... */
}

static int xxx_getcolreg(unsigned regno, unsigned *red, unsigned *green,
			 unsigned *blue, unsigned *transp,
			 const struct fb_info *fb_info)
{
    /*
     *  Read a single color register and split it into colors/transparent.
     *  Return != 0 for invalid regno.
     */

    /* ... */
    return 0;
}

static int xxx_setcolreg(unsigned regno, unsigned red, unsigned green,
			 unsigned blue, unsigned transp,
			 const struct fb_info *fb_info)
{
    /*
     *  Set a single color register. The values supplied are already rounded
     *  down to the hardware's capabilities (according to the entries in the
     *  `var' structure). Return != 0 for invalid regno.
     */

    if (regno < 16) {
	/*
	 *  Make the first 16 colors of the palette available to fbcon
	 */
	if (is_cfb15)		/* RGB 555 */
	    fbcon_cfb15_cmap[regno] = be16_to_cpu((red << 10) | (green << 5) |
						  blue);
	if (is_cfb16)		/* RGB 565 */
	    fbcon_cfb16_cmap[regno] = be16_to_cpu((red << 11) | (green << 5) |
						  blue);
	if (is_cfb24)		/* RGB 888 */
	    fbcon_cfb24_cmap[regno] = be32_to_cpu((red << 16) | (green << 8) |
						  blue);
	if (is_cfb32)		/* RGBA 8888 */
	    fbcon_cfb32_cmap[regno] = be32_to_cpu((red << 24) | (green << 16) |
						  (blue << 8) | transp);
    }
    /* ... */
    return 0;
}

static int xxx_pan_display(struct fb_var_screeninfo *var,
			   struct xxxfb_par *par,
			   const struct fb_info *fb_info)
{
    /*
     *  Pan (or wrap, depending on the `vmode' field) the display using the
     *  `xoffset' and `yoffset' fields of the `var' structure.
     *  If the values don't fit, return -EINVAL.
     */

    /* ... */
    return 0;
}

static int xxx_blank(int blank_mode, const struct fb_info *fb_info)
{
    /*
     *  Blank the screen if blank_mode != 0, else unblank. If blank == NULL
     *  then the caller blanks by setting the CLUT (Color Look Up Table) to all
     *  black. Return 0 if blanking succeeded, != 0 if un-/blanking failed due
     *  to e.g. a video mode which doesn't support it. Implements VESA suspend
     *  and powerdown modes on hardware that supports disabling hsync/vsync:
     *    blank_mode == 2: suspend vsync
     *    blank_mode == 3: suspend hsync
     *    blank_mode == 4: powerdown
     */

    /* ... */
    return 0;
}

static struct display_switch *xxx_get_dispsw(const void *par,
					     struct fb_info_gen *info)
{
    /*
     *  Return a pointer to appropriate low level text console operations for
     *  the video mode `par' of your video hardware. These can be generic
     *  software routines, or hardware accelerated routines specifically
     *  tailored for your hardware.
     *  If you don't have any appropriate operations, simple fill in the NULL
     *  pointer, and there will be no text output.
     */
#ifdef CONFIG_FBCON_CFB8
    if (is_cfb8)
	return &fbcon_cfb8;
#endif
#ifdef CONFIG_FBCON_CFB16
    if (is_cfb16)
	return &fbcon_cfb16;
#endif
#ifdef CONFIG_FBCON_CFB32
    if (is_cfb32)
	return &fbcon_cfb32;
#endif
    return NULL;
}


/* ------------ Interfaces to hardware functions ------------ */


struct fbgen_hwswitch xxx_switch = {
    xxx_detect, xxx_encode_fix, xxx_decode_var, xxx_encode_var, xxx_get_par,
    xxx_set_par, xxx_getcolreg, xxx_setcolreg, xxx_blank, xxx_dispsw
};



/* ------------ Hardware Independant Functions ------------ */


    /*
     *  Initialization
     */

__initfunc(unsigned long xxxfb_init(unsigned long mem_start))
{
    int err;
    struct fb_var_screeninfo var;

    fb_info.fbhw = &xxx_switch;
    fbhw->detect();
    strcpy(fb_info.modename, "XXX");
    fb_info.changevar = NULL;
    fb_info.node = -1;
    fb_info.fbops = &xxxfb_ops;
    fb_info.disp = disp;
    fb_info.switch_con = &xxxfb_switch;
    fb_info.updatevar = &xxxfb_update_var;
    fb_info.blank = &xxxfb_blank;
    /* This should give a reasonable default video mode */
    fbgen_get_var(&disp.var, -1, &fb_info.gen);
    fbgen_do_set_var(var, 1, &fbinfo.gen);
    err = register_framebuffer(&fb_info.gen.info);
    if (err < 0)
	return err;
    fbgen_set_disp(-1, &fb_info.gen.info);
    fbgen_install_cmap(0, &fb_info.gen);
    printk("fb%d: %s frame buffer device\n", GET_FB_IDX(fb_info.node),
	   fb_info.modename);

    /* uncomment this if your driver cannot be unloaded */
    /* MOD_INC_USE_COUNT; */

    return mem_start;
}


    /*
     *  Cleanup
     */

void xxxfb_cleanup(struct fb_info *info)
{
    /*
     *  If your driver supports multiple boards, you should unregister and
     *  clean up all instances.
     */

    unregister_framebuffer(&fb_info);
    /* ... */
}


    /*
     *  Setup
     */

__initfunc(void xxxfb_setup(char *options, int *ints))
{
    /* Parse user speficied options (`video=xxxfb:') */
}


/* ------------------------------------------------------------------------- */


    /*
     *  Frame buffer operations
     */

static int xxxfb_open(const struct fb_info *info)
{
    /* Nothing, only a usage count for the moment */
    MOD_INC_USE_COUNT;
    return 0;
}

static int xxxfb_release(const struct fb_info *info)
{
    MOD_DEC_USE_COUNT;
    return 0;
}


    /*
     *  In most cases the `generic' routines (fbgen_*) should be satisfactory.
     *  However, you're free to fill in your own replacements.
     */

static struct fb_ops xxxfb_ops = {
    xxxfb_open, xxxfb_release, fbgen_get_fix, fbgen_get_var, fbgen_set_var,
    fbgen_get_cmap, fbgen_set_cmap, fbgen_pan_display, NULL, fbgen_ioctl
};


/* ------------------------------------------------------------------------- */


    /*
     *  Modularization
     */

#ifdef MODULE
int init_module(void)
{
    return xxxfb_init(NULL);
}

void cleanup_module(void)
{
    xxxfb_cleanup(void);
}
#endif /* MODULE */