dsi_phy.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/of_device.h>
  6. #include <linux/err.h>
  7. #include <linux/regulator/consumer.h>
  8. #include <linux/clk.h>
  9. #include <linux/list.h>
  10. #include "msm_drv.h"
  11. #include "msm_kms.h"
  12. #include "dsi_phy.h"
  13. #include "dsi_phy_hw.h"
  14. #include "dsi_clk.h"
  15. #include "dsi_pwr.h"
  16. #include "dsi_catalog.h"
  17. #include "sde_dbg.h"
  18. #define DSI_PHY_DEFAULT_LABEL "MDSS PHY CTRL"
  19. #define BITS_PER_BYTE 8
  20. struct dsi_phy_list_item {
  21. struct msm_dsi_phy *phy;
  22. struct list_head list;
  23. };
  24. static LIST_HEAD(dsi_phy_list);
  25. static DEFINE_MUTEX(dsi_phy_list_lock);
  26. static const struct dsi_ver_spec_info dsi_phy_v0_0_hpm = {
  27. .version = DSI_PHY_VERSION_0_0_HPM,
  28. .lane_cfg_count = 4,
  29. .strength_cfg_count = 2,
  30. .regulator_cfg_count = 1,
  31. .timing_cfg_count = 8,
  32. };
  33. static const struct dsi_ver_spec_info dsi_phy_v0_0_lpm = {
  34. .version = DSI_PHY_VERSION_0_0_LPM,
  35. .lane_cfg_count = 4,
  36. .strength_cfg_count = 2,
  37. .regulator_cfg_count = 1,
  38. .timing_cfg_count = 8,
  39. };
  40. static const struct dsi_ver_spec_info dsi_phy_v1_0 = {
  41. .version = DSI_PHY_VERSION_1_0,
  42. .lane_cfg_count = 4,
  43. .strength_cfg_count = 2,
  44. .regulator_cfg_count = 1,
  45. .timing_cfg_count = 8,
  46. };
  47. static const struct dsi_ver_spec_info dsi_phy_v2_0 = {
  48. .version = DSI_PHY_VERSION_2_0,
  49. .lane_cfg_count = 4,
  50. .strength_cfg_count = 2,
  51. .regulator_cfg_count = 1,
  52. .timing_cfg_count = 8,
  53. };
  54. static const struct dsi_ver_spec_info dsi_phy_v3_0 = {
  55. .version = DSI_PHY_VERSION_3_0,
  56. .lane_cfg_count = 4,
  57. .strength_cfg_count = 2,
  58. .regulator_cfg_count = 0,
  59. .timing_cfg_count = 12,
  60. };
  61. static const struct dsi_ver_spec_info dsi_phy_v4_0 = {
  62. .version = DSI_PHY_VERSION_4_0,
  63. .lane_cfg_count = 4,
  64. .strength_cfg_count = 2,
  65. .regulator_cfg_count = 0,
  66. .timing_cfg_count = 14,
  67. };
  68. static const struct dsi_ver_spec_info dsi_phy_v4_1 = {
  69. .version = DSI_PHY_VERSION_4_1,
  70. .lane_cfg_count = 4,
  71. .strength_cfg_count = 2,
  72. .regulator_cfg_count = 0,
  73. .timing_cfg_count = 14,
  74. };
  75. static const struct dsi_ver_spec_info dsi_phy_v4_2 = {
  76. .version = DSI_PHY_VERSION_4_2,
  77. .lane_cfg_count = 4,
  78. .strength_cfg_count = 2,
  79. .regulator_cfg_count = 0,
  80. .timing_cfg_count = 14,
  81. };
  82. static const struct of_device_id msm_dsi_phy_of_match[] = {
  83. { .compatible = "qcom,dsi-phy-v0.0-hpm",
  84. .data = &dsi_phy_v0_0_hpm,},
  85. { .compatible = "qcom,dsi-phy-v0.0-lpm",
  86. .data = &dsi_phy_v0_0_lpm,},
  87. { .compatible = "qcom,dsi-phy-v1.0",
  88. .data = &dsi_phy_v1_0,},
  89. { .compatible = "qcom,dsi-phy-v2.0",
  90. .data = &dsi_phy_v2_0,},
  91. { .compatible = "qcom,dsi-phy-v3.0",
  92. .data = &dsi_phy_v3_0,},
  93. { .compatible = "qcom,dsi-phy-v4.0",
  94. .data = &dsi_phy_v4_0,},
  95. { .compatible = "qcom,dsi-phy-v4.1",
  96. .data = &dsi_phy_v4_1,},
  97. { .compatible = "qcom,dsi-phy-v4.2",
  98. .data = &dsi_phy_v4_2,},
  99. {}
  100. };
  101. int dsi_phy_get_version(struct msm_dsi_phy *phy)
  102. {
  103. return phy->ver_info->version;
  104. }
  105. static int dsi_phy_regmap_init(struct platform_device *pdev,
  106. struct msm_dsi_phy *phy)
  107. {
  108. int rc = 0;
  109. void __iomem *ptr;
  110. ptr = msm_ioremap(pdev, "dsi_phy", phy->name);
  111. if (IS_ERR(ptr)) {
  112. rc = PTR_ERR(ptr);
  113. return rc;
  114. }
  115. phy->hw.base = ptr;
  116. ptr = msm_ioremap(pdev, "dyn_refresh_base", phy->name);
  117. phy->hw.dyn_pll_base = ptr;
  118. DSI_PHY_DBG(phy, "map dsi_phy registers to %pK\n", phy->hw.base);
  119. switch (phy->ver_info->version) {
  120. case DSI_PHY_VERSION_2_0:
  121. ptr = msm_ioremap(pdev, "phy_clamp_base", phy->name);
  122. if (IS_ERR(ptr))
  123. phy->hw.phy_clamp_base = NULL;
  124. else
  125. phy->hw.phy_clamp_base = ptr;
  126. break;
  127. default:
  128. break;
  129. }
  130. return rc;
  131. }
  132. static int dsi_phy_regmap_deinit(struct msm_dsi_phy *phy)
  133. {
  134. DSI_PHY_DBG(phy, "unmap registers\n");
  135. return 0;
  136. }
  137. static int dsi_phy_supplies_init(struct platform_device *pdev,
  138. struct msm_dsi_phy *phy)
  139. {
  140. int rc = 0;
  141. int i = 0;
  142. struct dsi_regulator_info *regs;
  143. struct regulator *vreg = NULL;
  144. regs = &phy->pwr_info.digital;
  145. regs->vregs = devm_kzalloc(&pdev->dev, sizeof(struct dsi_vreg),
  146. GFP_KERNEL);
  147. if (!regs->vregs)
  148. goto error;
  149. regs->count = 1;
  150. snprintf(regs->vregs->vreg_name,
  151. ARRAY_SIZE(regs->vregs[i].vreg_name),
  152. "%s", "gdsc");
  153. rc = dsi_pwr_get_dt_vreg_data(&pdev->dev,
  154. &phy->pwr_info.phy_pwr,
  155. "qcom,phy-supply-entries");
  156. if (rc) {
  157. DSI_PHY_ERR(phy, "failed to get host power supplies, rc = %d\n",
  158. rc);
  159. goto error_digital;
  160. }
  161. regs = &phy->pwr_info.digital;
  162. for (i = 0; i < regs->count; i++) {
  163. vreg = devm_regulator_get(&pdev->dev, regs->vregs[i].vreg_name);
  164. rc = PTR_RET(vreg);
  165. if (rc) {
  166. DSI_PHY_ERR(phy, "failed to get %s regulator\n",
  167. regs->vregs[i].vreg_name);
  168. goto error_host_pwr;
  169. }
  170. regs->vregs[i].vreg = vreg;
  171. }
  172. regs = &phy->pwr_info.phy_pwr;
  173. for (i = 0; i < regs->count; i++) {
  174. vreg = devm_regulator_get(&pdev->dev, regs->vregs[i].vreg_name);
  175. rc = PTR_RET(vreg);
  176. if (rc) {
  177. DSI_PHY_ERR(phy, "failed to get %s regulator\n",
  178. regs->vregs[i].vreg_name);
  179. for (--i; i >= 0; i--)
  180. devm_regulator_put(regs->vregs[i].vreg);
  181. goto error_digital_put;
  182. }
  183. regs->vregs[i].vreg = vreg;
  184. }
  185. return rc;
  186. error_digital_put:
  187. regs = &phy->pwr_info.digital;
  188. for (i = 0; i < regs->count; i++)
  189. devm_regulator_put(regs->vregs[i].vreg);
  190. error_host_pwr:
  191. devm_kfree(&pdev->dev, phy->pwr_info.phy_pwr.vregs);
  192. phy->pwr_info.phy_pwr.vregs = NULL;
  193. phy->pwr_info.phy_pwr.count = 0;
  194. error_digital:
  195. devm_kfree(&pdev->dev, phy->pwr_info.digital.vregs);
  196. phy->pwr_info.digital.vregs = NULL;
  197. phy->pwr_info.digital.count = 0;
  198. error:
  199. return rc;
  200. }
  201. static int dsi_phy_supplies_deinit(struct msm_dsi_phy *phy)
  202. {
  203. int i = 0;
  204. int rc = 0;
  205. struct dsi_regulator_info *regs;
  206. regs = &phy->pwr_info.digital;
  207. for (i = 0; i < regs->count; i++) {
  208. if (!regs->vregs[i].vreg)
  209. DSI_PHY_ERR(phy, "vreg is NULL, should not reach here\n");
  210. else
  211. devm_regulator_put(regs->vregs[i].vreg);
  212. }
  213. regs = &phy->pwr_info.phy_pwr;
  214. for (i = 0; i < regs->count; i++) {
  215. if (!regs->vregs[i].vreg)
  216. DSI_PHY_ERR(phy, "vreg is NULL, should not reach here\n");
  217. else
  218. devm_regulator_put(regs->vregs[i].vreg);
  219. }
  220. if (phy->pwr_info.phy_pwr.vregs) {
  221. devm_kfree(&phy->pdev->dev, phy->pwr_info.phy_pwr.vregs);
  222. phy->pwr_info.phy_pwr.vregs = NULL;
  223. phy->pwr_info.phy_pwr.count = 0;
  224. }
  225. if (phy->pwr_info.digital.vregs) {
  226. devm_kfree(&phy->pdev->dev, phy->pwr_info.digital.vregs);
  227. phy->pwr_info.digital.vregs = NULL;
  228. phy->pwr_info.digital.count = 0;
  229. }
  230. return rc;
  231. }
  232. static int dsi_phy_parse_dt_per_lane_cfgs(struct platform_device *pdev,
  233. struct dsi_phy_per_lane_cfgs *cfg,
  234. char *property)
  235. {
  236. int rc = 0, i = 0, j = 0;
  237. const u8 *data;
  238. u32 len = 0;
  239. data = of_get_property(pdev->dev.of_node, property, &len);
  240. if (!data) {
  241. DSI_ERR("Unable to read Phy %s settings\n", property);
  242. return -EINVAL;
  243. }
  244. if (len != DSI_LANE_MAX * cfg->count_per_lane) {
  245. DSI_ERR("incorrect phy %s settings, exp=%d, act=%d\n",
  246. property, (DSI_LANE_MAX * cfg->count_per_lane), len);
  247. return -EINVAL;
  248. }
  249. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++) {
  250. for (j = 0; j < cfg->count_per_lane; j++) {
  251. cfg->lane[i][j] = *data;
  252. data++;
  253. }
  254. }
  255. return rc;
  256. }
  257. static int dsi_phy_settings_init(struct platform_device *pdev,
  258. struct msm_dsi_phy *phy)
  259. {
  260. int rc = 0;
  261. struct dsi_phy_per_lane_cfgs *lane = &phy->cfg.lanecfg;
  262. struct dsi_phy_per_lane_cfgs *strength = &phy->cfg.strength;
  263. struct dsi_phy_per_lane_cfgs *timing = &phy->cfg.timing;
  264. struct dsi_phy_per_lane_cfgs *regs = &phy->cfg.regulators;
  265. lane->count_per_lane = phy->ver_info->lane_cfg_count;
  266. rc = dsi_phy_parse_dt_per_lane_cfgs(pdev, lane,
  267. "qcom,platform-lane-config");
  268. if (rc) {
  269. DSI_PHY_ERR(phy, "failed to parse lane cfgs, rc=%d\n", rc);
  270. goto err;
  271. }
  272. strength->count_per_lane = phy->ver_info->strength_cfg_count;
  273. rc = dsi_phy_parse_dt_per_lane_cfgs(pdev, strength,
  274. "qcom,platform-strength-ctrl");
  275. if (rc) {
  276. DSI_PHY_ERR(phy, "failed to parse lane cfgs, rc=%d\n", rc);
  277. goto err;
  278. }
  279. regs->count_per_lane = phy->ver_info->regulator_cfg_count;
  280. if (regs->count_per_lane > 0) {
  281. rc = dsi_phy_parse_dt_per_lane_cfgs(pdev, regs,
  282. "qcom,platform-regulator-settings");
  283. if (rc) {
  284. DSI_PHY_ERR(phy, "failed to parse lane cfgs, rc=%d\n",
  285. rc);
  286. goto err;
  287. }
  288. }
  289. /* Actual timing values are dependent on panel */
  290. timing->count_per_lane = phy->ver_info->timing_cfg_count;
  291. phy->allow_phy_power_off = of_property_read_bool(pdev->dev.of_node,
  292. "qcom,panel-allow-phy-poweroff");
  293. of_property_read_u32(pdev->dev.of_node,
  294. "qcom,dsi-phy-regulator-min-datarate-bps",
  295. &phy->regulator_min_datarate_bps);
  296. return 0;
  297. err:
  298. lane->count_per_lane = 0;
  299. strength->count_per_lane = 0;
  300. regs->count_per_lane = 0;
  301. timing->count_per_lane = 0;
  302. return rc;
  303. }
  304. static int dsi_phy_settings_deinit(struct msm_dsi_phy *phy)
  305. {
  306. memset(&phy->cfg.lanecfg, 0x0, sizeof(phy->cfg.lanecfg));
  307. memset(&phy->cfg.strength, 0x0, sizeof(phy->cfg.strength));
  308. memset(&phy->cfg.timing, 0x0, sizeof(phy->cfg.timing));
  309. memset(&phy->cfg.regulators, 0x0, sizeof(phy->cfg.regulators));
  310. return 0;
  311. }
  312. static int dsi_phy_driver_probe(struct platform_device *pdev)
  313. {
  314. struct msm_dsi_phy *dsi_phy;
  315. struct dsi_phy_list_item *item;
  316. const struct of_device_id *id;
  317. const struct dsi_ver_spec_info *ver_info;
  318. int rc = 0;
  319. u32 index = 0;
  320. if (!pdev || !pdev->dev.of_node) {
  321. DSI_ERR("pdev not found\n");
  322. return -ENODEV;
  323. }
  324. id = of_match_node(msm_dsi_phy_of_match, pdev->dev.of_node);
  325. if (!id)
  326. return -ENODEV;
  327. ver_info = id->data;
  328. item = devm_kzalloc(&pdev->dev, sizeof(*item), GFP_KERNEL);
  329. if (!item)
  330. return -ENOMEM;
  331. dsi_phy = devm_kzalloc(&pdev->dev, sizeof(*dsi_phy), GFP_KERNEL);
  332. if (!dsi_phy) {
  333. devm_kfree(&pdev->dev, item);
  334. return -ENOMEM;
  335. }
  336. rc = of_property_read_u32(pdev->dev.of_node, "cell-index", &index);
  337. if (rc) {
  338. DSI_PHY_DBG(dsi_phy, "cell index not set, default to 0\n");
  339. index = 0;
  340. }
  341. dsi_phy->index = index;
  342. dsi_phy->name = of_get_property(pdev->dev.of_node, "label", NULL);
  343. if (!dsi_phy->name)
  344. dsi_phy->name = DSI_PHY_DEFAULT_LABEL;
  345. DSI_PHY_DBG(dsi_phy, "Probing device\n");
  346. dsi_phy->ver_info = ver_info;
  347. rc = dsi_phy_regmap_init(pdev, dsi_phy);
  348. if (rc) {
  349. DSI_PHY_ERR(dsi_phy, "Failed to parse register information, rc=%d\n",
  350. rc);
  351. goto fail;
  352. }
  353. rc = dsi_phy_supplies_init(pdev, dsi_phy);
  354. if (rc) {
  355. DSI_PHY_ERR(dsi_phy, "failed to parse voltage supplies, rc = %d\n",
  356. rc);
  357. goto fail_regmap;
  358. }
  359. rc = dsi_catalog_phy_setup(&dsi_phy->hw, ver_info->version,
  360. dsi_phy->index);
  361. if (rc) {
  362. DSI_PHY_ERR(dsi_phy, "Catalog does not support version (%d)\n",
  363. ver_info->version);
  364. goto fail_supplies;
  365. }
  366. rc = dsi_phy_settings_init(pdev, dsi_phy);
  367. if (rc) {
  368. DSI_PHY_ERR(dsi_phy, "Failed to parse phy setting, rc=%d\n",
  369. rc);
  370. goto fail_supplies;
  371. }
  372. rc = dsi_pll_init(pdev, &dsi_phy->pll);
  373. if (rc) {
  374. DSI_PHY_ERR(dsi_phy, "Failed to initialize DSI PLL, rc=%d\n", rc);
  375. goto fail_settings;
  376. }
  377. item->phy = dsi_phy;
  378. mutex_lock(&dsi_phy_list_lock);
  379. list_add(&item->list, &dsi_phy_list);
  380. mutex_unlock(&dsi_phy_list_lock);
  381. mutex_init(&dsi_phy->phy_lock);
  382. /** TODO: initialize debugfs */
  383. dsi_phy->pdev = pdev;
  384. platform_set_drvdata(pdev, dsi_phy);
  385. DSI_PHY_INFO(dsi_phy, "Probe successful\n");
  386. return 0;
  387. fail_settings:
  388. (void)dsi_phy_settings_deinit(dsi_phy);
  389. fail_supplies:
  390. (void)dsi_phy_supplies_deinit(dsi_phy);
  391. fail_regmap:
  392. (void)dsi_phy_regmap_deinit(dsi_phy);
  393. fail:
  394. devm_kfree(&pdev->dev, dsi_phy);
  395. devm_kfree(&pdev->dev, item);
  396. return rc;
  397. }
  398. static int dsi_phy_driver_remove(struct platform_device *pdev)
  399. {
  400. int rc = 0;
  401. struct msm_dsi_phy *phy = platform_get_drvdata(pdev);
  402. struct list_head *pos, *tmp;
  403. if (!pdev || !phy) {
  404. DSI_PHY_ERR(phy, "Invalid device\n");
  405. return -EINVAL;
  406. }
  407. mutex_lock(&dsi_phy_list_lock);
  408. list_for_each_safe(pos, tmp, &dsi_phy_list) {
  409. struct dsi_phy_list_item *n;
  410. n = list_entry(pos, struct dsi_phy_list_item, list);
  411. if (n->phy == phy) {
  412. list_del(&n->list);
  413. devm_kfree(&pdev->dev, n);
  414. break;
  415. }
  416. }
  417. mutex_unlock(&dsi_phy_list_lock);
  418. mutex_lock(&phy->phy_lock);
  419. rc = dsi_phy_settings_deinit(phy);
  420. if (rc)
  421. DSI_PHY_ERR(phy, "failed to deinitialize phy settings, rc=%d\n",
  422. rc);
  423. rc = dsi_phy_supplies_deinit(phy);
  424. if (rc)
  425. DSI_PHY_ERR(phy, "failed to deinitialize voltage supplies, rc=%d\n",
  426. rc);
  427. rc = dsi_phy_regmap_deinit(phy);
  428. if (rc)
  429. DSI_PHY_ERR(phy, "failed to deinitialize regmap, rc=%d\n", rc);
  430. mutex_unlock(&phy->phy_lock);
  431. mutex_destroy(&phy->phy_lock);
  432. devm_kfree(&pdev->dev, phy);
  433. platform_set_drvdata(pdev, NULL);
  434. return 0;
  435. }
  436. static struct platform_driver dsi_phy_platform_driver = {
  437. .probe = dsi_phy_driver_probe,
  438. .remove = dsi_phy_driver_remove,
  439. .driver = {
  440. .name = "dsi_phy",
  441. .of_match_table = msm_dsi_phy_of_match,
  442. },
  443. };
  444. static void dsi_phy_enable_hw(struct msm_dsi_phy *phy)
  445. {
  446. if (phy->hw.ops.regulator_enable)
  447. phy->hw.ops.regulator_enable(&phy->hw, &phy->cfg.regulators);
  448. if (phy->hw.ops.enable)
  449. phy->hw.ops.enable(&phy->hw, &phy->cfg);
  450. }
  451. static void dsi_phy_disable_hw(struct msm_dsi_phy *phy)
  452. {
  453. if (phy->hw.ops.disable)
  454. phy->hw.ops.disable(&phy->hw, &phy->cfg);
  455. if (phy->hw.ops.regulator_disable)
  456. phy->hw.ops.regulator_disable(&phy->hw);
  457. }
  458. /**
  459. * dsi_phy_get() - get a dsi phy handle from device node
  460. * @of_node: device node for dsi phy controller
  461. *
  462. * Gets the DSI PHY handle for the corresponding of_node. The ref count is
  463. * incremented to one all subsequents get will fail until the original client
  464. * calls a put.
  465. *
  466. * Return: DSI PHY handle or an error code.
  467. */
  468. struct msm_dsi_phy *dsi_phy_get(struct device_node *of_node)
  469. {
  470. struct list_head *pos, *tmp;
  471. struct msm_dsi_phy *phy = NULL;
  472. mutex_lock(&dsi_phy_list_lock);
  473. list_for_each_safe(pos, tmp, &dsi_phy_list) {
  474. struct dsi_phy_list_item *n;
  475. n = list_entry(pos, struct dsi_phy_list_item, list);
  476. if (n->phy->pdev->dev.of_node == of_node) {
  477. phy = n->phy;
  478. break;
  479. }
  480. }
  481. mutex_unlock(&dsi_phy_list_lock);
  482. if (!phy) {
  483. DSI_PHY_ERR(phy, "Device with of node not found rc=%d\n",
  484. -EPROBE_DEFER);
  485. phy = ERR_PTR(-EPROBE_DEFER);
  486. return phy;
  487. }
  488. mutex_lock(&phy->phy_lock);
  489. if (phy->refcount > 0) {
  490. DSI_PHY_ERR(phy, "Device under use\n");
  491. phy = ERR_PTR(-EINVAL);
  492. } else {
  493. phy->refcount++;
  494. }
  495. mutex_unlock(&phy->phy_lock);
  496. return phy;
  497. }
  498. /**
  499. * dsi_phy_put() - release dsi phy handle
  500. * @dsi_phy: DSI PHY handle.
  501. *
  502. * Release the DSI PHY hardware. Driver will clean up all resources and puts
  503. * back the DSI PHY into reset state.
  504. */
  505. void dsi_phy_put(struct msm_dsi_phy *dsi_phy)
  506. {
  507. mutex_lock(&dsi_phy->phy_lock);
  508. if (dsi_phy->refcount == 0)
  509. DSI_PHY_ERR(dsi_phy, "Unbalanced %s call\n", __func__);
  510. else
  511. dsi_phy->refcount--;
  512. mutex_unlock(&dsi_phy->phy_lock);
  513. }
  514. /**
  515. * dsi_phy_drv_init() - initialize dsi phy driver
  516. * @dsi_phy: DSI PHY handle.
  517. *
  518. * Initializes DSI PHY driver. Should be called after dsi_phy_get().
  519. *
  520. * Return: error code.
  521. */
  522. int dsi_phy_drv_init(struct msm_dsi_phy *dsi_phy)
  523. {
  524. char dbg_name[DSI_DEBUG_NAME_LEN];
  525. snprintf(dbg_name, DSI_DEBUG_NAME_LEN, "dsi%d_phy", dsi_phy->index);
  526. sde_dbg_reg_register_base(dbg_name, dsi_phy->hw.base,
  527. msm_iomap_size(dsi_phy->pdev, "dsi_phy"));
  528. return 0;
  529. }
  530. /**
  531. * dsi_phy_drv_deinit() - de-initialize dsi phy driver
  532. * @dsi_phy: DSI PHY handle.
  533. *
  534. * Release all resources acquired by dsi_phy_drv_init().
  535. *
  536. * Return: error code.
  537. */
  538. int dsi_phy_drv_deinit(struct msm_dsi_phy *dsi_phy)
  539. {
  540. return 0;
  541. }
  542. int dsi_phy_clk_cb_register(struct msm_dsi_phy *dsi_phy,
  543. struct clk_ctrl_cb *clk_cb)
  544. {
  545. if (!dsi_phy || !clk_cb) {
  546. DSI_PHY_ERR(dsi_phy, "Invalid params\n");
  547. return -EINVAL;
  548. }
  549. dsi_phy->clk_cb.priv = clk_cb->priv;
  550. dsi_phy->clk_cb.dsi_clk_cb = clk_cb->dsi_clk_cb;
  551. return 0;
  552. }
  553. /**
  554. * dsi_phy_validate_mode() - validate a display mode
  555. * @dsi_phy: DSI PHY handle.
  556. * @mode: Mode information.
  557. *
  558. * Validation will fail if the mode cannot be supported by the PHY driver or
  559. * hardware.
  560. *
  561. * Return: error code.
  562. */
  563. int dsi_phy_validate_mode(struct msm_dsi_phy *dsi_phy,
  564. struct dsi_mode_info *mode)
  565. {
  566. int rc = 0;
  567. if (!dsi_phy || !mode) {
  568. DSI_PHY_ERR(dsi_phy, "Invalid params\n");
  569. return -EINVAL;
  570. }
  571. DSI_PHY_DBG(dsi_phy, "Skipping validation\n");
  572. return rc;
  573. }
  574. /**
  575. * dsi_phy_set_power_state() - enable/disable dsi phy power supplies
  576. * @dsi_phy: DSI PHY handle.
  577. * @enable: Boolean flag to enable/disable.
  578. *
  579. * Return: error code.
  580. */
  581. int dsi_phy_set_power_state(struct msm_dsi_phy *dsi_phy, bool enable)
  582. {
  583. int rc = 0;
  584. if (!dsi_phy) {
  585. DSI_PHY_ERR(dsi_phy, "Invalid params\n");
  586. return -EINVAL;
  587. }
  588. mutex_lock(&dsi_phy->phy_lock);
  589. if (enable == dsi_phy->power_state) {
  590. DSI_PHY_ERR(dsi_phy, "No state change\n");
  591. goto error;
  592. }
  593. if (enable) {
  594. rc = dsi_pwr_enable_regulator(&dsi_phy->pwr_info.digital, true);
  595. if (rc) {
  596. DSI_PHY_ERR(dsi_phy, "failed to enable digital regulator\n");
  597. goto error;
  598. }
  599. if (dsi_phy->dsi_phy_state == DSI_PHY_ENGINE_OFF &&
  600. dsi_phy->regulator_required) {
  601. rc = dsi_pwr_enable_regulator(
  602. &dsi_phy->pwr_info.phy_pwr, true);
  603. if (rc) {
  604. DSI_PHY_ERR(dsi_phy, "failed to enable phy power\n");
  605. (void)dsi_pwr_enable_regulator(
  606. &dsi_phy->pwr_info.digital, false);
  607. goto error;
  608. }
  609. }
  610. } else {
  611. if (dsi_phy->dsi_phy_state == DSI_PHY_ENGINE_OFF &&
  612. dsi_phy->regulator_required) {
  613. rc = dsi_pwr_enable_regulator(
  614. &dsi_phy->pwr_info.phy_pwr, false);
  615. if (rc) {
  616. DSI_PHY_ERR(dsi_phy, "failed to enable digital regulator\n");
  617. goto error;
  618. }
  619. }
  620. rc = dsi_pwr_enable_regulator(&dsi_phy->pwr_info.digital,
  621. false);
  622. if (rc) {
  623. DSI_PHY_ERR(dsi_phy, "failed to enable phy power\n");
  624. goto error;
  625. }
  626. }
  627. dsi_phy->power_state = enable;
  628. error:
  629. mutex_unlock(&dsi_phy->phy_lock);
  630. return rc;
  631. }
  632. static int dsi_phy_enable_ulps(struct msm_dsi_phy *phy,
  633. struct dsi_host_config *config, bool clamp_enabled)
  634. {
  635. int rc = 0;
  636. u32 lanes = 0;
  637. u32 ulps_lanes;
  638. lanes = config->common_config.data_lanes;
  639. lanes |= DSI_CLOCK_LANE;
  640. /*
  641. * If DSI clamps are enabled, it means that the DSI lanes are
  642. * already in idle state. Checking for lanes to be in idle state
  643. * should be skipped during ULPS entry programming while coming
  644. * out of idle screen.
  645. */
  646. if (!clamp_enabled) {
  647. rc = phy->hw.ops.ulps_ops.wait_for_lane_idle(&phy->hw, lanes);
  648. if (rc) {
  649. DSI_PHY_ERR(phy, "lanes not entering idle, skip ULPS\n");
  650. return rc;
  651. }
  652. }
  653. phy->hw.ops.ulps_ops.ulps_request(&phy->hw, &phy->cfg, lanes);
  654. ulps_lanes = phy->hw.ops.ulps_ops.get_lanes_in_ulps(&phy->hw);
  655. if (!phy->hw.ops.ulps_ops.is_lanes_in_ulps(lanes, ulps_lanes)) {
  656. DSI_PHY_ERR(phy, "Failed to enter ULPS, request=0x%x, actual=0x%x\n",
  657. lanes, ulps_lanes);
  658. rc = -EIO;
  659. }
  660. return rc;
  661. }
  662. static int dsi_phy_disable_ulps(struct msm_dsi_phy *phy,
  663. struct dsi_host_config *config)
  664. {
  665. u32 ulps_lanes, lanes = 0;
  666. lanes = config->common_config.data_lanes;
  667. lanes |= DSI_CLOCK_LANE;
  668. ulps_lanes = phy->hw.ops.ulps_ops.get_lanes_in_ulps(&phy->hw);
  669. if (!phy->hw.ops.ulps_ops.is_lanes_in_ulps(lanes, ulps_lanes)) {
  670. DSI_PHY_ERR(phy, "Mismatch in ULPS: lanes:%d, ulps_lanes:%d\n",
  671. lanes, ulps_lanes);
  672. return -EIO;
  673. }
  674. phy->hw.ops.ulps_ops.ulps_exit(&phy->hw, &phy->cfg, lanes);
  675. ulps_lanes = phy->hw.ops.ulps_ops.get_lanes_in_ulps(&phy->hw);
  676. if (phy->hw.ops.ulps_ops.is_lanes_in_ulps(lanes, ulps_lanes)) {
  677. DSI_PHY_ERR(phy, "Lanes (0x%x) stuck in ULPS\n", ulps_lanes);
  678. return -EIO;
  679. }
  680. return 0;
  681. }
  682. void dsi_phy_toggle_resync_fifo(struct msm_dsi_phy *phy)
  683. {
  684. if (!phy)
  685. return;
  686. if (!phy->hw.ops.toggle_resync_fifo)
  687. return;
  688. phy->hw.ops.toggle_resync_fifo(&phy->hw);
  689. }
  690. void dsi_phy_reset_clk_en_sel(struct msm_dsi_phy *phy)
  691. {
  692. if (!phy)
  693. return;
  694. if (!phy->hw.ops.reset_clk_en_sel)
  695. return;
  696. phy->hw.ops.reset_clk_en_sel(&phy->hw);
  697. }
  698. int dsi_phy_set_ulps(struct msm_dsi_phy *phy, struct dsi_host_config *config,
  699. bool enable, bool clamp_enabled)
  700. {
  701. int rc = 0;
  702. if (!phy) {
  703. DSI_PHY_ERR(phy, "Invalid params\n");
  704. return DSI_PHY_ULPS_ERROR;
  705. }
  706. if (!phy->hw.ops.ulps_ops.ulps_request ||
  707. !phy->hw.ops.ulps_ops.ulps_exit ||
  708. !phy->hw.ops.ulps_ops.get_lanes_in_ulps ||
  709. !phy->hw.ops.ulps_ops.is_lanes_in_ulps ||
  710. !phy->hw.ops.ulps_ops.wait_for_lane_idle) {
  711. DSI_PHY_DBG(phy, "DSI PHY ULPS ops not present\n");
  712. return DSI_PHY_ULPS_NOT_HANDLED;
  713. }
  714. mutex_lock(&phy->phy_lock);
  715. if (enable)
  716. rc = dsi_phy_enable_ulps(phy, config, clamp_enabled);
  717. else
  718. rc = dsi_phy_disable_ulps(phy, config);
  719. if (rc) {
  720. DSI_PHY_ERR(phy, "Ulps state change(%d) failed, rc=%d\n",
  721. enable, rc);
  722. rc = DSI_PHY_ULPS_ERROR;
  723. goto error;
  724. }
  725. DSI_PHY_DBG(phy, "ULPS state = %d\n", enable);
  726. error:
  727. mutex_unlock(&phy->phy_lock);
  728. return rc;
  729. }
  730. /**
  731. * dsi_phy_enable() - enable DSI PHY hardware
  732. * @dsi_phy: DSI PHY handle.
  733. * @config: DSI host configuration.
  734. * @pll_source: Source PLL for PHY clock.
  735. * @skip_validation: Validation will not be performed on parameters.
  736. * @skip_op: Skip re-enabling dsi phy hw during usecases like
  737. * cont-splash/trusted-vm if set to true.
  738. *
  739. * Validates and enables DSI PHY.
  740. *
  741. * Return: error code.
  742. */
  743. int dsi_phy_enable(struct msm_dsi_phy *phy,
  744. struct dsi_host_config *config,
  745. enum dsi_phy_pll_source pll_source,
  746. bool skip_validation,
  747. bool skip_op)
  748. {
  749. int rc = 0;
  750. if (!phy || !config) {
  751. DSI_PHY_ERR(phy, "Invalid params\n");
  752. return -EINVAL;
  753. }
  754. mutex_lock(&phy->phy_lock);
  755. if (!skip_validation)
  756. DSI_PHY_DBG(phy, "TODO: perform validation\n");
  757. memcpy(&phy->mode, &config->video_timing, sizeof(phy->mode));
  758. memcpy(&phy->cfg.lane_map, &config->lane_map, sizeof(config->lane_map));
  759. phy->data_lanes = config->common_config.data_lanes;
  760. phy->dst_format = config->common_config.dst_format;
  761. phy->cfg.pll_source = pll_source;
  762. phy->cfg.bit_clk_rate_hz = config->bit_clk_rate_hz;
  763. /**
  764. * If PHY timing parameters are not present in panel dtsi file,
  765. * then calculate them in the driver
  766. */
  767. if (!phy->cfg.is_phy_timing_present)
  768. rc = phy->hw.ops.calculate_timing_params(&phy->hw,
  769. &phy->mode,
  770. &config->common_config,
  771. &phy->cfg.timing, false);
  772. if (rc) {
  773. DSI_PHY_ERR(phy, "failed to set timing, rc=%d\n", rc);
  774. goto error;
  775. }
  776. if (!skip_op) {
  777. dsi_phy_enable_hw(phy);
  778. DSI_PHY_DBG(phy, "cont splash not enabled, phy enable required\n");
  779. }
  780. phy->dsi_phy_state = DSI_PHY_ENGINE_ON;
  781. error:
  782. mutex_unlock(&phy->phy_lock);
  783. return rc;
  784. }
  785. /* update dsi phy timings for dynamic clk switch use case */
  786. int dsi_phy_update_phy_timings(struct msm_dsi_phy *phy,
  787. struct dsi_host_config *config)
  788. {
  789. int rc = 0;
  790. if (!phy || !config) {
  791. DSI_PHY_ERR(phy, "invalid argument\n");
  792. return -EINVAL;
  793. }
  794. memcpy(&phy->mode, &config->video_timing, sizeof(phy->mode));
  795. rc = phy->hw.ops.calculate_timing_params(&phy->hw, &phy->mode,
  796. &config->common_config,
  797. &phy->cfg.timing, true);
  798. if (rc)
  799. DSI_PHY_ERR(phy, "failed to calculate phy timings %d\n", rc);
  800. return rc;
  801. }
  802. int dsi_phy_lane_reset(struct msm_dsi_phy *phy)
  803. {
  804. int ret = 0;
  805. if (!phy)
  806. return ret;
  807. mutex_lock(&phy->phy_lock);
  808. if (phy->hw.ops.phy_lane_reset)
  809. ret = phy->hw.ops.phy_lane_reset(&phy->hw);
  810. mutex_unlock(&phy->phy_lock);
  811. return ret;
  812. }
  813. /**
  814. * dsi_phy_disable() - disable DSI PHY hardware.
  815. * @phy: DSI PHY handle.
  816. * @skip_op: Skip disabling dsi phy hw during usecases like
  817. * trusted-vm if set to true.
  818. *
  819. * Return: error code.
  820. */
  821. int dsi_phy_disable(struct msm_dsi_phy *phy, bool skip_op)
  822. {
  823. int rc = 0;
  824. if (!phy) {
  825. DSI_PHY_ERR(phy, "Invalid params\n");
  826. return -EINVAL;
  827. }
  828. mutex_lock(&phy->phy_lock);
  829. if (!skip_op)
  830. dsi_phy_disable_hw(phy);
  831. phy->dsi_phy_state = DSI_PHY_ENGINE_OFF;
  832. mutex_unlock(&phy->phy_lock);
  833. return rc;
  834. }
  835. /**
  836. * dsi_phy_set_clamp_state() - configure clamps for DSI lanes
  837. * @phy: DSI PHY handle.
  838. * @enable: boolean to specify clamp enable/disable.
  839. *
  840. * Return: error code.
  841. */
  842. int dsi_phy_set_clamp_state(struct msm_dsi_phy *phy, bool enable)
  843. {
  844. if (!phy)
  845. return -EINVAL;
  846. DSI_PHY_DBG(phy, "enable=%d\n", enable);
  847. if (phy->hw.ops.clamp_ctrl)
  848. phy->hw.ops.clamp_ctrl(&phy->hw, enable);
  849. return 0;
  850. }
  851. /**
  852. * dsi_phy_idle_ctrl() - enable/disable DSI PHY during idle screen
  853. * @phy: DSI PHY handle
  854. * @enable: boolean to specify PHY enable/disable.
  855. *
  856. * Return: error code.
  857. */
  858. int dsi_phy_idle_ctrl(struct msm_dsi_phy *phy, bool enable)
  859. {
  860. if (!phy) {
  861. DSI_PHY_ERR(phy, "Invalid params\n");
  862. return -EINVAL;
  863. }
  864. DSI_PHY_DBG(phy, "enable=%d\n", enable);
  865. mutex_lock(&phy->phy_lock);
  866. if (enable) {
  867. if (phy->hw.ops.phy_idle_on)
  868. phy->hw.ops.phy_idle_on(&phy->hw, &phy->cfg);
  869. if (phy->hw.ops.regulator_enable)
  870. phy->hw.ops.regulator_enable(&phy->hw,
  871. &phy->cfg.regulators);
  872. if (phy->hw.ops.enable)
  873. phy->hw.ops.enable(&phy->hw, &phy->cfg);
  874. phy->dsi_phy_state = DSI_PHY_ENGINE_ON;
  875. } else {
  876. phy->dsi_phy_state = DSI_PHY_ENGINE_OFF;
  877. if (phy->hw.ops.disable)
  878. phy->hw.ops.disable(&phy->hw, &phy->cfg);
  879. if (phy->hw.ops.phy_idle_off)
  880. phy->hw.ops.phy_idle_off(&phy->hw);
  881. }
  882. mutex_unlock(&phy->phy_lock);
  883. return 0;
  884. }
  885. /**
  886. * dsi_phy_set_clk_freq() - set DSI PHY clock frequency setting
  887. * @phy: DSI PHY handle
  888. * @clk_freq: link clock frequency
  889. *
  890. * Return: error code.
  891. */
  892. int dsi_phy_set_clk_freq(struct msm_dsi_phy *phy,
  893. struct link_clk_freq *clk_freq)
  894. {
  895. if (!phy || !clk_freq) {
  896. DSI_PHY_ERR(phy, "Invalid params\n");
  897. return -EINVAL;
  898. }
  899. phy->regulator_required = clk_freq->byte_clk_rate >
  900. (phy->regulator_min_datarate_bps / BITS_PER_BYTE);
  901. /*
  902. * DSI PLL needs 0p9 LDO1A for Powering DSI PLL block.
  903. * PLL driver can vote for this regulator in PLL driver file, but for
  904. * the usecase where we come out of idle(static screen), if PLL and
  905. * PHY vote for regulator ,there will be performance delays as both
  906. * votes go through RPM to enable regulators.
  907. */
  908. phy->regulator_required = true;
  909. DSI_PHY_DBG(phy, "lane_datarate=%u min_datarate=%u required=%d\n",
  910. clk_freq->byte_clk_rate * BITS_PER_BYTE,
  911. phy->regulator_min_datarate_bps,
  912. phy->regulator_required);
  913. return 0;
  914. }
  915. /**
  916. * dsi_phy_set_timing_params() - timing parameters for the panel
  917. * @phy: DSI PHY handle
  918. * @timing: array holding timing params.
  919. * @size: size of the array.
  920. * @commit: boolean to indicate if programming PHY HW registers is
  921. * required
  922. *
  923. * When PHY timing calculator is not implemented, this array will be used to
  924. * pass PHY timing information.
  925. *
  926. * Return: error code.
  927. */
  928. int dsi_phy_set_timing_params(struct msm_dsi_phy *phy,
  929. u32 *timing, u32 size, bool commit)
  930. {
  931. int rc = 0;
  932. if (!phy || !timing || !size) {
  933. DSI_PHY_ERR(phy, "Invalid params\n");
  934. return -EINVAL;
  935. }
  936. mutex_lock(&phy->phy_lock);
  937. if (phy->hw.ops.phy_timing_val)
  938. rc = phy->hw.ops.phy_timing_val(&phy->cfg.timing, timing, size);
  939. if (!rc)
  940. phy->cfg.is_phy_timing_present = true;
  941. if (phy->hw.ops.commit_phy_timing && commit)
  942. phy->hw.ops.commit_phy_timing(&phy->hw, &phy->cfg.timing);
  943. mutex_unlock(&phy->phy_lock);
  944. return rc;
  945. }
  946. /**
  947. * dsi_phy_conv_phy_to_logical_lane() - Convert physical to logical lane
  948. * @lane_map: logical lane
  949. * @phy_lane: physical lane
  950. *
  951. * Return: Error code on failure. Lane number on success.
  952. */
  953. int dsi_phy_conv_phy_to_logical_lane(
  954. struct dsi_lane_map *lane_map, enum dsi_phy_data_lanes phy_lane)
  955. {
  956. int i = 0;
  957. if (phy_lane > DSI_PHYSICAL_LANE_3)
  958. return -EINVAL;
  959. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++) {
  960. if (lane_map->lane_map_v2[i] == phy_lane)
  961. break;
  962. }
  963. return i;
  964. }
  965. /**
  966. * dsi_phy_conv_logical_to_phy_lane() - Convert logical to physical lane
  967. * @lane_map: physical lane
  968. * @lane: logical lane
  969. *
  970. * Return: Error code on failure. Lane number on success.
  971. */
  972. int dsi_phy_conv_logical_to_phy_lane(
  973. struct dsi_lane_map *lane_map, enum dsi_logical_lane lane)
  974. {
  975. int i = 0;
  976. if (lane > (DSI_LANE_MAX - 1))
  977. return -EINVAL;
  978. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++) {
  979. if (BIT(i) == lane_map->lane_map_v2[lane])
  980. break;
  981. }
  982. return i;
  983. }
  984. /**
  985. * dsi_phy_config_dynamic_refresh() - Configure dynamic refresh registers
  986. * @phy: DSI PHY handle
  987. * @delay: pipe delays for dynamic refresh
  988. * @is_master: Boolean to indicate if for master or slave.
  989. */
  990. void dsi_phy_config_dynamic_refresh(struct msm_dsi_phy *phy,
  991. struct dsi_dyn_clk_delay *delay,
  992. bool is_master)
  993. {
  994. struct dsi_phy_cfg *cfg;
  995. if (!phy)
  996. return;
  997. mutex_lock(&phy->phy_lock);
  998. cfg = &phy->cfg;
  999. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_config)
  1000. phy->hw.ops.dyn_refresh_ops.dyn_refresh_config(&phy->hw, cfg,
  1001. is_master);
  1002. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_pipe_delay)
  1003. phy->hw.ops.dyn_refresh_ops.dyn_refresh_pipe_delay(
  1004. &phy->hw, delay);
  1005. mutex_unlock(&phy->phy_lock);
  1006. }
  1007. /**
  1008. * dsi_phy_dynamic_refresh_trigger() - trigger dynamic refresh
  1009. * @phy: DSI PHY handle
  1010. * @is_master: Boolean to indicate if for master or slave.
  1011. */
  1012. void dsi_phy_dynamic_refresh_trigger(struct msm_dsi_phy *phy, bool is_master)
  1013. {
  1014. u32 off;
  1015. if (!phy)
  1016. return;
  1017. mutex_lock(&phy->phy_lock);
  1018. /*
  1019. * program PLL_SWI_INTF_SEL and SW_TRIGGER bit only for
  1020. * master and program SYNC_MODE bit only for slave.
  1021. */
  1022. if (is_master)
  1023. off = BIT(DYN_REFRESH_INTF_SEL) | BIT(DYN_REFRESH_SWI_CTRL) |
  1024. BIT(DYN_REFRESH_SW_TRIGGER);
  1025. else
  1026. off = BIT(DYN_REFRESH_SYNC_MODE) | BIT(DYN_REFRESH_SWI_CTRL);
  1027. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper)
  1028. phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper(&phy->hw, off);
  1029. mutex_unlock(&phy->phy_lock);
  1030. }
  1031. /**
  1032. * dsi_phy_cache_phy_timings - cache the phy timings calculated as part of
  1033. * dynamic refresh.
  1034. * @phy: DSI PHY Handle.
  1035. * @dst: Pointer to cache location.
  1036. * @size: Number of phy lane settings.
  1037. */
  1038. int dsi_phy_dyn_refresh_cache_phy_timings(struct msm_dsi_phy *phy, u32 *dst,
  1039. u32 size)
  1040. {
  1041. int rc = 0;
  1042. if (!phy || !dst || !size)
  1043. return -EINVAL;
  1044. if (phy->hw.ops.dyn_refresh_ops.cache_phy_timings)
  1045. rc = phy->hw.ops.dyn_refresh_ops.cache_phy_timings(
  1046. &phy->cfg.timing, dst, size);
  1047. if (rc)
  1048. DSI_PHY_ERR(phy, "failed to cache phy timings %d\n", rc);
  1049. return rc;
  1050. }
  1051. /**
  1052. * dsi_phy_dynamic_refresh_clear() - clear dynamic refresh config
  1053. * @phy: DSI PHY handle
  1054. */
  1055. void dsi_phy_dynamic_refresh_clear(struct msm_dsi_phy *phy)
  1056. {
  1057. if (!phy)
  1058. return;
  1059. mutex_lock(&phy->phy_lock);
  1060. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper)
  1061. phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper(&phy->hw, 0);
  1062. mutex_unlock(&phy->phy_lock);
  1063. }
  1064. /**
  1065. * dsi_phy_set_continuous_clk() - set/unset force clock lane HS request
  1066. * @phy: DSI PHY handle
  1067. * @enable: variable to control continuous clock
  1068. */
  1069. void dsi_phy_set_continuous_clk(struct msm_dsi_phy *phy, bool enable)
  1070. {
  1071. if (!phy)
  1072. return;
  1073. mutex_lock(&phy->phy_lock);
  1074. if (phy->hw.ops.set_continuous_clk)
  1075. phy->hw.ops.set_continuous_clk(&phy->hw, enable);
  1076. else
  1077. DSI_PHY_WARN(phy, "set_continuous_clk ops not present\n");
  1078. mutex_unlock(&phy->phy_lock);
  1079. }
  1080. void dsi_phy_drv_register(void)
  1081. {
  1082. platform_driver_register(&dsi_phy_platform_driver);
  1083. }
  1084. void dsi_phy_drv_unregister(void)
  1085. {
  1086. platform_driver_unregister(&dsi_phy_platform_driver);
  1087. }