3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
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
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.
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);
37 static int exynos_drm_create_enc_conn(struct drm_device *dev,
38 struct exynos_drm_subdrv *subdrv)
40 struct drm_encoder *encoder;
41 struct drm_connector *connector;
44 DRM_DEBUG_DRIVER("%s\n", __FILE__);
46 subdrv->manager->dev = subdrv->dev;
48 /* create and initialize a encoder for this sub driver. */
49 encoder = exynos_drm_encoder_create(dev, subdrv->manager,
52 DRM_ERROR("failed to create encoder\n");
57 * create and initialize a connector for this sub driver and
58 * attach the encoder created above to the connector.
60 connector = exynos_drm_connector_create(dev, encoder);
62 DRM_ERROR("failed to create connector\n");
64 goto err_destroy_encoder;
67 subdrv->encoder = encoder;
68 subdrv->connector = connector;
73 encoder->funcs->destroy(encoder);
77 static void exynos_drm_destroy_enc_conn(struct exynos_drm_subdrv *subdrv)
79 if (subdrv->encoder) {
80 struct drm_encoder *encoder = subdrv->encoder;
81 encoder->funcs->destroy(encoder);
82 subdrv->encoder = NULL;
85 if (subdrv->connector) {
86 struct drm_connector *connector = subdrv->connector;
87 connector->funcs->destroy(connector);
88 subdrv->connector = NULL;
92 static int exynos_drm_subdrv_probe(struct drm_device *dev,
93 struct exynos_drm_subdrv *subdrv)
98 subdrv->drm_dev = dev;
101 * this probe callback would be called by sub driver
102 * after setting of all resources to this sub driver,
103 * such as clock, irq and register map are done or by load()
104 * of exynos drm driver.
106 * P.S. note that this driver is considered for modularization.
108 ret = subdrv->probe(dev, subdrv->dev);
116 static void exynos_drm_subdrv_remove(struct drm_device *dev,
117 struct exynos_drm_subdrv *subdrv)
119 DRM_DEBUG_DRIVER("%s\n", __FILE__);
122 subdrv->remove(dev, subdrv->dev);
125 int exynos_drm_device_register(struct drm_device *dev)
127 struct exynos_drm_subdrv *subdrv, *n;
128 unsigned int fine_cnt = 0;
131 DRM_DEBUG_DRIVER("%s\n", __FILE__);
136 list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) {
137 err = exynos_drm_subdrv_probe(dev, subdrv);
139 DRM_DEBUG("exynos drm subdrv probe failed.\n");
140 list_del(&subdrv->list);
145 * if manager is null then it means that this sub driver
146 * doesn't need encoder and connector.
148 if (!subdrv->manager) {
153 err = exynos_drm_create_enc_conn(dev, subdrv);
155 DRM_DEBUG("failed to create encoder and connector.\n");
156 exynos_drm_subdrv_remove(dev, subdrv);
157 list_del(&subdrv->list);
169 EXPORT_SYMBOL_GPL(exynos_drm_device_register);
171 int exynos_drm_device_unregister(struct drm_device *dev)
173 struct exynos_drm_subdrv *subdrv;
175 DRM_DEBUG_DRIVER("%s\n", __FILE__);
178 WARN(1, "Unexpected drm device unregister!\n");
182 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
183 exynos_drm_subdrv_remove(dev, subdrv);
184 exynos_drm_destroy_enc_conn(subdrv);
189 EXPORT_SYMBOL_GPL(exynos_drm_device_unregister);
191 int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
193 DRM_DEBUG_DRIVER("%s\n", __FILE__);
198 list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
202 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register);
204 int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
206 DRM_DEBUG_DRIVER("%s\n", __FILE__);
211 list_del(&subdrv->list);
215 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister);
217 int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file)
219 struct exynos_drm_subdrv *subdrv;
222 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
224 ret = subdrv->open(dev, subdrv->dev, file);
233 list_for_each_entry_reverse(subdrv, &subdrv->list, list) {
235 subdrv->close(dev, subdrv->dev, file);
239 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_open);
241 void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file)
243 struct exynos_drm_subdrv *subdrv;
245 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
247 subdrv->close(dev, subdrv->dev, file);
250 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close);