dsi_phy_hw_v4_0.c 29 KB

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