Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/exynos/decon5433: add support for DECON-TV

DECON-TV IP is responsible for generating video stream which is transferred
to HDMI IP. It is almost fully compatible with DECON IP.

The patch is based on initial work of Hyungwon Hwang.

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
Signed-off-by: Inki Dae <inki.dae@samsung.com>

authored by

Andrzej Hajda and committed by
Inki Dae
b8182832 5d929ba5

+122 -61
+93 -61
drivers/gpu/drm/exynos/exynos5433_drm_decon.c
··· 13 13 #include <linux/platform_device.h> 14 14 #include <linux/clk.h> 15 15 #include <linux/component.h> 16 + #include <linux/of_device.h> 16 17 #include <linux/of_gpio.h> 17 18 #include <linux/pm_runtime.h> 18 19 ··· 38 37 "sclk_decon_eclk", 39 38 }; 40 39 40 + enum decon_iftype { 41 + IFTYPE_RGB, 42 + IFTYPE_I80, 43 + IFTYPE_HDMI 44 + }; 45 + 41 46 enum decon_flag_bits { 42 47 BIT_CLKS_ENABLED, 43 48 BIT_IRQS_ENABLED, ··· 60 53 struct clk *clks[ARRAY_SIZE(decon_clks_name)]; 61 54 int pipe; 62 55 unsigned long flags; 63 - bool i80_if; 56 + enum decon_iftype out_type; 57 + int first_win; 64 58 }; 65 59 66 60 static const uint32_t decon_formats[] = { ··· 88 80 89 81 if (test_and_set_bit(BIT_IRQS_ENABLED, &ctx->flags)) { 90 82 val = VIDINTCON0_INTEN; 91 - if (ctx->i80_if) 83 + if (ctx->out_type == IFTYPE_I80) 92 84 val |= VIDINTCON0_FRAMEDONE; 93 85 else 94 86 val |= VIDINTCON0_INTFRMEN; ··· 112 104 113 105 static void decon_setup_trigger(struct decon_context *ctx) 114 106 { 115 - u32 val = TRIGCON_TRIGEN_PER_F | TRIGCON_TRIGEN_F | 116 - TRIGCON_TE_AUTO_MASK | TRIGCON_SWTRIGEN; 107 + u32 val = (ctx->out_type != IFTYPE_HDMI) 108 + ? TRIGCON_TRIGEN_PER_F | TRIGCON_TRIGEN_F | 109 + TRIGCON_TE_AUTO_MASK | TRIGCON_SWTRIGEN 110 + : TRIGCON_TRIGEN_PER_F | TRIGCON_TRIGEN_F | 111 + TRIGCON_HWTRIGMASK_I80_RGB | TRIGCON_HWTRIGEN_I80_RGB; 117 112 writel(val, ctx->addr + DECON_TRIGCON); 118 113 } 119 114 ··· 129 118 if (test_bit(BIT_SUSPENDED, &ctx->flags)) 130 119 return; 131 120 121 + if (ctx->out_type == IFTYPE_HDMI) { 122 + m->crtc_hsync_start = m->crtc_hdisplay + 10; 123 + m->crtc_hsync_end = m->crtc_htotal - 92; 124 + m->crtc_vsync_start = m->crtc_vdisplay + 1; 125 + m->crtc_vsync_end = m->crtc_vsync_start + 1; 126 + } 127 + 128 + decon_set_bits(ctx, DECON_VIDCON0, VIDCON0_ENVID, 0); 129 + 132 130 /* enable clock gate */ 133 131 val = CMU_CLKGAGE_MODE_SFR_F | CMU_CLKGAGE_MODE_MEM_F; 134 132 writel(val, ctx->addr + DECON_CMU); 135 133 136 134 /* lcd on and use command if */ 137 135 val = VIDOUT_LCD_ON; 138 - if (ctx->i80_if) 136 + if (ctx->out_type == IFTYPE_I80) 139 137 val |= VIDOUT_COMMAND_IF; 140 138 else 141 139 val |= VIDOUT_RGB_IF; ··· 154 134 VIDTCON2_HOZVAL(m->hdisplay - 1); 155 135 writel(val, ctx->addr + DECON_VIDTCON2); 156 136 157 - if (!ctx->i80_if) { 137 + if (ctx->out_type != IFTYPE_I80) { 158 138 val = VIDTCON00_VBPD_F( 159 139 m->crtc_vtotal - m->crtc_vsync_end - 1) | 160 140 VIDTCON00_VFPD_F( ··· 179 159 decon_setup_trigger(ctx); 180 160 181 161 /* enable output and display signal */ 182 - val = VIDCON0_ENVID | VIDCON0_ENVID_F; 183 - writel(val, ctx->addr + DECON_VIDCON0); 162 + decon_set_bits(ctx, DECON_VIDCON0, VIDCON0_ENVID | VIDCON0_ENVID_F, ~0); 184 163 } 185 - 186 - #define COORDINATE_X(x) (((x) & 0xfff) << 12) 187 - #define COORDINATE_Y(x) ((x) & 0xfff) 188 - #define OFFSIZE(x) (((x) & 0x3fff) << 14) 189 - #define PAGEWIDTH(x) ((x) & 0x3fff) 190 164 191 165 static void decon_win_set_pixfmt(struct decon_context *ctx, unsigned int win, 192 166 struct drm_framebuffer *fb) ··· 252 238 decon_shadow_protect_win(ctx, plane->zpos, true); 253 239 } 254 240 241 + #define BIT_VAL(x, e, s) (((x) & ((1 << ((e) - (s) + 1)) - 1)) << (s)) 242 + #define COORDINATE_X(x) BIT_VAL((x), 23, 12) 243 + #define COORDINATE_Y(x) BIT_VAL((x), 11, 0) 244 + 255 245 static void decon_update_plane(struct exynos_drm_crtc *crtc, 256 246 struct exynos_drm_plane *plane) 257 247 { ··· 289 271 val = plane->dma_addr[0] + pitch * plane->crtc_h; 290 272 writel(val, ctx->addr + DECON_VIDW0xADD1B0(win)); 291 273 292 - val = OFFSIZE(pitch - plane->crtc_w * bpp) 293 - | PAGEWIDTH(plane->crtc_w * bpp); 274 + if (ctx->out_type != IFTYPE_HDMI) 275 + val = BIT_VAL(pitch - plane->crtc_w * bpp, 27, 14) 276 + | BIT_VAL(plane->crtc_w * bpp, 13, 0); 277 + else 278 + val = BIT_VAL(pitch - plane->crtc_w * bpp, 29, 15) 279 + | BIT_VAL(plane->crtc_w * bpp, 14, 0); 294 280 writel(val, ctx->addr + DECON_VIDW0xADD2(win)); 295 281 296 282 decon_win_set_pixfmt(ctx, win, state->fb); ··· 336 314 337 315 decon_shadow_protect_win(ctx, plane->zpos, false); 338 316 339 - if (ctx->i80_if) 317 + if (ctx->out_type == IFTYPE_I80) 340 318 set_bit(BIT_WIN_UPDATED, &ctx->flags); 341 319 } 342 320 ··· 361 339 } 362 340 363 341 WARN(tries == 0, "failed to software reset DECON\n"); 342 + 343 + if (ctx->out_type != IFTYPE_HDMI) 344 + return; 345 + 346 + writel(VIDCON0_CLKVALUP | VIDCON0_VLCKFREE, ctx->addr + DECON_VIDCON0); 347 + decon_set_bits(ctx, DECON_CMU, 348 + CMU_CLKGAGE_MODE_SFR_F | CMU_CLKGAGE_MODE_MEM_F, ~0); 349 + writel(VIDCON1_VCLK_RUN_VDEN_DISABLE, ctx->addr + DECON_VIDCON1); 350 + writel(CRCCTRL_CRCEN | CRCCTRL_CRCSTART_F | CRCCTRL_CRCCLKEN, 351 + ctx->addr + DECON_CRCCTRL); 352 + decon_setup_trigger(ctx); 364 353 } 365 354 366 355 static void decon_enable(struct exynos_drm_crtc *crtc) ··· 420 387 * suspend that connector. Otherwise we might try to scan from 421 388 * a destroyed buffer later. 422 389 */ 423 - for (i = 0; i < WINDOWS_NR; i++) 390 + for (i = ctx->first_win; i < WINDOWS_NR; i++) 424 391 decon_disable_plane(crtc, &ctx->planes[i]); 425 392 426 393 decon_swreset(ctx); ··· 494 461 struct drm_device *drm_dev = data; 495 462 struct exynos_drm_private *priv = drm_dev->dev_private; 496 463 struct exynos_drm_plane *exynos_plane; 464 + enum exynos_drm_output_type out_type; 497 465 enum drm_plane_type type; 498 - unsigned int zpos; 466 + unsigned int win; 499 467 int ret; 500 468 501 469 ctx->drm_dev = drm_dev; 502 470 ctx->pipe = priv->pipe++; 503 471 504 - for (zpos = 0; zpos < WINDOWS_NR; zpos++) { 505 - type = exynos_plane_get_type(zpos, CURSOR_WIN); 506 - ret = exynos_plane_init(drm_dev, &ctx->planes[zpos], 472 + for (win = ctx->first_win; win < WINDOWS_NR; win++) { 473 + int tmp = (win == ctx->first_win) ? 0 : win; 474 + 475 + type = exynos_plane_get_type(tmp, CURSOR_WIN); 476 + ret = exynos_plane_init(drm_dev, &ctx->planes[win], 507 477 1 << ctx->pipe, type, decon_formats, 508 - ARRAY_SIZE(decon_formats), zpos); 478 + ARRAY_SIZE(decon_formats), win); 509 479 if (ret) 510 480 return ret; 511 481 } 512 482 513 - exynos_plane = &ctx->planes[DEFAULT_WIN]; 483 + exynos_plane = &ctx->planes[ctx->first_win]; 484 + out_type = (ctx->out_type == IFTYPE_HDMI) ? EXYNOS_DISPLAY_TYPE_HDMI 485 + : EXYNOS_DISPLAY_TYPE_LCD; 514 486 ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base, 515 - ctx->pipe, EXYNOS_DISPLAY_TYPE_LCD, 487 + ctx->pipe, out_type, 516 488 &decon_crtc_ops, ctx); 517 489 if (IS_ERR(ctx->crtc)) { 518 490 ret = PTR_ERR(ctx->crtc); ··· 551 513 .unbind = decon_unbind, 552 514 }; 553 515 554 - static irqreturn_t decon_vsync_irq_handler(int irq, void *dev_id) 555 - { 556 - struct decon_context *ctx = dev_id; 557 - u32 val; 558 - 559 - if (!test_bit(BIT_CLKS_ENABLED, &ctx->flags)) 560 - goto out; 561 - 562 - val = readl(ctx->addr + DECON_VIDINTCON1); 563 - if (val & VIDINTCON1_INTFRMPEND) { 564 - drm_crtc_handle_vblank(&ctx->crtc->base); 565 - 566 - /* clear */ 567 - writel(VIDINTCON1_INTFRMPEND, ctx->addr + DECON_VIDINTCON1); 568 - } 569 - 570 - out: 571 - return IRQ_HANDLED; 572 - } 573 - 574 - static irqreturn_t decon_lcd_sys_irq_handler(int irq, void *dev_id) 516 + static irqreturn_t decon_irq_handler(int irq, void *dev_id) 575 517 { 576 518 struct decon_context *ctx = dev_id; 577 519 u32 val; ··· 561 543 goto out; 562 544 563 545 val = readl(ctx->addr + DECON_VIDINTCON1); 564 - if (val & VIDINTCON1_INTFRMDONEPEND) { 565 - for (win = 0 ; win < WINDOWS_NR ; win++) { 546 + val &= VIDINTCON1_INTFRMDONEPEND | VIDINTCON1_INTFRMPEND; 547 + 548 + if (val) { 549 + for (win = ctx->first_win; win < WINDOWS_NR ; win++) { 566 550 struct exynos_drm_plane *plane = &ctx->planes[win]; 567 551 568 552 if (!plane->pending_fb) ··· 574 554 } 575 555 576 556 /* clear */ 577 - writel(VIDINTCON1_INTFRMDONEPEND, 578 - ctx->addr + DECON_VIDINTCON1); 557 + writel(val, ctx->addr + DECON_VIDINTCON1); 579 558 } 580 559 581 560 out: 582 561 return IRQ_HANDLED; 583 562 } 584 563 564 + static const struct of_device_id exynos5433_decon_driver_dt_match[] = { 565 + { 566 + .compatible = "samsung,exynos5433-decon", 567 + .data = (void *)IFTYPE_RGB 568 + }, 569 + { 570 + .compatible = "samsung,exynos5433-decon-tv", 571 + .data = (void *)IFTYPE_HDMI 572 + }, 573 + {}, 574 + }; 575 + MODULE_DEVICE_TABLE(of, exynos5433_decon_driver_dt_match); 576 + 585 577 static int exynos5433_decon_probe(struct platform_device *pdev) 586 578 { 579 + const struct of_device_id *of_id; 587 580 struct device *dev = &pdev->dev; 588 581 struct decon_context *ctx; 589 582 struct resource *res; ··· 609 576 610 577 __set_bit(BIT_SUSPENDED, &ctx->flags); 611 578 ctx->dev = dev; 612 - if (of_get_child_by_name(dev->of_node, "i80-if-timings")) 613 - ctx->i80_if = true; 579 + 580 + of_id = of_match_device(exynos5433_decon_driver_dt_match, &pdev->dev); 581 + ctx->out_type = (enum decon_iftype)of_id->data; 582 + 583 + if (ctx->out_type == IFTYPE_HDMI) 584 + ctx->first_win = 1; 585 + else if (of_get_child_by_name(dev->of_node, "i80-if-timings")) 586 + ctx->out_type = IFTYPE_I80; 614 587 615 588 for (i = 0; i < ARRAY_SIZE(decon_clks_name); i++) { 616 589 struct clk *clk; ··· 641 602 } 642 603 643 604 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, 644 - ctx->i80_if ? "lcd_sys" : "vsync"); 605 + (ctx->out_type == IFTYPE_I80) ? "lcd_sys" : "vsync"); 645 606 if (!res) { 646 607 dev_err(dev, "cannot find IRQ resource\n"); 647 608 return -ENXIO; 648 609 } 649 610 650 - ret = devm_request_irq(dev, res->start, ctx->i80_if ? 651 - decon_lcd_sys_irq_handler : decon_vsync_irq_handler, 0, 652 - "drm_decon", ctx); 611 + ret = devm_request_irq(dev, res->start, decon_irq_handler, 0, 612 + "drm_decon", ctx); 653 613 if (ret < 0) { 654 614 dev_err(dev, "lcd_sys irq request failed\n"); 655 615 return ret; ··· 678 640 679 641 return 0; 680 642 } 681 - 682 - static const struct of_device_id exynos5433_decon_driver_dt_match[] = { 683 - { .compatible = "samsung,exynos5433-decon" }, 684 - {}, 685 - }; 686 - MODULE_DEVICE_TABLE(of, exynos5433_decon_driver_dt_match); 687 643 688 644 struct platform_driver exynos5433_decon_driver = { 689 645 .probe = exynos5433_decon_probe,
+29
include/video/exynos5433_decon.h
··· 82 82 83 83 /* VIDCON0 */ 84 84 #define VIDCON0_SWRESET (1 << 28) 85 + #define VIDCON0_CLKVALUP (1 << 14) 86 + #define VIDCON0_VLCKFREE (1 << 5) 85 87 #define VIDCON0_STOP_STATUS (1 << 2) 86 88 #define VIDCON0_ENVID (1 << 1) 87 89 #define VIDCON0_ENVID_F (1 << 0) ··· 139 137 /* DECON_UPDATE */ 140 138 #define STANDALONE_UPDATE_F (1 << 0) 141 139 140 + /* DECON_VIDCON1 */ 141 + #define VIDCON1_VCLK_MASK (0x3 << 9) 142 + #define VIDCON1_VCLK_RUN_VDEN_DISABLE (0x3 << 9) 143 + #define VIDCON1_VCLK_HOLD (0x0 << 9) 144 + #define VIDCON1_VCLK_RUN (0x1 << 9) 145 + 146 + 142 147 /* DECON_VIDTCON00 */ 143 148 #define VIDTCON00_VBPD_F(x) (((x) & 0xfff) << 16) 144 149 #define VIDTCON00_VFPD_F(x) ((x) & 0xfff) ··· 168 159 #define TRIGCON_TRIGEN_PER_F (1 << 31) 169 160 #define TRIGCON_TRIGEN_F (1 << 30) 170 161 #define TRIGCON_TE_AUTO_MASK (1 << 29) 162 + #define TRIGCON_WB_SWTRIGCMD (1 << 28) 163 + #define TRIGCON_SWTRIGCMD_W4BUF (1 << 26) 164 + #define TRIGCON_TRIGMODE_W4BUF (1 << 25) 165 + #define TRIGCON_SWTRIGCMD_W3BUF (1 << 21) 166 + #define TRIGCON_TRIGMODE_W3BUF (1 << 20) 167 + #define TRIGCON_SWTRIGCMD_W2BUF (1 << 16) 168 + #define TRIGCON_TRIGMODE_W2BUF (1 << 15) 169 + #define TRIGCON_SWTRIGCMD_W1BUF (1 << 11) 170 + #define TRIGCON_TRIGMODE_W1BUF (1 << 10) 171 + #define TRIGCON_SWTRIGCMD_W0BUF (1 << 6) 172 + #define TRIGCON_TRIGMODE_W0BUF (1 << 5) 173 + #define TRIGCON_HWTRIGMASK_I80_RGB (1 << 4) 174 + #define TRIGCON_HWTRIGEN_I80_RGB (1 << 3) 175 + #define TRIGCON_HWTRIG_INV_I80_RGB (1 << 2) 171 176 #define TRIGCON_SWTRIGCMD (1 << 1) 172 177 #define TRIGCON_SWTRIGEN (1 << 0) 178 + 179 + /* DECON_CRCCTRL */ 180 + #define CRCCTRL_CRCCLKEN (0x1 << 2) 181 + #define CRCCTRL_CRCSTART_F (0x1 << 1) 182 + #define CRCCTRL_CRCEN (0x1 << 0) 183 + #define CRCCTRL_MASK (0x7) 173 184 174 185 #endif /* EXYNOS_REGS_DECON_H */