Lines Matching +full:1 +full:- +full:sd

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2007-2010 Texas Instruments Inc
7 * - Initial version
9 * - ported to sub device interface
20 #include <media/v4l2-device.h>
27 #define MODULE_NAME "davinci-vpbe-osd"
48 static inline u32 osd_read(struct osd_state *sd, u32 offset) in osd_read() argument
50 struct osd_state *osd = sd; in osd_read()
52 return readl(osd->osd_base + offset); in osd_read()
55 static inline u32 osd_write(struct osd_state *sd, u32 val, u32 offset) in osd_write() argument
57 struct osd_state *osd = sd; in osd_write()
59 writel(val, osd->osd_base + offset); in osd_write()
64 static inline u32 osd_set(struct osd_state *sd, u32 mask, u32 offset) in osd_set() argument
66 struct osd_state *osd = sd; in osd_set()
68 void __iomem *addr = osd->osd_base + offset; in osd_set()
76 static inline u32 osd_clear(struct osd_state *sd, u32 mask, u32 offset) in osd_clear() argument
78 struct osd_state *osd = sd; in osd_clear()
80 void __iomem *addr = osd->osd_base + offset; in osd_clear()
88 static inline u32 osd_modify(struct osd_state *sd, u32 mask, u32 val, in osd_modify() argument
91 struct osd_state *osd = sd; in osd_modify()
93 void __iomem *addr = osd->osd_base + offset; in osd_modify()
113 * _osd_dm6446_vid0_pingpong() - field inversion fix for DM6446
114 * @sd: ptr to struct osd_state
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, in _osd_dm6446_vid0_pingpong() argument
134 pdata = (struct osd_platform_data *)sd->dev->platform_data; in _osd_dm6446_vid0_pingpong()
135 if (pdata != NULL && pdata->field_inv_wa_enable) { in _osd_dm6446_vid0_pingpong()
137 if (!field_inversion || !lconfig->interlaced) { in _osd_dm6446_vid0_pingpong()
138 osd_write(sd, fb_base_phys & ~0x1F, OSD_VIDWIN0ADR); in _osd_dm6446_vid0_pingpong()
139 osd_write(sd, fb_base_phys & ~0x1F, OSD_PPVWIN0ADR); in _osd_dm6446_vid0_pingpong()
140 osd_modify(sd, OSD_MISCCTL_PPSW | OSD_MISCCTL_PPRV, 0, in _osd_dm6446_vid0_pingpong()
146 osd_write(sd, in _osd_dm6446_vid0_pingpong()
147 (fb_base_phys & ~0x1F) - lconfig->line_length, in _osd_dm6446_vid0_pingpong()
149 osd_write(sd, in _osd_dm6446_vid0_pingpong()
150 (fb_base_phys & ~0x1F) + lconfig->line_length, in _osd_dm6446_vid0_pingpong()
152 osd_modify(sd, in _osd_dm6446_vid0_pingpong()
156 return 1; in _osd_dm6446_vid0_pingpong()
163 static void _osd_set_field_inversion(struct osd_state *sd, int enable) in _osd_set_field_inversion() argument
170 osd_modify(sd, OSD_MODE_FSINV, fsinv, OSD_MODE); in _osd_set_field_inversion()
173 static void _osd_set_blink_attribute(struct osd_state *sd, int enable, in _osd_set_blink_attribute() argument
183 osd_modify(sd, OSD_OSDATRMD_BLNKINT | OSD_OSDATRMD_BLNK, osdatrmd, in _osd_set_blink_attribute()
187 static void _osd_set_rom_clut(struct osd_state *sd, in _osd_set_rom_clut() argument
191 osd_clear(sd, OSD_MISCCTL_RSEL, OSD_MISCCTL); in _osd_set_rom_clut()
193 osd_set(sd, OSD_MISCCTL_RSEL, OSD_MISCCTL); in _osd_set_rom_clut()
196 static void _osd_set_palette_map(struct osd_state *sd, in _osd_set_palette_map() argument
225 bmp_offset = OSD_W0BMP01 + (bmp_reg >> 1) * sizeof(u32); in _osd_set_palette_map()
228 bmp_offset = OSD_W1BMP01 + (bmp_reg >> 1) * sizeof(u32); in _osd_set_palette_map()
234 if (bmp_reg & 1) { in _osd_set_palette_map()
242 osd_modify(sd, bmp_mask, clut_index << bmp_shift, bmp_offset); in _osd_set_palette_map()
245 static void _osd_set_rec601_attenuation(struct osd_state *sd, in _osd_set_rec601_attenuation() argument
250 osd_modify(sd, OSD_OSDWIN0MD_ATN0E, in _osd_set_rec601_attenuation()
253 if (sd->vpbe_type == VPBE_VERSION_1) in _osd_set_rec601_attenuation()
254 osd_modify(sd, OSD_OSDWIN0MD_ATN0E, in _osd_set_rec601_attenuation()
257 else if ((sd->vpbe_type == VPBE_VERSION_3) || in _osd_set_rec601_attenuation()
258 (sd->vpbe_type == VPBE_VERSION_2)) in _osd_set_rec601_attenuation()
259 osd_modify(sd, OSD_EXTMODE_ATNOSD0EN, in _osd_set_rec601_attenuation()
264 osd_modify(sd, OSD_OSDWIN1MD_ATN1E, in _osd_set_rec601_attenuation()
267 if (sd->vpbe_type == VPBE_VERSION_1) in _osd_set_rec601_attenuation()
268 osd_modify(sd, OSD_OSDWIN1MD_ATN1E, in _osd_set_rec601_attenuation()
271 else if ((sd->vpbe_type == VPBE_VERSION_3) || in _osd_set_rec601_attenuation()
272 (sd->vpbe_type == VPBE_VERSION_2)) in _osd_set_rec601_attenuation()
273 osd_modify(sd, OSD_EXTMODE_ATNOSD1EN, in _osd_set_rec601_attenuation()
280 static void _osd_set_blending_factor(struct osd_state *sd, in _osd_set_blending_factor() argument
286 osd_modify(sd, OSD_OSDWIN0MD_BLND0, in _osd_set_blending_factor()
290 osd_modify(sd, OSD_OSDWIN1MD_BLND1, in _osd_set_blending_factor()
296 static void _osd_enable_rgb888_pixblend(struct osd_state *sd, in _osd_enable_rgb888_pixblend() argument
300 osd_modify(sd, OSD_MISCCTL_BLDSEL, 0, OSD_MISCCTL); in _osd_enable_rgb888_pixblend()
303 osd_modify(sd, OSD_EXTMODE_OSD0BLDCHR, in _osd_enable_rgb888_pixblend()
307 osd_modify(sd, OSD_EXTMODE_OSD1BLDCHR, in _osd_enable_rgb888_pixblend()
313 static void _osd_enable_color_key(struct osd_state *sd, in _osd_enable_color_key() argument
323 if (sd->vpbe_type == VPBE_VERSION_3) { in _osd_enable_color_key()
326 osd_modify(sd, OSD_TRANSPBMPIDX_BMP0, in _osd_enable_color_key()
332 osd_modify(sd, OSD_TRANSPBMPIDX_BMP1, in _osd_enable_color_key()
341 if (sd->vpbe_type == VPBE_VERSION_1) in _osd_enable_color_key()
342 osd_write(sd, colorkey & OSD_TRANSPVAL_RGBTRANS, in _osd_enable_color_key()
344 else if (sd->vpbe_type == VPBE_VERSION_3) in _osd_enable_color_key()
345 osd_write(sd, colorkey & OSD_TRANSPVALL_RGBL, in _osd_enable_color_key()
350 if (sd->vpbe_type == VPBE_VERSION_3) in _osd_enable_color_key()
351 osd_modify(sd, OSD_TRANSPVALU_Y, colorkey, in _osd_enable_color_key()
355 if (sd->vpbe_type == VPBE_VERSION_3) { in _osd_enable_color_key()
356 osd_write(sd, colorkey & OSD_TRANSPVALL_RGBL, in _osd_enable_color_key()
358 osd_modify(sd, OSD_TRANSPVALU_RGBU, colorkey >> 16, in _osd_enable_color_key()
368 osd_set(sd, OSD_OSDWIN0MD_TE0, OSD_OSDWIN0MD); in _osd_enable_color_key()
371 osd_set(sd, OSD_OSDWIN1MD_TE1, OSD_OSDWIN1MD); in _osd_enable_color_key()
376 static void _osd_disable_color_key(struct osd_state *sd, in _osd_disable_color_key() argument
381 osd_clear(sd, OSD_OSDWIN0MD_TE0, OSD_OSDWIN0MD); in _osd_disable_color_key()
384 osd_clear(sd, OSD_OSDWIN1MD_TE1, OSD_OSDWIN1MD); in _osd_disable_color_key()
389 static void _osd_set_osd_clut(struct osd_state *sd, in _osd_set_osd_clut() argument
399 osd_modify(sd, OSD_OSDWIN0MD_CLUTS0, winmd, OSD_OSDWIN0MD); in _osd_set_osd_clut()
404 osd_modify(sd, OSD_OSDWIN1MD_CLUTS1, winmd, OSD_OSDWIN1MD); in _osd_set_osd_clut()
409 static void _osd_set_zoom(struct osd_state *sd, enum osd_layer layer, in _osd_set_zoom() argument
419 osd_modify(sd, OSD_OSDWIN0MD_OHZ0 | OSD_OSDWIN0MD_OVZ0, winmd, in _osd_set_zoom()
425 osd_modify(sd, OSD_VIDWINMD_VHZ0 | OSD_VIDWINMD_VVZ0, winmd, in _osd_set_zoom()
431 osd_modify(sd, OSD_OSDWIN1MD_OHZ1 | OSD_OSDWIN1MD_OVZ1, winmd, in _osd_set_zoom()
437 osd_modify(sd, OSD_VIDWINMD_VHZ1 | OSD_VIDWINMD_VVZ1, winmd, in _osd_set_zoom()
443 static void _osd_disable_layer(struct osd_state *sd, enum osd_layer layer) in _osd_disable_layer() argument
447 osd_clear(sd, OSD_OSDWIN0MD_OACT0, OSD_OSDWIN0MD); in _osd_disable_layer()
450 osd_clear(sd, OSD_VIDWINMD_ACT0, OSD_VIDWINMD); in _osd_disable_layer()
454 osd_clear(sd, OSD_OSDWIN1MD_OASW | OSD_OSDWIN1MD_OACT1, in _osd_disable_layer()
458 osd_clear(sd, OSD_VIDWINMD_ACT1, OSD_VIDWINMD); in _osd_disable_layer()
463 static void osd_disable_layer(struct osd_state *sd, enum osd_layer layer) in osd_disable_layer() argument
465 struct osd_state *osd = sd; in osd_disable_layer()
466 struct osd_window_state *win = &osd->win[layer]; in osd_disable_layer()
469 spin_lock_irqsave(&osd->lock, flags); in osd_disable_layer()
471 if (!win->is_enabled) { in osd_disable_layer()
472 spin_unlock_irqrestore(&osd->lock, flags); in osd_disable_layer()
475 win->is_enabled = 0; in osd_disable_layer()
477 _osd_disable_layer(sd, layer); in osd_disable_layer()
479 spin_unlock_irqrestore(&osd->lock, flags); in osd_disable_layer()
482 static void _osd_enable_attribute_mode(struct osd_state *sd) in _osd_enable_attribute_mode() argument
485 osd_set(sd, OSD_OSDWIN1MD_OASW, OSD_OSDWIN1MD); in _osd_enable_attribute_mode()
488 static void _osd_enable_layer(struct osd_state *sd, enum osd_layer layer) in _osd_enable_layer() argument
492 osd_set(sd, OSD_OSDWIN0MD_OACT0, OSD_OSDWIN0MD); in _osd_enable_layer()
495 osd_set(sd, OSD_VIDWINMD_ACT0, OSD_VIDWINMD); in _osd_enable_layer()
499 osd_modify(sd, OSD_OSDWIN1MD_OASW | OSD_OSDWIN1MD_OACT1, in _osd_enable_layer()
503 osd_set(sd, OSD_VIDWINMD_ACT1, OSD_VIDWINMD); in _osd_enable_layer()
508 static int osd_enable_layer(struct osd_state *sd, enum osd_layer layer, in osd_enable_layer() argument
511 struct osd_state *osd = sd; in osd_enable_layer()
512 struct osd_window_state *win = &osd->win[layer]; in osd_enable_layer()
513 struct osd_layer_config *cfg = &win->lconfig; in osd_enable_layer()
516 spin_lock_irqsave(&osd->lock, flags); in osd_enable_layer()
522 if (!otherwin && (!win->is_allocated || in osd_enable_layer()
523 !win->fb_base_phys || in osd_enable_layer()
524 !cfg->line_length || in osd_enable_layer()
525 !cfg->xsize || in osd_enable_layer()
526 !cfg->ysize)) { in osd_enable_layer()
527 spin_unlock_irqrestore(&osd->lock, flags); in osd_enable_layer()
528 return -1; in osd_enable_layer()
531 if (win->is_enabled) { in osd_enable_layer()
532 spin_unlock_irqrestore(&osd->lock, flags); in osd_enable_layer()
535 win->is_enabled = 1; in osd_enable_layer()
537 if (cfg->pixfmt != PIXFMT_OSD_ATTR) in osd_enable_layer()
538 _osd_enable_layer(sd, layer); in osd_enable_layer()
540 _osd_enable_attribute_mode(sd); in osd_enable_layer()
541 _osd_set_blink_attribute(sd, osd->is_blinking, osd->blink); in osd_enable_layer()
544 spin_unlock_irqrestore(&osd->lock, flags); in osd_enable_layer()
557 static void _osd_start_layer(struct osd_state *sd, enum osd_layer layer, in _osd_start_layer() argument
562 if (sd->vpbe_type == VPBE_VERSION_1) { in _osd_start_layer()
565 osd_write(sd, fb_base_phys & ~0x1F, OSD_OSDWIN0ADR); in _osd_start_layer()
568 osd_write(sd, fb_base_phys & ~0x1F, OSD_VIDWIN0ADR); in _osd_start_layer()
571 osd_write(sd, fb_base_phys & ~0x1F, OSD_OSDWIN1ADR); in _osd_start_layer()
574 osd_write(sd, fb_base_phys & ~0x1F, OSD_VIDWIN1ADR); in _osd_start_layer()
577 } else if (sd->vpbe_type == VPBE_VERSION_3) { in _osd_start_layer()
579 (fb_base_phys - VPBE_REG_BASE) >> 5; in _osd_start_layer()
583 osd_modify(sd, OSD_OSDWINADH_O0AH, in _osd_start_layer()
584 fb_offset_32 >> (OSD_SRCADD_ADD_SFT - in _osd_start_layer()
587 osd_write(sd, fb_offset_32 & OSD_OSDWIN0ADL_O0AL, in _osd_start_layer()
591 osd_modify(sd, OSD_VIDWINADH_V0AH, in _osd_start_layer()
592 fb_offset_32 >> (OSD_SRCADD_ADD_SFT - in _osd_start_layer()
595 osd_write(sd, fb_offset_32 & OSD_VIDWIN0ADL_V0AL, in _osd_start_layer()
599 osd_modify(sd, OSD_OSDWINADH_O1AH, in _osd_start_layer()
600 fb_offset_32 >> (OSD_SRCADD_ADD_SFT - in _osd_start_layer()
603 osd_write(sd, fb_offset_32 & OSD_OSDWIN1ADL_O1AL, in _osd_start_layer()
607 osd_modify(sd, OSD_VIDWINADH_V1AH, in _osd_start_layer()
608 fb_offset_32 >> (OSD_SRCADD_ADD_SFT - in _osd_start_layer()
611 osd_write(sd, fb_offset_32 & OSD_VIDWIN1ADL_V1AL, in _osd_start_layer()
615 } else if (sd->vpbe_type == VPBE_VERSION_2) { in _osd_start_layer()
616 struct osd_window_state *win = &sd->win[layer]; in _osd_start_layer()
619 fb_offset_32 = fb_base_phys - VPBE_REG_BASE; in _osd_start_layer()
623 cbcr_offset_32 = win->lconfig.line_length * in _osd_start_layer()
624 win->lconfig.ysize; in _osd_start_layer()
629 * DM365: start address is 27-bit long address b26 - b23 are in _osd_start_layer()
630 * in offset register b12 - b9, and * bit 26 has to be '1' in _osd_start_layer()
632 if (win->lconfig.pixfmt == PIXFMT_NV12) { in _osd_start_layer()
637 osd_modify(sd, OSD_VIDWIN0OFST_V0AH, in _osd_start_layer()
639 (OSD_SRCADD_OFSET_SFT - in _osd_start_layer()
642 osd_modify(sd, OSD_VIDWINADH_V0AH, in _osd_start_layer()
644 (OSD_SRCADD_ADD_SFT - in _osd_start_layer()
647 osd_write(sd, fb_offset_32 & OSD_WINADL_MASK, in _osd_start_layer()
650 osd_modify(sd, OSD_VIDWIN1OFST_V1AH, in _osd_start_layer()
653 (OSD_SRCADD_OFSET_SFT - in _osd_start_layer()
656 osd_modify(sd, OSD_VIDWINADH_V1AH, in _osd_start_layer()
659 (OSD_SRCADD_ADD_SFT - in _osd_start_layer()
662 osd_write(sd, cbcr_offset_32 & OSD_WINADL_MASK, in _osd_start_layer()
672 osd_modify(sd, OSD_OSDWIN0OFST_O0AH, in _osd_start_layer()
674 (OSD_SRCADD_OFSET_SFT - in _osd_start_layer()
677 osd_modify(sd, OSD_OSDWINADH_O0AH, in _osd_start_layer()
679 (OSD_SRCADD_ADD_SFT - in _osd_start_layer()
681 osd_write(sd, fb_offset_32 & OSD_WINADL_MASK, in _osd_start_layer()
685 if (win->lconfig.pixfmt != PIXFMT_NV12) { in _osd_start_layer()
686 osd_modify(sd, OSD_VIDWIN0OFST_V0AH, in _osd_start_layer()
688 (OSD_SRCADD_OFSET_SFT - in _osd_start_layer()
691 osd_modify(sd, OSD_VIDWINADH_V0AH, in _osd_start_layer()
693 (OSD_SRCADD_ADD_SFT - in _osd_start_layer()
696 osd_write(sd, fb_offset_32 & OSD_WINADL_MASK, in _osd_start_layer()
701 osd_modify(sd, OSD_OSDWIN1OFST_O1AH, in _osd_start_layer()
703 (OSD_SRCADD_OFSET_SFT - in _osd_start_layer()
706 osd_modify(sd, OSD_OSDWINADH_O1AH, in _osd_start_layer()
708 (OSD_SRCADD_ADD_SFT - in _osd_start_layer()
711 osd_write(sd, fb_offset_32 & OSD_WINADL_MASK, in _osd_start_layer()
715 if (win->lconfig.pixfmt != PIXFMT_NV12) { in _osd_start_layer()
716 osd_modify(sd, OSD_VIDWIN1OFST_V1AH, in _osd_start_layer()
718 (OSD_SRCADD_OFSET_SFT - in _osd_start_layer()
721 osd_modify(sd, OSD_VIDWINADH_V1AH, in _osd_start_layer()
723 (OSD_SRCADD_ADD_SFT - in _osd_start_layer()
726 osd_write(sd, fb_offset_32 & OSD_WINADL_MASK, in _osd_start_layer()
734 static void osd_start_layer(struct osd_state *sd, enum osd_layer layer, in osd_start_layer() argument
738 struct osd_state *osd = sd; in osd_start_layer()
739 struct osd_window_state *win = &osd->win[layer]; in osd_start_layer()
740 struct osd_layer_config *cfg = &win->lconfig; in osd_start_layer()
743 spin_lock_irqsave(&osd->lock, flags); in osd_start_layer()
745 win->fb_base_phys = fb_base_phys & ~0x1F; in osd_start_layer()
746 _osd_start_layer(sd, layer, fb_base_phys, cbcr_ofst); in osd_start_layer()
749 osd->pingpong = in osd_start_layer()
750 _osd_dm6446_vid0_pingpong(sd, osd->field_inversion, in osd_start_layer()
751 win->fb_base_phys, in osd_start_layer()
755 spin_unlock_irqrestore(&osd->lock, flags); in osd_start_layer()
758 static void osd_get_layer_config(struct osd_state *sd, enum osd_layer layer, in osd_get_layer_config() argument
761 struct osd_state *osd = sd; in osd_get_layer_config()
762 struct osd_window_state *win = &osd->win[layer]; in osd_get_layer_config()
765 spin_lock_irqsave(&osd->lock, flags); in osd_get_layer_config()
767 *lconfig = win->lconfig; in osd_get_layer_config()
769 spin_unlock_irqrestore(&osd->lock, flags); in osd_get_layer_config()
773 * try_layer_config() - Try a specific configuration for the layer
774 * @sd: ptr to struct osd_state
779 * exit is the current lconfig, then try_layer_config() returns 1. Otherwise,
784 static int try_layer_config(struct osd_state *sd, enum osd_layer layer, in try_layer_config() argument
787 struct osd_state *osd = sd; in try_layer_config()
788 struct osd_window_state *win = &osd->win[layer]; in try_layer_config()
792 switch (lconfig->pixfmt) { in try_layer_config()
798 if (osd->vpbe_type == VPBE_VERSION_1) in try_layer_config()
806 if (osd->vpbe_type == VPBE_VERSION_1) in try_layer_config()
808 else if ((osd->vpbe_type == VPBE_VERSION_3) || in try_layer_config()
809 (osd->vpbe_type == VPBE_VERSION_2)) in try_layer_config()
813 if (osd->vpbe_type != VPBE_VERSION_2) in try_layer_config()
814 bad_config = 1; in try_layer_config()
822 bad_config = 1; in try_layer_config()
830 *lconfig = win->lconfig; in try_layer_config()
836 if ((osd->vpbe_type == VPBE_VERSION_1) && in try_layer_config()
837 is_osd_win(layer) && is_rgb_pixfmt(lconfig->pixfmt)) { in try_layer_config()
841 pixfmt = osd->win[WIN_OSD1].lconfig.pixfmt; in try_layer_config()
843 pixfmt = osd->win[WIN_OSD0].lconfig.pixfmt; in try_layer_config()
850 *lconfig = win->lconfig; in try_layer_config()
851 return 1; in try_layer_config()
856 if ((osd->vpbe_type == VPBE_VERSION_1) && is_vid_win(layer) && in try_layer_config()
857 lconfig->pixfmt == PIXFMT_RGB888) { in try_layer_config()
861 pixfmt = osd->win[WIN_VID1].lconfig.pixfmt; in try_layer_config()
863 pixfmt = osd->win[WIN_VID0].lconfig.pixfmt; in try_layer_config()
870 *lconfig = win->lconfig; in try_layer_config()
871 return 1; in try_layer_config()
875 /* window dimensions must be non-zero */ in try_layer_config()
876 if (!lconfig->line_length || !lconfig->xsize || !lconfig->ysize) { in try_layer_config()
877 *lconfig = win->lconfig; in try_layer_config()
878 return 1; in try_layer_config()
882 lconfig->line_length = ((lconfig->line_length + 31) / 32) * 32; in try_layer_config()
883 lconfig->line_length = in try_layer_config()
884 min(lconfig->line_length, (unsigned)MAX_LINE_LENGTH); in try_layer_config()
885 lconfig->xsize = min(lconfig->xsize, (unsigned)MAX_WIN_SIZE); in try_layer_config()
886 lconfig->ysize = min(lconfig->ysize, (unsigned)MAX_WIN_SIZE); in try_layer_config()
887 lconfig->xpos = min(lconfig->xpos, (unsigned)MAX_WIN_SIZE); in try_layer_config()
888 lconfig->ypos = min(lconfig->ypos, (unsigned)MAX_WIN_SIZE); in try_layer_config()
889 lconfig->interlaced = (lconfig->interlaced != 0); in try_layer_config()
890 if (lconfig->interlaced) { in try_layer_config()
892 lconfig->ysize &= ~1; in try_layer_config()
893 lconfig->ypos &= ~1; in try_layer_config()
899 static void _osd_disable_vid_rgb888(struct osd_state *sd) in _osd_disable_vid_rgb888() argument
907 if (sd->vpbe_type == VPBE_VERSION_1) in _osd_disable_vid_rgb888()
908 osd_clear(sd, OSD_MISCCTL_RGBEN, OSD_MISCCTL); in _osd_disable_vid_rgb888()
911 static void _osd_enable_vid_rgb888(struct osd_state *sd, in _osd_enable_vid_rgb888() argument
921 if (sd->vpbe_type == VPBE_VERSION_1) { in _osd_enable_vid_rgb888()
923 osd_modify(sd, OSD_MISCCTL_RGBEN | OSD_MISCCTL_RGBWIN, in _osd_enable_vid_rgb888()
926 osd_modify(sd, OSD_MISCCTL_RGBEN | OSD_MISCCTL_RGBWIN, in _osd_enable_vid_rgb888()
932 static void _osd_set_cbcr_order(struct osd_state *sd, in _osd_set_cbcr_order() argument
940 osd_clear(sd, OSD_MODE_CS, OSD_MODE); in _osd_set_cbcr_order()
942 osd_set(sd, OSD_MODE_CS, OSD_MODE); in _osd_set_cbcr_order()
945 static void _osd_set_layer_config(struct osd_state *sd, enum osd_layer layer, in _osd_set_layer_config() argument
950 _osd_set_cbcr_order(sd, lconfig->pixfmt); in _osd_set_layer_config()
954 if (sd->vpbe_type == VPBE_VERSION_1) { in _osd_set_layer_config()
956 if (lconfig->pixfmt == PIXFMT_RGB565) in _osd_set_layer_config()
958 } else if ((sd->vpbe_type == VPBE_VERSION_3) || in _osd_set_layer_config()
959 (sd->vpbe_type == VPBE_VERSION_2)) { in _osd_set_layer_config()
961 switch (lconfig->pixfmt) { in _osd_set_layer_config()
963 winmd |= (1 << in _osd_set_layer_config()
968 _osd_enable_rgb888_pixblend(sd, OSDWIN_OSD0); in _osd_set_layer_config()
981 switch (lconfig->pixfmt) { in _osd_set_layer_config()
986 bmw = 1; in _osd_set_layer_config()
999 if (lconfig->interlaced) in _osd_set_layer_config()
1002 osd_modify(sd, winmd_mask, winmd, OSD_OSDWIN0MD); in _osd_set_layer_config()
1003 osd_write(sd, lconfig->line_length >> 5, OSD_OSDWIN0OFST); in _osd_set_layer_config()
1004 osd_write(sd, lconfig->xpos, OSD_OSDWIN0XP); in _osd_set_layer_config()
1005 osd_write(sd, lconfig->xsize, OSD_OSDWIN0XL); in _osd_set_layer_config()
1006 if (lconfig->interlaced) { in _osd_set_layer_config()
1007 osd_write(sd, lconfig->ypos >> 1, OSD_OSDWIN0YP); in _osd_set_layer_config()
1008 osd_write(sd, lconfig->ysize >> 1, OSD_OSDWIN0YL); in _osd_set_layer_config()
1010 osd_write(sd, lconfig->ypos, OSD_OSDWIN0YP); in _osd_set_layer_config()
1011 osd_write(sd, lconfig->ysize, OSD_OSDWIN0YL); in _osd_set_layer_config()
1016 if (lconfig->interlaced) in _osd_set_layer_config()
1019 osd_modify(sd, winmd_mask, winmd, OSD_VIDWINMD); in _osd_set_layer_config()
1020 osd_write(sd, lconfig->line_length >> 5, OSD_VIDWIN0OFST); in _osd_set_layer_config()
1021 osd_write(sd, lconfig->xpos, OSD_VIDWIN0XP); in _osd_set_layer_config()
1022 osd_write(sd, lconfig->xsize, OSD_VIDWIN0XL); in _osd_set_layer_config()
1027 if ((sd->vpbe_type == VPBE_VERSION_2) && in _osd_set_layer_config()
1028 (lconfig->pixfmt == PIXFMT_NV12)) { in _osd_set_layer_config()
1030 if (lconfig->interlaced) { in _osd_set_layer_config()
1033 osd_modify(sd, winmd_mask, winmd, in _osd_set_layer_config()
1037 osd_modify(sd, OSD_MISCCTL_S420D, in _osd_set_layer_config()
1039 osd_write(sd, lconfig->line_length >> 5, in _osd_set_layer_config()
1041 osd_write(sd, lconfig->xpos, OSD_VIDWIN1XP); in _osd_set_layer_config()
1042 osd_write(sd, lconfig->xsize, OSD_VIDWIN1XL); in _osd_set_layer_config()
1048 if (lconfig->xsize % 32) { in _osd_set_layer_config()
1049 osd_write(sd, in _osd_set_layer_config()
1050 ((lconfig->xsize + 31) & ~31), in _osd_set_layer_config()
1052 osd_write(sd, in _osd_set_layer_config()
1053 ((lconfig->xsize + 31) & ~31), in _osd_set_layer_config()
1056 } else if ((sd->vpbe_type == VPBE_VERSION_2) && in _osd_set_layer_config()
1057 (lconfig->pixfmt != PIXFMT_NV12)) { in _osd_set_layer_config()
1058 osd_modify(sd, OSD_MISCCTL_S420D, ~OSD_MISCCTL_S420D, in _osd_set_layer_config()
1062 if (lconfig->interlaced) { in _osd_set_layer_config()
1063 osd_write(sd, lconfig->ypos >> 1, OSD_VIDWIN0YP); in _osd_set_layer_config()
1064 osd_write(sd, lconfig->ysize >> 1, OSD_VIDWIN0YL); in _osd_set_layer_config()
1065 if ((sd->vpbe_type == VPBE_VERSION_2) && in _osd_set_layer_config()
1066 lconfig->pixfmt == PIXFMT_NV12) { in _osd_set_layer_config()
1067 osd_write(sd, lconfig->ypos >> 1, in _osd_set_layer_config()
1069 osd_write(sd, lconfig->ysize >> 1, in _osd_set_layer_config()
1073 osd_write(sd, lconfig->ypos, OSD_VIDWIN0YP); in _osd_set_layer_config()
1074 osd_write(sd, lconfig->ysize, OSD_VIDWIN0YL); in _osd_set_layer_config()
1075 if ((sd->vpbe_type == VPBE_VERSION_2) && in _osd_set_layer_config()
1076 lconfig->pixfmt == PIXFMT_NV12) { in _osd_set_layer_config()
1077 osd_write(sd, lconfig->ypos, OSD_VIDWIN1YP); in _osd_set_layer_config()
1078 osd_write(sd, lconfig->ysize, OSD_VIDWIN1YL); in _osd_set_layer_config()
1088 if (lconfig->pixfmt == PIXFMT_OSD_ATTR) { in _osd_set_layer_config()
1089 if (sd->vpbe_type == VPBE_VERSION_1) { in _osd_set_layer_config()
1099 if (sd->vpbe_type == VPBE_VERSION_1) { in _osd_set_layer_config()
1101 if (lconfig->pixfmt == PIXFMT_RGB565) in _osd_set_layer_config()
1103 } else if ((sd->vpbe_type == VPBE_VERSION_3) in _osd_set_layer_config()
1104 || (sd->vpbe_type == VPBE_VERSION_2)) { in _osd_set_layer_config()
1106 switch (lconfig->pixfmt) { in _osd_set_layer_config()
1109 (1 << OSD_OSDWIN1MD_BMP1MD_SHIFT); in _osd_set_layer_config()
1114 _osd_enable_rgb888_pixblend(sd, in _osd_set_layer_config()
1128 switch (lconfig->pixfmt) { in _osd_set_layer_config()
1133 bmw = 1; in _osd_set_layer_config()
1148 if (lconfig->interlaced) in _osd_set_layer_config()
1151 osd_modify(sd, winmd_mask, winmd, OSD_OSDWIN1MD); in _osd_set_layer_config()
1152 osd_write(sd, lconfig->line_length >> 5, OSD_OSDWIN1OFST); in _osd_set_layer_config()
1153 osd_write(sd, lconfig->xpos, OSD_OSDWIN1XP); in _osd_set_layer_config()
1154 osd_write(sd, lconfig->xsize, OSD_OSDWIN1XL); in _osd_set_layer_config()
1155 if (lconfig->interlaced) { in _osd_set_layer_config()
1156 osd_write(sd, lconfig->ypos >> 1, OSD_OSDWIN1YP); in _osd_set_layer_config()
1157 osd_write(sd, lconfig->ysize >> 1, OSD_OSDWIN1YL); in _osd_set_layer_config()
1159 osd_write(sd, lconfig->ypos, OSD_OSDWIN1YP); in _osd_set_layer_config()
1160 osd_write(sd, lconfig->ysize, OSD_OSDWIN1YL); in _osd_set_layer_config()
1165 if (lconfig->interlaced) in _osd_set_layer_config()
1168 osd_modify(sd, winmd_mask, winmd, OSD_VIDWINMD); in _osd_set_layer_config()
1169 osd_write(sd, lconfig->line_length >> 5, OSD_VIDWIN1OFST); in _osd_set_layer_config()
1170 osd_write(sd, lconfig->xpos, OSD_VIDWIN1XP); in _osd_set_layer_config()
1171 osd_write(sd, lconfig->xsize, OSD_VIDWIN1XL); in _osd_set_layer_config()
1176 if (sd->vpbe_type == VPBE_VERSION_2) { in _osd_set_layer_config()
1177 if (lconfig->pixfmt == PIXFMT_NV12) { in _osd_set_layer_config()
1179 if (lconfig->interlaced) { in _osd_set_layer_config()
1182 osd_modify(sd, winmd_mask, winmd, in _osd_set_layer_config()
1185 osd_modify(sd, OSD_MISCCTL_S420D, in _osd_set_layer_config()
1187 osd_write(sd, lconfig->line_length >> 5, in _osd_set_layer_config()
1189 osd_write(sd, lconfig->xpos, OSD_VIDWIN0XP); in _osd_set_layer_config()
1190 osd_write(sd, lconfig->xsize, OSD_VIDWIN0XL); in _osd_set_layer_config()
1192 osd_modify(sd, OSD_MISCCTL_S420D, in _osd_set_layer_config()
1197 if (lconfig->interlaced) { in _osd_set_layer_config()
1198 osd_write(sd, lconfig->ypos >> 1, OSD_VIDWIN1YP); in _osd_set_layer_config()
1199 osd_write(sd, lconfig->ysize >> 1, OSD_VIDWIN1YL); in _osd_set_layer_config()
1200 if ((sd->vpbe_type == VPBE_VERSION_2) && in _osd_set_layer_config()
1201 lconfig->pixfmt == PIXFMT_NV12) { in _osd_set_layer_config()
1202 osd_write(sd, lconfig->ypos >> 1, in _osd_set_layer_config()
1204 osd_write(sd, lconfig->ysize >> 1, in _osd_set_layer_config()
1208 osd_write(sd, lconfig->ypos, OSD_VIDWIN1YP); in _osd_set_layer_config()
1209 osd_write(sd, lconfig->ysize, OSD_VIDWIN1YL); in _osd_set_layer_config()
1210 if ((sd->vpbe_type == VPBE_VERSION_2) && in _osd_set_layer_config()
1211 lconfig->pixfmt == PIXFMT_NV12) { in _osd_set_layer_config()
1212 osd_write(sd, lconfig->ypos, OSD_VIDWIN0YP); in _osd_set_layer_config()
1213 osd_write(sd, lconfig->ysize, OSD_VIDWIN0YL); in _osd_set_layer_config()
1220 static int osd_set_layer_config(struct osd_state *sd, enum osd_layer layer, in osd_set_layer_config() argument
1223 struct osd_state *osd = sd; in osd_set_layer_config()
1224 struct osd_window_state *win = &osd->win[layer]; in osd_set_layer_config()
1225 struct osd_layer_config *cfg = &win->lconfig; in osd_set_layer_config()
1229 spin_lock_irqsave(&osd->lock, flags); in osd_set_layer_config()
1231 reject_config = try_layer_config(sd, layer, lconfig); in osd_set_layer_config()
1233 spin_unlock_irqrestore(&osd->lock, flags); in osd_set_layer_config()
1238 if (is_yc_pixfmt(lconfig->pixfmt)) in osd_set_layer_config()
1239 osd->yc_pixfmt = lconfig->pixfmt; in osd_set_layer_config()
1246 if (((lconfig->pixfmt == PIXFMT_OSD_ATTR) && in osd_set_layer_config()
1247 (cfg->pixfmt != PIXFMT_OSD_ATTR)) || in osd_set_layer_config()
1248 ((lconfig->pixfmt != PIXFMT_OSD_ATTR) && in osd_set_layer_config()
1249 (cfg->pixfmt == PIXFMT_OSD_ATTR))) { in osd_set_layer_config()
1250 win->is_enabled = 0; in osd_set_layer_config()
1251 _osd_disable_layer(sd, layer); in osd_set_layer_config()
1255 _osd_set_layer_config(sd, layer, lconfig); in osd_set_layer_config()
1259 &osd->osdwin[OSDWIN_OSD1]; in osd_set_layer_config()
1261 if ((lconfig->pixfmt != PIXFMT_OSD_ATTR) && in osd_set_layer_config()
1262 (cfg->pixfmt == PIXFMT_OSD_ATTR)) { in osd_set_layer_config()
1270 _osd_set_osd_clut(sd, OSDWIN_OSD1, in osd_set_layer_config()
1271 osdwin_state->clut); in osd_set_layer_config()
1272 _osd_set_blending_factor(sd, OSDWIN_OSD1, in osd_set_layer_config()
1273 osdwin_state->blend); in osd_set_layer_config()
1274 if (osdwin_state->colorkey_blending) { in osd_set_layer_config()
1275 _osd_enable_color_key(sd, OSDWIN_OSD1, in osd_set_layer_config()
1276 osdwin_state-> in osd_set_layer_config()
1278 lconfig->pixfmt); in osd_set_layer_config()
1280 _osd_disable_color_key(sd, OSDWIN_OSD1); in osd_set_layer_config()
1281 _osd_set_rec601_attenuation(sd, OSDWIN_OSD1, in osd_set_layer_config()
1282 osdwin_state-> in osd_set_layer_config()
1284 } else if ((lconfig->pixfmt == PIXFMT_OSD_ATTR) && in osd_set_layer_config()
1285 (cfg->pixfmt != PIXFMT_OSD_ATTR)) { in osd_set_layer_config()
1291 _osd_set_blink_attribute(sd, osd->is_blinking, in osd_set_layer_config()
1292 osd->blink); in osd_set_layer_config()
1297 * If we just switched to a 1-, 2-, or 4-bits-per-pixel bitmap format in osd_set_layer_config()
1300 if ((lconfig->pixfmt != cfg->pixfmt) && in osd_set_layer_config()
1301 ((lconfig->pixfmt == PIXFMT_1BPP) || in osd_set_layer_config()
1302 (lconfig->pixfmt == PIXFMT_2BPP) || in osd_set_layer_config()
1303 (lconfig->pixfmt == PIXFMT_4BPP))) { in osd_set_layer_config()
1307 &osd->osdwin[osdwin]; in osd_set_layer_config()
1311 switch (lconfig->pixfmt) { in osd_set_layer_config()
1327 * 1 maps to clut entry 1, etc. in osd_set_layer_config()
1330 osdwin_state->palette_map[clut_index] = clut_index; in osd_set_layer_config()
1332 _osd_set_palette_map(sd, osdwin, clut_index, in osd_set_layer_config()
1334 lconfig->pixfmt); in osd_set_layer_config()
1341 if (osd->win[WIN_VID0].lconfig.pixfmt == PIXFMT_RGB888) in osd_set_layer_config()
1342 _osd_enable_vid_rgb888(sd, WIN_VID0); in osd_set_layer_config()
1343 else if (osd->win[WIN_VID1].lconfig.pixfmt == PIXFMT_RGB888) in osd_set_layer_config()
1344 _osd_enable_vid_rgb888(sd, WIN_VID1); in osd_set_layer_config()
1346 _osd_disable_vid_rgb888(sd); in osd_set_layer_config()
1349 osd->pingpong = in osd_set_layer_config()
1350 _osd_dm6446_vid0_pingpong(sd, osd->field_inversion, in osd_set_layer_config()
1351 win->fb_base_phys, in osd_set_layer_config()
1355 spin_unlock_irqrestore(&osd->lock, flags); in osd_set_layer_config()
1360 static void osd_init_layer(struct osd_state *sd, enum osd_layer layer) in osd_init_layer() argument
1362 struct osd_state *osd = sd; in osd_init_layer()
1363 struct osd_window_state *win = &osd->win[layer]; in osd_init_layer()
1366 struct osd_layer_config *cfg = &win->lconfig; in osd_init_layer()
1369 spin_lock_irqsave(&osd->lock, flags); in osd_init_layer()
1371 win->is_enabled = 0; in osd_init_layer()
1372 _osd_disable_layer(sd, layer); in osd_init_layer()
1374 win->h_zoom = ZOOM_X1; in osd_init_layer()
1375 win->v_zoom = ZOOM_X1; in osd_init_layer()
1376 _osd_set_zoom(sd, layer, win->h_zoom, win->v_zoom); in osd_init_layer()
1378 win->fb_base_phys = 0; in osd_init_layer()
1379 _osd_start_layer(sd, layer, win->fb_base_phys, 0); in osd_init_layer()
1381 cfg->line_length = 0; in osd_init_layer()
1382 cfg->xsize = 0; in osd_init_layer()
1383 cfg->ysize = 0; in osd_init_layer()
1384 cfg->xpos = 0; in osd_init_layer()
1385 cfg->ypos = 0; in osd_init_layer()
1386 cfg->interlaced = 0; in osd_init_layer()
1391 osdwin_state = &osd->osdwin[osdwin]; in osd_init_layer()
1397 cfg->pixfmt = PIXFMT_8BPP; in osd_init_layer()
1398 _osd_set_layer_config(sd, layer, cfg); in osd_init_layer()
1399 osdwin_state->clut = RAM_CLUT; in osd_init_layer()
1400 _osd_set_osd_clut(sd, osdwin, osdwin_state->clut); in osd_init_layer()
1401 osdwin_state->colorkey_blending = 0; in osd_init_layer()
1402 _osd_disable_color_key(sd, osdwin); in osd_init_layer()
1403 osdwin_state->blend = OSD_8_VID_0; in osd_init_layer()
1404 _osd_set_blending_factor(sd, osdwin, osdwin_state->blend); in osd_init_layer()
1405 osdwin_state->rec601_attenuation = 0; in osd_init_layer()
1406 _osd_set_rec601_attenuation(sd, osdwin, in osd_init_layer()
1407 osdwin_state-> in osd_init_layer()
1410 osd->is_blinking = 0; in osd_init_layer()
1411 osd->blink = BLINK_X1; in osd_init_layer()
1416 cfg->pixfmt = osd->yc_pixfmt; in osd_init_layer()
1417 _osd_set_layer_config(sd, layer, cfg); in osd_init_layer()
1421 spin_unlock_irqrestore(&osd->lock, flags); in osd_init_layer()
1424 static void osd_release_layer(struct osd_state *sd, enum osd_layer layer) in osd_release_layer() argument
1426 struct osd_state *osd = sd; in osd_release_layer()
1427 struct osd_window_state *win = &osd->win[layer]; in osd_release_layer()
1430 spin_lock_irqsave(&osd->lock, flags); in osd_release_layer()
1432 if (!win->is_allocated) { in osd_release_layer()
1433 spin_unlock_irqrestore(&osd->lock, flags); in osd_release_layer()
1437 spin_unlock_irqrestore(&osd->lock, flags); in osd_release_layer()
1438 osd_init_layer(sd, layer); in osd_release_layer()
1439 spin_lock_irqsave(&osd->lock, flags); in osd_release_layer()
1441 win->is_allocated = 0; in osd_release_layer()
1443 spin_unlock_irqrestore(&osd->lock, flags); in osd_release_layer()
1446 static int osd_request_layer(struct osd_state *sd, enum osd_layer layer) in osd_request_layer() argument
1448 struct osd_state *osd = sd; in osd_request_layer()
1449 struct osd_window_state *win = &osd->win[layer]; in osd_request_layer()
1452 spin_lock_irqsave(&osd->lock, flags); in osd_request_layer()
1454 if (win->is_allocated) { in osd_request_layer()
1455 spin_unlock_irqrestore(&osd->lock, flags); in osd_request_layer()
1456 return -1; in osd_request_layer()
1458 win->is_allocated = 1; in osd_request_layer()
1460 spin_unlock_irqrestore(&osd->lock, flags); in osd_request_layer()
1465 static void _osd_init(struct osd_state *sd) in _osd_init() argument
1467 osd_write(sd, 0, OSD_MODE); in _osd_init()
1468 osd_write(sd, 0, OSD_VIDWINMD); in _osd_init()
1469 osd_write(sd, 0, OSD_OSDWIN0MD); in _osd_init()
1470 osd_write(sd, 0, OSD_OSDWIN1MD); in _osd_init()
1471 osd_write(sd, 0, OSD_RECTCUR); in _osd_init()
1472 osd_write(sd, 0, OSD_MISCCTL); in _osd_init()
1473 if (sd->vpbe_type == VPBE_VERSION_3) { in _osd_init()
1474 osd_write(sd, 0, OSD_VBNDRY); in _osd_init()
1475 osd_write(sd, 0, OSD_EXTMODE); in _osd_init()
1476 osd_write(sd, OSD_MISCCTL_DMANG, OSD_MISCCTL); in _osd_init()
1480 static void osd_set_left_margin(struct osd_state *sd, u32 val) in osd_set_left_margin() argument
1482 osd_write(sd, val, OSD_BASEPX); in osd_set_left_margin()
1485 static void osd_set_top_margin(struct osd_state *sd, u32 val) in osd_set_top_margin() argument
1487 osd_write(sd, val, OSD_BASEPY); in osd_set_top_margin()
1493 return -ENODEV; in osd_initialize()
1497 osd->yc_pixfmt = PIXFMT_YCBCRI; in osd_initialize()
1499 if (osd->vpbe_type == VPBE_VERSION_3) { in osd_initialize()
1504 osd->rom_clut = ROM_CLUT1; in osd_initialize()
1507 _osd_set_field_inversion(osd, osd->field_inversion); in osd_initialize()
1508 _osd_set_rom_clut(osd, osd->rom_clut); in osd_initialize()
1539 return -EINVAL; in osd_probe()
1541 osd = devm_kzalloc(&pdev->dev, sizeof(struct osd_state), GFP_KERNEL); in osd_probe()
1543 return -ENOMEM; in osd_probe()
1546 osd->dev = &pdev->dev; in osd_probe()
1547 osd->vpbe_type = pdev_id->driver_data; in osd_probe()
1550 osd->osd_base = devm_ioremap_resource(&pdev->dev, res); in osd_probe()
1551 if (IS_ERR(osd->osd_base)) in osd_probe()
1552 return PTR_ERR(osd->osd_base); in osd_probe()
1554 osd->osd_base_phys = res->start; in osd_probe()
1555 osd->osd_size = resource_size(res); in osd_probe()
1556 spin_lock_init(&osd->lock); in osd_probe()
1557 osd->ops = osd_ops; in osd_probe()
1559 dev_notice(osd->dev, "OSD sub device probe success\n"); in osd_probe()