Linux Audio

Check our new training course

Loading...
v5.9
  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_crtc_state *old_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_crtc_state *old_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	if (crtc->state->event && !crtc->state->active) {
 43		spin_lock_irq(&crtc->dev->event_lock);
 44		drm_crtc_send_vblank_event(crtc, crtc->state->event);
 45		spin_unlock_irq(&crtc->dev->event_lock);
 46
 47		crtc->state->event = NULL;
 48	}
 49}
 50
 51static int exynos_crtc_atomic_check(struct drm_crtc *crtc,
 52				     struct drm_crtc_state *state)
 53{
 54	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 55
 56	if (!state->enable)
 57		return 0;
 58
 59	if (exynos_crtc->ops->atomic_check)
 60		return exynos_crtc->ops->atomic_check(exynos_crtc, state);
 61
 62	return 0;
 63}
 64
 65static void exynos_crtc_atomic_begin(struct drm_crtc *crtc,
 66				     struct drm_crtc_state *old_crtc_state)
 67{
 68	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 69
 
 
 70	if (exynos_crtc->ops->atomic_begin)
 71		exynos_crtc->ops->atomic_begin(exynos_crtc);
 72}
 73
 74static void exynos_crtc_atomic_flush(struct drm_crtc *crtc,
 75				     struct drm_crtc_state *old_crtc_state)
 76{
 77	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 78
 79	if (exynos_crtc->ops->atomic_flush)
 80		exynos_crtc->ops->atomic_flush(exynos_crtc);
 81}
 82
 83static enum drm_mode_status exynos_crtc_mode_valid(struct drm_crtc *crtc,
 84	const struct drm_display_mode *mode)
 85{
 86	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 87
 88	if (exynos_crtc->ops->mode_valid)
 89		return exynos_crtc->ops->mode_valid(exynos_crtc, mode);
 90
 91	return MODE_OK;
 92}
 93
 94static bool exynos_crtc_mode_fixup(struct drm_crtc *crtc,
 95		const struct drm_display_mode *mode,
 96		struct drm_display_mode *adjusted_mode)
 97{
 98	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 99
100	if (exynos_crtc->ops->mode_fixup)
101		return exynos_crtc->ops->mode_fixup(exynos_crtc, mode,
102				adjusted_mode);
103
104	return true;
105}
106
107
108static const struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = {
109	.mode_valid	= exynos_crtc_mode_valid,
110	.mode_fixup	= exynos_crtc_mode_fixup,
 
111	.atomic_check	= exynos_crtc_atomic_check,
112	.atomic_begin	= exynos_crtc_atomic_begin,
113	.atomic_flush	= exynos_crtc_atomic_flush,
114	.atomic_enable	= exynos_drm_crtc_atomic_enable,
115	.atomic_disable	= exynos_drm_crtc_atomic_disable,
116};
117
118void exynos_crtc_handle_event(struct exynos_drm_crtc *exynos_crtc)
119{
120	struct drm_crtc *crtc = &exynos_crtc->base;
121	struct drm_pending_vblank_event *event = crtc->state->event;
122	unsigned long flags;
123
124	if (!event)
125		return;
126	crtc->state->event = NULL;
127
128	WARN_ON(drm_crtc_vblank_get(crtc) != 0);
129
130	spin_lock_irqsave(&crtc->dev->event_lock, flags);
131	drm_crtc_arm_vblank_event(crtc, event);
132	spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
133}
134
135static void exynos_drm_crtc_destroy(struct drm_crtc *crtc)
136{
137	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 
 
 
138
139	drm_crtc_cleanup(crtc);
140	kfree(exynos_crtc);
141}
142
143static int exynos_drm_crtc_enable_vblank(struct drm_crtc *crtc)
144{
145	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
146
147	if (exynos_crtc->ops->enable_vblank)
148		return exynos_crtc->ops->enable_vblank(exynos_crtc);
149
150	return 0;
151}
152
153static void exynos_drm_crtc_disable_vblank(struct drm_crtc *crtc)
154{
155	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
156
157	if (exynos_crtc->ops->disable_vblank)
158		exynos_crtc->ops->disable_vblank(exynos_crtc);
159}
160
161static const struct drm_crtc_funcs exynos_crtc_funcs = {
162	.set_config	= drm_atomic_helper_set_config,
163	.page_flip	= drm_atomic_helper_page_flip,
164	.destroy	= exynos_drm_crtc_destroy,
165	.reset = drm_atomic_helper_crtc_reset,
166	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
167	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
168	.enable_vblank = exynos_drm_crtc_enable_vblank,
169	.disable_vblank = exynos_drm_crtc_disable_vblank,
170};
171
172struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev,
173					struct drm_plane *plane,
 
