11558Srgrimes/* SPDX-License-Identifier: GPL-2.0-only */
21558Srgrimes/* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
31558Srgrimes */
41558Srgrimes
51558Srgrimes#ifndef _DPU_HW_PINGPONG_H
61558Srgrimes#define _DPU_HW_PINGPONG_H
71558Srgrimes
81558Srgrimes#include "dpu_hw_catalog.h"
91558Srgrimes#include "dpu_hw_mdss.h"
101558Srgrimes#include "dpu_hw_util.h"
111558Srgrimes
121558Srgrimes#define DITHER_MATRIX_SZ 16
131558Srgrimes
141558Srgrimesstruct dpu_hw_pingpong;
151558Srgrimes
161558Srgrimes/**
171558Srgrimes * struct dpu_hw_dither_cfg - dither feature structure
181558Srgrimes * @flags: for customizing operations
191558Srgrimes * @temporal_en: temperal dither enable
201558Srgrimes * @c0_bitdepth: c0 component bit depth
211558Srgrimes * @c1_bitdepth: c1 component bit depth
221558Srgrimes * @c2_bitdepth: c2 component bit depth
231558Srgrimes * @c3_bitdepth: c2 component bit depth
241558Srgrimes * @matrix: dither strength matrix
251558Srgrimes */
261558Srgrimesstruct dpu_hw_dither_cfg {
271558Srgrimes	u64 flags;
281558Srgrimes	u32 temporal_en;
291558Srgrimes	u32 c0_bitdepth;
301558Srgrimes	u32 c1_bitdepth;
311558Srgrimes	u32 c2_bitdepth;
321558Srgrimes	u32 c3_bitdepth;
331558Srgrimes	u32 matrix[DITHER_MATRIX_SZ];
341558Srgrimes};
3519914Swollman
361558Srgrimes/**
371558Srgrimes *
381558Srgrimes * struct dpu_hw_pingpong_ops : Interface to the pingpong Hw driver functions
391558Srgrimes *  Assumption is these functions will be called after clocks are enabled
401558Srgrimes *  @enable_tearcheck: program and enable tear check block
4119914Swollman *  @disable_tearcheck: disable able tear check block
421558Srgrimes *  @setup_dither : function to program the dither hw block
4319914Swollman *  @get_line_count: obtain current vertical line counter
4419914Swollman */
4525667Speterstruct dpu_hw_pingpong_ops {
461558Srgrimes	/**
471558Srgrimes	 * enables vysnc generation and sets up init value of
481558Srgrimes	 * read pointer and programs the tear check cofiguration
4919914Swollman	 */
501558Srgrimes	int (*enable_tearcheck)(struct dpu_hw_pingpong *pp,
5113145Speter			struct dpu_hw_tear_check *cfg);
5220287Swollman
531558Srgrimes	/**
541558Srgrimes	 * disables tear check block
5521264Swollman	 */
565298Sjkh	int (*disable_tearcheck)(struct dpu_hw_pingpong *pp);
5713145Speter
5813145Speter	/**
5919914Swollman	 * read, modify, write to either set or clear listening to external TE
6019914Swollman	 * @Return: 1 if TE was originally connected, 0 if not, or -ERROR
611558Srgrimes	 */
625298Sjkh	int (*connect_external_te)(struct dpu_hw_pingpong *pp,
631558Srgrimes			bool enable_external_te);
6411819Sjulian
651558Srgrimes	/**
6619914Swollman	 * Obtain current vertical line counter
6711819Sjulian	 */
6811819Sjulian	u32 (*get_line_count)(struct dpu_hw_pingpong *pp);
6911819Sjulian
7011819Sjulian	/**
7111819Sjulian	 * Disable autorefresh if enabled
7219914Swollman	 */
7317022Sjulian	void (*disable_autorefresh)(struct dpu_hw_pingpong *pp, uint32_t encoder_id, u16 vdisplay);
7417022Sjulian
7519914Swollman	/**
7614092Swollman	 * Setup dither matix for pingpong block
771558Srgrimes	 */
781558Srgrimes	void (*setup_dither)(struct dpu_hw_pingpong *pp,
791558Srgrimes			struct dpu_hw_dither_cfg *cfg);
8014092Swollman	/**
811558Srgrimes	 * Enable DSC
8219914Swollman	 */
8313940Swollman	int (*enable_dsc)(struct dpu_hw_pingpong *pp);
841558Srgrimes
851558Srgrimes	/**
861558Srgrimes	 * Disable DSC
8713940Swollman	 */
881558Srgrimes	void (*disable_dsc)(struct dpu_hw_pingpong *pp);
891558Srgrimes
901558Srgrimes	/**
911558Srgrimes	 * Setup DSC
9219914Swollman	 */
931558Srgrimes	int (*setup_dsc)(struct dpu_hw_pingpong *pp);
941558Srgrimes};
951558Srgrimes
961558Srgrimesstruct dpu_hw_merge_3d;
971558Srgrimes
9825451Speterstruct dpu_hw_pingpong {
9925451Speter	struct dpu_hw_blk base;
1001558Srgrimes	struct dpu_hw_blk_reg_map hw;
1011558Srgrimes
10213940Swollman	/* pingpong */
1031558Srgrimes	enum dpu_pingpong idx;
1041558Srgrimes	const struct dpu_pingpong_cfg *caps;
10513940Swollman	struct dpu_hw_merge_3d *merge_3d;
1061558Srgrimes
10717254Sjulian	/* ops */
1081558Srgrimes	struct dpu_hw_pingpong_ops ops;
10913145Speter};
1101558Srgrimes
1111558Srgrimes/**
1121940Sdg * to_dpu_hw_pingpong - convert base object dpu_hw_base to container
11314092Swollman * @hw: Pointer to base hardware block
1141558Srgrimes * return: Pointer to hardware block container
11514092Swollman */
1161558Srgrimesstatic inline struct dpu_hw_pingpong *to_dpu_hw_pingpong(struct dpu_hw_blk *hw)
1171558Srgrimes{
1181558Srgrimes	return container_of(hw, struct dpu_hw_pingpong, base);
1191558Srgrimes}
1201558Srgrimes
12125449Speter/**
1221558Srgrimes * dpu_hw_pingpong_init() - initializes the pingpong driver for the passed
12319914Swollman * pingpong catalog entry.
12419914Swollman * @dev:  Corresponding device for devres management
12519914Swollman * @cfg:  Pingpong catalog entry for which driver object is required
12619914Swollman * @addr: Mapped register io address of MDP
12725667Speter * @mdss_rev: dpu core's major and minor versions
12825667Speter * Return: Error code or allocated dpu_hw_pingpong context
12919914Swollman */
13019914Swollmanstruct dpu_hw_pingpong *dpu_hw_pingpong_init(struct drm_device *dev,
13125667Speter					     const struct dpu_pingpong_cfg *cfg,
13225667Speter					     void __iomem *addr,
13325667Speter					     const struct dpu_mdss_version *mdss_rev);
13425449Speter
13519914Swollman#endif /*_DPU_HW_PINGPONG_H */
13625667Speter