Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 28 | namespace android { |
| 29 | |
| 30 | DrmConnector::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 Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 44 | int 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 Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 50 | 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 Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | uint32_t DrmConnector::id() const { |
| 59 | return id_; |
| 60 | } |
| 61 | |
| 62 | int DrmConnector::display() const { |
| 63 | return display_; |
| 64 | } |
| 65 | |
| 66 | void DrmConnector::set_display(int display) { |
| 67 | display_ = display; |
| 68 | } |
| 69 | |
Robert Foss | 610d989 | 2017-11-01 12:50:04 -0500 | [diff] [blame^] | 70 | bool DrmConnector::internal() const { |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 71 | return type_ == DRM_MODE_CONNECTOR_LVDS || type_ == DRM_MODE_CONNECTOR_eDP || |
Rob Herring | 9b10c5f | 2015-12-04 17:14:31 -0600 | [diff] [blame] | 72 | type_ == DRM_MODE_CONNECTOR_DSI || type_ == DRM_MODE_CONNECTOR_VIRTUAL; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 73 | } |
| 74 | |
Robert Foss | 610d989 | 2017-11-01 12:50:04 -0500 | [diff] [blame^] | 75 | bool DrmConnector::external() const { |
| 76 | return type_ == DRM_MODE_CONNECTOR_HDMIA; |
| 77 | } |
| 78 | |
| 79 | bool DrmConnector::valid_type() const { |
| 80 | return internal() || external(); |
| 81 | } |
| 82 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 83 | int DrmConnector::UpdateModes() { |
| 84 | int fd = drm_->fd(); |
| 85 | |
| 86 | drmModeConnectorPtr c = drmModeGetConnector(fd, id_); |
| 87 | if (!c) { |
| 88 | ALOGE("Failed to get connector %d", id_); |
| 89 | return -ENODEV; |
| 90 | } |
| 91 | |
Sean Paul | 0921649 | 2015-10-26 15:36:37 -0400 | [diff] [blame] | 92 | state_ = c->connection; |
| 93 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 94 | std::vector<DrmMode> new_modes; |
| 95 | for (int i = 0; i < c->count_modes; ++i) { |
| 96 | bool exists = false; |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 97 | for (const DrmMode &mode : modes_) { |
| 98 | if (mode == c->modes[i]) { |
| 99 | new_modes.push_back(mode); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 100 | exists = true; |
| 101 | break; |
| 102 | } |
| 103 | } |
| 104 | if (exists) |
| 105 | continue; |
| 106 | |
| 107 | DrmMode m(&c->modes[i]); |
| 108 | m.set_id(drm_->next_mode_id()); |
| 109 | new_modes.push_back(m); |
| 110 | } |
| 111 | modes_.swap(new_modes); |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | const DrmMode &DrmConnector::active_mode() const { |
| 116 | return active_mode_; |
| 117 | } |
| 118 | |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 119 | void DrmConnector::set_active_mode(const DrmMode &mode) { |
| 120 | active_mode_ = mode; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | const DrmProperty &DrmConnector::dpms_property() const { |
| 124 | return dpms_property_; |
| 125 | } |
| 126 | |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 127 | const DrmProperty &DrmConnector::crtc_id_property() const { |
| 128 | return crtc_id_property_; |
| 129 | } |
| 130 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 131 | DrmEncoder *DrmConnector::encoder() const { |
| 132 | return encoder_; |
| 133 | } |
| 134 | |
| 135 | void DrmConnector::set_encoder(DrmEncoder *encoder) { |
| 136 | encoder_ = encoder; |
| 137 | } |
| 138 | |
Sean Paul | 0921649 | 2015-10-26 15:36:37 -0400 | [diff] [blame] | 139 | drmModeConnection DrmConnector::state() const { |
| 140 | return state_; |
| 141 | } |
| 142 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 143 | uint32_t DrmConnector::mm_width() const { |
| 144 | return mm_width_; |
| 145 | } |
| 146 | |
| 147 | uint32_t DrmConnector::mm_height() const { |
| 148 | return mm_height_; |
| 149 | } |
| 150 | } |