1 /* 2 * Copyright (C) 2024 The Android Open Source Project 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 #ifndef _DISPLAY_TE2_MANAGER_H_ 18 #define _DISPLAY_TE2_MANAGER_H_ 19 20 #include "ExynosDisplay.h" 21 #include "ExynosHWCHelper.h" 22 23 // TODO: Rename this and integrate with refresh rate throttler related features into this class. 24 class DisplayTe2Manager : public RefreshRateChangeListener { 25 public: 26 DisplayTe2Manager(ExynosDisplay* display, int32_t panelIndex, int fixedTe2DefaultRateHz); 27 ~DisplayTe2Manager() = default; 28 29 // Set the rate while option is fixed TE2. This should be set by the sensor. 30 int32_t setFixedTe2Rate(int targetTe2RateHz); 31 // Set the rate while option is changeable TE2. This should be set by the composer 32 // while the display state is idle or active. 33 int32_t setChangeableTe2Rate(int targetTe2RateHz); 34 // Update TE2 option to either fixed or changeable according to the proximity sensor state. 35 // Ideally we should use changeable TE2 if the proximity sensor is active. Also set the min 36 // refresh rate of fixed TE2. It equals to the refresh rate while display is idle after 37 // switching to changeable TE2, and we can use it for the notification of refresh rate 38 // change. 39 void updateTe2OptionForProximity(bool proximityActive, int minRefreshRate, bool dozeMode); isOptionFixedTe2()40 bool isOptionFixedTe2() { return mIsOptionFixedTe2; } 41 42 // By default we will continue the TE2 setting after entering doze mode. The ALSP may not 43 // work properly if it's changeable TE2 with lower refresh rates, e.g. 1Hz. To avoid this 44 // problem, we should update the setting to fixed TE2 no matter the proximity sensor is 45 // active or not. 46 void updateTe2ForDozeMode(); 47 // The TE2 might be enforced to different settings after entering doze mode. We should 48 // restore the previous settings to keep the request from ALSP. 49 void restoreTe2FromDozeMode(); 50 51 void dump(String8& result) const; 52 53 private: getPanelString()54 const char* getPanelString() { 55 return (mPanelIndex == 0 ? "primary" : mPanelIndex == 1 ? "secondary" : "unknown"); 56 } 57 getPanelTe2RatePath()58 const String8 getPanelTe2RatePath() { 59 return String8::format(kTe2RateFileNode, getPanelString()); 60 } 61 getPanelTe2OptionPath()62 const String8 getPanelTe2OptionPath() { 63 return String8::format(kTe2OptionFileNode, getPanelString()); 64 } 65 66 void setTe2Option(bool fixedTe2); 67 int32_t setTe2Rate(int targetTe2RateHz); 68 int32_t setFixedTe2RateInternal(int targetTe2RateHz, bool enforce); 69 70 virtual void onRefreshRateChange(int refreshRate) override; 71 72 ExynosDisplay* mDisplay; 73 int32_t mPanelIndex; 74 // The min refresh rate of fixed TE2. For the refresh rates lower than this, the changeable 75 // TE2 should be used. 76 int mMinRefreshRateForFixedTe2; 77 int mFixedTe2RateHz; 78 // True when the current option is fixed TE2, otherwise it's changeable TE2. 79 bool mIsOptionFixedTe2; 80 // True when the refresh rate change listener of VariableRefreshRateController is 81 // registered successfully. Thus we can receive the notification of refresh rate change 82 // for changeable TE2 usage. 83 bool mRefreshRateChangeListenerRegistered; 84 85 // Indicates that TE2 was changed from changeable to fixed after entering doze mode. We 86 // should restore the setting after exiting doze mode. 87 bool mPendingOptionChangeableTe2; 88 // After entering doze mode, the TE2 rate will be enforced to mFixedTe2RateForDozeMode. 89 // We should save the previous rate as a pending value and restore it after exiting doze 90 // mode. 91 int mPendingFixedTe2Rate; 92 // After entering doze mode, the TE2 will be enforced to fixed 30Hz. 93 const int kFixedTe2RateForDozeMode = 30; 94 95 Mutex mTe2Mutex; 96 97 static constexpr const char* kTe2RateFileNode = 98 "/sys/devices/platform/exynos-drm/%s-panel/te2_rate_hz"; 99 static constexpr const char* kTe2OptionFileNode = 100 "/sys/devices/platform/exynos-drm/%s-panel/te2_option"; 101 }; 102 103 #endif // _DISPLAY_TE2_MANAGER_H_ 104