edp_pll_28hpm.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #define pr_fmt(fmt) "%s: " fmt, __func__
  6. #include <linux/kernel.h>
  7. #include <linux/err.h>
  8. #include <linux/delay.h>
  9. #include <linux/clk.h>
  10. #include <linux/iopoll.h>
  11. #include <linux/clk/msm-clk-provider.h>
  12. #include <linux/clk/msm-clk.h>
  13. #include <linux/clk/msm-clock-generic.h>
  14. #include <dt-bindings/clock/msm-clocks-8974.h>
  15. #include "pll_drv.h"
  16. #include "edp_pll.h"
  17. #define EDP_PHY_PLL_UNIPHY_PLL_REFCLK_CFG (0x0)
  18. #define EDP_PHY_PLL_UNIPHY_PLL_POSTDIV1_CFG (0x0004)
  19. #define EDP_PHY_PLL_UNIPHY_PLL_VCOLPF_CFG (0x000C)
  20. #define EDP_PHY_PLL_UNIPHY_PLL_GLB_CFG (0x0020)
  21. #define EDP_PHY_PLL_UNIPHY_PLL_POSTDIV2_CFG (0x0024)
  22. #define EDP_PHY_PLL_UNIPHY_PLL_POSTDIV3_CFG (0x0028)
  23. #define EDP_PHY_PLL_UNIPHY_PLL_SDM_CFG0 (0x0038)
  24. #define EDP_PHY_PLL_UNIPHY_PLL_SDM_CFG1 (0x003C)
  25. #define EDP_PHY_PLL_UNIPHY_PLL_SDM_CFG2 (0x0040)
  26. #define EDP_PHY_PLL_UNIPHY_PLL_SDM_CFG3 (0x0044)
  27. #define EDP_PHY_PLL_UNIPHY_PLL_SDM_CFG4 (0x0048)
  28. #define EDP_PHY_PLL_UNIPHY_PLL_SSC_CFG0 (0x004C)
  29. #define EDP_PHY_PLL_UNIPHY_PLL_SSC_CFG1 (0x0050)
  30. #define EDP_PHY_PLL_UNIPHY_PLL_SSC_CFG2 (0x0054)
  31. #define EDP_PHY_PLL_UNIPHY_PLL_SSC_CFG3 (0x0058)
  32. #define EDP_PHY_PLL_UNIPHY_PLL_LKDET_CFG2 (0x0064)
  33. #define EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG0 (0x006C)
  34. #define EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG2 (0x0074)
  35. #define EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG6 (0x0084)
  36. #define EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG7 (0x0088)
  37. #define EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG8 (0x008C)
  38. #define EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG9 (0x0090)
  39. #define EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG10 (0x0094)
  40. #define EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG11 (0x0098)
  41. #define EDP_PHY_PLL_UNIPHY_PLL_LKDET_CFG0 (0x005C)
  42. #define EDP_PHY_PLL_UNIPHY_PLL_LKDET_CFG1 (0x0060)
  43. #define EDP_PLL_POLL_DELAY_US 50
  44. #define EDP_PLL_POLL_TIMEOUT_US 500
  45. static const struct clk_ops edp_mainlink_clk_src_ops;
  46. static struct clk_div_ops fixed_5div_ops; /* null ops */
  47. static const struct clk_ops edp_pixel_clk_ops;
  48. static inline struct edp_pll_vco_clk *to_edp_vco_clk(struct clk *clk)
  49. {
  50. return container_of(clk, struct edp_pll_vco_clk, c);
  51. }
  52. int edp_div_prepare(struct clk *c)
  53. {
  54. struct div_clk *div = to_div_clk(c);
  55. /* Restore the divider's value */
  56. return div->ops->set_div(div, div->data.div);
  57. }
  58. static int edp_vco_set_rate(struct clk *c, unsigned long vco_rate)
  59. {
  60. struct edp_pll_vco_clk *vco = to_edp_vco_clk(c);
  61. struct mdss_pll_resources *edp_pll_res = vco->priv;
  62. int rc;
  63. pr_debug("vco_rate=%d\n", (int)vco_rate);
  64. rc = mdss_pll_resource_enable(edp_pll_res, true);
  65. if (rc) {
  66. pr_err("failed to enable edp pll res rc=%d\n", rc);
  67. rc = -EINVAL;
  68. }
  69. if (vco_rate == 810000000) {
  70. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  71. EDP_PHY_PLL_UNIPHY_PLL_VCOLPF_CFG, 0x18);
  72. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  73. EDP_PHY_PLL_UNIPHY_PLL_LKDET_CFG2, 0x0d);
  74. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  75. EDP_PHY_PLL_UNIPHY_PLL_REFCLK_CFG, 0x00);
  76. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  77. EDP_PHY_PLL_UNIPHY_PLL_SDM_CFG0, 0x36);
  78. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  79. EDP_PHY_PLL_UNIPHY_PLL_SDM_CFG1, 0x69);
  80. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  81. EDP_PHY_PLL_UNIPHY_PLL_SDM_CFG2, 0xff);
  82. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  83. EDP_PHY_PLL_UNIPHY_PLL_SDM_CFG3, 0x2f);
  84. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  85. EDP_PHY_PLL_UNIPHY_PLL_SDM_CFG4, 0x00);
  86. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  87. EDP_PHY_PLL_UNIPHY_PLL_SSC_CFG0, 0x80);
  88. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  89. EDP_PHY_PLL_UNIPHY_PLL_SSC_CFG1, 0x00);
  90. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  91. EDP_PHY_PLL_UNIPHY_PLL_SSC_CFG2, 0x00);
  92. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  93. EDP_PHY_PLL_UNIPHY_PLL_SSC_CFG3, 0x00);
  94. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  95. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG0, 0x12);
  96. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  97. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG2, 0x01);
  98. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  99. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG6, 0x5a);
  100. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  101. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG7, 0x0);
  102. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  103. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG8, 0x60);
  104. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  105. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG9, 0x0);
  106. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  107. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG10, 0x2a);
  108. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  109. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG11, 0x3);
  110. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  111. EDP_PHY_PLL_UNIPHY_PLL_LKDET_CFG0, 0x10);
  112. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  113. EDP_PHY_PLL_UNIPHY_PLL_LKDET_CFG1, 0x1a);
  114. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  115. EDP_PHY_PLL_UNIPHY_PLL_POSTDIV1_CFG, 0x00);
  116. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  117. EDP_PHY_PLL_UNIPHY_PLL_POSTDIV3_CFG, 0x00);
  118. } else if (vco_rate == 1350000000) {
  119. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  120. EDP_PHY_PLL_UNIPHY_PLL_LKDET_CFG2, 0x0d);
  121. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  122. EDP_PHY_PLL_UNIPHY_PLL_REFCLK_CFG, 0x01);
  123. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  124. EDP_PHY_PLL_UNIPHY_PLL_SDM_CFG0, 0x36);
  125. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  126. EDP_PHY_PLL_UNIPHY_PLL_SDM_CFG1, 0x62);
  127. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  128. EDP_PHY_PLL_UNIPHY_PLL_SDM_CFG2, 0x00);
  129. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  130. EDP_PHY_PLL_UNIPHY_PLL_SDM_CFG3, 0x28);
  131. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  132. EDP_PHY_PLL_UNIPHY_PLL_SDM_CFG4, 0x00);
  133. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  134. EDP_PHY_PLL_UNIPHY_PLL_SSC_CFG0, 0x80);
  135. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  136. EDP_PHY_PLL_UNIPHY_PLL_SSC_CFG1, 0x00);
  137. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  138. EDP_PHY_PLL_UNIPHY_PLL_SSC_CFG2, 0x00);
  139. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  140. EDP_PHY_PLL_UNIPHY_PLL_SSC_CFG3, 0x00);
  141. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  142. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG0, 0x12);
  143. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  144. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG2, 0x01);
  145. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  146. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG6, 0x5a);
  147. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  148. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG7, 0x0);
  149. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  150. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG8, 0x60);
  151. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  152. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG9, 0x0);
  153. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  154. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG10, 0x46);
  155. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  156. EDP_PHY_PLL_UNIPHY_PLL_CAL_CFG11, 0x5);
  157. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  158. EDP_PHY_PLL_UNIPHY_PLL_LKDET_CFG0, 0x10);
  159. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  160. EDP_PHY_PLL_UNIPHY_PLL_LKDET_CFG1, 0x1a);
  161. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  162. EDP_PHY_PLL_UNIPHY_PLL_POSTDIV1_CFG, 0x00);
  163. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  164. EDP_PHY_PLL_UNIPHY_PLL_POSTDIV3_CFG, 0x00);
  165. } else {
  166. pr_err("rate=%d is NOT supported\n", (int)vco_rate);
  167. vco_rate = 0;
  168. rc = -EINVAL;
  169. }
  170. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  171. EDP_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x01);
  172. udelay(100);
  173. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  174. EDP_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05);
  175. udelay(100);
  176. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  177. EDP_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x07);
  178. udelay(100);
  179. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  180. EDP_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f);
  181. udelay(100);
  182. mdss_pll_resource_enable(edp_pll_res, false);
  183. vco->rate = vco_rate;
  184. return rc;
  185. }
  186. static int edp_pll_ready_poll(struct mdss_pll_resources *edp_pll_res)
  187. {
  188. int cnt;
  189. u32 status;
  190. cnt = 100;
  191. while (cnt--) {
  192. udelay(100);
  193. status = MDSS_PLL_REG_R(edp_pll_res->pll_base, 0xc0);
  194. status &= 0x01;
  195. if (status)
  196. break;
  197. }
  198. pr_debug("cnt=%d status=%d\n", cnt, (int)status);
  199. if (status)
  200. return 1;
  201. return 0;
  202. }
  203. static int edp_vco_enable(struct clk *c)
  204. {
  205. int i, ready;
  206. int rc;
  207. struct edp_pll_vco_clk *vco = to_edp_vco_clk(c);
  208. struct mdss_pll_resources *edp_pll_res = vco->priv;
  209. rc = mdss_pll_resource_enable(edp_pll_res, true);
  210. if (rc) {
  211. pr_err("edp pll resources not available\n");
  212. return rc;
  213. }
  214. for (i = 0; i < 3; i++) {
  215. ready = edp_pll_ready_poll(edp_pll_res);
  216. if (ready)
  217. break;
  218. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  219. EDP_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x01);
  220. udelay(100);
  221. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  222. EDP_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05);
  223. udelay(100);
  224. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  225. EDP_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x07);
  226. udelay(100);
  227. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  228. EDP_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f);
  229. udelay(100);
  230. }
  231. if (ready) {
  232. pr_debug("EDP PLL lock success\n");
  233. edp_pll_res->pll_on = true;
  234. rc = 0;
  235. } else {
  236. pr_err("EDP PLL failed to lock\n");
  237. mdss_pll_resource_enable(edp_pll_res, false);
  238. rc = -EINVAL;
  239. }
  240. return rc;
  241. }
  242. static void edp_vco_disable(struct clk *c)
  243. {
  244. struct edp_pll_vco_clk *vco = to_edp_vco_clk(c);
  245. struct mdss_pll_resources *edp_pll_res = vco->priv;
  246. if (!edp_pll_res) {
  247. pr_err("Invalid input parameter\n");
  248. return;
  249. }
  250. if (!edp_pll_res->pll_on &&
  251. mdss_pll_resource_enable(edp_pll_res, true)) {
  252. pr_err("edp pll resources not available\n");
  253. return;
  254. }
  255. MDSS_PLL_REG_W(edp_pll_res->pll_base, 0x20, 0x00);
  256. edp_pll_res->handoff_resources = false;
  257. edp_pll_res->pll_on = false;
  258. mdss_pll_resource_enable(edp_pll_res, false);
  259. pr_debug("EDP PLL Disabled\n");
  260. }
  261. static unsigned long edp_vco_get_rate(struct clk *c)
  262. {
  263. struct edp_pll_vco_clk *vco = to_edp_vco_clk(c);
  264. struct mdss_pll_resources *edp_pll_res = vco->priv;
  265. u32 pll_status, div2;
  266. int rc;
  267. if (is_gdsc_disabled(edp_pll_res))
  268. return 0;
  269. rc = mdss_pll_resource_enable(edp_pll_res, true);
  270. if (rc) {
  271. pr_err("edp pll resources not available\n");
  272. return rc;
  273. }
  274. if (vco->rate == 0) {
  275. pll_status = MDSS_PLL_REG_R(edp_pll_res->pll_base, 0xc0);
  276. if (pll_status & 0x01) {
  277. div2 = MDSS_PLL_REG_R(edp_pll_res->pll_base, 0x24);
  278. if (div2 & 0x01)
  279. vco->rate = 1350000000;
  280. else
  281. vco->rate = 810000000;
  282. }
  283. }
  284. mdss_pll_resource_enable(edp_pll_res, false);
  285. pr_debug("rate=%d\n", (int)vco->rate);
  286. return vco->rate;
  287. }
  288. static long edp_vco_round_rate(struct clk *c, unsigned long rate)
  289. {
  290. struct edp_pll_vco_clk *vco = to_edp_vco_clk(c);
  291. unsigned long rrate = -ENOENT;
  292. unsigned long *lp;
  293. lp = vco->rate_list;
  294. while (*lp) {
  295. rrate = *lp;
  296. if (rate <= rrate)
  297. break;
  298. lp++;
  299. }
  300. pr_debug("rrate=%d\n", (int)rrate);
  301. return rrate;
  302. }
  303. static int edp_vco_prepare(struct clk *c)
  304. {
  305. struct edp_pll_vco_clk *vco = to_edp_vco_clk(c);
  306. pr_debug("rate=%d\n", (int)vco->rate);
  307. return edp_vco_set_rate(c, vco->rate);
  308. }
  309. static void edp_vco_unprepare(struct clk *c)
  310. {
  311. struct edp_pll_vco_clk *vco = to_edp_vco_clk(c);
  312. pr_debug("rate=%d\n", (int)vco->rate);
  313. edp_vco_disable(c);
  314. }
  315. static int edp_pll_lock_status(struct mdss_pll_resources *edp_pll_res)
  316. {
  317. u32 status;
  318. int pll_locked = 0;
  319. int rc;
  320. rc = mdss_pll_resource_enable(edp_pll_res, true);
  321. if (rc) {
  322. pr_err("edp pll resources not available\n");
  323. return rc;
  324. }
  325. /* poll for PLL ready status */
  326. if (readl_poll_timeout_atomic((edp_pll_res->pll_base + 0xc0),
  327. status, ((status & BIT(0)) == 1),
  328. EDP_PLL_POLL_DELAY_US,
  329. EDP_PLL_POLL_TIMEOUT_US)) {
  330. pr_debug("EDP PLL status=%x failed to Lock\n", status);
  331. pll_locked = 0;
  332. } else {
  333. pll_locked = 1;
  334. }
  335. mdss_pll_resource_enable(edp_pll_res, false);
  336. return pll_locked;
  337. }
  338. static enum handoff edp_vco_handoff(struct clk *c)
  339. {
  340. enum handoff ret = HANDOFF_DISABLED_CLK;
  341. struct edp_pll_vco_clk *vco = to_edp_vco_clk(c);
  342. struct mdss_pll_resources *edp_pll_res = vco->priv;
  343. if (is_gdsc_disabled(edp_pll_res))
  344. return HANDOFF_DISABLED_CLK;
  345. if (mdss_pll_resource_enable(edp_pll_res, true)) {
  346. pr_err("edp pll resources not available\n");
  347. return ret;
  348. }
  349. edp_pll_res->handoff_resources = true;
  350. if (edp_pll_lock_status(edp_pll_res)) {
  351. c->rate = edp_vco_get_rate(c);
  352. edp_pll_res->pll_on = true;
  353. ret = HANDOFF_ENABLED_CLK;
  354. } else {
  355. edp_pll_res->handoff_resources = false;
  356. mdss_pll_resource_enable(edp_pll_res, false);
  357. }
  358. pr_debug("done, ret=%d\n", ret);
  359. return ret;
  360. }
  361. static unsigned long edp_vco_rate_list[] = {
  362. 810000000, 1350000000, 0};
  363. struct const clk_ops edp_vco_clk_ops = {
  364. .enable = edp_vco_enable,
  365. .set_rate = edp_vco_set_rate,
  366. .get_rate = edp_vco_get_rate,
  367. .round_rate = edp_vco_round_rate,
  368. .prepare = edp_vco_prepare,
  369. .unprepare = edp_vco_unprepare,
  370. .handoff = edp_vco_handoff,
  371. };
  372. struct edp_pll_vco_clk edp_vco_clk = {
  373. .ref_clk_rate = 19200000,
  374. .rate = 0,
  375. .rate_list = edp_vco_rate_list,
  376. .c = {
  377. .dbg_name = "edp_vco_clk",
  378. .ops = &edp_vco_clk_ops,
  379. CLK_INIT(edp_vco_clk.c),
  380. },
  381. };
  382. static unsigned long edp_mainlink_get_rate(struct clk *c)
  383. {
  384. struct div_clk *mclk = to_div_clk(c);
  385. struct clk *pclk;
  386. unsigned long rate = 0;
  387. pclk = clk_get_parent(c);
  388. if (pclk && pclk->ops->get_rate) {
  389. rate = pclk->ops->get_rate(pclk);
  390. rate /= mclk->data.div;
  391. }
  392. pr_debug("rate=%d div=%d\n", (int)rate, mclk->data.div);
  393. return rate;
  394. }
  395. struct div_clk edp_mainlink_clk_src = {
  396. .ops = &fixed_5div_ops,
  397. .data = {
  398. .div = 5,
  399. .min_div = 5,
  400. .max_div = 5,
  401. },
  402. .c = {
  403. .parent = &edp_vco_clk.c,
  404. .dbg_name = "edp_mainlink_clk_src",
  405. .ops = &edp_mainlink_clk_src_ops,
  406. .flags = CLKFLAG_NO_RATE_CACHE,
  407. CLK_INIT(edp_mainlink_clk_src.c),
  408. }
  409. };
  410. /*
  411. * this rate is from pll to clock controller
  412. * output from pll to CC has two possibilities
  413. * 1: if mainlink rate is 270M, then 675M
  414. * 2: if mainlink rate is 162M, then 810M
  415. */
  416. static int edp_pixel_set_div(struct div_clk *clk, int div)
  417. {
  418. int rc;
  419. struct mdss_pll_resources *edp_pll_res = clk->priv;
  420. rc = mdss_pll_resource_enable(edp_pll_res, true);
  421. if (rc) {
  422. pr_err("edp pll resources not available\n");
  423. return rc;
  424. }
  425. pr_debug("div=%d\n", div);
  426. MDSS_PLL_REG_W(edp_pll_res->pll_base,
  427. EDP_PHY_PLL_UNIPHY_PLL_POSTDIV2_CFG, (div - 1));
  428. mdss_pll_resource_enable(edp_pll_res, false);
  429. return 0;
  430. }
  431. static int edp_pixel_get_div(struct div_clk *clk)
  432. {
  433. int div = 0;
  434. int rc;
  435. struct mdss_pll_resources *edp_pll_res = clk->priv;
  436. if (is_gdsc_disabled(edp_pll_res))
  437. return 0;
  438. rc = mdss_pll_resource_enable(edp_pll_res, true);
  439. if (rc) {
  440. pr_err("edp pll resources not available\n");
  441. return rc;
  442. }
  443. div = MDSS_PLL_REG_R(edp_pll_res->pll_base,
  444. EDP_PHY_PLL_UNIPHY_PLL_POSTDIV2_CFG);
  445. mdss_pll_resource_enable(edp_pll_res, false);
  446. div &= 0x01;
  447. pr_debug("div=%d\n", div);
  448. return div + 1;
  449. }
  450. static struct clk_div_ops edp_pixel_ops = {
  451. .set_div = edp_pixel_set_div,
  452. .get_div = edp_pixel_get_div,
  453. };
  454. struct div_clk edp_pixel_clk_src = {
  455. .data = {
  456. .max_div = 2,
  457. .min_div = 1,
  458. },
  459. .ops = &edp_pixel_ops,
  460. .c = {
  461. .parent = &edp_vco_clk.c,
  462. .dbg_name = "edp_pixel_clk_src",
  463. .ops = &edp_pixel_clk_ops,
  464. .flags = CLKFLAG_NO_RATE_CACHE,
  465. CLK_INIT(edp_pixel_clk_src.c),
  466. },
  467. };
  468. static struct clk_lookup mdss_edp_pllcc_8974[] = {
  469. CLK_LOOKUP("edp_pixel_src", edp_pixel_clk_src.c,
  470. "fd8c0000.qcom,mmsscc-mdss"),
  471. CLK_LOOKUP("edp_mainlink_src", edp_mainlink_clk_src.c,
  472. "fd8c0000.qcom,mmsscc-mdss"),
  473. };
  474. int edp_pll_clock_register(struct platform_device *pdev,
  475. struct mdss_pll_resources *pll_res)
  476. {
  477. int rc = -ENOTSUPP;
  478. /* Set client data to div and vco clocks */
  479. edp_pixel_clk_src.priv = pll_res;
  480. edp_mainlink_clk_src.priv = pll_res;
  481. edp_vco_clk.priv = pll_res;
  482. /* Set clock operation for mainlink and pixel clock */
  483. edp_mainlink_clk_src_ops = clk_ops_div;
  484. edp_mainlink_clk_src_ops.get_parent = clk_get_parent;
  485. edp_mainlink_clk_src_ops.get_rate = edp_mainlink_get_rate;
  486. edp_pixel_clk_ops = clk_ops_slave_div;
  487. edp_pixel_clk_ops.prepare = edp_div_prepare;
  488. rc = of_msm_clock_register(pdev->dev.of_node, mdss_edp_pllcc_8974,
  489. ARRAY_SIZE(mdss_edp_pllcc_8974));
  490. if (rc) {
  491. pr_err("Clock register failed rc=%d\n", rc);
  492. rc = -EPROBE_DEFER;
  493. }
  494. return rc;
  495. }