1 /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13 #ifndef _DPU_HW_PINGPONG_H
14 #define _DPU_HW_PINGPONG_H
15
16 #include "dpu_hw_catalog.h"
17 #include "dpu_hw_mdss.h"
18 #include "dpu_hw_util.h"
19 #include "dpu_hw_blk.h"
20
21 struct dpu_hw_pingpong;
22
23 struct dpu_hw_tear_check {
24 /*
25 * This is ratio of MDP VSYNC clk freq(Hz) to
26 * refresh rate divided by no of lines
27 */
28 u32 vsync_count;
29 u32 sync_cfg_height;
30 u32 vsync_init_val;
31 u32 sync_threshold_start;
32 u32 sync_threshold_continue;
33 u32 start_pos;
34 u32 rd_ptr_irq;
35 u8 hw_vsync_mode;
36 };
37
38 struct dpu_hw_pp_vsync_info {
39 u32 rd_ptr_init_val; /* value of rd pointer at vsync edge */
40 u32 rd_ptr_frame_count; /* num frames sent since enabling interface */
41 u32 rd_ptr_line_count; /* current line on panel (rd ptr) */
42 u32 wr_ptr_line_count; /* current line within pp fifo (wr ptr) */
43 };
44
45 /**
46 *
47 * struct dpu_hw_pingpong_ops : Interface to the pingpong Hw driver functions
48 * Assumption is these functions will be called after clocks are enabled
49 * @setup_tearcheck : program tear check values
50 * @enable_tearcheck : enables tear check
51 * @get_vsync_info : retries timing info of the panel
52 * @setup_dither : function to program the dither hw block
53 * @get_line_count: obtain current vertical line counter
54 */
55 struct dpu_hw_pingpong_ops {
56 /**
57 * enables vysnc generation and sets up init value of
58 * read pointer and programs the tear check cofiguration
59 */
60 int (*setup_tearcheck)(struct dpu_hw_pingpong *pp,
61 struct dpu_hw_tear_check *cfg);
62
63 /**
64 * enables tear check block
65 */
66 int (*enable_tearcheck)(struct dpu_hw_pingpong *pp,
67 bool enable);
68
69 /**
70 * read, modify, write to either set or clear listening to external TE
71 * @Return: 1 if TE was originally connected, 0 if not, or -ERROR
72 */
73 int (*connect_external_te)(struct dpu_hw_pingpong *pp,
74 bool enable_external_te);
75
76 /**
77 * provides the programmed and current
78 * line_count
79 */
80 int (*get_vsync_info)(struct dpu_hw_pingpong *pp,
81 struct dpu_hw_pp_vsync_info *info);
82
83 /**
84 * poll until write pointer transmission starts
85 * @Return: 0 on success, -ETIMEDOUT on timeout
86 */
87 int (*poll_timeout_wr_ptr)(struct dpu_hw_pingpong *pp, u32 timeout_us);
88
89 /**
90 * Obtain current vertical line counter
91 */
92 u32 (*get_line_count)(struct dpu_hw_pingpong *pp);
93 };
94
95 struct dpu_hw_pingpong {
96 struct dpu_hw_blk base;
97 struct dpu_hw_blk_reg_map hw;
98
99 /* pingpong */
100 enum dpu_pingpong idx;
101 const struct dpu_pingpong_cfg *caps;
102
103 /* ops */
104 struct dpu_hw_pingpong_ops ops;
105 };
106
107 /**
108 * dpu_hw_pingpong - convert base object dpu_hw_base to container
109 * @hw: Pointer to base hardware block
110 * return: Pointer to hardware block container
111 */
to_dpu_hw_pingpong(struct dpu_hw_blk * hw)112 static inline struct dpu_hw_pingpong *to_dpu_hw_pingpong(struct dpu_hw_blk *hw)
113 {
114 return container_of(hw, struct dpu_hw_pingpong, base);
115 }
116
117 /**
118 * dpu_hw_pingpong_init - initializes the pingpong driver for the passed
119 * pingpong idx.
120 * @idx: Pingpong index for which driver object is required
121 * @addr: Mapped register io address of MDP
122 * @m: Pointer to mdss catalog data
123 * Returns: Error code or allocated dpu_hw_pingpong context
124 */
125 struct dpu_hw_pingpong *dpu_hw_pingpong_init(enum dpu_pingpong idx,
126 void __iomem *addr,
127 struct dpu_mdss_cfg *m);
128
129 /**
130 * dpu_hw_pingpong_destroy - destroys pingpong driver context
131 * should be called to free the context
132 * @pp: Pointer to PP driver context returned by dpu_hw_pingpong_init
133 */
134 void dpu_hw_pingpong_destroy(struct dpu_hw_pingpong *pp);
135
136 #endif /*_DPU_HW_PINGPONG_H */
137