drm/exynos: add subdrv open/close functions
[deliverable/linux.git] / drivers / gpu / drm / exynos / exynos_drm_core.c
CommitLineData
1c248b7d
ID
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
1c248b7d
ID
35static LIST_HEAD(exynos_drm_subdrv_list);
36static struct drm_device *drm_dev;
37
38static 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 */
41c24346 57 ret = subdrv->probe(dev, subdrv->manager.dev);
1c248b7d
ID
58 if (ret)
59 return ret;
60 }
61
62 /* create and initialize a encoder for this sub driver. */
63 encoder = exynos_drm_encoder_create(dev, &subdrv->manager,
64 (1 << MAX_CRTC) - 1);
65 if (!encoder) {
66 DRM_ERROR("failed to create encoder\n");
67 return -EFAULT;
68 }
69
70 /*
71 * create and initialize a connector for this sub driver and
72 * attach the encoder created above to the connector.
73 */
74 connector = exynos_drm_connector_create(dev, encoder);
75 if (!connector) {
76 DRM_ERROR("failed to create connector\n");
77 encoder->funcs->destroy(encoder);
78 return -EFAULT;
79 }
80
81 subdrv->encoder = encoder;
82 subdrv->connector = connector;
83
84 return 0;
85}
86
87static void exynos_drm_subdrv_remove(struct drm_device *dev,
88 struct exynos_drm_subdrv *subdrv)
89{
90 DRM_DEBUG_DRIVER("%s\n", __FILE__);
91
92 if (subdrv->remove)
93 subdrv->remove(dev);
94
95 if (subdrv->encoder) {
96 struct drm_encoder *encoder = subdrv->encoder;
97 encoder->funcs->destroy(encoder);
98 subdrv->encoder = NULL;
99 }
100
101 if (subdrv->connector) {
102 struct drm_connector *connector = subdrv->connector;
103 connector->funcs->destroy(connector);
104 subdrv->connector = NULL;
105 }
106}
107
108int exynos_drm_device_register(struct drm_device *dev)
109{
110 struct exynos_drm_subdrv *subdrv, *n;
111 int err;
112
113 DRM_DEBUG_DRIVER("%s\n", __FILE__);
114
115 if (!dev)
116 return -EINVAL;
117
132a5b91 118 drm_dev = dev;
1c248b7d 119
1c248b7d 120 list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) {
132a5b91 121 subdrv->drm_dev = dev;
1c248b7d
ID
122 err = exynos_drm_subdrv_probe(dev, subdrv);
123 if (err) {
124 DRM_DEBUG("exynos drm subdrv probe failed.\n");
125 list_del(&subdrv->list);
126 }
127 }
128
1c248b7d
ID
129 return 0;
130}
131EXPORT_SYMBOL_GPL(exynos_drm_device_register);
132
133int exynos_drm_device_unregister(struct drm_device *dev)
134{
135 struct exynos_drm_subdrv *subdrv;
136
137 DRM_DEBUG_DRIVER("%s\n", __FILE__);
138
132a5b91 139 if (!dev) {
1c248b7d
ID
140 WARN(1, "Unexpected drm device unregister!\n");
141 return -EINVAL;
142 }
143
1c248b7d
ID
144 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list)
145 exynos_drm_subdrv_remove(dev, subdrv);
146
147 drm_dev = NULL;
1c248b7d
ID
148
149 return 0;
150}
151EXPORT_SYMBOL_GPL(exynos_drm_device_unregister);
152
1c248b7d
ID
153int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
154{
1c248b7d
ID
155 DRM_DEBUG_DRIVER("%s\n", __FILE__);
156
157 if (!subdrv)
158 return -EINVAL;
159
1c248b7d 160 list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
1c248b7d
ID
161
162 return 0;
163}
164EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register);
165
166int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
167{
1c248b7d
ID
168 DRM_DEBUG_DRIVER("%s\n", __FILE__);
169
132a5b91
JS
170 if (!subdrv)
171 return -EINVAL;
1c248b7d 172
132a5b91 173 list_del(&subdrv->list);
1c248b7d 174
132a5b91 175 return 0;
1c248b7d
ID
176}
177EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister);
9084f7b8
JS
178
179int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file)
180{
181 struct exynos_drm_subdrv *subdrv;
182 int ret;
183
184 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
185 if (subdrv->open) {
186 ret = subdrv->open(dev, subdrv->manager.dev, file);
187 if (ret)
188 goto err;
189 }
190 }
191
192 return 0;
193
194err:
195 list_for_each_entry_reverse(subdrv, &subdrv->list, list) {
196 if (subdrv->close)
197 subdrv->close(dev, subdrv->manager.dev, file);
198 }
199 return ret;
200}
201EXPORT_SYMBOL_GPL(exynos_drm_subdrv_open);
202
203void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file)
204{
205 struct exynos_drm_subdrv *subdrv;
206
207 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
208 if (subdrv->close)
209 subdrv->close(dev, subdrv->manager.dev, file);
210 }
211}
212EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close);
This page took 0.056907 seconds and 5 git commands to generate.