dsi_phy.c 30 KB

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