Lines Matching +full:ti +full:- +full:sci
1 // SPDX-License-Identifier: GPL-2.0-only
3 * SCI Clock driver for keystone based devices
5 * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/
6 * Tero Kristo <t-kristo@ti.com>
8 #include <linux/clk-provider.h>
16 #include <linux/soc/ti/ti_sci_protocol.h>
25 * struct sci_clk_provider - TI SCI clock provider representation
26 * @sci: Handle to the System Control Interface protocol handler
27 * @ops: Pointer to the SCI ops to be used by the clocks
33 const struct ti_sci_handle *sci; member
41 * struct sci_clk - TI SCI clock representation
67 * sci_clk_prepare - Prepare (enable) a TI SCI clock
70 * Prepares a clock to be actively used. Returns the SCI protocol status.
75 bool enable_ssc = clk->flags & SCI_CLK_SSC_ENABLE; in sci_clk_prepare()
76 bool allow_freq_change = clk->flags & SCI_CLK_ALLOW_FREQ_CHANGE; in sci_clk_prepare()
77 bool input_termination = clk->flags & SCI_CLK_INPUT_TERMINATION; in sci_clk_prepare()
79 return clk->provider->ops->get_clock(clk->provider->sci, clk->dev_id, in sci_clk_prepare()
80 clk->clk_id, enable_ssc, in sci_clk_prepare()
86 * sci_clk_unprepare - Un-prepares (disables) a TI SCI clock
89 * Un-prepares a clock from active state.
96 ret = clk->provider->ops->put_clock(clk->provider->sci, clk->dev_id, in sci_clk_unprepare()
97 clk->clk_id); in sci_clk_unprepare()
99 dev_err(clk->provider->dev, in sci_clk_unprepare()
101 clk->dev_id, clk->clk_id, ret); in sci_clk_unprepare()
105 * sci_clk_is_prepared - Check if a TI SCI clock is prepared or not
108 * Checks if a clock is prepared (enabled) in hardware. Returns non-zero
117 ret = clk->provider->ops->is_on(clk->provider->sci, clk->dev_id, in sci_clk_is_prepared()
118 clk->clk_id, &req_state, in sci_clk_is_prepared()
121 dev_err(clk->provider->dev, in sci_clk_is_prepared()
123 clk->dev_id, clk->clk_id, ret); in sci_clk_is_prepared()
131 * sci_clk_recalc_rate - Get clock rate for a TI SCI clock
135 * Gets the current clock rate of a TI SCI clock. Returns the current
145 ret = clk->provider->ops->get_freq(clk->provider->sci, clk->dev_id, in sci_clk_recalc_rate()
146 clk->clk_id, &freq); in sci_clk_recalc_rate()
148 dev_err(clk->provider->dev, in sci_clk_recalc_rate()
149 "recalc-rate failed for dev=%d, clk=%d, ret=%d\n", in sci_clk_recalc_rate()
150 clk->dev_id, clk->clk_id, ret); in sci_clk_recalc_rate()
158 * sci_clk_determine_rate - Determines a clock rate a clock can be set to
162 * Determines a suitable clock rate and parent for a TI SCI clock.
163 * The parent handling is un-used, as generally the parent clock rates
174 if (clk->cached_req && clk->cached_req == req->rate) { in sci_clk_determine_rate()
175 req->rate = clk->cached_res; in sci_clk_determine_rate()
179 ret = clk->provider->ops->get_best_match_freq(clk->provider->sci, in sci_clk_determine_rate()
180 clk->dev_id, in sci_clk_determine_rate()
181 clk->clk_id, in sci_clk_determine_rate()
182 req->min_rate, in sci_clk_determine_rate()
183 req->rate, in sci_clk_determine_rate()
184 req->max_rate, in sci_clk_determine_rate()
187 dev_err(clk->provider->dev, in sci_clk_determine_rate()
188 "determine-rate failed for dev=%d, clk=%d, ret=%d\n", in sci_clk_determine_rate()
189 clk->dev_id, clk->clk_id, ret); in sci_clk_determine_rate()
193 clk->cached_req = req->rate; in sci_clk_determine_rate()
194 clk->cached_res = new_rate; in sci_clk_determine_rate()
196 req->rate = new_rate; in sci_clk_determine_rate()
202 * sci_clk_set_rate - Set rate for a TI SCI clock
205 * @parent_rate: rate of the clock parent, not used for TI SCI clocks
207 * Sets a clock frequency for a TI SCI clock. Returns the TI SCI
215 return clk->provider->ops->set_freq(clk->provider->sci, clk->dev_id, in sci_clk_set_rate()
216 clk->clk_id, rate / 10 * 9, rate, in sci_clk_set_rate()
221 * sci_clk_get_parent - Get the current parent of a TI SCI clock
224 * Returns the index of the currently selected parent for a TI SCI clock.
232 ret = clk->provider->ops->get_parent(clk->provider->sci, clk->dev_id, in sci_clk_get_parent()
233 clk->clk_id, (void *)&parent_id); in sci_clk_get_parent()
235 dev_err(clk->provider->dev, in sci_clk_get_parent()
236 "get-parent failed for dev=%d, clk=%d, ret=%d\n", in sci_clk_get_parent()
237 clk->dev_id, clk->clk_id, ret); in sci_clk_get_parent()
241 parent_id = parent_id - clk->clk_id - 1; in sci_clk_get_parent()
247 * sci_clk_set_parent - Set the parent of a TI SCI clock
251 * Sets the parent of a TI SCI clock. Return TI SCI protocol status.
257 clk->cached_req = 0; in sci_clk_set_parent()
259 return clk->provider->ops->set_parent(clk->provider->sci, clk->dev_id, in sci_clk_set_parent()
260 clk->clk_id, in sci_clk_set_parent()
261 index + 1 + clk->clk_id); in sci_clk_set_parent()
276 * _sci_clk_get - Gets a handle for an SCI clock
277 * @provider: Handle to SCI clock provider
278 * @sci_clk: Handle to the SCI clock to populate
280 * Gets a handle to an existing TI SCI hw clock, or builds a new clock
295 name = kasprintf(GFP_KERNEL, "clk:%d:%d", sci_clk->dev_id, in _sci_clk_build()
296 sci_clk->clk_id); in _sci_clk_build()
306 if (sci_clk->num_parents < 2) in _sci_clk_build()
307 sci_clk->num_parents = 0; in _sci_clk_build()
309 if (sci_clk->num_parents) { in _sci_clk_build()
310 parent_names = kcalloc(sci_clk->num_parents, sizeof(char *), in _sci_clk_build()
314 ret = -ENOMEM; in _sci_clk_build()
318 for (i = 0; i < sci_clk->num_parents; i++) { in _sci_clk_build()
322 sci_clk->dev_id, in _sci_clk_build()
323 sci_clk->clk_id + 1 + i); in _sci_clk_build()
325 ret = -ENOMEM; in _sci_clk_build()
334 init.num_parents = sci_clk->num_parents; in _sci_clk_build()
335 sci_clk->hw.init = &init; in _sci_clk_build()
337 ret = devm_clk_hw_register(provider->dev, &sci_clk->hw); in _sci_clk_build()
339 dev_err(provider->dev, "failed clk register with %d\n", ret); in _sci_clk_build()
343 for (i = 0; i < sci_clk->num_parents; i++) in _sci_clk_build()
359 if (ca->dev_id == cb->dev_id && ca->clk_id == cb->clk_id) in _cmp_sci_clk()
361 if (ca->dev_id > cb->dev_id || in _cmp_sci_clk()
362 (ca->dev_id == cb->dev_id && ca->clk_id > cb->clk_id)) in _cmp_sci_clk()
364 return -1; in _cmp_sci_clk()
368 * sci_clk_get - Xlate function for getting clock handles
372 * Xlate function for retrieving clock TI SCI hw clock handles based on
375 * to the TI SCI hw clock struct, or ERR_PTR value in failure.
383 if (clkspec->args_count != 2) in sci_clk_get()
384 return ERR_PTR(-EINVAL); in sci_clk_get()
386 key.dev_id = clkspec->args[0]; in sci_clk_get()
387 key.clk_id = clkspec->args[1]; in sci_clk_get()
389 clk = bsearch(&key, provider->clocks, provider->num_clocks, in sci_clk_get()
393 return ERR_PTR(-ENODEV); in sci_clk_get()
395 return &(*clk)->hw; in sci_clk_get()
403 for (i = 0; i < p->num_clocks; i++) { in ti_sci_init_clocks()
404 ret = _sci_clk_build(p, p->clocks[i]); in ti_sci_init_clocks()
413 { .compatible = "ti,k2g-sci-clk" },
431 struct device *dev = provider->dev; in ti_sci_scan_clocks_from_fw()
434 ret = provider->ops->get_num_parents(provider->sci, dev_id, in ti_sci_scan_clocks_from_fw()
470 return -ENOMEM; in ti_sci_scan_clocks_from_fw()
471 sci_clk->dev_id = dev_id; in ti_sci_scan_clocks_from_fw()
472 sci_clk->clk_id = clk_id; in ti_sci_scan_clocks_from_fw()
473 sci_clk->provider = provider; in ti_sci_scan_clocks_from_fw()
474 sci_clk->num_parents = num_parents; in ti_sci_scan_clocks_from_fw()
482 provider->clocks = devm_kmalloc_array(dev, num_clks, sizeof(sci_clk), in ti_sci_scan_clocks_from_fw()
484 if (!provider->clocks) in ti_sci_scan_clocks_from_fw()
485 return -ENOMEM; in ti_sci_scan_clocks_from_fw()
487 memcpy(provider->clocks, clks, num_clks * sizeof(sci_clk)); in ti_sci_scan_clocks_from_fw()
489 provider->num_clocks = num_clks; in ti_sci_scan_clocks_from_fw()
509 struct device *dev = provider->dev; in ti_sci_scan_clocks_from_dt()
520 "clocks", "assigned-clocks", "assigned-clock-parents", NULL in ti_sci_scan_clocks_from_dt()
542 "#clock-cells", index, in ti_sci_scan_clocks_from_dt()
547 if (args.args_count == 2 && args.np == dev->of_node) { in ti_sci_scan_clocks_from_dt()
551 return -ENOMEM; in ti_sci_scan_clocks_from_dt()
553 sci_clk->dev_id = args.args[0]; in ti_sci_scan_clocks_from_dt()
554 sci_clk->clk_id = args.args[1]; in ti_sci_scan_clocks_from_dt()
555 sci_clk->provider = provider; in ti_sci_scan_clocks_from_dt()
556 provider->ops->get_num_parents(provider->sci, in ti_sci_scan_clocks_from_dt()
557 sci_clk->dev_id, in ti_sci_scan_clocks_from_dt()
558 sci_clk->clk_id, in ti_sci_scan_clocks_from_dt()
559 (void *)&sci_clk->num_parents); in ti_sci_scan_clocks_from_dt()
560 list_add_tail(&sci_clk->node, &clks); in ti_sci_scan_clocks_from_dt()
564 num_parents = sci_clk->num_parents; in ti_sci_scan_clocks_from_dt()
572 * any mux clock from sci-clk driver in ti_sci_scan_clocks_from_dt()
580 sci_clk->dev_id, in ti_sci_scan_clocks_from_dt()
581 sci_clk->clk_id, num_parents); in ti_sci_scan_clocks_from_dt()
587 while (num_parents--) { in ti_sci_scan_clocks_from_dt()
592 return -ENOMEM; in ti_sci_scan_clocks_from_dt()
593 sci_clk->dev_id = args.args[0]; in ti_sci_scan_clocks_from_dt()
594 sci_clk->clk_id = clk_id++; in ti_sci_scan_clocks_from_dt()
595 sci_clk->provider = provider; in ti_sci_scan_clocks_from_dt()
596 list_add_tail(&sci_clk->node, &clks); in ti_sci_scan_clocks_from_dt()
608 provider->clocks = devm_kmalloc_array(dev, num_clks, sizeof(sci_clk), in ti_sci_scan_clocks_from_dt()
610 if (!provider->clocks) in ti_sci_scan_clocks_from_dt()
611 return -ENOMEM; in ti_sci_scan_clocks_from_dt()
617 if (prev && prev->dev_id == sci_clk->dev_id && in ti_sci_scan_clocks_from_dt()
618 prev->clk_id == sci_clk->clk_id) in ti_sci_scan_clocks_from_dt()
621 provider->clocks[num_clks++] = sci_clk; in ti_sci_scan_clocks_from_dt()
625 provider->num_clocks = num_clks; in ti_sci_scan_clocks_from_dt()
632 * ti_sci_clk_probe - Probe function for the TI SCI clock driver
635 * Probes the TI SCI clock device. Allocates a new clock provider
643 struct device *dev = &pdev->dev; in ti_sci_clk_probe()
644 struct device_node *np = dev->of_node; in ti_sci_clk_probe()
655 return -ENOMEM; in ti_sci_clk_probe()
657 provider->sci = handle; in ti_sci_clk_probe()
658 provider->ops = &handle->ops.clk_ops; in ti_sci_clk_probe()
659 provider->dev = dev; in ti_sci_clk_probe()
677 pr_err("ti-sci-init-clocks failed.\n"); in ti_sci_clk_probe()
685 * ti_sci_clk_remove - Remove TI SCI clock device
688 * Removes the TI SCI device. Unregisters the clock provider registered
694 of_clk_del_provider(pdev->dev.of_node); in ti_sci_clk_remove()
703 .name = "ti-sci-clk",
710 MODULE_DESCRIPTION("TI System Control Interface(SCI) Clock driver");
712 MODULE_ALIAS("platform:ti-sci-clk");