dsi_phy.c 34 KB

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