Merge tag 'asoc-fix-v5.17-rc5' of https://git.kernel.org/pub/scm/linux/kernel/git...
[linux-block.git] / drivers / gpu / drm / sti / sti_drv.c
CommitLineData
e2842570 1// SPDX-License-Identifier: GPL-2.0
9bbf86fe
BG
2/*
3 * Copyright (C) STMicroelectronics SA 2014
4 * Author: Benjamin Gaignard <benjamin.gaignard@st.com> for STMicroelectronics.
9bbf86fe
BG
5 */
6
9bbf86fe 7#include <linux/component.h>
5e2f97a9 8#include <linux/dma-mapping.h>
9bbf86fe
BG
9#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/of_platform.h>
12
de4b00b0
BG
13#include <drm/drm_atomic.h>
14#include <drm/drm_atomic_helper.h>
5e2f97a9
SR
15#include <drm/drm_debugfs.h>
16#include <drm/drm_drv.h>
17#include <drm/drm_fb_cma_helper.h>
18#include <drm/drm_fb_helper.h>
9bbf86fe 19#include <drm/drm_gem_cma_helper.h>
80cad29f 20#include <drm/drm_gem_framebuffer_helper.h>
97ac0e47 21#include <drm/drm_of.h>
fcd70cd3 22#include <drm/drm_probe_helper.h>
9bbf86fe 23
9e1f05b2 24#include "sti_drv.h"
bf8f9e4a 25#include "sti_plane.h"
9bbf86fe
BG
26
27#define DRIVER_NAME "sti"
28#define DRIVER_DESC "STMicroelectronics SoC DRM"
29#define DRIVER_DATE "20140601"
30#define DRIVER_MAJOR 1
31#define DRIVER_MINOR 0
32
33#define STI_MAX_FB_HEIGHT 4096
34#define STI_MAX_FB_WIDTH 4096
35
bf8f9e4a
VA
36static int sti_drm_fps_get(void *data, u64 *val)
37{
38 struct drm_device *drm_dev = data;
39 struct drm_plane *p;
40 unsigned int i = 0;
41
42 *val = 0;
43 list_for_each_entry(p, &drm_dev->mode_config.plane_list, head) {
44 struct sti_plane *plane = to_sti_plane(p);
45
46 *val |= plane->fps_info.output << i;
47 i++;
48 }
49
50 return 0;
51}
52
53static int sti_drm_fps_set(void *data, u64 val)
54{
55 struct drm_device *drm_dev = data;
56 struct drm_plane *p;
57 unsigned int i = 0;
58
59 list_for_each_entry(p, &drm_dev->mode_config.plane_list, head) {
60 struct sti_plane *plane = to_sti_plane(p);
61
c462c2f5 62 memset(&plane->fps_info, 0, sizeof(plane->fps_info));
bf8f9e4a 63 plane->fps_info.output = (val >> i) & 1;
c462c2f5 64
bf8f9e4a
VA
65 i++;
66 }
67
68 return 0;
69}
70
71DEFINE_SIMPLE_ATTRIBUTE(sti_drm_fps_fops,
72 sti_drm_fps_get, sti_drm_fps_set, "%llu\n");
73
74static int sti_drm_fps_dbg_show(struct seq_file *s, void *data)
75{
76 struct drm_info_node *node = s->private;
77 struct drm_device *dev = node->minor->dev;
78 struct drm_plane *p;
bf8f9e4a
VA
79
80 list_for_each_entry(p, &dev->mode_config.plane_list, head) {
81 struct sti_plane *plane = to_sti_plane(p);
82
83 seq_printf(s, "%s%s\n",
84 plane->fps_info.fps_str,
85 plane->fps_info.fips_str);
86 }
87
bf8f9e4a
VA
88 return 0;
89}
90
91static struct drm_info_list sti_drm_dbg_list[] = {
92 {"fps_get", sti_drm_fps_dbg_show, 0},
93};
94
7ce84471 95static void sti_drm_dbg_init(struct drm_minor *minor)
bf8f9e4a 96{
54ac836b
WK
97 drm_debugfs_create_files(sti_drm_dbg_list,
98 ARRAY_SIZE(sti_drm_dbg_list),
99 minor->debugfs_root, minor);
bf8f9e4a 100
150c6624
GKH
101 debugfs_create_file("fps_show", S_IRUGO | S_IWUSR, minor->debugfs_root,
102 minor->dev, &sti_drm_fps_fops);
bf8f9e4a
VA
103
104 DRM_INFO("%s: debugfs installed\n", DRIVER_NAME);
bf8f9e4a
VA
105}
106
c5de4853 107static const struct drm_mode_config_funcs sti_mode_config_funcs = {
80cad29f 108 .fb_create = drm_gem_fb_create,
352f9a84 109 .atomic_check = drm_atomic_helper_check,
5e60f595 110 .atomic_commit = drm_atomic_helper_commit,
9bbf86fe
BG
111};
112
9e1f05b2 113static void sti_mode_config_init(struct drm_device *dev)
9bbf86fe
BG
114{
115 dev->mode_config.min_width = 0;
116 dev->mode_config.min_height = 0;
117
118 /*
119 * set max width and height as default value.
120 * this value would be used to check framebuffer size limitation
121 * at drm_mode_addfb().
122 */
738be9d6
VA
123 dev->mode_config.max_width = STI_MAX_FB_WIDTH;
124 dev->mode_config.max_height = STI_MAX_FB_HEIGHT;
9bbf86fe 125
9e1f05b2 126 dev->mode_config.funcs = &sti_mode_config_funcs;
352f9a84
PU
127
128 dev->mode_config.normalize_zpos = true;
9bbf86fe
BG
129}
130
d55f7e5d 131DEFINE_DRM_GEM_CMA_FOPS(sti_driver_fops);
9bbf86fe 132
70a59dd8 133static const struct drm_driver sti_driver = {
0424fdaf 134 .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
9e1f05b2 135 .fops = &sti_driver_fops,
9ddf22ad 136 DRM_GEM_CMA_DRIVER_OPS,
9bbf86fe 137
bf8f9e4a 138 .debugfs_init = sti_drm_dbg_init,
bf8f9e4a 139
9bbf86fe
BG
140 .name = DRIVER_NAME,
141 .desc = DRIVER_DESC,
142 .date = DRIVER_DATE,
143 .major = DRIVER_MAJOR,
144 .minor = DRIVER_MINOR,
145};
146
147static int compare_of(struct device *dev, void *data)
148{
149 return dev->of_node == data;
150}
151
84601dbd
BG
152static int sti_init(struct drm_device *ddev)
153{
154 struct sti_private *private;
155
156 private = kzalloc(sizeof(*private), GFP_KERNEL);
157 if (!private)
158 return -ENOMEM;
159
160 ddev->dev_private = (void *)private;
161 dev_set_drvdata(ddev->dev, ddev);
162 private->drm_dev = ddev;
163
84601dbd
BG
164 drm_mode_config_init(ddev);
165
166 sti_mode_config_init(ddev);
167
168 drm_kms_helper_poll_init(ddev);
169
170 return 0;
171}
172
173static void sti_cleanup(struct drm_device *ddev)
174{
175 struct sti_private *private = ddev->dev_private;
176
84601dbd 177 drm_kms_helper_poll_fini(ddev);
a2b50bab
DV
178 drm_atomic_helper_shutdown(ddev);
179 drm_mode_config_cleanup(ddev);
b7e05db3 180 component_unbind_all(ddev->dev, ddev);
84601dbd
BG
181 kfree(private);
182 ddev->dev_private = NULL;
183}
184
9e1f05b2 185static int sti_bind(struct device *dev)
9bbf86fe 186{
84601dbd
BG
187 struct drm_device *ddev;
188 int ret;
189
190 ddev = drm_dev_alloc(&sti_driver, dev);
0f288605
TG
191 if (IS_ERR(ddev))
192 return PTR_ERR(ddev);
84601dbd 193
84601dbd
BG
194 ret = sti_init(ddev);
195 if (ret)
a08eac47 196 goto err_drm_dev_put;
84601dbd
BG
197
198 ret = component_bind_all(ddev->dev, ddev);
199 if (ret)
200 goto err_cleanup;
201
202 ret = drm_dev_register(ddev, 0);
203 if (ret)
a2b50bab 204 goto err_cleanup;
84601dbd
BG
205
206 drm_mode_config_reset(ddev);
207
0f26e5ce 208 drm_fbdev_generic_setup(ddev, 32);
8953e9ee 209
84601dbd
BG
210 return 0;
211
84601dbd
BG
212err_cleanup:
213 sti_cleanup(ddev);
a08eac47
TZ
214err_drm_dev_put:
215 drm_dev_put(ddev);
84601dbd 216 return ret;
9bbf86fe
BG
217}
218
9e1f05b2 219static void sti_unbind(struct device *dev)
9bbf86fe 220{
84601dbd
BG
221 struct drm_device *ddev = dev_get_drvdata(dev);
222
223 drm_dev_unregister(ddev);
224 sti_cleanup(ddev);
a08eac47 225 drm_dev_put(ddev);
9bbf86fe
BG
226}
227
9e1f05b2
VA
228static const struct component_master_ops sti_ops = {
229 .bind = sti_bind,
230 .unbind = sti_unbind,
9bbf86fe
BG
231};
232
9e1f05b2 233static int sti_platform_probe(struct platform_device *pdev)
9bbf86fe
BG
234{
235 struct device *dev = &pdev->dev;
53bdcf5f 236 struct device_node *node = dev->of_node;
9bbf86fe
BG
237 struct device_node *child_np;
238 struct component_match *match = NULL;
239
240 dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
241
ac7d3af8 242 devm_of_platform_populate(dev);
53bdcf5f 243
9bbf86fe
BG
244 child_np = of_get_next_available_child(node, NULL);
245
246 while (child_np) {
97ac0e47
RK
247 drm_of_component_match_add(dev, &match, compare_of,
248 child_np);
9bbf86fe
BG
249 child_np = of_get_next_available_child(node, child_np);
250 }
251
9e1f05b2 252 return component_master_add_with_match(dev, &sti_ops, match);
9bbf86fe
BG
253}
254
9e1f05b2 255static int sti_platform_remove(struct platform_device *pdev)
9bbf86fe 256{
9e1f05b2 257 component_master_del(&pdev->dev, &sti_ops);
53bdcf5f 258
9bbf86fe
BG
259 return 0;
260}
261
9e1f05b2 262static const struct of_device_id sti_dt_ids[] = {
9bbf86fe
BG
263 { .compatible = "st,sti-display-subsystem", },
264 { /* end node */ },
265};
9e1f05b2 266MODULE_DEVICE_TABLE(of, sti_dt_ids);
9bbf86fe 267
9e1f05b2
VA
268static struct platform_driver sti_platform_driver = {
269 .probe = sti_platform_probe,
270 .remove = sti_platform_remove,
9bbf86fe 271 .driver = {
9bbf86fe 272 .name = DRIVER_NAME,
9e1f05b2 273 .of_match_table = sti_dt_ids,
9bbf86fe
BG
274 },
275};
276
dcec16ef
TR
277static struct platform_driver * const drivers[] = {
278 &sti_tvout_driver,
dcec16ef
TR
279 &sti_hqvdp_driver,
280 &sti_hdmi_driver,
281 &sti_hda_driver,
282 &sti_dvo_driver,
283 &sti_vtg_driver,
284 &sti_compositor_driver,
285 &sti_platform_driver,
286};
287
288static int sti_drm_init(void)
289{
290 return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
291}
292module_init(sti_drm_init);
293
294static void sti_drm_exit(void)
295{
296 platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
297}
298module_exit(sti_drm_exit);
9bbf86fe
BG
299
300MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
301MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
302MODULE_LICENSE("GPL");