 +/* Sets phase given in degrees on given clock output */
 +int litex_clk_set_phase(struct clk_hw *hw, int degrees)
 +{
-+	struct litex_clk_clkout *l_clkout = clk_hw_to_litex_clk_clkout(hw);
++	struct litex_clk_clkout *lcko = clk_hw_to_litex_clk_clkout(hw);
 +	int ret;
 +	u16 bitset1, bitset2, reg2_mask;
-+	u8 *phase_mux = &l_clkout->phase.phase_mux,
-+	   *delay_time = &l_clkout->phase.delay_time,
-+	   *fract_cnt = &l_clkout->frac.frac,
-+	   *frac_en = &l_clkout->frac.frac_en,
-+	   *frac_wf_f = &l_clkout->frac.frac_wf_f,
-+	   *frac_wf_r = &l_clkout->frac.frac_wf_r,
-+	   *phase_mux_f = &l_clkout->frac.phase_mux_f,
-+	   clkout_nr = l_clkout->id;
-+
-+	l_clkout->ts_config.phase = degrees;
++	u8 *phase_mux = &lcko->phase.phase_mux,
++	   *delay_time = &lcko->phase.delay_time,
++	   *frac = &lcko->frac.frac,
++	   *frac_en = &lcko->frac.frac_en,
++	   *frac_wf_f = &lcko->frac.frac_wf_f,
++	   *frac_wf_r = &lcko->frac.frac_wf_r,
++	   *phase_mux_f = &lcko->frac.phase_mux_f,
++	   clkout_nr = lcko->id;
++
++	lcko->ts_config.phase = degrees;
 +	reg2_mask = REG2_PHASE_MASK;
 +	pr_debug("set_phase: %u deg", degrees);
 +
-+	if (*fract_cnt > 0 && degrees != 0) {
++	if (*frac > 0 && degrees != 0) {
 +		pr_err("CLKOUT%d: cannot set phase on that frequency",
 +								clkout_nr);
 +		return -ENOSYS;

+	if (ret != 0)
+		return -EINVAL;
+
+	l_clkout->ts_config.freq = rate;
+
+	ret = litex_clk_calc_all_params();
+	if (ret != 0)

+	int phase, dt_calc, dt, a_per_in_octets, a_phase_in_cycles,
+	    pm_rise_frac, pm_rise_frac_filtered, pm_fall,
+	    pm_fall_frac, pm_fall_frac_filtered;
+	u32 phase_offset, divider, frac;
+
+	phase_offset = lcko->ts_config.phase;
+	divider = lcko->config.div;
+	frac = lcko->frac.frac;
+
+	phase = phase_offset * 1000;
+	a_per_in_octets = (8 * divider) + frac;
+	a_phase_in_cycles = (phase + 10) * a_per_in_octets / 360000;
+
+	if ((a_phase_in_cycles & FULL_BYTE) != 0)
