1 /* 2 * Copyright (c) 2015-2016, 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 <ctype.h> 31 #include <math.h> 32 #include <fcntl.h> 33 #include <inttypes.h> 34 #include <sys/types.h> 35 #include <sys/stat.h> 36 #include <sys/resource.h> 37 #include <sys/prctl.h> 38 #include <linux/msm_mdp.h> 39 #include <utils/constants.h> 40 #include <utils/debug.h> 41 #include "hw_color_manager.h" 42 43 #define __CLASS__ "HWColorManager" 44 45 namespace sdm { 46 47 DisplayError (*HWColorManager::SetFeature[])(const PPFeatureInfo &, msmfb_mdp_pp *) = { 48 [kGlobalColorFeaturePcc] = &HWColorManager::SetPCC, 49 [kGlobalColorFeatureIgc] = &HWColorManager::SetIGC, 50 [kGlobalColorFeaturePgc] = &HWColorManager::SetPGC, 51 [kMixerColorFeatureGc] = &HWColorManager::SetMixerGC, 52 [kGlobalColorFeaturePaV2] = &HWColorManager::SetPAV2, 53 [kGlobalColorFeatureDither] = &HWColorManager::SetDither, 54 [kGlobalColorFeatureGamut] = &HWColorManager::SetGamut, 55 [kGlobalColorFeaturePADither] = &HWColorManager::SetPADither, 56 }; 57 58 DisplayError HWColorManager::SetPCC(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params) { 59 DisplayError ret = kErrorNone; 60 61 kernel_params->op = mdp_op_pcc_cfg; 62 kernel_params->data.pcc_cfg_data.version = feature.feature_version_; 63 kernel_params->data.pcc_cfg_data.block = MDP_LOGICAL_BLOCK_DISP_0 + feature.disp_id_; 64 kernel_params->data.pcc_cfg_data.ops = feature.enable_flags_; 65 kernel_params->data.pcc_cfg_data.cfg_payload = feature.GetConfigData(); 66 DLOGV_IF(kTagQDCM, "kernel params version = %d, block = %d, flags = %d", 67 kernel_params->data.pcc_cfg_data.version, kernel_params->data.pcc_cfg_data.block, 68 kernel_params->data.pcc_cfg_data.ops); 69 70 return ret; 71 } 72 73 DisplayError HWColorManager::SetIGC(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params) { 74 DisplayError ret = kErrorNone; 75 76 kernel_params->op = mdp_op_lut_cfg; 77 kernel_params->data.lut_cfg_data.lut_type = mdp_lut_igc; 78 kernel_params->data.lut_cfg_data.data.igc_lut_data.block = 79 MDP_LOGICAL_BLOCK_DISP_0 + feature.disp_id_; 80 kernel_params->data.lut_cfg_data.data.igc_lut_data.version = feature.feature_version_; 81 kernel_params->data.lut_cfg_data.data.igc_lut_data.ops = feature.enable_flags_; 82 kernel_params->data.lut_cfg_data.data.igc_lut_data.cfg_payload = feature.GetConfigData(); 83 84 return ret; 85 } 86 87 DisplayError HWColorManager::SetPGC(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params) { 88 DisplayError ret = kErrorNone; 89 90 kernel_params->op = mdp_op_lut_cfg; 91 kernel_params->data.lut_cfg_data.lut_type = mdp_lut_pgc; 92 kernel_params->data.lut_cfg_data.data.pgc_lut_data.version = feature.feature_version_; 93 kernel_params->data.lut_cfg_data.data.pgc_lut_data.block = 94 MDP_LOGICAL_BLOCK_DISP_0 + feature.disp_id_; 95 kernel_params->data.lut_cfg_data.data.pgc_lut_data.flags = feature.enable_flags_; 96 kernel_params->data.lut_cfg_data.data.pgc_lut_data.cfg_payload = feature.GetConfigData(); 97 98 return ret; 99 } 100 101 DisplayError HWColorManager::SetMixerGC(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params) { 102 DisplayError ret = kErrorNone; 103 104 kernel_params->op = mdp_op_lut_cfg; 105 kernel_params->data.lut_cfg_data.lut_type = mdp_lut_pgc; 106 kernel_params->data.lut_cfg_data.data.pgc_lut_data.version = feature.feature_version_; 107 kernel_params->data.lut_cfg_data.data.pgc_lut_data.block = 108 (MDP_LOGICAL_BLOCK_DISP_0 + feature.disp_id_) | MDSS_PP_LM_CFG; 109 kernel_params->data.lut_cfg_data.data.pgc_lut_data.flags = feature.enable_flags_; 110 kernel_params->data.lut_cfg_data.data.pgc_lut_data.cfg_payload = feature.GetConfigData(); 111 return ret; 112 } 113 114 DisplayError HWColorManager::SetPAV2(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params) { 115 DisplayError ret = kErrorNone; 116 117 kernel_params->op = mdp_op_pa_v2_cfg; 118 kernel_params->data.pa_v2_cfg_data.version = feature.feature_version_; 119 kernel_params->data.pa_v2_cfg_data.block = MDP_LOGICAL_BLOCK_DISP_0 + feature.disp_id_; 120 kernel_params->data.pa_v2_cfg_data.flags = feature.enable_flags_; 121 kernel_params->data.pa_v2_cfg_data.cfg_payload = feature.GetConfigData(); 122 DLOGV_IF(kTagQDCM, "kernel params version = %d, block = %d, flags = %d", 123 kernel_params->data.pa_v2_cfg_data.version, kernel_params->data.pa_v2_cfg_data.block, 124 kernel_params->data.pa_v2_cfg_data.flags); 125 126 return ret; 127 } 128 129 DisplayError HWColorManager::SetDither(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params) { 130 DisplayError ret = kErrorNone; 131 132 kernel_params->op = mdp_op_dither_cfg; 133 kernel_params->data.dither_cfg_data.version = feature.feature_version_; 134 kernel_params->data.dither_cfg_data.block = MDP_LOGICAL_BLOCK_DISP_0 + feature.disp_id_; 135 kernel_params->data.dither_cfg_data.flags = feature.enable_flags_; 136 kernel_params->data.dither_cfg_data.cfg_payload = feature.GetConfigData(); 137 138 return ret; 139 } 140 141 DisplayError HWColorManager::SetGamut(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params) { 142 DisplayError ret = kErrorNone; 143 144 kernel_params->op = mdp_op_gamut_cfg; 145 kernel_params->data.gamut_cfg_data.version = feature.feature_version_; 146 kernel_params->data.gamut_cfg_data.block = MDP_LOGICAL_BLOCK_DISP_0 + feature.disp_id_; 147 kernel_params->data.gamut_cfg_data.flags = feature.enable_flags_; 148 kernel_params->data.gamut_cfg_data.cfg_payload = feature.GetConfigData(); 149 150 return ret; 151 } 152 153 DisplayError HWColorManager::SetPADither(const PPFeatureInfo &feature, 154 msmfb_mdp_pp *kernel_params) { 155 DisplayError ret = kErrorNone; 156 157 // TODO(user): Kernel IOCTL preparation 158 159 return ret; 160 } 161 162 } // namespace sdm 163