]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/exynos/exynos_drm_core.c
powerpc/dma: dma_set_coherent_mask() should not be GPL only
[karo-tx-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 #include "exynos_drm_fbdev.h"
19
20 static LIST_HEAD(exynos_drm_subdrv_list);
21
22 int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
23 {
24         if (!subdrv)
25                 return -EINVAL;
26
27         list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
28
29         return 0;
30 }
31 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register);
32
33 int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
34 {
35         if (!subdrv)
36                 return -EINVAL;
37
38         list_del(&subdrv->list);
39
40         return 0;
41 }
42 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister);
43
44 int exynos_drm_device_subdrv_probe(struct drm_device *dev)
45 {
46         struct exynos_drm_subdrv *subdrv, *n;
47         int err;
48
49         if (!dev)
50                 return -EINVAL;
51
52         list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) {
53                 if (subdrv->probe) {
54                         subdrv->drm_dev = dev;
55
56                         /*
57                          * this probe callback would be called by sub driver
58                          * after setting of all resources to this sub driver,
59                          * such as clock, irq and register map are done.
60                          */
61                         err = subdrv->probe(dev, subdrv->dev);
62                         if (err) {
63                                 DRM_DEBUG("exynos drm subdrv probe failed.\n");
64                                 list_del(&subdrv->list);
65                                 continue;
66                         }
67                 }
68         }
69
70         return 0;
71 }
72 EXPORT_SYMBOL_GPL(exynos_drm_device_subdrv_probe);
73
74 int exynos_drm_device_subdrv_remove(struct drm_device *dev)
75 {
76         struct exynos_drm_subdrv *subdrv;
77
78         if (!dev) {
79                 WARN(1, "Unexpected drm device unregister!\n");
80                 return -EINVAL;
81         }
82
83         list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
84                 if (subdrv->remove)
85                         subdrv->remove(dev, subdrv->dev);
86         }
87
88         return 0;
89 }
90 EXPORT_SYMBOL_GPL(exynos_drm_device_subdrv_remove);
91
92 int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file)
93 {
94         struct exynos_drm_subdrv *subdrv;
95         int ret;
96
97         list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
98                 if (subdrv->open) {
99                         ret = subdrv->open(dev, subdrv->dev, file);
100                         if (ret)
101                                 goto err;
102                 }
103         }
104
105         return 0;
106
107 err:
108         list_for_each_entry_reverse(subdrv, &subdrv->list, list) {
109                 if (subdrv->close)
110                         subdrv->close(dev, subdrv->dev, file);
111         }
112         return ret;
113 }
114 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_open);
115
116 void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file)
117 {
118         struct exynos_drm_subdrv *subdrv;
119
120         list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
121                 if (subdrv->close)
122                         subdrv->close(dev, subdrv->dev, file);
123         }
124 }
125 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close);