Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1 | /* exynos_drm_core.c |
| 2 | * |
| 3 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. |
| 4 | * Author: |
| 5 | * Inki Dae <inki.dae@samsung.com> |
| 6 | * Joonyoung Shim <jy0922.shim@samsung.com> |
| 7 | * Seung-Woo Kim <sw0312.kim@samsung.com> |
| 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice (including the next |
| 17 | * paragraph) shall be included in all copies or substantial portions of the |
| 18 | * Software. |
| 19 | * |
| 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 23 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 24 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 25 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 26 | * OTHER DEALINGS IN THE SOFTWARE. |
| 27 | */ |
| 28 | |
| 29 | #include "drmP.h" |
| 30 | #include "exynos_drm_drv.h" |
| 31 | #include "exynos_drm_encoder.h" |
| 32 | #include "exynos_drm_connector.h" |
| 33 | #include "exynos_drm_fbdev.h" |
| 34 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 35 | static LIST_HEAD(exynos_drm_subdrv_list); |
| 36 | static struct drm_device *drm_dev; |
| 37 | |
| 38 | static int exynos_drm_subdrv_probe(struct drm_device *dev, |
| 39 | struct exynos_drm_subdrv *subdrv) |
| 40 | { |
| 41 | struct drm_encoder *encoder; |
| 42 | struct drm_connector *connector; |
| 43 | |
| 44 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
| 45 | |
| 46 | if (subdrv->probe) { |
| 47 | int ret; |
| 48 | |
| 49 | /* |
| 50 | * this probe callback would be called by sub driver |
| 51 | * after setting of all resources to this sub driver, |
| 52 | * such as clock, irq and register map are done or by load() |
| 53 | * of exynos drm driver. |
| 54 | * |
| 55 | * P.S. note that this driver is considered for modularization. |
| 56 | */ |
Inki Dae | 41c2434 | 2011-10-14 13:29:48 +0900 | [diff] [blame] | 57 | ret = subdrv->probe(dev, subdrv->manager.dev); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 58 | if (ret) |
| 59 | return ret; |
| 60 | } |
| 61 | |
Joonyoung Shim | a31f6ec | 2012-03-16 18:47:10 +0900 | [diff] [blame] | 62 | if (subdrv->is_local) |
| 63 | return 0; |
| 64 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 65 | /* create and initialize a encoder for this sub driver. */ |
| 66 | encoder = exynos_drm_encoder_create(dev, &subdrv->manager, |
| 67 | (1 << MAX_CRTC) - 1); |
| 68 | if (!encoder) { |
| 69 | DRM_ERROR("failed to create encoder\n"); |
| 70 | return -EFAULT; |
| 71 | } |
| 72 | |
| 73 | /* |
| 74 | * create and initialize a connector for this sub driver and |
| 75 | * attach the encoder created above to the connector. |
| 76 | */ |
| 77 | connector = exynos_drm_connector_create(dev, encoder); |
| 78 | if (!connector) { |
| 79 | DRM_ERROR("failed to create connector\n"); |
| 80 | encoder->funcs->destroy(encoder); |
| 81 | return -EFAULT; |
| 82 | } |
| 83 | |
| 84 | subdrv->encoder = encoder; |
| 85 | subdrv->connector = connector; |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | static void exynos_drm_subdrv_remove(struct drm_device *dev, |
| 91 | struct exynos_drm_subdrv *subdrv) |
| 92 | { |
| 93 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
| 94 | |
| 95 | if (subdrv->remove) |
| 96 | subdrv->remove(dev); |
| 97 | |
| 98 | if (subdrv->encoder) { |
| 99 | struct drm_encoder *encoder = subdrv->encoder; |
| 100 | encoder->funcs->destroy(encoder); |
| 101 | subdrv->encoder = NULL; |
| 102 | } |
| 103 | |
| 104 | if (subdrv->connector) { |
| 105 | struct drm_connector *connector = subdrv->connector; |
| 106 | connector->funcs->destroy(connector); |
| 107 | subdrv->connector = NULL; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | int exynos_drm_device_register(struct drm_device *dev) |
| 112 | { |
| 113 | struct exynos_drm_subdrv *subdrv, *n; |
| 114 | int err; |
| 115 | |
| 116 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
| 117 | |
| 118 | if (!dev) |
| 119 | return -EINVAL; |
| 120 | |
Joonyoung Shim | 132a5b9 | 2012-03-16 18:47:08 +0900 | [diff] [blame] | 121 | drm_dev = dev; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 122 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 123 | list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) { |
Joonyoung Shim | 132a5b9 | 2012-03-16 18:47:08 +0900 | [diff] [blame] | 124 | subdrv->drm_dev = dev; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 125 | err = exynos_drm_subdrv_probe(dev, subdrv); |
| 126 | if (err) { |
| 127 | DRM_DEBUG("exynos drm subdrv probe failed.\n"); |
| 128 | list_del(&subdrv->list); |
| 129 | } |
| 130 | } |
| 131 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 132 | return 0; |
| 133 | } |
| 134 | EXPORT_SYMBOL_GPL(exynos_drm_device_register); |
| 135 | |
| 136 | int exynos_drm_device_unregister(struct drm_device *dev) |
| 137 | { |
| 138 | struct exynos_drm_subdrv *subdrv; |
| 139 | |
| 140 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
| 141 | |
Joonyoung Shim | 132a5b9 | 2012-03-16 18:47:08 +0900 | [diff] [blame] | 142 | if (!dev) { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 143 | WARN(1, "Unexpected drm device unregister!\n"); |
| 144 | return -EINVAL; |
| 145 | } |
| 146 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 147 | list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) |
| 148 | exynos_drm_subdrv_remove(dev, subdrv); |
| 149 | |
| 150 | drm_dev = NULL; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 151 | |
| 152 | return 0; |
| 153 | } |
| 154 | EXPORT_SYMBOL_GPL(exynos_drm_device_unregister); |
| 155 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 156 | int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv) |
| 157 | { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 158 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
| 159 | |
| 160 | if (!subdrv) |
| 161 | return -EINVAL; |
| 162 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 163 | list_add_tail(&subdrv->list, &exynos_drm_subdrv_list); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register); |
| 168 | |
| 169 | int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv) |
| 170 | { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 171 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
| 172 | |
Joonyoung Shim | 132a5b9 | 2012-03-16 18:47:08 +0900 | [diff] [blame] | 173 | if (!subdrv) |
| 174 | return -EINVAL; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 175 | |
Joonyoung Shim | 132a5b9 | 2012-03-16 18:47:08 +0900 | [diff] [blame] | 176 | list_del(&subdrv->list); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 177 | |
Joonyoung Shim | 132a5b9 | 2012-03-16 18:47:08 +0900 | [diff] [blame] | 178 | return 0; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 179 | } |
| 180 | EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister); |
Joonyoung Shim | 9084f7b | 2012-03-16 18:47:09 +0900 | [diff] [blame] | 181 | |
| 182 | int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file) |
| 183 | { |
| 184 | struct exynos_drm_subdrv *subdrv; |
| 185 | int ret; |
| 186 | |
| 187 | list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) { |
| 188 | if (subdrv->open) { |
| 189 | ret = subdrv->open(dev, subdrv->manager.dev, file); |
| 190 | if (ret) |
| 191 | goto err; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | return 0; |
| 196 | |
| 197 | err: |
| 198 | list_for_each_entry_reverse(subdrv, &subdrv->list, list) { |
| 199 | if (subdrv->close) |
| 200 | subdrv->close(dev, subdrv->manager.dev, file); |
| 201 | } |
| 202 | return ret; |
| 203 | } |
| 204 | EXPORT_SYMBOL_GPL(exynos_drm_subdrv_open); |
| 205 | |
| 206 | void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file) |
| 207 | { |
| 208 | struct exynos_drm_subdrv *subdrv; |
| 209 | |
| 210 | list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) { |
| 211 | if (subdrv->close) |
| 212 | subdrv->close(dev, subdrv->manager.dev, file); |
| 213 | } |
| 214 | } |
| 215 | EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close); |