• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #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);
42   static DisplayError Destroy(HWInterface *intf);
43 
44  protected:
45   HWPrimary(BufferSyncHandler *buffer_sync_handler, HWInfoInterface *hw_info_intf);
46   virtual DisplayError Init();
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 DisplayError Commit(HWLayers *hw_layers);
59   virtual void SetIdleTimeoutMs(uint32_t timeout_ms);
60   virtual DisplayError SetVSyncState(bool enable);
61   virtual DisplayError SetDisplayMode(const HWDisplayMode hw_display_mode);
62   virtual DisplayError SetRefreshRate(uint32_t refresh_rate);
63   virtual DisplayError SetPanelBrightness(int level);
64   virtual DisplayError GetPPFeaturesVersion(PPFeatureVersion *vers);
65   virtual DisplayError SetPPFeatures(PPFeaturesConfig *feature_list);
66   virtual DisplayError GetPanelBrightness(int *level);
67   virtual DisplayError SetAutoRefresh(bool enable);
68   virtual DisplayError SetMixerAttributes(const HWMixerAttributes &mixer_attributes);
69 
70  private:
71   // Panel modes for the MSMFB_LPM_ENABLE ioctl
72   enum {
73     kModeLPMVideo,
74     kModeLPMCommand,
75   };
76 
77   DisplayError PopulateDisplayAttributes();
78   void InitializeConfigs();
IsResolutionSwitchEnabled()79   bool IsResolutionSwitchEnabled() { return !display_configs_.empty(); }
80   bool GetCurrentModeFromSysfs(size_t *curr_x_pixels, size_t *curr_y_pixels);
81   void UpdateMixerAttributes();
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 };
90 
91 }  // namespace sdm
92 
93 #endif  // __HW_PRIMARY_H__
94 
95