Linux Audio

Check our new training course

Loading...
v4.6
 
  1/*
  2 * Copyright (C) STMicroelectronics SA 2014
  3 * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
  4 *          Fabien Dessenne <fabien.dessenne@st.com>
  5 *          for STMicroelectronics.
  6 * License terms:  GNU General Public License (GPL), version 2
  7 */
  8
  9#include <linux/clk.h>
 10
 11#include <drm/drmP.h>
 12#include <drm/drm_atomic.h>
 13#include <drm/drm_atomic_helper.h>
 14#include <drm/drm_crtc_helper.h>
 15#include <drm/drm_plane_helper.h>
 
 
 
 16
 17#include "sti_compositor.h"
 18#include "sti_crtc.h"
 19#include "sti_drv.h"
 20#include "sti_vid.h"
 21#include "sti_vtg.h"
 22
 23static void sti_crtc_enable(struct drm_crtc *crtc)
 
 24{
 25	struct sti_mixer *mixer = to_sti_mixer(crtc);
 26	struct device *dev = mixer->dev;
 27	struct sti_compositor *compo = dev_get_drvdata(dev);
 28
 29	DRM_DEBUG_DRIVER("\n");
 30
 31	mixer->status = STI_MIXER_READY;
 32
 33	/* Prepare and enable the compo IP clock */
 34	if (mixer->id == STI_MIXER_MAIN) {
 35		if (clk_prepare_enable(compo->clk_compo_main))
 36			DRM_INFO("Failed to prepare/enable compo_main clk\n");
 37	} else {
 38		if (clk_prepare_enable(compo->clk_compo_aux))
 39			DRM_INFO("Failed to prepare/enable compo_aux clk\n");
 40	}
 41
 42	drm_crtc_vblank_on(crtc);
 43}
 44
 45static void sti_crtc_disabling(struct drm_crtc *crtc)
 
 46{
 47	struct sti_mixer *mixer = to_sti_mixer(crtc);
 48
 49	DRM_DEBUG_DRIVER("\n");
 50
 51	mixer->status = STI_MIXER_DISABLING;
 52}
 53
 54static bool sti_crtc_mode_fixup(struct drm_crtc *crtc,
 55				const struct drm_display_mode *mode,
 56				struct drm_display_mode *adjusted_mode)
 57{
 58	/* accept the provided drm_display_mode, do not fix it up */
 59	drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
 60	return true;
 61}
 62
 63static int
 64sti_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode)
 65{
 66	struct sti_mixer *mixer = to_sti_mixer(crtc);
 67	struct device *dev = mixer->dev;
 68	struct sti_compositor *compo = dev_get_drvdata(dev);
 69	struct clk *clk;
 70	int rate = mode->clock * 1000;
 71	int res;
 72
 73	DRM_DEBUG_KMS("CRTC:%d (%s) mode:%d (%s)\n",
 74		      crtc->base.id, sti_mixer_to_str(mixer),
 75		      mode->base.id, mode->name);
 76
 77	DRM_DEBUG_KMS("%d %d %d %d %d %d %d %d %d %d 0x%x 0x%x\n",
 78		      mode->vrefresh, mode->clock,
 79		      mode->hdisplay,
 80		      mode->hsync_start, mode->hsync_end,
 81		      mode->htotal,
 82		      mode->vdisplay,
 83		      mode->vsync_start, mode->vsync_end,
 84		      mode->vtotal, mode->type, mode->flags);
 85
 86	/* Set rate and prepare/enable pixel clock */
 87	if (mixer->id == STI_MIXER_MAIN)
 88		clk = compo->clk_pix_main;
 89	else
 90		clk = compo->clk_pix_aux;
 91
 92	res = clk_set_rate(clk, rate);
 93	if (res < 0) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 94		DRM_ERROR("Cannot set rate (%dHz) for pix clk\n", rate);
 95		return -EINVAL;
 96	}
 97	if (clk_prepare_enable(clk)) {
 98		DRM_ERROR("Failed to prepare/enable pix clk\n");
 99		return -EINVAL;
100	}
101
102	sti_vtg_set_config(mixer->id == STI_MIXER_MAIN ?
103			compo->vtg_main : compo->vtg_aux, &crtc->mode);
104
105	res = sti_mixer_active_video_area(mixer, &crtc->mode);
106	if (res) {
107		DRM_ERROR("Can't set active video area\n");
108		return -EINVAL;
109	}
110
111	return res;
 
 
 
 
 
 
 
