Get rid of 'remove_new' relic from platform driver struct
[linux.git] / drivers / gpu / drm / mediatek / mtk_padding.c
blobb4e3e5a3428b6f5a28786e8310ea50fe9edeeef5
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2023 MediaTek Inc.
4 */
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>
14 #include "mtk_crtc.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
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
32 * Every Padding should have different clock source, register base, and
33 * CMDQ settings, we stored these differences all together.
35 struct mtk_padding {
36 struct clk *clk;
37 void __iomem *reg;
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)
82 return 0;
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;
98 struct resource *res;
99 int ret;
101 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
102 if (!priv)
103 return -ENOMEM;
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);
117 if (ret)
118 return dev_err_probe(dev, ret, "failed to get gce client reg\n");
119 #endif
121 platform_set_drvdata(pdev, priv);
123 ret = devm_pm_runtime_enable(dev);
124 if (ret)
125 return ret;
127 ret = component_add(dev, &mtk_padding_component_ops);
128 if (ret) {
129 pm_runtime_disable(dev);
130 return dev_err_probe(dev, ret, "failed to add component\n");
133 return 0;
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" },
143 { /* sentinel */ }
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,
150 .driver = {
151 .name = "mediatek-disp-padding",
152 .of_match_table = mtk_padding_driver_dt_match,