Lines Matching +full:reg +full:- +full:init

1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Maxime Ripard <maxime.ripard@free-electrons.com>
9 #include <linux/clk-provider.h>
49 (rate - tmp_rate) < (rate - best_rate)) { in sun4i_tmds_calc_divider()
72 unsigned long rate = req->rate; in sun4i_tmds_determine_rate()
88 for (j = tmds->div_offset ?: 1; in sun4i_tmds_determine_rate()
89 j < (16 + tmds->div_offset); j++) { in sun4i_tmds_determine_rate()
103 abs(rate - rounded / i / j) < in sun4i_tmds_determine_rate()
104 abs(rate - best_parent / best_half / in sun4i_tmds_determine_rate()
115 return -EINVAL; in sun4i_tmds_determine_rate()
118 req->rate = best_parent / best_half / best_div; in sun4i_tmds_determine_rate()
119 req->best_parent_rate = best_parent; in sun4i_tmds_determine_rate()
120 req->best_parent_hw = parent; in sun4i_tmds_determine_rate()
129 u32 reg; in sun4i_tmds_recalc_rate() local
131 reg = readl(tmds->hdmi->base + SUN4I_HDMI_PAD_CTRL1_REG); in sun4i_tmds_recalc_rate()
132 if (reg & SUN4I_HDMI_PAD_CTRL1_HALVE_CLK) in sun4i_tmds_recalc_rate()
135 reg = readl(tmds->hdmi->base + SUN4I_HDMI_PLL_CTRL_REG); in sun4i_tmds_recalc_rate()
136 reg = ((reg >> 4) & 0xf) + tmds->div_offset; in sun4i_tmds_recalc_rate()
137 if (!reg) in sun4i_tmds_recalc_rate()
138 reg = 1; in sun4i_tmds_recalc_rate()
140 return parent_rate / reg; in sun4i_tmds_recalc_rate()
148 u32 reg; in sun4i_tmds_set_rate() local
151 sun4i_tmds_calc_divider(rate, parent_rate, tmds->div_offset, in sun4i_tmds_set_rate()
154 reg = readl(tmds->hdmi->base + SUN4I_HDMI_PAD_CTRL1_REG); in sun4i_tmds_set_rate()
155 reg &= ~SUN4I_HDMI_PAD_CTRL1_HALVE_CLK; in sun4i_tmds_set_rate()
157 reg |= SUN4I_HDMI_PAD_CTRL1_HALVE_CLK; in sun4i_tmds_set_rate()
158 writel(reg, tmds->hdmi->base + SUN4I_HDMI_PAD_CTRL1_REG); in sun4i_tmds_set_rate()
160 reg = readl(tmds->hdmi->base + SUN4I_HDMI_PLL_CTRL_REG); in sun4i_tmds_set_rate()
161 reg &= ~SUN4I_HDMI_PLL_CTRL_DIV_MASK; in sun4i_tmds_set_rate()
162 writel(reg | SUN4I_HDMI_PLL_CTRL_DIV(div - tmds->div_offset), in sun4i_tmds_set_rate()
163 tmds->hdmi->base + SUN4I_HDMI_PLL_CTRL_REG); in sun4i_tmds_set_rate()
171 u32 reg; in sun4i_tmds_get_parent() local
173 reg = readl(tmds->hdmi->base + SUN4I_HDMI_PLL_DBG0_REG); in sun4i_tmds_get_parent()
174 return ((reg & SUN4I_HDMI_PLL_DBG0_TMDS_PARENT_MASK) >> in sun4i_tmds_get_parent()
181 u32 reg; in sun4i_tmds_set_parent() local
184 return -EINVAL; in sun4i_tmds_set_parent()
186 reg = readl(tmds->hdmi->base + SUN4I_HDMI_PLL_DBG0_REG); in sun4i_tmds_set_parent()
187 reg &= ~SUN4I_HDMI_PLL_DBG0_TMDS_PARENT_MASK; in sun4i_tmds_set_parent()
188 writel(reg | SUN4I_HDMI_PLL_DBG0_TMDS_PARENT(index), in sun4i_tmds_set_parent()
189 tmds->hdmi->base + SUN4I_HDMI_PLL_DBG0_REG); in sun4i_tmds_set_parent()
205 struct clk_init_data init; in sun4i_tmds_create() local
209 parents[0] = __clk_get_name(hdmi->pll0_clk); in sun4i_tmds_create()
211 return -ENODEV; in sun4i_tmds_create()
213 parents[1] = __clk_get_name(hdmi->pll1_clk); in sun4i_tmds_create()
215 return -ENODEV; in sun4i_tmds_create()
217 tmds = devm_kzalloc(hdmi->dev, sizeof(*tmds), GFP_KERNEL); in sun4i_tmds_create()
219 return -ENOMEM; in sun4i_tmds_create()
221 init.name = "hdmi-tmds"; in sun4i_tmds_create()
222 init.ops = &sun4i_tmds_ops; in sun4i_tmds_create()
223 init.parent_names = parents; in sun4i_tmds_create()
224 init.num_parents = 2; in sun4i_tmds_create()
225 init.flags = CLK_SET_RATE_PARENT; in sun4i_tmds_create()
227 tmds->hdmi = hdmi; in sun4i_tmds_create()
228 tmds->hw.init = &init; in sun4i_tmds_create()
229 tmds->div_offset = hdmi->variant->tmds_clk_div_offset; in sun4i_tmds_create()
231 hdmi->tmds_clk = devm_clk_register(hdmi->dev, &tmds->hw); in sun4i_tmds_create()
232 if (IS_ERR(hdmi->tmds_clk)) in sun4i_tmds_create()
233 return PTR_ERR(hdmi->tmds_clk); in sun4i_tmds_create()