dsi_phy_hw_v3_0.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #define pr_fmt(fmt) "dsi-phy-hw:" fmt
  6. #include <linux/math64.h>
  7. #include <linux/delay.h>
  8. #include <linux/iopoll.h>
  9. #include "dsi_hw.h"
  10. #include "dsi_phy_hw.h"
  11. #include "dsi_catalog.h"
  12. #define DSIPHY_CMN_CLK_CFG0 0x010
  13. #define DSIPHY_CMN_CLK_CFG1 0x014
  14. #define DSIPHY_CMN_GLBL_CTRL 0x018
  15. #define DSIPHY_CMN_RBUF_CTRL 0x01C
  16. #define DSIPHY_CMN_VREG_CTRL 0x020
  17. #define DSIPHY_CMN_CTRL_0 0x024
  18. #define DSIPHY_CMN_CTRL_1 0x028
  19. #define DSIPHY_CMN_CTRL_2 0x02C
  20. #define DSIPHY_CMN_LANE_CFG0 0x030
  21. #define DSIPHY_CMN_LANE_CFG1 0x034
  22. #define DSIPHY_CMN_PLL_CNTRL 0x038
  23. #define DSIPHY_CMN_LANE_CTRL0 0x098
  24. #define DSIPHY_CMN_LANE_CTRL1 0x09C
  25. #define DSIPHY_CMN_LANE_CTRL2 0x0A0
  26. #define DSIPHY_CMN_LANE_CTRL3 0x0A4
  27. #define DSIPHY_CMN_LANE_CTRL4 0x0A8
  28. #define DSIPHY_CMN_TIMING_CTRL_0 0x0AC
  29. #define DSIPHY_CMN_TIMING_CTRL_1 0x0B0
  30. #define DSIPHY_CMN_TIMING_CTRL_2 0x0B4
  31. #define DSIPHY_CMN_TIMING_CTRL_3 0x0B8
  32. #define DSIPHY_CMN_TIMING_CTRL_4 0x0BC
  33. #define DSIPHY_CMN_TIMING_CTRL_5 0x0C0
  34. #define DSIPHY_CMN_TIMING_CTRL_6 0x0C4
  35. #define DSIPHY_CMN_TIMING_CTRL_7 0x0C8
  36. #define DSIPHY_CMN_TIMING_CTRL_8 0x0CC
  37. #define DSIPHY_CMN_TIMING_CTRL_9 0x0D0
  38. #define DSIPHY_CMN_TIMING_CTRL_10 0x0D4
  39. #define DSIPHY_CMN_TIMING_CTRL_11 0x0D8
  40. #define DSIPHY_CMN_PHY_STATUS 0x0EC
  41. #define DSIPHY_CMN_LANE_STATUS0 0x0F4
  42. #define DSIPHY_CMN_LANE_STATUS1 0x0F8
  43. /* n = 0..3 for data lanes and n = 4 for clock lane */
  44. #define DSIPHY_LNX_CFG0(n) (0x200 + (0x80 * (n)))
  45. #define DSIPHY_LNX_CFG1(n) (0x204 + (0x80 * (n)))
  46. #define DSIPHY_LNX_CFG2(n) (0x208 + (0x80 * (n)))
  47. #define DSIPHY_LNX_CFG3(n) (0x20C + (0x80 * (n)))
  48. #define DSIPHY_LNX_TEST_DATAPATH(n) (0x210 + (0x80 * (n)))
  49. #define DSIPHY_LNX_PIN_SWAP(n) (0x214 + (0x80 * (n)))
  50. #define DSIPHY_LNX_HSTX_STR_CTRL(n) (0x218 + (0x80 * (n)))
  51. #define DSIPHY_LNX_OFFSET_TOP_CTRL(n) (0x21C + (0x80 * (n)))
  52. #define DSIPHY_LNX_OFFSET_BOT_CTRL(n) (0x220 + (0x80 * (n)))
  53. #define DSIPHY_LNX_LPTX_STR_CTRL(n) (0x224 + (0x80 * (n)))
  54. #define DSIPHY_LNX_LPRX_CTRL(n) (0x228 + (0x80 * (n)))
  55. #define DSIPHY_LNX_TX_DCTRL(n) (0x22C + (0x80 * (n)))
  56. /* dynamic refresh control registers */
  57. #define DSI_DYN_REFRESH_CTRL (0x000)
  58. #define DSI_DYN_REFRESH_PIPE_DELAY (0x004)
  59. #define DSI_DYN_REFRESH_PIPE_DELAY2 (0x008)
  60. #define DSI_DYN_REFRESH_PLL_DELAY (0x00C)
  61. #define DSI_DYN_REFRESH_STATUS (0x010)
  62. #define DSI_DYN_REFRESH_PLL_CTRL0 (0x014)
  63. #define DSI_DYN_REFRESH_PLL_CTRL1 (0x018)
  64. #define DSI_DYN_REFRESH_PLL_CTRL2 (0x01C)
  65. #define DSI_DYN_REFRESH_PLL_CTRL3 (0x020)
  66. #define DSI_DYN_REFRESH_PLL_CTRL4 (0x024)
  67. #define DSI_DYN_REFRESH_PLL_CTRL5 (0x028)
  68. #define DSI_DYN_REFRESH_PLL_CTRL6 (0x02C)
  69. #define DSI_DYN_REFRESH_PLL_CTRL7 (0x030)
  70. #define DSI_DYN_REFRESH_PLL_CTRL8 (0x034)
  71. #define DSI_DYN_REFRESH_PLL_CTRL9 (0x038)
  72. #define DSI_DYN_REFRESH_PLL_CTRL10 (0x03C)
  73. #define DSI_DYN_REFRESH_PLL_CTRL11 (0x040)
  74. #define DSI_DYN_REFRESH_PLL_CTRL12 (0x044)
  75. #define DSI_DYN_REFRESH_PLL_CTRL13 (0x048)
  76. #define DSI_DYN_REFRESH_PLL_CTRL14 (0x04C)
  77. #define DSI_DYN_REFRESH_PLL_CTRL15 (0x050)
  78. #define DSI_DYN_REFRESH_PLL_CTRL16 (0x054)
  79. #define DSI_DYN_REFRESH_PLL_CTRL17 (0x058)
  80. #define DSI_DYN_REFRESH_PLL_CTRL18 (0x05C)
  81. #define DSI_DYN_REFRESH_PLL_CTRL19 (0x060)
  82. #define DSI_DYN_REFRESH_PLL_CTRL20 (0x064)
  83. #define DSI_DYN_REFRESH_PLL_CTRL21 (0x068)
  84. #define DSI_DYN_REFRESH_PLL_CTRL22 (0x06C)
  85. #define DSI_DYN_REFRESH_PLL_CTRL23 (0x070)
  86. #define DSI_DYN_REFRESH_PLL_CTRL24 (0x074)
  87. #define DSI_DYN_REFRESH_PLL_CTRL25 (0x078)
  88. #define DSI_DYN_REFRESH_PLL_CTRL26 (0x07C)
  89. #define DSI_DYN_REFRESH_PLL_CTRL27 (0x080)
  90. #define DSI_DYN_REFRESH_PLL_CTRL28 (0x084)
  91. #define DSI_DYN_REFRESH_PLL_CTRL29 (0x088)
  92. #define DSI_DYN_REFRESH_PLL_CTRL30 (0x08C)
  93. #define DSI_DYN_REFRESH_PLL_CTRL31 (0x090)
  94. #define DSI_DYN_REFRESH_PLL_UPPER_ADDR (0x094)
  95. #define DSI_DYN_REFRESH_PLL_UPPER_ADDR2 (0x098)
  96. /**
  97. * regulator_enable() - enable regulators for DSI PHY
  98. * @phy: Pointer to DSI PHY hardware object.
  99. * @reg_cfg: Regulator configuration for all DSI lanes.
  100. */
  101. void dsi_phy_hw_v3_0_regulator_enable(struct dsi_phy_hw *phy,
  102. struct dsi_phy_per_lane_cfgs *reg_cfg)
  103. {
  104. pr_debug("[DSI_%d] Phy regulators enabled\n", phy->index);
  105. /* Nothing to be done for DSI PHY regulator enable */
  106. }
  107. /**
  108. * regulator_disable() - disable regulators
  109. * @phy: Pointer to DSI PHY hardware object.
  110. */
  111. void dsi_phy_hw_v3_0_regulator_disable(struct dsi_phy_hw *phy)
  112. {
  113. pr_debug("[DSI_%d] Phy regulators disabled\n", phy->index);
  114. /* Nothing to be done for DSI PHY regulator disable */
  115. }
  116. void dsi_phy_hw_v3_0_toggle_resync_fifo(struct dsi_phy_hw *phy)
  117. {
  118. DSI_W32(phy, DSIPHY_CMN_RBUF_CTRL, 0x00);
  119. /* ensure that the FIFO is off */
  120. wmb();
  121. DSI_W32(phy, DSIPHY_CMN_RBUF_CTRL, 0x1);
  122. /* ensure that the FIFO is toggled back on */
  123. wmb();
  124. }
  125. static int dsi_phy_hw_v3_0_is_pll_on(struct dsi_phy_hw *phy)
  126. {
  127. u32 data = 0;
  128. data = DSI_R32(phy, DSIPHY_CMN_PLL_CNTRL);
  129. mb(); /*make sure read happened */
  130. return (data & BIT(0));
  131. }
  132. static void dsi_phy_hw_v3_0_config_lpcdrx(struct dsi_phy_hw *phy,
  133. struct dsi_phy_cfg *cfg, bool enable)
  134. {
  135. int phy_lane_0 = dsi_phy_conv_logical_to_phy_lane(&cfg->lane_map,
  136. DSI_LOGICAL_LANE_0);
  137. /*
  138. * LPRX and CDRX need to enabled only for physical data lane
  139. * corresponding to the logical data lane 0
  140. */
  141. if (enable)
  142. DSI_W32(phy, DSIPHY_LNX_LPRX_CTRL(phy_lane_0),
  143. cfg->strength.lane[phy_lane_0][1]);
  144. else
  145. DSI_W32(phy, DSIPHY_LNX_LPRX_CTRL(phy_lane_0), 0);
  146. }
  147. static void dsi_phy_hw_v3_0_lane_swap_config(struct dsi_phy_hw *phy,
  148. struct dsi_lane_map *lane_map)
  149. {
  150. DSI_W32(phy, DSIPHY_CMN_LANE_CFG0,
  151. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_0] |
  152. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_1] << 4)));
  153. DSI_W32(phy, DSIPHY_CMN_LANE_CFG1,
  154. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_2] |
  155. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_3] << 4)));
  156. }
  157. static void dsi_phy_hw_v3_0_lane_settings(struct dsi_phy_hw *phy,
  158. struct dsi_phy_cfg *cfg)
  159. {
  160. int i;
  161. u8 tx_dctrl[] = {0x00, 0x00, 0x00, 0x04, 0x01};
  162. /* Strength ctrl settings */
  163. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++) {
  164. DSI_W32(phy, DSIPHY_LNX_LPTX_STR_CTRL(i),
  165. cfg->strength.lane[i][0]);
  166. /*
  167. * Disable LPRX and CDRX for all lanes. And later on, it will
  168. * be only enabled for the physical data lane corresponding
  169. * to the logical data lane 0
  170. */
  171. DSI_W32(phy, DSIPHY_LNX_LPRX_CTRL(i), 0);
  172. DSI_W32(phy, DSIPHY_LNX_PIN_SWAP(i), 0x0);
  173. DSI_W32(phy, DSIPHY_LNX_HSTX_STR_CTRL(i), 0x88);
  174. }
  175. dsi_phy_hw_v3_0_config_lpcdrx(phy, cfg, true);
  176. /* other settings */
  177. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++) {
  178. DSI_W32(phy, DSIPHY_LNX_CFG0(i), cfg->lanecfg.lane[i][0]);
  179. DSI_W32(phy, DSIPHY_LNX_CFG1(i), cfg->lanecfg.lane[i][1]);
  180. DSI_W32(phy, DSIPHY_LNX_CFG2(i), cfg->lanecfg.lane[i][2]);
  181. DSI_W32(phy, DSIPHY_LNX_CFG3(i), cfg->lanecfg.lane[i][3]);
  182. DSI_W32(phy, DSIPHY_LNX_OFFSET_TOP_CTRL(i), 0x0);
  183. DSI_W32(phy, DSIPHY_LNX_OFFSET_BOT_CTRL(i), 0x0);
  184. DSI_W32(phy, DSIPHY_LNX_TX_DCTRL(i), tx_dctrl[i]);
  185. }
  186. }
  187. void dsi_phy_hw_v3_0_clamp_ctrl(struct dsi_phy_hw *phy, bool enable)
  188. {
  189. u32 reg;
  190. pr_debug("enable=%s\n", enable ? "true" : "false");
  191. /*
  192. * DSI PHY lane clamps, also referred to as PHY FreezeIO is
  193. * enalbed by default as part of the initialization sequnce.
  194. * This would get triggered anytime the chip FreezeIO is asserted.
  195. */
  196. if (enable)
  197. return;
  198. /*
  199. * Toggle BIT 0 to exlplictly release PHY freeze I/0 to disable
  200. * the clamps.
  201. */
  202. reg = DSI_R32(phy, DSIPHY_LNX_TX_DCTRL(3));
  203. DSI_W32(phy, DSIPHY_LNX_TX_DCTRL(3), reg | BIT(0));
  204. wmb(); /* Ensure that the freezeio bit is toggled */
  205. DSI_W32(phy, DSIPHY_LNX_TX_DCTRL(3), reg & ~BIT(0));
  206. wmb(); /* Ensure that the freezeio bit is toggled */
  207. }
  208. /**
  209. * enable() - Enable PHY hardware
  210. * @phy: Pointer to DSI PHY hardware object.
  211. * @cfg: Per lane configurations for timing, strength and lane
  212. * configurations.
  213. */
  214. void dsi_phy_hw_v3_0_enable(struct dsi_phy_hw *phy,
  215. struct dsi_phy_cfg *cfg)
  216. {
  217. int rc = 0;
  218. u32 status;
  219. u32 const delay_us = 5;
  220. u32 const timeout_us = 1000;
  221. struct dsi_phy_per_lane_cfgs *timing = &cfg->timing;
  222. u32 data;
  223. if (dsi_phy_hw_v3_0_is_pll_on(phy))
  224. pr_warn("PLL turned on before configuring PHY\n");
  225. /* wait for REFGEN READY */
  226. rc = readl_poll_timeout_atomic(phy->base + DSIPHY_CMN_PHY_STATUS,
  227. status, (status & BIT(0)), delay_us, timeout_us);
  228. if (rc) {
  229. pr_err("Ref gen not ready. Aborting\n");
  230. return;
  231. }
  232. /* de-assert digital and pll power down */
  233. data = BIT(6) | BIT(5);
  234. DSI_W32(phy, DSIPHY_CMN_CTRL_0, data);
  235. /* Assert PLL core reset */
  236. DSI_W32(phy, DSIPHY_CMN_PLL_CNTRL, 0x00);
  237. /* turn off resync FIFO */
  238. DSI_W32(phy, DSIPHY_CMN_RBUF_CTRL, 0x00);
  239. /* Select MS1 byte-clk */
  240. DSI_W32(phy, DSIPHY_CMN_GLBL_CTRL, 0x10);
  241. /* Enable LDO */
  242. DSI_W32(phy, DSIPHY_CMN_VREG_CTRL, 0x59);
  243. /* Configure PHY lane swap */
  244. dsi_phy_hw_v3_0_lane_swap_config(phy, &cfg->lane_map);
  245. /* DSI PHY timings */
  246. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_0, timing->lane_v3[0]);
  247. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_1, timing->lane_v3[1]);
  248. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_2, timing->lane_v3[2]);
  249. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_3, timing->lane_v3[3]);
  250. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_4, timing->lane_v3[4]);
  251. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_5, timing->lane_v3[5]);
  252. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_6, timing->lane_v3[6]);
  253. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_7, timing->lane_v3[7]);
  254. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_8, timing->lane_v3[8]);
  255. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_9, timing->lane_v3[9]);
  256. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_10, timing->lane_v3[10]);
  257. DSI_W32(phy, DSIPHY_CMN_TIMING_CTRL_11, timing->lane_v3[11]);
  258. /* Remove power down from all blocks */
  259. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0x7f);
  260. /*power up lanes */
  261. data = DSI_R32(phy, DSIPHY_CMN_CTRL_0);
  262. /* TODO: only power up lanes that are used */
  263. data |= 0x1F;
  264. DSI_W32(phy, DSIPHY_CMN_CTRL_0, data);
  265. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL0, 0x1F);
  266. /* Select full-rate mode */
  267. DSI_W32(phy, DSIPHY_CMN_CTRL_2, 0x40);
  268. switch (cfg->pll_source) {
  269. case DSI_PLL_SOURCE_STANDALONE:
  270. case DSI_PLL_SOURCE_NATIVE:
  271. data = 0x0; /* internal PLL */
  272. break;
  273. case DSI_PLL_SOURCE_NON_NATIVE:
  274. data = 0x1; /* external PLL */
  275. break;
  276. default:
  277. break;
  278. }
  279. DSI_W32(phy, DSIPHY_CMN_CLK_CFG1, (data << 2)); /* set PLL src */
  280. /* DSI lane settings */
  281. dsi_phy_hw_v3_0_lane_settings(phy, cfg);
  282. pr_debug("[DSI_%d]Phy enabled\n", phy->index);
  283. }
  284. /**
  285. * disable() - Disable PHY hardware
  286. * @phy: Pointer to DSI PHY hardware object.
  287. */
  288. void dsi_phy_hw_v3_0_disable(struct dsi_phy_hw *phy,
  289. struct dsi_phy_cfg *cfg)
  290. {
  291. u32 data = 0;
  292. if (dsi_phy_hw_v3_0_is_pll_on(phy))
  293. pr_warn("Turning OFF PHY while PLL is on\n");
  294. dsi_phy_hw_v3_0_config_lpcdrx(phy, cfg, false);
  295. data = DSI_R32(phy, DSIPHY_CMN_CTRL_0);
  296. /* disable all lanes */
  297. data &= ~0x1F;
  298. DSI_W32(phy, DSIPHY_CMN_CTRL_0, data);
  299. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL0, 0);
  300. /* Turn off all PHY blocks */
  301. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0x00);
  302. /* make sure phy is turned off */
  303. wmb();
  304. pr_debug("[DSI_%d]Phy disabled\n", phy->index);
  305. }
  306. int dsi_phy_hw_v3_0_wait_for_lane_idle(
  307. struct dsi_phy_hw *phy, u32 lanes)
  308. {
  309. int rc = 0, val = 0;
  310. u32 stop_state_mask = 0;
  311. u32 const sleep_us = 10;
  312. u32 const timeout_us = 100;
  313. stop_state_mask = BIT(4); /* clock lane */
  314. if (lanes & DSI_DATA_LANE_0)
  315. stop_state_mask |= BIT(0);
  316. if (lanes & DSI_DATA_LANE_1)
  317. stop_state_mask |= BIT(1);
  318. if (lanes & DSI_DATA_LANE_2)
  319. stop_state_mask |= BIT(2);
  320. if (lanes & DSI_DATA_LANE_3)
  321. stop_state_mask |= BIT(3);
  322. pr_debug("%s: polling for lanes to be in stop state, mask=0x%08x\n",
  323. __func__, stop_state_mask);
  324. rc = readl_poll_timeout(phy->base + DSIPHY_CMN_LANE_STATUS1, val,
  325. ((val & stop_state_mask) == stop_state_mask),
  326. sleep_us, timeout_us);
  327. if (rc) {
  328. pr_err("%s: lanes not in stop state, LANE_STATUS=0x%08x\n",
  329. __func__, val);
  330. return rc;
  331. }
  332. return 0;
  333. }
  334. void dsi_phy_hw_v3_0_ulps_request(struct dsi_phy_hw *phy,
  335. struct dsi_phy_cfg *cfg, u32 lanes)
  336. {
  337. u32 reg = 0;
  338. if (lanes & DSI_CLOCK_LANE)
  339. reg = BIT(4);
  340. if (lanes & DSI_DATA_LANE_0)
  341. reg |= BIT(0);
  342. if (lanes & DSI_DATA_LANE_1)
  343. reg |= BIT(1);
  344. if (lanes & DSI_DATA_LANE_2)
  345. reg |= BIT(2);
  346. if (lanes & DSI_DATA_LANE_3)
  347. reg |= BIT(3);
  348. /*
  349. * ULPS entry request. Wait for short time to make sure
  350. * that the lanes enter ULPS. Recommended as per HPG.
  351. */
  352. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL1, reg);
  353. usleep_range(100, 110);
  354. /* disable LPRX and CDRX */
  355. dsi_phy_hw_v3_0_config_lpcdrx(phy, cfg, false);
  356. /* disable lane LDOs */
  357. DSI_W32(phy, DSIPHY_CMN_VREG_CTRL, 0x19);
  358. pr_debug("[DSI_PHY%d] ULPS requested for lanes 0x%x\n", phy->index,
  359. lanes);
  360. }
  361. int dsi_phy_hw_v3_0_lane_reset(struct dsi_phy_hw *phy)
  362. {
  363. int ret = 0, loop = 10, u_dly = 200;
  364. u32 ln_status = 0;
  365. while ((ln_status != 0x1f) && loop) {
  366. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, 0x1f);
  367. wmb(); /* ensure register is committed */
  368. loop--;
  369. udelay(u_dly);
  370. ln_status = DSI_R32(phy, DSIPHY_CMN_LANE_STATUS1);
  371. pr_debug("trial no: %d\n", loop);
  372. }
  373. if (!loop)
  374. pr_debug("could not reset phy lanes\n");
  375. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, 0x0);
  376. wmb(); /* ensure register is committed */
  377. return ret;
  378. }
  379. void dsi_phy_hw_v3_0_ulps_exit(struct dsi_phy_hw *phy,
  380. struct dsi_phy_cfg *cfg, u32 lanes)
  381. {
  382. u32 reg = 0;
  383. if (lanes & DSI_CLOCK_LANE)
  384. reg = BIT(4);
  385. if (lanes & DSI_DATA_LANE_0)
  386. reg |= BIT(0);
  387. if (lanes & DSI_DATA_LANE_1)
  388. reg |= BIT(1);
  389. if (lanes & DSI_DATA_LANE_2)
  390. reg |= BIT(2);
  391. if (lanes & DSI_DATA_LANE_3)
  392. reg |= BIT(3);
  393. /* enable lane LDOs */
  394. DSI_W32(phy, DSIPHY_CMN_VREG_CTRL, 0x59);
  395. /* enable LPRX and CDRX */
  396. dsi_phy_hw_v3_0_config_lpcdrx(phy, cfg, true);
  397. /* ULPS exit request */
  398. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL2, reg);
  399. usleep_range(1000, 1010);
  400. /* Clear ULPS request flags on all lanes */
  401. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL1, 0);
  402. /* Clear ULPS exit flags on all lanes */
  403. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL2, 0);
  404. /*
  405. * Sometimes when exiting ULPS, it is possible that some DSI
  406. * lanes are not in the stop state which could lead to DSI
  407. * commands not going through. To avoid this, force the lanes
  408. * to be in stop state.
  409. */
  410. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, reg);
  411. DSI_W32(phy, DSIPHY_CMN_LANE_CTRL3, 0);
  412. usleep_range(100, 110);
  413. }
  414. u32 dsi_phy_hw_v3_0_get_lanes_in_ulps(struct dsi_phy_hw *phy)
  415. {
  416. u32 lanes = 0;
  417. lanes = DSI_R32(phy, DSIPHY_CMN_LANE_STATUS0);
  418. pr_debug("[DSI_PHY%d] lanes in ulps = 0x%x\n", phy->index, lanes);
  419. return lanes;
  420. }
  421. bool dsi_phy_hw_v3_0_is_lanes_in_ulps(u32 lanes, u32 ulps_lanes)
  422. {
  423. if (lanes & ulps_lanes)
  424. return false;
  425. return true;
  426. }
  427. int dsi_phy_hw_timing_val_v3_0(struct dsi_phy_per_lane_cfgs *timing_cfg,
  428. u32 *timing_val, u32 size)
  429. {
  430. int i = 0;
  431. if (size != DSI_PHY_TIMING_V3_SIZE) {
  432. pr_err("Unexpected timing array size %d\n", size);
  433. return -EINVAL;
  434. }
  435. for (i = 0; i < size; i++)
  436. timing_cfg->lane_v3[i] = timing_val[i];
  437. return 0;
  438. }
  439. void dsi_phy_hw_v3_0_dyn_refresh_config(struct dsi_phy_hw *phy,
  440. struct dsi_phy_cfg *cfg, bool is_master)
  441. {
  442. u32 reg;
  443. if (is_master) {
  444. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL9,
  445. DSIPHY_CMN_GLBL_CTRL, DSIPHY_CMN_VREG_CTRL,
  446. 0x10, 0x59);
  447. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL10,
  448. DSIPHY_CMN_TIMING_CTRL_0, DSIPHY_CMN_TIMING_CTRL_1,
  449. cfg->timing.lane_v3[0], cfg->timing.lane_v3[1]);
  450. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL11,
  451. DSIPHY_CMN_TIMING_CTRL_2, DSIPHY_CMN_TIMING_CTRL_3,
  452. cfg->timing.lane_v3[2], cfg->timing.lane_v3[3]);
  453. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL12,
  454. DSIPHY_CMN_TIMING_CTRL_4, DSIPHY_CMN_TIMING_CTRL_5,
  455. cfg->timing.lane_v3[4], cfg->timing.lane_v3[5]);
  456. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL13,
  457. DSIPHY_CMN_TIMING_CTRL_6, DSIPHY_CMN_TIMING_CTRL_7,
  458. cfg->timing.lane_v3[6], cfg->timing.lane_v3[7]);
  459. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL14,
  460. DSIPHY_CMN_TIMING_CTRL_8, DSIPHY_CMN_TIMING_CTRL_9,
  461. cfg->timing.lane_v3[8], cfg->timing.lane_v3[9]);
  462. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL15,
  463. DSIPHY_CMN_TIMING_CTRL_10, DSIPHY_CMN_TIMING_CTRL_11,
  464. cfg->timing.lane_v3[10], cfg->timing.lane_v3[11]);
  465. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL16,
  466. DSIPHY_CMN_CTRL_0, DSIPHY_CMN_LANE_CTRL0,
  467. 0x7f, 0x1f);
  468. } else {
  469. reg = DSI_R32(phy, DSIPHY_CMN_CLK_CFG0);
  470. reg &= ~BIT(5);
  471. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL0,
  472. DSIPHY_CMN_CLK_CFG0, DSIPHY_CMN_PLL_CNTRL,
  473. reg, 0x0);
  474. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL1,
  475. DSIPHY_CMN_RBUF_CTRL, DSIPHY_CMN_GLBL_CTRL,
  476. 0x0, 0x10);
  477. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL2,
  478. DSIPHY_CMN_VREG_CTRL, DSIPHY_CMN_TIMING_CTRL_0,
  479. 0x59, cfg->timing.lane_v3[0]);
  480. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL3,
  481. DSIPHY_CMN_TIMING_CTRL_1, DSIPHY_CMN_TIMING_CTRL_2,
  482. cfg->timing.lane_v3[1], cfg->timing.lane_v3[2]);
  483. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL4,
  484. DSIPHY_CMN_TIMING_CTRL_3, DSIPHY_CMN_TIMING_CTRL_4,
  485. cfg->timing.lane_v3[3], cfg->timing.lane_v3[4]);
  486. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL5,
  487. DSIPHY_CMN_TIMING_CTRL_5, DSIPHY_CMN_TIMING_CTRL_6,
  488. cfg->timing.lane_v3[5], cfg->timing.lane_v3[6]);
  489. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL6,
  490. DSIPHY_CMN_TIMING_CTRL_7, DSIPHY_CMN_TIMING_CTRL_8,
  491. cfg->timing.lane_v3[7], cfg->timing.lane_v3[8]);
  492. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL7,
  493. DSIPHY_CMN_TIMING_CTRL_9, DSIPHY_CMN_TIMING_CTRL_10,
  494. cfg->timing.lane_v3[9], cfg->timing.lane_v3[10]);
  495. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL8,
  496. DSIPHY_CMN_TIMING_CTRL_11, DSIPHY_CMN_CTRL_0,
  497. cfg->timing.lane_v3[11], 0x7f);
  498. DSI_DYN_REF_REG_W(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_CTRL9,
  499. DSIPHY_CMN_LANE_CTRL0, DSIPHY_CMN_CTRL_2,
  500. 0x1f, 0x40);
  501. /*
  502. * fill with dummy register writes since controller will blindly
  503. * send these values to DSI PHY.
  504. */
  505. reg = DSI_DYN_REFRESH_PLL_CTRL11;
  506. while (reg <= DSI_DYN_REFRESH_PLL_CTRL29) {
  507. DSI_DYN_REF_REG_W(phy->dyn_pll_base, reg,
  508. DSIPHY_CMN_LANE_CTRL0, DSIPHY_CMN_CTRL_0,
  509. 0x1f, 0x7f);
  510. reg += 0x4;
  511. }
  512. DSI_GEN_W32(phy->dyn_pll_base,
  513. DSI_DYN_REFRESH_PLL_UPPER_ADDR, 0);
  514. DSI_GEN_W32(phy->dyn_pll_base,
  515. DSI_DYN_REFRESH_PLL_UPPER_ADDR2, 0);
  516. }
  517. wmb(); /* make sure all registers are updated */
  518. }
  519. void dsi_phy_hw_v3_0_dyn_refresh_pipe_delay(struct dsi_phy_hw *phy,
  520. struct dsi_dyn_clk_delay *delay)
  521. {
  522. if (!delay)
  523. return;
  524. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_PIPE_DELAY,
  525. delay->pipe_delay);
  526. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_PIPE_DELAY2,
  527. delay->pipe_delay2);
  528. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_PLL_DELAY,
  529. delay->pll_delay);
  530. }
  531. void dsi_phy_hw_v3_0_dyn_refresh_helper(struct dsi_phy_hw *phy, u32 offset)
  532. {
  533. u32 reg;
  534. /*
  535. * if no offset is mentioned then this means we want to clear
  536. * the dynamic refresh ctrl register which is the last step
  537. * of dynamic refresh sequence.
  538. */
  539. if (!offset) {
  540. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  541. reg &= ~(BIT(0) | BIT(8));
  542. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  543. wmb(); /* ensure dynamic fps is cleared */
  544. return;
  545. }
  546. if (offset & BIT(DYN_REFRESH_INTF_SEL)) {
  547. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  548. reg |= BIT(13);
  549. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  550. }
  551. if (offset & BIT(DYN_REFRESH_SYNC_MODE)) {
  552. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  553. reg |= BIT(16);
  554. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  555. }
  556. if (offset & BIT(DYN_REFRESH_SWI_CTRL)) {
  557. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  558. reg |= BIT(0);
  559. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  560. }
  561. if (offset & BIT(DYN_REFRESH_SW_TRIGGER)) {
  562. reg = DSI_GEN_R32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL);
  563. reg |= BIT(8);
  564. DSI_GEN_W32(phy->dyn_pll_base, DSI_DYN_REFRESH_CTRL, reg);
  565. wmb(); /* ensure dynamic fps is triggered */
  566. }
  567. }
  568. int dsi_phy_hw_v3_0_cache_phy_timings(struct dsi_phy_per_lane_cfgs *timings,
  569. u32 *dst, u32 size)
  570. {
  571. int i;
  572. if (!timings || !dst || !size)
  573. return -EINVAL;
  574. if (size != DSI_PHY_TIMING_V3_SIZE) {
  575. pr_err("size mis-match\n");
  576. return -EINVAL;
  577. }
  578. for (i = 0; i < size; i++)
  579. dst[i] = timings->lane_v3[i];
  580. return 0;
  581. }