2 * Copyright (C) STMicroelectronics SA 2014
3 * Author: Fabien Dessenne <fabien.dessenne@st.com> for STMicroelectronics.
4 * License terms: GNU General Public License (GPL), version 2
30 /* Registers values */
31 #define VID_CTL_IGNORE (BIT(31) | BIT(30))
32 #define VID_CTL_PSI_ENABLE (BIT(2) | BIT(1) | BIT(0))
33 #define VID_ALP_OPAQUE 0x00000080
34 #define VID_BC_DFLT 0x00008000
35 #define VID_TINT_DFLT 0x00000000
36 #define VID_CSAT_DFLT 0x00000080
37 /* YCbCr to RGB BT709:
39 * G = Y-0.4590Cr-0.1826Cb
41 #define VID_MPR0_BT709 0x0A800000
42 #define VID_MPR1_BT709 0x0AC50000
43 #define VID_MPR2_BT709 0x07150545
44 #define VID_MPR3_BT709 0x00000AE8
46 static int sti_vid_prepare_layer(struct sti_layer
*vid
, bool first_prepare
)
51 val
= readl(vid
->regs
+ VID_CTL
);
52 val
&= ~VID_CTL_IGNORE
;
53 writel(val
, vid
->regs
+ VID_CTL
);
58 static int sti_vid_commit_layer(struct sti_layer
*vid
)
60 struct drm_display_mode
*mode
= vid
->mode
;
61 u32 ydo
, xdo
, yds
, xds
;
63 ydo
= sti_vtg_get_line_number(*mode
, vid
->dst_y
);
64 yds
= sti_vtg_get_line_number(*mode
, vid
->dst_y
+ vid
->dst_h
- 1);
65 xdo
= sti_vtg_get_pixel_number(*mode
, vid
->dst_x
);
66 xds
= sti_vtg_get_pixel_number(*mode
, vid
->dst_x
+ vid
->dst_w
- 1);
68 writel((ydo
<< 16) | xdo
, vid
->regs
+ VID_VPO
);
69 writel((yds
<< 16) | xds
, vid
->regs
+ VID_VPS
);
74 static int sti_vid_disable_layer(struct sti_layer
*vid
)
79 val
= readl(vid
->regs
+ VID_CTL
);
80 val
|= VID_CTL_IGNORE
;
81 writel(val
, vid
->regs
+ VID_CTL
);
86 static const uint32_t *sti_vid_get_formats(struct sti_layer
*layer
)
91 static unsigned int sti_vid_get_nb_formats(struct sti_layer
*layer
)
96 static void sti_vid_init(struct sti_layer
*vid
)
98 /* Enable PSI, Mask layer */
99 writel(VID_CTL_PSI_ENABLE
| VID_CTL_IGNORE
, vid
->regs
+ VID_CTL
);
102 writel(VID_ALP_OPAQUE
, vid
->regs
+ VID_ALP
);
104 /* Color conversion parameters */
105 writel(VID_MPR0_BT709
, vid
->regs
+ VID_MPR0
);
106 writel(VID_MPR1_BT709
, vid
->regs
+ VID_MPR1
);
107 writel(VID_MPR2_BT709
, vid
->regs
+ VID_MPR2
);
108 writel(VID_MPR3_BT709
, vid
->regs
+ VID_MPR3
);
110 /* Brightness, contrast, tint, saturation */
111 writel(VID_BC_DFLT
, vid
->regs
+ VID_BC
);
112 writel(VID_TINT_DFLT
, vid
->regs
+ VID_TINT
);
113 writel(VID_CSAT_DFLT
, vid
->regs
+ VID_CSAT
);
116 static const struct sti_layer_funcs vid_ops
= {
117 .get_formats
= sti_vid_get_formats
,
118 .get_nb_formats
= sti_vid_get_nb_formats
,
119 .init
= sti_vid_init
,
120 .prepare
= sti_vid_prepare_layer
,
121 .commit
= sti_vid_commit_layer
,
122 .disable
= sti_vid_disable_layer
,
125 struct sti_layer
*sti_vid_create(struct device
*dev
)
127 struct sti_layer
*vid
;
129 vid
= devm_kzalloc(dev
, sizeof(*vid
), GFP_KERNEL
);
131 DRM_ERROR("Failed to allocate memory for VID\n");