]> Pileus Git - ~andy/linux/blob - drivers/gpu/drm/exynos/exynos_drm_drv.c
Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[~andy/linux] / drivers / gpu / drm / exynos / exynos_drm_drv.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd.
3  * Authors:
4  *      Inki Dae <inki.dae@samsung.com>
5  *      Joonyoung Shim <jy0922.shim@samsung.com>
6  *      Seung-Woo Kim <sw0312.kim@samsung.com>
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice (including the next
16  * paragraph) shall be included in all copies or substantial portions of the
17  * Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  */
27
28 #include "drmP.h"
29 #include "drm.h"
30 #include "drm_crtc_helper.h"
31
32 #include <drm/exynos_drm.h>
33
34 #include "exynos_drm_drv.h"
35 #include "exynos_drm_crtc.h"
36 #include "exynos_drm_encoder.h"
37 #include "exynos_drm_fbdev.h"
38 #include "exynos_drm_fb.h"
39 #include "exynos_drm_gem.h"
40 #include "exynos_drm_plane.h"
41 #include "exynos_drm_vidi.h"
42 #include "exynos_drm_dmabuf.h"
43 #include "exynos_drm_g2d.h"
44
45 #define DRIVER_NAME     "exynos"
46 #define DRIVER_DESC     "Samsung SoC DRM"
47 #define DRIVER_DATE     "20110530"
48 #define DRIVER_MAJOR    1
49 #define DRIVER_MINOR    0
50
51 #define VBLANK_OFF_DELAY        50000
52
53 static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
54 {
55         struct exynos_drm_private *private;
56         int ret;
57         int nr;
58
59         DRM_DEBUG_DRIVER("%s\n", __FILE__);
60
61         private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
62         if (!private) {
63                 DRM_ERROR("failed to allocate private\n");
64                 return -ENOMEM;
65         }
66
67         INIT_LIST_HEAD(&private->pageflip_event_list);
68         dev->dev_private = (void *)private;
69
70         drm_mode_config_init(dev);
71
72         /* init kms poll for handling hpd */
73         drm_kms_helper_poll_init(dev);
74
75         exynos_drm_mode_config_init(dev);
76
77         /*
78          * EXYNOS4 is enough to have two CRTCs and each crtc would be used
79          * without dependency of hardware.
80          */
81         for (nr = 0; nr < MAX_CRTC; nr++) {
82                 ret = exynos_drm_crtc_create(dev, nr);
83                 if (ret)
84                         goto err_crtc;
85         }
86
87         for (nr = 0; nr < MAX_PLANE; nr++) {
88                 struct drm_plane *plane;
89                 unsigned int possible_crtcs = (1 << MAX_CRTC) - 1;
90
91                 plane = exynos_plane_init(dev, possible_crtcs, false);
92                 if (!plane)
93                         goto err_crtc;
94         }
95
96         ret = drm_vblank_init(dev, MAX_CRTC);
97         if (ret)
98                 goto err_crtc;
99
100         /*
101          * probe sub drivers such as display controller and hdmi driver,
102          * that were registered at probe() of platform driver
103          * to the sub driver and create encoder and connector for them.
104          */
105         ret = exynos_drm_device_register(dev);
106         if (ret)
107                 goto err_vblank;
108
109         /* setup possible_clones. */
110         exynos_drm_encoder_setup(dev);
111
112         /*
113          * create and configure fb helper and also exynos specific
114          * fbdev object.
115          */
116         ret = exynos_drm_fbdev_init(dev);
117         if (ret) {
118                 DRM_ERROR("failed to initialize drm fbdev\n");
119                 goto err_drm_device;
120         }
121
122         drm_vblank_offdelay = VBLANK_OFF_DELAY;
123
124         return 0;
125
126 err_drm_device:
127         exynos_drm_device_unregister(dev);
128 err_vblank:
129         drm_vblank_cleanup(dev);
130 err_crtc:
131         drm_mode_config_cleanup(dev);
132         kfree(private);
133
134         return ret;
135 }
136
137 static int exynos_drm_unload(struct drm_device *dev)
138 {
139         DRM_DEBUG_DRIVER("%s\n", __FILE__);
140
141         exynos_drm_fbdev_fini(dev);
142         exynos_drm_device_unregister(dev);
143         drm_vblank_cleanup(dev);
144         drm_kms_helper_poll_fini(dev);
145         drm_mode_config_cleanup(dev);
146         kfree(dev->dev_private);
147
148         dev->dev_private = NULL;
149
150         return 0;
151 }
152
153 static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
154 {
155         struct drm_exynos_file_private *file_priv;
156
157         DRM_DEBUG_DRIVER("%s\n", __FILE__);
158
159         file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL);
160         if (!file_priv)
161                 return -ENOMEM;
162
163         file->driver_priv = file_priv;
164
165         return exynos_drm_subdrv_open(dev, file);
166 }
167
168 static void exynos_drm_preclose(struct drm_device *dev,
169                                         struct drm_file *file)
170 {
171         struct exynos_drm_private *private = dev->dev_private;
172         struct drm_pending_vblank_event *e, *t;
173         unsigned long flags;
174
175         DRM_DEBUG_DRIVER("%s\n", __FILE__);
176
177         /* release events of current file */
178         spin_lock_irqsave(&dev->event_lock, flags);
179         list_for_each_entry_safe(e, t, &private->pageflip_event_list,
180                         base.link) {
181                 if (e->base.file_priv == file) {
182                         list_del(&e->base.link);
183                         e->base.destroy(&e->base);
184                 }
185         }
186         spin_unlock_irqrestore(&dev->event_lock, flags);
187
188         exynos_drm_subdrv_close(dev, file);
189 }
190
191 static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
192 {
193         DRM_DEBUG_DRIVER("%s\n", __FILE__);
194
195         if (!file->driver_priv)
196                 return;
197
198         kfree(file->driver_priv);
199         file->driver_priv = NULL;
200 }
201
202 static void exynos_drm_lastclose(struct drm_device *dev)
203 {
204         DRM_DEBUG_DRIVER("%s\n", __FILE__);
205
206         exynos_drm_fbdev_restore_mode(dev);
207 }
208
209 static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
210         .fault = exynos_drm_gem_fault,
211         .open = drm_gem_vm_open,
212         .close = drm_gem_vm_close,
213 };
214
215 static struct drm_ioctl_desc exynos_ioctls[] = {
216         DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
217                         DRM_UNLOCKED | DRM_AUTH),
218         DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET,
219                         exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
220                         DRM_AUTH),
221         DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP,
222                         exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
223         DRM_IOCTL_DEF_DRV(EXYNOS_GEM_GET,
224                         exynos_drm_gem_get_ioctl, DRM_UNLOCKED),
225         DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION,
226                         vidi_connection_ioctl, DRM_UNLOCKED | DRM_AUTH),
227         DRM_IOCTL_DEF_DRV(EXYNOS_G2D_GET_VER,
228                         exynos_g2d_get_ver_ioctl, DRM_UNLOCKED | DRM_AUTH),
229         DRM_IOCTL_DEF_DRV(EXYNOS_G2D_SET_CMDLIST,
230                         exynos_g2d_set_cmdlist_ioctl, DRM_UNLOCKED | DRM_AUTH),
231         DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC,
232                         exynos_g2d_exec_ioctl, DRM_UNLOCKED | DRM_AUTH),
233 };
234
235 static const struct file_operations exynos_drm_driver_fops = {
236         .owner          = THIS_MODULE,
237         .open           = drm_open,
238         .mmap           = exynos_drm_gem_mmap,
239         .poll           = drm_poll,
240         .read           = drm_read,
241         .unlocked_ioctl = drm_ioctl,
242 #ifdef CONFIG_COMPAT
243         .compat_ioctl = drm_compat_ioctl,
244 #endif
245         .release        = drm_release,
246 };
247
248 static struct drm_driver exynos_drm_driver = {
249         .driver_features        = DRIVER_HAVE_IRQ | DRIVER_MODESET |
250                                         DRIVER_GEM | DRIVER_PRIME,
251         .load                   = exynos_drm_load,
252         .unload                 = exynos_drm_unload,
253         .open                   = exynos_drm_open,
254         .preclose               = exynos_drm_preclose,
255         .lastclose              = exynos_drm_lastclose,
256         .postclose              = exynos_drm_postclose,
257         .get_vblank_counter     = drm_vblank_count,
258         .enable_vblank          = exynos_drm_crtc_enable_vblank,
259         .disable_vblank         = exynos_drm_crtc_disable_vblank,
260         .gem_init_object        = exynos_drm_gem_init_object,
261         .gem_free_object        = exynos_drm_gem_free_object,
262         .gem_vm_ops             = &exynos_drm_gem_vm_ops,
263         .dumb_create            = exynos_drm_gem_dumb_create,
264         .dumb_map_offset        = exynos_drm_gem_dumb_map_offset,
265         .dumb_destroy           = exynos_drm_gem_dumb_destroy,
266         .prime_handle_to_fd     = drm_gem_prime_handle_to_fd,
267         .prime_fd_to_handle     = drm_gem_prime_fd_to_handle,
268         .gem_prime_export       = exynos_dmabuf_prime_export,
269         .gem_prime_import       = exynos_dmabuf_prime_import,
270         .ioctls                 = exynos_ioctls,
271         .fops                   = &exynos_drm_driver_fops,
272         .name   = DRIVER_NAME,
273         .desc   = DRIVER_DESC,
274         .date   = DRIVER_DATE,
275         .major  = DRIVER_MAJOR,
276         .minor  = DRIVER_MINOR,
277 };
278
279 static int exynos_drm_platform_probe(struct platform_device *pdev)
280 {
281         DRM_DEBUG_DRIVER("%s\n", __FILE__);
282
283         exynos_drm_driver.num_ioctls = DRM_ARRAY_SIZE(exynos_ioctls);
284
285         return drm_platform_init(&exynos_drm_driver, pdev);
286 }
287
288 static int exynos_drm_platform_remove(struct platform_device *pdev)
289 {
290         DRM_DEBUG_DRIVER("%s\n", __FILE__);
291
292         drm_platform_exit(&exynos_drm_driver, pdev);
293
294         return 0;
295 }
296
297 static struct platform_driver exynos_drm_platform_driver = {
298         .probe          = exynos_drm_platform_probe,
299         .remove         = __devexit_p(exynos_drm_platform_remove),
300         .driver         = {
301                 .owner  = THIS_MODULE,
302                 .name   = "exynos-drm",
303         },
304 };
305
306 static int __init exynos_drm_init(void)
307 {
308         int ret;
309
310         DRM_DEBUG_DRIVER("%s\n", __FILE__);
311
312 #ifdef CONFIG_DRM_EXYNOS_FIMD
313         ret = platform_driver_register(&fimd_driver);
314         if (ret < 0)
315                 goto out_fimd;
316 #endif
317
318 #ifdef CONFIG_DRM_EXYNOS_HDMI
319         ret = platform_driver_register(&hdmi_driver);
320         if (ret < 0)
321                 goto out_hdmi;
322         ret = platform_driver_register(&mixer_driver);
323         if (ret < 0)
324                 goto out_mixer;
325         ret = platform_driver_register(&exynos_drm_common_hdmi_driver);
326         if (ret < 0)
327                 goto out_common_hdmi;
328 #endif
329
330 #ifdef CONFIG_DRM_EXYNOS_VIDI
331         ret = platform_driver_register(&vidi_driver);
332         if (ret < 0)
333                 goto out_vidi;
334 #endif
335
336 #ifdef CONFIG_DRM_EXYNOS_G2D
337         ret = platform_driver_register(&g2d_driver);
338         if (ret < 0)
339                 goto out_g2d;
340 #endif
341
342         ret = platform_driver_register(&exynos_drm_platform_driver);
343         if (ret < 0)
344                 goto out;
345
346         return 0;
347
348 out:
349 #ifdef CONFIG_DRM_EXYNOS_G2D
350         platform_driver_unregister(&g2d_driver);
351 out_g2d:
352 #endif
353
354 #ifdef CONFIG_DRM_EXYNOS_VIDI
355 out_vidi:
356         platform_driver_unregister(&vidi_driver);
357 #endif
358
359 #ifdef CONFIG_DRM_EXYNOS_HDMI
360         platform_driver_unregister(&exynos_drm_common_hdmi_driver);
361 out_common_hdmi:
362         platform_driver_unregister(&mixer_driver);
363 out_mixer:
364         platform_driver_unregister(&hdmi_driver);
365 out_hdmi:
366 #endif
367
368 #ifdef CONFIG_DRM_EXYNOS_FIMD
369         platform_driver_unregister(&fimd_driver);
370 out_fimd:
371 #endif
372         return ret;
373 }
374
375 static void __exit exynos_drm_exit(void)
376 {
377         DRM_DEBUG_DRIVER("%s\n", __FILE__);
378
379         platform_driver_unregister(&exynos_drm_platform_driver);
380
381 #ifdef CONFIG_DRM_EXYNOS_G2D
382         platform_driver_unregister(&g2d_driver);
383 #endif
384
385 #ifdef CONFIG_DRM_EXYNOS_HDMI
386         platform_driver_unregister(&exynos_drm_common_hdmi_driver);
387         platform_driver_unregister(&mixer_driver);
388         platform_driver_unregister(&hdmi_driver);
389 #endif
390
391 #ifdef CONFIG_DRM_EXYNOS_VIDI
392         platform_driver_unregister(&vidi_driver);
393 #endif
394
395 #ifdef CONFIG_DRM_EXYNOS_FIMD
396         platform_driver_unregister(&fimd_driver);
397 #endif
398 }
399
400 module_init(exynos_drm_init);
401 module_exit(exynos_drm_exit);
402
403 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
404 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
405 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
406 MODULE_DESCRIPTION("Samsung SoC DRM Driver");
407 MODULE_LICENSE("GPL");