2 * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
3 * Author:Mark Yao <mark.yao@rock-chips.com>
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
17 #include <linux/kernel.h>
18 #include <linux/component.h>
20 #include "rockchip_drm_vop.h"
21 #include "rockchip_vop_reg.h"
23 #define VOP_REG(off, _mask, s) \
28 static const uint32_t formats_01[] = {
42 static const uint32_t formats_234[] = {
53 static const struct vop_scl_extension win_full_ext = {
54 .cbcr_vsd_mode = VOP_REG(WIN0_CTRL1, 0x1, 31),
55 .cbcr_vsu_mode = VOP_REG(WIN0_CTRL1, 0x1, 30),
56 .cbcr_hsd_mode = VOP_REG(WIN0_CTRL1, 0x3, 28),
57 .cbcr_ver_scl_mode = VOP_REG(WIN0_CTRL1, 0x3, 26),
58 .cbcr_hor_scl_mode = VOP_REG(WIN0_CTRL1, 0x3, 24),
59 .yrgb_vsd_mode = VOP_REG(WIN0_CTRL1, 0x1, 23),
60 .yrgb_vsu_mode = VOP_REG(WIN0_CTRL1, 0x1, 22),
61 .yrgb_hsd_mode = VOP_REG(WIN0_CTRL1, 0x3, 20),
62 .yrgb_ver_scl_mode = VOP_REG(WIN0_CTRL1, 0x3, 18),
63 .yrgb_hor_scl_mode = VOP_REG(WIN0_CTRL1, 0x3, 16),
64 .line_load_mode = VOP_REG(WIN0_CTRL1, 0x1, 15),
65 .cbcr_axi_gather_num = VOP_REG(WIN0_CTRL1, 0x7, 12),
66 .yrgb_axi_gather_num = VOP_REG(WIN0_CTRL1, 0xf, 8),
67 .vsd_cbcr_gt2 = VOP_REG(WIN0_CTRL1, 0x1, 7),
68 .vsd_cbcr_gt4 = VOP_REG(WIN0_CTRL1, 0x1, 6),
69 .vsd_yrgb_gt2 = VOP_REG(WIN0_CTRL1, 0x1, 5),
70 .vsd_yrgb_gt4 = VOP_REG(WIN0_CTRL1, 0x1, 4),
71 .bic_coe_sel = VOP_REG(WIN0_CTRL1, 0x3, 2),
72 .cbcr_axi_gather_en = VOP_REG(WIN0_CTRL1, 0x1, 1),
73 .yrgb_axi_gather_en = VOP_REG(WIN0_CTRL1, 0x1, 0),
74 .lb_mode = VOP_REG(WIN0_CTRL0, 0x7, 5),
77 static const struct vop_scl_regs win_full_scl = {
78 .scale_yrgb_x = VOP_REG(WIN0_SCL_FACTOR_YRGB, 0xffff, 0x0),
79 .scale_yrgb_y = VOP_REG(WIN0_SCL_FACTOR_YRGB, 0xffff, 16),
80 .scale_cbcr_x = VOP_REG(WIN0_SCL_FACTOR_CBR, 0xffff, 0x0),
81 .scale_cbcr_y = VOP_REG(WIN0_SCL_FACTOR_CBR, 0xffff, 16),
84 static const struct vop_win_phy win01_data = {
86 .data_formats = formats_01,
87 .nformats = ARRAY_SIZE(formats_01),
88 .enable = VOP_REG(WIN0_CTRL0, 0x1, 0),
89 .format = VOP_REG(WIN0_CTRL0, 0x7, 1),
90 .rb_swap = VOP_REG(WIN0_CTRL0, 0x1, 12),
91 .act_info = VOP_REG(WIN0_ACT_INFO, 0x1fff1fff, 0),
92 .dsp_info = VOP_REG(WIN0_DSP_INFO, 0x0fff0fff, 0),
93 .dsp_st = VOP_REG(WIN0_DSP_ST, 0x1fff1fff, 0),
94 .yrgb_mst = VOP_REG(WIN0_YRGB_MST, 0xffffffff, 0),
95 .uv_mst = VOP_REG(WIN0_CBR_MST, 0xffffffff, 0),
96 .yrgb_vir = VOP_REG(WIN0_VIR, 0x3fff, 0),
97 .uv_vir = VOP_REG(WIN0_VIR, 0x3fff, 16),
98 .src_alpha_ctl = VOP_REG(WIN0_SRC_ALPHA_CTRL, 0xff, 0),
99 .dst_alpha_ctl = VOP_REG(WIN0_DST_ALPHA_CTRL, 0xff, 0),
102 static const struct vop_win_phy win23_data = {
103 .data_formats = formats_234,
104 .nformats = ARRAY_SIZE(formats_234),
105 .enable = VOP_REG(WIN2_CTRL0, 0x1, 0),
106 .format = VOP_REG(WIN2_CTRL0, 0x7, 1),
107 .rb_swap = VOP_REG(WIN2_CTRL0, 0x1, 12),
108 .dsp_info = VOP_REG(WIN2_DSP_INFO0, 0x0fff0fff, 0),
109 .dsp_st = VOP_REG(WIN2_DSP_ST0, 0x1fff1fff, 0),
110 .yrgb_mst = VOP_REG(WIN2_MST0, 0xffffffff, 0),
111 .yrgb_vir = VOP_REG(WIN2_VIR0_1, 0x1fff, 0),
112 .src_alpha_ctl = VOP_REG(WIN2_SRC_ALPHA_CTRL, 0xff, 0),
113 .dst_alpha_ctl = VOP_REG(WIN2_DST_ALPHA_CTRL, 0xff, 0),
116 static const struct vop_ctrl ctrl_data = {
117 .standby = VOP_REG(SYS_CTRL, 0x1, 22),
118 .gate_en = VOP_REG(SYS_CTRL, 0x1, 23),
119 .mmu_en = VOP_REG(SYS_CTRL, 0x1, 20),
120 .rgb_en = VOP_REG(SYS_CTRL, 0x1, 12),
121 .hdmi_en = VOP_REG(SYS_CTRL, 0x1, 13),
122 .edp_en = VOP_REG(SYS_CTRL, 0x1, 14),
123 .mipi_en = VOP_REG(SYS_CTRL, 0x1, 15),
124 .dither_down = VOP_REG(DSP_CTRL1, 0xf, 1),
125 .dither_up = VOP_REG(DSP_CTRL1, 0x1, 6),
126 .data_blank = VOP_REG(DSP_CTRL0, 0x1, 19),
127 .out_mode = VOP_REG(DSP_CTRL0, 0xf, 0),
128 .pin_pol = VOP_REG(DSP_CTRL0, 0xf, 4),
129 .htotal_pw = VOP_REG(DSP_HTOTAL_HS_END, 0x1fff1fff, 0),
130 .hact_st_end = VOP_REG(DSP_HACT_ST_END, 0x1fff1fff, 0),
131 .vtotal_pw = VOP_REG(DSP_VTOTAL_VS_END, 0x1fff1fff, 0),
132 .vact_st_end = VOP_REG(DSP_VACT_ST_END, 0x1fff1fff, 0),
133 .hpost_st_end = VOP_REG(POST_DSP_HACT_INFO, 0x1fff1fff, 0),
134 .vpost_st_end = VOP_REG(POST_DSP_VACT_INFO, 0x1fff1fff, 0),
135 .cfg_done = VOP_REG(REG_CFG_DONE, 0x1, 0),
138 static const struct vop_reg_data vop_init_reg_table[] = {
139 {SYS_CTRL, 0x00c00000},
140 {DSP_CTRL0, 0x00000000},
141 {WIN0_CTRL0, 0x00000080},
142 {WIN1_CTRL0, 0x00000080},
143 /* TODO: Win2/3 support multiple area function, but we haven't found
144 * a suitable way to use it yet, so let's just use them as other windows
145 * with only area 0 enabled.
147 {WIN2_CTRL0, 0x00000010},
148 {WIN3_CTRL0, 0x00000010},
152 * Note: rk3288 has a dedicated 'cursor' window, however, that window requires
153 * special support to get alpha blending working. For now, just use overlay
154 * window 3 for the drm cursor.
157 static const struct vop_win_data rk3288_vop_win_data[] = {
158 { .base = 0x00, .phy = &win01_data, .type = DRM_PLANE_TYPE_PRIMARY },
159 { .base = 0x40, .phy = &win01_data, .type = DRM_PLANE_TYPE_OVERLAY },
160 { .base = 0x00, .phy = &win23_data, .type = DRM_PLANE_TYPE_OVERLAY },
161 { .base = 0x50, .phy = &win23_data, .type = DRM_PLANE_TYPE_CURSOR },
164 static const int rk3288_vop_intrs[] = {
171 static const struct vop_intr rk3288_vop_intr = {
172 .intrs = rk3288_vop_intrs,
173 .nintrs = ARRAY_SIZE(rk3288_vop_intrs),
174 .status = VOP_REG(INTR_CTRL0, 0xf, 0),
175 .enable = VOP_REG(INTR_CTRL0, 0xf, 4),
176 .clear = VOP_REG(INTR_CTRL0, 0xf, 8),
179 static const struct vop_data rk3288_vop = {
180 .init_table = vop_init_reg_table,
181 .intr = &rk3288_vop_intr,
182 .table_size = ARRAY_SIZE(vop_init_reg_table),
184 .win = rk3288_vop_win_data,
185 .win_size = ARRAY_SIZE(rk3288_vop_win_data),
188 static const struct of_device_id vop_driver_dt_match[] = {
189 { .compatible = "rockchip,rk3288-vop",
190 .data = &rk3288_vop },
193 MODULE_DEVICE_TABLE(of, vop_driver_dt_match);
195 static int vop_probe(struct platform_device *pdev)
197 struct device *dev = &pdev->dev;
200 dev_err(dev, "can't find vop devices\n");
204 return component_add(dev, &vop_component_ops);
207 static int vop_remove(struct platform_device *pdev)
209 component_del(&pdev->dev, &vop_component_ops);
214 struct platform_driver vop_platform_driver = {
216 .remove = vop_remove,
218 .name = "rockchip-vop",
219 .owner = THIS_MODULE,
220 .of_match_table = of_match_ptr(vop_driver_dt_match),
224 module_platform_driver(vop_platform_driver);
226 MODULE_AUTHOR("Mark Yao <mark.yao@rock-chips.com>");
227 MODULE_DESCRIPTION("ROCKCHIP VOP Driver");
228 MODULE_LICENSE("GPL v2");