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 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
16 #include "exynos_drm_drv.h"
17 #include "exynos_drm_encoder.h"
18 #include "exynos_drm_connector.h"
19 #include "exynos_drm_fbdev.h"
21 static LIST_HEAD(exynos_drm_subdrv_list
);
23 static int exynos_drm_create_enc_conn(struct drm_device
*dev
,
24 struct exynos_drm_subdrv
*subdrv
)
26 struct drm_encoder
*encoder
;
27 struct drm_connector
*connector
;
30 subdrv
->manager
->dev
= subdrv
->dev
;
32 /* create and initialize a encoder for this sub driver. */
33 encoder
= exynos_drm_encoder_create(dev
, subdrv
->manager
,
36 DRM_ERROR("failed to create encoder\n");
41 * create and initialize a connector for this sub driver and
42 * attach the encoder created above to the connector.
44 connector
= exynos_drm_connector_create(dev
, encoder
);
46 DRM_ERROR("failed to create connector\n");
48 goto err_destroy_encoder
;
51 subdrv
->encoder
= encoder
;
52 subdrv
->connector
= connector
;
57 encoder
->funcs
->destroy(encoder
);
61 static void exynos_drm_destroy_enc_conn(struct exynos_drm_subdrv
*subdrv
)
63 if (subdrv
->encoder
) {
64 struct drm_encoder
*encoder
= subdrv
->encoder
;
65 encoder
->funcs
->destroy(encoder
);
66 subdrv
->encoder
= NULL
;
69 if (subdrv
->connector
) {
70 struct drm_connector
*connector
= subdrv
->connector
;
71 connector
->funcs
->destroy(connector
);
72 subdrv
->connector
= NULL
;
76 static int exynos_drm_subdrv_probe(struct drm_device
*dev
,
77 struct exynos_drm_subdrv
*subdrv
)
82 subdrv
->drm_dev
= dev
;
85 * this probe callback would be called by sub driver
86 * after setting of all resources to this sub driver,
87 * such as clock, irq and register map are done or by load()
88 * of exynos drm driver.
90 * P.S. note that this driver is considered for modularization.
92 ret
= subdrv
->probe(dev
, subdrv
->dev
);
100 static void exynos_drm_subdrv_remove(struct drm_device
*dev
,
101 struct exynos_drm_subdrv
*subdrv
)
104 subdrv
->remove(dev
, subdrv
->dev
);
107 int exynos_drm_device_register(struct drm_device
*dev
)
109 struct exynos_drm_subdrv
*subdrv
, *n
;
110 unsigned int fine_cnt
= 0;
116 list_for_each_entry_safe(subdrv
, n
, &exynos_drm_subdrv_list
, list
) {
117 err
= exynos_drm_subdrv_probe(dev
, subdrv
);
119 DRM_DEBUG("exynos drm subdrv probe failed.\n");
120 list_del(&subdrv
->list
);
125 * if manager is null then it means that this sub driver
126 * doesn't need encoder and connector.
128 if (!subdrv
->manager
) {
133 err
= exynos_drm_create_enc_conn(dev
, subdrv
);
135 DRM_DEBUG("failed to create encoder and connector.\n");
136 exynos_drm_subdrv_remove(dev
, subdrv
);
137 list_del(&subdrv
->list
);
149 EXPORT_SYMBOL_GPL(exynos_drm_device_register
);
151 int exynos_drm_device_unregister(struct drm_device
*dev
)
153 struct exynos_drm_subdrv
*subdrv
;
156 WARN(1, "Unexpected drm device unregister!\n");
160 list_for_each_entry(subdrv
, &exynos_drm_subdrv_list
, list
) {
161 exynos_drm_subdrv_remove(dev
, subdrv
);
162 exynos_drm_destroy_enc_conn(subdrv
);
167 EXPORT_SYMBOL_GPL(exynos_drm_device_unregister
);
169 int exynos_drm_subdrv_register(struct exynos_drm_subdrv
*subdrv
)
174 list_add_tail(&subdrv
->list
, &exynos_drm_subdrv_list
);
178 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register
);
180 int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv
*subdrv
)
185 list_del(&subdrv
->list
);
189 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister
);
191 int exynos_drm_subdrv_open(struct drm_device
*dev
, struct drm_file
*file
)
193 struct exynos_drm_subdrv
*subdrv
;
196 list_for_each_entry(subdrv
, &exynos_drm_subdrv_list
, list
) {
198 ret
= subdrv
->open(dev
, subdrv
->dev
, file
);
207 list_for_each_entry_reverse(subdrv
, &subdrv
->list
, list
) {
209 subdrv
->close(dev
, subdrv
->dev
, file
);
213 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_open
);
215 void exynos_drm_subdrv_close(struct drm_device
*dev
, struct drm_file
*file
)
217 struct exynos_drm_subdrv
*subdrv
;
219 list_for_each_entry(subdrv
, &exynos_drm_subdrv_list
, list
) {
221 subdrv
->close(dev
, subdrv
->dev
, file
);
224 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close
);