ccu-pll.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2020 BAIKAL ELECTRONICS, JSC
  4. *
  5. * Authors:
  6. * Serge Semin <[email protected]>
  7. * Dmitry Dunaev <[email protected]>
  8. *
  9. * Baikal-T1 CCU PLL interface driver
  10. */
  11. #define pr_fmt(fmt) "bt1-ccu-pll: " fmt
  12. #include <linux/kernel.h>
  13. #include <linux/printk.h>
  14. #include <linux/limits.h>
  15. #include <linux/bits.h>
  16. #include <linux/bitfield.h>
  17. #include <linux/slab.h>
  18. #include <linux/clk-provider.h>
  19. #include <linux/of.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/regmap.h>
  22. #include <linux/iopoll.h>
  23. #include <linux/time64.h>
  24. #include <linux/rational.h>
  25. #include <linux/debugfs.h>
  26. #include "ccu-pll.h"
  27. #define CCU_PLL_CTL 0x000
  28. #define CCU_PLL_CTL_EN BIT(0)
  29. #define CCU_PLL_CTL_RST BIT(1)
  30. #define CCU_PLL_CTL_CLKR_FLD 2
  31. #define CCU_PLL_CTL_CLKR_MASK GENMASK(7, CCU_PLL_CTL_CLKR_FLD)
  32. #define CCU_PLL_CTL_CLKF_FLD 8
  33. #define CCU_PLL_CTL_CLKF_MASK GENMASK(20, CCU_PLL_CTL_CLKF_FLD)
  34. #define CCU_PLL_CTL_CLKOD_FLD 21
  35. #define CCU_PLL_CTL_CLKOD_MASK GENMASK(24, CCU_PLL_CTL_CLKOD_FLD)
  36. #define CCU_PLL_CTL_BYPASS BIT(30)
  37. #define CCU_PLL_CTL_LOCK BIT(31)
  38. #define CCU_PLL_CTL1 0x004
  39. #define CCU_PLL_CTL1_BWADJ_FLD 3
  40. #define CCU_PLL_CTL1_BWADJ_MASK GENMASK(14, CCU_PLL_CTL1_BWADJ_FLD)
  41. #define CCU_PLL_LOCK_CHECK_RETRIES 50
  42. #define CCU_PLL_NR_MAX \
  43. ((CCU_PLL_CTL_CLKR_MASK >> CCU_PLL_CTL_CLKR_FLD) + 1)
  44. #define CCU_PLL_NF_MAX \
  45. ((CCU_PLL_CTL_CLKF_MASK >> (CCU_PLL_CTL_CLKF_FLD + 1)) + 1)
  46. #define CCU_PLL_OD_MAX \
  47. ((CCU_PLL_CTL_CLKOD_MASK >> CCU_PLL_CTL_CLKOD_FLD) + 1)
  48. #define CCU_PLL_NB_MAX \
  49. ((CCU_PLL_CTL1_BWADJ_MASK >> CCU_PLL_CTL1_BWADJ_FLD) + 1)
  50. #define CCU_PLL_FDIV_MIN 427000UL
  51. #define CCU_PLL_FDIV_MAX 3500000000UL
  52. #define CCU_PLL_FOUT_MIN 200000000UL
  53. #define CCU_PLL_FOUT_MAX 2500000000UL
  54. #define CCU_PLL_FVCO_MIN 700000000UL
  55. #define CCU_PLL_FVCO_MAX 3500000000UL
  56. #define CCU_PLL_CLKOD_FACTOR 2
  57. static inline unsigned long ccu_pll_lock_delay_us(unsigned long ref_clk,
  58. unsigned long nr)
  59. {
  60. u64 us = 500ULL * nr * USEC_PER_SEC;
  61. do_div(us, ref_clk);
  62. return us;
  63. }
  64. static inline unsigned long ccu_pll_calc_freq(unsigned long ref_clk,
  65. unsigned long nr,
  66. unsigned long nf,
  67. unsigned long od)
  68. {
  69. u64 tmp = ref_clk;
  70. do_div(tmp, nr);
  71. tmp *= nf;
  72. do_div(tmp, od);
  73. return tmp;
  74. }
  75. static int ccu_pll_reset(struct ccu_pll *pll, unsigned long ref_clk,
  76. unsigned long nr)
  77. {
  78. unsigned long ud, ut;
  79. u32 val;
  80. ud = ccu_pll_lock_delay_us(ref_clk, nr);
  81. ut = ud * CCU_PLL_LOCK_CHECK_RETRIES;
  82. regmap_update_bits(pll->sys_regs, pll->reg_ctl,
  83. CCU_PLL_CTL_RST, CCU_PLL_CTL_RST);
  84. return regmap_read_poll_timeout_atomic(pll->sys_regs, pll->reg_ctl, val,
  85. val & CCU_PLL_CTL_LOCK, ud, ut);
  86. }
  87. static int ccu_pll_enable(struct clk_hw *hw)
  88. {
  89. struct clk_hw *parent_hw = clk_hw_get_parent(hw);
  90. struct ccu_pll *pll = to_ccu_pll(hw);
  91. unsigned long flags;
  92. u32 val = 0;
  93. int ret;
  94. if (!parent_hw) {
  95. pr_err("Can't enable '%s' with no parent", clk_hw_get_name(hw));
  96. return -EINVAL;
  97. }
  98. regmap_read(pll->sys_regs, pll->reg_ctl, &val);
  99. if (val & CCU_PLL_CTL_EN)
  100. return 0;
  101. spin_lock_irqsave(&pll->lock, flags);
  102. regmap_write(pll->sys_regs, pll->reg_ctl, val | CCU_PLL_CTL_EN);
  103. ret = ccu_pll_reset(pll, clk_hw_get_rate(parent_hw),
  104. FIELD_GET(CCU_PLL_CTL_CLKR_MASK, val) + 1);
  105. spin_unlock_irqrestore(&pll->lock, flags);
  106. if (ret)
  107. pr_err("PLL '%s' reset timed out\n", clk_hw_get_name(hw));
  108. return ret;
  109. }
  110. static void ccu_pll_disable(struct clk_hw *hw)
  111. {
  112. struct ccu_pll *pll = to_ccu_pll(hw);
  113. unsigned long flags;
  114. spin_lock_irqsave(&pll->lock, flags);
  115. regmap_update_bits(pll->sys_regs, pll->reg_ctl, CCU_PLL_CTL_EN, 0);
  116. spin_unlock_irqrestore(&pll->lock, flags);
  117. }
  118. static int ccu_pll_is_enabled(struct clk_hw *hw)
  119. {
  120. struct ccu_pll *pll = to_ccu_pll(hw);
  121. u32 val = 0;
  122. regmap_read(pll->sys_regs, pll->reg_ctl, &val);
  123. return !!(val & CCU_PLL_CTL_EN);
  124. }
  125. static unsigned long ccu_pll_recalc_rate(struct clk_hw *hw,
  126. unsigned long parent_rate)
  127. {
  128. struct ccu_pll *pll = to_ccu_pll(hw);
  129. unsigned long nr, nf, od;
  130. u32 val = 0;
  131. regmap_read(pll->sys_regs, pll->reg_ctl, &val);
  132. nr = FIELD_GET(CCU_PLL_CTL_CLKR_MASK, val) + 1;
  133. nf = FIELD_GET(CCU_PLL_CTL_CLKF_MASK, val) + 1;
  134. od = FIELD_GET(CCU_PLL_CTL_CLKOD_MASK, val) + 1;
  135. return ccu_pll_calc_freq(parent_rate, nr, nf, od);
  136. }
  137. static void ccu_pll_calc_factors(unsigned long rate, unsigned long parent_rate,
  138. unsigned long *nr, unsigned long *nf,
  139. unsigned long *od)
  140. {
  141. unsigned long err, freq, min_err = ULONG_MAX;
  142. unsigned long num, denom, n1, d1, nri;
  143. unsigned long nr_max, nf_max, od_max;
  144. /*
  145. * Make sure PLL is working with valid input signal (Fdiv). If
  146. * you want to speed the function up just reduce CCU_PLL_NR_MAX.
  147. * This will cause a worse approximation though.
  148. */
  149. nri = (parent_rate / CCU_PLL_FDIV_MAX) + 1;
  150. nr_max = min(parent_rate / CCU_PLL_FDIV_MIN, CCU_PLL_NR_MAX);
  151. /*
  152. * Find a closest [nr;nf;od] vector taking into account the
  153. * limitations like: 1) 700MHz <= Fvco <= 3.5GHz, 2) PLL Od is
  154. * either 1 or even number within the acceptable range (alas 1s
  155. * is also excluded by the next loop).
  156. */
  157. for (; nri <= nr_max; ++nri) {
  158. /* Use Od factor to fulfill the limitation 2). */
  159. num = CCU_PLL_CLKOD_FACTOR * rate;
  160. denom = parent_rate / nri;
  161. /*
  162. * Make sure Fvco is within the acceptable range to fulfill
  163. * the condition 1). Note due to the CCU_PLL_CLKOD_FACTOR value
  164. * the actual upper limit is also divided by that factor.
  165. * It's not big problem for us since practically there is no
  166. * need in clocks with that high frequency.
  167. */
  168. nf_max = min(CCU_PLL_FVCO_MAX / denom, CCU_PLL_NF_MAX);
  169. od_max = CCU_PLL_OD_MAX / CCU_PLL_CLKOD_FACTOR;
  170. /*
  171. * Bypass the out-of-bound values, which can't be properly
  172. * handled by the rational fraction approximation algorithm.
  173. */
  174. if (num / denom >= nf_max) {
  175. n1 = nf_max;
  176. d1 = 1;
  177. } else if (denom / num >= od_max) {
  178. n1 = 1;
  179. d1 = od_max;
  180. } else {
  181. rational_best_approximation(num, denom, nf_max, od_max,
  182. &n1, &d1);
  183. }
  184. /* Select the best approximation of the target rate. */
  185. freq = ccu_pll_calc_freq(parent_rate, nri, n1, d1);
  186. err = abs((int64_t)freq - num);
  187. if (err < min_err) {
  188. min_err = err;
  189. *nr = nri;
  190. *nf = n1;
  191. *od = CCU_PLL_CLKOD_FACTOR * d1;
  192. }
  193. }
  194. }
  195. static long ccu_pll_round_rate(struct clk_hw *hw, unsigned long rate,
  196. unsigned long *parent_rate)
  197. {
  198. unsigned long nr = 1, nf = 1, od = 1;
  199. ccu_pll_calc_factors(rate, *parent_rate, &nr, &nf, &od);
  200. return ccu_pll_calc_freq(*parent_rate, nr, nf, od);
  201. }
  202. /*
  203. * This method is used for PLLs, which support the on-the-fly dividers
  204. * adjustment. So there is no need in gating such clocks.
  205. */
  206. static int ccu_pll_set_rate_reset(struct clk_hw *hw, unsigned long rate,
  207. unsigned long parent_rate)
  208. {
  209. struct ccu_pll *pll = to_ccu_pll(hw);
  210. unsigned long nr, nf, od;
  211. unsigned long flags;
  212. u32 mask, val;
  213. int ret;
  214. ccu_pll_calc_factors(rate, parent_rate, &nr, &nf, &od);
  215. mask = CCU_PLL_CTL_CLKR_MASK | CCU_PLL_CTL_CLKF_MASK |
  216. CCU_PLL_CTL_CLKOD_MASK;
  217. val = FIELD_PREP(CCU_PLL_CTL_CLKR_MASK, nr - 1) |
  218. FIELD_PREP(CCU_PLL_CTL_CLKF_MASK, nf - 1) |
  219. FIELD_PREP(CCU_PLL_CTL_CLKOD_MASK, od - 1);
  220. spin_lock_irqsave(&pll->lock, flags);
  221. regmap_update_bits(pll->sys_regs, pll->reg_ctl, mask, val);
  222. ret = ccu_pll_reset(pll, parent_rate, nr);
  223. spin_unlock_irqrestore(&pll->lock, flags);
  224. if (ret)
  225. pr_err("PLL '%s' reset timed out\n", clk_hw_get_name(hw));
  226. return ret;
  227. }
  228. /*
  229. * This method is used for PLLs, which don't support the on-the-fly dividers
  230. * adjustment. So the corresponding clocks are supposed to be gated first.
  231. */
  232. static int ccu_pll_set_rate_norst(struct clk_hw *hw, unsigned long rate,
  233. unsigned long parent_rate)
  234. {
  235. struct ccu_pll *pll = to_ccu_pll(hw);
  236. unsigned long nr, nf, od;
  237. unsigned long flags;
  238. u32 mask, val;
  239. ccu_pll_calc_factors(rate, parent_rate, &nr, &nf, &od);
  240. /*
  241. * Disable PLL if it was enabled by default or left enabled by the
  242. * system bootloader.
  243. */
  244. mask = CCU_PLL_CTL_CLKR_MASK | CCU_PLL_CTL_CLKF_MASK |
  245. CCU_PLL_CTL_CLKOD_MASK | CCU_PLL_CTL_EN;
  246. val = FIELD_PREP(CCU_PLL_CTL_CLKR_MASK, nr - 1) |
  247. FIELD_PREP(CCU_PLL_CTL_CLKF_MASK, nf - 1) |
  248. FIELD_PREP(CCU_PLL_CTL_CLKOD_MASK, od - 1);
  249. spin_lock_irqsave(&pll->lock, flags);
  250. regmap_update_bits(pll->sys_regs, pll->reg_ctl, mask, val);
  251. spin_unlock_irqrestore(&pll->lock, flags);
  252. return 0;
  253. }
  254. #ifdef CONFIG_DEBUG_FS
  255. struct ccu_pll_dbgfs_bit {
  256. struct ccu_pll *pll;
  257. const char *name;
  258. unsigned int reg;
  259. u32 mask;
  260. };
  261. struct ccu_pll_dbgfs_fld {
  262. struct ccu_pll *pll;
  263. const char *name;
  264. unsigned int reg;
  265. unsigned int lsb;
  266. u32 mask;
  267. u32 min;
  268. u32 max;
  269. };
  270. #define CCU_PLL_DBGFS_BIT_ATTR(_name, _reg, _mask) \
  271. { \
  272. .name = _name, \
  273. .reg = _reg, \
  274. .mask = _mask \
  275. }
  276. #define CCU_PLL_DBGFS_FLD_ATTR(_name, _reg, _lsb, _mask, _min, _max) \
  277. { \
  278. .name = _name, \
  279. .reg = _reg, \
  280. .lsb = _lsb, \
  281. .mask = _mask, \
  282. .min = _min, \
  283. .max = _max \
  284. }
  285. static const struct ccu_pll_dbgfs_bit ccu_pll_bits[] = {
  286. CCU_PLL_DBGFS_BIT_ATTR("pll_en", CCU_PLL_CTL, CCU_PLL_CTL_EN),
  287. CCU_PLL_DBGFS_BIT_ATTR("pll_rst", CCU_PLL_CTL, CCU_PLL_CTL_RST),
  288. CCU_PLL_DBGFS_BIT_ATTR("pll_bypass", CCU_PLL_CTL, CCU_PLL_CTL_BYPASS),
  289. CCU_PLL_DBGFS_BIT_ATTR("pll_lock", CCU_PLL_CTL, CCU_PLL_CTL_LOCK)
  290. };
  291. #define CCU_PLL_DBGFS_BIT_NUM ARRAY_SIZE(ccu_pll_bits)
  292. static const struct ccu_pll_dbgfs_fld ccu_pll_flds[] = {
  293. CCU_PLL_DBGFS_FLD_ATTR("pll_nr", CCU_PLL_CTL, CCU_PLL_CTL_CLKR_FLD,
  294. CCU_PLL_CTL_CLKR_MASK, 1, CCU_PLL_NR_MAX),
  295. CCU_PLL_DBGFS_FLD_ATTR("pll_nf", CCU_PLL_CTL, CCU_PLL_CTL_CLKF_FLD,
  296. CCU_PLL_CTL_CLKF_MASK, 1, CCU_PLL_NF_MAX),
  297. CCU_PLL_DBGFS_FLD_ATTR("pll_od", CCU_PLL_CTL, CCU_PLL_CTL_CLKOD_FLD,
  298. CCU_PLL_CTL_CLKOD_MASK, 1, CCU_PLL_OD_MAX),
  299. CCU_PLL_DBGFS_FLD_ATTR("pll_nb", CCU_PLL_CTL1, CCU_PLL_CTL1_BWADJ_FLD,
  300. CCU_PLL_CTL1_BWADJ_MASK, 1, CCU_PLL_NB_MAX)
  301. };
  302. #define CCU_PLL_DBGFS_FLD_NUM ARRAY_SIZE(ccu_pll_flds)
  303. /*
  304. * It can be dangerous to change the PLL settings behind clock framework back,
  305. * therefore we don't provide any kernel config based compile time option for
  306. * this feature to enable.
  307. */
  308. #undef CCU_PLL_ALLOW_WRITE_DEBUGFS
  309. #ifdef CCU_PLL_ALLOW_WRITE_DEBUGFS
  310. static int ccu_pll_dbgfs_bit_set(void *priv, u64 val)
  311. {
  312. const struct ccu_pll_dbgfs_bit *bit = priv;
  313. struct ccu_pll *pll = bit->pll;
  314. unsigned long flags;
  315. spin_lock_irqsave(&pll->lock, flags);
  316. regmap_update_bits(pll->sys_regs, pll->reg_ctl + bit->reg,
  317. bit->mask, val ? bit->mask : 0);
  318. spin_unlock_irqrestore(&pll->lock, flags);
  319. return 0;
  320. }
  321. static int ccu_pll_dbgfs_fld_set(void *priv, u64 val)
  322. {
  323. struct ccu_pll_dbgfs_fld *fld = priv;
  324. struct ccu_pll *pll = fld->pll;
  325. unsigned long flags;
  326. u32 data;
  327. val = clamp_t(u64, val, fld->min, fld->max);
  328. data = ((val - 1) << fld->lsb) & fld->mask;
  329. spin_lock_irqsave(&pll->lock, flags);
  330. regmap_update_bits(pll->sys_regs, pll->reg_ctl + fld->reg, fld->mask,
  331. data);
  332. spin_unlock_irqrestore(&pll->lock, flags);
  333. return 0;
  334. }
  335. #define ccu_pll_dbgfs_mode 0644
  336. #else /* !CCU_PLL_ALLOW_WRITE_DEBUGFS */
  337. #define ccu_pll_dbgfs_bit_set NULL
  338. #define ccu_pll_dbgfs_fld_set NULL
  339. #define ccu_pll_dbgfs_mode 0444
  340. #endif /* !CCU_PLL_ALLOW_WRITE_DEBUGFS */
  341. static int ccu_pll_dbgfs_bit_get(void *priv, u64 *val)
  342. {
  343. struct ccu_pll_dbgfs_bit *bit = priv;
  344. struct ccu_pll *pll = bit->pll;
  345. u32 data = 0;
  346. regmap_read(pll->sys_regs, pll->reg_ctl + bit->reg, &data);
  347. *val = !!(data & bit->mask);
  348. return 0;
  349. }
  350. DEFINE_DEBUGFS_ATTRIBUTE(ccu_pll_dbgfs_bit_fops,
  351. ccu_pll_dbgfs_bit_get, ccu_pll_dbgfs_bit_set, "%llu\n");
  352. static int ccu_pll_dbgfs_fld_get(void *priv, u64 *val)
  353. {
  354. struct ccu_pll_dbgfs_fld *fld = priv;
  355. struct ccu_pll *pll = fld->pll;
  356. u32 data = 0;
  357. regmap_read(pll->sys_regs, pll->reg_ctl + fld->reg, &data);
  358. *val = ((data & fld->mask) >> fld->lsb) + 1;
  359. return 0;
  360. }
  361. DEFINE_DEBUGFS_ATTRIBUTE(ccu_pll_dbgfs_fld_fops,
  362. ccu_pll_dbgfs_fld_get, ccu_pll_dbgfs_fld_set, "%llu\n");
  363. static void ccu_pll_debug_init(struct clk_hw *hw, struct dentry *dentry)
  364. {
  365. struct ccu_pll *pll = to_ccu_pll(hw);
  366. struct ccu_pll_dbgfs_bit *bits;
  367. struct ccu_pll_dbgfs_fld *flds;
  368. int idx;
  369. bits = kcalloc(CCU_PLL_DBGFS_BIT_NUM, sizeof(*bits), GFP_KERNEL);
  370. if (!bits)
  371. return;
  372. for (idx = 0; idx < CCU_PLL_DBGFS_BIT_NUM; ++idx) {
  373. bits[idx] = ccu_pll_bits[idx];
  374. bits[idx].pll = pll;
  375. debugfs_create_file_unsafe(bits[idx].name, ccu_pll_dbgfs_mode,
  376. dentry, &bits[idx],
  377. &ccu_pll_dbgfs_bit_fops);
  378. }
  379. flds = kcalloc(CCU_PLL_DBGFS_FLD_NUM, sizeof(*flds), GFP_KERNEL);
  380. if (!flds)
  381. return;
  382. for (idx = 0; idx < CCU_PLL_DBGFS_FLD_NUM; ++idx) {
  383. flds[idx] = ccu_pll_flds[idx];
  384. flds[idx].pll = pll;
  385. debugfs_create_file_unsafe(flds[idx].name, ccu_pll_dbgfs_mode,
  386. dentry, &flds[idx],
  387. &ccu_pll_dbgfs_fld_fops);
  388. }
  389. }
  390. #else /* !CONFIG_DEBUG_FS */
  391. #define ccu_pll_debug_init NULL
  392. #endif /* !CONFIG_DEBUG_FS */
  393. static const struct clk_ops ccu_pll_gate_to_set_ops = {
  394. .enable = ccu_pll_enable,
  395. .disable = ccu_pll_disable,
  396. .is_enabled = ccu_pll_is_enabled,
  397. .recalc_rate = ccu_pll_recalc_rate,
  398. .round_rate = ccu_pll_round_rate,
  399. .set_rate = ccu_pll_set_rate_norst,
  400. .debug_init = ccu_pll_debug_init
  401. };
  402. static const struct clk_ops ccu_pll_straight_set_ops = {
  403. .enable = ccu_pll_enable,
  404. .disable = ccu_pll_disable,
  405. .is_enabled = ccu_pll_is_enabled,
  406. .recalc_rate = ccu_pll_recalc_rate,
  407. .round_rate = ccu_pll_round_rate,
  408. .set_rate = ccu_pll_set_rate_reset,
  409. .debug_init = ccu_pll_debug_init
  410. };
  411. struct ccu_pll *ccu_pll_hw_register(const struct ccu_pll_init_data *pll_init)
  412. {
  413. struct clk_parent_data parent_data = { };
  414. struct clk_init_data hw_init = { };
  415. struct ccu_pll *pll;
  416. int ret;
  417. if (!pll_init)
  418. return ERR_PTR(-EINVAL);
  419. pll = kzalloc(sizeof(*pll), GFP_KERNEL);
  420. if (!pll)
  421. return ERR_PTR(-ENOMEM);
  422. /*
  423. * Note since Baikal-T1 System Controller registers are MMIO-backed
  424. * we won't check the regmap IO operations return status, because it
  425. * must be zero anyway.
  426. */
  427. pll->hw.init = &hw_init;
  428. pll->reg_ctl = pll_init->base + CCU_PLL_CTL;
  429. pll->reg_ctl1 = pll_init->base + CCU_PLL_CTL1;
  430. pll->sys_regs = pll_init->sys_regs;
  431. pll->id = pll_init->id;
  432. spin_lock_init(&pll->lock);
  433. hw_init.name = pll_init->name;
  434. hw_init.flags = pll_init->flags;
  435. if (hw_init.flags & CLK_SET_RATE_GATE)
  436. hw_init.ops = &ccu_pll_gate_to_set_ops;
  437. else
  438. hw_init.ops = &ccu_pll_straight_set_ops;
  439. if (!pll_init->parent_name) {
  440. ret = -EINVAL;
  441. goto err_free_pll;
  442. }
  443. parent_data.fw_name = pll_init->parent_name;
  444. hw_init.parent_data = &parent_data;
  445. hw_init.num_parents = 1;
  446. ret = of_clk_hw_register(pll_init->np, &pll->hw);
  447. if (ret)
  448. goto err_free_pll;
  449. return pll;
  450. err_free_pll:
  451. kfree(pll);
  452. return ERR_PTR(ret);
  453. }
  454. void ccu_pll_hw_unregister(struct ccu_pll *pll)
  455. {
  456. clk_hw_unregister(&pll->hw);
  457. kfree(pll);
  458. }