dsi_phy.c 31 KB

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