dsi_phy.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450
  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_check_resource() - check if DSI PHY is probed
  492. * @of_node: of_node of the DSI PHY.
  493. *
  494. * Checks if the DSI PHY has been probed and is available.
  495. *
  496. * Return: status of DSI PHY
  497. */
  498. bool dsi_phy_check_resource(struct device_node *of_node)
  499. {
  500. struct list_head *pos, *tmp;
  501. struct msm_dsi_phy *phy = NULL;
  502. mutex_lock(&dsi_phy_list_lock);
  503. list_for_each_safe(pos, tmp, &dsi_phy_list) {
  504. struct dsi_phy_list_item *n;
  505. n = list_entry(pos, struct dsi_phy_list_item, list);
  506. if (!n->phy || !n->phy->pdev)
  507. break;
  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. return phy ? true : false;
  515. }
  516. /**
  517. * dsi_phy_get() - get a dsi phy handle from device node
  518. * @of_node: device node for dsi phy controller
  519. *
  520. * Gets the DSI PHY handle for the corresponding of_node. The ref count is
  521. * incremented to one all subsequents get will fail until the original client
  522. * calls a put.
  523. *
  524. * Return: DSI PHY handle or an error code.
  525. */
  526. struct msm_dsi_phy *dsi_phy_get(struct device_node *of_node)
  527. {
  528. struct list_head *pos, *tmp;
  529. struct msm_dsi_phy *phy = NULL;
  530. mutex_lock(&dsi_phy_list_lock);
  531. list_for_each_safe(pos, tmp, &dsi_phy_list) {
  532. struct dsi_phy_list_item *n;
  533. n = list_entry(pos, struct dsi_phy_list_item, list);
  534. if (n->phy->pdev->dev.of_node == of_node) {
  535. phy = n->phy;
  536. break;
  537. }
  538. }
  539. mutex_unlock(&dsi_phy_list_lock);
  540. if (!phy) {
  541. DSI_PHY_ERR(phy, "Device with of node not found rc=%d\n",
  542. -EPROBE_DEFER);
  543. phy = ERR_PTR(-EPROBE_DEFER);
  544. return phy;
  545. }
  546. mutex_lock(&phy->phy_lock);
  547. if (phy->refcount > 0) {
  548. DSI_PHY_ERR(phy, "Device under use\n");
  549. phy = ERR_PTR(-EINVAL);
  550. } else {
  551. phy->refcount++;
  552. }
  553. mutex_unlock(&phy->phy_lock);
  554. return phy;
  555. }
  556. /**
  557. * dsi_phy_put() - release dsi phy handle
  558. * @dsi_phy: DSI PHY handle.
  559. *
  560. * Release the DSI PHY hardware. Driver will clean up all resources and puts
  561. * back the DSI PHY into reset state.
  562. */
  563. void dsi_phy_put(struct msm_dsi_phy *dsi_phy)
  564. {
  565. mutex_lock(&dsi_phy->phy_lock);
  566. if (dsi_phy->refcount == 0)
  567. DSI_PHY_ERR(dsi_phy, "Unbalanced %s call\n", __func__);
  568. else
  569. dsi_phy->refcount--;
  570. mutex_unlock(&dsi_phy->phy_lock);
  571. }
  572. /**
  573. * dsi_phy_drv_init() - initialize dsi phy driver
  574. * @dsi_phy: DSI PHY handle.
  575. *
  576. * Initializes DSI PHY driver. Should be called after dsi_phy_get().
  577. *
  578. * Return: error code.
  579. */
  580. int dsi_phy_drv_init(struct msm_dsi_phy *dsi_phy)
  581. {
  582. char dbg_name[DSI_DEBUG_NAME_LEN];
  583. snprintf(dbg_name, DSI_DEBUG_NAME_LEN, "dsi%d_phy", dsi_phy->index);
  584. sde_dbg_reg_register_base(dbg_name, dsi_phy->hw.base,
  585. msm_iomap_size(dsi_phy->pdev, "dsi_phy"),
  586. msm_get_phys_addr(dsi_phy->pdev, "dsi_phy"), SDE_DBG_DSI);
  587. return 0;
  588. }
  589. /**
  590. * dsi_phy_drv_deinit() - de-initialize dsi phy driver
  591. * @dsi_phy: DSI PHY handle.
  592. *
  593. * Release all resources acquired by dsi_phy_drv_init().
  594. *
  595. * Return: error code.
  596. */
  597. int dsi_phy_drv_deinit(struct msm_dsi_phy *dsi_phy)
  598. {
  599. return 0;
  600. }
  601. int dsi_phy_clk_cb_register(struct msm_dsi_phy *dsi_phy,
  602. struct clk_ctrl_cb *clk_cb)
  603. {
  604. if (!dsi_phy || !clk_cb) {
  605. DSI_PHY_ERR(dsi_phy, "Invalid params\n");
  606. return -EINVAL;
  607. }
  608. dsi_phy->clk_cb.priv = clk_cb->priv;
  609. dsi_phy->clk_cb.dsi_clk_cb = clk_cb->dsi_clk_cb;
  610. return 0;
  611. }
  612. /**
  613. * dsi_phy_validate_mode() - validate a display mode
  614. * @dsi_phy: DSI PHY handle.
  615. * @mode: Mode information.
  616. *
  617. * Validation will fail if the mode cannot be supported by the PHY driver or
  618. * hardware.
  619. *
  620. * Return: error code.
  621. */
  622. int dsi_phy_validate_mode(struct msm_dsi_phy *dsi_phy,
  623. struct dsi_mode_info *mode)
  624. {
  625. int rc = 0;
  626. if (!dsi_phy || !mode) {
  627. DSI_PHY_ERR(dsi_phy, "Invalid params\n");
  628. return -EINVAL;
  629. }
  630. DSI_PHY_DBG(dsi_phy, "Skipping validation\n");
  631. return rc;
  632. }
  633. /**
  634. * dsi_phy_set_power_state() - enable/disable dsi phy power supplies
  635. * @dsi_phy: DSI PHY handle.
  636. * @enable: Boolean flag to enable/disable.
  637. *
  638. * Return: error code.
  639. */
  640. int dsi_phy_set_power_state(struct msm_dsi_phy *dsi_phy, bool enable)
  641. {
  642. int rc = 0;
  643. if (!dsi_phy) {
  644. DSI_PHY_ERR(dsi_phy, "Invalid params\n");
  645. return -EINVAL;
  646. }
  647. mutex_lock(&dsi_phy->phy_lock);
  648. if (enable == dsi_phy->power_state) {
  649. DSI_PHY_ERR(dsi_phy, "No state change\n");
  650. goto error;
  651. }
  652. if (enable) {
  653. rc = dsi_pwr_enable_regulator(&dsi_phy->pwr_info.digital, true);
  654. if (rc) {
  655. DSI_PHY_ERR(dsi_phy, "failed to enable digital regulator\n");
  656. goto error;
  657. }
  658. if (dsi_phy->dsi_phy_state == DSI_PHY_ENGINE_OFF &&
  659. dsi_phy->regulator_required) {
  660. rc = dsi_pwr_enable_regulator(
  661. &dsi_phy->pwr_info.phy_pwr, true);
  662. if (rc) {
  663. DSI_PHY_ERR(dsi_phy, "failed to enable phy power\n");
  664. (void)dsi_pwr_enable_regulator(
  665. &dsi_phy->pwr_info.digital, false);
  666. goto error;
  667. }
  668. }
  669. } else {
  670. if (dsi_phy->dsi_phy_state == DSI_PHY_ENGINE_OFF &&
  671. dsi_phy->regulator_required) {
  672. rc = dsi_pwr_enable_regulator(
  673. &dsi_phy->pwr_info.phy_pwr, false);
  674. if (rc) {
  675. DSI_PHY_ERR(dsi_phy, "failed to enable digital regulator\n");
  676. goto error;
  677. }
  678. }
  679. rc = dsi_pwr_enable_regulator(&dsi_phy->pwr_info.digital,
  680. false);
  681. if (rc) {
  682. DSI_PHY_ERR(dsi_phy, "failed to enable phy power\n");
  683. goto error;
  684. }
  685. }
  686. dsi_phy->power_state = enable;
  687. error:
  688. mutex_unlock(&dsi_phy->phy_lock);
  689. return rc;
  690. }
  691. /**
  692. * dsi_phy_configure() - Configure DSI PHY PLL
  693. * @dsi_phy: DSI PHY handle.
  694. * @commit: boolean to specify if calculated PHY configuration
  695. * needs to be committed. Set to false in case of
  696. * dynamic clock switch.
  697. *
  698. * Return: error code.
  699. */
  700. int dsi_phy_configure(struct msm_dsi_phy *phy, bool commit)
  701. {
  702. int rc = 0;
  703. phy->pll->type = phy->cfg.phy_type;
  704. phy->pll->bpp = dsi_pixel_format_to_bpp(phy->dst_format);
  705. phy->pll->lanes = dsi_get_num_of_data_lanes(phy->data_lanes);
  706. if (phy->hw.ops.configure)
  707. rc = phy->hw.ops.configure(phy->pll, commit);
  708. return rc;
  709. }
  710. /**
  711. * dsi_phy_pll_toggle() - Toggle DSI PHY PLL
  712. * @dsi_phy: DSI PHY handle.
  713. * @prepare: specifies if PLL needs to be turned on or not.
  714. *
  715. * Return: error code.
  716. */
  717. int dsi_phy_pll_toggle(struct msm_dsi_phy *phy, bool prepare)
  718. {
  719. int rc = 0;
  720. if (phy->hw.ops.pll_toggle)
  721. rc = phy->hw.ops.pll_toggle(phy->pll, prepare);
  722. return rc;
  723. }
  724. static int dsi_phy_enable_ulps(struct msm_dsi_phy *phy,
  725. struct dsi_host_config *config, bool clamp_enabled)
  726. {
  727. int rc = 0;
  728. u32 lanes = 0;
  729. u32 ulps_lanes;
  730. lanes = config->common_config.data_lanes;
  731. lanes |= DSI_CLOCK_LANE;
  732. /*
  733. * If DSI clamps are enabled, it means that the DSI lanes are
  734. * already in idle state. Checking for lanes to be in idle state
  735. * should be skipped during ULPS entry programming while coming
  736. * out of idle screen.
  737. */
  738. if (!clamp_enabled) {
  739. rc = phy->hw.ops.ulps_ops.wait_for_lane_idle(&phy->hw, lanes);
  740. if (rc) {
  741. DSI_PHY_ERR(phy, "lanes not entering idle, skip ULPS\n");
  742. return rc;
  743. }
  744. }
  745. phy->hw.ops.ulps_ops.ulps_request(&phy->hw, &phy->cfg, lanes);
  746. ulps_lanes = phy->hw.ops.ulps_ops.get_lanes_in_ulps(&phy->hw);
  747. if (!phy->hw.ops.ulps_ops.is_lanes_in_ulps(lanes, ulps_lanes)) {
  748. DSI_PHY_ERR(phy, "Failed to enter ULPS, request=0x%x, actual=0x%x\n",
  749. lanes, ulps_lanes);
  750. rc = -EIO;
  751. }
  752. return rc;
  753. }
  754. static int dsi_phy_disable_ulps(struct msm_dsi_phy *phy,
  755. struct dsi_host_config *config)
  756. {
  757. u32 ulps_lanes, lanes = 0;
  758. lanes = config->common_config.data_lanes;
  759. lanes |= DSI_CLOCK_LANE;
  760. ulps_lanes = phy->hw.ops.ulps_ops.get_lanes_in_ulps(&phy->hw);
  761. if (!phy->hw.ops.ulps_ops.is_lanes_in_ulps(lanes, ulps_lanes)) {
  762. DSI_PHY_ERR(phy, "Mismatch in ULPS: lanes:%d, ulps_lanes:%d\n",
  763. lanes, ulps_lanes);
  764. return -EIO;
  765. }
  766. phy->hw.ops.ulps_ops.ulps_exit(&phy->hw, &phy->cfg, lanes);
  767. ulps_lanes = phy->hw.ops.ulps_ops.get_lanes_in_ulps(&phy->hw);
  768. if (phy->hw.ops.ulps_ops.is_lanes_in_ulps(lanes, ulps_lanes)) {
  769. DSI_PHY_ERR(phy, "Lanes (0x%x) stuck in ULPS\n", ulps_lanes);
  770. return -EIO;
  771. }
  772. return 0;
  773. }
  774. void dsi_phy_toggle_resync_fifo(struct msm_dsi_phy *phy)
  775. {
  776. if (!phy)
  777. return;
  778. if (!phy->hw.ops.toggle_resync_fifo)
  779. return;
  780. phy->hw.ops.toggle_resync_fifo(&phy->hw);
  781. }
  782. void dsi_phy_reset_clk_en_sel(struct msm_dsi_phy *phy)
  783. {
  784. if (!phy)
  785. return;
  786. if (!phy->hw.ops.reset_clk_en_sel)
  787. return;
  788. phy->hw.ops.reset_clk_en_sel(&phy->hw);
  789. }
  790. int dsi_phy_set_ulps(struct msm_dsi_phy *phy, struct dsi_host_config *config,
  791. bool enable, bool clamp_enabled)
  792. {
  793. int rc = 0;
  794. if (!phy) {
  795. DSI_PHY_ERR(phy, "Invalid params\n");
  796. return DSI_PHY_ULPS_ERROR;
  797. }
  798. if (!phy->hw.ops.ulps_ops.ulps_request ||
  799. !phy->hw.ops.ulps_ops.ulps_exit ||
  800. !phy->hw.ops.ulps_ops.get_lanes_in_ulps ||
  801. !phy->hw.ops.ulps_ops.is_lanes_in_ulps ||
  802. !phy->hw.ops.ulps_ops.wait_for_lane_idle) {
  803. DSI_PHY_DBG(phy, "DSI PHY ULPS ops not present\n");
  804. return DSI_PHY_ULPS_NOT_HANDLED;
  805. }
  806. mutex_lock(&phy->phy_lock);
  807. if (enable)
  808. rc = dsi_phy_enable_ulps(phy, config, clamp_enabled);
  809. else
  810. rc = dsi_phy_disable_ulps(phy, config);
  811. if (rc) {
  812. DSI_PHY_ERR(phy, "Ulps state change(%d) failed, rc=%d\n",
  813. enable, rc);
  814. rc = DSI_PHY_ULPS_ERROR;
  815. goto error;
  816. }
  817. DSI_PHY_DBG(phy, "ULPS state = %d\n", enable);
  818. error:
  819. mutex_unlock(&phy->phy_lock);
  820. return rc;
  821. }
  822. /**
  823. * dsi_phy_enable() - enable DSI PHY hardware
  824. * @dsi_phy: DSI PHY handle.
  825. * @config: DSI host configuration.
  826. * @pll_source: Source PLL for PHY clock.
  827. * @skip_validation: Validation will not be performed on parameters.
  828. * @skip_op: Skip re-enabling dsi phy hw during usecases like
  829. * cont-splash/trusted-vm if set to true.
  830. *
  831. * Validates and enables DSI PHY.
  832. *
  833. * Return: error code.
  834. */
  835. int dsi_phy_enable(struct msm_dsi_phy *phy,
  836. struct dsi_host_config *config,
  837. enum dsi_phy_pll_source pll_source,
  838. bool skip_validation,
  839. bool skip_op)
  840. {
  841. int rc = 0;
  842. if (!phy || !config) {
  843. DSI_PHY_ERR(phy, "Invalid params\n");
  844. return -EINVAL;
  845. }
  846. mutex_lock(&phy->phy_lock);
  847. if (!skip_validation)
  848. DSI_PHY_DBG(phy, "TODO: perform validation\n");
  849. memcpy(&phy->mode, &config->video_timing, sizeof(phy->mode));
  850. memcpy(&phy->cfg.lane_map, &config->lane_map, sizeof(config->lane_map));
  851. phy->data_lanes = config->common_config.data_lanes;
  852. phy->dst_format = config->common_config.dst_format;
  853. phy->cfg.pll_source = pll_source;
  854. phy->cfg.bit_clk_rate_hz = config->bit_clk_rate_hz;
  855. /**
  856. * If PHY timing parameters are not present in panel dtsi file,
  857. * then calculate them in the driver
  858. */
  859. if (!phy->cfg.is_phy_timing_present)
  860. rc = phy->hw.ops.calculate_timing_params(&phy->hw,
  861. &phy->mode,
  862. &config->common_config,
  863. &phy->cfg.timing, false);
  864. if (rc) {
  865. DSI_PHY_ERR(phy, "failed to set timing, rc=%d\n", rc);
  866. goto error;
  867. }
  868. if (!skip_op) {
  869. dsi_phy_enable_hw(phy);
  870. DSI_PHY_DBG(phy, "cont splash not enabled, phy enable required\n");
  871. }
  872. phy->dsi_phy_state = DSI_PHY_ENGINE_ON;
  873. error:
  874. mutex_unlock(&phy->phy_lock);
  875. return rc;
  876. }
  877. /* update dsi phy timings for dynamic clk switch use case */
  878. int dsi_phy_update_phy_timings(struct msm_dsi_phy *phy,
  879. struct dsi_host_config *config)
  880. {
  881. int rc = 0;
  882. if (!phy || !config) {
  883. DSI_PHY_ERR(phy, "invalid argument\n");
  884. return -EINVAL;
  885. }
  886. memcpy(&phy->mode, &config->video_timing, sizeof(phy->mode));
  887. rc = phy->hw.ops.calculate_timing_params(&phy->hw, &phy->mode,
  888. &config->common_config,
  889. &phy->cfg.timing, true);
  890. if (rc)
  891. DSI_PHY_ERR(phy, "failed to calculate phy timings %d\n", rc);
  892. return rc;
  893. }
  894. int dsi_phy_lane_reset(struct msm_dsi_phy *phy)
  895. {
  896. int ret = 0;
  897. if (!phy)
  898. return ret;
  899. mutex_lock(&phy->phy_lock);
  900. if (phy->hw.ops.phy_lane_reset)
  901. ret = phy->hw.ops.phy_lane_reset(&phy->hw);
  902. mutex_unlock(&phy->phy_lock);
  903. return ret;
  904. }
  905. /**
  906. * dsi_phy_disable() - disable DSI PHY hardware.
  907. * @phy: DSI PHY handle.
  908. * @skip_op: Skip disabling dsi phy hw during usecases like
  909. * trusted-vm if set to true.
  910. *
  911. * Return: error code.
  912. */
  913. int dsi_phy_disable(struct msm_dsi_phy *phy, bool skip_op)
  914. {
  915. int rc = 0;
  916. if (!phy) {
  917. DSI_PHY_ERR(phy, "Invalid params\n");
  918. return -EINVAL;
  919. }
  920. mutex_lock(&phy->phy_lock);
  921. if (!skip_op)
  922. dsi_phy_disable_hw(phy);
  923. phy->dsi_phy_state = DSI_PHY_ENGINE_OFF;
  924. mutex_unlock(&phy->phy_lock);
  925. return rc;
  926. }
  927. /**
  928. * dsi_phy_set_clamp_state() - configure clamps for DSI lanes
  929. * @phy: DSI PHY handle.
  930. * @enable: boolean to specify clamp enable/disable.
  931. *
  932. * Return: error code.
  933. */
  934. int dsi_phy_set_clamp_state(struct msm_dsi_phy *phy, bool enable)
  935. {
  936. if (!phy)
  937. return -EINVAL;
  938. DSI_PHY_DBG(phy, "enable=%d\n", enable);
  939. if (phy->hw.ops.clamp_ctrl)
  940. phy->hw.ops.clamp_ctrl(&phy->hw, enable);
  941. return 0;
  942. }
  943. /**
  944. * dsi_phy_idle_ctrl() - enable/disable DSI PHY during idle screen
  945. * @phy: DSI PHY handle
  946. * @enable: boolean to specify PHY enable/disable.
  947. *
  948. * Return: error code.
  949. */
  950. int dsi_phy_idle_ctrl(struct msm_dsi_phy *phy, bool enable)
  951. {
  952. if (!phy) {
  953. DSI_PHY_ERR(phy, "Invalid params\n");
  954. return -EINVAL;
  955. }
  956. DSI_PHY_DBG(phy, "enable=%d\n", enable);
  957. mutex_lock(&phy->phy_lock);
  958. if (enable) {
  959. if (phy->hw.ops.phy_idle_on)
  960. phy->hw.ops.phy_idle_on(&phy->hw, &phy->cfg);
  961. if (phy->hw.ops.regulator_enable)
  962. phy->hw.ops.regulator_enable(&phy->hw,
  963. &phy->cfg.regulators);
  964. if (phy->hw.ops.enable)
  965. phy->hw.ops.enable(&phy->hw, &phy->cfg);
  966. phy->dsi_phy_state = DSI_PHY_ENGINE_ON;
  967. } else {
  968. phy->dsi_phy_state = DSI_PHY_ENGINE_OFF;
  969. if (phy->hw.ops.disable)
  970. phy->hw.ops.disable(&phy->hw, &phy->cfg);
  971. if (phy->hw.ops.phy_idle_off)
  972. phy->hw.ops.phy_idle_off(&phy->hw);
  973. }
  974. mutex_unlock(&phy->phy_lock);
  975. return 0;
  976. }
  977. /**
  978. * dsi_phy_set_clk_freq() - set DSI PHY clock frequency setting
  979. * @phy: DSI PHY handle
  980. * @clk_freq: link clock frequency
  981. *
  982. * Return: error code.
  983. */
  984. int dsi_phy_set_clk_freq(struct msm_dsi_phy *phy,
  985. struct link_clk_freq *clk_freq)
  986. {
  987. if (!phy || !clk_freq) {
  988. DSI_PHY_ERR(phy, "Invalid params\n");
  989. return -EINVAL;
  990. }
  991. phy->regulator_required = clk_freq->byte_clk_rate >
  992. (phy->regulator_min_datarate_bps / BITS_PER_BYTE);
  993. /*
  994. * DSI PLL needs 0p9 LDO1A for Powering DSI PLL block.
  995. * PLL driver can vote for this regulator in PLL driver file, but for
  996. * the usecase where we come out of idle(static screen), if PLL and
  997. * PHY vote for regulator ,there will be performance delays as both
  998. * votes go through RPM to enable regulators.
  999. */
  1000. phy->regulator_required = true;
  1001. DSI_PHY_DBG(phy, "lane_datarate=%u min_datarate=%u required=%d\n",
  1002. clk_freq->byte_clk_rate * BITS_PER_BYTE,
  1003. phy->regulator_min_datarate_bps,
  1004. phy->regulator_required);
  1005. return 0;
  1006. }
  1007. /**
  1008. * dsi_phy_set_timing_params() - timing parameters for the panel
  1009. * @phy: DSI PHY handle
  1010. * @timing: array holding timing params.
  1011. * @size: size of the array.
  1012. * @commit: boolean to indicate if programming PHY HW registers is
  1013. * required
  1014. *
  1015. * When PHY timing calculator is not implemented, this array will be used to
  1016. * pass PHY timing information.
  1017. *
  1018. * Return: error code.
  1019. */
  1020. int dsi_phy_set_timing_params(struct msm_dsi_phy *phy,
  1021. u32 *timing, u32 size, bool commit)
  1022. {
  1023. int rc = 0;
  1024. if (!phy || !timing || !size) {
  1025. DSI_PHY_ERR(phy, "Invalid params\n");
  1026. return -EINVAL;
  1027. }
  1028. mutex_lock(&phy->phy_lock);
  1029. if (phy->hw.ops.phy_timing_val)
  1030. rc = phy->hw.ops.phy_timing_val(&phy->cfg.timing, timing, size);
  1031. if (!rc)
  1032. phy->cfg.is_phy_timing_present = true;
  1033. if (phy->hw.ops.commit_phy_timing && commit)
  1034. phy->hw.ops.commit_phy_timing(&phy->hw, &phy->cfg.timing);
  1035. mutex_unlock(&phy->phy_lock);
  1036. return rc;
  1037. }
  1038. /**
  1039. * dsi_phy_conv_phy_to_logical_lane() - Convert physical to logical lane
  1040. * @lane_map: logical lane
  1041. * @phy_lane: physical lane
  1042. *
  1043. * Return: Error code on failure. Lane number on success.
  1044. */
  1045. int dsi_phy_conv_phy_to_logical_lane(
  1046. struct dsi_lane_map *lane_map, enum dsi_phy_data_lanes phy_lane)
  1047. {
  1048. int i = 0;
  1049. if (phy_lane > DSI_PHYSICAL_LANE_3)
  1050. return -EINVAL;
  1051. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++) {
  1052. if (lane_map->lane_map_v2[i] == phy_lane)
  1053. break;
  1054. }
  1055. return i;
  1056. }
  1057. /**
  1058. * dsi_phy_conv_logical_to_phy_lane() - Convert logical to physical lane
  1059. * @lane_map: physical lane
  1060. * @lane: logical lane
  1061. *
  1062. * Return: Error code on failure. Lane number on success.
  1063. */
  1064. int dsi_phy_conv_logical_to_phy_lane(
  1065. struct dsi_lane_map *lane_map, enum dsi_logical_lane lane)
  1066. {
  1067. int i = 0;
  1068. if (lane > (DSI_LANE_MAX - 1))
  1069. return -EINVAL;
  1070. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++) {
  1071. if (BIT(i) == lane_map->lane_map_v2[lane])
  1072. break;
  1073. }
  1074. return i;
  1075. }
  1076. /**
  1077. * dsi_phy_config_dynamic_refresh() - Configure dynamic refresh registers
  1078. * @phy: DSI PHY handle
  1079. * @delay: pipe delays for dynamic refresh
  1080. * @is_master: Boolean to indicate if for master or slave.
  1081. */
  1082. void dsi_phy_config_dynamic_refresh(struct msm_dsi_phy *phy,
  1083. struct dsi_dyn_clk_delay *delay,
  1084. bool is_master)
  1085. {
  1086. struct dsi_phy_cfg *cfg;
  1087. if (!phy)
  1088. return;
  1089. mutex_lock(&phy->phy_lock);
  1090. cfg = &phy->cfg;
  1091. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_config)
  1092. phy->hw.ops.dyn_refresh_ops.dyn_refresh_config(&phy->hw, cfg,
  1093. is_master);
  1094. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_pipe_delay)
  1095. phy->hw.ops.dyn_refresh_ops.dyn_refresh_pipe_delay(
  1096. &phy->hw, delay);
  1097. mutex_unlock(&phy->phy_lock);
  1098. }
  1099. /**
  1100. * dsi_phy_dynamic_refresh_trigger_sel() - trigger dynamic refresh and
  1101. * update the video timings at next frame flush call.
  1102. * @phy: DSI PHY handle
  1103. * @is_master: Boolean to indicate if for master or slave.
  1104. */
  1105. void dsi_phy_dynamic_refresh_trigger_sel(struct msm_dsi_phy *phy,
  1106. bool is_master)
  1107. {
  1108. if (!phy)
  1109. return;
  1110. mutex_lock(&phy->phy_lock);
  1111. /*
  1112. * program DYNAMIC_REFRESH_CTRL.TRIGGER_SEL for master.
  1113. */
  1114. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_trigger_sel)
  1115. phy->hw.ops.dyn_refresh_ops.dyn_refresh_trigger_sel
  1116. (&phy->hw, is_master);
  1117. phy->dfps_trigger_mdpintf_flush = true;
  1118. SDE_EVT32(is_master, phy->index);
  1119. mutex_unlock(&phy->phy_lock);
  1120. }
  1121. /**
  1122. * dsi_phy_dynamic_refresh_trigger() - trigger dynamic refresh
  1123. * @phy: DSI PHY handle
  1124. * @is_master: Boolean to indicate if for master or slave.
  1125. */
  1126. void dsi_phy_dynamic_refresh_trigger(struct msm_dsi_phy *phy, bool is_master)
  1127. {
  1128. u32 off;
  1129. if (!phy)
  1130. return;
  1131. mutex_lock(&phy->phy_lock);
  1132. /*
  1133. * program PLL_SWI_INTF_SEL and SW_TRIGGER bit only for
  1134. * master and program SYNC_MODE bit only for slave.
  1135. */
  1136. if (is_master)
  1137. off = BIT(DYN_REFRESH_INTF_SEL) | BIT(DYN_REFRESH_SWI_CTRL) |
  1138. BIT(DYN_REFRESH_SW_TRIGGER);
  1139. else
  1140. off = BIT(DYN_REFRESH_SYNC_MODE) | BIT(DYN_REFRESH_SWI_CTRL);
  1141. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper)
  1142. phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper(&phy->hw, off);
  1143. mutex_unlock(&phy->phy_lock);
  1144. }
  1145. /**
  1146. * dsi_phy_cache_phy_timings - cache the phy timings calculated as part of
  1147. * dynamic refresh.
  1148. * @phy: DSI PHY Handle.
  1149. * @dst: Pointer to cache location.
  1150. * @size: Number of phy lane settings.
  1151. */
  1152. int dsi_phy_dyn_refresh_cache_phy_timings(struct msm_dsi_phy *phy, u32 *dst,
  1153. u32 size)
  1154. {
  1155. int rc = 0;
  1156. if (!phy || !dst || !size)
  1157. return -EINVAL;
  1158. if (phy->hw.ops.dyn_refresh_ops.cache_phy_timings)
  1159. rc = phy->hw.ops.dyn_refresh_ops.cache_phy_timings(
  1160. &phy->cfg.timing, dst, size);
  1161. if (rc)
  1162. DSI_PHY_ERR(phy, "failed to cache phy timings %d\n", rc);
  1163. return rc;
  1164. }
  1165. /**
  1166. * dsi_phy_dynamic_refresh_clear() - clear dynamic refresh config
  1167. * @phy: DSI PHY handle
  1168. */
  1169. void dsi_phy_dynamic_refresh_clear(struct msm_dsi_phy *phy)
  1170. {
  1171. if (!phy)
  1172. return;
  1173. mutex_lock(&phy->phy_lock);
  1174. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper)
  1175. phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper(&phy->hw, 0);
  1176. mutex_unlock(&phy->phy_lock);
  1177. }
  1178. /**
  1179. * dsi_phy_set_continuous_clk() - set/unset force clock lane HS request
  1180. * @phy: DSI PHY handle
  1181. * @enable: variable to control continuous clock
  1182. */
  1183. void dsi_phy_set_continuous_clk(struct msm_dsi_phy *phy, bool enable)
  1184. {
  1185. if (!phy)
  1186. return;
  1187. mutex_lock(&phy->phy_lock);
  1188. if (phy->hw.ops.set_continuous_clk)
  1189. phy->hw.ops.set_continuous_clk(&phy->hw, enable);
  1190. else
  1191. DSI_PHY_WARN(phy, "set_continuous_clk ops not present\n");
  1192. mutex_unlock(&phy->phy_lock);
  1193. }
  1194. /**
  1195. * dsi_phy_pll_parse_dfps_data() - parse dfps data for PLL
  1196. * @phy: DSI PHY handle
  1197. */
  1198. void dsi_phy_pll_parse_dfps_data(struct msm_dsi_phy *phy)
  1199. {
  1200. dsi_pll_parse_dfps_data(phy->pdev, phy->pll);
  1201. }
  1202. void dsi_phy_drv_register(void)
  1203. {
  1204. platform_driver_register(&dsi_phy_platform_driver);
  1205. }
  1206. void dsi_phy_drv_unregister(void)
  1207. {
  1208. platform_driver_unregister(&dsi_phy_platform_driver);
  1209. }