1 /* 2 * Copyright (C) 2012 Russell King 3 * Rewritten from the dovefb driver, and Armada510 manuals. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License version 2 as 7 * published by the Free Software Foundation. 8 */ 9 #include <linux/clk.h> 10 #include <linux/component.h> 11 #include <linux/of_device.h> 12 #include <linux/platform_device.h> 13 #include <drm/drmP.h> 14 #include <drm/drm_crtc_helper.h> 15 #include <drm/drm_plane_helper.h> 16 #include "armada_crtc.h" 17 #include "armada_drm.h" 18 #include "armada_fb.h" 19 #include "armada_gem.h" 20 #include "armada_hw.h" 21 22 struct armada_frame_work { 23 struct drm_pending_vblank_event *event; 24 struct armada_regs regs[4]; 25 struct drm_framebuffer *old_fb; 26 }; 27 28 enum csc_mode { 29 CSC_AUTO = 0, 30 CSC_YUV_CCIR601 = 1, 31 CSC_YUV_CCIR709 = 2, 32 CSC_RGB_COMPUTER = 1, 33 CSC_RGB_STUDIO = 2, 34 }; 35 36 /* 37 * A note about interlacing. Let's consider HDMI 1920x1080i. 38 * The timing parameters we have from X are: 39 * Hact HsyA HsyI Htot Vact VsyA VsyI Vtot 40 * 1920 2448 2492 2640 1080 1084 1094 1125 41 * Which get translated to: 42 * Hact HsyA HsyI Htot Vact VsyA VsyI Vtot 43 * 1920 2448 2492 2640 540 542 547 562 44 * 45 * This is how it is defined by CEA-861-D - line and pixel numbers are 46 * referenced to the rising edge of VSYNC and HSYNC. Total clocks per 47 * line: 2640. The odd frame, the first active line is at line 21, and 48 * the even frame, the first active line is 584. 49 * 50 * LN: 560 561 562 563 567 568 569 51 * DE: ~~~|____________________________//__________________________ 52 * HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____ 53 * VSYNC: _________________________|~~~~~~//~~~~~~~~~~~~~~~|__________ 54 * 22 blanking lines. VSYNC at 1320 (referenced to the HSYNC rising edge). 55 * 56 * LN: 1123 1124 1125 1 5 6 7 57 * DE: ~~~|____________________________//__________________________ 58 * HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____ 59 * VSYNC: ____________________|~~~~~~~~~~~//~~~~~~~~~~|_______________ 60 * 23 blanking lines 61 * 62 * The Armada LCD Controller line and pixel numbers are, like X timings, 63 * referenced to the top left of the active frame. 64 * 65 * So, translating these to our LCD controller: 66 * Odd frame, 563 total lines, VSYNC at line 543-548, pixel 1128. 67 * Even frame, 562 total lines, VSYNC at line 542-547, pixel 2448. 68 * Note: Vsync front porch remains constant! 69 * 70 * if (odd_frame) { 71 * vtotal = mode->crtc_vtotal + 1; 72 * vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay + 1; 73 * vhorizpos = mode->crtc_hsync_start - mode->crtc_htotal / 2 74 * } else { 75 * vtotal = mode->crtc_vtotal; 76 * vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay; 77 * vhorizpos = mode->crtc_hsync_start; 78 * } 79 * vfrontporch = mode->crtc_vtotal - mode->crtc_vsync_end; 80 * 81 * So, we need to reprogram these registers on each vsync event: 82 * LCD_SPU_V_PORCH, LCD_SPU_ADV_REG, LCD_SPUT_V_H_TOTAL 83 * 84 * Note: we do not use the frame done interrupts because these appear 85 * to happen too early, and lead to jitter on the display (presumably 86 * they occur at the end of the last active line, before the vsync back 87 * porch, which we're reprogramming.) 88 */ 89 90 void 91 armada_drm_crtc_update_regs(struct armada_crtc *dcrtc, struct armada_regs *regs) 92 { 93 while (regs->offset != ~0) { 94 void __iomem *reg = dcrtc->base + regs->offset; 95 uint32_t val; 96 97 val = regs->mask; 98 if (val != 0) 99 val &= readl_relaxed(reg); 100 writel_relaxed(val | regs->val, reg); 101 ++regs; 102 } 103 } 104 105 #define dpms_blanked(dpms) ((dpms) != DRM_MODE_DPMS_ON) 106 107 static void armada_drm_crtc_update(struct armada_crtc *dcrtc) 108 { 109 uint32_t dumb_ctrl; 110 111 dumb_ctrl = dcrtc->cfg_dumb_ctrl; 112 113 if (!dpms_blanked(dcrtc->dpms)) 114 dumb_ctrl |= CFG_DUMB_ENA; 115 116 /* 117 * When the dumb interface isn't in DUMB24_RGB888_0 mode, it might 118 * be using SPI or GPIO. If we set this to DUMB_BLANK, we will 119 * force LCD_D[23:0] to output blank color, overriding the GPIO or 120 * SPI usage. So leave it as-is unless in DUMB24_RGB888_0 mode. 121 */ 122 if (dpms_blanked(dcrtc->dpms) && 123 (dumb_ctrl & DUMB_MASK) == DUMB24_RGB888_0) { 124 dumb_ctrl &= ~DUMB_MASK; 125 dumb_ctrl |= DUMB_BLANK; 126 } 127 128 /* 129 * The documentation doesn't indicate what the normal state of 130 * the sync signals are. Sebastian Hesselbart kindly probed 131 * these signals on his board to determine their state. 132 * 133 * The non-inverted state of the sync signals is active high. 134 * Setting these bits makes the appropriate signal active low. 135 */ 136 if (dcrtc->crtc.mode.flags & DRM_MODE_FLAG_NCSYNC) 137 dumb_ctrl |= CFG_INV_CSYNC; 138 if (dcrtc->crtc.mode.flags & DRM_MODE_FLAG_NHSYNC) 139 dumb_ctrl |= CFG_INV_HSYNC; 140 if (dcrtc->crtc.mode.flags & DRM_MODE_FLAG_NVSYNC) 141 dumb_ctrl |= CFG_INV_VSYNC; 142 143 if (dcrtc->dumb_ctrl != dumb_ctrl) { 144 dcrtc->dumb_ctrl = dumb_ctrl; 145 writel_relaxed(dumb_ctrl, dcrtc->base + LCD_SPU_DUMB_CTRL); 146 } 147 } 148 149 static unsigned armada_drm_crtc_calc_fb(struct drm_framebuffer *fb, 150 int x, int y, struct armada_regs *regs, bool interlaced) 151 { 152 struct armada_gem_object *obj = drm_fb_obj(fb); 153 unsigned pitch = fb->pitches[0]; 154 unsigned offset = y * pitch + x * fb->bits_per_pixel / 8; 155 uint32_t addr_odd, addr_even; 156 unsigned i = 0; 157 158 DRM_DEBUG_DRIVER("pitch %u x %d y %d bpp %d\n", 159 pitch, x, y, fb->bits_per_pixel); 160 161 addr_odd = addr_even = obj->dev_addr + offset; 162 163 if (interlaced) { 164 addr_even += pitch; 165 pitch *= 2; 166 } 167 168 /* write offset, base, and pitch */ 169 armada_reg_queue_set(regs, i, addr_odd, LCD_CFG_GRA_START_ADDR0); 170 armada_reg_queue_set(regs, i, addr_even, LCD_CFG_GRA_START_ADDR1); 171 armada_reg_queue_mod(regs, i, pitch, 0xffff, LCD_CFG_GRA_PITCH); 172 173 return i; 174 } 175 176 static int armada_drm_crtc_queue_frame_work(struct armada_crtc *dcrtc, 177 struct armada_frame_work *work) 178 { 179 struct drm_device *dev = dcrtc->crtc.dev; 180 unsigned long flags; 181 int ret; 182 183 ret = drm_vblank_get(dev, dcrtc->num); 184 if (ret) { 185 DRM_ERROR("failed to acquire vblank counter\n"); 186 return ret; 187 } 188 189 spin_lock_irqsave(&dev->event_lock, flags); 190 if (!dcrtc->frame_work) 191 dcrtc->frame_work = work; 192 else 193 ret = -EBUSY; 194 spin_unlock_irqrestore(&dev->event_lock, flags); 195 196 if (ret) 197 drm_vblank_put(dev, dcrtc->num); 198 199 return ret; 200 } 201 202 static void armada_drm_crtc_complete_frame_work(struct armada_crtc *dcrtc) 203 { 204 struct drm_device *dev = dcrtc->crtc.dev; 205 struct armada_frame_work *work = dcrtc->frame_work; 206 207 dcrtc->frame_work = NULL; 208 209 armada_drm_crtc_update_regs(dcrtc, work->regs); 210 211 if (work->event) 212 drm_send_vblank_event(dev, dcrtc->num, work->event); 213 214 drm_vblank_put(dev, dcrtc->num); 215 216 /* Finally, queue the process-half of the cleanup. */ 217 __armada_drm_queue_unref_work(dcrtc->crtc.dev, work->old_fb); 218 kfree(work); 219 } 220 221 static void armada_drm_crtc_finish_fb(struct armada_crtc *dcrtc, 222 struct drm_framebuffer *fb, bool force) 223 { 224 struct armada_frame_work *work; 225 226 if (!fb) 227 return; 228 229 if (force) { 230 /* Display is disabled, so just drop the old fb */ 231 drm_framebuffer_unreference(fb); 232 return; 233 } 234 235 work = kmalloc(sizeof(*work), GFP_KERNEL); 236 if (work) { 237 int i = 0; 238 work->event = NULL; 239 work->old_fb = fb; 240 armada_reg_queue_end(work->regs, i); 241 242 if (armada_drm_crtc_queue_frame_work(dcrtc, work) == 0) 243 return; 244 245 kfree(work); 246 } 247 248 /* 249 * Oops - just drop the reference immediately and hope for 250 * the best. The worst that will happen is the buffer gets 251 * reused before it has finished being displayed. 252 */ 253 drm_framebuffer_unreference(fb); 254 } 255 256 static void armada_drm_vblank_off(struct armada_crtc *dcrtc) 257 { 258 struct drm_device *dev = dcrtc->crtc.dev; 259 260 /* 261 * Tell the DRM core that vblank IRQs aren't going to happen for 262 * a while. This cleans up any pending vblank events for us. 263 */ 264 drm_crtc_vblank_off(&dcrtc->crtc); 265 266 /* Handle any pending flip event. */ 267 spin_lock_irq(&dev->event_lock); 268 if (dcrtc->frame_work) 269 armada_drm_crtc_complete_frame_work(dcrtc); 270 spin_unlock_irq(&dev->event_lock); 271 } 272 273 void armada_drm_crtc_gamma_set(struct drm_crtc *crtc, u16 r, u16 g, u16 b, 274 int idx) 275 { 276 } 277 278 void armada_drm_crtc_gamma_get(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, 279 int idx) 280 { 281 } 282 283 /* The mode_config.mutex will be held for this call */ 284 static void armada_drm_crtc_dpms(struct drm_crtc *crtc, int dpms) 285 { 286 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 287 288 if (dcrtc->dpms != dpms) { 289 dcrtc->dpms = dpms; 290 armada_drm_crtc_update(dcrtc); 291 if (dpms_blanked(dpms)) 292 armada_drm_vblank_off(dcrtc); 293 else 294 drm_crtc_vblank_on(&dcrtc->crtc); 295 } 296 } 297 298 /* 299 * Prepare for a mode set. Turn off overlay to ensure that we don't end 300 * up with the overlay size being bigger than the active screen size. 301 * We rely upon X refreshing this state after the mode set has completed. 302 * 303 * The mode_config.mutex will be held for this call 304 */ 305 static void armada_drm_crtc_prepare(struct drm_crtc *crtc) 306 { 307 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 308 struct drm_plane *plane; 309 310 /* 311 * If we have an overlay plane associated with this CRTC, disable 312 * it before the modeset to avoid its coordinates being outside 313 * the new mode parameters. DRM doesn't provide help with this. 314 */ 315 plane = dcrtc->plane; 316 if (plane) { 317 struct drm_framebuffer *fb = plane->fb; 318 319 plane->funcs->disable_plane(plane); 320 plane->fb = NULL; 321 plane->crtc = NULL; 322 drm_framebuffer_unreference(fb); 323 } 324 } 325 326 /* The mode_config.mutex will be held for this call */ 327 static void armada_drm_crtc_commit(struct drm_crtc *crtc) 328 { 329 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 330 331 if (dcrtc->dpms != DRM_MODE_DPMS_ON) { 332 dcrtc->dpms = DRM_MODE_DPMS_ON; 333 armada_drm_crtc_update(dcrtc); 334 } 335 } 336 337 /* The mode_config.mutex will be held for this call */ 338 static bool armada_drm_crtc_mode_fixup(struct drm_crtc *crtc, 339 const struct drm_display_mode *mode, struct drm_display_mode *adj) 340 { 341 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 342 int ret; 343 344 /* We can't do interlaced modes if we don't have the SPU_ADV_REG */ 345 if (!dcrtc->variant->has_spu_adv_reg && 346 adj->flags & DRM_MODE_FLAG_INTERLACE) 347 return false; 348 349 /* Check whether the display mode is possible */ 350 ret = dcrtc->variant->compute_clock(dcrtc, adj, NULL); 351 if (ret) 352 return false; 353 354 return true; 355 } 356 357 static void armada_drm_crtc_irq(struct armada_crtc *dcrtc, u32 stat) 358 { 359 struct armada_vbl_event *e, *n; 360 void __iomem *base = dcrtc->base; 361 362 if (stat & DMA_FF_UNDERFLOW) 363 DRM_ERROR("video underflow on crtc %u\n", dcrtc->num); 364 if (stat & GRA_FF_UNDERFLOW) 365 DRM_ERROR("graphics underflow on crtc %u\n", dcrtc->num); 366 367 if (stat & VSYNC_IRQ) 368 drm_handle_vblank(dcrtc->crtc.dev, dcrtc->num); 369 370 spin_lock(&dcrtc->irq_lock); 371 372 list_for_each_entry_safe(e, n, &dcrtc->vbl_list, node) { 373 list_del_init(&e->node); 374 drm_vblank_put(dcrtc->crtc.dev, dcrtc->num); 375 e->fn(dcrtc, e->data); 376 } 377 378 if (stat & GRA_FRAME_IRQ && dcrtc->interlaced) { 379 int i = stat & GRA_FRAME_IRQ0 ? 0 : 1; 380 uint32_t val; 381 382 writel_relaxed(dcrtc->v[i].spu_v_porch, base + LCD_SPU_V_PORCH); 383 writel_relaxed(dcrtc->v[i].spu_v_h_total, 384 base + LCD_SPUT_V_H_TOTAL); 385 386 val = readl_relaxed(base + LCD_SPU_ADV_REG); 387 val &= ~(ADV_VSYNC_L_OFF | ADV_VSYNC_H_OFF | ADV_VSYNCOFFEN); 388 val |= dcrtc->v[i].spu_adv_reg; 389 writel_relaxed(val, base + LCD_SPU_ADV_REG); 390 } 391 392 if (stat & DUMB_FRAMEDONE && dcrtc->cursor_update) { 393 writel_relaxed(dcrtc->cursor_hw_pos, 394 base + LCD_SPU_HWC_OVSA_HPXL_VLN); 395 writel_relaxed(dcrtc->cursor_hw_sz, 396 base + LCD_SPU_HWC_HPXL_VLN); 397 armada_updatel(CFG_HWC_ENA, 398 CFG_HWC_ENA | CFG_HWC_1BITMOD | CFG_HWC_1BITENA, 399 base + LCD_SPU_DMA_CTRL0); 400 dcrtc->cursor_update = false; 401 armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA); 402 } 403 404 spin_unlock(&dcrtc->irq_lock); 405 406 if (stat & GRA_FRAME_IRQ) { 407 struct drm_device *dev = dcrtc->crtc.dev; 408 409 spin_lock(&dev->event_lock); 410 if (dcrtc->frame_work) 411 armada_drm_crtc_complete_frame_work(dcrtc); 412 spin_unlock(&dev->event_lock); 413 414 wake_up(&dcrtc->frame_wait); 415 } 416 } 417 418 static irqreturn_t armada_drm_irq(int irq, void *arg) 419 { 420 struct armada_crtc *dcrtc = arg; 421 u32 v, stat = readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR); 422 423 /* 424 * This is rediculous - rather than writing bits to clear, we 425 * have to set the actual status register value. This is racy. 426 */ 427 writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ISR); 428 429 /* Mask out those interrupts we haven't enabled */ 430 v = stat & dcrtc->irq_ena; 431 432 if (v & (VSYNC_IRQ|GRA_FRAME_IRQ|DUMB_FRAMEDONE)) { 433 armada_drm_crtc_irq(dcrtc, stat); 434 return IRQ_HANDLED; 435 } 436 return IRQ_NONE; 437 } 438 439 /* These are locked by dev->vbl_lock */ 440 void armada_drm_crtc_disable_irq(struct armada_crtc *dcrtc, u32 mask) 441 { 442 if (dcrtc->irq_ena & mask) { 443 dcrtc->irq_ena &= ~mask; 444 writel(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA); 445 } 446 } 447 448 void armada_drm_crtc_enable_irq(struct armada_crtc *dcrtc, u32 mask) 449 { 450 if ((dcrtc->irq_ena & mask) != mask) { 451 dcrtc->irq_ena |= mask; 452 writel(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA); 453 if (readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR) & mask) 454 writel(0, dcrtc->base + LCD_SPU_IRQ_ISR); 455 } 456 } 457 458 static uint32_t armada_drm_crtc_calculate_csc(struct armada_crtc *dcrtc) 459 { 460 struct drm_display_mode *adj = &dcrtc->crtc.mode; 461 uint32_t val = 0; 462 463 if (dcrtc->csc_yuv_mode == CSC_YUV_CCIR709) 464 val |= CFG_CSC_YUV_CCIR709; 465 if (dcrtc->csc_rgb_mode == CSC_RGB_STUDIO) 466 val |= CFG_CSC_RGB_STUDIO; 467 468 /* 469 * In auto mode, set the colorimetry, based upon the HDMI spec. 470 * 1280x720p, 1920x1080p and 1920x1080i use ITU709, others use 471 * ITU601. It may be more appropriate to set this depending on 472 * the source - but what if the graphic frame is YUV and the 473 * video frame is RGB? 474 */ 475 if ((adj->hdisplay == 1280 && adj->vdisplay == 720 && 476 !(adj->flags & DRM_MODE_FLAG_INTERLACE)) || 477 (adj->hdisplay == 1920 && adj->vdisplay == 1080)) { 478 if (dcrtc->csc_yuv_mode == CSC_AUTO) 479 val |= CFG_CSC_YUV_CCIR709; 480 } 481 482 /* 483 * We assume we're connected to a TV-like device, so the YUV->RGB 484 * conversion should produce a limited range. We should set this 485 * depending on the connectors attached to this CRTC, and what 486 * kind of device they report being connected. 487 */ 488 if (dcrtc->csc_rgb_mode == CSC_AUTO) 489 val |= CFG_CSC_RGB_STUDIO; 490 491 return val; 492 } 493 494 /* The mode_config.mutex will be held for this call */ 495 static int armada_drm_crtc_mode_set(struct drm_crtc *crtc, 496 struct drm_display_mode *mode, struct drm_display_mode *adj, 497 int x, int y, struct drm_framebuffer *old_fb) 498 { 499 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 500 struct armada_regs regs[17]; 501 uint32_t lm, rm, tm, bm, val, sclk; 502 unsigned long flags; 503 unsigned i; 504 bool interlaced; 505 506 drm_framebuffer_reference(crtc->primary->fb); 507 508 interlaced = !!(adj->flags & DRM_MODE_FLAG_INTERLACE); 509 510 i = armada_drm_crtc_calc_fb(dcrtc->crtc.primary->fb, 511 x, y, regs, interlaced); 512 513 rm = adj->crtc_hsync_start - adj->crtc_hdisplay; 514 lm = adj->crtc_htotal - adj->crtc_hsync_end; 515 bm = adj->crtc_vsync_start - adj->crtc_vdisplay; 516 tm = adj->crtc_vtotal - adj->crtc_vsync_end; 517 518 DRM_DEBUG_DRIVER("H: %d %d %d %d lm %d rm %d\n", 519 adj->crtc_hdisplay, 520 adj->crtc_hsync_start, 521 adj->crtc_hsync_end, 522 adj->crtc_htotal, lm, rm); 523 DRM_DEBUG_DRIVER("V: %d %d %d %d tm %d bm %d\n", 524 adj->crtc_vdisplay, 525 adj->crtc_vsync_start, 526 adj->crtc_vsync_end, 527 adj->crtc_vtotal, tm, bm); 528 529 /* Wait for pending flips to complete */ 530 wait_event(dcrtc->frame_wait, !dcrtc->frame_work); 531 532 drm_crtc_vblank_off(crtc); 533 534 crtc->mode = *adj; 535 536 val = dcrtc->dumb_ctrl & ~CFG_DUMB_ENA; 537 if (val != dcrtc->dumb_ctrl) { 538 dcrtc->dumb_ctrl = val; 539 writel_relaxed(val, dcrtc->base + LCD_SPU_DUMB_CTRL); 540 } 541 542 /* Now compute the divider for real */ 543 dcrtc->variant->compute_clock(dcrtc, adj, &sclk); 544 545 /* Ensure graphic fifo is enabled */ 546 armada_reg_queue_mod(regs, i, 0, CFG_PDWN64x66, LCD_SPU_SRAM_PARA1); 547 armada_reg_queue_set(regs, i, sclk, LCD_CFG_SCLK_DIV); 548 549 if (interlaced ^ dcrtc->interlaced) { 550 if (adj->flags & DRM_MODE_FLAG_INTERLACE) 551 drm_vblank_get(dcrtc->crtc.dev, dcrtc->num); 552 else 553 drm_vblank_put(dcrtc->crtc.dev, dcrtc->num); 554 dcrtc->interlaced = interlaced; 555 } 556 557 spin_lock_irqsave(&dcrtc->irq_lock, flags); 558 559 /* Even interlaced/progressive frame */ 560 dcrtc->v[1].spu_v_h_total = adj->crtc_vtotal << 16 | 561 adj->crtc_htotal; 562 dcrtc->v[1].spu_v_porch = tm << 16 | bm; 563 val = adj->crtc_hsync_start; 564 dcrtc->v[1].spu_adv_reg = val << 20 | val | ADV_VSYNCOFFEN | 565 dcrtc->variant->spu_adv_reg; 566 567 if (interlaced) { 568 /* Odd interlaced frame */ 569 dcrtc->v[0].spu_v_h_total = dcrtc->v[1].spu_v_h_total + 570 (1 << 16); 571 dcrtc->v[0].spu_v_porch = dcrtc->v[1].spu_v_porch + 1; 572 val = adj->crtc_hsync_start - adj->crtc_htotal / 2; 573 dcrtc->v[0].spu_adv_reg = val << 20 | val | ADV_VSYNCOFFEN | 574 dcrtc->variant->spu_adv_reg; 575 } else { 576 dcrtc->v[0] = dcrtc->v[1]; 577 } 578 579 val = adj->crtc_vdisplay << 16 | adj->crtc_hdisplay; 580 581 armada_reg_queue_set(regs, i, val, LCD_SPU_V_H_ACTIVE); 582 armada_reg_queue_set(regs, i, val, LCD_SPU_GRA_HPXL_VLN); 583 armada_reg_queue_set(regs, i, val, LCD_SPU_GZM_HPXL_VLN); 584 armada_reg_queue_set(regs, i, (lm << 16) | rm, LCD_SPU_H_PORCH); 585 armada_reg_queue_set(regs, i, dcrtc->v[0].spu_v_porch, LCD_SPU_V_PORCH); 586 armada_reg_queue_set(regs, i, dcrtc->v[0].spu_v_h_total, 587 LCD_SPUT_V_H_TOTAL); 588 589 if (dcrtc->variant->has_spu_adv_reg) { 590 armada_reg_queue_mod(regs, i, dcrtc->v[0].spu_adv_reg, 591 ADV_VSYNC_L_OFF | ADV_VSYNC_H_OFF | 592 ADV_VSYNCOFFEN, LCD_SPU_ADV_REG); 593 } 594 595 val = CFG_GRA_ENA | CFG_GRA_HSMOOTH; 596 val |= CFG_GRA_FMT(drm_fb_to_armada_fb(dcrtc->crtc.primary->fb)->fmt); 597 val |= CFG_GRA_MOD(drm_fb_to_armada_fb(dcrtc->crtc.primary->fb)->mod); 598 599 if (drm_fb_to_armada_fb(dcrtc->crtc.primary->fb)->fmt > CFG_420) 600 val |= CFG_PALETTE_ENA; 601 602 if (interlaced) 603 val |= CFG_GRA_FTOGGLE; 604 605 armada_reg_queue_mod(regs, i, val, CFG_GRAFORMAT | 606 CFG_GRA_MOD(CFG_SWAPRB | CFG_SWAPUV | 607 CFG_SWAPYU | CFG_YUV2RGB) | 608 CFG_PALETTE_ENA | CFG_GRA_FTOGGLE, 609 LCD_SPU_DMA_CTRL0); 610 611 val = adj->flags & DRM_MODE_FLAG_NVSYNC ? CFG_VSYNC_INV : 0; 612 armada_reg_queue_mod(regs, i, val, CFG_VSYNC_INV, LCD_SPU_DMA_CTRL1); 613 614 val = dcrtc->spu_iopad_ctrl | armada_drm_crtc_calculate_csc(dcrtc); 615 armada_reg_queue_set(regs, i, val, LCD_SPU_IOPAD_CONTROL); 616 armada_reg_queue_end(regs, i); 617 618 armada_drm_crtc_update_regs(dcrtc, regs); 619 spin_unlock_irqrestore(&dcrtc->irq_lock, flags); 620 621 armada_drm_crtc_update(dcrtc); 622 623 drm_crtc_vblank_on(crtc); 624 armada_drm_crtc_finish_fb(dcrtc, old_fb, dpms_blanked(dcrtc->dpms)); 625 626 return 0; 627 } 628 629 /* The mode_config.mutex will be held for this call */ 630 static int armada_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, 631 struct drm_framebuffer *old_fb) 632 { 633 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 634 struct armada_regs regs[4]; 635 unsigned i; 636 637 i = armada_drm_crtc_calc_fb(crtc->primary->fb, crtc->x, crtc->y, regs, 638 dcrtc->interlaced); 639 armada_reg_queue_end(regs, i); 640 641 /* Wait for pending flips to complete */ 642 wait_event(dcrtc->frame_wait, !dcrtc->frame_work); 643 644 /* Take a reference to the new fb as we're using it */ 645 drm_framebuffer_reference(crtc->primary->fb); 646 647 /* Update the base in the CRTC */ 648 armada_drm_crtc_update_regs(dcrtc, regs); 649 650 /* Drop our previously held reference */ 651 armada_drm_crtc_finish_fb(dcrtc, old_fb, dpms_blanked(dcrtc->dpms)); 652 653 return 0; 654 } 655 656 static void armada_drm_crtc_load_lut(struct drm_crtc *crtc) 657 { 658 } 659 660 /* The mode_config.mutex will be held for this call */ 661 static void armada_drm_crtc_disable(struct drm_crtc *crtc) 662 { 663 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 664 665 armada_drm_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); 666 armada_drm_crtc_finish_fb(dcrtc, crtc->primary->fb, true); 667 668 /* Power down most RAMs and FIFOs */ 669 writel_relaxed(CFG_PDWN256x32 | CFG_PDWN256x24 | CFG_PDWN256x8 | 670 CFG_PDWN32x32 | CFG_PDWN16x66 | CFG_PDWN32x66 | 671 CFG_PDWN64x66, dcrtc->base + LCD_SPU_SRAM_PARA1); 672 } 673 674 static const struct drm_crtc_helper_funcs armada_crtc_helper_funcs = { 675 .dpms = armada_drm_crtc_dpms, 676 .prepare = armada_drm_crtc_prepare, 677 .commit = armada_drm_crtc_commit, 678 .mode_fixup = armada_drm_crtc_mode_fixup, 679 .mode_set = armada_drm_crtc_mode_set, 680 .mode_set_base = armada_drm_crtc_mode_set_base, 681 .load_lut = armada_drm_crtc_load_lut, 682 .disable = armada_drm_crtc_disable, 683 }; 684 685 static void armada_load_cursor_argb(void __iomem *base, uint32_t *pix, 686 unsigned stride, unsigned width, unsigned height) 687 { 688 uint32_t addr; 689 unsigned y; 690 691 addr = SRAM_HWC32_RAM1; 692 for (y = 0; y < height; y++) { 693 uint32_t *p = &pix[y * stride]; 694 unsigned x; 695 696 for (x = 0; x < width; x++, p++) { 697 uint32_t val = *p; 698 699 val = (val & 0xff00ff00) | 700 (val & 0x000000ff) << 16 | 701 (val & 0x00ff0000) >> 16; 702 703 writel_relaxed(val, 704 base + LCD_SPU_SRAM_WRDAT); 705 writel_relaxed(addr | SRAM_WRITE, 706 base + LCD_SPU_SRAM_CTRL); 707 readl_relaxed(base + LCD_SPU_HWC_OVSA_HPXL_VLN); 708 addr += 1; 709 if ((addr & 0x00ff) == 0) 710 addr += 0xf00; 711 if ((addr & 0x30ff) == 0) 712 addr = SRAM_HWC32_RAM2; 713 } 714 } 715 } 716 717 static void armada_drm_crtc_cursor_tran(void __iomem *base) 718 { 719 unsigned addr; 720 721 for (addr = 0; addr < 256; addr++) { 722 /* write the default value */ 723 writel_relaxed(0x55555555, base + LCD_SPU_SRAM_WRDAT); 724 writel_relaxed(addr | SRAM_WRITE | SRAM_HWC32_TRAN, 725 base + LCD_SPU_SRAM_CTRL); 726 } 727 } 728 729 static int armada_drm_crtc_cursor_update(struct armada_crtc *dcrtc, bool reload) 730 { 731 uint32_t xoff, xscr, w = dcrtc->cursor_w, s; 732 uint32_t yoff, yscr, h = dcrtc->cursor_h; 733 uint32_t para1; 734 735 /* 736 * Calculate the visible width and height of the cursor, 737 * screen position, and the position in the cursor bitmap. 738 */ 739 if (dcrtc->cursor_x < 0) { 740 xoff = -dcrtc->cursor_x; 741 xscr = 0; 742 w -= min(xoff, w); 743 } else if (dcrtc->cursor_x + w > dcrtc->crtc.mode.hdisplay) { 744 xoff = 0; 745 xscr = dcrtc->cursor_x; 746 w = max_t(int, dcrtc->crtc.mode.hdisplay - dcrtc->cursor_x, 0); 747 } else { 748 xoff = 0; 749 xscr = dcrtc->cursor_x; 750 } 751 752 if (dcrtc->cursor_y < 0) { 753 yoff = -dcrtc->cursor_y; 754 yscr = 0; 755 h -= min(yoff, h); 756 } else if (dcrtc->cursor_y + h > dcrtc->crtc.mode.vdisplay) { 757 yoff = 0; 758 yscr = dcrtc->cursor_y; 759 h = max_t(int, dcrtc->crtc.mode.vdisplay - dcrtc->cursor_y, 0); 760 } else { 761 yoff = 0; 762 yscr = dcrtc->cursor_y; 763 } 764 765 /* On interlaced modes, the vertical cursor size must be halved */ 766 s = dcrtc->cursor_w; 767 if (dcrtc->interlaced) { 768 s *= 2; 769 yscr /= 2; 770 h /= 2; 771 } 772 773 if (!dcrtc->cursor_obj || !h || !w) { 774 spin_lock_irq(&dcrtc->irq_lock); 775 armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA); 776 dcrtc->cursor_update = false; 777 armada_updatel(0, CFG_HWC_ENA, dcrtc->base + LCD_SPU_DMA_CTRL0); 778 spin_unlock_irq(&dcrtc->irq_lock); 779 return 0; 780 } 781 782 para1 = readl_relaxed(dcrtc->base + LCD_SPU_SRAM_PARA1); 783 armada_updatel(CFG_CSB_256x32, CFG_CSB_256x32 | CFG_PDWN256x32, 784 dcrtc->base + LCD_SPU_SRAM_PARA1); 785 786 /* 787 * Initialize the transparency if the SRAM was powered down. 788 * We must also reload the cursor data as well. 789 */ 790 if (!(para1 & CFG_CSB_256x32)) { 791 armada_drm_crtc_cursor_tran(dcrtc->base); 792 reload = true; 793 } 794 795 if (dcrtc->cursor_hw_sz != (h << 16 | w)) { 796 spin_lock_irq(&dcrtc->irq_lock); 797 armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA); 798 dcrtc->cursor_update = false; 799 armada_updatel(0, CFG_HWC_ENA, dcrtc->base + LCD_SPU_DMA_CTRL0); 800 spin_unlock_irq(&dcrtc->irq_lock); 801 reload = true; 802 } 803 if (reload) { 804 struct armada_gem_object *obj = dcrtc->cursor_obj; 805 uint32_t *pix; 806 /* Set the top-left corner of the cursor image */ 807 pix = obj->addr; 808 pix += yoff * s + xoff; 809 armada_load_cursor_argb(dcrtc->base, pix, s, w, h); 810 } 811 812 /* Reload the cursor position, size and enable in the IRQ handler */ 813 spin_lock_irq(&dcrtc->irq_lock); 814 dcrtc->cursor_hw_pos = yscr << 16 | xscr; 815 dcrtc->cursor_hw_sz = h << 16 | w; 816 dcrtc->cursor_update = true; 817 armada_drm_crtc_enable_irq(dcrtc, DUMB_FRAMEDONE_ENA); 818 spin_unlock_irq(&dcrtc->irq_lock); 819 820 return 0; 821 } 822 823 static void cursor_update(void *data) 824 { 825 armada_drm_crtc_cursor_update(data, true); 826 } 827 828 static int armada_drm_crtc_cursor_set(struct drm_crtc *crtc, 829 struct drm_file *file, uint32_t handle, uint32_t w, uint32_t h) 830 { 831 struct drm_device *dev = crtc->dev; 832 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 833 struct armada_gem_object *obj = NULL; 834 int ret; 835 836 /* If no cursor support, replicate drm's return value */ 837 if (!dcrtc->variant->has_spu_adv_reg) 838 return -ENXIO; 839 840 if (handle && w > 0 && h > 0) { 841 /* maximum size is 64x32 or 32x64 */ 842 if (w > 64 || h > 64 || (w > 32 && h > 32)) 843 return -ENOMEM; 844 845 obj = armada_gem_object_lookup(dev, file, handle); 846 if (!obj) 847 return -ENOENT; 848 849 /* Must be a kernel-mapped object */ 850 if (!obj->addr) { 851 drm_gem_object_unreference_unlocked(&obj->obj); 852 return -EINVAL; 853 } 854 855 if (obj->obj.size < w * h * 4) { 856 DRM_ERROR("buffer is too small\n"); 857 drm_gem_object_unreference_unlocked(&obj->obj); 858 return -ENOMEM; 859 } 860 } 861 862 mutex_lock(&dev->struct_mutex); 863 if (dcrtc->cursor_obj) { 864 dcrtc->cursor_obj->update = NULL; 865 dcrtc->cursor_obj->update_data = NULL; 866 drm_gem_object_unreference(&dcrtc->cursor_obj->obj); 867 } 868 dcrtc->cursor_obj = obj; 869 dcrtc->cursor_w = w; 870 dcrtc->cursor_h = h; 871 ret = armada_drm_crtc_cursor_update(dcrtc, true); 872 if (obj) { 873 obj->update_data = dcrtc; 874 obj->update = cursor_update; 875 } 876 mutex_unlock(&dev->struct_mutex); 877 878 return ret; 879 } 880 881 static int armada_drm_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) 882 { 883 struct drm_device *dev = crtc->dev; 884 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 885 int ret; 886 887 /* If no cursor support, replicate drm's return value */ 888 if (!dcrtc->variant->has_spu_adv_reg) 889 return -EFAULT; 890 891 mutex_lock(&dev->struct_mutex); 892 dcrtc->cursor_x = x; 893 dcrtc->cursor_y = y; 894 ret = armada_drm_crtc_cursor_update(dcrtc, false); 895 mutex_unlock(&dev->struct_mutex); 896 897 return ret; 898 } 899 900 static void armada_drm_crtc_destroy(struct drm_crtc *crtc) 901 { 902 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 903 struct armada_private *priv = crtc->dev->dev_private; 904 905 if (dcrtc->cursor_obj) 906 drm_gem_object_unreference(&dcrtc->cursor_obj->obj); 907 908 priv->dcrtc[dcrtc->num] = NULL; 909 drm_crtc_cleanup(&dcrtc->crtc); 910 911 if (!IS_ERR(dcrtc->clk)) 912 clk_disable_unprepare(dcrtc->clk); 913 914 writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ENA); 915 916 of_node_put(dcrtc->crtc.port); 917 918 kfree(dcrtc); 919 } 920 921 /* 922 * The mode_config lock is held here, to prevent races between this 923 * and a mode_set. 924 */ 925 static int armada_drm_crtc_page_flip(struct drm_crtc *crtc, 926 struct drm_framebuffer *fb, struct drm_pending_vblank_event *event, uint32_t page_flip_flags) 927 { 928 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 929 struct armada_frame_work *work; 930 struct drm_device *dev = crtc->dev; 931 unsigned long flags; 932 unsigned i; 933 int ret; 934 935 /* We don't support changing the pixel format */ 936 if (fb->pixel_format != crtc->primary->fb->pixel_format) 937 return -EINVAL; 938 939 work = kmalloc(sizeof(*work), GFP_KERNEL); 940 if (!work) 941 return -ENOMEM; 942 943 work->event = event; 944 work->old_fb = dcrtc->crtc.primary->fb; 945 946 i = armada_drm_crtc_calc_fb(fb, crtc->x, crtc->y, work->regs, 947 dcrtc->interlaced); 948 armada_reg_queue_end(work->regs, i); 949 950 /* 951 * Ensure that we hold a reference on the new framebuffer. 952 * This has to match the behaviour in mode_set. 953 */ 954 drm_framebuffer_reference(fb); 955 956 ret = armada_drm_crtc_queue_frame_work(dcrtc, work); 957 if (ret) { 958 /* Undo our reference above */ 959 drm_framebuffer_unreference(fb); 960 kfree(work); 961 return ret; 962 } 963 964 /* 965 * Don't take a reference on the new framebuffer; 966 * drm_mode_page_flip_ioctl() has already grabbed a reference and 967 * will _not_ drop that reference on successful return from this 968 * function. Simply mark this new framebuffer as the current one. 969 */ 970 dcrtc->crtc.primary->fb = fb; 971 972 /* 973 * Finally, if the display is blanked, we won't receive an 974 * interrupt, so complete it now. 975 */ 976 if (dpms_blanked(dcrtc->dpms)) { 977 spin_lock_irqsave(&dev->event_lock, flags); 978 if (dcrtc->frame_work) 979 armada_drm_crtc_complete_frame_work(dcrtc); 980 spin_unlock_irqrestore(&dev->event_lock, flags); 981 } 982 983 return 0; 984 } 985 986 static int 987 armada_drm_crtc_set_property(struct drm_crtc *crtc, 988 struct drm_property *property, uint64_t val) 989 { 990 struct armada_private *priv = crtc->dev->dev_private; 991 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 992 bool update_csc = false; 993 994 if (property == priv->csc_yuv_prop) { 995 dcrtc->csc_yuv_mode = val; 996 update_csc = true; 997 } else if (property == priv->csc_rgb_prop) { 998 dcrtc->csc_rgb_mode = val; 999 update_csc = true; 1000 } 1001 1002 if (update_csc) { 1003 uint32_t val; 1004 1005 val = dcrtc->spu_iopad_ctrl | 1006 armada_drm_crtc_calculate_csc(dcrtc); 1007 writel_relaxed(val, dcrtc->base + LCD_SPU_IOPAD_CONTROL); 1008 } 1009 1010 return 0; 1011 } 1012 1013 static struct drm_crtc_funcs armada_crtc_funcs = { 1014 .cursor_set = armada_drm_crtc_cursor_set, 1015 .cursor_move = armada_drm_crtc_cursor_move, 1016 .destroy = armada_drm_crtc_destroy, 1017 .set_config = drm_crtc_helper_set_config, 1018 .page_flip = armada_drm_crtc_page_flip, 1019 .set_property = armada_drm_crtc_set_property, 1020 }; 1021 1022 static struct drm_prop_enum_list armada_drm_csc_yuv_enum_list[] = { 1023 { CSC_AUTO, "Auto" }, 1024 { CSC_YUV_CCIR601, "CCIR601" }, 1025 { CSC_YUV_CCIR709, "CCIR709" }, 1026 }; 1027 1028 static struct drm_prop_enum_list armada_drm_csc_rgb_enum_list[] = { 1029 { CSC_AUTO, "Auto" }, 1030 { CSC_RGB_COMPUTER, "Computer system" }, 1031 { CSC_RGB_STUDIO, "Studio" }, 1032 }; 1033 1034 static int armada_drm_crtc_create_properties(struct drm_device *dev) 1035 { 1036 struct armada_private *priv = dev->dev_private; 1037 1038 if (priv->csc_yuv_prop) 1039 return 0; 1040 1041 priv->csc_yuv_prop = drm_property_create_enum(dev, 0, 1042 "CSC_YUV", armada_drm_csc_yuv_enum_list, 1043 ARRAY_SIZE(armada_drm_csc_yuv_enum_list)); 1044 priv->csc_rgb_prop = drm_property_create_enum(dev, 0, 1045 "CSC_RGB", armada_drm_csc_rgb_enum_list, 1046 ARRAY_SIZE(armada_drm_csc_rgb_enum_list)); 1047 1048 if (!priv->csc_yuv_prop || !priv->csc_rgb_prop) 1049 return -ENOMEM; 1050 1051 return 0; 1052 } 1053 1054 int armada_drm_crtc_create(struct drm_device *drm, struct device *dev, 1055 struct resource *res, int irq, const struct armada_variant *variant, 1056 struct device_node *port) 1057 { 1058 struct armada_private *priv = drm->dev_private; 1059 struct armada_crtc *dcrtc; 1060 void __iomem *base; 1061 int ret; 1062 1063 ret = armada_drm_crtc_create_properties(drm); 1064 if (ret) 1065 return ret; 1066 1067 base = devm_ioremap_resource(dev, res); 1068 if (IS_ERR(base)) 1069 return PTR_ERR(base); 1070 1071 dcrtc = kzalloc(sizeof(*dcrtc), GFP_KERNEL); 1072 if (!dcrtc) { 1073 DRM_ERROR("failed to allocate Armada crtc\n"); 1074 return -ENOMEM; 1075 } 1076 1077 if (dev != drm->dev) 1078 dev_set_drvdata(dev, dcrtc); 1079 1080 dcrtc->variant = variant; 1081 dcrtc->base = base; 1082 dcrtc->num = drm->mode_config.num_crtc; 1083 dcrtc->clk = ERR_PTR(-EINVAL); 1084 dcrtc->csc_yuv_mode = CSC_AUTO; 1085 dcrtc->csc_rgb_mode = CSC_AUTO; 1086 dcrtc->cfg_dumb_ctrl = DUMB24_RGB888_0; 1087 dcrtc->spu_iopad_ctrl = CFG_VSCALE_LN_EN | CFG_IOPAD_DUMB24; 1088 spin_lock_init(&dcrtc->irq_lock); 1089 dcrtc->irq_ena = CLEAN_SPU_IRQ_ISR; 1090 INIT_LIST_HEAD(&dcrtc->vbl_list); 1091 init_waitqueue_head(&dcrtc->frame_wait); 1092 1093 /* Initialize some registers which we don't otherwise set */ 1094 writel_relaxed(0x00000001, dcrtc->base + LCD_CFG_SCLK_DIV); 1095 writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_BLANKCOLOR); 1096 writel_relaxed(dcrtc->spu_iopad_ctrl, 1097 dcrtc->base + LCD_SPU_IOPAD_CONTROL); 1098 writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_SRAM_PARA0); 1099 writel_relaxed(CFG_PDWN256x32 | CFG_PDWN256x24 | CFG_PDWN256x8 | 1100 CFG_PDWN32x32 | CFG_PDWN16x66 | CFG_PDWN32x66 | 1101 CFG_PDWN64x66, dcrtc->base + LCD_SPU_SRAM_PARA1); 1102 writel_relaxed(0x2032ff81, dcrtc->base + LCD_SPU_DMA_CTRL1); 1103 writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_GRA_OVSA_HPXL_VLN); 1104 writel_relaxed(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA); 1105 writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ISR); 1106 1107 ret = devm_request_irq(dev, irq, armada_drm_irq, 0, "armada_drm_crtc", 1108 dcrtc); 1109 if (ret < 0) { 1110 kfree(dcrtc); 1111 return ret; 1112 } 1113 1114 if (dcrtc->variant->init) { 1115 ret = dcrtc->variant->init(dcrtc, dev); 1116 if (ret) { 1117 kfree(dcrtc); 1118 return ret; 1119 } 1120 } 1121 1122 /* Ensure AXI pipeline is enabled */ 1123 armada_updatel(CFG_ARBFAST_ENA, 0, dcrtc->base + LCD_SPU_DMA_CTRL0); 1124 1125 priv->dcrtc[dcrtc->num] = dcrtc; 1126 1127 dcrtc->crtc.port = port; 1128 drm_crtc_init(drm, &dcrtc->crtc, &armada_crtc_funcs); 1129 drm_crtc_helper_add(&dcrtc->crtc, &armada_crtc_helper_funcs); 1130 1131 drm_object_attach_property(&dcrtc->crtc.base, priv->csc_yuv_prop, 1132 dcrtc->csc_yuv_mode); 1133 drm_object_attach_property(&dcrtc->crtc.base, priv->csc_rgb_prop, 1134 dcrtc->csc_rgb_mode); 1135 1136 return armada_overlay_plane_create(drm, 1 << dcrtc->num); 1137 } 1138 1139 static int 1140 armada_lcd_bind(struct device *dev, struct device *master, void *data) 1141 { 1142 struct platform_device *pdev = to_platform_device(dev); 1143 struct drm_device *drm = data; 1144 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1145 int irq = platform_get_irq(pdev, 0); 1146 const struct armada_variant *variant; 1147 struct device_node *port = NULL; 1148 1149 if (irq < 0) 1150 return irq; 1151 1152 if (!dev->of_node) { 1153 const struct platform_device_id *id; 1154 1155 id = platform_get_device_id(pdev); 1156 if (!id) 1157 return -ENXIO; 1158 1159 variant = (const struct armada_variant *)id->driver_data; 1160 } else { 1161 const struct of_device_id *match; 1162 struct device_node *np, *parent = dev->of_node; 1163 1164 match = of_match_device(dev->driver->of_match_table, dev); 1165 if (!match) 1166 return -ENXIO; 1167 1168 np = of_get_child_by_name(parent, "ports"); 1169 if (np) 1170 parent = np; 1171 port = of_get_child_by_name(parent, "port"); 1172 of_node_put(np); 1173 if (!port) { 1174 dev_err(dev, "no port node found in %s\n", 1175 parent->full_name); 1176 return -ENXIO; 1177 } 1178 1179 variant = match->data; 1180 } 1181 1182 return armada_drm_crtc_create(drm, dev, res, irq, variant, port); 1183 } 1184 1185 static void 1186 armada_lcd_unbind(struct device *dev, struct device *master, void *data) 1187 { 1188 struct armada_crtc *dcrtc = dev_get_drvdata(dev); 1189 1190 armada_drm_crtc_destroy(&dcrtc->crtc); 1191 } 1192 1193 static const struct component_ops armada_lcd_ops = { 1194 .bind = armada_lcd_bind, 1195 .unbind = armada_lcd_unbind, 1196 }; 1197 1198 static int armada_lcd_probe(struct platform_device *pdev) 1199 { 1200 return component_add(&pdev->dev, &armada_lcd_ops); 1201 } 1202 1203 static int armada_lcd_remove(struct platform_device *pdev) 1204 { 1205 component_del(&pdev->dev, &armada_lcd_ops); 1206 return 0; 1207 } 1208 1209 static struct of_device_id armada_lcd_of_match[] = { 1210 { 1211 .compatible = "marvell,dove-lcd", 1212 .data = &armada510_ops, 1213 }, 1214 {} 1215 }; 1216 MODULE_DEVICE_TABLE(of, armada_lcd_of_match); 1217 1218 static const struct platform_device_id armada_lcd_platform_ids[] = { 1219 { 1220 .name = "armada-lcd", 1221 .driver_data = (unsigned long)&armada510_ops, 1222 }, { 1223 .name = "armada-510-lcd", 1224 .driver_data = (unsigned long)&armada510_ops, 1225 }, 1226 { }, 1227 }; 1228 MODULE_DEVICE_TABLE(platform, armada_lcd_platform_ids); 1229 1230 struct platform_driver armada_lcd_platform_driver = { 1231 .probe = armada_lcd_probe, 1232 .remove = armada_lcd_remove, 1233 .driver = { 1234 .name = "armada-lcd", 1235 .owner = THIS_MODULE, 1236 .of_match_table = armada_lcd_of_match, 1237 }, 1238 .id_table = armada_lcd_platform_ids, 1239 }; 1240