blob: cfb3d97fb1b0f4b815b9029fbca6d6dcd3b7f3ff [file] [log] [blame]
limin.tian20df7d42023-02-10 10:05:52 +08001/*
2 * Copyright (c) 2023 Amlogic, Inc. All rights reserved.
3 *
4 * This source code is subject to the terms and conditions defined in the
5 * file 'LICENSE' which is part of this source code package.
6 *
7 * Description:
8 */
9#include <stdio.h>
10#include <stdlib.h>
11#include <fcntl.h>
12#include <unistd.h>
13#include <errno.h>
14#include <xf86drm.h>
15#include <xf86drmMode.h>
16#include <linux/string.h>
17#include "libdrm_meson_connector.h"
18#include "libdrm_meson_property.h"
19#include "meson_drm_settings.h"
20
21
22#define DEFAULT_CARD "/dev/dri/card0"
23#define PROP_NAME_MAX_LEN 50
24static int meson_drm_get_crtc_prop_value( int drmFd, MESON_CONNECTOR_TYPE connType,
25 char* name, uint32_t* prop_value );
26static int meson_drm_get_conn_prop_value( int drmFd, MESON_CONNECTOR_TYPE connType,
27 char* name, uint32_t* propValue );
28static int meson_drm_get_prop_value(int drmFd, MESON_CONNECTOR_TYPE connType,
29 uint32_t objType, char* name, uint32_t* propValue );
30
31static struct mesonConnector* get_current_connector(int drmFd, MESON_CONNECTOR_TYPE connType);
32static int meson_drm_set_property(int drmFd, drmModeAtomicReq *req, uint32_t objId,
33 uint32_t objType, char* name, uint64_t value);
34
35static int meson_drm_get_prop_value(int drmFd, MESON_CONNECTOR_TYPE connType, uint32_t objType, char* name, uint32_t* propValue )
36{
37 int ret = -1;
38 int objID = -1;
39 struct mesonConnector* conn = NULL;
40 if ( drmFd < 0 || name == NULL || propValue == NULL)
41 {
limin.tianfe2ab442023-03-06 08:40:15 +000042 fprintf(stderr, "\n%s %d drmfd invalid, or property name invalid\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +080043 goto out;
44 }
45 conn = get_current_connector(drmFd, connType);
46 if ( conn == NULL )
47 {
limin.tianfe2ab442023-03-06 08:40:15 +000048 fprintf(stderr, "\n%s %d get_current_connector fail\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +080049 goto out;
50 }
51 objID = mesonConnectorGetId(conn);
52 if (objType == DRM_MODE_OBJECT_CRTC)
53 objID = mesonConnectorGetCRTCId(conn);
54 struct mesonProperty* meson_prop = NULL;
55 meson_prop = mesonPropertyCreate(drmFd, objID, objType, name);
56 if (!meson_prop) {
57 printf("\n meson_prop create fail\n");
58 goto out;
59 }
60 uint64_t value = mesonPropertyGetValue(meson_prop);
61 *propValue = (uint32_t)value;
limin.tianfe2ab442023-03-06 08:40:15 +000062 fprintf(stderr, "\n prop value:%llu objID:%d,name:%s\n",value, objID,name);
limin.tian20df7d42023-02-10 10:05:52 +080063 mesonPropertyDestroy(meson_prop);
64 ret = 0;
65out:
66 if (conn)
67 mesonConnectorDestroy(drmFd,conn);
68 return ret;
69}
70
71static int meson_drm_get_conn_prop_value( int drmFd, MESON_CONNECTOR_TYPE conn_type, char* name, uint32_t* prop_value )
72{
73 return meson_drm_get_prop_value( drmFd, conn_type, DRM_MODE_OBJECT_CONNECTOR, name, prop_value );
74}
75
76static int meson_drm_get_crtc_prop_value( int drmFd, MESON_CONNECTOR_TYPE conn_type, char* name, uint32_t* prop_value )
77{
78 return meson_drm_get_prop_value( drmFd, conn_type, DRM_MODE_OBJECT_CRTC, name, prop_value );
79}
80
81static struct mesonConnector* get_current_connector(int drmFd, MESON_CONNECTOR_TYPE connType)
82{
83 struct mesonConnector* connector = NULL;
84 int drmConnType = DRM_MODE_CONNECTOR_HDMIA;
85 if (drmFd < 0) {
limin.tianfe2ab442023-03-06 08:40:15 +000086 fprintf(stderr, "\n %s %d invalid drmFd return\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +080087 return NULL;
88 }
89 switch (connType)
90 {
91 case MESON_CONNECTOR_HDMIA:
92 drmConnType = DRM_MODE_CONNECTOR_HDMIA;
93 break;
94 case MESON_CONNECTOR_HDMIB:
95 drmConnType = DRM_MODE_CONNECTOR_HDMIB;
96 break;
97 case MESON_CONNECTOR_LVDS:
98 drmConnType = DRM_MODE_CONNECTOR_LVDS;
99 break;
100 case MESON_CONNECTOR_CVBS:
101 drmConnType = DRM_MODE_CONNECTOR_TV;
limin.tiandcd053f2023-04-24 08:27:18 +0000102 break;
limin.tian20df7d42023-02-10 10:05:52 +0800103 default :
104 drmConnType = DRM_MODE_CONNECTOR_HDMIA;
105 break;
106 }
107 connector = mesonConnectorCreate(drmFd, drmConnType);
108 return connector;
109}
110int meson_open_drm()
111{
112 int ret_fd = -1;
113 const char *card;
114 int ret = -1;
115 card= getenv("WESTEROS_DRM_CARD");
116 if ( !card ) {
117 card = DEFAULT_CARD;
118 }
119 ret_fd = open(card, O_RDONLY|O_CLOEXEC);
120 if ( ret_fd < 0 )
limin.tianfe2ab442023-03-06 08:40:15 +0000121 fprintf(stderr, "\n meson_open_drm drm card:%s open fail\n",card);
limin.tian20df7d42023-02-10 10:05:52 +0800122 else
123 drmDropMaster(ret_fd);
124 ret = drmSetClientCap(ret_fd, DRM_CLIENT_CAP_ATOMIC, 1);
125 if (ret < 0)
limin.tianfe2ab442023-03-06 08:40:15 +0000126 fprintf(stderr, "Unable to set DRM atomic capability\n");
127
limin.tian20df7d42023-02-10 10:05:52 +0800128 ret = drmSetClientCap(ret_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
129 if (ret < 0)
limin.tianfe2ab442023-03-06 08:40:15 +0000130 fprintf(stderr, "Unable to set UNIVERSAL_PLANES\n");
limin.tian20df7d42023-02-10 10:05:52 +0800131 return ret_fd;
132}
133void meson_close_drm(int drmFd)
134{
135 if (drmFd >= 0)
136 close(drmFd);
137}
138static int meson_drm_set_property(int drmFd, drmModeAtomicReq *req, uint32_t objId,
139 uint32_t objType, char* name, uint64_t value)
140{
141 uint32_t propId;
142 int rc = -1;
143 if (drmFd < 0 || req == NULL) {
limin.tianfe2ab442023-03-06 08:40:15 +0000144 fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800145 return rc;
146 }
147 struct mesonProperty *prop = NULL;
148 prop = mesonPropertyCreate(drmFd, objId, objType, name);
149 propId = mesonPropertyGetId(prop);
150 mesonPropertyDestroy(prop);
limin.tiandcd053f2023-04-24 08:27:18 +0000151 fprintf(stderr, "\nmeson_drm_set_property name:%s objId:%d propId:%d value:%llu\n", name, objId, propId, value);
limin.tian20df7d42023-02-10 10:05:52 +0800152 rc = drmModeAtomicAddProperty( req, objId, propId, value );
153 if (rc < 0)
limin.tianfe2ab442023-03-06 08:40:15 +0000154 fprintf(stderr, "\n %s %d meson_drm_set_property fail\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800155 return rc;
156}
157
158int meson_drm_getModeInfo(int drmFd, MESON_CONNECTOR_TYPE connType, DisplayMode* modeInfo)
159{
160 int ret = -1;
161 struct mesonConnector* conn = NULL;
162 drmModeModeInfo* mode = NULL;
163 if (modeInfo == NULL || drmFd < 0) {
limin.tianfe2ab442023-03-06 08:40:15 +0000164 fprintf(stderr, "\n %s %d modeInfo == NULL || drmFd < 0 return\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800165 return ret;
166 }
167 conn = get_current_connector(drmFd, connType);
168 if ( conn ) {
169 mode = mesonConnectorGetCurMode(drmFd, conn);
170 if (mode) {
171 modeInfo->w = mode->hdisplay;
172 modeInfo->h = mode->vdisplay;
173 modeInfo->vrefresh = mode->vrefresh;
174 modeInfo->interlace = mode->flags & DRM_MODE_FLAG_INTERLACE;
175 strcpy(modeInfo->name, mode->name);
176 free(mode);
177 mode = NULL;
178 ret = 0;
179 } else {
limin.tianfe2ab442023-03-06 08:40:15 +0000180 fprintf(stderr, "\n %s %d mode get fail \n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800181 }
182 } else {
limin.tianfe2ab442023-03-06 08:40:15 +0000183 fprintf(stderr, "\n %s %d conn create fail \n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800184 }
185 if (conn)
186 mesonConnectorDestroy(drmFd,conn);
187 return ret;
188}
189int meson_drm_changeMode(int drmFd, drmModeAtomicReq *req, DisplayMode* modeInfo, MESON_CONNECTOR_TYPE connType)
190{
191 int ret = -1;
192 struct mesonConnector* conn = NULL;
193 drmModeModeInfo drm_mode;
194 int i;
195 bool interlace = false;
196 bool found = false;
197 int rc = -1;
198 int rc1 = -1;
199 int rc2 = -1;
200 int rc3 = -1;
201 uint32_t connId;
202 uint32_t crtcId;
203
204 uint32_t blobId = 0;
205 drmModeModeInfo* modes = NULL;
206 int modesNumber = 0;
207
208 if (modeInfo == NULL || drmFd < 0 || req == NULL) {
limin.tianfe2ab442023-03-06 08:40:15 +0000209 fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800210 return ret;
211 }
limin.tiandcd053f2023-04-24 08:27:18 +0000212 if (connType == MESON_CONNECTOR_CVBS)
213 {
214 struct mesonConnector* connHDMI = NULL;
215 uint32_t HDMIconnId;
216 int rc4 = -1;
217 connHDMI = get_current_connector(drmFd, MESON_CONNECTOR_HDMIA);
218 HDMIconnId = mesonConnectorGetId(connHDMI);
219 rc4 = meson_drm_set_property(drmFd, req, HDMIconnId, DRM_MODE_OBJECT_CONNECTOR, "CRTC_ID", 0);
220 mesonConnectorDestroy(drmFd,connHDMI);
221 fprintf(stderr, "\n %s %d change mode to cvbs, disconnect HDMI :%d \n",__FUNCTION__,__LINE__,rc4);
222 }
limin.tian20df7d42023-02-10 10:05:52 +0800223 conn = get_current_connector(drmFd, connType);
224 connId = mesonConnectorGetId(conn);
225 crtcId = mesonConnectorGetCRTCId(conn);
226 if ( conn ) {
227 mesonConnectorGetModes(conn, drmFd, &modes, &modesNumber);
228 for ( i = 0; i < modesNumber; i++ ) {
229 interlace = (modes[i].flags & DRM_MODE_FLAG_INTERLACE);
230 if ( (modeInfo->w == modes[i].hdisplay)
231 && (modeInfo->h == modes[i].vdisplay)
232 && (modeInfo->vrefresh == modes[i].vrefresh)
233 && (interlace == modeInfo->interlace)
234 ) {
235 drm_mode = modes[i];
236 found = true;
237 break;
238 }
239 }
240 } else {
limin.tianfe2ab442023-03-06 08:40:15 +0000241 fprintf(stderr, "\n %s %d conn create fail \n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800242 }
243
244 if (found) {
245 rc1 = meson_drm_set_property(drmFd, req, connId, DRM_MODE_OBJECT_CONNECTOR, "CRTC_ID", crtcId);
246 rc = drmModeCreatePropertyBlob( drmFd, &drm_mode, sizeof(drm_mode), &blobId );
247 if (rc == 0) {
248 rc2 = meson_drm_set_property(drmFd, req, crtcId, DRM_MODE_OBJECT_CRTC, "MODE_ID", blobId);
249 rc3 = meson_drm_set_property(drmFd, req, crtcId, DRM_MODE_OBJECT_CRTC, "ACTIVE", 1);
limin.tianfe2ab442023-03-06 08:40:15 +0000250 fprintf(stderr, "\n %s %d rc1:%d rc:%d rc2:%d, rc3:%d\n",__FUNCTION__,__LINE__, rc1, rc,rc2,rc3);
limin.tian20df7d42023-02-10 10:05:52 +0800251 if (rc1 >= 0 && rc2 >= 0 && rc3 >= 0)
252 ret = 0;
253 }
254 }
255 if (conn)
256 mesonConnectorDestroy(drmFd,conn);
257 return ret;
258}
259
260ENUM_MESON_CONN_CONNECTION meson_drm_getConnectionStatus(int drmFd, MESON_CONNECTOR_TYPE connType)
261{
262 ENUM_MESON_CONN_CONNECTION ret = MESON_UNKNOWNCONNECTION;
263 struct mesonConnector* conn = NULL;
264 if ( drmFd < 0) {
limin.tianfe2ab442023-03-06 08:40:15 +0000265 fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800266 return ret;
267 }
268 conn = get_current_connector(drmFd, connType);
269 if (conn) {
270 int ConnectState = -1;
271 ConnectState = mesonConnectorGetConnectState(conn);
272 if (ConnectState == 1) {
273 ret = MESON_CONNECTED;
274 } else if (ConnectState == 2) {
275 ret = MESON_DISCONNECTED;
276 } else {
277 ret = MESON_UNKNOWNCONNECTION;
278 }
279 } else {
limin.tianfe2ab442023-03-06 08:40:15 +0000280 fprintf(stderr, "\n drm open fail\n");
limin.tian20df7d42023-02-10 10:05:52 +0800281 }
282 if (conn)
283 mesonConnectorDestroy(drmFd,conn);
284 return ret;
285}
286
287ENUM_MESON_COLOR_SPACE meson_drm_getColorSpace(int drmFd, MESON_CONNECTOR_TYPE connType )
288{
289 char propName[PROP_NAME_MAX_LEN] = {'\0'};
290 sprintf( propName, "%s", DRM_CONNECTOR_PROP_COLOR_SPACE);
291 uint32_t value = 0;
292 ENUM_MESON_COLOR_SPACE colorSpace = MESON_COLOR_SPACE_RESERVED;
293 if ( drmFd < 0) {
limin.tianfe2ab442023-03-06 08:40:15 +0000294 fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800295 return colorSpace;
296 }
297 if ( 0 == meson_drm_get_conn_prop_value(drmFd, connType, propName, &value )) {
298 switch (value)
299 {
300 case 0:
301 colorSpace = MESON_COLOR_SPACE_RGB;
302 break;
303 case 1:
304 colorSpace = MESON_COLOR_SPACE_YCBCR422;
305 break;
306 case 2:
307 colorSpace = MESON_COLOR_SPACE_YCBCR444;
308 break;
309 case 3:
310 colorSpace = MESON_COLOR_SPACE_YCBCR420;
311 break;
312 default:
313 colorSpace = MESON_COLOR_SPACE_RESERVED;
314 break;
315 }
316 } else {
limin.tianfe2ab442023-03-06 08:40:15 +0000317 fprintf(stderr, "\n%s %d fail\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800318 }
319 return colorSpace;
320}
321int meson_drm_setColorSpace(int drmFd, drmModeAtomicReq *req,
322 ENUM_MESON_COLOR_SPACE colorSpace, MESON_CONNECTOR_TYPE connType)
323{
324 int ret = -1;
325 uint32_t connId = 0;
326 int rc = -1;
327 struct mesonConnector* conn = NULL;
328 if ( drmFd < 0 || req == NULL) {
limin.tianfe2ab442023-03-06 08:40:15 +0000329 fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800330 return ret;
331 }
332 conn = get_current_connector(drmFd, connType);
333 if (conn) {
334 connId = mesonConnectorGetId(conn);
335 rc = meson_drm_set_property(drmFd, req, connId, DRM_MODE_OBJECT_CONNECTOR,
336 DRM_CONNECTOR_PROP_COLOR_SPACE, (uint64_t)colorSpace);
337 mesonConnectorDestroy(drmFd,conn);
338 }
339 if (rc >= 0)
340 ret = 0;
341 return ret;
342
343}
344
345uint32_t meson_drm_getColorDepth( int drmFd, MESON_CONNECTOR_TYPE connType )
346{
347 char propName[PROP_NAME_MAX_LEN] = {'\0'};
348 sprintf( propName, "%s", DRM_CONNECTOR_PROP_COLOR_DEPTH);
349 uint32_t value = 0;
350 if ( drmFd < 0) {
limin.tianfe2ab442023-03-06 08:40:15 +0000351 fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800352 return value;
353 }
354 if ( 0 != meson_drm_get_conn_prop_value( drmFd, connType, propName, &value )) {
limin.tianfe2ab442023-03-06 08:40:15 +0000355 fprintf(stderr, "\n%s %d fail\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800356 }
357 return value;
358}
359int meson_drm_setColorDepth(int drmFd, drmModeAtomicReq *req,
360 uint32_t colorDepth, MESON_CONNECTOR_TYPE connType)
361{
362 int ret = -1;
363 int rc = -1;
364 struct mesonConnector* conn = NULL;
365 uint32_t connId = 0;
366 conn = get_current_connector(drmFd, connType);
367 if ( drmFd < 0 || req == NULL) {
limin.tianfe2ab442023-03-06 08:40:15 +0000368 fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800369 return ret;
370 }
371 if (conn) {
372 connId = mesonConnectorGetId(conn);
373 rc = meson_drm_set_property(drmFd, req, connId, DRM_MODE_OBJECT_CONNECTOR,
374 DRM_CONNECTOR_PROP_COLOR_DEPTH, (uint64_t)colorDepth);
375 mesonConnectorDestroy(drmFd,conn);
376 }
377 if (rc >= 0)
378 ret = 0;
379 return ret;
380}
381ENUM_MESON_HDR_POLICY meson_drm_getHDRPolicy( int drmFd, MESON_CONNECTOR_TYPE connType )
382{
383 char propName[PROP_NAME_MAX_LEN] = {'\0'};
384 sprintf( propName, "%s", DRM_CONNECTOR_PROP_TX_HDR_POLICY);
385 uint32_t value = 0;
386 ENUM_MESON_HDR_POLICY hdrPolicy = MESON_HDR_POLICY_FOLLOW_SINK;
387 if ( drmFd < 0) {
limin.tianfe2ab442023-03-06 08:40:15 +0000388 fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800389 return hdrPolicy;
390 }
391 if ( 0 == meson_drm_get_crtc_prop_value( drmFd, connType, propName, &value )) {
392 if (value == 0)
393 hdrPolicy = MESON_HDR_POLICY_FOLLOW_SINK;
394 if (value == 1)
395 hdrPolicy = MESON_HDR_POLICY_FOLLOW_SOURCE;
396 }
397 return hdrPolicy;
398}
399
400int meson_drm_setHDRPolicy(int drmFd, drmModeAtomicReq *req,
401 ENUM_MESON_HDR_POLICY hdrPolicy, MESON_CONNECTOR_TYPE connType)
402{
403 int ret = -1;
404 int rc = -1;
405 struct mesonConnector* conn = NULL;
406 uint32_t crtcId = 0;
407 conn = get_current_connector(drmFd, connType);
408 if ( drmFd < 0 || req == NULL) {
limin.tianfe2ab442023-03-06 08:40:15 +0000409 fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800410 return ret;
411 }
412 if (conn) {
413 crtcId = mesonConnectorGetCRTCId(conn);
414 rc = meson_drm_set_property(drmFd, req, crtcId, DRM_MODE_OBJECT_CRTC,
415 DRM_CONNECTOR_PROP_TX_HDR_POLICY, (uint64_t)hdrPolicy);
416 mesonConnectorDestroy(drmFd,conn);
417 }
418 if (rc >= 0)
419 ret = 0;
420 return ret;
421}
422
423ENUM_MESON_HDCP_VERSION meson_drm_getHdcpVersion( int drmFd, MESON_CONNECTOR_TYPE connType )
424{
425 char propName[PROP_NAME_MAX_LEN] = {'\0'};
426 sprintf( propName, "%s", DRM_CONNECTOR_PROP_TX_HDCP_AUTH_MODE);
427 uint32_t value = 0;
428 ENUM_MESON_HDCP_VERSION hdcpVersion = MESON_HDCP_RESERVED;
429 if ( drmFd < 0) {
limin.tianfe2ab442023-03-06 08:40:15 +0000430 fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800431 return hdcpVersion;
432 }
433 if ( 0 == meson_drm_get_conn_prop_value( drmFd, connType, propName, &value )) {
434 if (value & 0x1)
435 hdcpVersion = MESON_HDCP_14;
436 if (value & 0x2)
437 hdcpVersion = MESON_HDCP_22;
438 }
439 return hdcpVersion;
440}
441
442ENUM_MESON_HDR_MODE meson_drm_getHdrStatus(int drmFd, MESON_CONNECTOR_TYPE connType )
443{
444 char propName[PROP_NAME_MAX_LEN] = {'\0'};
445 sprintf( propName, "%s", DRM_CONNECTOR_PROP_TX_HDR_MODE);
446 uint32_t value = 0;
447 ENUM_MESON_HDR_MODE hdrMode = MESON_SDR;
448 if ( drmFd < 0) {
limin.tianfe2ab442023-03-06 08:40:15 +0000449 fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800450 return hdrMode;
451 }
452 if ( 0 == meson_drm_get_conn_prop_value( drmFd, connType, propName, &value )) {
453 switch (value)
454 {
455 case 0:
456 hdrMode = MESON_HDR10PLUS;
457 break;
458 case 1:
459 hdrMode = MESON_DOLBYVISION_STD;
460 break;
461 case 2:
462 hdrMode = MESON_DOLBYVISION_LL;
463 break;
464 case 3:
465 hdrMode = MESON_HDR10_ST2084;
466 break;
467 case 4:
468 hdrMode = MESON_HDR10_TRADITIONAL;
469 break;
470 case 5:
471 hdrMode = MESON_HDR_HLG;
472 break;
473 case 6:
474 hdrMode = MESON_SDR;
475 break;
476 default:
477 hdrMode = MESON_SDR;
478 break;
479 }
480 } else {
limin.tianfe2ab442023-03-06 08:40:15 +0000481 fprintf(stderr, "\n%s %d fail\n",__FUNCTION__,__LINE__);
limin.tian20df7d42023-02-10 10:05:52 +0800482 }
483 return hdrMode;
484}
limin.tianfe2ab442023-03-06 08:40:15 +0000485void meson_drm_getEDIDData(int drmFd, MESON_CONNECTOR_TYPE connType, int * data_Len, char **data )
486{
487 int i = 0;
488 int count = 0;
489 char* edid_data = NULL;
490 struct mesonConnector* conn = NULL;
491 if (drmFd < 0 || data_Len == NULL || data == NULL) {
492 fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
493 return;
494 }
495 conn = get_current_connector(drmFd, connType);
496 if (conn == NULL) {
497 fprintf(stderr, "\n%s %d connector create fail.return \n",__FUNCTION__,__LINE__);
498 return;
499 }
500 if (0 != mesonConnectorGetEdidBlob(conn, &count, &edid_data))
501 goto out;
502 char* edid = (char*)calloc(count, sizeof(char));
503 if (edid == NULL) {
504 fprintf(stderr, "\n%s %d edid alloc mem fail.return\n",__FUNCTION__,__LINE__);
505 return;
506 }
507 for (i = 0; i < count; i++)
508 {
509 edid[i] = edid_data[i];
510 }
511 *data_Len = count;
512 *data = edid;
513out:
514 if (conn)
515 mesonConnectorDestroy(drmFd,conn);
516}
517
518int meson_drm_setAVMute(int drmFd, drmModeAtomicReq *req,
519 bool mute, MESON_CONNECTOR_TYPE connType)
520
521{
522 int ret = -1;
523 int rc = -1;
524 struct mesonConnector* conn = NULL;
525 uint32_t connId = 0;
526 if ( drmFd < 0 || req == NULL) {
527 fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
528 return ret;
529 }
530 conn = get_current_connector(drmFd, connType);
531 if (conn) {
532 connId = mesonConnectorGetId(conn);
533 rc = meson_drm_set_property(drmFd, req, connId, DRM_MODE_OBJECT_CONNECTOR,
534 MESON_DRM_HDMITX_PROP_AVMUTE, (uint64_t)mute);
535 mesonConnectorDestroy(drmFd,conn);
536 }
537 if (rc >= 0)
538 ret = 0;
539 return ret;
540}
541ENUM_MESON_HDCPAUTH_STATUS meson_drm_getHdcpAuthStatus( int drmFd, MESON_CONNECTOR_TYPE connType )
542{
543 char propName[PROP_NAME_MAX_LEN] = {'\0'};
544 sprintf( propName, "%s", DRM_CONNECTOR_PROP_CONTENT_PROTECTION);
545 uint32_t value = 0;
546 ENUM_MESON_HDCPAUTH_STATUS hdcpAuthStatus = MESON_AUTH_STATUS_FAIL;
547 if ( drmFd < 0 ) {
548 fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
549 return hdcpAuthStatus;
550 }
551 if ( 0 == meson_drm_get_conn_prop_value( drmFd, connType, propName, &value )) {
552 if (value == 2)
553 hdcpAuthStatus = MESON_AUTH_STATUS_SUCCESS;
554 }
555 return hdcpAuthStatus;
556}
557
558int meson_drm_setHDCPEnable(int drmFd, drmModeAtomicReq *req,
559 bool enable, MESON_CONNECTOR_TYPE connType)
560
561{
562 int ret = -1;
563 int rc = -1;
564 struct mesonConnector* conn = NULL;
565 uint32_t connId = 0;
566 if ( drmFd < 0 || req == NULL) {
567 fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
568 return ret;
569 }
570 conn = get_current_connector(drmFd, connType);
571 if (conn) {
572 connId = mesonConnectorGetId(conn);
573 rc = meson_drm_set_property(drmFd, req, connId, DRM_MODE_OBJECT_CONNECTOR,
574 DRM_CONNECTOR_PROP_CONTENT_PROTECTION, (uint64_t)enable);
575 mesonConnectorDestroy(drmFd,conn);
576 }
577 if (rc >= 0)
578 ret = 0;
579 return ret;
580}
581
582
limin.tian20df7d42023-02-10 10:05:52 +0800583