x86: hpet: Fix copy-and-paste mistake in earlier change
[linux/fpc-iii.git] / drivers / gpu / drm / exynos / exynos_drm_core.c
blobeaf630dc5dba951e78f8a68c2d0bcc1b25ae40b3
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 LIST_HEAD(exynos_drm_subdrv_list);
36 static struct drm_device *drm_dev;
38 static int exynos_drm_subdrv_probe(struct drm_device *dev,
39 struct exynos_drm_subdrv *subdrv)
41 struct drm_encoder *encoder;
42 struct drm_connector *connector;
44 DRM_DEBUG_DRIVER("%s\n", __FILE__);
46 if (subdrv->probe) {
47 int ret;
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.
55 * P.S. note that this driver is considered for modularization.
57 ret = subdrv->probe(dev, subdrv->dev);
58 if (ret)
59 return ret;
62 if (!subdrv->manager)
63 return 0;
65 subdrv->manager->dev = subdrv->dev;
67 /* create and initialize a encoder for this sub driver. */
68 encoder = exynos_drm_encoder_create(dev, subdrv->manager,
69 (1 << MAX_CRTC) - 1);
70 if (!encoder) {
71 DRM_ERROR("failed to create encoder\n");
72 return -EFAULT;
76 * create and initialize a connector for this sub driver and
77 * attach the encoder created above to the connector.
79 connector = exynos_drm_connector_create(dev, encoder);
80 if (!connector) {
81 DRM_ERROR("failed to create connector\n");
82 encoder->funcs->destroy(encoder);
83 return -EFAULT;
86 subdrv->encoder = encoder;
87 subdrv->connector = connector;
89 return 0;
92 static void exynos_drm_subdrv_remove(struct drm_device *dev,
93 struct exynos_drm_subdrv *subdrv)
95 DRM_DEBUG_DRIVER("%s\n", __FILE__);
97 if (subdrv->remove)
98 subdrv->remove(dev);
100 if (subdrv->encoder) {
101 struct drm_encoder *encoder = subdrv->encoder;
102 encoder->funcs->destroy(encoder);
103 subdrv->encoder = NULL;
106 if (subdrv->connector) {
107 struct drm_connector *connector = subdrv->connector;
108 connector->funcs->destroy(connector);
109 subdrv->connector = NULL;
113 int exynos_drm_device_register(struct drm_device *dev)
115 struct exynos_drm_subdrv *subdrv, *n;
116 int err;
118 DRM_DEBUG_DRIVER("%s\n", __FILE__);
120 if (!dev)
121 return -EINVAL;
123 drm_dev = dev;
125 list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) {
126 subdrv->drm_dev = dev;
127 err = exynos_drm_subdrv_probe(dev, subdrv);
128 if (err) {
129 DRM_DEBUG("exynos drm subdrv probe failed.\n");
130 list_del(&subdrv->list);
134 return 0;
136 EXPORT_SYMBOL_GPL(exynos_drm_device_register);
138 int exynos_drm_device_unregister(struct drm_device *dev)
140 struct exynos_drm_subdrv *subdrv;
142 DRM_DEBUG_DRIVER("%s\n", __FILE__);
144 if (!dev) {
145 WARN(1, "Unexpected drm device unregister!\n");
146 return -EINVAL;
149 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list)
150 exynos_drm_subdrv_remove(dev, subdrv);
152 drm_dev = NULL;
154 return 0;
156 EXPORT_SYMBOL_GPL(exynos_drm_device_unregister);
158 int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
160 DRM_DEBUG_DRIVER("%s\n", __FILE__);
162 if (!subdrv)
163 return -EINVAL;
165 list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
167 return 0;
169 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register);
171 int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
173 DRM_DEBUG_DRIVER("%s\n", __FILE__);
175 if (!subdrv)
176 return -EINVAL;
178 list_del(&subdrv->list);
180 return 0;
182 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister);
184 int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file)
186 struct exynos_drm_subdrv *subdrv;
187 int ret;
189 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
190 if (subdrv->open) {
191 ret = subdrv->open(dev, subdrv->dev, file);
192 if (ret)
193 goto err;
197 return 0;
199 err:
200 list_for_each_entry_reverse(subdrv, &subdrv->list, list) {
201 if (subdrv->close)
202 subdrv->close(dev, subdrv->dev, file);
204 return ret;
206 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_open);
208 void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file)
210 struct exynos_drm_subdrv *subdrv;
212 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
213 if (subdrv->close)
214 subdrv->close(dev, subdrv->dev, file);
217 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close);