dsi_phy.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  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. phy->cfg.force_clk_lane_hs = of_property_read_bool(pdev->dev.of_node,
  297. "qcom,panel-force-clock-lane-hs");
  298. return 0;
  299. err:
  300. lane->count_per_lane = 0;
  301. strength->count_per_lane = 0;
  302. regs->count_per_lane = 0;
  303. timing->count_per_lane = 0;
  304. return rc;
  305. }
  306. static int dsi_phy_settings_deinit(struct msm_dsi_phy *phy)
  307. {
  308. memset(&phy->cfg.lanecfg, 0x0, sizeof(phy->cfg.lanecfg));
  309. memset(&phy->cfg.strength, 0x0, sizeof(phy->cfg.strength));
  310. memset(&phy->cfg.timing, 0x0, sizeof(phy->cfg.timing));
  311. memset(&phy->cfg.regulators, 0x0, sizeof(phy->cfg.regulators));
  312. return 0;
  313. }
  314. static int dsi_phy_driver_probe(struct platform_device *pdev)
  315. {
  316. struct msm_dsi_phy *dsi_phy;
  317. struct dsi_phy_list_item *item;
  318. const struct of_device_id *id;
  319. const struct dsi_ver_spec_info *ver_info;
  320. int rc = 0;
  321. u32 index = 0;
  322. if (!pdev || !pdev->dev.of_node) {
  323. DSI_ERR("pdev not found\n");
  324. return -ENODEV;
  325. }
  326. id = of_match_node(msm_dsi_phy_of_match, pdev->dev.of_node);
  327. if (!id)
  328. return -ENODEV;
  329. ver_info = id->data;
  330. item = devm_kzalloc(&pdev->dev, sizeof(*item), GFP_KERNEL);
  331. if (!item)
  332. return -ENOMEM;
  333. dsi_phy = devm_kzalloc(&pdev->dev, sizeof(*dsi_phy), GFP_KERNEL);
  334. if (!dsi_phy) {
  335. devm_kfree(&pdev->dev, item);
  336. return -ENOMEM;
  337. }
  338. rc = of_property_read_u32(pdev->dev.of_node, "cell-index", &index);
  339. if (rc) {
  340. DSI_PHY_DBG(dsi_phy, "cell index not set, default to 0\n");
  341. index = 0;
  342. }
  343. dsi_phy->index = index;
  344. dsi_phy->name = of_get_property(pdev->dev.of_node, "label", NULL);
  345. if (!dsi_phy->name)
  346. dsi_phy->name = DSI_PHY_DEFAULT_LABEL;
  347. DSI_PHY_DBG(dsi_phy, "Probing device\n");
  348. dsi_phy->ver_info = ver_info;
  349. rc = dsi_phy_regmap_init(pdev, dsi_phy);
  350. if (rc) {
  351. DSI_PHY_ERR(dsi_phy, "Failed to parse register information, rc=%d\n",
  352. rc);
  353. goto fail;
  354. }
  355. rc = dsi_phy_supplies_init(pdev, dsi_phy);
  356. if (rc) {
  357. DSI_PHY_ERR(dsi_phy, "failed to parse voltage supplies, rc = %d\n",
  358. rc);
  359. goto fail_regmap;
  360. }
  361. rc = dsi_catalog_phy_setup(&dsi_phy->hw, ver_info->version,
  362. dsi_phy->index);
  363. if (rc) {
  364. DSI_PHY_ERR(dsi_phy, "Catalog does not support version (%d)\n",
  365. ver_info->version);
  366. goto fail_supplies;
  367. }
  368. rc = dsi_phy_settings_init(pdev, dsi_phy);
  369. if (rc) {
  370. DSI_PHY_ERR(dsi_phy, "Failed to parse phy setting, rc=%d\n",
  371. rc);
  372. goto fail_supplies;
  373. }
  374. rc = dsi_pll_init(pdev, &dsi_phy->pll);
  375. if (rc) {
  376. DSI_PHY_ERR(dsi_phy, "Failed to initialize DSI PLL, rc=%d\n", rc);
  377. goto fail_settings;
  378. }
  379. item->phy = dsi_phy;
  380. mutex_lock(&dsi_phy_list_lock);
  381. list_add(&item->list, &dsi_phy_list);
  382. mutex_unlock(&dsi_phy_list_lock);
  383. mutex_init(&dsi_phy->phy_lock);
  384. /** TODO: initialize debugfs */
  385. dsi_phy->pdev = pdev;
  386. platform_set_drvdata(pdev, dsi_phy);
  387. DSI_PHY_INFO(dsi_phy, "Probe successful\n");
  388. return 0;
  389. fail_settings:
  390. (void)dsi_phy_settings_deinit(dsi_phy);
  391. fail_supplies:
  392. (void)dsi_phy_supplies_deinit(dsi_phy);
  393. fail_regmap:
  394. (void)dsi_phy_regmap_deinit(dsi_phy);
  395. fail:
  396. devm_kfree(&pdev->dev, dsi_phy);
  397. devm_kfree(&pdev->dev, item);
  398. return rc;
  399. }
  400. static int dsi_phy_driver_remove(struct platform_device *pdev)
  401. {
  402. int rc = 0;
  403. struct msm_dsi_phy *phy = platform_get_drvdata(pdev);
  404. struct list_head *pos, *tmp;
  405. if (!pdev || !phy) {
  406. DSI_PHY_ERR(phy, "Invalid device\n");
  407. return -EINVAL;
  408. }
  409. mutex_lock(&dsi_phy_list_lock);
  410. list_for_each_safe(pos, tmp, &dsi_phy_list) {
  411. struct dsi_phy_list_item *n;
  412. n = list_entry(pos, struct dsi_phy_list_item, list);
  413. if (n->phy == phy) {
  414. list_del(&n->list);
  415. devm_kfree(&pdev->dev, n);
  416. break;
  417. }
  418. }
  419. mutex_unlock(&dsi_phy_list_lock);
  420. mutex_lock(&phy->phy_lock);
  421. rc = dsi_phy_settings_deinit(phy);
  422. if (rc)
  423. DSI_PHY_ERR(phy, "failed to deinitialize phy settings, rc=%d\n",
  424. rc);
  425. rc = dsi_phy_supplies_deinit(phy);
  426. if (rc)
  427. DSI_PHY_ERR(phy, "failed to deinitialize voltage supplies, rc=%d\n",
  428. rc);
  429. rc = dsi_phy_regmap_deinit(phy);
  430. if (rc)
  431. DSI_PHY_ERR(phy, "failed to deinitialize regmap, rc=%d\n", rc);
  432. mutex_unlock(&phy->phy_lock);
  433. mutex_destroy(&phy->phy_lock);
  434. devm_kfree(&pdev->dev, phy);
  435. platform_set_drvdata(pdev, NULL);
  436. return 0;
  437. }
  438. static struct platform_driver dsi_phy_platform_driver = {
  439. .probe = dsi_phy_driver_probe,
  440. .remove = dsi_phy_driver_remove,
  441. .driver = {
  442. .name = "dsi_phy",
  443. .of_match_table = msm_dsi_phy_of_match,
  444. },
  445. };
  446. static void dsi_phy_enable_hw(struct msm_dsi_phy *phy)
  447. {
  448. if (phy->hw.ops.regulator_enable)
  449. phy->hw.ops.regulator_enable(&phy->hw, &phy->cfg.regulators);
  450. if (phy->hw.ops.enable)
  451. phy->hw.ops.enable(&phy->hw, &phy->cfg);
  452. }
  453. static void dsi_phy_disable_hw(struct msm_dsi_phy *phy)
  454. {
  455. if (phy->hw.ops.disable)
  456. phy->hw.ops.disable(&phy->hw, &phy->cfg);
  457. if (phy->hw.ops.regulator_disable)
  458. phy->hw.ops.regulator_disable(&phy->hw);
  459. }
  460. /**
  461. * dsi_phy_get() - get a dsi phy handle from device node
  462. * @of_node: device node for dsi phy controller
  463. *
  464. * Gets the DSI PHY handle for the corresponding of_node. The ref count is
  465. * incremented to one all subsequents get will fail until the original client
  466. * calls a put.
  467. *
  468. * Return: DSI PHY handle or an error code.
  469. */
  470. struct msm_dsi_phy *dsi_phy_get(struct device_node *of_node)
  471. {
  472. struct list_head *pos, *tmp;
  473. struct msm_dsi_phy *phy = NULL;
  474. mutex_lock(&dsi_phy_list_lock);
  475. list_for_each_safe(pos, tmp, &dsi_phy_list) {
  476. struct dsi_phy_list_item *n;
  477. n = list_entry(pos, struct dsi_phy_list_item, list);
  478. if (n->phy->pdev->dev.of_node == of_node) {
  479. phy = n->phy;
  480. break;
  481. }
  482. }
  483. mutex_unlock(&dsi_phy_list_lock);
  484. if (!phy) {
  485. DSI_PHY_ERR(phy, "Device with of node not found\n");
  486. phy = ERR_PTR(-EPROBE_DEFER);
  487. return phy;
  488. }
  489. mutex_lock(&phy->phy_lock);
  490. if (phy->refcount > 0) {
  491. DSI_PHY_ERR(phy, "Device under use\n");
  492. phy = ERR_PTR(-EINVAL);
  493. } else {
  494. phy->refcount++;
  495. }
  496. mutex_unlock(&phy->phy_lock);
  497. return phy;
  498. }
  499. /**
  500. * dsi_phy_put() - release dsi phy handle
  501. * @dsi_phy: DSI PHY handle.
  502. *
  503. * Release the DSI PHY hardware. Driver will clean up all resources and puts
  504. * back the DSI PHY into reset state.
  505. */
  506. void dsi_phy_put(struct msm_dsi_phy *dsi_phy)
  507. {
  508. mutex_lock(&dsi_phy->phy_lock);
  509. if (dsi_phy->refcount == 0)
  510. DSI_PHY_ERR(dsi_phy, "Unbalanced %s call\n", __func__);
  511. else
  512. dsi_phy->refcount--;
  513. mutex_unlock(&dsi_phy->phy_lock);
  514. }
  515. /**
  516. * dsi_phy_drv_init() - initialize dsi phy driver
  517. * @dsi_phy: DSI PHY handle.
  518. *
  519. * Initializes DSI PHY driver. Should be called after dsi_phy_get().
  520. *
  521. * Return: error code.
  522. */
  523. int dsi_phy_drv_init(struct msm_dsi_phy *dsi_phy)
  524. {
  525. char dbg_name[DSI_DEBUG_NAME_LEN];
  526. snprintf(dbg_name, DSI_DEBUG_NAME_LEN, "dsi%d_phy", dsi_phy->index);
  527. sde_dbg_reg_register_base(dbg_name, dsi_phy->hw.base,
  528. msm_iomap_size(dsi_phy->pdev, "dsi_phy"));
  529. return 0;
  530. }
  531. /**
  532. * dsi_phy_drv_deinit() - de-initialize dsi phy driver
  533. * @dsi_phy: DSI PHY handle.
  534. *
  535. * Release all resources acquired by dsi_phy_drv_init().
  536. *
  537. * Return: error code.
  538. */
  539. int dsi_phy_drv_deinit(struct msm_dsi_phy *dsi_phy)
  540. {
  541. return 0;
  542. }
  543. int dsi_phy_clk_cb_register(struct msm_dsi_phy *dsi_phy,
  544. struct clk_ctrl_cb *clk_cb)
  545. {
  546. if (!dsi_phy || !clk_cb) {
  547. DSI_PHY_ERR(dsi_phy, "Invalid params\n");
  548. return -EINVAL;
  549. }
  550. dsi_phy->clk_cb.priv = clk_cb->priv;
  551. dsi_phy->clk_cb.dsi_clk_cb = clk_cb->dsi_clk_cb;
  552. return 0;
  553. }
  554. /**
  555. * dsi_phy_validate_mode() - validate a display mode
  556. * @dsi_phy: DSI PHY handle.
  557. * @mode: Mode information.
  558. *
  559. * Validation will fail if the mode cannot be supported by the PHY driver or
  560. * hardware.
  561. *
  562. * Return: error code.
  563. */
  564. int dsi_phy_validate_mode(struct msm_dsi_phy *dsi_phy,
  565. struct dsi_mode_info *mode)
  566. {
  567. int rc = 0;
  568. if (!dsi_phy || !mode) {
  569. DSI_PHY_ERR(dsi_phy, "Invalid params\n");
  570. return -EINVAL;
  571. }
  572. DSI_PHY_DBG(dsi_phy, "Skipping validation\n");
  573. return rc;
  574. }
  575. /**
  576. * dsi_phy_set_power_state() - enable/disable dsi phy power supplies
  577. * @dsi_phy: DSI PHY handle.
  578. * @enable: Boolean flag to enable/disable.
  579. *
  580. * Return: error code.
  581. */
  582. int dsi_phy_set_power_state(struct msm_dsi_phy *dsi_phy, bool enable)
  583. {
  584. int rc = 0;
  585. if (!dsi_phy) {
  586. DSI_PHY_ERR(dsi_phy, "Invalid params\n");
  587. return -EINVAL;
  588. }
  589. mutex_lock(&dsi_phy->phy_lock);
  590. if (enable == dsi_phy->power_state) {
  591. DSI_PHY_ERR(dsi_phy, "No state change\n");
  592. goto error;
  593. }
  594. if (enable) {
  595. rc = dsi_pwr_enable_regulator(&dsi_phy->pwr_info.digital, true);
  596. if (rc) {
  597. DSI_PHY_ERR(dsi_phy, "failed to enable digital regulator\n");
  598. goto error;
  599. }
  600. if (dsi_phy->dsi_phy_state == DSI_PHY_ENGINE_OFF &&
  601. dsi_phy->regulator_required) {
  602. rc = dsi_pwr_enable_regulator(
  603. &dsi_phy->pwr_info.phy_pwr, true);
  604. if (rc) {
  605. DSI_PHY_ERR(dsi_phy, "failed to enable phy power\n");
  606. (void)dsi_pwr_enable_regulator(
  607. &dsi_phy->pwr_info.digital, false);
  608. goto error;
  609. }
  610. }
  611. } else {
  612. if (dsi_phy->dsi_phy_state == DSI_PHY_ENGINE_OFF &&
  613. dsi_phy->regulator_required) {
  614. rc = dsi_pwr_enable_regulator(
  615. &dsi_phy->pwr_info.phy_pwr, false);
  616. if (rc) {
  617. DSI_PHY_ERR(dsi_phy, "failed to enable digital regulator\n");
  618. goto error;
  619. }
  620. }
  621. rc = dsi_pwr_enable_regulator(&dsi_phy->pwr_info.digital,
  622. false);
  623. if (rc) {
  624. DSI_PHY_ERR(dsi_phy, "failed to enable phy power\n");
  625. goto error;
  626. }
  627. }
  628. dsi_phy->power_state = enable;
  629. error:
  630. mutex_unlock(&dsi_phy->phy_lock);
  631. return rc;
  632. }
  633. static int dsi_phy_enable_ulps(struct msm_dsi_phy *phy,
  634. struct dsi_host_config *config, bool clamp_enabled)
  635. {
  636. int rc = 0;
  637. u32 lanes = 0;
  638. u32 ulps_lanes;
  639. lanes = config->common_config.data_lanes;
  640. lanes |= DSI_CLOCK_LANE;
  641. /*
  642. * If DSI clamps are enabled, it means that the DSI lanes are
  643. * already in idle state. Checking for lanes to be in idle state
  644. * should be skipped during ULPS entry programming while coming
  645. * out of idle screen.
  646. */
  647. if (!clamp_enabled) {
  648. rc = phy->hw.ops.ulps_ops.wait_for_lane_idle(&phy->hw, lanes);
  649. if (rc) {
  650. DSI_PHY_ERR(phy, "lanes not entering idle, skip ULPS\n");
  651. return rc;
  652. }
  653. }
  654. phy->hw.ops.ulps_ops.ulps_request(&phy->hw, &phy->cfg, lanes);
  655. ulps_lanes = phy->hw.ops.ulps_ops.get_lanes_in_ulps(&phy->hw);
  656. if (!phy->hw.ops.ulps_ops.is_lanes_in_ulps(lanes, ulps_lanes)) {
  657. DSI_PHY_ERR(phy, "Failed to enter ULPS, request=0x%x, actual=0x%x\n",
  658. lanes, ulps_lanes);
  659. rc = -EIO;
  660. }
  661. return rc;
  662. }
  663. static int dsi_phy_disable_ulps(struct msm_dsi_phy *phy,
  664. struct dsi_host_config *config)
  665. {
  666. u32 ulps_lanes, lanes = 0;
  667. lanes = config->common_config.data_lanes;
  668. lanes |= DSI_CLOCK_LANE;
  669. ulps_lanes = phy->hw.ops.ulps_ops.get_lanes_in_ulps(&phy->hw);
  670. if (!phy->hw.ops.ulps_ops.is_lanes_in_ulps(lanes, ulps_lanes)) {
  671. DSI_PHY_ERR(phy, "Mismatch in ULPS: lanes:%d, ulps_lanes:%d\n",
  672. lanes, ulps_lanes);
  673. return -EIO;
  674. }
  675. phy->hw.ops.ulps_ops.ulps_exit(&phy->hw, &phy->cfg, lanes);
  676. ulps_lanes = phy->hw.ops.ulps_ops.get_lanes_in_ulps(&phy->hw);
  677. if (phy->hw.ops.ulps_ops.is_lanes_in_ulps(lanes, ulps_lanes)) {
  678. DSI_PHY_ERR(phy, "Lanes (0x%x) stuck in ULPS\n", ulps_lanes);
  679. return -EIO;
  680. }
  681. return 0;
  682. }
  683. void dsi_phy_toggle_resync_fifo(struct msm_dsi_phy *phy)
  684. {
  685. if (!phy)
  686. return;
  687. if (!phy->hw.ops.toggle_resync_fifo)
  688. return;
  689. phy->hw.ops.toggle_resync_fifo(&phy->hw);
  690. }
  691. void dsi_phy_reset_clk_en_sel(struct msm_dsi_phy *phy)
  692. {
  693. if (!phy)
  694. return;
  695. if (!phy->hw.ops.reset_clk_en_sel)
  696. return;
  697. phy->hw.ops.reset_clk_en_sel(&phy->hw);
  698. }
  699. int dsi_phy_set_ulps(struct msm_dsi_phy *phy, struct dsi_host_config *config,
  700. bool enable, bool clamp_enabled)
  701. {
  702. int rc = 0;
  703. if (!phy) {
  704. DSI_PHY_ERR(phy, "Invalid params\n");
  705. return DSI_PHY_ULPS_ERROR;
  706. }
  707. if (!phy->hw.ops.ulps_ops.ulps_request ||
  708. !phy->hw.ops.ulps_ops.ulps_exit ||
  709. !phy->hw.ops.ulps_ops.get_lanes_in_ulps ||
  710. !phy->hw.ops.ulps_ops.is_lanes_in_ulps ||
  711. !phy->hw.ops.ulps_ops.wait_for_lane_idle) {
  712. DSI_PHY_DBG(phy, "DSI PHY ULPS ops not present\n");
  713. return DSI_PHY_ULPS_NOT_HANDLED;
  714. }
  715. mutex_lock(&phy->phy_lock);
  716. if (enable)
  717. rc = dsi_phy_enable_ulps(phy, config, clamp_enabled);
  718. else
  719. rc = dsi_phy_disable_ulps(phy, config);
  720. if (rc) {
  721. DSI_PHY_ERR(phy, "Ulps state change(%d) failed, rc=%d\n",
  722. enable, rc);
  723. rc = DSI_PHY_ULPS_ERROR;
  724. goto error;
  725. }
  726. DSI_PHY_DBG(phy, "ULPS state = %d\n", enable);
  727. error:
  728. mutex_unlock(&phy->phy_lock);
  729. return rc;
  730. }
  731. /**
  732. * dsi_phy_enable() - enable DSI PHY hardware
  733. * @dsi_phy: DSI PHY handle.
  734. * @config: DSI host configuration.
  735. * @pll_source: Source PLL for PHY clock.
  736. * @skip_validation: Validation will not be performed on parameters.
  737. * @is_cont_splash_enabled: check whether continuous splash enabled.
  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 is_cont_splash_enabled)
  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 (!is_cont_splash_enabled) {
  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. *
  817. * Return: error code.
  818. */
  819. int dsi_phy_disable(struct msm_dsi_phy *phy)
  820. {
  821. int rc = 0;
  822. if (!phy) {
  823. DSI_PHY_ERR(phy, "Invalid params\n");
  824. return -EINVAL;
  825. }
  826. mutex_lock(&phy->phy_lock);
  827. dsi_phy_disable_hw(phy);
  828. phy->dsi_phy_state = DSI_PHY_ENGINE_OFF;
  829. mutex_unlock(&phy->phy_lock);
  830. return rc;
  831. }
  832. /**
  833. * dsi_phy_set_clamp_state() - configure clamps for DSI lanes
  834. * @phy: DSI PHY handle.
  835. * @enable: boolean to specify clamp enable/disable.
  836. *
  837. * Return: error code.
  838. */
  839. int dsi_phy_set_clamp_state(struct msm_dsi_phy *phy, bool enable)
  840. {
  841. if (!phy)
  842. return -EINVAL;
  843. DSI_PHY_DBG(phy, "enable=%d\n", enable);
  844. if (phy->hw.ops.clamp_ctrl)
  845. phy->hw.ops.clamp_ctrl(&phy->hw, enable);
  846. return 0;
  847. }
  848. /**
  849. * dsi_phy_idle_ctrl() - enable/disable DSI PHY during idle screen
  850. * @phy: DSI PHY handle
  851. * @enable: boolean to specify PHY enable/disable.
  852. *
  853. * Return: error code.
  854. */
  855. int dsi_phy_idle_ctrl(struct msm_dsi_phy *phy, bool enable)
  856. {
  857. if (!phy) {
  858. DSI_PHY_ERR(phy, "Invalid params\n");
  859. return -EINVAL;
  860. }
  861. DSI_PHY_DBG(phy, "enable=%d\n", enable);
  862. mutex_lock(&phy->phy_lock);
  863. if (enable) {
  864. if (phy->hw.ops.phy_idle_on)
  865. phy->hw.ops.phy_idle_on(&phy->hw, &phy->cfg);
  866. if (phy->hw.ops.regulator_enable)
  867. phy->hw.ops.regulator_enable(&phy->hw,
  868. &phy->cfg.regulators);
  869. if (phy->hw.ops.enable)
  870. phy->hw.ops.enable(&phy->hw, &phy->cfg);
  871. phy->dsi_phy_state = DSI_PHY_ENGINE_ON;
  872. } else {
  873. phy->dsi_phy_state = DSI_PHY_ENGINE_OFF;
  874. if (phy->hw.ops.disable)
  875. phy->hw.ops.disable(&phy->hw, &phy->cfg);
  876. if (phy->hw.ops.phy_idle_off)
  877. phy->hw.ops.phy_idle_off(&phy->hw);
  878. }
  879. mutex_unlock(&phy->phy_lock);
  880. return 0;
  881. }
  882. /**
  883. * dsi_phy_set_clk_freq() - set DSI PHY clock frequency setting
  884. * @phy: DSI PHY handle
  885. * @clk_freq: link clock frequency
  886. *
  887. * Return: error code.
  888. */
  889. int dsi_phy_set_clk_freq(struct msm_dsi_phy *phy,
  890. struct link_clk_freq *clk_freq)
  891. {
  892. if (!phy || !clk_freq) {
  893. DSI_PHY_ERR(phy, "Invalid params\n");
  894. return -EINVAL;
  895. }
  896. phy->regulator_required = clk_freq->byte_clk_rate >
  897. (phy->regulator_min_datarate_bps / BITS_PER_BYTE);
  898. /*
  899. * DSI PLL needs 0p9 LDO1A for Powering DSI PLL block.
  900. * PLL driver can vote for this regulator in PLL driver file, but for
  901. * the usecase where we come out of idle(static screen), if PLL and
  902. * PHY vote for regulator ,there will be performance delays as both
  903. * votes go through RPM to enable regulators.
  904. */
  905. phy->regulator_required = true;
  906. DSI_PHY_DBG(phy, "lane_datarate=%u min_datarate=%u required=%d\n",
  907. clk_freq->byte_clk_rate * BITS_PER_BYTE,
  908. phy->regulator_min_datarate_bps,
  909. phy->regulator_required);
  910. return 0;
  911. }
  912. /**
  913. * dsi_phy_set_timing_params() - timing parameters for the panel
  914. * @phy: DSI PHY handle
  915. * @timing: array holding timing params.
  916. * @size: size of the array.
  917. * @commit: boolean to indicate if programming PHY HW registers is
  918. * required
  919. *
  920. * When PHY timing calculator is not implemented, this array will be used to
  921. * pass PHY timing information.
  922. *
  923. * Return: error code.
  924. */
  925. int dsi_phy_set_timing_params(struct msm_dsi_phy *phy,
  926. u32 *timing, u32 size, bool commit)
  927. {
  928. int rc = 0;
  929. if (!phy || !timing || !size) {
  930. DSI_PHY_ERR(phy, "Invalid params\n");
  931. return -EINVAL;
  932. }
  933. mutex_lock(&phy->phy_lock);
  934. if (phy->hw.ops.phy_timing_val)
  935. rc = phy->hw.ops.phy_timing_val(&phy->cfg.timing, timing, size);
  936. if (!rc)
  937. phy->cfg.is_phy_timing_present = true;
  938. if (phy->hw.ops.commit_phy_timing && commit)
  939. phy->hw.ops.commit_phy_timing(&phy->hw, &phy->cfg.timing);
  940. mutex_unlock(&phy->phy_lock);
  941. return rc;
  942. }
  943. /**
  944. * dsi_phy_conv_phy_to_logical_lane() - Convert physical to logical lane
  945. * @lane_map: logical lane
  946. * @phy_lane: physical lane
  947. *
  948. * Return: Error code on failure. Lane number on success.
  949. */
  950. int dsi_phy_conv_phy_to_logical_lane(
  951. struct dsi_lane_map *lane_map, enum dsi_phy_data_lanes phy_lane)
  952. {
  953. int i = 0;
  954. if (phy_lane > DSI_PHYSICAL_LANE_3)
  955. return -EINVAL;
  956. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++) {
  957. if (lane_map->lane_map_v2[i] == phy_lane)
  958. break;
  959. }
  960. return i;
  961. }
  962. /**
  963. * dsi_phy_conv_logical_to_phy_lane() - Convert logical to physical lane
  964. * @lane_map: physical lane
  965. * @lane: logical lane
  966. *
  967. * Return: Error code on failure. Lane number on success.
  968. */
  969. int dsi_phy_conv_logical_to_phy_lane(
  970. struct dsi_lane_map *lane_map, enum dsi_logical_lane lane)
  971. {
  972. int i = 0;
  973. if (lane > (DSI_LANE_MAX - 1))
  974. return -EINVAL;
  975. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++) {
  976. if (BIT(i) == lane_map->lane_map_v2[lane])
  977. break;
  978. }
  979. return i;
  980. }
  981. /**
  982. * dsi_phy_config_dynamic_refresh() - Configure dynamic refresh registers
  983. * @phy: DSI PHY handle
  984. * @delay: pipe delays for dynamic refresh
  985. * @is_master: Boolean to indicate if for master or slave.
  986. */
  987. void dsi_phy_config_dynamic_refresh(struct msm_dsi_phy *phy,
  988. struct dsi_dyn_clk_delay *delay,
  989. bool is_master)
  990. {
  991. struct dsi_phy_cfg *cfg;
  992. if (!phy)
  993. return;
  994. mutex_lock(&phy->phy_lock);
  995. cfg = &phy->cfg;
  996. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_config)
  997. phy->hw.ops.dyn_refresh_ops.dyn_refresh_config(&phy->hw, cfg,
  998. is_master);
  999. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_pipe_delay)
  1000. phy->hw.ops.dyn_refresh_ops.dyn_refresh_pipe_delay(
  1001. &phy->hw, delay);
  1002. mutex_unlock(&phy->phy_lock);
  1003. }
  1004. /**
  1005. * dsi_phy_dynamic_refresh_trigger() - trigger dynamic refresh
  1006. * @phy: DSI PHY handle
  1007. * @is_master: Boolean to indicate if for master or slave.
  1008. */
  1009. void dsi_phy_dynamic_refresh_trigger(struct msm_dsi_phy *phy, bool is_master)
  1010. {
  1011. u32 off;
  1012. if (!phy)
  1013. return;
  1014. mutex_lock(&phy->phy_lock);
  1015. /*
  1016. * program PLL_SWI_INTF_SEL and SW_TRIGGER bit only for
  1017. * master and program SYNC_MODE bit only for slave.
  1018. */
  1019. if (is_master)
  1020. off = BIT(DYN_REFRESH_INTF_SEL) | BIT(DYN_REFRESH_SWI_CTRL) |
  1021. BIT(DYN_REFRESH_SW_TRIGGER);
  1022. else
  1023. off = BIT(DYN_REFRESH_SYNC_MODE) | BIT(DYN_REFRESH_SWI_CTRL);
  1024. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper)
  1025. phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper(&phy->hw, off);
  1026. mutex_unlock(&phy->phy_lock);
  1027. }
  1028. /**
  1029. * dsi_phy_cache_phy_timings - cache the phy timings calculated as part of
  1030. * dynamic refresh.
  1031. * @phy: DSI PHY Handle.
  1032. * @dst: Pointer to cache location.
  1033. * @size: Number of phy lane settings.
  1034. */
  1035. int dsi_phy_dyn_refresh_cache_phy_timings(struct msm_dsi_phy *phy, u32 *dst,
  1036. u32 size)
  1037. {
  1038. int rc = 0;
  1039. if (!phy || !dst || !size)
  1040. return -EINVAL;
  1041. if (phy->hw.ops.dyn_refresh_ops.cache_phy_timings)
  1042. rc = phy->hw.ops.dyn_refresh_ops.cache_phy_timings(
  1043. &phy->cfg.timing, dst, size);
  1044. if (rc)
  1045. DSI_PHY_ERR(phy, "failed to cache phy timings %d\n", rc);
  1046. return rc;
  1047. }
  1048. /**
  1049. * dsi_phy_dynamic_refresh_clear() - clear dynamic refresh config
  1050. * @phy: DSI PHY handle
  1051. */
  1052. void dsi_phy_dynamic_refresh_clear(struct msm_dsi_phy *phy)
  1053. {
  1054. if (!phy)
  1055. return;
  1056. mutex_lock(&phy->phy_lock);
  1057. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper)
  1058. phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper(&phy->hw, 0);
  1059. mutex_unlock(&phy->phy_lock);
  1060. }
  1061. /**
  1062. * dsi_phy_set_continuous_clk() - set/unset force clock lane HS request
  1063. * @phy: DSI PHY handle
  1064. * @enable: variable to control continuous clock
  1065. */
  1066. void dsi_phy_set_continuous_clk(struct msm_dsi_phy *phy, bool enable)
  1067. {
  1068. if (!phy)
  1069. return;
  1070. mutex_lock(&phy->phy_lock);
  1071. if (phy->hw.ops.set_continuous_clk)
  1072. phy->hw.ops.set_continuous_clk(&phy->hw, enable);
  1073. else
  1074. DSI_PHY_WARN(phy, "set_continuous_clk ops not present\n");
  1075. mutex_unlock(&phy->phy_lock);
  1076. }
  1077. void dsi_phy_drv_register(void)
  1078. {
  1079. platform_driver_register(&dsi_phy_platform_driver);
  1080. }
  1081. void dsi_phy_drv_unregister(void)
  1082. {
  1083. platform_driver_unregister(&dsi_phy_platform_driver);
  1084. }