Linux Audio

Check our new training course

Loading...
Note: File does not exist in v3.1.
  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
 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		 */
 57		ret = subdrv->probe(dev, subdrv->dev);
 58		if (ret)
 59			return ret;
 60	}
 61
 62	if (!subdrv->manager)
 63		return 0;
 64
 65	subdrv->manager->dev = subdrv->dev;
 66
 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;
 73	}
 74
 75	/*
 76	 * create and initialize a connector for this sub driver and
 77	 * attach the encoder created above to the connector.
 78	 */
 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;
 84	}
 85
 86	subdrv->encoder = encoder;
 87	subdrv->connector = connector;
 88
 89	return 0;
 90}
 91
 92static void exynos_drm_subdrv_remove(struct drm_device *dev,
 93				      struct exynos_drm_subdrv *subdrv)
 94{
 95	DRM_DEBUG_DRIVER("%s\n", __FILE__);
 96
 97	if (subdrv->remove)
 98		subdrv->remove(dev);
 99
100	if (subdrv->encoder) {
101		struct drm_encoder *encoder = subdrv->encoder;
102		encoder->funcs->destroy(encoder);
103		subdrv->encoder = NULL;
104	}
105
106	if (subdrv->connector) {
107		struct drm_connector *connector = subdrv->connector;
108		connector->funcs->destroy(connector);
109		subdrv->connector = NULL;
110	}
111}
112
113int exynos_drm_device_register(struct drm_device *dev)
114{
115	struct exynos_drm_subdrv *subdrv, *n;
116	int err;
117
118	DRM_DEBUG_DRIVER("%s\n", __FILE__);
119
120	if (!dev)
121		return -EINVAL;
122
123	drm_dev = dev;
124
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);
131		}
132	}
133
134	return 0;
135}
136EXPORT_SYMBOL_GPL(exynos_drm_device_register);
137
138int exynos_drm_device_unregister(struct drm_device *dev)
139{
140	struct exynos_drm_subdrv *subdrv;
141
142	DRM_DEBUG_DRIVER("%s\n", __FILE__);
143
144	if (!dev) {
145		WARN(1, "Unexpected drm device unregister!\n");
146		return -EINVAL;
147	}
148
149	list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list)
150		exynos_drm_subdrv_remove(dev, subdrv);
151
152	drm_dev = NULL;
153
154	return 0;
155}
156EXPORT_SYMBOL_GPL(exynos_drm_device_unregister);
157
158int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
159{
160	DRM_DEBUG_DRIVER("%s\n", __FILE__);
161
162	if (!subdrv)
163		return -EINVAL;
164
165	list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
166
167	return 0;
168}
169EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register);
170
171int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
172{
173	DRM_DEBUG_DRIVER("%s\n", __FILE__);
174
175	if (!subdrv)
176		return -EINVAL;
177
178	list_del(&subdrv->list);
179
180	return 0;
181}
182EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister);
183
184int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file)
185{
186	struct exynos_drm_subdrv *subdrv;
187	int ret;
188
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;
194		}
195	}
196
197	return 0;
198
199err:
200	list_for_each_entry_reverse(subdrv, &subdrv->list, list) {
201		if (subdrv->close)
202			subdrv->close(dev, subdrv->dev, file);
203	}
204	return ret;
205}
206EXPORT_SYMBOL_GPL(exynos_drm_subdrv_open);
207
208void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file)
209{
210	struct exynos_drm_subdrv *subdrv;
211
212	list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
213		if (subdrv->close)
214			subdrv->close(dev, subdrv->dev, file);
215	}
216}
217EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close);