Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 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" |
Seung-Woo Kim | 7db3eba | 2011-10-18 16:58:05 +0900 | [diff] [blame] | 30 | #include "drm_crtc_helper.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 31 | |
| 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" |
| 39 | |
| 40 | #define DRIVER_NAME "exynos-drm" |
| 41 | #define DRIVER_DESC "Samsung SoC DRM" |
| 42 | #define DRIVER_DATE "20110530" |
| 43 | #define DRIVER_MAJOR 1 |
| 44 | #define DRIVER_MINOR 0 |
| 45 | |
| 46 | static int exynos_drm_load(struct drm_device *dev, unsigned long flags) |
| 47 | { |
| 48 | struct exynos_drm_private *private; |
| 49 | int ret; |
| 50 | int nr; |
| 51 | |
| 52 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
| 53 | |
| 54 | private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL); |
| 55 | if (!private) { |
| 56 | DRM_ERROR("failed to allocate private\n"); |
| 57 | return -ENOMEM; |
| 58 | } |
| 59 | |
| 60 | INIT_LIST_HEAD(&private->pageflip_event_list); |
| 61 | dev->dev_private = (void *)private; |
| 62 | |
| 63 | drm_mode_config_init(dev); |
| 64 | |
Seung-Woo Kim | 7db3eba | 2011-10-18 16:58:05 +0900 | [diff] [blame] | 65 | /* init kms poll for handling hpd */ |
| 66 | drm_kms_helper_poll_init(dev); |
| 67 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 68 | exynos_drm_mode_config_init(dev); |
| 69 | |
| 70 | /* |
| 71 | * EXYNOS4 is enough to have two CRTCs and each crtc would be used |
| 72 | * without dependency of hardware. |
| 73 | */ |
| 74 | for (nr = 0; nr < MAX_CRTC; nr++) { |
| 75 | ret = exynos_drm_crtc_create(dev, nr); |
| 76 | if (ret) |
| 77 | goto err_crtc; |
| 78 | } |
| 79 | |
| 80 | ret = drm_vblank_init(dev, MAX_CRTC); |
| 81 | if (ret) |
| 82 | goto err_crtc; |
| 83 | |
| 84 | /* |
| 85 | * probe sub drivers such as display controller and hdmi driver, |
| 86 | * that were registered at probe() of platform driver |
| 87 | * to the sub driver and create encoder and connector for them. |
| 88 | */ |
| 89 | ret = exynos_drm_device_register(dev); |
| 90 | if (ret) |
| 91 | goto err_vblank; |
| 92 | |
| 93 | /* |
| 94 | * create and configure fb helper and also exynos specific |
| 95 | * fbdev object. |
| 96 | */ |
| 97 | ret = exynos_drm_fbdev_init(dev); |
| 98 | if (ret) { |
| 99 | DRM_ERROR("failed to initialize drm fbdev\n"); |
| 100 | goto err_drm_device; |
| 101 | } |
| 102 | |
| 103 | return 0; |
| 104 | |
| 105 | err_drm_device: |
| 106 | exynos_drm_device_unregister(dev); |
| 107 | err_vblank: |
| 108 | drm_vblank_cleanup(dev); |
| 109 | err_crtc: |
| 110 | drm_mode_config_cleanup(dev); |
| 111 | kfree(private); |
| 112 | |
| 113 | return ret; |
| 114 | } |
| 115 | |
| 116 | static int exynos_drm_unload(struct drm_device *dev) |
| 117 | { |
| 118 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
| 119 | |
| 120 | exynos_drm_fbdev_fini(dev); |
| 121 | exynos_drm_device_unregister(dev); |
| 122 | drm_vblank_cleanup(dev); |
Seung-Woo Kim | 7db3eba | 2011-10-18 16:58:05 +0900 | [diff] [blame] | 123 | drm_kms_helper_poll_fini(dev); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 124 | drm_mode_config_cleanup(dev); |
| 125 | kfree(dev->dev_private); |
| 126 | |
| 127 | dev->dev_private = NULL; |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
Inki Dae | ccf4d88 | 2011-10-14 13:29:51 +0900 | [diff] [blame] | 132 | static void exynos_drm_preclose(struct drm_device *dev, |
| 133 | struct drm_file *file_priv) |
| 134 | { |
| 135 | struct exynos_drm_private *dev_priv = dev->dev_private; |
| 136 | |
| 137 | /* |
| 138 | * drm framework frees all events at release time, |
| 139 | * so private event list should be cleared. |
| 140 | */ |
| 141 | if (!list_empty(&dev_priv->pageflip_event_list)) |
| 142 | INIT_LIST_HEAD(&dev_priv->pageflip_event_list); |
| 143 | } |
| 144 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 145 | static void exynos_drm_lastclose(struct drm_device *dev) |
| 146 | { |
| 147 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
| 148 | |
| 149 | exynos_drm_fbdev_restore_mode(dev); |
| 150 | } |
| 151 | |
| 152 | static struct vm_operations_struct exynos_drm_gem_vm_ops = { |
| 153 | .fault = exynos_drm_gem_fault, |
| 154 | .open = drm_gem_vm_open, |
| 155 | .close = drm_gem_vm_close, |
| 156 | }; |
| 157 | |
| 158 | static struct drm_ioctl_desc exynos_ioctls[] = { |
| 159 | DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl, |
| 160 | DRM_UNLOCKED | DRM_AUTH), |
| 161 | DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET, |
| 162 | exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED | |
| 163 | DRM_AUTH), |
| 164 | DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP, |
| 165 | exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH), |
| 166 | }; |
| 167 | |
| 168 | static struct drm_driver exynos_drm_driver = { |
| 169 | .driver_features = DRIVER_HAVE_IRQ | DRIVER_BUS_PLATFORM | |
| 170 | DRIVER_MODESET | DRIVER_GEM, |
| 171 | .load = exynos_drm_load, |
| 172 | .unload = exynos_drm_unload, |
Inki Dae | ccf4d88 | 2011-10-14 13:29:51 +0900 | [diff] [blame] | 173 | .preclose = exynos_drm_preclose, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 174 | .lastclose = exynos_drm_lastclose, |
| 175 | .get_vblank_counter = drm_vblank_count, |
| 176 | .enable_vblank = exynos_drm_crtc_enable_vblank, |
| 177 | .disable_vblank = exynos_drm_crtc_disable_vblank, |
| 178 | .gem_init_object = exynos_drm_gem_init_object, |
| 179 | .gem_free_object = exynos_drm_gem_free_object, |
| 180 | .gem_vm_ops = &exynos_drm_gem_vm_ops, |
| 181 | .dumb_create = exynos_drm_gem_dumb_create, |
| 182 | .dumb_map_offset = exynos_drm_gem_dumb_map_offset, |
| 183 | .dumb_destroy = exynos_drm_gem_dumb_destroy, |
| 184 | .ioctls = exynos_ioctls, |
| 185 | .fops = { |
| 186 | .owner = THIS_MODULE, |
| 187 | .open = drm_open, |
| 188 | .mmap = exynos_drm_gem_mmap, |
| 189 | .poll = drm_poll, |
| 190 | .read = drm_read, |
| 191 | .unlocked_ioctl = drm_ioctl, |
| 192 | .release = drm_release, |
| 193 | }, |
| 194 | .name = DRIVER_NAME, |
| 195 | .desc = DRIVER_DESC, |
| 196 | .date = DRIVER_DATE, |
| 197 | .major = DRIVER_MAJOR, |
| 198 | .minor = DRIVER_MINOR, |
| 199 | }; |
| 200 | |
| 201 | static int exynos_drm_platform_probe(struct platform_device *pdev) |
| 202 | { |
| 203 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
| 204 | |
| 205 | exynos_drm_driver.num_ioctls = DRM_ARRAY_SIZE(exynos_ioctls); |
| 206 | |
| 207 | return drm_platform_init(&exynos_drm_driver, pdev); |
| 208 | } |
| 209 | |
| 210 | static int exynos_drm_platform_remove(struct platform_device *pdev) |
| 211 | { |
| 212 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
| 213 | |
| 214 | drm_platform_exit(&exynos_drm_driver, pdev); |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | static struct platform_driver exynos_drm_platform_driver = { |
| 220 | .probe = exynos_drm_platform_probe, |
| 221 | .remove = __devexit_p(exynos_drm_platform_remove), |
| 222 | .driver = { |
| 223 | .owner = THIS_MODULE, |
| 224 | .name = DRIVER_NAME, |
| 225 | }, |
| 226 | }; |
| 227 | |
| 228 | static int __init exynos_drm_init(void) |
| 229 | { |
| 230 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
| 231 | |
| 232 | return platform_driver_register(&exynos_drm_platform_driver); |
| 233 | } |
| 234 | |
| 235 | static void __exit exynos_drm_exit(void) |
| 236 | { |
| 237 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
| 238 | |
| 239 | platform_driver_unregister(&exynos_drm_platform_driver); |
| 240 | } |
| 241 | |
| 242 | module_init(exynos_drm_init); |
| 243 | module_exit(exynos_drm_exit); |
| 244 | |
| 245 | MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>"); |
| 246 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
| 247 | MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>"); |
| 248 | MODULE_DESCRIPTION("Samsung SoC DRM Driver"); |
| 249 | MODULE_LICENSE("GPL"); |