linux/drivers/gpu/drm/xlnx/zynqmp_disp.c

// SPDX-License-Identifier: GPL-2.0
/*
 * ZynqMP Display Controller Driver
 *
 * Copyright (C) 2017 - 2020 Xilinx, Inc.
 *
 * Authors:
 * - Hyun Woo Kwon <[email protected]>
 * - Laurent Pinchart <[email protected]>
 */

#include <drm/drm_fb_dma_helper.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_framebuffer.h>
#include <drm/drm_plane.h>

#include <linux/clk.h>
#include <linux/dma/xilinx_dpdma.h>
#include <linux/dma-mapping.h>
#include <linux/dmaengine.h>
#include <linux/media-bus-format.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/slab.h>

#include "zynqmp_disp.h"
#include "zynqmp_disp_regs.h"
#include "zynqmp_dp.h"
#include "zynqmp_dpsub.h"

/*
 * Overview
 * --------
 *
 * The display controller part of ZynqMP DP subsystem, made of the Audio/Video
 * Buffer Manager, the Video Rendering Pipeline (blender) and the Audio Mixer.
 *
 *              +------------------------------------------------------------+
 * +--------+   | +----------------+     +-----------+                       |
 * | DPDMA  | --->|                | --> |   Video   | Video +-------------+ |
 * | 4x vid |   | |                |     | Rendering | -+--> |             | |   +------+
 * | 2x aud |   | |  Audio/Video   | --> | Pipeline  |  |    | DisplayPort |---> | PHY0 |
 * +--------+   | | Buffer Manager |     +-----------+  |    |   Source    | |   +------+
 *              | |    and STC     |     +-----------+  |    | Controller  | |   +------+
 * Live Video --->|                | --> |   Audio   | Audio |             |---> | PHY1 |
 *              | |                |     |   Mixer   | --+-> |             | |   +------+
 * Live Audio --->|                | --> |           |  ||   +-------------+ |
 *              | +----------------+     +-----------+  ||                   |
 *              +---------------------------------------||-------------------+
 *                                                      vv
 *                                                Blended Video and
 *                                                Mixed Audio to PL
 *
 * Only non-live input from the DPDMA and output to the DisplayPort Source
 * Controller are currently supported. Interface with the programmable logic
 * for live streams is not implemented.
 *
 * The display controller code creates planes for the DPDMA video and graphics
 * layers, and a CRTC for the Video Rendering Pipeline.
 */

#define ZYNQMP_DISP_AV_BUF_NUM_VID_GFX_BUFFERS
#define ZYNQMP_DISP_AV_BUF_NUM_BUFFERS

#define ZYNQMP_DISP_MAX_NUM_SUB_PLANES

/**
 * enum zynqmp_dpsub_layer_mode - Layer mode
 * @ZYNQMP_DPSUB_LAYER_NONLIVE: non-live (memory) mode
 * @ZYNQMP_DPSUB_LAYER_LIVE: live (stream) mode
 */
enum zynqmp_dpsub_layer_mode {};

/**
 * struct zynqmp_disp_format - Display subsystem format information
 * @drm_fmt: DRM format (4CC)
 * @bus_fmt: Media bus format
 * @buf_fmt: AV buffer format
 * @swap: Flag to swap R & B for RGB formats, and U & V for YUV formats
 * @sf: Scaling factors for color components
 */
struct zynqmp_disp_format {};

/**
 * struct zynqmp_disp_layer_dma - DMA channel for one data plane of a layer
 * @chan: DMA channel
 * @xt: Interleaved DMA descriptor template
 * @sgl: Data chunk for dma_interleaved_template
 */
struct zynqmp_disp_layer_dma {};

/**
 * struct zynqmp_disp_layer_info - Static layer information
 * @formats: Array of supported formats
 * @num_formats: Number of formats in @formats array
 * @num_channels: Number of DMA channels
 */
struct zynqmp_disp_layer_info {};

