Skip to content

Commit ba527e9

Browse files
Hsiao Chien SungChun-Kuang Hu
authored andcommitted
drm/mediatek: Support MT8188 Padding in display driver
Padding is a new display module on MT8188, it provides ability to add pixels to width and height of a layer with specified colors. Due to hardware design, Mixer in VDOSYS1 requires width of a layer to be 2-pixel-align, or 4-pixel-align when ETHDR is enabled, we need Padding to deal with odd width. Reviewed-by: CK Hu <ck.hu@mediatek.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Hsiao Chien Sung <shawn.sung@mediatek.com> Link: https://patchwork.kernel.org/project/dri-devel/patch/20231214055847.4936-19-shawn.sung@mediatek.com/ Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
1 parent 1168bb6 commit ba527e9

File tree

5 files changed

+168
-2
lines changed

5 files changed

+168
-2
lines changed

drivers/gpu/drm/mediatek/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ mediatek-drm-y := mtk_disp_aal.o \
1616
mtk_dsi.o \
1717
mtk_dpi.o \
1818
mtk_ethdr.o \
19-
mtk_mdp_rdma.o
19+
mtk_mdp_rdma.o \
20+
mtk_padding.o
2021

2122
obj-$(CONFIG_DRM_MEDIATEK) += mediatek-drm.o
2223

