xref: /OK3568_Linux_fs/kernel/include/media/v4l2-dv-timings.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * v4l2-dv-timings - Internal header with dv-timings helper functions
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright 2013 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifndef __V4L2_DV_TIMINGS_H
9*4882a593Smuzhiyun #define __V4L2_DV_TIMINGS_H
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <linux/videodev2.h>
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun /**
14*4882a593Smuzhiyun  * v4l2_calc_timeperframe - helper function to calculate timeperframe based
15*4882a593Smuzhiyun  *	v4l2_dv_timings fields.
16*4882a593Smuzhiyun  * @t: Timings for the video mode.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * Calculates the expected timeperframe using the pixel clock value and
19*4882a593Smuzhiyun  * horizontal/vertical measures. This means that v4l2_dv_timings structure
20*4882a593Smuzhiyun  * must be correctly and fully filled.
21*4882a593Smuzhiyun  */
22*4882a593Smuzhiyun struct v4l2_fract v4l2_calc_timeperframe(const struct v4l2_dv_timings *t);
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun /*
25*4882a593Smuzhiyun  * v4l2_dv_timings_presets: list of all dv_timings presets.
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun extern const struct v4l2_dv_timings v4l2_dv_timings_presets[];
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun /**
30*4882a593Smuzhiyun  * typedef v4l2_check_dv_timings_fnc - timings check callback
31*4882a593Smuzhiyun  *
32*4882a593Smuzhiyun  * @t: the v4l2_dv_timings struct.
33*4882a593Smuzhiyun  * @handle: a handle from the driver.
34*4882a593Smuzhiyun  *
35*4882a593Smuzhiyun  * Returns true if the given timings are valid.
36*4882a593Smuzhiyun  */
37*4882a593Smuzhiyun typedef bool v4l2_check_dv_timings_fnc(const struct v4l2_dv_timings *t, void *handle);
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /**
40*4882a593Smuzhiyun  * v4l2_valid_dv_timings() - are these timings valid?
41*4882a593Smuzhiyun  *
42*4882a593Smuzhiyun  * @t:	  the v4l2_dv_timings struct.
43*4882a593Smuzhiyun  * @cap: the v4l2_dv_timings_cap capabilities.
44*4882a593Smuzhiyun  * @fnc: callback to check if this timing is OK. May be NULL.
45*4882a593Smuzhiyun  * @fnc_handle: a handle that is passed on to @fnc.
46*4882a593Smuzhiyun  *
47*4882a593Smuzhiyun  * Returns true if the given dv_timings struct is supported by the
48*4882a593Smuzhiyun  * hardware capabilities and the callback function (if non-NULL), returns
49*4882a593Smuzhiyun  * false otherwise.
50*4882a593Smuzhiyun  */
51*4882a593Smuzhiyun bool v4l2_valid_dv_timings(const struct v4l2_dv_timings *t,
52*4882a593Smuzhiyun 			   const struct v4l2_dv_timings_cap *cap,
53*4882a593Smuzhiyun 			   v4l2_check_dv_timings_fnc fnc,
54*4882a593Smuzhiyun 			   void *fnc_handle);
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun /**
57*4882a593Smuzhiyun  * v4l2_enum_dv_timings_cap() - Helper function to enumerate possible DV
58*4882a593Smuzhiyun  *	 timings based on capabilities
59*4882a593Smuzhiyun  *
60*4882a593Smuzhiyun  * @t:	  the v4l2_enum_dv_timings struct.
61*4882a593Smuzhiyun  * @cap: the v4l2_dv_timings_cap capabilities.
62*4882a593Smuzhiyun  * @fnc: callback to check if this timing is OK. May be NULL.
63*4882a593Smuzhiyun  * @fnc_handle: a handle that is passed on to @fnc.
64*4882a593Smuzhiyun  *
65*4882a593Smuzhiyun  * This enumerates dv_timings using the full list of possible CEA-861 and DMT
66*4882a593Smuzhiyun  * timings, filtering out any timings that are not supported based on the
67*4882a593Smuzhiyun  * hardware capabilities and the callback function (if non-NULL).
68*4882a593Smuzhiyun  *
69*4882a593Smuzhiyun  * If a valid timing for the given index is found, it will fill in @t and
70*4882a593Smuzhiyun  * return 0, otherwise it returns -EINVAL.
71*4882a593Smuzhiyun  */
72*4882a593Smuzhiyun int v4l2_enum_dv_timings_cap(struct v4l2_enum_dv_timings *t,
73*4882a593Smuzhiyun 			     const struct v4l2_dv_timings_cap *cap,
74*4882a593Smuzhiyun 			     v4l2_check_dv_timings_fnc fnc,
75*4882a593Smuzhiyun 			     void *fnc_handle);
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun /**
78*4882a593Smuzhiyun  * v4l2_find_dv_timings_cap() - Find the closest timings struct
79*4882a593Smuzhiyun  *
80*4882a593Smuzhiyun  * @t:	  the v4l2_enum_dv_timings struct.
81*4882a593Smuzhiyun  * @cap: the v4l2_dv_timings_cap capabilities.
82*4882a593Smuzhiyun  * @pclock_delta: maximum delta between t->pixelclock and the timing struct
83*4882a593Smuzhiyun  *		under consideration.
84*4882a593Smuzhiyun  * @fnc: callback to check if a given timings struct is OK. May be NULL.
85*4882a593Smuzhiyun  * @fnc_handle: a handle that is passed on to @fnc.
86*4882a593Smuzhiyun  *
87*4882a593Smuzhiyun  * This function tries to map the given timings to an entry in the
88*4882a593Smuzhiyun  * full list of possible CEA-861 and DMT timings, filtering out any timings
89*4882a593Smuzhiyun  * that are not supported based on the hardware capabilities and the callback
90*4882a593Smuzhiyun  * function (if non-NULL).
91*4882a593Smuzhiyun  *
92*4882a593Smuzhiyun  * On success it will fill in @t with the found timings and it returns true.
93*4882a593Smuzhiyun  * On failure it will return false.
94*4882a593Smuzhiyun  */
95*4882a593Smuzhiyun bool v4l2_find_dv_timings_cap(struct v4l2_dv_timings *t,
96*4882a593Smuzhiyun 			      const struct v4l2_dv_timings_cap *cap,
97*4882a593Smuzhiyun 			      unsigned pclock_delta,
98*4882a593Smuzhiyun 			      v4l2_check_dv_timings_fnc fnc,
99*4882a593Smuzhiyun 			      void *fnc_handle);
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun /**
102*4882a593Smuzhiyun  * v4l2_find_dv_timings_cea861_vic() - find timings based on CEA-861 VIC
103*4882a593Smuzhiyun  * @t:		the timings data.
104*4882a593Smuzhiyun  * @vic:	CEA-861 VIC code
105*4882a593Smuzhiyun  *
106*4882a593Smuzhiyun  * On success it will fill in @t with the found timings and it returns true.
107*4882a593Smuzhiyun  * On failure it will return false.
108*4882a593Smuzhiyun  */
109*4882a593Smuzhiyun bool v4l2_find_dv_timings_cea861_vic(struct v4l2_dv_timings *t, u8 vic);
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun /**
112*4882a593Smuzhiyun  * v4l2_match_dv_timings() - do two timings match?
113*4882a593Smuzhiyun  *
114*4882a593Smuzhiyun  * @measured:	  the measured timings data.
115*4882a593Smuzhiyun  * @standard:	  the timings according to the standard.
116*4882a593Smuzhiyun  * @pclock_delta: maximum delta in Hz between standard->pixelclock and
117*4882a593Smuzhiyun  *		the measured timings.
118*4882a593Smuzhiyun  * @match_reduced_fps: if true, then fail if V4L2_DV_FL_REDUCED_FPS does not
119*4882a593Smuzhiyun  * match.
120*4882a593Smuzhiyun  *
121*4882a593Smuzhiyun  * Returns true if the two timings match, returns false otherwise.
122*4882a593Smuzhiyun  */
123*4882a593Smuzhiyun bool v4l2_match_dv_timings(const struct v4l2_dv_timings *measured,
124*4882a593Smuzhiyun 			   const struct v4l2_dv_timings *standard,
125*4882a593Smuzhiyun 			   unsigned pclock_delta, bool match_reduced_fps);
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun /**
128*4882a593Smuzhiyun  * v4l2_print_dv_timings() - log the contents of a dv_timings struct
129*4882a593Smuzhiyun  * @dev_prefix:device prefix for each log line.
130*4882a593Smuzhiyun  * @prefix:	additional prefix for each log line, may be NULL.
131*4882a593Smuzhiyun  * @t:		the timings data.
132*4882a593Smuzhiyun  * @detailed:	if true, give a detailed log.
133*4882a593Smuzhiyun  */
134*4882a593Smuzhiyun void v4l2_print_dv_timings(const char *dev_prefix, const char *prefix,
135*4882a593Smuzhiyun 			   const struct v4l2_dv_timings *t, bool detailed);
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun /**
138*4882a593Smuzhiyun  * v4l2_detect_cvt - detect if the given timings follow the CVT standard
139*4882a593Smuzhiyun  *
140*4882a593Smuzhiyun  * @frame_height: the total height of the frame (including blanking) in lines.
141*4882a593Smuzhiyun  * @hfreq: the horizontal frequency in Hz.
142*4882a593Smuzhiyun  * @vsync: the height of the vertical sync in lines.
143*4882a593Smuzhiyun  * @active_width: active width of image (does not include blanking). This
144*4882a593Smuzhiyun  * information is needed only in case of version 2 of reduced blanking.
145*4882a593Smuzhiyun  * In other cases, this parameter does not have any effect on timings.
146*4882a593Smuzhiyun  * @polarities: the horizontal and vertical polarities (same as struct
147*4882a593Smuzhiyun  *		v4l2_bt_timings polarities).
148*4882a593Smuzhiyun  * @interlaced: if this flag is true, it indicates interlaced format
149*4882a593Smuzhiyun  * @fmt: the resulting timings.
150*4882a593Smuzhiyun  *
151*4882a593Smuzhiyun  * This function will attempt to detect if the given values correspond to a
152*4882a593Smuzhiyun  * valid CVT format. If so, then it will return true, and fmt will be filled
153*4882a593Smuzhiyun  * in with the found CVT timings.
154*4882a593Smuzhiyun  */
155*4882a593Smuzhiyun bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync,
156*4882a593Smuzhiyun 		unsigned active_width, u32 polarities, bool interlaced,
157*4882a593Smuzhiyun 		struct v4l2_dv_timings *fmt);
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun /**
160*4882a593Smuzhiyun  * v4l2_detect_gtf - detect if the given timings follow the GTF standard
161*4882a593Smuzhiyun  *
162*4882a593Smuzhiyun  * @frame_height: the total height of the frame (including blanking) in lines.
163*4882a593Smuzhiyun  * @hfreq: the horizontal frequency in Hz.
164*4882a593Smuzhiyun  * @vsync: the height of the vertical sync in lines.
165*4882a593Smuzhiyun  * @polarities: the horizontal and vertical polarities (same as struct
166*4882a593Smuzhiyun  *		v4l2_bt_timings polarities).
167*4882a593Smuzhiyun  * @interlaced: if this flag is true, it indicates interlaced format
168*4882a593Smuzhiyun  * @aspect: preferred aspect ratio. GTF has no method of determining the
169*4882a593Smuzhiyun  *		aspect ratio in order to derive the image width from the
170*4882a593Smuzhiyun  *		image height, so it has to be passed explicitly. Usually
171*4882a593Smuzhiyun  *		the native screen aspect ratio is used for this. If it
172*4882a593Smuzhiyun  *		is not filled in correctly, then 16:9 will be assumed.
173*4882a593Smuzhiyun  * @fmt: the resulting timings.
174*4882a593Smuzhiyun  *
175*4882a593Smuzhiyun  * This function will attempt to detect if the given values correspond to a
176*4882a593Smuzhiyun  * valid GTF format. If so, then it will return true, and fmt will be filled
177*4882a593Smuzhiyun  * in with the found GTF timings.
178*4882a593Smuzhiyun  */
179*4882a593Smuzhiyun bool v4l2_detect_gtf(unsigned frame_height, unsigned hfreq, unsigned vsync,
180*4882a593Smuzhiyun 		u32 polarities, bool interlaced, struct v4l2_fract aspect,
181*4882a593Smuzhiyun 		struct v4l2_dv_timings *fmt);
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun /**
184*4882a593Smuzhiyun  * v4l2_calc_aspect_ratio - calculate the aspect ratio based on bytes
185*4882a593Smuzhiyun  *	0x15 and 0x16 from the EDID.
186*4882a593Smuzhiyun  *
187*4882a593Smuzhiyun  * @hor_landscape: byte 0x15 from the EDID.
188*4882a593Smuzhiyun  * @vert_portrait: byte 0x16 from the EDID.
189*4882a593Smuzhiyun  *
190*4882a593Smuzhiyun  * Determines the aspect ratio from the EDID.
191*4882a593Smuzhiyun  * See VESA Enhanced EDID standard, release A, rev 2, section 3.6.2:
192*4882a593Smuzhiyun  * "Horizontal and Vertical Screen Size or Aspect Ratio"
193*4882a593Smuzhiyun  */
194*4882a593Smuzhiyun struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, u8 vert_portrait);
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun /**
197*4882a593Smuzhiyun  * v4l2_dv_timings_aspect_ratio - calculate the aspect ratio based on the
198*4882a593Smuzhiyun  *	v4l2_dv_timings information.
199*4882a593Smuzhiyun  *
200*4882a593Smuzhiyun  * @t: the timings data.
201*4882a593Smuzhiyun  */
202*4882a593Smuzhiyun struct v4l2_fract v4l2_dv_timings_aspect_ratio(const struct v4l2_dv_timings *t);
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun /**
205*4882a593Smuzhiyun  * can_reduce_fps - check if conditions for reduced fps are true.
206*4882a593Smuzhiyun  * @bt: v4l2 timing structure
207*4882a593Smuzhiyun  *
208*4882a593Smuzhiyun  * For different timings reduced fps is allowed if the following conditions
209*4882a593Smuzhiyun  * are met:
210*4882a593Smuzhiyun  *
211*4882a593Smuzhiyun  *   - For CVT timings: if reduced blanking v2 (vsync == 8) is true.
212*4882a593Smuzhiyun  *   - For CEA861 timings: if %V4L2_DV_FL_CAN_REDUCE_FPS flag is true.
213*4882a593Smuzhiyun  */
can_reduce_fps(struct v4l2_bt_timings * bt)214*4882a593Smuzhiyun static inline  bool can_reduce_fps(struct v4l2_bt_timings *bt)
215*4882a593Smuzhiyun {
216*4882a593Smuzhiyun 	if ((bt->standards & V4L2_DV_BT_STD_CVT) && (bt->vsync == 8))
217*4882a593Smuzhiyun 		return true;
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun 	if ((bt->standards & V4L2_DV_BT_STD_CEA861) &&
220*4882a593Smuzhiyun 	    (bt->flags & V4L2_DV_FL_CAN_REDUCE_FPS))
221*4882a593Smuzhiyun 		return true;
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun 	return false;
224*4882a593Smuzhiyun }
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun /**
227*4882a593Smuzhiyun  * struct v4l2_hdmi_rx_colorimetry - describes the HDMI colorimetry information
228*4882a593Smuzhiyun  * @colorspace:		enum v4l2_colorspace, the colorspace
229*4882a593Smuzhiyun  * @ycbcr_enc:		enum v4l2_ycbcr_encoding, Y'CbCr encoding
230*4882a593Smuzhiyun  * @quantization:	enum v4l2_quantization, colorspace quantization
231*4882a593Smuzhiyun  * @xfer_func:		enum v4l2_xfer_func, colorspace transfer function
232*4882a593Smuzhiyun  */
233*4882a593Smuzhiyun struct v4l2_hdmi_colorimetry {
234*4882a593Smuzhiyun 	enum v4l2_colorspace colorspace;
235*4882a593Smuzhiyun 	enum v4l2_ycbcr_encoding ycbcr_enc;
236*4882a593Smuzhiyun 	enum v4l2_quantization quantization;
237*4882a593Smuzhiyun 	enum v4l2_xfer_func xfer_func;
238*4882a593Smuzhiyun };
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun struct hdmi_avi_infoframe;
241*4882a593Smuzhiyun struct hdmi_vendor_infoframe;
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun struct v4l2_hdmi_colorimetry
244*4882a593Smuzhiyun v4l2_hdmi_rx_colorimetry(const struct hdmi_avi_infoframe *avi,
245*4882a593Smuzhiyun 			 const struct hdmi_vendor_infoframe *hdmi,
246*4882a593Smuzhiyun 			 unsigned int height);
247*4882a593Smuzhiyun 
248*4882a593Smuzhiyun u16 v4l2_get_edid_phys_addr(const u8 *edid, unsigned int size,
249*4882a593Smuzhiyun 			    unsigned int *offset);
250*4882a593Smuzhiyun void v4l2_set_edid_phys_addr(u8 *edid, unsigned int size, u16 phys_addr);
251*4882a593Smuzhiyun u16 v4l2_phys_addr_for_input(u16 phys_addr, u8 input);
252*4882a593Smuzhiyun int v4l2_phys_addr_validate(u16 phys_addr, u16 *parent, u16 *port);
253*4882a593Smuzhiyun 
254*4882a593Smuzhiyun #endif
255