dsi_phy.c 33 KB

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