drivers/gpu/drm/mediatek/mtk_disp_drv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,8 @@ void mtk_mdp_rdma_config(struct device *dev, struct mtk_mdp_rdma_cfg *cfg,
164164
const u32 *mtk_mdp_rdma_get_formats(struct device *dev);
165165
size_t mtk_mdp_rdma_get_num_formats(struct device *dev);
166166

167+
int mtk_padding_clk_enable(struct device *dev);
168+
void mtk_padding_clk_disable(struct device *dev);
169+
void mtk_padding_start(struct device *dev);
170+
void mtk_padding_stop(struct device *dev);
167171
#endif

drivers/gpu/drm/mediatek/mtk_drm_drv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ static struct platform_driver * const mtk_drm_drivers[] = {
996996
&mtk_dsi_driver,
997997
&mtk_ethdr_driver,
998998
&mtk_mdp_rdma_driver,
999+
&mtk_padding_driver,
9991000
};
10001001

10011002
static int __init mtk_drm_init(void)

drivers/gpu/drm/mediatek/mtk_drm_drv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ extern struct platform_driver mtk_dpi_driver;
7777
extern struct platform_driver mtk_dsi_driver;
7878
extern struct platform_driver mtk_ethdr_driver;
7979
extern struct platform_driver mtk_mdp_rdma_driver;
80-
80+
extern struct platform_driver mtk_padding_driver;
8181
#endif /* MTK_DRM_DRV_H */
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright (c) 2023 MediaTek Inc.
4+
*/
5+
6+
#include <linux/clk.h>
7+
#include <linux/component.h>
8+
#include <linux/module.h>
9+
#include <linux/of_device.h>
10+
#include <linux/platform_device.h>
11+
#include <linux/pm_runtime.h>
12+
#include <linux/soc/mediatek/mtk-cmdq.h>
13+
14+
#include "mtk_disp_drv.h"
15+
#include "mtk_drm_crtc.h"
16+
#include "mtk_drm_ddp_comp.h"
17+
18+
#define PADDING_CONTROL_REG 0x00
19+
#define PADDING_BYPASS BIT(0)
20+
#define PADDING_ENABLE BIT(1)
21+
#define PADDING_PIC_SIZE_REG 0x04
22+
#define PADDING_H_REG 0x08 /* horizontal */
23+
#define PADDING_V_REG 0x0c /* vertical */
24+
#define PADDING_COLOR_REG 0x10
25+
26+
/**
27+
* struct mtk_padding - Basic information of the Padding
28+
* @clk: Clock of the module
29+
* @reg: Virtual address of the Padding for CPU to access
30+
* @cmdq_reg: CMDQ setting of the Padding
31+
*
32+
* Every Padding should have different clock source, register base, and
33+
* CMDQ settings, we stored these differences all together.
34+
*/
35+
struct mtk_padding {
36+
struct clk *clk;
37+
void __iomem *reg;
38+
struct cmdq_client_reg cmdq_reg;
39+
};
40+
41+
int mtk_padding_clk_enable(struct device *dev)
42+
{
43+
struct mtk_padding *padding = dev_get_drvdata(dev);
44+
45+
return clk_prepare_enable(padding->clk);
46+
}
47+
48+
void mtk_padding_clk_disable(struct device *dev)
49+
{
50+
struct mtk_padding *padding = dev_get_drvdata(dev);
51+
52+
clk_disable_unprepare(padding->clk);
53+
}
54+
55+
void mtk_padding_start(struct device *dev)
56+
{
57+
struct mtk_padding *padding = dev_get_drvdata(dev);
58+
59+
writel(PADDING_ENABLE | PADDING_BYPASS,
60+
padding->reg + PADDING_CONTROL_REG);
61+
62+
/*
63+
* Notice that even the padding is in bypass mode,
64+
* all the settings must be cleared to 0 or
65+
* undefined behaviors could happen
66+
*/
67+
writel(0, padding->reg + PADDING_PIC_SIZE_REG);
68+
writel(0, padding->reg + PADDING_H_REG);
69+
writel(0, padding->reg + PADDING_V_REG);
70+
writel(0, padding->reg + PADDING_COLOR_REG);
71+
}
72+
73+
void mtk_padding_stop(struct device *dev)
74+
{
75+
struct mtk_padding *padding = dev_get_drvdata(dev);
76+
77+
writel(0, padding->reg + PADDING_CONTROL_REG);
78+
}
79+
80+
static int mtk_padding_bind(struct device *dev, struct device *master, void *data)
81+
{
82+
return 0;
83+
}
84+
85+
static void mtk_padding_unbind(struct device *dev, struct device *master, void *data)
86+
{
87+
}
88+
89+
static const struct component_ops mtk_padding_component_ops = {
90+
.bind = mtk_padding_bind,
91+
.unbind = mtk_padding_unbind,
92+
};
93+
94+
static int mtk_padding_probe(struct platform_device *pdev)
95+
{
96+
struct device *dev = &pdev->dev;
97+
struct mtk_padding *priv;
98+
struct resource *res;
99+
int ret;
100+
101+
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
102+
if (!priv)
103+
return -ENOMEM;
104+
105+
priv->clk = devm_clk_get(dev, NULL);
106+
if (IS_ERR(priv->clk)) {
107+
dev_err(dev, "failed to get clk\n");
108+
return PTR_ERR(priv->clk);
109+
}
110+
111+
priv->reg = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
112+
if (IS_ERR(priv->reg)) {
113+
dev_err(dev, "failed to do ioremap\n");
114+
return PTR_ERR(priv->reg);
115+
}
116+
117+
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
118+
ret = cmdq_dev_get_client_reg(dev, &priv->cmdq_reg, 0);
119+
if (ret) {
120+
dev_err(dev, "failed to get gce client reg\n");
121+
return ret;
122+
}
123+
#endif
124+
125+
platform_set_drvdata(pdev, priv);
126+
127+
ret = devm_pm_runtime_enable(dev);
128+
if (ret)
129+
return ret;
130+
131+
ret = component_add(dev, &mtk_padding_component_ops);
132+
if (ret) {
133+
pm_runtime_disable(dev);
134+
return dev_err_probe(dev, ret, "failed to add component\n");
135+
}
136+
137+
return 0;
138+
}
139+
140+
static int mtk_padding_remove(struct platform_device *pdev)
141+
{
142+
component_del(&pdev->dev, &mtk_padding_component_ops);
143+
return 0;
144+
}
145+
146+
static const struct of_device_id mtk_padding_driver_dt_match[] = {
147+
{ .compatible = "mediatek,mt8188-disp-padding" },
148+
{ /* sentinel */ }
149+
};
150+
MODULE_DEVICE_TABLE(of, mtk_padding_driver_dt_match);
151+
152+
struct platform_driver mtk_padding_driver = {
153+
.probe = mtk_padding_probe,
154+
.remove = mtk_padding_remove,
155+
.driver = {
156+
.name = "mediatek-disp-padding",
157+
.owner = THIS_MODULE,
158+
.of_match_table = mtk_padding_driver_dt_match,
159+
},
160+
};

0 commit comments

Comments
 (0)