clkc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Zynq UltraScale+ MPSoC clock controller
  4. *
  5. * Copyright (C) 2016-2018 Xilinx
  6. *
  7. * Based on drivers/clk/zynq/clkc.c
  8. */
  9. #include <linux/bitfield.h>
  10. #include <linux/clk.h>
  11. #include <linux/clk-provider.h>
  12. #include <linux/module.h>
  13. #include <linux/of_platform.h>
  14. #include <linux/slab.h>
  15. #include <linux/string.h>
  16. #include "clk-zynqmp.h"
  17. #define MAX_PARENT 100
  18. #define MAX_NODES 6
  19. #define MAX_NAME_LEN 50
  20. #define CLK_TYPE_SHIFT 2
  21. #define PM_API_PAYLOAD_LEN 3
  22. #define NA_PARENT 0xFFFFFFFF
  23. #define DUMMY_PARENT 0xFFFFFFFE
  24. #define CLK_TYPE_FIELD_LEN 4
  25. #define CLK_TOPOLOGY_NODE_OFFSET 16
  26. #define NODES_PER_RESP 3
  27. #define CLK_TYPE_FIELD_MASK 0xF
  28. #define CLK_FLAG_FIELD_MASK GENMASK(21, 8)
  29. #define CLK_TYPE_FLAG_FIELD_MASK GENMASK(31, 24)
  30. #define CLK_PARENTS_ID_LEN 16
  31. #define CLK_PARENTS_ID_MASK 0xFFFF
  32. /* Flags for parents */
  33. #define PARENT_CLK_SELF 0
  34. #define PARENT_CLK_NODE1 1
  35. #define PARENT_CLK_NODE2 2
  36. #define PARENT_CLK_NODE3 3
  37. #define PARENT_CLK_NODE4 4
  38. #define PARENT_CLK_EXTERNAL 5
  39. #define END_OF_CLK_NAME "END_OF_CLK"
  40. #define END_OF_TOPOLOGY_NODE 1
  41. #define END_OF_PARENTS 1
  42. #define RESERVED_CLK_NAME ""
  43. #define CLK_VALID_MASK 0x1
  44. enum clk_type {
  45. CLK_TYPE_OUTPUT,
  46. CLK_TYPE_EXTERNAL,
  47. };
  48. /**
  49. * struct clock_parent - Clock parent
  50. * @name: Parent name
  51. * @id: Parent clock ID
  52. * @flag: Parent flags
  53. */
  54. struct clock_parent {
  55. char name[MAX_NAME_LEN];
  56. int id;
  57. u32 flag;
  58. };
  59. /**
  60. * struct zynqmp_clock - Clock
  61. * @clk_name: Clock name
  62. * @valid: Validity flag of clock
  63. * @type: Clock type (Output/External)
  64. * @node: Clock topology nodes
  65. * @num_nodes: Number of nodes present in topology
  66. * @parent: Parent of clock
  67. * @num_parents: Number of parents of clock
  68. */
  69. struct zynqmp_clock {
  70. char clk_name[MAX_NAME_LEN];
  71. u32 valid;
  72. enum clk_type type;
  73. struct clock_topology node[MAX_NODES];
  74. u32 num_nodes;
  75. struct clock_parent parent[MAX_PARENT];
  76. u32 num_parents;
  77. };
  78. static const char clk_type_postfix[][10] = {
  79. [TYPE_INVALID] = "",
  80. [TYPE_MUX] = "_mux",
  81. [TYPE_GATE] = "",
  82. [TYPE_DIV1] = "_div1",
  83. [TYPE_DIV2] = "_div2",
  84. [TYPE_FIXEDFACTOR] = "_ff",
  85. [TYPE_PLL] = ""
  86. };
  87. static struct clk_hw *(* const clk_topology[]) (const char *name, u32 clk_id,
  88. const char * const *parents,
  89. u8 num_parents,
  90. const struct clock_topology *nodes)
  91. = {
  92. [TYPE_INVALID] = NULL,
  93. [TYPE_MUX] = zynqmp_clk_register_mux,
  94. [TYPE_PLL] = zynqmp_clk_register_pll,
  95. [TYPE_FIXEDFACTOR] = zynqmp_clk_register_fixed_factor,
  96. [TYPE_DIV1] = zynqmp_clk_register_divider,
  97. [TYPE_DIV2] = zynqmp_clk_register_divider,
  98. [TYPE_GATE] = zynqmp_clk_register_gate
  99. };
  100. static struct zynqmp_clock *clock;
  101. static struct clk_hw_onecell_data *zynqmp_data;
  102. static unsigned int clock_max_idx;
  103. static const struct zynqmp_eemi_ops *eemi_ops;
  104. /**
  105. * zynqmp_is_valid_clock() - Check whether clock is valid or not
  106. * @clk_id: Clock index
  107. *
  108. * Return: 1 if clock is valid, 0 if clock is invalid else error code
  109. */
  110. static inline int zynqmp_is_valid_clock(u32 clk_id)
  111. {
  112. if (clk_id >= clock_max_idx)
  113. return -ENODEV;
  114. return clock[clk_id].valid;
  115. }
  116. /**
  117. * zynqmp_get_clock_name() - Get name of clock from Clock index
  118. * @clk_id: Clock index
  119. * @clk_name: Name of clock
  120. *
  121. * Return: 0 on success else error code
  122. */
  123. static int zynqmp_get_clock_name(u32 clk_id, char *clk_name)
  124. {
  125. int ret;
  126. ret = zynqmp_is_valid_clock(clk_id);
  127. if (ret == 1) {
  128. strncpy(clk_name, clock[clk_id].clk_name, MAX_NAME_LEN);
  129. return 0;
  130. }
  131. return ret == 0 ? -EINVAL : ret;
  132. }
  133. /**
  134. * zynqmp_get_clock_type() - Get type of clock
  135. * @clk_id: Clock index
  136. * @type: Clock type: CLK_TYPE_OUTPUT or CLK_TYPE_EXTERNAL
  137. *
  138. * Return: 0 on success else error code
  139. */
  140. static int zynqmp_get_clock_type(u32 clk_id, u32 *type)
  141. {
  142. int ret;
  143. ret = zynqmp_is_valid_clock(clk_id);
  144. if (ret == 1) {
  145. *type = clock[clk_id].type;
  146. return 0;
  147. }
  148. return ret == 0 ? -EINVAL : ret;
  149. }
  150. /**
  151. * zynqmp_pm_clock_get_num_clocks() - Get number of clocks in system
  152. * @nclocks: Number of clocks in system/board.
  153. *
  154. * Call firmware API to get number of clocks.
  155. *
  156. * Return: 0 on success else error code.
  157. */
  158. static int zynqmp_pm_clock_get_num_clocks(u32 *nclocks)
  159. {
  160. struct zynqmp_pm_query_data qdata = {0};
  161. u32 ret_payload[PAYLOAD_ARG_CNT];
  162. int ret;
  163. qdata.qid = PM_QID_CLOCK_GET_NUM_CLOCKS;
  164. ret = eemi_ops->query_data(qdata, ret_payload);
  165. *nclocks = ret_payload[1];
  166. return ret;
  167. }
  168. /**
  169. * zynqmp_pm_clock_get_name() - Get the name of clock for given id
  170. * @clock_id: ID of the clock to be queried
  171. * @name: Name of given clock
  172. *
  173. * This function is used to get name of clock specified by given
  174. * clock ID.
  175. *
  176. * Return: Returns 0, in case of error name would be 0
  177. */
  178. static int zynqmp_pm_clock_get_name(u32 clock_id, char *name)
  179. {
  180. struct zynqmp_pm_query_data qdata = {0};
  181. u32 ret_payload[PAYLOAD_ARG_CNT];
  182. qdata.qid = PM_QID_CLOCK_GET_NAME;
  183. qdata.arg1 = clock_id;
  184. eemi_ops->query_data(qdata, ret_payload);
  185. memcpy(name, ret_payload, CLK_GET_NAME_RESP_LEN);
  186. return 0;
  187. }
  188. /**
  189. * zynqmp_pm_clock_get_topology() - Get the topology of clock for given id
  190. * @clock_id: ID of the clock to be queried
  191. * @index: Node index of clock topology
  192. * @topology: Buffer to store nodes in topology and flags
  193. *
  194. * This function is used to get topology information for the clock
  195. * specified by given clock ID.
  196. *
  197. * This API will return 3 node of topology with a single response. To get
  198. * other nodes, master should call same API in loop with new
  199. * index till error is returned. E.g First call should have
  200. * index 0 which will return nodes 0,1 and 2. Next call, index
  201. * should be 3 which will return nodes 3,4 and 5 and so on.
  202. *
  203. * Return: 0 on success else error+reason
  204. */
  205. static int zynqmp_pm_clock_get_topology(u32 clock_id, u32 index, u32 *topology)
  206. {
  207. struct zynqmp_pm_query_data qdata = {0};
  208. u32 ret_payload[PAYLOAD_ARG_CNT];
  209. int ret;
  210. qdata.qid = PM_QID_CLOCK_GET_TOPOLOGY;
  211. qdata.arg1 = clock_id;
  212. qdata.arg2 = index;
  213. ret = eemi_ops->query_data(qdata, ret_payload);
  214. memcpy(topology, &ret_payload[1], CLK_GET_TOPOLOGY_RESP_WORDS * 4);
  215. return ret;
  216. }
  217. /**
  218. * zynqmp_clk_register_fixed_factor() - Register fixed factor with the
  219. * clock framework
  220. * @name: Name of this clock
  221. * @clk_id: Clock ID
  222. * @parents: Name of this clock's parents
  223. * @num_parents: Number of parents
  224. * @nodes: Clock topology node
  225. *
  226. * Return: clock hardware to the registered clock
  227. */
  228. struct clk_hw *zynqmp_clk_register_fixed_factor(const char *name, u32 clk_id,
  229. const char * const *parents,
  230. u8 num_parents,
  231. const struct clock_topology *nodes)
  232. {
  233. u32 mult, div;
  234. struct clk_hw *hw;
  235. struct zynqmp_pm_query_data qdata = {0};
  236. u32 ret_payload[PAYLOAD_ARG_CNT];
  237. int ret;
  238. qdata.qid = PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS;
  239. qdata.arg1 = clk_id;
  240. ret = eemi_ops->query_data(qdata, ret_payload);
  241. if (ret)
  242. return ERR_PTR(ret);
  243. mult = ret_payload[1];
  244. div = ret_payload[2];
  245. hw = clk_hw_register_fixed_factor(NULL, name,
  246. parents[0],
  247. nodes->flag, mult,
  248. div);
  249. return hw;
  250. }
  251. /**
  252. * zynqmp_pm_clock_get_parents() - Get the first 3 parents of clock for given id
  253. * @clock_id: Clock ID
  254. * @index: Parent index
  255. * @parents: 3 parents of the given clock
  256. *
  257. * This function is used to get 3 parents for the clock specified by
  258. * given clock ID.
  259. *
  260. * This API will return 3 parents with a single response. To get
  261. * other parents, master should call same API in loop with new
  262. * parent index till error is returned. E.g First call should have
  263. * index 0 which will return parents 0,1 and 2. Next call, index
  264. * should be 3 which will return parent 3,4 and 5 and so on.
  265. *
  266. * Return: 0 on success else error+reason
  267. */
  268. static int zynqmp_pm_clock_get_parents(u32 clock_id, u32 index, u32 *parents)
  269. {
  270. struct zynqmp_pm_query_data qdata = {0};
  271. u32 ret_payload[PAYLOAD_ARG_CNT];
  272. int ret;
  273. qdata.qid = PM_QID_CLOCK_GET_PARENTS;
  274. qdata.arg1 = clock_id;
  275. qdata.arg2 = index;
  276. ret = eemi_ops->query_data(qdata, ret_payload);
  277. memcpy(parents, &ret_payload[1], CLK_GET_PARENTS_RESP_WORDS * 4);
  278. return ret;
  279. }
  280. /**
  281. * zynqmp_pm_clock_get_attributes() - Get the attributes of clock for given id
  282. * @clock_id: Clock ID
  283. * @attr: Clock attributes
  284. *
  285. * This function is used to get clock's attributes(e.g. valid, clock type, etc).
  286. *
  287. * Return: 0 on success else error+reason
  288. */
  289. static int zynqmp_pm_clock_get_attributes(u32 clock_id, u32 *attr)
  290. {
  291. struct zynqmp_pm_query_data qdata = {0};
  292. u32 ret_payload[PAYLOAD_ARG_CNT];
  293. int ret;
  294. qdata.qid = PM_QID_CLOCK_GET_ATTRIBUTES;
  295. qdata.arg1 = clock_id;
  296. ret = eemi_ops->query_data(qdata, ret_payload);
  297. memcpy(attr, &ret_payload[1], CLK_GET_ATTR_RESP_WORDS * 4);
  298. return ret;
  299. }
  300. /**
  301. * __zynqmp_clock_get_topology() - Get topology data of clock from firmware
  302. * response data
  303. * @topology: Clock topology
  304. * @data: Clock topology data received from firmware
  305. * @nnodes: Number of nodes
  306. *
  307. * Return: 0 on success else error+reason
  308. */
  309. static int __zynqmp_clock_get_topology(struct clock_topology *topology,
  310. u32 *data, u32 *nnodes)
  311. {
  312. int i;
  313. for (i = 0; i < PM_API_PAYLOAD_LEN; i++) {
  314. if (!(data[i] & CLK_TYPE_FIELD_MASK))
  315. return END_OF_TOPOLOGY_NODE;
  316. topology[*nnodes].type = data[i] & CLK_TYPE_FIELD_MASK;
  317. topology[*nnodes].flag = FIELD_GET(CLK_FLAG_FIELD_MASK,
  318. data[i]);
  319. topology[*nnodes].type_flag =
  320. FIELD_GET(CLK_TYPE_FLAG_FIELD_MASK, data[i]);
  321. (*nnodes)++;
  322. }
  323. return 0;
  324. }
  325. /**
  326. * zynqmp_clock_get_topology() - Get topology of clock from firmware using
  327. * PM_API
  328. * @clk_id: Clock index
  329. * @topology: Clock topology
  330. * @num_nodes: Number of nodes
  331. *
  332. * Return: 0 on success else error+reason
  333. */
  334. static int zynqmp_clock_get_topology(u32 clk_id,
  335. struct clock_topology *topology,
  336. u32 *num_nodes)
  337. {
  338. int j, ret;
  339. u32 pm_resp[PM_API_PAYLOAD_LEN] = {0};
  340. *num_nodes = 0;
  341. for (j = 0; j <= MAX_NODES; j += 3) {
  342. ret = zynqmp_pm_clock_get_topology(clk_id, j, pm_resp);
  343. if (ret)
  344. return ret;
  345. ret = __zynqmp_clock_get_topology(topology, pm_resp, num_nodes);
  346. if (ret == END_OF_TOPOLOGY_NODE)
  347. return 0;
  348. }
  349. return 0;
  350. }
  351. /**
  352. * __zynqmp_clock_get_topology() - Get parents info of clock from firmware
  353. * response data
  354. * @parents: Clock parents
  355. * @data: Clock parents data received from firmware
  356. * @nparent: Number of parent
  357. *
  358. * Return: 0 on success else error+reason
  359. */
  360. static int __zynqmp_clock_get_parents(struct clock_parent *parents, u32 *data,
  361. u32 *nparent)
  362. {
  363. int i;
  364. struct clock_parent *parent;
  365. for (i = 0; i < PM_API_PAYLOAD_LEN; i++) {
  366. if (data[i] == NA_PARENT)
  367. return END_OF_PARENTS;
  368. parent = &parents[i];
  369. parent->id = data[i] & CLK_PARENTS_ID_MASK;
  370. if (data[i] == DUMMY_PARENT) {
  371. strcpy(parent->name, "dummy_name");
  372. parent->flag = 0;
  373. } else {
  374. parent->flag = data[i] >> CLK_PARENTS_ID_LEN;
  375. if (zynqmp_get_clock_name(parent->id, parent->name))
  376. continue;
  377. }
  378. *nparent += 1;
  379. }
  380. return 0;
  381. }
  382. /**
  383. * zynqmp_clock_get_parents() - Get parents info from firmware using PM_API
  384. * @clk_id: Clock index
  385. * @parents: Clock parents
  386. * @num_parents: Total number of parents
  387. *
  388. * Return: 0 on success else error+reason
  389. */
  390. static int zynqmp_clock_get_parents(u32 clk_id, struct clock_parent *parents,
  391. u32 *num_parents)
  392. {
  393. int j = 0, ret;
  394. u32 pm_resp[PM_API_PAYLOAD_LEN] = {0};
  395. *num_parents = 0;
  396. do {
  397. /* Get parents from firmware */
  398. ret = zynqmp_pm_clock_get_parents(clk_id, j, pm_resp);
  399. if (ret)
  400. return ret;
  401. ret = __zynqmp_clock_get_parents(&parents[j], pm_resp,
  402. num_parents);
  403. if (ret == END_OF_PARENTS)
  404. return 0;
  405. j += PM_API_PAYLOAD_LEN;
  406. } while (*num_parents <= MAX_PARENT);
  407. return 0;
  408. }
  409. /**
  410. * zynqmp_get_parent_list() - Create list of parents name
  411. * @np: Device node
  412. * @clk_id: Clock index
  413. * @parent_list: List of parent's name
  414. * @num_parents: Total number of parents
  415. *
  416. * Return: 0 on success else error+reason
  417. */
  418. static int zynqmp_get_parent_list(struct device_node *np, u32 clk_id,
  419. const char **parent_list, u32 *num_parents)
  420. {
  421. int i = 0, ret;
  422. u32 total_parents = clock[clk_id].num_parents;
  423. struct clock_topology *clk_nodes;
  424. struct clock_parent *parents;
  425. clk_nodes = clock[clk_id].node;
  426. parents = clock[clk_id].parent;
  427. for (i = 0; i < total_parents; i++) {
  428. if (!parents[i].flag) {
  429. parent_list[i] = parents[i].name;
  430. } else if (parents[i].flag == PARENT_CLK_EXTERNAL) {
  431. ret = of_property_match_string(np, "clock-names",
  432. parents[i].name);
  433. if (ret < 0)
  434. strcpy(parents[i].name, "dummy_name");
  435. parent_list[i] = parents[i].name;
  436. } else {
  437. strcat(parents[i].name,
  438. clk_type_postfix[clk_nodes[parents[i].flag - 1].
  439. type]);
  440. parent_list[i] = parents[i].name;
  441. }
  442. }
  443. *num_parents = total_parents;
  444. return 0;
  445. }
  446. /**
  447. * zynqmp_register_clk_topology() - Register clock topology
  448. * @clk_id: Clock index
  449. * @clk_name: Clock Name
  450. * @num_parents: Total number of parents
  451. * @parent_names: List of parents name
  452. *
  453. * Return: Returns either clock hardware or error+reason
  454. */
  455. static struct clk_hw *zynqmp_register_clk_topology(int clk_id, char *clk_name,
  456. int num_parents,
  457. const char **parent_names)
  458. {
  459. int j;
  460. u32 num_nodes;
  461. char *clk_out = NULL;
  462. struct clock_topology *nodes;
  463. struct clk_hw *hw = NULL;
  464. nodes = clock[clk_id].node;
  465. num_nodes = clock[clk_id].num_nodes;
  466. for (j = 0; j < num_nodes; j++) {
  467. /*
  468. * Clock name received from firmware is output clock name.
  469. * Intermediate clock names are postfixed with type of clock.
  470. */
  471. if (j != (num_nodes - 1)) {
  472. clk_out = kasprintf(GFP_KERNEL, "%s%s", clk_name,
  473. clk_type_postfix[nodes[j].type]);
  474. } else {
  475. clk_out = kasprintf(GFP_KERNEL, "%s", clk_name);
  476. }
  477. if (!clk_topology[nodes[j].type])
  478. continue;
  479. hw = (*clk_topology[nodes[j].type])(clk_out, clk_id,
  480. parent_names,
  481. num_parents,
  482. &nodes[j]);
  483. if (IS_ERR(hw))
  484. pr_warn_once("%s() %s register fail with %ld\n",
  485. __func__, clk_name, PTR_ERR(hw));
  486. parent_names[0] = clk_out;
  487. }
  488. kfree(clk_out);
  489. return hw;
  490. }
  491. /**
  492. * zynqmp_register_clocks() - Register clocks
  493. * @np: Device node
  494. *
  495. * Return: 0 on success else error code
  496. */
  497. static int zynqmp_register_clocks(struct device_node *np)
  498. {
  499. int ret;
  500. u32 i, total_parents = 0, type = 0;
  501. const char *parent_names[MAX_PARENT];
  502. for (i = 0; i < clock_max_idx; i++) {
  503. char clk_name[MAX_NAME_LEN];
  504. /* get clock name, continue to next clock if name not found */
  505. if (zynqmp_get_clock_name(i, clk_name))
  506. continue;
  507. /* Check if clock is valid and output clock.
  508. * Do not register invalid or external clock.
  509. */
  510. ret = zynqmp_get_clock_type(i, &type);
  511. if (ret || type != CLK_TYPE_OUTPUT)
  512. continue;
  513. /* Get parents of clock*/
  514. if (zynqmp_get_parent_list(np, i, parent_names,
  515. &total_parents)) {
  516. WARN_ONCE(1, "No parents found for %s\n",
  517. clock[i].clk_name);
  518. continue;
  519. }
  520. zynqmp_data->hws[i] =
  521. zynqmp_register_clk_topology(i, clk_name,
  522. total_parents,
  523. parent_names);
  524. }
  525. for (i = 0; i < clock_max_idx; i++) {
  526. if (IS_ERR(zynqmp_data->hws[i])) {
  527. pr_err("Zynq Ultrascale+ MPSoC clk %s: register failed with %ld\n",
  528. clock[i].clk_name, PTR_ERR(zynqmp_data->hws[i]));
  529. WARN_ON(1);
  530. }
  531. }
  532. return 0;
  533. }
  534. /**
  535. * zynqmp_get_clock_info() - Get clock information from firmware using PM_API
  536. */
  537. static void zynqmp_get_clock_info(void)
  538. {
  539. int i, ret;
  540. u32 attr, type = 0;
  541. for (i = 0; i < clock_max_idx; i++) {
  542. zynqmp_pm_clock_get_name(i, clock[i].clk_name);
  543. if (!strcmp(clock[i].clk_name, RESERVED_CLK_NAME))
  544. continue;
  545. ret = zynqmp_pm_clock_get_attributes(i, &attr);
  546. if (ret)
  547. continue;
  548. clock[i].valid = attr & CLK_VALID_MASK;
  549. clock[i].type = attr >> CLK_TYPE_SHIFT ? CLK_TYPE_EXTERNAL :
  550. CLK_TYPE_OUTPUT;
  551. }
  552. /* Get topology of all clock */
  553. for (i = 0; i < clock_max_idx; i++) {
  554. ret = zynqmp_get_clock_type(i, &type);
  555. if (ret || type != CLK_TYPE_OUTPUT)
  556. continue;
  557. ret = zynqmp_clock_get_topology(i, clock[i].node,
  558. &clock[i].num_nodes);
  559. if (ret)
  560. continue;
  561. ret = zynqmp_clock_get_parents(i, clock[i].parent,
  562. &clock[i].num_parents);
  563. if (ret)
  564. continue;
  565. }
  566. }
  567. /**
  568. * zynqmp_clk_setup() - Setup the clock framework and register clocks
  569. * @np: Device node
  570. *
  571. * Return: 0 on success else error code
  572. */
  573. static int zynqmp_clk_setup(struct device_node *np)
  574. {
  575. int ret;
  576. ret = zynqmp_pm_clock_get_num_clocks(&clock_max_idx);
  577. if (ret)
  578. return ret;
  579. zynqmp_data = kzalloc(sizeof(*zynqmp_data) + sizeof(*zynqmp_data) *
  580. clock_max_idx, GFP_KERNEL);
  581. if (!zynqmp_data)
  582. return -ENOMEM;
  583. clock = kcalloc(clock_max_idx, sizeof(*clock), GFP_KERNEL);
  584. if (!clock) {
  585. kfree(zynqmp_data);
  586. return -ENOMEM;
  587. }
  588. zynqmp_get_clock_info();
  589. zynqmp_register_clocks(np);
  590. zynqmp_data->num = clock_max_idx;
  591. of_clk_add_hw_provider(np, of_clk_hw_onecell_get, zynqmp_data);
  592. return 0;
  593. }
  594. static int zynqmp_clock_probe(struct platform_device *pdev)
  595. {
  596. int ret;
  597. struct device *dev = &pdev->dev;
  598. eemi_ops = zynqmp_pm_get_eemi_ops();
  599. if (!eemi_ops)
  600. return -ENXIO;
  601. ret = zynqmp_clk_setup(dev->of_node);
  602. return ret;
  603. }
  604. static const struct of_device_id zynqmp_clock_of_match[] = {
  605. {.compatible = "xlnx,zynqmp-clk"},
  606. {},
  607. };
  608. MODULE_DEVICE_TABLE(of, zynqmp_clock_of_match);
  609. static struct platform_driver zynqmp_clock_driver = {
  610. .driver = {
  611. .name = "zynqmp_clock",
  612. .of_match_table = zynqmp_clock_of_match,
  613. },
  614. .probe = zynqmp_clock_probe,
  615. };
  616. module_platform_driver(zynqmp_clock_driver);