1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * (C) COPYRIGHT 2012-2013 ARM Limited. All rights reserved. 4 * 5 * Parts of this file were based on sources as follows: 6 * 7 * Copyright (c) 2006-2008 Intel Corporation 8 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie> 9 * Copyright (C) 2011 Texas Instruments 10 */ 11 12 #include <linux/clk.h> 13 #include <linux/delay.h> 14 #include <linux/dma-buf.h> 15 #include <linux/media-bus-format.h> 16 #include <linux/of_graph.h> 17 18 #include <drm/drm_atomic_helper.h> 19 #include <drm/drm_fb_dma_helper.h> 20 #include <drm/drm_fourcc.h> 21 #include <drm/drm_framebuffer.h> 22 #include <drm/drm_gem_atomic_helper.h> 23 #include <drm/drm_gem_dma_helper.h> 24 #include <drm/drm_print.h> 25 #include <drm/drm_vblank.h> 26 27 #include "pl111_drm.h" 28 29 irqreturn_t pl111_irq(int irq, void *data) 30 { 31 struct pl111_drm_dev_private *priv = data; 32 u32 irq_stat; 33 irqreturn_t status = IRQ_NONE; 34 35 irq_stat = readl(priv->regs + CLCD_PL111_MIS); 36 37 if (!irq_stat) 38 return IRQ_NONE; 39 40 if (irq_stat & CLCD_IRQ_NEXTBASE_UPDATE) { 41 drm_crtc_handle_vblank(&priv->crtc); 42 43 status = IRQ_HANDLED; 44 } 45 46 /* Clear the interrupt once done */ 47 writel(irq_stat, priv->regs + CLCD_PL111_ICR); 48 49 return status; 50 } 51 52 static enum drm_mode_status 53 pl111_crtc_helper_mode_valid(struct drm_crtc *crtc, 54 const struct drm_display_mode *mode) 55 { 56 struct drm_device *drm = crtc->dev; 57 struct pl111_drm_dev_private *priv = drm->dev_private; 58 u32 cpp = DIV_ROUND_UP(priv->variant->fb_depth, 8); 59 u64 bw; 60 61 /* 62 * We use the pixelclock to also account for interlaced modes, the 63 * resulting bandwidth is in bytes per second. 64 */ 65 bw = mode->clock * 1000ULL; /* In Hz */ 66 bw = bw * mode->hdisplay * mode->vdisplay * cpp; 67 bw = div_u64(bw, mode->htotal * mode->vtotal); 68 69 /* 70 * If no bandwidth constraints, anything goes, else 71 * check if we are too fast. 72 */ 73 if (priv->memory_bw && (bw > priv->memory_bw)) { 74 DRM_DEBUG_KMS("%d x %d @ %d Hz, %d cpp, bw %llu too fast\n", 75 mode->hdisplay, mode->vdisplay, 76 mode->clock * 1000, cpp, bw); 77 78 return MODE_BAD; 79 } 80 DRM_DEBUG_KMS("%d x %d @ %d Hz, %d cpp, bw %llu bytes/s OK\n", 81 mode->hdisplay, mode->vdisplay, 82 mode->clock * 1000, cpp, bw); 83 84 return MODE_OK; 85 } 86 87 static int pl111_plane_helper_atomic_check(struct drm_plane *plane, 88 struct drm_atomic_commit *commit) 89 { 90 struct drm_plane_state *pstate = drm_atomic_get_new_plane_state(commit, plane); 91 struct drm_plane_state *old_pstate = drm_atomic_get_old_plane_state(commit, plane); 92 struct drm_crtc_state *cstate = NULL; 93 const struct drm_display_mode *mode; 94 struct drm_framebuffer *old_fb = old_pstate->fb; 95 struct drm_framebuffer *fb = pstate->fb; 96 int ret; 97 98 if (pstate->crtc) { 99 cstate = drm_atomic_get_crtc_state(commit, pstate->crtc); 100 if (IS_ERR(cstate)) 101 return PTR_ERR(cstate); 102 } 103 104 ret = drm_atomic_helper_check_plane_state(pstate, cstate, 105 DRM_PLANE_NO_SCALING, 106 DRM_PLANE_NO_SCALING, 107 false, false); 108 if (ret) 109 return ret; 110 111 if (!pstate->visible) 112 return 0; 113 114 mode = &cstate->mode; 115 116 if (mode->hdisplay % 16) 117 return -EINVAL; 118 119 if (fb) { 120 u32 offset = drm_fb_dma_get_gem_addr(fb, pstate, 0); 121 122 /* FB base address must be dword aligned. */ 123 if (offset & 3) 124 return -EINVAL; 125 126 /* There's no pitch register -- the mode's hdisplay 127 * controls it. 128 */ 129 if (fb->pitches[0] != mode->hdisplay * fb->format->cpp[0]) 130 return -EINVAL; 131 132 /* We can't change the FB format in a flicker-free 133 * manner (and only update it during CRTC enable). 134 */ 135 if (old_fb && old_fb->format != fb->format) 136 cstate->mode_changed = true; 137 } 138 139 return 0; 140 } 141 142 static void pl111_crtc_helper_atomic_enable(struct drm_crtc *crtc, 143 struct drm_atomic_commit *commit) 144 { 145 struct drm_device *drm = crtc->dev; 146 struct pl111_drm_dev_private *priv = drm->dev_private; 147 struct drm_crtc_state *cstate = drm_atomic_get_new_crtc_state(commit, crtc); 148 struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(commit, &priv->plane); 149 const struct drm_display_mode *mode = &cstate->mode; 150 struct drm_framebuffer *fb = plane_state->fb; 151 struct drm_connector *connector = priv->connector; 152 struct drm_bridge *bridge = priv->bridge; 153 bool grayscale = false; 154 u32 cntl; 155 u32 ppl, hsw, hfp, hbp; 156 u32 lpp, vsw, vfp, vbp; 157 u32 cpl, tim2; 158 int ret; 159 160 ret = clk_set_rate(priv->clk, mode->clock * 1000); 161 if (ret) { 162 drm_err(drm, 163 "Failed to set pixel clock rate to %d: %d\n", 164 mode->clock * 1000, ret); 165 } 166 167 clk_prepare_enable(priv->clk); 168 169 ppl = (mode->hdisplay / 16) - 1; 170 hsw = mode->hsync_end - mode->hsync_start - 1; 171 hfp = mode->hsync_start - mode->hdisplay - 1; 172 hbp = mode->htotal - mode->hsync_end - 1; 173 174 lpp = mode->vdisplay - 1; 175 vsw = mode->vsync_end - mode->vsync_start - 1; 176 vfp = mode->vsync_start - mode->vdisplay; 177 vbp = mode->vtotal - mode->vsync_end; 178 179 cpl = mode->hdisplay - 1; 180 181 writel((ppl << 2) | 182 (hsw << 8) | 183 (hfp << 16) | 184 (hbp << 24), 185 priv->regs + CLCD_TIM0); 186 writel(lpp | 187 (vsw << 10) | 188 (vfp << 16) | 189 (vbp << 24), 190 priv->regs + CLCD_TIM1); 191 192 spin_lock(&priv->tim2_lock); 193 194 tim2 = readl(priv->regs + CLCD_TIM2); 195 tim2 &= (TIM2_BCD | TIM2_PCD_LO_MASK | TIM2_PCD_HI_MASK); 196 197 if (priv->variant->broken_clockdivider) 198 tim2 |= TIM2_BCD; 199 200 if (mode->flags & DRM_MODE_FLAG_NHSYNC) 201 tim2 |= TIM2_IHS; 202 203 if (mode->flags & DRM_MODE_FLAG_NVSYNC) 204 tim2 |= TIM2_IVS; 205 206 if (connector) { 207 if (connector->display_info.bus_flags & DRM_BUS_FLAG_DE_LOW) 208 tim2 |= TIM2_IOE; 209 210 if (connector->display_info.bus_flags & 211 DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE) 212 tim2 |= TIM2_IPC; 213 214 if (connector->display_info.num_bus_formats == 1 && 215 connector->display_info.bus_formats[0] == 216 MEDIA_BUS_FMT_Y8_1X8) 217 grayscale = true; 218 219 /* 220 * The AC pin bias frequency is set to max count when using 221 * grayscale so at least once in a while we will reverse 222 * polarity and get rid of any DC built up that could 223 * damage the display. 224 */ 225 if (grayscale) 226 tim2 |= TIM2_ACB_MASK; 227 } 228 229 if (bridge) { 230 const struct drm_bridge_timings *btimings = bridge->timings; 231 232 /* 233 * Here is when things get really fun. Sometimes the bridge 234 * timings are such that the signal out from PL11x is not 235 * stable before the receiving bridge (such as a dumb VGA DAC 236 * or similar) samples it. If that happens, we compensate by 237 * the only method we have: output the data on the opposite 238 * edge of the clock so it is for sure stable when it gets 239 * sampled. 240 * 241 * The PL111 manual does not contain proper timining diagrams 242 * or data for these details, but we know from experiments 243 * that the setup time is more than 3000 picoseconds (3 ns). 244 * If we have a bridge that requires the signal to be stable 245 * earlier than 3000 ps before the clock pulse, we have to 246 * output the data on the opposite edge to avoid flicker. 247 */ 248 if (btimings && btimings->setup_time_ps >= 3000) 249 tim2 ^= TIM2_IPC; 250 } 251 252 tim2 |= cpl << 16; 253 writel(tim2, priv->regs + CLCD_TIM2); 254 spin_unlock(&priv->tim2_lock); 255 256 writel(0, priv->regs + CLCD_TIM3); 257 258 /* 259 * Detect grayscale bus format. We do not support a grayscale mode 260 * toward userspace, instead we expose an RGB24 buffer and then the 261 * hardware will activate its grayscaler to convert to the grayscale 262 * format. 263 */ 264 if (grayscale) 265 cntl = CNTL_LCDEN | CNTL_LCDMONO8; 266 else 267 /* Else we assume TFT display */ 268 cntl = CNTL_LCDEN | CNTL_LCDTFT | CNTL_LCDVCOMP(1); 269 270 /* On the ST Micro variant, assume all 24 bits are connected */ 271 if (priv->variant->st_bitmux_control) 272 cntl |= CNTL_ST_CDWID_24; 273 274 /* 275 * Note that the ARM hardware's format reader takes 'r' from 276 * the low bit, while DRM formats list channels from high bit 277 * to low bit as you read left to right. The ST Micro version of 278 * the PL110 (LCDC) however uses the standard DRM format. 279 */ 280 switch (fb->format->format) { 281 case DRM_FORMAT_BGR888: 282 /* Only supported on the ST Micro variant */ 283 if (priv->variant->st_bitmux_control) 284 cntl |= CNTL_ST_LCDBPP24_PACKED | CNTL_BGR; 285 break; 286 case DRM_FORMAT_RGB888: 287 /* Only supported on the ST Micro variant */ 288 if (priv->variant->st_bitmux_control) 289 cntl |= CNTL_ST_LCDBPP24_PACKED; 290 break; 291 case DRM_FORMAT_XBGR8888: 292 if (priv->variant->st_bitmux_control) 293 cntl |= CNTL_LCDBPP24 | CNTL_BGR; 294 else 295 cntl |= CNTL_LCDBPP24; 296 break; 297 case DRM_FORMAT_XRGB8888: 298 if (priv->variant->st_bitmux_control) 299 cntl |= CNTL_LCDBPP24; 300 else 301 cntl |= CNTL_LCDBPP24 | CNTL_BGR; 302 break; 303 case DRM_FORMAT_BGR565: 304 if (priv->variant->is_pl110) 305 cntl |= CNTL_LCDBPP16; 306 else if (priv->variant->st_bitmux_control) 307 cntl |= CNTL_LCDBPP16 | CNTL_ST_1XBPP_565 | CNTL_BGR; 308 else 309 cntl |= CNTL_LCDBPP16_565; 310 break; 311 case DRM_FORMAT_RGB565: 312 if (priv->variant->is_pl110) 313 cntl |= CNTL_LCDBPP16 | CNTL_BGR; 314 else if (priv->variant->st_bitmux_control) 315 cntl |= CNTL_LCDBPP16 | CNTL_ST_1XBPP_565; 316 else 317 cntl |= CNTL_LCDBPP16_565 | CNTL_BGR; 318 break; 319 case DRM_FORMAT_XBGR1555: 320 cntl |= CNTL_LCDBPP16; 321 if (priv->variant->st_bitmux_control) 322 cntl |= CNTL_ST_1XBPP_5551 | CNTL_BGR; 323 break; 324 case DRM_FORMAT_XRGB1555: 325 cntl |= CNTL_LCDBPP16; 326 if (priv->variant->st_bitmux_control) 327 cntl |= CNTL_ST_1XBPP_5551; 328 else 329 cntl |= CNTL_BGR; 330 break; 331 case DRM_FORMAT_XBGR4444: 332 cntl |= CNTL_LCDBPP16_444; 333 if (priv->variant->st_bitmux_control) 334 cntl |= CNTL_ST_1XBPP_444 | CNTL_BGR; 335 break; 336 case DRM_FORMAT_XRGB4444: 337 cntl |= CNTL_LCDBPP16_444; 338 if (priv->variant->st_bitmux_control) 339 cntl |= CNTL_ST_1XBPP_444; 340 else 341 cntl |= CNTL_BGR; 342 break; 343 default: 344 WARN_ONCE(true, "Unknown FB format 0x%08x\n", 345 fb->format->format); 346 break; 347 } 348 349 /* The PL110 in Integrator/Versatile does the BGR routing externally */ 350 if (priv->variant->external_bgr) 351 cntl &= ~CNTL_BGR; 352 353 /* Power sequence: first enable and chill */ 354 writel(cntl, priv->regs + priv->ctrl); 355 356 /* 357 * We expect this delay to stabilize the contrast 358 * voltage Vee as stipulated by the manual 359 */ 360 msleep(20); 361 362 if (priv->variant_display_enable) 363 priv->variant_display_enable(drm, fb->format->format); 364 365 /* Power Up */ 366 cntl |= CNTL_LCDPWR; 367 writel(cntl, priv->regs + priv->ctrl); 368 369 if (!priv->variant->broken_vblank) 370 drm_crtc_vblank_on(crtc); 371 } 372 373 static void pl111_crtc_helper_atomic_disable(struct drm_crtc *crtc, 374 struct drm_atomic_commit *commit) 375 { 376 struct drm_device *drm = crtc->dev; 377 struct pl111_drm_dev_private *priv = drm->dev_private; 378 u32 cntl; 379 380 if (!priv->variant->broken_vblank) 381 drm_crtc_vblank_off(crtc); 382 383 /* Power Down */ 384 cntl = readl(priv->regs + priv->ctrl); 385 if (cntl & CNTL_LCDPWR) { 386 cntl &= ~CNTL_LCDPWR; 387 writel(cntl, priv->regs + priv->ctrl); 388 } 389 390 /* 391 * We expect this delay to stabilize the contrast voltage Vee as 392 * stipulated by the manual 393 */ 394 msleep(20); 395 396 if (priv->variant_display_disable) 397 priv->variant_display_disable(drm); 398 399 /* Disable */ 400 writel(0, priv->regs + priv->ctrl); 401 402 clk_disable_unprepare(priv->clk); 403 } 404 405 static void pl111_plane_helper_atomic_update(struct drm_plane *plane, 406 struct drm_atomic_commit *commit) 407 { 408 struct drm_device *drm = plane->dev; 409 struct pl111_drm_dev_private *priv = drm->dev_private; 410 struct drm_plane_state *pstate = drm_atomic_get_new_plane_state(commit, plane); 411 struct drm_framebuffer *fb = pstate->fb; 412 413 if (!fb) 414 return; 415 416 u32 addr = drm_fb_dma_get_gem_addr(fb, pstate, 0); 417 418 writel(addr, priv->regs + CLCD_UBAS); 419 } 420 421 static void pl111_crtc_helper_atomic_flush(struct drm_crtc *crtc, 422 struct drm_atomic_commit *commit) 423 { 424 struct drm_crtc_state *cstate = drm_atomic_get_new_crtc_state(commit, crtc); 425 struct drm_pending_vblank_event *event = cstate->event; 426 427 if (!event) 428 return; 429 430 cstate->event = NULL; 431 432 spin_lock_irq(&crtc->dev->event_lock); 433 if (cstate->active && drm_crtc_vblank_get(crtc) == 0) 434 drm_crtc_arm_vblank_event(crtc, event); 435 else 436 drm_crtc_send_vblank_event(crtc, event); 437 spin_unlock_irq(&crtc->dev->event_lock); 438 } 439 440 static int pl111_display_enable_vblank(struct drm_crtc *crtc) 441 { 442 struct drm_device *drm = crtc->dev; 443 struct pl111_drm_dev_private *priv = drm->dev_private; 444 445 writel(CLCD_IRQ_NEXTBASE_UPDATE, priv->regs + priv->ienb); 446 447 return 0; 448 } 449 450 static void pl111_display_disable_vblank(struct drm_crtc *crtc) 451 { 452 struct drm_device *drm = crtc->dev; 453 struct pl111_drm_dev_private *priv = drm->dev_private; 454 455 writel(0, priv->regs + priv->ienb); 456 } 457 458 static int pl111_crtc_helper_atomic_check(struct drm_crtc *crtc, struct drm_atomic_commit *commit) 459 { 460 struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(commit, crtc); 461 int ret; 462 463 if (crtc_state->enable) { 464 ret = drm_atomic_helper_check_crtc_primary_plane(crtc_state); 465 if (ret) 466 return ret; 467 } 468 469 return drm_atomic_add_affected_planes(commit, crtc); 470 } 471 472 static struct drm_crtc_funcs pl111_crtc_funcs = { 473 .atomic_create_state = drm_atomic_helper_crtc_create_state, 474 .destroy = drm_crtc_cleanup, 475 .set_config = drm_atomic_helper_set_config, 476 .page_flip = drm_atomic_helper_page_flip, 477 .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, 478 .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, 479 }; 480 481 static const struct drm_crtc_helper_funcs pl111_crtc_helper_funcs = { 482 .mode_valid = pl111_crtc_helper_mode_valid, 483 .atomic_check = pl111_crtc_helper_atomic_check, 484 .atomic_enable = pl111_crtc_helper_atomic_enable, 485 .atomic_disable = pl111_crtc_helper_atomic_disable, 486 .atomic_flush = pl111_crtc_helper_atomic_flush, 487 }; 488 489 static const struct drm_plane_funcs pl111_plane_funcs = { 490 .update_plane = drm_atomic_helper_update_plane, 491 .disable_plane = drm_atomic_helper_disable_plane, 492 .atomic_create_state = drm_atomic_helper_plane_create_state, 493 .destroy = drm_plane_cleanup, 494 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, 495 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, 496 }; 497 498 static const struct drm_plane_helper_funcs pl111_plane_helper_funcs = { 499 .prepare_fb = drm_gem_plane_helper_prepare_fb, 500 .atomic_check = pl111_plane_helper_atomic_check, 501 .atomic_update = pl111_plane_helper_atomic_update, 502 }; 503 504 static const struct drm_encoder_funcs pl111_encoder_funcs = { 505 .destroy = drm_encoder_cleanup, 506 }; 507 508 static int pl111_clk_div_choose_div(struct clk_hw *hw, unsigned long rate, 509 unsigned long *prate, bool set_parent) 510 { 511 int best_div = 1, div; 512 struct clk_hw *parent = clk_hw_get_parent(hw); 513 unsigned long best_prate = 0; 514 unsigned long best_diff = ~0ul; 515 int max_div = (1 << (TIM2_PCD_LO_BITS + TIM2_PCD_HI_BITS)) - 1; 516 517 for (div = 1; div < max_div; div++) { 518 unsigned long this_prate, div_rate, diff; 519 520 if (set_parent) 521 this_prate = clk_hw_round_rate(parent, rate * div); 522 else 523 this_prate = *prate; 524 div_rate = DIV_ROUND_UP_ULL(this_prate, div); 525 diff = abs(rate - div_rate); 526 527 if (diff < best_diff) { 528 best_div = div; 529 best_diff = diff; 530 best_prate = this_prate; 531 } 532 } 533 534 *prate = best_prate; 535 return best_div; 536 } 537 538 static int pl111_clk_div_determine_rate(struct clk_hw *hw, 539 struct clk_rate_request *req) 540 { 541 int div = pl111_clk_div_choose_div(hw, req->rate, 542 &req->best_parent_rate, true); 543 544 req->rate = DIV_ROUND_UP_ULL(req->best_parent_rate, div); 545 546 return 0; 547 } 548 549 static unsigned long pl111_clk_div_recalc_rate(struct clk_hw *hw, 550 unsigned long prate) 551 { 552 struct pl111_drm_dev_private *priv = 553 container_of(hw, struct pl111_drm_dev_private, clk_div); 554 u32 tim2 = readl(priv->regs + CLCD_TIM2); 555 int div; 556 557 if (tim2 & TIM2_BCD) 558 return prate; 559 560 div = tim2 & TIM2_PCD_LO_MASK; 561 div |= (tim2 & TIM2_PCD_HI_MASK) >> 562 (TIM2_PCD_HI_SHIFT - TIM2_PCD_LO_BITS); 563 div += 2; 564 565 return DIV_ROUND_UP_ULL(prate, div); 566 } 567 568 static int pl111_clk_div_set_rate(struct clk_hw *hw, unsigned long rate, 569 unsigned long prate) 570 { 571 struct pl111_drm_dev_private *priv = 572 container_of(hw, struct pl111_drm_dev_private, clk_div); 573 int div = pl111_clk_div_choose_div(hw, rate, &prate, false); 574 u32 tim2; 575 576 spin_lock(&priv->tim2_lock); 577 tim2 = readl(priv->regs + CLCD_TIM2); 578 tim2 &= ~(TIM2_BCD | TIM2_PCD_LO_MASK | TIM2_PCD_HI_MASK); 579 580 if (div == 1) { 581 tim2 |= TIM2_BCD; 582 } else { 583 div -= 2; 584 tim2 |= div & TIM2_PCD_LO_MASK; 585 tim2 |= (div >> TIM2_PCD_LO_BITS) << TIM2_PCD_HI_SHIFT; 586 } 587 588 writel(tim2, priv->regs + CLCD_TIM2); 589 spin_unlock(&priv->tim2_lock); 590 591 return 0; 592 } 593 594 static const struct clk_ops pl111_clk_div_ops = { 595 .recalc_rate = pl111_clk_div_recalc_rate, 596 .determine_rate = pl111_clk_div_determine_rate, 597 .set_rate = pl111_clk_div_set_rate, 598 }; 599 600 static int 601 pl111_init_clock_divider(struct drm_device *drm) 602 { 603 struct pl111_drm_dev_private *priv = drm->dev_private; 604 struct clk *parent = devm_clk_get(drm->dev, "clcdclk"); 605 struct clk_hw *div = &priv->clk_div; 606 const char *parent_name; 607 struct clk_init_data init = { 608 .name = "pl111_div", 609 .ops = &pl111_clk_div_ops, 610 .parent_names = &parent_name, 611 .num_parents = 1, 612 .flags = CLK_SET_RATE_PARENT, 613 }; 614 int ret; 615 616 if (IS_ERR(parent)) { 617 drm_err(drm, "CLCD: unable to get clcdclk.\n"); 618 return PTR_ERR(parent); 619 } 620 621 spin_lock_init(&priv->tim2_lock); 622 623 /* If the clock divider is broken, use the parent directly */ 624 if (priv->variant->broken_clockdivider) { 625 priv->clk = parent; 626 return 0; 627 } 628 parent_name = __clk_get_name(parent); 629 div->init = &init; 630 631 ret = devm_clk_hw_register(drm->dev, div); 632 633 priv->clk = div->clk; 634 return ret; 635 } 636 637 int pl111_display_init(struct drm_device *drm) 638 { 639 struct pl111_drm_dev_private *priv = drm->dev_private; 640 int ret; 641 642 ret = pl111_init_clock_divider(drm); 643 if (ret) 644 return ret; 645 646 if (!priv->variant->broken_vblank) { 647 pl111_crtc_funcs.enable_vblank = pl111_display_enable_vblank; 648 pl111_crtc_funcs.disable_vblank = pl111_display_disable_vblank; 649 } 650 651 ret = drm_universal_plane_init(drm, &priv->plane, 0, 652 &pl111_plane_funcs, 653 priv->variant->formats, 654 priv->variant->nformats, 655 NULL, DRM_PLANE_TYPE_PRIMARY, NULL); 656 if (ret) 657 return ret; 658 659 drm_plane_helper_add(&priv->plane, &pl111_plane_helper_funcs); 660 661 ret = drm_crtc_init_with_planes(drm, &priv->crtc, &priv->plane, 662 NULL, &pl111_crtc_funcs, NULL); 663 if (ret) 664 return ret; 665 666 drm_crtc_helper_add(&priv->crtc, &pl111_crtc_helper_funcs); 667 668 ret = drm_encoder_init(drm, &priv->encoder, &pl111_encoder_funcs, 669 DRM_MODE_ENCODER_NONE, NULL); 670 if (ret) 671 return ret; 672 673 priv->encoder.possible_crtcs = drm_crtc_mask(&priv->crtc); 674 675 if (priv->connector) { 676 ret = drm_connector_attach_encoder(priv->connector, 677 &priv->encoder); 678 if (ret) 679 return ret; 680 } 681 682 return 0; 683 } 684