1 /* 2 * Copyright (c) 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_PRIMARY_H__ 26 #define __HW_PRIMARY_H__ 27 28 #include <sys/poll.h> 29 #include <vector> 30 #include <string> 31 32 #include "hw_device.h" 33 34 namespace sdm { 35 #define MAX_SYSFS_COMMAND_LENGTH 12 36 struct DisplayConfigVariableInfo; 37 38 class HWPrimary : public HWDevice { 39 public: 40 static DisplayError Create(HWInterface **intf, HWInfoInterface *hw_info_intf, 41 BufferSyncHandler *buffer_sync_handler, HWEventHandler *eventhandler); 42 static DisplayError Destroy(HWInterface *intf); 43 44 protected: 45 HWPrimary(BufferSyncHandler *buffer_sync_handler, HWInfoInterface *hw_info_intf); 46 virtual DisplayError Init(HWEventHandler *eventhandler); 47 virtual DisplayError Deinit(); 48 virtual DisplayError GetNumDisplayAttributes(uint32_t *count); 49 virtual DisplayError GetActiveConfig(uint32_t *active_config); 50 virtual DisplayError GetDisplayAttributes(uint32_t index, 51 HWDisplayAttributes *display_attributes); 52 virtual DisplayError SetDisplayAttributes(uint32_t index); 53 virtual DisplayError GetConfigIndex(uint32_t mode, uint32_t *index); 54 virtual DisplayError PowerOff(); 55 virtual DisplayError Doze(); 56 virtual DisplayError DozeSuspend(); 57 virtual DisplayError Validate(HWLayers *hw_layers); 58 virtual void SetIdleTimeoutMs(uint32_t timeout_ms); 59 virtual DisplayError SetVSyncState(bool enable); 60 virtual DisplayError SetDisplayMode(const HWDisplayMode hw_display_mode); 61 virtual DisplayError SetRefreshRate(uint32_t refresh_rate); 62 virtual DisplayError SetPanelBrightness(int level); 63 virtual DisplayError GetPPFeaturesVersion(PPFeatureVersion *vers); 64 virtual DisplayError SetPPFeatures(PPFeaturesConfig *feature_list); 65 virtual DisplayError GetPanelBrightness(int *level); 66 virtual DisplayError SetAutoRefresh(bool enable); 67 68 private: 69 // Panel modes for the MSMFB_LPM_ENABLE ioctl 70 enum { 71 kModeLPMVideo, 72 kModeLPMCommand, 73 }; 74 75 // Event Thread to receive vsync/blank events 76 static void* DisplayEventThread(void *context); 77 void* DisplayEventThreadHandler(); 78 79 void HandleVSync(char *data); 80 void HandleBlank(char *data); 81 void HandleIdleTimeout(char *data); 82 void HandleThermal(char *data); 83 DisplayError PopulateDisplayAttributes(); 84 void InitializeConfigs(); IsResolutionSwitchEnabled()85 bool IsResolutionSwitchEnabled() { return !display_configs_.empty(); } 86 bool GetCurrentModeFromSysfs(size_t *curr_x_pixels, size_t *curr_y_pixels); 87 88 pollfd poll_fds_[kNumDisplayEvents]; 89 pthread_t event_thread_; 90 const char *event_thread_name_ = "SDM_EventThread"; 91 bool fake_vsync_ = false; 92 bool exit_threads_ = false; 93 HWDisplayAttributes display_attributes_; 94 std::vector<DisplayConfigVariableInfo> display_configs_; 95 std::vector<std::string> display_config_strings_; 96 uint32_t active_config_index_ = 0; 97 const char *kBrightnessNode = "/sys/class/leds/lcd-backlight/brightness"; 98 const char *kAutoRefreshNode = "/sys/devices/virtual/graphics/fb0/msm_cmd_autorefresh_en"; 99 bool auto_refresh_ = false; 100 }; 101 102 } // namespace sdm 103 104 #endif // __HW_PRIMARY_H__ 105 106