dsi_phy.c 35 KB

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