1dee8268fSThierry Reding /* 2dee8268fSThierry Reding * Copyright (C) 2012 Avionic Design GmbH 3dee8268fSThierry Reding * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved. 4dee8268fSThierry Reding * 5dee8268fSThierry Reding * This program is free software; you can redistribute it and/or modify 6dee8268fSThierry Reding * it under the terms of the GNU General Public License version 2 as 7dee8268fSThierry Reding * published by the Free Software Foundation. 8dee8268fSThierry Reding */ 9dee8268fSThierry Reding 10dee8268fSThierry Reding #include <linux/clk.h> 11dee8268fSThierry Reding #include <linux/debugfs.h> 12df06b759SThierry Reding #include <linux/iommu.h> 13b9ff7aeaSThierry Reding #include <linux/of_device.h> 1433a8eb8dSThierry Reding #include <linux/pm_runtime.h> 15ca48080aSStephen Warren #include <linux/reset.h> 16dee8268fSThierry Reding 179c012700SThierry Reding #include <soc/tegra/pmc.h> 189c012700SThierry Reding 19dee8268fSThierry Reding #include "dc.h" 20dee8268fSThierry Reding #include "drm.h" 21dee8268fSThierry Reding #include "gem.h" 22dee8268fSThierry Reding 239d44189fSThierry Reding #include <drm/drm_atomic.h> 244aa3df71SThierry Reding #include <drm/drm_atomic_helper.h> 253cb9ae4fSDaniel Vetter #include <drm/drm_plane_helper.h> 263cb9ae4fSDaniel Vetter 27dee8268fSThierry Reding struct tegra_plane { 28dee8268fSThierry Reding struct drm_plane base; 29dee8268fSThierry Reding unsigned int index; 30dee8268fSThierry Reding }; 31dee8268fSThierry Reding 32dee8268fSThierry Reding static inline struct tegra_plane *to_tegra_plane(struct drm_plane *plane) 33dee8268fSThierry Reding { 34dee8268fSThierry Reding return container_of(plane, struct tegra_plane, base); 35dee8268fSThierry Reding } 36dee8268fSThierry Reding 37ca915b10SThierry Reding struct tegra_dc_state { 38ca915b10SThierry Reding struct drm_crtc_state base; 39ca915b10SThierry Reding 40ca915b10SThierry Reding struct clk *clk; 41ca915b10SThierry Reding unsigned long pclk; 42ca915b10SThierry Reding unsigned int div; 4347802b09SThierry Reding 4447802b09SThierry Reding u32 planes; 45ca915b10SThierry Reding }; 46ca915b10SThierry Reding 47ca915b10SThierry Reding static inline struct tegra_dc_state *to_dc_state(struct drm_crtc_state *state) 48ca915b10SThierry Reding { 49ca915b10SThierry Reding if (state) 50ca915b10SThierry Reding return container_of(state, struct tegra_dc_state, base); 51ca915b10SThierry Reding 52ca915b10SThierry Reding return NULL; 53ca915b10SThierry Reding } 54ca915b10SThierry Reding 558f604f8cSThierry Reding struct tegra_plane_state { 568f604f8cSThierry Reding struct drm_plane_state base; 578f604f8cSThierry Reding 588f604f8cSThierry Reding struct tegra_bo_tiling tiling; 598f604f8cSThierry Reding u32 format; 608f604f8cSThierry Reding u32 swap; 618f604f8cSThierry Reding }; 628f604f8cSThierry Reding 638f604f8cSThierry Reding static inline struct tegra_plane_state * 648f604f8cSThierry Reding to_tegra_plane_state(struct drm_plane_state *state) 658f604f8cSThierry Reding { 668f604f8cSThierry Reding if (state) 678f604f8cSThierry Reding return container_of(state, struct tegra_plane_state, base); 688f604f8cSThierry Reding 698f604f8cSThierry Reding return NULL; 708f604f8cSThierry Reding } 718f604f8cSThierry Reding 72791ddb1eSThierry Reding static void tegra_dc_stats_reset(struct tegra_dc_stats *stats) 73791ddb1eSThierry Reding { 74791ddb1eSThierry Reding stats->frames = 0; 75791ddb1eSThierry Reding stats->vblank = 0; 76791ddb1eSThierry Reding stats->underflow = 0; 77791ddb1eSThierry Reding stats->overflow = 0; 78791ddb1eSThierry Reding } 79791ddb1eSThierry Reding 80d700ba7aSThierry Reding /* 8186df256fSThierry Reding * Reads the active copy of a register. This takes the dc->lock spinlock to 8286df256fSThierry Reding * prevent races with the VBLANK processing which also needs access to the 8386df256fSThierry Reding * active copy of some registers. 8486df256fSThierry Reding */ 8586df256fSThierry Reding static u32 tegra_dc_readl_active(struct tegra_dc *dc, unsigned long offset) 8686df256fSThierry Reding { 8786df256fSThierry Reding unsigned long flags; 8886df256fSThierry Reding u32 value; 8986df256fSThierry Reding 9086df256fSThierry Reding spin_lock_irqsave(&dc->lock, flags); 9186df256fSThierry Reding 9286df256fSThierry Reding tegra_dc_writel(dc, READ_MUX, DC_CMD_STATE_ACCESS); 9386df256fSThierry Reding value = tegra_dc_readl(dc, offset); 9486df256fSThierry Reding tegra_dc_writel(dc, 0, DC_CMD_STATE_ACCESS); 9586df256fSThierry Reding 9686df256fSThierry Reding spin_unlock_irqrestore(&dc->lock, flags); 9786df256fSThierry Reding return value; 9886df256fSThierry Reding } 9986df256fSThierry Reding 10086df256fSThierry Reding /* 101d700ba7aSThierry Reding * Double-buffered registers have two copies: ASSEMBLY and ACTIVE. When the 102d700ba7aSThierry Reding * *_ACT_REQ bits are set the ASSEMBLY copy is latched into the ACTIVE copy. 103d700ba7aSThierry Reding * Latching happens mmediately if the display controller is in STOP mode or 104d700ba7aSThierry Reding * on the next frame boundary otherwise. 105d700ba7aSThierry Reding * 106d700ba7aSThierry Reding * Triple-buffered registers have three copies: ASSEMBLY, ARM and ACTIVE. The 107d700ba7aSThierry Reding * ASSEMBLY copy is latched into the ARM copy immediately after *_UPDATE bits 108d700ba7aSThierry Reding * are written. When the *_ACT_REQ bits are written, the ARM copy is latched 109d700ba7aSThierry Reding * into the ACTIVE copy, either immediately if the display controller is in 110d700ba7aSThierry Reding * STOP mode, or at the next frame boundary otherwise. 111d700ba7aSThierry Reding */ 11262b9e063SThierry Reding void tegra_dc_commit(struct tegra_dc *dc) 113205d48edSThierry Reding { 114205d48edSThierry Reding tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL); 115205d48edSThierry Reding tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL); 116205d48edSThierry Reding } 117205d48edSThierry Reding 1188f604f8cSThierry Reding static int tegra_dc_format(u32 fourcc, u32 *format, u32 *swap) 11910288eeaSThierry Reding { 12010288eeaSThierry Reding /* assume no swapping of fetched data */ 12110288eeaSThierry Reding if (swap) 12210288eeaSThierry Reding *swap = BYTE_SWAP_NOSWAP; 12310288eeaSThierry Reding 1248f604f8cSThierry Reding switch (fourcc) { 12510288eeaSThierry Reding case DRM_FORMAT_XBGR8888: 1268f604f8cSThierry Reding *format = WIN_COLOR_DEPTH_R8G8B8A8; 1278f604f8cSThierry Reding break; 12810288eeaSThierry Reding 12910288eeaSThierry Reding case DRM_FORMAT_XRGB8888: 1308f604f8cSThierry Reding *format = WIN_COLOR_DEPTH_B8G8R8A8; 1318f604f8cSThierry Reding break; 13210288eeaSThierry Reding 13310288eeaSThierry Reding case DRM_FORMAT_RGB565: 1348f604f8cSThierry Reding *format = WIN_COLOR_DEPTH_B5G6R5; 1358f604f8cSThierry Reding break; 13610288eeaSThierry Reding 13710288eeaSThierry Reding case DRM_FORMAT_UYVY: 1388f604f8cSThierry Reding *format = WIN_COLOR_DEPTH_YCbCr422; 1398f604f8cSThierry Reding break; 14010288eeaSThierry Reding 14110288eeaSThierry Reding case DRM_FORMAT_YUYV: 14210288eeaSThierry Reding if (swap) 14310288eeaSThierry Reding *swap = BYTE_SWAP_SWAP2; 14410288eeaSThierry Reding 1458f604f8cSThierry Reding *format = WIN_COLOR_DEPTH_YCbCr422; 1468f604f8cSThierry Reding break; 14710288eeaSThierry Reding 14810288eeaSThierry Reding case DRM_FORMAT_YUV420: 1498f604f8cSThierry Reding *format = WIN_COLOR_DEPTH_YCbCr420P; 1508f604f8cSThierry Reding break; 15110288eeaSThierry Reding 15210288eeaSThierry Reding case DRM_FORMAT_YUV422: 1538f604f8cSThierry Reding *format = WIN_COLOR_DEPTH_YCbCr422P; 1548f604f8cSThierry Reding break; 15510288eeaSThierry Reding 15610288eeaSThierry Reding default: 1578f604f8cSThierry Reding return -EINVAL; 15810288eeaSThierry Reding } 15910288eeaSThierry Reding 1608f604f8cSThierry Reding return 0; 16110288eeaSThierry Reding } 16210288eeaSThierry Reding 16310288eeaSThierry Reding static bool tegra_dc_format_is_yuv(unsigned int format, bool *planar) 16410288eeaSThierry Reding { 16510288eeaSThierry Reding switch (format) { 16610288eeaSThierry Reding case WIN_COLOR_DEPTH_YCbCr422: 16710288eeaSThierry Reding case WIN_COLOR_DEPTH_YUV422: 16810288eeaSThierry Reding if (planar) 16910288eeaSThierry Reding *planar = false; 17010288eeaSThierry Reding 17110288eeaSThierry Reding return true; 17210288eeaSThierry Reding 17310288eeaSThierry Reding case WIN_COLOR_DEPTH_YCbCr420P: 17410288eeaSThierry Reding case WIN_COLOR_DEPTH_YUV420P: 17510288eeaSThierry Reding case WIN_COLOR_DEPTH_YCbCr422P: 17610288eeaSThierry Reding case WIN_COLOR_DEPTH_YUV422P: 17710288eeaSThierry Reding case WIN_COLOR_DEPTH_YCbCr422R: 17810288eeaSThierry Reding case WIN_COLOR_DEPTH_YUV422R: 17910288eeaSThierry Reding case WIN_COLOR_DEPTH_YCbCr422RA: 18010288eeaSThierry Reding case WIN_COLOR_DEPTH_YUV422RA: 18110288eeaSThierry Reding if (planar) 18210288eeaSThierry Reding *planar = true; 18310288eeaSThierry Reding 18410288eeaSThierry Reding return true; 18510288eeaSThierry Reding } 18610288eeaSThierry Reding 187fb35c6b6SThierry Reding if (planar) 188fb35c6b6SThierry Reding *planar = false; 189fb35c6b6SThierry Reding 19010288eeaSThierry Reding return false; 19110288eeaSThierry Reding } 19210288eeaSThierry Reding 19310288eeaSThierry Reding static inline u32 compute_dda_inc(unsigned int in, unsigned int out, bool v, 19410288eeaSThierry Reding unsigned int bpp) 19510288eeaSThierry Reding { 19610288eeaSThierry Reding fixed20_12 outf = dfixed_init(out); 19710288eeaSThierry Reding fixed20_12 inf = dfixed_init(in); 19810288eeaSThierry Reding u32 dda_inc; 19910288eeaSThierry Reding int max; 20010288eeaSThierry Reding 20110288eeaSThierry Reding if (v) 20210288eeaSThierry Reding max = 15; 20310288eeaSThierry Reding else { 20410288eeaSThierry Reding switch (bpp) { 20510288eeaSThierry Reding case 2: 20610288eeaSThierry Reding max = 8; 20710288eeaSThierry Reding break; 20810288eeaSThierry Reding 20910288eeaSThierry Reding default: 21010288eeaSThierry Reding WARN_ON_ONCE(1); 21110288eeaSThierry Reding /* fallthrough */ 21210288eeaSThierry Reding case 4: 21310288eeaSThierry Reding max = 4; 21410288eeaSThierry Reding break; 21510288eeaSThierry Reding } 21610288eeaSThierry Reding } 21710288eeaSThierry Reding 21810288eeaSThierry Reding outf.full = max_t(u32, outf.full - dfixed_const(1), dfixed_const(1)); 21910288eeaSThierry Reding inf.full -= dfixed_const(1); 22010288eeaSThierry Reding 22110288eeaSThierry Reding dda_inc = dfixed_div(inf, outf); 22210288eeaSThierry Reding dda_inc = min_t(u32, dda_inc, dfixed_const(max)); 22310288eeaSThierry Reding 22410288eeaSThierry Reding return dda_inc; 22510288eeaSThierry Reding } 22610288eeaSThierry Reding 22710288eeaSThierry Reding static inline u32 compute_initial_dda(unsigned int in) 22810288eeaSThierry Reding { 22910288eeaSThierry Reding fixed20_12 inf = dfixed_init(in); 23010288eeaSThierry Reding return dfixed_frac(inf); 23110288eeaSThierry Reding } 23210288eeaSThierry Reding 2334aa3df71SThierry Reding static void tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index, 23410288eeaSThierry Reding const struct tegra_dc_window *window) 23510288eeaSThierry Reding { 23610288eeaSThierry Reding unsigned h_offset, v_offset, h_size, v_size, h_dda, v_dda, bpp; 23793396d0fSSean Paul unsigned long value, flags; 23810288eeaSThierry Reding bool yuv, planar; 23910288eeaSThierry Reding 24010288eeaSThierry Reding /* 24110288eeaSThierry Reding * For YUV planar modes, the number of bytes per pixel takes into 24210288eeaSThierry Reding * account only the luma component and therefore is 1. 24310288eeaSThierry Reding */ 24410288eeaSThierry Reding yuv = tegra_dc_format_is_yuv(window->format, &planar); 24510288eeaSThierry Reding if (!yuv) 24610288eeaSThierry Reding bpp = window->bits_per_pixel / 8; 24710288eeaSThierry Reding else 24810288eeaSThierry Reding bpp = planar ? 1 : 2; 24910288eeaSThierry Reding 25093396d0fSSean Paul spin_lock_irqsave(&dc->lock, flags); 25193396d0fSSean Paul 25210288eeaSThierry Reding value = WINDOW_A_SELECT << index; 25310288eeaSThierry Reding tegra_dc_writel(dc, value, DC_CMD_DISPLAY_WINDOW_HEADER); 25410288eeaSThierry Reding 25510288eeaSThierry Reding tegra_dc_writel(dc, window->format, DC_WIN_COLOR_DEPTH); 25610288eeaSThierry Reding tegra_dc_writel(dc, window->swap, DC_WIN_BYTE_SWAP); 25710288eeaSThierry Reding 25810288eeaSThierry Reding value = V_POSITION(window->dst.y) | H_POSITION(window->dst.x); 25910288eeaSThierry Reding tegra_dc_writel(dc, value, DC_WIN_POSITION); 26010288eeaSThierry Reding 26110288eeaSThierry Reding value = V_SIZE(window->dst.h) | H_SIZE(window->dst.w); 26210288eeaSThierry Reding tegra_dc_writel(dc, value, DC_WIN_SIZE); 26310288eeaSThierry Reding 26410288eeaSThierry Reding h_offset = window->src.x * bpp; 26510288eeaSThierry Reding v_offset = window->src.y; 26610288eeaSThierry Reding h_size = window->src.w * bpp; 26710288eeaSThierry Reding v_size = window->src.h; 26810288eeaSThierry Reding 26910288eeaSThierry Reding value = V_PRESCALED_SIZE(v_size) | H_PRESCALED_SIZE(h_size); 27010288eeaSThierry Reding tegra_dc_writel(dc, value, DC_WIN_PRESCALED_SIZE); 27110288eeaSThierry Reding 27210288eeaSThierry Reding /* 27310288eeaSThierry Reding * For DDA computations the number of bytes per pixel for YUV planar 27410288eeaSThierry Reding * modes needs to take into account all Y, U and V components. 27510288eeaSThierry Reding */ 27610288eeaSThierry Reding if (yuv && planar) 27710288eeaSThierry Reding bpp = 2; 27810288eeaSThierry Reding 27910288eeaSThierry Reding h_dda = compute_dda_inc(window->src.w, window->dst.w, false, bpp); 28010288eeaSThierry Reding v_dda = compute_dda_inc(window->src.h, window->dst.h, true, bpp); 28110288eeaSThierry Reding 28210288eeaSThierry Reding value = V_DDA_INC(v_dda) | H_DDA_INC(h_dda); 28310288eeaSThierry Reding tegra_dc_writel(dc, value, DC_WIN_DDA_INC); 28410288eeaSThierry Reding 28510288eeaSThierry Reding h_dda = compute_initial_dda(window->src.x); 28610288eeaSThierry Reding v_dda = compute_initial_dda(window->src.y); 28710288eeaSThierry Reding 28810288eeaSThierry Reding tegra_dc_writel(dc, h_dda, DC_WIN_H_INITIAL_DDA); 28910288eeaSThierry Reding tegra_dc_writel(dc, v_dda, DC_WIN_V_INITIAL_DDA); 29010288eeaSThierry Reding 29110288eeaSThierry Reding tegra_dc_writel(dc, 0, DC_WIN_UV_BUF_STRIDE); 29210288eeaSThierry Reding tegra_dc_writel(dc, 0, DC_WIN_BUF_STRIDE); 29310288eeaSThierry Reding 29410288eeaSThierry Reding tegra_dc_writel(dc, window->base[0], DC_WINBUF_START_ADDR); 29510288eeaSThierry Reding 29610288eeaSThierry Reding if (yuv && planar) { 29710288eeaSThierry Reding tegra_dc_writel(dc, window->base[1], DC_WINBUF_START_ADDR_U); 29810288eeaSThierry Reding tegra_dc_writel(dc, window->base[2], DC_WINBUF_START_ADDR_V); 29910288eeaSThierry Reding value = window->stride[1] << 16 | window->stride[0]; 30010288eeaSThierry Reding tegra_dc_writel(dc, value, DC_WIN_LINE_STRIDE); 30110288eeaSThierry Reding } else { 30210288eeaSThierry Reding tegra_dc_writel(dc, window->stride[0], DC_WIN_LINE_STRIDE); 30310288eeaSThierry Reding } 30410288eeaSThierry Reding 30510288eeaSThierry Reding if (window->bottom_up) 30610288eeaSThierry Reding v_offset += window->src.h - 1; 30710288eeaSThierry Reding 30810288eeaSThierry Reding tegra_dc_writel(dc, h_offset, DC_WINBUF_ADDR_H_OFFSET); 30910288eeaSThierry Reding tegra_dc_writel(dc, v_offset, DC_WINBUF_ADDR_V_OFFSET); 31010288eeaSThierry Reding 311c134f019SThierry Reding if (dc->soc->supports_block_linear) { 312c134f019SThierry Reding unsigned long height = window->tiling.value; 313c134f019SThierry Reding 314c134f019SThierry Reding switch (window->tiling.mode) { 315c134f019SThierry Reding case TEGRA_BO_TILING_MODE_PITCH: 316c134f019SThierry Reding value = DC_WINBUF_SURFACE_KIND_PITCH; 317c134f019SThierry Reding break; 318c134f019SThierry Reding 319c134f019SThierry Reding case TEGRA_BO_TILING_MODE_TILED: 320c134f019SThierry Reding value = DC_WINBUF_SURFACE_KIND_TILED; 321c134f019SThierry Reding break; 322c134f019SThierry Reding 323c134f019SThierry Reding case TEGRA_BO_TILING_MODE_BLOCK: 324c134f019SThierry Reding value = DC_WINBUF_SURFACE_KIND_BLOCK_HEIGHT(height) | 325c134f019SThierry Reding DC_WINBUF_SURFACE_KIND_BLOCK; 326c134f019SThierry Reding break; 327c134f019SThierry Reding } 328c134f019SThierry Reding 329c134f019SThierry Reding tegra_dc_writel(dc, value, DC_WINBUF_SURFACE_KIND); 33010288eeaSThierry Reding } else { 331c134f019SThierry Reding switch (window->tiling.mode) { 332c134f019SThierry Reding case TEGRA_BO_TILING_MODE_PITCH: 33310288eeaSThierry Reding value = DC_WIN_BUFFER_ADDR_MODE_LINEAR_UV | 33410288eeaSThierry Reding DC_WIN_BUFFER_ADDR_MODE_LINEAR; 335c134f019SThierry Reding break; 336c134f019SThierry Reding 337c134f019SThierry Reding case TEGRA_BO_TILING_MODE_TILED: 338c134f019SThierry Reding value = DC_WIN_BUFFER_ADDR_MODE_TILE_UV | 339c134f019SThierry Reding DC_WIN_BUFFER_ADDR_MODE_TILE; 340c134f019SThierry Reding break; 341c134f019SThierry Reding 342c134f019SThierry Reding case TEGRA_BO_TILING_MODE_BLOCK: 3434aa3df71SThierry Reding /* 3444aa3df71SThierry Reding * No need to handle this here because ->atomic_check 3454aa3df71SThierry Reding * will already have filtered it out. 3464aa3df71SThierry Reding */ 3474aa3df71SThierry Reding break; 34810288eeaSThierry Reding } 34910288eeaSThierry Reding 35010288eeaSThierry Reding tegra_dc_writel(dc, value, DC_WIN_BUFFER_ADDR_MODE); 351c134f019SThierry Reding } 35210288eeaSThierry Reding 35310288eeaSThierry Reding value = WIN_ENABLE; 35410288eeaSThierry Reding 35510288eeaSThierry Reding if (yuv) { 35610288eeaSThierry Reding /* setup default colorspace conversion coefficients */ 35710288eeaSThierry Reding tegra_dc_writel(dc, 0x00f0, DC_WIN_CSC_YOF); 35810288eeaSThierry Reding tegra_dc_writel(dc, 0x012a, DC_WIN_CSC_KYRGB); 35910288eeaSThierry Reding tegra_dc_writel(dc, 0x0000, DC_WIN_CSC_KUR); 36010288eeaSThierry Reding tegra_dc_writel(dc, 0x0198, DC_WIN_CSC_KVR); 36110288eeaSThierry Reding tegra_dc_writel(dc, 0x039b, DC_WIN_CSC_KUG); 36210288eeaSThierry Reding tegra_dc_writel(dc, 0x032f, DC_WIN_CSC_KVG); 36310288eeaSThierry Reding tegra_dc_writel(dc, 0x0204, DC_WIN_CSC_KUB); 36410288eeaSThierry Reding tegra_dc_writel(dc, 0x0000, DC_WIN_CSC_KVB); 36510288eeaSThierry Reding 36610288eeaSThierry Reding value |= CSC_ENABLE; 36710288eeaSThierry Reding } else if (window->bits_per_pixel < 24) { 36810288eeaSThierry Reding value |= COLOR_EXPAND; 36910288eeaSThierry Reding } 37010288eeaSThierry Reding 37110288eeaSThierry Reding if (window->bottom_up) 37210288eeaSThierry Reding value |= V_DIRECTION; 37310288eeaSThierry Reding 37410288eeaSThierry Reding tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS); 37510288eeaSThierry Reding 37610288eeaSThierry Reding /* 37710288eeaSThierry Reding * Disable blending and assume Window A is the bottom-most window, 37810288eeaSThierry Reding * Window C is the top-most window and Window B is in the middle. 37910288eeaSThierry Reding */ 38010288eeaSThierry Reding tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_NOKEY); 38110288eeaSThierry Reding tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_1WIN); 38210288eeaSThierry Reding 38310288eeaSThierry Reding switch (index) { 38410288eeaSThierry Reding case 0: 38510288eeaSThierry Reding tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_X); 38610288eeaSThierry Reding tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_Y); 38710288eeaSThierry Reding tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_3WIN_XY); 38810288eeaSThierry Reding break; 38910288eeaSThierry Reding 39010288eeaSThierry Reding case 1: 39110288eeaSThierry Reding tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_X); 39210288eeaSThierry Reding tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_Y); 39310288eeaSThierry Reding tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_3WIN_XY); 39410288eeaSThierry Reding break; 39510288eeaSThierry Reding 39610288eeaSThierry Reding case 2: 39710288eeaSThierry Reding tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_X); 39810288eeaSThierry Reding tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_Y); 39910288eeaSThierry Reding tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_3WIN_XY); 40010288eeaSThierry Reding break; 40110288eeaSThierry Reding } 40210288eeaSThierry Reding 40393396d0fSSean Paul spin_unlock_irqrestore(&dc->lock, flags); 404c7679306SThierry Reding } 405c7679306SThierry Reding 406c7679306SThierry Reding static void tegra_plane_destroy(struct drm_plane *plane) 407c7679306SThierry Reding { 408c7679306SThierry Reding struct tegra_plane *p = to_tegra_plane(plane); 409c7679306SThierry Reding 410c7679306SThierry Reding drm_plane_cleanup(plane); 411c7679306SThierry Reding kfree(p); 412c7679306SThierry Reding } 413c7679306SThierry Reding 414c7679306SThierry Reding static const u32 tegra_primary_plane_formats[] = { 415c7679306SThierry Reding DRM_FORMAT_XBGR8888, 416c7679306SThierry Reding DRM_FORMAT_XRGB8888, 417c7679306SThierry Reding DRM_FORMAT_RGB565, 418c7679306SThierry Reding }; 419c7679306SThierry Reding 4204aa3df71SThierry Reding static void tegra_primary_plane_destroy(struct drm_plane *plane) 421c7679306SThierry Reding { 4224aa3df71SThierry Reding tegra_plane_destroy(plane); 4234aa3df71SThierry Reding } 4244aa3df71SThierry Reding 4258f604f8cSThierry Reding static void tegra_plane_reset(struct drm_plane *plane) 4268f604f8cSThierry Reding { 4278f604f8cSThierry Reding struct tegra_plane_state *state; 4288f604f8cSThierry Reding 4293b59b7acSThierry Reding if (plane->state) 4302f701695SDaniel Vetter __drm_atomic_helper_plane_destroy_state(plane->state); 4318f604f8cSThierry Reding 4328f604f8cSThierry Reding kfree(plane->state); 4338f604f8cSThierry Reding plane->state = NULL; 4348f604f8cSThierry Reding 4358f604f8cSThierry Reding state = kzalloc(sizeof(*state), GFP_KERNEL); 4368f604f8cSThierry Reding if (state) { 4378f604f8cSThierry Reding plane->state = &state->base; 4388f604f8cSThierry Reding plane->state->plane = plane; 4398f604f8cSThierry Reding } 4408f604f8cSThierry Reding } 4418f604f8cSThierry Reding 4428f604f8cSThierry Reding static struct drm_plane_state *tegra_plane_atomic_duplicate_state(struct drm_plane *plane) 4438f604f8cSThierry Reding { 4448f604f8cSThierry Reding struct tegra_plane_state *state = to_tegra_plane_state(plane->state); 4458f604f8cSThierry Reding struct tegra_plane_state *copy; 4468f604f8cSThierry Reding 4473b59b7acSThierry Reding copy = kmalloc(sizeof(*copy), GFP_KERNEL); 4488f604f8cSThierry Reding if (!copy) 4498f604f8cSThierry Reding return NULL; 4508f604f8cSThierry Reding 4513b59b7acSThierry Reding __drm_atomic_helper_plane_duplicate_state(plane, ©->base); 4523b59b7acSThierry Reding copy->tiling = state->tiling; 4533b59b7acSThierry Reding copy->format = state->format; 4543b59b7acSThierry Reding copy->swap = state->swap; 4558f604f8cSThierry Reding 4568f604f8cSThierry Reding return ©->base; 4578f604f8cSThierry Reding } 4588f604f8cSThierry Reding 4598f604f8cSThierry Reding static void tegra_plane_atomic_destroy_state(struct drm_plane *plane, 4608f604f8cSThierry Reding struct drm_plane_state *state) 4618f604f8cSThierry Reding { 4622f701695SDaniel Vetter __drm_atomic_helper_plane_destroy_state(state); 4638f604f8cSThierry Reding kfree(state); 4648f604f8cSThierry Reding } 4658f604f8cSThierry Reding 4664aa3df71SThierry Reding static const struct drm_plane_funcs tegra_primary_plane_funcs = { 46707866963SThierry Reding .update_plane = drm_atomic_helper_update_plane, 46807866963SThierry Reding .disable_plane = drm_atomic_helper_disable_plane, 4694aa3df71SThierry Reding .destroy = tegra_primary_plane_destroy, 4708f604f8cSThierry Reding .reset = tegra_plane_reset, 4718f604f8cSThierry Reding .atomic_duplicate_state = tegra_plane_atomic_duplicate_state, 4728f604f8cSThierry Reding .atomic_destroy_state = tegra_plane_atomic_destroy_state, 4734aa3df71SThierry Reding }; 4744aa3df71SThierry Reding 47547802b09SThierry Reding static int tegra_plane_state_add(struct tegra_plane *plane, 47647802b09SThierry Reding struct drm_plane_state *state) 47747802b09SThierry Reding { 47847802b09SThierry Reding struct drm_crtc_state *crtc_state; 47947802b09SThierry Reding struct tegra_dc_state *tegra; 4807d205857SDmitry Osipenko struct drm_rect clip; 4817d205857SDmitry Osipenko int err; 48247802b09SThierry Reding 48347802b09SThierry Reding /* Propagate errors from allocation or locking failures. */ 48447802b09SThierry Reding crtc_state = drm_atomic_get_crtc_state(state->state, state->crtc); 48547802b09SThierry Reding if (IS_ERR(crtc_state)) 48647802b09SThierry Reding return PTR_ERR(crtc_state); 48747802b09SThierry Reding 4887d205857SDmitry Osipenko clip.x1 = 0; 4897d205857SDmitry Osipenko clip.y1 = 0; 4907d205857SDmitry Osipenko clip.x2 = crtc_state->mode.hdisplay; 4917d205857SDmitry Osipenko clip.y2 = crtc_state->mode.vdisplay; 4927d205857SDmitry Osipenko 4937d205857SDmitry Osipenko /* Check plane state for visibility and calculate clipping bounds */ 4947d205857SDmitry Osipenko err = drm_plane_helper_check_state(state, &clip, 0, INT_MAX, 4957d205857SDmitry Osipenko true, true); 4967d205857SDmitry Osipenko if (err < 0) 4977d205857SDmitry Osipenko return err; 4987d205857SDmitry Osipenko 49947802b09SThierry Reding tegra = to_dc_state(crtc_state); 50047802b09SThierry Reding 50147802b09SThierry Reding tegra->planes |= WIN_A_ACT_REQ << plane->index; 50247802b09SThierry Reding 50347802b09SThierry Reding return 0; 50447802b09SThierry Reding } 50547802b09SThierry Reding 5064aa3df71SThierry Reding static int tegra_plane_atomic_check(struct drm_plane *plane, 5074aa3df71SThierry Reding struct drm_plane_state *state) 5084aa3df71SThierry Reding { 5098f604f8cSThierry Reding struct tegra_plane_state *plane_state = to_tegra_plane_state(state); 5108f604f8cSThierry Reding struct tegra_bo_tiling *tiling = &plane_state->tiling; 51147802b09SThierry Reding struct tegra_plane *tegra = to_tegra_plane(plane); 5124aa3df71SThierry Reding struct tegra_dc *dc = to_tegra_dc(state->crtc); 513c7679306SThierry Reding int err; 514c7679306SThierry Reding 5154aa3df71SThierry Reding /* no need for further checks if the plane is being disabled */ 5164aa3df71SThierry Reding if (!state->crtc) 5174aa3df71SThierry Reding return 0; 5184aa3df71SThierry Reding 519438b74a5SVille Syrjälä err = tegra_dc_format(state->fb->format->format, &plane_state->format, 5208f604f8cSThierry Reding &plane_state->swap); 5214aa3df71SThierry Reding if (err < 0) 5224aa3df71SThierry Reding return err; 5234aa3df71SThierry Reding 5248f604f8cSThierry Reding err = tegra_fb_get_tiling(state->fb, tiling); 5258f604f8cSThierry Reding if (err < 0) 5268f604f8cSThierry Reding return err; 5278f604f8cSThierry Reding 5288f604f8cSThierry Reding if (tiling->mode == TEGRA_BO_TILING_MODE_BLOCK && 5294aa3df71SThierry Reding !dc->soc->supports_block_linear) { 5304aa3df71SThierry Reding DRM_ERROR("hardware doesn't support block linear mode\n"); 5314aa3df71SThierry Reding return -EINVAL; 5324aa3df71SThierry Reding } 5334aa3df71SThierry Reding 5344aa3df71SThierry Reding /* 5354aa3df71SThierry Reding * Tegra doesn't support different strides for U and V planes so we 5364aa3df71SThierry Reding * error out if the user tries to display a framebuffer with such a 5374aa3df71SThierry Reding * configuration. 5384aa3df71SThierry Reding */ 539bcb0b461SVille Syrjälä if (state->fb->format->num_planes > 2) { 5404aa3df71SThierry Reding if (state->fb->pitches[2] != state->fb->pitches[1]) { 5414aa3df71SThierry Reding DRM_ERROR("unsupported UV-plane configuration\n"); 5424aa3df71SThierry Reding return -EINVAL; 5434aa3df71SThierry Reding } 5444aa3df71SThierry Reding } 5454aa3df71SThierry Reding 54647802b09SThierry Reding err = tegra_plane_state_add(tegra, state); 54747802b09SThierry Reding if (err < 0) 54847802b09SThierry Reding return err; 54947802b09SThierry Reding 5504aa3df71SThierry Reding return 0; 5514aa3df71SThierry Reding } 5524aa3df71SThierry Reding 553a4bfa096SThierry Reding static void tegra_plane_atomic_disable(struct drm_plane *plane, 554a4bfa096SThierry Reding struct drm_plane_state *old_state) 55580d3eef1SDmitry Osipenko { 556a4bfa096SThierry Reding struct tegra_dc *dc = to_tegra_dc(old_state->crtc); 557a4bfa096SThierry Reding struct tegra_plane *p = to_tegra_plane(plane); 55880d3eef1SDmitry Osipenko unsigned long flags; 55980d3eef1SDmitry Osipenko u32 value; 56080d3eef1SDmitry Osipenko 561a4bfa096SThierry Reding /* rien ne va plus */ 562a4bfa096SThierry Reding if (!old_state || !old_state->crtc) 563a4bfa096SThierry Reding return; 564a4bfa096SThierry Reding 56580d3eef1SDmitry Osipenko spin_lock_irqsave(&dc->lock, flags); 56680d3eef1SDmitry Osipenko 567a4bfa096SThierry Reding value = WINDOW_A_SELECT << p->index; 56880d3eef1SDmitry Osipenko tegra_dc_writel(dc, value, DC_CMD_DISPLAY_WINDOW_HEADER); 56980d3eef1SDmitry Osipenko 57080d3eef1SDmitry Osipenko value = tegra_dc_readl(dc, DC_WIN_WIN_OPTIONS); 57180d3eef1SDmitry Osipenko value &= ~WIN_ENABLE; 57280d3eef1SDmitry Osipenko tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS); 57380d3eef1SDmitry Osipenko 57480d3eef1SDmitry Osipenko spin_unlock_irqrestore(&dc->lock, flags); 57580d3eef1SDmitry Osipenko } 57680d3eef1SDmitry Osipenko 5774aa3df71SThierry Reding static void tegra_plane_atomic_update(struct drm_plane *plane, 5784aa3df71SThierry Reding struct drm_plane_state *old_state) 5794aa3df71SThierry Reding { 5808f604f8cSThierry Reding struct tegra_plane_state *state = to_tegra_plane_state(plane->state); 5814aa3df71SThierry Reding struct tegra_dc *dc = to_tegra_dc(plane->state->crtc); 5824aa3df71SThierry Reding struct drm_framebuffer *fb = plane->state->fb; 5834aa3df71SThierry Reding struct tegra_plane *p = to_tegra_plane(plane); 5844aa3df71SThierry Reding struct tegra_dc_window window; 5854aa3df71SThierry Reding unsigned int i; 5864aa3df71SThierry Reding 5874aa3df71SThierry Reding /* rien ne va plus */ 5884aa3df71SThierry Reding if (!plane->state->crtc || !plane->state->fb) 5894aa3df71SThierry Reding return; 5904aa3df71SThierry Reding 59180d3eef1SDmitry Osipenko if (!plane->state->visible) 592a4bfa096SThierry Reding return tegra_plane_atomic_disable(plane, old_state); 59380d3eef1SDmitry Osipenko 594c7679306SThierry Reding memset(&window, 0, sizeof(window)); 5957d205857SDmitry Osipenko window.src.x = plane->state->src.x1 >> 16; 5967d205857SDmitry Osipenko window.src.y = plane->state->src.y1 >> 16; 5977d205857SDmitry Osipenko window.src.w = drm_rect_width(&plane->state->src) >> 16; 5987d205857SDmitry Osipenko window.src.h = drm_rect_height(&plane->state->src) >> 16; 5997d205857SDmitry Osipenko window.dst.x = plane->state->dst.x1; 6007d205857SDmitry Osipenko window.dst.y = plane->state->dst.y1; 6017d205857SDmitry Osipenko window.dst.w = drm_rect_width(&plane->state->dst); 6027d205857SDmitry Osipenko window.dst.h = drm_rect_height(&plane->state->dst); 603272725c7SVille Syrjälä window.bits_per_pixel = fb->format->cpp[0] * 8; 604c7679306SThierry Reding window.bottom_up = tegra_fb_is_bottom_up(fb); 605c7679306SThierry Reding 6068f604f8cSThierry Reding /* copy from state */ 6078f604f8cSThierry Reding window.tiling = state->tiling; 6088f604f8cSThierry Reding window.format = state->format; 6098f604f8cSThierry Reding window.swap = state->swap; 610c7679306SThierry Reding 611bcb0b461SVille Syrjälä for (i = 0; i < fb->format->num_planes; i++) { 6124aa3df71SThierry Reding struct tegra_bo *bo = tegra_fb_get_plane(fb, i); 613c7679306SThierry Reding 6144aa3df71SThierry Reding window.base[i] = bo->paddr + fb->offsets[i]; 61508ee0178SDmitry Osipenko 61608ee0178SDmitry Osipenko /* 61708ee0178SDmitry Osipenko * Tegra uses a shared stride for UV planes. Framebuffers are 61808ee0178SDmitry Osipenko * already checked for this in the tegra_plane_atomic_check() 61908ee0178SDmitry Osipenko * function, so it's safe to ignore the V-plane pitch here. 62008ee0178SDmitry Osipenko */ 62108ee0178SDmitry Osipenko if (i < 2) 6224aa3df71SThierry Reding window.stride[i] = fb->pitches[i]; 623c7679306SThierry Reding } 624c7679306SThierry Reding 6254aa3df71SThierry Reding tegra_dc_setup_window(dc, p->index, &window); 6264aa3df71SThierry Reding } 6274aa3df71SThierry Reding 628a4bfa096SThierry Reding static const struct drm_plane_helper_funcs tegra_plane_helper_funcs = { 6294aa3df71SThierry Reding .atomic_check = tegra_plane_atomic_check, 6304aa3df71SThierry Reding .atomic_disable = tegra_plane_atomic_disable, 631a4bfa096SThierry Reding .atomic_update = tegra_plane_atomic_update, 632c7679306SThierry Reding }; 633c7679306SThierry Reding 634c7679306SThierry Reding static struct drm_plane *tegra_dc_primary_plane_create(struct drm_device *drm, 635c7679306SThierry Reding struct tegra_dc *dc) 636c7679306SThierry Reding { 637518e6227SThierry Reding /* 638518e6227SThierry Reding * Ideally this would use drm_crtc_mask(), but that would require the 639518e6227SThierry Reding * CRTC to already be in the mode_config's list of CRTCs. However, it 640518e6227SThierry Reding * will only be added to that list in the drm_crtc_init_with_planes() 641518e6227SThierry Reding * (in tegra_dc_init()), which in turn requires registration of these 642518e6227SThierry Reding * planes. So we have ourselves a nice little chicken and egg problem 643518e6227SThierry Reding * here. 644518e6227SThierry Reding * 645518e6227SThierry Reding * We work around this by manually creating the mask from the number 646518e6227SThierry Reding * of CRTCs that have been registered, and should therefore always be 647518e6227SThierry Reding * the same as drm_crtc_index() after registration. 648518e6227SThierry Reding */ 649518e6227SThierry Reding unsigned long possible_crtcs = 1 << drm->mode_config.num_crtc; 650c7679306SThierry Reding struct tegra_plane *plane; 651c7679306SThierry Reding unsigned int num_formats; 652c7679306SThierry Reding const u32 *formats; 653c7679306SThierry Reding int err; 654c7679306SThierry Reding 655c7679306SThierry Reding plane = kzalloc(sizeof(*plane), GFP_KERNEL); 656c7679306SThierry Reding if (!plane) 657c7679306SThierry Reding return ERR_PTR(-ENOMEM); 658c7679306SThierry Reding 659c7679306SThierry Reding num_formats = ARRAY_SIZE(tegra_primary_plane_formats); 660c7679306SThierry Reding formats = tegra_primary_plane_formats; 661c7679306SThierry Reding 662518e6227SThierry Reding err = drm_universal_plane_init(drm, &plane->base, possible_crtcs, 663c7679306SThierry Reding &tegra_primary_plane_funcs, formats, 664e6fc3b68SBen Widawsky num_formats, NULL, 665e6fc3b68SBen Widawsky DRM_PLANE_TYPE_PRIMARY, NULL); 666c7679306SThierry Reding if (err < 0) { 667c7679306SThierry Reding kfree(plane); 668c7679306SThierry Reding return ERR_PTR(err); 669c7679306SThierry Reding } 670c7679306SThierry Reding 671a4bfa096SThierry Reding drm_plane_helper_add(&plane->base, &tegra_plane_helper_funcs); 6724aa3df71SThierry Reding 673c7679306SThierry Reding return &plane->base; 674c7679306SThierry Reding } 675c7679306SThierry Reding 676c7679306SThierry Reding static const u32 tegra_cursor_plane_formats[] = { 677c7679306SThierry Reding DRM_FORMAT_RGBA8888, 678c7679306SThierry Reding }; 679c7679306SThierry Reding 6804aa3df71SThierry Reding static int tegra_cursor_atomic_check(struct drm_plane *plane, 6814aa3df71SThierry Reding struct drm_plane_state *state) 682c7679306SThierry Reding { 68347802b09SThierry Reding struct tegra_plane *tegra = to_tegra_plane(plane); 68447802b09SThierry Reding int err; 68547802b09SThierry Reding 6864aa3df71SThierry Reding /* no need for further checks if the plane is being disabled */ 6874aa3df71SThierry Reding if (!state->crtc) 6884aa3df71SThierry Reding return 0; 689c7679306SThierry Reding 690c7679306SThierry Reding /* scaling not supported for cursor */ 6914aa3df71SThierry Reding if ((state->src_w >> 16 != state->crtc_w) || 6924aa3df71SThierry Reding (state->src_h >> 16 != state->crtc_h)) 693c7679306SThierry Reding return -EINVAL; 694c7679306SThierry Reding 695c7679306SThierry Reding /* only square cursors supported */ 6964aa3df71SThierry Reding if (state->src_w != state->src_h) 697c7679306SThierry Reding return -EINVAL; 698c7679306SThierry Reding 6994aa3df71SThierry Reding if (state->crtc_w != 32 && state->crtc_w != 64 && 7004aa3df71SThierry Reding state->crtc_w != 128 && state->crtc_w != 256) 7014aa3df71SThierry Reding return -EINVAL; 7024aa3df71SThierry Reding 70347802b09SThierry Reding err = tegra_plane_state_add(tegra, state); 70447802b09SThierry Reding if (err < 0) 70547802b09SThierry Reding return err; 70647802b09SThierry Reding 7074aa3df71SThierry Reding return 0; 7084aa3df71SThierry Reding } 7094aa3df71SThierry Reding 7104aa3df71SThierry Reding static void tegra_cursor_atomic_update(struct drm_plane *plane, 7114aa3df71SThierry Reding struct drm_plane_state *old_state) 7124aa3df71SThierry Reding { 7134aa3df71SThierry Reding struct tegra_bo *bo = tegra_fb_get_plane(plane->state->fb, 0); 7144aa3df71SThierry Reding struct tegra_dc *dc = to_tegra_dc(plane->state->crtc); 7154aa3df71SThierry Reding struct drm_plane_state *state = plane->state; 7164aa3df71SThierry Reding u32 value = CURSOR_CLIP_DISPLAY; 7174aa3df71SThierry Reding 7184aa3df71SThierry Reding /* rien ne va plus */ 7194aa3df71SThierry Reding if (!plane->state->crtc || !plane->state->fb) 7204aa3df71SThierry Reding return; 7214aa3df71SThierry Reding 7224aa3df71SThierry Reding switch (state->crtc_w) { 723c7679306SThierry Reding case 32: 724c7679306SThierry Reding value |= CURSOR_SIZE_32x32; 725c7679306SThierry Reding break; 726c7679306SThierry Reding 727c7679306SThierry Reding case 64: 728c7679306SThierry Reding value |= CURSOR_SIZE_64x64; 729c7679306SThierry Reding break; 730c7679306SThierry Reding 731c7679306SThierry Reding case 128: 732c7679306SThierry Reding value |= CURSOR_SIZE_128x128; 733c7679306SThierry Reding break; 734c7679306SThierry Reding 735c7679306SThierry Reding case 256: 736c7679306SThierry Reding value |= CURSOR_SIZE_256x256; 737c7679306SThierry Reding break; 738c7679306SThierry Reding 739c7679306SThierry Reding default: 7404aa3df71SThierry Reding WARN(1, "cursor size %ux%u not supported\n", state->crtc_w, 7414aa3df71SThierry Reding state->crtc_h); 7424aa3df71SThierry Reding return; 743c7679306SThierry Reding } 744c7679306SThierry Reding 745c7679306SThierry Reding value |= (bo->paddr >> 10) & 0x3fffff; 746c7679306SThierry Reding tegra_dc_writel(dc, value, DC_DISP_CURSOR_START_ADDR); 747c7679306SThierry Reding 748c7679306SThierry Reding #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT 749c7679306SThierry Reding value = (bo->paddr >> 32) & 0x3; 750c7679306SThierry Reding tegra_dc_writel(dc, value, DC_DISP_CURSOR_START_ADDR_HI); 751c7679306SThierry Reding #endif 752c7679306SThierry Reding 753c7679306SThierry Reding /* enable cursor and set blend mode */ 754c7679306SThierry Reding value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); 755c7679306SThierry Reding value |= CURSOR_ENABLE; 756c7679306SThierry Reding tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); 757c7679306SThierry Reding 758c7679306SThierry Reding value = tegra_dc_readl(dc, DC_DISP_BLEND_CURSOR_CONTROL); 759c7679306SThierry Reding value &= ~CURSOR_DST_BLEND_MASK; 760c7679306SThierry Reding value &= ~CURSOR_SRC_BLEND_MASK; 761c7679306SThierry Reding value |= CURSOR_MODE_NORMAL; 762c7679306SThierry Reding value |= CURSOR_DST_BLEND_NEG_K1_TIMES_SRC; 763c7679306SThierry Reding value |= CURSOR_SRC_BLEND_K1_TIMES_SRC; 764c7679306SThierry Reding value |= CURSOR_ALPHA; 765c7679306SThierry Reding tegra_dc_writel(dc, value, DC_DISP_BLEND_CURSOR_CONTROL); 766c7679306SThierry Reding 767c7679306SThierry Reding /* position the cursor */ 7684aa3df71SThierry Reding value = (state->crtc_y & 0x3fff) << 16 | (state->crtc_x & 0x3fff); 769c7679306SThierry Reding tegra_dc_writel(dc, value, DC_DISP_CURSOR_POSITION); 770c7679306SThierry Reding } 771c7679306SThierry Reding 7724aa3df71SThierry Reding static void tegra_cursor_atomic_disable(struct drm_plane *plane, 7734aa3df71SThierry Reding struct drm_plane_state *old_state) 774c7679306SThierry Reding { 7754aa3df71SThierry Reding struct tegra_dc *dc; 776c7679306SThierry Reding u32 value; 777c7679306SThierry Reding 7784aa3df71SThierry Reding /* rien ne va plus */ 7794aa3df71SThierry Reding if (!old_state || !old_state->crtc) 7804aa3df71SThierry Reding return; 7814aa3df71SThierry Reding 7824aa3df71SThierry Reding dc = to_tegra_dc(old_state->crtc); 783c7679306SThierry Reding 784c7679306SThierry Reding value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); 785c7679306SThierry Reding value &= ~CURSOR_ENABLE; 786c7679306SThierry Reding tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); 787c7679306SThierry Reding } 788c7679306SThierry Reding 789c7679306SThierry Reding static const struct drm_plane_funcs tegra_cursor_plane_funcs = { 79007866963SThierry Reding .update_plane = drm_atomic_helper_update_plane, 79107866963SThierry Reding .disable_plane = drm_atomic_helper_disable_plane, 792c7679306SThierry Reding .destroy = tegra_plane_destroy, 7938f604f8cSThierry Reding .reset = tegra_plane_reset, 7948f604f8cSThierry Reding .atomic_duplicate_state = tegra_plane_atomic_duplicate_state, 7958f604f8cSThierry Reding .atomic_destroy_state = tegra_plane_atomic_destroy_state, 7964aa3df71SThierry Reding }; 7974aa3df71SThierry Reding 7984aa3df71SThierry Reding static const struct drm_plane_helper_funcs tegra_cursor_plane_helper_funcs = { 7994aa3df71SThierry Reding .atomic_check = tegra_cursor_atomic_check, 8004aa3df71SThierry Reding .atomic_update = tegra_cursor_atomic_update, 8014aa3df71SThierry Reding .atomic_disable = tegra_cursor_atomic_disable, 802c7679306SThierry Reding }; 803c7679306SThierry Reding 804c7679306SThierry Reding static struct drm_plane *tegra_dc_cursor_plane_create(struct drm_device *drm, 805c7679306SThierry Reding struct tegra_dc *dc) 806c7679306SThierry Reding { 807c7679306SThierry Reding struct tegra_plane *plane; 808c7679306SThierry Reding unsigned int num_formats; 809c7679306SThierry Reding const u32 *formats; 810c7679306SThierry Reding int err; 811c7679306SThierry Reding 812c7679306SThierry Reding plane = kzalloc(sizeof(*plane), GFP_KERNEL); 813c7679306SThierry Reding if (!plane) 814c7679306SThierry Reding return ERR_PTR(-ENOMEM); 815c7679306SThierry Reding 81647802b09SThierry Reding /* 817a1df3b24SThierry Reding * This index is kind of fake. The cursor isn't a regular plane, but 818a1df3b24SThierry Reding * its update and activation request bits in DC_CMD_STATE_CONTROL do 819a1df3b24SThierry Reding * use the same programming. Setting this fake index here allows the 820a1df3b24SThierry Reding * code in tegra_add_plane_state() to do the right thing without the 821a1df3b24SThierry Reding * need to special-casing the cursor plane. 82247802b09SThierry Reding */ 82347802b09SThierry Reding plane->index = 6; 82447802b09SThierry Reding 825c7679306SThierry Reding num_formats = ARRAY_SIZE(tegra_cursor_plane_formats); 826c7679306SThierry Reding formats = tegra_cursor_plane_formats; 827c7679306SThierry Reding 828c7679306SThierry Reding err = drm_universal_plane_init(drm, &plane->base, 1 << dc->pipe, 829c7679306SThierry Reding &tegra_cursor_plane_funcs, formats, 830e6fc3b68SBen Widawsky num_formats, NULL, 831e6fc3b68SBen Widawsky DRM_PLANE_TYPE_CURSOR, NULL); 832c7679306SThierry Reding if (err < 0) { 833c7679306SThierry Reding kfree(plane); 834c7679306SThierry Reding return ERR_PTR(err); 835c7679306SThierry Reding } 836c7679306SThierry Reding 8374aa3df71SThierry Reding drm_plane_helper_add(&plane->base, &tegra_cursor_plane_helper_funcs); 8384aa3df71SThierry Reding 839c7679306SThierry Reding return &plane->base; 840c7679306SThierry Reding } 841c7679306SThierry Reding 842c7679306SThierry Reding static void tegra_overlay_plane_destroy(struct drm_plane *plane) 843dee8268fSThierry Reding { 844c7679306SThierry Reding tegra_plane_destroy(plane); 845dee8268fSThierry Reding } 846dee8268fSThierry Reding 847c7679306SThierry Reding static const struct drm_plane_funcs tegra_overlay_plane_funcs = { 84807866963SThierry Reding .update_plane = drm_atomic_helper_update_plane, 84907866963SThierry Reding .disable_plane = drm_atomic_helper_disable_plane, 850c7679306SThierry Reding .destroy = tegra_overlay_plane_destroy, 8518f604f8cSThierry Reding .reset = tegra_plane_reset, 8528f604f8cSThierry Reding .atomic_duplicate_state = tegra_plane_atomic_duplicate_state, 8538f604f8cSThierry Reding .atomic_destroy_state = tegra_plane_atomic_destroy_state, 854dee8268fSThierry Reding }; 855dee8268fSThierry Reding 856c7679306SThierry Reding static const uint32_t tegra_overlay_plane_formats[] = { 857dee8268fSThierry Reding DRM_FORMAT_XBGR8888, 858dee8268fSThierry Reding DRM_FORMAT_XRGB8888, 859dee8268fSThierry Reding DRM_FORMAT_RGB565, 860dee8268fSThierry Reding DRM_FORMAT_UYVY, 861f925390eSThierry Reding DRM_FORMAT_YUYV, 862dee8268fSThierry Reding DRM_FORMAT_YUV420, 863dee8268fSThierry Reding DRM_FORMAT_YUV422, 864dee8268fSThierry Reding }; 865dee8268fSThierry Reding 866c7679306SThierry Reding static struct drm_plane *tegra_dc_overlay_plane_create(struct drm_device *drm, 867c7679306SThierry Reding struct tegra_dc *dc, 868c7679306SThierry Reding unsigned int index) 869dee8268fSThierry Reding { 870dee8268fSThierry Reding struct tegra_plane *plane; 871c7679306SThierry Reding unsigned int num_formats; 872c7679306SThierry Reding const u32 *formats; 873c7679306SThierry Reding int err; 874dee8268fSThierry Reding 875f002abc1SThierry Reding plane = kzalloc(sizeof(*plane), GFP_KERNEL); 876dee8268fSThierry Reding if (!plane) 877c7679306SThierry Reding return ERR_PTR(-ENOMEM); 878dee8268fSThierry Reding 879c7679306SThierry Reding plane->index = index; 880dee8268fSThierry Reding 881c7679306SThierry Reding num_formats = ARRAY_SIZE(tegra_overlay_plane_formats); 882c7679306SThierry Reding formats = tegra_overlay_plane_formats; 883c7679306SThierry Reding 884c7679306SThierry Reding err = drm_universal_plane_init(drm, &plane->base, 1 << dc->pipe, 885c7679306SThierry Reding &tegra_overlay_plane_funcs, formats, 886e6fc3b68SBen Widawsky num_formats, NULL, 887e6fc3b68SBen Widawsky DRM_PLANE_TYPE_OVERLAY, NULL); 888f002abc1SThierry Reding if (err < 0) { 889f002abc1SThierry Reding kfree(plane); 890c7679306SThierry Reding return ERR_PTR(err); 891dee8268fSThierry Reding } 892c7679306SThierry Reding 893a4bfa096SThierry Reding drm_plane_helper_add(&plane->base, &tegra_plane_helper_funcs); 8944aa3df71SThierry Reding 895c7679306SThierry Reding return &plane->base; 896c7679306SThierry Reding } 897c7679306SThierry Reding 898c7679306SThierry Reding static int tegra_dc_add_planes(struct drm_device *drm, struct tegra_dc *dc) 899c7679306SThierry Reding { 900c7679306SThierry Reding struct drm_plane *plane; 901c7679306SThierry Reding unsigned int i; 902c7679306SThierry Reding 903c7679306SThierry Reding for (i = 0; i < 2; i++) { 904c7679306SThierry Reding plane = tegra_dc_overlay_plane_create(drm, dc, 1 + i); 905c7679306SThierry Reding if (IS_ERR(plane)) 906c7679306SThierry Reding return PTR_ERR(plane); 907f002abc1SThierry Reding } 908dee8268fSThierry Reding 909dee8268fSThierry Reding return 0; 910dee8268fSThierry Reding } 911dee8268fSThierry Reding 91210437d9bSShawn Guo static u32 tegra_dc_get_vblank_counter(struct drm_crtc *crtc) 91342e9ce05SThierry Reding { 91410437d9bSShawn Guo struct tegra_dc *dc = to_tegra_dc(crtc); 91510437d9bSShawn Guo 91642e9ce05SThierry Reding if (dc->syncpt) 91742e9ce05SThierry Reding return host1x_syncpt_read(dc->syncpt); 91842e9ce05SThierry Reding 91942e9ce05SThierry Reding /* fallback to software emulated VBLANK counter */ 92042e9ce05SThierry Reding return drm_crtc_vblank_count(&dc->base); 92142e9ce05SThierry Reding } 92242e9ce05SThierry Reding 92310437d9bSShawn Guo static int tegra_dc_enable_vblank(struct drm_crtc *crtc) 924dee8268fSThierry Reding { 92510437d9bSShawn Guo struct tegra_dc *dc = to_tegra_dc(crtc); 926dee8268fSThierry Reding unsigned long value, flags; 927dee8268fSThierry Reding 928dee8268fSThierry Reding spin_lock_irqsave(&dc->lock, flags); 929dee8268fSThierry Reding 930dee8268fSThierry Reding value = tegra_dc_readl(dc, DC_CMD_INT_MASK); 931dee8268fSThierry Reding value |= VBLANK_INT; 932dee8268fSThierry Reding tegra_dc_writel(dc, value, DC_CMD_INT_MASK); 933dee8268fSThierry Reding 934dee8268fSThierry Reding spin_unlock_irqrestore(&dc->lock, flags); 93510437d9bSShawn Guo 93610437d9bSShawn Guo return 0; 937dee8268fSThierry Reding } 938dee8268fSThierry Reding 93910437d9bSShawn Guo static void tegra_dc_disable_vblank(struct drm_crtc *crtc) 940dee8268fSThierry Reding { 94110437d9bSShawn Guo struct tegra_dc *dc = to_tegra_dc(crtc); 942dee8268fSThierry Reding unsigned long value, flags; 943dee8268fSThierry Reding 944dee8268fSThierry Reding spin_lock_irqsave(&dc->lock, flags); 945dee8268fSThierry Reding 946dee8268fSThierry Reding value = tegra_dc_readl(dc, DC_CMD_INT_MASK); 947dee8268fSThierry Reding value &= ~VBLANK_INT; 948dee8268fSThierry Reding tegra_dc_writel(dc, value, DC_CMD_INT_MASK); 949dee8268fSThierry Reding 950dee8268fSThierry Reding spin_unlock_irqrestore(&dc->lock, flags); 951dee8268fSThierry Reding } 952dee8268fSThierry Reding 953dee8268fSThierry Reding static void tegra_dc_finish_page_flip(struct tegra_dc *dc) 954dee8268fSThierry Reding { 955dee8268fSThierry Reding struct drm_device *drm = dc->base.dev; 956dee8268fSThierry Reding struct drm_crtc *crtc = &dc->base; 957dee8268fSThierry Reding unsigned long flags, base; 958dee8268fSThierry Reding struct tegra_bo *bo; 959dee8268fSThierry Reding 9606b59cc1cSThierry Reding spin_lock_irqsave(&drm->event_lock, flags); 9616b59cc1cSThierry Reding 9626b59cc1cSThierry Reding if (!dc->event) { 9636b59cc1cSThierry Reding spin_unlock_irqrestore(&drm->event_lock, flags); 964dee8268fSThierry Reding return; 9656b59cc1cSThierry Reding } 966dee8268fSThierry Reding 967f4510a27SMatt Roper bo = tegra_fb_get_plane(crtc->primary->fb, 0); 968dee8268fSThierry Reding 9698643bc6dSDan Carpenter spin_lock(&dc->lock); 97093396d0fSSean Paul 971dee8268fSThierry Reding /* check if new start address has been latched */ 97293396d0fSSean Paul tegra_dc_writel(dc, WINDOW_A_SELECT, DC_CMD_DISPLAY_WINDOW_HEADER); 973dee8268fSThierry Reding tegra_dc_writel(dc, READ_MUX, DC_CMD_STATE_ACCESS); 974dee8268fSThierry Reding base = tegra_dc_readl(dc, DC_WINBUF_START_ADDR); 975dee8268fSThierry Reding tegra_dc_writel(dc, 0, DC_CMD_STATE_ACCESS); 976dee8268fSThierry Reding 9778643bc6dSDan Carpenter spin_unlock(&dc->lock); 97893396d0fSSean Paul 979f4510a27SMatt Roper if (base == bo->paddr + crtc->primary->fb->offsets[0]) { 980ed7dae58SThierry Reding drm_crtc_send_vblank_event(crtc, dc->event); 981ed7dae58SThierry Reding drm_crtc_vblank_put(crtc); 982dee8268fSThierry Reding dc->event = NULL; 983dee8268fSThierry Reding } 9846b59cc1cSThierry Reding 9856b59cc1cSThierry Reding spin_unlock_irqrestore(&drm->event_lock, flags); 986dee8268fSThierry Reding } 987dee8268fSThierry Reding 988f002abc1SThierry Reding static void tegra_dc_destroy(struct drm_crtc *crtc) 989f002abc1SThierry Reding { 990f002abc1SThierry Reding drm_crtc_cleanup(crtc); 991f002abc1SThierry Reding } 992f002abc1SThierry Reding 993ca915b10SThierry Reding static void tegra_crtc_reset(struct drm_crtc *crtc) 994ca915b10SThierry Reding { 995ca915b10SThierry Reding struct tegra_dc_state *state; 996ca915b10SThierry Reding 9973b59b7acSThierry Reding if (crtc->state) 998ec2dc6a0SDaniel Vetter __drm_atomic_helper_crtc_destroy_state(crtc->state); 9993b59b7acSThierry Reding 1000ca915b10SThierry Reding kfree(crtc->state); 1001ca915b10SThierry Reding crtc->state = NULL; 1002ca915b10SThierry Reding 1003ca915b10SThierry Reding state = kzalloc(sizeof(*state), GFP_KERNEL); 1004332bbe70SThierry Reding if (state) { 1005ca915b10SThierry Reding crtc->state = &state->base; 1006332bbe70SThierry Reding crtc->state->crtc = crtc; 1007332bbe70SThierry Reding } 100831930d4dSThierry Reding 100931930d4dSThierry Reding drm_crtc_vblank_reset(crtc); 1010ca915b10SThierry Reding } 1011ca915b10SThierry Reding 1012ca915b10SThierry Reding static struct drm_crtc_state * 1013ca915b10SThierry Reding tegra_crtc_atomic_duplicate_state(struct drm_crtc *crtc) 1014ca915b10SThierry Reding { 1015ca915b10SThierry Reding struct tegra_dc_state *state = to_dc_state(crtc->state); 1016ca915b10SThierry Reding struct tegra_dc_state *copy; 1017ca915b10SThierry Reding 10183b59b7acSThierry Reding copy = kmalloc(sizeof(*copy), GFP_KERNEL); 1019ca915b10SThierry Reding if (!copy) 1020ca915b10SThierry Reding return NULL; 1021ca915b10SThierry Reding 10223b59b7acSThierry Reding __drm_atomic_helper_crtc_duplicate_state(crtc, ©->base); 10233b59b7acSThierry Reding copy->clk = state->clk; 10243b59b7acSThierry Reding copy->pclk = state->pclk; 10253b59b7acSThierry Reding copy->div = state->div; 10263b59b7acSThierry Reding copy->planes = state->planes; 1027ca915b10SThierry Reding 1028ca915b10SThierry Reding return ©->base; 1029ca915b10SThierry Reding } 1030ca915b10SThierry Reding 1031ca915b10SThierry Reding static void tegra_crtc_atomic_destroy_state(struct drm_crtc *crtc, 1032ca915b10SThierry Reding struct drm_crtc_state *state) 1033ca915b10SThierry Reding { 1034ec2dc6a0SDaniel Vetter __drm_atomic_helper_crtc_destroy_state(state); 1035ca915b10SThierry Reding kfree(state); 1036ca915b10SThierry Reding } 1037ca915b10SThierry Reding 1038dee8268fSThierry Reding static const struct drm_crtc_funcs tegra_crtc_funcs = { 10391503ca47SThierry Reding .page_flip = drm_atomic_helper_page_flip, 104074f48791SThierry Reding .set_config = drm_atomic_helper_set_config, 1041f002abc1SThierry Reding .destroy = tegra_dc_destroy, 1042ca915b10SThierry Reding .reset = tegra_crtc_reset, 1043ca915b10SThierry Reding .atomic_duplicate_state = tegra_crtc_atomic_duplicate_state, 1044ca915b10SThierry Reding .atomic_destroy_state = tegra_crtc_atomic_destroy_state, 104510437d9bSShawn Guo .get_vblank_counter = tegra_dc_get_vblank_counter, 104610437d9bSShawn Guo .enable_vblank = tegra_dc_enable_vblank, 104710437d9bSShawn Guo .disable_vblank = tegra_dc_disable_vblank, 1048dee8268fSThierry Reding }; 1049dee8268fSThierry Reding 1050dee8268fSThierry Reding static int tegra_dc_set_timings(struct tegra_dc *dc, 1051dee8268fSThierry Reding struct drm_display_mode *mode) 1052dee8268fSThierry Reding { 10530444c0ffSThierry Reding unsigned int h_ref_to_sync = 1; 10540444c0ffSThierry Reding unsigned int v_ref_to_sync = 1; 1055dee8268fSThierry Reding unsigned long value; 1056dee8268fSThierry Reding 1057dee8268fSThierry Reding tegra_dc_writel(dc, 0x0, DC_DISP_DISP_TIMING_OPTIONS); 1058dee8268fSThierry Reding 1059dee8268fSThierry Reding value = (v_ref_to_sync << 16) | h_ref_to_sync; 1060dee8268fSThierry Reding tegra_dc_writel(dc, value, DC_DISP_REF_TO_SYNC); 1061dee8268fSThierry Reding 1062dee8268fSThierry Reding value = ((mode->vsync_end - mode->vsync_start) << 16) | 1063dee8268fSThierry Reding ((mode->hsync_end - mode->hsync_start) << 0); 1064dee8268fSThierry Reding tegra_dc_writel(dc, value, DC_DISP_SYNC_WIDTH); 1065dee8268fSThierry Reding 1066dee8268fSThierry Reding value = ((mode->vtotal - mode->vsync_end) << 16) | 1067dee8268fSThierry Reding ((mode->htotal - mode->hsync_end) << 0); 1068dee8268fSThierry Reding tegra_dc_writel(dc, value, DC_DISP_BACK_PORCH); 1069dee8268fSThierry Reding 1070dee8268fSThierry Reding value = ((mode->vsync_start - mode->vdisplay) << 16) | 1071dee8268fSThierry Reding ((mode->hsync_start - mode->hdisplay) << 0); 1072dee8268fSThierry Reding tegra_dc_writel(dc, value, DC_DISP_FRONT_PORCH); 1073dee8268fSThierry Reding 1074dee8268fSThierry Reding value = (mode->vdisplay << 16) | mode->hdisplay; 1075dee8268fSThierry Reding tegra_dc_writel(dc, value, DC_DISP_ACTIVE); 1076dee8268fSThierry Reding 1077dee8268fSThierry Reding return 0; 1078dee8268fSThierry Reding } 1079dee8268fSThierry Reding 10809d910b60SThierry Reding /** 10819d910b60SThierry Reding * tegra_dc_state_setup_clock - check clock settings and store them in atomic 10829d910b60SThierry Reding * state 10839d910b60SThierry Reding * @dc: display controller 10849d910b60SThierry Reding * @crtc_state: CRTC atomic state 10859d910b60SThierry Reding * @clk: parent clock for display controller 10869d910b60SThierry Reding * @pclk: pixel clock 10879d910b60SThierry Reding * @div: shift clock divider 10889d910b60SThierry Reding * 10899d910b60SThierry Reding * Returns: 10909d910b60SThierry Reding * 0 on success or a negative error-code on failure. 10919d910b60SThierry Reding */ 1092ca915b10SThierry Reding int tegra_dc_state_setup_clock(struct tegra_dc *dc, 1093ca915b10SThierry Reding struct drm_crtc_state *crtc_state, 1094ca915b10SThierry Reding struct clk *clk, unsigned long pclk, 1095ca915b10SThierry Reding unsigned int div) 1096ca915b10SThierry Reding { 1097ca915b10SThierry Reding struct tegra_dc_state *state = to_dc_state(crtc_state); 1098ca915b10SThierry Reding 1099d2982748SThierry Reding if (!clk_has_parent(dc->clk, clk)) 1100d2982748SThierry Reding return -EINVAL; 1101d2982748SThierry Reding 1102ca915b10SThierry Reding state->clk = clk; 1103ca915b10SThierry Reding state->pclk = pclk; 1104ca915b10SThierry Reding state->div = div; 1105ca915b10SThierry Reding 1106ca915b10SThierry Reding return 0; 1107ca915b10SThierry Reding } 1108ca915b10SThierry Reding 110976d59ed0SThierry Reding static void tegra_dc_commit_state(struct tegra_dc *dc, 111076d59ed0SThierry Reding struct tegra_dc_state *state) 111176d59ed0SThierry Reding { 111276d59ed0SThierry Reding u32 value; 111376d59ed0SThierry Reding int err; 111476d59ed0SThierry Reding 111576d59ed0SThierry Reding err = clk_set_parent(dc->clk, state->clk); 111676d59ed0SThierry Reding if (err < 0) 111776d59ed0SThierry Reding dev_err(dc->dev, "failed to set parent clock: %d\n", err); 111876d59ed0SThierry Reding 111976d59ed0SThierry Reding /* 112076d59ed0SThierry Reding * Outputs may not want to change the parent clock rate. This is only 112176d59ed0SThierry Reding * relevant to Tegra20 where only a single display PLL is available. 112276d59ed0SThierry Reding * Since that PLL would typically be used for HDMI, an internal LVDS 112376d59ed0SThierry Reding * panel would need to be driven by some other clock such as PLL_P 112476d59ed0SThierry Reding * which is shared with other peripherals. Changing the clock rate 112576d59ed0SThierry Reding * should therefore be avoided. 112676d59ed0SThierry Reding */ 112776d59ed0SThierry Reding if (state->pclk > 0) { 112876d59ed0SThierry Reding err = clk_set_rate(state->clk, state->pclk); 112976d59ed0SThierry Reding if (err < 0) 113076d59ed0SThierry Reding dev_err(dc->dev, 113176d59ed0SThierry Reding "failed to set clock rate to %lu Hz\n", 113276d59ed0SThierry Reding state->pclk); 113376d59ed0SThierry Reding } 113476d59ed0SThierry Reding 113576d59ed0SThierry Reding DRM_DEBUG_KMS("rate: %lu, div: %u\n", clk_get_rate(dc->clk), 113676d59ed0SThierry Reding state->div); 113776d59ed0SThierry Reding DRM_DEBUG_KMS("pclk: %lu\n", state->pclk); 113876d59ed0SThierry Reding 113976d59ed0SThierry Reding value = SHIFT_CLK_DIVIDER(state->div) | PIXEL_CLK_DIVIDER_PCD1; 114076d59ed0SThierry Reding tegra_dc_writel(dc, value, DC_DISP_DISP_CLOCK_CONTROL); 1141*39e08affSThierry Reding 1142*39e08affSThierry Reding err = clk_set_rate(dc->clk, state->pclk); 1143*39e08affSThierry Reding if (err < 0) 1144*39e08affSThierry Reding dev_err(dc->dev, "failed to set clock %pC to %lu Hz: %d\n", 1145*39e08affSThierry Reding dc->clk, state->pclk, err); 114676d59ed0SThierry Reding } 114776d59ed0SThierry Reding 1148003fc848SThierry Reding static void tegra_dc_stop(struct tegra_dc *dc) 1149003fc848SThierry Reding { 1150003fc848SThierry Reding u32 value; 1151003fc848SThierry Reding 1152003fc848SThierry Reding /* stop the display controller */ 1153003fc848SThierry Reding value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND); 1154003fc848SThierry Reding value &= ~DISP_CTRL_MODE_MASK; 1155003fc848SThierry Reding tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND); 1156003fc848SThierry Reding 1157003fc848SThierry Reding tegra_dc_commit(dc); 1158003fc848SThierry Reding } 1159003fc848SThierry Reding 1160003fc848SThierry Reding static bool tegra_dc_idle(struct tegra_dc *dc) 1161003fc848SThierry Reding { 1162003fc848SThierry Reding u32 value; 1163003fc848SThierry Reding 1164003fc848SThierry Reding value = tegra_dc_readl_active(dc, DC_CMD_DISPLAY_COMMAND); 1165003fc848SThierry Reding 1166003fc848SThierry Reding return (value & DISP_CTRL_MODE_MASK) == 0; 1167003fc848SThierry Reding } 1168003fc848SThierry Reding 1169003fc848SThierry Reding static int tegra_dc_wait_idle(struct tegra_dc *dc, unsigned long timeout) 1170003fc848SThierry Reding { 1171003fc848SThierry Reding timeout = jiffies + msecs_to_jiffies(timeout); 1172003fc848SThierry Reding 1173003fc848SThierry Reding while (time_before(jiffies, timeout)) { 1174003fc848SThierry Reding if (tegra_dc_idle(dc)) 1175003fc848SThierry Reding return 0; 1176003fc848SThierry Reding 1177003fc848SThierry Reding usleep_range(1000, 2000); 1178003fc848SThierry Reding } 1179003fc848SThierry Reding 1180003fc848SThierry Reding dev_dbg(dc->dev, "timeout waiting for DC to become idle\n"); 1181003fc848SThierry Reding return -ETIMEDOUT; 1182003fc848SThierry Reding } 1183003fc848SThierry Reding 118464581714SLaurent Pinchart static void tegra_crtc_atomic_disable(struct drm_crtc *crtc, 118564581714SLaurent Pinchart struct drm_crtc_state *old_state) 1186003fc848SThierry Reding { 1187003fc848SThierry Reding struct tegra_dc *dc = to_tegra_dc(crtc); 1188003fc848SThierry Reding u32 value; 1189003fc848SThierry Reding 1190003fc848SThierry Reding if (!tegra_dc_idle(dc)) { 1191003fc848SThierry Reding tegra_dc_stop(dc); 1192003fc848SThierry Reding 1193003fc848SThierry Reding /* 1194003fc848SThierry Reding * Ignore the return value, there isn't anything useful to do 1195003fc848SThierry Reding * in case this fails. 1196003fc848SThierry Reding */ 1197003fc848SThierry Reding tegra_dc_wait_idle(dc, 100); 1198003fc848SThierry Reding } 1199003fc848SThierry Reding 1200003fc848SThierry Reding /* 1201003fc848SThierry Reding * This should really be part of the RGB encoder driver, but clearing 1202003fc848SThierry Reding * these bits has the side-effect of stopping the display controller. 1203003fc848SThierry Reding * When that happens no VBLANK interrupts will be raised. At the same 1204003fc848SThierry Reding * time the encoder is disabled before the display controller, so the 1205003fc848SThierry Reding * above code is always going to timeout waiting for the controller 1206003fc848SThierry Reding * to go idle. 1207003fc848SThierry Reding * 1208003fc848SThierry Reding * Given the close coupling between the RGB encoder and the display 1209003fc848SThierry Reding * controller doing it here is still kind of okay. None of the other 1210003fc848SThierry Reding * encoder drivers require these bits to be cleared. 1211003fc848SThierry Reding * 1212003fc848SThierry Reding * XXX: Perhaps given that the display controller is switched off at 1213003fc848SThierry Reding * this point anyway maybe clearing these bits isn't even useful for 1214003fc848SThierry Reding * the RGB encoder? 1215003fc848SThierry Reding */ 1216003fc848SThierry Reding if (dc->rgb) { 1217003fc848SThierry Reding value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL); 1218003fc848SThierry Reding value &= ~(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE | 1219003fc848SThierry Reding PW4_ENABLE | PM0_ENABLE | PM1_ENABLE); 1220003fc848SThierry Reding tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL); 1221003fc848SThierry Reding } 1222003fc848SThierry Reding 1223003fc848SThierry Reding tegra_dc_stats_reset(&dc->stats); 1224003fc848SThierry Reding drm_crtc_vblank_off(crtc); 122533a8eb8dSThierry Reding 122633a8eb8dSThierry Reding pm_runtime_put_sync(dc->dev); 1227003fc848SThierry Reding } 1228003fc848SThierry Reding 12290b20a0f8SLaurent Pinchart static void tegra_crtc_atomic_enable(struct drm_crtc *crtc, 12300b20a0f8SLaurent Pinchart struct drm_crtc_state *old_state) 1231dee8268fSThierry Reding { 12324aa3df71SThierry Reding struct drm_display_mode *mode = &crtc->state->adjusted_mode; 123376d59ed0SThierry Reding struct tegra_dc_state *state = to_dc_state(crtc->state); 1234dee8268fSThierry Reding struct tegra_dc *dc = to_tegra_dc(crtc); 1235dbb3f2f7SThierry Reding u32 value; 1236dee8268fSThierry Reding 123733a8eb8dSThierry Reding pm_runtime_get_sync(dc->dev); 123833a8eb8dSThierry Reding 123933a8eb8dSThierry Reding /* initialize display controller */ 124033a8eb8dSThierry Reding if (dc->syncpt) { 124133a8eb8dSThierry Reding u32 syncpt = host1x_syncpt_id(dc->syncpt); 124233a8eb8dSThierry Reding 124333a8eb8dSThierry Reding value = SYNCPT_CNTRL_NO_STALL; 124433a8eb8dSThierry Reding tegra_dc_writel(dc, value, DC_CMD_GENERAL_INCR_SYNCPT_CNTRL); 124533a8eb8dSThierry Reding 124633a8eb8dSThierry Reding value = SYNCPT_VSYNC_ENABLE | syncpt; 124733a8eb8dSThierry Reding tegra_dc_writel(dc, value, DC_CMD_CONT_SYNCPT_VSYNC); 124833a8eb8dSThierry Reding } 124933a8eb8dSThierry Reding 125033a8eb8dSThierry Reding value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT | 125133a8eb8dSThierry Reding WIN_A_OF_INT | WIN_B_OF_INT | WIN_C_OF_INT; 125233a8eb8dSThierry Reding tegra_dc_writel(dc, value, DC_CMD_INT_TYPE); 125333a8eb8dSThierry Reding 125433a8eb8dSThierry Reding value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT | 125533a8eb8dSThierry Reding WIN_A_OF_INT | WIN_B_OF_INT | WIN_C_OF_INT; 125633a8eb8dSThierry Reding tegra_dc_writel(dc, value, DC_CMD_INT_POLARITY); 125733a8eb8dSThierry Reding 125833a8eb8dSThierry Reding /* initialize timer */ 125933a8eb8dSThierry Reding value = CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(0x20) | 126033a8eb8dSThierry Reding WINDOW_B_THRESHOLD(0x20) | WINDOW_C_THRESHOLD(0x20); 126133a8eb8dSThierry Reding tegra_dc_writel(dc, value, DC_DISP_DISP_MEM_HIGH_PRIORITY); 126233a8eb8dSThierry Reding 126333a8eb8dSThierry Reding value = CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(1) | 126433a8eb8dSThierry Reding WINDOW_B_THRESHOLD(1) | WINDOW_C_THRESHOLD(1); 126533a8eb8dSThierry Reding tegra_dc_writel(dc, value, DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER); 126633a8eb8dSThierry Reding 126733a8eb8dSThierry Reding value = VBLANK_INT | WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT | 126833a8eb8dSThierry Reding WIN_A_OF_INT | WIN_B_OF_INT | WIN_C_OF_INT; 126933a8eb8dSThierry Reding tegra_dc_writel(dc, value, DC_CMD_INT_ENABLE); 127033a8eb8dSThierry Reding 127133a8eb8dSThierry Reding value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT | 127233a8eb8dSThierry Reding WIN_A_OF_INT | WIN_B_OF_INT | WIN_C_OF_INT; 127333a8eb8dSThierry Reding tegra_dc_writel(dc, value, DC_CMD_INT_MASK); 127433a8eb8dSThierry Reding 127533a8eb8dSThierry Reding if (dc->soc->supports_border_color) 127633a8eb8dSThierry Reding tegra_dc_writel(dc, 0, DC_DISP_BORDER_COLOR); 127733a8eb8dSThierry Reding 127833a8eb8dSThierry Reding /* apply PLL and pixel clock changes */ 127976d59ed0SThierry Reding tegra_dc_commit_state(dc, state); 128076d59ed0SThierry Reding 1281dee8268fSThierry Reding /* program display mode */ 1282dee8268fSThierry Reding tegra_dc_set_timings(dc, mode); 1283dee8268fSThierry Reding 12848620fc62SThierry Reding /* interlacing isn't supported yet, so disable it */ 12858620fc62SThierry Reding if (dc->soc->supports_interlacing) { 12868620fc62SThierry Reding value = tegra_dc_readl(dc, DC_DISP_INTERLACE_CONTROL); 12878620fc62SThierry Reding value &= ~INTERLACE_ENABLE; 12888620fc62SThierry Reding tegra_dc_writel(dc, value, DC_DISP_INTERLACE_CONTROL); 12898620fc62SThierry Reding } 1290666cb873SThierry Reding 1291666cb873SThierry Reding value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND); 1292666cb873SThierry Reding value &= ~DISP_CTRL_MODE_MASK; 1293666cb873SThierry Reding value |= DISP_CTRL_MODE_C_DISPLAY; 1294666cb873SThierry Reding tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND); 1295666cb873SThierry Reding 1296666cb873SThierry Reding value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL); 1297666cb873SThierry Reding value |= PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE | 1298666cb873SThierry Reding PW4_ENABLE | PM0_ENABLE | PM1_ENABLE; 1299666cb873SThierry Reding tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL); 1300666cb873SThierry Reding 1301666cb873SThierry Reding tegra_dc_commit(dc); 1302dee8268fSThierry Reding 13038ff64c17SThierry Reding drm_crtc_vblank_on(crtc); 1304dee8268fSThierry Reding } 1305dee8268fSThierry Reding 13064aa3df71SThierry Reding static int tegra_crtc_atomic_check(struct drm_crtc *crtc, 13074aa3df71SThierry Reding struct drm_crtc_state *state) 13084aa3df71SThierry Reding { 13094aa3df71SThierry Reding return 0; 13104aa3df71SThierry Reding } 13114aa3df71SThierry Reding 1312613d2b27SMaarten Lankhorst static void tegra_crtc_atomic_begin(struct drm_crtc *crtc, 1313613d2b27SMaarten Lankhorst struct drm_crtc_state *old_crtc_state) 13144aa3df71SThierry Reding { 13151503ca47SThierry Reding struct tegra_dc *dc = to_tegra_dc(crtc); 13161503ca47SThierry Reding 13171503ca47SThierry Reding if (crtc->state->event) { 13181503ca47SThierry Reding crtc->state->event->pipe = drm_crtc_index(crtc); 13191503ca47SThierry Reding 13201503ca47SThierry Reding WARN_ON(drm_crtc_vblank_get(crtc) != 0); 13211503ca47SThierry Reding 13221503ca47SThierry Reding dc->event = crtc->state->event; 13231503ca47SThierry Reding crtc->state->event = NULL; 13241503ca47SThierry Reding } 13254aa3df71SThierry Reding } 13264aa3df71SThierry Reding 1327613d2b27SMaarten Lankhorst static void tegra_crtc_atomic_flush(struct drm_crtc *crtc, 1328613d2b27SMaarten Lankhorst struct drm_crtc_state *old_crtc_state) 13294aa3df71SThierry Reding { 133047802b09SThierry Reding struct tegra_dc_state *state = to_dc_state(crtc->state); 133147802b09SThierry Reding struct tegra_dc *dc = to_tegra_dc(crtc); 133247802b09SThierry Reding 133347802b09SThierry Reding tegra_dc_writel(dc, state->planes << 8, DC_CMD_STATE_CONTROL); 133447802b09SThierry Reding tegra_dc_writel(dc, state->planes, DC_CMD_STATE_CONTROL); 13354aa3df71SThierry Reding } 13364aa3df71SThierry Reding 1337dee8268fSThierry Reding static const struct drm_crtc_helper_funcs tegra_crtc_helper_funcs = { 13384aa3df71SThierry Reding .atomic_check = tegra_crtc_atomic_check, 13394aa3df71SThierry Reding .atomic_begin = tegra_crtc_atomic_begin, 13404aa3df71SThierry Reding .atomic_flush = tegra_crtc_atomic_flush, 13410b20a0f8SLaurent Pinchart .atomic_enable = tegra_crtc_atomic_enable, 134264581714SLaurent Pinchart .atomic_disable = tegra_crtc_atomic_disable, 1343dee8268fSThierry Reding }; 1344dee8268fSThierry Reding 1345dee8268fSThierry Reding static irqreturn_t tegra_dc_irq(int irq, void *data) 1346dee8268fSThierry Reding { 1347dee8268fSThierry Reding struct tegra_dc *dc = data; 1348dee8268fSThierry Reding unsigned long status; 1349dee8268fSThierry Reding 1350dee8268fSThierry Reding status = tegra_dc_readl(dc, DC_CMD_INT_STATUS); 1351dee8268fSThierry Reding tegra_dc_writel(dc, status, DC_CMD_INT_STATUS); 1352dee8268fSThierry Reding 1353dee8268fSThierry Reding if (status & FRAME_END_INT) { 1354dee8268fSThierry Reding /* 1355dee8268fSThierry Reding dev_dbg(dc->dev, "%s(): frame end\n", __func__); 1356dee8268fSThierry Reding */ 1357791ddb1eSThierry Reding dc->stats.frames++; 1358dee8268fSThierry Reding } 1359dee8268fSThierry Reding 1360dee8268fSThierry Reding if (status & VBLANK_INT) { 1361dee8268fSThierry Reding /* 1362dee8268fSThierry Reding dev_dbg(dc->dev, "%s(): vertical blank\n", __func__); 1363dee8268fSThierry Reding */ 1364ed7dae58SThierry Reding drm_crtc_handle_vblank(&dc->base); 1365dee8268fSThierry Reding tegra_dc_finish_page_flip(dc); 1366791ddb1eSThierry Reding dc->stats.vblank++; 1367dee8268fSThierry Reding } 1368dee8268fSThierry Reding 1369dee8268fSThierry Reding if (status & (WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT)) { 1370dee8268fSThierry Reding /* 1371dee8268fSThierry Reding dev_dbg(dc->dev, "%s(): underflow\n", __func__); 1372dee8268fSThierry Reding */ 1373791ddb1eSThierry Reding dc->stats.underflow++; 1374791ddb1eSThierry Reding } 1375791ddb1eSThierry Reding 1376791ddb1eSThierry Reding if (status & (WIN_A_OF_INT | WIN_B_OF_INT | WIN_C_OF_INT)) { 1377791ddb1eSThierry Reding /* 1378791ddb1eSThierry Reding dev_dbg(dc->dev, "%s(): overflow\n", __func__); 1379791ddb1eSThierry Reding */ 1380791ddb1eSThierry Reding dc->stats.overflow++; 1381dee8268fSThierry Reding } 1382dee8268fSThierry Reding 1383dee8268fSThierry Reding return IRQ_HANDLED; 1384dee8268fSThierry Reding } 1385dee8268fSThierry Reding 1386dee8268fSThierry Reding static int tegra_dc_show_regs(struct seq_file *s, void *data) 1387dee8268fSThierry Reding { 1388dee8268fSThierry Reding struct drm_info_node *node = s->private; 1389dee8268fSThierry Reding struct tegra_dc *dc = node->info_ent->data; 1390003fc848SThierry Reding int err = 0; 1391003fc848SThierry Reding 139299612b27SDaniel Vetter drm_modeset_lock(&dc->base.mutex, NULL); 1393003fc848SThierry Reding 1394003fc848SThierry Reding if (!dc->base.state->active) { 1395003fc848SThierry Reding err = -EBUSY; 1396003fc848SThierry Reding goto unlock; 1397003fc848SThierry Reding } 1398dee8268fSThierry Reding 1399dee8268fSThierry Reding #define DUMP_REG(name) \ 140003a60569SThierry Reding seq_printf(s, "%-40s %#05x %08x\n", #name, name, \ 1401dee8268fSThierry Reding tegra_dc_readl(dc, name)) 1402dee8268fSThierry Reding 1403dee8268fSThierry Reding DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT); 1404dee8268fSThierry Reding DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT_CNTRL); 1405dee8268fSThierry Reding DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT_ERROR); 1406dee8268fSThierry Reding DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT); 1407dee8268fSThierry Reding DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT_CNTRL); 1408dee8268fSThierry Reding DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT_ERROR); 1409dee8268fSThierry Reding DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT); 1410dee8268fSThierry Reding DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT_CNTRL); 1411dee8268fSThierry Reding DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT_ERROR); 1412dee8268fSThierry Reding DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT); 1413dee8268fSThierry Reding DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT_CNTRL); 1414dee8268fSThierry Reding DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT_ERROR); 1415dee8268fSThierry Reding DUMP_REG(DC_CMD_CONT_SYNCPT_VSYNC); 1416dee8268fSThierry Reding DUMP_REG(DC_CMD_DISPLAY_COMMAND_OPTION0); 1417dee8268fSThierry Reding DUMP_REG(DC_CMD_DISPLAY_COMMAND); 1418dee8268fSThierry Reding DUMP_REG(DC_CMD_SIGNAL_RAISE); 1419dee8268fSThierry Reding DUMP_REG(DC_CMD_DISPLAY_POWER_CONTROL); 1420dee8268fSThierry Reding DUMP_REG(DC_CMD_INT_STATUS); 1421dee8268fSThierry Reding DUMP_REG(DC_CMD_INT_MASK); 1422dee8268fSThierry Reding DUMP_REG(DC_CMD_INT_ENABLE); 1423dee8268fSThierry Reding DUMP_REG(DC_CMD_INT_TYPE); 1424dee8268fSThierry Reding DUMP_REG(DC_CMD_INT_POLARITY); 1425dee8268fSThierry Reding DUMP_REG(DC_CMD_SIGNAL_RAISE1); 1426dee8268fSThierry Reding DUMP_REG(DC_CMD_SIGNAL_RAISE2); 1427dee8268fSThierry Reding DUMP_REG(DC_CMD_SIGNAL_RAISE3); 1428dee8268fSThierry Reding DUMP_REG(DC_CMD_STATE_ACCESS); 1429dee8268fSThierry Reding DUMP_REG(DC_CMD_STATE_CONTROL); 1430dee8268fSThierry Reding DUMP_REG(DC_CMD_DISPLAY_WINDOW_HEADER); 1431dee8268fSThierry Reding DUMP_REG(DC_CMD_REG_ACT_CONTROL); 1432dee8268fSThierry Reding DUMP_REG(DC_COM_CRC_CONTROL); 1433dee8268fSThierry Reding DUMP_REG(DC_COM_CRC_CHECKSUM); 1434dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(0)); 1435dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(1)); 1436dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(2)); 1437dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(3)); 1438dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(0)); 1439dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(1)); 1440dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(2)); 1441dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(3)); 1442dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_DATA(0)); 1443dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_DATA(1)); 1444dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_DATA(2)); 1445dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_DATA(3)); 1446dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_INPUT_ENABLE(0)); 1447dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_INPUT_ENABLE(1)); 1448dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_INPUT_ENABLE(2)); 1449dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_INPUT_ENABLE(3)); 1450dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_INPUT_DATA(0)); 1451dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_INPUT_DATA(1)); 1452dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(0)); 1453dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(1)); 1454dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(2)); 1455dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(3)); 1456dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(4)); 1457dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(5)); 1458dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(6)); 1459dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_MISC_CONTROL); 1460dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_PM0_CONTROL); 1461dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_PM0_DUTY_CYCLE); 1462dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_PM1_CONTROL); 1463dee8268fSThierry Reding DUMP_REG(DC_COM_PIN_PM1_DUTY_CYCLE); 1464dee8268fSThierry Reding DUMP_REG(DC_COM_SPI_CONTROL); 1465dee8268fSThierry Reding DUMP_REG(DC_COM_SPI_START_BYTE); 1466dee8268fSThierry Reding DUMP_REG(DC_COM_HSPI_WRITE_DATA_AB); 1467dee8268fSThierry Reding DUMP_REG(DC_COM_HSPI_WRITE_DATA_CD); 1468dee8268fSThierry Reding DUMP_REG(DC_COM_HSPI_CS_DC); 1469dee8268fSThierry Reding DUMP_REG(DC_COM_SCRATCH_REGISTER_A); 1470dee8268fSThierry Reding DUMP_REG(DC_COM_SCRATCH_REGISTER_B); 1471dee8268fSThierry Reding DUMP_REG(DC_COM_GPIO_CTRL); 1472dee8268fSThierry Reding DUMP_REG(DC_COM_GPIO_DEBOUNCE_COUNTER); 1473dee8268fSThierry Reding DUMP_REG(DC_COM_CRC_CHECKSUM_LATCHED); 1474dee8268fSThierry Reding DUMP_REG(DC_DISP_DISP_SIGNAL_OPTIONS0); 1475dee8268fSThierry Reding DUMP_REG(DC_DISP_DISP_SIGNAL_OPTIONS1); 1476dee8268fSThierry Reding DUMP_REG(DC_DISP_DISP_WIN_OPTIONS); 1477dee8268fSThierry Reding DUMP_REG(DC_DISP_DISP_MEM_HIGH_PRIORITY); 1478dee8268fSThierry Reding DUMP_REG(DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER); 1479dee8268fSThierry Reding DUMP_REG(DC_DISP_DISP_TIMING_OPTIONS); 1480dee8268fSThierry Reding DUMP_REG(DC_DISP_REF_TO_SYNC); 1481dee8268fSThierry Reding DUMP_REG(DC_DISP_SYNC_WIDTH); 1482dee8268fSThierry Reding DUMP_REG(DC_DISP_BACK_PORCH); 1483dee8268fSThierry Reding DUMP_REG(DC_DISP_ACTIVE); 1484dee8268fSThierry Reding DUMP_REG(DC_DISP_FRONT_PORCH); 1485dee8268fSThierry Reding DUMP_REG(DC_DISP_H_PULSE0_CONTROL); 1486dee8268fSThierry Reding DUMP_REG(DC_DISP_H_PULSE0_POSITION_A); 1487dee8268fSThierry Reding DUMP_REG(DC_DISP_H_PULSE0_POSITION_B); 1488dee8268fSThierry Reding DUMP_REG(DC_DISP_H_PULSE0_POSITION_C); 1489dee8268fSThierry Reding DUMP_REG(DC_DISP_H_PULSE0_POSITION_D); 1490dee8268fSThierry Reding DUMP_REG(DC_DISP_H_PULSE1_CONTROL); 1491dee8268fSThierry Reding DUMP_REG(DC_DISP_H_PULSE1_POSITION_A); 1492dee8268fSThierry Reding DUMP_REG(DC_DISP_H_PULSE1_POSITION_B); 1493dee8268fSThierry Reding DUMP_REG(DC_DISP_H_PULSE1_POSITION_C); 1494dee8268fSThierry Reding DUMP_REG(DC_DISP_H_PULSE1_POSITION_D); 1495dee8268fSThierry Reding DUMP_REG(DC_DISP_H_PULSE2_CONTROL); 1496dee8268fSThierry Reding DUMP_REG(DC_DISP_H_PULSE2_POSITION_A); 1497dee8268fSThierry Reding DUMP_REG(DC_DISP_H_PULSE2_POSITION_B); 1498dee8268fSThierry Reding DUMP_REG(DC_DISP_H_PULSE2_POSITION_C); 1499dee8268fSThierry Reding DUMP_REG(DC_DISP_H_PULSE2_POSITION_D); 1500dee8268fSThierry Reding DUMP_REG(DC_DISP_V_PULSE0_CONTROL); 1501dee8268fSThierry Reding DUMP_REG(DC_DISP_V_PULSE0_POSITION_A); 1502dee8268fSThierry Reding DUMP_REG(DC_DISP_V_PULSE0_POSITION_B); 1503dee8268fSThierry Reding DUMP_REG(DC_DISP_V_PULSE0_POSITION_C); 1504dee8268fSThierry Reding DUMP_REG(DC_DISP_V_PULSE1_CONTROL); 1505dee8268fSThierry Reding DUMP_REG(DC_DISP_V_PULSE1_POSITION_A); 1506dee8268fSThierry Reding DUMP_REG(DC_DISP_V_PULSE1_POSITION_B); 1507dee8268fSThierry Reding DUMP_REG(DC_DISP_V_PULSE1_POSITION_C); 1508dee8268fSThierry Reding DUMP_REG(DC_DISP_V_PULSE2_CONTROL); 1509dee8268fSThierry Reding DUMP_REG(DC_DISP_V_PULSE2_POSITION_A); 1510dee8268fSThierry Reding DUMP_REG(DC_DISP_V_PULSE3_CONTROL); 1511dee8268fSThierry Reding DUMP_REG(DC_DISP_V_PULSE3_POSITION_A); 1512dee8268fSThierry Reding DUMP_REG(DC_DISP_M0_CONTROL); 1513dee8268fSThierry Reding DUMP_REG(DC_DISP_M1_CONTROL); 1514dee8268fSThierry Reding DUMP_REG(DC_DISP_DI_CONTROL); 1515dee8268fSThierry Reding DUMP_REG(DC_DISP_PP_CONTROL); 1516dee8268fSThierry Reding DUMP_REG(DC_DISP_PP_SELECT_A); 1517dee8268fSThierry Reding DUMP_REG(DC_DISP_PP_SELECT_B); 1518dee8268fSThierry Reding DUMP_REG(DC_DISP_PP_SELECT_C); 1519dee8268fSThierry Reding DUMP_REG(DC_DISP_PP_SELECT_D); 1520dee8268fSThierry Reding DUMP_REG(DC_DISP_DISP_CLOCK_CONTROL); 1521dee8268fSThierry Reding DUMP_REG(DC_DISP_DISP_INTERFACE_CONTROL); 1522dee8268fSThierry Reding DUMP_REG(DC_DISP_DISP_COLOR_CONTROL); 1523dee8268fSThierry Reding DUMP_REG(DC_DISP_SHIFT_CLOCK_OPTIONS); 1524dee8268fSThierry Reding DUMP_REG(DC_DISP_DATA_ENABLE_OPTIONS); 1525dee8268fSThierry Reding DUMP_REG(DC_DISP_SERIAL_INTERFACE_OPTIONS); 1526dee8268fSThierry Reding DUMP_REG(DC_DISP_LCD_SPI_OPTIONS); 1527dee8268fSThierry Reding DUMP_REG(DC_DISP_BORDER_COLOR); 1528dee8268fSThierry Reding DUMP_REG(DC_DISP_COLOR_KEY0_LOWER); 1529dee8268fSThierry Reding DUMP_REG(DC_DISP_COLOR_KEY0_UPPER); 1530dee8268fSThierry Reding DUMP_REG(DC_DISP_COLOR_KEY1_LOWER); 1531dee8268fSThierry Reding DUMP_REG(DC_DISP_COLOR_KEY1_UPPER); 1532dee8268fSThierry Reding DUMP_REG(DC_DISP_CURSOR_FOREGROUND); 1533dee8268fSThierry Reding DUMP_REG(DC_DISP_CURSOR_BACKGROUND); 1534dee8268fSThierry Reding DUMP_REG(DC_DISP_CURSOR_START_ADDR); 1535dee8268fSThierry Reding DUMP_REG(DC_DISP_CURSOR_START_ADDR_NS); 1536dee8268fSThierry Reding DUMP_REG(DC_DISP_CURSOR_POSITION); 1537dee8268fSThierry Reding DUMP_REG(DC_DISP_CURSOR_POSITION_NS); 1538dee8268fSThierry Reding DUMP_REG(DC_DISP_INIT_SEQ_CONTROL); 1539dee8268fSThierry Reding DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_A); 1540dee8268fSThierry Reding DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_B); 1541dee8268fSThierry Reding DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_C); 1542dee8268fSThierry Reding DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_D); 1543dee8268fSThierry Reding DUMP_REG(DC_DISP_DC_MCCIF_FIFOCTRL); 1544dee8268fSThierry Reding DUMP_REG(DC_DISP_MCCIF_DISPLAY0A_HYST); 1545dee8268fSThierry Reding DUMP_REG(DC_DISP_MCCIF_DISPLAY0B_HYST); 1546dee8268fSThierry Reding DUMP_REG(DC_DISP_MCCIF_DISPLAY1A_HYST); 1547dee8268fSThierry Reding DUMP_REG(DC_DISP_MCCIF_DISPLAY1B_HYST); 1548dee8268fSThierry Reding DUMP_REG(DC_DISP_DAC_CRT_CTRL); 1549dee8268fSThierry Reding DUMP_REG(DC_DISP_DISP_MISC_CONTROL); 1550dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_CONTROL); 1551dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_CSC_COEFF); 1552dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_LUT(0)); 1553dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_LUT(1)); 1554dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_LUT(2)); 1555dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_LUT(3)); 1556dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_LUT(4)); 1557dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_LUT(5)); 1558dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_LUT(6)); 1559dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_LUT(7)); 1560dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_LUT(8)); 1561dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_FLICKER_CONTROL); 1562dee8268fSThierry Reding DUMP_REG(DC_DISP_DC_PIXEL_COUNT); 1563dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_HISTOGRAM(0)); 1564dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_HISTOGRAM(1)); 1565dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_HISTOGRAM(2)); 1566dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_HISTOGRAM(3)); 1567dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_HISTOGRAM(4)); 1568dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_HISTOGRAM(5)); 1569dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_HISTOGRAM(6)); 1570dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_HISTOGRAM(7)); 1571dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_BL_TF(0)); 1572dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_BL_TF(1)); 1573dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_BL_TF(2)); 1574dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_BL_TF(3)); 1575dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_BL_CONTROL); 1576dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_HW_K_VALUES); 1577dee8268fSThierry Reding DUMP_REG(DC_DISP_SD_MAN_K_VALUES); 1578e687651bSThierry Reding DUMP_REG(DC_DISP_CURSOR_START_ADDR_HI); 1579e687651bSThierry Reding DUMP_REG(DC_DISP_BLEND_CURSOR_CONTROL); 1580dee8268fSThierry Reding DUMP_REG(DC_WIN_WIN_OPTIONS); 1581dee8268fSThierry Reding DUMP_REG(DC_WIN_BYTE_SWAP); 1582dee8268fSThierry Reding DUMP_REG(DC_WIN_BUFFER_CONTROL); 1583dee8268fSThierry Reding DUMP_REG(DC_WIN_COLOR_DEPTH); 1584dee8268fSThierry Reding DUMP_REG(DC_WIN_POSITION); 1585dee8268fSThierry Reding DUMP_REG(DC_WIN_SIZE); 1586dee8268fSThierry Reding DUMP_REG(DC_WIN_PRESCALED_SIZE); 1587dee8268fSThierry Reding DUMP_REG(DC_WIN_H_INITIAL_DDA); 1588dee8268fSThierry Reding DUMP_REG(DC_WIN_V_INITIAL_DDA); 1589dee8268fSThierry Reding DUMP_REG(DC_WIN_DDA_INC); 1590dee8268fSThierry Reding DUMP_REG(DC_WIN_LINE_STRIDE); 1591dee8268fSThierry Reding DUMP_REG(DC_WIN_BUF_STRIDE); 1592dee8268fSThierry Reding DUMP_REG(DC_WIN_UV_BUF_STRIDE); 1593dee8268fSThierry Reding DUMP_REG(DC_WIN_BUFFER_ADDR_MODE); 1594dee8268fSThierry Reding DUMP_REG(DC_WIN_DV_CONTROL); 1595dee8268fSThierry Reding DUMP_REG(DC_WIN_BLEND_NOKEY); 1596dee8268fSThierry Reding DUMP_REG(DC_WIN_BLEND_1WIN); 1597dee8268fSThierry Reding DUMP_REG(DC_WIN_BLEND_2WIN_X); 1598dee8268fSThierry Reding DUMP_REG(DC_WIN_BLEND_2WIN_Y); 1599dee8268fSThierry Reding DUMP_REG(DC_WIN_BLEND_3WIN_XY); 1600dee8268fSThierry Reding DUMP_REG(DC_WIN_HP_FETCH_CONTROL); 1601dee8268fSThierry Reding DUMP_REG(DC_WINBUF_START_ADDR); 1602dee8268fSThierry Reding DUMP_REG(DC_WINBUF_START_ADDR_NS); 1603dee8268fSThierry Reding DUMP_REG(DC_WINBUF_START_ADDR_U); 1604dee8268fSThierry Reding DUMP_REG(DC_WINBUF_START_ADDR_U_NS); 1605dee8268fSThierry Reding DUMP_REG(DC_WINBUF_START_ADDR_V); 1606dee8268fSThierry Reding DUMP_REG(DC_WINBUF_START_ADDR_V_NS); 1607dee8268fSThierry Reding DUMP_REG(DC_WINBUF_ADDR_H_OFFSET); 1608dee8268fSThierry Reding DUMP_REG(DC_WINBUF_ADDR_H_OFFSET_NS); 1609dee8268fSThierry Reding DUMP_REG(DC_WINBUF_ADDR_V_OFFSET); 1610dee8268fSThierry Reding DUMP_REG(DC_WINBUF_ADDR_V_OFFSET_NS); 1611dee8268fSThierry Reding DUMP_REG(DC_WINBUF_UFLOW_STATUS); 1612dee8268fSThierry Reding DUMP_REG(DC_WINBUF_AD_UFLOW_STATUS); 1613dee8268fSThierry Reding DUMP_REG(DC_WINBUF_BD_UFLOW_STATUS); 1614dee8268fSThierry Reding DUMP_REG(DC_WINBUF_CD_UFLOW_STATUS); 1615dee8268fSThierry Reding 1616dee8268fSThierry Reding #undef DUMP_REG 1617dee8268fSThierry Reding 1618003fc848SThierry Reding unlock: 161999612b27SDaniel Vetter drm_modeset_unlock(&dc->base.mutex); 1620003fc848SThierry Reding return err; 1621dee8268fSThierry Reding } 1622dee8268fSThierry Reding 16236ca1f62fSThierry Reding static int tegra_dc_show_crc(struct seq_file *s, void *data) 16246ca1f62fSThierry Reding { 16256ca1f62fSThierry Reding struct drm_info_node *node = s->private; 16266ca1f62fSThierry Reding struct tegra_dc *dc = node->info_ent->data; 1627003fc848SThierry Reding int err = 0; 16286ca1f62fSThierry Reding u32 value; 16296ca1f62fSThierry Reding 163099612b27SDaniel Vetter drm_modeset_lock(&dc->base.mutex, NULL); 1631003fc848SThierry Reding 1632003fc848SThierry Reding if (!dc->base.state->active) { 1633003fc848SThierry Reding err = -EBUSY; 1634003fc848SThierry Reding goto unlock; 1635003fc848SThierry Reding } 1636003fc848SThierry Reding 16376ca1f62fSThierry Reding value = DC_COM_CRC_CONTROL_ACTIVE_DATA | DC_COM_CRC_CONTROL_ENABLE; 16386ca1f62fSThierry Reding tegra_dc_writel(dc, value, DC_COM_CRC_CONTROL); 16396ca1f62fSThierry Reding tegra_dc_commit(dc); 16406ca1f62fSThierry Reding 16416ca1f62fSThierry Reding drm_crtc_wait_one_vblank(&dc->base); 16426ca1f62fSThierry Reding drm_crtc_wait_one_vblank(&dc->base); 16436ca1f62fSThierry Reding 16446ca1f62fSThierry Reding value = tegra_dc_readl(dc, DC_COM_CRC_CHECKSUM); 16456ca1f62fSThierry Reding seq_printf(s, "%08x\n", value); 16466ca1f62fSThierry Reding 16476ca1f62fSThierry Reding tegra_dc_writel(dc, 0, DC_COM_CRC_CONTROL); 16486ca1f62fSThierry Reding 1649003fc848SThierry Reding unlock: 165099612b27SDaniel Vetter drm_modeset_unlock(&dc->base.mutex); 1651003fc848SThierry Reding return err; 16526ca1f62fSThierry Reding } 16536ca1f62fSThierry Reding 1654791ddb1eSThierry Reding static int tegra_dc_show_stats(struct seq_file *s, void *data) 1655791ddb1eSThierry Reding { 1656791ddb1eSThierry Reding struct drm_info_node *node = s->private; 1657791ddb1eSThierry Reding struct tegra_dc *dc = node->info_ent->data; 1658791ddb1eSThierry Reding 1659791ddb1eSThierry Reding seq_printf(s, "frames: %lu\n", dc->stats.frames); 1660791ddb1eSThierry Reding seq_printf(s, "vblank: %lu\n", dc->stats.vblank); 1661791ddb1eSThierry Reding seq_printf(s, "underflow: %lu\n", dc->stats.underflow); 1662791ddb1eSThierry Reding seq_printf(s, "overflow: %lu\n", dc->stats.overflow); 1663791ddb1eSThierry Reding 1664dee8268fSThierry Reding return 0; 1665dee8268fSThierry Reding } 1666dee8268fSThierry Reding 1667dee8268fSThierry Reding static struct drm_info_list debugfs_files[] = { 1668dee8268fSThierry Reding { "regs", tegra_dc_show_regs, 0, NULL }, 16696ca1f62fSThierry Reding { "crc", tegra_dc_show_crc, 0, NULL }, 1670791ddb1eSThierry Reding { "stats", tegra_dc_show_stats, 0, NULL }, 1671dee8268fSThierry Reding }; 1672dee8268fSThierry Reding 1673dee8268fSThierry Reding static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor) 1674dee8268fSThierry Reding { 1675dee8268fSThierry Reding unsigned int i; 1676dee8268fSThierry Reding char *name; 1677dee8268fSThierry Reding int err; 1678dee8268fSThierry Reding 1679dee8268fSThierry Reding name = kasprintf(GFP_KERNEL, "dc.%d", dc->pipe); 1680dee8268fSThierry Reding dc->debugfs = debugfs_create_dir(name, minor->debugfs_root); 1681dee8268fSThierry Reding kfree(name); 1682dee8268fSThierry Reding 1683dee8268fSThierry Reding if (!dc->debugfs) 1684dee8268fSThierry Reding return -ENOMEM; 1685dee8268fSThierry Reding 1686dee8268fSThierry Reding dc->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files), 1687dee8268fSThierry Reding GFP_KERNEL); 1688dee8268fSThierry Reding if (!dc->debugfs_files) { 1689dee8268fSThierry Reding err = -ENOMEM; 1690dee8268fSThierry Reding goto remove; 1691dee8268fSThierry Reding } 1692dee8268fSThierry Reding 1693dee8268fSThierry Reding for (i = 0; i < ARRAY_SIZE(debugfs_files); i++) 1694dee8268fSThierry Reding dc->debugfs_files[i].data = dc; 1695dee8268fSThierry Reding 1696dee8268fSThierry Reding err = drm_debugfs_create_files(dc->debugfs_files, 1697dee8268fSThierry Reding ARRAY_SIZE(debugfs_files), 1698dee8268fSThierry Reding dc->debugfs, minor); 1699dee8268fSThierry Reding if (err < 0) 1700dee8268fSThierry Reding goto free; 1701dee8268fSThierry Reding 1702dee8268fSThierry Reding dc->minor = minor; 1703dee8268fSThierry Reding 1704dee8268fSThierry Reding return 0; 1705dee8268fSThierry Reding 1706dee8268fSThierry Reding free: 1707dee8268fSThierry Reding kfree(dc->debugfs_files); 1708dee8268fSThierry Reding dc->debugfs_files = NULL; 1709dee8268fSThierry Reding remove: 1710dee8268fSThierry Reding debugfs_remove(dc->debugfs); 1711dee8268fSThierry Reding dc->debugfs = NULL; 1712dee8268fSThierry Reding 1713dee8268fSThierry Reding return err; 1714dee8268fSThierry Reding } 1715dee8268fSThierry Reding 1716dee8268fSThierry Reding static int tegra_dc_debugfs_exit(struct tegra_dc *dc) 1717dee8268fSThierry Reding { 1718dee8268fSThierry Reding drm_debugfs_remove_files(dc->debugfs_files, ARRAY_SIZE(debugfs_files), 1719dee8268fSThierry Reding dc->minor); 1720dee8268fSThierry Reding dc->minor = NULL; 1721dee8268fSThierry Reding 1722dee8268fSThierry Reding kfree(dc->debugfs_files); 1723dee8268fSThierry Reding dc->debugfs_files = NULL; 1724dee8268fSThierry Reding 1725dee8268fSThierry Reding debugfs_remove(dc->debugfs); 1726dee8268fSThierry Reding dc->debugfs = NULL; 1727dee8268fSThierry Reding 1728dee8268fSThierry Reding return 0; 1729dee8268fSThierry Reding } 1730dee8268fSThierry Reding 1731dee8268fSThierry Reding static int tegra_dc_init(struct host1x_client *client) 1732dee8268fSThierry Reding { 17339910f5c4SThierry Reding struct drm_device *drm = dev_get_drvdata(client->parent); 17342bcdcbfaSThierry Reding unsigned long flags = HOST1X_SYNCPT_CLIENT_MANAGED; 1735dee8268fSThierry Reding struct tegra_dc *dc = host1x_client_to_dc(client); 1736d1f3e1e0SThierry Reding struct tegra_drm *tegra = drm->dev_private; 1737c7679306SThierry Reding struct drm_plane *primary = NULL; 1738c7679306SThierry Reding struct drm_plane *cursor = NULL; 1739dee8268fSThierry Reding int err; 1740dee8268fSThierry Reding 1741617dd7ccSThierry Reding dc->syncpt = host1x_syncpt_request(client, flags); 17422bcdcbfaSThierry Reding if (!dc->syncpt) 17432bcdcbfaSThierry Reding dev_warn(dc->dev, "failed to allocate syncpoint\n"); 17442bcdcbfaSThierry Reding 1745df06b759SThierry Reding if (tegra->domain) { 1746df06b759SThierry Reding err = iommu_attach_device(tegra->domain, dc->dev); 1747df06b759SThierry Reding if (err < 0) { 1748df06b759SThierry Reding dev_err(dc->dev, "failed to attach to domain: %d\n", 1749df06b759SThierry Reding err); 1750df06b759SThierry Reding return err; 1751df06b759SThierry Reding } 1752df06b759SThierry Reding 1753df06b759SThierry Reding dc->domain = tegra->domain; 1754df06b759SThierry Reding } 1755df06b759SThierry Reding 1756c7679306SThierry Reding primary = tegra_dc_primary_plane_create(drm, dc); 1757c7679306SThierry Reding if (IS_ERR(primary)) { 1758c7679306SThierry Reding err = PTR_ERR(primary); 1759c7679306SThierry Reding goto cleanup; 1760c7679306SThierry Reding } 1761c7679306SThierry Reding 1762c7679306SThierry Reding if (dc->soc->supports_cursor) { 1763c7679306SThierry Reding cursor = tegra_dc_cursor_plane_create(drm, dc); 1764c7679306SThierry Reding if (IS_ERR(cursor)) { 1765c7679306SThierry Reding err = PTR_ERR(cursor); 1766c7679306SThierry Reding goto cleanup; 1767c7679306SThierry Reding } 1768c7679306SThierry Reding } 1769c7679306SThierry Reding 1770c7679306SThierry Reding err = drm_crtc_init_with_planes(drm, &dc->base, primary, cursor, 1771f9882876SVille Syrjälä &tegra_crtc_funcs, NULL); 1772c7679306SThierry Reding if (err < 0) 1773c7679306SThierry Reding goto cleanup; 1774c7679306SThierry Reding 1775dee8268fSThierry Reding drm_crtc_helper_add(&dc->base, &tegra_crtc_helper_funcs); 1776dee8268fSThierry Reding 1777d1f3e1e0SThierry Reding /* 1778d1f3e1e0SThierry Reding * Keep track of the minimum pitch alignment across all display 1779d1f3e1e0SThierry Reding * controllers. 1780d1f3e1e0SThierry Reding */ 1781d1f3e1e0SThierry Reding if (dc->soc->pitch_align > tegra->pitch_align) 1782d1f3e1e0SThierry Reding tegra->pitch_align = dc->soc->pitch_align; 1783d1f3e1e0SThierry Reding 17849910f5c4SThierry Reding err = tegra_dc_rgb_init(drm, dc); 1785dee8268fSThierry Reding if (err < 0 && err != -ENODEV) { 1786dee8268fSThierry Reding dev_err(dc->dev, "failed to initialize RGB output: %d\n", err); 1787c7679306SThierry Reding goto cleanup; 1788dee8268fSThierry Reding } 1789dee8268fSThierry Reding 17909910f5c4SThierry Reding err = tegra_dc_add_planes(drm, dc); 1791dee8268fSThierry Reding if (err < 0) 1792c7679306SThierry Reding goto cleanup; 1793dee8268fSThierry Reding 1794dee8268fSThierry Reding if (IS_ENABLED(CONFIG_DEBUG_FS)) { 17959910f5c4SThierry Reding err = tegra_dc_debugfs_init(dc, drm->primary); 1796dee8268fSThierry Reding if (err < 0) 1797dee8268fSThierry Reding dev_err(dc->dev, "debugfs setup failed: %d\n", err); 1798dee8268fSThierry Reding } 1799dee8268fSThierry Reding 1800dee8268fSThierry Reding err = devm_request_irq(dc->dev, dc->irq, tegra_dc_irq, 0, 1801dee8268fSThierry Reding dev_name(dc->dev), dc); 1802dee8268fSThierry Reding if (err < 0) { 1803dee8268fSThierry Reding dev_err(dc->dev, "failed to request IRQ#%u: %d\n", dc->irq, 1804dee8268fSThierry Reding err); 1805c7679306SThierry Reding goto cleanup; 1806dee8268fSThierry Reding } 1807dee8268fSThierry Reding 1808dee8268fSThierry Reding return 0; 1809c7679306SThierry Reding 1810c7679306SThierry Reding cleanup: 1811c7679306SThierry Reding if (cursor) 1812c7679306SThierry Reding drm_plane_cleanup(cursor); 1813c7679306SThierry Reding 1814c7679306SThierry Reding if (primary) 1815c7679306SThierry Reding drm_plane_cleanup(primary); 1816c7679306SThierry Reding 1817c7679306SThierry Reding if (tegra->domain) { 1818c7679306SThierry Reding iommu_detach_device(tegra->domain, dc->dev); 1819c7679306SThierry Reding dc->domain = NULL; 1820c7679306SThierry Reding } 1821c7679306SThierry Reding 1822c7679306SThierry Reding return err; 1823dee8268fSThierry Reding } 1824dee8268fSThierry Reding 1825dee8268fSThierry Reding static int tegra_dc_exit(struct host1x_client *client) 1826dee8268fSThierry Reding { 1827dee8268fSThierry Reding struct tegra_dc *dc = host1x_client_to_dc(client); 1828dee8268fSThierry Reding int err; 1829dee8268fSThierry Reding 1830dee8268fSThierry Reding devm_free_irq(dc->dev, dc->irq, dc); 1831dee8268fSThierry Reding 1832dee8268fSThierry Reding if (IS_ENABLED(CONFIG_DEBUG_FS)) { 1833dee8268fSThierry Reding err = tegra_dc_debugfs_exit(dc); 1834dee8268fSThierry Reding if (err < 0) 1835dee8268fSThierry Reding dev_err(dc->dev, "debugfs cleanup failed: %d\n", err); 1836dee8268fSThierry Reding } 1837dee8268fSThierry Reding 1838dee8268fSThierry Reding err = tegra_dc_rgb_exit(dc); 1839dee8268fSThierry Reding if (err) { 1840dee8268fSThierry Reding dev_err(dc->dev, "failed to shutdown RGB output: %d\n", err); 1841dee8268fSThierry Reding return err; 1842dee8268fSThierry Reding } 1843dee8268fSThierry Reding 1844df06b759SThierry Reding if (dc->domain) { 1845df06b759SThierry Reding iommu_detach_device(dc->domain, dc->dev); 1846df06b759SThierry Reding dc->domain = NULL; 1847df06b759SThierry Reding } 1848df06b759SThierry Reding 18492bcdcbfaSThierry Reding host1x_syncpt_free(dc->syncpt); 18502bcdcbfaSThierry Reding 1851dee8268fSThierry Reding return 0; 1852dee8268fSThierry Reding } 1853dee8268fSThierry Reding 1854dee8268fSThierry Reding static const struct host1x_client_ops dc_client_ops = { 1855dee8268fSThierry Reding .init = tegra_dc_init, 1856dee8268fSThierry Reding .exit = tegra_dc_exit, 1857dee8268fSThierry Reding }; 1858dee8268fSThierry Reding 18598620fc62SThierry Reding static const struct tegra_dc_soc_info tegra20_dc_soc_info = { 186042d0659bSThierry Reding .supports_border_color = true, 18618620fc62SThierry Reding .supports_interlacing = false, 1862e687651bSThierry Reding .supports_cursor = false, 1863c134f019SThierry Reding .supports_block_linear = false, 1864d1f3e1e0SThierry Reding .pitch_align = 8, 18659c012700SThierry Reding .has_powergate = false, 18666ac1571bSDmitry Osipenko .broken_reset = true, 18678620fc62SThierry Reding }; 18688620fc62SThierry Reding 18698620fc62SThierry Reding static const struct tegra_dc_soc_info tegra30_dc_soc_info = { 187042d0659bSThierry Reding .supports_border_color = true, 18718620fc62SThierry Reding .supports_interlacing = false, 1872e687651bSThierry Reding .supports_cursor = false, 1873c134f019SThierry Reding .supports_block_linear = false, 1874d1f3e1e0SThierry Reding .pitch_align = 8, 18759c012700SThierry Reding .has_powergate = false, 18766ac1571bSDmitry Osipenko .broken_reset = false, 1877d1f3e1e0SThierry Reding }; 1878d1f3e1e0SThierry Reding 1879d1f3e1e0SThierry Reding static const struct tegra_dc_soc_info tegra114_dc_soc_info = { 188042d0659bSThierry Reding .supports_border_color = true, 1881d1f3e1e0SThierry Reding .supports_interlacing = false, 1882d1f3e1e0SThierry Reding .supports_cursor = false, 1883d1f3e1e0SThierry Reding .supports_block_linear = false, 1884d1f3e1e0SThierry Reding .pitch_align = 64, 18859c012700SThierry Reding .has_powergate = true, 18866ac1571bSDmitry Osipenko .broken_reset = false, 18878620fc62SThierry Reding }; 18888620fc62SThierry Reding 18898620fc62SThierry Reding static const struct tegra_dc_soc_info tegra124_dc_soc_info = { 189042d0659bSThierry Reding .supports_border_color = false, 18918620fc62SThierry Reding .supports_interlacing = true, 1892e687651bSThierry Reding .supports_cursor = true, 1893c134f019SThierry Reding .supports_block_linear = true, 1894d1f3e1e0SThierry Reding .pitch_align = 64, 18959c012700SThierry Reding .has_powergate = true, 18966ac1571bSDmitry Osipenko .broken_reset = false, 18978620fc62SThierry Reding }; 18988620fc62SThierry Reding 18995b4f516fSThierry Reding static const struct tegra_dc_soc_info tegra210_dc_soc_info = { 19005b4f516fSThierry Reding .supports_border_color = false, 19015b4f516fSThierry Reding .supports_interlacing = true, 19025b4f516fSThierry Reding .supports_cursor = true, 19035b4f516fSThierry Reding .supports_block_linear = true, 19045b4f516fSThierry Reding .pitch_align = 64, 19055b4f516fSThierry Reding .has_powergate = true, 19066ac1571bSDmitry Osipenko .broken_reset = false, 19075b4f516fSThierry Reding }; 19085b4f516fSThierry Reding 19098620fc62SThierry Reding static const struct of_device_id tegra_dc_of_match[] = { 19108620fc62SThierry Reding { 19115b4f516fSThierry Reding .compatible = "nvidia,tegra210-dc", 19125b4f516fSThierry Reding .data = &tegra210_dc_soc_info, 19135b4f516fSThierry Reding }, { 19148620fc62SThierry Reding .compatible = "nvidia,tegra124-dc", 19158620fc62SThierry Reding .data = &tegra124_dc_soc_info, 19168620fc62SThierry Reding }, { 19179c012700SThierry Reding .compatible = "nvidia,tegra114-dc", 19189c012700SThierry Reding .data = &tegra114_dc_soc_info, 19199c012700SThierry Reding }, { 19208620fc62SThierry Reding .compatible = "nvidia,tegra30-dc", 19218620fc62SThierry Reding .data = &tegra30_dc_soc_info, 19228620fc62SThierry Reding }, { 19238620fc62SThierry Reding .compatible = "nvidia,tegra20-dc", 19248620fc62SThierry Reding .data = &tegra20_dc_soc_info, 19258620fc62SThierry Reding }, { 19268620fc62SThierry Reding /* sentinel */ 19278620fc62SThierry Reding } 19288620fc62SThierry Reding }; 1929ef70728cSStephen Warren MODULE_DEVICE_TABLE(of, tegra_dc_of_match); 19308620fc62SThierry Reding 193113411dddSThierry Reding static int tegra_dc_parse_dt(struct tegra_dc *dc) 193213411dddSThierry Reding { 193313411dddSThierry Reding struct device_node *np; 193413411dddSThierry Reding u32 value = 0; 193513411dddSThierry Reding int err; 193613411dddSThierry Reding 193713411dddSThierry Reding err = of_property_read_u32(dc->dev->of_node, "nvidia,head", &value); 193813411dddSThierry Reding if (err < 0) { 193913411dddSThierry Reding dev_err(dc->dev, "missing \"nvidia,head\" property\n"); 194013411dddSThierry Reding 194113411dddSThierry Reding /* 194213411dddSThierry Reding * If the nvidia,head property isn't present, try to find the 194313411dddSThierry Reding * correct head number by looking up the position of this 194413411dddSThierry Reding * display controller's node within the device tree. Assuming 194513411dddSThierry Reding * that the nodes are ordered properly in the DTS file and 194613411dddSThierry Reding * that the translation into a flattened device tree blob 194713411dddSThierry Reding * preserves that ordering this will actually yield the right 194813411dddSThierry Reding * head number. 194913411dddSThierry Reding * 195013411dddSThierry Reding * If those assumptions don't hold, this will still work for 195113411dddSThierry Reding * cases where only a single display controller is used. 195213411dddSThierry Reding */ 195313411dddSThierry Reding for_each_matching_node(np, tegra_dc_of_match) { 1954cf6b1744SJulia Lawall if (np == dc->dev->of_node) { 1955cf6b1744SJulia Lawall of_node_put(np); 195613411dddSThierry Reding break; 1957cf6b1744SJulia Lawall } 195813411dddSThierry Reding 195913411dddSThierry Reding value++; 196013411dddSThierry Reding } 196113411dddSThierry Reding } 196213411dddSThierry Reding 196313411dddSThierry Reding dc->pipe = value; 196413411dddSThierry Reding 196513411dddSThierry Reding return 0; 196613411dddSThierry Reding } 196713411dddSThierry Reding 1968dee8268fSThierry Reding static int tegra_dc_probe(struct platform_device *pdev) 1969dee8268fSThierry Reding { 1970dee8268fSThierry Reding struct resource *regs; 1971dee8268fSThierry Reding struct tegra_dc *dc; 1972dee8268fSThierry Reding int err; 1973dee8268fSThierry Reding 1974dee8268fSThierry Reding dc = devm_kzalloc(&pdev->dev, sizeof(*dc), GFP_KERNEL); 1975dee8268fSThierry Reding if (!dc) 1976dee8268fSThierry Reding return -ENOMEM; 1977dee8268fSThierry Reding 1978b9ff7aeaSThierry Reding dc->soc = of_device_get_match_data(&pdev->dev); 19798620fc62SThierry Reding 1980dee8268fSThierry Reding spin_lock_init(&dc->lock); 1981dee8268fSThierry Reding INIT_LIST_HEAD(&dc->list); 1982dee8268fSThierry Reding dc->dev = &pdev->dev; 1983dee8268fSThierry Reding 198413411dddSThierry Reding err = tegra_dc_parse_dt(dc); 198513411dddSThierry Reding if (err < 0) 198613411dddSThierry Reding return err; 198713411dddSThierry Reding 1988dee8268fSThierry Reding dc->clk = devm_clk_get(&pdev->dev, NULL); 1989dee8268fSThierry Reding if (IS_ERR(dc->clk)) { 1990dee8268fSThierry Reding dev_err(&pdev->dev, "failed to get clock\n"); 1991dee8268fSThierry Reding return PTR_ERR(dc->clk); 1992dee8268fSThierry Reding } 1993dee8268fSThierry Reding 1994ca48080aSStephen Warren dc->rst = devm_reset_control_get(&pdev->dev, "dc"); 1995ca48080aSStephen Warren if (IS_ERR(dc->rst)) { 1996ca48080aSStephen Warren dev_err(&pdev->dev, "failed to get reset\n"); 1997ca48080aSStephen Warren return PTR_ERR(dc->rst); 1998ca48080aSStephen Warren } 1999ca48080aSStephen Warren 20006ac1571bSDmitry Osipenko if (!dc->soc->broken_reset) 200133a8eb8dSThierry Reding reset_control_assert(dc->rst); 200233a8eb8dSThierry Reding 20039c012700SThierry Reding if (dc->soc->has_powergate) { 20049c012700SThierry Reding if (dc->pipe == 0) 20059c012700SThierry Reding dc->powergate = TEGRA_POWERGATE_DIS; 20069c012700SThierry Reding else 20079c012700SThierry Reding dc->powergate = TEGRA_POWERGATE_DISB; 20089c012700SThierry Reding 200933a8eb8dSThierry Reding tegra_powergate_power_off(dc->powergate); 20109c012700SThierry Reding } 2011dee8268fSThierry Reding 2012dee8268fSThierry Reding regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2013dee8268fSThierry Reding dc->regs = devm_ioremap_resource(&pdev->dev, regs); 2014dee8268fSThierry Reding if (IS_ERR(dc->regs)) 2015dee8268fSThierry Reding return PTR_ERR(dc->regs); 2016dee8268fSThierry Reding 2017dee8268fSThierry Reding dc->irq = platform_get_irq(pdev, 0); 2018dee8268fSThierry Reding if (dc->irq < 0) { 2019dee8268fSThierry Reding dev_err(&pdev->dev, "failed to get IRQ\n"); 2020dee8268fSThierry Reding return -ENXIO; 2021dee8268fSThierry Reding } 2022dee8268fSThierry Reding 2023dee8268fSThierry Reding err = tegra_dc_rgb_probe(dc); 2024dee8268fSThierry Reding if (err < 0 && err != -ENODEV) { 2025dee8268fSThierry Reding dev_err(&pdev->dev, "failed to probe RGB output: %d\n", err); 2026dee8268fSThierry Reding return err; 2027dee8268fSThierry Reding } 2028dee8268fSThierry Reding 202933a8eb8dSThierry Reding platform_set_drvdata(pdev, dc); 203033a8eb8dSThierry Reding pm_runtime_enable(&pdev->dev); 203133a8eb8dSThierry Reding 203233a8eb8dSThierry Reding INIT_LIST_HEAD(&dc->client.list); 203333a8eb8dSThierry Reding dc->client.ops = &dc_client_ops; 203433a8eb8dSThierry Reding dc->client.dev = &pdev->dev; 203533a8eb8dSThierry Reding 2036dee8268fSThierry Reding err = host1x_client_register(&dc->client); 2037dee8268fSThierry Reding if (err < 0) { 2038dee8268fSThierry Reding dev_err(&pdev->dev, "failed to register host1x client: %d\n", 2039dee8268fSThierry Reding err); 2040dee8268fSThierry Reding return err; 2041dee8268fSThierry Reding } 2042dee8268fSThierry Reding 2043dee8268fSThierry Reding return 0; 2044dee8268fSThierry Reding } 2045dee8268fSThierry Reding 2046dee8268fSThierry Reding static int tegra_dc_remove(struct platform_device *pdev) 2047dee8268fSThierry Reding { 2048dee8268fSThierry Reding struct tegra_dc *dc = platform_get_drvdata(pdev); 2049dee8268fSThierry Reding int err; 2050dee8268fSThierry Reding 2051dee8268fSThierry Reding err = host1x_client_unregister(&dc->client); 2052dee8268fSThierry Reding if (err < 0) { 2053dee8268fSThierry Reding dev_err(&pdev->dev, "failed to unregister host1x client: %d\n", 2054dee8268fSThierry Reding err); 2055dee8268fSThierry Reding return err; 2056dee8268fSThierry Reding } 2057dee8268fSThierry Reding 205859d29c0eSThierry Reding err = tegra_dc_rgb_remove(dc); 205959d29c0eSThierry Reding if (err < 0) { 206059d29c0eSThierry Reding dev_err(&pdev->dev, "failed to remove RGB output: %d\n", err); 206159d29c0eSThierry Reding return err; 206259d29c0eSThierry Reding } 206359d29c0eSThierry Reding 206433a8eb8dSThierry Reding pm_runtime_disable(&pdev->dev); 206533a8eb8dSThierry Reding 206633a8eb8dSThierry Reding return 0; 206733a8eb8dSThierry Reding } 206833a8eb8dSThierry Reding 206933a8eb8dSThierry Reding #ifdef CONFIG_PM 207033a8eb8dSThierry Reding static int tegra_dc_suspend(struct device *dev) 207133a8eb8dSThierry Reding { 207233a8eb8dSThierry Reding struct tegra_dc *dc = dev_get_drvdata(dev); 207333a8eb8dSThierry Reding int err; 207433a8eb8dSThierry Reding 20756ac1571bSDmitry Osipenko if (!dc->soc->broken_reset) { 207633a8eb8dSThierry Reding err = reset_control_assert(dc->rst); 207733a8eb8dSThierry Reding if (err < 0) { 207833a8eb8dSThierry Reding dev_err(dev, "failed to assert reset: %d\n", err); 207933a8eb8dSThierry Reding return err; 208033a8eb8dSThierry Reding } 20816ac1571bSDmitry Osipenko } 20829c012700SThierry Reding 20839c012700SThierry Reding if (dc->soc->has_powergate) 20849c012700SThierry Reding tegra_powergate_power_off(dc->powergate); 20859c012700SThierry Reding 2086dee8268fSThierry Reding clk_disable_unprepare(dc->clk); 2087dee8268fSThierry Reding 2088dee8268fSThierry Reding return 0; 2089dee8268fSThierry Reding } 2090dee8268fSThierry Reding 209133a8eb8dSThierry Reding static int tegra_dc_resume(struct device *dev) 209233a8eb8dSThierry Reding { 209333a8eb8dSThierry Reding struct tegra_dc *dc = dev_get_drvdata(dev); 209433a8eb8dSThierry Reding int err; 209533a8eb8dSThierry Reding 209633a8eb8dSThierry Reding if (dc->soc->has_powergate) { 209733a8eb8dSThierry Reding err = tegra_powergate_sequence_power_up(dc->powergate, dc->clk, 209833a8eb8dSThierry Reding dc->rst); 209933a8eb8dSThierry Reding if (err < 0) { 210033a8eb8dSThierry Reding dev_err(dev, "failed to power partition: %d\n", err); 210133a8eb8dSThierry Reding return err; 210233a8eb8dSThierry Reding } 210333a8eb8dSThierry Reding } else { 210433a8eb8dSThierry Reding err = clk_prepare_enable(dc->clk); 210533a8eb8dSThierry Reding if (err < 0) { 210633a8eb8dSThierry Reding dev_err(dev, "failed to enable clock: %d\n", err); 210733a8eb8dSThierry Reding return err; 210833a8eb8dSThierry Reding } 210933a8eb8dSThierry Reding 21106ac1571bSDmitry Osipenko if (!dc->soc->broken_reset) { 211133a8eb8dSThierry Reding err = reset_control_deassert(dc->rst); 211233a8eb8dSThierry Reding if (err < 0) { 21136ac1571bSDmitry Osipenko dev_err(dev, 21146ac1571bSDmitry Osipenko "failed to deassert reset: %d\n", err); 211533a8eb8dSThierry Reding return err; 211633a8eb8dSThierry Reding } 211733a8eb8dSThierry Reding } 21186ac1571bSDmitry Osipenko } 211933a8eb8dSThierry Reding 212033a8eb8dSThierry Reding return 0; 212133a8eb8dSThierry Reding } 212233a8eb8dSThierry Reding #endif 212333a8eb8dSThierry Reding 212433a8eb8dSThierry Reding static const struct dev_pm_ops tegra_dc_pm_ops = { 212533a8eb8dSThierry Reding SET_RUNTIME_PM_OPS(tegra_dc_suspend, tegra_dc_resume, NULL) 212633a8eb8dSThierry Reding }; 212733a8eb8dSThierry Reding 2128dee8268fSThierry Reding struct platform_driver tegra_dc_driver = { 2129dee8268fSThierry Reding .driver = { 2130dee8268fSThierry Reding .name = "tegra-dc", 2131dee8268fSThierry Reding .of_match_table = tegra_dc_of_match, 213233a8eb8dSThierry Reding .pm = &tegra_dc_pm_ops, 2133dee8268fSThierry Reding }, 2134dee8268fSThierry Reding .probe = tegra_dc_probe, 2135dee8268fSThierry Reding .remove = tegra_dc_remove, 2136dee8268fSThierry Reding }; 2137