/**
 * struct zynqmp_disp_layer - Display layer
 * @id: Layer ID
 * @disp: Back pointer to struct zynqmp_disp
 * @info: Static layer information
 * @dmas: DMA channels
 * @disp_fmt: Current format information
 * @drm_fmt: Current DRM format information
 * @mode: Current operation mode
 */
struct zynqmp_disp_layer {};

/**
 * struct zynqmp_disp - Display controller
 * @dev: Device structure
 * @dpsub: Display subsystem
 * @blend: Register I/O base address for the blender
 * @avbuf: Register I/O base address for the audio/video buffer manager
 * @audio: Registers I/O base address for the audio mixer
 * @layers: Layers (planes)
 */
struct zynqmp_disp {};

/* -----------------------------------------------------------------------------
 * Audio/Video Buffer Manager
 */

static const u32 scaling_factors_444[] =;

static const u32 scaling_factors_555[] =;

static const u32 scaling_factors_565[] =;

static const u32 scaling_factors_666[] =;

static const u32 scaling_factors_888[] =;

static const u32 scaling_factors_101010[] =;

/* List of video layer formats */
static const struct zynqmp_disp_format avbuf_vid_fmts[] =;

/* List of graphics layer formats */
static const struct zynqmp_disp_format avbuf_gfx_fmts[] =;

/* List of live video layer formats */
static const struct zynqmp_disp_format avbuf_live_fmts[] =;

static u32 zynqmp_disp_avbuf_read(struct zynqmp_disp *disp, int reg)
{}

static void zynqmp_disp_avbuf_write(struct zynqmp_disp *disp, int reg, u32 val)
{}

static bool zynqmp_disp_layer_is_video(const struct zynqmp_disp_layer *layer)
{}

/**
 * zynqmp_disp_avbuf_set_format - Set the input format for a layer
 * @disp: Display controller
 * @layer: The layer
 * @fmt: The format information
 *
 * Set the video buffer manager format for @layer to @fmt.
 */
static void zynqmp_disp_avbuf_set_format(struct zynqmp_disp *disp,
					 struct zynqmp_disp_layer *layer,
					 const struct zynqmp_disp_format *fmt)
{}

/**
 * zynqmp_disp_avbuf_set_clocks_sources - Set the clocks sources
 * @disp: Display controller
 * @video_from_ps: True if the video clock originates from the PS
 * @audio_from_ps: True if the audio clock originates from the PS
 * @timings_internal: True if video timings are generated internally
 *
 * Set the source for the video and audio clocks, as well as for the video
 * timings. Clocks can originate from the PS or PL, and timings can be
 * generated internally or externally.
 */
static void
zynqmp_disp_avbuf_set_clocks_sources(struct zynqmp_disp *disp,
				     bool video_from_ps, bool audio_from_ps,
				     bool timings_internal)
{}

/**
 * zynqmp_disp_avbuf_enable_channels - Enable buffer channels
 * @disp: Display controller
 *
 * Enable all (video and audio) buffer channels.
 */
static void zynqmp_disp_avbuf_enable_channels(struct zynqmp_disp *disp)
{}

/**
 * zynqmp_disp_avbuf_disable_channels - Disable buffer channels
 * @disp: Display controller
 *
 * Disable all (video and audio) buffer channels.
 */
static void zynqmp_disp_avbuf_disable_channels(struct zynqmp_disp *disp)
{}

/**
 * zynqmp_disp_avbuf_enable_audio - Enable audio
 * @disp: Display controller
 *
 * Enable all audio buffers with a non-live (memory) source.
 */
static void zynqmp_disp_avbuf_enable_audio(struct zynqmp_disp *disp)
{}

/**
 * zynqmp_disp_avbuf_disable_audio - Disable audio
 * @disp: Display controller
 *
 * Disable all audio buffers.
 */
static void zynqmp_disp_avbuf_disable_audio(struct zynqmp_disp *disp)
{}

