2 * linux/drivers/video/omap2/omapfb-main.c
4 * Copyright (C) 2008 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7 * Some code and ideas taken from drivers/video/omap/ driver
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <linux/module.h>
24 #include <linux/delay.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/vmalloc.h>
28 #include <linux/device.h>
29 #include <linux/platform_device.h>
30 #include <linux/omapfb.h>
32 #include <plat/display.h>
33 #include <plat/vram.h>
34 #include <plat/vrfb.h>
38 #define MODULE_NAME "omapfb"
40 #define OMAPFB_PLANE_XRES_MIN 8
41 #define OMAPFB_PLANE_YRES_MIN 8
43 static char *def_mode
;
44 static char *def_vram
;
46 static int def_rotate
;
47 static int def_mirror
;
50 unsigned int omapfb_debug
;
51 module_param_named(debug
, omapfb_debug
, bool, 0644);
52 static unsigned int omapfb_test_pattern
;
53 module_param_named(test
, omapfb_test_pattern
, bool, 0644);
56 static int omapfb_fb_init(struct omapfb2_device
*fbdev
, struct fb_info
*fbi
);
59 static void draw_pixel(struct fb_info
*fbi
, int x
, int y
, unsigned color
)
61 struct fb_var_screeninfo
*var
= &fbi
->var
;
62 struct fb_fix_screeninfo
*fix
= &fbi
->fix
;
63 void __iomem
*addr
= fbi
->screen_base
;
64 const unsigned bytespp
= var
->bits_per_pixel
>> 3;
65 const unsigned line_len
= fix
->line_length
/ bytespp
;
67 int r
= (color
>> 16) & 0xff;
68 int g
= (color
>> 8) & 0xff;
69 int b
= (color
>> 0) & 0xff;
71 if (var
->bits_per_pixel
== 16) {
72 u16 __iomem
*p
= (u16 __iomem
*)addr
;
73 p
+= y
* line_len
+ x
;
79 __raw_writew((r
<< 11) | (g
<< 5) | (b
<< 0), p
);
80 } else if (var
->bits_per_pixel
== 24) {
81 u8 __iomem
*p
= (u8 __iomem
*)addr
;
82 p
+= (y
* line_len
+ x
) * 3;
84 __raw_writeb(b
, p
+ 0);
85 __raw_writeb(g
, p
+ 1);
86 __raw_writeb(r
, p
+ 2);
87 } else if (var
->bits_per_pixel
== 32) {
88 u32 __iomem
*p
= (u32 __iomem
*)addr
;
89 p
+= y
* line_len
+ x
;
90 __raw_writel(color
, p
);
94 static void fill_fb(struct fb_info
*fbi
)
96 struct fb_var_screeninfo
*var
= &fbi
->var
;
97 const short w
= var
->xres_virtual
;
98 const short h
= var
->yres_virtual
;
99 void __iomem
*addr
= fbi
->screen_base
;
105 DBG("fill_fb %dx%d, line_len %d bytes\n", w
, h
, fbi
->fix
.line_length
);
107 for (y
= 0; y
< h
; y
++) {
108 for (x
= 0; x
< w
; x
++) {
109 if (x
< 20 && y
< 20)
110 draw_pixel(fbi
, x
, y
, 0xffffff);
111 else if (x
< 20 && (y
> 20 && y
< h
- 20))
112 draw_pixel(fbi
, x
, y
, 0xff);
113 else if (y
< 20 && (x
> 20 && x
< w
- 20))
114 draw_pixel(fbi
, x
, y
, 0xff00);
115 else if (x
> w
- 20 && (y
> 20 && y
< h
- 20))
116 draw_pixel(fbi
, x
, y
, 0xff0000);
117 else if (y
> h
- 20 && (x
> 20 && x
< w
- 20))
118 draw_pixel(fbi
, x
, y
, 0xffff00);
119 else if (x
== 20 || x
== w
- 20 ||
120 y
== 20 || y
== h
- 20)
121 draw_pixel(fbi
, x
, y
, 0xffffff);
122 else if (x
== y
|| w
- x
== h
- y
)
123 draw_pixel(fbi
, x
, y
, 0xff00ff);
124 else if (w
- x
== y
|| x
== h
- y
)
125 draw_pixel(fbi
, x
, y
, 0x00ffff);
126 else if (x
> 20 && y
> 20 && x
< w
- 20 && y
< h
- 20) {
128 unsigned r
= 0, g
= 0, b
= 0;
130 if (var
->bits_per_pixel
== 16) {
132 b
= (y
% 32) * 256 / 32;
134 g
= (y
% 64) * 256 / 64;
136 r
= (y
% 32) * 256 / 32;
145 c
= (r
<< 16) | (g
<< 8) | (b
<< 0);
146 draw_pixel(fbi
, x
, y
, c
);
148 draw_pixel(fbi
, x
, y
, 0);
155 static unsigned omapfb_get_vrfb_offset(struct omapfb_info
*ofbi
, int rot
)
157 struct vrfb
*vrfb
= &ofbi
->region
.vrfb
;
165 offset
= vrfb
->yoffset
;
168 offset
= vrfb
->yoffset
* OMAP_VRFB_LINE_LEN
+ vrfb
->xoffset
;
171 offset
= vrfb
->xoffset
* OMAP_VRFB_LINE_LEN
;
177 offset
*= vrfb
->bytespp
;
182 static u32
omapfb_get_region_rot_paddr(struct omapfb_info
*ofbi
, int rot
)
184 if (ofbi
->rotation_type
== OMAP_DSS_ROT_VRFB
) {
185 return ofbi
->region
.vrfb
.paddr
[rot
]
186 + omapfb_get_vrfb_offset(ofbi
, rot
);
188 return ofbi
->region
.paddr
;
192 static u32
omapfb_get_region_paddr(struct omapfb_info
*ofbi
)
194 if (ofbi
->rotation_type
== OMAP_DSS_ROT_VRFB
)
195 return ofbi
->region
.vrfb
.paddr
[0];
197 return ofbi
->region
.paddr
;
200 static void __iomem
*omapfb_get_region_vaddr(struct omapfb_info
*ofbi
)
202 if (ofbi
->rotation_type
== OMAP_DSS_ROT_VRFB
)
203 return ofbi
->region
.vrfb
.vaddr
[0];
205 return ofbi
->region
.vaddr
;
208 static struct omapfb_colormode omapfb_colormodes
[] = {
210 .dssmode
= OMAP_DSS_COLOR_UYVY
,
211 .bits_per_pixel
= 16,
212 .nonstd
= OMAPFB_COLOR_YUV422
,
214 .dssmode
= OMAP_DSS_COLOR_YUV2
,
215 .bits_per_pixel
= 16,
216 .nonstd
= OMAPFB_COLOR_YUY422
,
218 .dssmode
= OMAP_DSS_COLOR_ARGB16
,
219 .bits_per_pixel
= 16,
220 .red
= { .length
= 4, .offset
= 8, .msb_right
= 0 },
221 .green
= { .length
= 4, .offset
= 4, .msb_right
= 0 },
222 .blue
= { .length
= 4, .offset
= 0, .msb_right
= 0 },
223 .transp
= { .length
= 4, .offset
= 12, .msb_right
= 0 },
225 .dssmode
= OMAP_DSS_COLOR_RGB16
,
226 .bits_per_pixel
= 16,
227 .red
= { .length
= 5, .offset
= 11, .msb_right
= 0 },
228 .green
= { .length
= 6, .offset
= 5, .msb_right
= 0 },
229 .blue
= { .length
= 5, .offset
= 0, .msb_right
= 0 },
230 .transp
= { .length
= 0, .offset
= 0, .msb_right
= 0 },
232 .dssmode
= OMAP_DSS_COLOR_RGB24P
,
233 .bits_per_pixel
= 24,
234 .red
= { .length
= 8, .offset
= 16, .msb_right
= 0 },
235 .green
= { .length
= 8, .offset
= 8, .msb_right
= 0 },
236 .blue
= { .length
= 8, .offset
= 0, .msb_right
= 0 },
237 .transp
= { .length
= 0, .offset
= 0, .msb_right
= 0 },
239 .dssmode
= OMAP_DSS_COLOR_RGB24U
,
240 .bits_per_pixel
= 32,
241 .red
= { .length
= 8, .offset
= 16, .msb_right
= 0 },
242 .green
= { .length
= 8, .offset
= 8, .msb_right
= 0 },
243 .blue
= { .length
= 8, .offset
= 0, .msb_right
= 0 },
244 .transp
= { .length
= 0, .offset
= 0, .msb_right
= 0 },
246 .dssmode
= OMAP_DSS_COLOR_ARGB32
,
247 .bits_per_pixel
= 32,
248 .red
= { .length
= 8, .offset
= 16, .msb_right
= 0 },
249 .green
= { .length
= 8, .offset
= 8, .msb_right
= 0 },
250 .blue
= { .length
= 8, .offset
= 0, .msb_right
= 0 },
251 .transp
= { .length
= 8, .offset
= 24, .msb_right
= 0 },
253 .dssmode
= OMAP_DSS_COLOR_RGBA32
,
254 .bits_per_pixel
= 32,
255 .red
= { .length
= 8, .offset
= 24, .msb_right
= 0 },
256 .green
= { .length
= 8, .offset
= 16, .msb_right
= 0 },
257 .blue
= { .length
= 8, .offset
= 8, .msb_right
= 0 },
258 .transp
= { .length
= 8, .offset
= 0, .msb_right
= 0 },
260 .dssmode
= OMAP_DSS_COLOR_RGBX32
,
261 .bits_per_pixel
= 32,
262 .red
= { .length
= 8, .offset
= 24, .msb_right
= 0 },
263 .green
= { .length
= 8, .offset
= 16, .msb_right
= 0 },
264 .blue
= { .length
= 8, .offset
= 8, .msb_right
= 0 },
265 .transp
= { .length
= 0, .offset
= 0, .msb_right
= 0 },
269 static bool cmp_var_to_colormode(struct fb_var_screeninfo
*var
,
270 struct omapfb_colormode
*color
)
272 bool cmp_component(struct fb_bitfield
*f1
, struct fb_bitfield
*f2
)
274 return f1
->length
== f2
->length
&&
275 f1
->offset
== f2
->offset
&&
276 f1
->msb_right
== f2
->msb_right
;
279 if (var
->bits_per_pixel
== 0 ||
280 var
->red
.length
== 0 ||
281 var
->blue
.length
== 0 ||
282 var
->green
.length
== 0)
285 return var
->bits_per_pixel
== color
->bits_per_pixel
&&
286 cmp_component(&var
->red
, &color
->red
) &&
287 cmp_component(&var
->green
, &color
->green
) &&
288 cmp_component(&var
->blue
, &color
->blue
) &&
289 cmp_component(&var
->transp
, &color
->transp
);
292 static void assign_colormode_to_var(struct fb_var_screeninfo
*var
,
293 struct omapfb_colormode
*color
)
295 var
->bits_per_pixel
= color
->bits_per_pixel
;
296 var
->nonstd
= color
->nonstd
;
297 var
->red
= color
->red
;
298 var
->green
= color
->green
;
299 var
->blue
= color
->blue
;
300 var
->transp
= color
->transp
;
303 static int fb_mode_to_dss_mode(struct fb_var_screeninfo
*var
,
304 enum omap_color_mode
*mode
)
306 enum omap_color_mode dssmode
;
309 /* first match with nonstd field */
311 for (i
= 0; i
< ARRAY_SIZE(omapfb_colormodes
); ++i
) {
312 struct omapfb_colormode
*m
= &omapfb_colormodes
[i
];
313 if (var
->nonstd
== m
->nonstd
) {
314 assign_colormode_to_var(var
, m
);
323 /* then try exact match of bpp and colors */
324 for (i
= 0; i
< ARRAY_SIZE(omapfb_colormodes
); ++i
) {
325 struct omapfb_colormode
*m
= &omapfb_colormodes
[i
];
326 if (cmp_var_to_colormode(var
, m
)) {
327 assign_colormode_to_var(var
, m
);
333 /* match with bpp if user has not filled color fields
335 switch (var
->bits_per_pixel
) {
337 dssmode
= OMAP_DSS_COLOR_CLUT1
;
340 dssmode
= OMAP_DSS_COLOR_CLUT2
;
343 dssmode
= OMAP_DSS_COLOR_CLUT4
;
346 dssmode
= OMAP_DSS_COLOR_CLUT8
;
349 dssmode
= OMAP_DSS_COLOR_RGB12U
;
352 dssmode
= OMAP_DSS_COLOR_RGB16
;
355 dssmode
= OMAP_DSS_COLOR_RGB24P
;
358 dssmode
= OMAP_DSS_COLOR_RGB24U
;
364 for (i
= 0; i
< ARRAY_SIZE(omapfb_colormodes
); ++i
) {
365 struct omapfb_colormode
*m
= &omapfb_colormodes
[i
];
366 if (dssmode
== m
->dssmode
) {
367 assign_colormode_to_var(var
, m
);
376 static int check_fb_res_bounds(struct fb_var_screeninfo
*var
)
378 int xres_min
= OMAPFB_PLANE_XRES_MIN
;
380 int yres_min
= OMAPFB_PLANE_YRES_MIN
;
383 /* XXX: some applications seem to set virtual res to 0. */
384 if (var
->xres_virtual
== 0)
385 var
->xres_virtual
= var
->xres
;
387 if (var
->yres_virtual
== 0)
388 var
->yres_virtual
= var
->yres
;
390 if (var
->xres_virtual
< xres_min
|| var
->yres_virtual
< yres_min
)
393 if (var
->xres
< xres_min
)
394 var
->xres
= xres_min
;
395 if (var
->yres
< yres_min
)
396 var
->yres
= yres_min
;
397 if (var
->xres
> xres_max
)
398 var
->xres
= xres_max
;
399 if (var
->yres
> yres_max
)
400 var
->yres
= yres_max
;
402 if (var
->xres
> var
->xres_virtual
)
403 var
->xres
= var
->xres_virtual
;
404 if (var
->yres
> var
->yres_virtual
)
405 var
->yres
= var
->yres_virtual
;
410 static void shrink_height(unsigned long max_frame_size
,
411 struct fb_var_screeninfo
*var
)
413 DBG("can't fit FB into memory, reducing y\n");
414 var
->yres_virtual
= max_frame_size
/
415 (var
->xres_virtual
* var
->bits_per_pixel
>> 3);
417 if (var
->yres_virtual
< OMAPFB_PLANE_YRES_MIN
)
418 var
->yres_virtual
= OMAPFB_PLANE_YRES_MIN
;
420 if (var
->yres
> var
->yres_virtual
)
421 var
->yres
= var
->yres_virtual
;
424 static void shrink_width(unsigned long max_frame_size
,
425 struct fb_var_screeninfo
*var
)
427 DBG("can't fit FB into memory, reducing x\n");
428 var
->xres_virtual
= max_frame_size
/ var
->yres_virtual
/
429 (var
->bits_per_pixel
>> 3);
431 if (var
->xres_virtual
< OMAPFB_PLANE_XRES_MIN
)
432 var
->xres_virtual
= OMAPFB_PLANE_XRES_MIN
;
434 if (var
->xres
> var
->xres_virtual
)
435 var
->xres
= var
->xres_virtual
;
438 static int check_vrfb_fb_size(unsigned long region_size
,
439 const struct fb_var_screeninfo
*var
)
441 unsigned long min_phys_size
= omap_vrfb_min_phys_size(var
->xres_virtual
,
442 var
->yres_virtual
, var
->bits_per_pixel
>> 3);
444 return min_phys_size
> region_size
? -EINVAL
: 0;
447 static int check_fb_size(const struct omapfb_info
*ofbi
,
448 struct fb_var_screeninfo
*var
)
450 unsigned long max_frame_size
= ofbi
->region
.size
;
451 int bytespp
= var
->bits_per_pixel
>> 3;
452 unsigned long line_size
= var
->xres_virtual
* bytespp
;
454 if (ofbi
->rotation_type
== OMAP_DSS_ROT_VRFB
) {
455 /* One needs to check for both VRFB and OMAPFB limitations. */
456 if (check_vrfb_fb_size(max_frame_size
, var
))
457 shrink_height(omap_vrfb_max_height(
458 max_frame_size
, var
->xres_virtual
, bytespp
) *
461 if (check_vrfb_fb_size(max_frame_size
, var
)) {
462 DBG("cannot fit FB to memory\n");
469 DBG("max frame size %lu, line size %lu\n", max_frame_size
, line_size
);
471 if (line_size
* var
->yres_virtual
> max_frame_size
)
472 shrink_height(max_frame_size
, var
);
474 if (line_size
* var
->yres_virtual
> max_frame_size
) {
475 shrink_width(max_frame_size
, var
);
476 line_size
= var
->xres_virtual
* bytespp
;
479 if (line_size
* var
->yres_virtual
> max_frame_size
) {
480 DBG("cannot fit FB to memory\n");
488 * Consider if VRFB assisted rotation is in use and if the virtual space for
489 * the zero degree view needs to be mapped. The need for mapping also acts as
490 * the trigger for setting up the hardware on the context in question. This
491 * ensures that one does not attempt to access the virtual view before the
492 * hardware is serving the address translations.
494 static int setup_vrfb_rotation(struct fb_info
*fbi
)
496 struct omapfb_info
*ofbi
= FB2OFB(fbi
);
497 struct omapfb2_mem_region
*rg
= &ofbi
->region
;
498 struct vrfb
*vrfb
= &rg
->vrfb
;
499 struct fb_var_screeninfo
*var
= &fbi
->var
;
500 struct fb_fix_screeninfo
*fix
= &fbi
->fix
;
503 enum omap_color_mode mode
;
507 if (!rg
->size
|| ofbi
->rotation_type
!= OMAP_DSS_ROT_VRFB
)
510 DBG("setup_vrfb_rotation\n");
512 r
= fb_mode_to_dss_mode(var
, &mode
);
516 bytespp
= var
->bits_per_pixel
>> 3;
518 yuv_mode
= mode
== OMAP_DSS_COLOR_YUV2
|| mode
== OMAP_DSS_COLOR_UYVY
;
520 /* We need to reconfigure VRFB if the resolution changes, if yuv mode
521 * is enabled/disabled, or if bytes per pixel changes */
523 /* XXX we shouldn't allow this when framebuffer is mmapped */
527 if (yuv_mode
!= vrfb
->yuv_mode
)
529 else if (bytespp
!= vrfb
->bytespp
)
531 else if (vrfb
->xres
!= var
->xres_virtual
||
532 vrfb
->yres
!= var
->yres_virtual
)
535 if (vrfb
->vaddr
[0] && reconf
) {
536 fbi
->screen_base
= NULL
;
539 iounmap(vrfb
->vaddr
[0]);
540 vrfb
->vaddr
[0] = NULL
;
541 DBG("setup_vrfb_rotation: reset fb\n");
547 omap_vrfb_setup(&rg
->vrfb
, rg
->paddr
,
552 /* Now one can ioremap the 0 angle view */
553 r
= omap_vrfb_map_angle(vrfb
, var
->yres_virtual
, 0);
557 /* used by open/write in fbmem.c */
558 fbi
->screen_base
= ofbi
->region
.vrfb
.vaddr
[0];
560 fix
->smem_start
= ofbi
->region
.vrfb
.paddr
[0];
562 switch (var
->nonstd
) {
563 case OMAPFB_COLOR_YUV422
:
564 case OMAPFB_COLOR_YUY422
:
566 (OMAP_VRFB_LINE_LEN
* var
->bits_per_pixel
) >> 2;
570 (OMAP_VRFB_LINE_LEN
* var
->bits_per_pixel
) >> 3;
574 fix
->smem_len
= var
->yres_virtual
* fix
->line_length
;
579 int dss_mode_to_fb_mode(enum omap_color_mode dssmode
,
580 struct fb_var_screeninfo
*var
)
584 for (i
= 0; i
< ARRAY_SIZE(omapfb_colormodes
); ++i
) {
585 struct omapfb_colormode
*mode
= &omapfb_colormodes
[i
];
586 if (dssmode
== mode
->dssmode
) {
587 assign_colormode_to_var(var
, mode
);
594 void set_fb_fix(struct fb_info
*fbi
)
596 struct fb_fix_screeninfo
*fix
= &fbi
->fix
;
597 struct fb_var_screeninfo
*var
= &fbi
->var
;
598 struct omapfb_info
*ofbi
= FB2OFB(fbi
);
599 struct omapfb2_mem_region
*rg
= &ofbi
->region
;
603 /* used by open/write in fbmem.c */
604 fbi
->screen_base
= (char __iomem
*)omapfb_get_region_vaddr(ofbi
);
606 /* used by mmap in fbmem.c */
607 if (ofbi
->rotation_type
== OMAP_DSS_ROT_VRFB
) {
608 switch (var
->nonstd
) {
609 case OMAPFB_COLOR_YUV422
:
610 case OMAPFB_COLOR_YUY422
:
612 (OMAP_VRFB_LINE_LEN
* var
->bits_per_pixel
) >> 2;
616 (OMAP_VRFB_LINE_LEN
* var
->bits_per_pixel
) >> 3;
620 fix
->smem_len
= var
->yres_virtual
* fix
->line_length
;
623 (var
->xres_virtual
* var
->bits_per_pixel
) >> 3;
624 fix
->smem_len
= rg
->size
;
627 fix
->smem_start
= omapfb_get_region_paddr(ofbi
);
629 fix
->type
= FB_TYPE_PACKED_PIXELS
;
632 fix
->visual
= FB_VISUAL_PSEUDOCOLOR
;
634 switch (var
->bits_per_pixel
) {
639 fix
->visual
= FB_VISUAL_TRUECOLOR
;
640 /* 12bpp is stored in 16 bits */
646 fix
->visual
= FB_VISUAL_PSEUDOCOLOR
;
651 fix
->accel
= FB_ACCEL_NONE
;
657 /* check new var and possibly modify it to be ok */
658 int check_fb_var(struct fb_info
*fbi
, struct fb_var_screeninfo
*var
)
660 struct omapfb_info
*ofbi
= FB2OFB(fbi
);
661 struct omap_dss_device
*display
= fb2display(fbi
);
662 enum omap_color_mode mode
= 0;
666 DBG("check_fb_var %d\n", ofbi
->id
);
668 if (ofbi
->region
.size
== 0)
671 r
= fb_mode_to_dss_mode(var
, &mode
);
673 DBG("cannot convert var to omap dss mode\n");
677 for (i
= 0; i
< ofbi
->num_overlays
; ++i
) {
678 if ((ofbi
->overlays
[i
]->supported_modes
& mode
) == 0) {
679 DBG("invalid mode\n");
684 if (var
->rotate
< 0 || var
->rotate
> 3)
687 if (check_fb_res_bounds(var
))
690 if (check_fb_size(ofbi
, var
))
693 if (var
->xres
+ var
->xoffset
> var
->xres_virtual
)
694 var
->xoffset
= var
->xres_virtual
- var
->xres
;
695 if (var
->yres
+ var
->yoffset
> var
->yres_virtual
)
696 var
->yoffset
= var
->yres_virtual
- var
->yres
;
698 DBG("xres = %d, yres = %d, vxres = %d, vyres = %d\n",
699 var
->xres
, var
->yres
,
700 var
->xres_virtual
, var
->yres_virtual
);
706 if (display
&& display
->get_timings
) {
707 struct omap_video_timings timings
;
708 display
->get_timings(display
, &timings
);
710 /* pixclock in ps, the rest in pixclock */
711 var
->pixclock
= timings
.pixel_clock
!= 0 ?
712 KHZ2PICOS(timings
.pixel_clock
) :
714 var
->left_margin
= timings
.hfp
;
715 var
->right_margin
= timings
.hbp
;
716 var
->upper_margin
= timings
.vfp
;
717 var
->lower_margin
= timings
.vbp
;
718 var
->hsync_len
= timings
.hsw
;
719 var
->vsync_len
= timings
.vsw
;
722 var
->left_margin
= 0;
723 var
->right_margin
= 0;
724 var
->upper_margin
= 0;
725 var
->lower_margin
= 0;
730 /* TODO: get these from panel->config */
731 var
->vmode
= FB_VMODE_NONINTERLACED
;
738 * ---------------------------------------------------------------------------
739 * fbdev framework callbacks
740 * ---------------------------------------------------------------------------
742 static int omapfb_open(struct fb_info
*fbi
, int user
)
747 static int omapfb_release(struct fb_info
*fbi
, int user
)
750 struct omapfb_info
*ofbi
= FB2OFB(fbi
);
751 struct omapfb2_device
*fbdev
= ofbi
->fbdev
;
752 struct omap_dss_device
*display
= fb2display(fbi
);
754 DBG("Closing fb with plane index %d\n", ofbi
->id
);
758 if (display
&& display
->get_update_mode
&& display
->update
) {
759 /* XXX this update should be removed, I think. But it's
760 * good for debugging */
761 if (display
->get_update_mode(display
) ==
762 OMAP_DSS_UPDATE_MANUAL
) {
766 display
->sync(display
);
768 display
->get_resolution(display
, &w
, &h
);
769 display
->update(display
, 0, 0, w
, h
);
773 if (display
&& display
->sync
)
774 display
->sync(display
);
776 omapfb_unlock(fbdev
);
781 static unsigned calc_rotation_offset_dma(struct fb_var_screeninfo
*var
,
782 struct fb_fix_screeninfo
*fix
, int rotation
)
786 offset
= var
->yoffset
* fix
->line_length
+
787 var
->xoffset
* (var
->bits_per_pixel
>> 3);
792 static unsigned calc_rotation_offset_vrfb(struct fb_var_screeninfo
*var
,
793 struct fb_fix_screeninfo
*fix
, int rotation
)
797 if (rotation
== FB_ROTATE_UD
)
798 offset
= (var
->yres_virtual
- var
->yres
) *
800 else if (rotation
== FB_ROTATE_CW
)
801 offset
= (var
->yres_virtual
- var
->yres
) *
802 (var
->bits_per_pixel
>> 3);
806 if (rotation
== FB_ROTATE_UR
)
807 offset
+= var
->yoffset
* fix
->line_length
+
808 var
->xoffset
* (var
->bits_per_pixel
>> 3);
809 else if (rotation
== FB_ROTATE_UD
)
810 offset
-= var
->yoffset
* fix
->line_length
+
811 var
->xoffset
* (var
->bits_per_pixel
>> 3);
812 else if (rotation
== FB_ROTATE_CW
)
813 offset
-= var
->xoffset
* fix
->line_length
+
814 var
->yoffset
* (var
->bits_per_pixel
>> 3);
815 else if (rotation
== FB_ROTATE_CCW
)
816 offset
+= var
->xoffset
* fix
->line_length
+
817 var
->yoffset
* (var
->bits_per_pixel
>> 3);
823 /* setup overlay according to the fb */
824 static int omapfb_setup_overlay(struct fb_info
*fbi
, struct omap_overlay
*ovl
,
825 u16 posx
, u16 posy
, u16 outw
, u16 outh
)
828 struct omapfb_info
*ofbi
= FB2OFB(fbi
);
829 struct fb_var_screeninfo
*var
= &fbi
->var
;
830 struct fb_fix_screeninfo
*fix
= &fbi
->fix
;
831 enum omap_color_mode mode
= 0;
834 void __iomem
*data_start_v
;
835 struct omap_overlay_info info
;
839 int rotation
= var
->rotate
;
842 for (i
= 0; i
< ofbi
->num_overlays
; i
++) {
843 if (ovl
!= ofbi
->overlays
[i
])
846 rotation
= (rotation
+ ofbi
->rotation
[i
]) % 4;
850 DBG("setup_overlay %d, posx %d, posy %d, outw %d, outh %d\n", ofbi
->id
,
851 posx
, posy
, outw
, outh
);
853 if (rotation
== FB_ROTATE_CW
|| rotation
== FB_ROTATE_CCW
) {
862 if (ofbi
->rotation_type
== OMAP_DSS_ROT_VRFB
) {
863 data_start_p
= omapfb_get_region_rot_paddr(ofbi
, rotation
);
866 data_start_p
= omapfb_get_region_paddr(ofbi
);
867 data_start_v
= omapfb_get_region_vaddr(ofbi
);
870 if (ofbi
->rotation_type
== OMAP_DSS_ROT_VRFB
)
871 offset
= calc_rotation_offset_vrfb(var
, fix
, rotation
);
873 offset
= calc_rotation_offset_dma(var
, fix
, rotation
);
875 data_start_p
+= offset
;
876 data_start_v
+= offset
;
879 DBG("offset %d, %d = %d\n",
880 var
->xoffset
, var
->yoffset
, offset
);
882 DBG("paddr %x, vaddr %p\n", data_start_p
, data_start_v
);
884 r
= fb_mode_to_dss_mode(var
, &mode
);
886 DBG("fb_mode_to_dss_mode failed");
890 switch (var
->nonstd
) {
891 case OMAPFB_COLOR_YUV422
:
892 case OMAPFB_COLOR_YUY422
:
893 if (ofbi
->rotation_type
== OMAP_DSS_ROT_VRFB
) {
894 screen_width
= fix
->line_length
895 / (var
->bits_per_pixel
>> 2);
899 screen_width
= fix
->line_length
/ (var
->bits_per_pixel
>> 3);
903 ovl
->get_overlay_info(ovl
, &info
);
905 if (ofbi
->rotation_type
== OMAP_DSS_ROT_VRFB
)
908 mirror
= ofbi
->mirror
;
910 info
.paddr
= data_start_p
;
911 info
.vaddr
= data_start_v
;
912 info
.screen_width
= screen_width
;
915 info
.color_mode
= mode
;
916 info
.rotation_type
= ofbi
->rotation_type
;
917 info
.rotation
= rotation
;
918 info
.mirror
= mirror
;
922 info
.out_width
= outw
;
923 info
.out_height
= outh
;
925 r
= ovl
->set_overlay_info(ovl
, &info
);
927 DBG("ovl->setup_overlay_info failed\n");
934 DBG("setup_overlay failed\n");
938 /* apply var to the overlay */
939 int omapfb_apply_changes(struct fb_info
*fbi
, int init
)
942 struct omapfb_info
*ofbi
= FB2OFB(fbi
);
943 struct fb_var_screeninfo
*var
= &fbi
->var
;
944 struct omap_overlay
*ovl
;
950 if (omapfb_test_pattern
)
954 for (i
= 0; i
< ofbi
->num_overlays
; i
++) {
955 ovl
= ofbi
->overlays
[i
];
957 DBG("apply_changes, fb %d, ovl %d\n", ofbi
->id
, ovl
->id
);
959 if (ofbi
->region
.size
== 0) {
960 /* the fb is not available. disable the overlay */
961 omapfb_overlay_enable(ovl
, 0);
962 if (!init
&& ovl
->manager
)
963 ovl
->manager
->apply(ovl
->manager
);
967 if (init
|| (ovl
->caps
& OMAP_DSS_OVL_CAP_SCALE
) == 0) {
968 int rotation
= (var
->rotate
+ ofbi
->rotation
[i
]) % 4;
969 if (rotation
== FB_ROTATE_CW
||
970 rotation
== FB_ROTATE_CCW
) {
978 outw
= ovl
->info
.out_width
;
979 outh
= ovl
->info
.out_height
;
986 posx
= ovl
->info
.pos_x
;
987 posy
= ovl
->info
.pos_y
;
990 r
= omapfb_setup_overlay(fbi
, ovl
, posx
, posy
, outw
, outh
);
994 if (!init
&& ovl
->manager
)
995 ovl
->manager
->apply(ovl
->manager
);
999 DBG("apply_changes failed\n");
1003 /* checks var and eventually tweaks it to something supported,
1004 * DO NOT MODIFY PAR */
1005 static int omapfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*fbi
)
1009 DBG("check_var(%d)\n", FB2OFB(fbi
)->id
);
1011 r
= check_fb_var(fbi
, var
);
1016 /* set the video mode according to info->var */
1017 static int omapfb_set_par(struct fb_info
*fbi
)
1021 DBG("set_par(%d)\n", FB2OFB(fbi
)->id
);
1025 r
= setup_vrfb_rotation(fbi
);
1029 r
= omapfb_apply_changes(fbi
, 0);
1034 static int omapfb_pan_display(struct fb_var_screeninfo
*var
,
1035 struct fb_info
*fbi
)
1037 struct fb_var_screeninfo new_var
;
1040 DBG("pan_display(%d)\n", FB2OFB(fbi
)->id
);
1042 if (var
->xoffset
== fbi
->var
.xoffset
&&
1043 var
->yoffset
== fbi
->var
.yoffset
)
1047 new_var
.xoffset
= var
->xoffset
;
1048 new_var
.yoffset
= var
->yoffset
;
1052 r
= omapfb_apply_changes(fbi
, 0);
1057 static void mmap_user_open(struct vm_area_struct
*vma
)
1059 struct omapfb_info
*ofbi
= (struct omapfb_info
*)vma
->vm_private_data
;
1061 atomic_inc(&ofbi
->map_count
);
1064 static void mmap_user_close(struct vm_area_struct
*vma
)
1066 struct omapfb_info
*ofbi
= (struct omapfb_info
*)vma
->vm_private_data
;
1068 atomic_dec(&ofbi
->map_count
);
1071 static struct vm_operations_struct mmap_user_ops
= {
1072 .open
= mmap_user_open
,
1073 .close
= mmap_user_close
,
1076 static int omapfb_mmap(struct fb_info
*fbi
, struct vm_area_struct
*vma
)
1078 struct omapfb_info
*ofbi
= FB2OFB(fbi
);
1079 struct fb_fix_screeninfo
*fix
= &fbi
->fix
;
1081 unsigned long start
;
1084 if (vma
->vm_end
- vma
->vm_start
== 0)
1086 if (vma
->vm_pgoff
> (~0UL >> PAGE_SHIFT
))
1088 off
= vma
->vm_pgoff
<< PAGE_SHIFT
;
1090 start
= omapfb_get_region_paddr(ofbi
);
1091 len
= fix
->smem_len
;
1094 if ((vma
->vm_end
- vma
->vm_start
+ off
) > len
)
1099 DBG("user mmap region start %lx, len %d, off %lx\n", start
, len
, off
);
1101 vma
->vm_pgoff
= off
>> PAGE_SHIFT
;
1102 vma
->vm_flags
|= VM_IO
| VM_RESERVED
;
1103 vma
->vm_page_prot
= pgprot_writecombine(vma
->vm_page_prot
);
1104 vma
->vm_ops
= &mmap_user_ops
;
1105 vma
->vm_private_data
= ofbi
;
1106 if (io_remap_pfn_range(vma
, vma
->vm_start
, off
>> PAGE_SHIFT
,
1107 vma
->vm_end
- vma
->vm_start
, vma
->vm_page_prot
))
1109 /* vm_ops.open won't be called for mmap itself. */
1110 atomic_inc(&ofbi
->map_count
);
1114 /* Store a single color palette entry into a pseudo palette or the hardware
1115 * palette if one is available. For now we support only 16bpp and thus store
1116 * the entry only to the pseudo palette.
1118 static int _setcolreg(struct fb_info
*fbi
, u_int regno
, u_int red
, u_int green
,
1119 u_int blue
, u_int transp
, int update_hw_pal
)
1121 /*struct omapfb_info *ofbi = FB2OFB(fbi);*/
1122 /*struct omapfb2_device *fbdev = ofbi->fbdev;*/
1123 struct fb_var_screeninfo
*var
= &fbi
->var
;
1126 enum omapfb_color_format mode
= OMAPFB_COLOR_RGB24U
; /* XXX */
1128 /*switch (plane->color_mode) {*/
1130 case OMAPFB_COLOR_YUV422
:
1131 case OMAPFB_COLOR_YUV420
:
1132 case OMAPFB_COLOR_YUY422
:
1135 case OMAPFB_COLOR_CLUT_8BPP
:
1136 case OMAPFB_COLOR_CLUT_4BPP
:
1137 case OMAPFB_COLOR_CLUT_2BPP
:
1138 case OMAPFB_COLOR_CLUT_1BPP
:
1140 if (fbdev->ctrl->setcolreg)
1141 r = fbdev->ctrl->setcolreg(regno, red, green, blue,
1142 transp, update_hw_pal);
1147 case OMAPFB_COLOR_RGB565
:
1148 case OMAPFB_COLOR_RGB444
:
1149 case OMAPFB_COLOR_RGB24P
:
1150 case OMAPFB_COLOR_RGB24U
:
1161 pal
= ((red
>> (16 - var
->red
.length
)) <<
1163 ((green
>> (16 - var
->green
.length
)) <<
1164 var
->green
.offset
) |
1165 (blue
>> (16 - var
->blue
.length
));
1166 ((u32
*)(fbi
->pseudo_palette
))[regno
] = pal
;
1175 static int omapfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
1176 u_int transp
, struct fb_info
*info
)
1180 return _setcolreg(info
, regno
, red
, green
, blue
, transp
, 1);
1183 static int omapfb_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
1185 int count
, index
, r
;
1186 u16
*red
, *green
, *blue
, *transp
;
1192 green
= cmap
->green
;
1194 transp
= cmap
->transp
;
1195 index
= cmap
->start
;
1197 for (count
= 0; count
< cmap
->len
; count
++) {
1200 r
= _setcolreg(info
, index
++, *red
++, *green
++, *blue
++, trans
,
1201 count
== cmap
->len
- 1);
1209 static int omapfb_blank(int blank
, struct fb_info
*fbi
)
1211 struct omapfb_info
*ofbi
= FB2OFB(fbi
);
1212 struct omapfb2_device
*fbdev
= ofbi
->fbdev
;
1213 struct omap_dss_device
*display
= fb2display(fbi
);
1220 case FB_BLANK_UNBLANK
:
1221 if (display
->state
!= OMAP_DSS_DISPLAY_SUSPENDED
)
1224 if (display
->resume
)
1225 r
= display
->resume(display
);
1227 if (r
== 0 && display
->get_update_mode
&&
1228 display
->get_update_mode(display
) ==
1229 OMAP_DSS_UPDATE_MANUAL
)
1234 case FB_BLANK_NORMAL
:
1235 /* FB_BLANK_NORMAL could be implemented.
1236 * Needs DSS additions. */
1237 case FB_BLANK_VSYNC_SUSPEND
:
1238 case FB_BLANK_HSYNC_SUSPEND
:
1239 case FB_BLANK_POWERDOWN
:
1240 if (display
->state
!= OMAP_DSS_DISPLAY_ACTIVE
)
1243 if (display
->suspend
)
1244 r
= display
->suspend(display
);
1253 omapfb_unlock(fbdev
);
1255 if (r
== 0 && do_update
&& display
->update
) {
1257 display
->get_resolution(display
, &w
, &h
);
1259 r
= display
->update(display
, 0, 0, w
, h
);
1266 /* XXX fb_read and fb_write are needed for VRFB */
1267 ssize_t
omapfb_write(struct fb_info
*info
, const char __user
*buf
,
1268 size_t count
, loff_t
*ppos
)
1270 DBG("omapfb_write %d, %lu\n", count
, (unsigned long)*ppos
);
1271 /* XXX needed for VRFB */
1276 static struct fb_ops omapfb_ops
= {
1277 .owner
= THIS_MODULE
,
1278 .fb_open
= omapfb_open
,
1279 .fb_release
= omapfb_release
,
1280 .fb_fillrect
= cfb_fillrect
,
1281 .fb_copyarea
= cfb_copyarea
,
1282 .fb_imageblit
= cfb_imageblit
,
1283 .fb_blank
= omapfb_blank
,
1284 .fb_ioctl
= omapfb_ioctl
,
1285 .fb_check_var
= omapfb_check_var
,
1286 .fb_set_par
= omapfb_set_par
,
1287 .fb_pan_display
= omapfb_pan_display
,
1288 .fb_mmap
= omapfb_mmap
,
1289 .fb_setcolreg
= omapfb_setcolreg
,
1290 .fb_setcmap
= omapfb_setcmap
,
1291 /*.fb_write = omapfb_write,*/
1294 static void omapfb_free_fbmem(struct fb_info
*fbi
)
1296 struct omapfb_info
*ofbi
= FB2OFB(fbi
);
1297 struct omapfb2_device
*fbdev
= ofbi
->fbdev
;
1298 struct omapfb2_mem_region
*rg
;
1303 if (omap_vram_free(rg
->paddr
, rg
->size
))
1304 dev_err(fbdev
->dev
, "VRAM FREE failed\n");
1309 if (ofbi
->rotation_type
== OMAP_DSS_ROT_VRFB
) {
1310 /* unmap the 0 angle rotation */
1311 if (rg
->vrfb
.vaddr
[0]) {
1312 iounmap(rg
->vrfb
.vaddr
[0]);
1313 omap_vrfb_release_ctx(&rg
->vrfb
);
1314 rg
->vrfb
.vaddr
[0] = NULL
;
1324 static void clear_fb_info(struct fb_info
*fbi
)
1326 memset(&fbi
->var
, 0, sizeof(fbi
->var
));
1327 memset(&fbi
->fix
, 0, sizeof(fbi
->fix
));
1328 strlcpy(fbi
->fix
.id
, MODULE_NAME
, sizeof(fbi
->fix
.id
));
1331 static int omapfb_free_all_fbmem(struct omapfb2_device
*fbdev
)
1335 DBG("free all fbmem\n");
1337 for (i
= 0; i
< fbdev
->num_fbs
; i
++) {
1338 struct fb_info
*fbi
= fbdev
->fbs
[i
];
1339 omapfb_free_fbmem(fbi
);
1346 static int omapfb_alloc_fbmem(struct fb_info
*fbi
, unsigned long size
,
1347 unsigned long paddr
)
1349 struct omapfb_info
*ofbi
= FB2OFB(fbi
);
1350 struct omapfb2_device
*fbdev
= ofbi
->fbdev
;
1351 struct omapfb2_mem_region
*rg
;
1352 void __iomem
*vaddr
;
1356 memset(rg
, 0, sizeof(*rg
));
1358 size
= PAGE_ALIGN(size
);
1361 DBG("allocating %lu bytes for fb %d\n", size
, ofbi
->id
);
1362 r
= omap_vram_alloc(OMAP_VRAM_MEMTYPE_SDRAM
, size
, &paddr
);
1364 DBG("reserving %lu bytes at %lx for fb %d\n", size
, paddr
,
1366 r
= omap_vram_reserve(paddr
, size
);
1370 dev_err(fbdev
->dev
, "failed to allocate framebuffer\n");
1374 if (ofbi
->rotation_type
!= OMAP_DSS_ROT_VRFB
) {
1375 vaddr
= ioremap_wc(paddr
, size
);
1378 dev_err(fbdev
->dev
, "failed to ioremap framebuffer\n");
1379 omap_vram_free(paddr
, size
);
1383 DBG("allocated VRAM paddr %lx, vaddr %p\n", paddr
, vaddr
);
1385 r
= omap_vrfb_request_ctx(&rg
->vrfb
);
1387 dev_err(fbdev
->dev
, "vrfb create ctx failed\n");
1402 /* allocate fbmem using display resolution as reference */
1403 static int omapfb_alloc_fbmem_display(struct fb_info
*fbi
, unsigned long size
,
1404 unsigned long paddr
)
1406 struct omapfb_info
*ofbi
= FB2OFB(fbi
);
1407 struct omap_dss_device
*display
;
1410 display
= fb2display(fbi
);
1415 switch (display
->get_recommended_bpp(display
)) {
1430 display
->get_resolution(display
, &w
, &h
);
1432 if (ofbi
->rotation_type
== OMAP_DSS_ROT_VRFB
) {
1433 size
= max(omap_vrfb_min_phys_size(w
, h
, bytespp
),
1434 omap_vrfb_min_phys_size(h
, w
, bytespp
));
1436 DBG("adjusting fb mem size for VRFB, %u -> %lu\n",
1437 w
* h
* bytespp
, size
);
1439 size
= w
* h
* bytespp
;
1446 return omapfb_alloc_fbmem(fbi
, size
, paddr
);
1449 static enum omap_color_mode
fb_format_to_dss_mode(enum omapfb_color_format fmt
)
1451 enum omap_color_mode mode
;
1454 case OMAPFB_COLOR_RGB565
:
1455 mode
= OMAP_DSS_COLOR_RGB16
;
1457 case OMAPFB_COLOR_YUV422
:
1458 mode
= OMAP_DSS_COLOR_YUV2
;
1460 case OMAPFB_COLOR_CLUT_8BPP
:
1461 mode
= OMAP_DSS_COLOR_CLUT8
;
1463 case OMAPFB_COLOR_CLUT_4BPP
:
1464 mode
= OMAP_DSS_COLOR_CLUT4
;
1466 case OMAPFB_COLOR_CLUT_2BPP
:
1467 mode
= OMAP_DSS_COLOR_CLUT2
;
1469 case OMAPFB_COLOR_CLUT_1BPP
:
1470 mode
= OMAP_DSS_COLOR_CLUT1
;
1472 case OMAPFB_COLOR_RGB444
:
1473 mode
= OMAP_DSS_COLOR_RGB12U
;
1475 case OMAPFB_COLOR_YUY422
:
1476 mode
= OMAP_DSS_COLOR_UYVY
;
1478 case OMAPFB_COLOR_ARGB16
:
1479 mode
= OMAP_DSS_COLOR_ARGB16
;
1481 case OMAPFB_COLOR_RGB24U
:
1482 mode
= OMAP_DSS_COLOR_RGB24U
;
1484 case OMAPFB_COLOR_RGB24P
:
1485 mode
= OMAP_DSS_COLOR_RGB24P
;
1487 case OMAPFB_COLOR_ARGB32
:
1488 mode
= OMAP_DSS_COLOR_ARGB32
;
1490 case OMAPFB_COLOR_RGBA32
:
1491 mode
= OMAP_DSS_COLOR_RGBA32
;
1493 case OMAPFB_COLOR_RGBX32
:
1494 mode
= OMAP_DSS_COLOR_RGBX32
;
1503 static int omapfb_parse_vram_param(const char *param
, int max_entries
,
1504 unsigned long *sizes
, unsigned long *paddrs
)
1508 unsigned long paddr
= 0;
1511 start
= (char *)param
;
1516 fbnum
= simple_strtoul(p
, &p
, 10);
1524 if (fbnum
>= max_entries
)
1527 size
= memparse(p
+ 1, &p
);
1535 paddr
= simple_strtoul(p
+ 1, &p
, 16);
1542 paddrs
[fbnum
] = paddr
;
1543 sizes
[fbnum
] = size
;
1559 static int omapfb_allocate_all_fbs(struct omapfb2_device
*fbdev
)
1562 unsigned long vram_sizes
[10];
1563 unsigned long vram_paddrs
[10];
1565 memset(&vram_sizes
, 0, sizeof(vram_sizes
));
1566 memset(&vram_paddrs
, 0, sizeof(vram_paddrs
));
1568 if (def_vram
&& omapfb_parse_vram_param(def_vram
, 10,
1569 vram_sizes
, vram_paddrs
)) {
1570 dev_err(fbdev
->dev
, "failed to parse vram parameter\n");
1572 memset(&vram_sizes
, 0, sizeof(vram_sizes
));
1573 memset(&vram_paddrs
, 0, sizeof(vram_paddrs
));
1576 if (fbdev
->dev
->platform_data
) {
1577 struct omapfb_platform_data
*opd
;
1578 opd
= fbdev
->dev
->platform_data
;
1579 for (i
= 0; i
< opd
->mem_desc
.region_cnt
; ++i
) {
1580 if (!vram_sizes
[i
]) {
1582 unsigned long paddr
;
1584 size
= opd
->mem_desc
.region
[i
].size
;
1585 paddr
= opd
->mem_desc
.region
[i
].paddr
;
1587 vram_sizes
[i
] = size
;
1588 vram_paddrs
[i
] = paddr
;
1593 for (i
= 0; i
< fbdev
->num_fbs
; i
++) {
1594 /* allocate memory automatically only for fb0, or if
1595 * excplicitly defined with vram or plat data option */
1596 if (i
== 0 || vram_sizes
[i
] != 0) {
1597 r
= omapfb_alloc_fbmem_display(fbdev
->fbs
[i
],
1598 vram_sizes
[i
], vram_paddrs
[i
]);
1605 for (i
= 0; i
< fbdev
->num_fbs
; i
++) {
1606 struct omapfb_info
*ofbi
= FB2OFB(fbdev
->fbs
[i
]);
1607 struct omapfb2_mem_region
*rg
;
1610 DBG("region%d phys %08x virt %p size=%lu\n",
1620 int omapfb_realloc_fbmem(struct fb_info
*fbi
, unsigned long size
, int type
)
1622 struct omapfb_info
*ofbi
= FB2OFB(fbi
);
1623 struct omapfb2_device
*fbdev
= ofbi
->fbdev
;
1624 struct omap_dss_device
*display
= fb2display(fbi
);
1625 struct omapfb2_mem_region
*rg
= &ofbi
->region
;
1626 unsigned long old_size
= rg
->size
;
1627 unsigned long old_paddr
= rg
->paddr
;
1628 int old_type
= rg
->type
;
1631 if (type
> OMAPFB_MEMTYPE_MAX
)
1634 size
= PAGE_ALIGN(size
);
1636 if (old_size
== size
&& old_type
== type
)
1639 if (display
&& display
->sync
)
1640 display
->sync(display
);
1642 omapfb_free_fbmem(fbi
);
1649 r
= omapfb_alloc_fbmem(fbi
, size
, 0);
1653 omapfb_alloc_fbmem(fbi
, old_size
, old_paddr
);
1661 if (old_size
== size
)
1664 if (old_size
== 0) {
1665 DBG("initializing fb %d\n", ofbi
->id
);
1666 r
= omapfb_fb_init(fbdev
, fbi
);
1668 DBG("omapfb_fb_init failed\n");
1671 r
= omapfb_apply_changes(fbi
, 1);
1673 DBG("omapfb_apply_changes failed\n");
1677 struct fb_var_screeninfo new_var
;
1678 memcpy(&new_var
, &fbi
->var
, sizeof(new_var
));
1679 r
= check_fb_var(fbi
, &new_var
);
1682 memcpy(&fbi
->var
, &new_var
, sizeof(fbi
->var
));
1684 r
= setup_vrfb_rotation(fbi
);
1691 omapfb_free_fbmem(fbi
);
1696 /* initialize fb_info, var, fix to something sane based on the display */
1697 static int omapfb_fb_init(struct omapfb2_device
*fbdev
, struct fb_info
*fbi
)
1699 struct fb_var_screeninfo
*var
= &fbi
->var
;
1700 struct omap_dss_device
*display
= fb2display(fbi
);
1701 struct omapfb_info
*ofbi
= FB2OFB(fbi
);
1704 fbi
->fbops
= &omapfb_ops
;
1705 fbi
->flags
= FBINFO_FLAG_DEFAULT
;
1706 fbi
->pseudo_palette
= fbdev
->pseudo_palette
;
1708 if (ofbi
->region
.size
== 0) {
1714 var
->bits_per_pixel
= 0;
1716 var
->rotate
= def_rotate
;
1719 * Check if there is a default color format set in the board file,
1720 * and use this format instead the default deducted from the
1723 if (fbdev
->dev
->platform_data
) {
1724 struct omapfb_platform_data
*opd
;
1727 opd
= fbdev
->dev
->platform_data
;
1728 if (opd
->mem_desc
.region
[id
].format_used
) {
1729 enum omap_color_mode mode
;
1730 enum omapfb_color_format format
;
1732 format
= opd
->mem_desc
.region
[id
].format
;
1733 mode
= fb_format_to_dss_mode(format
);
1738 r
= dss_mode_to_fb_mode(mode
, var
);
1746 int rotation
= (var
->rotate
+ ofbi
->rotation
[0]) % 4;
1748 display
->get_resolution(display
, &w
, &h
);
1750 if (rotation
== FB_ROTATE_CW
||
1751 rotation
== FB_ROTATE_CCW
) {
1759 var
->xres_virtual
= var
->xres
;
1760 var
->yres_virtual
= var
->yres
;
1762 if (!var
->bits_per_pixel
) {
1763 switch (display
->get_recommended_bpp(display
)) {
1765 var
->bits_per_pixel
= 16;
1768 var
->bits_per_pixel
= 32;
1771 dev_err(fbdev
->dev
, "illegal display "
1777 /* if there's no display, let's just guess some basic values */
1780 var
->xres_virtual
= var
->xres
;
1781 var
->yres_virtual
= var
->yres
;
1782 if (!var
->bits_per_pixel
)
1783 var
->bits_per_pixel
= 16;
1786 r
= check_fb_var(fbi
, var
);
1791 r
= setup_vrfb_rotation(fbi
);
1795 r
= fb_alloc_cmap(&fbi
->cmap
, 256, 0);
1797 dev_err(fbdev
->dev
, "unable to allocate color map memory\n");
1803 static void fbinfo_cleanup(struct omapfb2_device
*fbdev
, struct fb_info
*fbi
)
1805 fb_dealloc_cmap(&fbi
->cmap
);
1809 static void omapfb_free_resources(struct omapfb2_device
*fbdev
)
1813 DBG("free_resources\n");
1818 for (i
= 0; i
< fbdev
->num_fbs
; i
++)
1819 unregister_framebuffer(fbdev
->fbs
[i
]);
1821 /* free the reserved fbmem */
1822 omapfb_free_all_fbmem(fbdev
);
1824 for (i
= 0; i
< fbdev
->num_fbs
; i
++) {
1825 fbinfo_cleanup(fbdev
, fbdev
->fbs
[i
]);
1826 framebuffer_release(fbdev
->fbs
[i
]);
1829 for (i
= 0; i
< fbdev
->num_displays
; i
++) {
1830 if (fbdev
->displays
[i
]->state
!= OMAP_DSS_DISPLAY_DISABLED
)
1831 fbdev
->displays
[i
]->disable(fbdev
->displays
[i
]);
1833 omap_dss_put_device(fbdev
->displays
[i
]);
1836 dev_set_drvdata(fbdev
->dev
, NULL
);
1840 static int omapfb_create_framebuffers(struct omapfb2_device
*fbdev
)
1846 DBG("create %d framebuffers\n", CONFIG_FB_OMAP2_NUM_FBS
);
1848 /* allocate fb_infos */
1849 for (i
= 0; i
< CONFIG_FB_OMAP2_NUM_FBS
; i
++) {
1850 struct fb_info
*fbi
;
1851 struct omapfb_info
*ofbi
;
1853 fbi
= framebuffer_alloc(sizeof(struct omapfb_info
),
1858 "unable to allocate memory for plane info\n");
1864 fbdev
->fbs
[i
] = fbi
;
1867 ofbi
->fbdev
= fbdev
;
1870 /* assign these early, so that fb alloc can use them */
1871 ofbi
->rotation_type
= def_vrfb
? OMAP_DSS_ROT_VRFB
:
1873 ofbi
->mirror
= def_mirror
;
1878 DBG("fb_infos allocated\n");
1880 /* assign overlays for the fbs */
1881 for (i
= 0; i
< min(fbdev
->num_fbs
, fbdev
->num_overlays
); i
++) {
1882 struct omapfb_info
*ofbi
= FB2OFB(fbdev
->fbs
[i
]);
1884 ofbi
->overlays
[0] = fbdev
->overlays
[i
];
1885 ofbi
->num_overlays
= 1;
1888 /* allocate fb memories */
1889 r
= omapfb_allocate_all_fbs(fbdev
);
1891 dev_err(fbdev
->dev
, "failed to allocate fbmem\n");
1895 DBG("fbmems allocated\n");
1897 /* setup fb_infos */
1898 for (i
= 0; i
< fbdev
->num_fbs
; i
++) {
1899 r
= omapfb_fb_init(fbdev
, fbdev
->fbs
[i
]);
1901 dev_err(fbdev
->dev
, "failed to setup fb_info\n");
1906 DBG("fb_infos initialized\n");
1908 for (i
= 0; i
< fbdev
->num_fbs
; i
++) {
1909 r
= register_framebuffer(fbdev
->fbs
[i
]);
1912 "registering framebuffer %d failed\n", i
);
1917 DBG("framebuffers registered\n");
1919 for (i
= 0; i
< fbdev
->num_fbs
; i
++) {
1920 r
= omapfb_apply_changes(fbdev
->fbs
[i
], 1);
1922 dev_err(fbdev
->dev
, "failed to change mode\n");
1927 DBG("create sysfs for fbs\n");
1928 r
= omapfb_create_sysfs(fbdev
);
1930 dev_err(fbdev
->dev
, "failed to create sysfs entries\n");
1935 if (fbdev
->num_fbs
> 0) {
1936 struct omapfb_info
*ofbi
= FB2OFB(fbdev
->fbs
[0]);
1938 if (ofbi
->num_overlays
> 0) {
1939 struct omap_overlay
*ovl
= ofbi
->overlays
[0];
1941 r
= omapfb_overlay_enable(ovl
, 1);
1945 "failed to enable overlay\n");
1951 DBG("create_framebuffers done\n");
1956 static int omapfb_mode_to_timings(const char *mode_str
,
1957 struct omap_video_timings
*timings
, u8
*bpp
)
1960 struct fb_var_screeninfo var
;
1961 struct fb_ops fbops
;
1964 #ifdef CONFIG_OMAP2_DSS_VENC
1965 if (strcmp(mode_str
, "pal") == 0) {
1966 *timings
= omap_dss_pal_timings
;
1969 } else if (strcmp(mode_str
, "ntsc") == 0) {
1970 *timings
= omap_dss_ntsc_timings
;
1976 /* this is quite a hack, but I wanted to use the modedb and for
1977 * that we need fb_info and var, so we create dummy ones */
1979 memset(&fbi
, 0, sizeof(fbi
));
1980 memset(&var
, 0, sizeof(var
));
1981 memset(&fbops
, 0, sizeof(fbops
));
1984 r
= fb_find_mode(&var
, &fbi
, mode_str
, NULL
, 0, NULL
, 24);
1987 timings
->pixel_clock
= PICOS2KHZ(var
.pixclock
);
1988 timings
->hfp
= var
.left_margin
;
1989 timings
->hbp
= var
.right_margin
;
1990 timings
->vfp
= var
.upper_margin
;
1991 timings
->vbp
= var
.lower_margin
;
1992 timings
->hsw
= var
.hsync_len
;
1993 timings
->vsw
= var
.vsync_len
;
1994 timings
->x_res
= var
.xres
;
1995 timings
->y_res
= var
.yres
;
1997 switch (var
.bits_per_pixel
) {
2014 static int omapfb_set_def_mode(struct omap_dss_device
*display
, char *mode_str
)
2018 struct omap_video_timings timings
;
2020 r
= omapfb_mode_to_timings(mode_str
, &timings
, &bpp
);
2024 display
->panel
.recommended_bpp
= bpp
;
2026 if (!display
->check_timings
|| !display
->set_timings
)
2029 r
= display
->check_timings(display
, &timings
);
2033 display
->set_timings(display
, &timings
);
2038 static int omapfb_parse_def_modes(struct omapfb2_device
*fbdev
)
2040 char *str
, *options
, *this_opt
;
2043 str
= kmalloc(strlen(def_mode
) + 1, GFP_KERNEL
);
2044 strcpy(str
, def_mode
);
2047 while (!r
&& (this_opt
= strsep(&options
, ",")) != NULL
) {
2048 char *p
, *display_str
, *mode_str
;
2049 struct omap_dss_device
*display
;
2052 p
= strchr(this_opt
, ':');
2059 display_str
= this_opt
;
2063 for (i
= 0; i
< fbdev
->num_displays
; ++i
) {
2064 if (strcmp(fbdev
->displays
[i
]->name
,
2065 display_str
) == 0) {
2066 display
= fbdev
->displays
[i
];
2076 r
= omapfb_set_def_mode(display
, mode_str
);
2086 static int omapfb_probe(struct platform_device
*pdev
)
2088 struct omapfb2_device
*fbdev
= NULL
;
2091 struct omap_overlay
*ovl
;
2092 struct omap_dss_device
*def_display
;
2093 struct omap_dss_device
*dssdev
;
2095 DBG("omapfb_probe\n");
2097 if (pdev
->num_resources
!= 0) {
2098 dev_err(&pdev
->dev
, "probed for an unknown device\n");
2103 fbdev
= kzalloc(sizeof(struct omapfb2_device
), GFP_KERNEL
);
2104 if (fbdev
== NULL
) {
2109 mutex_init(&fbdev
->mtx
);
2111 fbdev
->dev
= &pdev
->dev
;
2112 platform_set_drvdata(pdev
, fbdev
);
2114 fbdev
->num_displays
= 0;
2116 for_each_dss_dev(dssdev
) {
2117 omap_dss_get_device(dssdev
);
2118 if (!dssdev
->driver
) {
2119 dev_err(&pdev
->dev
, "no driver for display\n");
2123 fbdev
->displays
[fbdev
->num_displays
++] = dssdev
;
2126 if (fbdev
->num_displays
== 0) {
2127 dev_err(&pdev
->dev
, "no displays\n");
2132 fbdev
->num_overlays
= omap_dss_get_num_overlays();
2133 for (i
= 0; i
< fbdev
->num_overlays
; i
++)
2134 fbdev
->overlays
[i
] = omap_dss_get_overlay(i
);
2136 fbdev
->num_managers
= omap_dss_get_num_overlay_managers();
2137 for (i
= 0; i
< fbdev
->num_managers
; i
++)
2138 fbdev
->managers
[i
] = omap_dss_get_overlay_manager(i
);
2140 if (def_mode
&& strlen(def_mode
) > 0) {
2141 if (omapfb_parse_def_modes(fbdev
))
2142 dev_warn(&pdev
->dev
, "cannot parse default modes\n");
2145 r
= omapfb_create_framebuffers(fbdev
);
2149 for (i
= 0; i
< fbdev
->num_managers
; i
++) {
2150 struct omap_overlay_manager
*mgr
;
2151 mgr
= fbdev
->managers
[i
];
2152 r
= mgr
->apply(mgr
);
2154 dev_warn(fbdev
->dev
, "failed to apply dispc config\n");
2157 DBG("mgr->apply'ed\n");
2159 /* gfx overlay should be the default one. find a display
2160 * connected to that, and use it as default display */
2161 ovl
= omap_dss_get_overlay(0);
2162 if (ovl
->manager
&& ovl
->manager
->device
) {
2163 def_display
= ovl
->manager
->device
;
2165 dev_warn(&pdev
->dev
, "cannot find default display\n");
2170 #ifndef CONFIG_FB_OMAP2_FORCE_AUTO_UPDATE
2173 r
= def_display
->enable(def_display
);
2175 dev_warn(fbdev
->dev
, "Failed to enable display '%s'\n",
2178 /* set the update mode */
2179 if (def_display
->caps
& OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
) {
2180 #ifdef CONFIG_FB_OMAP2_FORCE_AUTO_UPDATE
2181 if (def_display
->enable_te
)
2182 def_display
->enable_te(def_display
, 1);
2183 if (def_display
->set_update_mode
)
2184 def_display
->set_update_mode(def_display
,
2185 OMAP_DSS_UPDATE_AUTO
);
2186 #else /* MANUAL_UPDATE */
2187 if (def_display
->enable_te
)
2188 def_display
->enable_te(def_display
, 0);
2189 if (def_display
->set_update_mode
)
2190 def_display
->set_update_mode(def_display
,
2191 OMAP_DSS_UPDATE_MANUAL
);
2193 def_display
->get_resolution(def_display
, &w
, &h
);
2194 def_display
->update(def_display
, 0, 0, w
, h
);
2197 if (def_display
->set_update_mode
)
2198 def_display
->set_update_mode(def_display
,
2199 OMAP_DSS_UPDATE_AUTO
);
2206 omapfb_free_resources(fbdev
);
2208 dev_err(&pdev
->dev
, "failed to setup omapfb\n");
2212 static int omapfb_remove(struct platform_device
*pdev
)
2214 struct omapfb2_device
*fbdev
= platform_get_drvdata(pdev
);
2216 /* FIXME: wait till completion of pending events */
2218 omapfb_remove_sysfs(fbdev
);
2220 omapfb_free_resources(fbdev
);
2225 static struct platform_driver omapfb_driver
= {
2226 .probe
= omapfb_probe
,
2227 .remove
= omapfb_remove
,
2230 .owner
= THIS_MODULE
,
2234 static int __init
omapfb_init(void)
2236 DBG("omapfb_init\n");
2238 if (platform_driver_register(&omapfb_driver
)) {
2239 printk(KERN_ERR
"failed to register omapfb driver\n");
2246 static void __exit
omapfb_exit(void)
2248 DBG("omapfb_exit\n");
2249 platform_driver_unregister(&omapfb_driver
);
2252 module_param_named(mode
, def_mode
, charp
, 0);
2253 module_param_named(vram
, def_vram
, charp
, 0);
2254 module_param_named(rotate
, def_rotate
, int, 0);
2255 module_param_named(vrfb
, def_vrfb
, bool, 0);
2256 module_param_named(mirror
, def_mirror
, bool, 0);
2258 /* late_initcall to let panel/ctrl drivers loaded first.
2259 * I guess better option would be a more dynamic approach,
2260 * so that omapfb reacts to new panels when they are loaded */
2261 late_initcall(omapfb_init
);
2262 /*module_init(omapfb_init);*/
2263 module_exit(omapfb_exit
);
2265 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
2266 MODULE_DESCRIPTION("OMAP2/3 Framebuffer");
2267 MODULE_LICENSE("GPL v2");