Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/* exynos_drm_crtc.c
  3 *
  4 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  5 * Authors:
  6 *	Inki Dae <inki.dae@samsung.com>
  7 *	Joonyoung Shim <jy0922.shim@samsung.com>
  8 *	Seung-Woo Kim <sw0312.kim@samsung.com>
 
 
 
 
 
  9 */
 10
 
 
 11#include <drm/drm_atomic.h>
 12#include <drm/drm_atomic_helper.h>
 13#include <drm/drm_encoder.h>
 14#include <drm/drm_probe_helper.h>
 15#include <drm/drm_vblank.h>
 16
 17#include "exynos_drm_crtc.h"
 18#include "exynos_drm_drv.h"
 19#include "exynos_drm_plane.h"
 20
 21static void exynos_drm_crtc_atomic_enable(struct drm_crtc *crtc,
 22					  struct drm_atomic_state *state)
 23{
 24	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 25
 26	if (exynos_crtc->ops->atomic_enable)
 27		exynos_crtc->ops->atomic_enable(exynos_crtc);
 28
 29	drm_crtc_vblank_on(crtc);
 30}
 31
 32static void exynos_drm_crtc_atomic_disable(struct drm_crtc *crtc,
 33					   struct drm_atomic_state *state)
 34{
 35	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 36
 37	drm_crtc_vblank_off(crtc);
 38
 39	if (exynos_crtc->ops->atomic_disable)
 40		exynos_crtc->ops->atomic_disable(exynos_crtc);
 
 41
 42	spin_lock_irq(&crtc->dev->event_lock);
 43	if (crtc->state->event && !crtc->state->active) {
 44		drm_crtc_send_vblank_event(crtc, crtc->state->event);
 45		crtc->state->event = NULL;
 46	}
 47	spin_unlock_irq(&crtc->dev->event_lock);
 
 48}
 49
 50static int exynos_crtc_atomic_check(struct drm_crtc *crtc,
 51				     struct drm_atomic_state *state)
 52{
 53	struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state,
 54									  crtc);
 55	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 56
 57	if (!crtc_state->enable)
 58		return 0;
 59
 60	if (exynos_crtc->ops->atomic_check)
 61		return exynos_crtc->ops->atomic_check(exynos_crtc, crtc_state);
 62
 63	return 0;
 64}
 65
 66static void exynos_crtc_atomic_begin(struct drm_crtc *crtc,
 67				     struct drm_atomic_state *state)
 68{
 69	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 70
 71	if (exynos_crtc->ops->atomic_begin)
 72		exynos_crtc->ops->atomic_begin(exynos_crtc);
 73}
 74
 75static void exynos_crtc_atomic_flush(struct drm_crtc *crtc,
 76				     struct drm_atomic_state *state)
 77{
 78	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 
 
 79
 80	if (exynos_crtc->ops->atomic_flush)
 81		exynos_crtc->ops->atomic_flush(exynos_crtc);
 82}
 83
 84static enum drm_mode_status exynos_crtc_mode_valid(struct drm_crtc *crtc,
 85	const struct drm_display_mode *mode)
 86{
 87	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 88
 89	if (exynos_crtc->ops->mode_valid)
 90		return exynos_crtc->ops->mode_valid(exynos_crtc, mode);
 91
 92	return MODE_OK;
 93}
 94
 95static bool exynos_crtc_mode_fixup(struct drm_crtc *crtc,
 96		const struct drm_display_mode *mode,
 97		struct drm_display_mode *adjusted_mode)
 98{
 99	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
100
101	if (exynos_crtc->ops->mode_fixup)
102		return exynos_crtc->ops->mode_fixup(exynos_crtc, mode,
103				adjusted_mode);
 
 
 
 
104
105	return true;
106}
107
108
109static const struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = {
110	.mode_valid	= exynos_crtc_mode_valid,
111	.mode_fixup	= exynos_crtc_mode_fixup,
 
112	.atomic_check	= exynos_crtc_atomic_check,
113	.atomic_begin	= exynos_crtc_atomic_begin,
114	.atomic_flush	= exynos_crtc_atomic_flush,
115	.atomic_enable	= exynos_drm_crtc_atomic_enable,
116	.atomic_disable	= exynos_drm_crtc_atomic_disable,
117};
118
119void exynos_crtc_handle_event(struct exynos_drm_crtc *exynos_crtc)
120{
121	struct drm_crtc *crtc = &exynos_crtc->base;
122	struct drm_pending_vblank_event *event = crtc->state->event;
123	unsigned long flags;
124
125	if (!event)
126		return;
127	crtc->state->event = NULL;
128
129	WARN_ON(drm_crtc_vblank_get(crtc) != 0);
130
131	spin_lock_irqsave(&crtc->dev->event_lock, flags);
132	drm_crtc_arm_vblank_event(crtc, event);
133	spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
134}
135
136static void exynos_drm_crtc_destroy(struct drm_crtc *crtc)
137{
138	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 
 
 
139
140	drm_crtc_cleanup(crtc);
141	kfree(exynos_crtc);
142}
143
144static int exynos_drm_crtc_enable_vblank(struct drm_crtc *crtc)
145{
146	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
147
148	if (exynos_crtc->ops->enable_vblank)
149		return exynos_crtc->ops->enable_vblank(exynos_crtc);
150
151	return 0;
152}
153
154static void exynos_drm_crtc_disable_vblank(struct drm_crtc *crtc)
155{
156	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
157
158	if (exynos_crtc->ops->disable_vblank)
159		exynos_crtc->ops->disable_vblank(exynos_crtc);
160}
161
162static const struct drm_crtc_funcs exynos_crtc_funcs = {
163	.set_config	= drm_atomic_helper_set_config,
164	.page_flip	= drm_atomic_helper_page_flip,
165	.destroy	= exynos_drm_crtc_destroy,
166	.reset = drm_atomic_helper_crtc_reset,
167	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
168	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
169	.enable_vblank = exynos_drm_crtc_enable_vblank,
170	.disable_vblank = exynos_drm_crtc_disable_vblank,
171};
172
173struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev,
174					struct drm_plane *plane,
 
