dsi_phy.c 33 KB

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