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 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 36 class HWPrimary : public HWDevice { 37 public: 38 HWPrimary(BufferSyncHandler *buffer_sync_handler, HWInfoInterface *hw_info_intf); 39 40 protected: 41 virtual DisplayError Init(); 42 virtual DisplayError GetNumDisplayAttributes(uint32_t *count); 43 virtual DisplayError GetActiveConfig(uint32_t *active_config); 44 virtual DisplayError GetDisplayAttributes(uint32_t index, 45 HWDisplayAttributes *display_attributes); 46 virtual DisplayError SetDisplayAttributes(uint32_t index); 47 virtual DisplayError GetConfigIndex(uint32_t mode, uint32_t *index); 48 virtual DisplayError PowerOff(); 49 virtual DisplayError Doze(); 50 virtual DisplayError DozeSuspend(); 51 virtual DisplayError Validate(HWLayers *hw_layers); 52 virtual DisplayError Commit(HWLayers *hw_layers); 53 virtual void SetIdleTimeoutMs(uint32_t timeout_ms); 54 virtual DisplayError SetVSyncState(bool enable); 55 virtual DisplayError SetDisplayMode(const HWDisplayMode hw_display_mode); 56 virtual DisplayError SetRefreshRate(uint32_t refresh_rate); 57 virtual DisplayError SetPanelBrightness(int level); 58 virtual DisplayError CachePanelBrightness(int level); 59 virtual DisplayError GetPPFeaturesVersion(PPFeatureVersion *vers); 60 virtual DisplayError SetPPFeatures(PPFeaturesConfig *feature_list); 61 virtual DisplayError GetPanelBrightness(int *level); 62 virtual DisplayError SetAutoRefresh(bool enable); 63 virtual DisplayError SetMixerAttributes(const HWMixerAttributes &mixer_attributes); 64 65 private: 66 // Panel modes for the MSMFB_LPM_ENABLE ioctl 67 enum { 68 kModeLPMVideo, 69 kModeLPMCommand, 70 }; 71 72 enum { 73 kMaxSysfsCommandLength = 12, 74 }; 75 76 DisplayError PopulateDisplayAttributes(); 77 void InitializeConfigs(); 78 bool IsResolutionSwitchEnabled() { return !display_configs_.empty(); } 79 bool GetCurrentModeFromSysfs(size_t *curr_x_pixels, size_t *curr_y_pixels); 80 void UpdateMixerAttributes(); 81 void SetAVRFlags(const HWAVRInfo &hw_avr_info, uint32_t *avr_flags); 82 83 std::vector<DisplayConfigVariableInfo> display_configs_; 84 std::vector<std::string> display_config_strings_; 85 uint32_t active_config_index_ = 0; 86 const char *kBrightnessNode = "/sys/class/leds/lcd-backlight/brightness"; 87 const char *kAutoRefreshNode = "/sys/devices/virtual/graphics/fb0/msm_cmd_autorefresh_en"; 88 bool auto_refresh_ = false; 89 bool avr_prop_disabled_ = false; 90 }; 91 92 } // namespace sdm 93 94 #endif // __HW_PRIMARY_H__ 95 96