174					enum exynos_drm_output_type type,
175					const struct exynos_drm_crtc_ops *ops,
176					void *ctx)
177{
178	struct exynos_drm_crtc *exynos_crtc;
 
179	struct drm_crtc *crtc;
180	int ret;
181
182	exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL);
183	if (!exynos_crtc)
184		return ERR_PTR(-ENOMEM);
185
 
186	exynos_crtc->type = type;
187	exynos_crtc->ops = ops;
188	exynos_crtc->ctx = ctx;
189
 
 
190	crtc = &exynos_crtc->base;
191
 
 
192	ret = drm_crtc_init_with_planes(drm_dev, crtc, plane, NULL,
193					&exynos_crtc_funcs, NULL);
194	if (ret < 0)
195		goto err_crtc;
196
197	drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs);
198
199	return exynos_crtc;
200
201err_crtc:
202	plane->funcs->destroy(plane);
203	kfree(exynos_crtc);
204	return ERR_PTR(ret);
205}
206
207struct exynos_drm_crtc *exynos_drm_crtc_get_by_type(struct drm_device *drm_dev,
208				       enum exynos_drm_output_type out_type)
209{
210	struct drm_crtc *crtc;
 
 
 
 
 
 
 
 
211
212	drm_for_each_crtc(crtc, drm_dev)
213		if (to_exynos_crtc(crtc)->type == out_type)
214			return to_exynos_crtc(crtc);
 
 
215
216	return ERR_PTR(-ENODEV);
 
217}
218
219int exynos_drm_set_possible_crtcs(struct drm_encoder *encoder,
220		enum exynos_drm_output_type out_type)
221{
222	struct exynos_drm_crtc *crtc = exynos_drm_crtc_get_by_type(encoder->dev,
223						out_type);
 
 
224
225	if (IS_ERR(crtc))
226		return PTR_ERR(crtc);
 
 
 
227
228	encoder->possible_crtcs = drm_crtc_mask(&crtc->base);
229
230	return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231}
232
233void exynos_drm_crtc_te_handler(struct drm_crtc *crtc)
234{
235	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
236
237	if (exynos_crtc->ops->te_handler)
238		exynos_crtc->ops->te_handler(exynos_crtc);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239}
v4.6
 
  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	exynos_crtc->event = crtc->state->event;
 73
 74	if (exynos_crtc->ops->atomic_begin)
 75		exynos_crtc->ops->atomic_begin(exynos_crtc);
 76}
 77
 78static void exynos_crtc_atomic_flush(struct drm_crtc *crtc,
 79				     struct drm_crtc_state *old_crtc_state)
 80{
 81	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 82
 83	if (exynos_crtc->ops->atomic_flush)
 84		exynos_crtc->ops->atomic_flush(exynos_crtc);
 85}
 86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 87static const struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = {
 88	.enable		= exynos_drm_crtc_enable,
 89	.disable	= exynos_drm_crtc_disable,
 90	.mode_set_nofb	= exynos_drm_crtc_mode_set_nofb,
 91	.atomic_check	= exynos_crtc_atomic_check,
 92	.atomic_begin	= exynos_crtc_atomic_begin,
 93	.atomic_flush	= exynos_crtc_atomic_flush,
 
 
 94};
 95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 96static void exynos_drm_crtc_destroy(struct drm_crtc *crtc)
 97{
 98	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
 99	struct exynos_drm_private *private = crtc->dev->dev_private;
100
101	private->crtc[exynos_crtc->pipe] = NULL;
102
103	drm_crtc_cleanup(crtc);
104	kfree(exynos_crtc);
105}
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107static const struct drm_crtc_funcs exynos_crtc_funcs = {
108	.set_config	= drm_atomic_helper_set_config,
109	.page_flip	= drm_atomic_helper_page_flip,
110	.destroy	= exynos_drm_crtc_destroy,
111	.reset = drm_atomic_helper_crtc_reset,
112	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
113	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
 
 
114};
115
116struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev,
117					struct drm_plane *plane,
118					int pipe,
119					enum exynos_drm_output_type type,
120					const struct exynos_drm_crtc_ops *ops,
121					void *ctx)
122{
123	struct exynos_drm_crtc *exynos_crtc;
124	struct exynos_drm_private *private = drm_dev->dev_private;
125	struct drm_crtc *crtc;
126	int ret;
127
128	exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL);
129	if (!exynos_crtc)
130		return ERR_PTR(-ENOMEM);
131
132	exynos_crtc->pipe = pipe;
133	exynos_crtc->type = type;
134	exynos_crtc->ops = ops;
135	exynos_crtc->ctx = ctx;
136
137	init_waitqueue_head(&exynos_crtc->wait_update);
138
139	crtc = &exynos_crtc->base;
140
141	private->crtc[pipe] = crtc;
142
143	ret = drm_crtc_init_with_planes(drm_dev, crtc, plane, NULL,
144					&exynos_crtc_funcs, NULL);
145	if (ret < 0)
146		goto err_crtc;
147
148	drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs);
149
150	return exynos_crtc;
151
152err_crtc:
153	plane->funcs->destroy(plane);
154	kfree(exynos_crtc);
155	return ERR_PTR(ret);
156}
157
158int exynos_drm_crtc_enable_vblank(struct drm_device *dev, unsigned int pipe)
 
