Merge tag 'afs-fixes-20171124' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowe...
[sfrench/cifs-2.6.git] / drivers / gpu / drm / amd / display / dc / core / dc_hw_sequencer.c
1 /*
2  * Copyright 2015 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: AMD
23  *
24  */
25
26 #include "dm_services.h"
27 #include "core_types.h"
28 #include "timing_generator.h"
29 #include "hw_sequencer.h"
30
31 /* used as index in array of black_color_format */
32 enum black_color_format {
33         BLACK_COLOR_FORMAT_RGB_FULLRANGE = 0,
34         BLACK_COLOR_FORMAT_RGB_LIMITED,
35         BLACK_COLOR_FORMAT_YUV_TV,
36         BLACK_COLOR_FORMAT_YUV_CV,
37         BLACK_COLOR_FORMAT_YUV_SUPER_AA,
38         BLACK_COLOR_FORMAT_DEBUG,
39 };
40
41 static const struct tg_color black_color_format[] = {
42         /* BlackColorFormat_RGB_FullRange */
43         {0, 0, 0},
44         /* BlackColorFormat_RGB_Limited */
45         {0x40, 0x40, 0x40},
46         /* BlackColorFormat_YUV_TV */
47         {0x200, 0x40, 0x200},
48         /* BlackColorFormat_YUV_CV */
49         {0x1f4, 0x40, 0x1f4},
50         /* BlackColorFormat_YUV_SuperAA */
51         {0x1a2, 0x20, 0x1a2},
52         /* visual confirm debug */
53         {0xff, 0xff, 0},
54 };
55
56 void color_space_to_black_color(
57         const struct dc *dc,
58         enum dc_color_space colorspace,
59         struct tg_color *black_color)
60 {
61         switch (colorspace) {
62         case COLOR_SPACE_YCBCR601:
63         case COLOR_SPACE_YCBCR709:
64         case COLOR_SPACE_YCBCR601_LIMITED:
65         case COLOR_SPACE_YCBCR709_LIMITED:
66                 *black_color = black_color_format[BLACK_COLOR_FORMAT_YUV_CV];
67                 break;
68
69         case COLOR_SPACE_SRGB_LIMITED:
70                 *black_color =
71                         black_color_format[BLACK_COLOR_FORMAT_RGB_LIMITED];
72                 break;
73
74         default:
75                 /* fefault is sRGB black (full range). */
76                 *black_color =
77                         black_color_format[BLACK_COLOR_FORMAT_RGB_FULLRANGE];
78                 /* default is sRGB black 0. */
79                 break;
80         }
81 }
82
83 bool hwss_wait_for_blank_complete(
84                 struct timing_generator *tg)
85 {
86         int counter;
87
88         for (counter = 0; counter < 100; counter++) {
89                 if (tg->funcs->is_blanked(tg))
90                         break;
91
92                 msleep(1);
93         }
94
95         if (counter == 100) {
96                 dm_error("DC: failed to blank crtc!\n");
97                 return false;
98         }
99
100         return true;
101 }