dsi_phy_hw_v4_0.c 27 KB

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