2 * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "input_drm.h"
20 #include <sys/types.h>
25 #include <xf86drmMode.h>
28 #include "input_hal.h"
29 #include "input_hal_debug.h"
31 #define DIR_PATH "/dev/dri/card0"
32 #define DEFAULT_RESOLUTION_HORIZONTAL 1280 /* Horizontal resolution default value */
33 #define DEFAULT_RESOLUTION_VERTICAL 800 /* Vertical resolution default value */
35 * Panel resolution acquisition / GetPanelSpecResolutionInput
37 int GetPanelSpecResolutionInput(int *reso_h, int *reso_v) {
38 if ((NULL == reso_h) || (NULL == reso_v)) {
39 return HAL_INPUT_RET_ERROR;
44 drmModeRes *resources = NULL;
45 drmModeConnector *connector = NULL;
46 drmModeEncoder *encoder = NULL;
47 drmModeCrtc *crtc = NULL;
49 fd = open(DIR_PATH, O_RDWR);
51 INPUT_ERROR_LOG("DRI Open Error=%s\n", DIR_PATH);
55 resources = drmModeGetResources(fd);
57 INPUT_ERROR_LOG("No resources\n");
60 if (2 > resources->count_connectors) {
61 INPUT_ERROR_LOG("DRI Connect Num Error connectors=%d\n",
62 resources->count_connectors);
66 connector = drmModeGetConnector(fd, resources->connectors[1]);
68 INPUT_ERROR_LOG("No Connector\n");
72 if ((DRM_MODE_CONNECTED == connector->connection) &&(connector->count_modes > 0)) {
74 INPUT_ERROR_LOG("Not found connected connector\n");
78 encoder = drmModeGetEncoder(fd, connector->encoder_id);
80 INPUT_ERROR_LOG("drmModeGetEncoder null\n");
84 crtc = drmModeGetCrtc(fd, encoder->crtc_id);
86 INPUT_ERROR_LOG("drmModeGetCrtc null\n");
90 *reso_h = crtc->mode.hdisplay;
91 *reso_v = crtc->mode.vdisplay;
93 drmModeFreeCrtc(crtc);
94 drmModeFreeEncoder(encoder);
95 drmModeFreeConnector(connector);
96 drmModeFreeResources(resources);
99 INPUT_LOG_TRACE("width=%d height=%d\n", *reso_h, *reso_v);
100 return HAL_INPUT_RET_NORMAL;
105 drmModeFreeEncoder(encoder);
108 drmModeFreeConnector(connector);
111 drmModeFreeResources(resources);
117 INPUT_ERROR_LOG("Use Default Resolution\n");
118 *reso_h = DEFAULT_RESOLUTION_HORIZONTAL;
119 *reso_v = DEFAULT_RESOLUTION_VERTICAL;
121 return HAL_INPUT_RET_ERROR;
123 *reso_h = DEFAULT_RESOLUTION_HORIZONTAL;
124 *reso_v = DEFAULT_RESOLUTION_VERTICAL;
126 return HAL_INPUT_RET_NORMAL;