Lines Matching +full:cmd +full:- +full:max +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0-or-later
7 #include <linux/clk-provider.h>
52 u32 id = periph->id; in clk_peripheral_enable()
58 regmap_write(periph->regmap, offset, PERIPHERAL_MASK(id)); in clk_peripheral_enable()
67 u32 id = periph->id; in clk_peripheral_disable()
73 regmap_write(periph->regmap, offset, PERIPHERAL_MASK(id)); in clk_peripheral_disable()
81 u32 id = periph->id; in clk_peripheral_is_enabled()
87 regmap_read(periph->regmap, offset, &status); in clk_peripheral_is_enabled()
99 at91_clk_register_peripheral(struct regmap *regmap, const char *name, in at91_clk_register_peripheral() argument
108 if (!name || !(parent_name || parent_hw) || id > PERIPHERAL_ID_MAX) in at91_clk_register_peripheral()
109 return ERR_PTR(-EINVAL); in at91_clk_register_peripheral()
113 return ERR_PTR(-ENOMEM); in at91_clk_register_peripheral()
115 init.name = name; in at91_clk_register_peripheral()
124 periph->id = id; in at91_clk_register_peripheral()
125 periph->hw.init = &init; in at91_clk_register_peripheral()
126 periph->regmap = regmap; in at91_clk_register_peripheral()
128 hw = &periph->hw; in at91_clk_register_peripheral()
129 ret = clk_hw_register(NULL, &periph->hw); in at91_clk_register_peripheral()
144 if (!periph->auto_div) in clk_sam9x5_peripheral_autodiv()
147 if (periph->range.max) { in clk_sam9x5_peripheral_autodiv()
148 parent = clk_hw_get_parent_by_index(&periph->hw, 0); in clk_sam9x5_peripheral_autodiv()
154 if (parent_rate >> shift <= periph->range.max) in clk_sam9x5_peripheral_autodiv()
159 periph->auto_div = false; in clk_sam9x5_peripheral_autodiv()
160 periph->div = shift; in clk_sam9x5_peripheral_autodiv()
169 if (periph->id < PERIPHERAL_ID_MIN) in clk_sam9x5_peripheral_set()
172 spin_lock_irqsave(periph->lock, flags); in clk_sam9x5_peripheral_set()
173 regmap_write(periph->regmap, periph->layout->offset, in clk_sam9x5_peripheral_set()
174 (periph->id & periph->layout->pid_mask)); in clk_sam9x5_peripheral_set()
175 regmap_update_bits(periph->regmap, periph->layout->offset, in clk_sam9x5_peripheral_set()
176 periph->layout->div_mask | periph->layout->cmd | in clk_sam9x5_peripheral_set()
178 field_prep(periph->layout->div_mask, periph->div) | in clk_sam9x5_peripheral_set()
179 periph->layout->cmd | enable); in clk_sam9x5_peripheral_set()
180 spin_unlock_irqrestore(periph->lock, flags); in clk_sam9x5_peripheral_set()
197 if (periph->id < PERIPHERAL_ID_MIN) in clk_sam9x5_peripheral_disable()
200 spin_lock_irqsave(periph->lock, flags); in clk_sam9x5_peripheral_disable()
201 regmap_write(periph->regmap, periph->layout->offset, in clk_sam9x5_peripheral_disable()
202 (periph->id & periph->layout->pid_mask)); in clk_sam9x5_peripheral_disable()
203 regmap_update_bits(periph->regmap, periph->layout->offset, in clk_sam9x5_peripheral_disable()
204 AT91_PMC_PCR_EN | periph->layout->cmd, in clk_sam9x5_peripheral_disable()
205 periph->layout->cmd); in clk_sam9x5_peripheral_disable()
206 spin_unlock_irqrestore(periph->lock, flags); in clk_sam9x5_peripheral_disable()
215 if (periph->id < PERIPHERAL_ID_MIN) in clk_sam9x5_peripheral_is_enabled()
218 spin_lock_irqsave(periph->lock, flags); in clk_sam9x5_peripheral_is_enabled()
219 regmap_write(periph->regmap, periph->layout->offset, in clk_sam9x5_peripheral_is_enabled()
220 (periph->id & periph->layout->pid_mask)); in clk_sam9x5_peripheral_is_enabled()
221 regmap_read(periph->regmap, periph->layout->offset, &status); in clk_sam9x5_peripheral_is_enabled()
222 spin_unlock_irqrestore(periph->lock, flags); in clk_sam9x5_peripheral_is_enabled()
235 if (periph->id < PERIPHERAL_ID_MIN) in clk_sam9x5_peripheral_recalc_rate()
238 spin_lock_irqsave(periph->lock, flags); in clk_sam9x5_peripheral_recalc_rate()
239 regmap_write(periph->regmap, periph->layout->offset, in clk_sam9x5_peripheral_recalc_rate()
240 (periph->id & periph->layout->pid_mask)); in clk_sam9x5_peripheral_recalc_rate()
241 regmap_read(periph->regmap, periph->layout->offset, &status); in clk_sam9x5_peripheral_recalc_rate()
242 spin_unlock_irqrestore(periph->lock, flags); in clk_sam9x5_peripheral_recalc_rate()
245 periph->div = field_get(periph->layout->div_mask, status); in clk_sam9x5_peripheral_recalc_rate()
246 periph->auto_div = false; in clk_sam9x5_peripheral_recalc_rate()
251 return parent_rate >> periph->div; in clk_sam9x5_peripheral_recalc_rate()
261 unsigned long tmp_diff = abs(req->rate - tmp_rate); in clk_sam9x5_peripheral_best_diff()
266 req->best_parent_rate = parent_rate; in clk_sam9x5_peripheral_best_diff()
267 req->best_parent_hw = parent; in clk_sam9x5_peripheral_best_diff()
282 if (periph->id < PERIPHERAL_ID_MIN || !periph->range.max) { in clk_sam9x5_peripheral_determine_rate()
283 req->rate = parent_rate; in clk_sam9x5_peripheral_determine_rate()
292 if (periph->range.max && tmp_rate > periph->range.max) in clk_sam9x5_peripheral_determine_rate()
298 if (!best_diff || best_rate <= req->rate) in clk_sam9x5_peripheral_determine_rate()
302 if (periph->chg_pid < 0) in clk_sam9x5_peripheral_determine_rate()
306 parent = clk_hw_get_parent_by_index(hw, periph->chg_pid); in clk_sam9x5_peripheral_determine_rate()
313 clk_hw_forward_rate_request(hw, req, parent, &req_parent, req->rate << shift); in clk_sam9x5_peripheral_determine_rate()
325 (periph->range.max && best_rate > periph->range.max)) in clk_sam9x5_peripheral_determine_rate()
326 return -EINVAL; in clk_sam9x5_peripheral_determine_rate()
330 __clk_get_name((req->best_parent_hw)->clk), in clk_sam9x5_peripheral_determine_rate()
331 req->best_parent_rate); in clk_sam9x5_peripheral_determine_rate()
333 req->rate = best_rate; in clk_sam9x5_peripheral_determine_rate()
344 unsigned long cur_rate = req->best_parent_rate; in clk_sam9x5_peripheral_no_parent_determine_rate()
348 if (periph->id < PERIPHERAL_ID_MIN || !periph->range.max) { in clk_sam9x5_peripheral_no_parent_determine_rate()
349 req->rate = req->best_parent_rate; in clk_sam9x5_peripheral_no_parent_determine_rate()
354 if (periph->range.max) { in clk_sam9x5_peripheral_no_parent_determine_rate()
356 cur_rate = req->best_parent_rate >> shift; in clk_sam9x5_peripheral_no_parent_determine_rate()
357 if (cur_rate <= periph->range.max) in clk_sam9x5_peripheral_no_parent_determine_rate()
362 if (req->rate >= cur_rate) { in clk_sam9x5_peripheral_no_parent_determine_rate()
363 req->rate = cur_rate; in clk_sam9x5_peripheral_no_parent_determine_rate()
368 best_diff = cur_rate - req->rate; in clk_sam9x5_peripheral_no_parent_determine_rate()
371 cur_rate = req->best_parent_rate >> shift; in clk_sam9x5_peripheral_no_parent_determine_rate()
372 if (cur_rate < req->rate) in clk_sam9x5_peripheral_no_parent_determine_rate()
373 cur_diff = req->rate - cur_rate; in clk_sam9x5_peripheral_no_parent_determine_rate()
375 cur_diff = cur_rate - req->rate; in clk_sam9x5_peripheral_no_parent_determine_rate()
382 if (!best_diff || cur_rate < req->rate) in clk_sam9x5_peripheral_no_parent_determine_rate()
386 req->rate = best_rate; in clk_sam9x5_peripheral_no_parent_determine_rate()
397 if (periph->id < PERIPHERAL_ID_MIN || !periph->range.max) { in clk_sam9x5_peripheral_set_rate()
401 return -EINVAL; in clk_sam9x5_peripheral_set_rate()
404 if (periph->range.max && rate > periph->range.max) in clk_sam9x5_peripheral_set_rate()
405 return -EINVAL; in clk_sam9x5_peripheral_set_rate()
409 periph->auto_div = false; in clk_sam9x5_peripheral_set_rate()
410 periph->div = shift; in clk_sam9x5_peripheral_set_rate()
415 return -EINVAL; in clk_sam9x5_peripheral_set_rate()
422 periph->pms.status = clk_sam9x5_peripheral_is_enabled(hw); in clk_sam9x5_peripheral_save_context()
431 if (periph->pms.status) in clk_sam9x5_peripheral_restore_context()
432 clk_sam9x5_peripheral_set(periph, periph->pms.status); in clk_sam9x5_peripheral_restore_context()
460 const char *name, const char *parent_name, in at91_clk_register_sam9x5_peripheral() argument
470 if (!name || !(parent_name || parent_hw)) in at91_clk_register_sam9x5_peripheral()
471 return ERR_PTR(-EINVAL); in at91_clk_register_sam9x5_peripheral()
475 return ERR_PTR(-ENOMEM); in at91_clk_register_sam9x5_peripheral()
477 init.name = name; in at91_clk_register_sam9x5_peripheral()
492 periph->id = id; in at91_clk_register_sam9x5_peripheral()
493 periph->hw.init = &init; in at91_clk_register_sam9x5_peripheral()
494 periph->div = 0; in at91_clk_register_sam9x5_peripheral()
495 periph->regmap = regmap; in at91_clk_register_sam9x5_peripheral()
496 periph->lock = lock; in at91_clk_register_sam9x5_peripheral()
497 if (layout->div_mask) in at91_clk_register_sam9x5_peripheral()
498 periph->auto_div = true; in at91_clk_register_sam9x5_peripheral()
499 periph->layout = layout; in at91_clk_register_sam9x5_peripheral()
500 periph->range = *range; in at91_clk_register_sam9x5_peripheral()
501 periph->chg_pid = chg_pid; in at91_clk_register_sam9x5_peripheral()
503 hw = &periph->hw; in at91_clk_register_sam9x5_peripheral()
504 ret = clk_hw_register(NULL, &periph->hw); in at91_clk_register_sam9x5_peripheral()