dsi_phy.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  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_configure() - Configure DSI PHY PLL
  646. * @dsi_phy: DSI PHY handle.
  647. * @commit: boolean to specify if calculated PHY configuration
  648. * needs to be committed. Set to false in case of
  649. * dynamic clock switch.
  650. *
  651. * Return: error code.
  652. */
  653. int dsi_phy_configure(struct msm_dsi_phy *phy, bool commit)
  654. {
  655. int rc = 0;
  656. phy->pll->type = phy->cfg.phy_type;
  657. phy->pll->bpp = dsi_pixel_format_to_bpp(phy->dst_format);
  658. phy->pll->lanes = dsi_get_num_of_data_lanes(phy->data_lanes);
  659. if (phy->hw.ops.configure)
  660. rc = phy->hw.ops.configure(phy->pll, commit);
  661. return rc;
  662. }
  663. /**
  664. * dsi_phy_pll_toggle() - Toggle DSI PHY PLL
  665. * @dsi_phy: DSI PHY handle.
  666. * @prepare: specifies if PLL needs to be turned on or not.
  667. *
  668. * Return: error code.
  669. */
  670. int dsi_phy_pll_toggle(struct msm_dsi_phy *phy, bool prepare)
  671. {
  672. int rc = 0;
  673. if (phy->hw.ops.pll_toggle)
  674. rc = phy->hw.ops.pll_toggle(phy->pll, prepare);
  675. return rc;
  676. }
  677. static int dsi_phy_enable_ulps(struct msm_dsi_phy *phy,
  678. struct dsi_host_config *config, bool clamp_enabled)
  679. {
  680. int rc = 0;
  681. u32 lanes = 0;
  682. u32 ulps_lanes;
  683. lanes = config->common_config.data_lanes;
  684. lanes |= DSI_CLOCK_LANE;
  685. /*
  686. * If DSI clamps are enabled, it means that the DSI lanes are
  687. * already in idle state. Checking for lanes to be in idle state
  688. * should be skipped during ULPS entry programming while coming
  689. * out of idle screen.
  690. */
  691. if (!clamp_enabled) {
  692. rc = phy->hw.ops.ulps_ops.wait_for_lane_idle(&phy->hw, lanes);
  693. if (rc) {
  694. DSI_PHY_ERR(phy, "lanes not entering idle, skip ULPS\n");
  695. return rc;
  696. }
  697. }
  698. phy->hw.ops.ulps_ops.ulps_request(&phy->hw, &phy->cfg, lanes);
  699. ulps_lanes = phy->hw.ops.ulps_ops.get_lanes_in_ulps(&phy->hw);
  700. if (!phy->hw.ops.ulps_ops.is_lanes_in_ulps(lanes, ulps_lanes)) {
  701. DSI_PHY_ERR(phy, "Failed to enter ULPS, request=0x%x, actual=0x%x\n",
  702. lanes, ulps_lanes);
  703. rc = -EIO;
  704. }
  705. return rc;
  706. }
  707. static int dsi_phy_disable_ulps(struct msm_dsi_phy *phy,
  708. struct dsi_host_config *config)
  709. {
  710. u32 ulps_lanes, lanes = 0;
  711. lanes = config->common_config.data_lanes;
  712. lanes |= DSI_CLOCK_LANE;
  713. ulps_lanes = phy->hw.ops.ulps_ops.get_lanes_in_ulps(&phy->hw);
  714. if (!phy->hw.ops.ulps_ops.is_lanes_in_ulps(lanes, ulps_lanes)) {
  715. DSI_PHY_ERR(phy, "Mismatch in ULPS: lanes:%d, ulps_lanes:%d\n",
  716. lanes, ulps_lanes);
  717. return -EIO;
  718. }
  719. phy->hw.ops.ulps_ops.ulps_exit(&phy->hw, &phy->cfg, lanes);
  720. ulps_lanes = phy->hw.ops.ulps_ops.get_lanes_in_ulps(&phy->hw);
  721. if (phy->hw.ops.ulps_ops.is_lanes_in_ulps(lanes, ulps_lanes)) {
  722. DSI_PHY_ERR(phy, "Lanes (0x%x) stuck in ULPS\n", ulps_lanes);
  723. return -EIO;
  724. }
  725. return 0;
  726. }
  727. void dsi_phy_toggle_resync_fifo(struct msm_dsi_phy *phy)
  728. {
  729. if (!phy)
  730. return;
  731. if (!phy->hw.ops.toggle_resync_fifo)
  732. return;
  733. phy->hw.ops.toggle_resync_fifo(&phy->hw);
  734. }
  735. void dsi_phy_reset_clk_en_sel(struct msm_dsi_phy *phy)
  736. {
  737. if (!phy)
  738. return;
  739. if (!phy->hw.ops.reset_clk_en_sel)
  740. return;
  741. phy->hw.ops.reset_clk_en_sel(&phy->hw);
  742. }
  743. int dsi_phy_set_ulps(struct msm_dsi_phy *phy, struct dsi_host_config *config,
  744. bool enable, bool clamp_enabled)
  745. {
  746. int rc = 0;
  747. if (!phy) {
  748. DSI_PHY_ERR(phy, "Invalid params\n");
  749. return DSI_PHY_ULPS_ERROR;
  750. }
  751. if (!phy->hw.ops.ulps_ops.ulps_request ||
  752. !phy->hw.ops.ulps_ops.ulps_exit ||
  753. !phy->hw.ops.ulps_ops.get_lanes_in_ulps ||
  754. !phy->hw.ops.ulps_ops.is_lanes_in_ulps ||
  755. !phy->hw.ops.ulps_ops.wait_for_lane_idle) {
  756. DSI_PHY_DBG(phy, "DSI PHY ULPS ops not present\n");
  757. return DSI_PHY_ULPS_NOT_HANDLED;
  758. }
  759. mutex_lock(&phy->phy_lock);
  760. if (enable)
  761. rc = dsi_phy_enable_ulps(phy, config, clamp_enabled);
  762. else
  763. rc = dsi_phy_disable_ulps(phy, config);
  764. if (rc) {
  765. DSI_PHY_ERR(phy, "Ulps state change(%d) failed, rc=%d\n",
  766. enable, rc);
  767. rc = DSI_PHY_ULPS_ERROR;
  768. goto error;
  769. }
  770. DSI_PHY_DBG(phy, "ULPS state = %d\n", enable);
  771. error:
  772. mutex_unlock(&phy->phy_lock);
  773. return rc;
  774. }
  775. /**
  776. * dsi_phy_enable() - enable DSI PHY hardware
  777. * @dsi_phy: DSI PHY handle.
  778. * @config: DSI host configuration.
  779. * @pll_source: Source PLL for PHY clock.
  780. * @skip_validation: Validation will not be performed on parameters.
  781. * @skip_op: Skip re-enabling dsi phy hw during usecases like
  782. * cont-splash/trusted-vm if set to true.
  783. *
  784. * Validates and enables DSI PHY.
  785. *
  786. * Return: error code.
  787. */
  788. int dsi_phy_enable(struct msm_dsi_phy *phy,
  789. struct dsi_host_config *config,
  790. enum dsi_phy_pll_source pll_source,
  791. bool skip_validation,
  792. bool skip_op)
  793. {
  794. int rc = 0;
  795. if (!phy || !config) {
  796. DSI_PHY_ERR(phy, "Invalid params\n");
  797. return -EINVAL;
  798. }
  799. mutex_lock(&phy->phy_lock);
  800. if (!skip_validation)
  801. DSI_PHY_DBG(phy, "TODO: perform validation\n");
  802. memcpy(&phy->mode, &config->video_timing, sizeof(phy->mode));
  803. memcpy(&phy->cfg.lane_map, &config->lane_map, sizeof(config->lane_map));
  804. phy->data_lanes = config->common_config.data_lanes;
  805. phy->dst_format = config->common_config.dst_format;
  806. phy->cfg.pll_source = pll_source;
  807. phy->cfg.bit_clk_rate_hz = config->bit_clk_rate_hz;
  808. /**
  809. * If PHY timing parameters are not present in panel dtsi file,
  810. * then calculate them in the driver
  811. */
  812. if (!phy->cfg.is_phy_timing_present)
  813. rc = phy->hw.ops.calculate_timing_params(&phy->hw,
  814. &phy->mode,
  815. &config->common_config,
  816. &phy->cfg.timing, false);
  817. if (rc) {
  818. DSI_PHY_ERR(phy, "failed to set timing, rc=%d\n", rc);
  819. goto error;
  820. }
  821. if (!skip_op) {
  822. dsi_phy_enable_hw(phy);
  823. DSI_PHY_DBG(phy, "cont splash not enabled, phy enable required\n");
  824. }
  825. phy->dsi_phy_state = DSI_PHY_ENGINE_ON;
  826. error:
  827. mutex_unlock(&phy->phy_lock);
  828. return rc;
  829. }
  830. /* update dsi phy timings for dynamic clk switch use case */
  831. int dsi_phy_update_phy_timings(struct msm_dsi_phy *phy,
  832. struct dsi_host_config *config)
  833. {
  834. int rc = 0;
  835. if (!phy || !config) {
  836. DSI_PHY_ERR(phy, "invalid argument\n");
  837. return -EINVAL;
  838. }
  839. memcpy(&phy->mode, &config->video_timing, sizeof(phy->mode));
  840. rc = phy->hw.ops.calculate_timing_params(&phy->hw, &phy->mode,
  841. &config->common_config,
  842. &phy->cfg.timing, true);
  843. if (rc)
  844. DSI_PHY_ERR(phy, "failed to calculate phy timings %d\n", rc);
  845. return rc;
  846. }
  847. int dsi_phy_lane_reset(struct msm_dsi_phy *phy)
  848. {
  849. int ret = 0;
  850. if (!phy)
  851. return ret;
  852. mutex_lock(&phy->phy_lock);
  853. if (phy->hw.ops.phy_lane_reset)
  854. ret = phy->hw.ops.phy_lane_reset(&phy->hw);
  855. mutex_unlock(&phy->phy_lock);
  856. return ret;
  857. }
  858. /**
  859. * dsi_phy_disable() - disable DSI PHY hardware.
  860. * @phy: DSI PHY handle.
  861. * @skip_op: Skip disabling dsi phy hw during usecases like
  862. * trusted-vm if set to true.
  863. *
  864. * Return: error code.
  865. */
  866. int dsi_phy_disable(struct msm_dsi_phy *phy, bool skip_op)
  867. {
  868. int rc = 0;
  869. if (!phy) {
  870. DSI_PHY_ERR(phy, "Invalid params\n");
  871. return -EINVAL;
  872. }
  873. mutex_lock(&phy->phy_lock);
  874. if (!skip_op)
  875. dsi_phy_disable_hw(phy);
  876. phy->dsi_phy_state = DSI_PHY_ENGINE_OFF;
  877. mutex_unlock(&phy->phy_lock);
  878. return rc;
  879. }
  880. /**
  881. * dsi_phy_set_clamp_state() - configure clamps for DSI lanes
  882. * @phy: DSI PHY handle.
  883. * @enable: boolean to specify clamp enable/disable.
  884. *
  885. * Return: error code.
  886. */
  887. int dsi_phy_set_clamp_state(struct msm_dsi_phy *phy, bool enable)
  888. {
  889. if (!phy)
  890. return -EINVAL;
  891. DSI_PHY_DBG(phy, "enable=%d\n", enable);
  892. if (phy->hw.ops.clamp_ctrl)
  893. phy->hw.ops.clamp_ctrl(&phy->hw, enable);
  894. return 0;
  895. }
  896. /**
  897. * dsi_phy_idle_ctrl() - enable/disable DSI PHY during idle screen
  898. * @phy: DSI PHY handle
  899. * @enable: boolean to specify PHY enable/disable.
  900. *
  901. * Return: error code.
  902. */
  903. int dsi_phy_idle_ctrl(struct msm_dsi_phy *phy, bool enable)
  904. {
  905. if (!phy) {
  906. DSI_PHY_ERR(phy, "Invalid params\n");
  907. return -EINVAL;
  908. }
  909. DSI_PHY_DBG(phy, "enable=%d\n", enable);
  910. mutex_lock(&phy->phy_lock);
  911. if (enable) {
  912. if (phy->hw.ops.phy_idle_on)
  913. phy->hw.ops.phy_idle_on(&phy->hw, &phy->cfg);
  914. if (phy->hw.ops.regulator_enable)
  915. phy->hw.ops.regulator_enable(&phy->hw,
  916. &phy->cfg.regulators);
  917. if (phy->hw.ops.enable)
  918. phy->hw.ops.enable(&phy->hw, &phy->cfg);
  919. phy->dsi_phy_state = DSI_PHY_ENGINE_ON;
  920. } else {
  921. phy->dsi_phy_state = DSI_PHY_ENGINE_OFF;
  922. if (phy->hw.ops.disable)
  923. phy->hw.ops.disable(&phy->hw, &phy->cfg);
  924. if (phy->hw.ops.phy_idle_off)
  925. phy->hw.ops.phy_idle_off(&phy->hw);
  926. }
  927. mutex_unlock(&phy->phy_lock);
  928. return 0;
  929. }
  930. /**
  931. * dsi_phy_set_clk_freq() - set DSI PHY clock frequency setting
  932. * @phy: DSI PHY handle
  933. * @clk_freq: link clock frequency
  934. *
  935. * Return: error code.
  936. */
  937. int dsi_phy_set_clk_freq(struct msm_dsi_phy *phy,
  938. struct link_clk_freq *clk_freq)
  939. {
  940. if (!phy || !clk_freq) {
  941. DSI_PHY_ERR(phy, "Invalid params\n");
  942. return -EINVAL;
  943. }
  944. phy->regulator_required = clk_freq->byte_clk_rate >
  945. (phy->regulator_min_datarate_bps / BITS_PER_BYTE);
  946. /*
  947. * DSI PLL needs 0p9 LDO1A for Powering DSI PLL block.
  948. * PLL driver can vote for this regulator in PLL driver file, but for
  949. * the usecase where we come out of idle(static screen), if PLL and
  950. * PHY vote for regulator ,there will be performance delays as both
  951. * votes go through RPM to enable regulators.
  952. */
  953. phy->regulator_required = true;
  954. DSI_PHY_DBG(phy, "lane_datarate=%u min_datarate=%u required=%d\n",
  955. clk_freq->byte_clk_rate * BITS_PER_BYTE,
  956. phy->regulator_min_datarate_bps,
  957. phy->regulator_required);
  958. return 0;
  959. }
  960. /**
  961. * dsi_phy_set_timing_params() - timing parameters for the panel
  962. * @phy: DSI PHY handle
  963. * @timing: array holding timing params.
  964. * @size: size of the array.
  965. * @commit: boolean to indicate if programming PHY HW registers is
  966. * required
  967. *
  968. * When PHY timing calculator is not implemented, this array will be used to
  969. * pass PHY timing information.
  970. *
  971. * Return: error code.
  972. */
  973. int dsi_phy_set_timing_params(struct msm_dsi_phy *phy,
  974. u32 *timing, u32 size, bool commit)
  975. {
  976. int rc = 0;
  977. if (!phy || !timing || !size) {
  978. DSI_PHY_ERR(phy, "Invalid params\n");
  979. return -EINVAL;
  980. }
  981. mutex_lock(&phy->phy_lock);
  982. if (phy->hw.ops.phy_timing_val)
  983. rc = phy->hw.ops.phy_timing_val(&phy->cfg.timing, timing, size);
  984. if (!rc)
  985. phy->cfg.is_phy_timing_present = true;
  986. if (phy->hw.ops.commit_phy_timing && commit)
  987. phy->hw.ops.commit_phy_timing(&phy->hw, &phy->cfg.timing);
  988. mutex_unlock(&phy->phy_lock);
  989. return rc;
  990. }
  991. /**
  992. * dsi_phy_conv_phy_to_logical_lane() - Convert physical to logical lane
  993. * @lane_map: logical lane
  994. * @phy_lane: physical lane
  995. *
  996. * Return: Error code on failure. Lane number on success.
  997. */
  998. int dsi_phy_conv_phy_to_logical_lane(
  999. struct dsi_lane_map *lane_map, enum dsi_phy_data_lanes phy_lane)
  1000. {
  1001. int i = 0;
  1002. if (phy_lane > DSI_PHYSICAL_LANE_3)
  1003. return -EINVAL;
  1004. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++) {
  1005. if (lane_map->lane_map_v2[i] == phy_lane)
  1006. break;
  1007. }
  1008. return i;
  1009. }
  1010. /**
  1011. * dsi_phy_conv_logical_to_phy_lane() - Convert logical to physical lane
  1012. * @lane_map: physical lane
  1013. * @lane: logical lane
  1014. *
  1015. * Return: Error code on failure. Lane number on success.
  1016. */
  1017. int dsi_phy_conv_logical_to_phy_lane(
  1018. struct dsi_lane_map *lane_map, enum dsi_logical_lane lane)
  1019. {
  1020. int i = 0;
  1021. if (lane > (DSI_LANE_MAX - 1))
  1022. return -EINVAL;
  1023. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++) {
  1024. if (BIT(i) == lane_map->lane_map_v2[lane])
  1025. break;
  1026. }
  1027. return i;
  1028. }
  1029. /**
  1030. * dsi_phy_config_dynamic_refresh() - Configure dynamic refresh registers
  1031. * @phy: DSI PHY handle
  1032. * @delay: pipe delays for dynamic refresh
  1033. * @is_master: Boolean to indicate if for master or slave.
  1034. */
  1035. void dsi_phy_config_dynamic_refresh(struct msm_dsi_phy *phy,
  1036. struct dsi_dyn_clk_delay *delay,
  1037. bool is_master)
  1038. {
  1039. struct dsi_phy_cfg *cfg;
  1040. if (!phy)
  1041. return;
  1042. mutex_lock(&phy->phy_lock);
  1043. cfg = &phy->cfg;
  1044. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_config)
  1045. phy->hw.ops.dyn_refresh_ops.dyn_refresh_config(&phy->hw, cfg,
  1046. is_master);
  1047. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_pipe_delay)
  1048. phy->hw.ops.dyn_refresh_ops.dyn_refresh_pipe_delay(
  1049. &phy->hw, delay);
  1050. mutex_unlock(&phy->phy_lock);
  1051. }
  1052. /**
  1053. * dsi_phy_dynamic_refresh_trigger_sel() - trigger dynamic refresh and
  1054. * update the video timings at next frame flush call.
  1055. * @phy: DSI PHY handle
  1056. * @is_master: Boolean to indicate if for master or slave.
  1057. */
  1058. void dsi_phy_dynamic_refresh_trigger_sel(struct msm_dsi_phy *phy,
  1059. bool is_master)
  1060. {
  1061. if (!phy)
  1062. return;
  1063. mutex_lock(&phy->phy_lock);
  1064. /*
  1065. * program DYNAMIC_REFRESH_CTRL.TRIGGER_SEL for master.
  1066. */
  1067. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_trigger_sel)
  1068. phy->hw.ops.dyn_refresh_ops.dyn_refresh_trigger_sel
  1069. (&phy->hw, is_master);
  1070. phy->dfps_trigger_mdpintf_flush = true;
  1071. SDE_EVT32(is_master, phy->index);
  1072. mutex_unlock(&phy->phy_lock);
  1073. }
  1074. /**
  1075. * dsi_phy_dynamic_refresh_trigger() - trigger dynamic refresh
  1076. * @phy: DSI PHY handle
  1077. * @is_master: Boolean to indicate if for master or slave.
  1078. */
  1079. void dsi_phy_dynamic_refresh_trigger(struct msm_dsi_phy *phy, bool is_master)
  1080. {
  1081. u32 off;
  1082. if (!phy)
  1083. return;
  1084. mutex_lock(&phy->phy_lock);
  1085. /*
  1086. * program PLL_SWI_INTF_SEL and SW_TRIGGER bit only for
  1087. * master and program SYNC_MODE bit only for slave.
  1088. */
  1089. if (is_master)
  1090. off = BIT(DYN_REFRESH_INTF_SEL) | BIT(DYN_REFRESH_SWI_CTRL) |
  1091. BIT(DYN_REFRESH_SW_TRIGGER);
  1092. else
  1093. off = BIT(DYN_REFRESH_SYNC_MODE) | BIT(DYN_REFRESH_SWI_CTRL);
  1094. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper)
  1095. phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper(&phy->hw, off);
  1096. mutex_unlock(&phy->phy_lock);
  1097. }
  1098. /**
  1099. * dsi_phy_cache_phy_timings - cache the phy timings calculated as part of
  1100. * dynamic refresh.
  1101. * @phy: DSI PHY Handle.
  1102. * @dst: Pointer to cache location.
  1103. * @size: Number of phy lane settings.
  1104. */
  1105. int dsi_phy_dyn_refresh_cache_phy_timings(struct msm_dsi_phy *phy, u32 *dst,
  1106. u32 size)
  1107. {
  1108. int rc = 0;
  1109. if (!phy || !dst || !size)
  1110. return -EINVAL;
  1111. if (phy->hw.ops.dyn_refresh_ops.cache_phy_timings)
  1112. rc = phy->hw.ops.dyn_refresh_ops.cache_phy_timings(
  1113. &phy->cfg.timing, dst, size);
  1114. if (rc)
  1115. DSI_PHY_ERR(phy, "failed to cache phy timings %d\n", rc);
  1116. return rc;
  1117. }
  1118. /**
  1119. * dsi_phy_dynamic_refresh_clear() - clear dynamic refresh config
  1120. * @phy: DSI PHY handle
  1121. */
  1122. void dsi_phy_dynamic_refresh_clear(struct msm_dsi_phy *phy)
  1123. {
  1124. if (!phy)
  1125. return;
  1126. mutex_lock(&phy->phy_lock);
  1127. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper)
  1128. phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper(&phy->hw, 0);
  1129. mutex_unlock(&phy->phy_lock);
  1130. }
  1131. /**
  1132. * dsi_phy_set_continuous_clk() - set/unset force clock lane HS request
  1133. * @phy: DSI PHY handle
  1134. * @enable: variable to control continuous clock
  1135. */
  1136. void dsi_phy_set_continuous_clk(struct msm_dsi_phy *phy, bool enable)
  1137. {
  1138. if (!phy)
  1139. return;
  1140. mutex_lock(&phy->phy_lock);
  1141. if (phy->hw.ops.set_continuous_clk)
  1142. phy->hw.ops.set_continuous_clk(&phy->hw, enable);
  1143. else
  1144. DSI_PHY_WARN(phy, "set_continuous_clk ops not present\n");
  1145. mutex_unlock(&phy->phy_lock);
  1146. }
  1147. /**
  1148. * dsi_phy_pll_parse_dfps_data() - parse dfps data for PLL
  1149. * @phy: DSI PHY handle
  1150. */
  1151. void dsi_phy_pll_parse_dfps_data(struct msm_dsi_phy *phy)
  1152. {
  1153. dsi_pll_parse_dfps_data(phy->pdev, phy->pll);
  1154. }
  1155. void dsi_phy_drv_register(void)
  1156. {
  1157. platform_driver_register(&dsi_phy_platform_driver);
  1158. }
  1159. void dsi_phy_drv_unregister(void)
  1160. {
  1161. platform_driver_unregister(&dsi_phy_platform_driver);
  1162. }