dsi_phy_hw_v5_0.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/math64.h>
  7. #include <linux/delay.h>
  8. #include <linux/iopoll.h>
  9. #include "dsi_hw.h"
  10. #include "dsi_defs.h"
  11. #include "dsi_phy_hw.h"
  12. #include "dsi_catalog.h"
  13. #define DSIPHY_CMN_REVISION_ID0 0x000
  14. #define DSIPHY_CMN_REVISION_ID1 0x004
  15. #define DSIPHY_CMN_REVISION_ID2 0x008
  16. #define DSIPHY_CMN_REVISION_ID3 0x00C
  17. #define DSIPHY_CMN_CLK_CFG0 0x010
  18. #define DSIPHY_CMN_CLK_CFG1 0x014
  19. #define DSIPHY_CMN_GLBL_CTRL 0x018
  20. #define DSIPHY_CMN_RBUF_CTRL 0x01C
  21. #define DSIPHY_CMN_VREG_CTRL_0 0x020
  22. #define DSIPHY_CMN_CTRL_0 0x024
  23. #define DSIPHY_CMN_CTRL_1 0x028
  24. #define DSIPHY_CMN_CTRL_2 0x02C
  25. #define DSIPHY_CMN_CTRL_3 0x030
  26. #define DSIPHY_CMN_LANE_CFG0 0x034
  27. #define DSIPHY_CMN_LANE_CFG1 0x038
  28. #define DSIPHY_CMN_PLL_CNTRL 0x03C
  29. #define DSIPHY_CMN_DPHY_SOT 0x040
  30. #define DSIPHY_CMN_LANE_CTRL0 0x0A0
  31. #define DSIPHY_CMN_LANE_CTRL1 0x0A4
  32. #define DSIPHY_CMN_LANE_CTRL2 0x0A8
  33. #define DSIPHY_CMN_LANE_CTRL3 0x0AC
  34. #define DSIPHY_CMN_LANE_CTRL4 0x0B0
  35. #define DSIPHY_CMN_TIMING_CTRL_0 0x0B4
  36. #define DSIPHY_CMN_TIMING_CTRL_1 0x0B8
  37. #define DSIPHY_CMN_TIMING_CTRL_2 0x0Bc
  38. #define DSIPHY_CMN_TIMING_CTRL_3 0x0C0
  39. #define DSIPHY_CMN_TIMING_CTRL_4 0x0C4
  40. #define DSIPHY_CMN_TIMING_CTRL_5 0x0C8
  41. #define DSIPHY_CMN_TIMING_CTRL_6 0x0CC
  42. #define DSIPHY_CMN_TIMING_CTRL_7 0x0D0
  43. #define DSIPHY_CMN_TIMING_CTRL_8 0x0D4
  44. #define DSIPHY_CMN_TIMING_CTRL_9 0x0D8
  45. #define DSIPHY_CMN_TIMING_CTRL_10 0x0DC
  46. #define DSIPHY_CMN_TIMING_CTRL_11 0x0E0
  47. #define DSIPHY_CMN_TIMING_CTRL_12 0x0E4
  48. #define DSIPHY_CMN_TIMING_CTRL_13 0x0E8
  49. #define DSIPHY_CMN_GLBL_HSTX_STR_CTRL_0 0x0EC
  50. #define DSIPHY_CMN_GLBL_HSTX_STR_CTRL_1 0x0F0
  51. #define DSIPHY_CMN_GLBL_RESCODE_OFFSET_TOP_CTRL 0x0F4
  52. #define DSIPHY_CMN_GLBL_RESCODE_OFFSET_BOT_CTRL 0x0F8
  53. #define DSIPHY_CMN_GLBL_RESCODE_OFFSET_MID_CTRL 0x0FC
  54. #define DSIPHY_CMN_GLBL_LPTX_STR_CTRL 0x100
  55. #define DSIPHY_CMN_GLBL_PEMPH_CTRL_0 0x104
  56. #define DSIPHY_CMN_GLBL_PEMPH_CTRL_1 0x108
  57. #define DSIPHY_CMN_GLBL_STR_SWI_CAL_SEL_CTRL 0x10C
  58. #define DSIPHY_CMN_VREG_CTRL_1 0x110
  59. #define DSIPHY_CMN_CTRL_4 0x114
  60. #define DSIPHY_CMN_PHY_STATUS 0x140
  61. #define DSIPHY_CMN_LANE_STATUS0 0x148
  62. #define DSIPHY_CMN_LANE_STATUS1 0x14C
  63. #define DSIPHY_CMN_GLBL_DIGTOP_SPARE10 0x1AC
  64. #define DSIPHY_CMN_SL_DSI_LANE_CTRL1 0x1B4
  65. /* n = 0..3 for data lanes and n = 4 for clock lane */
  66. #define DSIPHY_LNX_CFG0(n) (0x200 + (0x80 * (n)))
  67. #define DSIPHY_LNX_CFG1(n) (0x204 + (0x80 * (n)))
  68. #define DSIPHY_LNX_CFG2(n) (0x208 + (0x80 * (n)))
  69. #define DSIPHY_LNX_TEST_DATAPATH(n) (0x20C + (0x80 * (n)))
  70. #define DSIPHY_LNX_PIN_SWAP(n) (0x210 + (0x80 * (n)))
  71. #define DSIPHY_LNX_LPRX_CTRL(n) (0x214 + (0x80 * (n)))
  72. #define DSIPHY_LNX_TX_DCTRL(n) (0x218 + (0x80 * (n)))
  73. /* dynamic refresh control registers */
  74. #define DSI_DYN_REFRESH_CTRL (0x000)
  75. #define DSI_DYN_REFRESH_PIPE_DELAY (0x004)
  76. #define DSI_DYN_REFRESH_PIPE_DELAY2 (0x008)
  77. #define DSI_DYN_REFRESH_PLL_DELAY (0x00C)
  78. #define DSI_DYN_REFRESH_STATUS (0x010)
  79. #define DSI_DYN_REFRESH_PLL_CTRL0 (0x014)
  80. #define DSI_DYN_REFRESH_PLL_CTRL1 (0x018)
  81. #define DSI_DYN_REFRESH_PLL_CTRL2 (0x01C)
  82. #define DSI_DYN_REFRESH_PLL_CTRL3 (0x020)
  83. #define DSI_DYN_REFRESH_PLL_CTRL4 (0x024)
  84. #define DSI_DYN_REFRESH_PLL_CTRL5 (0x028)
  85. #define DSI_DYN_REFRESH_PLL_CTRL6 (0x02C)
  86. #define DSI_DYN_REFRESH_PLL_CTRL7 (0x030)
  87. #define DSI_DYN_REFRESH_PLL_CTRL8 (0x034)
  88. #define DSI_DYN_REFRESH_PLL_CTRL9 (0x038)
  89. #define DSI_DYN_REFRESH_PLL_CTRL10 (0x03C)
  90. #define DSI_DYN_REFRESH_PLL_CTRL11 (0x040)
  91. #define DSI_DYN_REFRESH_PLL_CTRL12 (0x044)
  92. #define DSI_DYN_REFRESH_PLL_CTRL13 (0x048)
  93. #define DSI_DYN_REFRESH_PLL_CTRL14 (0x04C)
  94. #define DSI_DYN_REFRESH_PLL_CTRL15 (0x050)
  95. #define DSI_DYN_REFRESH_PLL_CTRL16 (0x054)
  96. #define DSI_DYN_REFRESH_PLL_CTRL17 (0x058)
  97. #define DSI_DYN_REFRESH_PLL_CTRL18 (0x05C)
  98. #define DSI_DYN_REFRESH_PLL_CTRL19 (0x060)
  99. #define DSI_DYN_REFRESH_PLL_CTRL20 (0x064)
  100. #define DSI_DYN_REFRESH_PLL_CTRL21 (0x068)
  101. #define DSI_DYN_REFRESH_PLL_CTRL22 (0x06C)
  102. #define DSI_DYN_REFRESH_PLL_CTRL23 (0x070)
  103. #define DSI_DYN_REFRESH_PLL_CTRL24 (0x074)
  104. #define DSI_DYN_REFRESH_PLL_CTRL25 (0x078)
  105. #define DSI_DYN_REFRESH_PLL_CTRL26 (0x07C)
  106. #define DSI_DYN_REFRESH_PLL_CTRL27 (0x080)
  107. #define DSI_DYN_REFRESH_PLL_CTRL28 (0x084)
  108. #define DSI_DYN_REFRESH_PLL_CTRL29 (0x088)
  109. #define DSI_DYN_REFRESH_PLL_CTRL30 (0x08C)
  110. #define DSI_DYN_REFRESH_PLL_CTRL31 (0x090)
  111. #define DSI_DYN_REFRESH_PLL_UPPER_ADDR (0x094)
  112. #define DSI_DYN_REFRESH_PLL_UPPER_ADDR2 (0x098)
  113. static int dsi_phy_hw_v5_0_is_pll_on(struct dsi_phy_hw *phy)
  114. {
  115. u32 data = 0;
  116. if (phy->phy_pll_bypass)
  117. return 0;
  118. data = DSI_R32(phy, DSIPHY_CMN_PLL_CNTRL);
  119. mb(); /*make sure read happened */
  120. return (data & BIT(0));
  121. }
  122. static bool dsi_phy_hw_v5_0_is_split_link_enabled(struct dsi_phy_hw *phy)
  123. {
  124. u32 reg = 0;
  125. reg = DSI_R32(phy, DSIPHY_CMN_GLBL_CTRL);
  126. mb(); /*make sure read happened */
  127. return (reg & BIT(5));
  128. }
  129. static void dsi_phy_hw_v5_0_config_lpcdrx(struct dsi_phy_hw *phy,
  130. struct dsi_phy_cfg *cfg, bool enable)
  131. {
  132. int phy_lane_0 = dsi_phy_conv_logical_to_phy_lane(&cfg->lane_map, DSI_LOGICAL_LANE_0);
  133. /*
  134. * LPRX and CDRX need to enabled only for physical data lane
  135. * corresponding to the logical data lane 0
  136. */
  137. if (enable)
  138. DSI_W32(phy, DSIPHY_LNX_LPRX_CTRL(phy_lane_0), cfg->strength.lane[phy_lane_0][1]);
  139. else
  140. DSI_W32(phy, DSIPHY_LNX_LPRX_CTRL(phy_lane_0), 0);
  141. }
  142. static void dsi_phy_hw_v5_0_lane_swap_config(struct dsi_phy_hw *phy,
  143. struct dsi_lane_map *lane_map)
  144. {
  145. DSI_W32(phy, DSIPHY_CMN_LANE_CFG0,
  146. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_0] |
  147. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_1] << 4)));
  148. DSI_W32(phy, DSIPHY_CMN_LANE_CFG1,
  149. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_2] |
  150. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_3] << 4)));
  151. }
  152. static void dsi_phy_hw_v5_0_lane_settings(struct dsi_phy_hw *phy,
  153. struct dsi_phy_cfg *cfg)
  154. {
  155. int i;
  156. u8 tx_dctrl[] = {0x40, 0x40, 0x40, 0x46, 0x41};
  157. bool split_link_enabled;
  158. u32 lanes_per_sublink;
  159. split_link_enabled = cfg->split_link.enabled;
  160. lanes_per_sublink = cfg->split_link.lanes_per_sublink;
  161. /* Strength ctrl settings */
  162. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++) {
  163. /*
  164. * Disable LPRX and CDRX for all lanes. And later on, it will
  165. * be only enabled for the physical data lane corresponding
  166. * to the logical data lane 0
  167. */
  168. DSI_W32(phy, DSIPHY_LNX_LPRX_CTRL(i), 0);
  169. DSI_W32(phy, DSIPHY_LNX_PIN_SWAP(i), 0x0);
  170. }
  171. dsi_phy_hw_v5_0_config_lpcdrx(phy, cfg, true);
  172. /* other settings */
  173. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++) {
  174. DSI_W32(phy, DSIPHY_LNX_CFG0(i), cfg->lanecfg.lane[i][0]);
  175. DSI_W32(phy, DSIPHY_LNX_CFG1(i), cfg->lanecfg.lane[i][1]);
  176. DSI_W32(phy, DSIPHY_LNX_CFG2(i), cfg->lanecfg.lane[i][2]);
  177. DSI_W32(phy, DSIPHY_LNX_TX_DCTRL(i), tx_dctrl[i]);
  178. }
  179. /* remove below check if cphy splitlink is enabled */
  180. if (split_link_enabled && (cfg->phy_type == DSI_PHY_TYPE_CPHY))
  181. return;
  182. /* Configure the splitlink clock lane with clk lane settings */
  183. if (split_link_enabled) {
  184. DSI_W32(phy, DSIPHY_LNX_LPRX_CTRL(5), 0x0);
  185. DSI_W32(phy, DSIPHY_LNX_PIN_SWAP(5), 0x0);
  186. DSI_W32(phy, DSIPHY_LNX_CFG0(5), cfg->lanecfg.lane[4][0]);
  187. DSI_W32(phy, DSIPHY_LNX_CFG1(5), cfg->lanecfg.lane[4][1]);
  188. DSI_W32(phy, DSIPHY_LNX_CFG2(5), cfg->lanecfg.lane[4][2]);
  189. DSI_W32(phy, DSIPHY_LNX_TX_DCTRL(5), tx_dctrl[4]);
  190. }
  191. }
  192. void dsi_phy_hw_v5_0_commit_phy_timing(struct dsi_phy_hw *phy,
  193. struct dsi_phy_per_lane_cfgs *timing)
  194. {
  195. /* Commit DSI PHY timings */
  196. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_0, timing->lane_v4[0]);
  197. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_1, timing->lane_v4[1]);
  198. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_2, timing->lane_v4[2]);
  199. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_3, timing->lane_v4[3]);
  200. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_4, timing->lane_v4[4]);
  201. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_5, timing->lane_v4[5]);
  202. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_6, timing->lane_v4[6]);
  203. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_7, timing->lane_v4[7]);
  204. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_8, timing->lane_v4[8]);
  205. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_9, timing->lane_v4[9]);
  206. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_10, timing->lane_v4[10]);
  207. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_11, timing->lane_v4[11]);
  208. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_12, timing->lane_v4[12]);
  209. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_13, timing->lane_v4[13]);
  210. }
  211. /**
  212. * cphy_enable() - Enable CPHY hardware
  213. * @phy: Pointer to DSI PHY hardware object.
  214. * @cfg: Per lane configurations for timing, strength and lane
  215. * configurations.
  216. */
  217. static void dsi_phy_hw_cphy_enable(struct dsi_phy_hw *phy, struct dsi_phy_cfg *cfg)
  218. {
  219. struct dsi_phy_per_lane_cfgs *timing = &cfg->timing;
  220. u32 data;
  221. /* For C-PHY, no low power settings for lower clk rate */
  222. u32 glbl_str_swi_cal_sel_ctrl = 0;
  223. u32 glbl_hstx_str_ctrl_0 = 0;
  224. /* de-assert digital and pll power down */
  225. data = BIT(6) | BIT(5);
  226. DSI_W32(phy, DSIPHY_CMN_CTRL_0, data);
  227. /* Assert PLL core reset */
  228. DSI_W32(phy, DSIPHY_CMN_PLL_CNTRL, 0x00);
  229. /* turn off resync FIFO */
  230. DSI_W32(phy, DSIPHY_CMN_RBUF_CTRL, 0x00);
  231. /* program CMN_CTRL_4 for minor_ver greater than 2 chipsets*/
  232. DSI_W32(phy, DSIPHY_CMN_CTRL_4, 0x04);
  233. /* Configure PHY lane swap */
  234. dsi_phy_hw_v5_0_lane_swap_config(phy, &cfg->lane_map);
  235. DSI_W32(phy, DSIPHY_CMN_GLBL_CTRL, BIT(6));
  236. /* Enable LDO */
  237. DSI_W32(phy, DSIPHY_CMN_VREG_CTRL_0, 0x45);
  238. DSI_W32(phy, DSIPHY_CMN_VREG_CTRL_1, 0x41);
  239. DSI_W32(phy, DSIPHY_CMN_GLBL_STR_SWI_CAL_SEL_CTRL, glbl_str_swi_cal_sel_ctrl);
  240. DSI_W32(phy, DSIPHY_CMN_GLBL_HSTX_STR_CTRL_0, glbl_hstx_str_ctrl_0);
  241. DSI_W32(phy, DSIPHY_CMN_GLBL_PEMPH_CTRL_0, 0x11);
  242. DSI_W32(phy, DSIPHY_CMN_GLBL_PEMPH_CTRL_1, 0x01);
  243. DSI_W32(phy, DSIPHY_CMN_GLBL_RESCODE_OFFSET_TOP_CTRL, 0x00);
  244. DSI_W32(phy, DSIPHY_CMN_GLBL_RESCODE_OFFSET_BOT_CTRL, 0x00);
  245. DSI_W32(phy, DSIPHY_CMN_GLBL_LPTX_STR_CTRL, 0x55);
  246. /* Remove power down from all blocks */
  247. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0x7f);
  248. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL0, 0x17);
  249. switch (cfg->pll_source) {
  250. case DSI_PLL_SOURCE_STANDALONE:
  251. case DSI_PLL_SOURCE_NATIVE:
  252. data = 0x0; /* internal PLL */
  253. break;
  254. case DSI_PLL_SOURCE_NON_NATIVE:
  255. data = 0x1; /* external PLL */
  256. break;
  257. default:
  258. break;
  259. }
  260. DSI_W32(phy, DSIPHY_CMN_CLK_CFG1, (data << 2)); /* set PLL src */
  261. /* DSI PHY timings */
  262. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_0, timing->lane_v4[0]);
  263. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_4, timing->lane_v4[4]);
  264. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_5, timing->lane_v4[5]);
  265. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_6, timing->lane_v4[6]);
  266. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_7, timing->lane_v4[7]);
  267. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_8, timing->lane_v4[8]);
  268. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_9, timing->lane_v4[9]);
  269. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_10, timing->lane_v4[10]);
  270. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_11, timing->lane_v4[11]);
  271. /* DSI lane settings */
  272. dsi_phy_hw_v5_0_lane_settings(phy, cfg);
  273. DSI_PHY_DBG(phy, "C-Phy enabled\n");
  274. }
  275. /**
  276. * dphy_enable() - Enable DPHY hardware
  277. * @phy: Pointer to DSI PHY hardware object.
  278. * @cfg: Per lane configurations for timing, strength and lane
  279. * configurations.
  280. */
  281. static void dsi_phy_hw_dphy_enable(struct dsi_phy_hw *phy, struct dsi_phy_cfg *cfg)
  282. {
  283. struct dsi_phy_per_lane_cfgs *timing = &cfg->timing;
  284. u32 data;
  285. bool less_than_1500_mhz = false;
  286. u32 vreg_ctrl_0 = 0;
  287. u32 glbl_str_swi_cal_sel_ctrl = 0;
  288. u32 glbl_hstx_str_ctrl_0 = 0;
  289. u32 glbl_rescode_top_ctrl = 0;
  290. u32 glbl_rescode_bot_ctrl = 0;
  291. bool split_link_enabled;
  292. u32 lanes_per_sublink;
  293. /* Alter PHY configurations if data rate less than 1.5GHZ*/
  294. if (cfg->bit_clk_rate_hz <= 1500000000)
  295. less_than_1500_mhz = true;
  296. vreg_ctrl_0 = 0x44;
  297. glbl_rescode_top_ctrl = less_than_1500_mhz ? 0x3c : 0x03;
  298. glbl_rescode_bot_ctrl = less_than_1500_mhz ? 0x38 : 0x3c;
  299. glbl_str_swi_cal_sel_ctrl = 0x00;
  300. glbl_hstx_str_ctrl_0 = 0x88;
  301. split_link_enabled = cfg->split_link.enabled;
  302. lanes_per_sublink = cfg->split_link.lanes_per_sublink;
  303. /* de-assert digital and pll power down */
  304. data = BIT(6) | BIT(5);
  305. DSI_W32(phy, DSIPHY_CMN_CTRL_0, data);
  306. if (split_link_enabled) {
  307. data = DSI_R32(phy, DSIPHY_CMN_GLBL_CTRL);
  308. /* set SPLIT_LINK_ENABLE in global control */
  309. DSI_W32(phy, DSIPHY_CMN_GLBL_CTRL, (data | BIT(5)));
  310. }
  311. /* Assert PLL core reset */
  312. DSI_W32(phy, DSIPHY_CMN_PLL_CNTRL, 0x00);
  313. /* turn off resync FIFO */
  314. DSI_W32(phy, DSIPHY_CMN_RBUF_CTRL, 0x00);
  315. /* program CMN_CTRL_4 for minor_ver greater than 2 chipsets*/
  316. DSI_W32(phy, DSIPHY_CMN_CTRL_4, 0x04);
  317. /* Configure PHY lane swap */
  318. dsi_phy_hw_v5_0_lane_swap_config(phy, &cfg->lane_map);
  319. /* Enable LDO */
  320. DSI_W32(phy, DSIPHY_CMN_VREG_CTRL_0, vreg_ctrl_0);
  321. DSI_W32(phy, DSIPHY_CMN_VREG_CTRL_1, 0x19);
  322. DSI_W32(phy, DSIPHY_CMN_CTRL_3, 0x00);
  323. DSI_W32(phy, DSIPHY_CMN_GLBL_STR_SWI_CAL_SEL_CTRL,
  324. glbl_str_swi_cal_sel_ctrl);
  325. DSI_W32(phy, DSIPHY_CMN_GLBL_HSTX_STR_CTRL_0, glbl_hstx_str_ctrl_0);
  326. DSI_W32(phy, DSIPHY_CMN_GLBL_PEMPH_CTRL_0, 0x00);
  327. DSI_W32(phy, DSIPHY_CMN_GLBL_RESCODE_OFFSET_TOP_CTRL,
  328. glbl_rescode_top_ctrl);
  329. DSI_W32(phy, DSIPHY_CMN_GLBL_RESCODE_OFFSET_BOT_CTRL,
  330. glbl_rescode_bot_ctrl);
  331. DSI_W32(phy, DSIPHY_CMN_GLBL_LPTX_STR_CTRL, 0x55);
  332. if (split_link_enabled) {
  333. if (lanes_per_sublink == 1) {
  334. /* remove Lane1 and Lane3 configs */
  335. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0xed);
  336. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL0, 0x35);
  337. } else {
  338. /* enable all together with sublink clock */
  339. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0xff);
  340. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL0, 0x3F);
  341. }
  342. DSI_W32(phy, DSIPHY_CMN_SL_DSI_LANE_CTRL1, 0x03);
  343. } else {
  344. /* Remove power down from all blocks */
  345. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0x7f);
  346. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL0, 0x1F);
  347. }
  348. /* Select full-rate mode */
  349. DSI_W32(phy, DSIPHY_CMN_CTRL_2, 0x40);
  350. switch (cfg->pll_source) {
  351. case DSI_PLL_SOURCE_STANDALONE:
  352. case DSI_PLL_SOURCE_NATIVE:
  353. data = 0x0; /* internal PLL */
  354. break;
  355. case DSI_PLL_SOURCE_NON_NATIVE:
  356. data = 0x1; /* external PLL */
  357. break;
  358. default:
  359. break;
  360. }
  361. DSI_W32(phy, DSIPHY_CMN_CLK_CFG1, (data << 2)); /* set PLL src */
  362. /* DSI PHY timings */
  363. dsi_phy_hw_v5_0_commit_phy_timing(phy, timing);
  364. /* DSI lane settings */
  365. dsi_phy_hw_v5_0_lane_settings(phy, cfg);
  366. DSI_PHY_DBG(phy, "D-Phy enabled\n");
  367. }
  368. /**
  369. * enable() - Enable PHY hardware
  370. * @phy: Pointer to DSI PHY hardware object.
  371. * @cfg: Per lane configurations for timing, strength and lane
  372. * configurations.
  373. */
  374. void dsi_phy_hw_v5_0_enable(struct dsi_phy_hw *phy,
  375. struct dsi_phy_cfg *cfg)
  376. {
  377. int rc = 0;
  378. u32 status;
  379. u32 const delay_us = 5;
  380. u32 const timeout_us = 1000;
  381. if (dsi_phy_hw_v5_0_is_pll_on(phy))
  382. DSI_PHY_WARN(phy, "PLL turned on before configuring PHY\n");
  383. /* Request for REFGEN ready */
  384. DSI_W32(phy, DSIPHY_CMN_GLBL_DIGTOP_SPARE10, 0x1);
  385. udelay(500);
  386. if (!phy->phy_pll_bypass) {
  387. /* wait for REFGEN READY */
  388. rc = DSI_READ_POLL_TIMEOUT_ATOMIC(phy, DSIPHY_CMN_PHY_STATUS,
  389. status, (status & BIT(0)), delay_us, timeout_us);
  390. if (rc) {
  391. DSI_PHY_ERR(phy, "Ref gen not ready. Aborting\n");
  392. return;
  393. }
  394. }
  395. if (cfg->phy_type == DSI_PHY_TYPE_CPHY)
  396. dsi_phy_hw_cphy_enable(phy, cfg);
  397. else /* Default PHY type is DPHY */
  398. dsi_phy_hw_dphy_enable(phy, cfg);
  399. }
  400. /**
  401. * disable() - Disable PHY hardware
  402. * @phy: Pointer to DSI PHY hardware object.
  403. */
  404. void dsi_phy_hw_v5_0_disable(struct dsi_phy_hw *phy,
  405. struct dsi_phy_cfg *cfg)
  406. {
  407. u32 data = 0;
  408. if (phy->phy_pll_bypass)
  409. return;
  410. if (dsi_phy_hw_v5_0_is_pll_on(phy))
  411. DSI_PHY_WARN(phy, "Turning OFF PHY while PLL is on\n");
  412. dsi_phy_hw_v5_0_config_lpcdrx(phy, cfg, false);
  413. /* Turn off REFGEN Vote */
  414. DSI_W32(phy, DSIPHY_CMN_GLBL_DIGTOP_SPARE10, 0x0);
  415. wmb();
  416. /* Delay to ensure HW removes vote before PHY shut down */
  417. udelay(2);
  418. data = DSI_R32(phy, DSIPHY_CMN_CTRL_0);
  419. /* disable all lanes and splitlink clk lane*/
  420. data &= ~0x9F;
  421. DSI_W32(phy, DSIPHY_CMN_CTRL_0, data);
  422. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL0, 0);
  423. /* Turn off all PHY blocks */
  424. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0x00);
  425. /* make sure phy is turned off */
  426. wmb();
  427. DSI_PHY_DBG(phy, "Phy disabled\n");
  428. }
  429. void dsi_phy_hw_v5_0_toggle_resync_fifo(struct dsi_phy_hw *phy)
  430. {
  431. DSI_W32(phy, DSIPHY_CMN_RBUF_CTRL, 0x00);
  432. /* ensure that the FIFO is off */
  433. wmb();
  434. DSI_W32(phy, DSIPHY_CMN_RBUF_CTRL, 0x1);
  435. /* ensure that the FIFO is toggled back on */
  436. wmb();
  437. }
  438. void dsi_phy_hw_v5_0_reset_clk_en_sel(struct dsi_phy_hw *phy)
  439. {
  440. u32 data = 0;
  441. if (phy->phy_pll_bypass)
  442. return;
  443. /*Turning off CLK_EN_SEL after retime buffer sync */
  444. data = DSI_R32(phy, DSIPHY_CMN_CLK_CFG1);
  445. data &= ~BIT(4);
  446. DSI_W32(phy, DSIPHY_CMN_CLK_CFG1, data);
  447. /* ensure that clk_en_sel bit is turned off */
  448. wmb();
  449. }
  450. int dsi_phy_hw_v5_0_wait_for_lane_idle(
  451. struct dsi_phy_hw *phy, u32 lanes)
  452. {
  453. int rc = 0, val = 0;
  454. u32 stop_state_mask = 0;
  455. u32 const sleep_us = 10;
  456. u32 const timeout_us = 100;
  457. bool split_link_enabled = dsi_phy_hw_v5_0_is_split_link_enabled(phy);
  458. if (phy->phy_pll_bypass)
  459. return 0;
  460. stop_state_mask = BIT(4); /* clock lane */
  461. if (split_link_enabled)
  462. stop_state_mask |= BIT(5);
  463. if (lanes & DSI_DATA_LANE_0)
  464. stop_state_mask |= BIT(0);
  465. if (lanes & DSI_DATA_LANE_1)
  466. stop_state_mask |= BIT(1);
  467. if (lanes & DSI_DATA_LANE_2)
  468. stop_state_mask |= BIT(2);
  469. if (lanes & DSI_DATA_LANE_3)
  470. stop_state_mask |= BIT(3);
  471. DSI_PHY_DBG(phy, "polling for lanes to be in stop state, mask=0x%08x\n", stop_state_mask);
  472. rc = DSI_READ_POLL_TIMEOUT(phy, DSIPHY_CMN_LANE_STATUS1, val,
  473. ((val & stop_state_mask) == stop_state_mask),
  474. sleep_us, timeout_us);
  475. if (rc) {
  476. DSI_PHY_ERR(phy, "lanes not in stop state, LANE_STATUS=0x%08x\n", val);
  477. return rc;
  478. }
  479. return 0;
  480. }
  481. void dsi_phy_hw_v5_0_ulps_request(struct dsi_phy_hw *phy, struct dsi_phy_cfg *cfg, u32 lanes)
  482. {
  483. u32 reg = 0, sl_lane_ctrl1 = 0;
  484. if (lanes & DSI_CLOCK_LANE)
  485. reg = BIT(4);
  486. if (lanes & DSI_DATA_LANE_0)
  487. reg |= BIT(0);
  488. if (lanes & DSI_DATA_LANE_1)
  489. reg |= BIT(1);
  490. if (lanes & DSI_DATA_LANE_2)
  491. reg |= BIT(2);
  492. if (lanes & DSI_DATA_LANE_3)
  493. reg |= BIT(3);
  494. if (cfg->split_link.enabled)
  495. reg |= BIT(7);
  496. if (cfg->force_clk_lane_hs) {
  497. reg |= BIT(5) | BIT(6);
  498. if (cfg->split_link.enabled) {
  499. sl_lane_ctrl1 = DSI_R32(phy, DSIPHY_CMN_SL_DSI_LANE_CTRL1);
  500. sl_lane_ctrl1 |= BIT(2);
  501. DSI_W32(phy, DSIPHY_CMN_SL_DSI_LANE_CTRL1, sl_lane_ctrl1);
  502. }
  503. }
  504. /*
  505. * ULPS entry request. Wait for short time to make sure
  506. * that the lanes enter ULPS. Recommended as per HPG.
  507. */
  508. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL1, reg);
  509. usleep_range(100, 110);
  510. /* disable LPRX and CDRX */
  511. dsi_phy_hw_v5_0_config_lpcdrx(phy, cfg, false);
  512. DSI_PHY_DBG(phy, "ULPS requested for lanes 0x%x\n", lanes);
  513. }
  514. int dsi_phy_hw_v5_0_lane_reset(struct dsi_phy_hw *phy)
  515. {
  516. int ret = 0, loop = 10, u_dly = 200;
  517. u32 ln_status = 0;
  518. while ((ln_status != 0x1f) && loop) {
  519. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, 0x1f);
  520. wmb(); /* ensure register is committed */
  521. loop--;
  522. udelay(u_dly);
  523. ln_status = DSI_R32(phy, DSIPHY_CMN_LANE_STATUS1);
  524. DSI_PHY_DBG(phy, "trial no: %d\n", loop);
  525. }
  526. if (!loop)
  527. DSI_PHY_DBG(phy, "could not reset phy lanes\n");
  528. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, 0x0);
  529. wmb(); /* ensure register is committed */
  530. return ret;
  531. }
  532. void dsi_phy_hw_v5_0_ulps_exit(struct dsi_phy_hw *phy,
  533. struct dsi_phy_cfg *cfg, u32 lanes)
  534. {
  535. u32 reg = 0, sl_lane_ctrl1 = 0;
  536. if (lanes & DSI_CLOCK_LANE)
  537. reg = BIT(4);
  538. if (lanes & DSI_DATA_LANE_0)
  539. reg |= BIT(0);
  540. if (lanes & DSI_DATA_LANE_1)
  541. reg |= BIT(1);
  542. if (lanes & DSI_DATA_LANE_2)
  543. reg |= BIT(2);
  544. if (lanes & DSI_DATA_LANE_3)
  545. reg |= BIT(3);
  546. if (cfg->split_link.enabled)
  547. reg |= BIT(5);
  548. /* enable LPRX and CDRX */
  549. dsi_phy_hw_v5_0_config_lpcdrx(phy, cfg, true);
  550. /* ULPS exit request */
  551. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL2, reg);
  552. usleep_range(1000, 1010);
  553. /* Clear ULPS request flags on all lanes */
  554. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL1, 0);
  555. /* Clear ULPS exit flags on all lanes */
  556. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL2, 0);
  557. /*
  558. * Sometimes when exiting ULPS, it is possible that some DSI
  559. * lanes are not in the stop state which could lead to DSI
  560. * commands not going through. To avoid this, force the lanes
  561. * to be in stop state.
  562. */
  563. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, reg);
  564. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, 0);
  565. usleep_range(100, 110);
  566. if (cfg->force_clk_lane_hs) {
  567. reg = BIT(5) | BIT(6);
  568. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL1, reg);
  569. if (cfg->split_link.enabled) {
  570. sl_lane_ctrl1 = DSI_R32(phy, DSIPHY_CMN_SL_DSI_LANE_CTRL1);
  571. sl_lane_ctrl1 |= BIT(2);
  572. DSI_W32(phy, DSIPHY_CMN_SL_DSI_LANE_CTRL1, sl_lane_ctrl1);
  573. }
  574. }
  575. }
  576. u32 dsi_phy_hw_v5_0_get_lanes_in_ulps(struct dsi_phy_hw *phy)
  577. {
  578. u32 lanes = 0;
  579. lanes = DSI_R32(phy, DSIPHY_CMN_LANE_STATUS0);
  580. DSI_PHY_DBG(phy, "lanes in ulps = 0x%x\n", lanes);
  581. return lanes;
  582. }
  583. bool dsi_phy_hw_v5_0_is_lanes_in_ulps(u32 lanes, u32 ulps_lanes)
  584. {
  585. if (lanes & ulps_lanes)
  586. return false;
  587. return true;
  588. }
  589. int dsi_phy_hw_timing_val_v5_0(struct dsi_phy_per_lane_cfgs *timing_cfg,
  590. u32 *timing_val, u32 size)
  591. {
  592. int i = 0;
  593. if (size != DSI_PHY_TIMING_V4_SIZE) {
  594. DSI_ERR("Unexpected timing array size %d\n", size);
  595. return -EINVAL;
  596. }
  597. for (i = 0; i < size; i++)
  598. timing_cfg->lane_v4[i] = timing_val[i];
  599. return 0;
  600. }
  601. void dsi_phy_hw_v5_0_dyn_refresh_config(struct dsi_phy_hw *phy,
  602. struct dsi_phy_cfg *cfg, bool is_master)
  603. {
  604. u32 reg;
  605. bool is_cphy = (cfg->phy_type == DSI_PHY_TYPE_CPHY) ? true : false;
  606. if (is_master) {
  607. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL19,
  608. DSIPHY_CMN_TIMING_CTRL_0, DSIPHY_CMN_TIMING_CTRL_1,
  609. cfg->timing.lane_v4[0], cfg->timing.lane_v4[1]);
  610. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL20,
  611. DSIPHY_CMN_TIMING_CTRL_2, DSIPHY_CMN_TIMING_CTRL_3,
  612. cfg->timing.lane_v4[2], cfg->timing.lane_v4[3]);
  613. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL21,
  614. DSIPHY_CMN_TIMING_CTRL_4, DSIPHY_CMN_TIMING_CTRL_5,
  615. cfg->timing.lane_v4[4], cfg->timing.lane_v4[5]);
  616. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL22,
  617. DSIPHY_CMN_TIMING_CTRL_6, DSIPHY_CMN_TIMING_CTRL_7,
  618. cfg->timing.lane_v4[6], cfg->timing.lane_v4[7]);
  619. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL23,
  620. DSIPHY_CMN_TIMING_CTRL_8, DSIPHY_CMN_TIMING_CTRL_9,
  621. cfg->timing.lane_v4[8], cfg->timing.lane_v4[9]);
  622. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL24,
  623. DSIPHY_CMN_TIMING_CTRL_10, DSIPHY_CMN_TIMING_CTRL_11,
  624. cfg->timing.lane_v4[10], cfg->timing.lane_v4[11]);
  625. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL25,
  626. DSIPHY_CMN_TIMING_CTRL_12, DSIPHY_CMN_TIMING_CTRL_13,
  627. cfg->timing.lane_v4[12], cfg->timing.lane_v4[13]);
  628. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL26,
  629. DSIPHY_CMN_CTRL_0, DSIPHY_CMN_LANE_CTRL0, 0x7f,
  630. is_cphy ? 0x17 : 0x1f);
  631. } else {
  632. reg = DSI_R32(phy, DSIPHY_CMN_CLK_CFG1);
  633. reg &= ~BIT(5);
  634. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL0,
  635. DSIPHY_CMN_CLK_CFG1, DSIPHY_CMN_PLL_CNTRL, reg, 0x0);
  636. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL1,
  637. DSIPHY_CMN_RBUF_CTRL, DSIPHY_CMN_TIMING_CTRL_0, 0x0,
  638. cfg->timing.lane_v4[0]);
  639. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL2,
  640. DSIPHY_CMN_TIMING_CTRL_1, DSIPHY_CMN_TIMING_CTRL_2,
  641. cfg->timing.lane_v4[1], cfg->timing.lane_v4[2]);
  642. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL3,
  643. DSIPHY_CMN_TIMING_CTRL_3, DSIPHY_CMN_TIMING_CTRL_4,
  644. cfg->timing.lane_v4[3], cfg->timing.lane_v4[4]);
  645. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL4,
  646. DSIPHY_CMN_TIMING_CTRL_5, DSIPHY_CMN_TIMING_CTRL_6,
  647. cfg->timing.lane_v4[5], cfg->timing.lane_v4[6]);
  648. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL5,
  649. DSIPHY_CMN_TIMING_CTRL_7, DSIPHY_CMN_TIMING_CTRL_8,
  650. cfg->timing.lane_v4[7], cfg->timing.lane_v4[8]);
  651. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL6,
  652. DSIPHY_CMN_TIMING_CTRL_9, DSIPHY_CMN_TIMING_CTRL_10,
  653. cfg->timing.lane_v4[9], cfg->timing.lane_v4[10]);
  654. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL7,
  655. DSIPHY_CMN_TIMING_CTRL_11, DSIPHY_CMN_TIMING_CTRL_12,
  656. cfg->timing.lane_v4[11], cfg->timing.lane_v4[12]);
  657. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL8,
  658. DSIPHY_CMN_TIMING_CTRL_13, DSIPHY_CMN_CTRL_0,
  659. cfg->timing.lane_v4[13], 0x7f);
  660. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL9,
  661. DSIPHY_CMN_LANE_CTRL0, DSIPHY_CMN_CTRL_2,
  662. is_cphy ? 0x17 : 0x1f, 0x40);
  663. /*
  664. * fill with dummy register writes since controller will blindly
  665. * send these values to DSI PHY.
  666. */
  667. reg = DSI_DYN_REFRESH_PLL_CTRL11;
  668. while (reg <= DSI_DYN_REFRESH_PLL_CTRL29) {
  669. DSI_DYN_REF_REG_W(phy->dyn_pll_base, reg, DSIPHY_CMN_LANE_CTRL0,
  670. DSIPHY_CMN_CTRL_0, is_cphy ? 0x17 : 0x1f, 0x7f);
  671. reg += 0x4;
  672. }
  673. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_UPPER_ADDR, 0);
  674. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_UPPER_ADDR2, 0);
  675. }
  676. wmb(); /* make sure all registers are updated */
  677. }
  678. void dsi_phy_hw_v5_0_dyn_refresh_pipe_delay(struct dsi_phy_hw *phy, struct dsi_dyn_clk_delay *delay)
  679. {
  680. if (!delay)
  681. return;
  682. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_PIPE_DELAY, delay->pipe_delay);
  683. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_PIPE_DELAY2, delay->pipe_delay2);
  684. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_DELAY, delay->pll_delay);
  685. }
  686. void dsi_phy_hw_v5_0_dyn_refresh_trigger_sel(struct dsi_phy_hw *phy, bool is_master)
  687. {
  688. u32 reg;
  689. /*
  690. * Dynamic refresh will take effect at next mdp flush event.
  691. * This makes sure that any update to frame timings together
  692. * with dfps will take effect in one vsync at next mdp flush.
  693. */
  694. if (is_master) {
  695. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  696. reg |= BIT(17);
  697. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  698. }
  699. }
  700. void dsi_phy_hw_v5_0_dyn_refresh_helper(struct dsi_phy_hw *phy, u32 offset)
  701. {
  702. u32 reg;
  703. /*
  704. * if no offset is mentioned then this means we want to clear
  705. * the dynamic refresh ctrl register which is the last step
  706. * of dynamic refresh sequence.
  707. */
  708. if (!offset) {
  709. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  710. reg &= ~(BIT(0) | BIT(8) | BIT(13) | BIT(16) | BIT(17));
  711. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  712. wmb(); /* ensure dynamic fps is cleared */
  713. return;
  714. }
  715. if (offset & BIT(DYN_REFRESH_INTF_SEL)) {
  716. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  717. reg |= BIT(13);
  718. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  719. }
  720. if (offset & BIT(DYN_REFRESH_SYNC_MODE)) {
  721. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  722. reg |= BIT(16);
  723. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  724. }
  725. if (offset & BIT(DYN_REFRESH_SWI_CTRL)) {
  726. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  727. reg |= BIT(0);
  728. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  729. }
  730. if (offset & BIT(DYN_REFRESH_SW_TRIGGER)) {
  731. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  732. reg |= BIT(8);
  733. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  734. wmb(); /* ensure dynamic fps is triggered */
  735. }
  736. }
  737. int dsi_phy_hw_v5_0_cache_phy_timings(struct dsi_phy_per_lane_cfgs *timings,
  738. u32 *dst, u32 size)
  739. {
  740. int i;
  741. if (!timings || !dst || !size)
  742. return -EINVAL;
  743. if (size != DSI_PHY_TIMING_V4_SIZE) {
  744. DSI_ERR("size mis-match\n");
  745. return -EINVAL;
  746. }
  747. for (i = 0; i < size; i++)
  748. dst[i] = timings->lane_v4[i];
  749. return 0;
  750. }
  751. void dsi_phy_hw_v5_0_set_continuous_clk(struct dsi_phy_hw *phy, bool enable)
  752. {
  753. u32 reg = 0, sl_lane_ctrl1 = 0;
  754. bool is_split_link_enabled = dsi_phy_hw_v5_0_is_split_link_enabled(phy);
  755. reg = DSI_R32(phy, DSIPHY_CMN_LANE_CTRL1);
  756. if (enable)
  757. reg |= BIT(5) | BIT(6);
  758. else
  759. reg &= ~(BIT(5) | BIT(6));
  760. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL1, reg);
  761. if (is_split_link_enabled) {
  762. sl_lane_ctrl1 = DSI_R32(phy, DSIPHY_CMN_SL_DSI_LANE_CTRL1);
  763. if (enable)
  764. sl_lane_ctrl1 |= BIT(2);
  765. else
  766. sl_lane_ctrl1 &= ~BIT(2);
  767. DSI_W32(phy, DSIPHY_CMN_SL_DSI_LANE_CTRL1, sl_lane_ctrl1);
  768. }
  769. wmb(); /* make sure request is set */
  770. }
  771. void dsi_phy_hw_v5_0_phy_idle_off(struct dsi_phy_hw *phy,
  772. struct dsi_phy_cfg *cfg)
  773. {
  774. if (dsi_phy_hw_v5_0_is_pll_on(phy))
  775. DSI_PHY_WARN(phy, "Turning OFF PHY while PLL is on\n");
  776. /* enable clamping of PADS */
  777. DSI_W32(phy, DSIPHY_CMN_CTRL_4, 0x1);
  778. DSI_W32(phy, DSIPHY_CMN_CTRL_3, 0x0);
  779. wmb();
  780. dsi_phy_hw_v5_0_config_lpcdrx(phy, cfg, false);
  781. /* Turn off REFGEN Vote */
  782. DSI_W32(phy, DSIPHY_CMN_GLBL_DIGTOP_SPARE10, 0x0);
  783. /* make sure request is set */
  784. wmb();
  785. /* Delay to ensure HW removes vote*/
  786. udelay(2);
  787. }