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" |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 20 | #include "drmdevice.h" |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 21 | |
| 22 | #include <errno.h> |
| 23 | #include <stdint.h> |
| 24 | |
John Stultz | 9057a6f | 2018-04-26 12:05:55 -0700 | [diff] [blame] | 25 | #include <log/log.h> |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 26 | #include <xf86drmMode.h> |
| 27 | |
| 28 | namespace android { |
| 29 | |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 30 | DrmConnector::DrmConnector(DrmDevice *drm, drmModeConnectorPtr c, |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 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 | } |
Alexandru Gheorghe | 364f957 | 2018-03-21 11:40:01 +0000 | [diff] [blame] | 55 | if (writeback()) { |
| 56 | ret = drm_->GetConnectorProperty(*this, "WRITEBACK_PIXEL_FORMATS", |
| 57 | &writeback_pixel_formats_); |
| 58 | if (ret) { |
| 59 | ALOGE("Could not get WRITEBACK_PIXEL_FORMATS connector_id = %d\n", id_); |
| 60 | return ret; |
| 61 | } |
| 62 | ret = drm_->GetConnectorProperty(*this, "WRITEBACK_FB_ID", |
| 63 | &writeback_fb_id_); |
| 64 | if (ret) { |
| 65 | ALOGE("Could not get WRITEBACK_FB_ID connector_id = %d\n", id_); |
| 66 | return ret; |
| 67 | } |
| 68 | ret = drm_->GetConnectorProperty(*this, "WRITEBACK_OUT_FENCE_PTR", |
| 69 | &writeback_out_fence_); |
| 70 | if (ret) { |
| 71 | ALOGE("Could not get WRITEBACK_OUT_FENCE_PTR connector_id = %d\n", id_); |
| 72 | return ret; |
| 73 | } |
| 74 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | uint32_t DrmConnector::id() const { |
| 79 | return id_; |
| 80 | } |
| 81 | |
| 82 | int DrmConnector::display() const { |
| 83 | return display_; |
| 84 | } |
| 85 | |
| 86 | void DrmConnector::set_display(int display) { |
| 87 | display_ = display; |
| 88 | } |
| 89 | |
Robert Foss | 610d989 | 2017-11-01 12:50:04 -0500 | [diff] [blame] | 90 | bool DrmConnector::internal() const { |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 91 | return type_ == DRM_MODE_CONNECTOR_LVDS || type_ == DRM_MODE_CONNECTOR_eDP || |
Rob Herring | 9b10c5f | 2015-12-04 17:14:31 -0600 | [diff] [blame] | 92 | type_ == DRM_MODE_CONNECTOR_DSI || type_ == DRM_MODE_CONNECTOR_VIRTUAL; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 93 | } |
| 94 | |
Robert Foss | 610d989 | 2017-11-01 12:50:04 -0500 | [diff] [blame] | 95 | bool DrmConnector::external() const { |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 96 | return type_ == DRM_MODE_CONNECTOR_HDMIA || |
| 97 | type_ == DRM_MODE_CONNECTOR_DisplayPort || |
Mauro Rossi | 556bedf | 2018-01-06 00:59:59 +0100 | [diff] [blame] | 98 | type_ == DRM_MODE_CONNECTOR_DVID || type_ == DRM_MODE_CONNECTOR_DVII || |
| 99 | type_ == DRM_MODE_CONNECTOR_VGA; |
Robert Foss | 610d989 | 2017-11-01 12:50:04 -0500 | [diff] [blame] | 100 | } |
| 101 | |
Alexandru Gheorghe | 364f957 | 2018-03-21 11:40:01 +0000 | [diff] [blame] | 102 | bool DrmConnector::writeback() const { |
| 103 | #ifdef DRM_MODE_CONNECTOR_WRITEBACK |
| 104 | return type_ == DRM_MODE_CONNECTOR_WRITEBACK; |
| 105 | #else |
| 106 | return false; |
| 107 | #endif |
| 108 | } |
| 109 | |
Robert Foss | 610d989 | 2017-11-01 12:50:04 -0500 | [diff] [blame] | 110 | bool DrmConnector::valid_type() const { |
Alexandru Gheorghe | 364f957 | 2018-03-21 11:40:01 +0000 | [diff] [blame] | 111 | return internal() || external() || writeback(); |
Robert Foss | 610d989 | 2017-11-01 12:50:04 -0500 | [diff] [blame] | 112 | } |
| 113 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 114 | int DrmConnector::UpdateModes() { |
| 115 | int fd = drm_->fd(); |
| 116 | |
| 117 | drmModeConnectorPtr c = drmModeGetConnector(fd, id_); |
| 118 | if (!c) { |
| 119 | ALOGE("Failed to get connector %d", id_); |
| 120 | return -ENODEV; |
| 121 | } |
| 122 | |
Sean Paul | 0921649 | 2015-10-26 15:36:37 -0400 | [diff] [blame] | 123 | state_ = c->connection; |
| 124 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 125 | std::vector<DrmMode> new_modes; |
| 126 | for (int i = 0; i < c->count_modes; ++i) { |
| 127 | bool exists = false; |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 128 | for (const DrmMode &mode : modes_) { |
| 129 | if (mode == c->modes[i]) { |
| 130 | new_modes.push_back(mode); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 131 | exists = true; |
| 132 | break; |
| 133 | } |
| 134 | } |
| 135 | if (exists) |
| 136 | continue; |
| 137 | |
| 138 | DrmMode m(&c->modes[i]); |
| 139 | m.set_id(drm_->next_mode_id()); |
| 140 | new_modes.push_back(m); |
| 141 | } |
| 142 | modes_.swap(new_modes); |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | const DrmMode &DrmConnector::active_mode() const { |
| 147 | return active_mode_; |
| 148 | } |
| 149 | |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 150 | void DrmConnector::set_active_mode(const DrmMode &mode) { |
| 151 | active_mode_ = mode; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | const DrmProperty &DrmConnector::dpms_property() const { |
| 155 | return dpms_property_; |
| 156 | } |
| 157 | |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 158 | const DrmProperty &DrmConnector::crtc_id_property() const { |
| 159 | return crtc_id_property_; |
| 160 | } |
| 161 | |
Alexandru Gheorghe | 364f957 | 2018-03-21 11:40:01 +0000 | [diff] [blame] | 162 | const DrmProperty &DrmConnector::writeback_pixel_formats() const { |
| 163 | return writeback_pixel_formats_; |
| 164 | } |
| 165 | |
| 166 | const DrmProperty &DrmConnector::writeback_fb_id() const { |
| 167 | return writeback_fb_id_; |
| 168 | } |
| 169 | |
| 170 | const DrmProperty &DrmConnector::writeback_out_fence() const { |
| 171 | return writeback_out_fence_; |
| 172 | } |
| 173 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 174 | DrmEncoder *DrmConnector::encoder() const { |
| 175 | return encoder_; |
| 176 | } |
| 177 | |
| 178 | void DrmConnector::set_encoder(DrmEncoder *encoder) { |
| 179 | encoder_ = encoder; |
| 180 | } |
| 181 | |
Sean Paul | 0921649 | 2015-10-26 15:36:37 -0400 | [diff] [blame] | 182 | drmModeConnection DrmConnector::state() const { |
| 183 | return state_; |
| 184 | } |
| 185 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 186 | uint32_t DrmConnector::mm_width() const { |
| 187 | return mm_width_; |
| 188 | } |
| 189 | |
| 190 | uint32_t DrmConnector::mm_height() const { |
| 191 | return mm_height_; |
| 192 | } |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 193 | } // namespace android |