1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (C) 2022, Intel Corporation. */ 3 4 #ifndef _ICE_DPLL_H_ 5 #define _ICE_DPLL_H_ 6 7 #include "ice.h" 8 9 #define ICE_DPLL_RCLK_NUM_MAX 4 10 11 /** 12 * enum ice_dpll_pin_sw - enumerate ice software pin indices: 13 * @ICE_DPLL_PIN_SW_1_IDX: index of first SW pin 14 * @ICE_DPLL_PIN_SW_2_IDX: index of second SW pin 15 * @ICE_DPLL_PIN_SW_NUM: number of SW pins in pair 16 */ 17 enum ice_dpll_pin_sw { 18 ICE_DPLL_PIN_SW_1_IDX, 19 ICE_DPLL_PIN_SW_2_IDX, 20 ICE_DPLL_PIN_SW_NUM 21 }; 22 23 /** ice_dpll_pin - store info about pins 24 * @pin: dpll pin structure 25 * @pf: pointer to pf, which has registered the dpll_pin 26 * @idx: ice pin private idx 27 * @num_parents: hols number of parent pins 28 * @parent_idx: hold indexes of parent pins 29 * @flags: pin flags returned from HW 30 * @state: state of a pin 31 * @prop: pin properties 32 * @freq: current frequency of a pin 33 * @phase_adjust: current phase adjust value 34 * @phase_offset: monitored phase offset value 35 */ 36 struct ice_dpll_pin { 37 struct dpll_pin *pin; 38 struct ice_pf *pf; 39 u8 idx; 40 u8 num_parents; 41 u8 parent_idx[ICE_DPLL_RCLK_NUM_MAX]; 42 u8 flags[ICE_DPLL_RCLK_NUM_MAX]; 43 u8 state[ICE_DPLL_RCLK_NUM_MAX]; 44 struct dpll_pin_properties prop; 45 u32 freq; 46 s32 phase_adjust; 47 struct ice_dpll_pin *input; 48 struct ice_dpll_pin *output; 49 enum dpll_pin_direction direction; 50 s64 phase_offset; 51 u8 status; 52 bool active; 53 bool hidden; 54 }; 55 56 /** ice_dpll - store info required for DPLL control 57 * @dpll: pointer to dpll dev 58 * @pf: pointer to pf, which has registered the dpll_device 59 * @dpll_idx: index of dpll on the NIC 60 * @input_idx: currently selected input index 61 * @prev_input_idx: previously selected input index 62 * @ref_state: state of dpll reference signals 63 * @eec_mode: eec_mode dpll is configured for 64 * @phase_offset: phase offset of active pin vs dpll signal 65 * @prev_phase_offset: previous phase offset of active pin vs dpll signal 66 * @input_prio: priorities of each input 67 * @dpll_state: current dpll sync state 68 * @prev_dpll_state: last dpll sync state 69 * @phase_offset_monitor_period: period for phase offset monitor read frequency 70 * @active_input: pointer to active input pin 71 * @prev_input: pointer to previous active input pin 72 * @ops: holds the registered ops 73 */ 74 struct ice_dpll { 75 struct dpll_device *dpll; 76 struct ice_pf *pf; 77 u8 dpll_idx; 78 u8 input_idx; 79 u8 prev_input_idx; 80 u8 ref_state; 81 u8 eec_mode; 82 s64 phase_offset; 83 s64 prev_phase_offset; 84 u8 *input_prio; 85 enum dpll_lock_status dpll_state; 86 enum dpll_lock_status prev_dpll_state; 87 enum dpll_mode mode; 88 u32 phase_offset_monitor_period; 89 struct dpll_pin *active_input; 90 struct dpll_pin *prev_input; 91 const struct dpll_device_ops *ops; 92 }; 93 94 /** ice_dplls - store info required for CCU (clock controlling unit) 95 * @kworker: periodic worker 96 * @work: periodic work 97 * @lock: locks access to configuration of a dpll 98 * @eec: pointer to EEC dpll dev 99 * @pps: pointer to PPS dpll dev 100 * @inputs: input pins pointer 101 * @outputs: output pins pointer 102 * @rclk: recovered pins pointer 103 * @num_inputs: number of input pins available on dpll 104 * @num_outputs: number of output pins available on dpll 105 * @cgu_state_acq_err_num: number of errors returned during periodic work 106 * @base_rclk_idx: idx of first pin used for clock revocery pins 107 * @clock_id: clock_id of dplls 108 * @input_phase_adj_max: max phase adjust value for an input pins 109 * @output_phase_adj_max: max phase adjust value for an output pins 110 * @periodic_counter: counter of periodic work executions 111 */ 112 struct ice_dplls { 113 struct kthread_worker *kworker; 114 struct kthread_delayed_work work; 115 struct mutex lock; 116 struct ice_dpll eec; 117 struct ice_dpll pps; 118 struct ice_dpll_pin *inputs; 119 struct ice_dpll_pin *outputs; 120 struct ice_dpll_pin sma[ICE_DPLL_PIN_SW_NUM]; 121 struct ice_dpll_pin ufl[ICE_DPLL_PIN_SW_NUM]; 122 struct ice_dpll_pin rclk; 123 u8 num_inputs; 124 u8 num_outputs; 125 u8 sma_data; 126 u8 base_rclk_idx; 127 int cgu_state_acq_err_num; 128 u64 clock_id; 129 s32 input_phase_adj_max; 130 s32 output_phase_adj_max; 131 u32 periodic_counter; 132 bool generic; 133 }; 134 135 #if IS_ENABLED(CONFIG_PTP_1588_CLOCK) 136 void ice_dpll_init(struct ice_pf *pf); 137 void ice_dpll_deinit(struct ice_pf *pf); 138 #else 139 static inline void ice_dpll_init(struct ice_pf *pf) { } 140 static inline void ice_dpll_deinit(struct ice_pf *pf) { } 141 #endif 142 143 #endif 144