dsi_phy.c 32 KB

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