24 #include <linux/module.h>
25 #include <linux/kernel.h>
29 #include <linux/slab.h>
31 #include <mach/cputype.h>
32 #include <mach/hardware.h>
42 #define MODULE_NAME VPBE_OSD_SUBDEV_NAME
91 u32 new_val = (
readl(addr) & ~mask) | (val & mask);
99 #define is_osd_win(layer) (((layer) == WIN_OSD0) || ((layer) == WIN_OSD1))
100 #define is_vid_win(layer) (((layer) == WIN_VID0) || ((layer) == WIN_VID1))
101 #define is_rgb_pixfmt(pixfmt) \
102 (((pixfmt) == PIXFMT_RGB565) || ((pixfmt) == PIXFMT_RGB888))
103 #define is_yc_pixfmt(pixfmt) \
104 (((pixfmt) == PIXFMT_YCbCrI) || ((pixfmt) == PIXFMT_YCrCbI) || \
105 ((pixfmt) == PIXFMT_NV12))
106 #define MAX_WIN_SIZE OSD_VIDWIN0XP_V0X
107 #define MAX_LINE_LENGTH (OSD_VIDWIN0OFST_V0LO << 5)
124 static int _osd_dm6446_vid0_pingpong(
struct osd_state *sd,
126 unsigned long fb_base_phys,
134 if (!field_inversion || !lconfig->
interlaced) {
170 static void _osd_set_blink_attribute(
struct osd_state *sd,
int enable,
184 static void _osd_set_rom_clut(
struct osd_state *sd,
193 static void _osd_set_palette_map(
struct osd_state *sd,
195 unsigned char pixel_value,
196 unsigned char clut_index,
199 static const int map_2bpp[] = { 0, 5, 10, 15 };
200 static const int map_1bpp[] = { 0, 15 };
208 bmp_reg = map_1bpp[pixel_value & 0x1];
211 bmp_reg = map_2bpp[pixel_value & 0x3];
214 bmp_reg = pixel_value & 0xf;
233 bmp_mask = 0xff << 8;
239 osd_modify(sd, bmp_mask, clut_index << bmp_shift, bmp_offset);
242 static void _osd_set_rec601_attenuation(
struct osd_state *sd,
277 static void _osd_set_blending_factor(
struct osd_state *sd,
293 static void _osd_enable_rgb888_pixblend(
struct osd_state *sd,
310 static void _osd_enable_color_key(
struct osd_state *sd,
373 static void _osd_disable_color_key(
struct osd_state *sd,
386 static void _osd_set_osd_clut(
struct osd_state *sd,
469 spin_unlock_irqrestore(&osd->
lock, flags);
474 _osd_disable_layer(sd, layer);
476 spin_unlock_irqrestore(&osd->
lock, flags);
479 static void _osd_enable_attribute_mode(
struct osd_state *sd)
524 spin_unlock_irqrestore(&osd->
lock, flags);
529 spin_unlock_irqrestore(&osd->
lock, flags);
535 _osd_enable_layer(sd, layer);
537 _osd_enable_attribute_mode(sd);
541 spin_unlock_irqrestore(&osd->
lock, flags);
546 #define OSD_SRC_ADDR_HIGH4 0x7800000
547 #define OSD_SRC_ADDR_HIGH7 0x7F0000
548 #define OSD_SRCADD_OFSET_SFT 23
549 #define OSD_SRCADD_ADD_SFT 16
550 #define OSD_WINADL_MASK 0xFFFF
551 #define OSD_WINOFST_MASK 0x1000
552 #define VPBE_REG_BASE 0x80000000
555 unsigned long fb_base_phys,
556 unsigned long cbcr_ofst)
575 unsigned long fb_offset_32 =
614 unsigned long fb_offset_32, cbcr_offset_32;
618 cbcr_offset_32 = cbcr_ofst;
620 cbcr_offset_32 = win->
lconfig.line_length *
622 cbcr_offset_32 += fb_offset_32;
623 fb_offset_32 = fb_offset_32 >> 5;
624 cbcr_offset_32 = cbcr_offset_32 >> 5;
649 OSD_SRC_ADDR_HIGH4) >>
655 OSD_SRC_ADDR_HIGH7) >>
659 osd_write(sd, cbcr_offset_32 & OSD_WINADL_MASK,
684 ((fb_offset_32 & OSD_SRC_ADDR_HIGH4) >>
689 (fb_offset_32 & OSD_SRC_ADDR_HIGH7) >>
693 osd_write(sd, fb_offset_32 & OSD_WINADL_MASK,
699 ((fb_offset_32 & OSD_SRC_ADDR_HIGH4) >>
704 (fb_offset_32 & OSD_SRC_ADDR_HIGH7) >>
708 osd_write(sd, fb_offset_32 & OSD_WINADL_MASK,
714 ((fb_offset_32 & OSD_SRC_ADDR_HIGH4) >>
719 (fb_offset_32 & OSD_SRC_ADDR_HIGH7) >>
723 osd_write(sd, fb_offset_32 & OSD_WINADL_MASK,
733 unsigned long cbcr_ofst)
743 _osd_start_layer(sd, layer, fb_base_phys, cbcr_ofst);
752 spin_unlock_irqrestore(&osd->
lock, flags);
766 spin_unlock_irqrestore(&osd->
lock, flags);
789 switch (lconfig->
pixfmt) {
888 lconfig->
ysize &= ~1;
895 static void _osd_disable_vid_rgb888(
struct osd_state *sd)
907 static void _osd_enable_vid_rgb888(
struct osd_state *sd,
928 static void _osd_set_cbcr_order(
struct osd_state *sd,
944 u32 winmd = 0, winmd_mask = 0, bmw = 0;
946 _osd_set_cbcr_order(sd, lconfig->
pixfmt);
957 switch (lconfig->
pixfmt) {
977 switch (lconfig->
pixfmt) {
1029 osd_modify(sd, winmd_mask, winmd,
1044 if (lconfig->
xsize % 32) {
1046 ((lconfig->
xsize + 31) & ~31),
1049 ((lconfig->
xsize + 31) & ~31),
1063 osd_write(sd, lconfig->
ypos >> 1,
1065 osd_write(sd, lconfig->
ysize >> 1,
1102 switch (lconfig->
pixfmt) {
1110 _osd_enable_rgb888_pixblend(sd,
1124 switch (lconfig->
pixfmt) {
1178 osd_modify(sd, winmd_mask, winmd,
1198 osd_write(sd, lconfig->
ypos >> 1,
1200 osd_write(sd, lconfig->
ysize >> 1,
1222 unsigned long flags;
1227 reject_config = try_layer_config(sd, layer, lconfig);
1228 if (reject_config) {
1229 spin_unlock_irqrestore(&osd->
lock, flags);
1230 return reject_config;
1247 _osd_disable_layer(sd, layer);
1251 _osd_set_layer_config(sd, layer, lconfig);
1267 osdwin_state->
clut);
1269 osdwin_state->
blend);
1304 unsigned char clut_index;
1305 unsigned char clut_entries = 0;
1307 switch (lconfig->
pixfmt) {
1325 for (clut_index = 0; clut_index < 16; clut_index++) {
1326 osdwin_state->
palette_map[clut_index] = clut_index;
1327 if (clut_index < clut_entries) {
1328 _osd_set_palette_map(sd, osdwin, clut_index,
1338 _osd_enable_vid_rgb888(sd,
WIN_VID0);
1340 _osd_enable_vid_rgb888(sd,
WIN_VID1);
1342 _osd_disable_vid_rgb888(sd);
1351 spin_unlock_irqrestore(&osd->
lock, flags);
1363 unsigned long flags;
1368 _osd_disable_layer(sd, layer);
1387 osdwin_state = &osd->
osdwin[osdwin];
1394 _osd_set_layer_config(sd, layer, cfg);
1396 _osd_set_osd_clut(sd, osdwin, osdwin_state->
clut);
1398 _osd_disable_color_key(sd, osdwin);
1400 _osd_set_blending_factor(sd, osdwin, osdwin_state->
blend);
1402 _osd_set_rec601_attenuation(sd, osdwin,
1404 rec601_attenuation);
1405 if (osdwin == OSDWIN_OSD1) {
1413 _osd_set_layer_config(sd, layer, cfg);
1417 spin_unlock_irqrestore(&osd->
lock, flags);
1424 unsigned long flags;
1429 spin_unlock_irqrestore(&osd->
lock, flags);
1433 spin_unlock_irqrestore(&osd->
lock, flags);
1434 osd_init_layer(sd, layer);
1439 spin_unlock_irqrestore(&osd->
lock, flags);
1446 unsigned long flags;
1451 spin_unlock_irqrestore(&osd->
lock, flags);
1456 spin_unlock_irqrestore(&osd->
lock, flags);
1461 static void _osd_init(
struct osd_state *sd)
1476 static void osd_set_left_margin(
struct osd_state *sd,
u32 val)
1481 static void osd_set_top_margin(
struct osd_state *sd,
u32 val)
1486 static int osd_initialize(
struct osd_state *osd)
1504 _osd_set_rom_clut(osd, osd->
rom_clut);
1515 .initialize = osd_initialize,
1516 .request_layer = osd_request_layer,
1517 .release_layer = osd_release_layer,
1518 .enable_layer = osd_enable_layer,
1519 .disable_layer = osd_disable_layer,
1520 .set_layer_config = osd_set_layer_config,
1521 .get_layer_config = osd_get_layer_config,
1522 .start_layer = osd_start_layer,
1523 .set_left_margin = osd_set_left_margin,
1524 .set_top_margin = osd_set_top_margin,
1541 if (
NULL == pdev->
dev.platform_data) {
1542 dev_err(osd->
dev,
"No platform data defined for OSD"
1550 dev_err(osd->
dev,
"Unable to get OSD register address map\n");
1555 osd->
osd_size = resource_size(res);
1558 dev_err(osd->
dev,
"Unable to reserve OSD MMIO region\n");
1565 dev_err(osd->
dev,
"Unable to map the OSD region\n");
1571 platform_set_drvdata(pdev, osd);
1572 dev_notice(osd->
dev,
"OSD sub device probe success\n");
1584 struct osd_state *osd = platform_get_drvdata(pdev);
1594 .remove = osd_remove,