1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2007-2010 Texas Instruments Inc
4 * Copyright (C) 2007 MontaVista Software, Inc.
6 * Andy Lowe (alowe@mvista.com), MontaVista Software
8 * Murali Karicheri (mkaricheri@gmail.com), Texas Instruments Ltd.
9 * - ported to sub device interface
11 #include <linux/module.h>
12 #include <linux/mod_devicetable.h>
13 #include <linux/kernel.h>
14 #include <linux/interrupt.h>
15 #include <linux/platform_device.h>
16 #include <linux/clk.h>
17 #include <linux/slab.h>
19 #include <media/davinci/vpss.h>
20 #include <media/v4l2-device.h>
21 #include <media/davinci/vpbe_types.h>
22 #include <media/davinci/vpbe_osd.h>
25 #include "vpbe_osd_regs.h"
27 #define MODULE_NAME "davinci-vpbe-osd"
29 static const struct platform_device_id vpbe_osd_devtype
[] = {
31 .name
= DM644X_VPBE_OSD_SUBDEV_NAME
,
32 .driver_data
= VPBE_VERSION_1
,
34 .name
= DM365_VPBE_OSD_SUBDEV_NAME
,
35 .driver_data
= VPBE_VERSION_2
,
37 .name
= DM355_VPBE_OSD_SUBDEV_NAME
,
38 .driver_data
= VPBE_VERSION_3
,
45 MODULE_DEVICE_TABLE(platform
, vpbe_osd_devtype
);
47 /* register access routines */
48 static inline u32
osd_read(struct osd_state
*sd
, u32 offset
)
50 struct osd_state
*osd
= sd
;
52 return readl(osd
->osd_base
+ offset
);
55 static inline u32
osd_write(struct osd_state
*sd
, u32 val
, u32 offset
)
57 struct osd_state
*osd
= sd
;
59 writel(val
, osd
->osd_base
+ offset
);
64 static inline u32
osd_set(struct osd_state
*sd
, u32 mask
, u32 offset
)
66 struct osd_state
*osd
= sd
;
68 void __iomem
*addr
= osd
->osd_base
+ offset
;
69 u32 val
= readl(addr
) | mask
;
76 static inline u32
osd_clear(struct osd_state
*sd
, u32 mask
, u32 offset
)
78 struct osd_state
*osd
= sd
;
80 void __iomem
*addr
= osd
->osd_base
+ offset
;
81 u32 val
= readl(addr
) & ~mask
;
88 static inline u32
osd_modify(struct osd_state
*sd
, u32 mask
, u32 val
,
91 struct osd_state
*osd
= sd
;
93 void __iomem
*addr
= osd
->osd_base
+ offset
;
94 u32 new_val
= (readl(addr
) & ~mask
) | (val
& mask
);
96 writel(new_val
, addr
);
101 /* define some macros for layer and pixfmt classification */
102 #define is_osd_win(layer) (((layer) == WIN_OSD0) || ((layer) == WIN_OSD1))
103 #define is_vid_win(layer) (((layer) == WIN_VID0) || ((layer) == WIN_VID1))
104 #define is_rgb_pixfmt(pixfmt) \
105 (((pixfmt) == PIXFMT_RGB565) || ((pixfmt) == PIXFMT_RGB888))
106 #define is_yc_pixfmt(pixfmt) \
107 (((pixfmt) == PIXFMT_YCBCRI) || ((pixfmt) == PIXFMT_YCRCBI) || \
108 ((pixfmt) == PIXFMT_NV12))
109 #define MAX_WIN_SIZE OSD_VIDWIN0XP_V0X
110 #define MAX_LINE_LENGTH (OSD_VIDWIN0OFST_V0LO << 5)
113 * _osd_dm6446_vid0_pingpong() - field inversion fix for DM6446
114 * @sd: ptr to struct osd_state
115 * @field_inversion: inversion flag
116 * @fb_base_phys: frame buffer address
117 * @lconfig: ptr to layer config
119 * This routine implements a workaround for the field signal inversion silicon
120 * erratum described in Advisory 1.3.8 for the DM6446. The fb_base_phys and
121 * lconfig parameters apply to the vid0 window. This routine should be called
122 * whenever the vid0 layer configuration or start address is modified, or when
123 * the OSD field inversion setting is modified.
124 * Returns: 1 if the ping-pong buffers need to be toggled in the vsync isr, or
127 static int _osd_dm6446_vid0_pingpong(struct osd_state
*sd
,
129 unsigned long fb_base_phys
,
130 const struct osd_layer_config
*lconfig
)
132 struct osd_platform_data
*pdata
;
134 pdata
= (struct osd_platform_data
*)sd
->dev
->platform_data
;
135 if (pdata
!= NULL
&& pdata
->field_inv_wa_enable
) {
137 if (!field_inversion
|| !lconfig
->interlaced
) {
138 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_VIDWIN0ADR
);
139 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_PPVWIN0ADR
);
140 osd_modify(sd
, OSD_MISCCTL_PPSW
| OSD_MISCCTL_PPRV
, 0,
144 unsigned miscctl
= OSD_MISCCTL_PPRV
;
147 (fb_base_phys
& ~0x1F) - lconfig
->line_length
,
150 (fb_base_phys
& ~0x1F) + lconfig
->line_length
,
153 OSD_MISCCTL_PPSW
| OSD_MISCCTL_PPRV
, miscctl
,
163 static void _osd_set_field_inversion(struct osd_state
*sd
, int enable
)
168 fsinv
= OSD_MODE_FSINV
;
170 osd_modify(sd
, OSD_MODE_FSINV
, fsinv
, OSD_MODE
);
173 static void _osd_set_blink_attribute(struct osd_state
*sd
, int enable
,
174 enum osd_blink_interval blink
)
179 osdatrmd
|= OSD_OSDATRMD_BLNK
;
180 osdatrmd
|= blink
<< OSD_OSDATRMD_BLNKINT_SHIFT
;
182 /* caller must ensure that OSD1 is configured in attribute mode */
183 osd_modify(sd
, OSD_OSDATRMD_BLNKINT
| OSD_OSDATRMD_BLNK
, osdatrmd
,
187 static void _osd_set_rom_clut(struct osd_state
*sd
,
188 enum osd_rom_clut rom_clut
)
190 if (rom_clut
== ROM_CLUT0
)
191 osd_clear(sd
, OSD_MISCCTL_RSEL
, OSD_MISCCTL
);
193 osd_set(sd
, OSD_MISCCTL_RSEL
, OSD_MISCCTL
);
196 static void _osd_set_palette_map(struct osd_state
*sd
,
197 enum osd_win_layer osdwin
,
198 unsigned char pixel_value
,
199 unsigned char clut_index
,
200 enum osd_pix_format pixfmt
)
202 static const int map_2bpp
[] = { 0, 5, 10, 15 };
203 static const int map_1bpp
[] = { 0, 15 };
211 bmp_reg
= map_1bpp
[pixel_value
& 0x1];
214 bmp_reg
= map_2bpp
[pixel_value
& 0x3];
217 bmp_reg
= pixel_value
& 0xf;
225 bmp_offset
= OSD_W0BMP01
+ (bmp_reg
>> 1) * sizeof(u32
);
228 bmp_offset
= OSD_W1BMP01
+ (bmp_reg
>> 1) * sizeof(u32
);
236 bmp_mask
= 0xff << 8;
242 osd_modify(sd
, bmp_mask
, clut_index
<< bmp_shift
, bmp_offset
);
245 static void _osd_set_rec601_attenuation(struct osd_state
*sd
,
246 enum osd_win_layer osdwin
, int enable
)
250 osd_modify(sd
, OSD_OSDWIN0MD_ATN0E
,
251 enable
? OSD_OSDWIN0MD_ATN0E
: 0,
253 if (sd
->vpbe_type
== VPBE_VERSION_1
)
254 osd_modify(sd
, OSD_OSDWIN0MD_ATN0E
,
255 enable
? OSD_OSDWIN0MD_ATN0E
: 0,
257 else if ((sd
->vpbe_type
== VPBE_VERSION_3
) ||
258 (sd
->vpbe_type
== VPBE_VERSION_2
))
259 osd_modify(sd
, OSD_EXTMODE_ATNOSD0EN
,
260 enable
? OSD_EXTMODE_ATNOSD0EN
: 0,
264 osd_modify(sd
, OSD_OSDWIN1MD_ATN1E
,
265 enable
? OSD_OSDWIN1MD_ATN1E
: 0,
267 if (sd
->vpbe_type
== VPBE_VERSION_1
)
268 osd_modify(sd
, OSD_OSDWIN1MD_ATN1E
,
269 enable
? OSD_OSDWIN1MD_ATN1E
: 0,
271 else if ((sd
->vpbe_type
== VPBE_VERSION_3
) ||
272 (sd
->vpbe_type
== VPBE_VERSION_2
))
273 osd_modify(sd
, OSD_EXTMODE_ATNOSD1EN
,
274 enable
? OSD_EXTMODE_ATNOSD1EN
: 0,
280 static void _osd_set_blending_factor(struct osd_state
*sd
,
281 enum osd_win_layer osdwin
,
282 enum osd_blending_factor blend
)
286 osd_modify(sd
, OSD_OSDWIN0MD_BLND0
,
287 blend
<< OSD_OSDWIN0MD_BLND0_SHIFT
, OSD_OSDWIN0MD
);
290 osd_modify(sd
, OSD_OSDWIN1MD_BLND1
,
291 blend
<< OSD_OSDWIN1MD_BLND1_SHIFT
, OSD_OSDWIN1MD
);
296 static void _osd_enable_rgb888_pixblend(struct osd_state
*sd
,
297 enum osd_win_layer osdwin
)
300 osd_modify(sd
, OSD_MISCCTL_BLDSEL
, 0, OSD_MISCCTL
);
303 osd_modify(sd
, OSD_EXTMODE_OSD0BLDCHR
,
304 OSD_EXTMODE_OSD0BLDCHR
, OSD_EXTMODE
);
307 osd_modify(sd
, OSD_EXTMODE_OSD1BLDCHR
,
308 OSD_EXTMODE_OSD1BLDCHR
, OSD_EXTMODE
);
313 static void _osd_enable_color_key(struct osd_state
*sd
,
314 enum osd_win_layer osdwin
,
316 enum osd_pix_format pixfmt
)
323 if (sd
->vpbe_type
== VPBE_VERSION_3
) {
326 osd_modify(sd
, OSD_TRANSPBMPIDX_BMP0
,
328 OSD_TRANSPBMPIDX_BMP0_SHIFT
,
332 osd_modify(sd
, OSD_TRANSPBMPIDX_BMP1
,
334 OSD_TRANSPBMPIDX_BMP1_SHIFT
,
341 if (sd
->vpbe_type
== VPBE_VERSION_1
)
342 osd_write(sd
, colorkey
& OSD_TRANSPVAL_RGBTRANS
,
344 else if (sd
->vpbe_type
== VPBE_VERSION_3
)
345 osd_write(sd
, colorkey
& OSD_TRANSPVALL_RGBL
,
350 if (sd
->vpbe_type
== VPBE_VERSION_3
)
351 osd_modify(sd
, OSD_TRANSPVALU_Y
, colorkey
,
355 if (sd
->vpbe_type
== VPBE_VERSION_3
) {
356 osd_write(sd
, colorkey
& OSD_TRANSPVALL_RGBL
,
358 osd_modify(sd
, OSD_TRANSPVALU_RGBU
, colorkey
>> 16,
368 osd_set(sd
, OSD_OSDWIN0MD_TE0
, OSD_OSDWIN0MD
);
371 osd_set(sd
, OSD_OSDWIN1MD_TE1
, OSD_OSDWIN1MD
);
376 static void _osd_disable_color_key(struct osd_state
*sd
,
377 enum osd_win_layer osdwin
)
381 osd_clear(sd
, OSD_OSDWIN0MD_TE0
, OSD_OSDWIN0MD
);
384 osd_clear(sd
, OSD_OSDWIN1MD_TE1
, OSD_OSDWIN1MD
);
389 static void _osd_set_osd_clut(struct osd_state
*sd
,
390 enum osd_win_layer osdwin
,
397 if (clut
== RAM_CLUT
)
398 winmd
|= OSD_OSDWIN0MD_CLUTS0
;
399 osd_modify(sd
, OSD_OSDWIN0MD_CLUTS0
, winmd
, OSD_OSDWIN0MD
);
402 if (clut
== RAM_CLUT
)
403 winmd
|= OSD_OSDWIN1MD_CLUTS1
;
404 osd_modify(sd
, OSD_OSDWIN1MD_CLUTS1
, winmd
, OSD_OSDWIN1MD
);
409 static void _osd_set_zoom(struct osd_state
*sd
, enum osd_layer layer
,
410 enum osd_zoom_factor h_zoom
,
411 enum osd_zoom_factor v_zoom
)
417 winmd
|= (h_zoom
<< OSD_OSDWIN0MD_OHZ0_SHIFT
);
418 winmd
|= (v_zoom
<< OSD_OSDWIN0MD_OVZ0_SHIFT
);
419 osd_modify(sd
, OSD_OSDWIN0MD_OHZ0
| OSD_OSDWIN0MD_OVZ0
, winmd
,
423 winmd
|= (h_zoom
<< OSD_VIDWINMD_VHZ0_SHIFT
);
424 winmd
|= (v_zoom
<< OSD_VIDWINMD_VVZ0_SHIFT
);
425 osd_modify(sd
, OSD_VIDWINMD_VHZ0
| OSD_VIDWINMD_VVZ0
, winmd
,
429 winmd
|= (h_zoom
<< OSD_OSDWIN1MD_OHZ1_SHIFT
);
430 winmd
|= (v_zoom
<< OSD_OSDWIN1MD_OVZ1_SHIFT
);
431 osd_modify(sd
, OSD_OSDWIN1MD_OHZ1
| OSD_OSDWIN1MD_OVZ1
, winmd
,
435 winmd
|= (h_zoom
<< OSD_VIDWINMD_VHZ1_SHIFT
);
436 winmd
|= (v_zoom
<< OSD_VIDWINMD_VVZ1_SHIFT
);
437 osd_modify(sd
, OSD_VIDWINMD_VHZ1
| OSD_VIDWINMD_VVZ1
, winmd
,
443 static void _osd_disable_layer(struct osd_state
*sd
, enum osd_layer layer
)
447 osd_clear(sd
, OSD_OSDWIN0MD_OACT0
, OSD_OSDWIN0MD
);
450 osd_clear(sd
, OSD_VIDWINMD_ACT0
, OSD_VIDWINMD
);
453 /* disable attribute mode as well as disabling the window */
454 osd_clear(sd
, OSD_OSDWIN1MD_OASW
| OSD_OSDWIN1MD_OACT1
,
458 osd_clear(sd
, OSD_VIDWINMD_ACT1
, OSD_VIDWINMD
);
463 static void osd_disable_layer(struct osd_state
*sd
, enum osd_layer layer
)
465 struct osd_state
*osd
= sd
;
466 struct osd_window_state
*win
= &osd
->win
[layer
];
469 spin_lock_irqsave(&osd
->lock
, flags
);
471 if (!win
->is_enabled
) {
472 spin_unlock_irqrestore(&osd
->lock
, flags
);
477 _osd_disable_layer(sd
, layer
);
479 spin_unlock_irqrestore(&osd
->lock
, flags
);
482 static void _osd_enable_attribute_mode(struct osd_state
*sd
)
484 /* enable attribute mode for OSD1 */
485 osd_set(sd
, OSD_OSDWIN1MD_OASW
, OSD_OSDWIN1MD
);
488 static void _osd_enable_layer(struct osd_state
*sd
, enum osd_layer layer
)
492 osd_set(sd
, OSD_OSDWIN0MD_OACT0
, OSD_OSDWIN0MD
);
495 osd_set(sd
, OSD_VIDWINMD_ACT0
, OSD_VIDWINMD
);
498 /* enable OSD1 and disable attribute mode */
499 osd_modify(sd
, OSD_OSDWIN1MD_OASW
| OSD_OSDWIN1MD_OACT1
,
500 OSD_OSDWIN1MD_OACT1
, OSD_OSDWIN1MD
);
503 osd_set(sd
, OSD_VIDWINMD_ACT1
, OSD_VIDWINMD
);
508 static int osd_enable_layer(struct osd_state
*sd
, enum osd_layer layer
,
511 struct osd_state
*osd
= sd
;
512 struct osd_window_state
*win
= &osd
->win
[layer
];
513 struct osd_layer_config
*cfg
= &win
->lconfig
;
516 spin_lock_irqsave(&osd
->lock
, flags
);
519 * use otherwin flag to know this is the other vid window
520 * in YUV420 mode, if is, skip this check
522 if (!otherwin
&& (!win
->is_allocated
||
523 !win
->fb_base_phys
||
527 spin_unlock_irqrestore(&osd
->lock
, flags
);
531 if (win
->is_enabled
) {
532 spin_unlock_irqrestore(&osd
->lock
, flags
);
537 if (cfg
->pixfmt
!= PIXFMT_OSD_ATTR
)
538 _osd_enable_layer(sd
, layer
);
540 _osd_enable_attribute_mode(sd
);
541 _osd_set_blink_attribute(sd
, osd
->is_blinking
, osd
->blink
);
544 spin_unlock_irqrestore(&osd
->lock
, flags
);
549 #define OSD_SRC_ADDR_HIGH4 0x7800000
550 #define OSD_SRC_ADDR_HIGH7 0x7F0000
551 #define OSD_SRCADD_OFSET_SFT 23
552 #define OSD_SRCADD_ADD_SFT 16
553 #define OSD_WINADL_MASK 0xFFFF
554 #define OSD_WINOFST_MASK 0x1000
555 #define VPBE_REG_BASE 0x80000000
557 static void _osd_start_layer(struct osd_state
*sd
, enum osd_layer layer
,
558 unsigned long fb_base_phys
,
559 unsigned long cbcr_ofst
)
562 if (sd
->vpbe_type
== VPBE_VERSION_1
) {
565 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_OSDWIN0ADR
);
568 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_VIDWIN0ADR
);
571 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_OSDWIN1ADR
);
574 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_VIDWIN1ADR
);
577 } else if (sd
->vpbe_type
== VPBE_VERSION_3
) {
578 unsigned long fb_offset_32
=
579 (fb_base_phys
- VPBE_REG_BASE
) >> 5;
583 osd_modify(sd
, OSD_OSDWINADH_O0AH
,
584 fb_offset_32
>> (OSD_SRCADD_ADD_SFT
-
585 OSD_OSDWINADH_O0AH_SHIFT
),
587 osd_write(sd
, fb_offset_32
& OSD_OSDWIN0ADL_O0AL
,
591 osd_modify(sd
, OSD_VIDWINADH_V0AH
,
592 fb_offset_32
>> (OSD_SRCADD_ADD_SFT
-
593 OSD_VIDWINADH_V0AH_SHIFT
),
595 osd_write(sd
, fb_offset_32
& OSD_VIDWIN0ADL_V0AL
,
599 osd_modify(sd
, OSD_OSDWINADH_O1AH
,
600 fb_offset_32
>> (OSD_SRCADD_ADD_SFT
-
601 OSD_OSDWINADH_O1AH_SHIFT
),
603 osd_write(sd
, fb_offset_32
& OSD_OSDWIN1ADL_O1AL
,
607 osd_modify(sd
, OSD_VIDWINADH_V1AH
,
608 fb_offset_32
>> (OSD_SRCADD_ADD_SFT
-
609 OSD_VIDWINADH_V1AH_SHIFT
),
611 osd_write(sd
, fb_offset_32
& OSD_VIDWIN1ADL_V1AL
,
615 } else if (sd
->vpbe_type
== VPBE_VERSION_2
) {
616 struct osd_window_state
*win
= &sd
->win
[layer
];
617 unsigned long fb_offset_32
, cbcr_offset_32
;
619 fb_offset_32
= fb_base_phys
- VPBE_REG_BASE
;
621 cbcr_offset_32
= cbcr_ofst
;
623 cbcr_offset_32
= win
->lconfig
.line_length
*
625 cbcr_offset_32
+= fb_offset_32
;
626 fb_offset_32
= fb_offset_32
>> 5;
627 cbcr_offset_32
= cbcr_offset_32
>> 5;
629 * DM365: start address is 27-bit long address b26 - b23 are
630 * in offset register b12 - b9, and * bit 26 has to be '1'
632 if (win
->lconfig
.pixfmt
== PIXFMT_NV12
) {
637 osd_modify(sd
, OSD_VIDWIN0OFST_V0AH
,
638 ((fb_offset_32
& OSD_SRC_ADDR_HIGH4
) >>
639 (OSD_SRCADD_OFSET_SFT
-
640 OSD_WINOFST_AH_SHIFT
)) |
641 OSD_WINOFST_MASK
, OSD_VIDWIN0OFST
);
642 osd_modify(sd
, OSD_VIDWINADH_V0AH
,
643 (fb_offset_32
& OSD_SRC_ADDR_HIGH7
) >>
644 (OSD_SRCADD_ADD_SFT
-
645 OSD_VIDWINADH_V0AH_SHIFT
),
647 osd_write(sd
, fb_offset_32
& OSD_WINADL_MASK
,
649 /* CbCr is in VID1 */
650 osd_modify(sd
, OSD_VIDWIN1OFST_V1AH
,
652 OSD_SRC_ADDR_HIGH4
) >>
653 (OSD_SRCADD_OFSET_SFT
-
654 OSD_WINOFST_AH_SHIFT
)) |
655 OSD_WINOFST_MASK
, OSD_VIDWIN1OFST
);
656 osd_modify(sd
, OSD_VIDWINADH_V1AH
,
658 OSD_SRC_ADDR_HIGH7
) >>
659 (OSD_SRCADD_ADD_SFT
-
660 OSD_VIDWINADH_V1AH_SHIFT
),
662 osd_write(sd
, cbcr_offset_32
& OSD_WINADL_MASK
,
672 osd_modify(sd
, OSD_OSDWIN0OFST_O0AH
,
673 ((fb_offset_32
& OSD_SRC_ADDR_HIGH4
) >>
674 (OSD_SRCADD_OFSET_SFT
-
675 OSD_WINOFST_AH_SHIFT
)) | OSD_WINOFST_MASK
,
677 osd_modify(sd
, OSD_OSDWINADH_O0AH
,
678 (fb_offset_32
& OSD_SRC_ADDR_HIGH7
) >>
679 (OSD_SRCADD_ADD_SFT
-
680 OSD_OSDWINADH_O0AH_SHIFT
), OSD_OSDWINADH
);
681 osd_write(sd
, fb_offset_32
& OSD_WINADL_MASK
,
685 if (win
->lconfig
.pixfmt
!= PIXFMT_NV12
) {
686 osd_modify(sd
, OSD_VIDWIN0OFST_V0AH
,
687 ((fb_offset_32
& OSD_SRC_ADDR_HIGH4
) >>
688 (OSD_SRCADD_OFSET_SFT
-
689 OSD_WINOFST_AH_SHIFT
)) |
690 OSD_WINOFST_MASK
, OSD_VIDWIN0OFST
);
691 osd_modify(sd
, OSD_VIDWINADH_V0AH
,
692 (fb_offset_32
& OSD_SRC_ADDR_HIGH7
) >>
693 (OSD_SRCADD_ADD_SFT
-
694 OSD_VIDWINADH_V0AH_SHIFT
),
696 osd_write(sd
, fb_offset_32
& OSD_WINADL_MASK
,
701 osd_modify(sd
, OSD_OSDWIN1OFST_O1AH
,
702 ((fb_offset_32
& OSD_SRC_ADDR_HIGH4
) >>
703 (OSD_SRCADD_OFSET_SFT
-
704 OSD_WINOFST_AH_SHIFT
)) | OSD_WINOFST_MASK
,
706 osd_modify(sd
, OSD_OSDWINADH_O1AH
,
707 (fb_offset_32
& OSD_SRC_ADDR_HIGH7
) >>
708 (OSD_SRCADD_ADD_SFT
-
709 OSD_OSDWINADH_O1AH_SHIFT
),
711 osd_write(sd
, fb_offset_32
& OSD_WINADL_MASK
,
715 if (win
->lconfig
.pixfmt
!= PIXFMT_NV12
) {
716 osd_modify(sd
, OSD_VIDWIN1OFST_V1AH
,
717 ((fb_offset_32
& OSD_SRC_ADDR_HIGH4
) >>
718 (OSD_SRCADD_OFSET_SFT
-
719 OSD_WINOFST_AH_SHIFT
)) |
720 OSD_WINOFST_MASK
, OSD_VIDWIN1OFST
);
721 osd_modify(sd
, OSD_VIDWINADH_V1AH
,
722 (fb_offset_32
& OSD_SRC_ADDR_HIGH7
) >>
723 (OSD_SRCADD_ADD_SFT
-
724 OSD_VIDWINADH_V1AH_SHIFT
),
726 osd_write(sd
, fb_offset_32
& OSD_WINADL_MASK
,
734 static void osd_start_layer(struct osd_state
*sd
, enum osd_layer layer
,
735 unsigned long fb_base_phys
,
736 unsigned long cbcr_ofst
)
738 struct osd_state
*osd
= sd
;
739 struct osd_window_state
*win
= &osd
->win
[layer
];
740 struct osd_layer_config
*cfg
= &win
->lconfig
;
743 spin_lock_irqsave(&osd
->lock
, flags
);
745 win
->fb_base_phys
= fb_base_phys
& ~0x1F;
746 _osd_start_layer(sd
, layer
, fb_base_phys
, cbcr_ofst
);
748 if (layer
== WIN_VID0
) {
750 _osd_dm6446_vid0_pingpong(sd
, osd
->field_inversion
,
755 spin_unlock_irqrestore(&osd
->lock
, flags
);
758 static void osd_get_layer_config(struct osd_state
*sd
, enum osd_layer layer
,
759 struct osd_layer_config
*lconfig
)
761 struct osd_state
*osd
= sd
;
762 struct osd_window_state
*win
= &osd
->win
[layer
];
765 spin_lock_irqsave(&osd
->lock
, flags
);
767 *lconfig
= win
->lconfig
;
769 spin_unlock_irqrestore(&osd
->lock
, flags
);
773 * try_layer_config() - Try a specific configuration for the layer
774 * @sd: ptr to struct osd_state
775 * @layer: layer to configure
776 * @lconfig: layer configuration to try
778 * If the requested lconfig is completely rejected and the value of lconfig on
779 * exit is the current lconfig, then try_layer_config() returns 1. Otherwise,
780 * try_layer_config() returns 0. A return value of 0 does not necessarily mean
781 * that the value of lconfig on exit is identical to the value of lconfig on
782 * entry, but merely that it represents a change from the current lconfig.
784 static int try_layer_config(struct osd_state
*sd
, enum osd_layer layer
,
785 struct osd_layer_config
*lconfig
)
787 struct osd_state
*osd
= sd
;
788 struct osd_window_state
*win
= &osd
->win
[layer
];
791 /* verify that the pixel format is compatible with the layer */
792 switch (lconfig
->pixfmt
) {
798 if (osd
->vpbe_type
== VPBE_VERSION_1
)
799 bad_config
= !is_vid_win(layer
);
803 bad_config
= !is_vid_win(layer
);
806 if (osd
->vpbe_type
== VPBE_VERSION_1
)
807 bad_config
= !is_vid_win(layer
);
808 else if ((osd
->vpbe_type
== VPBE_VERSION_3
) ||
809 (osd
->vpbe_type
== VPBE_VERSION_2
))
810 bad_config
= !is_osd_win(layer
);
813 if (osd
->vpbe_type
!= VPBE_VERSION_2
)
816 bad_config
= is_osd_win(layer
);
818 case PIXFMT_OSD_ATTR
:
819 bad_config
= (layer
!= WIN_OSD1
);
827 * The requested pixel format is incompatible with the layer,
828 * so keep the current layer configuration.
830 *lconfig
= win
->lconfig
;
835 /* only one OSD window at a time can use RGB pixel formats */
836 if ((osd
->vpbe_type
== VPBE_VERSION_1
) &&
837 is_osd_win(layer
) && is_rgb_pixfmt(lconfig
->pixfmt
)) {
838 enum osd_pix_format pixfmt
;
840 if (layer
== WIN_OSD0
)
841 pixfmt
= osd
->win
[WIN_OSD1
].lconfig
.pixfmt
;
843 pixfmt
= osd
->win
[WIN_OSD0
].lconfig
.pixfmt
;
845 if (is_rgb_pixfmt(pixfmt
)) {
847 * The other OSD window is already configured for an
848 * RGB, so keep the current layer configuration.
850 *lconfig
= win
->lconfig
;
855 /* DM6446: only one video window at a time can use RGB888 */
856 if ((osd
->vpbe_type
== VPBE_VERSION_1
) && is_vid_win(layer
) &&
857 lconfig
->pixfmt
== PIXFMT_RGB888
) {
858 enum osd_pix_format pixfmt
;
860 if (layer
== WIN_VID0
)
861 pixfmt
= osd
->win
[WIN_VID1
].lconfig
.pixfmt
;
863 pixfmt
= osd
->win
[WIN_VID0
].lconfig
.pixfmt
;
865 if (pixfmt
== PIXFMT_RGB888
) {
867 * The other video window is already configured for
868 * RGB888, so keep the current layer configuration.
870 *lconfig
= win
->lconfig
;
875 /* window dimensions must be non-zero */
876 if (!lconfig
->line_length
|| !lconfig
->xsize
|| !lconfig
->ysize
) {
877 *lconfig
= win
->lconfig
;
881 /* round line_length up to a multiple of 32 */
882 lconfig
->line_length
= ((lconfig
->line_length
+ 31) / 32) * 32;
883 lconfig
->line_length
=
884 min(lconfig
->line_length
, (unsigned)MAX_LINE_LENGTH
);
885 lconfig
->xsize
= min(lconfig
->xsize
, (unsigned)MAX_WIN_SIZE
);
886 lconfig
->ysize
= min(lconfig
->ysize
, (unsigned)MAX_WIN_SIZE
);
887 lconfig
->xpos
= min(lconfig
->xpos
, (unsigned)MAX_WIN_SIZE
);
888 lconfig
->ypos
= min(lconfig
->ypos
, (unsigned)MAX_WIN_SIZE
);
889 lconfig
->interlaced
= (lconfig
->interlaced
!= 0);
890 if (lconfig
->interlaced
) {
891 /* ysize and ypos must be even for interlaced displays */
892 lconfig
->ysize
&= ~1;
899 static void _osd_disable_vid_rgb888(struct osd_state
*sd
)
902 * The DM6446 supports RGB888 pixel format in a single video window.
903 * This routine disables RGB888 pixel format for both video windows.
904 * The caller must ensure that neither video window is currently
905 * configured for RGB888 pixel format.
907 if (sd
->vpbe_type
== VPBE_VERSION_1
)
908 osd_clear(sd
, OSD_MISCCTL_RGBEN
, OSD_MISCCTL
);
911 static void _osd_enable_vid_rgb888(struct osd_state
*sd
,
912 enum osd_layer layer
)
915 * The DM6446 supports RGB888 pixel format in a single video window.
916 * This routine enables RGB888 pixel format for the specified video
917 * window. The caller must ensure that the other video window is not
918 * currently configured for RGB888 pixel format, as this routine will
919 * disable RGB888 pixel format for the other window.
921 if (sd
->vpbe_type
== VPBE_VERSION_1
) {
922 if (layer
== WIN_VID0
)
923 osd_modify(sd
, OSD_MISCCTL_RGBEN
| OSD_MISCCTL_RGBWIN
,
924 OSD_MISCCTL_RGBEN
, OSD_MISCCTL
);
925 else if (layer
== WIN_VID1
)
926 osd_modify(sd
, OSD_MISCCTL_RGBEN
| OSD_MISCCTL_RGBWIN
,
927 OSD_MISCCTL_RGBEN
| OSD_MISCCTL_RGBWIN
,
932 static void _osd_set_cbcr_order(struct osd_state
*sd
,
933 enum osd_pix_format pixfmt
)
936 * The caller must ensure that all windows using YC pixfmt use the same
939 if (pixfmt
== PIXFMT_YCBCRI
)
940 osd_clear(sd
, OSD_MODE_CS
, OSD_MODE
);
941 else if (pixfmt
== PIXFMT_YCRCBI
)
942 osd_set(sd
, OSD_MODE_CS
, OSD_MODE
);
945 static void _osd_set_layer_config(struct osd_state
*sd
, enum osd_layer layer
,
946 const struct osd_layer_config
*lconfig
)
948 u32 winmd
= 0, winmd_mask
= 0, bmw
= 0;
950 _osd_set_cbcr_order(sd
, lconfig
->pixfmt
);
954 if (sd
->vpbe_type
== VPBE_VERSION_1
) {
955 winmd_mask
|= OSD_OSDWIN0MD_RGB0E
;
956 if (lconfig
->pixfmt
== PIXFMT_RGB565
)
957 winmd
|= OSD_OSDWIN0MD_RGB0E
;
958 } else if ((sd
->vpbe_type
== VPBE_VERSION_3
) ||
959 (sd
->vpbe_type
== VPBE_VERSION_2
)) {
960 winmd_mask
|= OSD_OSDWIN0MD_BMP0MD
;
961 switch (lconfig
->pixfmt
) {
964 OSD_OSDWIN0MD_BMP0MD_SHIFT
);
967 winmd
|= (2 << OSD_OSDWIN0MD_BMP0MD_SHIFT
);
968 _osd_enable_rgb888_pixblend(sd
, OSDWIN_OSD0
);
972 winmd
|= (3 << OSD_OSDWIN0MD_BMP0MD_SHIFT
);
979 winmd_mask
|= OSD_OSDWIN0MD_BMW0
| OSD_OSDWIN0MD_OFF0
;
981 switch (lconfig
->pixfmt
) {
997 winmd
|= (bmw
<< OSD_OSDWIN0MD_BMW0_SHIFT
);
999 if (lconfig
->interlaced
)
1000 winmd
|= OSD_OSDWIN0MD_OFF0
;
1002 osd_modify(sd
, winmd_mask
, winmd
, OSD_OSDWIN0MD
);
1003 osd_write(sd
, lconfig
->line_length
>> 5, OSD_OSDWIN0OFST
);
1004 osd_write(sd
, lconfig
->xpos
, OSD_OSDWIN0XP
);
1005 osd_write(sd
, lconfig
->xsize
, OSD_OSDWIN0XL
);
1006 if (lconfig
->interlaced
) {
1007 osd_write(sd
, lconfig
->ypos
>> 1, OSD_OSDWIN0YP
);
1008 osd_write(sd
, lconfig
->ysize
>> 1, OSD_OSDWIN0YL
);
1010 osd_write(sd
, lconfig
->ypos
, OSD_OSDWIN0YP
);
1011 osd_write(sd
, lconfig
->ysize
, OSD_OSDWIN0YL
);
1015 winmd_mask
|= OSD_VIDWINMD_VFF0
;
1016 if (lconfig
->interlaced
)
1017 winmd
|= OSD_VIDWINMD_VFF0
;
1019 osd_modify(sd
, winmd_mask
, winmd
, OSD_VIDWINMD
);
1020 osd_write(sd
, lconfig
->line_length
>> 5, OSD_VIDWIN0OFST
);
1021 osd_write(sd
, lconfig
->xpos
, OSD_VIDWIN0XP
);
1022 osd_write(sd
, lconfig
->xsize
, OSD_VIDWIN0XL
);
1024 * For YUV420P format the register contents are
1025 * duplicated in both VID registers
1027 if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1028 (lconfig
->pixfmt
== PIXFMT_NV12
)) {
1029 /* other window also */
1030 if (lconfig
->interlaced
) {
1031 winmd_mask
|= OSD_VIDWINMD_VFF1
;
1032 winmd
|= OSD_VIDWINMD_VFF1
;
1033 osd_modify(sd
, winmd_mask
, winmd
,
1037 osd_modify(sd
, OSD_MISCCTL_S420D
,
1038 OSD_MISCCTL_S420D
, OSD_MISCCTL
);
1039 osd_write(sd
, lconfig
->line_length
>> 5,
1041 osd_write(sd
, lconfig
->xpos
, OSD_VIDWIN1XP
);
1042 osd_write(sd
, lconfig
->xsize
, OSD_VIDWIN1XL
);
1044 * if NV21 pixfmt and line length not 32B
1045 * aligned (e.g. NTSC), Need to set window
1046 * X pixel size to be 32B aligned as well
1048 if (lconfig
->xsize
% 32) {
1050 ((lconfig
->xsize
+ 31) & ~31),
1053 ((lconfig
->xsize
+ 31) & ~31),
1056 } else if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1057 (lconfig
->pixfmt
!= PIXFMT_NV12
)) {
1058 osd_modify(sd
, OSD_MISCCTL_S420D
, ~OSD_MISCCTL_S420D
,
1062 if (lconfig
->interlaced
) {
1063 osd_write(sd
, lconfig
->ypos
>> 1, OSD_VIDWIN0YP
);
1064 osd_write(sd
, lconfig
->ysize
>> 1, OSD_VIDWIN0YL
);
1065 if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1066 lconfig
->pixfmt
== PIXFMT_NV12
) {
1067 osd_write(sd
, lconfig
->ypos
>> 1,
1069 osd_write(sd
, lconfig
->ysize
>> 1,
1073 osd_write(sd
, lconfig
->ypos
, OSD_VIDWIN0YP
);
1074 osd_write(sd
, lconfig
->ysize
, OSD_VIDWIN0YL
);
1075 if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1076 lconfig
->pixfmt
== PIXFMT_NV12
) {
1077 osd_write(sd
, lconfig
->ypos
, OSD_VIDWIN1YP
);
1078 osd_write(sd
, lconfig
->ysize
, OSD_VIDWIN1YL
);
1084 * The caller must ensure that OSD1 is disabled prior to
1085 * switching from a normal mode to attribute mode or from
1086 * attribute mode to a normal mode.
1088 if (lconfig
->pixfmt
== PIXFMT_OSD_ATTR
) {
1089 if (sd
->vpbe_type
== VPBE_VERSION_1
) {
1090 winmd_mask
|= OSD_OSDWIN1MD_ATN1E
|
1091 OSD_OSDWIN1MD_RGB1E
| OSD_OSDWIN1MD_CLUTS1
|
1092 OSD_OSDWIN1MD_BLND1
| OSD_OSDWIN1MD_TE1
;
1094 winmd_mask
|= OSD_OSDWIN1MD_BMP1MD
|
1095 OSD_OSDWIN1MD_CLUTS1
| OSD_OSDWIN1MD_BLND1
|
1099 if (sd
->vpbe_type
== VPBE_VERSION_1
) {
1100 winmd_mask
|= OSD_OSDWIN1MD_RGB1E
;
1101 if (lconfig
->pixfmt
== PIXFMT_RGB565
)
1102 winmd
|= OSD_OSDWIN1MD_RGB1E
;
1103 } else if ((sd
->vpbe_type
== VPBE_VERSION_3
)
1104 || (sd
->vpbe_type
== VPBE_VERSION_2
)) {
1105 winmd_mask
|= OSD_OSDWIN1MD_BMP1MD
;
1106 switch (lconfig
->pixfmt
) {
1109 (1 << OSD_OSDWIN1MD_BMP1MD_SHIFT
);
1113 (2 << OSD_OSDWIN1MD_BMP1MD_SHIFT
);
1114 _osd_enable_rgb888_pixblend(sd
,
1120 (3 << OSD_OSDWIN1MD_BMP1MD_SHIFT
);
1127 winmd_mask
|= OSD_OSDWIN1MD_BMW1
;
1128 switch (lconfig
->pixfmt
) {
1144 winmd
|= (bmw
<< OSD_OSDWIN1MD_BMW1_SHIFT
);
1147 winmd_mask
|= OSD_OSDWIN1MD_OFF1
;
1148 if (lconfig
->interlaced
)
1149 winmd
|= OSD_OSDWIN1MD_OFF1
;
1151 osd_modify(sd
, winmd_mask
, winmd
, OSD_OSDWIN1MD
);
1152 osd_write(sd
, lconfig
->line_length
>> 5, OSD_OSDWIN1OFST
);
1153 osd_write(sd
, lconfig
->xpos
, OSD_OSDWIN1XP
);
1154 osd_write(sd
, lconfig
->xsize
, OSD_OSDWIN1XL
);
1155 if (lconfig
->interlaced
) {
1156 osd_write(sd
, lconfig
->ypos
>> 1, OSD_OSDWIN1YP
);
1157 osd_write(sd
, lconfig
->ysize
>> 1, OSD_OSDWIN1YL
);
1159 osd_write(sd
, lconfig
->ypos
, OSD_OSDWIN1YP
);
1160 osd_write(sd
, lconfig
->ysize
, OSD_OSDWIN1YL
);
1164 winmd_mask
|= OSD_VIDWINMD_VFF1
;
1165 if (lconfig
->interlaced
)
1166 winmd
|= OSD_VIDWINMD_VFF1
;
1168 osd_modify(sd
, winmd_mask
, winmd
, OSD_VIDWINMD
);
1169 osd_write(sd
, lconfig
->line_length
>> 5, OSD_VIDWIN1OFST
);
1170 osd_write(sd
, lconfig
->xpos
, OSD_VIDWIN1XP
);
1171 osd_write(sd
, lconfig
->xsize
, OSD_VIDWIN1XL
);
1173 * For YUV420P format the register contents are
1174 * duplicated in both VID registers
1176 if (sd
->vpbe_type
== VPBE_VERSION_2
) {
1177 if (lconfig
->pixfmt
== PIXFMT_NV12
) {
1178 /* other window also */
1179 if (lconfig
->interlaced
) {
1180 winmd_mask
|= OSD_VIDWINMD_VFF0
;
1181 winmd
|= OSD_VIDWINMD_VFF0
;
1182 osd_modify(sd
, winmd_mask
, winmd
,
1185 osd_modify(sd
, OSD_MISCCTL_S420D
,
1186 OSD_MISCCTL_S420D
, OSD_MISCCTL
);
1187 osd_write(sd
, lconfig
->line_length
>> 5,
1189 osd_write(sd
, lconfig
->xpos
, OSD_VIDWIN0XP
);
1190 osd_write(sd
, lconfig
->xsize
, OSD_VIDWIN0XL
);
1192 osd_modify(sd
, OSD_MISCCTL_S420D
,
1193 ~OSD_MISCCTL_S420D
, OSD_MISCCTL
);
1197 if (lconfig
->interlaced
) {
1198 osd_write(sd
, lconfig
->ypos
>> 1, OSD_VIDWIN1YP
);
1199 osd_write(sd
, lconfig
->ysize
>> 1, OSD_VIDWIN1YL
);
1200 if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1201 lconfig
->pixfmt
== PIXFMT_NV12
) {
1202 osd_write(sd
, lconfig
->ypos
>> 1,
1204 osd_write(sd
, lconfig
->ysize
>> 1,
1208 osd_write(sd
, lconfig
->ypos
, OSD_VIDWIN1YP
);
1209 osd_write(sd
, lconfig
->ysize
, OSD_VIDWIN1YL
);
1210 if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1211 lconfig
->pixfmt
== PIXFMT_NV12
) {
1212 osd_write(sd
, lconfig
->ypos
, OSD_VIDWIN0YP
);
1213 osd_write(sd
, lconfig
->ysize
, OSD_VIDWIN0YL
);
1220 static int osd_set_layer_config(struct osd_state
*sd
, enum osd_layer layer
,
1221 struct osd_layer_config
*lconfig
)
1223 struct osd_state
*osd
= sd
;
1224 struct osd_window_state
*win
= &osd
->win
[layer
];
1225 struct osd_layer_config
*cfg
= &win
->lconfig
;
1226 unsigned long flags
;
1229 spin_lock_irqsave(&osd
->lock
, flags
);
1231 reject_config
= try_layer_config(sd
, layer
, lconfig
);
1232 if (reject_config
) {
1233 spin_unlock_irqrestore(&osd
->lock
, flags
);
1234 return reject_config
;
1237 /* update the current Cb/Cr order */
1238 if (is_yc_pixfmt(lconfig
->pixfmt
))
1239 osd
->yc_pixfmt
= lconfig
->pixfmt
;
1242 * If we are switching OSD1 from normal mode to attribute mode or from
1243 * attribute mode to normal mode, then we must disable the window.
1245 if (layer
== WIN_OSD1
) {
1246 if (((lconfig
->pixfmt
== PIXFMT_OSD_ATTR
) &&
1247 (cfg
->pixfmt
!= PIXFMT_OSD_ATTR
)) ||
1248 ((lconfig
->pixfmt
!= PIXFMT_OSD_ATTR
) &&
1249 (cfg
->pixfmt
== PIXFMT_OSD_ATTR
))) {
1250 win
->is_enabled
= 0;
1251 _osd_disable_layer(sd
, layer
);
1255 _osd_set_layer_config(sd
, layer
, lconfig
);
1257 if (layer
== WIN_OSD1
) {
1258 struct osd_osdwin_state
*osdwin_state
=
1259 &osd
->osdwin
[OSDWIN_OSD1
];
1261 if ((lconfig
->pixfmt
!= PIXFMT_OSD_ATTR
) &&
1262 (cfg
->pixfmt
== PIXFMT_OSD_ATTR
)) {
1264 * We just switched OSD1 from attribute mode to normal
1265 * mode, so we must initialize the CLUT select, the
1266 * blend factor, transparency colorkey enable, and
1267 * attenuation enable (DM6446 only) bits in the
1268 * OSDWIN1MD register.
1270 _osd_set_osd_clut(sd
, OSDWIN_OSD1
,
1271 osdwin_state
->clut
);
1272 _osd_set_blending_factor(sd
, OSDWIN_OSD1
,
1273 osdwin_state
->blend
);
1274 if (osdwin_state
->colorkey_blending
) {
1275 _osd_enable_color_key(sd
, OSDWIN_OSD1
,
1280 _osd_disable_color_key(sd
, OSDWIN_OSD1
);
1281 _osd_set_rec601_attenuation(sd
, OSDWIN_OSD1
,
1283 rec601_attenuation
);
1284 } else if ((lconfig
->pixfmt
== PIXFMT_OSD_ATTR
) &&
1285 (cfg
->pixfmt
!= PIXFMT_OSD_ATTR
)) {
1287 * We just switched OSD1 from normal mode to attribute
1288 * mode, so we must initialize the blink enable and
1289 * blink interval bits in the OSDATRMD register.
1291 _osd_set_blink_attribute(sd
, osd
->is_blinking
,
1297 * If we just switched to a 1-, 2-, or 4-bits-per-pixel bitmap format
1298 * then configure a default palette map.
1300 if ((lconfig
->pixfmt
!= cfg
->pixfmt
) &&
1301 ((lconfig
->pixfmt
== PIXFMT_1BPP
) ||
1302 (lconfig
->pixfmt
== PIXFMT_2BPP
) ||
1303 (lconfig
->pixfmt
== PIXFMT_4BPP
))) {
1304 enum osd_win_layer osdwin
=
1305 ((layer
== WIN_OSD0
) ? OSDWIN_OSD0
: OSDWIN_OSD1
);
1306 struct osd_osdwin_state
*osdwin_state
=
1307 &osd
->osdwin
[osdwin
];
1308 unsigned char clut_index
;
1309 unsigned char clut_entries
= 0;
1311 switch (lconfig
->pixfmt
) {
1325 * The default palette map maps the pixel value to the clut
1326 * index, i.e. pixel value 0 maps to clut entry 0, pixel value
1327 * 1 maps to clut entry 1, etc.
1329 for (clut_index
= 0; clut_index
< 16; clut_index
++) {
1330 osdwin_state
->palette_map
[clut_index
] = clut_index
;
1331 if (clut_index
< clut_entries
) {
1332 _osd_set_palette_map(sd
, osdwin
, clut_index
,
1340 /* DM6446: configure the RGB888 enable and window selection */
1341 if (osd
->win
[WIN_VID0
].lconfig
.pixfmt
== PIXFMT_RGB888
)
1342 _osd_enable_vid_rgb888(sd
, WIN_VID0
);
1343 else if (osd
->win
[WIN_VID1
].lconfig
.pixfmt
== PIXFMT_RGB888
)
1344 _osd_enable_vid_rgb888(sd
, WIN_VID1
);
1346 _osd_disable_vid_rgb888(sd
);
1348 if (layer
== WIN_VID0
) {
1350 _osd_dm6446_vid0_pingpong(sd
, osd
->field_inversion
,
1355 spin_unlock_irqrestore(&osd
->lock
, flags
);
1360 static void osd_init_layer(struct osd_state
*sd
, enum osd_layer layer
)
1362 struct osd_state
*osd
= sd
;
1363 struct osd_window_state
*win
= &osd
->win
[layer
];
1364 enum osd_win_layer osdwin
;
1365 struct osd_osdwin_state
*osdwin_state
;
1366 struct osd_layer_config
*cfg
= &win
->lconfig
;
1367 unsigned long flags
;
1369 spin_lock_irqsave(&osd
->lock
, flags
);
1371 win
->is_enabled
= 0;
1372 _osd_disable_layer(sd
, layer
);
1374 win
->h_zoom
= ZOOM_X1
;
1375 win
->v_zoom
= ZOOM_X1
;
1376 _osd_set_zoom(sd
, layer
, win
->h_zoom
, win
->v_zoom
);
1378 win
->fb_base_phys
= 0;
1379 _osd_start_layer(sd
, layer
, win
->fb_base_phys
, 0);
1381 cfg
->line_length
= 0;
1386 cfg
->interlaced
= 0;
1390 osdwin
= (layer
== WIN_OSD0
) ? OSDWIN_OSD0
: OSDWIN_OSD1
;
1391 osdwin_state
= &osd
->osdwin
[osdwin
];
1393 * Other code relies on the fact that OSD windows default to a
1394 * bitmap pixel format when they are deallocated, so don't
1395 * change this default pixel format.
1397 cfg
->pixfmt
= PIXFMT_8BPP
;
1398 _osd_set_layer_config(sd
, layer
, cfg
);
1399 osdwin_state
->clut
= RAM_CLUT
;
1400 _osd_set_osd_clut(sd
, osdwin
, osdwin_state
->clut
);
1401 osdwin_state
->colorkey_blending
= 0;
1402 _osd_disable_color_key(sd
, osdwin
);
1403 osdwin_state
->blend
= OSD_8_VID_0
;
1404 _osd_set_blending_factor(sd
, osdwin
, osdwin_state
->blend
);
1405 osdwin_state
->rec601_attenuation
= 0;
1406 _osd_set_rec601_attenuation(sd
, osdwin
,
1408 rec601_attenuation
);
1409 if (osdwin
== OSDWIN_OSD1
) {
1410 osd
->is_blinking
= 0;
1411 osd
->blink
= BLINK_X1
;
1416 cfg
->pixfmt
= osd
->yc_pixfmt
;
1417 _osd_set_layer_config(sd
, layer
, cfg
);
1421 spin_unlock_irqrestore(&osd
->lock
, flags
);
1424 static void osd_release_layer(struct osd_state
*sd
, enum osd_layer layer
)
1426 struct osd_state
*osd
= sd
;
1427 struct osd_window_state
*win
= &osd
->win
[layer
];
1428 unsigned long flags
;
1430 spin_lock_irqsave(&osd
->lock
, flags
);
1432 if (!win
->is_allocated
) {
1433 spin_unlock_irqrestore(&osd
->lock
, flags
);
1437 spin_unlock_irqrestore(&osd
->lock
, flags
);
1438 osd_init_layer(sd
, layer
);
1439 spin_lock_irqsave(&osd
->lock
, flags
);
1441 win
->is_allocated
= 0;
1443 spin_unlock_irqrestore(&osd
->lock
, flags
);
1446 static int osd_request_layer(struct osd_state
*sd
, enum osd_layer layer
)
1448 struct osd_state
*osd
= sd
;
1449 struct osd_window_state
*win
= &osd
->win
[layer
];
1450 unsigned long flags
;
1452 spin_lock_irqsave(&osd
->lock
, flags
);
1454 if (win
->is_allocated
) {
1455 spin_unlock_irqrestore(&osd
->lock
, flags
);
1458 win
->is_allocated
= 1;
1460 spin_unlock_irqrestore(&osd
->lock
, flags
);
1465 static void _osd_init(struct osd_state
*sd
)
1467 osd_write(sd
, 0, OSD_MODE
);
1468 osd_write(sd
, 0, OSD_VIDWINMD
);
1469 osd_write(sd
, 0, OSD_OSDWIN0MD
);
1470 osd_write(sd
, 0, OSD_OSDWIN1MD
);
1471 osd_write(sd
, 0, OSD_RECTCUR
);
1472 osd_write(sd
, 0, OSD_MISCCTL
);
1473 if (sd
->vpbe_type
== VPBE_VERSION_3
) {
1474 osd_write(sd
, 0, OSD_VBNDRY
);
1475 osd_write(sd
, 0, OSD_EXTMODE
);
1476 osd_write(sd
, OSD_MISCCTL_DMANG
, OSD_MISCCTL
);
1480 static void osd_set_left_margin(struct osd_state
*sd
, u32 val
)
1482 osd_write(sd
, val
, OSD_BASEPX
);
1485 static void osd_set_top_margin(struct osd_state
*sd
, u32 val
)
1487 osd_write(sd
, val
, OSD_BASEPY
);
1490 static int osd_initialize(struct osd_state
*osd
)
1496 /* set default Cb/Cr order */
1497 osd
->yc_pixfmt
= PIXFMT_YCBCRI
;
1499 if (osd
->vpbe_type
== VPBE_VERSION_3
) {
1501 * ROM CLUT1 on the DM355 is similar (identical?) to ROM CLUT0
1502 * on the DM6446, so make ROM_CLUT1 the default on the DM355.
1504 osd
->rom_clut
= ROM_CLUT1
;
1507 _osd_set_field_inversion(osd
, osd
->field_inversion
);
1508 _osd_set_rom_clut(osd
, osd
->rom_clut
);
1510 osd_init_layer(osd
, WIN_OSD0
);
1511 osd_init_layer(osd
, WIN_VID0
);
1512 osd_init_layer(osd
, WIN_OSD1
);
1513 osd_init_layer(osd
, WIN_VID1
);
1518 static const struct vpbe_osd_ops osd_ops
= {
1519 .initialize
= osd_initialize
,
1520 .request_layer
= osd_request_layer
,
1521 .release_layer
= osd_release_layer
,
1522 .enable_layer
= osd_enable_layer
,
1523 .disable_layer
= osd_disable_layer
,
1524 .set_layer_config
= osd_set_layer_config
,
1525 .get_layer_config
= osd_get_layer_config
,
1526 .start_layer
= osd_start_layer
,
1527 .set_left_margin
= osd_set_left_margin
,
1528 .set_top_margin
= osd_set_top_margin
,
1531 static int osd_probe(struct platform_device
*pdev
)
1533 const struct platform_device_id
*pdev_id
;
1534 struct osd_state
*osd
;
1535 struct resource
*res
;
1537 pdev_id
= platform_get_device_id(pdev
);
1541 osd
= devm_kzalloc(&pdev
->dev
, sizeof(struct osd_state
), GFP_KERNEL
);
1546 osd
->dev
= &pdev
->dev
;
1547 osd
->vpbe_type
= pdev_id
->driver_data
;
1549 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1550 osd
->osd_base
= devm_ioremap_resource(&pdev
->dev
, res
);
1551 if (IS_ERR(osd
->osd_base
))
1552 return PTR_ERR(osd
->osd_base
);
1554 osd
->osd_base_phys
= res
->start
;
1555 osd
->osd_size
= resource_size(res
);
1556 spin_lock_init(&osd
->lock
);
1558 platform_set_drvdata(pdev
, osd
);
1559 dev_notice(osd
->dev
, "OSD sub device probe success\n");
1564 static int osd_remove(struct platform_device
*pdev
)
1569 static struct platform_driver osd_driver
= {
1571 .remove
= osd_remove
,
1573 .name
= MODULE_NAME
,
1575 .id_table
= vpbe_osd_devtype
1578 module_platform_driver(osd_driver
);
1580 MODULE_LICENSE("GPL");
1581 MODULE_DESCRIPTION("DaVinci OSD Manager Driver");
1582 MODULE_AUTHOR("Texas Instruments");