155 lines · c
1// SPDX-License-Identifier: GPL-2.0-only2/*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_crtc.h"15#include "mtk_ddp_comp.h"16#include "mtk_disp_drv.h"17 18#define PADDING_CONTROL_REG 0x0019#define PADDING_BYPASS BIT(0)20#define PADDING_ENABLE BIT(1)21#define PADDING_PIC_SIZE_REG 0x0422#define PADDING_H_REG 0x08 /* horizontal */23#define PADDING_V_REG 0x0c /* vertical */24#define PADDING_COLOR_REG 0x1025 26/**27 * struct mtk_padding - Basic information of the Padding28 * @clk: Clock of the module29 * @reg: Virtual address of the Padding for CPU to access30 * @cmdq_reg: CMDQ setting of the Padding31 *32 * Every Padding should have different clock source, register base, and33 * CMDQ settings, we stored these differences all together.34 */35struct mtk_padding {36 struct clk *clk;37 void __iomem *reg;38 struct cmdq_client_reg cmdq_reg;39};40 41int 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 48void 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 55void 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 or65 * undefined behaviors could happen66 */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 73void 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 80static int mtk_padding_bind(struct device *dev, struct device *master, void *data)81{82 return 0;83}84 85static void mtk_padding_unbind(struct device *dev, struct device *master, void *data)86{87}88 89static const struct component_ops mtk_padding_component_ops = {90 .bind = mtk_padding_bind,91 .unbind = mtk_padding_unbind,92};93 94static 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 return dev_err_probe(dev, PTR_ERR(priv->clk),108 "failed to get clk\n");109 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");114 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#endif120 121 platform_set_drvdata(pdev, priv);122 123 ret = devm_pm_runtime_enable(dev);124 if (ret)125 return ret;126 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");131 }132 133 return 0;134}135 136static void mtk_padding_remove(struct platform_device *pdev)137{138 component_del(&pdev->dev, &mtk_padding_component_ops);139}140 141static const struct of_device_id mtk_padding_driver_dt_match[] = {142 { .compatible = "mediatek,mt8188-disp-padding" },143 { /* sentinel */ }144};145MODULE_DEVICE_TABLE(of, mtk_padding_driver_dt_match);146 147struct platform_driver mtk_padding_driver = {148 .probe = mtk_padding_probe,149 .remove_new = mtk_padding_remove,150 .driver = {151 .name = "mediatek-disp-padding",152 .of_match_table = mtk_padding_driver_dt_match,153 },154};155