clkgen-pll.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  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.h>
  18. #include <linux/clk-provider.h>
  19. #include <linux/iopoll.h>
  20. #include "clkgen.h"
  21. static DEFINE_SPINLOCK(clkgena_c32_odf_lock);
  22. DEFINE_SPINLOCK(clkgen_a9_lock);
  23. /*
  24. * Common PLL configuration register bits for PLL800 and PLL1600 C65
  25. */
  26. #define C65_MDIV_PLL800_MASK (0xff)
  27. #define C65_MDIV_PLL1600_MASK (0x7)
  28. #define C65_NDIV_MASK (0xff)
  29. #define C65_PDIV_MASK (0x7)
  30. /*
  31. * PLL configuration register bits for PLL3200 C32
  32. */
  33. #define C32_NDIV_MASK (0xff)
  34. #define C32_IDF_MASK (0x7)
  35. #define C32_ODF_MASK (0x3f)
  36. #define C32_LDF_MASK (0x7f)
  37. #define C32_CP_MASK (0x1f)
  38. #define C32_MAX_ODFS (4)
  39. /*
  40. * PLL configuration register bits for PLL4600 C28
  41. */
  42. #define C28_NDIV_MASK (0xff)
  43. #define C28_IDF_MASK (0x7)
  44. #define C28_ODF_MASK (0x3f)
  45. struct clkgen_pll_data {
  46. struct clkgen_field pdn_status;
  47. struct clkgen_field pdn_ctrl;
  48. struct clkgen_field locked_status;
  49. struct clkgen_field mdiv;
  50. struct clkgen_field ndiv;
  51. struct clkgen_field pdiv;
  52. struct clkgen_field idf;
  53. struct clkgen_field ldf;
  54. struct clkgen_field cp;
  55. unsigned int num_odfs;
  56. struct clkgen_field odf[C32_MAX_ODFS];
  57. struct clkgen_field odf_gate[C32_MAX_ODFS];
  58. bool switch2pll_en;
  59. struct clkgen_field switch2pll;
  60. spinlock_t *lock;
  61. const struct clk_ops *ops;
  62. };
  63. static const struct clk_ops st_pll1600c65_ops;
  64. static const struct clk_ops st_pll800c65_ops;
  65. static const struct clk_ops stm_pll3200c32_ops;
  66. static const struct clk_ops stm_pll3200c32_a9_ops;
  67. static const struct clk_ops st_pll1200c32_ops;
  68. static const struct clk_ops stm_pll4600c28_ops;
  69. static const struct clkgen_pll_data st_pll1600c65_ax = {
  70. .pdn_status = CLKGEN_FIELD(0x0, 0x1, 19),
  71. .pdn_ctrl = CLKGEN_FIELD(0x10, 0x1, 0),
  72. .locked_status = CLKGEN_FIELD(0x0, 0x1, 31),
  73. .mdiv = CLKGEN_FIELD(0x0, C65_MDIV_PLL1600_MASK, 0),
  74. .ndiv = CLKGEN_FIELD(0x0, C65_NDIV_MASK, 8),
  75. .ops = &st_pll1600c65_ops
  76. };
  77. static const struct clkgen_pll_data st_pll800c65_ax = {
  78. .pdn_status = CLKGEN_FIELD(0x0, 0x1, 19),
  79. .pdn_ctrl = CLKGEN_FIELD(0xC, 0x1, 1),
  80. .locked_status = CLKGEN_FIELD(0x0, 0x1, 31),
  81. .mdiv = CLKGEN_FIELD(0x0, C65_MDIV_PLL800_MASK, 0),
  82. .ndiv = CLKGEN_FIELD(0x0, C65_NDIV_MASK, 8),
  83. .pdiv = CLKGEN_FIELD(0x0, C65_PDIV_MASK, 16),
  84. .ops = &st_pll800c65_ops
  85. };
  86. static const struct clkgen_pll_data st_pll3200c32_a1x_0 = {
  87. .pdn_status = CLKGEN_FIELD(0x0, 0x1, 31),
  88. .pdn_ctrl = CLKGEN_FIELD(0x18, 0x1, 0),
  89. .locked_status = CLKGEN_FIELD(0x4, 0x1, 31),
  90. .ndiv = CLKGEN_FIELD(0x0, C32_NDIV_MASK, 0x0),
  91. .idf = CLKGEN_FIELD(0x4, C32_IDF_MASK, 0x0),
  92. .num_odfs = 4,
  93. .odf = { CLKGEN_FIELD(0x54, C32_ODF_MASK, 4),
  94. CLKGEN_FIELD(0x54, C32_ODF_MASK, 10),
  95. CLKGEN_FIELD(0x54, C32_ODF_MASK, 16),
  96. CLKGEN_FIELD(0x54, C32_ODF_MASK, 22) },
  97. .odf_gate = { CLKGEN_FIELD(0x54, 0x1, 0),
  98. CLKGEN_FIELD(0x54, 0x1, 1),
  99. CLKGEN_FIELD(0x54, 0x1, 2),
  100. CLKGEN_FIELD(0x54, 0x1, 3) },
  101. .ops = &stm_pll3200c32_ops,
  102. };
  103. static const struct clkgen_pll_data st_pll3200c32_a1x_1 = {
  104. .pdn_status = CLKGEN_FIELD(0xC, 0x1, 31),
  105. .pdn_ctrl = CLKGEN_FIELD(0x18, 0x1, 1),
  106. .locked_status = CLKGEN_FIELD(0x10, 0x1, 31),
  107. .ndiv = CLKGEN_FIELD(0xC, C32_NDIV_MASK, 0x0),
  108. .idf = CLKGEN_FIELD(0x10, C32_IDF_MASK, 0x0),
  109. .num_odfs = 4,
  110. .odf = { CLKGEN_FIELD(0x58, C32_ODF_MASK, 4),
  111. CLKGEN_FIELD(0x58, C32_ODF_MASK, 10),
  112. CLKGEN_FIELD(0x58, C32_ODF_MASK, 16),
  113. CLKGEN_FIELD(0x58, C32_ODF_MASK, 22) },
  114. .odf_gate = { CLKGEN_FIELD(0x58, 0x1, 0),
  115. CLKGEN_FIELD(0x58, 0x1, 1),
  116. CLKGEN_FIELD(0x58, 0x1, 2),
  117. CLKGEN_FIELD(0x58, 0x1, 3) },
  118. .ops = &stm_pll3200c32_ops,
  119. };
  120. /* 415 specific */
  121. static const struct clkgen_pll_data st_pll3200c32_a9_415 = {
  122. .pdn_status = CLKGEN_FIELD(0x0, 0x1, 0),
  123. .pdn_ctrl = CLKGEN_FIELD(0x0, 0x1, 0),
  124. .locked_status = CLKGEN_FIELD(0x6C, 0x1, 0),
  125. .ndiv = CLKGEN_FIELD(0x0, C32_NDIV_MASK, 9),
  126. .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 22),
  127. .num_odfs = 1,
  128. .odf = { CLKGEN_FIELD(0x0, C32_ODF_MASK, 3) },
  129. .odf_gate = { CLKGEN_FIELD(0x0, 0x1, 28) },
  130. .ops = &stm_pll3200c32_ops,
  131. };
  132. static const struct clkgen_pll_data st_pll3200c32_ddr_415 = {
  133. .pdn_status = CLKGEN_FIELD(0x0, 0x1, 0),
  134. .pdn_ctrl = CLKGEN_FIELD(0x0, 0x1, 0),
  135. .locked_status = CLKGEN_FIELD(0x100, 0x1, 0),
  136. .ndiv = CLKGEN_FIELD(0x8, C32_NDIV_MASK, 0),
  137. .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 25),
  138. .num_odfs = 2,
  139. .odf = { CLKGEN_FIELD(0x8, C32_ODF_MASK, 8),
  140. CLKGEN_FIELD(0x8, C32_ODF_MASK, 14) },
  141. .odf_gate = { CLKGEN_FIELD(0x4, 0x1, 28),
  142. CLKGEN_FIELD(0x4, 0x1, 29) },
  143. .ops = &stm_pll3200c32_ops,
  144. };
  145. static const struct clkgen_pll_data st_pll1200c32_gpu_415 = {
  146. .pdn_status = CLKGEN_FIELD(0x4, 0x1, 0),
  147. .pdn_ctrl = CLKGEN_FIELD(0x4, 0x1, 0),
  148. .locked_status = CLKGEN_FIELD(0x168, 0x1, 0),
  149. .ldf = CLKGEN_FIELD(0x0, C32_LDF_MASK, 3),
  150. .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 0),
  151. .num_odfs = 0,
  152. .odf = { CLKGEN_FIELD(0x0, C32_ODF_MASK, 10) },
  153. .ops = &st_pll1200c32_ops,
  154. };
  155. /* 416 specific */
  156. static const struct clkgen_pll_data st_pll3200c32_a9_416 = {
  157. .pdn_status = CLKGEN_FIELD(0x0, 0x1, 0),
  158. .pdn_ctrl = CLKGEN_FIELD(0x0, 0x1, 0),
  159. .locked_status = CLKGEN_FIELD(0x6C, 0x1, 0),
  160. .ndiv = CLKGEN_FIELD(0x8, C32_NDIV_MASK, 0),
  161. .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 25),
  162. .num_odfs = 1,
  163. .odf = { CLKGEN_FIELD(0x8, C32_ODF_MASK, 8) },
  164. .odf_gate = { CLKGEN_FIELD(0x4, 0x1, 28) },
  165. .ops = &stm_pll3200c32_ops,
  166. };
  167. static const struct clkgen_pll_data st_pll3200c32_ddr_416 = {
  168. .pdn_status = CLKGEN_FIELD(0x0, 0x1, 0),
  169. .pdn_ctrl = CLKGEN_FIELD(0x0, 0x1, 0),
  170. .locked_status = CLKGEN_FIELD(0x10C, 0x1, 0),
  171. .ndiv = CLKGEN_FIELD(0x8, C32_NDIV_MASK, 0),
  172. .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 25),
  173. .num_odfs = 2,
  174. .odf = { CLKGEN_FIELD(0x8, C32_ODF_MASK, 8),
  175. CLKGEN_FIELD(0x8, C32_ODF_MASK, 14) },
  176. .odf_gate = { CLKGEN_FIELD(0x4, 0x1, 28),
  177. CLKGEN_FIELD(0x4, 0x1, 29) },
  178. .ops = &stm_pll3200c32_ops,
  179. };
  180. static const struct clkgen_pll_data st_pll1200c32_gpu_416 = {
  181. .pdn_status = CLKGEN_FIELD(0x8E4, 0x1, 3),
  182. .pdn_ctrl = CLKGEN_FIELD(0x8E4, 0x1, 3),
  183. .locked_status = CLKGEN_FIELD(0x90C, 0x1, 0),
  184. .ldf = CLKGEN_FIELD(0x0, C32_LDF_MASK, 3),
  185. .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 0),
  186. .num_odfs = 0,
  187. .odf = { CLKGEN_FIELD(0x0, C32_ODF_MASK, 10) },
  188. .ops = &st_pll1200c32_ops,
  189. };
  190. static const struct clkgen_pll_data st_pll3200c32_407_a0 = {
  191. /* 407 A0 */
  192. .pdn_status = CLKGEN_FIELD(0x2a0, 0x1, 8),
  193. .pdn_ctrl = CLKGEN_FIELD(0x2a0, 0x1, 8),
  194. .locked_status = CLKGEN_FIELD(0x2a0, 0x1, 24),
  195. .ndiv = CLKGEN_FIELD(0x2a4, C32_NDIV_MASK, 16),
  196. .idf = CLKGEN_FIELD(0x2a4, C32_IDF_MASK, 0x0),
  197. .num_odfs = 1,
  198. .odf = { CLKGEN_FIELD(0x2b4, C32_ODF_MASK, 0) },
  199. .odf_gate = { CLKGEN_FIELD(0x2b4, 0x1, 6) },
  200. .ops = &stm_pll3200c32_ops,
  201. };
  202. static const struct clkgen_pll_data st_pll3200c32_cx_0 = {
  203. /* 407 C0 PLL0 */
  204. .pdn_status = CLKGEN_FIELD(0x2a0, 0x1, 8),
  205. .pdn_ctrl = CLKGEN_FIELD(0x2a0, 0x1, 8),
  206. .locked_status = CLKGEN_FIELD(0x2a0, 0x1, 24),
  207. .ndiv = CLKGEN_FIELD(0x2a4, C32_NDIV_MASK, 16),
  208. .idf = CLKGEN_FIELD(0x2a4, C32_IDF_MASK, 0x0),
  209. .num_odfs = 1,
  210. .odf = { CLKGEN_FIELD(0x2b4, C32_ODF_MASK, 0) },
  211. .odf_gate = { CLKGEN_FIELD(0x2b4, 0x1, 6) },
  212. .ops = &stm_pll3200c32_ops,
  213. };
  214. static const struct clkgen_pll_data st_pll3200c32_cx_1 = {
  215. /* 407 C0 PLL1 */
  216. .pdn_status = CLKGEN_FIELD(0x2c8, 0x1, 8),
  217. .pdn_ctrl = CLKGEN_FIELD(0x2c8, 0x1, 8),
  218. .locked_status = CLKGEN_FIELD(0x2c8, 0x1, 24),
  219. .ndiv = CLKGEN_FIELD(0x2cc, C32_NDIV_MASK, 16),
  220. .idf = CLKGEN_FIELD(0x2cc, C32_IDF_MASK, 0x0),
  221. .num_odfs = 1,
  222. .odf = { CLKGEN_FIELD(0x2dc, C32_ODF_MASK, 0) },
  223. .odf_gate = { CLKGEN_FIELD(0x2dc, 0x1, 6) },
  224. .ops = &stm_pll3200c32_ops,
  225. };
  226. static const struct clkgen_pll_data st_pll3200c32_407_a9 = {
  227. /* 407 A9 */
  228. .pdn_status = CLKGEN_FIELD(0x1a8, 0x1, 0),
  229. .pdn_ctrl = CLKGEN_FIELD(0x1a8, 0x1, 0),
  230. .locked_status = CLKGEN_FIELD(0x87c, 0x1, 0),
  231. .ndiv = CLKGEN_FIELD(0x1b0, C32_NDIV_MASK, 0),
  232. .idf = CLKGEN_FIELD(0x1a8, C32_IDF_MASK, 25),
  233. .num_odfs = 1,
  234. .odf = { CLKGEN_FIELD(0x1b0, C32_ODF_MASK, 8) },
  235. .odf_gate = { CLKGEN_FIELD(0x1ac, 0x1, 28) },
  236. .switch2pll_en = true,
  237. .cp = CLKGEN_FIELD(0x1a8, C32_CP_MASK, 1),
  238. .switch2pll = CLKGEN_FIELD(0x1a4, 0x1, 1),
  239. .lock = &clkgen_a9_lock,
  240. .ops = &stm_pll3200c32_a9_ops,
  241. };
  242. static struct clkgen_pll_data st_pll4600c28_418_a9 = {
  243. /* 418 A9 */
  244. .pdn_status = CLKGEN_FIELD(0x1a8, 0x1, 0),
  245. .pdn_ctrl = CLKGEN_FIELD(0x1a8, 0x1, 0),
  246. .locked_status = CLKGEN_FIELD(0x87c, 0x1, 0),
  247. .ndiv = CLKGEN_FIELD(0x1b0, C28_NDIV_MASK, 0),
  248. .idf = CLKGEN_FIELD(0x1a8, C28_IDF_MASK, 25),
  249. .num_odfs = 1,
  250. .odf = { CLKGEN_FIELD(0x1b0, C28_ODF_MASK, 8) },
  251. .odf_gate = { CLKGEN_FIELD(0x1ac, 0x1, 28) },
  252. .switch2pll_en = true,
  253. .switch2pll = CLKGEN_FIELD(0x1a4, 0x1, 1),
  254. .lock = &clkgen_a9_lock,
  255. .ops = &stm_pll4600c28_ops,
  256. };
  257. /**
  258. * DOC: Clock Generated by PLL, rate set and enabled by bootloader
  259. *
  260. * Traits of this clock:
  261. * prepare - clk_(un)prepare only ensures parent is (un)prepared
  262. * enable - clk_enable/disable only ensures parent is enabled
  263. * rate - rate is fixed. No clk_set_rate support
  264. * parent - fixed parent. No clk_set_parent support
  265. */
  266. /**
  267. * PLL clock that is integrated in the ClockGenA instances on the STiH415
  268. * and STiH416.
  269. *
  270. * @hw: handle between common and hardware-specific interfaces.
  271. * @type: PLL instance type.
  272. * @regs_base: base of the PLL configuration register(s).
  273. *
  274. */
  275. struct clkgen_pll {
  276. struct clk_hw hw;
  277. struct clkgen_pll_data *data;
  278. void __iomem *regs_base;
  279. spinlock_t *lock;
  280. u32 ndiv;
  281. u32 idf;
  282. u32 odf;
  283. u32 cp;
  284. };
  285. #define to_clkgen_pll(_hw) container_of(_hw, struct clkgen_pll, hw)
  286. struct stm_pll {
  287. unsigned long mdiv;
  288. unsigned long ndiv;
  289. unsigned long pdiv;
  290. unsigned long odf;
  291. unsigned long idf;
  292. unsigned long ldf;
  293. unsigned long cp;
  294. };
  295. static int clkgen_pll_is_locked(struct clk_hw *hw)
  296. {
  297. struct clkgen_pll *pll = to_clkgen_pll(hw);
  298. u32 locked = CLKGEN_READ(pll, locked_status);
  299. return !!locked;
  300. }
  301. static int clkgen_pll_is_enabled(struct clk_hw *hw)
  302. {
  303. struct clkgen_pll *pll = to_clkgen_pll(hw);
  304. u32 poweroff = CLKGEN_READ(pll, pdn_status);
  305. return !poweroff;
  306. }
  307. static int __clkgen_pll_enable(struct clk_hw *hw)
  308. {
  309. struct clkgen_pll *pll = to_clkgen_pll(hw);
  310. void __iomem *base = pll->regs_base;
  311. struct clkgen_field *field = &pll->data->locked_status;
  312. int ret = 0;
  313. u32 reg;
  314. if (clkgen_pll_is_enabled(hw))
  315. return 0;
  316. CLKGEN_WRITE(pll, pdn_ctrl, 0);
  317. ret = readl_relaxed_poll_timeout(base + field->offset, reg,
  318. !!((reg >> field->shift) & field->mask), 0, 10000);
  319. if (!ret) {
  320. if (pll->data->switch2pll_en)
  321. CLKGEN_WRITE(pll, switch2pll, 0);
  322. pr_debug("%s:%s enabled\n", __clk_get_name(hw->clk), __func__);
  323. }
  324. return ret;
  325. }
  326. static int clkgen_pll_enable(struct clk_hw *hw)
  327. {
  328. struct clkgen_pll *pll = to_clkgen_pll(hw);
  329. unsigned long flags = 0;
  330. int ret = 0;
  331. if (pll->lock)
  332. spin_lock_irqsave(pll->lock, flags);
  333. ret = __clkgen_pll_enable(hw);
  334. if (pll->lock)
  335. spin_unlock_irqrestore(pll->lock, flags);
  336. return ret;
  337. }
  338. static void __clkgen_pll_disable(struct clk_hw *hw)
  339. {
  340. struct clkgen_pll *pll = to_clkgen_pll(hw);
  341. if (!clkgen_pll_is_enabled(hw))
  342. return;
  343. if (pll->data->switch2pll_en)
  344. CLKGEN_WRITE(pll, switch2pll, 1);
  345. CLKGEN_WRITE(pll, pdn_ctrl, 1);
  346. pr_debug("%s:%s disabled\n", __clk_get_name(hw->clk), __func__);
  347. }
  348. static void clkgen_pll_disable(struct clk_hw *hw)
  349. {
  350. struct clkgen_pll *pll = to_clkgen_pll(hw);
  351. unsigned long flags = 0;
  352. if (pll->lock)
  353. spin_lock_irqsave(pll->lock, flags);
  354. __clkgen_pll_disable(hw);
  355. if (pll->lock)
  356. spin_unlock_irqrestore(pll->lock, flags);
  357. }
  358. static unsigned long recalc_stm_pll800c65(struct clk_hw *hw,
  359. unsigned long parent_rate)
  360. {
  361. struct clkgen_pll *pll = to_clkgen_pll(hw);
  362. unsigned long mdiv, ndiv, pdiv;
  363. unsigned long rate;
  364. uint64_t res;
  365. if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw))
  366. return 0;
  367. pdiv = CLKGEN_READ(pll, pdiv);
  368. mdiv = CLKGEN_READ(pll, mdiv);
  369. ndiv = CLKGEN_READ(pll, ndiv);
  370. if (!mdiv)
  371. mdiv++; /* mdiv=0 or 1 => MDIV=1 */
  372. res = (uint64_t)2 * (uint64_t)parent_rate * (uint64_t)ndiv;
  373. rate = (unsigned long)div64_u64(res, mdiv * (1 << pdiv));
  374. pr_debug("%s:%s rate %lu\n", clk_hw_get_name(hw), __func__, rate);
  375. return rate;
  376. }
  377. static unsigned long recalc_stm_pll1600c65(struct clk_hw *hw,
  378. unsigned long parent_rate)
  379. {
  380. struct clkgen_pll *pll = to_clkgen_pll(hw);
  381. unsigned long mdiv, ndiv;
  382. unsigned long rate;
  383. if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw))
  384. return 0;
  385. mdiv = CLKGEN_READ(pll, mdiv);
  386. ndiv = CLKGEN_READ(pll, ndiv);
  387. if (!mdiv)
  388. mdiv = 1;
  389. /* Note: input is divided by 1000 to avoid overflow */
  390. rate = ((2 * (parent_rate / 1000) * ndiv) / mdiv) * 1000;
  391. pr_debug("%s:%s rate %lu\n", clk_hw_get_name(hw), __func__, rate);
  392. return rate;
  393. }
  394. static int clk_pll3200c32_get_params(unsigned long input, unsigned long output,
  395. struct stm_pll *pll)
  396. {
  397. unsigned long i, n;
  398. unsigned long deviation = ~0;
  399. unsigned long new_freq;
  400. long new_deviation;
  401. /* Charge pump table: highest ndiv value for cp=6 to 25 */
  402. static const unsigned char cp_table[] = {
  403. 48, 56, 64, 72, 80, 88, 96, 104, 112, 120,
  404. 128, 136, 144, 152, 160, 168, 176, 184, 192
  405. };
  406. /* Output clock range: 800Mhz to 1600Mhz */
  407. if (output < 800000000 || output > 1600000000)
  408. return -EINVAL;
  409. input /= 1000;
  410. output /= 1000;
  411. for (i = 1; i <= 7 && deviation; i++) {
  412. n = i * output / (2 * input);
  413. /* Checks */
  414. if (n < 8)
  415. continue;
  416. if (n > 200)
  417. break;
  418. new_freq = (input * 2 * n) / i;
  419. new_deviation = abs(new_freq - output);
  420. if (!new_deviation || new_deviation < deviation) {
  421. pll->idf = i;
  422. pll->ndiv = n;
  423. deviation = new_deviation;
  424. }
  425. }
  426. if (deviation == ~0) /* No solution found */
  427. return -EINVAL;
  428. /* Computing recommended charge pump value */
  429. for (pll->cp = 6; pll->ndiv > cp_table[pll->cp-6]; (pll->cp)++)
  430. ;
  431. return 0;
  432. }
  433. static int clk_pll3200c32_get_rate(unsigned long input, struct stm_pll *pll,
  434. unsigned long *rate)
  435. {
  436. if (!pll->idf)
  437. pll->idf = 1;
  438. *rate = ((2 * (input / 1000) * pll->ndiv) / pll->idf) * 1000;
  439. return 0;
  440. }
  441. static unsigned long recalc_stm_pll3200c32(struct clk_hw *hw,
  442. unsigned long parent_rate)
  443. {
  444. struct clkgen_pll *pll = to_clkgen_pll(hw);
  445. unsigned long ndiv, idf;
  446. unsigned long rate = 0;
  447. if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw))
  448. return 0;
  449. ndiv = CLKGEN_READ(pll, ndiv);
  450. idf = CLKGEN_READ(pll, idf);
  451. if (idf)
  452. /* Note: input is divided to avoid overflow */
  453. rate = ((2 * (parent_rate/1000) * ndiv) / idf) * 1000;
  454. pr_debug("%s:%s rate %lu\n", clk_hw_get_name(hw), __func__, rate);
  455. return rate;
  456. }
  457. static long round_rate_stm_pll3200c32(struct clk_hw *hw, unsigned long rate,
  458. unsigned long *prate)
  459. {
  460. struct stm_pll params;
  461. if (!clk_pll3200c32_get_params(*prate, rate, &params))
  462. clk_pll3200c32_get_rate(*prate, &params, &rate);
  463. else {
  464. pr_debug("%s: %s rate %ld Invalid\n", __func__,
  465. __clk_get_name(hw->clk), rate);
  466. return 0;
  467. }
  468. pr_debug("%s: %s new rate %ld [ndiv=%u] [idf=%u]\n",
  469. __func__, __clk_get_name(hw->clk),
  470. rate, (unsigned int)params.ndiv,
  471. (unsigned int)params.idf);
  472. return rate;
  473. }
  474. static int set_rate_stm_pll3200c32(struct clk_hw *hw, unsigned long rate,
  475. unsigned long parent_rate)
  476. {
  477. struct clkgen_pll *pll = to_clkgen_pll(hw);
  478. struct stm_pll params;
  479. long hwrate = 0;
  480. unsigned long flags = 0;
  481. if (!rate || !parent_rate)
  482. return -EINVAL;
  483. if (!clk_pll3200c32_get_params(parent_rate, rate, &params))
  484. clk_pll3200c32_get_rate(parent_rate, &params, &hwrate);
  485. pr_debug("%s: %s new rate %ld [ndiv=0x%x] [idf=0x%x]\n",
  486. __func__, __clk_get_name(hw->clk),
  487. hwrate, (unsigned int)params.ndiv,
  488. (unsigned int)params.idf);
  489. if (!hwrate)
  490. return -EINVAL;
  491. pll->ndiv = params.ndiv;
  492. pll->idf = params.idf;
  493. pll->cp = params.cp;
  494. __clkgen_pll_disable(hw);
  495. if (pll->lock)
  496. spin_lock_irqsave(pll->lock, flags);
  497. CLKGEN_WRITE(pll, ndiv, pll->ndiv);
  498. CLKGEN_WRITE(pll, idf, pll->idf);
  499. CLKGEN_WRITE(pll, cp, pll->cp);
  500. if (pll->lock)
  501. spin_unlock_irqrestore(pll->lock, flags);
  502. __clkgen_pll_enable(hw);
  503. return 0;
  504. }
  505. static unsigned long recalc_stm_pll1200c32(struct clk_hw *hw,
  506. unsigned long parent_rate)
  507. {
  508. struct clkgen_pll *pll = to_clkgen_pll(hw);
  509. unsigned long odf, ldf, idf;
  510. unsigned long rate;
  511. if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw))
  512. return 0;
  513. odf = CLKGEN_READ(pll, odf[0]);
  514. ldf = CLKGEN_READ(pll, ldf);
  515. idf = CLKGEN_READ(pll, idf);
  516. if (!idf) /* idf==0 means 1 */
  517. idf = 1;
  518. if (!odf) /* odf==0 means 1 */
  519. odf = 1;
  520. /* Note: input is divided by 1000 to avoid overflow */
  521. rate = (((parent_rate / 1000) * ldf) / (odf * idf)) * 1000;
  522. pr_debug("%s:%s rate %lu\n", clk_hw_get_name(hw), __func__, rate);
  523. return rate;
  524. }
  525. /* PLL output structure
  526. * FVCO >> /2 >> FVCOBY2 (no output)
  527. * |> Divider (ODF) >> PHI
  528. *
  529. * FVCOby2 output = (input * 2 * NDIV) / IDF (assuming FRAC_CONTROL==L)
  530. *
  531. * Rules:
  532. * 4Mhz <= INFF input <= 350Mhz
  533. * 4Mhz <= INFIN (INFF / IDF) <= 50Mhz
  534. * 19.05Mhz <= FVCOby2 output (PHI w ODF=1) <= 3000Mhz
  535. * 1 <= i (register/dec value for IDF) <= 7
  536. * 8 <= n (register/dec value for NDIV) <= 246
  537. */
  538. static int clk_pll4600c28_get_params(unsigned long input, unsigned long output,
  539. struct stm_pll *pll)
  540. {
  541. unsigned long i, infin, n;
  542. unsigned long deviation = ~0;
  543. unsigned long new_freq, new_deviation;
  544. /* Output clock range: 19Mhz to 3000Mhz */
  545. if (output < 19000000 || output > 3000000000u)
  546. return -EINVAL;
  547. /* For better jitter, IDF should be smallest and NDIV must be maximum */
  548. for (i = 1; i <= 7 && deviation; i++) {
  549. /* INFIN checks */
  550. infin = input / i;
  551. if (infin < 4000000 || infin > 50000000)
  552. continue; /* Invalid case */
  553. n = output / (infin * 2);
  554. if (n < 8 || n > 246)
  555. continue; /* Invalid case */
  556. if (n < 246)
  557. n++; /* To work around 'y' when n=x.y */
  558. for (; n >= 8 && deviation; n--) {
  559. new_freq = infin * 2 * n;
  560. if (new_freq < output)
  561. break; /* Optimization: shorting loop */
  562. new_deviation = new_freq - output;
  563. if (!new_deviation || new_deviation < deviation) {
  564. pll->idf = i;
  565. pll->ndiv = n;
  566. deviation = new_deviation;
  567. }
  568. }
  569. }
  570. if (deviation == ~0) /* No solution found */
  571. return -EINVAL;
  572. return 0;
  573. }
  574. static int clk_pll4600c28_get_rate(unsigned long input, struct stm_pll *pll,
  575. unsigned long *rate)
  576. {
  577. if (!pll->idf)
  578. pll->idf = 1;
  579. *rate = (input / pll->idf) * 2 * pll->ndiv;
  580. return 0;
  581. }
  582. static unsigned long recalc_stm_pll4600c28(struct clk_hw *hw,
  583. unsigned long parent_rate)
  584. {
  585. struct clkgen_pll *pll = to_clkgen_pll(hw);
  586. struct stm_pll params;
  587. unsigned long rate;
  588. if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw))
  589. return 0;
  590. params.ndiv = CLKGEN_READ(pll, ndiv);
  591. params.idf = CLKGEN_READ(pll, idf);
  592. clk_pll4600c28_get_rate(parent_rate, &params, &rate);
  593. pr_debug("%s:%s rate %lu\n", __clk_get_name(hw->clk), __func__, rate);
  594. return rate;
  595. }
  596. static long round_rate_stm_pll4600c28(struct clk_hw *hw, unsigned long rate,
  597. unsigned long *prate)
  598. {
  599. struct stm_pll params;
  600. if (!clk_pll4600c28_get_params(*prate, rate, &params)) {
  601. clk_pll4600c28_get_rate(*prate, &params, &rate);
  602. } else {
  603. pr_debug("%s: %s rate %ld Invalid\n", __func__,
  604. __clk_get_name(hw->clk), rate);
  605. return 0;
  606. }
  607. pr_debug("%s: %s new rate %ld [ndiv=%u] [idf=%u]\n",
  608. __func__, __clk_get_name(hw->clk),
  609. rate, (unsigned int)params.ndiv,
  610. (unsigned int)params.idf);
  611. return rate;
  612. }
  613. static int set_rate_stm_pll4600c28(struct clk_hw *hw, unsigned long rate,
  614. unsigned long parent_rate)
  615. {
  616. struct clkgen_pll *pll = to_clkgen_pll(hw);
  617. struct stm_pll params;
  618. long hwrate;
  619. unsigned long flags = 0;
  620. if (!rate || !parent_rate)
  621. return -EINVAL;
  622. if (!clk_pll4600c28_get_params(parent_rate, rate, &params)) {
  623. clk_pll4600c28_get_rate(parent_rate, &params, &hwrate);
  624. } else {
  625. pr_debug("%s: %s rate %ld Invalid\n", __func__,
  626. __clk_get_name(hw->clk), rate);
  627. return -EINVAL;
  628. }
  629. pr_debug("%s: %s new rate %ld [ndiv=0x%x] [idf=0x%x]\n",
  630. __func__, __clk_get_name(hw->clk),
  631. hwrate, (unsigned int)params.ndiv,
  632. (unsigned int)params.idf);
  633. if (!hwrate)
  634. return -EINVAL;
  635. pll->ndiv = params.ndiv;
  636. pll->idf = params.idf;
  637. __clkgen_pll_disable(hw);
  638. if (pll->lock)
  639. spin_lock_irqsave(pll->lock, flags);
  640. CLKGEN_WRITE(pll, ndiv, pll->ndiv);
  641. CLKGEN_WRITE(pll, idf, pll->idf);
  642. if (pll->lock)
  643. spin_unlock_irqrestore(pll->lock, flags);
  644. __clkgen_pll_enable(hw);
  645. return 0;
  646. }
  647. static const struct clk_ops st_pll1600c65_ops = {
  648. .enable = clkgen_pll_enable,
  649. .disable = clkgen_pll_disable,
  650. .is_enabled = clkgen_pll_is_enabled,
  651. .recalc_rate = recalc_stm_pll1600c65,
  652. };
  653. static const struct clk_ops st_pll800c65_ops = {
  654. .enable = clkgen_pll_enable,
  655. .disable = clkgen_pll_disable,
  656. .is_enabled = clkgen_pll_is_enabled,
  657. .recalc_rate = recalc_stm_pll800c65,
  658. };
  659. static const struct clk_ops stm_pll3200c32_ops = {
  660. .enable = clkgen_pll_enable,
  661. .disable = clkgen_pll_disable,
  662. .is_enabled = clkgen_pll_is_enabled,
  663. .recalc_rate = recalc_stm_pll3200c32,
  664. };
  665. static const struct clk_ops stm_pll3200c32_a9_ops = {
  666. .enable = clkgen_pll_enable,
  667. .disable = clkgen_pll_disable,
  668. .is_enabled = clkgen_pll_is_enabled,
  669. .recalc_rate = recalc_stm_pll3200c32,
  670. .round_rate = round_rate_stm_pll3200c32,
  671. .set_rate = set_rate_stm_pll3200c32,
  672. };
  673. static const struct clk_ops st_pll1200c32_ops = {
  674. .enable = clkgen_pll_enable,
  675. .disable = clkgen_pll_disable,
  676. .is_enabled = clkgen_pll_is_enabled,
  677. .recalc_rate = recalc_stm_pll1200c32,
  678. };
  679. static const struct clk_ops stm_pll4600c28_ops = {
  680. .enable = clkgen_pll_enable,
  681. .disable = clkgen_pll_disable,
  682. .is_enabled = clkgen_pll_is_enabled,
  683. .recalc_rate = recalc_stm_pll4600c28,
  684. .round_rate = round_rate_stm_pll4600c28,
  685. .set_rate = set_rate_stm_pll4600c28,
  686. };
  687. static struct clk * __init clkgen_pll_register(const char *parent_name,
  688. struct clkgen_pll_data *pll_data,
  689. void __iomem *reg,
  690. const char *clk_name, spinlock_t *lock)
  691. {
  692. struct clkgen_pll *pll;
  693. struct clk *clk;
  694. struct clk_init_data init;
  695. pll = kzalloc(sizeof(*pll), GFP_KERNEL);
  696. if (!pll)
  697. return ERR_PTR(-ENOMEM);
  698. init.name = clk_name;
  699. init.ops = pll_data->ops;
  700. init.flags = CLK_IS_BASIC | CLK_GET_RATE_NOCACHE;
  701. init.parent_names = &parent_name;
  702. init.num_parents = 1;
  703. pll->data = pll_data;
  704. pll->regs_base = reg;
  705. pll->hw.init = &init;
  706. pll->lock = lock;
  707. clk = clk_register(NULL, &pll->hw);
  708. if (IS_ERR(clk)) {
  709. kfree(pll);
  710. return clk;
  711. }
  712. pr_debug("%s: parent %s rate %lu\n",
  713. __clk_get_name(clk),
  714. __clk_get_name(clk_get_parent(clk)),
  715. clk_get_rate(clk));
  716. return clk;
  717. }
  718. static struct clk * __init clkgen_c65_lsdiv_register(const char *parent_name,
  719. const char *clk_name)
  720. {
  721. struct clk *clk;
  722. clk = clk_register_fixed_factor(NULL, clk_name, parent_name, 0, 1, 2);
  723. if (IS_ERR(clk))
  724. return clk;
  725. pr_debug("%s: parent %s rate %lu\n",
  726. __clk_get_name(clk),
  727. __clk_get_name(clk_get_parent(clk)),
  728. clk_get_rate(clk));
  729. return clk;
  730. }
  731. static void __iomem * __init clkgen_get_register_base(
  732. struct device_node *np)
  733. {
  734. struct device_node *pnode;
  735. void __iomem *reg = NULL;
  736. pnode = of_get_parent(np);
  737. if (!pnode)
  738. return NULL;
  739. reg = of_iomap(pnode, 0);
  740. of_node_put(pnode);
  741. return reg;
  742. }
  743. #define CLKGENAx_PLL0_OFFSET 0x0
  744. #define CLKGENAx_PLL1_OFFSET 0x4
  745. static void __init clkgena_c65_pll_setup(struct device_node *np)
  746. {
  747. const int num_pll_outputs = 3;
  748. struct clk_onecell_data *clk_data;
  749. const char *parent_name;
  750. void __iomem *reg;
  751. const char *clk_name;
  752. parent_name = of_clk_get_parent_name(np, 0);
  753. if (!parent_name)
  754. return;
  755. reg = clkgen_get_register_base(np);
  756. if (!reg)
  757. return;
  758. clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
  759. if (!clk_data)
  760. return;
  761. clk_data->clk_num = num_pll_outputs;
  762. clk_data->clks = kzalloc(clk_data->clk_num * sizeof(struct clk *),
  763. GFP_KERNEL);
  764. if (!clk_data->clks)
  765. goto err;
  766. if (of_property_read_string_index(np, "clock-output-names",
  767. 0, &clk_name))
  768. goto err;
  769. /*
  770. * PLL0 HS (high speed) output
  771. */
  772. clk_data->clks[0] = clkgen_pll_register(parent_name,
  773. (struct clkgen_pll_data *) &st_pll1600c65_ax,
  774. reg + CLKGENAx_PLL0_OFFSET, clk_name, NULL);
  775. if (IS_ERR(clk_data->clks[0]))
  776. goto err;
  777. if (of_property_read_string_index(np, "clock-output-names",
  778. 1, &clk_name))
  779. goto err;
  780. /*
  781. * PLL0 LS (low speed) output, which is a fixed divide by 2 of the
  782. * high speed output.
  783. */
  784. clk_data->clks[1] = clkgen_c65_lsdiv_register(__clk_get_name
  785. (clk_data->clks[0]),
  786. clk_name);
  787. if (IS_ERR(clk_data->clks[1]))
  788. goto err;
  789. if (of_property_read_string_index(np, "clock-output-names",
  790. 2, &clk_name))
  791. goto err;
  792. /*
  793. * PLL1 output
  794. */
  795. clk_data->clks[2] = clkgen_pll_register(parent_name,
  796. (struct clkgen_pll_data *) &st_pll800c65_ax,
  797. reg + CLKGENAx_PLL1_OFFSET, clk_name, NULL);
  798. if (IS_ERR(clk_data->clks[2]))
  799. goto err;
  800. of_clk_add_provider(np, of_clk_src_onecell_get, clk_data);
  801. return;
  802. err:
  803. kfree(clk_data->clks);
  804. kfree(clk_data);
  805. }
  806. CLK_OF_DECLARE(clkgena_c65_plls,
  807. "st,clkgena-plls-c65", clkgena_c65_pll_setup);
  808. static struct clk * __init clkgen_odf_register(const char *parent_name,
  809. void __iomem *reg,
  810. struct clkgen_pll_data *pll_data,
  811. int odf,
  812. spinlock_t *odf_lock,
  813. const char *odf_name)
  814. {
  815. struct clk *clk;
  816. unsigned long flags;
  817. struct clk_gate *gate;
  818. struct clk_divider *div;
  819. flags = CLK_GET_RATE_NOCACHE | CLK_SET_RATE_PARENT;
  820. gate = kzalloc(sizeof(*gate), GFP_KERNEL);
  821. if (!gate)
  822. return ERR_PTR(-ENOMEM);
  823. gate->flags = CLK_GATE_SET_TO_DISABLE;
  824. gate->reg = reg + pll_data->odf_gate[odf].offset;
  825. gate->bit_idx = pll_data->odf_gate[odf].shift;
  826. gate->lock = odf_lock;
  827. div = kzalloc(sizeof(*div), GFP_KERNEL);
  828. if (!div) {
  829. kfree(gate);
  830. return ERR_PTR(-ENOMEM);
  831. }
  832. div->flags = CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO;
  833. div->reg = reg + pll_data->odf[odf].offset;
  834. div->shift = pll_data->odf[odf].shift;
  835. div->width = fls(pll_data->odf[odf].mask);
  836. div->lock = odf_lock;
  837. clk = clk_register_composite(NULL, odf_name, &parent_name, 1,
  838. NULL, NULL,
  839. &div->hw, &clk_divider_ops,
  840. &gate->hw, &clk_gate_ops,
  841. flags);
  842. if (IS_ERR(clk))
  843. return clk;
  844. pr_debug("%s: parent %s rate %lu\n",
  845. __clk_get_name(clk),
  846. __clk_get_name(clk_get_parent(clk)),
  847. clk_get_rate(clk));
  848. return clk;
  849. }
  850. static const struct of_device_id c32_pll_of_match[] = {
  851. {
  852. .compatible = "st,plls-c32-a1x-0",
  853. .data = &st_pll3200c32_a1x_0,
  854. },
  855. {
  856. .compatible = "st,plls-c32-a1x-1",
  857. .data = &st_pll3200c32_a1x_1,
  858. },
  859. {
  860. .compatible = "st,stih415-plls-c32-a9",
  861. .data = &st_pll3200c32_a9_415,
  862. },
  863. {
  864. .compatible = "st,stih415-plls-c32-ddr",
  865. .data = &st_pll3200c32_ddr_415,
  866. },
  867. {
  868. .compatible = "st,stih416-plls-c32-a9",
  869. .data = &st_pll3200c32_a9_416,
  870. },
  871. {
  872. .compatible = "st,stih416-plls-c32-ddr",
  873. .data = &st_pll3200c32_ddr_416,
  874. },
  875. {
  876. .compatible = "st,stih407-plls-c32-a0",
  877. .data = &st_pll3200c32_407_a0,
  878. },
  879. {
  880. .compatible = "st,plls-c32-cx_0",
  881. .data = &st_pll3200c32_cx_0,
  882. },
  883. {
  884. .compatible = "st,plls-c32-cx_1",
  885. .data = &st_pll3200c32_cx_1,
  886. },
  887. {
  888. .compatible = "st,stih407-plls-c32-a9",
  889. .data = &st_pll3200c32_407_a9,
  890. },
  891. {
  892. .compatible = "st,stih418-plls-c28-a9",
  893. .data = &st_pll4600c28_418_a9,
  894. },
  895. {}
  896. };
  897. static void __init clkgen_c32_pll_setup(struct device_node *np)
  898. {
  899. const struct of_device_id *match;
  900. struct clk *clk;
  901. const char *parent_name, *pll_name;
  902. void __iomem *pll_base;
  903. int num_odfs, odf;
  904. struct clk_onecell_data *clk_data;
  905. struct clkgen_pll_data *data;
  906. match = of_match_node(c32_pll_of_match, np);
  907. if (!match) {
  908. pr_err("%s: No matching data\n", __func__);
  909. return;
  910. }
  911. data = (struct clkgen_pll_data *) match->data;
  912. parent_name = of_clk_get_parent_name(np, 0);
  913. if (!parent_name)
  914. return;
  915. pll_base = clkgen_get_register_base(np);
  916. if (!pll_base)
  917. return;
  918. clk = clkgen_pll_register(parent_name, data, pll_base, np->name,
  919. data->lock);
  920. if (IS_ERR(clk))
  921. return;
  922. pll_name = __clk_get_name(clk);
  923. num_odfs = data->num_odfs;
  924. clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
  925. if (!clk_data)
  926. return;
  927. clk_data->clk_num = num_odfs;
  928. clk_data->clks = kzalloc(clk_data->clk_num * sizeof(struct clk *),
  929. GFP_KERNEL);
  930. if (!clk_data->clks)
  931. goto err;
  932. for (odf = 0; odf < num_odfs; odf++) {
  933. struct clk *clk;
  934. const char *clk_name;
  935. if (of_property_read_string_index(np, "clock-output-names",
  936. odf, &clk_name))
  937. return;
  938. clk = clkgen_odf_register(pll_name, pll_base, data,
  939. odf, &clkgena_c32_odf_lock, clk_name);
  940. if (IS_ERR(clk))
  941. goto err;
  942. clk_data->clks[odf] = clk;
  943. }
  944. of_clk_add_provider(np, of_clk_src_onecell_get, clk_data);
  945. return;
  946. err:
  947. kfree(pll_name);
  948. kfree(clk_data->clks);
  949. kfree(clk_data);
  950. }
  951. CLK_OF_DECLARE(clkgen_c32_pll, "st,clkgen-plls-c32", clkgen_c32_pll_setup);
  952. static const struct of_device_id c32_gpu_pll_of_match[] = {
  953. {
  954. .compatible = "st,stih415-gpu-pll-c32",
  955. .data = &st_pll1200c32_gpu_415,
  956. },
  957. {
  958. .compatible = "st,stih416-gpu-pll-c32",
  959. .data = &st_pll1200c32_gpu_416,
  960. },
  961. {}
  962. };
  963. static void __init clkgengpu_c32_pll_setup(struct device_node *np)
  964. {
  965. const struct of_device_id *match;
  966. struct clk *clk;
  967. const char *parent_name;
  968. void __iomem *reg;
  969. const char *clk_name;
  970. struct clkgen_pll_data *data;
  971. match = of_match_node(c32_gpu_pll_of_match, np);
  972. if (!match) {
  973. pr_err("%s: No matching data\n", __func__);
  974. return;
  975. }
  976. data = (struct clkgen_pll_data *)match->data;
  977. parent_name = of_clk_get_parent_name(np, 0);
  978. if (!parent_name)
  979. return;
  980. reg = clkgen_get_register_base(np);
  981. if (!reg)
  982. return;
  983. if (of_property_read_string_index(np, "clock-output-names",
  984. 0, &clk_name))
  985. return;
  986. /*
  987. * PLL 1200MHz output
  988. */
  989. clk = clkgen_pll_register(parent_name, data, reg, clk_name, data->lock);
  990. if (!IS_ERR(clk))
  991. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  992. return;
  993. }
  994. CLK_OF_DECLARE(clkgengpu_c32_pll,
  995. "st,clkgengpu-pll-c32", clkgengpu_c32_pll_setup);