clkgen-pll.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. * Copyright (C) 2014 STMicroelectronics (R&D) Limited
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. */
  10. /*
  11. * Authors:
  12. * Stephen Gallimore <stephen.gallimore@st.com>,
  13. * Pankaj Dev <pankaj.dev@st.com>.
  14. */
  15. #include <linux/slab.h>
  16. #include <linux/of_address.h>
  17. #include <linux/clk-provider.h>
  18. #include "clkgen.h"
  19. static DEFINE_SPINLOCK(clkgena_c32_odf_lock);
  20. /*
  21. * Common PLL configuration register bits for PLL800 and PLL1600 C65
  22. */
  23. #define C65_MDIV_PLL800_MASK (0xff)
  24. #define C65_MDIV_PLL1600_MASK (0x7)
  25. #define C65_NDIV_MASK (0xff)
  26. #define C65_PDIV_MASK (0x7)
  27. /*
  28. * PLL configuration register bits for PLL3200 C32
  29. */
  30. #define C32_NDIV_MASK (0xff)
  31. #define C32_IDF_MASK (0x7)
  32. #define C32_ODF_MASK (0x3f)
  33. #define C32_LDF_MASK (0x7f)
  34. #define C32_MAX_ODFS (4)
  35. struct clkgen_pll_data {
  36. struct clkgen_field pdn_status;
  37. struct clkgen_field locked_status;
  38. struct clkgen_field mdiv;
  39. struct clkgen_field ndiv;
  40. struct clkgen_field pdiv;
  41. struct clkgen_field idf;
  42. struct clkgen_field ldf;
  43. unsigned int num_odfs;
  44. struct clkgen_field odf[C32_MAX_ODFS];
  45. struct clkgen_field odf_gate[C32_MAX_ODFS];
  46. const struct clk_ops *ops;
  47. };
  48. static const struct clk_ops st_pll1600c65_ops;
  49. static const struct clk_ops st_pll800c65_ops;
  50. static const struct clk_ops stm_pll3200c32_ops;
  51. static const struct clk_ops st_pll1200c32_ops;
  52. static struct clkgen_pll_data st_pll1600c65_ax = {
  53. .pdn_status = CLKGEN_FIELD(0x0, 0x1, 19),
  54. .locked_status = CLKGEN_FIELD(0x0, 0x1, 31),
  55. .mdiv = CLKGEN_FIELD(0x0, C65_MDIV_PLL1600_MASK, 0),
  56. .ndiv = CLKGEN_FIELD(0x0, C65_NDIV_MASK, 8),
  57. .ops = &st_pll1600c65_ops
  58. };
  59. static struct clkgen_pll_data st_pll800c65_ax = {
  60. .pdn_status = CLKGEN_FIELD(0x0, 0x1, 19),
  61. .locked_status = CLKGEN_FIELD(0x0, 0x1, 31),
  62. .mdiv = CLKGEN_FIELD(0x0, C65_MDIV_PLL800_MASK, 0),
  63. .ndiv = CLKGEN_FIELD(0x0, C65_NDIV_MASK, 8),
  64. .pdiv = CLKGEN_FIELD(0x0, C65_PDIV_MASK, 16),
  65. .ops = &st_pll800c65_ops
  66. };
  67. static struct clkgen_pll_data st_pll3200c32_a1x_0 = {
  68. .pdn_status = CLKGEN_FIELD(0x0, 0x1, 31),
  69. .locked_status = CLKGEN_FIELD(0x4, 0x1, 31),
  70. .ndiv = CLKGEN_FIELD(0x0, C32_NDIV_MASK, 0x0),
  71. .idf = CLKGEN_FIELD(0x4, C32_IDF_MASK, 0x0),
  72. .num_odfs = 4,
  73. .odf = { CLKGEN_FIELD(0x54, C32_ODF_MASK, 4),
  74. CLKGEN_FIELD(0x54, C32_ODF_MASK, 10),
  75. CLKGEN_FIELD(0x54, C32_ODF_MASK, 16),
  76. CLKGEN_FIELD(0x54, C32_ODF_MASK, 22) },
  77. .odf_gate = { CLKGEN_FIELD(0x54, 0x1, 0),
  78. CLKGEN_FIELD(0x54, 0x1, 1),
  79. CLKGEN_FIELD(0x54, 0x1, 2),
  80. CLKGEN_FIELD(0x54, 0x1, 3) },
  81. .ops = &stm_pll3200c32_ops,
  82. };
  83. static struct clkgen_pll_data st_pll3200c32_a1x_1 = {
  84. .pdn_status = CLKGEN_FIELD(0xC, 0x1, 31),
  85. .locked_status = CLKGEN_FIELD(0x10, 0x1, 31),
  86. .ndiv = CLKGEN_FIELD(0xC, C32_NDIV_MASK, 0x0),
  87. .idf = CLKGEN_FIELD(0x10, C32_IDF_MASK, 0x0),
  88. .num_odfs = 4,
  89. .odf = { CLKGEN_FIELD(0x58, C32_ODF_MASK, 4),
  90. CLKGEN_FIELD(0x58, C32_ODF_MASK, 10),
  91. CLKGEN_FIELD(0x58, C32_ODF_MASK, 16),
  92. CLKGEN_FIELD(0x58, C32_ODF_MASK, 22) },
  93. .odf_gate = { CLKGEN_FIELD(0x58, 0x1, 0),
  94. CLKGEN_FIELD(0x58, 0x1, 1),
  95. CLKGEN_FIELD(0x58, 0x1, 2),
  96. CLKGEN_FIELD(0x58, 0x1, 3) },
  97. .ops = &stm_pll3200c32_ops,
  98. };
  99. /* 415 specific */
  100. static struct clkgen_pll_data st_pll3200c32_a9_415 = {
  101. .pdn_status = CLKGEN_FIELD(0x0, 0x1, 0),
  102. .locked_status = CLKGEN_FIELD(0x6C, 0x1, 0),
  103. .ndiv = CLKGEN_FIELD(0x0, C32_NDIV_MASK, 9),
  104. .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 22),
  105. .num_odfs = 1,
  106. .odf = { CLKGEN_FIELD(0x0, C32_ODF_MASK, 3) },
  107. .odf_gate = { CLKGEN_FIELD(0x0, 0x1, 28) },
  108. .ops = &stm_pll3200c32_ops,
  109. };
  110. static struct clkgen_pll_data st_pll3200c32_ddr_415 = {
  111. .pdn_status = CLKGEN_FIELD(0x0, 0x1, 0),
  112. .locked_status = CLKGEN_FIELD(0x100, 0x1, 0),
  113. .ndiv = CLKGEN_FIELD(0x8, C32_NDIV_MASK, 0),
  114. .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 25),
  115. .num_odfs = 2,
  116. .odf = { CLKGEN_FIELD(0x8, C32_ODF_MASK, 8),
  117. CLKGEN_FIELD(0x8, C32_ODF_MASK, 14) },
  118. .odf_gate = { CLKGEN_FIELD(0x4, 0x1, 28),
  119. CLKGEN_FIELD(0x4, 0x1, 29) },
  120. .ops = &stm_pll3200c32_ops,
  121. };
  122. static struct clkgen_pll_data st_pll1200c32_gpu_415 = {
  123. .pdn_status = CLKGEN_FIELD(0x144, 0x1, 3),
  124. .locked_status = CLKGEN_FIELD(0x168, 0x1, 0),
  125. .ldf = CLKGEN_FIELD(0x0, C32_LDF_MASK, 3),
  126. .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 0),
  127. .num_odfs = 0,
  128. .odf = { CLKGEN_FIELD(0x0, C32_ODF_MASK, 10) },
  129. .ops = &st_pll1200c32_ops,
  130. };
  131. /* 416 specific */
  132. static struct clkgen_pll_data st_pll3200c32_a9_416 = {
  133. .pdn_status = CLKGEN_FIELD(0x0, 0x1, 0),
  134. .locked_status = CLKGEN_FIELD(0x6C, 0x1, 0),
  135. .ndiv = CLKGEN_FIELD(0x8, C32_NDIV_MASK, 0),
  136. .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 25),
  137. .num_odfs = 1,
  138. .odf = { CLKGEN_FIELD(0x8, C32_ODF_MASK, 8) },
  139. .odf_gate = { CLKGEN_FIELD(0x4, 0x1, 28) },
  140. .ops = &stm_pll3200c32_ops,
  141. };
  142. static struct clkgen_pll_data st_pll3200c32_ddr_416 = {
  143. .pdn_status = CLKGEN_FIELD(0x0, 0x1, 0),
  144. .locked_status = CLKGEN_FIELD(0x10C, 0x1, 0),
  145. .ndiv = CLKGEN_FIELD(0x8, C32_NDIV_MASK, 0),
  146. .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 25),
  147. .num_odfs = 2,
  148. .odf = { CLKGEN_FIELD(0x8, C32_ODF_MASK, 8),
  149. CLKGEN_FIELD(0x8, C32_ODF_MASK, 14) },
  150. .odf_gate = { CLKGEN_FIELD(0x4, 0x1, 28),
  151. CLKGEN_FIELD(0x4, 0x1, 29) },
  152. .ops = &stm_pll3200c32_ops,
  153. };
  154. static struct clkgen_pll_data st_pll1200c32_gpu_416 = {
  155. .pdn_status = CLKGEN_FIELD(0x8E4, 0x1, 3),
  156. .locked_status = CLKGEN_FIELD(0x90C, 0x1, 0),
  157. .ldf = CLKGEN_FIELD(0x0, C32_LDF_MASK, 3),
  158. .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 0),
  159. .num_odfs = 0,
  160. .odf = { CLKGEN_FIELD(0x0, C32_ODF_MASK, 10) },
  161. .ops = &st_pll1200c32_ops,
  162. };
  163. /**
  164. * DOC: Clock Generated by PLL, rate set and enabled by bootloader
  165. *
  166. * Traits of this clock:
  167. * prepare - clk_(un)prepare only ensures parent is (un)prepared
  168. * enable - clk_enable/disable only ensures parent is enabled
  169. * rate - rate is fixed. No clk_set_rate support
  170. * parent - fixed parent. No clk_set_parent support
  171. */
  172. /**
  173. * PLL clock that is integrated in the ClockGenA instances on the STiH415
  174. * and STiH416.
  175. *
  176. * @hw: handle between common and hardware-specific interfaces.
  177. * @type: PLL instance type.
  178. * @regs_base: base of the PLL configuration register(s).
  179. *
  180. */
  181. struct clkgen_pll {
  182. struct clk_hw hw;
  183. struct clkgen_pll_data *data;
  184. void __iomem *regs_base;
  185. };
  186. #define to_clkgen_pll(_hw) container_of(_hw, struct clkgen_pll, hw)
  187. static int clkgen_pll_is_locked(struct clk_hw *hw)
  188. {
  189. struct clkgen_pll *pll = to_clkgen_pll(hw);
  190. u32 locked = CLKGEN_READ(pll, locked_status);
  191. return !!locked;
  192. }
  193. static int clkgen_pll_is_enabled(struct clk_hw *hw)
  194. {
  195. struct clkgen_pll *pll = to_clkgen_pll(hw);
  196. u32 poweroff = CLKGEN_READ(pll, pdn_status);
  197. return !poweroff;
  198. }
  199. unsigned long recalc_stm_pll800c65(struct clk_hw *hw,
  200. unsigned long parent_rate)
  201. {
  202. struct clkgen_pll *pll = to_clkgen_pll(hw);
  203. unsigned long mdiv, ndiv, pdiv;
  204. unsigned long rate;
  205. uint64_t res;
  206. if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw))
  207. return 0;
  208. pdiv = CLKGEN_READ(pll, pdiv);
  209. mdiv = CLKGEN_READ(pll, mdiv);
  210. ndiv = CLKGEN_READ(pll, ndiv);
  211. if (!mdiv)
  212. mdiv++; /* mdiv=0 or 1 => MDIV=1 */
  213. res = (uint64_t)2 * (uint64_t)parent_rate * (uint64_t)ndiv;
  214. rate = (unsigned long)div64_u64(res, mdiv * (1 << pdiv));
  215. pr_debug("%s:%s rate %lu\n", __clk_get_name(hw->clk), __func__, rate);
  216. return rate;
  217. }
  218. unsigned long recalc_stm_pll1600c65(struct clk_hw *hw,
  219. unsigned long parent_rate)
  220. {
  221. struct clkgen_pll *pll = to_clkgen_pll(hw);
  222. unsigned long mdiv, ndiv;
  223. unsigned long rate;
  224. if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw))
  225. return 0;
  226. mdiv = CLKGEN_READ(pll, mdiv);
  227. ndiv = CLKGEN_READ(pll, ndiv);
  228. if (!mdiv)
  229. mdiv = 1;
  230. /* Note: input is divided by 1000 to avoid overflow */
  231. rate = ((2 * (parent_rate / 1000) * ndiv) / mdiv) * 1000;
  232. pr_debug("%s:%s rate %lu\n", __clk_get_name(hw->clk), __func__, rate);
  233. return rate;
  234. }
  235. unsigned long recalc_stm_pll3200c32(struct clk_hw *hw,
  236. unsigned long parent_rate)
  237. {
  238. struct clkgen_pll *pll = to_clkgen_pll(hw);
  239. unsigned long ndiv, idf;
  240. unsigned long rate = 0;
  241. if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw))
  242. return 0;
  243. ndiv = CLKGEN_READ(pll, ndiv);
  244. idf = CLKGEN_READ(pll, idf);
  245. if (idf)
  246. /* Note: input is divided to avoid overflow */
  247. rate = ((2 * (parent_rate/1000) * ndiv) / idf) * 1000;
  248. pr_debug("%s:%s rate %lu\n", __clk_get_name(hw->clk), __func__, rate);
  249. return rate;
  250. }
  251. unsigned long recalc_stm_pll1200c32(struct clk_hw *hw,
  252. unsigned long parent_rate)
  253. {
  254. struct clkgen_pll *pll = to_clkgen_pll(hw);
  255. unsigned long odf, ldf, idf;
  256. unsigned long rate;
  257. if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw))
  258. return 0;
  259. odf = CLKGEN_READ(pll, odf[0]);
  260. ldf = CLKGEN_READ(pll, ldf);
  261. idf = CLKGEN_READ(pll, idf);
  262. if (!idf) /* idf==0 means 1 */
  263. idf = 1;
  264. if (!odf) /* odf==0 means 1 */
  265. odf = 1;
  266. /* Note: input is divided by 1000 to avoid overflow */
  267. rate = (((parent_rate / 1000) * ldf) / (odf * idf)) * 1000;
  268. pr_debug("%s:%s rate %lu\n", __clk_get_name(hw->clk), __func__, rate);
  269. return rate;
  270. }
  271. static const struct clk_ops st_pll1600c65_ops = {
  272. .is_enabled = clkgen_pll_is_enabled,
  273. .recalc_rate = recalc_stm_pll1600c65,
  274. };
  275. static const struct clk_ops st_pll800c65_ops = {
  276. .is_enabled = clkgen_pll_is_enabled,
  277. .recalc_rate = recalc_stm_pll800c65,
  278. };
  279. static const struct clk_ops stm_pll3200c32_ops = {
  280. .is_enabled = clkgen_pll_is_enabled,
  281. .recalc_rate = recalc_stm_pll3200c32,
  282. };
  283. static const struct clk_ops st_pll1200c32_ops = {
  284. .is_enabled = clkgen_pll_is_enabled,
  285. .recalc_rate = recalc_stm_pll1200c32,
  286. };
  287. static struct clk * __init clkgen_pll_register(const char *parent_name,
  288. struct clkgen_pll_data *pll_data,
  289. void __iomem *reg,
  290. const char *clk_name)
  291. {
  292. struct clkgen_pll *pll;
  293. struct clk *clk;
  294. struct clk_init_data init;
  295. pll = kzalloc(sizeof(*pll), GFP_KERNEL);
  296. if (!pll)
  297. return ERR_PTR(-ENOMEM);
  298. init.name = clk_name;
  299. init.ops = pll_data->ops;
  300. init.flags = CLK_IS_BASIC;
  301. init.parent_names = &parent_name;
  302. init.num_parents = 1;
  303. pll->data = pll_data;
  304. pll->regs_base = reg;
  305. pll->hw.init = &init;
  306. clk = clk_register(NULL, &pll->hw);
  307. if (IS_ERR(clk)) {
  308. kfree(pll);
  309. return clk;
  310. }
  311. pr_debug("%s: parent %s rate %lu\n",
  312. __clk_get_name(clk),
  313. __clk_get_name(clk_get_parent(clk)),
  314. clk_get_rate(clk));
  315. return clk;
  316. }
  317. static struct clk * __init clkgen_c65_lsdiv_register(const char *parent_name,
  318. const char *clk_name)
  319. {
  320. struct clk *clk;
  321. clk = clk_register_fixed_factor(NULL, clk_name, parent_name, 0, 1, 2);
  322. if (IS_ERR(clk))
  323. return clk;
  324. pr_debug("%s: parent %s rate %lu\n",
  325. __clk_get_name(clk),
  326. __clk_get_name(clk_get_parent(clk)),
  327. clk_get_rate(clk));
  328. return clk;
  329. }
  330. static void __iomem * __init clkgen_get_register_base(
  331. struct device_node *np)
  332. {
  333. struct device_node *pnode;
  334. void __iomem *reg = NULL;
  335. pnode = of_get_parent(np);
  336. if (!pnode)
  337. return NULL;
  338. reg = of_iomap(pnode, 0);
  339. of_node_put(pnode);
  340. return reg;
  341. }
  342. #define CLKGENAx_PLL0_OFFSET 0x0
  343. #define CLKGENAx_PLL1_OFFSET 0x4
  344. static void __init clkgena_c65_pll_setup(struct device_node *np)
  345. {
  346. const int num_pll_outputs = 3;
  347. struct clk_onecell_data *clk_data;
  348. const char *parent_name;
  349. void __iomem *reg;
  350. const char *clk_name;
  351. parent_name = of_clk_get_parent_name(np, 0);
  352. if (!parent_name)
  353. return;
  354. reg = clkgen_get_register_base(np);
  355. if (!reg)
  356. return;
  357. clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
  358. if (!clk_data)
  359. return;
  360. clk_data->clk_num = num_pll_outputs;
  361. clk_data->clks = kzalloc(clk_data->clk_num * sizeof(struct clk *),
  362. GFP_KERNEL);
  363. if (!clk_data->clks)
  364. goto err;
  365. if (of_property_read_string_index(np, "clock-output-names",
  366. 0, &clk_name))
  367. goto err;
  368. /*
  369. * PLL0 HS (high speed) output
  370. */
  371. clk_data->clks[0] = clkgen_pll_register(parent_name,
  372. &st_pll1600c65_ax,
  373. reg + CLKGENAx_PLL0_OFFSET,
  374. clk_name);
  375. if (IS_ERR(clk_data->clks[0]))
  376. goto err;
  377. if (of_property_read_string_index(np, "clock-output-names",
  378. 1, &clk_name))
  379. goto err;
  380. /*
  381. * PLL0 LS (low speed) output, which is a fixed divide by 2 of the
  382. * high speed output.
  383. */
  384. clk_data->clks[1] = clkgen_c65_lsdiv_register(__clk_get_name
  385. (clk_data->clks[0]),
  386. clk_name);
  387. if (IS_ERR(clk_data->clks[1]))
  388. goto err;
  389. if (of_property_read_string_index(np, "clock-output-names",
  390. 2, &clk_name))
  391. goto err;
  392. /*
  393. * PLL1 output
  394. */
  395. clk_data->clks[2] = clkgen_pll_register(parent_name,
  396. &st_pll800c65_ax,
  397. reg + CLKGENAx_PLL1_OFFSET,
  398. clk_name);
  399. if (IS_ERR(clk_data->clks[2]))
  400. goto err;
  401. of_clk_add_provider(np, of_clk_src_onecell_get, clk_data);
  402. return;
  403. err:
  404. kfree(clk_data->clks);
  405. kfree(clk_data);
  406. }
  407. CLK_OF_DECLARE(clkgena_c65_plls,
  408. "st,clkgena-plls-c65", clkgena_c65_pll_setup);
  409. static struct clk * __init clkgen_odf_register(const char *parent_name,
  410. void * __iomem reg,
  411. struct clkgen_pll_data *pll_data,
  412. int odf,
  413. spinlock_t *odf_lock,
  414. const char *odf_name)
  415. {
  416. struct clk *clk;
  417. unsigned long flags;
  418. struct clk_gate *gate;
  419. struct clk_divider *div;
  420. flags = CLK_GET_RATE_NOCACHE | CLK_SET_RATE_GATE;
  421. gate = kzalloc(sizeof(*gate), GFP_KERNEL);
  422. if (!gate)
  423. return ERR_PTR(-ENOMEM);
  424. gate->flags = CLK_GATE_SET_TO_DISABLE;
  425. gate->reg = reg + pll_data->odf_gate[odf].offset;
  426. gate->bit_idx = pll_data->odf_gate[odf].shift;
  427. gate->lock = odf_lock;
  428. div = kzalloc(sizeof(*div), GFP_KERNEL);
  429. if (!div) {
  430. kfree(gate);
  431. return ERR_PTR(-ENOMEM);
  432. }
  433. div->flags = CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO;
  434. div->reg = reg + pll_data->odf[odf].offset;
  435. div->shift = pll_data->odf[odf].shift;
  436. div->width = fls(pll_data->odf[odf].mask);
  437. div->lock = odf_lock;
  438. clk = clk_register_composite(NULL, odf_name, &parent_name, 1,
  439. NULL, NULL,
  440. &div->hw, &clk_divider_ops,
  441. &gate->hw, &clk_gate_ops,
  442. flags);
  443. if (IS_ERR(clk))
  444. return clk;
  445. pr_debug("%s: parent %s rate %lu\n",
  446. __clk_get_name(clk),
  447. __clk_get_name(clk_get_parent(clk)),
  448. clk_get_rate(clk));
  449. return clk;
  450. }
  451. static struct of_device_id c32_pll_of_match[] = {
  452. {
  453. .compatible = "st,plls-c32-a1x-0",
  454. .data = &st_pll3200c32_a1x_0,
  455. },
  456. {
  457. .compatible = "st,plls-c32-a1x-1",
  458. .data = &st_pll3200c32_a1x_1,
  459. },
  460. {
  461. .compatible = "st,stih415-plls-c32-a9",
  462. .data = &st_pll3200c32_a9_415,
  463. },
  464. {
  465. .compatible = "st,stih415-plls-c32-ddr",
  466. .data = &st_pll3200c32_ddr_415,
  467. },
  468. {
  469. .compatible = "st,stih416-plls-c32-a9",
  470. .data = &st_pll3200c32_a9_416,
  471. },
  472. {
  473. .compatible = "st,stih416-plls-c32-ddr",
  474. .data = &st_pll3200c32_ddr_416,
  475. },
  476. {}
  477. };
  478. static void __init clkgen_c32_pll_setup(struct device_node *np)
  479. {
  480. const struct of_device_id *match;
  481. struct clk *clk;
  482. const char *parent_name, *pll_name;
  483. void __iomem *pll_base;
  484. int num_odfs, odf;
  485. struct clk_onecell_data *clk_data;
  486. struct clkgen_pll_data *data;
  487. match = of_match_node(c32_pll_of_match, np);
  488. if (!match) {
  489. pr_err("%s: No matching data\n", __func__);
  490. return;
  491. }
  492. data = (struct clkgen_pll_data *) match->data;
  493. parent_name = of_clk_get_parent_name(np, 0);
  494. if (!parent_name)
  495. return;
  496. pll_base = clkgen_get_register_base(np);
  497. if (!pll_base)
  498. return;
  499. clk = clkgen_pll_register(parent_name, data, pll_base, np->name);
  500. if (IS_ERR(clk))
  501. return;
  502. pll_name = __clk_get_name(clk);
  503. num_odfs = data->num_odfs;
  504. clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
  505. if (!clk_data)
  506. return;
  507. clk_data->clk_num = num_odfs;
  508. clk_data->clks = kzalloc(clk_data->clk_num * sizeof(struct clk *),
  509. GFP_KERNEL);
  510. if (!clk_data->clks)
  511. goto err;
  512. for (odf = 0; odf < num_odfs; odf++) {
  513. struct clk *clk;
  514. const char *clk_name;
  515. if (of_property_read_string_index(np, "clock-output-names",
  516. odf, &clk_name))
  517. return;
  518. clk = clkgen_odf_register(pll_name, pll_base, data,
  519. odf, &clkgena_c32_odf_lock, clk_name);
  520. if (IS_ERR(clk))
  521. goto err;
  522. clk_data->clks[odf] = clk;
  523. }
  524. of_clk_add_provider(np, of_clk_src_onecell_get, clk_data);
  525. return;
  526. err:
  527. kfree(pll_name);
  528. kfree(clk_data->clks);
  529. kfree(clk_data);
  530. }
  531. CLK_OF_DECLARE(clkgen_c32_pll, "st,clkgen-plls-c32", clkgen_c32_pll_setup);
  532. static struct of_device_id c32_gpu_pll_of_match[] = {
  533. {
  534. .compatible = "st,stih415-gpu-pll-c32",
  535. .data = &st_pll1200c32_gpu_415,
  536. },
  537. {
  538. .compatible = "st,stih416-gpu-pll-c32",
  539. .data = &st_pll1200c32_gpu_416,
  540. },
  541. {}
  542. };
  543. static void __init clkgengpu_c32_pll_setup(struct device_node *np)
  544. {
  545. const struct of_device_id *match;
  546. struct clk *clk;
  547. const char *parent_name;
  548. void __iomem *reg;
  549. const char *clk_name;
  550. struct clkgen_pll_data *data;
  551. match = of_match_node(c32_gpu_pll_of_match, np);
  552. if (!match) {
  553. pr_err("%s: No matching data\n", __func__);
  554. return;
  555. }
  556. data = (struct clkgen_pll_data *)match->data;
  557. parent_name = of_clk_get_parent_name(np, 0);
  558. if (!parent_name)
  559. return;
  560. reg = clkgen_get_register_base(np);
  561. if (!reg)
  562. return;
  563. if (of_property_read_string_index(np, "clock-output-names",
  564. 0, &clk_name))
  565. return;
  566. /*
  567. * PLL 1200MHz output
  568. */
  569. clk = clkgen_pll_register(parent_name, data, reg, clk_name);
  570. if (!IS_ERR(clk))
  571. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  572. return;
  573. }
  574. CLK_OF_DECLARE(clkgengpu_c32_pll,
  575. "st,clkgengpu-pll-c32", clkgengpu_c32_pll_setup);