]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/gpu/drm/zte/zx_drm_drv.c
drm/zte: drop use of drmP.h
[linux.git] / drivers / gpu / drm / zte / zx_drm_drv.c
1 /*
2  * Copyright 2016 Linaro Ltd.
3  * Copyright 2016 ZTE Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  */
10
11 #include <linux/clk.h>
12 #include <linux/component.h>
13 #include <linux/list.h>
14 #include <linux/module.h>
15 #include <linux/of_graph.h>
16 #include <linux/of_platform.h>
17 #include <linux/spinlock.h>
18
19 #include <drm/drm_atomic_helper.h>
20 #include <drm/drm_crtc.h>
21 #include <drm/drm_drv.h>
22 #include <drm/drm_fb_cma_helper.h>
23 #include <drm/drm_fb_helper.h>
24 #include <drm/drm_gem_cma_helper.h>
25 #include <drm/drm_gem_framebuffer_helper.h>
26 #include <drm/drm_of.h>
27 #include <drm/drm_probe_helper.h>
28 #include <drm/drm_vblank.h>
29
30 #include "zx_drm_drv.h"
31 #include "zx_vou.h"
32
33 static const struct drm_mode_config_funcs zx_drm_mode_config_funcs = {
34         .fb_create = drm_gem_fb_create,
35         .atomic_check = drm_atomic_helper_check,
36         .atomic_commit = drm_atomic_helper_commit,
37 };
38
39 DEFINE_DRM_GEM_CMA_FOPS(zx_drm_fops);
40
41 static struct drm_driver zx_drm_driver = {
42         .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
43         .gem_free_object_unlocked = drm_gem_cma_free_object,
44         .gem_vm_ops = &drm_gem_cma_vm_ops,
45         .dumb_create = drm_gem_cma_dumb_create,
46         .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
47         .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
48         .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
49         .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table,
50         .gem_prime_vmap = drm_gem_cma_prime_vmap,
51         .gem_prime_vunmap = drm_gem_cma_prime_vunmap,
52         .gem_prime_mmap = drm_gem_cma_prime_mmap,
53         .fops = &zx_drm_fops,
54         .name = "zx-vou",
55         .desc = "ZTE VOU Controller DRM",
56         .date = "20160811",
57         .major = 1,
58         .minor = 0,
59 };
60
61 static int zx_drm_bind(struct device *dev)
62 {
63         struct drm_device *drm;
64         int ret;
65
66         drm = drm_dev_alloc(&zx_drm_driver, dev);
67         if (IS_ERR(drm))
68                 return PTR_ERR(drm);
69
70         dev_set_drvdata(dev, drm);
71
72         drm_mode_config_init(drm);
73         drm->mode_config.min_width = 16;
74         drm->mode_config.min_height = 16;
75         drm->mode_config.max_width = 4096;
76         drm->mode_config.max_height = 4096;
77         drm->mode_config.funcs = &zx_drm_mode_config_funcs;
78
79         ret = component_bind_all(dev, drm);
80         if (ret) {
81                 DRM_DEV_ERROR(dev, "failed to bind all components: %d\n", ret);
82                 goto out_unregister;
83         }
84
85         ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
86         if (ret < 0) {
87                 DRM_DEV_ERROR(dev, "failed to init vblank: %d\n", ret);
88                 goto out_unbind;
89         }
90
91         /*
92          * We will manage irq handler on our own.  In this case, irq_enabled
93          * need to be true for using vblank core support.
94          */
95         drm->irq_enabled = true;
96
97         drm_mode_config_reset(drm);
98         drm_kms_helper_poll_init(drm);
99
100         ret = drm_dev_register(drm, 0);
101         if (ret)
102                 goto out_poll_fini;
103
104         drm_fbdev_generic_setup(drm, 32);
105
106         return 0;
107
108 out_poll_fini:
109         drm_kms_helper_poll_fini(drm);
110         drm_mode_config_cleanup(drm);
111 out_unbind:
112         component_unbind_all(dev, drm);
113 out_unregister:
114         dev_set_drvdata(dev, NULL);
115         drm_dev_put(drm);
116         return ret;
117 }
118
119 static void zx_drm_unbind(struct device *dev)
120 {
121         struct drm_device *drm = dev_get_drvdata(dev);
122
123         drm_dev_unregister(drm);
124         drm_kms_helper_poll_fini(drm);
125         drm_atomic_helper_shutdown(drm);
126         drm_mode_config_cleanup(drm);
127         component_unbind_all(dev, drm);
128         dev_set_drvdata(dev, NULL);
129         drm_dev_put(drm);
130 }
131
132 static const struct component_master_ops zx_drm_master_ops = {
133         .bind = zx_drm_bind,
134         .unbind = zx_drm_unbind,
135 };
136
137 static int compare_of(struct device *dev, void *data)
138 {
139         return dev->of_node == data;
140 }
141
142 static int zx_drm_probe(struct platform_device *pdev)
143 {
144         struct device *dev = &pdev->dev;
145         struct device_node *parent = dev->of_node;
146         struct device_node *child;
147         struct component_match *match = NULL;
148         int ret;
149
150         ret = devm_of_platform_populate(dev);
151         if (ret)
152                 return ret;
153
154         for_each_available_child_of_node(parent, child)
155                 component_match_add(dev, &match, compare_of, child);
156
157         return component_master_add_with_match(dev, &zx_drm_master_ops, match);
158 }
159
160 static int zx_drm_remove(struct platform_device *pdev)
161 {
162         component_master_del(&pdev->dev, &zx_drm_master_ops);
163         return 0;
164 }
165
166 static const struct of_device_id zx_drm_of_match[] = {
167         { .compatible = "zte,zx296718-vou", },
168         { /* end */ },
169 };
170 MODULE_DEVICE_TABLE(of, zx_drm_of_match);
171
172 static struct platform_driver zx_drm_platform_driver = {
173         .probe = zx_drm_probe,
174         .remove = zx_drm_remove,
175         .driver = {
176                 .name = "zx-drm",
177                 .of_match_table = zx_drm_of_match,
178         },
179 };
180
181 static struct platform_driver *drivers[] = {
182         &zx_crtc_driver,
183         &zx_hdmi_driver,
184         &zx_tvenc_driver,
185         &zx_vga_driver,
186         &zx_drm_platform_driver,
187 };
188
189 static int zx_drm_init(void)
190 {
191         return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
192 }
193 module_init(zx_drm_init);
194
195 static void zx_drm_exit(void)
196 {
197         platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
198 }
199 module_exit(zx_drm_exit);
200
201 MODULE_AUTHOR("Shawn Guo <shawn.guo@linaro.org>");
202 MODULE_DESCRIPTION("ZTE ZX VOU DRM driver");
203 MODULE_LICENSE("GPL v2");