diff options
author | Eric Ruei | 2017-01-31 16:16:12 -0600 |
---|---|---|
committer | Karthik Ramanan | 2017-03-16 06:33:05 -0500 |
commit | 0fa27a594fd3290644f5666eac62dc570f26f866 (patch) | |
tree | 20d3da0dc8784bd82b2b717a9017694375a85179 | |
parent | b1ce0f606029efe8f16f1d7dbfeb1453107b5fc7 (diff) | |
download | kmscube-0fa27a594fd3290644f5666eac62dc570f26f866.tar.gz kmscube-0fa27a594fd3290644f5666eac62dc570f26f866.tar.xz kmscube-0fa27a594fd3290644f5666eac62dc570f26f866.zip |
kmscube.c: init_drm(): handle usecase where display is disabled
In some usecases HDMI is connected but is disabled by default.
In such scenario, connector->encoder_id and encoder->crtc_id
may be 0. This patch iterates over all possible encoders and
CRTCs to find and store the encoder and CRTC accordingly.
Signed-off-by: Eric Ruei <e-ruei1@ti.com>
-rw-r--r-- | kmscube.c | 41 |
1 files changed, 36 insertions, 5 deletions
@@ -91,7 +91,7 @@ static int init_drm(void) | |||
91 | drmModeEncoder *encoder = NULL; | 91 | drmModeEncoder *encoder = NULL; |
92 | drmModeCrtc *crtc = NULL; | 92 | drmModeCrtc *crtc = NULL; |
93 | 93 | ||
94 | int i, j; | 94 | int i, j, k; |
95 | uint32_t maxRes, curRes; | 95 | uint32_t maxRes, curRes; |
96 | 96 | ||
97 | for (i = 0; i < ARRAY_SIZE(modules); i++) { | 97 | for (i = 0; i < ARRAY_SIZE(modules); i++) { |
@@ -123,18 +123,49 @@ static int init_drm(void) | |||
123 | if (connector->connection == DRM_MODE_CONNECTED) { | 123 | if (connector->connection == DRM_MODE_CONNECTED) { |
124 | 124 | ||
125 | /* find the matched encoders */ | 125 | /* find the matched encoders */ |
126 | for (j=0; j<resources->count_encoders; j++) { | 126 | for (j=0; j<connector->count_encoders; j++) { |
127 | encoder = drmModeGetEncoder(drm.fd, resources->encoders[j]); | 127 | encoder = drmModeGetEncoder(drm.fd, connector->encoders[j]); |
128 | |||
129 | /* Take the fisrt one, if none is assigned */ | ||
130 | if (!connector->encoder_id) | ||
131 | { | ||
132 | connector->encoder_id = encoder->encoder_id; | ||
133 | } | ||
134 | |||
128 | if (encoder->encoder_id == connector->encoder_id) | 135 | if (encoder->encoder_id == connector->encoder_id) |
136 | { | ||
137 | /* find the first valid CRTC if not assigned */ | ||
138 | if (!encoder->crtc_id) | ||
139 | { | ||
140 | for (k = 0; k < resources->count_crtcs; ++k) { | ||
141 | /* check whether this CRTC works with the encoder */ | ||
142 | if (!(encoder->possible_crtcs & (1 << k))) | ||
143 | continue; | ||
144 | |||
145 | encoder->crtc_id = resources->crtcs[k]; | ||
146 | break; | ||
147 | } | ||
148 | |||
149 | if (!encoder->crtc_id) | ||
150 | { | ||
151 | printf("Encoder(%d): no CRTC find!\n", encoder->encoder_id); | ||
152 | drmModeFreeEncoder(encoder); | ||
153 | encoder = NULL; | ||
154 | continue; | ||
155 | } | ||
156 | } | ||
157 | |||
129 | break; | 158 | break; |
159 | } | ||
130 | 160 | ||
131 | drmModeFreeEncoder(encoder); | 161 | drmModeFreeEncoder(encoder); |
132 | encoder = NULL; | 162 | encoder = NULL; |
133 | } | 163 | } |
134 | 164 | ||
135 | if (!encoder) { | 165 | if (!encoder) { |
136 | printf("no encoder!\n"); | 166 | printf("Connector (%d): no encoder!\n", connector->connector_id); |
137 | return -1; | 167 | drmModeFreeConnector(connector); |
168 | continue; | ||
138 | } | 169 | } |
139 | 170 | ||
140 | /* choose the current or first supported mode */ | 171 | /* choose the current or first supported mode */ |