dsi_phy.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  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. * @is_cont_splash_enabled: check whether continuous splash enabled.
  737. *
  738. * Validates and enables DSI PHY.
  739. *
  740. * Return: error code.
  741. */
  742. int dsi_phy_enable(struct msm_dsi_phy *phy,
  743. struct dsi_host_config *config,
  744. enum dsi_phy_pll_source pll_source,
  745. bool skip_validation,
  746. bool is_cont_splash_enabled)
  747. {
  748. int rc = 0;
  749. if (!phy || !config) {
  750. DSI_PHY_ERR(phy, "Invalid params\n");
  751. return -EINVAL;
  752. }
  753. mutex_lock(&phy->phy_lock);
  754. if (!skip_validation)
  755. DSI_PHY_DBG(phy, "TODO: perform validation\n");
  756. memcpy(&phy->mode, &config->video_timing, sizeof(phy->mode));
  757. memcpy(&phy->cfg.lane_map, &config->lane_map, sizeof(config->lane_map));
  758. phy->data_lanes = config->common_config.data_lanes;
  759. phy->dst_format = config->common_config.dst_format;
  760. phy->cfg.pll_source = pll_source;
  761. phy->cfg.bit_clk_rate_hz = config->bit_clk_rate_hz;
  762. /**
  763. * If PHY timing parameters are not present in panel dtsi file,
  764. * then calculate them in the driver
  765. */
  766. if (!phy->cfg.is_phy_timing_present)
  767. rc = phy->hw.ops.calculate_timing_params(&phy->hw,
  768. &phy->mode,
  769. &config->common_config,
  770. &phy->cfg.timing, false);
  771. if (rc) {
  772. DSI_PHY_ERR(phy, "failed to set timing, rc=%d\n", rc);
  773. goto error;
  774. }
  775. if (!is_cont_splash_enabled) {
  776. dsi_phy_enable_hw(phy);
  777. DSI_PHY_DBG(phy, "cont splash not enabled, phy enable required\n");
  778. }
  779. phy->dsi_phy_state = DSI_PHY_ENGINE_ON;
  780. error:
  781. mutex_unlock(&phy->phy_lock);
  782. return rc;
  783. }
  784. /* update dsi phy timings for dynamic clk switch use case */
  785. int dsi_phy_update_phy_timings(struct msm_dsi_phy *phy,
  786. struct dsi_host_config *config)
  787. {
  788. int rc = 0;
  789. if (!phy || !config) {
  790. DSI_PHY_ERR(phy, "invalid argument\n");
  791. return -EINVAL;
  792. }
  793. memcpy(&phy->mode, &config->video_timing, sizeof(phy->mode));
  794. rc = phy->hw.ops.calculate_timing_params(&phy->hw, &phy->mode,
  795. &config->common_config,
  796. &phy->cfg.timing, true);
  797. if (rc)
  798. DSI_PHY_ERR(phy, "failed to calculate phy timings %d\n", rc);
  799. return rc;
  800. }
  801. int dsi_phy_lane_reset(struct msm_dsi_phy *phy)
  802. {
  803. int ret = 0;
  804. if (!phy)
  805. return ret;
  806. mutex_lock(&phy->phy_lock);
  807. if (phy->hw.ops.phy_lane_reset)
  808. ret = phy->hw.ops.phy_lane_reset(&phy->hw);
  809. mutex_unlock(&phy->phy_lock);
  810. return ret;
  811. }
  812. /**
  813. * dsi_phy_disable() - disable DSI PHY hardware.
  814. * @phy: DSI PHY handle.
  815. *
  816. * Return: error code.
  817. */
  818. int dsi_phy_disable(struct msm_dsi_phy *phy)
  819. {
  820. int rc = 0;
  821. if (!phy) {
  822. DSI_PHY_ERR(phy, "Invalid params\n");
  823. return -EINVAL;
  824. }
  825. mutex_lock(&phy->phy_lock);
  826. dsi_phy_disable_hw(phy);
  827. phy->dsi_phy_state = DSI_PHY_ENGINE_OFF;
  828. mutex_unlock(&phy->phy_lock);
  829. return rc;
  830. }
  831. /**
  832. * dsi_phy_set_clamp_state() - configure clamps for DSI lanes
  833. * @phy: DSI PHY handle.
  834. * @enable: boolean to specify clamp enable/disable.
  835. *
  836. * Return: error code.
  837. */
  838. int dsi_phy_set_clamp_state(struct msm_dsi_phy *phy, bool enable)
  839. {
  840. if (!phy)
  841. return -EINVAL;
  842. DSI_PHY_DBG(phy, "enable=%d\n", enable);
  843. if (phy->hw.ops.clamp_ctrl)
  844. phy->hw.ops.clamp_ctrl(&phy->hw, enable);
  845. return 0;
  846. }
  847. /**
  848. * dsi_phy_idle_ctrl() - enable/disable DSI PHY during idle screen
  849. * @phy: DSI PHY handle
  850. * @enable: boolean to specify PHY enable/disable.
  851. *
  852. * Return: error code.
  853. */
  854. int dsi_phy_idle_ctrl(struct msm_dsi_phy *phy, bool enable)
  855. {
  856. if (!phy) {
  857. DSI_PHY_ERR(phy, "Invalid params\n");
  858. return -EINVAL;
  859. }
  860. DSI_PHY_DBG(phy, "enable=%d\n", enable);
  861. mutex_lock(&phy->phy_lock);
  862. if (enable) {
  863. if (phy->hw.ops.phy_idle_on)
  864. phy->hw.ops.phy_idle_on(&phy->hw, &phy->cfg);
  865. if (phy->hw.ops.regulator_enable)
  866. phy->hw.ops.regulator_enable(&phy->hw,
  867. &phy->cfg.regulators);
  868. if (phy->hw.ops.enable)
  869. phy->hw.ops.enable(&phy->hw, &phy->cfg);
  870. phy->dsi_phy_state = DSI_PHY_ENGINE_ON;
  871. } else {
  872. phy->dsi_phy_state = DSI_PHY_ENGINE_OFF;
  873. if (phy->hw.ops.disable)
  874. phy->hw.ops.disable(&phy->hw, &phy->cfg);
  875. if (phy->hw.ops.phy_idle_off)
  876. phy->hw.ops.phy_idle_off(&phy->hw);
  877. }
  878. mutex_unlock(&phy->phy_lock);
  879. return 0;
  880. }
  881. /**
  882. * dsi_phy_set_clk_freq() - set DSI PHY clock frequency setting
  883. * @phy: DSI PHY handle
  884. * @clk_freq: link clock frequency
  885. *
  886. * Return: error code.
  887. */
  888. int dsi_phy_set_clk_freq(struct msm_dsi_phy *phy,
  889. struct link_clk_freq *clk_freq)
  890. {
  891. if (!phy || !clk_freq) {
  892. DSI_PHY_ERR(phy, "Invalid params\n");
  893. return -EINVAL;
  894. }
  895. phy->regulator_required = clk_freq->byte_clk_rate >
  896. (phy->regulator_min_datarate_bps / BITS_PER_BYTE);
  897. /*
  898. * DSI PLL needs 0p9 LDO1A for Powering DSI PLL block.
  899. * PLL driver can vote for this regulator in PLL driver file, but for
  900. * the usecase where we come out of idle(static screen), if PLL and
  901. * PHY vote for regulator ,there will be performance delays as both
  902. * votes go through RPM to enable regulators.
  903. */
  904. phy->regulator_required = true;
  905. DSI_PHY_DBG(phy, "lane_datarate=%u min_datarate=%u required=%d\n",
  906. clk_freq->byte_clk_rate * BITS_PER_BYTE,
  907. phy->regulator_min_datarate_bps,
  908. phy->regulator_required);
  909. return 0;
  910. }
  911. /**
  912. * dsi_phy_set_timing_params() - timing parameters for the panel
  913. * @phy: DSI PHY handle
  914. * @timing: array holding timing params.
  915. * @size: size of the array.
  916. * @commit: boolean to indicate if programming PHY HW registers is
  917. * required
  918. *
  919. * When PHY timing calculator is not implemented, this array will be used to
  920. * pass PHY timing information.
  921. *
  922. * Return: error code.
  923. */
  924. int dsi_phy_set_timing_params(struct msm_dsi_phy *phy,
  925. u32 *timing, u32 size, bool commit)
  926. {
  927. int rc = 0;
  928. if (!phy || !timing || !size) {
  929. DSI_PHY_ERR(phy, "Invalid params\n");
  930. return -EINVAL;
  931. }
  932. mutex_lock(&phy->phy_lock);
  933. if (phy->hw.ops.phy_timing_val)
  934. rc = phy->hw.ops.phy_timing_val(&phy->cfg.timing, timing, size);
  935. if (!rc)
  936. phy->cfg.is_phy_timing_present = true;
  937. if (phy->hw.ops.commit_phy_timing && commit)
  938. phy->hw.ops.commit_phy_timing(&phy->hw, &phy->cfg.timing);
  939. mutex_unlock(&phy->phy_lock);
  940. return rc;
  941. }
  942. /**
  943. * dsi_phy_conv_phy_to_logical_lane() - Convert physical to logical lane
  944. * @lane_map: logical lane
  945. * @phy_lane: physical lane
  946. *
  947. * Return: Error code on failure. Lane number on success.
  948. */
  949. int dsi_phy_conv_phy_to_logical_lane(
  950. struct dsi_lane_map *lane_map, enum dsi_phy_data_lanes phy_lane)
  951. {
  952. int i = 0;
  953. if (phy_lane > DSI_PHYSICAL_LANE_3)
  954. return -EINVAL;
  955. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++) {
  956. if (lane_map->lane_map_v2[i] == phy_lane)
  957. break;
  958. }
  959. return i;
  960. }
  961. /**
  962. * dsi_phy_conv_logical_to_phy_lane() - Convert logical to physical lane
  963. * @lane_map: physical lane
  964. * @lane: logical lane
  965. *
  966. * Return: Error code on failure. Lane number on success.
  967. */
  968. int dsi_phy_conv_logical_to_phy_lane(
  969. struct dsi_lane_map *lane_map, enum dsi_logical_lane lane)
  970. {
  971. int i = 0;
  972. if (lane > (DSI_LANE_MAX - 1))
  973. return -EINVAL;
  974. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++) {
  975. if (BIT(i) == lane_map->lane_map_v2[lane])
  976. break;
  977. }
  978. return i;
  979. }
  980. /**
  981. * dsi_phy_config_dynamic_refresh() - Configure dynamic refresh registers
  982. * @phy: DSI PHY handle
  983. * @delay: pipe delays for dynamic refresh
  984. * @is_master: Boolean to indicate if for master or slave.
  985. */
  986. void dsi_phy_config_dynamic_refresh(struct msm_dsi_phy *phy,
  987. struct dsi_dyn_clk_delay *delay,
  988. bool is_master)
  989. {
  990. struct dsi_phy_cfg *cfg;
  991. if (!phy)
  992. return;
  993. mutex_lock(&phy->phy_lock);
  994. cfg = &phy->cfg;
  995. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_config)
  996. phy->hw.ops.dyn_refresh_ops.dyn_refresh_config(&phy->hw, cfg,
  997. is_master);
  998. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_pipe_delay)
  999. phy->hw.ops.dyn_refresh_ops.dyn_refresh_pipe_delay(
  1000. &phy->hw, delay);
  1001. mutex_unlock(&phy->phy_lock);
  1002. }
  1003. /**
  1004. * dsi_phy_dynamic_refresh_trigger_sel() - trigger dynamic refresh and
  1005. * update the video timings at next frame flush call.
  1006. * @phy: DSI PHY handle
  1007. * @is_master: Boolean to indicate if for master or slave.
  1008. */
  1009. void dsi_phy_dynamic_refresh_trigger_sel(struct msm_dsi_phy *phy,
  1010. bool is_master)
  1011. {
  1012. if (!phy)
  1013. return;
  1014. mutex_lock(&phy->phy_lock);
  1015. /*
  1016. * program DYNAMIC_REFRESH_CTRL.TRIGGER_SEL for master.
  1017. */
  1018. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_trigger_sel)
  1019. phy->hw.ops.dyn_refresh_ops.dyn_refresh_trigger_sel
  1020. (&phy->hw, is_master);
  1021. phy->dfps_trigger_mdpintf_flush = true;
  1022. SDE_EVT32(is_master, phy->index);
  1023. mutex_unlock(&phy->phy_lock);
  1024. }
  1025. /**
  1026. * dsi_phy_dynamic_refresh_trigger() - trigger dynamic refresh
  1027. * @phy: DSI PHY handle
  1028. * @is_master: Boolean to indicate if for master or slave.
  1029. */
  1030. void dsi_phy_dynamic_refresh_trigger(struct msm_dsi_phy *phy, bool is_master)
  1031. {
  1032. u32 off;
  1033. if (!phy)
  1034. return;
  1035. mutex_lock(&phy->phy_lock);
  1036. /*
  1037. * program PLL_SWI_INTF_SEL and SW_TRIGGER bit only for
  1038. * master and program SYNC_MODE bit only for slave.
  1039. */
  1040. if (is_master)
  1041. off = BIT(DYN_REFRESH_INTF_SEL) | BIT(DYN_REFRESH_SWI_CTRL) |
  1042. BIT(DYN_REFRESH_SW_TRIGGER);
  1043. else
  1044. off = BIT(DYN_REFRESH_SYNC_MODE) | BIT(DYN_REFRESH_SWI_CTRL);
  1045. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper)
  1046. phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper(&phy->hw, off);
  1047. mutex_unlock(&phy->phy_lock);
  1048. }
  1049. /**
  1050. * dsi_phy_cache_phy_timings - cache the phy timings calculated as part of
  1051. * dynamic refresh.
  1052. * @phy: DSI PHY Handle.
  1053. * @dst: Pointer to cache location.
  1054. * @size: Number of phy lane settings.
  1055. */
  1056. int dsi_phy_dyn_refresh_cache_phy_timings(struct msm_dsi_phy *phy, u32 *dst,
  1057. u32 size)
  1058. {
  1059. int rc = 0;
  1060. if (!phy || !dst || !size)
  1061. return -EINVAL;
  1062. if (phy->hw.ops.dyn_refresh_ops.cache_phy_timings)
  1063. rc = phy->hw.ops.dyn_refresh_ops.cache_phy_timings(
  1064. &phy->cfg.timing, dst, size);
  1065. if (rc)
  1066. DSI_PHY_ERR(phy, "failed to cache phy timings %d\n", rc);
  1067. return rc;
  1068. }
  1069. /**
  1070. * dsi_phy_dynamic_refresh_clear() - clear dynamic refresh config
  1071. * @phy: DSI PHY handle
  1072. */
  1073. void dsi_phy_dynamic_refresh_clear(struct msm_dsi_phy *phy)
  1074. {
  1075. if (!phy)
  1076. return;
  1077. mutex_lock(&phy->phy_lock);
  1078. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper)
  1079. phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper(&phy->hw, 0);
  1080. mutex_unlock(&phy->phy_lock);
  1081. }
  1082. /**
  1083. * dsi_phy_set_continuous_clk() - set/unset force clock lane HS request
  1084. * @phy: DSI PHY handle
  1085. * @enable: variable to control continuous clock
  1086. */
  1087. void dsi_phy_set_continuous_clk(struct msm_dsi_phy *phy, bool enable)
  1088. {
  1089. if (!phy)
  1090. return;
  1091. mutex_lock(&phy->phy_lock);
  1092. if (phy->hw.ops.set_continuous_clk)
  1093. phy->hw.ops.set_continuous_clk(&phy->hw, enable);
  1094. else
  1095. DSI_PHY_WARN(phy, "set_continuous_clk ops not present\n");
  1096. mutex_unlock(&phy->phy_lock);
  1097. }
  1098. void dsi_phy_drv_register(void)
  1099. {
  1100. platform_driver_register(&dsi_phy_platform_driver);
  1101. }
  1102. void dsi_phy_drv_unregister(void)
  1103. {
  1104. platform_driver_unregister(&dsi_phy_platform_driver);
  1105. }