Saurabh Shah | 82b06f4 | 2017-09-06 16:43:49 -0700 | [diff] [blame] | 1 | /* |
Xu Yang | 32e58c2 | 2017-11-20 09:58:11 +0800 | [diff] [blame] | 2 | Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. |
Saurabh Shah | 82b06f4 | 2017-09-06 16:43:49 -0700 | [diff] [blame] | 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 <utils/debug.h> |
| 31 | |
| 32 | #include "hw_peripheral_drm.h" |
| 33 | |
| 34 | #define __CLASS__ "HWPeripheralDRM" |
| 35 | |
| 36 | using sde_drm::DRMDisplayType; |
| 37 | using sde_drm::DRMOps; |
Saurabh Shah | 82b06f4 | 2017-09-06 16:43:49 -0700 | [diff] [blame] | 38 | using sde_drm::DRMPowerMode; |
Xu Yang | 32e58c2 | 2017-11-20 09:58:11 +0800 | [diff] [blame] | 39 | using sde_drm::DRMDppsFeatureInfo; |
Saurabh Shah | 82b06f4 | 2017-09-06 16:43:49 -0700 | [diff] [blame] | 40 | |
| 41 | namespace sdm { |
| 42 | |
| 43 | HWPeripheralDRM::HWPeripheralDRM(BufferSyncHandler *buffer_sync_handler, |
| 44 | BufferAllocator *buffer_allocator, |
| 45 | HWInfoInterface *hw_info_intf) |
| 46 | : HWDeviceDRM(buffer_sync_handler, buffer_allocator, hw_info_intf) { |
| 47 | disp_type_ = DRMDisplayType::PERIPHERAL; |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame^] | 48 | device_name_ = "Peripheral"; |
Saurabh Shah | 82b06f4 | 2017-09-06 16:43:49 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | DisplayError HWPeripheralDRM::Init() { |
| 52 | DisplayError ret = HWDeviceDRM::Init(); |
| 53 | if (ret != kErrorNone) { |
| 54 | DLOGE("Init failed for %s", device_name_); |
| 55 | return ret; |
| 56 | } |
| 57 | |
Ramkumar Radhakrishnan | 7e971e0 | 2017-08-17 14:19:15 +0530 | [diff] [blame] | 58 | scalar_data_.resize(hw_resource_.hw_dest_scalar_info.count); |
| 59 | |
Saurabh Shah | 82b06f4 | 2017-09-06 16:43:49 -0700 | [diff] [blame] | 60 | return kErrorNone; |
| 61 | } |
| 62 | |
| 63 | DisplayError HWPeripheralDRM::Validate(HWLayers *hw_layers) { |
Ramkumar Radhakrishnan | 7e971e0 | 2017-08-17 14:19:15 +0530 | [diff] [blame] | 64 | HWLayersInfo &hw_layer_info = hw_layers->info; |
Ramkumar Radhakrishnan | 7e971e0 | 2017-08-17 14:19:15 +0530 | [diff] [blame] | 65 | SetDestScalarData(hw_layer_info); |
Saurabh Shah | 82b06f4 | 2017-09-06 16:43:49 -0700 | [diff] [blame] | 66 | |
| 67 | return HWDeviceDRM::Validate(hw_layers); |
| 68 | } |
| 69 | |
Ramkumar Radhakrishnan | 7e971e0 | 2017-08-17 14:19:15 +0530 | [diff] [blame] | 70 | DisplayError HWPeripheralDRM::Commit(HWLayers *hw_layers) { |
| 71 | HWLayersInfo &hw_layer_info = hw_layers->info; |
| 72 | SetDestScalarData(hw_layer_info); |
| 73 | |
| 74 | return HWDeviceDRM::Commit(hw_layers); |
| 75 | } |
| 76 | |
Ramkumar Radhakrishnan | 7e971e0 | 2017-08-17 14:19:15 +0530 | [diff] [blame] | 77 | void HWPeripheralDRM::ResetDisplayParams() { |
| 78 | sde_dest_scalar_data_ = {}; |
| 79 | for (uint32_t j = 0; j < scalar_data_.size(); j++) { |
| 80 | scalar_data_[j] = {}; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | void HWPeripheralDRM::SetDestScalarData(HWLayersInfo hw_layer_info) { |
| 85 | if (!hw_resource_.hw_dest_scalar_info.count) { |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | uint32_t index = 0; |
| 90 | for (uint32_t i = 0; i < hw_resource_.hw_dest_scalar_info.count; i++) { |
| 91 | DestScaleInfoMap::iterator it = hw_layer_info.dest_scale_info_map.find(i); |
| 92 | |
| 93 | if (it == hw_layer_info.dest_scale_info_map.end()) { |
| 94 | continue; |
| 95 | } |
| 96 | |
| 97 | HWDestScaleInfo *dest_scale_info = it->second; |
| 98 | SDEScaler *scale = &scalar_data_[index]; |
| 99 | hw_scale_->SetScaler(dest_scale_info->scale_data, scale); |
| 100 | sde_drm_dest_scaler_cfg *dest_scalar_data = &sde_dest_scalar_data_.ds_cfg[index]; |
| 101 | dest_scalar_data->flags = 0; |
| 102 | if (scale->scaler_v2.enable) { |
| 103 | dest_scalar_data->flags |= SDE_DRM_DESTSCALER_ENABLE; |
| 104 | } |
| 105 | if (scale->scaler_v2.de.enable) { |
| 106 | dest_scalar_data->flags |= SDE_DRM_DESTSCALER_ENHANCER_UPDATE; |
| 107 | } |
| 108 | if (dest_scale_info->scale_update) { |
| 109 | dest_scalar_data->flags |= SDE_DRM_DESTSCALER_SCALE_UPDATE; |
| 110 | } |
| 111 | dest_scalar_data->index = i; |
| 112 | dest_scalar_data->lm_width = dest_scale_info->mixer_width; |
| 113 | dest_scalar_data->lm_height = dest_scale_info->mixer_height; |
| 114 | dest_scalar_data->scaler_cfg = reinterpret_cast<uint64_t>(&scale->scaler_v2); |
| 115 | if (hw_panel_info_.partial_update) { |
| 116 | dest_scalar_data->flags |= SDE_DRM_DESTSCALER_PU_ENABLE; |
| 117 | } |
| 118 | index++; |
| 119 | } |
| 120 | sde_dest_scalar_data_.num_dest_scaler = UINT32(hw_layer_info.dest_scale_info_map.size()); |
| 121 | drm_atomic_intf_->Perform(DRMOps::CRTC_SET_DEST_SCALER_CONFIG, token_.crtc_id, |
| 122 | reinterpret_cast<uint64_t>(&sde_dest_scalar_data_)); |
| 123 | } |
| 124 | |
| 125 | DisplayError HWPeripheralDRM::Flush() { |
| 126 | DisplayError err = HWDeviceDRM::Flush(); |
| 127 | if (err != kErrorNone) { |
| 128 | return err; |
| 129 | } |
| 130 | |
| 131 | ResetDisplayParams(); |
| 132 | return kErrorNone; |
| 133 | } |
| 134 | |
Xu Yang | 32e58c2 | 2017-11-20 09:58:11 +0800 | [diff] [blame] | 135 | DisplayError HWPeripheralDRM::SetDppsFeature(uint32_t object_type, |
| 136 | uint32_t feature_id, uint64_t value) { |
| 137 | uint32_t obj_id; |
| 138 | |
| 139 | if (object_type == DRM_MODE_OBJECT_CRTC) { |
| 140 | obj_id = token_.crtc_id; |
| 141 | } else if (object_type == DRM_MODE_OBJECT_CONNECTOR) { |
| 142 | obj_id = token_.conn_id; |
| 143 | } else { |
| 144 | DLOGE("invalid object type 0x%x", object_type); |
| 145 | return kErrorUndefined; |
| 146 | } |
| 147 | |
| 148 | drm_atomic_intf_->Perform(DRMOps::DPPS_CACHE_FEATURE, obj_id, feature_id, value); |
| 149 | return kErrorNone; |
| 150 | } |
| 151 | |
| 152 | DisplayError HWPeripheralDRM::GetDppsFeatureInfo(void *info) { |
| 153 | DRMDppsFeatureInfo *feature_info = reinterpret_cast<DRMDppsFeatureInfo *>(info); |
| 154 | drm_mgr_intf_->GetDppsFeatureInfo(feature_info); |
| 155 | return kErrorNone; |
| 156 | } |
Ramkumar Radhakrishnan | 7e971e0 | 2017-08-17 14:19:15 +0530 | [diff] [blame] | 157 | |
Saurabh Shah | 82b06f4 | 2017-09-06 16:43:49 -0700 | [diff] [blame] | 158 | } // namespace sdm |