This source file includes following definitions.
- comp_to_color
- mtk_color_config
- mtk_color_start
- mtk_disp_color_bind
- mtk_disp_color_unbind
- mtk_disp_color_probe
- mtk_disp_color_remove
1
2
3
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/of_irq.h>
11 #include <linux/platform_device.h>
12
13 #include "mtk_drm_crtc.h"
14 #include "mtk_drm_ddp_comp.h"
15
16 #define DISP_COLOR_CFG_MAIN 0x0400
17 #define DISP_COLOR_START_MT2701 0x0f00
18 #define DISP_COLOR_START_MT8173 0x0c00
19 #define DISP_COLOR_START(comp) ((comp)->data->color_offset)
20 #define DISP_COLOR_WIDTH(comp) (DISP_COLOR_START(comp) + 0x50)
21 #define DISP_COLOR_HEIGHT(comp) (DISP_COLOR_START(comp) + 0x54)
22
23 #define COLOR_BYPASS_ALL BIT(7)
24 #define COLOR_SEQ_SEL BIT(13)
25
26 struct mtk_disp_color_data {
27 unsigned int color_offset;
28 };
29
30
31
32
33
34
35 struct mtk_disp_color {
36 struct mtk_ddp_comp ddp_comp;
37 struct drm_crtc *crtc;
38 const struct mtk_disp_color_data *data;
39 };
40
41 static inline struct mtk_disp_color *comp_to_color(struct mtk_ddp_comp *comp)
42 {
43 return container_of(comp, struct mtk_disp_color, ddp_comp);
44 }
45
46 static void mtk_color_config(struct mtk_ddp_comp *comp, unsigned int w,
47 unsigned int h, unsigned int vrefresh,
48 unsigned int bpc)
49 {
50 struct mtk_disp_color *color = comp_to_color(comp);
51
52 writel(w, comp->regs + DISP_COLOR_WIDTH(color));
53 writel(h, comp->regs + DISP_COLOR_HEIGHT(color));
54 }
55
56 static void mtk_color_start(struct mtk_ddp_comp *comp)
57 {
58 struct mtk_disp_color *color = comp_to_color(comp);
59
60 writel(COLOR_BYPASS_ALL | COLOR_SEQ_SEL,
61 comp->regs + DISP_COLOR_CFG_MAIN);
62 writel(0x1, comp->regs + DISP_COLOR_START(color));
63 }
64
65 static const struct mtk_ddp_comp_funcs mtk_disp_color_funcs = {
66 .config = mtk_color_config,
67 .start = mtk_color_start,
68 };
69
70 static int mtk_disp_color_bind(struct device *dev, struct device *master,
71 void *data)
72 {
73 struct mtk_disp_color *priv = dev_get_drvdata(dev);
74 struct drm_device *drm_dev = data;
75 int ret;
76
77 ret = mtk_ddp_comp_register(drm_dev, &priv->ddp_comp);
78 if (ret < 0) {
79 dev_err(dev, "Failed to register component %pOF: %d\n",
80 dev->of_node, ret);
81 return ret;
82 }
83
84 return 0;
85 }
86
87 static void mtk_disp_color_unbind(struct device *dev, struct device *master,
88 void *data)
89 {
90 struct mtk_disp_color *priv = dev_get_drvdata(dev);
91 struct drm_device *drm_dev = data;
92
93 mtk_ddp_comp_unregister(drm_dev, &priv->ddp_comp);
94 }
95
96 static const struct component_ops mtk_disp_color_component_ops = {
97 .bind = mtk_disp_color_bind,
98 .unbind = mtk_disp_color_unbind,
99 };
100
101 static int mtk_disp_color_probe(struct platform_device *pdev)
102 {
103 struct device *dev = &pdev->dev;
104 struct mtk_disp_color *priv;
105 int comp_id;
106 int ret;
107
108 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
109 if (!priv)
110 return -ENOMEM;
111
112 comp_id = mtk_ddp_comp_get_id(dev->of_node, MTK_DISP_COLOR);
113 if (comp_id < 0) {
114 dev_err(dev, "Failed to identify by alias: %d\n", comp_id);
115 return comp_id;
116 }
117
118 ret = mtk_ddp_comp_init(dev, dev->of_node, &priv->ddp_comp, comp_id,
119 &mtk_disp_color_funcs);
120 if (ret) {
121 dev_err(dev, "Failed to initialize component: %d\n", ret);
122 return ret;
123 }
124
125 priv->data = of_device_get_match_data(dev);
126
127 platform_set_drvdata(pdev, priv);
128
129 ret = component_add(dev, &mtk_disp_color_component_ops);
130 if (ret)
131 dev_err(dev, "Failed to add component: %d\n", ret);
132
133 return ret;
134 }
135
136 static int mtk_disp_color_remove(struct platform_device *pdev)
137 {
138 component_del(&pdev->dev, &mtk_disp_color_component_ops);
139
140 return 0;
141 }
142
143 static const struct mtk_disp_color_data mt2701_color_driver_data = {
144 .color_offset = DISP_COLOR_START_MT2701,
145 };
146
147 static const struct mtk_disp_color_data mt8173_color_driver_data = {
148 .color_offset = DISP_COLOR_START_MT8173,
149 };
150
151 static const struct of_device_id mtk_disp_color_driver_dt_match[] = {
152 { .compatible = "mediatek,mt2701-disp-color",
153 .data = &mt2701_color_driver_data},
154 { .compatible = "mediatek,mt8173-disp-color",
155 .data = &mt8173_color_driver_data},
156 {},
157 };
158 MODULE_DEVICE_TABLE(of, mtk_disp_color_driver_dt_match);
159
160 struct platform_driver mtk_disp_color_driver = {
161 .probe = mtk_disp_color_probe,
162 .remove = mtk_disp_color_remove,
163 .driver = {
164 .name = "mediatek-disp-color",
165 .owner = THIS_MODULE,
166 .of_match_table = mtk_disp_color_driver_dt_match,
167 },
168 };