sci-clk.c 18 KB

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