blob: 84dd099eae3b93cfa49e733d42353e1a0d0e12e4 [file] [log] [blame]
Inki Dae1c248b72011-10-04 19:19:01 +09001/* 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 Dae1c248b72011-10-04 19:19:01 +090035static LIST_HEAD(exynos_drm_subdrv_list);
Inki Dae1c248b72011-10-04 19:19:01 +090036
37static int exynos_drm_subdrv_probe(struct drm_device *dev,
38 struct exynos_drm_subdrv *subdrv)
39{
40 struct drm_encoder *encoder;
41 struct drm_connector *connector;
42
43 DRM_DEBUG_DRIVER("%s\n", __FILE__);
44
45 if (subdrv->probe) {
46 int ret;
47
48 /*
49 * this probe callback would be called by sub driver
50 * after setting of all resources to this sub driver,
51 * such as clock, irq and register map are done or by load()
52 * of exynos drm driver.
53 *
54 * P.S. note that this driver is considered for modularization.
55 */
Joonyoung Shim677e84c2012-04-05 20:49:27 +090056 ret = subdrv->probe(dev, subdrv->dev);
Inki Dae1c248b72011-10-04 19:19:01 +090057 if (ret)
58 return ret;
59 }
60
Joonyoung Shim677e84c2012-04-05 20:49:27 +090061 if (!subdrv->manager)
Joonyoung Shima31f6ec2012-03-16 18:47:10 +090062 return 0;
63
Joonyoung Shim677e84c2012-04-05 20:49:27 +090064 subdrv->manager->dev = subdrv->dev;
65
Inki Dae1c248b72011-10-04 19:19:01 +090066 /* create and initialize a encoder for this sub driver. */
Joonyoung Shim677e84c2012-04-05 20:49:27 +090067 encoder = exynos_drm_encoder_create(dev, subdrv->manager,
Inki Dae1c248b72011-10-04 19:19:01 +090068 (1 << MAX_CRTC) - 1);
69 if (!encoder) {
70 DRM_ERROR("failed to create encoder\n");
71 return -EFAULT;
72 }
73
74 /*
75 * create and initialize a connector for this sub driver and
76 * attach the encoder created above to the connector.
77 */
78 connector = exynos_drm_connector_create(dev, encoder);
79 if (!connector) {
80 DRM_ERROR("failed to create connector\n");
81 encoder->funcs->destroy(encoder);
82 return -EFAULT;
83 }
84
85 subdrv->encoder = encoder;
86 subdrv->connector = connector;
87
88 return 0;
89}
90
91static void exynos_drm_subdrv_remove(struct drm_device *dev,
92 struct exynos_drm_subdrv *subdrv)
93{
94 DRM_DEBUG_DRIVER("%s\n", __FILE__);
95
96 if (subdrv->remove)
97 subdrv->remove(dev);
98
99 if (subdrv->encoder) {
100 struct drm_encoder *encoder = subdrv->encoder;
101 encoder->funcs->destroy(encoder);
102 subdrv->encoder = NULL;
103 }
104
105 if (subdrv->connector) {
106 struct drm_connector *connector = subdrv->connector;
107 connector->funcs->destroy(connector);
108 subdrv->connector = NULL;
109 }
110}
111
112int exynos_drm_device_register(struct drm_device *dev)
113{
114 struct exynos_drm_subdrv *subdrv, *n;
115 int err;
116
117 DRM_DEBUG_DRIVER("%s\n", __FILE__);
118
119 if (!dev)
120 return -EINVAL;
121
Inki Dae1c248b72011-10-04 19:19:01 +0900122 list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) {
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900123 subdrv->drm_dev = dev;
Inki Dae1c248b72011-10-04 19:19:01 +0900124 err = exynos_drm_subdrv_probe(dev, subdrv);
125 if (err) {
126 DRM_DEBUG("exynos drm subdrv probe failed.\n");
127 list_del(&subdrv->list);
128 }
129 }
130
Inki Dae1c248b72011-10-04 19:19:01 +0900131 return 0;
132}
133EXPORT_SYMBOL_GPL(exynos_drm_device_register);
134
135int exynos_drm_device_unregister(struct drm_device *dev)
136{
137 struct exynos_drm_subdrv *subdrv;
138
139 DRM_DEBUG_DRIVER("%s\n", __FILE__);
140
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900141 if (!dev) {
Inki Dae1c248b72011-10-04 19:19:01 +0900142 WARN(1, "Unexpected drm device unregister!\n");
143 return -EINVAL;
144 }
145
Inki Dae1c248b72011-10-04 19:19:01 +0900146 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list)
147 exynos_drm_subdrv_remove(dev, subdrv);
148
Inki Dae1c248b72011-10-04 19:19:01 +0900149 return 0;
150}
151EXPORT_SYMBOL_GPL(exynos_drm_device_unregister);
152
Inki Dae1c248b72011-10-04 19:19:01 +0900153int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
154{
Inki Dae1c248b72011-10-04 19:19:01 +0900155 DRM_DEBUG_DRIVER("%s\n", __FILE__);
156
157 if (!subdrv)
158 return -EINVAL;
159
Inki Dae1c248b72011-10-04 19:19:01 +0900160 list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
Inki Dae1c248b72011-10-04 19:19:01 +0900161
162 return 0;
163}
164EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register);
165
166int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
167{
Inki Dae1c248b72011-10-04 19:19:01 +0900168 DRM_DEBUG_DRIVER("%s\n", __FILE__);
169
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900170 if (!subdrv)
171 return -EINVAL;
Inki Dae1c248b72011-10-04 19:19:01 +0900172
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900173 list_del(&subdrv->list);
Inki Dae1c248b72011-10-04 19:19:01 +0900174
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900175 return 0;
Inki Dae1c248b72011-10-04 19:19:01 +0900176}
177EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister);
Joonyoung Shim9084f7b2012-03-16 18:47:09 +0900178
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) {
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900186 ret = subdrv->open(dev, subdrv->dev, file);
Joonyoung Shim9084f7b2012-03-16 18:47:09 +0900187 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)
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900197 subdrv->close(dev, subdrv->dev, file);
Joonyoung Shim9084f7b2012-03-16 18:47:09 +0900198 }
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)
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900209 subdrv->close(dev, subdrv->dev, file);
Joonyoung Shim9084f7b2012-03-16 18:47:09 +0900210 }
211}
212EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close);