aboutsummaryrefslogtreecommitdiff
path: root/drivers/video/display/display-core.c
blob: 020a18357f9b47afcbb634c09957e84c0dce94e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
 * Display Core
 *
 * Copyright (C) 2012 Renesas Solutions Corp.
 *
 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/export.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/mutex.h>
//#include <linux/videomode.h>

#include <video/display.h>

/* -----------------------------------------------------------------------------
 * Display Entity
 */

static LIST_HEAD(display_entity_list);
static DEFINE_MUTEX(display_entity_mutex);

struct display_entity *display_entity_get_first(void)
{
	if (list_empty(&display_entity_list))
		return NULL;

	return list_first_entry(&display_entity_list, struct display_entity,
			list);
}
EXPORT_SYMBOL(display_entity_get_first);

int display_entity_set_state(struct display_entity *entity,
			     enum display_entity_state state)
{
	int ret;

	if (entity->state == state)
		return 0;

	if (!entity->ops || !entity->ops->set_state)
		return 0;

	ret = entity->ops->set_state(entity, state);
	if (ret < 0)
		return ret;

	entity->state = state;
	return 0;
}
EXPORT_SYMBOL_GPL(display_entity_set_state);

int display_entity_get_modes(struct display_entity *entity,
			     const struct videomode **modes)
{
	if (!entity->ops || !entity->ops->get_modes)
		return 0;

	return entity->ops->get_modes(entity, modes);
}
EXPORT_SYMBOL_GPL(display_entity_get_modes);

int display_entity_get_size(struct display_entity *entity,
			    unsigned int *width, unsigned int *height)
{
	if (!entity->ops || !entity->ops->get_size)
		return -EOPNOTSUPP;

	return entity->ops->get_size(entity, width, height);
}
EXPORT_SYMBOL_GPL(display_entity_get_size);

static void display_entity_release(struct kref *ref)
{
	struct display_entity *entity =
		container_of(ref, struct display_entity, ref);

	if (entity->release)
		entity->release(entity);
}

struct display_entity *display_entity_get(struct display_entity *entity)
{
	if (entity == NULL)
		return NULL;

	kref_get(&entity->ref);
	return entity;
}
EXPORT_SYMBOL_GPL(display_entity_get);

void display_entity_put(struct display_entity *entity)
{
	kref_put(&entity->ref, display_entity_release);
}
EXPORT_SYMBOL_GPL(display_entity_put);

int __must_check __display_entity_register(struct display_entity *entity,
					   struct module *owner)
{
	kref_init(&entity->ref);
	entity->owner = owner;
	entity->state = DISPLAY_ENTITY_STATE_OFF;

	mutex_lock(&display_entity_mutex);
	list_add(&entity->list, &display_entity_list);

	mutex_unlock(&display_entity_mutex);

	return 0;
}
EXPORT_SYMBOL_GPL(__display_entity_register);

void display_entity_unregister(struct display_entity *entity)
{
	mutex_lock(&display_entity_mutex);

	list_del(&entity->list);
	mutex_unlock(&display_entity_mutex);

	display_entity_put(entity);
}
EXPORT_SYMBOL_GPL(display_entity_unregister);

/* -----------------------------------------------------------------------------
 * Video Source
 */

static LIST_HEAD(video_source_list);
static DEFINE_MUTEX(video_source_mutex);

int __must_check __video_source_register(struct video_source *src,
					   struct module *owner)
{
	kref_init(&src->ref);
	src->owner = owner;

	mutex_lock(&video_source_mutex);
	list_add(&src->list, &video_source_list);

	mutex_unlock(&video_source_mutex);

	return 0;
}
EXPORT_SYMBOL_GPL(__video_source_register);

void video_source_unregister(struct video_source *src)
{
	mutex_lock(&video_source_mutex);

	list_del(&src->list);
	mutex_unlock(&video_source_mutex);

	video_source_put(src);
}
EXPORT_SYMBOL_GPL(video_source_unregister);


static void video_source_release(struct kref *ref)
{
	struct video_source *src =
		container_of(ref, struct video_source, ref);

	if (src->release)
		src->release(src);
}

struct video_source *video_source_get(struct video_source *src)
{
	if (src == NULL)
		return NULL;

	kref_get(&src->ref);
	return src;
}
EXPORT_SYMBOL_GPL(video_source_get);

void video_source_put(struct video_source *src)
{
	kref_put(&src->ref, video_source_release);
}
EXPORT_SYMBOL_GPL(video_source_put);

struct video_source *video_source_find(const char *name)
{
	struct video_source *src;

	list_for_each_entry(src, &video_source_list, list) {
		if (strcmp(src->name, name) == 0) {
			kref_get(&src->ref);
			return src;
		}
	}

	return NULL;
}
EXPORT_SYMBOL_GPL(video_source_find);

MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
MODULE_DESCRIPTION("Display Core");
MODULE_LICENSE("GPL");