112}
113
114static void sti_crtc_disable(struct drm_crtc *crtc)
115{
116	struct sti_mixer *mixer = to_sti_mixer(crtc);
117	struct device *dev = mixer->dev;
118	struct sti_compositor *compo = dev_get_drvdata(dev);
119
120	DRM_DEBUG_KMS("CRTC:%d (%s)\n", crtc->base.id, sti_mixer_to_str(mixer));
121
122	/* Disable Background */
123	sti_mixer_set_background_status(mixer, false);
124
125	drm_crtc_vblank_off(crtc);
126
127	/* Disable pixel clock and compo IP clocks */
128	if (mixer->id == STI_MIXER_MAIN) {
129		clk_disable_unprepare(compo->clk_pix_main);
130		clk_disable_unprepare(compo->clk_compo_main);
131	} else {
132		clk_disable_unprepare(compo->clk_pix_aux);
133		clk_disable_unprepare(compo->clk_compo_aux);
134	}
135
136	mixer->status = STI_MIXER_DISABLED;
137}
138
139static void
140sti_crtc_mode_set_nofb(struct drm_crtc *crtc)
141{
142	sti_crtc_enable(crtc);
143	sti_crtc_mode_set(crtc, &crtc->state->adjusted_mode);
144}
145
146static void sti_crtc_atomic_begin(struct drm_crtc *crtc,
147				  struct drm_crtc_state *old_crtc_state)
148{
149	struct sti_mixer *mixer = to_sti_mixer(crtc);
150
151	if (crtc->state->event) {
152		crtc->state->event->pipe = drm_crtc_index(crtc);
153
154		WARN_ON(drm_crtc_vblank_get(crtc) != 0);
155
156		mixer->pending_event = crtc->state->event;
157		crtc->state->event = NULL;
158	}
159}
160
161static void sti_crtc_atomic_flush(struct drm_crtc *crtc,
162				  struct drm_crtc_state *old_crtc_state)
163{
164	struct drm_device *drm_dev = crtc->dev;
165	struct sti_mixer *mixer = to_sti_mixer(crtc);
166	struct sti_compositor *compo = dev_get_drvdata(mixer->dev);
167	struct drm_plane *p;
 
 
168
169	DRM_DEBUG_DRIVER("\n");
170
171	/* perform plane actions */
172	list_for_each_entry(p, &drm_dev->mode_config.plane_list, head) {
173		struct sti_plane *plane = to_sti_plane(p);
174
175		switch (plane->status) {
176		case STI_PLANE_UPDATED:
 
 
 
 
177			/* update planes tag as updated */
178			DRM_DEBUG_DRIVER("update plane %s\n",
179					 sti_plane_to_str(plane));
180
181			if (sti_mixer_set_plane_depth(mixer, plane)) {
182				DRM_ERROR("Cannot set plane %s depth\n",
183					  sti_plane_to_str(plane));
184				break;
185			}
186
187			if (sti_mixer_set_plane_status(mixer, plane, true)) {
188				DRM_ERROR("Cannot enable plane %s at mixer\n",
189					  sti_plane_to_str(plane));
190				break;
191			}
192
193			/* if plane is HQVDP_0 then commit the vid[0] */
194			if (plane->desc == STI_HQVDP_0)
195				sti_vid_commit(compo->vid[0], p->state);
196
197			plane->status = STI_PLANE_READY;
198
199			break;
200		case STI_PLANE_DISABLING:
201			/* disabling sequence for planes tag as disabling */
202			DRM_DEBUG_DRIVER("disable plane %s from mixer\n",
203					 sti_plane_to_str(plane));
204
205			if (sti_mixer_set_plane_status(mixer, plane, false)) {
206				DRM_ERROR("Cannot disable plane %s at mixer\n",
207					  sti_plane_to_str(plane));
208				continue;
209			}
210
211			if (plane->desc == STI_CURSOR)
212				/* tag plane status for disabled */
213				plane->status = STI_PLANE_DISABLED;
214			else
215				/* tag plane status for flushing */
216				plane->status = STI_PLANE_FLUSHING;
217
218			/* if plane is HQVDP_0 then disable the vid[0] */
219			if (plane->desc == STI_HQVDP_0)
220				sti_vid_disable(compo->vid[0]);
221
222			break;
223		default:
224			/* Other status case are not handled */
225			break;
226		}
227	}
 
 
 
 
 
 
 
 
 
 
 
 
228}
229
230static const struct drm_crtc_helper_funcs sti_crtc_helper_funcs = {
231	.enable = sti_crtc_enable,
232	.disable = sti_crtc_disabling,
233	.mode_fixup = sti_crtc_mode_fixup,
234	.mode_set = drm_helper_crtc_mode_set,
235	.mode_set_nofb = sti_crtc_mode_set_nofb,
236	.mode_set_base = drm_helper_crtc_mode_set_base,
237	.atomic_begin = sti_crtc_atomic_begin,
238	.atomic_flush = sti_crtc_atomic_flush,
 
 
239};
240
241static void sti_crtc_destroy(struct drm_crtc *crtc)
242{
243	DRM_DEBUG_KMS("\n");
244	drm_crtc_cleanup(crtc);
245}
246
247static int sti_crtc_set_property(struct drm_crtc *crtc,
248				 struct drm_property *property,
249				 uint64_t val)
250{
251	DRM_DEBUG_KMS("\n");
252	return 0;
253}
254
255int sti_crtc_vblank_cb(struct notifier_block *nb,
256		       unsigned long event, void *data)
257{
258	struct sti_compositor *compo =
259		container_of(nb, struct sti_compositor, vtg_vblank_nb);
260	struct drm_crtc *crtc = data;
261	struct sti_mixer *mixer;
262	unsigned long flags;
263	struct sti_private *priv;
264	unsigned int pipe;
265
266	priv = crtc->dev->dev_private;
267	pipe = drm_crtc_index(crtc);
 
268	mixer = compo->mixer[pipe];
269
270	if ((event != VTG_TOP_FIELD_EVENT) &&
271	    (event != VTG_BOTTOM_FIELD_EVENT)) {
272		DRM_ERROR("unknown event: %lu\n", event);
273		return -EINVAL;
274	}
275
276	drm_crtc_handle_vblank(crtc);
277
278	spin_lock_irqsave(&crtc->dev->event_lock, flags);
279	if (mixer->pending_event) {
280		drm_crtc_send_vblank_event(crtc, mixer->pending_event);
281		drm_crtc_vblank_put(crtc);
282		mixer->pending_event = NULL;
283	}
284	spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
285
286	if (mixer->status == STI_MIXER_DISABLING) {
287		struct drm_plane *p;
288
289		/* Disable mixer only if all overlay planes (GDP and VDP)
290		 * are disabled */
291		list_for_each_entry(p, &crtc->dev->mode_config.plane_list,
292				    head) {
293			struct sti_plane *plane = to_sti_plane(p);
294
295			if ((plane->desc & STI_PLANE_TYPE_MASK) <= STI_VDP)
296				if (plane->status != STI_PLANE_DISABLED)
297					return 0;
298		}
299		sti_crtc_disable(crtc);
300	}
301
302	return 0;
303}
304
305int sti_crtc_enable_vblank(struct drm_device *dev, unsigned int pipe)
306{
 
 
307	struct sti_private *dev_priv = dev->dev_private;
308	struct sti_compositor *compo = dev_priv->compo;
309	struct notifier_block *vtg_vblank_nb = &compo->vtg_vblank_nb;
310	struct drm_crtc *crtc = &compo->mixer[pipe]->drm_crtc;
311
312	DRM_DEBUG_DRIVER("\n");
313
314	if (sti_vtg_register_client(pipe == STI_MIXER_MAIN ?
315			compo->vtg_main : compo->vtg_aux,
316			vtg_vblank_nb, crtc)) {
317		DRM_ERROR("Cannot register VTG notifier\n");
318		return -EINVAL;
319	}
320
321	return 0;
322}
323
324void sti_crtc_disable_vblank(struct drm_device *drm_dev, unsigned int pipe)
325{
 
 
326	struct sti_private *priv = drm_dev->dev_private;
327	struct sti_compositor *compo = priv->compo;
328	struct notifier_block *vtg_vblank_nb = &compo->vtg_vblank_nb;
329	struct drm_crtc *crtc = &compo->mixer[pipe]->drm_crtc;
330
331	DRM_DEBUG_DRIVER("\n");
332
333	if (sti_vtg_unregister_client(pipe == STI_MIXER_MAIN ?
334			compo->vtg_main : compo->vtg_aux, vtg_vblank_nb))
335		DRM_DEBUG_DRIVER("Warning: cannot unregister VTG notifier\n");
 
336
337	/* free the resources of the pending requests */
338	if (compo->mixer[pipe]->pending_event) {
339		drm_crtc_vblank_put(crtc);
340		compo->mixer[pipe]->pending_event = NULL;
341	}
 
 
 
 
342}
343
344static const struct drm_crtc_funcs sti_crtc_funcs = {
345	.set_config = drm_atomic_helper_set_config,
346	.page_flip = drm_atomic_helper_page_flip,
347	.destroy = sti_crtc_destroy,
348	.set_property = sti_crtc_set_property,
349	.reset = drm_atomic_helper_crtc_reset,
350	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
351	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
 
 
 
352};
353
354bool sti_crtc_is_main(struct drm_crtc *crtc)
355{
356	struct sti_mixer *mixer = to_sti_mixer(crtc);
357
358	if (mixer->id == STI_MIXER_MAIN)
359		return true;
360
361	return false;
362}
363
364int sti_crtc_init(struct drm_device *drm_dev, struct sti_mixer *mixer,
365		  struct drm_plane *primary, struct drm_plane *cursor)
366{
367	struct drm_crtc *crtc = &mixer->drm_crtc;
368	int res;
369
370	res = drm_crtc_init_with_planes(drm_dev, crtc, primary, cursor,
371					&sti_crtc_funcs, NULL);
372	if (res) {
373		DRM_ERROR("Can't initialze CRTC\n");
374		return -EINVAL;
375	}
376
377	drm_crtc_helper_add(crtc, &sti_crtc_helper_funcs);
378
379	DRM_DEBUG_DRIVER("drm CRTC:%d mapped to %s\n",
380			 crtc->base.id, sti_mixer_to_str(mixer));
381
382	return 0;
383}
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Copyright (C) STMicroelectronics SA 2014
  4 * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
  5 *          Fabien Dessenne <fabien.dessenne@st.com>
  6 *          for STMicroelectronics.
 
  7 */
  8
  9#include <linux/clk.h>
 10
 
 11#include <drm/drm_atomic.h>
 12#include <drm/drm_atomic_helper.h>
 13#include <drm/drm_device.h>
 14#include <drm/drm_plane_helper.h>
 15#include <drm/drm_print.h>
 16#include <drm/drm_probe_helper.h>
 17#include <drm/drm_vblank.h>
 18
 19#include "sti_compositor.h"
 20#include "sti_crtc.h"
 21#include "sti_drv.h"
 22#include "sti_vid.h"
 23#include "sti_vtg.h"
 24
 25static void sti_crtc_atomic_enable(struct drm_crtc *crtc,
 26				   struct drm_atomic_state *state)
 27{
 28	struct sti_mixer *mixer = to_sti_mixer(crtc);
 
 
 29
 30	DRM_DEBUG_DRIVER("\n");
 31
 32	mixer->status = STI_MIXER_READY;
 33
 
 
 
 
 
 
 
 
 
 34	drm_crtc_vblank_on(crtc);
 35}
 36
 37static void sti_crtc_atomic_disable(struct drm_crtc *crtc,
 38				    struct drm_atomic_state *state)
 39{
 40	struct sti_mixer *mixer = to_sti_mixer(crtc);
 41
 42	DRM_DEBUG_DRIVER("\n");
 43
 44	mixer->status = STI_MIXER_DISABLING;
 
 45
 46	drm_crtc_wait_one_vblank(crtc);
 
 
 
 
 
 
 47}
 48
 49static int
 50sti_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode)
 51{
 52	struct sti_mixer *mixer = to_sti_mixer(crtc);
 53	struct device *dev = mixer->dev;
 54	struct sti_compositor *compo = dev_get_drvdata(dev);
 55	struct clk *compo_clk, *pix_clk;
 56	int rate = mode->clock * 1000;
 
 57
 58	DRM_DEBUG_KMS("CRTC:%d (%s) mode: (%s)\n",
 59		      crtc->base.id, sti_mixer_to_str(mixer), mode->name);
 
 
 
 
 
 
 
 
 
 
 60
 61	DRM_DEBUG_KMS(DRM_MODE_FMT "\n", DRM_MODE_ARG(mode));
 
 
 
 
 62
 63	if (mixer->id == STI_MIXER_MAIN) {
 64		compo_clk = compo->clk_compo_main;
 65		pix_clk = compo->clk_pix_main;
 66	} else {
 67		compo_clk = compo->clk_compo_aux;
 68		pix_clk = compo->clk_pix_aux;
 69	}
 70
 71	/* Prepare and enable the compo IP clock */
 72	if (clk_prepare_enable(compo_clk)) {
 73		DRM_INFO("Failed to prepare/enable compositor clk\n");
 74		goto compo_error;
 75	}
 76
 77	/* Set rate and prepare/enable pixel clock */
 78	if (clk_set_rate(pix_clk, rate) < 0) {
 79		DRM_ERROR("Cannot set rate (%dHz) for pix clk\n", rate);
 80		goto pix_error;
 81	}
 82	if (clk_prepare_enable(pix_clk)) {
 83		DRM_ERROR("Failed to prepare/enable pix clk\n");
 84		goto pix_error;
 85	}
 86
 87	sti_vtg_set_config(compo->vtg[mixer->id], &crtc->mode);
 
 88
 89	if (sti_mixer_active_video_area(mixer, &crtc->mode)) {
 
 90		DRM_ERROR("Can't set active video area\n");
 91		goto mixer_error;
 92	}
 93
 94	return 0;
 95
 96mixer_error:
 97	clk_disable_unprepare(pix_clk);
 98pix_error:
 99	clk_disable_unprepare(compo_clk);
100compo_error:
101	return -EINVAL;
102}
103
104static void sti_crtc_disable(struct drm_crtc *crtc)
105{
106	struct sti_mixer *mixer = to_sti_mixer(crtc);
107	struct device *dev = mixer->dev;
108	struct sti_compositor *compo = dev_get_drvdata(dev);
109
110	DRM_DEBUG_KMS("CRTC:%d (%s)\n", crtc->base.id, sti_mixer_to_str(mixer));
111
112	/* Disable Background */
113	sti_mixer_set_background_status(mixer, false);
114
115	drm_crtc_vblank_off(crtc);
116
117	/* Disable pixel clock and compo IP clocks */
118	if (mixer->id == STI_MIXER_MAIN) {
119		clk_disable_unprepare(compo->clk_pix_main);
120		clk_disable_unprepare(compo->clk_compo_main);
121	} else {
122		clk_disable_unprepare(compo->clk_pix_aux);
123		clk_disable_unprepare(compo->clk_compo_aux);
124	}
125
126	mixer->status = STI_MIXER_DISABLED;
127}
128
129static void
130sti_crtc_mode_set_nofb(struct drm_crtc *crtc)
131{
 
132	sti_crtc_mode_set(crtc, &crtc->state->adjusted_mode);
133}
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135static void sti_crtc_atomic_flush(struct drm_crtc *crtc,
136				  struct drm_atomic_state *state)
137{
138	struct drm_device *drm_dev = crtc->dev;
139	struct sti_mixer *mixer = to_sti_mixer(crtc);
140	struct sti_compositor *compo = dev_get_drvdata(mixer->dev);
141	struct drm_plane *p;
142	struct drm_pending_vblank_event *event;
143	unsigned long flags;
144
145	DRM_DEBUG_DRIVER("\n");
146
147	/* perform plane actions */
148	list_for_each_entry(p, &drm_dev->mode_config.plane_list, head) {
149		struct sti_plane *plane = to_sti_plane(p);
150
151		switch (plane->status) {
152		case STI_PLANE_UPDATED:
153			/* ignore update for other CRTC */
154			if (p->state->crtc != crtc)
155				continue;
156
157			/* update planes tag as updated */
158			DRM_DEBUG_DRIVER("update plane %s\n",
159					 sti_plane_to_str(plane));
160
161			if (sti_mixer_set_plane_depth(mixer, plane)) {
162				DRM_ERROR("Cannot set plane %s depth\n",
163					  sti_plane_to_str(plane));
164				break;
165			}
166
167			if (sti_mixer_set_plane_status(mixer, plane, true)) {
168				DRM_ERROR("Cannot enable plane %s at mixer\n",
169					  sti_plane_to_str(plane));
170				break;
171			}
172
173			/* if plane is HQVDP_0 then commit the vid[0] */
174			if (plane->desc == STI_HQVDP_0)
175				sti_vid_commit(compo->vid[0], p->state);
176
177			plane->status = STI_PLANE_READY;
178
179			break;
180		case STI_PLANE_DISABLING:
181			/* disabling sequence for planes tag as disabling */
182			DRM_DEBUG_DRIVER("disable plane %s from mixer\n",
183					 sti_plane_to_str(plane));
184
185			if (sti_mixer_set_plane_status(mixer, plane, false)) {
186				DRM_ERROR("Cannot disable plane %s at mixer\n",
187					  sti_plane_to_str(plane));
188				continue;
189			}
190
191			if (plane->desc == STI_CURSOR)
192				/* tag plane status for disabled */
193				plane->status = STI_PLANE_DISABLED;
194			else
195				/* tag plane status for flushing */
196				plane->status = STI_PLANE_FLUSHING;
197
198			/* if plane is HQVDP_0 then disable the vid[0] */
199			if (plane->desc == STI_HQVDP_0)
200				sti_vid_disable(compo->vid[0]);
201
202			break;
203		default:
204			/* Other status case are not handled */
205			break;
206		}
207	}
208
209	event = crtc->state->event;
210	if (event) {
211		crtc->state->event = NULL;
212
213		spin_lock_irqsave(&crtc->dev->event_lock, flags);
214		if (drm_crtc_vblank_get(crtc) == 0)
215			drm_crtc_arm_vblank_event(crtc, event);
216		else
217			drm_crtc_send_vblank_event(crtc, event);
218		spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
219	}
220}
221
222static const struct drm_crtc_helper_funcs sti_crtc_helper_funcs = {
 
 
 
 
223	.mode_set_nofb = sti_crtc_mode_set_nofb,
 
 
224	.atomic_flush = sti_crtc_atomic_flush,
225	.atomic_enable = sti_crtc_atomic_enable,
226	.atomic_disable = sti_crtc_atomic_disable,
227};
228
229static void sti_crtc_destroy(struct drm_crtc *crtc)
230{
231	DRM_DEBUG_KMS("\n");
232	drm_crtc_cleanup(crtc);
233}
234
235static int sti_crtc_set_property(struct drm_crtc *crtc,
236				 struct drm_property *property,
237				 uint64_t val)
238{
239	DRM_DEBUG_KMS("\n");
240	return 0;
241}
242
243int sti_crtc_vblank_cb(struct notifier_block *nb,
244		       unsigned long event, void *data)
245{
246	struct sti_compositor *compo;
 
247	struct drm_crtc *crtc = data;
248	struct sti_mixer *mixer;
 
 
249	unsigned int pipe;
250
 
251	pipe = drm_crtc_index(crtc);
252	compo = container_of(nb, struct sti_compositor, vtg_vblank_nb[pipe]);
253	mixer = compo->mixer[pipe];
254
255	if ((event != VTG_TOP_FIELD_EVENT) &&
256	    (event != VTG_BOTTOM_FIELD_EVENT)) {
257		DRM_ERROR("unknown event: %lu\n", event);
258		return -EINVAL;
259	}
260
261	drm_crtc_handle_vblank(crtc);
262
 
 
 
 
 
 
 
 
263	if (mixer->status == STI_MIXER_DISABLING) {
264		struct drm_plane *p;
265
266		/* Disable mixer only if all overlay planes (GDP and VDP)
267		 * are disabled */
268		list_for_each_entry(p, &crtc->dev->mode_config.plane_list,
269				    head) {
270			struct sti_plane *plane = to_sti_plane(p);
271
272			if ((plane->desc & STI_PLANE_TYPE_MASK) <= STI_VDP)
273				if (plane->status != STI_PLANE_DISABLED)
274					return 0;
275		}
276		sti_crtc_disable(crtc);
277	}
278
279	return 0;
280}
281
282static int sti_crtc_enable_vblank(struct drm_crtc *crtc)
283{
284	struct drm_device *dev = crtc->dev;
285	unsigned int pipe = crtc->index;
286	struct sti_private *dev_priv = dev->dev_private;
287	struct sti_compositor *compo = dev_priv->compo;
288	struct notifier_block *vtg_vblank_nb = &compo->vtg_vblank_nb[pipe];
289	struct sti_vtg *vtg = compo->vtg[pipe];
290
291	DRM_DEBUG_DRIVER("\n");
292
293	if (sti_vtg_register_client(vtg, vtg_vblank_nb, crtc)) {
 
 
294		DRM_ERROR("Cannot register VTG notifier\n");
295		return -EINVAL;
296	}
297
298	return 0;
299}
300
301static void sti_crtc_disable_vblank(struct drm_crtc *crtc)
302{
303	struct drm_device *drm_dev = crtc->dev;
304	unsigned int pipe = crtc->index;
305	struct sti_private *priv = drm_dev->dev_private;
306	struct sti_compositor *compo = priv->compo;
307	struct notifier_block *vtg_vblank_nb = &compo->vtg_vblank_nb[pipe];
308	struct sti_vtg *vtg = compo->vtg[pipe];
309
310	DRM_DEBUG_DRIVER("\n");
311
312	if (sti_vtg_unregister_client(vtg, vtg_vblank_nb))
 
313		DRM_DEBUG_DRIVER("Warning: cannot unregister VTG notifier\n");
314}
315
316static int sti_crtc_late_register(struct drm_crtc *crtc)
317{
318	struct sti_mixer *mixer = to_sti_mixer(crtc);
319	struct sti_compositor *compo = dev_get_drvdata(mixer->dev);
320
321	if (drm_crtc_index(crtc) == 0)
322		sti_compositor_debugfs_init(compo, crtc->dev->primary);
323
324	return 0;
325}
326
327static const struct drm_crtc_funcs sti_crtc_funcs = {
328	.set_config = drm_atomic_helper_set_config,
329	.page_flip = drm_atomic_helper_page_flip,
330	.destroy = sti_crtc_destroy,
331	.set_property = sti_crtc_set_property,
332	.reset = drm_atomic_helper_crtc_reset,
333	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
334	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
335	.late_register = sti_crtc_late_register,
336	.enable_vblank = sti_crtc_enable_vblank,
337	.disable_vblank = sti_crtc_disable_vblank,
338};
339
340bool sti_crtc_is_main(struct drm_crtc *crtc)
341{
342	struct sti_mixer *mixer = to_sti_mixer(crtc);
343
344	if (mixer->id == STI_MIXER_MAIN)
345		return true;
346
347	return false;
348}
349
350int sti_crtc_init(struct drm_device *drm_dev, struct sti_mixer *mixer,
351		  struct drm_plane *primary, struct drm_plane *cursor)
352{
353	struct drm_crtc *crtc = &mixer->drm_crtc;
354	int res;
355
356	res = drm_crtc_init_with_planes(drm_dev, crtc, primary, cursor,
357					&sti_crtc_funcs, NULL);
358	if (res) {
359		DRM_ERROR("Can't initialize CRTC\n");
360		return -EINVAL;
361	}
362
363	drm_crtc_helper_add(crtc, &sti_crtc_helper_funcs);
364
365	DRM_DEBUG_DRIVER("drm CRTC:%d mapped to %s\n",
366			 crtc->base.id, sti_mixer_to_str(mixer));
367
368	return 0;
369}