blob: 35889ca255e93996f6cc37094a44147f756051f8 [file] [log] [blame]
Inki Dae1c248b72011-10-04 19:19:01 +09001/*
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"
Seung-Woo Kim7db3eba2011-10-18 16:58:05 +090030#include "drm_crtc_helper.h"
Inki Dae1c248b72011-10-04 19:19:01 +090031
32#include <drm/exynos_drm.h>
33
34#include "exynos_drm_drv.h"
35#include "exynos_drm_crtc.h"
36#include "exynos_drm_fbdev.h"
37#include "exynos_drm_fb.h"
38#include "exynos_drm_gem.h"
Joonyoung Shim864ee9e2011-12-08 17:54:07 +090039#include "exynos_drm_plane.h"
Inki Dae1c248b72011-10-04 19:19:01 +090040
Inki Dae0edf9932011-12-15 17:31:24 +090041#define DRIVER_NAME "exynos"
Inki Dae1c248b72011-10-04 19:19:01 +090042#define DRIVER_DESC "Samsung SoC DRM"
43#define DRIVER_DATE "20110530"
44#define DRIVER_MAJOR 1
45#define DRIVER_MINOR 0
46
Inki Dae52c68812011-12-16 21:31:12 +090047#define VBLANK_OFF_DELAY 50000
48
Inki Dae1c248b72011-10-04 19:19:01 +090049static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
50{
51 struct exynos_drm_private *private;
52 int ret;
53 int nr;
54
55 DRM_DEBUG_DRIVER("%s\n", __FILE__);
56
57 private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
58 if (!private) {
59 DRM_ERROR("failed to allocate private\n");
60 return -ENOMEM;
61 }
62
63 INIT_LIST_HEAD(&private->pageflip_event_list);
64 dev->dev_private = (void *)private;
65
66 drm_mode_config_init(dev);
67
Seung-Woo Kim7db3eba2011-10-18 16:58:05 +090068 /* init kms poll for handling hpd */
69 drm_kms_helper_poll_init(dev);
70
Inki Dae1c248b72011-10-04 19:19:01 +090071 exynos_drm_mode_config_init(dev);
72
73 /*
74 * EXYNOS4 is enough to have two CRTCs and each crtc would be used
75 * without dependency of hardware.
76 */
77 for (nr = 0; nr < MAX_CRTC; nr++) {
78 ret = exynos_drm_crtc_create(dev, nr);
79 if (ret)
80 goto err_crtc;
81 }
82
Joonyoung Shim864ee9e2011-12-08 17:54:07 +090083 for (nr = 0; nr < MAX_PLANE; nr++) {
84 ret = exynos_plane_init(dev, nr);
85 if (ret)
86 goto err_crtc;
87 }
88
Inki Dae1c248b72011-10-04 19:19:01 +090089 ret = drm_vblank_init(dev, MAX_CRTC);
90 if (ret)
91 goto err_crtc;
92
93 /*
94 * probe sub drivers such as display controller and hdmi driver,
95 * that were registered at probe() of platform driver
96 * to the sub driver and create encoder and connector for them.
97 */
98 ret = exynos_drm_device_register(dev);
99 if (ret)
100 goto err_vblank;
101
102 /*
103 * create and configure fb helper and also exynos specific
104 * fbdev object.
105 */
106 ret = exynos_drm_fbdev_init(dev);
107 if (ret) {
108 DRM_ERROR("failed to initialize drm fbdev\n");
109 goto err_drm_device;
110 }
111
Inki Dae52c68812011-12-16 21:31:12 +0900112 drm_vblank_offdelay = VBLANK_OFF_DELAY;
113
Inki Dae1c248b72011-10-04 19:19:01 +0900114 return 0;
115
116err_drm_device:
117 exynos_drm_device_unregister(dev);
118err_vblank:
119 drm_vblank_cleanup(dev);
120err_crtc:
121 drm_mode_config_cleanup(dev);
122 kfree(private);
123
124 return ret;
125}
126
127static int exynos_drm_unload(struct drm_device *dev)
128{
129 DRM_DEBUG_DRIVER("%s\n", __FILE__);
130
131 exynos_drm_fbdev_fini(dev);
132 exynos_drm_device_unregister(dev);
133 drm_vblank_cleanup(dev);
Seung-Woo Kim7db3eba2011-10-18 16:58:05 +0900134 drm_kms_helper_poll_fini(dev);
Inki Dae1c248b72011-10-04 19:19:01 +0900135 drm_mode_config_cleanup(dev);
136 kfree(dev->dev_private);
137
138 dev->dev_private = NULL;
139
140 return 0;
141}
142
Inki Daeccf4d882011-10-14 13:29:51 +0900143static void exynos_drm_preclose(struct drm_device *dev,
144 struct drm_file *file_priv)
145{
146 struct exynos_drm_private *dev_priv = dev->dev_private;
147
148 /*
149 * drm framework frees all events at release time,
150 * so private event list should be cleared.
151 */
152 if (!list_empty(&dev_priv->pageflip_event_list))
153 INIT_LIST_HEAD(&dev_priv->pageflip_event_list);
154}
155
Inki Dae1c248b72011-10-04 19:19:01 +0900156static void exynos_drm_lastclose(struct drm_device *dev)
157{
158 DRM_DEBUG_DRIVER("%s\n", __FILE__);
159
160 exynos_drm_fbdev_restore_mode(dev);
161}
162
163static struct vm_operations_struct exynos_drm_gem_vm_ops = {
164 .fault = exynos_drm_gem_fault,
165 .open = drm_gem_vm_open,
166 .close = drm_gem_vm_close,
167};
168
169static struct drm_ioctl_desc exynos_ioctls[] = {
170 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
171 DRM_UNLOCKED | DRM_AUTH),
172 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET,
173 exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
174 DRM_AUTH),
175 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP,
176 exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
Joonyoung Shim864ee9e2011-12-08 17:54:07 +0900177 DRM_IOCTL_DEF_DRV(EXYNOS_PLANE_SET_ZPOS, exynos_plane_set_zpos_ioctl,
178 DRM_UNLOCKED | DRM_AUTH),
Inki Dae1c248b72011-10-04 19:19:01 +0900179};
180
Joonyoung Shimac2bdf72011-12-08 15:00:20 +0900181static const struct file_operations exynos_drm_driver_fops = {
182 .owner = THIS_MODULE,
183 .open = drm_open,
184 .mmap = exynos_drm_gem_mmap,
185 .poll = drm_poll,
186 .read = drm_read,
187 .unlocked_ioctl = drm_ioctl,
188 .release = drm_release,
189};
190
Inki Dae1c248b72011-10-04 19:19:01 +0900191static struct drm_driver exynos_drm_driver = {
192 .driver_features = DRIVER_HAVE_IRQ | DRIVER_BUS_PLATFORM |
193 DRIVER_MODESET | DRIVER_GEM,
194 .load = exynos_drm_load,
195 .unload = exynos_drm_unload,
Inki Daeccf4d882011-10-14 13:29:51 +0900196 .preclose = exynos_drm_preclose,
Inki Dae1c248b72011-10-04 19:19:01 +0900197 .lastclose = exynos_drm_lastclose,
198 .get_vblank_counter = drm_vblank_count,
199 .enable_vblank = exynos_drm_crtc_enable_vblank,
200 .disable_vblank = exynos_drm_crtc_disable_vblank,
201 .gem_init_object = exynos_drm_gem_init_object,
202 .gem_free_object = exynos_drm_gem_free_object,
203 .gem_vm_ops = &exynos_drm_gem_vm_ops,
204 .dumb_create = exynos_drm_gem_dumb_create,
205 .dumb_map_offset = exynos_drm_gem_dumb_map_offset,
206 .dumb_destroy = exynos_drm_gem_dumb_destroy,
207 .ioctls = exynos_ioctls,
Joonyoung Shimac2bdf72011-12-08 15:00:20 +0900208 .fops = &exynos_drm_driver_fops,
Inki Dae1c248b72011-10-04 19:19:01 +0900209 .name = DRIVER_NAME,
210 .desc = DRIVER_DESC,
211 .date = DRIVER_DATE,
212 .major = DRIVER_MAJOR,
213 .minor = DRIVER_MINOR,
214};
215
216static int exynos_drm_platform_probe(struct platform_device *pdev)
217{
218 DRM_DEBUG_DRIVER("%s\n", __FILE__);
219
220 exynos_drm_driver.num_ioctls = DRM_ARRAY_SIZE(exynos_ioctls);
221
222 return drm_platform_init(&exynos_drm_driver, pdev);
223}
224
225static int exynos_drm_platform_remove(struct platform_device *pdev)
226{
227 DRM_DEBUG_DRIVER("%s\n", __FILE__);
228
229 drm_platform_exit(&exynos_drm_driver, pdev);
230
231 return 0;
232}
233
234static struct platform_driver exynos_drm_platform_driver = {
235 .probe = exynos_drm_platform_probe,
236 .remove = __devexit_p(exynos_drm_platform_remove),
237 .driver = {
238 .owner = THIS_MODULE,
239 .name = DRIVER_NAME,
240 },
241};
242
243static int __init exynos_drm_init(void)
244{
245 DRM_DEBUG_DRIVER("%s\n", __FILE__);
246
247 return platform_driver_register(&exynos_drm_platform_driver);
248}
249
250static void __exit exynos_drm_exit(void)
251{
252 DRM_DEBUG_DRIVER("%s\n", __FILE__);
253
254 platform_driver_unregister(&exynos_drm_platform_driver);
255}
256
257module_init(exynos_drm_init);
258module_exit(exynos_drm_exit);
259
260MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
261MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
262MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
263MODULE_DESCRIPTION("Samsung SoC DRM Driver");
264MODULE_LICENSE("GPL");