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.
20 #include <linux/module.h>
21 #include <linux/mod_devicetable.h>
22 #include <linux/kernel.h>
23 #include <linux/interrupt.h>
24 #include <linux/platform_device.h>
25 #include <linux/clk.h>
26 #include <linux/slab.h>
28 #ifdef CONFIG_ARCH_DAVINCI
29 #include <mach/cputype.h>
30 #include <mach/hardware.h>
33 #include <media/davinci/vpss.h>
34 #include <media/v4l2-device.h>
35 #include <media/davinci/vpbe_types.h>
36 #include <media/davinci/vpbe_osd.h>
39 #include "vpbe_osd_regs.h"
41 #define MODULE_NAME "davinci-vpbe-osd"
43 static const struct platform_device_id vpbe_osd_devtype
[] = {
45 .name
= DM644X_VPBE_OSD_SUBDEV_NAME
,
46 .driver_data
= VPBE_VERSION_1
,
48 .name
= DM365_VPBE_OSD_SUBDEV_NAME
,
49 .driver_data
= VPBE_VERSION_2
,
51 .name
= DM355_VPBE_OSD_SUBDEV_NAME
,
52 .driver_data
= VPBE_VERSION_3
,
59 MODULE_DEVICE_TABLE(platform
, vpbe_osd_devtype
);
61 /* register access routines */
62 static inline u32
osd_read(struct osd_state
*sd
, u32 offset
)
64 struct osd_state
*osd
= sd
;
66 return readl(osd
->osd_base
+ offset
);
69 static inline u32
osd_write(struct osd_state
*sd
, u32 val
, u32 offset
)
71 struct osd_state
*osd
= sd
;
73 writel(val
, osd
->osd_base
+ offset
);
78 static inline u32
osd_set(struct osd_state
*sd
, u32 mask
, u32 offset
)
80 struct osd_state
*osd
= sd
;
82 void __iomem
*addr
= osd
->osd_base
+ offset
;
83 u32 val
= readl(addr
) | mask
;
90 static inline u32
osd_clear(struct osd_state
*sd
, u32 mask
, u32 offset
)
92 struct osd_state
*osd
= sd
;
94 void __iomem
*addr
= osd
->osd_base
+ offset
;
95 u32 val
= readl(addr
) & ~mask
;
102 static inline u32
osd_modify(struct osd_state
*sd
, u32 mask
, u32 val
,
105 struct osd_state
*osd
= sd
;
107 void __iomem
*addr
= osd
->osd_base
+ offset
;
108 u32 new_val
= (readl(addr
) & ~mask
) | (val
& mask
);
110 writel(new_val
, addr
);
115 /* define some macros for layer and pixfmt classification */
116 #define is_osd_win(layer) (((layer) == WIN_OSD0) || ((layer) == WIN_OSD1))
117 #define is_vid_win(layer) (((layer) == WIN_VID0) || ((layer) == WIN_VID1))
118 #define is_rgb_pixfmt(pixfmt) \
119 (((pixfmt) == PIXFMT_RGB565) || ((pixfmt) == PIXFMT_RGB888))
120 #define is_yc_pixfmt(pixfmt) \
121 (((pixfmt) == PIXFMT_YCBCRI) || ((pixfmt) == PIXFMT_YCRCBI) || \
122 ((pixfmt) == PIXFMT_NV12))
123 #define MAX_WIN_SIZE OSD_VIDWIN0XP_V0X
124 #define MAX_LINE_LENGTH (OSD_VIDWIN0OFST_V0LO << 5)
127 * _osd_dm6446_vid0_pingpong() - field inversion fix for DM6446
128 * @sd: ptr to struct osd_state
129 * @field_inversion: inversion flag
130 * @fb_base_phys: frame buffer address
131 * @lconfig: ptr to layer config
133 * This routine implements a workaround for the field signal inversion silicon
134 * erratum described in Advisory 1.3.8 for the DM6446. The fb_base_phys and
135 * lconfig parameters apply to the vid0 window. This routine should be called
136 * whenever the vid0 layer configuration or start address is modified, or when
137 * the OSD field inversion setting is modified.
138 * Returns: 1 if the ping-pong buffers need to be toggled in the vsync isr, or
141 static int _osd_dm6446_vid0_pingpong(struct osd_state
*sd
,
143 unsigned long fb_base_phys
,
144 const struct osd_layer_config
*lconfig
)
146 struct osd_platform_data
*pdata
;
148 pdata
= (struct osd_platform_data
*)sd
->dev
->platform_data
;
149 if (pdata
!= NULL
&& pdata
->field_inv_wa_enable
) {
151 if (!field_inversion
|| !lconfig
->interlaced
) {
152 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_VIDWIN0ADR
);
153 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_PPVWIN0ADR
);
154 osd_modify(sd
, OSD_MISCCTL_PPSW
| OSD_MISCCTL_PPRV
, 0,
158 unsigned miscctl
= OSD_MISCCTL_PPRV
;
161 (fb_base_phys
& ~0x1F) - lconfig
->line_length
,
164 (fb_base_phys
& ~0x1F) + lconfig
->line_length
,
167 OSD_MISCCTL_PPSW
| OSD_MISCCTL_PPRV
, miscctl
,
177 static void _osd_set_field_inversion(struct osd_state
*sd
, int enable
)
182 fsinv
= OSD_MODE_FSINV
;
184 osd_modify(sd
, OSD_MODE_FSINV
, fsinv
, OSD_MODE
);
187 static void _osd_set_blink_attribute(struct osd_state
*sd
, int enable
,
188 enum osd_blink_interval blink
)
193 osdatrmd
|= OSD_OSDATRMD_BLNK
;
194 osdatrmd
|= blink
<< OSD_OSDATRMD_BLNKINT_SHIFT
;
196 /* caller must ensure that OSD1 is configured in attribute mode */
197 osd_modify(sd
, OSD_OSDATRMD_BLNKINT
| OSD_OSDATRMD_BLNK
, osdatrmd
,
201 static void _osd_set_rom_clut(struct osd_state
*sd
,
202 enum osd_rom_clut rom_clut
)
204 if (rom_clut
== ROM_CLUT0
)
205 osd_clear(sd
, OSD_MISCCTL_RSEL
, OSD_MISCCTL
);
207 osd_set(sd
, OSD_MISCCTL_RSEL
, OSD_MISCCTL
);
210 static void _osd_set_palette_map(struct osd_state
*sd
,
211 enum osd_win_layer osdwin
,
212 unsigned char pixel_value
,
213 unsigned char clut_index
,
214 enum osd_pix_format pixfmt
)
216 static const int map_2bpp
[] = { 0, 5, 10, 15 };
217 static const int map_1bpp
[] = { 0, 15 };
225 bmp_reg
= map_1bpp
[pixel_value
& 0x1];
228 bmp_reg
= map_2bpp
[pixel_value
& 0x3];
231 bmp_reg
= pixel_value
& 0xf;
239 bmp_offset
= OSD_W0BMP01
+ (bmp_reg
>> 1) * sizeof(u32
);
242 bmp_offset
= OSD_W1BMP01
+ (bmp_reg
>> 1) * sizeof(u32
);
250 bmp_mask
= 0xff << 8;
256 osd_modify(sd
, bmp_mask
, clut_index
<< bmp_shift
, bmp_offset
);
259 static void _osd_set_rec601_attenuation(struct osd_state
*sd
,
260 enum osd_win_layer osdwin
, int enable
)
264 osd_modify(sd
, OSD_OSDWIN0MD_ATN0E
,
265 enable
? OSD_OSDWIN0MD_ATN0E
: 0,
267 if (sd
->vpbe_type
== VPBE_VERSION_1
)
268 osd_modify(sd
, OSD_OSDWIN0MD_ATN0E
,
269 enable
? OSD_OSDWIN0MD_ATN0E
: 0,
271 else if ((sd
->vpbe_type
== VPBE_VERSION_3
) ||
272 (sd
->vpbe_type
== VPBE_VERSION_2
))
273 osd_modify(sd
, OSD_EXTMODE_ATNOSD0EN
,
274 enable
? OSD_EXTMODE_ATNOSD0EN
: 0,
278 osd_modify(sd
, OSD_OSDWIN1MD_ATN1E
,
279 enable
? OSD_OSDWIN1MD_ATN1E
: 0,
281 if (sd
->vpbe_type
== VPBE_VERSION_1
)
282 osd_modify(sd
, OSD_OSDWIN1MD_ATN1E
,
283 enable
? OSD_OSDWIN1MD_ATN1E
: 0,
285 else if ((sd
->vpbe_type
== VPBE_VERSION_3
) ||
286 (sd
->vpbe_type
== VPBE_VERSION_2
))
287 osd_modify(sd
, OSD_EXTMODE_ATNOSD1EN
,
288 enable
? OSD_EXTMODE_ATNOSD1EN
: 0,
294 static void _osd_set_blending_factor(struct osd_state
*sd
,
295 enum osd_win_layer osdwin
,
296 enum osd_blending_factor blend
)
300 osd_modify(sd
, OSD_OSDWIN0MD_BLND0
,
301 blend
<< OSD_OSDWIN0MD_BLND0_SHIFT
, OSD_OSDWIN0MD
);
304 osd_modify(sd
, OSD_OSDWIN1MD_BLND1
,
305 blend
<< OSD_OSDWIN1MD_BLND1_SHIFT
, OSD_OSDWIN1MD
);
310 static void _osd_enable_rgb888_pixblend(struct osd_state
*sd
,
311 enum osd_win_layer osdwin
)
314 osd_modify(sd
, OSD_MISCCTL_BLDSEL
, 0, OSD_MISCCTL
);
317 osd_modify(sd
, OSD_EXTMODE_OSD0BLDCHR
,
318 OSD_EXTMODE_OSD0BLDCHR
, OSD_EXTMODE
);
321 osd_modify(sd
, OSD_EXTMODE_OSD1BLDCHR
,
322 OSD_EXTMODE_OSD1BLDCHR
, OSD_EXTMODE
);
327 static void _osd_enable_color_key(struct osd_state
*sd
,
328 enum osd_win_layer osdwin
,
330 enum osd_pix_format pixfmt
)
337 if (sd
->vpbe_type
== VPBE_VERSION_3
) {
340 osd_modify(sd
, OSD_TRANSPBMPIDX_BMP0
,
342 OSD_TRANSPBMPIDX_BMP0_SHIFT
,
346 osd_modify(sd
, OSD_TRANSPBMPIDX_BMP1
,
348 OSD_TRANSPBMPIDX_BMP1_SHIFT
,
355 if (sd
->vpbe_type
== VPBE_VERSION_1
)
356 osd_write(sd
, colorkey
& OSD_TRANSPVAL_RGBTRANS
,
358 else if (sd
->vpbe_type
== VPBE_VERSION_3
)
359 osd_write(sd
, colorkey
& OSD_TRANSPVALL_RGBL
,
364 if (sd
->vpbe_type
== VPBE_VERSION_3
)
365 osd_modify(sd
, OSD_TRANSPVALU_Y
, colorkey
,
369 if (sd
->vpbe_type
== VPBE_VERSION_3
) {
370 osd_write(sd
, colorkey
& OSD_TRANSPVALL_RGBL
,
372 osd_modify(sd
, OSD_TRANSPVALU_RGBU
, colorkey
>> 16,
382 osd_set(sd
, OSD_OSDWIN0MD_TE0
, OSD_OSDWIN0MD
);
385 osd_set(sd
, OSD_OSDWIN1MD_TE1
, OSD_OSDWIN1MD
);
390 static void _osd_disable_color_key(struct osd_state
*sd
,
391 enum osd_win_layer osdwin
)
395 osd_clear(sd
, OSD_OSDWIN0MD_TE0
, OSD_OSDWIN0MD
);
398 osd_clear(sd
, OSD_OSDWIN1MD_TE1
, OSD_OSDWIN1MD
);
403 static void _osd_set_osd_clut(struct osd_state
*sd
,
404 enum osd_win_layer osdwin
,
411 if (clut
== RAM_CLUT
)
412 winmd
|= OSD_OSDWIN0MD_CLUTS0
;
413 osd_modify(sd
, OSD_OSDWIN0MD_CLUTS0
, winmd
, OSD_OSDWIN0MD
);
416 if (clut
== RAM_CLUT
)
417 winmd
|= OSD_OSDWIN1MD_CLUTS1
;
418 osd_modify(sd
, OSD_OSDWIN1MD_CLUTS1
, winmd
, OSD_OSDWIN1MD
);
423 static void _osd_set_zoom(struct osd_state
*sd
, enum osd_layer layer
,
424 enum osd_zoom_factor h_zoom
,
425 enum osd_zoom_factor v_zoom
)
431 winmd
|= (h_zoom
<< OSD_OSDWIN0MD_OHZ0_SHIFT
);
432 winmd
|= (v_zoom
<< OSD_OSDWIN0MD_OVZ0_SHIFT
);
433 osd_modify(sd
, OSD_OSDWIN0MD_OHZ0
| OSD_OSDWIN0MD_OVZ0
, winmd
,
437 winmd
|= (h_zoom
<< OSD_VIDWINMD_VHZ0_SHIFT
);
438 winmd
|= (v_zoom
<< OSD_VIDWINMD_VVZ0_SHIFT
);
439 osd_modify(sd
, OSD_VIDWINMD_VHZ0
| OSD_VIDWINMD_VVZ0
, winmd
,
443 winmd
|= (h_zoom
<< OSD_OSDWIN1MD_OHZ1_SHIFT
);
444 winmd
|= (v_zoom
<< OSD_OSDWIN1MD_OVZ1_SHIFT
);
445 osd_modify(sd
, OSD_OSDWIN1MD_OHZ1
| OSD_OSDWIN1MD_OVZ1
, winmd
,
449 winmd
|= (h_zoom
<< OSD_VIDWINMD_VHZ1_SHIFT
);
450 winmd
|= (v_zoom
<< OSD_VIDWINMD_VVZ1_SHIFT
);
451 osd_modify(sd
, OSD_VIDWINMD_VHZ1
| OSD_VIDWINMD_VVZ1
, winmd
,
457 static void _osd_disable_layer(struct osd_state
*sd
, enum osd_layer layer
)
461 osd_clear(sd
, OSD_OSDWIN0MD_OACT0
, OSD_OSDWIN0MD
);
464 osd_clear(sd
, OSD_VIDWINMD_ACT0
, OSD_VIDWINMD
);
467 /* disable attribute mode as well as disabling the window */
468 osd_clear(sd
, OSD_OSDWIN1MD_OASW
| OSD_OSDWIN1MD_OACT1
,
472 osd_clear(sd
, OSD_VIDWINMD_ACT1
, OSD_VIDWINMD
);
477 static void osd_disable_layer(struct osd_state
*sd
, enum osd_layer layer
)
479 struct osd_state
*osd
= sd
;
480 struct osd_window_state
*win
= &osd
->win
[layer
];
483 spin_lock_irqsave(&osd
->lock
, flags
);
485 if (!win
->is_enabled
) {
486 spin_unlock_irqrestore(&osd
->lock
, flags
);
491 _osd_disable_layer(sd
, layer
);
493 spin_unlock_irqrestore(&osd
->lock
, flags
);
496 static void _osd_enable_attribute_mode(struct osd_state
*sd
)
498 /* enable attribute mode for OSD1 */
499 osd_set(sd
, OSD_OSDWIN1MD_OASW
, OSD_OSDWIN1MD
);
502 static void _osd_enable_layer(struct osd_state
*sd
, enum osd_layer layer
)
506 osd_set(sd
, OSD_OSDWIN0MD_OACT0
, OSD_OSDWIN0MD
);
509 osd_set(sd
, OSD_VIDWINMD_ACT0
, OSD_VIDWINMD
);
512 /* enable OSD1 and disable attribute mode */
513 osd_modify(sd
, OSD_OSDWIN1MD_OASW
| OSD_OSDWIN1MD_OACT1
,
514 OSD_OSDWIN1MD_OACT1
, OSD_OSDWIN1MD
);
517 osd_set(sd
, OSD_VIDWINMD_ACT1
, OSD_VIDWINMD
);
522 static int osd_enable_layer(struct osd_state
*sd
, enum osd_layer layer
,
525 struct osd_state
*osd
= sd
;
526 struct osd_window_state
*win
= &osd
->win
[layer
];
527 struct osd_layer_config
*cfg
= &win
->lconfig
;
530 spin_lock_irqsave(&osd
->lock
, flags
);
533 * use otherwin flag to know this is the other vid window
534 * in YUV420 mode, if is, skip this check
536 if (!otherwin
&& (!win
->is_allocated
||
537 !win
->fb_base_phys
||
541 spin_unlock_irqrestore(&osd
->lock
, flags
);
545 if (win
->is_enabled
) {
546 spin_unlock_irqrestore(&osd
->lock
, flags
);
551 if (cfg
->pixfmt
!= PIXFMT_OSD_ATTR
)
552 _osd_enable_layer(sd
, layer
);
554 _osd_enable_attribute_mode(sd
);
555 _osd_set_blink_attribute(sd
, osd
->is_blinking
, osd
->blink
);
558 spin_unlock_irqrestore(&osd
->lock
, flags
);
563 #define OSD_SRC_ADDR_HIGH4 0x7800000
564 #define OSD_SRC_ADDR_HIGH7 0x7F0000
565 #define OSD_SRCADD_OFSET_SFT 23
566 #define OSD_SRCADD_ADD_SFT 16
567 #define OSD_WINADL_MASK 0xFFFF
568 #define OSD_WINOFST_MASK 0x1000
569 #define VPBE_REG_BASE 0x80000000
571 static void _osd_start_layer(struct osd_state
*sd
, enum osd_layer layer
,
572 unsigned long fb_base_phys
,
573 unsigned long cbcr_ofst
)
576 if (sd
->vpbe_type
== VPBE_VERSION_1
) {
579 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_OSDWIN0ADR
);
582 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_VIDWIN0ADR
);
585 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_OSDWIN1ADR
);
588 osd_write(sd
, fb_base_phys
& ~0x1F, OSD_VIDWIN1ADR
);
591 } else if (sd
->vpbe_type
== VPBE_VERSION_3
) {
592 unsigned long fb_offset_32
=
593 (fb_base_phys
- VPBE_REG_BASE
) >> 5;
597 osd_modify(sd
, OSD_OSDWINADH_O0AH
,
598 fb_offset_32
>> (OSD_SRCADD_ADD_SFT
-
599 OSD_OSDWINADH_O0AH_SHIFT
),
601 osd_write(sd
, fb_offset_32
& OSD_OSDWIN0ADL_O0AL
,
605 osd_modify(sd
, OSD_VIDWINADH_V0AH
,
606 fb_offset_32
>> (OSD_SRCADD_ADD_SFT
-
607 OSD_VIDWINADH_V0AH_SHIFT
),
609 osd_write(sd
, fb_offset_32
& OSD_VIDWIN0ADL_V0AL
,
613 osd_modify(sd
, OSD_OSDWINADH_O1AH
,
614 fb_offset_32
>> (OSD_SRCADD_ADD_SFT
-
615 OSD_OSDWINADH_O1AH_SHIFT
),
617 osd_write(sd
, fb_offset_32
& OSD_OSDWIN1ADL_O1AL
,
621 osd_modify(sd
, OSD_VIDWINADH_V1AH
,
622 fb_offset_32
>> (OSD_SRCADD_ADD_SFT
-
623 OSD_VIDWINADH_V1AH_SHIFT
),
625 osd_write(sd
, fb_offset_32
& OSD_VIDWIN1ADL_V1AL
,
629 } else if (sd
->vpbe_type
== VPBE_VERSION_2
) {
630 struct osd_window_state
*win
= &sd
->win
[layer
];
631 unsigned long fb_offset_32
, cbcr_offset_32
;
633 fb_offset_32
= fb_base_phys
- VPBE_REG_BASE
;
635 cbcr_offset_32
= cbcr_ofst
;
637 cbcr_offset_32
= win
->lconfig
.line_length
*
639 cbcr_offset_32
+= fb_offset_32
;
640 fb_offset_32
= fb_offset_32
>> 5;
641 cbcr_offset_32
= cbcr_offset_32
>> 5;
643 * DM365: start address is 27-bit long address b26 - b23 are
644 * in offset register b12 - b9, and * bit 26 has to be '1'
646 if (win
->lconfig
.pixfmt
== PIXFMT_NV12
) {
651 osd_modify(sd
, OSD_VIDWIN0OFST_V0AH
,
652 ((fb_offset_32
& OSD_SRC_ADDR_HIGH4
) >>
653 (OSD_SRCADD_OFSET_SFT
-
654 OSD_WINOFST_AH_SHIFT
)) |
655 OSD_WINOFST_MASK
, OSD_VIDWIN0OFST
);
656 osd_modify(sd
, OSD_VIDWINADH_V0AH
,
657 (fb_offset_32
& OSD_SRC_ADDR_HIGH7
) >>
658 (OSD_SRCADD_ADD_SFT
-
659 OSD_VIDWINADH_V0AH_SHIFT
),
661 osd_write(sd
, fb_offset_32
& OSD_WINADL_MASK
,
663 /* CbCr is in VID1 */
664 osd_modify(sd
, OSD_VIDWIN1OFST_V1AH
,
666 OSD_SRC_ADDR_HIGH4
) >>
667 (OSD_SRCADD_OFSET_SFT
-
668 OSD_WINOFST_AH_SHIFT
)) |
669 OSD_WINOFST_MASK
, OSD_VIDWIN1OFST
);
670 osd_modify(sd
, OSD_VIDWINADH_V1AH
,
672 OSD_SRC_ADDR_HIGH7
) >>
673 (OSD_SRCADD_ADD_SFT
-
674 OSD_VIDWINADH_V1AH_SHIFT
),
676 osd_write(sd
, cbcr_offset_32
& OSD_WINADL_MASK
,
686 osd_modify(sd
, OSD_OSDWIN0OFST_O0AH
,
687 ((fb_offset_32
& OSD_SRC_ADDR_HIGH4
) >>
688 (OSD_SRCADD_OFSET_SFT
-
689 OSD_WINOFST_AH_SHIFT
)) | OSD_WINOFST_MASK
,
691 osd_modify(sd
, OSD_OSDWINADH_O0AH
,
692 (fb_offset_32
& OSD_SRC_ADDR_HIGH7
) >>
693 (OSD_SRCADD_ADD_SFT
-
694 OSD_OSDWINADH_O0AH_SHIFT
), OSD_OSDWINADH
);
695 osd_write(sd
, fb_offset_32
& OSD_WINADL_MASK
,
699 if (win
->lconfig
.pixfmt
!= PIXFMT_NV12
) {
700 osd_modify(sd
, OSD_VIDWIN0OFST_V0AH
,
701 ((fb_offset_32
& OSD_SRC_ADDR_HIGH4
) >>
702 (OSD_SRCADD_OFSET_SFT
-
703 OSD_WINOFST_AH_SHIFT
)) |
704 OSD_WINOFST_MASK
, OSD_VIDWIN0OFST
);
705 osd_modify(sd
, OSD_VIDWINADH_V0AH
,
706 (fb_offset_32
& OSD_SRC_ADDR_HIGH7
) >>
707 (OSD_SRCADD_ADD_SFT
-
708 OSD_VIDWINADH_V0AH_SHIFT
),
710 osd_write(sd
, fb_offset_32
& OSD_WINADL_MASK
,
715 osd_modify(sd
, OSD_OSDWIN1OFST_O1AH
,
716 ((fb_offset_32
& OSD_SRC_ADDR_HIGH4
) >>
717 (OSD_SRCADD_OFSET_SFT
-
718 OSD_WINOFST_AH_SHIFT
)) | OSD_WINOFST_MASK
,
720 osd_modify(sd
, OSD_OSDWINADH_O1AH
,
721 (fb_offset_32
& OSD_SRC_ADDR_HIGH7
) >>
722 (OSD_SRCADD_ADD_SFT
-
723 OSD_OSDWINADH_O1AH_SHIFT
),
725 osd_write(sd
, fb_offset_32
& OSD_WINADL_MASK
,
729 if (win
->lconfig
.pixfmt
!= PIXFMT_NV12
) {
730 osd_modify(sd
, OSD_VIDWIN1OFST_V1AH
,
731 ((fb_offset_32
& OSD_SRC_ADDR_HIGH4
) >>
732 (OSD_SRCADD_OFSET_SFT
-
733 OSD_WINOFST_AH_SHIFT
)) |
734 OSD_WINOFST_MASK
, OSD_VIDWIN1OFST
);
735 osd_modify(sd
, OSD_VIDWINADH_V1AH
,
736 (fb_offset_32
& OSD_SRC_ADDR_HIGH7
) >>
737 (OSD_SRCADD_ADD_SFT
-
738 OSD_VIDWINADH_V1AH_SHIFT
),
740 osd_write(sd
, fb_offset_32
& OSD_WINADL_MASK
,
748 static void osd_start_layer(struct osd_state
*sd
, enum osd_layer layer
,
749 unsigned long fb_base_phys
,
750 unsigned long cbcr_ofst
)
752 struct osd_state
*osd
= sd
;
753 struct osd_window_state
*win
= &osd
->win
[layer
];
754 struct osd_layer_config
*cfg
= &win
->lconfig
;
757 spin_lock_irqsave(&osd
->lock
, flags
);
759 win
->fb_base_phys
= fb_base_phys
& ~0x1F;
760 _osd_start_layer(sd
, layer
, fb_base_phys
, cbcr_ofst
);
762 if (layer
== WIN_VID0
) {
764 _osd_dm6446_vid0_pingpong(sd
, osd
->field_inversion
,
769 spin_unlock_irqrestore(&osd
->lock
, flags
);
772 static void osd_get_layer_config(struct osd_state
*sd
, enum osd_layer layer
,
773 struct osd_layer_config
*lconfig
)
775 struct osd_state
*osd
= sd
;
776 struct osd_window_state
*win
= &osd
->win
[layer
];
779 spin_lock_irqsave(&osd
->lock
, flags
);
781 *lconfig
= win
->lconfig
;
783 spin_unlock_irqrestore(&osd
->lock
, flags
);
787 * try_layer_config() - Try a specific configuration for the layer
788 * @sd: ptr to struct osd_state
789 * @layer: layer to configure
790 * @lconfig: layer configuration to try
792 * If the requested lconfig is completely rejected and the value of lconfig on
793 * exit is the current lconfig, then try_layer_config() returns 1. Otherwise,
794 * try_layer_config() returns 0. A return value of 0 does not necessarily mean
795 * that the value of lconfig on exit is identical to the value of lconfig on
796 * entry, but merely that it represents a change from the current lconfig.
798 static int try_layer_config(struct osd_state
*sd
, enum osd_layer layer
,
799 struct osd_layer_config
*lconfig
)
801 struct osd_state
*osd
= sd
;
802 struct osd_window_state
*win
= &osd
->win
[layer
];
805 /* verify that the pixel format is compatible with the layer */
806 switch (lconfig
->pixfmt
) {
812 if (osd
->vpbe_type
== VPBE_VERSION_1
)
813 bad_config
= !is_vid_win(layer
);
817 bad_config
= !is_vid_win(layer
);
820 if (osd
->vpbe_type
== VPBE_VERSION_1
)
821 bad_config
= !is_vid_win(layer
);
822 else if ((osd
->vpbe_type
== VPBE_VERSION_3
) ||
823 (osd
->vpbe_type
== VPBE_VERSION_2
))
824 bad_config
= !is_osd_win(layer
);
827 if (osd
->vpbe_type
!= VPBE_VERSION_2
)
830 bad_config
= is_osd_win(layer
);
832 case PIXFMT_OSD_ATTR
:
833 bad_config
= (layer
!= WIN_OSD1
);
841 * The requested pixel format is incompatible with the layer,
842 * so keep the current layer configuration.
844 *lconfig
= win
->lconfig
;
849 /* only one OSD window at a time can use RGB pixel formats */
850 if ((osd
->vpbe_type
== VPBE_VERSION_1
) &&
851 is_osd_win(layer
) && is_rgb_pixfmt(lconfig
->pixfmt
)) {
852 enum osd_pix_format pixfmt
;
854 if (layer
== WIN_OSD0
)
855 pixfmt
= osd
->win
[WIN_OSD1
].lconfig
.pixfmt
;
857 pixfmt
= osd
->win
[WIN_OSD0
].lconfig
.pixfmt
;
859 if (is_rgb_pixfmt(pixfmt
)) {
861 * The other OSD window is already configured for an
862 * RGB, so keep the current layer configuration.
864 *lconfig
= win
->lconfig
;
869 /* DM6446: only one video window at a time can use RGB888 */
870 if ((osd
->vpbe_type
== VPBE_VERSION_1
) && is_vid_win(layer
) &&
871 lconfig
->pixfmt
== PIXFMT_RGB888
) {
872 enum osd_pix_format pixfmt
;
874 if (layer
== WIN_VID0
)
875 pixfmt
= osd
->win
[WIN_VID1
].lconfig
.pixfmt
;
877 pixfmt
= osd
->win
[WIN_VID0
].lconfig
.pixfmt
;
879 if (pixfmt
== PIXFMT_RGB888
) {
881 * The other video window is already configured for
882 * RGB888, so keep the current layer configuration.
884 *lconfig
= win
->lconfig
;
889 /* window dimensions must be non-zero */
890 if (!lconfig
->line_length
|| !lconfig
->xsize
|| !lconfig
->ysize
) {
891 *lconfig
= win
->lconfig
;
895 /* round line_length up to a multiple of 32 */
896 lconfig
->line_length
= ((lconfig
->line_length
+ 31) / 32) * 32;
897 lconfig
->line_length
=
898 min(lconfig
->line_length
, (unsigned)MAX_LINE_LENGTH
);
899 lconfig
->xsize
= min(lconfig
->xsize
, (unsigned)MAX_WIN_SIZE
);
900 lconfig
->ysize
= min(lconfig
->ysize
, (unsigned)MAX_WIN_SIZE
);
901 lconfig
->xpos
= min(lconfig
->xpos
, (unsigned)MAX_WIN_SIZE
);
902 lconfig
->ypos
= min(lconfig
->ypos
, (unsigned)MAX_WIN_SIZE
);
903 lconfig
->interlaced
= (lconfig
->interlaced
!= 0);
904 if (lconfig
->interlaced
) {
905 /* ysize and ypos must be even for interlaced displays */
906 lconfig
->ysize
&= ~1;
913 static void _osd_disable_vid_rgb888(struct osd_state
*sd
)
916 * The DM6446 supports RGB888 pixel format in a single video window.
917 * This routine disables RGB888 pixel format for both video windows.
918 * The caller must ensure that neither video window is currently
919 * configured for RGB888 pixel format.
921 if (sd
->vpbe_type
== VPBE_VERSION_1
)
922 osd_clear(sd
, OSD_MISCCTL_RGBEN
, OSD_MISCCTL
);
925 static void _osd_enable_vid_rgb888(struct osd_state
*sd
,
926 enum osd_layer layer
)
929 * The DM6446 supports RGB888 pixel format in a single video window.
930 * This routine enables RGB888 pixel format for the specified video
931 * window. The caller must ensure that the other video window is not
932 * currently configured for RGB888 pixel format, as this routine will
933 * disable RGB888 pixel format for the other window.
935 if (sd
->vpbe_type
== VPBE_VERSION_1
) {
936 if (layer
== WIN_VID0
)
937 osd_modify(sd
, OSD_MISCCTL_RGBEN
| OSD_MISCCTL_RGBWIN
,
938 OSD_MISCCTL_RGBEN
, OSD_MISCCTL
);
939 else if (layer
== WIN_VID1
)
940 osd_modify(sd
, OSD_MISCCTL_RGBEN
| OSD_MISCCTL_RGBWIN
,
941 OSD_MISCCTL_RGBEN
| OSD_MISCCTL_RGBWIN
,
946 static void _osd_set_cbcr_order(struct osd_state
*sd
,
947 enum osd_pix_format pixfmt
)
950 * The caller must ensure that all windows using YC pixfmt use the same
953 if (pixfmt
== PIXFMT_YCBCRI
)
954 osd_clear(sd
, OSD_MODE_CS
, OSD_MODE
);
955 else if (pixfmt
== PIXFMT_YCRCBI
)
956 osd_set(sd
, OSD_MODE_CS
, OSD_MODE
);
959 static void _osd_set_layer_config(struct osd_state
*sd
, enum osd_layer layer
,
960 const struct osd_layer_config
*lconfig
)
962 u32 winmd
= 0, winmd_mask
= 0, bmw
= 0;
964 _osd_set_cbcr_order(sd
, lconfig
->pixfmt
);
968 if (sd
->vpbe_type
== VPBE_VERSION_1
) {
969 winmd_mask
|= OSD_OSDWIN0MD_RGB0E
;
970 if (lconfig
->pixfmt
== PIXFMT_RGB565
)
971 winmd
|= OSD_OSDWIN0MD_RGB0E
;
972 } else if ((sd
->vpbe_type
== VPBE_VERSION_3
) ||
973 (sd
->vpbe_type
== VPBE_VERSION_2
)) {
974 winmd_mask
|= OSD_OSDWIN0MD_BMP0MD
;
975 switch (lconfig
->pixfmt
) {
978 OSD_OSDWIN0MD_BMP0MD_SHIFT
);
981 winmd
|= (2 << OSD_OSDWIN0MD_BMP0MD_SHIFT
);
982 _osd_enable_rgb888_pixblend(sd
, OSDWIN_OSD0
);
986 winmd
|= (3 << OSD_OSDWIN0MD_BMP0MD_SHIFT
);
993 winmd_mask
|= OSD_OSDWIN0MD_BMW0
| OSD_OSDWIN0MD_OFF0
;
995 switch (lconfig
->pixfmt
) {
1011 winmd
|= (bmw
<< OSD_OSDWIN0MD_BMW0_SHIFT
);
1013 if (lconfig
->interlaced
)
1014 winmd
|= OSD_OSDWIN0MD_OFF0
;
1016 osd_modify(sd
, winmd_mask
, winmd
, OSD_OSDWIN0MD
);
1017 osd_write(sd
, lconfig
->line_length
>> 5, OSD_OSDWIN0OFST
);
1018 osd_write(sd
, lconfig
->xpos
, OSD_OSDWIN0XP
);
1019 osd_write(sd
, lconfig
->xsize
, OSD_OSDWIN0XL
);
1020 if (lconfig
->interlaced
) {
1021 osd_write(sd
, lconfig
->ypos
>> 1, OSD_OSDWIN0YP
);
1022 osd_write(sd
, lconfig
->ysize
>> 1, OSD_OSDWIN0YL
);
1024 osd_write(sd
, lconfig
->ypos
, OSD_OSDWIN0YP
);
1025 osd_write(sd
, lconfig
->ysize
, OSD_OSDWIN0YL
);
1029 winmd_mask
|= OSD_VIDWINMD_VFF0
;
1030 if (lconfig
->interlaced
)
1031 winmd
|= OSD_VIDWINMD_VFF0
;
1033 osd_modify(sd
, winmd_mask
, winmd
, OSD_VIDWINMD
);
1034 osd_write(sd
, lconfig
->line_length
>> 5, OSD_VIDWIN0OFST
);
1035 osd_write(sd
, lconfig
->xpos
, OSD_VIDWIN0XP
);
1036 osd_write(sd
, lconfig
->xsize
, OSD_VIDWIN0XL
);
1038 * For YUV420P format the register contents are
1039 * duplicated in both VID registers
1041 if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1042 (lconfig
->pixfmt
== PIXFMT_NV12
)) {
1043 /* other window also */
1044 if (lconfig
->interlaced
) {
1045 winmd_mask
|= OSD_VIDWINMD_VFF1
;
1046 winmd
|= OSD_VIDWINMD_VFF1
;
1047 osd_modify(sd
, winmd_mask
, winmd
,
1051 osd_modify(sd
, OSD_MISCCTL_S420D
,
1052 OSD_MISCCTL_S420D
, OSD_MISCCTL
);
1053 osd_write(sd
, lconfig
->line_length
>> 5,
1055 osd_write(sd
, lconfig
->xpos
, OSD_VIDWIN1XP
);
1056 osd_write(sd
, lconfig
->xsize
, OSD_VIDWIN1XL
);
1058 * if NV21 pixfmt and line length not 32B
1059 * aligned (e.g. NTSC), Need to set window
1060 * X pixel size to be 32B aligned as well
1062 if (lconfig
->xsize
% 32) {
1064 ((lconfig
->xsize
+ 31) & ~31),
1067 ((lconfig
->xsize
+ 31) & ~31),
1070 } else if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1071 (lconfig
->pixfmt
!= PIXFMT_NV12
)) {
1072 osd_modify(sd
, OSD_MISCCTL_S420D
, ~OSD_MISCCTL_S420D
,
1076 if (lconfig
->interlaced
) {
1077 osd_write(sd
, lconfig
->ypos
>> 1, OSD_VIDWIN0YP
);
1078 osd_write(sd
, lconfig
->ysize
>> 1, OSD_VIDWIN0YL
);
1079 if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1080 lconfig
->pixfmt
== PIXFMT_NV12
) {
1081 osd_write(sd
, lconfig
->ypos
>> 1,
1083 osd_write(sd
, lconfig
->ysize
>> 1,
1087 osd_write(sd
, lconfig
->ypos
, OSD_VIDWIN0YP
);
1088 osd_write(sd
, lconfig
->ysize
, OSD_VIDWIN0YL
);
1089 if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1090 lconfig
->pixfmt
== PIXFMT_NV12
) {
1091 osd_write(sd
, lconfig
->ypos
, OSD_VIDWIN1YP
);
1092 osd_write(sd
, lconfig
->ysize
, OSD_VIDWIN1YL
);
1098 * The caller must ensure that OSD1 is disabled prior to
1099 * switching from a normal mode to attribute mode or from
1100 * attribute mode to a normal mode.
1102 if (lconfig
->pixfmt
== PIXFMT_OSD_ATTR
) {
1103 if (sd
->vpbe_type
== VPBE_VERSION_1
) {
1104 winmd_mask
|= OSD_OSDWIN1MD_ATN1E
|
1105 OSD_OSDWIN1MD_RGB1E
| OSD_OSDWIN1MD_CLUTS1
|
1106 OSD_OSDWIN1MD_BLND1
| OSD_OSDWIN1MD_TE1
;
1108 winmd_mask
|= OSD_OSDWIN1MD_BMP1MD
|
1109 OSD_OSDWIN1MD_CLUTS1
| OSD_OSDWIN1MD_BLND1
|
1113 if (sd
->vpbe_type
== VPBE_VERSION_1
) {
1114 winmd_mask
|= OSD_OSDWIN1MD_RGB1E
;
1115 if (lconfig
->pixfmt
== PIXFMT_RGB565
)
1116 winmd
|= OSD_OSDWIN1MD_RGB1E
;
1117 } else if ((sd
->vpbe_type
== VPBE_VERSION_3
)
1118 || (sd
->vpbe_type
== VPBE_VERSION_2
)) {
1119 winmd_mask
|= OSD_OSDWIN1MD_BMP1MD
;
1120 switch (lconfig
->pixfmt
) {
1123 (1 << OSD_OSDWIN1MD_BMP1MD_SHIFT
);
1127 (2 << OSD_OSDWIN1MD_BMP1MD_SHIFT
);
1128 _osd_enable_rgb888_pixblend(sd
,
1134 (3 << OSD_OSDWIN1MD_BMP1MD_SHIFT
);
1141 winmd_mask
|= OSD_OSDWIN1MD_BMW1
;
1142 switch (lconfig
->pixfmt
) {
1158 winmd
|= (bmw
<< OSD_OSDWIN1MD_BMW1_SHIFT
);
1161 winmd_mask
|= OSD_OSDWIN1MD_OFF1
;
1162 if (lconfig
->interlaced
)
1163 winmd
|= OSD_OSDWIN1MD_OFF1
;
1165 osd_modify(sd
, winmd_mask
, winmd
, OSD_OSDWIN1MD
);
1166 osd_write(sd
, lconfig
->line_length
>> 5, OSD_OSDWIN1OFST
);
1167 osd_write(sd
, lconfig
->xpos
, OSD_OSDWIN1XP
);
1168 osd_write(sd
, lconfig
->xsize
, OSD_OSDWIN1XL
);
1169 if (lconfig
->interlaced
) {
1170 osd_write(sd
, lconfig
->ypos
>> 1, OSD_OSDWIN1YP
);
1171 osd_write(sd
, lconfig
->ysize
>> 1, OSD_OSDWIN1YL
);
1173 osd_write(sd
, lconfig
->ypos
, OSD_OSDWIN1YP
);
1174 osd_write(sd
, lconfig
->ysize
, OSD_OSDWIN1YL
);
1178 winmd_mask
|= OSD_VIDWINMD_VFF1
;
1179 if (lconfig
->interlaced
)
1180 winmd
|= OSD_VIDWINMD_VFF1
;
1182 osd_modify(sd
, winmd_mask
, winmd
, OSD_VIDWINMD
);
1183 osd_write(sd
, lconfig
->line_length
>> 5, OSD_VIDWIN1OFST
);
1184 osd_write(sd
, lconfig
->xpos
, OSD_VIDWIN1XP
);
1185 osd_write(sd
, lconfig
->xsize
, OSD_VIDWIN1XL
);
1187 * For YUV420P format the register contents are
1188 * duplicated in both VID registers
1190 if (sd
->vpbe_type
== VPBE_VERSION_2
) {
1191 if (lconfig
->pixfmt
== PIXFMT_NV12
) {
1192 /* other window also */
1193 if (lconfig
->interlaced
) {
1194 winmd_mask
|= OSD_VIDWINMD_VFF0
;
1195 winmd
|= OSD_VIDWINMD_VFF0
;
1196 osd_modify(sd
, winmd_mask
, winmd
,
1199 osd_modify(sd
, OSD_MISCCTL_S420D
,
1200 OSD_MISCCTL_S420D
, OSD_MISCCTL
);
1201 osd_write(sd
, lconfig
->line_length
>> 5,
1203 osd_write(sd
, lconfig
->xpos
, OSD_VIDWIN0XP
);
1204 osd_write(sd
, lconfig
->xsize
, OSD_VIDWIN0XL
);
1206 osd_modify(sd
, OSD_MISCCTL_S420D
,
1207 ~OSD_MISCCTL_S420D
, OSD_MISCCTL
);
1211 if (lconfig
->interlaced
) {
1212 osd_write(sd
, lconfig
->ypos
>> 1, OSD_VIDWIN1YP
);
1213 osd_write(sd
, lconfig
->ysize
>> 1, OSD_VIDWIN1YL
);
1214 if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1215 lconfig
->pixfmt
== PIXFMT_NV12
) {
1216 osd_write(sd
, lconfig
->ypos
>> 1,
1218 osd_write(sd
, lconfig
->ysize
>> 1,
1222 osd_write(sd
, lconfig
->ypos
, OSD_VIDWIN1YP
);
1223 osd_write(sd
, lconfig
->ysize
, OSD_VIDWIN1YL
);
1224 if ((sd
->vpbe_type
== VPBE_VERSION_2
) &&
1225 lconfig
->pixfmt
== PIXFMT_NV12
) {
1226 osd_write(sd
, lconfig
->ypos
, OSD_VIDWIN0YP
);
1227 osd_write(sd
, lconfig
->ysize
, OSD_VIDWIN0YL
);
1234 static int osd_set_layer_config(struct osd_state
*sd
, enum osd_layer layer
,
1235 struct osd_layer_config
*lconfig
)
1237 struct osd_state
*osd
= sd
;
1238 struct osd_window_state
*win
= &osd
->win
[layer
];
1239 struct osd_layer_config
*cfg
= &win
->lconfig
;
1240 unsigned long flags
;
1243 spin_lock_irqsave(&osd
->lock
, flags
);
1245 reject_config
= try_layer_config(sd
, layer
, lconfig
);
1246 if (reject_config
) {
1247 spin_unlock_irqrestore(&osd
->lock
, flags
);
1248 return reject_config
;
1251 /* update the current Cb/Cr order */
1252 if (is_yc_pixfmt(lconfig
->pixfmt
))
1253 osd
->yc_pixfmt
= lconfig
->pixfmt
;
1256 * If we are switching OSD1 from normal mode to attribute mode or from
1257 * attribute mode to normal mode, then we must disable the window.
1259 if (layer
== WIN_OSD1
) {
1260 if (((lconfig
->pixfmt
== PIXFMT_OSD_ATTR
) &&
1261 (cfg
->pixfmt
!= PIXFMT_OSD_ATTR
)) ||
1262 ((lconfig
->pixfmt
!= PIXFMT_OSD_ATTR
) &&
1263 (cfg
->pixfmt
== PIXFMT_OSD_ATTR
))) {
1264 win
->is_enabled
= 0;
1265 _osd_disable_layer(sd
, layer
);
1269 _osd_set_layer_config(sd
, layer
, lconfig
);
1271 if (layer
== WIN_OSD1
) {
1272 struct osd_osdwin_state
*osdwin_state
=
1273 &osd
->osdwin
[OSDWIN_OSD1
];
1275 if ((lconfig
->pixfmt
!= PIXFMT_OSD_ATTR
) &&
1276 (cfg
->pixfmt
== PIXFMT_OSD_ATTR
)) {
1278 * We just switched OSD1 from attribute mode to normal
1279 * mode, so we must initialize the CLUT select, the
1280 * blend factor, transparency colorkey enable, and
1281 * attenuation enable (DM6446 only) bits in the
1282 * OSDWIN1MD register.
1284 _osd_set_osd_clut(sd
, OSDWIN_OSD1
,
1285 osdwin_state
->clut
);
1286 _osd_set_blending_factor(sd
, OSDWIN_OSD1
,
1287 osdwin_state
->blend
);
1288 if (osdwin_state
->colorkey_blending
) {
1289 _osd_enable_color_key(sd
, OSDWIN_OSD1
,
1294 _osd_disable_color_key(sd
, OSDWIN_OSD1
);
1295 _osd_set_rec601_attenuation(sd
, OSDWIN_OSD1
,
1297 rec601_attenuation
);
1298 } else if ((lconfig
->pixfmt
== PIXFMT_OSD_ATTR
) &&
1299 (cfg
->pixfmt
!= PIXFMT_OSD_ATTR
)) {
1301 * We just switched OSD1 from normal mode to attribute
1302 * mode, so we must initialize the blink enable and
1303 * blink interval bits in the OSDATRMD register.
1305 _osd_set_blink_attribute(sd
, osd
->is_blinking
,
1311 * If we just switched to a 1-, 2-, or 4-bits-per-pixel bitmap format
1312 * then configure a default palette map.
1314 if ((lconfig
->pixfmt
!= cfg
->pixfmt
) &&
1315 ((lconfig
->pixfmt
== PIXFMT_1BPP
) ||
1316 (lconfig
->pixfmt
== PIXFMT_2BPP
) ||
1317 (lconfig
->pixfmt
== PIXFMT_4BPP
))) {
1318 enum osd_win_layer osdwin
=
1319 ((layer
== WIN_OSD0
) ? OSDWIN_OSD0
: OSDWIN_OSD1
);
1320 struct osd_osdwin_state
*osdwin_state
=
1321 &osd
->osdwin
[osdwin
];
1322 unsigned char clut_index
;
1323 unsigned char clut_entries
= 0;
1325 switch (lconfig
->pixfmt
) {
1339 * The default palette map maps the pixel value to the clut
1340 * index, i.e. pixel value 0 maps to clut entry 0, pixel value
1341 * 1 maps to clut entry 1, etc.
1343 for (clut_index
= 0; clut_index
< 16; clut_index
++) {
1344 osdwin_state
->palette_map
[clut_index
] = clut_index
;
1345 if (clut_index
< clut_entries
) {
1346 _osd_set_palette_map(sd
, osdwin
, clut_index
,
1354 /* DM6446: configure the RGB888 enable and window selection */
1355 if (osd
->win
[WIN_VID0
].lconfig
.pixfmt
== PIXFMT_RGB888
)
1356 _osd_enable_vid_rgb888(sd
, WIN_VID0
);
1357 else if (osd
->win
[WIN_VID1
].lconfig
.pixfmt
== PIXFMT_RGB888
)
1358 _osd_enable_vid_rgb888(sd
, WIN_VID1
);
1360 _osd_disable_vid_rgb888(sd
);
1362 if (layer
== WIN_VID0
) {
1364 _osd_dm6446_vid0_pingpong(sd
, osd
->field_inversion
,
1369 spin_unlock_irqrestore(&osd
->lock
, flags
);
1374 static void osd_init_layer(struct osd_state
*sd
, enum osd_layer layer
)
1376 struct osd_state
*osd
= sd
;
1377 struct osd_window_state
*win
= &osd
->win
[layer
];
1378 enum osd_win_layer osdwin
;
1379 struct osd_osdwin_state
*osdwin_state
;
1380 struct osd_layer_config
*cfg
= &win
->lconfig
;
1381 unsigned long flags
;
1383 spin_lock_irqsave(&osd
->lock
, flags
);
1385 win
->is_enabled
= 0;
1386 _osd_disable_layer(sd
, layer
);
1388 win
->h_zoom
= ZOOM_X1
;
1389 win
->v_zoom
= ZOOM_X1
;
1390 _osd_set_zoom(sd
, layer
, win
->h_zoom
, win
->v_zoom
);
1392 win
->fb_base_phys
= 0;
1393 _osd_start_layer(sd
, layer
, win
->fb_base_phys
, 0);
1395 cfg
->line_length
= 0;
1400 cfg
->interlaced
= 0;
1404 osdwin
= (layer
== WIN_OSD0
) ? OSDWIN_OSD0
: OSDWIN_OSD1
;
1405 osdwin_state
= &osd
->osdwin
[osdwin
];
1407 * Other code relies on the fact that OSD windows default to a
1408 * bitmap pixel format when they are deallocated, so don't
1409 * change this default pixel format.
1411 cfg
->pixfmt
= PIXFMT_8BPP
;
1412 _osd_set_layer_config(sd
, layer
, cfg
);
1413 osdwin_state
->clut
= RAM_CLUT
;
1414 _osd_set_osd_clut(sd
, osdwin
, osdwin_state
->clut
);
1415 osdwin_state
->colorkey_blending
= 0;
1416 _osd_disable_color_key(sd
, osdwin
);
1417 osdwin_state
->blend
= OSD_8_VID_0
;
1418 _osd_set_blending_factor(sd
, osdwin
, osdwin_state
->blend
);
1419 osdwin_state
->rec601_attenuation
= 0;
1420 _osd_set_rec601_attenuation(sd
, osdwin
,
1422 rec601_attenuation
);
1423 if (osdwin
== OSDWIN_OSD1
) {
1424 osd
->is_blinking
= 0;
1425 osd
->blink
= BLINK_X1
;
1430 cfg
->pixfmt
= osd
->yc_pixfmt
;
1431 _osd_set_layer_config(sd
, layer
, cfg
);
1435 spin_unlock_irqrestore(&osd
->lock
, flags
);
1438 static void osd_release_layer(struct osd_state
*sd
, enum osd_layer layer
)
1440 struct osd_state
*osd
= sd
;
1441 struct osd_window_state
*win
= &osd
->win
[layer
];
1442 unsigned long flags
;
1444 spin_lock_irqsave(&osd
->lock
, flags
);
1446 if (!win
->is_allocated
) {
1447 spin_unlock_irqrestore(&osd
->lock
, flags
);
1451 spin_unlock_irqrestore(&osd
->lock
, flags
);
1452 osd_init_layer(sd
, layer
);
1453 spin_lock_irqsave(&osd
->lock
, flags
);
1455 win
->is_allocated
= 0;
1457 spin_unlock_irqrestore(&osd
->lock
, flags
);
1460 static int osd_request_layer(struct osd_state
*sd
, enum osd_layer layer
)
1462 struct osd_state
*osd
= sd
;
1463 struct osd_window_state
*win
= &osd
->win
[layer
];
1464 unsigned long flags
;
1466 spin_lock_irqsave(&osd
->lock
, flags
);
1468 if (win
->is_allocated
) {
1469 spin_unlock_irqrestore(&osd
->lock
, flags
);
1472 win
->is_allocated
= 1;
1474 spin_unlock_irqrestore(&osd
->lock
, flags
);
1479 static void _osd_init(struct osd_state
*sd
)
1481 osd_write(sd
, 0, OSD_MODE
);
1482 osd_write(sd
, 0, OSD_VIDWINMD
);
1483 osd_write(sd
, 0, OSD_OSDWIN0MD
);
1484 osd_write(sd
, 0, OSD_OSDWIN1MD
);
1485 osd_write(sd
, 0, OSD_RECTCUR
);
1486 osd_write(sd
, 0, OSD_MISCCTL
);
1487 if (sd
->vpbe_type
== VPBE_VERSION_3
) {
1488 osd_write(sd
, 0, OSD_VBNDRY
);
1489 osd_write(sd
, 0, OSD_EXTMODE
);
1490 osd_write(sd
, OSD_MISCCTL_DMANG
, OSD_MISCCTL
);
1494 static void osd_set_left_margin(struct osd_state
*sd
, u32 val
)
1496 osd_write(sd
, val
, OSD_BASEPX
);
1499 static void osd_set_top_margin(struct osd_state
*sd
, u32 val
)
1501 osd_write(sd
, val
, OSD_BASEPY
);
1504 static int osd_initialize(struct osd_state
*osd
)
1510 /* set default Cb/Cr order */
1511 osd
->yc_pixfmt
= PIXFMT_YCBCRI
;
1513 if (osd
->vpbe_type
== VPBE_VERSION_3
) {
1515 * ROM CLUT1 on the DM355 is similar (identical?) to ROM CLUT0
1516 * on the DM6446, so make ROM_CLUT1 the default on the DM355.
1518 osd
->rom_clut
= ROM_CLUT1
;
1521 _osd_set_field_inversion(osd
, osd
->field_inversion
);
1522 _osd_set_rom_clut(osd
, osd
->rom_clut
);
1524 osd_init_layer(osd
, WIN_OSD0
);
1525 osd_init_layer(osd
, WIN_VID0
);
1526 osd_init_layer(osd
, WIN_OSD1
);
1527 osd_init_layer(osd
, WIN_VID1
);
1532 static const struct vpbe_osd_ops osd_ops
= {
1533 .initialize
= osd_initialize
,
1534 .request_layer
= osd_request_layer
,
1535 .release_layer
= osd_release_layer
,
1536 .enable_layer
= osd_enable_layer
,
1537 .disable_layer
= osd_disable_layer
,
1538 .set_layer_config
= osd_set_layer_config
,
1539 .get_layer_config
= osd_get_layer_config
,
1540 .start_layer
= osd_start_layer
,
1541 .set_left_margin
= osd_set_left_margin
,
1542 .set_top_margin
= osd_set_top_margin
,
1545 static int osd_probe(struct platform_device
*pdev
)
1547 const struct platform_device_id
*pdev_id
;
1548 struct osd_state
*osd
;
1549 struct resource
*res
;
1551 pdev_id
= platform_get_device_id(pdev
);
1555 osd
= devm_kzalloc(&pdev
->dev
, sizeof(struct osd_state
), GFP_KERNEL
);
1560 osd
->dev
= &pdev
->dev
;
1561 osd
->vpbe_type
= pdev_id
->driver_data
;
1563 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1564 osd
->osd_base
= devm_ioremap_resource(&pdev
->dev
, res
);
1565 if (IS_ERR(osd
->osd_base
))
1566 return PTR_ERR(osd
->osd_base
);
1568 osd
->osd_base_phys
= res
->start
;
1569 osd
->osd_size
= resource_size(res
);
1570 spin_lock_init(&osd
->lock
);
1572 platform_set_drvdata(pdev
, osd
);
1573 dev_notice(osd
->dev
, "OSD sub device probe success\n");
1578 static int osd_remove(struct platform_device
*pdev
)
1583 static struct platform_driver osd_driver
= {
1585 .remove
= osd_remove
,
1587 .name
= MODULE_NAME
,
1589 .id_table
= vpbe_osd_devtype
1592 module_platform_driver(osd_driver
);
1594 MODULE_LICENSE("GPL");
1595 MODULE_DESCRIPTION("DaVinci OSD Manager Driver");
1596 MODULE_AUTHOR("Texas Instruments");