dsi_phy.c 33 KB

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