dsi_phy_hw_v4_0.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023, 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_v4_0_is_pll_on(struct dsi_phy_hw *phy)
  114. {
  115. u32 data = 0;
  116. data = DSI_R32(phy, DSIPHY_CMN_PLL_CNTRL);
  117. mb(); /*make sure read happened */
  118. return (data & BIT(0));
  119. }
  120. static bool dsi_phy_hw_v4_0_is_split_link_enabled(struct dsi_phy_hw *phy)
  121. {
  122. u32 reg = 0;
  123. reg = DSI_R32(phy, DSIPHY_CMN_GLBL_CTRL);
  124. mb(); /*make sure read happened */
  125. return (reg & BIT(5));
  126. }
  127. static void dsi_phy_hw_v4_0_config_lpcdrx(struct dsi_phy_hw *phy,
  128. struct dsi_phy_cfg *cfg, bool enable)
  129. {
  130. int phy_lane_0 = dsi_phy_conv_logical_to_phy_lane(&cfg->lane_map,
  131. DSI_LOGICAL_LANE_0);
  132. /*
  133. * LPRX and CDRX need to enabled only for physical data lane
  134. * corresponding to the logical data lane 0
  135. */
  136. if (enable)
  137. DSI_W32(phy, DSIPHY_LNX_LPRX_CTRL(phy_lane_0),
  138. 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_v4_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_v4_0_lane_settings(struct dsi_phy_hw *phy,
  153. struct dsi_phy_cfg *cfg)
  154. {
  155. int i;
  156. u8 tx_dctrl_v4[] = {0x00, 0x00, 0x00, 0x04, 0x01};
  157. u8 tx_dctrl_v4_1[] = {0x40, 0x40, 0x40, 0x46, 0x41};
  158. u8 *tx_dctrl;
  159. bool split_link_enabled;
  160. u32 lanes_per_sublink;
  161. if (phy->version >= DSI_PHY_VERSION_4_1)
  162. tx_dctrl = &tx_dctrl_v4_1[0];
  163. else
  164. tx_dctrl = &tx_dctrl_v4[0];
  165. split_link_enabled = cfg->split_link.enabled;
  166. lanes_per_sublink = cfg->split_link.lanes_per_sublink;
  167. /* Strength ctrl settings */
  168. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++) {
  169. /*
  170. * Disable LPRX and CDRX for all lanes. And later on, it will
  171. * be only enabled for the physical data lane corresponding
  172. * to the logical data lane 0
  173. */
  174. DSI_W32(phy, DSIPHY_LNX_LPRX_CTRL(i), 0);
  175. DSI_W32(phy, DSIPHY_LNX_PIN_SWAP(i), 0x0);
  176. }
  177. dsi_phy_hw_v4_0_config_lpcdrx(phy, cfg, true);
  178. /* other settings */
  179. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++) {
  180. DSI_W32(phy, DSIPHY_LNX_CFG0(i), cfg->lanecfg.lane[i][0]);
  181. DSI_W32(phy, DSIPHY_LNX_CFG1(i), cfg->lanecfg.lane[i][1]);
  182. DSI_W32(phy, DSIPHY_LNX_CFG2(i), cfg->lanecfg.lane[i][2]);
  183. DSI_W32(phy, DSIPHY_LNX_TX_DCTRL(i), tx_dctrl[i]);
  184. }
  185. /* remove below check if cphy splitlink is enabled */
  186. if (split_link_enabled && (cfg->phy_type == DSI_PHY_TYPE_CPHY))
  187. return;
  188. /* Configure the splitlink clock lane with clk lane settings */
  189. if (split_link_enabled) {
  190. DSI_W32(phy, DSIPHY_LNX_LPRX_CTRL(5), 0x0);
  191. DSI_W32(phy, DSIPHY_LNX_PIN_SWAP(5), 0x0);
  192. DSI_W32(phy, DSIPHY_LNX_CFG0(5), cfg->lanecfg.lane[4][0]);
  193. DSI_W32(phy, DSIPHY_LNX_CFG1(5), cfg->lanecfg.lane[4][1]);
  194. DSI_W32(phy, DSIPHY_LNX_CFG2(5), cfg->lanecfg.lane[4][2]);
  195. DSI_W32(phy, DSIPHY_LNX_TX_DCTRL(5), tx_dctrl[4]);
  196. }
  197. }
  198. void dsi_phy_hw_v4_0_commit_phy_timing(struct dsi_phy_hw *phy,
  199. struct dsi_phy_per_lane_cfgs *timing)
  200. {
  201. /* Commit DSI PHY timings */
  202. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_0, timing->lane_v4[0]);
  203. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_1, timing->lane_v4[1]);
  204. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_2, timing->lane_v4[2]);
  205. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_3, timing->lane_v4[3]);
  206. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_4, timing->lane_v4[4]);
  207. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_5, timing->lane_v4[5]);
  208. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_6, timing->lane_v4[6]);
  209. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_7, timing->lane_v4[7]);
  210. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_8, timing->lane_v4[8]);
  211. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_9, timing->lane_v4[9]);
  212. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_10, timing->lane_v4[10]);
  213. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_11, timing->lane_v4[11]);
  214. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_12, timing->lane_v4[12]);
  215. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_13, timing->lane_v4[13]);
  216. }
  217. /**
  218. * calc_cmn_lane_ctrl0() - Calculate the value to be set for
  219. * DSIPHY_CMN_LANE_CTRL0 register.
  220. * @cfg: Per lane configurations for timing, strength and lane
  221. * configurations.
  222. */
  223. static inline u32 dsi_phy_hw_calc_cmn_lane_ctrl0(struct dsi_phy_cfg *cfg)
  224. {
  225. u32 cmn_lane_ctrl0 = 0;
  226. /* Only enable lanes that are required */
  227. cmn_lane_ctrl0 |= ((cfg->data_lanes & DSI_DATA_LANE_0) ? BIT(0) : 0);
  228. cmn_lane_ctrl0 |= ((cfg->data_lanes & DSI_DATA_LANE_1) ? BIT(1) : 0);
  229. cmn_lane_ctrl0 |= ((cfg->data_lanes & DSI_DATA_LANE_2) ? BIT(2) : 0);
  230. cmn_lane_ctrl0 |= ((cfg->data_lanes & DSI_DATA_LANE_3) ? BIT(3) : 0);
  231. cmn_lane_ctrl0 |= BIT(4);
  232. return cmn_lane_ctrl0;
  233. }
  234. /**
  235. * cphy_enable() - Enable CPHY hardware
  236. * @phy: Pointer to DSI PHY hardware object.
  237. * @cfg: Per lane configurations for timing, strength and lane
  238. * configurations.
  239. */
  240. static void dsi_phy_hw_cphy_enable(struct dsi_phy_hw *phy,
  241. struct dsi_phy_cfg *cfg)
  242. {
  243. struct dsi_phy_per_lane_cfgs *timing = &cfg->timing;
  244. u32 data;
  245. u32 minor_ver = 0;
  246. /* For C-PHY, no low power settings for lower clk rate */
  247. u32 vreg_ctrl_0 = 0x51;
  248. u32 vreg_ctrl_1 = 0x55;
  249. u32 glbl_str_swi_cal_sel_ctrl = 0;
  250. u32 glbl_hstx_str_ctrl_0 = 0;
  251. u32 glbl_rescode_top_ctrl = 0;
  252. u32 glbl_rescode_bot_ctrl = 0;
  253. bool less_than_1500_mhz = false;
  254. u32 cmn_lane_ctrl0 = 0;
  255. /* Alter PHY configurations if data rate less than 1.5GHZ*/
  256. if (cfg->bit_clk_rate_hz <= 1500000000)
  257. less_than_1500_mhz = true;
  258. if (phy->version >= DSI_PHY_VERSION_4_2) {
  259. glbl_rescode_top_ctrl = less_than_1500_mhz ? 0x3d : 0x01;
  260. glbl_rescode_bot_ctrl = less_than_1500_mhz ? 0x38 : 0x3b;
  261. } else if (phy->version == DSI_PHY_VERSION_4_1) {
  262. glbl_rescode_top_ctrl = 0x00;
  263. glbl_rescode_bot_ctrl = 0x3C;
  264. glbl_str_swi_cal_sel_ctrl = 0x00;
  265. glbl_hstx_str_ctrl_0 = 0x88;
  266. } else {
  267. glbl_str_swi_cal_sel_ctrl = 0x03;
  268. glbl_hstx_str_ctrl_0 = 0x66;
  269. glbl_rescode_top_ctrl = 0x03;
  270. glbl_rescode_bot_ctrl = 0x3c;
  271. }
  272. if (phy->version == DSI_PHY_VERSION_4_3_2) {
  273. vreg_ctrl_0 = 0x45;
  274. vreg_ctrl_1 = 0x41;
  275. }
  276. /* de-assert digital and pll power down */
  277. data = BIT(6) | BIT(5);
  278. DSI_W32(phy, DSIPHY_CMN_CTRL_0, data);
  279. /* Assert PLL core reset */
  280. DSI_W32(phy, DSIPHY_CMN_PLL_CNTRL, 0x00);
  281. /* turn off resync FIFO */
  282. DSI_W32(phy, DSIPHY_CMN_RBUF_CTRL, 0x00);
  283. /* program CMN_CTRL_4 for minor_ver greater than 2 chipsets*/
  284. minor_ver = DSI_R32(phy, DSIPHY_CMN_REVISION_ID0);
  285. minor_ver = minor_ver & (0xf0);
  286. if (minor_ver >= 0x20)
  287. DSI_W32(phy, DSIPHY_CMN_CTRL_4, 0x04);
  288. /* Configure PHY lane swap */
  289. dsi_phy_hw_v4_0_lane_swap_config(phy, &cfg->lane_map);
  290. DSI_W32(phy, DSIPHY_CMN_GLBL_CTRL, BIT(6));
  291. /* Enable LDO */
  292. DSI_W32(phy, DSIPHY_CMN_VREG_CTRL_0, vreg_ctrl_0);
  293. DSI_W32(phy, DSIPHY_CMN_VREG_CTRL_1, vreg_ctrl_1);
  294. DSI_W32(phy, DSIPHY_CMN_GLBL_STR_SWI_CAL_SEL_CTRL,
  295. glbl_str_swi_cal_sel_ctrl);
  296. DSI_W32(phy, DSIPHY_CMN_GLBL_HSTX_STR_CTRL_0, glbl_hstx_str_ctrl_0);
  297. DSI_W32(phy, DSIPHY_CMN_GLBL_PEMPH_CTRL_0, 0x11);
  298. DSI_W32(phy, DSIPHY_CMN_GLBL_PEMPH_CTRL_1, 0x01);
  299. DSI_W32(phy, DSIPHY_CMN_GLBL_RESCODE_OFFSET_TOP_CTRL,
  300. glbl_rescode_top_ctrl);
  301. DSI_W32(phy, DSIPHY_CMN_GLBL_RESCODE_OFFSET_BOT_CTRL,
  302. glbl_rescode_bot_ctrl);
  303. DSI_W32(phy, DSIPHY_CMN_GLBL_LPTX_STR_CTRL, 0x55);
  304. /* Remove power down from all blocks */
  305. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0x7f);
  306. cmn_lane_ctrl0 = dsi_phy_hw_calc_cmn_lane_ctrl0(cfg);
  307. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL0, cmn_lane_ctrl0);
  308. switch (cfg->pll_source) {
  309. case DSI_PLL_SOURCE_STANDALONE:
  310. case DSI_PLL_SOURCE_NATIVE:
  311. data = 0x0; /* internal PLL */
  312. break;
  313. case DSI_PLL_SOURCE_NON_NATIVE:
  314. data = 0x1; /* external PLL */
  315. break;
  316. default:
  317. break;
  318. }
  319. DSI_W32(phy, DSIPHY_CMN_CLK_CFG1, (data << 2)); /* set PLL src */
  320. /* DSI PHY timings */
  321. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_0, timing->lane_v4[0]);
  322. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_4, timing->lane_v4[4]);
  323. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_5, timing->lane_v4[5]);
  324. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_6, timing->lane_v4[6]);
  325. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_7, timing->lane_v4[7]);
  326. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_8, timing->lane_v4[8]);
  327. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_9, timing->lane_v4[9]);
  328. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_10, timing->lane_v4[10]);
  329. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_11, timing->lane_v4[11]);
  330. /* DSI lane settings */
  331. dsi_phy_hw_v4_0_lane_settings(phy, cfg);
  332. DSI_PHY_DBG(phy, "C-Phy enabled\n");
  333. }
  334. /**
  335. * dphy_enable() - Enable DPHY hardware
  336. * @phy: Pointer to DSI PHY hardware object.
  337. * @cfg: Per lane configurations for timing, strength and lane
  338. * configurations.
  339. */
  340. static void dsi_phy_hw_dphy_enable(struct dsi_phy_hw *phy,
  341. struct dsi_phy_cfg *cfg)
  342. {
  343. struct dsi_phy_per_lane_cfgs *timing = &cfg->timing;
  344. u32 data;
  345. u32 minor_ver = 0;
  346. bool less_than_1500_mhz = false;
  347. u32 vreg_ctrl_0 = 0;
  348. u32 vreg_ctrl_1 = 0x5c;
  349. u32 glbl_str_swi_cal_sel_ctrl = 0;
  350. u32 glbl_hstx_str_ctrl_0 = 0;
  351. u32 glbl_rescode_top_ctrl = 0;
  352. u32 glbl_rescode_bot_ctrl = 0;
  353. bool split_link_enabled;
  354. u32 lanes_per_sublink;
  355. u32 cmn_lane_ctrl0 = 0;
  356. /* Alter PHY configurations if data rate less than 1.5GHZ*/
  357. if (cfg->bit_clk_rate_hz <= 1500000000)
  358. less_than_1500_mhz = true;
  359. if (phy->version >= DSI_PHY_VERSION_4_2) {
  360. vreg_ctrl_0 = less_than_1500_mhz ? 0x53 : 0x52;
  361. glbl_rescode_top_ctrl = less_than_1500_mhz ? 0x3c : 0x00;
  362. glbl_rescode_bot_ctrl = less_than_1500_mhz ? 0x38 : 0x39;
  363. glbl_str_swi_cal_sel_ctrl = 0x00;
  364. glbl_hstx_str_ctrl_0 = 0x88;
  365. } else if (phy->version == DSI_PHY_VERSION_4_1) {
  366. vreg_ctrl_0 = less_than_1500_mhz ? 0x53 : 0x52;
  367. glbl_rescode_top_ctrl = less_than_1500_mhz ? 0x3d : 0x00;
  368. glbl_rescode_bot_ctrl = less_than_1500_mhz ? 0x39 : 0x3c;
  369. glbl_str_swi_cal_sel_ctrl = 0x00;
  370. glbl_hstx_str_ctrl_0 = 0x88;
  371. } else {
  372. vreg_ctrl_0 = less_than_1500_mhz ? 0x5B : 0x59;
  373. glbl_str_swi_cal_sel_ctrl = less_than_1500_mhz ? 0x03 : 0x00;
  374. glbl_hstx_str_ctrl_0 = less_than_1500_mhz ? 0x66 : 0x88;
  375. glbl_rescode_top_ctrl = 0x03;
  376. glbl_rescode_bot_ctrl = 0x3c;
  377. }
  378. if (phy->version >= DSI_PHY_VERSION_4_3)
  379. glbl_rescode_top_ctrl = less_than_1500_mhz ? 0x3d : 0x01;
  380. if (phy->version == DSI_PHY_VERSION_4_3_2){
  381. vreg_ctrl_0 = 0x44;
  382. vreg_ctrl_1 = 0x19;
  383. }
  384. split_link_enabled = cfg->split_link.enabled;
  385. lanes_per_sublink = cfg->split_link.lanes_per_sublink;
  386. /* de-assert digital and pll power down */
  387. data = BIT(6) | BIT(5);
  388. DSI_W32(phy, DSIPHY_CMN_CTRL_0, data);
  389. if (split_link_enabled) {
  390. data = DSI_R32(phy, DSIPHY_CMN_GLBL_CTRL);
  391. /* set SPLIT_LINK_ENABLE in global control */
  392. DSI_W32(phy, DSIPHY_CMN_GLBL_CTRL, (data | BIT(5)));
  393. }
  394. /* Assert PLL core reset */
  395. DSI_W32(phy, DSIPHY_CMN_PLL_CNTRL, 0x00);
  396. /* turn off resync FIFO */
  397. DSI_W32(phy, DSIPHY_CMN_RBUF_CTRL, 0x00);
  398. /* program CMN_CTRL_4 for minor_ver greater than 2 chipsets*/
  399. minor_ver = DSI_R32(phy, DSIPHY_CMN_REVISION_ID0);
  400. minor_ver = minor_ver & (0xf0);
  401. if (minor_ver >= 0x20)
  402. DSI_W32(phy, DSIPHY_CMN_CTRL_4, 0x04);
  403. /* Configure PHY lane swap */
  404. dsi_phy_hw_v4_0_lane_swap_config(phy, &cfg->lane_map);
  405. /* Enable LDO */
  406. DSI_W32(phy, DSIPHY_CMN_VREG_CTRL_0, vreg_ctrl_0);
  407. DSI_W32(phy, DSIPHY_CMN_VREG_CTRL_1, vreg_ctrl_1);
  408. DSI_W32(phy, DSIPHY_CMN_CTRL_3, 0x00);
  409. DSI_W32(phy, DSIPHY_CMN_GLBL_STR_SWI_CAL_SEL_CTRL,
  410. glbl_str_swi_cal_sel_ctrl);
  411. DSI_W32(phy, DSIPHY_CMN_GLBL_HSTX_STR_CTRL_0, glbl_hstx_str_ctrl_0);
  412. DSI_W32(phy, DSIPHY_CMN_GLBL_PEMPH_CTRL_0, 0x00);
  413. DSI_W32(phy, DSIPHY_CMN_GLBL_RESCODE_OFFSET_TOP_CTRL,
  414. glbl_rescode_top_ctrl);
  415. DSI_W32(phy, DSIPHY_CMN_GLBL_RESCODE_OFFSET_BOT_CTRL,
  416. glbl_rescode_bot_ctrl);
  417. DSI_W32(phy, DSIPHY_CMN_GLBL_LPTX_STR_CTRL, 0x55);
  418. if (split_link_enabled) {
  419. if (lanes_per_sublink == 1) {
  420. /* remove Lane1 and Lane3 configs */
  421. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0xed);
  422. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL0, 0x35);
  423. } else {
  424. /* enable all together with sublink clock */
  425. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0xff);
  426. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL0, 0x3F);
  427. }
  428. DSI_W32(phy, DSIPHY_CMN_SL_DSI_LANE_CTRL1, 0x03);
  429. } else {
  430. /* Remove power down from all blocks */
  431. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0x7f);
  432. cmn_lane_ctrl0 = dsi_phy_hw_calc_cmn_lane_ctrl0(cfg);
  433. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL0, cmn_lane_ctrl0);
  434. }
  435. /* Select full-rate mode */
  436. DSI_W32(phy, DSIPHY_CMN_CTRL_2, 0x40);
  437. switch (cfg->pll_source) {
  438. case DSI_PLL_SOURCE_STANDALONE:
  439. case DSI_PLL_SOURCE_NATIVE:
  440. data = 0x0; /* internal PLL */
  441. break;
  442. case DSI_PLL_SOURCE_NON_NATIVE:
  443. data = 0x1; /* external PLL */
  444. break;
  445. default:
  446. break;
  447. }
  448. DSI_W32(phy, DSIPHY_CMN_CLK_CFG1, (data << 2)); /* set PLL src */
  449. /* DSI PHY timings */
  450. dsi_phy_hw_v4_0_commit_phy_timing(phy, timing);
  451. /* DSI lane settings */
  452. dsi_phy_hw_v4_0_lane_settings(phy, cfg);
  453. DSI_PHY_DBG(phy, "D-Phy enabled\n");
  454. }
  455. /**
  456. * enable() - Enable PHY hardware
  457. * @phy: Pointer to DSI PHY hardware object.
  458. * @cfg: Per lane configurations for timing, strength and lane
  459. * configurations.
  460. */
  461. void dsi_phy_hw_v4_0_enable(struct dsi_phy_hw *phy,
  462. struct dsi_phy_cfg *cfg)
  463. {
  464. int rc = 0;
  465. u32 status;
  466. u32 const delay_us = 5;
  467. u32 const timeout_us = 1000;
  468. if (dsi_phy_hw_v4_0_is_pll_on(phy))
  469. pr_warn("PLL turned on before configuring PHY\n");
  470. /* Request for REFGEN ready */
  471. if (phy->version >= DSI_PHY_VERSION_4_3) {
  472. DSI_W32(phy, DSIPHY_CMN_GLBL_DIGTOP_SPARE10, 0x1);
  473. udelay(500);
  474. }
  475. /* wait for REFGEN READY */
  476. rc = DSI_READ_POLL_TIMEOUT_ATOMIC(phy, DSIPHY_CMN_PHY_STATUS,
  477. status, (status & BIT(0)), delay_us, timeout_us);
  478. if (rc) {
  479. DSI_PHY_ERR(phy, "Ref gen not ready. Aborting\n");
  480. return;
  481. }
  482. if (cfg->phy_type == DSI_PHY_TYPE_CPHY)
  483. dsi_phy_hw_cphy_enable(phy, cfg);
  484. else /* Default PHY type is DPHY */
  485. dsi_phy_hw_dphy_enable(phy, cfg);
  486. }
  487. /**
  488. * disable() - Disable PHY hardware
  489. * @phy: Pointer to DSI PHY hardware object.
  490. */
  491. void dsi_phy_hw_v4_0_disable(struct dsi_phy_hw *phy,
  492. struct dsi_phy_cfg *cfg)
  493. {
  494. u32 data = 0;
  495. if (dsi_phy_hw_v4_0_is_pll_on(phy))
  496. DSI_PHY_WARN(phy, "Turning OFF PHY while PLL is on\n");
  497. dsi_phy_hw_v4_0_config_lpcdrx(phy, cfg, false);
  498. /* Turn off REFGEN Vote */
  499. DSI_W32(phy, DSIPHY_CMN_GLBL_DIGTOP_SPARE10, 0x0);
  500. wmb();
  501. /* Delay to ensure HW removes vote before PHY shut down */
  502. udelay(2);
  503. data = DSI_R32(phy, DSIPHY_CMN_CTRL_0);
  504. /* disable all lanes and splitlink clk lane*/
  505. data &= ~0x9F;
  506. DSI_W32(phy, DSIPHY_CMN_CTRL_0, data);
  507. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL0, 0);
  508. /* Turn off all PHY blocks */
  509. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0x00);
  510. /* make sure phy is turned off */
  511. wmb();
  512. DSI_PHY_DBG(phy, "Phy disabled\n");
  513. }
  514. void dsi_phy_hw_v4_0_toggle_resync_fifo(struct dsi_phy_hw *phy)
  515. {
  516. DSI_W32(phy, DSIPHY_CMN_RBUF_CTRL, 0x00);
  517. /* ensure that the FIFO is off */
  518. wmb();
  519. DSI_W32(phy, DSIPHY_CMN_RBUF_CTRL, 0x1);
  520. /* ensure that the FIFO is toggled back on */
  521. wmb();
  522. }
  523. void dsi_phy_hw_v4_0_reset_clk_en_sel(struct dsi_phy_hw *phy)
  524. {
  525. u32 data = 0;
  526. /*Turning off CLK_EN_SEL after retime buffer sync */
  527. data = DSI_R32(phy, DSIPHY_CMN_CLK_CFG1);
  528. data &= ~BIT(4);
  529. DSI_W32(phy, DSIPHY_CMN_CLK_CFG1, data);
  530. /* ensure that clk_en_sel bit is turned off */
  531. wmb();
  532. }
  533. int dsi_phy_hw_v4_0_wait_for_lane_idle(
  534. struct dsi_phy_hw *phy, u32 lanes)
  535. {
  536. int rc = 0, val = 0;
  537. u32 stop_state_mask = 0;
  538. u32 const sleep_us = 10;
  539. u32 const timeout_us = 100;
  540. bool split_link_enabled = dsi_phy_hw_v4_0_is_split_link_enabled(phy);
  541. stop_state_mask = BIT(4); /* clock lane */
  542. if (split_link_enabled)
  543. stop_state_mask |= BIT(5);
  544. if (lanes & DSI_DATA_LANE_0)
  545. stop_state_mask |= BIT(0);
  546. if (lanes & DSI_DATA_LANE_1)
  547. stop_state_mask |= BIT(1);
  548. if (lanes & DSI_DATA_LANE_2)
  549. stop_state_mask |= BIT(2);
  550. if (lanes & DSI_DATA_LANE_3)
  551. stop_state_mask |= BIT(3);
  552. DSI_PHY_DBG(phy, "polling for lanes to be in stop state, mask=0x%08x\n",
  553. stop_state_mask);
  554. rc = DSI_READ_POLL_TIMEOUT(phy, DSIPHY_CMN_LANE_STATUS1, val,
  555. ((val & stop_state_mask) == stop_state_mask),
  556. sleep_us, timeout_us);
  557. if (rc) {
  558. DSI_PHY_ERR(phy, "lanes not in stop state, LANE_STATUS=0x%08x\n",
  559. val);
  560. return rc;
  561. }
  562. return 0;
  563. }
  564. void dsi_phy_hw_v4_0_ulps_request(struct dsi_phy_hw *phy,
  565. struct dsi_phy_cfg *cfg, u32 lanes)
  566. {
  567. u32 reg = 0, sl_lane_ctrl1 = 0;
  568. if (lanes & DSI_CLOCK_LANE)
  569. reg = BIT(4);
  570. if (lanes & DSI_DATA_LANE_0)
  571. reg |= BIT(0);
  572. if (lanes & DSI_DATA_LANE_1)
  573. reg |= BIT(1);
  574. if (lanes & DSI_DATA_LANE_2)
  575. reg |= BIT(2);
  576. if (lanes & DSI_DATA_LANE_3)
  577. reg |= BIT(3);
  578. if (cfg->split_link.enabled)
  579. reg |= BIT(7);
  580. if (cfg->force_clk_lane_hs) {
  581. reg |= BIT(5) | BIT(6);
  582. if (cfg->split_link.enabled) {
  583. sl_lane_ctrl1 = DSI_R32(phy, DSIPHY_CMN_SL_DSI_LANE_CTRL1);
  584. sl_lane_ctrl1 |= BIT(2);
  585. DSI_W32(phy, DSIPHY_CMN_SL_DSI_LANE_CTRL1, sl_lane_ctrl1);
  586. }
  587. }
  588. /*
  589. * ULPS entry request. Wait for short time to make sure
  590. * that the lanes enter ULPS. Recommended as per HPG.
  591. */
  592. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL1, reg);
  593. usleep_range(100, 110);
  594. /* disable LPRX and CDRX */
  595. dsi_phy_hw_v4_0_config_lpcdrx(phy, cfg, false);
  596. DSI_PHY_DBG(phy, "ULPS requested for lanes 0x%x\n", lanes);
  597. }
  598. int dsi_phy_hw_v4_0_lane_reset(struct dsi_phy_hw *phy)
  599. {
  600. int ret = 0, loop = 10, u_dly = 200;
  601. u32 ln_status = 0;
  602. while ((ln_status != 0x1f) && loop) {
  603. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, 0x1f);
  604. wmb(); /* ensure register is committed */
  605. loop--;
  606. udelay(u_dly);
  607. ln_status = DSI_R32(phy, DSIPHY_CMN_LANE_STATUS1);
  608. DSI_PHY_DBG(phy, "trial no: %d\n", loop);
  609. }
  610. if (!loop)
  611. DSI_PHY_DBG(phy, "could not reset phy lanes\n");
  612. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, 0x0);
  613. wmb(); /* ensure register is committed */
  614. return ret;
  615. }
  616. void dsi_phy_hw_v4_0_ulps_exit(struct dsi_phy_hw *phy,
  617. struct dsi_phy_cfg *cfg, u32 lanes)
  618. {
  619. u32 reg = 0, sl_lane_ctrl1 = 0;
  620. if (lanes & DSI_CLOCK_LANE)
  621. reg = BIT(4);
  622. if (lanes & DSI_DATA_LANE_0)
  623. reg |= BIT(0);
  624. if (lanes & DSI_DATA_LANE_1)
  625. reg |= BIT(1);
  626. if (lanes & DSI_DATA_LANE_2)
  627. reg |= BIT(2);
  628. if (lanes & DSI_DATA_LANE_3)
  629. reg |= BIT(3);
  630. if (cfg->split_link.enabled)
  631. reg |= BIT(5);
  632. /* enable LPRX and CDRX */
  633. dsi_phy_hw_v4_0_config_lpcdrx(phy, cfg, true);
  634. /* ULPS exit request */
  635. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL2, reg);
  636. usleep_range(1000, 1010);
  637. /* Clear ULPS request flags on all lanes */
  638. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL1, 0);
  639. /* Clear ULPS exit flags on all lanes */
  640. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL2, 0);
  641. /*
  642. * Sometimes when exiting ULPS, it is possible that some DSI
  643. * lanes are not in the stop state which could lead to DSI
  644. * commands not going through. To avoid this, force the lanes
  645. * to be in stop state.
  646. */
  647. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, reg);
  648. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, 0);
  649. usleep_range(100, 110);
  650. if (cfg->force_clk_lane_hs) {
  651. reg = BIT(5) | BIT(6);
  652. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL1, reg);
  653. if (cfg->split_link.enabled) {
  654. sl_lane_ctrl1 = DSI_R32(phy, DSIPHY_CMN_SL_DSI_LANE_CTRL1);
  655. sl_lane_ctrl1 |= BIT(2);
  656. DSI_W32(phy, DSIPHY_CMN_SL_DSI_LANE_CTRL1, sl_lane_ctrl1);
  657. }
  658. }
  659. }
  660. u32 dsi_phy_hw_v4_0_get_lanes_in_ulps(struct dsi_phy_hw *phy)
  661. {
  662. u32 lanes = 0;
  663. lanes = DSI_R32(phy, DSIPHY_CMN_LANE_STATUS0);
  664. DSI_PHY_DBG(phy, "lanes in ulps = 0x%x\n", lanes);
  665. return lanes;
  666. }
  667. bool dsi_phy_hw_v4_0_is_lanes_in_ulps(u32 lanes, u32 ulps_lanes)
  668. {
  669. if (lanes & ulps_lanes)
  670. return false;
  671. return true;
  672. }
  673. int dsi_phy_hw_timing_val_v4_0(struct dsi_phy_per_lane_cfgs *timing_cfg,
  674. u32 *timing_val, u32 size)
  675. {
  676. int i = 0;
  677. if (size != DSI_PHY_TIMING_V4_SIZE) {
  678. DSI_ERR("Unexpected timing array size %d\n", size);
  679. return -EINVAL;
  680. }
  681. for (i = 0; i < size; i++)
  682. timing_cfg->lane_v4[i] = timing_val[i];
  683. return 0;
  684. }
  685. void dsi_phy_hw_v4_0_dyn_refresh_config(struct dsi_phy_hw *phy,
  686. struct dsi_phy_cfg *cfg, bool is_master)
  687. {
  688. u32 reg;
  689. u32 cmn_lane_ctrl0 = dsi_phy_hw_calc_cmn_lane_ctrl0(cfg);
  690. if (is_master) {
  691. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL19,
  692. DSIPHY_CMN_TIMING_CTRL_0, DSIPHY_CMN_TIMING_CTRL_1,
  693. cfg->timing.lane_v4[0], cfg->timing.lane_v4[1]);
  694. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL20,
  695. DSIPHY_CMN_TIMING_CTRL_2, DSIPHY_CMN_TIMING_CTRL_3,
  696. cfg->timing.lane_v4[2], cfg->timing.lane_v4[3]);
  697. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL21,
  698. DSIPHY_CMN_TIMING_CTRL_4, DSIPHY_CMN_TIMING_CTRL_5,
  699. cfg->timing.lane_v4[4], cfg->timing.lane_v4[5]);
  700. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL22,
  701. DSIPHY_CMN_TIMING_CTRL_6, DSIPHY_CMN_TIMING_CTRL_7,
  702. cfg->timing.lane_v4[6], cfg->timing.lane_v4[7]);
  703. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL23,
  704. DSIPHY_CMN_TIMING_CTRL_8, DSIPHY_CMN_TIMING_CTRL_9,
  705. cfg->timing.lane_v4[8], cfg->timing.lane_v4[9]);
  706. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL24,
  707. DSIPHY_CMN_TIMING_CTRL_10, DSIPHY_CMN_TIMING_CTRL_11,
  708. cfg->timing.lane_v4[10], cfg->timing.lane_v4[11]);
  709. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL25,
  710. DSIPHY_CMN_TIMING_CTRL_12, DSIPHY_CMN_TIMING_CTRL_13,
  711. cfg->timing.lane_v4[12], cfg->timing.lane_v4[13]);
  712. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL26,
  713. DSIPHY_CMN_CTRL_0, DSIPHY_CMN_LANE_CTRL0,
  714. 0x7f, cmn_lane_ctrl0);
  715. } else {
  716. reg = DSI_R32(phy, DSIPHY_CMN_CLK_CFG1);
  717. reg &= ~BIT(5);
  718. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL0,
  719. DSIPHY_CMN_CLK_CFG1, DSIPHY_CMN_PLL_CNTRL,
  720. reg, 0x0);
  721. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL1,
  722. DSIPHY_CMN_RBUF_CTRL, DSIPHY_CMN_TIMING_CTRL_0,
  723. 0x0, cfg->timing.lane_v4[0]);
  724. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL2,
  725. DSIPHY_CMN_TIMING_CTRL_1, DSIPHY_CMN_TIMING_CTRL_2,
  726. cfg->timing.lane_v4[1], cfg->timing.lane_v4[2]);
  727. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL3,
  728. DSIPHY_CMN_TIMING_CTRL_3, DSIPHY_CMN_TIMING_CTRL_4,
  729. cfg->timing.lane_v4[3], cfg->timing.lane_v4[4]);
  730. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL4,
  731. DSIPHY_CMN_TIMING_CTRL_5, DSIPHY_CMN_TIMING_CTRL_6,
  732. cfg->timing.lane_v4[5], cfg->timing.lane_v4[6]);
  733. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL5,
  734. DSIPHY_CMN_TIMING_CTRL_7, DSIPHY_CMN_TIMING_CTRL_8,
  735. cfg->timing.lane_v4[7], cfg->timing.lane_v4[8]);
  736. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL6,
  737. DSIPHY_CMN_TIMING_CTRL_9, DSIPHY_CMN_TIMING_CTRL_10,
  738. cfg->timing.lane_v4[9], cfg->timing.lane_v4[10]);
  739. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL7,
  740. DSIPHY_CMN_TIMING_CTRL_11, DSIPHY_CMN_TIMING_CTRL_12,
  741. cfg->timing.lane_v4[11], cfg->timing.lane_v4[12]);
  742. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL8,
  743. DSIPHY_CMN_TIMING_CTRL_13, DSIPHY_CMN_CTRL_0,
  744. cfg->timing.lane_v4[13], 0x7f);
  745. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL9,
  746. DSIPHY_CMN_LANE_CTRL0, DSIPHY_CMN_CTRL_2,
  747. cmn_lane_ctrl0, 0x40);
  748. /*
  749. * fill with dummy register writes since controller will blindly
  750. * send these values to DSI PHY.
  751. */
  752. reg = DSI_DYN_REFRESH_PLL_CTRL11;
  753. while (reg <= DSI_DYN_REFRESH_PLL_CTRL29) {
  754. DSI_DYN_REF_REG_W(phy->dyn_pll_base, reg,
  755. DSIPHY_CMN_LANE_CTRL0, DSIPHY_CMN_CTRL_0,
  756. cmn_lane_ctrl0, 0x7f);
  757. reg += 0x4;
  758. }
  759. DSI_GEN_W32(phy->dyn_pll_base,
  760. DSI_DYN_REFRESH_PLL_UPPER_ADDR, 0);
  761. DSI_GEN_W32(phy->dyn_pll_base,
  762. DSI_DYN_REFRESH_PLL_UPPER_ADDR2, 0);
  763. }
  764. wmb(); /* make sure all registers are updated */
  765. }
  766. void dsi_phy_hw_v4_0_dyn_refresh_pipe_delay(struct dsi_phy_hw *phy,
  767. struct dsi_dyn_clk_delay *delay)
  768. {
  769. if (!delay)
  770. return;
  771. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_PIPE_DELAY,
  772. delay->pipe_delay);
  773. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_PIPE_DELAY2,
  774. delay->pipe_delay2);
  775. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_DELAY,
  776. delay->pll_delay);
  777. }
  778. void dsi_phy_hw_v4_0_dyn_refresh_trigger_sel(struct dsi_phy_hw *phy,
  779. bool is_master)
  780. {
  781. u32 reg;
  782. /*
  783. * Dynamic refresh will take effect at next mdp flush event.
  784. * This makes sure that any update to frame timings together
  785. * with dfps will take effect in one vsync at next mdp flush.
  786. */
  787. if (is_master) {
  788. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  789. reg |= BIT(17);
  790. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  791. }
  792. }
  793. void dsi_phy_hw_v4_0_dyn_refresh_helper(struct dsi_phy_hw *phy, u32 offset)
  794. {
  795. u32 reg;
  796. /*
  797. * if no offset is mentioned then this means we want to clear
  798. * the dynamic refresh ctrl register which is the last step
  799. * of dynamic refresh sequence.
  800. */
  801. if (!offset) {
  802. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  803. reg &= ~(BIT(0) | BIT(8) | BIT(13) | BIT(16) | BIT(17));
  804. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  805. wmb(); /* ensure dynamic fps is cleared */
  806. return;
  807. }
  808. if (offset & BIT(DYN_REFRESH_INTF_SEL)) {
  809. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  810. reg |= BIT(13);
  811. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  812. }
  813. if (offset & BIT(DYN_REFRESH_SYNC_MODE)) {
  814. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  815. reg |= BIT(16);
  816. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  817. }
  818. if (offset & BIT(DYN_REFRESH_SWI_CTRL)) {
  819. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  820. reg |= BIT(0);
  821. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  822. }
  823. if (offset & BIT(DYN_REFRESH_SW_TRIGGER)) {
  824. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  825. reg |= BIT(8);
  826. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  827. wmb(); /* ensure dynamic fps is triggered */
  828. }
  829. }
  830. int dsi_phy_hw_v4_0_cache_phy_timings(struct dsi_phy_per_lane_cfgs *timings,
  831. u32 *dst, u32 size)
  832. {
  833. int i;
  834. if (!timings || !dst || !size)
  835. return -EINVAL;
  836. if (size != DSI_PHY_TIMING_V4_SIZE) {
  837. DSI_ERR("size mis-match\n");
  838. return -EINVAL;
  839. }
  840. for (i = 0; i < size; i++)
  841. dst[i] = timings->lane_v4[i];
  842. return 0;
  843. }
  844. void dsi_phy_hw_v4_0_set_continuous_clk(struct dsi_phy_hw *phy, bool enable)
  845. {
  846. u32 reg = 0, sl_lane_ctrl1 = 0;
  847. bool is_split_link_enabled = dsi_phy_hw_v4_0_is_split_link_enabled(phy);
  848. reg = DSI_R32(phy, DSIPHY_CMN_LANE_CTRL1);
  849. if (enable)
  850. reg |= BIT(5) | BIT(6);
  851. else
  852. reg &= ~(BIT(5) | BIT(6));
  853. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL1, reg);
  854. if (is_split_link_enabled) {
  855. sl_lane_ctrl1 = DSI_R32(phy, DSIPHY_CMN_SL_DSI_LANE_CTRL1);
  856. if (enable)
  857. sl_lane_ctrl1 |= BIT(2);
  858. else
  859. sl_lane_ctrl1 &= ~BIT(2);
  860. DSI_W32(phy, DSIPHY_CMN_SL_DSI_LANE_CTRL1, sl_lane_ctrl1);
  861. }
  862. wmb(); /* make sure request is set */
  863. }