dsi_phy.c 34 KB

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