dsi_phy_hw_v4_0.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2019, 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. /* n = 0..3 for data lanes and n = 4 for clock lane */
  62. #define DSIPHY_LNX_CFG0(n) (0x200 + (0x80 * (n)))
  63. #define DSIPHY_LNX_CFG1(n) (0x204 + (0x80 * (n)))
  64. #define DSIPHY_LNX_CFG2(n) (0x208 + (0x80 * (n)))
  65. #define DSIPHY_LNX_TEST_DATAPATH(n) (0x20C + (0x80 * (n)))
  66. #define DSIPHY_LNX_PIN_SWAP(n) (0x210 + (0x80 * (n)))
  67. #define DSIPHY_LNX_LPRX_CTRL(n) (0x214 + (0x80 * (n)))
  68. #define DSIPHY_LNX_TX_DCTRL(n) (0x218 + (0x80 * (n)))
  69. /* dynamic refresh control registers */
  70. #define DSI_DYN_REFRESH_CTRL (0x000)
  71. #define DSI_DYN_REFRESH_PIPE_DELAY (0x004)
  72. #define DSI_DYN_REFRESH_PIPE_DELAY2 (0x008)
  73. #define DSI_DYN_REFRESH_PLL_DELAY (0x00C)
  74. #define DSI_DYN_REFRESH_STATUS (0x010)
  75. #define DSI_DYN_REFRESH_PLL_CTRL0 (0x014)
  76. #define DSI_DYN_REFRESH_PLL_CTRL1 (0x018)
  77. #define DSI_DYN_REFRESH_PLL_CTRL2 (0x01C)
  78. #define DSI_DYN_REFRESH_PLL_CTRL3 (0x020)
  79. #define DSI_DYN_REFRESH_PLL_CTRL4 (0x024)
  80. #define DSI_DYN_REFRESH_PLL_CTRL5 (0x028)
  81. #define DSI_DYN_REFRESH_PLL_CTRL6 (0x02C)
  82. #define DSI_DYN_REFRESH_PLL_CTRL7 (0x030)
  83. #define DSI_DYN_REFRESH_PLL_CTRL8 (0x034)
  84. #define DSI_DYN_REFRESH_PLL_CTRL9 (0x038)
  85. #define DSI_DYN_REFRESH_PLL_CTRL10 (0x03C)
  86. #define DSI_DYN_REFRESH_PLL_CTRL11 (0x040)
  87. #define DSI_DYN_REFRESH_PLL_CTRL12 (0x044)
  88. #define DSI_DYN_REFRESH_PLL_CTRL13 (0x048)
  89. #define DSI_DYN_REFRESH_PLL_CTRL14 (0x04C)
  90. #define DSI_DYN_REFRESH_PLL_CTRL15 (0x050)
  91. #define DSI_DYN_REFRESH_PLL_CTRL16 (0x054)
  92. #define DSI_DYN_REFRESH_PLL_CTRL17 (0x058)
  93. #define DSI_DYN_REFRESH_PLL_CTRL18 (0x05C)
  94. #define DSI_DYN_REFRESH_PLL_CTRL19 (0x060)
  95. #define DSI_DYN_REFRESH_PLL_CTRL20 (0x064)
  96. #define DSI_DYN_REFRESH_PLL_CTRL21 (0x068)
  97. #define DSI_DYN_REFRESH_PLL_CTRL22 (0x06C)
  98. #define DSI_DYN_REFRESH_PLL_CTRL23 (0x070)
  99. #define DSI_DYN_REFRESH_PLL_CTRL24 (0x074)
  100. #define DSI_DYN_REFRESH_PLL_CTRL25 (0x078)
  101. #define DSI_DYN_REFRESH_PLL_CTRL26 (0x07C)
  102. #define DSI_DYN_REFRESH_PLL_CTRL27 (0x080)
  103. #define DSI_DYN_REFRESH_PLL_CTRL28 (0x084)
  104. #define DSI_DYN_REFRESH_PLL_CTRL29 (0x088)
  105. #define DSI_DYN_REFRESH_PLL_CTRL30 (0x08C)
  106. #define DSI_DYN_REFRESH_PLL_CTRL31 (0x090)
  107. #define DSI_DYN_REFRESH_PLL_UPPER_ADDR (0x094)
  108. #define DSI_DYN_REFRESH_PLL_UPPER_ADDR2 (0x098)
  109. static int dsi_phy_hw_v4_0_is_pll_on(struct dsi_phy_hw *phy)
  110. {
  111. u32 data = 0;
  112. data = DSI_R32(phy, DSIPHY_CMN_PLL_CNTRL);
  113. mb(); /*make sure read happened */
  114. return (data & BIT(0));
  115. }
  116. static void dsi_phy_hw_v4_0_config_lpcdrx(struct dsi_phy_hw *phy,
  117. struct dsi_phy_cfg *cfg, bool enable)
  118. {
  119. int phy_lane_0 = dsi_phy_conv_logical_to_phy_lane(&cfg->lane_map,
  120. DSI_LOGICAL_LANE_0);
  121. /*
  122. * LPRX and CDRX need to enabled only for physical data lane
  123. * corresponding to the logical data lane 0
  124. */
  125. if (enable)
  126. DSI_W32(phy, DSIPHY_LNX_LPRX_CTRL(phy_lane_0),
  127. cfg->strength.lane[phy_lane_0][1]);
  128. else
  129. DSI_W32(phy, DSIPHY_LNX_LPRX_CTRL(phy_lane_0), 0);
  130. }
  131. static void dsi_phy_hw_v4_0_lane_swap_config(struct dsi_phy_hw *phy,
  132. struct dsi_lane_map *lane_map)
  133. {
  134. DSI_W32(phy, DSIPHY_CMN_LANE_CFG0,
  135. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_0] |
  136. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_1] << 4)));
  137. DSI_W32(phy, DSIPHY_CMN_LANE_CFG1,
  138. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_2] |
  139. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_3] << 4)));
  140. }
  141. static void dsi_phy_hw_v4_0_lane_settings(struct dsi_phy_hw *phy,
  142. struct dsi_phy_cfg *cfg)
  143. {
  144. int i;
  145. u8 tx_dctrl_v4[] = {0x00, 0x00, 0x00, 0x04, 0x01};
  146. u8 tx_dctrl_v4_1[] = {0x40, 0x40, 0x40, 0x46, 0x41};
  147. u8 *tx_dctrl;
  148. if (phy->version == DSI_PHY_VERSION_4_1)
  149. tx_dctrl = &tx_dctrl_v4_1[0];
  150. else
  151. tx_dctrl = &tx_dctrl_v4[0];
  152. /* Strength ctrl settings */
  153. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++) {
  154. /*
  155. * Disable LPRX and CDRX for all lanes. And later on, it will
  156. * be only enabled for the physical data lane corresponding
  157. * to the logical data lane 0
  158. */
  159. DSI_W32(phy, DSIPHY_LNX_LPRX_CTRL(i), 0);
  160. DSI_W32(phy, DSIPHY_LNX_PIN_SWAP(i), 0x0);
  161. }
  162. dsi_phy_hw_v4_0_config_lpcdrx(phy, cfg, true);
  163. /* other settings */
  164. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++) {
  165. DSI_W32(phy, DSIPHY_LNX_CFG0(i), cfg->lanecfg.lane[i][0]);
  166. DSI_W32(phy, DSIPHY_LNX_CFG1(i), cfg->lanecfg.lane[i][1]);
  167. DSI_W32(phy, DSIPHY_LNX_CFG2(i), cfg->lanecfg.lane[i][2]);
  168. DSI_W32(phy, DSIPHY_LNX_TX_DCTRL(i), tx_dctrl[i]);
  169. }
  170. }
  171. /**
  172. * enable() - Enable PHY hardware
  173. * @phy: Pointer to DSI PHY hardware object.
  174. * @cfg: Per lane configurations for timing, strength and lane
  175. * configurations.
  176. */
  177. void dsi_phy_hw_v4_0_enable(struct dsi_phy_hw *phy,
  178. struct dsi_phy_cfg *cfg)
  179. {
  180. int rc = 0;
  181. u32 status;
  182. u32 const delay_us = 5;
  183. u32 const timeout_us = 1000;
  184. struct dsi_phy_per_lane_cfgs *timing = &cfg->timing;
  185. u32 data;
  186. u32 minor_ver = 0;
  187. bool less_than_1500_mhz = false;
  188. u32 vreg_ctrl_0 = 0;
  189. u32 glbl_str_swi_cal_sel_ctrl = 0;
  190. u32 glbl_hstx_str_ctrl_0 = 0;
  191. u32 glbl_rescode_top_ctrl = 0;
  192. u32 glbl_rescode_bot_ctrl = 0;
  193. if (dsi_phy_hw_v4_0_is_pll_on(phy))
  194. DSI_PHY_WARN(phy, "PLL turned on before configuring PHY\n");
  195. /* wait for REFGEN READY */
  196. rc = readl_poll_timeout_atomic(phy->base + DSIPHY_CMN_PHY_STATUS,
  197. status, (status & BIT(0)), delay_us, timeout_us);
  198. if (rc) {
  199. DSI_PHY_ERR(phy, "Ref gen not ready. Aborting\n");
  200. return;
  201. }
  202. /* Alter PHY configurations if data rate less than 1.5GHZ*/
  203. if (cfg->bit_clk_rate_hz <= 1500000000)
  204. less_than_1500_mhz = true;
  205. if (phy->version == DSI_PHY_VERSION_4_1) {
  206. vreg_ctrl_0 = less_than_1500_mhz ? 0x53 : 0x52;
  207. glbl_rescode_top_ctrl = less_than_1500_mhz ? 0x3d : 0x00;
  208. glbl_rescode_bot_ctrl = less_than_1500_mhz ? 0x39 : 0x3c;
  209. glbl_str_swi_cal_sel_ctrl = 0x00;
  210. glbl_hstx_str_ctrl_0 = 0x88;
  211. } else {
  212. vreg_ctrl_0 = less_than_1500_mhz ? 0x5B : 0x59;
  213. glbl_str_swi_cal_sel_ctrl = less_than_1500_mhz ? 0x03 : 0x00;
  214. glbl_hstx_str_ctrl_0 = less_than_1500_mhz ? 0x66 : 0x88;
  215. glbl_rescode_top_ctrl = 0x03;
  216. glbl_rescode_bot_ctrl = 0x3c;
  217. }
  218. /* de-assert digital and pll power down */
  219. data = BIT(6) | BIT(5);
  220. DSI_W32(phy, DSIPHY_CMN_CTRL_0, data);
  221. /* Assert PLL core reset */
  222. DSI_W32(phy, DSIPHY_CMN_PLL_CNTRL, 0x00);
  223. /* turn off resync FIFO */
  224. DSI_W32(phy, DSIPHY_CMN_RBUF_CTRL, 0x00);
  225. /* program CMN_CTRL_4 for minor_ver 2 chipsets*/
  226. minor_ver = DSI_R32(phy, DSIPHY_CMN_REVISION_ID0);
  227. minor_ver = minor_ver & (0xf0);
  228. if (minor_ver == 0x20)
  229. DSI_W32(phy, DSIPHY_CMN_CTRL_4, 0x04);
  230. /* Configure PHY lane swap */
  231. dsi_phy_hw_v4_0_lane_swap_config(phy, &cfg->lane_map);
  232. /* Enable LDO */
  233. DSI_W32(phy, DSIPHY_CMN_VREG_CTRL_0, vreg_ctrl_0);
  234. DSI_W32(phy, DSIPHY_CMN_VREG_CTRL_1, 0x5c);
  235. DSI_W32(phy, DSIPHY_CMN_CTRL_3, 0x00);
  236. DSI_W32(phy, DSIPHY_CMN_GLBL_STR_SWI_CAL_SEL_CTRL,
  237. glbl_str_swi_cal_sel_ctrl);
  238. DSI_W32(phy, DSIPHY_CMN_GLBL_HSTX_STR_CTRL_0, glbl_hstx_str_ctrl_0);
  239. DSI_W32(phy, DSIPHY_CMN_GLBL_PEMPH_CTRL_0, 0x00);
  240. DSI_W32(phy, DSIPHY_CMN_GLBL_RESCODE_OFFSET_TOP_CTRL,
  241. glbl_rescode_top_ctrl);
  242. DSI_W32(phy, DSIPHY_CMN_GLBL_RESCODE_OFFSET_BOT_CTRL,
  243. glbl_rescode_bot_ctrl);
  244. DSI_W32(phy, DSIPHY_CMN_GLBL_LPTX_STR_CTRL, 0x55);
  245. /* Remove power down from all blocks */
  246. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0x7f);
  247. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL0, 0x1F);
  248. /* Select full-rate mode */
  249. DSI_W32(phy, DSIPHY_CMN_CTRL_2, 0x40);
  250. switch (cfg->pll_source) {
  251. case DSI_PLL_SOURCE_STANDALONE:
  252. case DSI_PLL_SOURCE_NATIVE:
  253. data = 0x0; /* internal PLL */
  254. break;
  255. case DSI_PLL_SOURCE_NON_NATIVE:
  256. data = 0x1; /* external PLL */
  257. break;
  258. default:
  259. break;
  260. }
  261. DSI_W32(phy, DSIPHY_CMN_CLK_CFG1, (data << 2)); /* set PLL src */
  262. /* DSI PHY timings */
  263. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_0, timing->lane_v4[0]);
  264. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_1, timing->lane_v4[1]);
  265. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_2, timing->lane_v4[2]);
  266. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_3, timing->lane_v4[3]);
  267. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_4, timing->lane_v4[4]);
  268. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_5, timing->lane_v4[5]);
  269. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_6, timing->lane_v4[6]);
  270. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_7, timing->lane_v4[7]);
  271. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_8, timing->lane_v4[8]);
  272. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_9, timing->lane_v4[9]);
  273. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_10, timing->lane_v4[10]);
  274. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_11, timing->lane_v4[11]);
  275. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_12, timing->lane_v4[12]);
  276. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_13, timing->lane_v4[13]);
  277. /* DSI lane settings */
  278. dsi_phy_hw_v4_0_lane_settings(phy, cfg);
  279. DSI_PHY_DBG(phy, "Phy enabled\n");
  280. }
  281. /**
  282. * disable() - Disable PHY hardware
  283. * @phy: Pointer to DSI PHY hardware object.
  284. */
  285. void dsi_phy_hw_v4_0_disable(struct dsi_phy_hw *phy,
  286. struct dsi_phy_cfg *cfg)
  287. {
  288. u32 data = 0;
  289. if (dsi_phy_hw_v4_0_is_pll_on(phy))
  290. DSI_PHY_WARN(phy, "Turning OFF PHY while PLL is on\n");
  291. dsi_phy_hw_v4_0_config_lpcdrx(phy, cfg, false);
  292. data = DSI_R32(phy, DSIPHY_CMN_CTRL_0);
  293. /* disable all lanes */
  294. data &= ~0x1F;
  295. DSI_W32(phy, DSIPHY_CMN_CTRL_0, data);
  296. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL0, 0);
  297. /* Turn off all PHY blocks */
  298. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0x00);
  299. /* make sure phy is turned off */
  300. wmb();
  301. DSI_PHY_DBG(phy, "Phy disabled\n");
  302. }
  303. void dsi_phy_hw_v4_0_toggle_resync_fifo(struct dsi_phy_hw *phy)
  304. {
  305. DSI_W32(phy, DSIPHY_CMN_RBUF_CTRL, 0x00);
  306. /* ensure that the FIFO is off */
  307. wmb();
  308. DSI_W32(phy, DSIPHY_CMN_RBUF_CTRL, 0x1);
  309. /* ensure that the FIFO is toggled back on */
  310. wmb();
  311. }
  312. void dsi_phy_hw_v4_0_reset_clk_en_sel(struct dsi_phy_hw *phy)
  313. {
  314. u32 data = 0;
  315. /*Turning off CLK_EN_SEL after retime buffer sync */
  316. data = DSI_R32(phy, DSIPHY_CMN_CLK_CFG1);
  317. data &= ~BIT(4);
  318. DSI_W32(phy, DSIPHY_CMN_CLK_CFG1, data);
  319. /* ensure that clk_en_sel bit is turned off */
  320. wmb();
  321. }
  322. int dsi_phy_hw_v4_0_wait_for_lane_idle(
  323. struct dsi_phy_hw *phy, u32 lanes)
  324. {
  325. int rc = 0, val = 0;
  326. u32 stop_state_mask = 0;
  327. u32 const sleep_us = 10;
  328. u32 const timeout_us = 100;
  329. stop_state_mask = BIT(4); /* clock lane */
  330. if (lanes & DSI_DATA_LANE_0)
  331. stop_state_mask |= BIT(0);
  332. if (lanes & DSI_DATA_LANE_1)
  333. stop_state_mask |= BIT(1);
  334. if (lanes & DSI_DATA_LANE_2)
  335. stop_state_mask |= BIT(2);
  336. if (lanes & DSI_DATA_LANE_3)
  337. stop_state_mask |= BIT(3);
  338. DSI_PHY_DBG(phy, "polling for lanes to be in stop state, mask=0x%08x\n",
  339. stop_state_mask);
  340. rc = readl_poll_timeout(phy->base + DSIPHY_CMN_LANE_STATUS1, val,
  341. ((val & stop_state_mask) == stop_state_mask),
  342. sleep_us, timeout_us);
  343. if (rc) {
  344. DSI_PHY_ERR(phy, "lanes not in stop state, LANE_STATUS=0x%08x\n",
  345. val);
  346. return rc;
  347. }
  348. return 0;
  349. }
  350. void dsi_phy_hw_v4_0_ulps_request(struct dsi_phy_hw *phy,
  351. struct dsi_phy_cfg *cfg, u32 lanes)
  352. {
  353. u32 reg = 0;
  354. if (lanes & DSI_CLOCK_LANE)
  355. reg = BIT(4);
  356. if (lanes & DSI_DATA_LANE_0)
  357. reg |= BIT(0);
  358. if (lanes & DSI_DATA_LANE_1)
  359. reg |= BIT(1);
  360. if (lanes & DSI_DATA_LANE_2)
  361. reg |= BIT(2);
  362. if (lanes & DSI_DATA_LANE_3)
  363. reg |= BIT(3);
  364. if (cfg->force_clk_lane_hs)
  365. reg |= BIT(5) | BIT(6);
  366. /*
  367. * ULPS entry request. Wait for short time to make sure
  368. * that the lanes enter ULPS. Recommended as per HPG.
  369. */
  370. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL1, reg);
  371. usleep_range(100, 110);
  372. /* disable LPRX and CDRX */
  373. dsi_phy_hw_v4_0_config_lpcdrx(phy, cfg, false);
  374. DSI_PHY_DBG(phy, "ULPS requested for lanes 0x%x\n", lanes);
  375. }
  376. int dsi_phy_hw_v4_0_lane_reset(struct dsi_phy_hw *phy)
  377. {
  378. int ret = 0, loop = 10, u_dly = 200;
  379. u32 ln_status = 0;
  380. while ((ln_status != 0x1f) && loop) {
  381. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, 0x1f);
  382. wmb(); /* ensure register is committed */
  383. loop--;
  384. udelay(u_dly);
  385. ln_status = DSI_R32(phy, DSIPHY_CMN_LANE_STATUS1);
  386. DSI_PHY_DBG(phy, "trial no: %d\n", loop);
  387. }
  388. if (!loop)
  389. DSI_PHY_DBG(phy, "could not reset phy lanes\n");
  390. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, 0x0);
  391. wmb(); /* ensure register is committed */
  392. return ret;
  393. }
  394. void dsi_phy_hw_v4_0_ulps_exit(struct dsi_phy_hw *phy,
  395. struct dsi_phy_cfg *cfg, u32 lanes)
  396. {
  397. u32 reg = 0;
  398. if (lanes & DSI_CLOCK_LANE)
  399. reg = BIT(4);
  400. if (lanes & DSI_DATA_LANE_0)
  401. reg |= BIT(0);
  402. if (lanes & DSI_DATA_LANE_1)
  403. reg |= BIT(1);
  404. if (lanes & DSI_DATA_LANE_2)
  405. reg |= BIT(2);
  406. if (lanes & DSI_DATA_LANE_3)
  407. reg |= BIT(3);
  408. /* enable LPRX and CDRX */
  409. dsi_phy_hw_v4_0_config_lpcdrx(phy, cfg, true);
  410. /* ULPS exit request */
  411. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL2, reg);
  412. usleep_range(1000, 1010);
  413. /* Clear ULPS request flags on all lanes */
  414. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL1, 0);
  415. /* Clear ULPS exit flags on all lanes */
  416. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL2, 0);
  417. /*
  418. * Sometimes when exiting ULPS, it is possible that some DSI
  419. * lanes are not in the stop state which could lead to DSI
  420. * commands not going through. To avoid this, force the lanes
  421. * to be in stop state.
  422. */
  423. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, reg);
  424. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, 0);
  425. usleep_range(100, 110);
  426. if (cfg->force_clk_lane_hs) {
  427. reg = BIT(5) | BIT(6);
  428. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL1, reg);
  429. }
  430. }
  431. u32 dsi_phy_hw_v4_0_get_lanes_in_ulps(struct dsi_phy_hw *phy)
  432. {
  433. u32 lanes = 0;
  434. lanes = DSI_R32(phy, DSIPHY_CMN_LANE_STATUS0);
  435. DSI_PHY_DBG(phy, "lanes in ulps = 0x%x\n", lanes);
  436. return lanes;
  437. }
  438. bool dsi_phy_hw_v4_0_is_lanes_in_ulps(u32 lanes, u32 ulps_lanes)
  439. {
  440. if (lanes & ulps_lanes)
  441. return false;
  442. return true;
  443. }
  444. int dsi_phy_hw_timing_val_v4_0(struct dsi_phy_per_lane_cfgs *timing_cfg,
  445. u32 *timing_val, u32 size)
  446. {
  447. int i = 0;
  448. if (size != DSI_PHY_TIMING_V4_SIZE) {
  449. DSI_ERR("Unexpected timing array size %d\n", size);
  450. return -EINVAL;
  451. }
  452. for (i = 0; i < size; i++)
  453. timing_cfg->lane_v4[i] = timing_val[i];
  454. return 0;
  455. }
  456. void dsi_phy_hw_v4_0_dyn_refresh_config(struct dsi_phy_hw *phy,
  457. struct dsi_phy_cfg *cfg, bool is_master)
  458. {
  459. u32 reg;
  460. if (is_master) {
  461. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL19,
  462. DSIPHY_CMN_TIMING_CTRL_0, DSIPHY_CMN_TIMING_CTRL_1,
  463. cfg->timing.lane_v4[0], cfg->timing.lane_v4[1]);
  464. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL20,
  465. DSIPHY_CMN_TIMING_CTRL_2, DSIPHY_CMN_TIMING_CTRL_3,
  466. cfg->timing.lane_v4[2], cfg->timing.lane_v4[3]);
  467. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL21,
  468. DSIPHY_CMN_TIMING_CTRL_4, DSIPHY_CMN_TIMING_CTRL_5,
  469. cfg->timing.lane_v4[4], cfg->timing.lane_v4[5]);
  470. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL22,
  471. DSIPHY_CMN_TIMING_CTRL_6, DSIPHY_CMN_TIMING_CTRL_7,
  472. cfg->timing.lane_v4[6], cfg->timing.lane_v4[7]);
  473. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL23,
  474. DSIPHY_CMN_TIMING_CTRL_8, DSIPHY_CMN_TIMING_CTRL_9,
  475. cfg->timing.lane_v4[8], cfg->timing.lane_v4[9]);
  476. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL24,
  477. DSIPHY_CMN_TIMING_CTRL_10, DSIPHY_CMN_TIMING_CTRL_11,
  478. cfg->timing.lane_v4[10], cfg->timing.lane_v4[11]);
  479. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL25,
  480. DSIPHY_CMN_TIMING_CTRL_12, DSIPHY_CMN_TIMING_CTRL_13,
  481. cfg->timing.lane_v4[12], cfg->timing.lane_v4[13]);
  482. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL26,
  483. DSIPHY_CMN_CTRL_0, DSIPHY_CMN_LANE_CTRL0,
  484. 0x7f, 0x1f);
  485. } else {
  486. reg = DSI_R32(phy, DSIPHY_CMN_CLK_CFG1);
  487. reg &= ~BIT(5);
  488. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL0,
  489. DSIPHY_CMN_CLK_CFG1, DSIPHY_CMN_PLL_CNTRL,
  490. reg, 0x0);
  491. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL1,
  492. DSIPHY_CMN_RBUF_CTRL, DSIPHY_CMN_TIMING_CTRL_0,
  493. 0x0, cfg->timing.lane_v4[0]);
  494. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL2,
  495. DSIPHY_CMN_TIMING_CTRL_1, DSIPHY_CMN_TIMING_CTRL_2,
  496. cfg->timing.lane_v4[1], cfg->timing.lane_v4[2]);
  497. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL3,
  498. DSIPHY_CMN_TIMING_CTRL_3, DSIPHY_CMN_TIMING_CTRL_4,
  499. cfg->timing.lane_v4[3], cfg->timing.lane_v4[4]);
  500. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL4,
  501. DSIPHY_CMN_TIMING_CTRL_5, DSIPHY_CMN_TIMING_CTRL_6,
  502. cfg->timing.lane_v4[5], cfg->timing.lane_v4[6]);
  503. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL5,
  504. DSIPHY_CMN_TIMING_CTRL_7, DSIPHY_CMN_TIMING_CTRL_8,
  505. cfg->timing.lane_v4[7], cfg->timing.lane_v4[8]);
  506. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL6,
  507. DSIPHY_CMN_TIMING_CTRL_9, DSIPHY_CMN_TIMING_CTRL_10,
  508. cfg->timing.lane_v4[9], cfg->timing.lane_v4[10]);
  509. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL7,
  510. DSIPHY_CMN_TIMING_CTRL_11, DSIPHY_CMN_TIMING_CTRL_12,
  511. cfg->timing.lane_v4[11], cfg->timing.lane_v4[12]);
  512. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL8,
  513. DSIPHY_CMN_TIMING_CTRL_13, DSIPHY_CMN_CTRL_0,
  514. cfg->timing.lane_v4[13], 0x7f);
  515. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL9,
  516. DSIPHY_CMN_LANE_CTRL0, DSIPHY_CMN_CTRL_2,
  517. 0x1f, 0x40);
  518. /*
  519. * fill with dummy register writes since controller will blindly
  520. * send these values to DSI PHY.
  521. */
  522. reg = DSI_DYN_REFRESH_PLL_CTRL11;
  523. while (reg <= DSI_DYN_REFRESH_PLL_CTRL29) {
  524. DSI_DYN_REF_REG_W(phy->dyn_pll_base, reg,
  525. DSIPHY_CMN_LANE_CTRL0, DSIPHY_CMN_CTRL_0,
  526. 0x1f, 0x7f);
  527. reg += 0x4;
  528. }
  529. DSI_GEN_W32(phy->dyn_pll_base,
  530. DSI_DYN_REFRESH_PLL_UPPER_ADDR, 0);
  531. DSI_GEN_W32(phy->dyn_pll_base,
  532. DSI_DYN_REFRESH_PLL_UPPER_ADDR2, 0);
  533. }
  534. wmb(); /* make sure all registers are updated */
  535. }
  536. void dsi_phy_hw_v4_0_dyn_refresh_pipe_delay(struct dsi_phy_hw *phy,
  537. struct dsi_dyn_clk_delay *delay)
  538. {
  539. if (!delay)
  540. return;
  541. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_PIPE_DELAY,
  542. delay->pipe_delay);
  543. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_PIPE_DELAY2,
  544. delay->pipe_delay2);
  545. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_DELAY,
  546. delay->pll_delay);
  547. }
  548. void dsi_phy_hw_v4_0_dyn_refresh_helper(struct dsi_phy_hw *phy, u32 offset)
  549. {
  550. u32 reg;
  551. /*
  552. * if no offset is mentioned then this means we want to clear
  553. * the dynamic refresh ctrl register which is the last step
  554. * of dynamic refresh sequence.
  555. */
  556. if (!offset) {
  557. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  558. reg &= ~(BIT(0) | BIT(8));
  559. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  560. wmb(); /* ensure dynamic fps is cleared */
  561. return;
  562. }
  563. if (offset & BIT(DYN_REFRESH_INTF_SEL)) {
  564. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  565. reg |= BIT(13);
  566. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  567. }
  568. if (offset & BIT(DYN_REFRESH_SYNC_MODE)) {
  569. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  570. reg |= BIT(16);
  571. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  572. }
  573. if (offset & BIT(DYN_REFRESH_SWI_CTRL)) {
  574. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  575. reg |= BIT(0);
  576. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  577. }
  578. if (offset & BIT(DYN_REFRESH_SW_TRIGGER)) {
  579. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  580. reg |= BIT(8);
  581. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  582. wmb(); /* ensure dynamic fps is triggered */
  583. }
  584. }
  585. int dsi_phy_hw_v4_0_cache_phy_timings(struct dsi_phy_per_lane_cfgs *timings,
  586. u32 *dst, u32 size)
  587. {
  588. int i;
  589. if (!timings || !dst || !size)
  590. return -EINVAL;
  591. if (size != DSI_PHY_TIMING_V4_SIZE) {
  592. DSI_ERR("size mis-match\n");
  593. return -EINVAL;
  594. }
  595. for (i = 0; i < size; i++)
  596. dst[i] = timings->lane_v4[i];
  597. return 0;
  598. }
  599. void dsi_phy_hw_v4_0_set_continuous_clk(struct dsi_phy_hw *phy, bool enable)
  600. {
  601. u32 reg = 0;
  602. reg = DSI_R32(phy, DSIPHY_CMN_LANE_CTRL1);
  603. if (enable)
  604. reg |= BIT(5) | BIT(6);
  605. else
  606. reg &= ~(BIT(5) | BIT(6));
  607. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL1, reg);
  608. wmb(); /* make sure request is set */
  609. }