1 /*
2 * Copyright (c) 2014 - 2018, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <stdlib.h>
31 #include <utils/debug.h>
32 #include <utils/constants.h>
33 #include <string>
34 #include <algorithm>
35
36 namespace sdm {
37
38 Debug Debug::debug_;
39
Debug()40 Debug::Debug() : debug_handler_(&default_debug_handler_) {
41 }
42
GetSimulationFlag()43 int Debug::GetSimulationFlag() {
44 int value = 0;
45 debug_.debug_handler_->GetProperty(COMPOSITION_MASK_PROP, &value);
46
47 return value;
48 }
49
GetHDMIResolution()50 int Debug::GetHDMIResolution() {
51 int value = 0;
52 debug_.debug_handler_->GetProperty(HDMI_CONFIG_INDEX_PROP, &value);
53 return value;
54 }
55
GetIdleTimeoutMs(uint32_t * active_ms,uint32_t * inactive_ms)56 void Debug::GetIdleTimeoutMs(uint32_t *active_ms, uint32_t *inactive_ms) {
57 int active_val = IDLE_TIMEOUT_ACTIVE_MS;
58 int inactive_val = IDLE_TIMEOUT_INACTIVE_MS;
59
60 debug_.debug_handler_->GetProperty(IDLE_TIME_PROP, &active_val);
61 debug_.debug_handler_->GetProperty(IDLE_TIME_INACTIVE_PROP, &inactive_val);
62
63 *active_ms = UINT32(active_val);
64 *inactive_ms = UINT32(inactive_val);
65 }
66
GetBootAnimLayerCount()67 int Debug::GetBootAnimLayerCount() {
68 int value = 0;
69 debug_.debug_handler_->GetProperty(BOOT_ANIMATION_LAYER_COUNT_PROP, &value);
70
71 return value;
72 }
73
IsRotatorDownScaleDisabled()74 bool Debug::IsRotatorDownScaleDisabled() {
75 int value = 0;
76 debug_.debug_handler_->GetProperty(DISABLE_ROTATOR_DOWNSCALE_PROP, &value);
77
78 return (value == 1);
79 }
80
IsDecimationDisabled()81 bool Debug::IsDecimationDisabled() {
82 int value = 0;
83 debug_.debug_handler_->GetProperty(DISABLE_DECIMATION_PROP, &value);
84
85 return (value == 1);
86 }
87
GetMaxPipesPerMixer(DisplayType display_type)88 int Debug::GetMaxPipesPerMixer(DisplayType display_type) {
89 int value = -1;
90 switch (display_type) {
91 case kPrimary:
92 debug_.debug_handler_->GetProperty(PRIMARY_MIXER_STAGES_PROP, &value);
93 break;
94 case kHDMI:
95 debug_.debug_handler_->GetProperty(EXTERNAL_MIXER_STAGES_PROP, &value);
96 break;
97 case kVirtual:
98 debug_.debug_handler_->GetProperty(VIRTUAL_MIXER_STAGES_PROP, &value);
99 break;
100 default:
101 break;
102 }
103
104 return value;
105 }
106
GetMaxUpscale()107 int Debug::GetMaxUpscale() {
108 int value = 0;
109 debug_.debug_handler_->GetProperty(MAX_UPSCALE_PROP, &value);
110
111 return value;
112 }
113
IsVideoModeEnabled()114 bool Debug::IsVideoModeEnabled() {
115 int value = 0;
116 debug_.debug_handler_->GetProperty(VIDEO_MODE_PANEL_PROP, &value);
117
118 return (value == 1);
119 }
120
IsRotatorUbwcDisabled()121 bool Debug::IsRotatorUbwcDisabled() {
122 int value = 0;
123 debug_.debug_handler_->GetProperty(DISABLE_ROTATOR_UBWC_PROP, &value);
124
125 return (value == 1);
126 }
127
IsRotatorSplitDisabled()128 bool Debug::IsRotatorSplitDisabled() {
129 int value = 0;
130 debug_.debug_handler_->GetProperty(DISABLE_ROTATOR_SPLIT_PROP, &value);
131
132 return (value == 1);
133 }
134
IsScalarDisabled()135 bool Debug::IsScalarDisabled() {
136 int value = 0;
137 debug_.debug_handler_->GetProperty(DISABLE_SCALER_PROP, &value);
138
139 return (value == 1);
140 }
141
IsUbwcTiledFrameBuffer()142 bool Debug::IsUbwcTiledFrameBuffer() {
143 int ubwc_disabled = 0;
144 int ubwc_framebuffer = 0;
145
146 debug_.debug_handler_->GetProperty(DISABLE_UBWC_PROP, &ubwc_disabled);
147
148 if (!ubwc_disabled) {
149 debug_.debug_handler_->GetProperty(ENABLE_FB_UBWC_PROP, &ubwc_framebuffer);
150 }
151
152 return (ubwc_framebuffer == 1);
153 }
154
IsAVRDisabled()155 bool Debug::IsAVRDisabled() {
156 int value = 0;
157 debug_.debug_handler_->GetProperty(DISABLE_AVR_PROP, &value);
158
159 return (value == 1);
160 }
161
IsExtAnimDisabled()162 bool Debug::IsExtAnimDisabled() {
163 int value = 0;
164 debug_.debug_handler_->GetProperty(DISABLE_EXTERNAL_ANIMATION_PROP, &value);
165
166 return (value == 1);
167 }
168
IsPartialSplitDisabled()169 bool Debug::IsPartialSplitDisabled() {
170 int value = 0;
171 debug_.debug_handler_->GetProperty(DISABLE_PARTIAL_SPLIT_PROP, &value);
172
173 return (value == 1);
174 }
175
GetMixerResolution(uint32_t * width,uint32_t * height)176 DisplayError Debug::GetMixerResolution(uint32_t *width, uint32_t *height) {
177 char value[64] = {};
178
179 DisplayError error = debug_.debug_handler_->GetProperty(MIXER_RESOLUTION_PROP, value);
180 if (error !=kErrorNone) {
181 return error;
182 }
183
184 std::string str(value);
185
186 *width = UINT32(stoi(str));
187 *height = UINT32(stoi(str.substr(str.find('x') + 1)));
188
189 return kErrorNone;
190 }
191
GetExtMaxlayers()192 int Debug::GetExtMaxlayers() {
193 int max_external_layers = 0;
194 debug_.debug_handler_->GetProperty(MAX_EXTERNAL_LAYERS_PROP, &max_external_layers);
195
196 return std::max(max_external_layers, 2);
197 }
198
GetProperty(const char * property_name,char * value)199 bool Debug::GetProperty(const char* property_name, char* value) {
200 if (debug_.debug_handler_->GetProperty(property_name, value) != kErrorNone) {
201 return false;
202 }
203
204 return true;
205 }
206
SetProperty(const char * property_name,const char * value)207 bool Debug::SetProperty(const char* property_name, const char* value) {
208 if (debug_.debug_handler_->SetProperty(property_name, value) != kErrorNone) {
209 return false;
210 }
211
212 return true;
213 }
214
215 } // namespace sdm
216
217