/**
 * zynqmp_disp_avbuf_enable_video - Enable a video layer
 * @disp: Display controller
 * @layer: The layer
 *
 * Enable the video/graphics buffer for @layer.
 */
static void zynqmp_disp_avbuf_enable_video(struct zynqmp_disp *disp,
					   struct zynqmp_disp_layer *layer)
{}

/**
 * zynqmp_disp_avbuf_disable_video - Disable a video layer
 * @disp: Display controller
 * @layer: The layer
 *
 * Disable the video/graphics buffer for @layer.
 */
static void zynqmp_disp_avbuf_disable_video(struct zynqmp_disp *disp,
					    struct zynqmp_disp_layer *layer)
{}

/**
 * zynqmp_disp_avbuf_enable - Enable the video pipe
 * @disp: Display controller
 *
 * De-assert the video pipe reset.
 */
static void zynqmp_disp_avbuf_enable(struct zynqmp_disp *disp)
{}

/**
 * zynqmp_disp_avbuf_disable - Disable the video pipe
 * @disp: Display controller
 *
 * Assert the video pipe reset.
 */
static void zynqmp_disp_avbuf_disable(struct zynqmp_disp *disp)
{}

/* -----------------------------------------------------------------------------
 * Blender (Video Pipeline)
 */

static void zynqmp_disp_blend_write(struct zynqmp_disp *disp, int reg, u32 val)
{}

/*
 * Colorspace conversion matrices.
 *
 * Hardcode RGB <-> YUV conversion to full-range SDTV for now.
 */
static const u16 csc_zero_matrix[] =;

static const u16 csc_identity_matrix[] =;

static const u32 csc_zero_offsets[] =;

static const u16 csc_rgb_to_sdtv_matrix[] =;

static const u32 csc_rgb_to_sdtv_offsets[] =;

static const u16 csc_sdtv_to_rgb_matrix[] =;

static const u32 csc_sdtv_to_rgb_offsets[] =;

/**
 * zynqmp_disp_blend_set_output_format - Set the output format of the blender
 * @disp: Display controller
 * @format: Output format
 *
 * Set the output format of the blender to @format.
 */
static void zynqmp_disp_blend_set_output_format(struct zynqmp_disp *disp,
						enum zynqmp_dpsub_format format)
{}

/**
 * zynqmp_disp_blend_set_bg_color - Set the background color
 * @disp: Display controller
 * @rcr: Red/Cr color component
 * @gy: Green/Y color component
 * @bcb: Blue/Cb color component
 *
 * Set the background color to (@rcr, @gy, @bcb), corresponding to the R, G and
 * B or Cr, Y and Cb components respectively depending on the selected output
 * format.
 */
static void zynqmp_disp_blend_set_bg_color(struct zynqmp_disp *disp,
					   u32 rcr, u32 gy, u32 bcb)
{}

/**
 * zynqmp_disp_blend_set_global_alpha - Configure global alpha blending
 * @disp: Display controller
 * @enable: True to enable global alpha blending
 * @alpha: Global alpha value (ignored if @enabled is false)
 */
void zynqmp_disp_blend_set_global_alpha(struct zynqmp_disp *disp,
					bool enable, u32 alpha)
{}

/**
 * zynqmp_disp_blend_layer_set_csc - Configure colorspace conversion for layer
 * @disp: Display controller
 * @layer: The layer
 * @coeffs: Colorspace conversion matrix
 * @offsets: Colorspace conversion offsets
 *
 * Configure the input colorspace conversion matrix and offsets for the @layer.
 * Columns of the matrix are automatically swapped based on the input format to
 * handle RGB and YCrCb components permutations.
 */
static void zynqmp_disp_blend_layer_set_csc(struct zynqmp_disp *disp,
					    struct zynqmp_disp_layer *layer,
					    const u16 *coeffs,
					    const u32 *offsets)
{}

/**
 * zynqmp_disp_blend_layer_enable - Enable a layer
 * @disp: Display controller
 * @layer: The layer
 */