159{
160	struct exynos_drm_private *private = dev->dev_private;
161	struct exynos_drm_crtc *exynos_crtc =
162		to_exynos_crtc(private->crtc[pipe]);
163
164	if (exynos_crtc->ops->enable_vblank)
165		return exynos_crtc->ops->enable_vblank(exynos_crtc);
166
167	return 0;
168}
169
170void exynos_drm_crtc_disable_vblank(struct drm_device *dev, unsigned int pipe)
171{
172	struct exynos_drm_private *private = dev->dev_private;
173	struct exynos_drm_crtc *exynos_crtc =
174		to_exynos_crtc(private->crtc[pipe]);
175
176	if (exynos_crtc->ops->disable_vblank)
177		exynos_crtc->ops->disable_vblank(exynos_crtc);
178}
179
180void exynos_drm_crtc_wait_pending_update(struct exynos_drm_crtc *exynos_crtc)
 
181{
182	wait_event_timeout(exynos_crtc->wait_update,
183			   (atomic_read(&exynos_crtc->pending_update) == 0),
184			   msecs_to_jiffies(50));
185}
186
187void exynos_drm_crtc_finish_update(struct exynos_drm_crtc *exynos_crtc,
188				struct exynos_drm_plane *exynos_plane)
189{
190	struct drm_crtc *crtc = &exynos_crtc->base;
191	unsigned long flags;
192
193	exynos_plane->pending_fb = NULL;
194
195	if (atomic_dec_and_test(&exynos_crtc->pending_update))
196		wake_up(&exynos_crtc->wait_update);
197
198	spin_lock_irqsave(&crtc->dev->event_lock, flags);
199	if (exynos_crtc->event)
200		drm_crtc_send_vblank_event(crtc, exynos_crtc->event);
201
202	exynos_crtc->event = NULL;
203	spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
204}
205
206int exynos_drm_crtc_get_pipe_from_type(struct drm_device *drm_dev,
207				       enum exynos_drm_output_type out_type)
208{
209	struct drm_crtc *crtc;
210
211	list_for_each_entry(crtc, &drm_dev->mode_config.crtc_list, head) {
212		struct exynos_drm_crtc *exynos_crtc;
213
214		exynos_crtc = to_exynos_crtc(crtc);
215		if (exynos_crtc->type == out_type)
216			return exynos_crtc->pipe;
217	}
218
219	return -EPERM;
220}
221
222void exynos_drm_crtc_te_handler(struct drm_crtc *crtc)
223{
224	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
225
226	if (exynos_crtc->ops->te_handler)
227		exynos_crtc->ops->te_handler(exynos_crtc);
228}
229
230void exynos_drm_crtc_cancel_page_flip(struct drm_crtc *crtc,
231					struct drm_file *file)
232{
233	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
234	struct drm_pending_vblank_event *e;
235	unsigned long flags;
236
237	spin_lock_irqsave(&crtc->dev->event_lock, flags);
238	e = exynos_crtc->event;
239	if (e && e->base.file_priv == file) {
240		exynos_crtc->event = NULL;
241		/*
242		 * event will be destroyed by core part
243		 * so below line should be removed later with core changes
244		 */
245		e->base.destroy(&e->base);
246		/*
247		 * event_space will be increased by core part
248		 * so below line should be removed later with core changes.
249		 */
250		file->event_space += sizeof(e->event);
251		atomic_dec(&exynos_crtc->pending_update);
252	}
253	spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
254}