1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
3  */
4 
5 #ifndef _DPU_HW_PINGPONG_H
6 #define _DPU_HW_PINGPONG_H
7 
8 #include "dpu_hw_catalog.h"
9 #include "dpu_hw_mdss.h"
10 #include "dpu_hw_util.h"
11 
12 #define DITHER_MATRIX_SZ 16
13 
14 struct dpu_hw_pingpong;
15 
16 /**
17  * struct dpu_hw_dither_cfg - dither feature structure
18  * @flags: for customizing operations
19  * @temporal_en: temperal dither enable
20  * @c0_bitdepth: c0 component bit depth
21  * @c1_bitdepth: c1 component bit depth
22  * @c2_bitdepth: c2 component bit depth
23  * @c3_bitdepth: c2 component bit depth
24  * @matrix: dither strength matrix
25  */
26 struct dpu_hw_dither_cfg {
27 	u64 flags;
28 	u32 temporal_en;
29 	u32 c0_bitdepth;
30 	u32 c1_bitdepth;
31 	u32 c2_bitdepth;
32 	u32 c3_bitdepth;
33 	u32 matrix[DITHER_MATRIX_SZ];
34 };
35 
36 /**
37  *
38  * struct dpu_hw_pingpong_ops : Interface to the pingpong Hw driver functions
39  *  Assumption is these functions will be called after clocks are enabled
40  *  @enable_tearcheck: program and enable tear check block
41  *  @disable_tearcheck: disable able tear check block
42  *  @setup_dither : function to program the dither hw block
43  *  @get_line_count: obtain current vertical line counter
44  */
45 struct dpu_hw_pingpong_ops {
46 	/**
47 	 * enables vysnc generation and sets up init value of
48 	 * read pointer and programs the tear check cofiguration
49 	 */
50 	int (*enable_tearcheck)(struct dpu_hw_pingpong *pp,
51 			struct dpu_hw_tear_check *cfg);
52 
53 	/**
54 	 * disables tear check block
55 	 */
56 	int (*disable_tearcheck)(struct dpu_hw_pingpong *pp);
57 
58 	/**
59 	 * read, modify, write to either set or clear listening to external TE
60 	 * @Return: 1 if TE was originally connected, 0 if not, or -ERROR
61 	 */
62 	int (*connect_external_te)(struct dpu_hw_pingpong *pp,
63 			bool enable_external_te);
64 
65 	/**
66 	 * Obtain current vertical line counter
67 	 */
68 	u32 (*get_line_count)(struct dpu_hw_pingpong *pp);
69 
70 	/**
71 	 * Disable autorefresh if enabled
72 	 */
73 	void (*disable_autorefresh)(struct dpu_hw_pingpong *pp, uint32_t encoder_id, u16 vdisplay);
74 
75 	/**
76 	 * Setup dither matix for pingpong block
77 	 */
78 	void (*setup_dither)(struct dpu_hw_pingpong *pp,
79 			struct dpu_hw_dither_cfg *cfg);
80 	/**
81 	 * Enable DSC
82 	 */
83 	int (*enable_dsc)(struct dpu_hw_pingpong *pp);
84 
85 	/**
86 	 * Disable DSC
87 	 */
88 	void (*disable_dsc)(struct dpu_hw_pingpong *pp);
89 
90 	/**
91 	 * Setup DSC
92 	 */
93 	int (*setup_dsc)(struct dpu_hw_pingpong *pp);
94 };
95 
96 struct dpu_hw_merge_3d;
97 
98 struct dpu_hw_pingpong {
99 	struct dpu_hw_blk base;
100 	struct dpu_hw_blk_reg_map hw;
101 
102 	/* pingpong */
103 	enum dpu_pingpong idx;
104 	const struct dpu_pingpong_cfg *caps;
105 	struct dpu_hw_merge_3d *merge_3d;
106 
107 	/* ops */
108 	struct dpu_hw_pingpong_ops ops;
109 };
110 
111 /**
112  * to_dpu_hw_pingpong - convert base object dpu_hw_base to container
113  * @hw: Pointer to base hardware block
114  * return: Pointer to hardware block container
115  */
to_dpu_hw_pingpong(struct dpu_hw_blk * hw)116 static inline struct dpu_hw_pingpong *to_dpu_hw_pingpong(struct dpu_hw_blk *hw)
117 {
118 	return container_of(hw, struct dpu_hw_pingpong, base);
119 }
120 
121 /**
122  * dpu_hw_pingpong_init() - initializes the pingpong driver for the passed
123  * pingpong catalog entry.
124  * @cfg:  Pingpong catalog entry for which driver object is required
125  * @addr: Mapped register io address of MDP
126  * Return: Error code or allocated dpu_hw_pingpong context
127  */
128 struct dpu_hw_pingpong *dpu_hw_pingpong_init(const struct dpu_pingpong_cfg *cfg,
129 		void __iomem *addr);
130 
131 /**
132  * dpu_hw_pingpong_destroy - destroys pingpong driver context
133  *	should be called to free the context
134  * @pp:   Pointer to PP driver context returned by dpu_hw_pingpong_init
135  */
136 void dpu_hw_pingpong_destroy(struct dpu_hw_pingpong *pp);
137 
138 #endif /*_DPU_HW_PINGPONG_H */
139