static void zynqmp_disp_blend_layer_enable(struct zynqmp_disp *disp,
					   struct zynqmp_disp_layer *layer)
{}

/**
 * zynqmp_disp_blend_layer_disable - Disable a layer
 * @disp: Display controller
 * @layer: The layer
 */
static void zynqmp_disp_blend_layer_disable(struct zynqmp_disp *disp,
					    struct zynqmp_disp_layer *layer)
{}

/* -----------------------------------------------------------------------------
 * Audio Mixer
 */

static void zynqmp_disp_audio_write(struct zynqmp_disp *disp, int reg, u32 val)
{}

/**
 * zynqmp_disp_audio_enable - Enable the audio mixer
 * @disp: Display controller
 *
 * Enable the audio mixer by de-asserting the soft reset. The audio state is set to
 * default values by the reset, set the default mixer volume explicitly.
 */
static void zynqmp_disp_audio_enable(struct zynqmp_disp *disp)
{}

/**
 * zynqmp_disp_audio_disable - Disable the audio mixer
 * @disp: Display controller
 *
 * Disable the audio mixer by asserting its soft reset.
 */
static void zynqmp_disp_audio_disable(struct zynqmp_disp *disp)
{}

/* -----------------------------------------------------------------------------
 * ZynqMP Display Layer & DRM Plane
 */

/**
 * zynqmp_disp_layer_find_format - Find format information for a DRM format
 * @layer: The layer
 * @drm_fmt: DRM format to search
 *
 * Search display subsystem format information corresponding to the given DRM
 * format @drm_fmt for the @layer, and return a pointer to the format
 * descriptor.
 *
 * Return: A pointer to the format descriptor if found, NULL otherwise
 */
static const struct zynqmp_disp_format *
zynqmp_disp_layer_find_format(struct zynqmp_disp_layer *layer,
			      u32 drm_fmt)
{}

/**
 * zynqmp_disp_layer_find_live_format - Find format information for given
 * media bus format
 * @layer: The layer
 * @media_bus_format: Media bus format to search
 *
 * Search display subsystem format information corresponding to the given media
 * bus format @media_bus_format for the @layer, and return a pointer to the
 * format descriptor.
 *
 * Return: A pointer to the format descriptor if found, NULL otherwise
 */
static const struct zynqmp_disp_format *
zynqmp_disp_layer_find_live_format(struct zynqmp_disp_layer *layer,
				   u32 media_bus_format)
{}

/**
 * zynqmp_disp_layer_drm_formats - Return the DRM formats supported by the layer
 * @layer: The layer
 * @num_formats: Pointer to the returned number of formats
 *
 * NOTE: This function doesn't make sense for live video layers and will
 * always return an empty list in such cases. zynqmp_disp_live_layer_formats()
 * should be used to query a list of media bus formats supported by the live
 * video input layer.
 *
 * Return: A newly allocated u32 array that stores all the DRM formats
 * supported by the layer. The number of formats in the array is returned
 * through the num_formats argument.
 */
u32 *zynqmp_disp_layer_drm_formats(struct zynqmp_disp_layer *layer,
				   unsigned int *num_formats)
{}

/**
 * zynqmp_disp_live_layer_formats - Return the media bus formats supported by
 * the live video layer
 * @layer: The layer
 * @num_formats: Pointer to the returned number of formats
 *
 * NOTE: This function should be used only for live video input layers.
 *
 * Return: A newly allocated u32 array of media bus formats supported by the
 * layer. The number of formats in the array is returned through the
 * @num_formats argument.
 */
u32 *zynqmp_disp_live_layer_formats(struct zynqmp_disp_layer *layer,
				    unsigned int *num_formats)
{}

/**
 * zynqmp_disp_layer_enable - Enable a layer
 * @layer: The layer
 *
 * Enable the @layer in the audio/video buffer manager and the blender. DMA
 * channels are started separately by zynqmp_disp_layer_update().
 */
void zynqmp_disp_layer_enable(struct zynqmp_disp_layer *layer)
{}

