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()
289 if (periph->range.max && tmp_rate > periph->range.max) in clk_sam9x5_peripheral_determine_rate()
295 if (!best_diff || best_rate <= req->rate) in clk_sam9x5_peripheral_determine_rate()
299 if (periph->chg_pid < 0) in clk_sam9x5_peripheral_determine_rate()
303 parent = clk_hw_get_parent_by_index(hw, periph->chg_pid); in clk_sam9x5_peripheral_determine_rate()
310 clk_hw_forward_rate_request(hw, req, parent, &req_parent, req->rate << shift); in clk_sam9x5_peripheral_determine_rate()
322 (periph->range.max && best_rate > periph->range.max)) in clk_sam9x5_peripheral_determine_rate()
323 return -EINVAL; in clk_sam9x5_peripheral_determine_rate()
327 __clk_get_name((req->best_parent_hw)->clk), in clk_sam9x5_peripheral_determine_rate()
328 req->best_parent_rate); in clk_sam9x5_peripheral_determine_rate()
330 req->rate = best_rate; in clk_sam9x5_peripheral_determine_rate()
346 if (periph->id < PERIPHERAL_ID_MIN || !periph->range.max) in clk_sam9x5_peripheral_round_rate()
349 if (periph->range.max) { in clk_sam9x5_peripheral_round_rate()
352 if (cur_rate <= periph->range.max) in clk_sam9x5_peripheral_round_rate()
360 best_diff = cur_rate - rate; in clk_sam9x5_peripheral_round_rate()
365 cur_diff = rate - cur_rate; in clk_sam9x5_peripheral_round_rate()
367 cur_diff = cur_rate - rate; in clk_sam9x5_peripheral_round_rate()
387 if (periph->id < PERIPHERAL_ID_MIN || !periph->range.max) { in clk_sam9x5_peripheral_set_rate()
391 return -EINVAL; in clk_sam9x5_peripheral_set_rate()
394 if (periph->range.max && rate > periph->range.max) in clk_sam9x5_peripheral_set_rate()
395 return -EINVAL; in clk_sam9x5_peripheral_set_rate()
399 periph->auto_div = false; in clk_sam9x5_peripheral_set_rate()
400 periph->div = shift; in clk_sam9x5_peripheral_set_rate()
405 return -EINVAL; in clk_sam9x5_peripheral_set_rate()
412 periph->pms.status = clk_sam9x5_peripheral_is_enabled(hw); in clk_sam9x5_peripheral_save_context()
421 if (periph->pms.status) in clk_sam9x5_peripheral_restore_context()
422 clk_sam9x5_peripheral_set(periph, periph->pms.status); in clk_sam9x5_peripheral_restore_context()
450 const char *name, const char *parent_name, in at91_clk_register_sam9x5_peripheral() argument
460 if (!name || !(parent_name || parent_hw)) in at91_clk_register_sam9x5_peripheral()
461 return ERR_PTR(-EINVAL); in at91_clk_register_sam9x5_peripheral()
465 return ERR_PTR(-ENOMEM); in at91_clk_register_sam9x5_peripheral()
467 init.name = name; in at91_clk_register_sam9x5_peripheral()
482 periph->id = id; in at91_clk_register_sam9x5_peripheral()
483 periph->hw.init = &init; in at91_clk_register_sam9x5_peripheral()
484 periph->div = 0; in at91_clk_register_sam9x5_peripheral()
485 periph->regmap = regmap; in at91_clk_register_sam9x5_peripheral()
486 periph->lock = lock; in at91_clk_register_sam9x5_peripheral()
487 if (layout->div_mask) in at91_clk_register_sam9x5_peripheral()
488 periph->auto_div = true; in at91_clk_register_sam9x5_peripheral()
489 periph->layout = layout; in at91_clk_register_sam9x5_peripheral()
490 periph->range = *range; in at91_clk_register_sam9x5_peripheral()
491 periph->chg_pid = chg_pid; in at91_clk_register_sam9x5_peripheral()
493 hw = &periph->hw; in at91_clk_register_sam9x5_peripheral()
494 ret = clk_hw_register(NULL, &periph->hw); in at91_clk_register_sam9x5_peripheral()