Home | History | Annotate | Line # | Download | only in inc
      1 /*	$NetBSD: clock_source.h,v 1.3 2021/12/19 11:23:17 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2012-15 Advanced Micro Devices, Inc.
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the "Software"),
      8  * to deal in the Software without restriction, including without limitation
      9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  * and/or sell copies of the Software, and to permit persons to whom the
     11  * Software is furnished to do so, subject to the following conditions:
     12  *
     13  * The above copyright notice and this permission notice shall be included in
     14  * all copies or substantial portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  * OTHER DEALINGS IN THE SOFTWARE.
     23  *
     24  * Authors: AMD
     25  *
     26  */
     27 
     28 #ifndef __DC_CLOCK_SOURCE_H__
     29 #define __DC_CLOCK_SOURCE_H__
     30 
     31 #include "dc_types.h"
     32 #include "include/grph_object_id.h"
     33 #include "include/bios_parser_types.h"
     34 
     35 struct clock_source;
     36 
     37 struct spread_spectrum_data {
     38 	uint32_t percentage;		/*> In unit of 0.01% or 0.001%*/
     39 	uint32_t percentage_divider;	/*> 100 or 1000	*/
     40 	uint32_t freq_range_khz;
     41 	uint32_t modulation_freq_hz;
     42 
     43 	struct spread_spectrum_flags flags;
     44 };
     45 
     46 struct delta_sigma_data {
     47 	uint32_t feedback_amount;
     48 	uint32_t nfrac_amount;
     49 	uint32_t ds_frac_size;
     50 	uint32_t ds_frac_amount;
     51 };
     52 
     53 /**
     54  *  Pixel Clock Parameters structure
     55  *  These parameters are required as input
     56  *  when calculating Pixel Clock Dividers for requested Pixel Clock
     57  */
     58 struct pixel_clk_flags {
     59 	uint32_t ENABLE_SS:1;
     60 	uint32_t DISPLAY_BLANKED:1;
     61 	uint32_t PROGRAM_PIXEL_CLOCK:1;
     62 	uint32_t PROGRAM_ID_CLOCK:1;
     63 	uint32_t SUPPORT_YCBCR420:1;
     64 };
     65 
     66 /**
     67  *  Display Port HW De spread of Reference Clock related Parameters structure
     68  *  Store it once at boot for later usage
     69   */
     70 struct csdp_ref_clk_ds_params {
     71 	bool hw_dso_n_dp_ref_clk;
     72 /* Flag for HW De Spread enabled (if enabled SS on DP Reference Clock)*/
     73 	uint32_t avg_dp_ref_clk_khz;
     74 /* Average DP Reference clock (in KHz)*/
     75 	uint32_t ss_percentage_on_dp_ref_clk;
     76 /* DP Reference clock SS percentage
     77  * (not to be mixed with DP IDCLK SS from PLL Settings)*/
     78 	uint32_t ss_percentage_divider;
     79 /* DP Reference clock SS percentage divider */
     80 };
     81 
     82 struct pixel_clk_params {
     83 	uint32_t requested_pix_clk_100hz;
     84 /*> Requested Pixel Clock
     85  * (based on Video Timing standard used for requested mode)*/
     86 	uint32_t requested_sym_clk; /* in KHz */
     87 /*> Requested Sym Clock (relevant only for display port)*/
     88 	uint32_t dp_ref_clk; /* in KHz */
     89 /*> DP reference clock - calculated only for DP signal for specific cases*/
     90 	struct graphics_object_id encoder_object_id;
     91 /*> Encoder object Id - needed by VBIOS Exec table*/
     92 	enum signal_type signal_type;
     93 /*> signalType -> Encoder Mode - needed by VBIOS Exec table*/
     94 	enum controller_id controller_id;
     95 /*> ControllerId - which controller using this PLL*/
     96 	enum dc_color_depth color_depth;
     97 	struct csdp_ref_clk_ds_params de_spread_params;
     98 /*> de-spread info, relevant only for on-the-fly tune-up pixel rate*/
     99 	enum dc_pixel_encoding pixel_encoding;
    100 	struct pixel_clk_flags flags;
    101 };
    102 
    103 /**
    104  *  Pixel Clock Dividers structure with desired Pixel Clock
    105  *  (adjusted after VBIOS exec table),
    106  *  with actually calculated Clock and reference Crystal frequency
    107  */
    108 struct pll_settings {
    109 	uint32_t actual_pix_clk_100hz;
    110 	uint32_t adjusted_pix_clk_100hz;
    111 	uint32_t calculated_pix_clk_100hz;
    112 	uint32_t vco_freq;
    113 	uint32_t reference_freq;
    114 	uint32_t reference_divider;
    115 	uint32_t feedback_divider;
    116 	uint32_t fract_feedback_divider;
    117 	uint32_t pix_clk_post_divider;
    118 	uint32_t ss_percentage;
    119 	bool use_external_clk;
    120 };
    121 
    122 struct calc_pll_clock_source_init_data {
    123 	struct dc_bios *bp;
    124 	uint32_t min_pix_clk_pll_post_divider;
    125 	uint32_t max_pix_clk_pll_post_divider;
    126 	uint32_t min_pll_ref_divider;
    127 	uint32_t max_pll_ref_divider;
    128 	uint32_t min_override_input_pxl_clk_pll_freq_khz;
    129 /* if not 0, override the firmware info */
    130 
    131 	uint32_t max_override_input_pxl_clk_pll_freq_khz;
    132 /* if not 0, override the firmware info */
    133 
    134 	uint32_t num_fract_fb_divider_decimal_point;
    135 /* number of decimal point for fractional feedback divider value */
    136 
    137 	uint32_t num_fract_fb_divider_decimal_point_precision;
    138 /* number of decimal point to round off for fractional feedback divider value*/
    139 	struct dc_context *ctx;
    140 
    141 };
    142 
    143 struct calc_pll_clock_source {
    144 	uint32_t ref_freq_khz;
    145 	uint32_t min_pix_clock_pll_post_divider;
    146 	uint32_t max_pix_clock_pll_post_divider;
    147 	uint32_t min_pll_ref_divider;
    148 	uint32_t max_pll_ref_divider;
    149 
    150 	uint32_t max_vco_khz;
    151 	uint32_t min_vco_khz;
    152 	uint32_t min_pll_input_freq_khz;
    153 	uint32_t max_pll_input_freq_khz;
    154 
    155 	uint32_t fract_fb_divider_decimal_points_num;
    156 	uint32_t fract_fb_divider_factor;
    157 	uint32_t fract_fb_divider_precision;
    158 	uint32_t fract_fb_divider_precision_factor;
    159 	struct dc_context *ctx;
    160 };
    161 
    162 struct clock_source_funcs {
    163 	bool (*cs_power_down)(
    164 			struct clock_source *);
    165 	bool (*program_pix_clk)(struct clock_source *,
    166 			struct pixel_clk_params *, struct pll_settings *);
    167 	uint32_t (*get_pix_clk_dividers)(
    168 			struct clock_source *,
    169 			struct pixel_clk_params *,
    170 			struct pll_settings *);
    171 	bool (*get_pixel_clk_frequency_100hz)(
    172 			struct clock_source *clock_source,
    173 			unsigned int inst,
    174 			unsigned int *pixel_clk_khz);
    175 };
    176 
    177 struct clock_source {
    178 	const struct clock_source_funcs *funcs;
    179 	struct dc_context *ctx;
    180 	enum clock_source_id id;
    181 	bool dp_clk_src;
    182 };
    183 
    184 #endif
    185