Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[deliverable/linux.git] / drivers / gpu / drm / exynos / exynos_drm_core.c
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 * 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.
13 */
14
15 #include <drm/drmP.h>
16 #include "exynos_drm_drv.h"
17 #include "exynos_drm_crtc.h"
18
19 static LIST_HEAD(exynos_drm_subdrv_list);
20
21 int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
22 {
23 if (!subdrv)
24 return -EINVAL;
25
26 list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
27
28 return 0;
29 }
30
31 int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
32 {
33 if (!subdrv)
34 return -EINVAL;
35
36 list_del(&subdrv->list);
37
38 return 0;
39 }
40
41 int exynos_drm_device_subdrv_probe(struct drm_device *dev)
42 {
43 struct exynos_drm_subdrv *subdrv, *n;
44 int err;
45
46 if (!dev)
47 return -EINVAL;
48
49 list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) {
50 if (subdrv->probe) {
51 subdrv->drm_dev = dev;
52
53 /*
54 * this probe callback would be called by sub driver
55 * after setting of all resources to this sub driver,
56 * such as clock, irq and register map are done.
57 */
58 err = subdrv->probe(dev, subdrv->dev);
59 if (err) {
60 DRM_DEBUG("exynos drm subdrv probe failed.\n");
61 list_del(&subdrv->list);
62 continue;
63 }
64 }
65 }
66
67 return 0;
68 }
69
70 int exynos_drm_device_subdrv_remove(struct drm_device *dev)
71 {
72 struct exynos_drm_subdrv *subdrv;
73
74 if (!dev) {
75 WARN(1, "Unexpected drm device unregister!\n");
76 return -EINVAL;
77 }
78
79 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
80 if (subdrv->remove)
81 subdrv->remove(dev, subdrv->dev);
82 }
83
84 return 0;
85 }
86
87 int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file)
88 {
89 struct exynos_drm_subdrv *subdrv;
90 int ret;
91
92 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
93 if (subdrv->open) {
94 ret = subdrv->open(dev, subdrv->dev, file);
95 if (ret)
96 goto err;
97 }
98 }
99
100 return 0;
101
102 err:
103 list_for_each_entry_continue_reverse(subdrv, &exynos_drm_subdrv_list, list) {
104 if (subdrv->close)
105 subdrv->close(dev, subdrv->dev, file);
106 }
107 return ret;
108 }
109
110 void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file)
111 {
112 struct exynos_drm_subdrv *subdrv;
113
114 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
115 if (subdrv->close)
116 subdrv->close(dev, subdrv->dev, file);
117 }
118 }
This page took 0.034099 seconds and 5 git commands to generate.