1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * SCI Clock driver for keystone based devices
4 *
5 * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/
6 * Tero Kristo <t-kristo@ti.com>
7 */
8 #include <linux/clk-provider.h>
9 #include <linux/err.h>
10 #include <linux/io.h>
11 #include <linux/module.h>
12 #include <linux/of.h>
13 #include <linux/platform_device.h>
14 #include <linux/slab.h>
15 #include <linux/soc/ti/ti_sci_protocol.h>
16 #include <linux/bsearch.h>
17 #include <linux/list_sort.h>
18
19 #define SCI_CLK_SSC_ENABLE BIT(0)
20 #define SCI_CLK_ALLOW_FREQ_CHANGE BIT(1)
21 #define SCI_CLK_INPUT_TERMINATION BIT(2)
22
23 /**
24 * struct sci_clk_provider - TI SCI clock provider representation
25 * @sci: Handle to the System Control Interface protocol handler
26 * @ops: Pointer to the SCI ops to be used by the clocks
27 * @dev: Device pointer for the clock provider
28 * @clocks: Clocks array for this device
29 * @num_clocks: Total number of clocks for this provider
30 */
31 struct sci_clk_provider {
32 const struct ti_sci_handle *sci;
33 const struct ti_sci_clk_ops *ops;
34 struct device *dev;
35 struct sci_clk **clocks;
36 int num_clocks;
37 };
38
39 /**
40 * struct sci_clk - TI SCI clock representation
41 * @hw: Hardware clock cookie for common clock framework
42 * @dev_id: Device index
43 * @clk_id: Clock index
44 * @num_parents: Number of parents for this clock
45 * @provider: Master clock provider
46 * @flags: Flags for the clock
47 * @node: Link for handling clocks probed via DT
48 * @cached_req: Cached requested freq for determine rate calls
49 * @cached_res: Cached result freq for determine rate calls
50 * @parent_id: Parent index for this clock
51 * @rate: Clock rate
52 */
53 struct sci_clk {
54 struct clk_hw hw;
55 u16 dev_id;
56 u32 clk_id;
57 u32 num_parents;
58 struct sci_clk_provider *provider;
59 u8 flags;
60 struct list_head node;
61 unsigned long cached_req;
62 unsigned long cached_res;
63 int parent_id;
64 unsigned long rate;
65 };
66
67 #define to_sci_clk(_hw) container_of(_hw, struct sci_clk, hw)
68
69 /**
70 * sci_clk_prepare - Prepare (enable) a TI SCI clock
71 * @hw: clock to prepare
72 *
73 * Prepares a clock to be actively used. Returns the SCI protocol status.
74 */
sci_clk_prepare(struct clk_hw * hw)75 static int sci_clk_prepare(struct clk_hw *hw)
76 {
77 struct sci_clk *clk = to_sci_clk(hw);
78 bool enable_ssc = clk->flags & SCI_CLK_SSC_ENABLE;
79 bool allow_freq_change = clk->flags & SCI_CLK_ALLOW_FREQ_CHANGE;
80 bool input_termination = clk->flags & SCI_CLK_INPUT_TERMINATION;
81
82 return clk->provider->ops->get_clock(clk->provider->sci, clk->dev_id,
83 clk->clk_id, enable_ssc,
84 allow_freq_change,
85 input_termination);
86 }
87
88 /**
89 * sci_clk_unprepare - Un-prepares (disables) a TI SCI clock
90 * @hw: clock to unprepare
91 *
92 * Un-prepares a clock from active state.
93 */
sci_clk_unprepare(struct clk_hw * hw)94 static void sci_clk_unprepare(struct clk_hw *hw)
95 {
96 struct sci_clk *clk = to_sci_clk(hw);
97 int ret;
98
99 ret = clk->provider->ops->put_clock(clk->provider->sci, clk->dev_id,
100 clk->clk_id);
101 if (ret)
102 dev_err(clk->provider->dev,
103 "unprepare failed for dev=%d, clk=%d, ret=%d\n",
104 clk->dev_id, clk->clk_id, ret);
105 }
106
107 /**
108 * sci_clk_is_prepared - Check if a TI SCI clock is prepared or not
109 * @hw: clock to check status for
110 *
111 * Checks if a clock is prepared (enabled) in hardware. Returns non-zero
112 * value if clock is enabled, zero otherwise.
113 */
sci_clk_is_prepared(struct clk_hw * hw)114 static int sci_clk_is_prepared(struct clk_hw *hw)
115 {
116 struct sci_clk *clk = to_sci_clk(hw);
117 bool req_state, current_state;
118 int ret;
119
120 ret = clk->provider->ops->is_on(clk->provider->sci, clk->dev_id,
121 clk->clk_id, &req_state,
122 ¤t_state);
123 if (ret) {
124 dev_err(clk->provider->dev,
125 "is_prepared failed for dev=%d, clk=%d, ret=%d\n",
126 clk->dev_id, clk->clk_id, ret);
127 return 0;
128 }
129
130 return req_state;
131 }
132
133 /**
134 * sci_clk_recalc_rate - Get clock rate for a TI SCI clock
135 * @hw: clock to get rate for
136 * @parent_rate: parent rate provided by common clock framework, not used
137 *
138 * Gets the current clock rate of a TI SCI clock. Returns the current
139 * clock rate, or zero in failure.
140 */
sci_clk_recalc_rate(struct clk_hw * hw,unsigned long parent_rate)141 static unsigned long sci_clk_recalc_rate(struct clk_hw *hw,
142 unsigned long parent_rate)
143 {
144 struct sci_clk *clk = to_sci_clk(hw);
145 u64 freq;
146 int ret;
147
148 ret = clk->provider->ops->get_freq(clk->provider->sci, clk->dev_id,
149 clk->clk_id, &freq);
150 if (ret) {
151 dev_err(clk->provider->dev,
152 "recalc-rate failed for dev=%d, clk=%d, ret=%d\n",
153 clk->dev_id, clk->clk_id, ret);
154 return 0;
155 }
156
157 clk->rate = freq;
158
159 return freq;
160 }
161
162 /**
163 * sci_clk_determine_rate - Determines a clock rate a clock can be set to
164 * @hw: clock to change rate for
165 * @req: requested rate configuration for the clock
166 *
167 * Determines a suitable clock rate and parent for a TI SCI clock.
168 * The parent handling is un-used, as generally the parent clock rates
169 * are not known by the kernel; instead these are internally handled
170 * by the firmware. Returns 0 on success, negative error value on failure.
171 */
sci_clk_determine_rate(struct clk_hw * hw,struct clk_rate_request * req)172 static int sci_clk_determine_rate(struct clk_hw *hw,
173 struct clk_rate_request *req)
174 {
175 struct sci_clk *clk = to_sci_clk(hw);
176 int ret;
177 u64 new_rate;
178
179 if (clk->cached_req && clk->cached_req == req->rate) {
180 req->rate = clk->cached_res;
181 return 0;
182 }
183
184 ret = clk->provider->ops->get_best_match_freq(clk->provider->sci,
185 clk->dev_id,
186 clk->clk_id,
187 req->min_rate,
188 req->rate,
189 req->max_rate,
190 &new_rate);
191 if (ret) {
192 dev_err(clk->provider->dev,
193 "determine-rate failed for dev=%d, clk=%d, ret=%d\n",
194 clk->dev_id, clk->clk_id, ret);
195 return ret;
196 }
197
198 clk->cached_req = req->rate;
199 clk->cached_res = new_rate;
200
201 req->rate = new_rate;
202
203 return 0;
204 }
205
206 /**
207 * sci_clk_set_rate - Set rate for a TI SCI clock
208 * @hw: clock to change rate for
209 * @rate: target rate for the clock
210 * @parent_rate: rate of the clock parent, not used for TI SCI clocks
211 *
212 * Sets a clock frequency for a TI SCI clock. Returns the TI SCI
213 * protocol status.
214 */
sci_clk_set_rate(struct clk_hw * hw,unsigned long rate,unsigned long parent_rate)215 static int sci_clk_set_rate(struct clk_hw *hw, unsigned long rate,
216 unsigned long parent_rate)
217 {
218 struct sci_clk *clk = to_sci_clk(hw);
219 int ret;
220
221 ret = clk->provider->ops->set_freq(clk->provider->sci, clk->dev_id,
222 clk->clk_id, rate / 10 * 9, rate,
223 rate / 10 * 11);
224 if (!ret)
225 clk->rate = rate;
226
227 return ret;
228 }
229
230 /**
231 * sci_clk_get_parent - Get the current parent of a TI SCI clock
232 * @hw: clock to get parent for
233 *
234 * Returns the index of the currently selected parent for a TI SCI clock.
235 */
sci_clk_get_parent(struct clk_hw * hw)236 static u8 sci_clk_get_parent(struct clk_hw *hw)
237 {
238 struct sci_clk *clk = to_sci_clk(hw);
239 u32 parent_id = 0;
240 int ret;
241
242 ret = clk->provider->ops->get_parent(clk->provider->sci, clk->dev_id,
243 clk->clk_id, (void *)&parent_id);
244 if (ret) {
245 dev_err(clk->provider->dev,
246 "get-parent failed for dev=%d, clk=%d, ret=%d\n",
247 clk->dev_id, clk->clk_id, ret);
248 clk->parent_id = ret;
249 return 0;
250 }
251
252 clk->parent_id = parent_id - clk->clk_id - 1;
253
254 return (u8)clk->parent_id;
255 }
256
257 /**
258 * sci_clk_set_parent - Set the parent of a TI SCI clock
259 * @hw: clock to set parent for
260 * @index: new parent index for the clock
261 *
262 * Sets the parent of a TI SCI clock. Return TI SCI protocol status.
263 */
sci_clk_set_parent(struct clk_hw * hw,u8 index)264 static int sci_clk_set_parent(struct clk_hw *hw, u8 index)
265 {
266 struct sci_clk *clk = to_sci_clk(hw);
267 int ret;
268
269 clk->cached_req = 0;
270
271 ret = clk->provider->ops->set_parent(clk->provider->sci, clk->dev_id,
272 clk->clk_id,
273 index + 1 + clk->clk_id);
274 if (!ret)
275 clk->parent_id = index;
276
277 return ret;
278 }
279
sci_clk_restore_context(struct clk_hw * hw)280 static void sci_clk_restore_context(struct clk_hw *hw)
281 {
282 struct sci_clk *clk = to_sci_clk(hw);
283
284 if (clk->num_parents > 1 && clk->parent_id >= 0)
285 sci_clk_set_parent(hw, (u8)clk->parent_id);
286
287 if (clk->rate)
288 sci_clk_set_rate(hw, clk->rate, 0);
289 }
290
291 static const struct clk_ops sci_clk_ops = {
292 .prepare = sci_clk_prepare,
293 .unprepare = sci_clk_unprepare,
294 .is_prepared = sci_clk_is_prepared,
295 .recalc_rate = sci_clk_recalc_rate,
296 .determine_rate = sci_clk_determine_rate,
297 .set_rate = sci_clk_set_rate,
298 .get_parent = sci_clk_get_parent,
299 .set_parent = sci_clk_set_parent,
300 .restore_context = sci_clk_restore_context,
301 };
302
303 /**
304 * _sci_clk_build - Gets a handle for an SCI clock
305 * @provider: Handle to SCI clock provider
306 * @sci_clk: Handle to the SCI clock to populate
307 *
308 * Gets a handle to an existing TI SCI hw clock, or builds a new clock
309 * entry and registers it with the common clock framework. Called from
310 * the common clock framework, when a corresponding of_clk_get call is
311 * executed, or recursively from itself when parsing parent clocks.
312 * Returns 0 on success, negative error code on failure.
313 */
_sci_clk_build(struct sci_clk_provider * provider,struct sci_clk * sci_clk)314 static int _sci_clk_build(struct sci_clk_provider *provider,
315 struct sci_clk *sci_clk)
316 {
317 struct clk_init_data init = { NULL };
318 char *name = NULL;
319 char **parent_names = NULL;
320 int i;
321 int ret = 0;
322
323 name = kasprintf(GFP_KERNEL, "clk:%d:%d", sci_clk->dev_id,
324 sci_clk->clk_id);
325 if (!name)
326 return -ENOMEM;
327
328 init.name = name;
329
330 /*
331 * From kernel point of view, we only care about a clocks parents,
332 * if it has more than 1 possible parent. In this case, it is going
333 * to have mux functionality. Otherwise it is going to act as a root
334 * clock.
335 */
336 if (sci_clk->num_parents < 2)
337 sci_clk->num_parents = 0;
338
339 if (sci_clk->num_parents) {
340 parent_names = kcalloc(sci_clk->num_parents, sizeof(char *),
341 GFP_KERNEL);
342
343 if (!parent_names) {
344 ret = -ENOMEM;
345 goto err;
346 }
347
348 for (i = 0; i < sci_clk->num_parents; i++) {
349 char *parent_name;
350
351 parent_name = kasprintf(GFP_KERNEL, "clk:%d:%d",
352 sci_clk->dev_id,
353 sci_clk->clk_id + 1 + i);
354 if (!parent_name) {
355 ret = -ENOMEM;
356 goto err;
357 }
358 parent_names[i] = parent_name;
359 }
360 init.parent_names = (void *)parent_names;
361 }
362
363 init.ops = &sci_clk_ops;
364 init.num_parents = sci_clk->num_parents;
365
366 /*
367 * A clock rate query to the SCI firmware will return 0 if either the
368 * clock itself is disabled or the attached device/consumer is disabled.
369 * This makes it inherently unsuitable for the caching of the clk
370 * framework.
371 */
372 init.flags = CLK_GET_RATE_NOCACHE;
373 sci_clk->hw.init = &init;
374
375 ret = devm_clk_hw_register(provider->dev, &sci_clk->hw);
376 if (ret)
377 dev_err(provider->dev, "failed clk register with %d\n", ret);
378
379 err:
380 if (parent_names) {
381 for (i = 0; i < sci_clk->num_parents; i++)
382 kfree(parent_names[i]);
383
384 kfree(parent_names);
385 }
386
387 kfree(name);
388
389 return ret;
390 }
391
_cmp_sci_clk(const void * a,const void * b)392 static int _cmp_sci_clk(const void *a, const void *b)
393 {
394 const struct sci_clk *ca = a;
395 const struct sci_clk *cb = *(struct sci_clk **)b;
396
397 if (ca->dev_id == cb->dev_id && ca->clk_id == cb->clk_id)
398 return 0;
399 if (ca->dev_id > cb->dev_id ||
400 (ca->dev_id == cb->dev_id && ca->clk_id > cb->clk_id))
401 return 1;
402 return -1;
403 }
404
405 /**
406 * sci_clk_get - Xlate function for getting clock handles
407 * @clkspec: device tree clock specifier
408 * @data: pointer to the clock provider
409 *
410 * Xlate function for retrieving clock TI SCI hw clock handles based on
411 * device tree clock specifier. Called from the common clock framework,
412 * when a corresponding of_clk_get call is executed. Returns a pointer
413 * to the TI SCI hw clock struct, or ERR_PTR value in failure.
414 */
sci_clk_get(struct of_phandle_args * clkspec,void * data)415 static struct clk_hw *sci_clk_get(struct of_phandle_args *clkspec, void *data)
416 {
417 struct sci_clk_provider *provider = data;
418 struct sci_clk **clk;
419 struct sci_clk key;
420
421 if (clkspec->args_count != 2)
422 return ERR_PTR(-EINVAL);
423
424 key.dev_id = clkspec->args[0];
425 key.clk_id = clkspec->args[1];
426
427 clk = bsearch(&key, provider->clocks, provider->num_clocks,
428 sizeof(*clk), _cmp_sci_clk);
429
430 if (!clk)
431 return ERR_PTR(-ENODEV);
432
433 return &(*clk)->hw;
434 }
435
ti_sci_init_clocks(struct sci_clk_provider * p)436 static int ti_sci_init_clocks(struct sci_clk_provider *p)
437 {
438 int i;
439 int ret;
440
441 for (i = 0; i < p->num_clocks; i++) {
442 ret = _sci_clk_build(p, p->clocks[i]);
443 if (ret)
444 return ret;
445 }
446
447 return 0;
448 }
449
450 static const struct of_device_id ti_sci_clk_of_match[] = {
451 { .compatible = "ti,k2g-sci-clk" },
452 { /* Sentinel */ },
453 };
454 MODULE_DEVICE_TABLE(of, ti_sci_clk_of_match);
455
456 #ifdef CONFIG_TI_SCI_CLK_PROBE_FROM_FW
ti_sci_scan_clocks_from_fw(struct sci_clk_provider * provider)457 static int ti_sci_scan_clocks_from_fw(struct sci_clk_provider *provider)
458 {
459 int ret;
460 int num_clks = 0;
461 struct sci_clk **clks = NULL;
462 struct sci_clk **tmp_clks;
463 struct sci_clk *sci_clk;
464 int max_clks = 0;
465 int clk_id = 0;
466 int dev_id = 0;
467 u32 num_parents = 0;
468 int gap_size = 0;
469 struct device *dev = provider->dev;
470
471 while (1) {
472 ret = provider->ops->get_num_parents(provider->sci, dev_id,
473 clk_id,
474 (void *)&num_parents);
475 if (ret) {
476 gap_size++;
477 if (!clk_id) {
478 if (gap_size >= 5)
479 break;
480 dev_id++;
481 } else {
482 if (gap_size >= 2) {
483 dev_id++;
484 clk_id = 0;
485 gap_size = 0;
486 } else {
487 clk_id++;
488 }
489 }
490 continue;
491 }
492
493 gap_size = 0;
494
495 if (num_clks == max_clks) {
496 tmp_clks = devm_kmalloc_array(dev, max_clks + 64,
497 sizeof(sci_clk),
498 GFP_KERNEL);
499 memcpy(tmp_clks, clks, max_clks * sizeof(sci_clk));
500 if (max_clks)
501 devm_kfree(dev, clks);
502 max_clks += 64;
503 clks = tmp_clks;
504 }
505
506 sci_clk = devm_kzalloc(dev, sizeof(*sci_clk), GFP_KERNEL);
507 if (!sci_clk)
508 return -ENOMEM;
509 sci_clk->dev_id = dev_id;
510 sci_clk->clk_id = clk_id;
511 sci_clk->provider = provider;
512 sci_clk->num_parents = num_parents;
513
514 clks[num_clks] = sci_clk;
515
516 clk_id++;
517 num_clks++;
518 }
519
520 provider->clocks = devm_kmemdup_array(dev, clks, num_clks, sizeof(sci_clk), GFP_KERNEL);
521 if (!provider->clocks)
522 return -ENOMEM;
523
524 provider->num_clocks = num_clks;
525
526 devm_kfree(dev, clks);
527
528 return 0;
529 }
530
531 #else
532
_cmp_sci_clk_list(void * priv,const struct list_head * a,const struct list_head * b)533 static int _cmp_sci_clk_list(void *priv, const struct list_head *a,
534 const struct list_head *b)
535 {
536 const struct sci_clk *ca = container_of(a, struct sci_clk, node);
537 const struct sci_clk *cb = container_of(b, struct sci_clk, node);
538
539 return _cmp_sci_clk(ca, &cb);
540 }
541
ti_sci_scan_clocks_from_dt(struct sci_clk_provider * provider)542 static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider)
543 {
544 struct device *dev = provider->dev;
545 struct device_node *np = NULL;
546 int ret;
547 int index;
548 struct of_phandle_args args;
549 struct list_head clks;
550 struct sci_clk *sci_clk, *prev;
551 int num_clks = 0;
552 int num_parents;
553 bool state;
554 int clk_id;
555 const char * const clk_names[] = {
556 "clocks", "assigned-clocks", "assigned-clock-parents", NULL
557 };
558 const char * const *clk_name;
559
560 INIT_LIST_HEAD(&clks);
561
562 clk_name = clk_names;
563
564 while (*clk_name) {
565 np = of_find_node_with_property(np, *clk_name);
566 if (!np) {
567 clk_name++;
568 continue;
569 }
570
571 if (!of_device_is_available(np))
572 continue;
573
574 index = 0;
575
576 do {
577 ret = of_parse_phandle_with_args(np, *clk_name,
578 "#clock-cells", index,
579 &args);
580 if (ret)
581 break;
582
583 if (args.args_count == 2 && args.np == dev->of_node) {
584 sci_clk = devm_kzalloc(dev, sizeof(*sci_clk),
585 GFP_KERNEL);
586 if (!sci_clk)
587 return -ENOMEM;
588
589 sci_clk->dev_id = args.args[0];
590 sci_clk->clk_id = args.args[1];
591 sci_clk->provider = provider;
592 provider->ops->get_num_parents(provider->sci,
593 sci_clk->dev_id,
594 sci_clk->clk_id,
595 (void *)&sci_clk->num_parents);
596 list_add_tail(&sci_clk->node, &clks);
597
598 num_clks++;
599
600 num_parents = sci_clk->num_parents;
601 if (num_parents == 1)
602 num_parents = 0;
603
604 /*
605 * Linux kernel has inherent limitation
606 * of 255 clock parents at the moment.
607 * Right now, it is not expected that
608 * any mux clock from sci-clk driver
609 * would exceed that limit either, but
610 * the ABI basically provides that
611 * possibility. Print out a warning if
612 * this happens for any clock.
613 */
614 if (num_parents >= 255) {
615 dev_warn(dev, "too many parents for dev=%d, clk=%d (%d), cropping to 255.\n",
616 sci_clk->dev_id,
617 sci_clk->clk_id, num_parents);
618 num_parents = 255;
619 }
620
621 clk_id = args.args[1] + 1;
622
623 while (num_parents--) {
624 /* Check if this clock id is valid */
625 ret = provider->ops->is_auto(provider->sci,
626 sci_clk->dev_id, clk_id, &state);
627
628 if (ret) {
629 clk_id++;
630 continue;
631 }
632
633 sci_clk = devm_kzalloc(dev,
634 sizeof(*sci_clk),
635 GFP_KERNEL);
636 if (!sci_clk)
637 return -ENOMEM;
638 sci_clk->dev_id = args.args[0];
639 sci_clk->clk_id = clk_id++;
640 sci_clk->provider = provider;
641 list_add_tail(&sci_clk->node, &clks);
642
643 num_clks++;
644 }
645 }
646
647 index++;
648 } while (args.np);
649 }
650
651 list_sort(NULL, &clks, _cmp_sci_clk_list);
652
653 provider->clocks = devm_kmalloc_array(dev, num_clks, sizeof(sci_clk),
654 GFP_KERNEL);
655 if (!provider->clocks)
656 return -ENOMEM;
657
658 num_clks = 0;
659 prev = NULL;
660
661 list_for_each_entry(sci_clk, &clks, node) {
662 if (prev && prev->dev_id == sci_clk->dev_id &&
663 prev->clk_id == sci_clk->clk_id)
664 continue;
665
666 provider->clocks[num_clks++] = sci_clk;
667 prev = sci_clk;
668 }
669
670 provider->num_clocks = num_clks;
671
672 return 0;
673 }
674 #endif
675
676 /**
677 * ti_sci_clk_probe - Probe function for the TI SCI clock driver
678 * @pdev: platform device pointer to be probed
679 *
680 * Probes the TI SCI clock device. Allocates a new clock provider
681 * and registers this to the common clock framework. Also applies
682 * any required flags to the identified clocks via clock lists
683 * supplied from DT. Returns 0 for success, negative error value
684 * for failure.
685 */
ti_sci_clk_probe(struct platform_device * pdev)686 static int ti_sci_clk_probe(struct platform_device *pdev)
687 {
688 struct device *dev = &pdev->dev;
689 struct device_node *np = dev->of_node;
690 struct sci_clk_provider *provider;
691 const struct ti_sci_handle *handle;
692 int ret;
693
694 handle = devm_ti_sci_get_handle(dev);
695 if (IS_ERR(handle))
696 return PTR_ERR(handle);
697
698 provider = devm_kzalloc(dev, sizeof(*provider), GFP_KERNEL);
699 if (!provider)
700 return -ENOMEM;
701
702 provider->sci = handle;
703 provider->ops = &handle->ops.clk_ops;
704 provider->dev = dev;
705
706 #ifdef CONFIG_TI_SCI_CLK_PROBE_FROM_FW
707 ret = ti_sci_scan_clocks_from_fw(provider);
708 if (ret) {
709 dev_err(dev, "scan clocks from FW failed: %d\n", ret);
710 return ret;
711 }
712 #else
713 ret = ti_sci_scan_clocks_from_dt(provider);
714 if (ret) {
715 dev_err(dev, "scan clocks from DT failed: %d\n", ret);
716 return ret;
717 }
718 #endif
719
720 ret = ti_sci_init_clocks(provider);
721 if (ret) {
722 pr_err("ti-sci-init-clocks failed.\n");
723 return ret;
724 }
725
726 return of_clk_add_hw_provider(np, sci_clk_get, provider);
727 }
728
729 /**
730 * ti_sci_clk_remove - Remove TI SCI clock device
731 * @pdev: platform device pointer for the device to be removed
732 *
733 * Removes the TI SCI device. Unregisters the clock provider registered
734 * via common clock framework. Any memory allocated for the device will
735 * be free'd silently via the devm framework. Returns 0 always.
736 */
ti_sci_clk_remove(struct platform_device * pdev)737 static void ti_sci_clk_remove(struct platform_device *pdev)
738 {
739 of_clk_del_provider(pdev->dev.of_node);
740 }
741
742 static struct platform_driver ti_sci_clk_driver = {
743 .probe = ti_sci_clk_probe,
744 .remove = ti_sci_clk_remove,
745 .driver = {
746 .name = "ti-sci-clk",
747 .of_match_table = of_match_ptr(ti_sci_clk_of_match),
748 },
749 };
750 module_platform_driver(ti_sci_clk_driver);
751
752 MODULE_LICENSE("GPL v2");
753 MODULE_DESCRIPTION("TI System Control Interface(SCI) Clock driver");
754 MODULE_AUTHOR("Tero Kristo");
755 MODULE_ALIAS("platform:ti-sci-clk");
756