blob: 667cd888ab8e9e945a33075fd9a54576e752cbc3 [file] [log] [blame]
/*
Copyright (c) 2017, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <utils/debug.h>
#include "hw_peripheral_drm.h"
#define __CLASS__ "HWPeripheralDRM"
using sde_drm::DRMDisplayType;
using sde_drm::DRMOps;
using sde_drm::DRMTopology;
using sde_drm::DRMPowerMode;
namespace sdm {
HWPeripheralDRM::HWPeripheralDRM(BufferSyncHandler *buffer_sync_handler,
BufferAllocator *buffer_allocator,
HWInfoInterface *hw_info_intf)
: HWDeviceDRM(buffer_sync_handler, buffer_allocator, hw_info_intf) {
disp_type_ = DRMDisplayType::PERIPHERAL;
device_name_ = "Peripheral Display";
}
DisplayError HWPeripheralDRM::Init() {
DisplayError ret = HWDeviceDRM::Init();
if (ret != kErrorNone) {
DLOGE("Init failed for %s", device_name_);
return ret;
}
scalar_data_.resize(hw_resource_.hw_dest_scalar_info.count);
drm_mgr_intf_->GetConnectorInfo(token_.conn_id, &connector_info_);
if (connector_info_.topology == DRMTopology::UNKNOWN) {
connector_info_.topology = DRMTopology::DUAL_LM;
}
InitializeConfigs();
PopulateHWPanelInfo();
UpdateMixerAttributes();
return kErrorNone;
}
DisplayError HWPeripheralDRM::Validate(HWLayers *hw_layers) {
// Hijack the first validate to setup pipeline. This is a stopgap solution
HWLayersInfo &hw_layer_info = hw_layers->info;
if (first_cycle_) {
drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_CRTC, token_.conn_id, token_.crtc_id);
drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_POWER_MODE, token_.conn_id, DRMPowerMode::ON);
drm_atomic_intf_->Perform(DRMOps::CRTC_SET_MODE, token_.crtc_id,
&connector_info_.modes[current_mode_index_]);
drm_atomic_intf_->Perform(DRMOps::CRTC_SET_ACTIVE, token_.crtc_id, 1);
if (drm_atomic_intf_->Commit(true /* synchronous */, false /* retain pipes*/)) {
DLOGE("Setting up CRTC %d, Connector %d for %s failed",
token_.crtc_id, token_.conn_id, device_name_);
return kErrorResources;
}
// Reload connector info for updated info after 1st commit
drm_mgr_intf_->GetConnectorInfo(token_.conn_id, &connector_info_);
PopulateDisplayAttributes(current_mode_index_);
PopulateHWPanelInfo();
first_cycle_ = false;
}
SetDestScalarData(hw_layer_info);
return HWDeviceDRM::Validate(hw_layers);
}
DisplayError HWPeripheralDRM::Commit(HWLayers *hw_layers) {
HWLayersInfo &hw_layer_info = hw_layers->info;
SetDestScalarData(hw_layer_info);
return HWDeviceDRM::Commit(hw_layers);
}
DisplayError HWPeripheralDRM::PowerOn() {
if (first_cycle_) {
return kErrorNone;
}
return HWDeviceDRM::PowerOn();
}
void HWPeripheralDRM::ResetDisplayParams() {
sde_dest_scalar_data_ = {};
for (uint32_t j = 0; j < scalar_data_.size(); j++) {
scalar_data_[j] = {};
}
}
void HWPeripheralDRM::SetDestScalarData(HWLayersInfo hw_layer_info) {
if (!hw_resource_.hw_dest_scalar_info.count) {
return;
}
uint32_t index = 0;
for (uint32_t i = 0; i < hw_resource_.hw_dest_scalar_info.count; i++) {
DestScaleInfoMap::iterator it = hw_layer_info.dest_scale_info_map.find(i);
if (it == hw_layer_info.dest_scale_info_map.end()) {
continue;
}
HWDestScaleInfo *dest_scale_info = it->second;
SDEScaler *scale = &scalar_data_[index];
hw_scale_->SetScaler(dest_scale_info->scale_data, scale);
sde_drm_dest_scaler_cfg *dest_scalar_data = &sde_dest_scalar_data_.ds_cfg[index];
dest_scalar_data->flags = 0;
if (scale->scaler_v2.enable) {
dest_scalar_data->flags |= SDE_DRM_DESTSCALER_ENABLE;
}
if (scale->scaler_v2.de.enable) {
dest_scalar_data->flags |= SDE_DRM_DESTSCALER_ENHANCER_UPDATE;
}
if (dest_scale_info->scale_update) {
dest_scalar_data->flags |= SDE_DRM_DESTSCALER_SCALE_UPDATE;
}
dest_scalar_data->index = i;
dest_scalar_data->lm_width = dest_scale_info->mixer_width;
dest_scalar_data->lm_height = dest_scale_info->mixer_height;
dest_scalar_data->scaler_cfg = reinterpret_cast<uint64_t>(&scale->scaler_v2);
if (hw_panel_info_.partial_update) {
dest_scalar_data->flags |= SDE_DRM_DESTSCALER_PU_ENABLE;
}
index++;
}
sde_dest_scalar_data_.num_dest_scaler = UINT32(hw_layer_info.dest_scale_info_map.size());
drm_atomic_intf_->Perform(DRMOps::CRTC_SET_DEST_SCALER_CONFIG, token_.crtc_id,
reinterpret_cast<uint64_t>(&sde_dest_scalar_data_));
}
DisplayError HWPeripheralDRM::Flush() {
DisplayError err = HWDeviceDRM::Flush();
if (err != kErrorNone) {
return err;
}
ResetDisplayParams();
return kErrorNone;
}
} // namespace sdm