1f8946e2bSNancy.Lin // SPDX-License-Identifier: GPL-2.0-only
2f8946e2bSNancy.Lin /*
3f8946e2bSNancy.Lin * Copyright (c) 2021 MediaTek Inc.
4f8946e2bSNancy.Lin */
5f8946e2bSNancy.Lin
6f8946e2bSNancy.Lin #include <drm/drm_fourcc.h>
7f8946e2bSNancy.Lin #include <linux/clk.h>
8f8946e2bSNancy.Lin #include <linux/component.h>
9722d4f06SRob Herring #include <linux/mod_devicetable.h>
10f8946e2bSNancy.Lin #include <linux/platform_device.h>
11f8946e2bSNancy.Lin #include <linux/pm_runtime.h>
12f8946e2bSNancy.Lin #include <linux/soc/mediatek/mtk-cmdq.h>
13f8946e2bSNancy.Lin
14f8946e2bSNancy.Lin #include "mtk_disp_drv.h"
15f8946e2bSNancy.Lin #include "mtk_drm_drv.h"
16f8946e2bSNancy.Lin #include "mtk_mdp_rdma.h"
17f8946e2bSNancy.Lin
18f8946e2bSNancy.Lin #define MDP_RDMA_EN 0x000
19f8946e2bSNancy.Lin #define FLD_ROT_ENABLE BIT(0)
20f8946e2bSNancy.Lin #define MDP_RDMA_RESET 0x008
21f8946e2bSNancy.Lin #define MDP_RDMA_CON 0x020
22f8946e2bSNancy.Lin #define FLD_OUTPUT_10B BIT(5)
23f8946e2bSNancy.Lin #define FLD_SIMPLE_MODE BIT(4)
24f8946e2bSNancy.Lin #define MDP_RDMA_GMCIF_CON 0x028
25f8946e2bSNancy.Lin #define FLD_COMMAND_DIV BIT(0)
26f8946e2bSNancy.Lin #define FLD_EXT_PREULTRA_EN BIT(3)
27f8946e2bSNancy.Lin #define FLD_RD_REQ_TYPE GENMASK(7, 4)
28f8946e2bSNancy.Lin #define VAL_RD_REQ_TYPE_BURST_8_ACCESS 7
29f8946e2bSNancy.Lin #define FLD_ULTRA_EN GENMASK(13, 12)
30f8946e2bSNancy.Lin #define VAL_ULTRA_EN_ENABLE 1
31f8946e2bSNancy.Lin #define FLD_PRE_ULTRA_EN GENMASK(17, 16)
32f8946e2bSNancy.Lin #define VAL_PRE_ULTRA_EN_ENABLE 1
33f8946e2bSNancy.Lin #define FLD_EXT_ULTRA_EN BIT(18)
34f8946e2bSNancy.Lin #define MDP_RDMA_SRC_CON 0x030
35f8946e2bSNancy.Lin #define FLD_OUTPUT_ARGB BIT(25)
36f8946e2bSNancy.Lin #define FLD_BIT_NUMBER GENMASK(19, 18)
37f8946e2bSNancy.Lin #define FLD_SWAP BIT(14)
38f8946e2bSNancy.Lin #define FLD_UNIFORM_CONFIG BIT(17)
39f8946e2bSNancy.Lin #define RDMA_INPUT_10BIT BIT(18)
40f8946e2bSNancy.Lin #define FLD_SRC_FORMAT GENMASK(3, 0)
41f8946e2bSNancy.Lin #define MDP_RDMA_COMP_CON 0x038
42f8946e2bSNancy.Lin #define FLD_AFBC_EN BIT(22)
43f8946e2bSNancy.Lin #define FLD_AFBC_YUV_TRANSFORM BIT(21)
44f8946e2bSNancy.Lin #define FLD_UFBDC_EN BIT(12)
45f8946e2bSNancy.Lin #define MDP_RDMA_MF_BKGD_SIZE_IN_BYTE 0x060
46f8946e2bSNancy.Lin #define FLD_MF_BKGD_WB GENMASK(22, 0)
47f8946e2bSNancy.Lin #define MDP_RDMA_MF_SRC_SIZE 0x070
48f8946e2bSNancy.Lin #define FLD_MF_SRC_H GENMASK(30, 16)
49f8946e2bSNancy.Lin #define FLD_MF_SRC_W GENMASK(14, 0)
50f8946e2bSNancy.Lin #define MDP_RDMA_MF_CLIP_SIZE 0x078
51f8946e2bSNancy.Lin #define FLD_MF_CLIP_H GENMASK(30, 16)
52f8946e2bSNancy.Lin #define FLD_MF_CLIP_W GENMASK(14, 0)
53f8946e2bSNancy.Lin #define MDP_RDMA_SRC_OFFSET_0 0x118
54f8946e2bSNancy.Lin #define FLD_SRC_OFFSET_0 GENMASK(31, 0)
55f8946e2bSNancy.Lin #define MDP_RDMA_TRANSFORM_0 0x200
56f8946e2bSNancy.Lin #define FLD_INT_MATRIX_SEL GENMASK(27, 23)
57f8946e2bSNancy.Lin #define FLD_TRANS_EN BIT(16)
58f8946e2bSNancy.Lin #define MDP_RDMA_SRC_BASE_0 0xf00
59f8946e2bSNancy.Lin #define FLD_SRC_BASE_0 GENMASK(31, 0)
60f8946e2bSNancy.Lin
61f8946e2bSNancy.Lin #define RDMA_CSC_FULL709_TO_RGB 5
62f8946e2bSNancy.Lin #define RDMA_CSC_BT601_TO_RGB 6
63f8946e2bSNancy.Lin
64df475244SNancy.Lin static const u32 formats[] = {
65df475244SNancy.Lin DRM_FORMAT_XRGB8888,
66df475244SNancy.Lin DRM_FORMAT_ARGB8888,
67df475244SNancy.Lin DRM_FORMAT_BGRX8888,
68df475244SNancy.Lin DRM_FORMAT_BGRA8888,
69df475244SNancy.Lin DRM_FORMAT_ABGR8888,
70df475244SNancy.Lin DRM_FORMAT_XBGR8888,
71df475244SNancy.Lin DRM_FORMAT_RGB888,
72df475244SNancy.Lin DRM_FORMAT_BGR888,
73df475244SNancy.Lin DRM_FORMAT_RGB565,
74df475244SNancy.Lin DRM_FORMAT_UYVY,
75df475244SNancy.Lin DRM_FORMAT_YUYV,
76df475244SNancy.Lin };
77df475244SNancy.Lin
78f8946e2bSNancy.Lin enum rdma_format {
79f8946e2bSNancy.Lin RDMA_INPUT_FORMAT_RGB565 = 0,
80f8946e2bSNancy.Lin RDMA_INPUT_FORMAT_RGB888 = 1,
81f8946e2bSNancy.Lin RDMA_INPUT_FORMAT_RGBA8888 = 2,
82f8946e2bSNancy.Lin RDMA_INPUT_FORMAT_ARGB8888 = 3,
83f8946e2bSNancy.Lin RDMA_INPUT_FORMAT_UYVY = 4,
84f8946e2bSNancy.Lin RDMA_INPUT_FORMAT_YUY2 = 5,
85f8946e2bSNancy.Lin RDMA_INPUT_FORMAT_Y8 = 7,
86f8946e2bSNancy.Lin RDMA_INPUT_FORMAT_YV12 = 8,
87f8946e2bSNancy.Lin RDMA_INPUT_FORMAT_UYVY_3PL = 9,
88f8946e2bSNancy.Lin RDMA_INPUT_FORMAT_NV12 = 12,
89f8946e2bSNancy.Lin RDMA_INPUT_FORMAT_UYVY_2PL = 13,
90f8946e2bSNancy.Lin RDMA_INPUT_FORMAT_Y410 = 14
91f8946e2bSNancy.Lin };
92f8946e2bSNancy.Lin
93f8946e2bSNancy.Lin struct mtk_mdp_rdma {
94f8946e2bSNancy.Lin void __iomem *regs;
95f8946e2bSNancy.Lin struct clk *clk;
96f8946e2bSNancy.Lin struct cmdq_client_reg cmdq_reg;
97f8946e2bSNancy.Lin };
98f8946e2bSNancy.Lin
rdma_fmt_convert(unsigned int fmt)99f8946e2bSNancy.Lin static unsigned int rdma_fmt_convert(unsigned int fmt)
100f8946e2bSNancy.Lin {
101f8946e2bSNancy.Lin switch (fmt) {
102f8946e2bSNancy.Lin default:
103f8946e2bSNancy.Lin case DRM_FORMAT_RGB565:
104f8946e2bSNancy.Lin return RDMA_INPUT_FORMAT_RGB565;
105f8946e2bSNancy.Lin case DRM_FORMAT_BGR565:
106f8946e2bSNancy.Lin return RDMA_INPUT_FORMAT_RGB565 | FLD_SWAP;
107f8946e2bSNancy.Lin case DRM_FORMAT_RGB888:
108f8946e2bSNancy.Lin return RDMA_INPUT_FORMAT_RGB888;
109f8946e2bSNancy.Lin case DRM_FORMAT_BGR888:
110f8946e2bSNancy.Lin return RDMA_INPUT_FORMAT_RGB888 | FLD_SWAP;
111f8946e2bSNancy.Lin case DRM_FORMAT_RGBX8888:
112f8946e2bSNancy.Lin case DRM_FORMAT_RGBA8888:
113f8946e2bSNancy.Lin return RDMA_INPUT_FORMAT_ARGB8888;
114f8946e2bSNancy.Lin case DRM_FORMAT_BGRX8888:
115f8946e2bSNancy.Lin case DRM_FORMAT_BGRA8888:
116f8946e2bSNancy.Lin return RDMA_INPUT_FORMAT_ARGB8888 | FLD_SWAP;
117f8946e2bSNancy.Lin case DRM_FORMAT_XRGB8888:
118f8946e2bSNancy.Lin case DRM_FORMAT_ARGB8888:
119f8946e2bSNancy.Lin return RDMA_INPUT_FORMAT_RGBA8888;
120f8946e2bSNancy.Lin case DRM_FORMAT_XBGR8888:
121f8946e2bSNancy.Lin case DRM_FORMAT_ABGR8888:
122f8946e2bSNancy.Lin return RDMA_INPUT_FORMAT_RGBA8888 | FLD_SWAP;
123f8946e2bSNancy.Lin case DRM_FORMAT_ABGR2101010:
124f8946e2bSNancy.Lin return RDMA_INPUT_FORMAT_RGBA8888 | FLD_SWAP | RDMA_INPUT_10BIT;
125f8946e2bSNancy.Lin case DRM_FORMAT_ARGB2101010:
126f8946e2bSNancy.Lin return RDMA_INPUT_FORMAT_RGBA8888 | RDMA_INPUT_10BIT;
127f8946e2bSNancy.Lin case DRM_FORMAT_RGBA1010102:
128f8946e2bSNancy.Lin return RDMA_INPUT_FORMAT_ARGB8888 | FLD_SWAP | RDMA_INPUT_10BIT;
129f8946e2bSNancy.Lin case DRM_FORMAT_BGRA1010102:
130f8946e2bSNancy.Lin return RDMA_INPUT_FORMAT_ARGB8888 | RDMA_INPUT_10BIT;
131f8946e2bSNancy.Lin case DRM_FORMAT_UYVY:
132f8946e2bSNancy.Lin return RDMA_INPUT_FORMAT_UYVY;
133f8946e2bSNancy.Lin case DRM_FORMAT_YUYV:
134f8946e2bSNancy.Lin return RDMA_INPUT_FORMAT_YUY2;
135f8946e2bSNancy.Lin }
136f8946e2bSNancy.Lin }
137f8946e2bSNancy.Lin
rdma_color_convert(unsigned int color_encoding)138f8946e2bSNancy.Lin static unsigned int rdma_color_convert(unsigned int color_encoding)
139f8946e2bSNancy.Lin {
140f8946e2bSNancy.Lin switch (color_encoding) {
141f8946e2bSNancy.Lin default:
142f8946e2bSNancy.Lin case DRM_COLOR_YCBCR_BT709:
143f8946e2bSNancy.Lin return RDMA_CSC_FULL709_TO_RGB;
144f8946e2bSNancy.Lin case DRM_COLOR_YCBCR_BT601:
145f8946e2bSNancy.Lin return RDMA_CSC_BT601_TO_RGB;
146f8946e2bSNancy.Lin }
147f8946e2bSNancy.Lin }
148f8946e2bSNancy.Lin
mtk_mdp_rdma_fifo_config(struct device * dev,struct cmdq_pkt * cmdq_pkt)149f8946e2bSNancy.Lin static void mtk_mdp_rdma_fifo_config(struct device *dev, struct cmdq_pkt *cmdq_pkt)
150f8946e2bSNancy.Lin {
151f8946e2bSNancy.Lin struct mtk_mdp_rdma *priv = dev_get_drvdata(dev);
152f8946e2bSNancy.Lin
153f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, FLD_EXT_ULTRA_EN | VAL_PRE_ULTRA_EN_ENABLE << 16 |
154f8946e2bSNancy.Lin VAL_ULTRA_EN_ENABLE << 12 | VAL_RD_REQ_TYPE_BURST_8_ACCESS << 4 |
155f8946e2bSNancy.Lin FLD_EXT_PREULTRA_EN | FLD_COMMAND_DIV, &priv->cmdq_reg,
156f8946e2bSNancy.Lin priv->regs, MDP_RDMA_GMCIF_CON, FLD_EXT_ULTRA_EN |
157f8946e2bSNancy.Lin FLD_PRE_ULTRA_EN | FLD_ULTRA_EN | FLD_RD_REQ_TYPE |
158f8946e2bSNancy.Lin FLD_EXT_PREULTRA_EN | FLD_COMMAND_DIV);
159f8946e2bSNancy.Lin }
160f8946e2bSNancy.Lin
mtk_mdp_rdma_start(struct device * dev,struct cmdq_pkt * cmdq_pkt)161f8946e2bSNancy.Lin void mtk_mdp_rdma_start(struct device *dev, struct cmdq_pkt *cmdq_pkt)
162f8946e2bSNancy.Lin {
163f8946e2bSNancy.Lin struct mtk_mdp_rdma *priv = dev_get_drvdata(dev);
164f8946e2bSNancy.Lin
165f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, FLD_ROT_ENABLE, &priv->cmdq_reg,
166f8946e2bSNancy.Lin priv->regs, MDP_RDMA_EN, FLD_ROT_ENABLE);
167f8946e2bSNancy.Lin }
168f8946e2bSNancy.Lin
mtk_mdp_rdma_stop(struct device * dev,struct cmdq_pkt * cmdq_pkt)169f8946e2bSNancy.Lin void mtk_mdp_rdma_stop(struct device *dev, struct cmdq_pkt *cmdq_pkt)
170f8946e2bSNancy.Lin {
171f8946e2bSNancy.Lin struct mtk_mdp_rdma *priv = dev_get_drvdata(dev);
172f8946e2bSNancy.Lin
173f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, 0, &priv->cmdq_reg,
174f8946e2bSNancy.Lin priv->regs, MDP_RDMA_EN, FLD_ROT_ENABLE);
175f8946e2bSNancy.Lin mtk_ddp_write(cmdq_pkt, 1, &priv->cmdq_reg, priv->regs, MDP_RDMA_RESET);
176f8946e2bSNancy.Lin mtk_ddp_write(cmdq_pkt, 0, &priv->cmdq_reg, priv->regs, MDP_RDMA_RESET);
177f8946e2bSNancy.Lin }
178f8946e2bSNancy.Lin
mtk_mdp_rdma_config(struct device * dev,struct mtk_mdp_rdma_cfg * cfg,struct cmdq_pkt * cmdq_pkt)179f8946e2bSNancy.Lin void mtk_mdp_rdma_config(struct device *dev, struct mtk_mdp_rdma_cfg *cfg,
180f8946e2bSNancy.Lin struct cmdq_pkt *cmdq_pkt)
181f8946e2bSNancy.Lin {
182f8946e2bSNancy.Lin struct mtk_mdp_rdma *priv = dev_get_drvdata(dev);
183f8946e2bSNancy.Lin const struct drm_format_info *fmt_info = drm_format_info(cfg->fmt);
184f8946e2bSNancy.Lin bool csc_enable = fmt_info->is_yuv ? true : false;
185f8946e2bSNancy.Lin unsigned int src_pitch_y = cfg->pitch;
186f8946e2bSNancy.Lin unsigned int offset_y = 0;
187f8946e2bSNancy.Lin
188f8946e2bSNancy.Lin mtk_mdp_rdma_fifo_config(dev, cmdq_pkt);
189f8946e2bSNancy.Lin
190f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, FLD_UNIFORM_CONFIG, &priv->cmdq_reg, priv->regs,
191f8946e2bSNancy.Lin MDP_RDMA_SRC_CON, FLD_UNIFORM_CONFIG);
192f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, rdma_fmt_convert(cfg->fmt), &priv->cmdq_reg, priv->regs,
193f8946e2bSNancy.Lin MDP_RDMA_SRC_CON, FLD_SWAP | FLD_SRC_FORMAT | FLD_BIT_NUMBER);
194f8946e2bSNancy.Lin
195f8946e2bSNancy.Lin if (!csc_enable && fmt_info->has_alpha)
196f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, FLD_OUTPUT_ARGB, &priv->cmdq_reg,
197f8946e2bSNancy.Lin priv->regs, MDP_RDMA_SRC_CON, FLD_OUTPUT_ARGB);
198f8946e2bSNancy.Lin else
199f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, 0, &priv->cmdq_reg, priv->regs,
200f8946e2bSNancy.Lin MDP_RDMA_SRC_CON, FLD_OUTPUT_ARGB);
201f8946e2bSNancy.Lin
202f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, cfg->addr0, &priv->cmdq_reg, priv->regs,
203f8946e2bSNancy.Lin MDP_RDMA_SRC_BASE_0, FLD_SRC_BASE_0);
204f8946e2bSNancy.Lin
205f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, src_pitch_y, &priv->cmdq_reg, priv->regs,
206f8946e2bSNancy.Lin MDP_RDMA_MF_BKGD_SIZE_IN_BYTE, FLD_MF_BKGD_WB);
207f8946e2bSNancy.Lin
208f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, 0, &priv->cmdq_reg, priv->regs, MDP_RDMA_COMP_CON,
209f8946e2bSNancy.Lin FLD_AFBC_YUV_TRANSFORM | FLD_UFBDC_EN | FLD_AFBC_EN);
210f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, FLD_OUTPUT_10B, &priv->cmdq_reg, priv->regs,
211f8946e2bSNancy.Lin MDP_RDMA_CON, FLD_OUTPUT_10B);
212f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, FLD_SIMPLE_MODE, &priv->cmdq_reg, priv->regs,
213f8946e2bSNancy.Lin MDP_RDMA_CON, FLD_SIMPLE_MODE);
214f8946e2bSNancy.Lin if (csc_enable)
215f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, rdma_color_convert(cfg->color_encoding) << 23,
216f8946e2bSNancy.Lin &priv->cmdq_reg, priv->regs, MDP_RDMA_TRANSFORM_0,
217f8946e2bSNancy.Lin FLD_INT_MATRIX_SEL);
218f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, csc_enable << 16, &priv->cmdq_reg, priv->regs,
219f8946e2bSNancy.Lin MDP_RDMA_TRANSFORM_0, FLD_TRANS_EN);
220f8946e2bSNancy.Lin
221f8946e2bSNancy.Lin offset_y = cfg->x_left * fmt_info->cpp[0] + cfg->y_top * src_pitch_y;
222f8946e2bSNancy.Lin
223f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, offset_y, &priv->cmdq_reg, priv->regs,
224f8946e2bSNancy.Lin MDP_RDMA_SRC_OFFSET_0, FLD_SRC_OFFSET_0);
225f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, cfg->width, &priv->cmdq_reg, priv->regs,
226f8946e2bSNancy.Lin MDP_RDMA_MF_SRC_SIZE, FLD_MF_SRC_W);
227f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, cfg->height << 16, &priv->cmdq_reg, priv->regs,
228f8946e2bSNancy.Lin MDP_RDMA_MF_SRC_SIZE, FLD_MF_SRC_H);
229f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, cfg->width, &priv->cmdq_reg, priv->regs,
230f8946e2bSNancy.Lin MDP_RDMA_MF_CLIP_SIZE, FLD_MF_CLIP_W);
231f8946e2bSNancy.Lin mtk_ddp_write_mask(cmdq_pkt, cfg->height << 16, &priv->cmdq_reg, priv->regs,
232f8946e2bSNancy.Lin MDP_RDMA_MF_CLIP_SIZE, FLD_MF_CLIP_H);
233f8946e2bSNancy.Lin }
234f8946e2bSNancy.Lin
mtk_mdp_rdma_get_formats(struct device * dev)235df475244SNancy.Lin const u32 *mtk_mdp_rdma_get_formats(struct device *dev)
236df475244SNancy.Lin {
237df475244SNancy.Lin return formats;
238df475244SNancy.Lin }
239df475244SNancy.Lin
mtk_mdp_rdma_get_num_formats(struct device * dev)240df475244SNancy.Lin size_t mtk_mdp_rdma_get_num_formats(struct device *dev)
241df475244SNancy.Lin {
242df475244SNancy.Lin return ARRAY_SIZE(formats);
243df475244SNancy.Lin }
244df475244SNancy.Lin
mtk_mdp_rdma_power_on(struct device * dev)245b97fa2f3SHsiao Chien Sung int mtk_mdp_rdma_power_on(struct device *dev)
246b97fa2f3SHsiao Chien Sung {
247b97fa2f3SHsiao Chien Sung int ret = pm_runtime_resume_and_get(dev);
248b97fa2f3SHsiao Chien Sung
249b97fa2f3SHsiao Chien Sung if (ret < 0) {
250b97fa2f3SHsiao Chien Sung dev_err(dev, "Failed to power on: %d\n", ret);
251b97fa2f3SHsiao Chien Sung return ret;
252b97fa2f3SHsiao Chien Sung }
253b97fa2f3SHsiao Chien Sung return 0;
254b97fa2f3SHsiao Chien Sung }
255b97fa2f3SHsiao Chien Sung
mtk_mdp_rdma_power_off(struct device * dev)256b97fa2f3SHsiao Chien Sung void mtk_mdp_rdma_power_off(struct device *dev)
257b97fa2f3SHsiao Chien Sung {
258b97fa2f3SHsiao Chien Sung pm_runtime_put(dev);
259b97fa2f3SHsiao Chien Sung }
260b97fa2f3SHsiao Chien Sung
mtk_mdp_rdma_clk_enable(struct device * dev)261f8946e2bSNancy.Lin int mtk_mdp_rdma_clk_enable(struct device *dev)
262f8946e2bSNancy.Lin {
263f8946e2bSNancy.Lin struct mtk_mdp_rdma *rdma = dev_get_drvdata(dev);
264f8946e2bSNancy.Lin
26521b28714SHsiao Chien Sung return clk_prepare_enable(rdma->clk);
266f8946e2bSNancy.Lin }
267f8946e2bSNancy.Lin
mtk_mdp_rdma_clk_disable(struct device * dev)268f8946e2bSNancy.Lin void mtk_mdp_rdma_clk_disable(struct device *dev)
269f8946e2bSNancy.Lin {
270f8946e2bSNancy.Lin struct mtk_mdp_rdma *rdma = dev_get_drvdata(dev);
271f8946e2bSNancy.Lin
272f8946e2bSNancy.Lin clk_disable_unprepare(rdma->clk);
273f8946e2bSNancy.Lin }
274f8946e2bSNancy.Lin
mtk_mdp_rdma_bind(struct device * dev,struct device * master,void * data)275f8946e2bSNancy.Lin static int mtk_mdp_rdma_bind(struct device *dev, struct device *master,
276f8946e2bSNancy.Lin void *data)
277f8946e2bSNancy.Lin {
278f8946e2bSNancy.Lin return 0;
279f8946e2bSNancy.Lin }
280f8946e2bSNancy.Lin
mtk_mdp_rdma_unbind(struct device * dev,struct device * master,void * data)281f8946e2bSNancy.Lin static void mtk_mdp_rdma_unbind(struct device *dev, struct device *master,
282f8946e2bSNancy.Lin void *data)
283f8946e2bSNancy.Lin {
284f8946e2bSNancy.Lin }
285f8946e2bSNancy.Lin
286f8946e2bSNancy.Lin static const struct component_ops mtk_mdp_rdma_component_ops = {
287f8946e2bSNancy.Lin .bind = mtk_mdp_rdma_bind,
288f8946e2bSNancy.Lin .unbind = mtk_mdp_rdma_unbind,
289f8946e2bSNancy.Lin };
290f8946e2bSNancy.Lin
mtk_mdp_rdma_probe(struct platform_device * pdev)291f8946e2bSNancy.Lin static int mtk_mdp_rdma_probe(struct platform_device *pdev)
292f8946e2bSNancy.Lin {
293f8946e2bSNancy.Lin struct device *dev = &pdev->dev;
294f8946e2bSNancy.Lin struct resource *res;
295f8946e2bSNancy.Lin struct mtk_mdp_rdma *priv;
296f8946e2bSNancy.Lin int ret = 0;
297f8946e2bSNancy.Lin
298f8946e2bSNancy.Lin priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
299f8946e2bSNancy.Lin if (!priv)
300f8946e2bSNancy.Lin return -ENOMEM;
301f8946e2bSNancy.Lin
302f8946e2bSNancy.Lin res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
303f8946e2bSNancy.Lin priv->regs = devm_ioremap_resource(dev, res);
304*45b70f71SNícolas F. R. A. Prado if (IS_ERR(priv->regs))
305*45b70f71SNícolas F. R. A. Prado return dev_err_probe(dev, PTR_ERR(priv->regs),
306*45b70f71SNícolas F. R. A. Prado "failed to ioremap rdma\n");
307f8946e2bSNancy.Lin
308f8946e2bSNancy.Lin priv->clk = devm_clk_get(dev, NULL);
309*45b70f71SNícolas F. R. A. Prado if (IS_ERR(priv->clk))
310*45b70f71SNícolas F. R. A. Prado return dev_err_probe(dev, PTR_ERR(priv->clk),
311*45b70f71SNícolas F. R. A. Prado "failed to get rdma clk\n");
312f8946e2bSNancy.Lin
313f8946e2bSNancy.Lin #if IS_REACHABLE(CONFIG_MTK_CMDQ)
314f8946e2bSNancy.Lin ret = cmdq_dev_get_client_reg(dev, &priv->cmdq_reg, 0);
315f8946e2bSNancy.Lin if (ret)
316f8946e2bSNancy.Lin dev_dbg(dev, "get mediatek,gce-client-reg fail!\n");
317f8946e2bSNancy.Lin #endif
318f8946e2bSNancy.Lin platform_set_drvdata(pdev, priv);
319f8946e2bSNancy.Lin
320f8946e2bSNancy.Lin pm_runtime_enable(dev);
321f8946e2bSNancy.Lin
322f8946e2bSNancy.Lin ret = component_add(dev, &mtk_mdp_rdma_component_ops);
323f8946e2bSNancy.Lin if (ret != 0) {
324f8946e2bSNancy.Lin pm_runtime_disable(dev);
325*45b70f71SNícolas F. R. A. Prado return dev_err_probe(dev, ret, "Failed to add component\n");
326f8946e2bSNancy.Lin }
327*45b70f71SNícolas F. R. A. Prado return 0;
328f8946e2bSNancy.Lin }
329f8946e2bSNancy.Lin
mtk_mdp_rdma_remove(struct platform_device * pdev)330b3af12a0SUwe Kleine-König static void mtk_mdp_rdma_remove(struct platform_device *pdev)
331f8946e2bSNancy.Lin {
332f8946e2bSNancy.Lin component_del(&pdev->dev, &mtk_mdp_rdma_component_ops);
333f8946e2bSNancy.Lin pm_runtime_disable(&pdev->dev);
334f8946e2bSNancy.Lin }
335f8946e2bSNancy.Lin
336f8946e2bSNancy.Lin static const struct of_device_id mtk_mdp_rdma_driver_dt_match[] = {
337f8946e2bSNancy.Lin { .compatible = "mediatek,mt8195-vdo1-rdma", },
338f8946e2bSNancy.Lin {},
339f8946e2bSNancy.Lin };
340f8946e2bSNancy.Lin MODULE_DEVICE_TABLE(of, mtk_mdp_rdma_driver_dt_match);
341f8946e2bSNancy.Lin
342f8946e2bSNancy.Lin struct platform_driver mtk_mdp_rdma_driver = {
343f8946e2bSNancy.Lin .probe = mtk_mdp_rdma_probe,
344b3af12a0SUwe Kleine-König .remove_new = mtk_mdp_rdma_remove,
345f8946e2bSNancy.Lin .driver = {
346f8946e2bSNancy.Lin .name = "mediatek-mdp-rdma",
347f8946e2bSNancy.Lin .of_match_table = mtk_mdp_rdma_driver_dt_match,
348f8946e2bSNancy.Lin },
349f8946e2bSNancy.Lin };
350