• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "disp_hal.h"
17 #include <securec.h>
18 #include "hdf_io_service_if.h"
19 #include "hdf_log.h"
20 #include "hdf_sbuf.h"
21 
22 #define OFFSET_TWO_BYTE    16
23 #define MASK_TWO_BYTE      0xffff
24 
DispCmdSend(const uint32_t cmd,struct HdfSBuf * reqData,struct HdfSBuf * respData)25 static int32_t DispCmdSend(const uint32_t cmd, struct HdfSBuf *reqData, struct HdfSBuf *respData)
26 {
27     struct HdfIoService *dispService = NULL;
28 
29     dispService = HdfIoServiceBind(DISP_SERVICE_NAME);
30     if ((dispService == NULL) || (dispService->dispatcher == NULL) || (dispService->dispatcher->Dispatch == NULL)) {
31         HDF_LOGE("%s:bad remote service found", __func__);
32         goto EXIT;
33     }
34     int32_t ret = dispService->dispatcher->Dispatch(&dispService->object, cmd, reqData, respData);
35     if (ret != DISPLAY_SUCCESS) {
36         HDF_LOGE("%s: cmd=%u, ret=%d", __func__, cmd, ret);
37         goto EXIT;
38     }
39     HDF_LOGI("%s: cmd=%u, ret=%d", __func__, cmd, ret);
40     HdfIoServiceRecycle(dispService);
41     return DISPLAY_SUCCESS;
42 
43 EXIT:
44     HdfIoServiceRecycle(dispService);
45     return DISPLAY_FAILURE;
46 }
47 
GetInfo(uint32_t devId,struct DispInfo * info)48 static int32_t GetInfo(uint32_t devId, struct DispInfo *info)
49 {
50     int32_t ret;
51     struct DispInfo *tmpInfo = NULL;
52     struct HdfSBuf *data = NULL;
53     struct HdfSBuf *reply = NULL;
54 
55     if (info == NULL) {
56         HDF_LOGE("%s: invalid param", __func__);
57         return DISPLAY_FAILURE;
58     }
59 
60     data = HdfSBufObtainDefaultSize();
61     if (data == NULL) {
62         HDF_LOGE("%s: obtain data sbuf fail", __func__);
63         return DISPLAY_FAILURE;
64     }
65     reply = HdfSBufObtainDefaultSize();
66     if (reply == NULL) {
67         HDF_LOGE("%s: obtain reply sbuf fail", __func__);
68         goto EXIT;
69     }
70     if (!HdfSbufWriteUint32(data, devId)) {
71         HDF_LOGE("HdfSbufWriteUint32 failure");
72         goto EXIT;
73     }
74     ret = DispCmdSend(DISP_CMD_GET_PANELINFO, data, reply);
75     if (ret != DISPLAY_SUCCESS) {
76         HDF_LOGE("cmd:DISP_CMD_GET_PANEL_INFO failure");
77         goto EXIT;
78     }
79     uint32_t dataSize = 0;
80     if (!HdfSbufReadBuffer(reply, (const void **)(&tmpInfo), &dataSize) || dataSize != sizeof(struct DispInfo)) {
81         HDF_LOGE("HdfSbufReadBuffer failure");
82         goto EXIT;
83     }
84     (void)memcpy_s(info, sizeof(struct DispInfo), tmpInfo, dataSize);
85     HDF_LOGI("tmpInfo->width = %u, tmpInfo->height = %u", tmpInfo->width, tmpInfo->height);
86     HDF_LOGI("tmpInfo->hbp = %u, tmpInfo->hfp = %u", tmpInfo->hbp, tmpInfo->hfp);
87     HDF_LOGI("tmpInfo->frameRate = %u", tmpInfo->frameRate);
88     HDF_LOGI("tmpInfo->intfSync = %d", tmpInfo->intfSync);
89     HdfSBufRecycle(data);
90     HdfSBufRecycle(reply);
91     return DISPLAY_SUCCESS;
92 
93 EXIT:
94     HdfSBufRecycle(data);
95     HdfSBufRecycle(reply);
96     return DISPLAY_FAILURE;
97 }
98 
DispGetParaProcess(uint32_t devId,const uint32_t cmd,uint32_t * value)99 static int32_t DispGetParaProcess(uint32_t devId, const uint32_t cmd, uint32_t *value)
100 {
101     int32_t ret;
102     struct HdfSBuf *data = NULL;
103     struct HdfSBuf *reply = NULL;
104 
105     if (value == NULL) {
106         HDF_LOGE("%s: invalid param", __func__);
107         return DISPLAY_FAILURE;
108     }
109 
110     data = HdfSBufObtainDefaultSize();
111     if (data == NULL) {
112         HDF_LOGE("%s: obtain data sbuf fail", __func__);
113         return DISPLAY_FAILURE;
114     }
115     reply = HdfSBufObtainDefaultSize();
116     if (reply == NULL) {
117         HDF_LOGE("%s: obtain reply sbuf fail", __func__);
118         goto EXIT;
119     }
120     if (!HdfSbufWriteUint32(data, devId)) {
121         HDF_LOGE("HdfSbufWriteUint32 failure");
122         goto EXIT;
123     }
124     ret = DispCmdSend(cmd, data, reply);
125     if (ret != DISPLAY_SUCCESS) {
126         HDF_LOGE("cmd:DISP_CMD_GET_PANEL_INFO failure");
127         goto EXIT;
128     }
129     if (!HdfSbufReadUint32(reply, value)) {
130         HDF_LOGE("HdfSbufReadUint32 failure");
131         goto EXIT;
132     }
133     HdfSBufRecycle(data);
134     HdfSBufRecycle(reply);
135     return DISPLAY_SUCCESS;
136 
137 EXIT:
138     HdfSBufRecycle(data);
139     HdfSBufRecycle(reply);
140     return DISPLAY_FAILURE;
141 }
142 
DispEventProcess(uint32_t devId,const uint32_t cmd,uint32_t val)143 static int32_t DispEventProcess(uint32_t devId, const uint32_t cmd, uint32_t val)
144 {
145     int32_t ret;
146 
147     struct HdfSBuf *data = HdfSBufObtainDefaultSize();
148     if (data == NULL) {
149         HDF_LOGE("%s: obtain data sbuf fail", __func__);
150         return DISPLAY_FAILURE;
151     }
152     uint32_t para = (devId << OFFSET_TWO_BYTE) | (val & 0xffff);
153     if (!HdfSbufWriteUint32(data, para)) {
154         HDF_LOGE("HdfSbufWriteUint32 failure\n");
155         goto EXIT;
156     }
157     ret = DispCmdSend(cmd, data, NULL);
158     if (ret) {
159         HDF_LOGE("cmd:DISP_CMD_SET_%s failure\n", (cmd == DISP_CMD_SET_POWERSTATUS) ? "POWERMODE" : "BACKLIGHT");
160         goto EXIT;
161     }
162     HdfSBufRecycle(data);
163     return DISPLAY_SUCCESS;
164 
165 EXIT:
166     HdfSBufRecycle(data);
167     return DISPLAY_FAILURE;
168 }
169 
SetPowerStatus(uint32_t devId,DispPowerStatus status)170 static int32_t SetPowerStatus(uint32_t devId,  DispPowerStatus status)
171 {
172     return DispEventProcess(devId, DISP_CMD_SET_POWERSTATUS, status);
173 }
174 
GetPowerStatus(uint32_t devId,DispPowerStatus * pStatus)175 static int32_t GetPowerStatus(uint32_t devId,  DispPowerStatus *pStatus)
176 {
177     return DispGetParaProcess(devId, DISP_CMD_GET_POWERSTATUS, pStatus);
178 }
179 
SetBacklight(uint32_t devId,uint32_t level)180 static int32_t SetBacklight(uint32_t devId, uint32_t level)
181 {
182     return DispEventProcess(devId, DISP_CMD_SET_BACKLIGHT, level);
183 }
184 
GetBacklight(uint32_t devId,uint32_t * level)185 static int32_t GetBacklight(uint32_t devId, uint32_t *level)
186 {
187     return DispGetParaProcess(devId, DISP_CMD_GET_BACKLIGHT, level);
188 }
189 
GetHalFuncs(void)190 HalFuncs *GetHalFuncs(void)
191 {
192     static HalFuncs *hFuncs = NULL;
193 
194     if (hFuncs == NULL) {
195         hFuncs = (HalFuncs *)malloc(sizeof(HalFuncs));
196         if (hFuncs == NULL) {
197             HDF_LOGE("%s: malloc fail", __func__);
198             return NULL;
199         }
200         (void)memset_s(hFuncs, sizeof(HalFuncs), 0, sizeof(HalFuncs));
201         hFuncs->SetPowerStatus = SetPowerStatus;
202         hFuncs->GetPowerStatus = GetPowerStatus;
203         hFuncs->SetBacklight = SetBacklight;
204         hFuncs->GetBacklight = GetBacklight;
205         hFuncs->GetInfo = GetInfo;
206     }
207     return hFuncs;
208 }
209