sci-clk.c 18 KB

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