/**
 * zynqmp_disp_layer_disable - Disable the layer
 * @layer: The layer
 *
 * Disable the layer by stopping its DMA channels and disabling it in the
 * audio/video buffer manager and the blender.
 */
void zynqmp_disp_layer_disable(struct zynqmp_disp_layer *layer)
{}

/**
 * zynqmp_disp_layer_set_format - Set the layer format
 * @layer: The layer
 * @info: The format info
 *
 * NOTE: Use zynqmp_disp_layer_set_live_format() to set media bus format for
 * live video layers.
 *
 * Set the format for @layer to @info. The layer must be disabled.
 */
void zynqmp_disp_layer_set_format(struct zynqmp_disp_layer *layer,
				  const struct drm_format_info *info)
{}

/**
 * zynqmp_disp_layer_set_live_format - Set the live video layer format
 * @layer: The layer
 * @media_bus_format: Media bus format to set
 *
 * NOTE: This function should not be used to set format for non-live video
 * layer. Use zynqmp_disp_layer_set_format() instead.
 *
 * Set the display format for the live @layer. The layer must be disabled.
 */
void zynqmp_disp_layer_set_live_format(struct zynqmp_disp_layer *layer,
				       u32 media_bus_format)
{}

/**
 * zynqmp_disp_layer_update - Update the layer framebuffer
 * @layer: The layer
 * @state: The plane state
 *
 * Update the framebuffer for the layer by issuing a new DMA engine transaction
 * for the new framebuffer.
 *
 * Return: 0 on success, or the DMA descriptor failure error otherwise
 */
int zynqmp_disp_layer_update(struct zynqmp_disp_layer *layer,
			     struct drm_plane_state *state)
{}

/**
 * zynqmp_disp_layer_release_dma - Release DMA channels for a layer
 * @disp: Display controller
 * @layer: The layer
 *
 * Release the DMA channels associated with @layer.
 */
static void zynqmp_disp_layer_release_dma(struct zynqmp_disp *disp,
					  struct zynqmp_disp_layer *layer)
{}

/**
 * zynqmp_disp_destroy_layers - Destroy all layers
 * @disp: Display controller
 */
static void zynqmp_disp_destroy_layers(struct zynqmp_disp *disp)
{}

/**
 * zynqmp_disp_layer_request_dma - Request DMA channels for a layer
 * @disp: Display controller
 * @layer: The layer
 *
 * Request all DMA engine channels needed by @layer.
 *
 * Return: 0 on success, or the DMA channel request error otherwise
 */
static int zynqmp_disp_layer_request_dma(struct zynqmp_disp *disp,
					 struct zynqmp_disp_layer *layer)
{}

/**
 * zynqmp_disp_create_layers - Create and initialize all layers
 * @disp: Display controller
 *
 * Return: 0 on success, or the DMA channel request error otherwise
 */
static int zynqmp_disp_create_layers(struct zynqmp_disp *disp)
{}

/* -----------------------------------------------------------------------------
 * ZynqMP Display
 */

/**
 * zynqmp_disp_enable - Enable the display controller
 * @disp: Display controller
 */
void zynqmp_disp_enable(struct zynqmp_disp *disp)
{}

/**
 * zynqmp_disp_disable - Disable the display controller
 * @disp: Display controller
 */
void zynqmp_disp_disable(struct zynqmp_disp *disp)
{}

/**
 * zynqmp_disp_setup_clock - Configure the display controller pixel clock rate
 * @disp: Display controller
 * @mode_clock: The pixel clock rate, in Hz
 *
 * Return: 0 on success, or a negative error clock otherwise
 */
int zynqmp_disp_setup_clock(struct zynqmp_disp *disp,
			    unsigned long mode_clock)
{}

/* -----------------------------------------------------------------------------
 * Initialization & Cleanup
 */

int zynqmp_disp_probe(struct zynqmp_dpsub *dpsub)
{}

void zynqmp_disp_remove(struct zynqmp_dpsub *dpsub)
{}