1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2023 MediaTek Inc.
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>
15 #include "mtk_ddp_comp.h"
16 #include "mtk_disp_drv.h"
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
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
32 * Every Padding should have different clock source, register base, and
33 * CMDQ settings, we stored these differences all together.
38 struct cmdq_client_reg cmdq_reg
;
41 int mtk_padding_clk_enable(struct device
*dev
)
43 struct mtk_padding
*padding
= dev_get_drvdata(dev
);
45 return clk_prepare_enable(padding
->clk
);
48 void mtk_padding_clk_disable(struct device
*dev
)
50 struct mtk_padding
*padding
= dev_get_drvdata(dev
);
52 clk_disable_unprepare(padding
->clk
);
55 void mtk_padding_start(struct device
*dev
)
57 struct mtk_padding
*padding
= dev_get_drvdata(dev
);
59 writel(PADDING_ENABLE
| PADDING_BYPASS
,
60 padding
->reg
+ PADDING_CONTROL_REG
);
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
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
);
73 void mtk_padding_stop(struct device
*dev
)
75 struct mtk_padding
*padding
= dev_get_drvdata(dev
);
77 writel(0, padding
->reg
+ PADDING_CONTROL_REG
);
80 static int mtk_padding_bind(struct device
*dev
, struct device
*master
, void *data
)
85 static void mtk_padding_unbind(struct device
*dev
, struct device
*master
, void *data
)
89 static const struct component_ops mtk_padding_component_ops
= {
90 .bind
= mtk_padding_bind
,
91 .unbind
= mtk_padding_unbind
,
94 static int mtk_padding_probe(struct platform_device
*pdev
)
96 struct device
*dev
= &pdev
->dev
;
97 struct mtk_padding
*priv
;
101 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
105 priv
->clk
= devm_clk_get(dev
, NULL
);
106 if (IS_ERR(priv
->clk
))
107 return dev_err_probe(dev
, PTR_ERR(priv
->clk
),
108 "failed to get clk\n");
110 priv
->reg
= devm_platform_get_and_ioremap_resource(pdev
, 0, &res
);
111 if (IS_ERR(priv
->reg
))
112 return dev_err_probe(dev
, PTR_ERR(priv
->reg
),
113 "failed to do ioremap\n");
115 #if IS_REACHABLE(CONFIG_MTK_CMDQ)
116 ret
= cmdq_dev_get_client_reg(dev
, &priv
->cmdq_reg
, 0);
118 return dev_err_probe(dev
, ret
, "failed to get gce client reg\n");
121 platform_set_drvdata(pdev
, priv
);
123 ret
= devm_pm_runtime_enable(dev
);
127 ret
= component_add(dev
, &mtk_padding_component_ops
);
129 pm_runtime_disable(dev
);
130 return dev_err_probe(dev
, ret
, "failed to add component\n");
136 static void mtk_padding_remove(struct platform_device
*pdev
)
138 component_del(&pdev
->dev
, &mtk_padding_component_ops
);
141 static const struct of_device_id mtk_padding_driver_dt_match
[] = {
142 { .compatible
= "mediatek,mt8188-disp-padding" },
145 MODULE_DEVICE_TABLE(of
, mtk_padding_driver_dt_match
);
147 struct platform_driver mtk_padding_driver
= {
148 .probe
= mtk_padding_probe
,
149 .remove
= mtk_padding_remove
,
151 .name
= "mediatek-disp-padding",
152 .of_match_table
= mtk_padding_driver_dt_match
,