[S390] Remove error checking from copy_oldmem_page()
[linux/fpc-iii.git] / drivers / gpu / drm / exynos / exynos_drm_core.c
blob661a03571d0c6ba672ea28b8fae172c2a7681a57
1 /* exynos_drm_core.c
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>
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:
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.
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.
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"
35 static DEFINE_MUTEX(exynos_drm_mutex);
36 static LIST_HEAD(exynos_drm_subdrv_list);
37 static struct drm_device *drm_dev;
39 static int exynos_drm_subdrv_probe(struct drm_device *dev,
40 struct exynos_drm_subdrv *subdrv)
42 struct drm_encoder *encoder;
43 struct drm_connector *connector;
45 DRM_DEBUG_DRIVER("%s\n", __FILE__);
47 if (subdrv->probe) {
48 int ret;
51 * this probe callback would be called by sub driver
52 * after setting of all resources to this sub driver,
53 * such as clock, irq and register map are done or by load()
54 * of exynos drm driver.
56 * P.S. note that this driver is considered for modularization.
58 ret = subdrv->probe(dev, subdrv->manager.dev);
59 if (ret)
60 return ret;
63 /* create and initialize a encoder for this sub driver. */
64 encoder = exynos_drm_encoder_create(dev, &subdrv->manager,
65 (1 << MAX_CRTC) - 1);
66 if (!encoder) {
67 DRM_ERROR("failed to create encoder\n");
68 return -EFAULT;
72 * create and initialize a connector for this sub driver and
73 * attach the encoder created above to the connector.
75 connector = exynos_drm_connector_create(dev, encoder);
76 if (!connector) {
77 DRM_ERROR("failed to create connector\n");
78 encoder->funcs->destroy(encoder);
79 return -EFAULT;
82 subdrv->encoder = encoder;
83 subdrv->connector = connector;
85 return 0;
88 static void exynos_drm_subdrv_remove(struct drm_device *dev,
89 struct exynos_drm_subdrv *subdrv)
91 DRM_DEBUG_DRIVER("%s\n", __FILE__);
93 if (subdrv->remove)
94 subdrv->remove(dev);
96 if (subdrv->encoder) {
97 struct drm_encoder *encoder = subdrv->encoder;
98 encoder->funcs->destroy(encoder);
99 subdrv->encoder = NULL;
102 if (subdrv->connector) {
103 struct drm_connector *connector = subdrv->connector;
104 connector->funcs->destroy(connector);
105 subdrv->connector = NULL;
109 int exynos_drm_device_register(struct drm_device *dev)
111 struct exynos_drm_subdrv *subdrv, *n;
112 int err;
114 DRM_DEBUG_DRIVER("%s\n", __FILE__);
116 if (!dev)
117 return -EINVAL;
119 if (drm_dev) {
120 DRM_ERROR("Already drm device were registered\n");
121 return -EBUSY;
124 mutex_lock(&exynos_drm_mutex);
125 list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) {
126 err = exynos_drm_subdrv_probe(dev, subdrv);
127 if (err) {
128 DRM_DEBUG("exynos drm subdrv probe failed.\n");
129 list_del(&subdrv->list);
133 drm_dev = dev;
134 mutex_unlock(&exynos_drm_mutex);
136 return 0;
138 EXPORT_SYMBOL_GPL(exynos_drm_device_register);
140 int exynos_drm_device_unregister(struct drm_device *dev)
142 struct exynos_drm_subdrv *subdrv;
144 DRM_DEBUG_DRIVER("%s\n", __FILE__);
146 if (!dev || dev != drm_dev) {
147 WARN(1, "Unexpected drm device unregister!\n");
148 return -EINVAL;
151 mutex_lock(&exynos_drm_mutex);
152 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list)
153 exynos_drm_subdrv_remove(dev, subdrv);
155 drm_dev = NULL;
156 mutex_unlock(&exynos_drm_mutex);
158 return 0;
160 EXPORT_SYMBOL_GPL(exynos_drm_device_unregister);
162 static int exynos_drm_mode_group_reinit(struct drm_device *dev)
164 struct drm_mode_group *group = &dev->primary->mode_group;
165 uint32_t *id_list = group->id_list;
166 int ret;
168 DRM_DEBUG_DRIVER("%s\n", __FILE__);
170 ret = drm_mode_group_init_legacy_group(dev, group);
171 if (ret < 0)
172 return ret;
174 kfree(id_list);
175 return 0;
178 int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
180 int err;
182 DRM_DEBUG_DRIVER("%s\n", __FILE__);
184 if (!subdrv)
185 return -EINVAL;
187 mutex_lock(&exynos_drm_mutex);
188 if (drm_dev) {
189 err = exynos_drm_subdrv_probe(drm_dev, subdrv);
190 if (err) {
191 DRM_ERROR("failed to probe exynos drm subdrv\n");
192 mutex_unlock(&exynos_drm_mutex);
193 return err;
197 * if any specific driver such as fimd or hdmi driver called
198 * exynos_drm_subdrv_register() later than drm_load(),
199 * the fb helper should be re-initialized and re-configured.
201 err = exynos_drm_fbdev_reinit(drm_dev);
202 if (err) {
203 DRM_ERROR("failed to reinitialize exynos drm fbdev\n");
204 exynos_drm_subdrv_remove(drm_dev, subdrv);
205 mutex_unlock(&exynos_drm_mutex);
206 return err;
209 err = exynos_drm_mode_group_reinit(drm_dev);
210 if (err) {
211 DRM_ERROR("failed to reinitialize mode group\n");
212 exynos_drm_fbdev_fini(drm_dev);
213 exynos_drm_subdrv_remove(drm_dev, subdrv);
214 mutex_unlock(&exynos_drm_mutex);
215 return err;
219 subdrv->drm_dev = drm_dev;
221 list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
222 mutex_unlock(&exynos_drm_mutex);
224 return 0;
226 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register);
228 int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
230 int ret = -EFAULT;
232 DRM_DEBUG_DRIVER("%s\n", __FILE__);
234 if (!subdrv) {
235 DRM_DEBUG("Unexpected exynos drm subdrv unregister!\n");
236 return ret;
239 mutex_lock(&exynos_drm_mutex);
240 if (drm_dev) {
241 exynos_drm_subdrv_remove(drm_dev, subdrv);
242 list_del(&subdrv->list);
245 * fb helper should be updated once a sub driver is released
246 * to re-configure crtc and connector and also to re-setup
247 * drm framebuffer.
249 ret = exynos_drm_fbdev_reinit(drm_dev);
250 if (ret < 0) {
251 DRM_ERROR("failed fb helper reinit.\n");
252 goto fail;
255 ret = exynos_drm_mode_group_reinit(drm_dev);
256 if (ret < 0) {
257 DRM_ERROR("failed drm mode group reinit.\n");
258 goto fail;
262 fail:
263 mutex_unlock(&exynos_drm_mutex);
264 return ret;
266 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister);
268 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
269 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
270 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
271 MODULE_DESCRIPTION("Samsung SoC DRM Core Driver");
272 MODULE_LICENSE("GPL");