xref: /linux/drivers/gpu/drm/tegra/plane.c (revision cb8fef4b07f71da01843457b66e579ad248a625e)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2017 NVIDIA CORPORATION.  All rights reserved.
4  */
5 
6 #include <linux/dma-mapping.h>
7 #include <linux/iommu.h>
8 #include <linux/interconnect.h>
9 
10 #include <drm/drm_atomic.h>
11 #include <drm/drm_atomic_helper.h>
12 #include <drm/drm_fourcc.h>
13 #include <drm/drm_framebuffer.h>
14 #include <drm/drm_gem_atomic_helper.h>
15 
16 #include "dc.h"
17 #include "plane.h"
18 
19 static void tegra_plane_destroy(struct drm_plane *plane)
20 {
21 	struct tegra_plane *p = to_tegra_plane(plane);
22 
23 	drm_plane_cleanup(plane);
24 	kfree(p);
25 }
26 
27 static struct drm_plane_state *tegra_plane_atomic_create_state(struct drm_plane *plane)
28 {
29 	struct tegra_plane *p = to_tegra_plane(plane);
30 	struct tegra_plane_state *state;
31 	unsigned int i;
32 
33 	state = kzalloc_obj(*state);
34 	if (!state)
35 		return ERR_PTR(-ENOMEM);
36 
37 	state->base.plane = plane;
38 	state->base.zpos = p->index;
39 	state->base.normalized_zpos = p->index;
40 
41 	for (i = 0; i < 3; i++)
42 		state->iova[i] = DMA_MAPPING_ERROR;
43 
44 	return &state->base;
45 }
46 
47 static struct drm_plane_state *
48 tegra_plane_atomic_duplicate_state(struct drm_plane *plane)
49 {
50 	struct tegra_plane_state *state = to_tegra_plane_state(plane->state);
51 	struct tegra_plane_state *copy;
52 	unsigned int i;
53 
54 	copy = kmalloc_obj(*copy);
55 	if (!copy)
56 		return NULL;
57 
58 	__drm_atomic_helper_plane_duplicate_state(plane, &copy->base);
59 	copy->tiling = state->tiling;
60 	copy->format = state->format;
61 	copy->swap = state->swap;
62 	copy->reflect_x = state->reflect_x;
63 	copy->reflect_y = state->reflect_y;
64 	copy->opaque = state->opaque;
65 	copy->total_peak_memory_bandwidth = state->total_peak_memory_bandwidth;
66 	copy->peak_memory_bandwidth = state->peak_memory_bandwidth;
67 	copy->avg_memory_bandwidth = state->avg_memory_bandwidth;
68 
69 	for (i = 0; i < 2; i++)
70 		copy->blending[i] = state->blending[i];
71 
72 	for (i = 0; i < 3; i++) {
73 		copy->iova[i] = DMA_MAPPING_ERROR;
74 		copy->map[i] = NULL;
75 	}
76 
77 	return &copy->base;
78 }
79 
80 static void tegra_plane_atomic_destroy_state(struct drm_plane *plane,
81 					     struct drm_plane_state *state)
82 {
83 	__drm_atomic_helper_plane_destroy_state(state);
84 	kfree(state);
85 }
86 
87 static bool tegra_plane_supports_sector_layout(struct drm_plane *plane)
88 {
89 	struct drm_crtc *crtc;
90 
91 	drm_for_each_crtc(crtc, plane->dev) {
92 		if (plane->possible_crtcs & drm_crtc_mask(crtc)) {
93 			struct tegra_dc *dc = to_tegra_dc(crtc);
94 
95 			if (!dc->soc->supports_sector_layout)
96 				return false;
97 		}
98 	}
99 
100 	return true;
101 }
102 
103 static bool tegra_plane_format_mod_supported(struct drm_plane *plane,
104 					     uint32_t format,
105 					     uint64_t modifier)
106 {
107 	const struct drm_format_info *info = drm_format_info(format);
108 
109 	if (modifier == DRM_FORMAT_MOD_LINEAR)
110 		return true;
111 
112 	/* check for the sector layout bit */
113 	if (fourcc_mod_is_vendor(modifier, NVIDIA)) {
114 		if (modifier & DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT) {
115 			if (!tegra_plane_supports_sector_layout(plane))
116 				return false;
117 		}
118 	}
119 
120 	if (info->num_planes == 1)
121 		return true;
122 
123 	return false;
124 }
125 
126 const struct drm_plane_funcs tegra_plane_funcs = {
127 	.update_plane = drm_atomic_helper_update_plane,
128 	.disable_plane = drm_atomic_helper_disable_plane,
129 	.destroy = tegra_plane_destroy,
130 	.atomic_create_state = tegra_plane_atomic_create_state,
131 	.atomic_duplicate_state = tegra_plane_atomic_duplicate_state,
132 	.atomic_destroy_state = tegra_plane_atomic_destroy_state,
133 	.format_mod_supported = tegra_plane_format_mod_supported,
134 };
135 
136 static int tegra_dc_pin(struct tegra_dc *dc, struct tegra_plane_state *state)
137 {
138 	unsigned int i;
139 	int err;
140 
141 	for (i = 0; i < state->base.fb->format->num_planes; i++) {
142 		struct tegra_bo *bo = tegra_fb_get_plane(state->base.fb, i);
143 		struct host1x_bo_mapping *map;
144 
145 		map = host1x_bo_pin(dc->dev, &bo->base, DMA_TO_DEVICE, &dc->client.cache);
146 		if (IS_ERR(map)) {
147 			err = PTR_ERR(map);
148 			goto unpin;
149 		}
150 
151 		if (!dc->client.group) {
152 			/*
153 			 * The display controller needs contiguous memory, so
154 			 * fail if the buffer is discontiguous and we fail to
155 			 * map its SG table to a single contiguous chunk of
156 			 * I/O virtual memory.
157 			 */
158 			if (map->chunks > 1) {
159 				err = -EINVAL;
160 				goto unpin;
161 			}
162 
163 			state->iova[i] = map->phys;
164 		} else {
165 			state->iova[i] = bo->iova;
166 		}
167 
168 		state->map[i] = map;
169 	}
170 
171 	return 0;
172 
173 unpin:
174 	dev_err(dc->dev, "failed to map plane %u: %d\n", i, err);
175 
176 	while (i--) {
177 		host1x_bo_unpin(state->map[i]);
178 		state->iova[i] = DMA_MAPPING_ERROR;
179 		state->map[i] = NULL;
180 	}
181 
182 	return err;
183 }
184 
185 static void tegra_dc_unpin(struct tegra_dc *dc, struct tegra_plane_state *state)
186 {
187 	unsigned int i;
188 
189 	for (i = 0; i < state->base.fb->format->num_planes; i++) {
190 		host1x_bo_unpin(state->map[i]);
191 		state->iova[i] = DMA_MAPPING_ERROR;
192 		state->map[i] = NULL;
193 	}
194 }
195 
196 int tegra_plane_prepare_fb(struct drm_plane *plane,
197 			   struct drm_plane_state *state)
198 {
199 	struct tegra_dc *dc = to_tegra_dc(state->crtc);
200 	int err;
201 
202 	if (!state->fb)
203 		return 0;
204 
205 	err = drm_gem_plane_helper_prepare_fb(plane, state);
206 	if (err < 0)
207 		return err;
208 
209 	return tegra_dc_pin(dc, to_tegra_plane_state(state));
210 }
211 
212 void tegra_plane_cleanup_fb(struct drm_plane *plane,
213 			    struct drm_plane_state *state)
214 {
215 	struct tegra_dc *dc = to_tegra_dc(state->crtc);
216 
217 	if (dc)
218 		tegra_dc_unpin(dc, to_tegra_plane_state(state));
219 }
220 
221 static int tegra_plane_calculate_memory_bandwidth(struct drm_plane_state *state)
222 {
223 	struct tegra_plane_state *tegra_state = to_tegra_plane_state(state);
224 	unsigned int i, bpp, dst_w, dst_h, src_w, src_h, mul;
225 	const struct tegra_dc_soc_info *soc;
226 	const struct drm_format_info *fmt;
227 	struct drm_crtc_state *crtc_state;
228 	u64 avg_bandwidth, peak_bandwidth;
229 
230 	if (!state->visible)
231 		return 0;
232 
233 	crtc_state = drm_atomic_get_new_crtc_state(state->state, state->crtc);
234 	if (!crtc_state)
235 		return -EINVAL;
236 
237 	src_w = drm_rect_width(&state->src) >> 16;
238 	src_h = drm_rect_height(&state->src) >> 16;
239 	dst_w = drm_rect_width(&state->dst);
240 	dst_h = drm_rect_height(&state->dst);
241 
242 	fmt = state->fb->format;
243 	soc = to_tegra_dc(state->crtc)->soc;
244 
245 	/*
246 	 * Note that real memory bandwidth vary depending on format and
247 	 * memory layout, we are not taking that into account because small
248 	 * estimation error isn't important since bandwidth is rounded up
249 	 * anyway.
250 	 */
251 	for (i = 0, bpp = 0; i < fmt->num_planes; i++) {
252 		unsigned int bpp_plane = fmt->cpp[i] * 8;
253 
254 		/*
255 		 * Sub-sampling is relevant for chroma planes only and vertical
256 		 * readouts are not cached, hence only horizontal sub-sampling
257 		 * matters.
258 		 */
259 		if (i > 0)
260 			bpp_plane /= fmt->hsub;
261 
262 		bpp += bpp_plane;
263 	}
264 
265 	/* average bandwidth in kbytes/sec */
266 	avg_bandwidth  = min(src_w, dst_w) * min(src_h, dst_h);
267 	avg_bandwidth *= drm_mode_vrefresh(&crtc_state->adjusted_mode);
268 	avg_bandwidth  = DIV_ROUND_UP(avg_bandwidth * bpp, 8) + 999;
269 	do_div(avg_bandwidth, 1000);
270 
271 	/* mode.clock in kHz, peak bandwidth in kbytes/sec */
272 	peak_bandwidth = DIV_ROUND_UP(crtc_state->adjusted_mode.clock * bpp, 8);
273 
274 	/*
275 	 * Tegra30/114 Memory Controller can't interleave DC memory requests
276 	 * for the tiled windows because DC uses 16-bytes atom, while DDR3
277 	 * uses 32-bytes atom.  Hence there is x2 memory overfetch for tiled
278 	 * framebuffer and DDR3 on these SoCs.
279 	 */
280 	if (soc->plane_tiled_memory_bandwidth_x2 &&
281 	    tegra_state->tiling.mode == TEGRA_BO_TILING_MODE_TILED)
282 		mul = 2;
283 	else
284 		mul = 1;
285 
286 	/* ICC bandwidth in kbytes/sec */
287 	tegra_state->peak_memory_bandwidth = kBps_to_icc(peak_bandwidth) * mul;
288 	tegra_state->avg_memory_bandwidth  = kBps_to_icc(avg_bandwidth)  * mul;
289 
290 	return 0;
291 }
292 
293 int tegra_plane_state_add(struct tegra_plane *plane,
294 			  struct drm_plane_state *state)
295 {
296 	struct drm_crtc_state *crtc_state;
297 	struct tegra_dc_state *tegra;
298 	int err;
299 
300 	/* Propagate errors from allocation or locking failures. */
301 	crtc_state = drm_atomic_get_crtc_state(state->state, state->crtc);
302 	if (IS_ERR(crtc_state))
303 		return PTR_ERR(crtc_state);
304 
305 	/* Check plane state for visibility and calculate clipping bounds */
306 	err = drm_atomic_helper_check_plane_state(state, crtc_state,
307 						  0, INT_MAX, true, true);
308 	if (err < 0)
309 		return err;
310 
311 	err = tegra_plane_calculate_memory_bandwidth(state);
312 	if (err < 0)
313 		return err;
314 
315 	tegra = to_dc_state(crtc_state);
316 
317 	tegra->planes |= WIN_A_ACT_REQ << plane->index;
318 
319 	return 0;
320 }
321 
322 int tegra_plane_format(u32 fourcc, u32 *format, u32 *swap)
323 {
324 	/* assume no swapping of fetched data */
325 	if (swap)
326 		*swap = BYTE_SWAP_NOSWAP;
327 
328 	switch (fourcc) {
329 	case DRM_FORMAT_ARGB4444:
330 		*format = WIN_COLOR_DEPTH_B4G4R4A4;
331 		break;
332 
333 	case DRM_FORMAT_ARGB1555:
334 		*format = WIN_COLOR_DEPTH_B5G5R5A1;
335 		break;
336 
337 	case DRM_FORMAT_RGB565:
338 		*format = WIN_COLOR_DEPTH_B5G6R5;
339 		break;
340 
341 	case DRM_FORMAT_RGBA5551:
342 		*format = WIN_COLOR_DEPTH_A1B5G5R5;
343 		break;
344 
345 	case DRM_FORMAT_ARGB8888:
346 		*format = WIN_COLOR_DEPTH_B8G8R8A8;
347 		break;
348 
349 	case DRM_FORMAT_ABGR8888:
350 		*format = WIN_COLOR_DEPTH_R8G8B8A8;
351 		break;
352 
353 	case DRM_FORMAT_ABGR4444:
354 		*format = WIN_COLOR_DEPTH_R4G4B4A4;
355 		break;
356 
357 	case DRM_FORMAT_ABGR1555:
358 		*format = WIN_COLOR_DEPTH_R5G5B5A;
359 		break;
360 
361 	case DRM_FORMAT_BGRA5551:
362 		*format = WIN_COLOR_DEPTH_AR5G5B5;
363 		break;
364 
365 	case DRM_FORMAT_XRGB1555:
366 		*format = WIN_COLOR_DEPTH_B5G5R5X1;
367 		break;
368 
369 	case DRM_FORMAT_RGBX5551:
370 		*format = WIN_COLOR_DEPTH_X1B5G5R5;
371 		break;
372 
373 	case DRM_FORMAT_XBGR1555:
374 		*format = WIN_COLOR_DEPTH_R5G5B5X1;
375 		break;
376 
377 	case DRM_FORMAT_BGRX5551:
378 		*format = WIN_COLOR_DEPTH_X1R5G5B5;
379 		break;
380 
381 	case DRM_FORMAT_BGR565:
382 		*format = WIN_COLOR_DEPTH_R5G6B5;
383 		break;
384 
385 	case DRM_FORMAT_BGRA8888:
386 		*format = WIN_COLOR_DEPTH_A8R8G8B8;
387 		break;
388 
389 	case DRM_FORMAT_RGBA8888:
390 		*format = WIN_COLOR_DEPTH_A8B8G8R8;
391 		break;
392 
393 	case DRM_FORMAT_XRGB8888:
394 		*format = WIN_COLOR_DEPTH_B8G8R8X8;
395 		break;
396 
397 	case DRM_FORMAT_XBGR8888:
398 		*format = WIN_COLOR_DEPTH_R8G8B8X8;
399 		break;
400 
401 	case DRM_FORMAT_UYVY:
402 		*format = WIN_COLOR_DEPTH_YCbCr422;
403 		break;
404 
405 	case DRM_FORMAT_YUYV:
406 		if (!swap)
407 			return -EINVAL;
408 
409 		*format = WIN_COLOR_DEPTH_YCbCr422;
410 		*swap = BYTE_SWAP_SWAP2;
411 		break;
412 
413 	case DRM_FORMAT_YVYU:
414 		if (!swap)
415 			return -EINVAL;
416 
417 		*format = WIN_COLOR_DEPTH_YCbCr422;
418 		*swap = BYTE_SWAP_SWAP4;
419 		break;
420 
421 	case DRM_FORMAT_VYUY:
422 		if (!swap)
423 			return -EINVAL;
424 
425 		*format = WIN_COLOR_DEPTH_YCbCr422;
426 		*swap = BYTE_SWAP_SWAP4HW;
427 		break;
428 
429 	case DRM_FORMAT_YUV420:
430 		*format = WIN_COLOR_DEPTH_YCbCr420P;
431 		break;
432 
433 	case DRM_FORMAT_YUV422:
434 		*format = WIN_COLOR_DEPTH_YCbCr422P;
435 		break;
436 
437 	case DRM_FORMAT_YUV444:
438 		*format = WIN_COLOR_DEPTH_YCbCr444P;
439 		break;
440 
441 	case DRM_FORMAT_NV12:
442 		*format = WIN_COLOR_DEPTH_YCbCr420SP;
443 		break;
444 
445 	case DRM_FORMAT_NV21:
446 		*format = WIN_COLOR_DEPTH_YCrCb420SP;
447 		break;
448 
449 	case DRM_FORMAT_NV16:
450 		*format = WIN_COLOR_DEPTH_YCbCr422SP;
451 		break;
452 
453 	case DRM_FORMAT_NV61:
454 		*format = WIN_COLOR_DEPTH_YCrCb422SP;
455 		break;
456 
457 	case DRM_FORMAT_NV24:
458 		*format = WIN_COLOR_DEPTH_YCbCr444SP;
459 		break;
460 
461 	case DRM_FORMAT_NV42:
462 		*format = WIN_COLOR_DEPTH_YCrCb444SP;
463 		break;
464 
465 	default:
466 		return -EINVAL;
467 	}
468 
469 	return 0;
470 }
471 
472 bool tegra_plane_format_is_indexed(unsigned int format)
473 {
474 	switch (format) {
475 	case WIN_COLOR_DEPTH_P1:
476 	case WIN_COLOR_DEPTH_P2:
477 	case WIN_COLOR_DEPTH_P4:
478 	case WIN_COLOR_DEPTH_P8:
479 		return true;
480 	}
481 
482 	return false;
483 }
484 
485 bool tegra_plane_format_is_yuv(unsigned int format, unsigned int *planes, unsigned int *bpc)
486 {
487 	switch (format) {
488 	case WIN_COLOR_DEPTH_YCbCr422:
489 	case WIN_COLOR_DEPTH_YUV422:
490 		if (planes)
491 			*planes = 1;
492 
493 		if (bpc)
494 			*bpc = 8;
495 
496 		return true;
497 
498 	case WIN_COLOR_DEPTH_YCbCr420P:
499 	case WIN_COLOR_DEPTH_YUV420P:
500 	case WIN_COLOR_DEPTH_YCbCr422P:
501 	case WIN_COLOR_DEPTH_YUV422P:
502 	case WIN_COLOR_DEPTH_YCbCr422R:
503 	case WIN_COLOR_DEPTH_YUV422R:
504 	case WIN_COLOR_DEPTH_YCbCr422RA:
505 	case WIN_COLOR_DEPTH_YUV422RA:
506 	case WIN_COLOR_DEPTH_YCbCr444P:
507 		if (planes)
508 			*planes = 3;
509 
510 		if (bpc)
511 			*bpc = 8;
512 
513 		return true;
514 
515 	case WIN_COLOR_DEPTH_YCrCb420SP:
516 	case WIN_COLOR_DEPTH_YCbCr420SP:
517 	case WIN_COLOR_DEPTH_YCrCb422SP:
518 	case WIN_COLOR_DEPTH_YCbCr422SP:
519 	case WIN_COLOR_DEPTH_YCrCb444SP:
520 	case WIN_COLOR_DEPTH_YCbCr444SP:
521 		if (planes)
522 			*planes = 2;
523 
524 		if (bpc)
525 			*bpc = 8;
526 
527 		return true;
528 	}
529 
530 	if (planes)
531 		*planes = 1;
532 
533 	return false;
534 }
535 
536 static bool __drm_format_has_alpha(u32 format)
537 {
538 	switch (format) {
539 	case DRM_FORMAT_ARGB1555:
540 	case DRM_FORMAT_RGBA5551:
541 	case DRM_FORMAT_ABGR8888:
542 	case DRM_FORMAT_ARGB8888:
543 		return true;
544 	}
545 
546 	return false;
547 }
548 
549 static int tegra_plane_format_get_alpha(unsigned int opaque,
550 					unsigned int *alpha)
551 {
552 	if (tegra_plane_format_is_yuv(opaque, NULL, NULL)) {
553 		*alpha = opaque;
554 		return 0;
555 	}
556 
557 	switch (opaque) {
558 	case WIN_COLOR_DEPTH_B5G5R5X1:
559 		*alpha = WIN_COLOR_DEPTH_B5G5R5A1;
560 		return 0;
561 
562 	case WIN_COLOR_DEPTH_X1B5G5R5:
563 		*alpha = WIN_COLOR_DEPTH_A1B5G5R5;
564 		return 0;
565 
566 	case WIN_COLOR_DEPTH_R8G8B8X8:
567 		*alpha = WIN_COLOR_DEPTH_R8G8B8A8;
568 		return 0;
569 
570 	case WIN_COLOR_DEPTH_B8G8R8X8:
571 		*alpha = WIN_COLOR_DEPTH_B8G8R8A8;
572 		return 0;
573 
574 	case WIN_COLOR_DEPTH_B5G6R5:
575 		*alpha = opaque;
576 		return 0;
577 	}
578 
579 	return -EINVAL;
580 }
581 
582 /*
583  * This is applicable to Tegra20 and Tegra30 only where the opaque formats can
584  * be emulated using the alpha formats and alpha blending disabled.
585  */
586 static int tegra_plane_setup_opacity(struct tegra_plane *tegra,
587 				     struct tegra_plane_state *state)
588 {
589 	unsigned int format;
590 	int err;
591 
592 	switch (state->format) {
593 	case WIN_COLOR_DEPTH_B5G5R5A1:
594 	case WIN_COLOR_DEPTH_A1B5G5R5:
595 	case WIN_COLOR_DEPTH_R8G8B8A8:
596 	case WIN_COLOR_DEPTH_B8G8R8A8:
597 		state->opaque = false;
598 		break;
599 
600 	default:
601 		err = tegra_plane_format_get_alpha(state->format, &format);
602 		if (err < 0)
603 			return err;
604 
605 		state->format = format;
606 		state->opaque = true;
607 		break;
608 	}
609 
610 	return 0;
611 }
612 
613 static int tegra_plane_check_transparency(struct tegra_plane *tegra,
614 					  struct tegra_plane_state *state)
615 {
616 	struct drm_plane_state *old, *plane_state;
617 	struct drm_plane *plane;
618 
619 	old = drm_atomic_get_old_plane_state(state->base.state, &tegra->base);
620 
621 	/* check if zpos / transparency changed */
622 	if (old->normalized_zpos == state->base.normalized_zpos &&
623 	    to_tegra_plane_state(old)->opaque == state->opaque)
624 		return 0;
625 
626 	/* include all sibling planes into this commit */
627 	drm_for_each_plane(plane, tegra->base.dev) {
628 		struct tegra_plane *p = to_tegra_plane(plane);
629 
630 		/* skip this plane and planes on different CRTCs */
631 		if (p == tegra || p->dc != tegra->dc)
632 			continue;
633 
634 		plane_state = drm_atomic_get_plane_state(state->base.state,
635 							 plane);
636 		if (IS_ERR(plane_state))
637 			return PTR_ERR(plane_state);
638 	}
639 
640 	return 1;
641 }
642 
643 static unsigned int tegra_plane_get_overlap_index(struct tegra_plane *plane,
644 						  struct tegra_plane *other)
645 {
646 	unsigned int index = 0, i;
647 
648 	WARN_ON(plane == other);
649 
650 	for (i = 0; i < 3; i++) {
651 		if (i == plane->index)
652 			continue;
653 
654 		if (i == other->index)
655 			break;
656 
657 		index++;
658 	}
659 
660 	return index;
661 }
662 
663 static void tegra_plane_update_transparency(struct tegra_plane *tegra,
664 					    struct tegra_plane_state *state)
665 {
666 	struct drm_plane_state *new;
667 	struct drm_plane *plane;
668 	unsigned int i;
669 
670 	for_each_new_plane_in_state(state->base.state, plane, new, i) {
671 		struct tegra_plane *p = to_tegra_plane(plane);
672 		unsigned index;
673 
674 		/* skip this plane and planes on different CRTCs */
675 		if (p == tegra || p->dc != tegra->dc)
676 			continue;
677 
678 		index = tegra_plane_get_overlap_index(tegra, p);
679 
680 		if (new->fb && __drm_format_has_alpha(new->fb->format->format))
681 			state->blending[index].alpha = true;
682 		else
683 			state->blending[index].alpha = false;
684 
685 		if (new->normalized_zpos > state->base.normalized_zpos)
686 			state->blending[index].top = true;
687 		else
688 			state->blending[index].top = false;
689 
690 		/*
691 		 * Missing framebuffer means that plane is disabled, in this
692 		 * case mark B / C window as top to be able to differentiate
693 		 * windows indices order in regards to zPos for the middle
694 		 * window X / Y registers programming.
695 		 */
696 		if (!new->fb)
697 			state->blending[index].top = (index == 1);
698 	}
699 }
700 
701 static int tegra_plane_setup_transparency(struct tegra_plane *tegra,
702 					  struct tegra_plane_state *state)
703 {
704 	struct tegra_plane_state *tegra_state;
705 	struct drm_plane_state *new;
706 	struct drm_plane *plane;
707 	int err;
708 
709 	/*
710 	 * If planes zpos / transparency changed, sibling planes blending
711 	 * state may require adjustment and in this case they will be included
712 	 * into this atom commit, otherwise blending state is unchanged.
713 	 */
714 	err = tegra_plane_check_transparency(tegra, state);
715 	if (err <= 0)
716 		return err;
717 
718 	/*
719 	 * All planes are now in the atomic state, walk them up and update
720 	 * transparency state for each plane.
721 	 */
722 	drm_for_each_plane(plane, tegra->base.dev) {
723 		struct tegra_plane *p = to_tegra_plane(plane);
724 
725 		/* skip planes on different CRTCs */
726 		if (p->dc != tegra->dc)
727 			continue;
728 
729 		new = drm_atomic_get_new_plane_state(state->base.state, plane);
730 		tegra_state = to_tegra_plane_state(new);
731 
732 		/*
733 		 * There is no need to update blending state for the disabled
734 		 * plane.
735 		 */
736 		if (new->fb)
737 			tegra_plane_update_transparency(p, tegra_state);
738 	}
739 
740 	return 0;
741 }
742 
743 int tegra_plane_setup_legacy_state(struct tegra_plane *tegra,
744 				   struct tegra_plane_state *state)
745 {
746 	int err;
747 
748 	err = tegra_plane_setup_opacity(tegra, state);
749 	if (err < 0)
750 		return err;
751 
752 	err = tegra_plane_setup_transparency(tegra, state);
753 	if (err < 0)
754 		return err;
755 
756 	return 0;
757 }
758 
759 static const char * const tegra_plane_icc_names[TEGRA_DC_LEGACY_PLANES_NUM] = {
760 	"wina", "winb", "winc", NULL, NULL, NULL, "cursor",
761 };
762 
763 int tegra_plane_interconnect_init(struct tegra_plane *plane)
764 {
765 	const char *icc_name = tegra_plane_icc_names[plane->index];
766 	struct device *dev = plane->dc->dev;
767 	struct tegra_dc *dc = plane->dc;
768 	int err;
769 
770 	if (WARN_ON(plane->index >= TEGRA_DC_LEGACY_PLANES_NUM) ||
771 	    WARN_ON(!tegra_plane_icc_names[plane->index]))
772 		return -EINVAL;
773 
774 	plane->icc_mem = devm_of_icc_get(dev, icc_name);
775 	err = PTR_ERR_OR_ZERO(plane->icc_mem);
776 	if (err)
777 		return dev_err_probe(dev, err, "failed to get %s interconnect\n",
778 				     icc_name);
779 
780 	/* plane B on T20/30 has a dedicated memory client for a 6-tap vertical filter */
781 	if (plane->index == 1 && dc->soc->has_win_b_vfilter_mem_client) {
782 		plane->icc_mem_vfilter = devm_of_icc_get(dev, "winb-vfilter");
783 		err = PTR_ERR_OR_ZERO(plane->icc_mem_vfilter);
784 		if (err)
785 			return dev_err_probe(dev, err, "failed to get %s interconnect\n",
786 					     "winb-vfilter");
787 	}
788 
789 	return 0;
790 }
791