Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2016, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #define pr_fmt(fmt) "sde-drm:[%s] " fmt, __func__ |
| 14 | #include "msm_drv.h" |
| 15 | |
| 16 | #include "sde_kms.h" |
| 17 | #include "sde_connector.h" |
| 18 | |
Lloyd Atkinson | b619197 | 2016-08-10 18:31:46 -0400 | [diff] [blame] | 19 | static const struct drm_prop_enum_list e_topology_name[] = { |
| 20 | {SDE_RM_TOPOLOGY_UNKNOWN, "sde_unknown"}, |
| 21 | {SDE_RM_TOPOLOGY_SINGLEPIPE, "sde_singlepipe"}, |
| 22 | {SDE_RM_TOPOLOGY_DUALPIPE, "sde_dualpipe"}, |
| 23 | {SDE_RM_TOPOLOGY_PPSPLIT, "sde_ppsplit"}, |
| 24 | {SDE_RM_TOPOLOGY_DUALPIPEMERGE, "sde_dualpipemerge"} |
| 25 | }; |
| 26 | static const struct drm_prop_enum_list e_topology_control[] = { |
| 27 | {SDE_RM_TOPCTL_RESERVE_LOCK, "reserve_lock"}, |
| 28 | {SDE_RM_TOPCTL_RESERVE_CLEAR, "reserve_clear"}, |
| 29 | {SDE_RM_TOPCTL_DSPP, "dspp"}, |
| 30 | {SDE_RM_TOPCTL_FORCE_TILING, "force_tiling"}, |
| 31 | {SDE_RM_TOPCTL_PPSPLIT, "ppsplit"} |
| 32 | }; |
| 33 | |
Clarence Ip | cb3afd4 | 2016-07-15 16:25:34 -0400 | [diff] [blame] | 34 | int sde_connector_get_info(struct drm_connector *connector, |
| 35 | struct msm_display_info *info) |
| 36 | { |
| 37 | struct sde_connector *c_conn; |
| 38 | |
| 39 | if (!connector || !info) { |
| 40 | SDE_ERROR("invalid argument(s), conn %pK, info %pK\n", |
| 41 | connector, info); |
| 42 | return -EINVAL; |
| 43 | } |
| 44 | |
| 45 | c_conn = to_sde_connector(connector); |
| 46 | |
| 47 | if (!c_conn->display || !c_conn->ops.get_info) { |
| 48 | SDE_ERROR("display info not supported for %pK\n", |
| 49 | c_conn->display); |
| 50 | return -EINVAL; |
| 51 | } |
| 52 | |
| 53 | return c_conn->ops.get_info(info, c_conn->display); |
| 54 | } |
| 55 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 56 | static void sde_connector_destroy(struct drm_connector *connector) |
| 57 | { |
| 58 | struct sde_connector *c_conn; |
| 59 | |
| 60 | if (!connector) { |
| 61 | SDE_ERROR("invalid connector\n"); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | c_conn = to_sde_connector(connector); |
| 66 | |
| 67 | if (c_conn->blob_sde_info) |
| 68 | drm_property_unreference_blob(c_conn->blob_sde_info); |
| 69 | msm_property_destroy(&c_conn->property_info); |
| 70 | |
| 71 | drm_connector_unregister(connector); |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 72 | sde_fence_deinit(&c_conn->retire_fence); |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 73 | drm_connector_cleanup(connector); |
| 74 | kfree(c_conn); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * _sde_connector_destroy_fb - clean up connector state's out_fb buffer |
| 79 | * @c_conn: Pointer to sde connector structure |
| 80 | * @c_state: Pointer to sde connector state structure |
| 81 | */ |
| 82 | static void _sde_connector_destroy_fb(struct sde_connector *c_conn, |
| 83 | struct sde_connector_state *c_state) |
| 84 | { |
| 85 | if (!c_state || !c_state->out_fb) { |
| 86 | SDE_ERROR("invalid state %pK\n", c_state); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | msm_framebuffer_cleanup(c_state->out_fb, |
| 91 | c_state->mmu_id); |
| 92 | drm_framebuffer_unreference(c_state->out_fb); |
| 93 | c_state->out_fb = NULL; |
| 94 | |
| 95 | if (c_conn) { |
| 96 | c_state->property_values[CONNECTOR_PROP_OUT_FB] = |
| 97 | msm_property_get_default(&c_conn->property_info, |
| 98 | CONNECTOR_PROP_OUT_FB); |
| 99 | } else { |
| 100 | c_state->property_values[CONNECTOR_PROP_OUT_FB] = ~0; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | static void sde_connector_atomic_destroy_state(struct drm_connector *connector, |
| 105 | struct drm_connector_state *state) |
| 106 | { |
| 107 | struct sde_connector *c_conn = NULL; |
| 108 | struct sde_connector_state *c_state = NULL; |
| 109 | |
| 110 | if (!state) { |
| 111 | SDE_ERROR("invalid state\n"); |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | /* |
| 116 | * The base DRM framework currently always passes in a NULL |
| 117 | * connector pointer. This is not correct, but attempt to |
| 118 | * handle that case as much as possible. |
| 119 | */ |
| 120 | if (connector) |
| 121 | c_conn = to_sde_connector(connector); |
| 122 | c_state = to_sde_connector_state(state); |
| 123 | |
| 124 | if (c_state->out_fb) |
| 125 | _sde_connector_destroy_fb(c_conn, c_state); |
| 126 | |
| 127 | if (!c_conn) { |
| 128 | kfree(c_state); |
| 129 | } else { |
| 130 | /* destroy value helper */ |
| 131 | msm_property_destroy_state(&c_conn->property_info, c_state, |
| 132 | c_state->property_values, 0); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | static void sde_connector_atomic_reset(struct drm_connector *connector) |
| 137 | { |
| 138 | struct sde_connector *c_conn; |
| 139 | struct sde_connector_state *c_state; |
| 140 | |
| 141 | if (!connector) { |
| 142 | SDE_ERROR("invalid connector\n"); |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | c_conn = to_sde_connector(connector); |
| 147 | |
| 148 | if (connector->state) { |
| 149 | sde_connector_atomic_destroy_state(connector, connector->state); |
| 150 | connector->state = 0; |
| 151 | } |
| 152 | |
| 153 | c_state = msm_property_alloc_state(&c_conn->property_info); |
| 154 | if (!c_state) { |
| 155 | SDE_ERROR("state alloc failed\n"); |
| 156 | return; |
| 157 | } |
| 158 | |
| 159 | /* reset value helper, zero out state structure and reset properties */ |
| 160 | msm_property_reset_state(&c_conn->property_info, c_state, |
| 161 | c_state->property_values, 0); |
| 162 | |
| 163 | c_state->base.connector = connector; |
| 164 | connector->state = &c_state->base; |
| 165 | } |
| 166 | |
| 167 | static struct drm_connector_state * |
| 168 | sde_connector_atomic_duplicate_state(struct drm_connector *connector) |
| 169 | { |
| 170 | struct sde_connector *c_conn; |
| 171 | struct sde_connector_state *c_state, *c_oldstate; |
| 172 | int rc; |
| 173 | |
| 174 | if (!connector || !connector->state) { |
| 175 | SDE_ERROR("invalid connector %pK\n", connector); |
| 176 | return NULL; |
| 177 | } |
| 178 | |
| 179 | c_conn = to_sde_connector(connector); |
| 180 | c_oldstate = to_sde_connector_state(connector->state); |
| 181 | c_state = msm_property_alloc_state(&c_conn->property_info); |
| 182 | if (!c_state) { |
| 183 | SDE_ERROR("state alloc failed\n"); |
| 184 | return NULL; |
| 185 | } |
| 186 | |
| 187 | /* duplicate value helper */ |
| 188 | msm_property_duplicate_state(&c_conn->property_info, |
| 189 | c_oldstate, c_state, c_state->property_values, 0); |
| 190 | |
| 191 | /* additional handling for drm framebuffer objects */ |
| 192 | if (c_state->out_fb) { |
| 193 | drm_framebuffer_reference(c_state->out_fb); |
| 194 | rc = msm_framebuffer_prepare(c_state->out_fb, |
| 195 | c_state->mmu_id); |
| 196 | if (rc) |
| 197 | SDE_ERROR("failed to prepare fb, %d\n", rc); |
| 198 | } |
| 199 | |
| 200 | return &c_state->base; |
| 201 | } |
| 202 | |
| 203 | static int sde_connector_atomic_set_property(struct drm_connector *connector, |
| 204 | struct drm_connector_state *state, |
| 205 | struct drm_property *property, |
| 206 | uint64_t val) |
| 207 | { |
| 208 | struct sde_connector *c_conn; |
| 209 | struct sde_connector_state *c_state; |
| 210 | int idx, rc; |
| 211 | |
| 212 | if (!connector || !state || !property) { |
| 213 | SDE_ERROR("invalid argument(s), conn %pK, state %pK, prp %pK\n", |
| 214 | connector, state, property); |
| 215 | return -EINVAL; |
| 216 | } |
| 217 | |
| 218 | c_conn = to_sde_connector(connector); |
| 219 | c_state = to_sde_connector_state(state); |
| 220 | |
| 221 | /* generic property handling */ |
| 222 | rc = msm_property_atomic_set(&c_conn->property_info, |
| 223 | c_state->property_values, 0, property, val); |
| 224 | if (rc) |
| 225 | goto end; |
| 226 | |
| 227 | /* connector-specific property handling */ |
| 228 | idx = msm_property_index(&c_conn->property_info, property); |
| 229 | |
| 230 | if (idx == CONNECTOR_PROP_OUT_FB) { |
| 231 | /* clear old fb, if present */ |
| 232 | if (c_state->out_fb) |
| 233 | _sde_connector_destroy_fb(c_conn, c_state); |
| 234 | |
| 235 | /* convert fb val to drm framebuffer and prepare it */ |
| 236 | c_state->out_fb = |
| 237 | drm_framebuffer_lookup(connector->dev, val); |
| 238 | if (!c_state->out_fb) { |
| 239 | SDE_ERROR("failed to look up fb %lld\n", val); |
| 240 | rc = -EFAULT; |
| 241 | } else { |
Alan Kwong | dfa8c08 | 2016-07-29 04:10:00 -0400 | [diff] [blame] | 242 | if (c_state->out_fb->flags & DRM_MODE_FB_SECURE) |
| 243 | c_state->mmu_id = |
| 244 | c_conn->mmu_id[SDE_IOMMU_DOMAIN_SECURE]; |
| 245 | else |
| 246 | c_state->mmu_id = |
| 247 | c_conn->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE]; |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 248 | |
| 249 | rc = msm_framebuffer_prepare(c_state->out_fb, |
| 250 | c_state->mmu_id); |
| 251 | if (rc) |
| 252 | SDE_ERROR("prep fb failed, %d\n", rc); |
| 253 | } |
| 254 | } |
| 255 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame^] | 256 | if (idx == CONNECTOR_PROP_TOPOLOGY_CONTROL) { |
| 257 | rc = sde_rm_check_property_topctl(val); |
| 258 | if (rc) |
| 259 | SDE_ERROR("invalid topology_control: 0x%llX\n", val); |
| 260 | } |
| 261 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 262 | /* check for custom property handling */ |
| 263 | if (!rc && c_conn->ops.set_property) { |
| 264 | rc = c_conn->ops.set_property(connector, |
| 265 | state, |
| 266 | idx, |
| 267 | val, |
| 268 | c_conn->display); |
| 269 | |
| 270 | /* potentially clean up out_fb if rc != 0 */ |
| 271 | if ((idx == CONNECTOR_PROP_OUT_FB) && rc) |
| 272 | _sde_connector_destroy_fb(c_conn, c_state); |
| 273 | } |
| 274 | end: |
| 275 | return rc; |
| 276 | } |
| 277 | |
| 278 | static int sde_connector_set_property(struct drm_connector *connector, |
| 279 | struct drm_property *property, |
| 280 | uint64_t val) |
| 281 | { |
| 282 | if (!connector) { |
| 283 | SDE_ERROR("invalid connector\n"); |
| 284 | return -EINVAL; |
| 285 | } |
| 286 | |
| 287 | return sde_connector_atomic_set_property(connector, |
| 288 | connector->state, property, val); |
| 289 | } |
| 290 | |
| 291 | static int sde_connector_atomic_get_property(struct drm_connector *connector, |
| 292 | const struct drm_connector_state *state, |
| 293 | struct drm_property *property, |
| 294 | uint64_t *val) |
| 295 | { |
| 296 | struct sde_connector *c_conn; |
| 297 | struct sde_connector_state *c_state; |
| 298 | int idx, rc = -EINVAL; |
| 299 | |
| 300 | if (!connector || !state) { |
| 301 | SDE_ERROR("invalid argument(s), conn %pK, state %pK\n", |
| 302 | connector, state); |
| 303 | return -EINVAL; |
| 304 | } |
| 305 | |
| 306 | c_conn = to_sde_connector(connector); |
| 307 | c_state = to_sde_connector_state(state); |
| 308 | |
| 309 | idx = msm_property_index(&c_conn->property_info, property); |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 310 | if (idx == CONNECTOR_PROP_RETIRE_FENCE) |
| 311 | rc = sde_fence_create(&c_conn->retire_fence, val); |
| 312 | else |
| 313 | /* get cached property value */ |
| 314 | rc = msm_property_atomic_get(&c_conn->property_info, |
| 315 | c_state->property_values, 0, property, val); |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 316 | |
| 317 | /* allow for custom override */ |
| 318 | if (c_conn->ops.get_property) |
| 319 | rc = c_conn->ops.get_property(connector, |
| 320 | (struct drm_connector_state *)state, |
| 321 | idx, |
| 322 | val, |
| 323 | c_conn->display); |
| 324 | return rc; |
| 325 | } |
| 326 | |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 327 | void sde_connector_prepare_fence(struct drm_connector *connector) |
| 328 | { |
| 329 | if (!connector) { |
| 330 | SDE_ERROR("invalid connector\n"); |
| 331 | return; |
| 332 | } |
| 333 | |
| 334 | sde_fence_prepare(&to_sde_connector(connector)->retire_fence); |
| 335 | } |
| 336 | |
| 337 | void sde_connector_complete_commit(struct drm_connector *connector) |
| 338 | { |
| 339 | if (!connector) { |
| 340 | SDE_ERROR("invalid connector\n"); |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | /* signal connector's retire fence */ |
| 345 | sde_fence_signal(&to_sde_connector(connector)->retire_fence, 0); |
| 346 | } |
| 347 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 348 | static enum drm_connector_status |
| 349 | sde_connector_detect(struct drm_connector *connector, bool force) |
| 350 | { |
| 351 | enum drm_connector_status status = connector_status_unknown; |
| 352 | struct sde_connector *c_conn; |
| 353 | |
| 354 | if (!connector) { |
| 355 | SDE_ERROR("invalid connector\n"); |
| 356 | return status; |
| 357 | } |
| 358 | |
| 359 | c_conn = to_sde_connector(connector); |
| 360 | |
| 361 | if (c_conn->ops.detect) |
| 362 | status = c_conn->ops.detect(connector, |
| 363 | force, |
| 364 | c_conn->display); |
| 365 | |
| 366 | return status; |
| 367 | } |
| 368 | |
| 369 | static const struct drm_connector_funcs sde_connector_ops = { |
| 370 | .dpms = drm_atomic_helper_connector_dpms, |
| 371 | .reset = sde_connector_atomic_reset, |
| 372 | .detect = sde_connector_detect, |
| 373 | .destroy = sde_connector_destroy, |
| 374 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 375 | .atomic_duplicate_state = sde_connector_atomic_duplicate_state, |
| 376 | .atomic_destroy_state = sde_connector_atomic_destroy_state, |
| 377 | .atomic_set_property = sde_connector_atomic_set_property, |
| 378 | .atomic_get_property = sde_connector_atomic_get_property, |
| 379 | .set_property = sde_connector_set_property, |
| 380 | }; |
| 381 | |
| 382 | static int sde_connector_get_modes(struct drm_connector *connector) |
| 383 | { |
| 384 | struct sde_connector *c_conn; |
| 385 | |
| 386 | if (!connector) { |
| 387 | SDE_ERROR("invalid connector\n"); |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | c_conn = to_sde_connector(connector); |
| 392 | if (!c_conn->ops.get_modes) { |
| 393 | SDE_DEBUG("missing get_modes callback\n"); |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | return c_conn->ops.get_modes(connector, c_conn->display); |
| 398 | } |
| 399 | |
| 400 | static enum drm_mode_status |
| 401 | sde_connector_mode_valid(struct drm_connector *connector, |
| 402 | struct drm_display_mode *mode) |
| 403 | { |
| 404 | struct sde_connector *c_conn; |
| 405 | |
| 406 | if (!connector || !mode) { |
| 407 | SDE_ERROR("invalid argument(s), conn %pK, mode %pK\n", |
| 408 | connector, mode); |
| 409 | return MODE_ERROR; |
| 410 | } |
| 411 | |
| 412 | c_conn = to_sde_connector(connector); |
| 413 | |
| 414 | if (c_conn->ops.mode_valid) |
| 415 | return c_conn->ops.mode_valid(connector, mode, c_conn->display); |
| 416 | |
| 417 | /* assume all modes okay by default */ |
| 418 | return MODE_OK; |
| 419 | } |
| 420 | |
| 421 | static struct drm_encoder * |
| 422 | sde_connector_best_encoder(struct drm_connector *connector) |
| 423 | { |
| 424 | struct sde_connector *c_conn = to_sde_connector(connector); |
| 425 | |
| 426 | if (!connector) { |
| 427 | SDE_ERROR("invalid connector\n"); |
| 428 | return NULL; |
| 429 | } |
| 430 | |
| 431 | /* |
| 432 | * This is true for now, revisit this code when multiple encoders are |
| 433 | * supported. |
| 434 | */ |
| 435 | return c_conn->encoder; |
| 436 | } |
| 437 | |
| 438 | static const struct drm_connector_helper_funcs sde_connector_helper_ops = { |
| 439 | .get_modes = sde_connector_get_modes, |
| 440 | .mode_valid = sde_connector_mode_valid, |
| 441 | .best_encoder = sde_connector_best_encoder, |
| 442 | }; |
| 443 | |
| 444 | struct drm_connector *sde_connector_init(struct drm_device *dev, |
| 445 | struct drm_encoder *encoder, |
| 446 | struct drm_panel *panel, |
| 447 | void *display, |
| 448 | const struct sde_connector_ops *ops, |
| 449 | int connector_poll, |
| 450 | int connector_type) |
| 451 | { |
| 452 | struct msm_drm_private *priv; |
| 453 | struct sde_kms *sde_kms; |
| 454 | struct sde_kms_info *info; |
| 455 | struct sde_connector *c_conn = NULL; |
| 456 | int rc; |
| 457 | |
| 458 | if (!dev || !dev->dev_private || !encoder) { |
| 459 | SDE_ERROR("invalid argument(s), dev %pK, enc %pK\n", |
| 460 | dev, encoder); |
| 461 | return ERR_PTR(-EINVAL); |
| 462 | } |
| 463 | |
| 464 | priv = dev->dev_private; |
| 465 | if (!priv->kms) { |
| 466 | SDE_ERROR("invalid kms reference\n"); |
| 467 | return ERR_PTR(-EINVAL); |
| 468 | } |
| 469 | |
| 470 | c_conn = kzalloc(sizeof(*c_conn), GFP_KERNEL); |
| 471 | if (!c_conn) { |
| 472 | SDE_ERROR("failed to alloc sde connector\n"); |
| 473 | return ERR_PTR(-ENOMEM); |
| 474 | } |
| 475 | |
| 476 | rc = drm_connector_init(dev, |
| 477 | &c_conn->base, |
| 478 | &sde_connector_ops, |
| 479 | connector_type); |
| 480 | if (rc) |
| 481 | goto error_free_conn; |
| 482 | |
| 483 | c_conn->connector_type = connector_type; |
| 484 | c_conn->encoder = encoder; |
| 485 | c_conn->panel = panel; |
| 486 | c_conn->display = display; |
| 487 | |
Alan Kwong | dfa8c08 | 2016-07-29 04:10:00 -0400 | [diff] [blame] | 488 | /* cache mmu_id's for later */ |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 489 | sde_kms = to_sde_kms(priv->kms); |
Alan Kwong | dfa8c08 | 2016-07-29 04:10:00 -0400 | [diff] [blame] | 490 | if (sde_kms->vbif[VBIF_NRT]) { |
| 491 | c_conn->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] = |
| 492 | sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_UNSECURE]; |
| 493 | c_conn->mmu_id[SDE_IOMMU_DOMAIN_SECURE] = |
| 494 | sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_SECURE]; |
| 495 | } else { |
| 496 | c_conn->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] = |
| 497 | sde_kms->mmu_id[MSM_SMMU_DOMAIN_UNSECURE]; |
| 498 | c_conn->mmu_id[SDE_IOMMU_DOMAIN_SECURE] = |
| 499 | sde_kms->mmu_id[MSM_SMMU_DOMAIN_SECURE]; |
| 500 | } |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 501 | |
| 502 | if (ops) |
| 503 | c_conn->ops = *ops; |
| 504 | |
| 505 | c_conn->base.helper_private = &sde_connector_helper_ops; |
| 506 | c_conn->base.polled = connector_poll; |
| 507 | c_conn->base.interlace_allowed = 0; |
| 508 | c_conn->base.doublescan_allowed = 0; |
| 509 | |
| 510 | snprintf(c_conn->name, |
| 511 | SDE_CONNECTOR_NAME_SIZE, |
| 512 | "conn%u", |
| 513 | c_conn->base.base.id); |
| 514 | |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 515 | /* |
| 516 | * Initialize retire fence support. Set fence offset to 0 for virtual |
| 517 | * connectors so that the fence signals at the end of the current commit |
| 518 | * and 1 for others so that the fence signals after one additional |
| 519 | * commit. |
| 520 | */ |
| 521 | rc = sde_fence_init(dev, &c_conn->retire_fence, c_conn->name, |
| 522 | connector_type == DRM_MODE_CONNECTOR_VIRTUAL ? 0 : 1); |
| 523 | if (rc) { |
| 524 | SDE_ERROR("failed to init fence, %d\n", rc); |
| 525 | goto error_cleanup_conn; |
| 526 | } |
| 527 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 528 | rc = drm_connector_register(&c_conn->base); |
| 529 | if (rc) { |
| 530 | SDE_ERROR("failed to register drm connector, %d\n", rc); |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 531 | goto error_cleanup_fence; |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | rc = drm_mode_connector_attach_encoder(&c_conn->base, encoder); |
| 535 | if (rc) { |
| 536 | SDE_ERROR("failed to attach encoder to connector, %d\n", rc); |
| 537 | goto error_unregister_conn; |
| 538 | } |
| 539 | |
| 540 | /* create properties */ |
| 541 | msm_property_init(&c_conn->property_info, &c_conn->base.base, dev, |
| 542 | priv->conn_property, c_conn->property_data, |
| 543 | CONNECTOR_PROP_COUNT, CONNECTOR_PROP_BLOBCOUNT, |
| 544 | sizeof(struct sde_connector_state)); |
| 545 | |
| 546 | if (c_conn->ops.post_init) { |
| 547 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
| 548 | if (!info) { |
| 549 | SDE_ERROR("failed to allocate info buffer\n"); |
| 550 | rc = -ENOMEM; |
| 551 | goto error_unregister_conn; |
| 552 | } |
| 553 | |
| 554 | sde_kms_info_reset(info); |
| 555 | rc = c_conn->ops.post_init(&c_conn->base, info, display); |
| 556 | if (rc) { |
| 557 | SDE_ERROR("post-init failed, %d\n", rc); |
| 558 | kfree(info); |
| 559 | goto error_unregister_conn; |
| 560 | } |
| 561 | |
| 562 | msm_property_install_blob(&c_conn->property_info, |
| 563 | "sde_info", |
| 564 | DRM_MODE_PROP_IMMUTABLE, |
| 565 | CONNECTOR_PROP_SDE_INFO); |
| 566 | |
| 567 | msm_property_set_blob(&c_conn->property_info, |
| 568 | &c_conn->blob_sde_info, |
| 569 | SDE_KMS_INFO_DATA(info), |
| 570 | SDE_KMS_INFO_DATALEN(info), |
| 571 | CONNECTOR_PROP_SDE_INFO); |
| 572 | kfree(info); |
| 573 | } |
| 574 | |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 575 | msm_property_install_range(&c_conn->property_info, "RETIRE_FENCE", |
Lloyd Atkinson | 38ad8c9 | 2016-07-06 10:39:32 -0400 | [diff] [blame] | 576 | 0x0, 0, ~0, ~0, CONNECTOR_PROP_RETIRE_FENCE); |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 577 | |
Lloyd Atkinson | b619197 | 2016-08-10 18:31:46 -0400 | [diff] [blame] | 578 | /* enum/bitmask properties */ |
| 579 | msm_property_install_enum(&c_conn->property_info, "topology_name", |
| 580 | DRM_MODE_PROP_IMMUTABLE, 0, e_topology_name, |
| 581 | ARRAY_SIZE(e_topology_name), |
| 582 | CONNECTOR_PROP_TOPOLOGY_NAME); |
| 583 | msm_property_install_enum(&c_conn->property_info, "topology_control", |
| 584 | 0, 1, e_topology_control, |
| 585 | ARRAY_SIZE(e_topology_control), |
| 586 | CONNECTOR_PROP_TOPOLOGY_CONTROL); |
| 587 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 588 | rc = msm_property_install_get_status(&c_conn->property_info); |
| 589 | if (rc) { |
| 590 | SDE_ERROR("failed to create one or more properties\n"); |
| 591 | goto error_destroy_property; |
| 592 | } |
| 593 | |
Lloyd Atkinson | b619197 | 2016-08-10 18:31:46 -0400 | [diff] [blame] | 594 | SDE_DEBUG("connector %d attach encoder %d\n", |
| 595 | c_conn->base.base.id, encoder->base.id); |
| 596 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 597 | priv->connectors[priv->num_connectors++] = &c_conn->base; |
| 598 | |
| 599 | return &c_conn->base; |
| 600 | |
| 601 | error_destroy_property: |
| 602 | if (c_conn->blob_sde_info) |
| 603 | drm_property_unreference_blob(c_conn->blob_sde_info); |
| 604 | msm_property_destroy(&c_conn->property_info); |
| 605 | error_unregister_conn: |
| 606 | drm_connector_unregister(&c_conn->base); |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 607 | error_cleanup_fence: |
| 608 | sde_fence_deinit(&c_conn->retire_fence); |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 609 | error_cleanup_conn: |
| 610 | drm_connector_cleanup(&c_conn->base); |
| 611 | error_free_conn: |
| 612 | kfree(c_conn); |
| 613 | |
| 614 | return ERR_PTR(rc); |
| 615 | } |