2 * Copyright (C) 2007-2010 Texas Instruments Inc
3 * Copyright (C) 2007 MontaVista Software, Inc.
5 * Andy Lowe (alowe@mvista.com), MontaVista Software
7 * Murali Karicheri (mkaricheri@gmail.com), Texas Instruments Ltd.
8 * - ported to sub device interface
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation version 2.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/interrupt.h>
27 #include <linux/platform_device.h>
28 #include <linux/clk.h>
29 #include <linux/slab.h>
32 #include <mach/cputype.h>
33 #include <mach/hardware.h>
35 #include <media/davinci/vpss.h>
36 #include <media/v4l2-device.h>
37 #include <media/davinci/vpbe_types.h>
38 #include <media/davinci/vpbe_osd.h>
41 #include "vpbe_osd_regs.h"
43 #define MODULE_NAME VPBE_OSD_SUBDEV_NAME
45 /* register access routines */
46 static inline u32
osd_read(struct osd_state
*sd
, u32 offset
)
48 struct osd_state
*osd
= sd
;
50 return readl(osd
->osd_base
+ offset
);
53 static inline u32
osd_write(struct osd_state
*sd
, u32 val
, u32 offset
)
55 struct osd_state
*osd
= sd
;
57 writel(val
, osd
->osd_base
+ offset
);
62 static inline u32
osd_set(struct osd_state
*sd
, u32 mask
, u32 offset
)
64 struct osd_state
*osd
= sd
;
66 u32 addr
= osd
->osd_base
+ offset
;
67 u32 val
= readl(addr
) | mask
;
74 static inline u32
osd_clear(struct osd_state
*sd
, u32 mask
, u32 offset
)
76 struct osd_state
*osd
= sd
;
78 u32 addr
= osd
->osd_base
+ offset
;
79 u32 val
= readl(addr
) & ~mask
;
86 static inline u32
osd_modify(struct osd_state
*sd
, u32 mask
, u32 val
,
89 struct osd_state
*osd
= sd
;
91 u32 addr
= osd
->osd_base
+ offset
;
92 u32 new_val
= (readl(addr
) & ~mask
) | (val
& mask
);
94 writel(new_val
, addr
);
99 /* define some macros for layer and pixfmt classification */
100 #define is_osd_win(layer) (((layer) == WIN_OSD0) || ((layer) == WIN_OSD1))
101 #define is_vid_win(layer) (((layer) == WIN_VID0) || ((layer) == WIN_VID1))
102 #define is_rgb_pixfmt(pixfmt) \
103 (((pixfmt) == PIXFMT_RGB565) || ((pixfmt) == PIXFMT_RGB888))
104 #define is_yc_pixfmt(pixfmt) \
105 (((pixfmt) == PIXFMT_YCbCrI) || ((pixfmt) == PIXFMT_YCrCbI) || \
106 ((pixfmt) == PIXFMT_NV12))
107 #define MAX_WIN_SIZE OSD_VIDWIN0XP_V0X
108 #define MAX_LINE_LENGTH (OSD_VIDWIN0OFST_V0LO << 5)
111 * _osd_dm6446_vid0_pingpong() - field inversion fix for DM6446
112 * @sd - ptr to struct osd_state
113 * @field_inversion - inversion flag
114 * @fb_base_phys - frame buffer address
115 * @lconfig - ptr to layer config
117 * This routine implements a workaround for the field signal inversion silicon
118 * erratum described in Advisory 1.3.8 for the DM6446. The fb_base_phys and
119 * lconfig parameters apply to the vid0 window. This routine should be called
120 * whenever the vid0 layer configuration or start address is modified, or when
121 * the OSD field inversion setting is modified.
122 * Returns: 1 if the ping-pong buffers need to be toggled in the vsync isr, or
125 static int _osd_dm6446_vid0_pingpong(struct osd_state
*sd
,
127 unsigned long fb_base_phys
,
128 const struct osd_layer_config
*lconfig
)
130 struct osd_platform_data
*pdata
;
132 pdata
= (struct osd_platform_data
*)sd
->dev
->platform_data
;
133 if (pdata
->field_inv_wa_enable
) {
135 if (!field_inversion
|| !lconfig
->interlaced
) {
136 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_VIDWIN0ADR
);
137 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_PPVWIN0ADR
);
138 osd_modify(sd
, OSD_MISCCTL_PPSW
| OSD_MISCCTL_PPRV
, 0,
142 unsigned miscctl
= OSD_MISCCTL_PPRV
;
145 (fb_base_phys
& ~0x1F) - lconfig
->line_length
,
148 (fb_base_phys
& ~0x1F) + lconfig
->line_length
,
151 OSD_MISCCTL_PPSW
| OSD_MISCCTL_PPRV
, miscctl
,
161 static void _osd_set_field_inversion(struct osd_state
*sd
, int enable
)
166 fsinv
= OSD_MODE_FSINV
;
168 osd_modify(sd
, OSD_MODE_FSINV
, fsinv
, OSD_MODE
);
171 static void _osd_set_blink_attribute(struct osd_state
*sd
, int enable
,
172 enum osd_blink_interval blink
)
177 osdatrmd
|= OSD_OSDATRMD_BLNK
;
178 osdatrmd
|= blink
<< OSD_OSDATRMD_BLNKINT_SHIFT
;
180 /* caller must ensure that OSD1 is configured in attribute mode */
181 osd_modify(sd
, OSD_OSDATRMD_BLNKINT
| OSD_OSDATRMD_BLNK
, osdatrmd
,
185 static void _osd_set_rom_clut(struct osd_state
*sd
,
186 enum osd_rom_clut rom_clut
)
188 if (rom_clut
== ROM_CLUT0
)
189 osd_clear(sd
, OSD_MISCCTL_RSEL
, OSD_MISCCTL
);
191 osd_set(sd
, OSD_MISCCTL_RSEL
, OSD_MISCCTL
);
194 static void _osd_set_palette_map(struct osd_state
*sd
,
195 enum osd_win_layer osdwin
,
196 unsigned char pixel_value
,
197 unsigned char clut_index
,
198 enum osd_pix_format pixfmt
)
200 static const int map_2bpp
[] = { 0, 5, 10, 15 };
201 static const int map_1bpp
[] = { 0, 15 };
209 bmp_reg
= map_1bpp
[pixel_value
& 0x1];
212 bmp_reg
= map_2bpp
[pixel_value
& 0x3];
215 bmp_reg
= pixel_value
& 0xf;
223 bmp_offset
= OSD_W0BMP01
+ (bmp_reg
>> 1) * sizeof(u32
);
226 bmp_offset
= OSD_W1BMP01
+ (bmp_reg
>> 1) * sizeof(u32
);
234 bmp_mask
= 0xff << 8;
240 osd_modify(sd
, bmp_mask
, clut_index
<< bmp_shift
, bmp_offset
);
243 static void _osd_set_rec601_attenuation(struct osd_state
*sd
,
244 enum osd_win_layer osdwin
, int enable
)
248 osd_modify(sd
, OSD_OSDWIN0MD_ATN0E
,
249 enable
? OSD_OSDWIN0MD_ATN0E
: 0,
251 if (sd
->vpbe_type
== VPBE_VERSION_1
)
252 osd_modify(sd
, OSD_OSDWIN0MD_ATN0E
,
253 enable
? OSD_OSDWIN0MD_ATN0E
: 0,
255 else if ((sd
->vpbe_type
== VPBE_VERSION_3
) ||
256 (sd
->vpbe_type
== VPBE_VERSION_2
))
257 osd_modify(sd
, OSD_EXTMODE_ATNOSD0EN
,
258 enable
? OSD_EXTMODE_ATNOSD0EN
: 0,
262 osd_modify(sd
, OSD_OSDWIN1MD_ATN1E
,
263 enable
? OSD_OSDWIN1MD_ATN1E
: 0,
265 if (sd
->vpbe_type
== VPBE_VERSION_1
)
266 osd_modify(sd
, OSD_OSDWIN1MD_ATN1E
,
267 enable
? OSD_OSDWIN1MD_ATN1E
: 0,
269 else if ((sd
->vpbe_type
== VPBE_VERSION_3
) ||
270 (sd
->vpbe_type
== VPBE_VERSION_2
))
271 osd_modify(sd
, OSD_EXTMODE_ATNOSD1EN
,
272 enable
? OSD_EXTMODE_ATNOSD1EN
: 0,
278 static void _osd_set_blending_factor(struct osd_state
*sd
,
279 enum osd_win_layer osdwin
,
280 enum osd_blending_factor blend
)
284 osd_modify(sd
, OSD_OSDWIN0MD_BLND0
,
285 blend
<< OSD_OSDWIN0MD_BLND0_SHIFT
, OSD_OSDWIN0MD
);
288 osd_modify(sd
, OSD_OSDWIN1MD_BLND1
,
289 blend
<< OSD_OSDWIN1MD_BLND1_SHIFT
, OSD_OSDWIN1MD
);
294 static void _osd_enable_rgb888_pixblend(struct osd_state
*sd
,
295 enum osd_win_layer osdwin
)
298 osd_modify(sd
, OSD_MISCCTL_BLDSEL
, 0, OSD_MISCCTL
);
301 osd_modify(sd
, OSD_EXTMODE_OSD0BLDCHR
,
302 OSD_EXTMODE_OSD0BLDCHR
, OSD_EXTMODE
);
305 osd_modify(sd
, OSD_EXTMODE_OSD1BLDCHR
,
306 OSD_EXTMODE_OSD1BLDCHR
, OSD_EXTMODE
);
311 static void _osd_enable_color_key(struct osd_state
*sd
,
312 enum osd_win_layer osdwin
,
314 enum osd_pix_format pixfmt
)
321 if (sd
->vpbe_type
== VPBE_VERSION_3
) {
324 osd_modify(sd
, OSD_TRANSPBMPIDX_BMP0
,
326 OSD_TRANSPBMPIDX_BMP0_SHIFT
,
330 osd_modify(sd
, OSD_TRANSPBMPIDX_BMP1
,
332 OSD_TRANSPBMPIDX_BMP1_SHIFT
,
339 if (sd
->vpbe_type
== VPBE_VERSION_1
)
340 osd_write(sd
, colorkey
& OSD_TRANSPVAL_RGBTRANS
,
342 else if (sd
->vpbe_type
== VPBE_VERSION_3
)
343 osd_write(sd
, colorkey
& OSD_TRANSPVALL_RGBL
,
348 if (sd
->vpbe_type
== VPBE_VERSION_3
)
349 osd_modify(sd
, OSD_TRANSPVALU_Y
, colorkey
,
353 if (sd
->vpbe_type
== VPBE_VERSION_3
) {
354 osd_write(sd
, colorkey
& OSD_TRANSPVALL_RGBL
,
356 osd_modify(sd
, OSD_TRANSPVALU_RGBU
, colorkey
>> 16,
366 osd_set(sd
, OSD_OSDWIN0MD_TE0
, OSD_OSDWIN0MD
);
369 osd_set(sd
, OSD_OSDWIN1MD_TE1
, OSD_OSDWIN1MD
);
374 static void _osd_disable_color_key(struct osd_state
*sd
,
375 enum osd_win_layer osdwin
)
379 osd_clear(sd
, OSD_OSDWIN0MD_TE0
, OSD_OSDWIN0MD
);
382 osd_clear(sd
, OSD_OSDWIN1MD_TE1
, OSD_OSDWIN1MD
);
387 static void _osd_set_osd_clut(struct osd_state
*sd
,
388 enum osd_win_layer osdwin
,
395 if (clut
== RAM_CLUT
)
396 winmd
|= OSD_OSDWIN0MD_CLUTS0
;
397 osd_modify(sd
, OSD_OSDWIN0MD_CLUTS0
, winmd
, OSD_OSDWIN0MD
);
400 if (clut
== RAM_CLUT
)
401 winmd
|= OSD_OSDWIN1MD_CLUTS1
;
402 osd_modify(sd
, OSD_OSDWIN1MD_CLUTS1
, winmd
, OSD_OSDWIN1MD
);
407 static void _osd_set_zoom(struct osd_state
*sd
, enum osd_layer layer
,
408 enum osd_zoom_factor h_zoom
,
409 enum osd_zoom_factor v_zoom
)
415 winmd
|= (h_zoom
<< OSD_OSDWIN0MD_OHZ0_SHIFT
);
416 winmd
|= (v_zoom
<< OSD_OSDWIN0MD_OVZ0_SHIFT
);
417 osd_modify(sd
, OSD_OSDWIN0MD_OHZ0
| OSD_OSDWIN0MD_OVZ0
, winmd
,
421 winmd
|= (h_zoom
<< OSD_VIDWINMD_VHZ0_SHIFT
);
422 winmd
|= (v_zoom
<< OSD_VIDWINMD_VVZ0_SHIFT
);
423 osd_modify(sd
, OSD_VIDWINMD_VHZ0
| OSD_VIDWINMD_VVZ0
, winmd
,
427 winmd
|= (h_zoom
<< OSD_OSDWIN1MD_OHZ1_SHIFT
);
428 winmd
|= (v_zoom
<< OSD_OSDWIN1MD_OVZ1_SHIFT
);
429 osd_modify(sd
, OSD_OSDWIN1MD_OHZ1
| OSD_OSDWIN1MD_OVZ1
, winmd
,
433 winmd
|= (h_zoom
<< OSD_VIDWINMD_VHZ1_SHIFT
);
434 winmd
|= (v_zoom
<< OSD_VIDWINMD_VVZ1_SHIFT
);
435 osd_modify(sd
, OSD_VIDWINMD_VHZ1
| OSD_VIDWINMD_VVZ1
, winmd
,
441 static void _osd_disable_layer(struct osd_state
*sd
, enum osd_layer layer
)
445 osd_clear(sd
, OSD_OSDWIN0MD_OACT0
, OSD_OSDWIN0MD
);
448 osd_clear(sd
, OSD_VIDWINMD_ACT0
, OSD_VIDWINMD
);
451 /* disable attribute mode as well as disabling the window */
452 osd_clear(sd
, OSD_OSDWIN1MD_OASW
| OSD_OSDWIN1MD_OACT1
,
456 osd_clear(sd
, OSD_VIDWINMD_ACT1
, OSD_VIDWINMD
);
461 static void osd_disable_layer(struct osd_state
*sd
, enum osd_layer layer
)
463 struct osd_state
*osd
= sd
;
464 struct osd_window_state
*win
= &osd
->win
[layer
];
467 spin_lock_irqsave(&osd
->lock
, flags
);
469 if (!win
->is_enabled
) {
470 spin_unlock_irqrestore(&osd
->lock
, flags
);
475 _osd_disable_layer(sd
, layer
);
477 spin_unlock_irqrestore(&osd
->lock
, flags
);
480 static void _osd_enable_attribute_mode(struct osd_state
*sd
)
482 /* enable attribute mode for OSD1 */
483 osd_set(sd
, OSD_OSDWIN1MD_OASW
, OSD_OSDWIN1MD
);
486 static void _osd_enable_layer(struct osd_state
*sd
, enum osd_layer layer
)
490 osd_set(sd
, OSD_OSDWIN0MD_OACT0
, OSD_OSDWIN0MD
);
493 osd_set(sd
, OSD_VIDWINMD_ACT0
, OSD_VIDWINMD
);
496 /* enable OSD1 and disable attribute mode */
497 osd_modify(sd
, OSD_OSDWIN1MD_OASW
| OSD_OSDWIN1MD_OACT1
,
498 OSD_OSDWIN1MD_OACT1
, OSD_OSDWIN1MD
);
501 osd_set(sd
, OSD_VIDWINMD_ACT1
, OSD_VIDWINMD
);
506 static int osd_enable_layer(struct osd_state
*sd
, enum osd_layer layer
,
509 struct osd_state
*osd
= sd
;
510 struct osd_window_state
*win
= &osd
->win
[layer
];
511 struct osd_layer_config
*cfg
= &win
->lconfig
;
514 spin_lock_irqsave(&osd
->lock
, flags
);
517 * use otherwin flag to know this is the other vid window
518 * in YUV420 mode, if is, skip this check
520 if (!otherwin
&& (!win
->is_allocated
||
521 !win
->fb_base_phys
||
525 spin_unlock_irqrestore(&osd
->lock
, flags
);
529 if (win
->is_enabled
) {
530 spin_unlock_irqrestore(&osd
->lock
, flags
);
535 if (cfg
->pixfmt
!= PIXFMT_OSD_ATTR
)
536 _osd_enable_layer(sd
, layer
);
538 _osd_enable_attribute_mode(sd
);
539 _osd_set_blink_attribute(sd
, osd
->is_blinking
, osd
->blink
);
542 spin_unlock_irqrestore(&osd
->lock
, flags
);
547 #define OSD_SRC_ADDR_HIGH4 0x7800000
548 #define OSD_SRC_ADDR_HIGH7 0x7F0000
549 #define OSD_SRCADD_OFSET_SFT 23
550 #define OSD_SRCADD_ADD_SFT 16
551 #define OSD_WINADL_MASK 0xFFFF
552 #define OSD_WINOFST_MASK 0x1000
553 #define VPBE_REG_BASE 0x80000000
555 static void _osd_start_layer(struct osd_state
*sd
, enum osd_layer layer
,
556 unsigned long fb_base_phys
,
557 unsigned long cbcr_ofst
)
560 if (sd
->vpbe_type
== VPBE_VERSION_1
) {
563 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_OSDWIN0ADR
);
566 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_VIDWIN0ADR
);
569 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_OSDWIN1ADR
);
572 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_VIDWIN1ADR
);
575 } else if (sd
->vpbe_type
== VPBE_VERSION_3
) {
576 unsigned long fb_offset_32
=
577 (fb_base_phys
- VPBE_REG_BASE
) >> 5;
581 osd_modify(sd
, OSD_OSDWINADH_O0AH
,
582 fb_offset_32
>> (OSD_SRCADD_ADD_SFT
-
583 OSD_OSDWINADH_O0AH_SHIFT
),
585 osd_write(sd
, fb_offset_32
& OSD_OSDWIN0ADL_O0AL
,
589 osd_modify(sd
, OSD_VIDWINADH_V0AH
,
590 fb_offset_32
>> (OSD_SRCADD_ADD_SFT
-
591 OSD_VIDWINADH_V0AH_SHIFT
),
593 osd_write(sd
, fb_offset_32
& OSD_VIDWIN0ADL_V0AL
,
597 osd_modify(sd
, OSD_OSDWINADH_O1AH
,
598 fb_offset_32
>> (OSD_SRCADD_ADD_SFT
-
599 OSD_OSDWINADH_O1AH_SHIFT
),
601 osd_write(sd
, fb_offset_32
& OSD_OSDWIN1ADL_O1AL
,
605 osd_modify(sd
, OSD_VIDWINADH_V1AH
,
606 fb_offset_32
>> (OSD_SRCADD_ADD_SFT
-
607 OSD_VIDWINADH_V1AH_SHIFT
),
609 osd_write(sd
, fb_offset_32
& OSD_VIDWIN1ADL_V1AL
,
613 } else if (sd
->vpbe_type
== VPBE_VERSION_2
) {
614 struct osd_window_state
*win
= &sd
->win
[layer
];
615 unsigned long fb_offset_32
, cbcr_offset_32
;
617 fb_offset_32
= fb_base_phys
- VPBE_REG_BASE
;
619 cbcr_offset_32
= cbcr_ofst
;
621 cbcr_offset_32
= win
->lconfig
.line_length
*
623 cbcr_offset_32
+= fb_offset_32
;
624 fb_offset_32
= fb_offset_32
>> 5;
625 cbcr_offset_32
= cbcr_offset_32
>> 5;
627 * DM365: start address is 27-bit long address b26 - b23 are
628 * in offset register b12 - b9, and * bit 26 has to be '1'
630 if (win
->lconfig
.pixfmt
== PIXFMT_NV12
) {
635 osd_modify(sd
, OSD_VIDWIN0OFST_V0AH
,
636 ((fb_offset_32
& OSD_SRC_ADDR_HIGH4
) >>
637 (OSD_SRCADD_OFSET_SFT
-
638 OSD_WINOFST_AH_SHIFT
)) |
639 OSD_WINOFST_MASK
, OSD_VIDWIN0OFST
);
640 osd_modify(sd
, OSD_VIDWINADH_V0AH
,
641 (fb_offset_32
& OSD_SRC_ADDR_HIGH7
) >>
642 (OSD_SRCADD_ADD_SFT
-
643 OSD_VIDWINADH_V0AH_SHIFT
),
645 osd_write(sd
, fb_offset_32
& OSD_WINADL_MASK
,
647 /* CbCr is in VID1 */
648 osd_modify(sd
, OSD_VIDWIN1OFST_V1AH
,
650 OSD_SRC_ADDR_HIGH4
) >>
651 (OSD_SRCADD_OFSET_SFT
-
652 OSD_WINOFST_AH_SHIFT
)) |
653 OSD_WINOFST_MASK
, OSD_VIDWIN1OFST
);
654 osd_modify(sd
, OSD_VIDWINADH_V1AH
,
656 OSD_SRC_ADDR_HIGH7
) >>
657 (OSD_SRCADD_ADD_SFT
-
658 OSD_VIDWINADH_V1AH_SHIFT
),
660 osd_write(sd
, cbcr_offset_32
& OSD_WINADL_MASK
,
670 osd_modify(sd
, OSD_OSDWIN0OFST_O0AH
,
671 ((fb_offset_32
& OSD_SRC_ADDR_HIGH4
) >>
672 (OSD_SRCADD_OFSET_SFT
-
673 OSD_WINOFST_AH_SHIFT
)) | OSD_WINOFST_MASK
,
675 osd_modify(sd
, OSD_OSDWINADH_O0AH
,
676 (fb_offset_32
& OSD_SRC_ADDR_HIGH7
) >>
677 (OSD_SRCADD_ADD_SFT
-
678 OSD_OSDWINADH_O0AH_SHIFT
), OSD_OSDWINADH
);
679 osd_write(sd
, fb_offset_32
& OSD_WINADL_MASK
,
683 if (win
->lconfig
.pixfmt
!= PIXFMT_NV12
) {
684 osd_modify(sd
, OSD_VIDWIN0OFST_V0AH
,
685 ((fb_offset_32
& OSD_SRC_ADDR_HIGH4
) >>
686 (OSD_SRCADD_OFSET_SFT
-
687 OSD_WINOFST_AH_SHIFT
)) |
688 OSD_WINOFST_MASK
, OSD_VIDWIN0OFST
);
689 osd_modify(sd
, OSD_VIDWINADH_V0AH
,
690 (fb_offset_32
& OSD_SRC_ADDR_HIGH7
) >>
691 (OSD_SRCADD_ADD_SFT
-
692 OSD_VIDWINADH_V0AH_SHIFT
),
694 osd_write(sd
, fb_offset_32
& OSD_WINADL_MASK
,
699 osd_modify(sd
, OSD_OSDWIN1OFST_O1AH
,
700 ((fb_offset_32
& OSD_SRC_ADDR_HIGH4
) >>
701 (OSD_SRCADD_OFSET_SFT
-
702 OSD_WINOFST_AH_SHIFT
)) | OSD_WINOFST_MASK
,
704 osd_modify(sd
, OSD_OSDWINADH_O1AH
,
705 (fb_offset_32
& OSD_SRC_ADDR_HIGH7
) >>
706 (OSD_SRCADD_ADD_SFT
-
707 OSD_OSDWINADH_O1AH_SHIFT
),
709 osd_write(sd
, fb_offset_32
& OSD_WINADL_MASK
,
713 if (win
->lconfig
.pixfmt
!= PIXFMT_NV12
) {
714 osd_modify(sd
, OSD_VIDWIN1OFST_V1AH
,
715 ((fb_offset_32
& OSD_SRC_ADDR_HIGH4
) >>
716 (OSD_SRCADD_OFSET_SFT
-
717 OSD_WINOFST_AH_SHIFT
)) |
718 OSD_WINOFST_MASK
, OSD_VIDWIN1OFST
);
719 osd_modify(sd
, OSD_VIDWINADH_V1AH
,
720 (fb_offset_32
& OSD_SRC_ADDR_HIGH7
) >>
721 (OSD_SRCADD_ADD_SFT
-
722 OSD_VIDWINADH_V1AH_SHIFT
),
724 osd_write(sd
, fb_offset_32
& OSD_WINADL_MASK
,
732 static void osd_start_layer(struct osd_state
*sd
, enum osd_layer layer
,
733 unsigned long fb_base_phys
,
734 unsigned long cbcr_ofst
)
736 struct osd_state
*osd
= sd
;
737 struct osd_window_state
*win
= &osd
->win
[layer
];
738 struct osd_layer_config
*cfg
= &win
->lconfig
;
741 spin_lock_irqsave(&osd
->lock
, flags
);
743 win
->fb_base_phys
= fb_base_phys
& ~0x1F;
744 _osd_start_layer(sd
, layer
, fb_base_phys
, cbcr_ofst
);
746 if (layer
== WIN_VID0
) {
748 _osd_dm6446_vid0_pingpong(sd
, osd
->field_inversion
,
753 spin_unlock_irqrestore(&osd
->lock
, flags
);
756 static void osd_get_layer_config(struct osd_state
*sd
, enum osd_layer layer
,
757 struct osd_layer_config
*lconfig
)
759 struct osd_state
*osd
= sd
;
760 struct osd_window_state
*win
= &osd
->win
[layer
];
763 spin_lock_irqsave(&osd
->lock
, flags
);
765 *lconfig
= win
->lconfig
;
767 spin_unlock_irqrestore(&osd
->lock
, flags
);
771 * try_layer_config() - Try a specific configuration for the layer
772 * @sd - ptr to struct osd_state
773 * @layer - layer to configure
774 * @lconfig - layer configuration to try
776 * If the requested lconfig is completely rejected and the value of lconfig on
777 * exit is the current lconfig, then try_layer_config() returns 1. Otherwise,
778 * try_layer_config() returns 0. A return value of 0 does not necessarily mean
779 * that the value of lconfig on exit is identical to the value of lconfig on
780 * entry, but merely that it represents a change from the current lconfig.
782 static int try_layer_config(struct osd_state
*sd
, enum osd_layer layer
,
783 struct osd_layer_config
*lconfig
)
785 struct osd_state
*osd
= sd
;
786 struct osd_window_state
*win
= &osd
->win
[layer
];
789 /* verify that the pixel format is compatible with the layer */
790 switch (lconfig
->pixfmt
) {
796 if (osd
->vpbe_type
== VPBE_VERSION_1
)
797 bad_config
= !is_vid_win(layer
);
801 bad_config
= !is_vid_win(layer
);
804 if (osd
->vpbe_type
== VPBE_VERSION_1
)
805 bad_config
= !is_vid_win(layer
);
806 else if ((osd
->vpbe_type
== VPBE_VERSION_3
) ||
807 (osd
->vpbe_type
== VPBE_VERSION_2
))
808 bad_config
= !is_osd_win(layer
);
811 if (osd
->vpbe_type
!= VPBE_VERSION_2
)
814 bad_config
= is_osd_win(layer
);
816 case PIXFMT_OSD_ATTR
:
817 bad_config
= (layer
!= WIN_OSD1
);
825 * The requested pixel format is incompatible with the layer,
826 * so keep the current layer configuration.
828 *lconfig
= win
->lconfig
;
833 /* only one OSD window at a time can use RGB pixel formats */
834 if ((osd
->vpbe_type
== VPBE_VERSION_1
) &&
835 is_osd_win(layer
) && is_rgb_pixfmt(lconfig
->pixfmt
)) {
836 enum osd_pix_format pixfmt
;
837 if (layer
== WIN_OSD0
)
838 pixfmt
= osd
->win
[WIN_OSD1
].lconfig
.pixfmt
;
840 pixfmt
= osd
->win
[WIN_OSD0
].lconfig
.pixfmt
;
842 if (is_rgb_pixfmt(pixfmt
)) {
844 * The other OSD window is already configured for an
845 * RGB, so keep the current layer configuration.
847 *lconfig
= win
->lconfig
;
852 /* DM6446: only one video window at a time can use RGB888 */
853 if ((osd
->vpbe_type
== VPBE_VERSION_1
) && is_vid_win(layer
) &&
854 lconfig
->pixfmt
== PIXFMT_RGB888
) {
855 enum osd_pix_format pixfmt
;
857 if (layer
== WIN_VID0
)
858 pixfmt
= osd
->win
[WIN_VID1
].lconfig
.pixfmt
;
860 pixfmt
= osd
->win
[WIN_VID0
].lconfig
.pixfmt
;
862 if (pixfmt
== PIXFMT_RGB888
) {
864 * The other video window is already configured for
865 * RGB888, so keep the current layer configuration.
867 *lconfig
= win
->lconfig
;
872 /* window dimensions must be non-zero */
873 if (!lconfig
->line_length
|| !lconfig
->xsize
|| !lconfig
->ysize
) {
874 *lconfig
= win
->lconfig
;
878 /* round line_length up to a multiple of 32 */
879 lconfig
->line_length
= ((lconfig
->line_length
+ 31) / 32) * 32;
880 lconfig
->line_length
=
881 min(lconfig
->line_length
, (unsigned)MAX_LINE_LENGTH
);
882 lconfig
->xsize
= min(lconfig
->xsize
, (unsigned)MAX_WIN_SIZE
);
883 lconfig
->ysize
= min(lconfig
->ysize
, (unsigned)MAX_WIN_SIZE
);
884 lconfig
->xpos
= min(lconfig
->xpos
, (unsigned)MAX_WIN_SIZE
);
885 lconfig
->ypos
= min(lconfig
->ypos
, (unsigned)MAX_WIN_SIZE
);
886 lconfig
->interlaced
= (lconfig
->interlaced
!= 0);
887 if (lconfig
->interlaced
) {
888 /* ysize and ypos must be even for interlaced displays */
889 lconfig
->ysize
&= ~1;
896 static void _osd_disable_vid_rgb888(struct osd_state
*sd
)
899 * The DM6446 supports RGB888 pixel format in a single video window.
900 * This routine disables RGB888 pixel format for both video windows.
901 * The caller must ensure that neither video window is currently
902 * configured for RGB888 pixel format.
904 if (sd
->vpbe_type
== VPBE_VERSION_1
)
905 osd_clear(sd
, OSD_MISCCTL_RGBEN
, OSD_MISCCTL
);
908 static void _osd_enable_vid_rgb888(struct osd_state
*sd
,
909 enum osd_layer layer
)
912 * The DM6446 supports RGB888 pixel format in a single video window.
913 * This routine enables RGB888 pixel format for the specified video
914 * window. The caller must ensure that the other video window is not
915 * currently configured for RGB888 pixel format, as this routine will
916 * disable RGB888 pixel format for the other window.
918 if (sd
->vpbe_type
== VPBE_VERSION_1
) {
919 if (layer
== WIN_VID0
)
920 osd_modify(sd
, OSD_MISCCTL_RGBEN
| OSD_MISCCTL_RGBWIN
,
921 OSD_MISCCTL_RGBEN
, OSD_MISCCTL
);
922 else if (layer
== WIN_VID1
)
923 osd_modify(sd
, OSD_MISCCTL_RGBEN
| OSD_MISCCTL_RGBWIN
,
924 OSD_MISCCTL_RGBEN
| OSD_MISCCTL_RGBWIN
,
929 static void _osd_set_cbcr_order(struct osd_state
*sd
,
930 enum osd_pix_format pixfmt
)
933 * The caller must ensure that all windows using YC pixfmt use the same
936 if (pixfmt
== PIXFMT_YCbCrI
)
937 osd_clear(sd
, OSD_MODE_CS
, OSD_MODE
);
938 else if (pixfmt
== PIXFMT_YCrCbI
)
939 osd_set(sd
, OSD_MODE_CS
, OSD_MODE
);
942 static void _osd_set_layer_config(struct osd_state
*sd
, enum osd_layer layer
,
943 const struct osd_layer_config
*lconfig
)
945 u32 winmd
= 0, winmd_mask
= 0, bmw
= 0;
947 _osd_set_cbcr_order(sd
, lconfig
->pixfmt
);
951 if (sd
->vpbe_type
== VPBE_VERSION_1
) {
952 winmd_mask
|= OSD_OSDWIN0MD_RGB0E
;
953 if (lconfig
->pixfmt
== PIXFMT_RGB565
)
954 winmd
|= OSD_OSDWIN0MD_RGB0E
;
955 } else if ((sd
->vpbe_type
== VPBE_VERSION_3
) ||
956 (sd
->vpbe_type
== VPBE_VERSION_2
)) {
957 winmd_mask
|= OSD_OSDWIN0MD_BMP0MD
;
958 switch (lconfig
->pixfmt
) {
961 OSD_OSDWIN0MD_BMP0MD_SHIFT
);
964 winmd
|= (2 << OSD_OSDWIN0MD_BMP0MD_SHIFT
);
965 _osd_enable_rgb888_pixblend(sd
, OSDWIN_OSD0
);
969 winmd
|= (3 << OSD_OSDWIN0MD_BMP0MD_SHIFT
);
976 winmd_mask
|= OSD_OSDWIN0MD_BMW0
| OSD_OSDWIN0MD_OFF0
;
978 switch (lconfig
->pixfmt
) {
994 winmd
|= (bmw
<< OSD_OSDWIN0MD_BMW0_SHIFT
);
996 if (lconfig
->interlaced
)
997 winmd
|= OSD_OSDWIN0MD_OFF0
;
999 osd_modify(sd
, winmd_mask
, winmd
, OSD_OSDWIN0MD
);
1000 osd_write(sd
, lconfig
->line_length
>> 5, OSD_OSDWIN0OFST
);
1001 osd_write(sd
, lconfig
->xpos
, OSD_OSDWIN0XP
);
1002 osd_write(sd
, lconfig
->xsize
, OSD_OSDWIN0XL
);
1003 if (lconfig
->interlaced
) {
1004 osd_write(sd
, lconfig
->ypos
>> 1, OSD_OSDWIN0YP
);
1005 osd_write(sd
, lconfig
->ysize
>> 1, OSD_OSDWIN0YL
);
1007 osd_write(sd
, lconfig
->ypos
, OSD_OSDWIN0YP
);
1008 osd_write(sd
, lconfig
->ysize
, OSD_OSDWIN0YL
);
1012 winmd_mask
|= OSD_VIDWINMD_VFF0
;
1013 if (lconfig
->interlaced
)
1014 winmd
|= OSD_VIDWINMD_VFF0
;
1016 osd_modify(sd
, winmd_mask
, winmd
, OSD_VIDWINMD
);
1017 osd_write(sd
, lconfig
->line_length
>> 5, OSD_VIDWIN0OFST
);
1018 osd_write(sd
, lconfig
->xpos
, OSD_VIDWIN0XP
);
1019 osd_write(sd
, lconfig
->xsize
, OSD_VIDWIN0XL
);
1021 * For YUV420P format the register contents are
1022 * duplicated in both VID registers
1024 if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1025 (lconfig
->pixfmt
== PIXFMT_NV12
)) {
1026 /* other window also */
1027 if (lconfig
->interlaced
) {
1028 winmd_mask
|= OSD_VIDWINMD_VFF1
;
1029 winmd
|= OSD_VIDWINMD_VFF1
;
1030 osd_modify(sd
, winmd_mask
, winmd
,
1034 osd_modify(sd
, OSD_MISCCTL_S420D
,
1035 OSD_MISCCTL_S420D
, OSD_MISCCTL
);
1036 osd_write(sd
, lconfig
->line_length
>> 5,
1038 osd_write(sd
, lconfig
->xpos
, OSD_VIDWIN1XP
);
1039 osd_write(sd
, lconfig
->xsize
, OSD_VIDWIN1XL
);
1041 * if NV21 pixfmt and line length not 32B
1042 * aligned (e.g. NTSC), Need to set window
1043 * X pixel size to be 32B aligned as well
1045 if (lconfig
->xsize
% 32) {
1047 ((lconfig
->xsize
+ 31) & ~31),
1050 ((lconfig
->xsize
+ 31) & ~31),
1053 } else if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1054 (lconfig
->pixfmt
!= PIXFMT_NV12
)) {
1055 osd_modify(sd
, OSD_MISCCTL_S420D
, ~OSD_MISCCTL_S420D
,
1059 if (lconfig
->interlaced
) {
1060 osd_write(sd
, lconfig
->ypos
>> 1, OSD_VIDWIN0YP
);
1061 osd_write(sd
, lconfig
->ysize
>> 1, OSD_VIDWIN0YL
);
1062 if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1063 lconfig
->pixfmt
== PIXFMT_NV12
) {
1064 osd_write(sd
, lconfig
->ypos
>> 1,
1066 osd_write(sd
, lconfig
->ysize
>> 1,
1070 osd_write(sd
, lconfig
->ypos
, OSD_VIDWIN0YP
);
1071 osd_write(sd
, lconfig
->ysize
, OSD_VIDWIN0YL
);
1072 if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1073 lconfig
->pixfmt
== PIXFMT_NV12
) {
1074 osd_write(sd
, lconfig
->ypos
, OSD_VIDWIN1YP
);
1075 osd_write(sd
, lconfig
->ysize
, OSD_VIDWIN1YL
);
1081 * The caller must ensure that OSD1 is disabled prior to
1082 * switching from a normal mode to attribute mode or from
1083 * attribute mode to a normal mode.
1085 if (lconfig
->pixfmt
== PIXFMT_OSD_ATTR
) {
1086 if (sd
->vpbe_type
== VPBE_VERSION_1
) {
1087 winmd_mask
|= OSD_OSDWIN1MD_ATN1E
|
1088 OSD_OSDWIN1MD_RGB1E
| OSD_OSDWIN1MD_CLUTS1
|
1089 OSD_OSDWIN1MD_BLND1
| OSD_OSDWIN1MD_TE1
;
1091 winmd_mask
|= OSD_OSDWIN1MD_BMP1MD
|
1092 OSD_OSDWIN1MD_CLUTS1
| OSD_OSDWIN1MD_BLND1
|
1096 if (sd
->vpbe_type
== VPBE_VERSION_1
) {
1097 winmd_mask
|= OSD_OSDWIN1MD_RGB1E
;
1098 if (lconfig
->pixfmt
== PIXFMT_RGB565
)
1099 winmd
|= OSD_OSDWIN1MD_RGB1E
;
1100 } else if ((sd
->vpbe_type
== VPBE_VERSION_3
)
1101 || (sd
->vpbe_type
== VPBE_VERSION_2
)) {
1102 winmd_mask
|= OSD_OSDWIN1MD_BMP1MD
;
1103 switch (lconfig
->pixfmt
) {
1106 (1 << OSD_OSDWIN1MD_BMP1MD_SHIFT
);
1110 (2 << OSD_OSDWIN1MD_BMP1MD_SHIFT
);
1111 _osd_enable_rgb888_pixblend(sd
,
1117 (3 << OSD_OSDWIN1MD_BMP1MD_SHIFT
);
1124 winmd_mask
|= OSD_OSDWIN1MD_BMW1
;
1125 switch (lconfig
->pixfmt
) {
1141 winmd
|= (bmw
<< OSD_OSDWIN1MD_BMW1_SHIFT
);
1144 winmd_mask
|= OSD_OSDWIN1MD_OFF1
;
1145 if (lconfig
->interlaced
)
1146 winmd
|= OSD_OSDWIN1MD_OFF1
;
1148 osd_modify(sd
, winmd_mask
, winmd
, OSD_OSDWIN1MD
);
1149 osd_write(sd
, lconfig
->line_length
>> 5, OSD_OSDWIN1OFST
);
1150 osd_write(sd
, lconfig
->xpos
, OSD_OSDWIN1XP
);
1151 osd_write(sd
, lconfig
->xsize
, OSD_OSDWIN1XL
);
1152 if (lconfig
->interlaced
) {
1153 osd_write(sd
, lconfig
->ypos
>> 1, OSD_OSDWIN1YP
);
1154 osd_write(sd
, lconfig
->ysize
>> 1, OSD_OSDWIN1YL
);
1156 osd_write(sd
, lconfig
->ypos
, OSD_OSDWIN1YP
);
1157 osd_write(sd
, lconfig
->ysize
, OSD_OSDWIN1YL
);
1161 winmd_mask
|= OSD_VIDWINMD_VFF1
;
1162 if (lconfig
->interlaced
)
1163 winmd
|= OSD_VIDWINMD_VFF1
;
1165 osd_modify(sd
, winmd_mask
, winmd
, OSD_VIDWINMD
);
1166 osd_write(sd
, lconfig
->line_length
>> 5, OSD_VIDWIN1OFST
);
1167 osd_write(sd
, lconfig
->xpos
, OSD_VIDWIN1XP
);
1168 osd_write(sd
, lconfig
->xsize
, OSD_VIDWIN1XL
);
1170 * For YUV420P format the register contents are
1171 * duplicated in both VID registers
1173 if (sd
->vpbe_type
== VPBE_VERSION_2
) {
1174 if (lconfig
->pixfmt
== PIXFMT_NV12
) {
1175 /* other window also */
1176 if (lconfig
->interlaced
) {
1177 winmd_mask
|= OSD_VIDWINMD_VFF0
;
1178 winmd
|= OSD_VIDWINMD_VFF0
;
1179 osd_modify(sd
, winmd_mask
, winmd
,
1182 osd_modify(sd
, OSD_MISCCTL_S420D
,
1183 OSD_MISCCTL_S420D
, OSD_MISCCTL
);
1184 osd_write(sd
, lconfig
->line_length
>> 5,
1186 osd_write(sd
, lconfig
->xpos
, OSD_VIDWIN0XP
);
1187 osd_write(sd
, lconfig
->xsize
, OSD_VIDWIN0XL
);
1189 osd_modify(sd
, OSD_MISCCTL_S420D
,
1190 ~OSD_MISCCTL_S420D
, OSD_MISCCTL
);
1194 if (lconfig
->interlaced
) {
1195 osd_write(sd
, lconfig
->ypos
>> 1, OSD_VIDWIN1YP
);
1196 osd_write(sd
, lconfig
->ysize
>> 1, OSD_VIDWIN1YL
);
1197 if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1198 lconfig
->pixfmt
== PIXFMT_NV12
) {
1199 osd_write(sd
, lconfig
->ypos
>> 1,
1201 osd_write(sd
, lconfig
->ysize
>> 1,
1205 osd_write(sd
, lconfig
->ypos
, OSD_VIDWIN1YP
);
1206 osd_write(sd
, lconfig
->ysize
, OSD_VIDWIN1YL
);
1207 if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1208 lconfig
->pixfmt
== PIXFMT_NV12
) {
1209 osd_write(sd
, lconfig
->ypos
, OSD_VIDWIN0YP
);
1210 osd_write(sd
, lconfig
->ysize
, OSD_VIDWIN0YL
);
1217 static int osd_set_layer_config(struct osd_state
*sd
, enum osd_layer layer
,
1218 struct osd_layer_config
*lconfig
)
1220 struct osd_state
*osd
= sd
;
1221 struct osd_window_state
*win
= &osd
->win
[layer
];
1222 struct osd_layer_config
*cfg
= &win
->lconfig
;
1223 unsigned long flags
;
1226 spin_lock_irqsave(&osd
->lock
, flags
);
1228 reject_config
= try_layer_config(sd
, layer
, lconfig
);
1229 if (reject_config
) {
1230 spin_unlock_irqrestore(&osd
->lock
, flags
);
1231 return reject_config
;
1234 /* update the current Cb/Cr order */
1235 if (is_yc_pixfmt(lconfig
->pixfmt
))
1236 osd
->yc_pixfmt
= lconfig
->pixfmt
;
1239 * If we are switching OSD1 from normal mode to attribute mode or from
1240 * attribute mode to normal mode, then we must disable the window.
1242 if (layer
== WIN_OSD1
) {
1243 if (((lconfig
->pixfmt
== PIXFMT_OSD_ATTR
) &&
1244 (cfg
->pixfmt
!= PIXFMT_OSD_ATTR
)) ||
1245 ((lconfig
->pixfmt
!= PIXFMT_OSD_ATTR
) &&
1246 (cfg
->pixfmt
== PIXFMT_OSD_ATTR
))) {
1247 win
->is_enabled
= 0;
1248 _osd_disable_layer(sd
, layer
);
1252 _osd_set_layer_config(sd
, layer
, lconfig
);
1254 if (layer
== WIN_OSD1
) {
1255 struct osd_osdwin_state
*osdwin_state
=
1256 &osd
->osdwin
[OSDWIN_OSD1
];
1258 if ((lconfig
->pixfmt
!= PIXFMT_OSD_ATTR
) &&
1259 (cfg
->pixfmt
== PIXFMT_OSD_ATTR
)) {
1261 * We just switched OSD1 from attribute mode to normal
1262 * mode, so we must initialize the CLUT select, the
1263 * blend factor, transparency colorkey enable, and
1264 * attenuation enable (DM6446 only) bits in the
1265 * OSDWIN1MD register.
1267 _osd_set_osd_clut(sd
, OSDWIN_OSD1
,
1268 osdwin_state
->clut
);
1269 _osd_set_blending_factor(sd
, OSDWIN_OSD1
,
1270 osdwin_state
->blend
);
1271 if (osdwin_state
->colorkey_blending
) {
1272 _osd_enable_color_key(sd
, OSDWIN_OSD1
,
1277 _osd_disable_color_key(sd
, OSDWIN_OSD1
);
1278 _osd_set_rec601_attenuation(sd
, OSDWIN_OSD1
,
1280 rec601_attenuation
);
1281 } else if ((lconfig
->pixfmt
== PIXFMT_OSD_ATTR
) &&
1282 (cfg
->pixfmt
!= PIXFMT_OSD_ATTR
)) {
1284 * We just switched OSD1 from normal mode to attribute
1285 * mode, so we must initialize the blink enable and
1286 * blink interval bits in the OSDATRMD register.
1288 _osd_set_blink_attribute(sd
, osd
->is_blinking
,
1294 * If we just switched to a 1-, 2-, or 4-bits-per-pixel bitmap format
1295 * then configure a default palette map.
1297 if ((lconfig
->pixfmt
!= cfg
->pixfmt
) &&
1298 ((lconfig
->pixfmt
== PIXFMT_1BPP
) ||
1299 (lconfig
->pixfmt
== PIXFMT_2BPP
) ||
1300 (lconfig
->pixfmt
== PIXFMT_4BPP
))) {
1301 enum osd_win_layer osdwin
=
1302 ((layer
== WIN_OSD0
) ? OSDWIN_OSD0
: OSDWIN_OSD1
);
1303 struct osd_osdwin_state
*osdwin_state
=
1304 &osd
->osdwin
[osdwin
];
1305 unsigned char clut_index
;
1306 unsigned char clut_entries
= 0;
1308 switch (lconfig
->pixfmt
) {
1322 * The default palette map maps the pixel value to the clut
1323 * index, i.e. pixel value 0 maps to clut entry 0, pixel value
1324 * 1 maps to clut entry 1, etc.
1326 for (clut_index
= 0; clut_index
< 16; clut_index
++) {
1327 osdwin_state
->palette_map
[clut_index
] = clut_index
;
1328 if (clut_index
< clut_entries
) {
1329 _osd_set_palette_map(sd
, osdwin
, clut_index
,
1337 /* DM6446: configure the RGB888 enable and window selection */
1338 if (osd
->win
[WIN_VID0
].lconfig
.pixfmt
== PIXFMT_RGB888
)
1339 _osd_enable_vid_rgb888(sd
, WIN_VID0
);
1340 else if (osd
->win
[WIN_VID1
].lconfig
.pixfmt
== PIXFMT_RGB888
)
1341 _osd_enable_vid_rgb888(sd
, WIN_VID1
);
1343 _osd_disable_vid_rgb888(sd
);
1345 if (layer
== WIN_VID0
) {
1347 _osd_dm6446_vid0_pingpong(sd
, osd
->field_inversion
,
1352 spin_unlock_irqrestore(&osd
->lock
, flags
);
1357 static void osd_init_layer(struct osd_state
*sd
, enum osd_layer layer
)
1359 struct osd_state
*osd
= sd
;
1360 struct osd_window_state
*win
= &osd
->win
[layer
];
1361 enum osd_win_layer osdwin
;
1362 struct osd_osdwin_state
*osdwin_state
;
1363 struct osd_layer_config
*cfg
= &win
->lconfig
;
1364 unsigned long flags
;
1366 spin_lock_irqsave(&osd
->lock
, flags
);
1368 win
->is_enabled
= 0;
1369 _osd_disable_layer(sd
, layer
);
1371 win
->h_zoom
= ZOOM_X1
;
1372 win
->v_zoom
= ZOOM_X1
;
1373 _osd_set_zoom(sd
, layer
, win
->h_zoom
, win
->v_zoom
);
1375 win
->fb_base_phys
= 0;
1376 _osd_start_layer(sd
, layer
, win
->fb_base_phys
, 0);
1378 cfg
->line_length
= 0;
1383 cfg
->interlaced
= 0;
1387 osdwin
= (layer
== WIN_OSD0
) ? OSDWIN_OSD0
: OSDWIN_OSD1
;
1388 osdwin_state
= &osd
->osdwin
[osdwin
];
1390 * Other code relies on the fact that OSD windows default to a
1391 * bitmap pixel format when they are deallocated, so don't
1392 * change this default pixel format.
1394 cfg
->pixfmt
= PIXFMT_8BPP
;
1395 _osd_set_layer_config(sd
, layer
, cfg
);
1396 osdwin_state
->clut
= RAM_CLUT
;
1397 _osd_set_osd_clut(sd
, osdwin
, osdwin_state
->clut
);
1398 osdwin_state
->colorkey_blending
= 0;
1399 _osd_disable_color_key(sd
, osdwin
);
1400 osdwin_state
->blend
= OSD_8_VID_0
;
1401 _osd_set_blending_factor(sd
, osdwin
, osdwin_state
->blend
);
1402 osdwin_state
->rec601_attenuation
= 0;
1403 _osd_set_rec601_attenuation(sd
, osdwin
,
1405 rec601_attenuation
);
1406 if (osdwin
== OSDWIN_OSD1
) {
1407 osd
->is_blinking
= 0;
1408 osd
->blink
= BLINK_X1
;
1413 cfg
->pixfmt
= osd
->yc_pixfmt
;
1414 _osd_set_layer_config(sd
, layer
, cfg
);
1418 spin_unlock_irqrestore(&osd
->lock
, flags
);
1421 static void osd_release_layer(struct osd_state
*sd
, enum osd_layer layer
)
1423 struct osd_state
*osd
= sd
;
1424 struct osd_window_state
*win
= &osd
->win
[layer
];
1425 unsigned long flags
;
1427 spin_lock_irqsave(&osd
->lock
, flags
);
1429 if (!win
->is_allocated
) {
1430 spin_unlock_irqrestore(&osd
->lock
, flags
);
1434 spin_unlock_irqrestore(&osd
->lock
, flags
);
1435 osd_init_layer(sd
, layer
);
1436 spin_lock_irqsave(&osd
->lock
, flags
);
1438 win
->is_allocated
= 0;
1440 spin_unlock_irqrestore(&osd
->lock
, flags
);
1443 static int osd_request_layer(struct osd_state
*sd
, enum osd_layer layer
)
1445 struct osd_state
*osd
= sd
;
1446 struct osd_window_state
*win
= &osd
->win
[layer
];
1447 unsigned long flags
;
1449 spin_lock_irqsave(&osd
->lock
, flags
);
1451 if (win
->is_allocated
) {
1452 spin_unlock_irqrestore(&osd
->lock
, flags
);
1455 win
->is_allocated
= 1;
1457 spin_unlock_irqrestore(&osd
->lock
, flags
);
1462 static void _osd_init(struct osd_state
*sd
)
1464 osd_write(sd
, 0, OSD_MODE
);
1465 osd_write(sd
, 0, OSD_VIDWINMD
);
1466 osd_write(sd
, 0, OSD_OSDWIN0MD
);
1467 osd_write(sd
, 0, OSD_OSDWIN1MD
);
1468 osd_write(sd
, 0, OSD_RECTCUR
);
1469 osd_write(sd
, 0, OSD_MISCCTL
);
1470 if (sd
->vpbe_type
== VPBE_VERSION_3
) {
1471 osd_write(sd
, 0, OSD_VBNDRY
);
1472 osd_write(sd
, 0, OSD_EXTMODE
);
1473 osd_write(sd
, OSD_MISCCTL_DMANG
, OSD_MISCCTL
);
1477 static void osd_set_left_margin(struct osd_state
*sd
, u32 val
)
1479 osd_write(sd
, val
, OSD_BASEPX
);
1482 static void osd_set_top_margin(struct osd_state
*sd
, u32 val
)
1484 osd_write(sd
, val
, OSD_BASEPY
);
1487 static int osd_initialize(struct osd_state
*osd
)
1493 /* set default Cb/Cr order */
1494 osd
->yc_pixfmt
= PIXFMT_YCbCrI
;
1496 if (osd
->vpbe_type
== VPBE_VERSION_3
) {
1498 * ROM CLUT1 on the DM355 is similar (identical?) to ROM CLUT0
1499 * on the DM6446, so make ROM_CLUT1 the default on the DM355.
1501 osd
->rom_clut
= ROM_CLUT1
;
1504 _osd_set_field_inversion(osd
, osd
->field_inversion
);
1505 _osd_set_rom_clut(osd
, osd
->rom_clut
);
1507 osd_init_layer(osd
, WIN_OSD0
);
1508 osd_init_layer(osd
, WIN_VID0
);
1509 osd_init_layer(osd
, WIN_OSD1
);
1510 osd_init_layer(osd
, WIN_VID1
);
1515 static const struct vpbe_osd_ops osd_ops
= {
1516 .initialize
= osd_initialize
,
1517 .request_layer
= osd_request_layer
,
1518 .release_layer
= osd_release_layer
,
1519 .enable_layer
= osd_enable_layer
,
1520 .disable_layer
= osd_disable_layer
,
1521 .set_layer_config
= osd_set_layer_config
,
1522 .get_layer_config
= osd_get_layer_config
,
1523 .start_layer
= osd_start_layer
,
1524 .set_left_margin
= osd_set_left_margin
,
1525 .set_top_margin
= osd_set_top_margin
,
1528 static int osd_probe(struct platform_device
*pdev
)
1530 struct osd_platform_data
*pdata
;
1531 struct osd_state
*osd
;
1532 struct resource
*res
;
1535 osd
= kzalloc(sizeof(struct osd_state
), GFP_KERNEL
);
1539 osd
->dev
= &pdev
->dev
;
1540 pdata
= (struct osd_platform_data
*)pdev
->dev
.platform_data
;
1541 osd
->vpbe_type
= (enum vpbe_version
)pdata
->vpbe_type
;
1542 if (NULL
== pdev
->dev
.platform_data
) {
1543 dev_err(osd
->dev
, "No platform data defined for OSD"
1549 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1551 dev_err(osd
->dev
, "Unable to get OSD register address map\n");
1555 osd
->osd_base_phys
= res
->start
;
1556 osd
->osd_size
= resource_size(res
);
1557 if (!request_mem_region(osd
->osd_base_phys
, osd
->osd_size
,
1559 dev_err(osd
->dev
, "Unable to reserve OSD MMIO region\n");
1563 osd
->osd_base
= (unsigned long)ioremap_nocache(res
->start
,
1565 if (!osd
->osd_base
) {
1566 dev_err(osd
->dev
, "Unable to map the OSD region\n");
1568 goto release_mem_region
;
1570 spin_lock_init(&osd
->lock
);
1572 platform_set_drvdata(pdev
, osd
);
1573 dev_notice(osd
->dev
, "OSD sub device probe success\n");
1577 release_mem_region(osd
->osd_base_phys
, osd
->osd_size
);
1583 static int osd_remove(struct platform_device
*pdev
)
1585 struct osd_state
*osd
= platform_get_drvdata(pdev
);
1587 iounmap((void *)osd
->osd_base
);
1588 release_mem_region(osd
->osd_base_phys
, osd
->osd_size
);
1593 static struct platform_driver osd_driver
= {
1595 .remove
= osd_remove
,
1597 .name
= MODULE_NAME
,
1598 .owner
= THIS_MODULE
,
1602 module_platform_driver(osd_driver
);
1604 MODULE_LICENSE("GPL");
1605 MODULE_DESCRIPTION("DaVinci OSD Manager Driver");
1606 MODULE_AUTHOR("Texas Instruments");