Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * v4l2-dv-timings - Internal header with dv-timings helper functions
0004  *
0005  * Copyright 2013 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
0006  */
0007 
0008 #ifndef __V4L2_DV_TIMINGS_H
0009 #define __V4L2_DV_TIMINGS_H
0010 
0011 #include <linux/videodev2.h>
0012 
0013 /**
0014  * v4l2_calc_timeperframe - helper function to calculate timeperframe based
0015  *  v4l2_dv_timings fields.
0016  * @t: Timings for the video mode.
0017  *
0018  * Calculates the expected timeperframe using the pixel clock value and
0019  * horizontal/vertical measures. This means that v4l2_dv_timings structure
0020  * must be correctly and fully filled.
0021  */
0022 struct v4l2_fract v4l2_calc_timeperframe(const struct v4l2_dv_timings *t);
0023 
0024 /*
0025  * v4l2_dv_timings_presets: list of all dv_timings presets.
0026  */
0027 extern const struct v4l2_dv_timings v4l2_dv_timings_presets[];
0028 
0029 /**
0030  * typedef v4l2_check_dv_timings_fnc - timings check callback
0031  *
0032  * @t: the v4l2_dv_timings struct.
0033  * @handle: a handle from the driver.
0034  *
0035  * Returns true if the given timings are valid.
0036  */
0037 typedef bool v4l2_check_dv_timings_fnc(const struct v4l2_dv_timings *t, void *handle);
0038 
0039 /**
0040  * v4l2_valid_dv_timings() - are these timings valid?
0041  *
0042  * @t:    the v4l2_dv_timings struct.
0043  * @cap: the v4l2_dv_timings_cap capabilities.
0044  * @fnc: callback to check if this timing is OK. May be NULL.
0045  * @fnc_handle: a handle that is passed on to @fnc.
0046  *
0047  * Returns true if the given dv_timings struct is supported by the
0048  * hardware capabilities and the callback function (if non-NULL), returns
0049  * false otherwise.
0050  */
0051 bool v4l2_valid_dv_timings(const struct v4l2_dv_timings *t,
0052                const struct v4l2_dv_timings_cap *cap,
0053                v4l2_check_dv_timings_fnc fnc,
0054                void *fnc_handle);
0055 
0056 /**
0057  * v4l2_enum_dv_timings_cap() - Helper function to enumerate possible DV
0058  *   timings based on capabilities
0059  *
0060  * @t:    the v4l2_enum_dv_timings struct.
0061  * @cap: the v4l2_dv_timings_cap capabilities.
0062  * @fnc: callback to check if this timing is OK. May be NULL.
0063  * @fnc_handle: a handle that is passed on to @fnc.
0064  *
0065  * This enumerates dv_timings using the full list of possible CEA-861 and DMT
0066  * timings, filtering out any timings that are not supported based on the
0067  * hardware capabilities and the callback function (if non-NULL).
0068  *
0069  * If a valid timing for the given index is found, it will fill in @t and
0070  * return 0, otherwise it returns -EINVAL.
0071  */
0072 int v4l2_enum_dv_timings_cap(struct v4l2_enum_dv_timings *t,
0073                  const struct v4l2_dv_timings_cap *cap,
0074                  v4l2_check_dv_timings_fnc fnc,
0075                  void *fnc_handle);
0076 
0077 /**
0078  * v4l2_find_dv_timings_cap() - Find the closest timings struct
0079  *
0080  * @t:    the v4l2_enum_dv_timings struct.
0081  * @cap: the v4l2_dv_timings_cap capabilities.
0082  * @pclock_delta: maximum delta between t->pixelclock and the timing struct
0083  *      under consideration.
0084  * @fnc: callback to check if a given timings struct is OK. May be NULL.
0085  * @fnc_handle: a handle that is passed on to @fnc.
0086  *
0087  * This function tries to map the given timings to an entry in the
0088  * full list of possible CEA-861 and DMT timings, filtering out any timings
0089  * that are not supported based on the hardware capabilities and the callback
0090  * function (if non-NULL).
0091  *
0092  * On success it will fill in @t with the found timings and it returns true.
0093  * On failure it will return false.
0094  */
0095 bool v4l2_find_dv_timings_cap(struct v4l2_dv_timings *t,
0096                   const struct v4l2_dv_timings_cap *cap,
0097                   unsigned pclock_delta,
0098                   v4l2_check_dv_timings_fnc fnc,
0099                   void *fnc_handle);
0100 
0101 /**
0102  * v4l2_find_dv_timings_cea861_vic() - find timings based on CEA-861 VIC
0103  * @t:      the timings data.
0104  * @vic:    CEA-861 VIC code
0105  *
0106  * On success it will fill in @t with the found timings and it returns true.
0107  * On failure it will return false.
0108  */
0109 bool v4l2_find_dv_timings_cea861_vic(struct v4l2_dv_timings *t, u8 vic);
0110 
0111 /**
0112  * v4l2_match_dv_timings() - do two timings match?
0113  *
0114  * @measured:     the measured timings data.
0115  * @standard:     the timings according to the standard.
0116  * @pclock_delta: maximum delta in Hz between standard->pixelclock and
0117  *      the measured timings.
0118  * @match_reduced_fps: if true, then fail if V4L2_DV_FL_REDUCED_FPS does not
0119  * match.
0120  *
0121  * Returns true if the two timings match, returns false otherwise.
0122  */
0123 bool v4l2_match_dv_timings(const struct v4l2_dv_timings *measured,
0124                const struct v4l2_dv_timings *standard,
0125                unsigned pclock_delta, bool match_reduced_fps);
0126 
0127 /**
0128  * v4l2_print_dv_timings() - log the contents of a dv_timings struct
0129  * @dev_prefix:device prefix for each log line.
0130  * @prefix: additional prefix for each log line, may be NULL.
0131  * @t:      the timings data.
0132  * @detailed:   if true, give a detailed log.
0133  */
0134 void v4l2_print_dv_timings(const char *dev_prefix, const char *prefix,
0135                const struct v4l2_dv_timings *t, bool detailed);
0136 
0137 /**
0138  * v4l2_detect_cvt - detect if the given timings follow the CVT standard
0139  *
0140  * @frame_height: the total height of the frame (including blanking) in lines.
0141  * @hfreq: the horizontal frequency in Hz.
0142  * @vsync: the height of the vertical sync in lines.
0143  * @active_width: active width of image (does not include blanking). This
0144  * information is needed only in case of version 2 of reduced blanking.
0145  * In other cases, this parameter does not have any effect on timings.
0146  * @polarities: the horizontal and vertical polarities (same as struct
0147  *      v4l2_bt_timings polarities).
0148  * @interlaced: if this flag is true, it indicates interlaced format
0149  * @fmt: the resulting timings.
0150  *
0151  * This function will attempt to detect if the given values correspond to a
0152  * valid CVT format. If so, then it will return true, and fmt will be filled
0153  * in with the found CVT timings.
0154  */
0155 bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync,
0156         unsigned active_width, u32 polarities, bool interlaced,
0157         struct v4l2_dv_timings *fmt);
0158 
0159 /**
0160  * v4l2_detect_gtf - detect if the given timings follow the GTF standard
0161  *
0162  * @frame_height: the total height of the frame (including blanking) in lines.
0163  * @hfreq: the horizontal frequency in Hz.
0164  * @vsync: the height of the vertical sync in lines.
0165  * @polarities: the horizontal and vertical polarities (same as struct
0166  *      v4l2_bt_timings polarities).
0167  * @interlaced: if this flag is true, it indicates interlaced format
0168  * @aspect: preferred aspect ratio. GTF has no method of determining the
0169  *      aspect ratio in order to derive the image width from the
0170  *      image height, so it has to be passed explicitly. Usually
0171  *      the native screen aspect ratio is used for this. If it
0172  *      is not filled in correctly, then 16:9 will be assumed.
0173  * @fmt: the resulting timings.
0174  *
0175  * This function will attempt to detect if the given values correspond to a
0176  * valid GTF format. If so, then it will return true, and fmt will be filled
0177  * in with the found GTF timings.
0178  */
0179 bool v4l2_detect_gtf(unsigned frame_height, unsigned hfreq, unsigned vsync,
0180         u32 polarities, bool interlaced, struct v4l2_fract aspect,
0181         struct v4l2_dv_timings *fmt);
0182 
0183 /**
0184  * v4l2_calc_aspect_ratio - calculate the aspect ratio based on bytes
0185  *  0x15 and 0x16 from the EDID.
0186  *
0187  * @hor_landscape: byte 0x15 from the EDID.
0188  * @vert_portrait: byte 0x16 from the EDID.
0189  *
0190  * Determines the aspect ratio from the EDID.
0191  * See VESA Enhanced EDID standard, release A, rev 2, section 3.6.2:
0192  * "Horizontal and Vertical Screen Size or Aspect Ratio"
0193  */
0194 struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, u8 vert_portrait);
0195 
0196 /**
0197  * v4l2_dv_timings_aspect_ratio - calculate the aspect ratio based on the
0198  *  v4l2_dv_timings information.
0199  *
0200  * @t: the timings data.
0201  */
0202 struct v4l2_fract v4l2_dv_timings_aspect_ratio(const struct v4l2_dv_timings *t);
0203 
0204 /**
0205  * can_reduce_fps - check if conditions for reduced fps are true.
0206  * @bt: v4l2 timing structure
0207  *
0208  * For different timings reduced fps is allowed if the following conditions
0209  * are met:
0210  *
0211  *   - For CVT timings: if reduced blanking v2 (vsync == 8) is true.
0212  *   - For CEA861 timings: if %V4L2_DV_FL_CAN_REDUCE_FPS flag is true.
0213  */
0214 static inline  bool can_reduce_fps(struct v4l2_bt_timings *bt)
0215 {
0216     if ((bt->standards & V4L2_DV_BT_STD_CVT) && (bt->vsync == 8))
0217         return true;
0218 
0219     if ((bt->standards & V4L2_DV_BT_STD_CEA861) &&
0220         (bt->flags & V4L2_DV_FL_CAN_REDUCE_FPS))
0221         return true;
0222 
0223     return false;
0224 }
0225 
0226 /**
0227  * struct v4l2_hdmi_colorimetry - describes the HDMI colorimetry information
0228  * @colorspace:     enum v4l2_colorspace, the colorspace
0229  * @ycbcr_enc:      enum v4l2_ycbcr_encoding, Y'CbCr encoding
0230  * @quantization:   enum v4l2_quantization, colorspace quantization
0231  * @xfer_func:      enum v4l2_xfer_func, colorspace transfer function
0232  */
0233 struct v4l2_hdmi_colorimetry {
0234     enum v4l2_colorspace colorspace;
0235     enum v4l2_ycbcr_encoding ycbcr_enc;
0236     enum v4l2_quantization quantization;
0237     enum v4l2_xfer_func xfer_func;
0238 };
0239 
0240 struct hdmi_avi_infoframe;
0241 struct hdmi_vendor_infoframe;
0242 
0243 struct v4l2_hdmi_colorimetry
0244 v4l2_hdmi_rx_colorimetry(const struct hdmi_avi_infoframe *avi,
0245              const struct hdmi_vendor_infoframe *hdmi,
0246              unsigned int height);
0247 
0248 u16 v4l2_get_edid_phys_addr(const u8 *edid, unsigned int size,
0249                 unsigned int *offset);
0250 void v4l2_set_edid_phys_addr(u8 *edid, unsigned int size, u16 phys_addr);
0251 u16 v4l2_phys_addr_for_input(u16 phys_addr, u8 input);
0252 int v4l2_phys_addr_validate(u16 phys_addr, u16 *parent, u16 *port);
0253 
0254 #endif