1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2016 Linaro Ltd.
4 * Copyright 2016 ZTE Corporation.
8 #include <linux/component.h>
9 #include <linux/list.h>
10 #include <linux/module.h>
11 #include <linux/of_graph.h>
12 #include <linux/of_platform.h>
13 #include <linux/spinlock.h>
15 #include <drm/drm_atomic_helper.h>
16 #include <drm/drm_crtc.h>
17 #include <drm/drm_drv.h>
18 #include <drm/drm_fb_cma_helper.h>
19 #include <drm/drm_fb_helper.h>
20 #include <drm/drm_gem_cma_helper.h>
21 #include <drm/drm_gem_framebuffer_helper.h>
22 #include <drm/drm_of.h>
23 #include <drm/drm_probe_helper.h>
24 #include <drm/drm_vblank.h>
26 #include "zx_drm_drv.h"
29 static const struct drm_mode_config_funcs zx_drm_mode_config_funcs
= {
30 .fb_create
= drm_gem_fb_create
,
31 .atomic_check
= drm_atomic_helper_check
,
32 .atomic_commit
= drm_atomic_helper_commit
,
35 DEFINE_DRM_GEM_CMA_FOPS(zx_drm_fops
);
37 static struct drm_driver zx_drm_driver
= {
38 .driver_features
= DRIVER_GEM
| DRIVER_MODESET
| DRIVER_ATOMIC
,
39 .gem_free_object_unlocked
= drm_gem_cma_free_object
,
40 .gem_vm_ops
= &drm_gem_cma_vm_ops
,
41 .dumb_create
= drm_gem_cma_dumb_create
,
42 .prime_handle_to_fd
= drm_gem_prime_handle_to_fd
,
43 .prime_fd_to_handle
= drm_gem_prime_fd_to_handle
,
44 .gem_prime_get_sg_table
= drm_gem_cma_prime_get_sg_table
,
45 .gem_prime_import_sg_table
= drm_gem_cma_prime_import_sg_table
,
46 .gem_prime_vmap
= drm_gem_cma_prime_vmap
,
47 .gem_prime_vunmap
= drm_gem_cma_prime_vunmap
,
48 .gem_prime_mmap
= drm_gem_cma_prime_mmap
,
51 .desc
= "ZTE VOU Controller DRM",
57 static int zx_drm_bind(struct device
*dev
)
59 struct drm_device
*drm
;
62 drm
= drm_dev_alloc(&zx_drm_driver
, dev
);
66 dev_set_drvdata(dev
, drm
);
68 drm_mode_config_init(drm
);
69 drm
->mode_config
.min_width
= 16;
70 drm
->mode_config
.min_height
= 16;
71 drm
->mode_config
.max_width
= 4096;
72 drm
->mode_config
.max_height
= 4096;
73 drm
->mode_config
.funcs
= &zx_drm_mode_config_funcs
;
75 ret
= component_bind_all(dev
, drm
);
77 DRM_DEV_ERROR(dev
, "failed to bind all components: %d\n", ret
);
81 ret
= drm_vblank_init(drm
, drm
->mode_config
.num_crtc
);
83 DRM_DEV_ERROR(dev
, "failed to init vblank: %d\n", ret
);
88 * We will manage irq handler on our own. In this case, irq_enabled
89 * need to be true for using vblank core support.
91 drm
->irq_enabled
= true;
93 drm_mode_config_reset(drm
);
94 drm_kms_helper_poll_init(drm
);
96 ret
= drm_dev_register(drm
, 0);
100 drm_fbdev_generic_setup(drm
, 32);
105 drm_kms_helper_poll_fini(drm
);
106 drm_mode_config_cleanup(drm
);
108 component_unbind_all(dev
, drm
);
110 dev_set_drvdata(dev
, NULL
);
115 static void zx_drm_unbind(struct device
*dev
)
117 struct drm_device
*drm
= dev_get_drvdata(dev
);
119 drm_dev_unregister(drm
);
120 drm_kms_helper_poll_fini(drm
);
121 drm_atomic_helper_shutdown(drm
);
122 drm_mode_config_cleanup(drm
);
123 component_unbind_all(dev
, drm
);
124 dev_set_drvdata(dev
, NULL
);
128 static const struct component_master_ops zx_drm_master_ops
= {
130 .unbind
= zx_drm_unbind
,
133 static int compare_of(struct device
*dev
, void *data
)
135 return dev
->of_node
== data
;
138 static int zx_drm_probe(struct platform_device
*pdev
)
140 struct device
*dev
= &pdev
->dev
;
141 struct device_node
*parent
= dev
->of_node
;
142 struct device_node
*child
;
143 struct component_match
*match
= NULL
;
146 ret
= devm_of_platform_populate(dev
);
150 for_each_available_child_of_node(parent
, child
)
151 component_match_add(dev
, &match
, compare_of
, child
);
153 return component_master_add_with_match(dev
, &zx_drm_master_ops
, match
);
156 static int zx_drm_remove(struct platform_device
*pdev
)
158 component_master_del(&pdev
->dev
, &zx_drm_master_ops
);
162 static const struct of_device_id zx_drm_of_match
[] = {
163 { .compatible
= "zte,zx296718-vou", },
166 MODULE_DEVICE_TABLE(of
, zx_drm_of_match
);
168 static struct platform_driver zx_drm_platform_driver
= {
169 .probe
= zx_drm_probe
,
170 .remove
= zx_drm_remove
,
173 .of_match_table
= zx_drm_of_match
,
177 static struct platform_driver
*drivers
[] = {
182 &zx_drm_platform_driver
,
185 static int zx_drm_init(void)
187 return platform_register_drivers(drivers
, ARRAY_SIZE(drivers
));
189 module_init(zx_drm_init
);
191 static void zx_drm_exit(void)
193 platform_unregister_drivers(drivers
, ARRAY_SIZE(drivers
));
195 module_exit(zx_drm_exit
);
197 MODULE_AUTHOR("Shawn Guo <shawn.guo@linaro.org>");
198 MODULE_DESCRIPTION("ZTE ZX VOU DRM driver");
199 MODULE_LICENSE("GPL v2");