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_CDM_H
14 #define _DPU_HW_CDM_H
15
16 #include "dpu_hw_mdss.h"
17 #include "dpu_hw_top.h"
18 #include "dpu_hw_blk.h"
19
20 struct dpu_hw_cdm;
21
22 struct dpu_hw_cdm_cfg {
23 u32 output_width;
24 u32 output_height;
25 u32 output_bit_depth;
26 u32 h_cdwn_type;
27 u32 v_cdwn_type;
28 const struct dpu_format *output_fmt;
29 u32 output_type;
30 int flags;
31 };
32
33 enum dpu_hw_cdwn_type {
34 CDM_CDWN_DISABLE,
35 CDM_CDWN_PIXEL_DROP,
36 CDM_CDWN_AVG,
37 CDM_CDWN_COSITE,
38 CDM_CDWN_OFFSITE,
39 };
40
41 enum dpu_hw_cdwn_output_type {
42 CDM_CDWN_OUTPUT_HDMI,
43 CDM_CDWN_OUTPUT_WB,
44 };
45
46 enum dpu_hw_cdwn_output_bit_depth {
47 CDM_CDWN_OUTPUT_8BIT,
48 CDM_CDWN_OUTPUT_10BIT,
49 };
50
51 /**
52 * struct dpu_hw_cdm_ops : Interface to the chroma down Hw driver functions
53 * Assumption is these functions will be called after
54 * clocks are enabled
55 * @setup_csc: Programs the csc matrix
56 * @setup_cdwn: Sets up the chroma down sub module
57 * @enable: Enables the output to interface and programs the
58 * output packer
59 * @disable: Puts the cdm in bypass mode
60 */
61 struct dpu_hw_cdm_ops {
62 /**
63 * Programs the CSC matrix for conversion from RGB space to YUV space,
64 * it is optional to call this function as this matrix is automatically
65 * set during initialization, user should call this if it wants
66 * to program a different matrix than default matrix.
67 * @cdm: Pointer to the chroma down context structure
68 * @data Pointer to CSC configuration data
69 * return: 0 if success; error code otherwise
70 */
71 int (*setup_csc_data)(struct dpu_hw_cdm *cdm,
72 struct dpu_csc_cfg *data);
73
74 /**
75 * Programs the Chroma downsample part.
76 * @cdm Pointer to chroma down context
77 */
78 int (*setup_cdwn)(struct dpu_hw_cdm *cdm,
79 struct dpu_hw_cdm_cfg *cfg);
80
81 /**
82 * Enable the CDM module
83 * @cdm Pointer to chroma down context
84 */
85 int (*enable)(struct dpu_hw_cdm *cdm,
86 struct dpu_hw_cdm_cfg *cfg);
87
88 /**
89 * Disable the CDM module
90 * @cdm Pointer to chroma down context
91 */
92 void (*disable)(struct dpu_hw_cdm *cdm);
93 };
94
95 struct dpu_hw_cdm {
96 struct dpu_hw_blk base;
97 struct dpu_hw_blk_reg_map hw;
98
99 /* chroma down */
100 const struct dpu_cdm_cfg *caps;
101 enum dpu_cdm idx;
102
103 /* mdp top hw driver */
104 struct dpu_hw_mdp *hw_mdp;
105
106 /* ops */
107 struct dpu_hw_cdm_ops ops;
108 };
109
110 /**
111 * dpu_hw_cdm - convert base object dpu_hw_base to container
112 * @hw: Pointer to base hardware block
113 * return: Pointer to hardware block container
114 */
to_dpu_hw_cdm(struct dpu_hw_blk * hw)115 static inline struct dpu_hw_cdm *to_dpu_hw_cdm(struct dpu_hw_blk *hw)
116 {
117 return container_of(hw, struct dpu_hw_cdm, base);
118 }
119
120 /**
121 * dpu_hw_cdm_init - initializes the cdm hw driver object.
122 * should be called once before accessing every cdm.
123 * @idx: cdm index for which driver object is required
124 * @addr: mapped register io address of MDP
125 * @m : pointer to mdss catalog data
126 * @hw_mdp: pointer to mdp top hw driver object
127 */
128 struct dpu_hw_cdm *dpu_hw_cdm_init(enum dpu_cdm idx,
129 void __iomem *addr,
130 struct dpu_mdss_cfg *m,
131 struct dpu_hw_mdp *hw_mdp);
132
133 /**
134 * dpu_hw_cdm_destroy - destroys CDM driver context
135 * @cdm: pointer to CDM driver context
136 */
137 void dpu_hw_cdm_destroy(struct dpu_hw_cdm *cdm);
138
139 #endif /*_DPU_HW_CDM_H */
140