1 /*
2 * Copyright (C) 2023 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 #include "ExynosDisplayDrmInterfaceModule.h"
18 #include "ExynosPrimaryDisplayModule.h"
19
20 using namespace zuma;
21
22 //////////////////////////////////////////////////// ExynosPrimaryDisplayDrmInterfaceModule //////////////////////////////////////////////////////////////////
ExynosPrimaryDisplayDrmInterfaceModule(ExynosDisplay * exynosDisplay)23 ExynosPrimaryDisplayDrmInterfaceModule::ExynosPrimaryDisplayDrmInterfaceModule(ExynosDisplay *exynosDisplay)
24 : gs201::ExynosPrimaryDisplayDrmInterfaceModule(exynosDisplay)
25 {
26 ExynosPrimaryDisplayModule* display = (ExynosPrimaryDisplayModule*)mExynosDisplay;
27 const std::string &sysfs = display->getPanelSysfsPath(display->getBuiltInDisplayType());
28 std::string panelModel;
29
30 if (sysfs.empty()) {
31 return;
32 }
33
34 if (readLineFromFile(sysfs + "/panel_model", panelModel, '\n') != OK) {
35 return;
36 }
37
38 /*
39 * VESA EDID Standard requires monitor descriptor data to terminate
40 * with '\n' character and to pad with ' ' characters if < 13 bytes.
41 */
42 if (panelModel.size() < MONITOR_DESCRIPTOR_DATA_LENGTH) {
43 panelModel += '\n';
44 panelModel.append(MONITOR_DESCRIPTOR_DATA_LENGTH - panelModel.size(), ' ');
45 }
46
47 if (panelModel.size() > MONITOR_DESCRIPTOR_DATA_LENGTH) {
48 ALOGE("Panel model longer than maximum %u bytes", MONITOR_DESCRIPTOR_DATA_LENGTH);
49 return;
50 }
51
52 std::memcpy(mMonitorDescription.data(), panelModel.c_str(), mMonitorDescription.size());
53 }
54
55 // TODO: b/295990513 - Remove the if defined after kernel prebuilts are merged.
56 #if defined(EXYNOS_HISTOGRAM_CHANNEL_REQUEST)
sendHistogramChannelIoctl(HistogramChannelIoctl_t control,uint8_t channelId) const57 int32_t ExynosPrimaryDisplayDrmInterfaceModule::sendHistogramChannelIoctl(HistogramChannelIoctl_t control, uint8_t channelId) const {
58 struct exynos_drm_histogram_channel_request histogramRequest;
59
60 histogramRequest.crtc_id = mDrmCrtc->id();
61 histogramRequest.hist_id = channelId;
62
63 if (control == HistogramChannelIoctl_t::REQUEST) {
64 ATRACE_NAME(String8::format("requestIoctl #%u", channelId).string());
65 return mDrmDevice->CallVendorIoctl(DRM_IOCTL_EXYNOS_HISTOGRAM_CHANNEL_REQUEST,
66 (void *)&histogramRequest);
67 } else if (control == HistogramChannelIoctl_t::CANCEL) {
68 ATRACE_NAME(String8::format("cancelIoctl #%u", channelId).string());
69 return mDrmDevice->CallVendorIoctl(DRM_IOCTL_EXYNOS_HISTOGRAM_CHANNEL_CANCEL,
70 (void *)&histogramRequest);
71 } else {
72 ALOGE("%s: unknown control %d", __func__, (int)control);
73 return BAD_VALUE;
74 }
75 }
76 #endif
77