blob: 4ddca4037dfa7ffb4d793f4f2614eb9fe662bf11
1 | /* |
2 | // Copyright (c) 2017 Amlogic |
3 | // |
4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
5 | // you may not use this file except in compliance with the License. |
6 | // You may obtain a copy of the License at |
7 | // |
8 | // http://www.apache.org/licenses/LICENSE-2.0 |
9 | // |
10 | // Unless required by applicable law or agreed to in writing, software |
11 | // distributed under the License is distributed on an "AS IS" BASIS, |
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | // See the License for the specific language governing permissions and |
14 | // limitations under the License. |
15 | // |
16 | */ |
17 | |
18 | #ifndef AML_DISPLAY_HDMI_H |
19 | #define AML_DISPLAY_HDMI_H |
20 | |
21 | #include <utils/String8.h> |
22 | #include <utils/Errors.h> |
23 | #include <sys/ioctl.h> |
24 | #include <sys/mman.h> |
25 | #include <sys/time.h> |
26 | #include <sys/types.h> |
27 | #include <sys/resource.h> |
28 | #include <linux/fb.h> |
29 | #include <string> |
30 | #include <vector> |
31 | |
32 | #include <hardware/hardware.h> |
33 | #include <hardware/hwcomposer.h> |
34 | #include <Hwcomposer.h> |
35 | #include <Utils.h> |
36 | #include <ISystemControlService.h> |
37 | #include <gui/SurfaceComposerClient.h> |
38 | #include <AmVinfo.h> |
39 | #include <framebuffer.h> |
40 | |
41 | #define HDMI_FRAC_RATE_POLICY "/sys/class/amhdmitx/amhdmitx0/frac_rate_policy" |
42 | |
43 | #if PLATFORM_SDK_VERSION >= 26 |
44 | #include <vendor/amlogic/hardware/systemcontrol/1.0/ISystemControl.h> |
45 | using ::vendor::amlogic::hardware::systemcontrol::V1_0::ISystemControl; |
46 | using ::vendor::amlogic::hardware::systemcontrol::V1_0::Result; |
47 | using ::android::hardware::hidl_vec; |
48 | using ::android::hardware::hidl_string; |
49 | using ::android::hardware::Return; |
50 | #endif |
51 | |
52 | namespace android { |
53 | namespace amlogic { |
54 | |
55 | // refresh rates. |
56 | enum { |
57 | REFRESH_24kHZ = 24, |
58 | REFRESH_30kHZ = 30, |
59 | REFRESH_60kHZ = 60, |
60 | REFRESH_120kHZ = 120, |
61 | REFRESH_240kHZ = 240 |
62 | }; |
63 | |
64 | // display config |
65 | class DisplayConfig { |
66 | public: |
67 | DisplayConfig(const std::string dm, |
68 | int rr, |
69 | int w = 0, |
70 | int h = 0, |
71 | int dpix = 0, |
72 | int dpiy = 0, |
73 | bool frac = false) |
74 | : mDisplayMode(dm), |
75 | mRefreshRate(rr), |
76 | mWidth(w), |
77 | mHeight(h), |
78 | mDpiX(dpix), |
79 | mDpiY(dpiy), |
80 | mFracRate(frac) |
81 | {} |
82 | public: |
83 | std::string getDisplayMode() const { return mDisplayMode; }; |
84 | float getRefreshRate() const { |
85 | float actualRate = 0.0f; |
86 | |
87 | if (mRefreshRate) { |
88 | if (mFracRate) { |
89 | actualRate = (mRefreshRate * 1000) / (float)1001; |
90 | } else { |
91 | actualRate = mRefreshRate; |
92 | } |
93 | } |
94 | return actualRate; |
95 | }; |
96 | int getWidth() const { return mWidth; }; |
97 | int getHeight() const { return mHeight; }; |
98 | int getDpiX() const { return mDpiX; }; |
99 | int getDpiY() const { return mDpiY; }; |
100 | void setDpi(int dpix, int dpiy) { |
101 | mDpiX = dpix; |
102 | mDpiY = dpiy; |
103 | }; |
104 | bool getFracRatePolicy() { return mFracRate; }; |
105 | |
106 | private: |
107 | std::string mDisplayMode; |
108 | int mRefreshRate; |
109 | int mWidth; |
110 | int mHeight; |
111 | int mDpiX; |
112 | int mDpiY; |
113 | bool mFracRate; |
114 | }; |
115 | |
116 | class DisplayHdmi { |
117 | public: |
118 | DisplayHdmi(); |
119 | ~DisplayHdmi(); |
120 | |
121 | void initialize(framebuffer_info_t& framebufferInfo); |
122 | void deinitialize(); |
123 | bool updateHotplug(bool connected, framebuffer_info_t& framebufferInfo); |
124 | status_t setBestDisplayMode(); |
125 | |
126 | status_t getDisplayConfigs(uint32_t* outNumConfigs, hwc2_config_t* outConfigs); |
127 | status_t getDisplayAttribute(hwc2_config_t config, int32_t attribute, int32_t* outValue); |
128 | status_t getActiveConfig(hwc2_config_t* outConfig); |
129 | status_t getRealActiveConfig(hwc2_config_t* outConfig); |
130 | status_t setActiveConfig(int modeId); |
131 | // int setPowerMode(int power) {return 0;}; |
132 | int getDisplayWorkMode() const { return mWorkMode; }; |
133 | |
134 | inline bool isConnected() {return mConnected;}; |
135 | bool chkPresent(); |
136 | |
137 | bool isSecure(); |
138 | |
139 | void dump(Dump& d); |
140 | |
141 | protected: |
142 | /* hdmi operations: |
143 | * TODO: need move all these operations to HAL. |
144 | */ |
145 | auto getSystemControlService(); |
146 | status_t readEdidList(std::vector<std::string> &edidlist); |
147 | status_t writeHdmiDispMode(std::string &dispmode); |
148 | status_t readHdmiDispMode(std::string &dispmode); |
149 | status_t readHdmiPhySize(framebuffer_info_t& fbInfo); |
150 | status_t readBestHdmiOutputMode(std::string &dispmode); |
151 | |
152 | void switchRatePolicy(bool fracRatePolicy); |
153 | void reset(); |
154 | |
155 | // operations on mSupportDispModes |
156 | status_t clearSupportedConfigs(); |
157 | status_t updateSupportedConfigs(); |
158 | status_t updateDisplayAttributes(framebuffer_info_t& framebufferInfo); |
159 | status_t addSupportedConfig(std::string& mode); |
160 | |
161 | // ensure the active mode equals the current displaymode. |
162 | status_t updateActiveConfig(std::string& activeMode); |
163 | |
164 | status_t setDisplayMode(std::string& dispmode, bool policy = false); |
165 | bool isDispModeValid(std::string& dispmode); |
166 | |
167 | bool readConfigFile(const char* configPath, std::vector<std::string>* supportDispModes); |
168 | |
169 | status_t calcDefaultMode(framebuffer_info_t& framebufferInfo, std::string& defaultMode); |
170 | status_t buildSingleConfigList(std::string& defaultMode); |
171 | |
172 | bool checkVinfo(framebuffer_info_t *fbInfo); |
173 | |
174 | private: |
175 | bool mConnected; |
176 | |
177 | #if PLATFORM_SDK_VERSION >= 26 |
178 | struct SystemControlDeathRecipient : public android::hardware::hidl_death_recipient { |
179 | // hidl_death_recipient interface |
180 | virtual void serviceDied(uint64_t cookie, |
181 | const ::android::wp<::android::hidl::base::V1_0::IBase>& who) override{}; |
182 | }; |
183 | sp<SystemControlDeathRecipient> mDeathRecipient = nullptr; |
184 | #endif |
185 | |
186 | // configures variables. |
187 | hwc2_config_t mActiveConfigId; // for amlogic, it is vmode_e. |
188 | std::string mActiveConfigStr; |
189 | hwc2_config_t mRealActiveConfigId; |
190 | std::string mRealActiveConfigStr; |
191 | KeyedVector<int, DisplayConfig*> mSupportDispConfigs; |
192 | |
193 | // physical size in mm. |
194 | int mPhyWidth; |
195 | int mPhyHeight; |
196 | // framebuffer size. |
197 | int mFbWidth; |
198 | int mFbHeight; |
199 | |
200 | // work modes |
201 | enum { |
202 | REAL_ACTIVEMODE = 0, |
203 | LOGIC_ACTIVEMODE, // return the logic size which is framebuffer size. |
204 | NONE_ACTIVEMODE // no active mode list, always return a default config. |
205 | }; |
206 | int mWorkMode; |
207 | // first boot up flag. |
208 | bool mFirstBootup; |
209 | }; |
210 | } // namespace amlogic |
211 | } // namespace android |
212 | |
213 | #endif |
214 |