1 /* 2 * Copyright (c) 2014 - 2015, The Linux Foundation. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, are permitted 5 * provided that the following conditions are met: 6 * * Redistributions of source code must retain the above copyright notice, this list of 7 * conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above copyright notice, this list of 9 * conditions and the following disclaimer in the documentation and/or other materials provided 10 * with the distribution. 11 * * Neither the name of The Linux Foundation nor the names of its contributors may be used to 12 * endorse or promote products derived from this software without specific prior written 13 * permission. 14 * 15 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 21 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25 #ifndef __HW_DEVICE_H__ 26 #define __HW_DEVICE_H__ 27 28 #include <errno.h> 29 #include <linux/msm_mdp_ext.h> 30 #include <linux/mdss_rotator.h> 31 #include <pthread.h> 32 33 #include "hw_interface.h" 34 35 #define IOCTL_LOGE(ioctl, type) DLOGE("ioctl %s, device = %d errno = %d, desc = %s", #ioctl, \ 36 type, errno, strerror(errno)) 37 38 namespace sdm { 39 class HWInfoInterface; 40 41 class HWDevice : public HWInterface { 42 protected: 43 explicit HWDevice(BufferSyncHandler *buffer_sync_handler); ~HWDevice()44 virtual ~HWDevice() {} 45 46 // From HWInterface 47 virtual DisplayError GetActiveConfig(uint32_t *active_config); 48 virtual DisplayError GetNumDisplayAttributes(uint32_t *count); 49 virtual DisplayError GetDisplayAttributes(uint32_t index, 50 HWDisplayAttributes *display_attributes); 51 virtual DisplayError GetHWPanelInfo(HWPanelInfo *panel_info); 52 virtual DisplayError SetDisplayAttributes(uint32_t index); 53 virtual DisplayError GetConfigIndex(uint32_t mode, uint32_t *index); 54 virtual DisplayError PowerOn(); 55 virtual DisplayError PowerOff(); 56 virtual DisplayError Doze(); 57 virtual DisplayError DozeSuspend(); 58 virtual DisplayError Standby(); 59 virtual DisplayError Validate(HWLayers *hw_layers); 60 virtual DisplayError Commit(HWLayers *hw_layers); 61 virtual DisplayError Flush(); 62 virtual DisplayError GetPPFeaturesVersion(PPFeatureVersion *vers); 63 virtual DisplayError SetPPFeatures(PPFeaturesConfig *feature_list); 64 virtual DisplayError SetVSyncState(bool enable); 65 virtual void SetIdleTimeoutMs(uint32_t timeout_ms); 66 virtual DisplayError SetDisplayMode(const HWDisplayMode hw_display_mode); 67 virtual DisplayError SetRefreshRate(uint32_t refresh_rate); 68 virtual DisplayError SetPanelBrightness(int level); 69 virtual DisplayError GetHWScanInfo(HWScanInfo *scan_info); 70 virtual DisplayError GetVideoFormat(uint32_t config_index, uint32_t *video_format); 71 virtual DisplayError GetMaxCEAFormat(uint32_t *max_cea_format); 72 virtual DisplayError SetCursorPosition(HWLayers *hw_layers, int x, int y); 73 virtual DisplayError OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level); 74 virtual DisplayError GetPanelBrightness(int *level); SetAutoRefresh(bool enable)75 virtual DisplayError SetAutoRefresh(bool enable) { return kErrorNone; } 76 virtual DisplayError SetS3DMode(HWS3DMode s3d_mode); 77 78 // For HWDevice derivatives 79 virtual DisplayError Init(HWEventHandler *eventhandler); 80 virtual DisplayError Deinit(); 81 82 enum { 83 kHWEventVSync, 84 kHWEventBlank, 85 }; 86 87 static const int kMaxStringLength = 1024; 88 static const int kNumPhysicalDisplays = 2; 89 static const int kNumDisplayEvents = 4; 90 91 void DumpLayerCommit(const mdp_layer_commit &layer_commit); 92 DisplayError SetFormat(const LayerBufferFormat &source, uint32_t *target); 93 DisplayError SetStride(HWDeviceType device_type, LayerBufferFormat format, 94 uint32_t width, uint32_t *target); 95 void SetBlending(const LayerBlending &source, mdss_mdp_blend_op *target); 96 void SetRect(const LayerRect &source, mdp_rect *target); 97 void SetMDPFlags(const Layer &layer, const bool &is_rotator_used, 98 bool is_cursor_pipe_used, uint32_t *mdp_flags); 99 // Retrieves HW FrameBuffer Node Index 100 int GetFBNodeIndex(HWDeviceType device_type); 101 // Populates HWPanelInfo based on node index 102 void PopulateHWPanelInfo(); 103 void GetHWPanelInfoByNode(int device_node, HWPanelInfo *panel_info); 104 void GetHWPanelNameByNode(int device_node, HWPanelInfo *panel_info); 105 void GetHWDisplayPortAndMode(int device_node, HWDisplayPort *port, HWDisplayMode *mode); 106 void GetSplitInfo(int device_node, HWPanelInfo *panel_info); 107 void GetHWPanelMaxBrightnessFromNode(HWPanelInfo *panel_info); 108 int ParseLine(char *input, char *tokens[], const uint32_t max_token, uint32_t *count); 109 int ParseLine(char *input, const char *delim, char *tokens[], 110 const uint32_t max_token, uint32_t *count); GetScaleDataRef(uint32_t index)111 mdp_scale_data* GetScaleDataRef(uint32_t index) { return &scale_data_[index]; } 112 void SetHWScaleData(const ScaleData &scale, uint32_t index); 113 void ResetDisplayParams(); 114 void SetCSC(LayerCSC source, mdp_color_space *color_space); 115 void SetIGC(const Layer &layer, uint32_t index); 116 117 bool EnableHotPlugDetection(int enable); 118 ssize_t SysFsWrite(const char* file_node, const char* value, ssize_t length); 119 120 // Store the Device EventHandler - used for callback 121 HWEventHandler *event_handler_; 122 HWResourceInfo hw_resource_; 123 HWPanelInfo hw_panel_info_; 124 HWInfoInterface *hw_info_intf_; 125 int fb_node_index_; 126 const char *fb_path_; 127 bool hotplug_enabled_; 128 BufferSyncHandler *buffer_sync_handler_; 129 int device_fd_; 130 HWDeviceType device_type_; 131 mdp_layer_commit mdp_disp_commit_; 132 mdp_input_layer mdp_in_layers_[kMaxSDELayers * 2]; // split panel (left + right) 133 mdp_scale_data scale_data_[kMaxSDELayers * 2]; 134 mdp_overlay_pp_params pp_params_[kMaxSDELayers * 2]; 135 mdp_igc_lut_data_v1_7 igc_lut_data_[kMaxSDELayers * 2]; 136 mdp_output_layer mdp_out_layer_; 137 const char *device_name_; 138 bool synchronous_commit_; 139 }; 140 141 } // namespace sdm 142 143 #endif // __HW_DEVICE_H__ 144 145