175					enum exynos_drm_output_type type,
176					const struct exynos_drm_crtc_ops *ops,
177					void *ctx)
178{
179	struct exynos_drm_crtc *exynos_crtc;
 
180	struct drm_crtc *crtc;
181	int ret;
182
183	exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL);
184	if (!exynos_crtc)
185		return ERR_PTR(-ENOMEM);
186
 
187	exynos_crtc->type = type;
188	exynos_crtc->ops = ops;
189	exynos_crtc->ctx = ctx;
190
191	crtc = &exynos_crtc->base;
192
 
 
193	ret = drm_crtc_init_with_planes(drm_dev, crtc, plane, NULL,
194					&exynos_crtc_funcs, NULL);
195	if (ret < 0)
196		goto err_crtc;
197
198	drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs);
199
200	return exynos_crtc;
201
202err_crtc:
203	plane->funcs->destroy(plane);
204	kfree(exynos_crtc);
205	return ERR_PTR(ret);
206}
207
208struct exynos_drm_crtc *exynos_drm_crtc_get_by_type(struct drm_device *drm_dev,
209				       enum exynos_drm_output_type out_type)
210{
211	struct drm_crtc *crtc;
 
 
 
 
 
 
 
212
213	drm_for_each_crtc(crtc, drm_dev)
214		if (to_exynos_crtc(crtc)->type == out_type)
215			return to_exynos_crtc(crtc);
 
216
217	return ERR_PTR(-ENODEV);
 
218}
219
220int exynos_drm_set_possible_crtcs(struct drm_encoder *encoder,
221		enum exynos_drm_output_type out_type)
222{
223	struct exynos_drm_crtc *crtc = exynos_drm_crtc_get_by_type(encoder->dev,
224						out_type);
225
226	if (IS_ERR(crtc))
227		return PTR_ERR(crtc);
228
229	encoder->possible_crtcs = drm_crtc_mask(&crtc->base);
 
 
 
230
231	return 0;
232}
233
234void exynos_drm_crtc_te_handler(struct drm_crtc *crtc)
235{
236	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
237
238	if (exynos_crtc->ops->te_handler)
239		exynos_crtc->ops->te_handler(exynos_crtc);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240}
v4.10.11
 
  1/* exynos_drm_crtc.c
  2 *
  3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  4 * Authors:
  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 <drm/drm_crtc_helper.h>
 17#include <drm/drm_atomic.h>
 18#include <drm/drm_atomic_helper.h>
 
 
 
 19
 20#include "exynos_drm_crtc.h"
 21#include "exynos_drm_drv.h"
 22#include "exynos_drm_plane.h"
 23
 24static void exynos_drm_crtc_enable(struct drm_crtc *crtc)
 
 25{
 26	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 27
 28	if (exynos_crtc->ops->enable)
 29		exynos_crtc->ops->enable(exynos_crtc);
 30
 31	drm_crtc_vblank_on(crtc);
 32}
 33
 34static void exynos_drm_crtc_disable(struct drm_crtc *crtc)
 
 35{
 36	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 37
 38	drm_crtc_vblank_off(crtc);
 39
 40	if (exynos_crtc->ops->disable)
 41		exynos_crtc->ops->disable(exynos_crtc);
 42}
 43
 44static void
 45exynos_drm_crtc_mode_set_nofb(struct drm_crtc *crtc)
 46{
 47	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 48
 49	if (exynos_crtc->ops->commit)
 50		exynos_crtc->ops->commit(exynos_crtc);
 51}
 52
 53static int exynos_crtc_atomic_check(struct drm_crtc *crtc,
 54				     struct drm_crtc_state *state)
 55{
 
 
 56	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 57
 58	if (!state->enable)
 59		return 0;
 60
 61	if (exynos_crtc->ops->atomic_check)
 62		return exynos_crtc->ops->atomic_check(exynos_crtc, state);
 63
 64	return 0;
 65}
 66
 67static void exynos_crtc_atomic_begin(struct drm_crtc *crtc,
 68				     struct drm_crtc_state *old_crtc_state)
 69{
 70	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 71
 72	if (exynos_crtc->ops->atomic_begin)
 73		exynos_crtc->ops->atomic_begin(exynos_crtc);
 74}
 75
 76static void exynos_crtc_atomic_flush(struct drm_crtc *crtc,
 77				     struct drm_crtc_state *old_crtc_state)
 78{
 79	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 80	struct drm_pending_vblank_event *event;
 81	unsigned long flags;
 82
 83	if (exynos_crtc->ops->atomic_flush)
 84		exynos_crtc->ops->atomic_flush(exynos_crtc);
 
 85
 86	event = crtc->state->event;
 87	if (event) {
 88		crtc->state->event = NULL;
 
 
 
 
 
 
 
 
 
 
 
 
 
 89
 90		spin_lock_irqsave(&crtc->dev->event_lock, flags);
 91		if (drm_crtc_vblank_get(crtc) == 0)
 92			drm_crtc_arm_vblank_event(crtc, event);
 93		else
 94			drm_crtc_send_vblank_event(crtc, event);
 95		spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
 96	}
 97
 
 98}
 99
 
100static const struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = {
101	.enable		= exynos_drm_crtc_enable,
102	.disable	= exynos_drm_crtc_disable,
103	.mode_set_nofb	= exynos_drm_crtc_mode_set_nofb,
104	.atomic_check	= exynos_crtc_atomic_check,
105	.atomic_begin	= exynos_crtc_atomic_begin,
106	.atomic_flush	= exynos_crtc_atomic_flush,
 
 
107};
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109static void exynos_drm_crtc_destroy(struct drm_crtc *crtc)
110{
111	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
112	struct exynos_drm_private *private = crtc->dev->dev_private;
113
114	private->crtc[exynos_crtc->pipe] = NULL;
115
116	drm_crtc_cleanup(crtc);
117	kfree(exynos_crtc);
118}
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120static const struct drm_crtc_funcs exynos_crtc_funcs = {
121	.set_config	= drm_atomic_helper_set_config,
122	.page_flip	= drm_atomic_helper_page_flip,
123	.destroy	= exynos_drm_crtc_destroy,
124	.reset = drm_atomic_helper_crtc_reset,
125	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
126	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
 
 
127};
128
129struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev,
130					struct drm_plane *plane,
131					int pipe,
132					enum exynos_drm_output_type type,
133					const struct exynos_drm_crtc_ops *ops,
134					void *ctx)
135{
136	struct exynos_drm_crtc *exynos_crtc;
137	struct exynos_drm_private *private = drm_dev->dev_private;
138	struct drm_crtc *crtc;
139	int ret;
140
141	exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL);
142	if (!exynos_crtc)
143		return ERR_PTR(-ENOMEM);
144
145	exynos_crtc->pipe = pipe;
146	exynos_crtc->type = type;
147	exynos_crtc->ops = ops;
148	exynos_crtc->ctx = ctx;
149
150	crtc = &exynos_crtc->base;
151
152	private->crtc[pipe] = crtc;
153
154	ret = drm_crtc_init_with_planes(drm_dev, crtc, plane, NULL,
155					&exynos_crtc_funcs, NULL);
156	if (ret < 0)
157		goto err_crtc;
158
159	drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs);
160
161	return exynos_crtc;
162
163err_crtc:
164	plane->funcs->destroy(plane);
165	kfree(exynos_crtc);
166	return ERR_PTR(ret);
167}
168
169int exynos_drm_crtc_enable_vblank(struct drm_device *dev, unsigned int pipe)
 
170{
171	struct exynos_drm_crtc *exynos_crtc = exynos_drm_crtc_from_pipe(dev,
172									pipe);
173
174	if (exynos_crtc->ops->enable_vblank)
175		return exynos_crtc->ops->enable_vblank(exynos_crtc);
176
177	return 0;
178}
179
180void exynos_drm_crtc_disable_vblank(struct drm_device *dev, unsigned int pipe)
181{
182	struct exynos_drm_crtc *exynos_crtc = exynos_drm_crtc_from_pipe(dev,
183									pipe);
184
185	if (exynos_crtc->ops->disable_vblank)
186		exynos_crtc->ops->disable_vblank(exynos_crtc);
187}
188
189int exynos_drm_crtc_get_pipe_from_type(struct drm_device *drm_dev,
190				       enum exynos_drm_output_type out_type)
191{
192	struct drm_crtc *crtc;
 
193
194	list_for_each_entry(crtc, &drm_dev->mode_config.crtc_list, head) {
195		struct exynos_drm_crtc *exynos_crtc;
196
197		exynos_crtc = to_exynos_crtc(crtc);
198		if (exynos_crtc->type == out_type)
199			return exynos_crtc->pipe;
200	}
201
202	return -EPERM;
203}
204
205void exynos_drm_crtc_te_handler(struct drm_crtc *crtc)
206{
207	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
208
209	if (exynos_crtc->ops->te_handler)
210		exynos_crtc->ops->te_handler(exynos_crtc);
211}
212
213void exynos_drm_crtc_cancel_page_flip(struct drm_crtc *crtc,
214					struct drm_file *file)
215{
216	struct drm_pending_vblank_event *e;
217	unsigned long flags;
218
219	spin_lock_irqsave(&crtc->dev->event_lock, flags);
220
221	e = crtc->state->event;
222	if (e && e->base.file_priv == file)
223		crtc->state->event = NULL;
224	else
225		e = NULL;
226
227	spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
228
229	if (e)
230		drm_event_cancel_free(crtc->dev, &e->base);
231}