blob: 145518fb59f05103aa921776ca783be046db408c [file] [log] [blame]
Sean Paul6a55e9f2015-04-30 15:31:06 -04001/*
2 * Copyright (C) 2015 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#define LOG_TAG "hwc-drm-connector"
18
19#include "drmconnector.h"
20#include "drmresources.h"
21
22#include <errno.h>
23#include <stdint.h>
24
25#include <cutils/log.h>
26#include <xf86drmMode.h>
27
28namespace android {
29
30DrmConnector::DrmConnector(DrmResources *drm, drmModeConnectorPtr c,
31 DrmEncoder *current_encoder,
32 std::vector<DrmEncoder *> &possible_encoders)
33 : drm_(drm),
34 id_(c->connector_id),
35 encoder_(current_encoder),
36 display_(-1),
37 type_(c->connector_type),
38 state_(c->connection),
39 mm_width_(c->mmWidth),
40 mm_height_(c->mmHeight),
41 possible_encoders_(possible_encoders) {
42}
43
Sean Paul6a55e9f2015-04-30 15:31:06 -040044int DrmConnector::Init() {
45 int ret = drm_->GetConnectorProperty(*this, "DPMS", &dpms_property_);
46 if (ret) {
47 ALOGE("Could not get DPMS property\n");
48 return ret;
49 }
Sean Paul877be972015-06-03 14:08:27 -040050 ret = drm_->GetConnectorProperty(*this, "CRTC_ID", &crtc_id_property_);
51 if (ret) {
52 ALOGE("Could not get CRTC_ID property\n");
53 return ret;
54 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040055 return 0;
56}
57
58uint32_t DrmConnector::id() const {
59 return id_;
60}
61
62int DrmConnector::display() const {
63 return display_;
64}
65
66void DrmConnector::set_display(int display) {
67 display_ = display;
68}
69
Robert Foss610d9892017-11-01 12:50:04 -050070bool DrmConnector::internal() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040071 return type_ == DRM_MODE_CONNECTOR_LVDS || type_ == DRM_MODE_CONNECTOR_eDP ||
Rob Herring9b10c5f2015-12-04 17:14:31 -060072 type_ == DRM_MODE_CONNECTOR_DSI || type_ == DRM_MODE_CONNECTOR_VIRTUAL;
Sean Paul6a55e9f2015-04-30 15:31:06 -040073}
74
Robert Foss610d9892017-11-01 12:50:04 -050075bool DrmConnector::external() const {
Mauro Rossi556bedf2018-01-06 00:59:59 +010076 return type_ == DRM_MODE_CONNECTOR_HDMIA || type_ == DRM_MODE_CONNECTOR_DisplayPort ||
77 type_ == DRM_MODE_CONNECTOR_DVID || type_ == DRM_MODE_CONNECTOR_DVII ||
78 type_ == DRM_MODE_CONNECTOR_VGA;
Robert Foss610d9892017-11-01 12:50:04 -050079}
80
81bool DrmConnector::valid_type() const {
82 return internal() || external();
83}
84
Sean Paul6a55e9f2015-04-30 15:31:06 -040085int DrmConnector::UpdateModes() {
86 int fd = drm_->fd();
87
88 drmModeConnectorPtr c = drmModeGetConnector(fd, id_);
89 if (!c) {
90 ALOGE("Failed to get connector %d", id_);
91 return -ENODEV;
92 }
93
Sean Paul09216492015-10-26 15:36:37 -040094 state_ = c->connection;
95
Sean Paul6a55e9f2015-04-30 15:31:06 -040096 std::vector<DrmMode> new_modes;
97 for (int i = 0; i < c->count_modes; ++i) {
98 bool exists = false;
Zach Reiznerff30b522015-10-28 19:08:45 -070099 for (const DrmMode &mode : modes_) {
100 if (mode == c->modes[i]) {
101 new_modes.push_back(mode);
Sean Paul6a55e9f2015-04-30 15:31:06 -0400102 exists = true;
103 break;
104 }
105 }
106 if (exists)
107 continue;
108
109 DrmMode m(&c->modes[i]);
110 m.set_id(drm_->next_mode_id());
111 new_modes.push_back(m);
112 }
113 modes_.swap(new_modes);
114 return 0;
115}
116
117const DrmMode &DrmConnector::active_mode() const {
118 return active_mode_;
119}
120
Sean Paul877be972015-06-03 14:08:27 -0400121void DrmConnector::set_active_mode(const DrmMode &mode) {
122 active_mode_ = mode;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400123}
124
125const DrmProperty &DrmConnector::dpms_property() const {
126 return dpms_property_;
127}
128
Sean Paul877be972015-06-03 14:08:27 -0400129const DrmProperty &DrmConnector::crtc_id_property() const {
130 return crtc_id_property_;
131}
132
Sean Paul6a55e9f2015-04-30 15:31:06 -0400133DrmEncoder *DrmConnector::encoder() const {
134 return encoder_;
135}
136
137void DrmConnector::set_encoder(DrmEncoder *encoder) {
138 encoder_ = encoder;
139}
140
Sean Paul09216492015-10-26 15:36:37 -0400141drmModeConnection DrmConnector::state() const {
142 return state_;
143}
144
Sean Paul6a55e9f2015-04-30 15:31:06 -0400145uint32_t DrmConnector::mm_width() const {
146 return mm_width_;
147}
148
149uint32_t DrmConnector::mm_height() const {
150 return mm_height_;
151}
152}