dsi_phy.c 31 KB

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