dsi_phy.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021-2022 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. return 0;
  294. err:
  295. lane->count_per_lane = 0;
  296. strength->count_per_lane = 0;
  297. regs->count_per_lane = 0;
  298. timing->count_per_lane = 0;
  299. return rc;
  300. }
  301. static int dsi_phy_settings_deinit(struct msm_dsi_phy *phy)
  302. {
  303. memset(&phy->cfg.lanecfg, 0x0, sizeof(phy->cfg.lanecfg));
  304. memset(&phy->cfg.strength, 0x0, sizeof(phy->cfg.strength));
  305. memset(&phy->cfg.timing, 0x0, sizeof(phy->cfg.timing));
  306. memset(&phy->cfg.regulators, 0x0, sizeof(phy->cfg.regulators));
  307. return 0;
  308. }
  309. static int dsi_phy_driver_probe(struct platform_device *pdev)
  310. {
  311. struct msm_dsi_phy *dsi_phy;
  312. struct dsi_phy_list_item *item;
  313. const struct of_device_id *id;
  314. const struct dsi_ver_spec_info *ver_info;
  315. int rc = 0;
  316. u32 index = 0;
  317. if (!pdev || !pdev->dev.of_node) {
  318. DSI_ERR("pdev not found\n");
  319. return -ENODEV;
  320. }
  321. id = of_match_node(msm_dsi_phy_of_match, pdev->dev.of_node);
  322. if (!id)
  323. return -ENODEV;
  324. ver_info = id->data;
  325. item = devm_kzalloc(&pdev->dev, sizeof(*item), GFP_KERNEL);
  326. if (!item)
  327. return -ENOMEM;
  328. dsi_phy = devm_kzalloc(&pdev->dev, sizeof(*dsi_phy), GFP_KERNEL);
  329. if (!dsi_phy) {
  330. devm_kfree(&pdev->dev, item);
  331. return -ENOMEM;
  332. }
  333. rc = of_property_read_u32(pdev->dev.of_node, "cell-index", &index);
  334. if (rc) {
  335. DSI_PHY_DBG(dsi_phy, "cell index not set, default to 0\n");
  336. index = 0;
  337. }
  338. dsi_phy->index = index;
  339. dsi_phy->name = of_get_property(pdev->dev.of_node, "label", NULL);
  340. if (!dsi_phy->name)
  341. dsi_phy->name = DSI_PHY_DEFAULT_LABEL;
  342. dsi_phy->hw.phy_pll_bypass = of_property_read_bool(pdev->dev.of_node,
  343. "qcom,dsi-phy-pll-bypass");
  344. DSI_PHY_DBG(dsi_phy, "Probing device\n");
  345. dsi_phy->ver_info = ver_info;
  346. rc = dsi_phy_regmap_init(pdev, dsi_phy);
  347. if (rc) {
  348. DSI_PHY_ERR(dsi_phy, "Failed to parse register information, rc=%d\n",
  349. rc);
  350. goto fail;
  351. }
  352. rc = dsi_phy_supplies_init(pdev, dsi_phy);
  353. if (rc) {
  354. DSI_PHY_ERR(dsi_phy, "failed to parse voltage supplies, rc = %d\n",
  355. rc);
  356. goto fail_regmap;
  357. }
  358. rc = dsi_catalog_phy_setup(&dsi_phy->hw, ver_info->version,
  359. dsi_phy->index);
  360. if (rc) {
  361. DSI_PHY_ERR(dsi_phy, "Catalog does not support version (%d)\n",
  362. ver_info->version);
  363. goto fail_supplies;
  364. }
  365. rc = dsi_phy_settings_init(pdev, dsi_phy);
  366. if (rc) {
  367. DSI_PHY_ERR(dsi_phy, "Failed to parse phy setting, rc=%d\n",
  368. rc);
  369. goto fail_supplies;
  370. }
  371. rc = dsi_pll_init(pdev, &dsi_phy->pll);
  372. if (rc) {
  373. DSI_PHY_ERR(dsi_phy, "Failed to initialize DSI PLL, rc=%d\n", rc);
  374. goto fail_settings;
  375. }
  376. rc = dsi_catalog_phy_pll_setup(&dsi_phy->hw,
  377. dsi_phy->pll->pll_revision);
  378. if (rc) {
  379. DSI_PHY_ERR(dsi_phy, "Catalog does not support PLL version (%d)\n",
  380. dsi_phy->pll->pll_revision);
  381. goto fail_settings;
  382. }
  383. item->phy = dsi_phy;
  384. mutex_lock(&dsi_phy_list_lock);
  385. list_add(&item->list, &dsi_phy_list);
  386. mutex_unlock(&dsi_phy_list_lock);
  387. mutex_init(&dsi_phy->phy_lock);
  388. /** TODO: initialize debugfs */
  389. dsi_phy->pdev = pdev;
  390. platform_set_drvdata(pdev, dsi_phy);
  391. DSI_PHY_INFO(dsi_phy, "Probe successful\n");
  392. return 0;
  393. fail_settings:
  394. (void)dsi_phy_settings_deinit(dsi_phy);
  395. fail_supplies:
  396. (void)dsi_phy_supplies_deinit(dsi_phy);
  397. fail_regmap:
  398. (void)dsi_phy_regmap_deinit(dsi_phy);
  399. fail:
  400. devm_kfree(&pdev->dev, dsi_phy);
  401. devm_kfree(&pdev->dev, item);
  402. return rc;
  403. }
  404. static int dsi_phy_driver_remove(struct platform_device *pdev)
  405. {
  406. int rc = 0;
  407. struct msm_dsi_phy *phy = platform_get_drvdata(pdev);
  408. struct list_head *pos, *tmp;
  409. if (!pdev || !phy) {
  410. DSI_PHY_ERR(phy, "Invalid device\n");
  411. return -EINVAL;
  412. }
  413. mutex_lock(&dsi_phy_list_lock);
  414. list_for_each_safe(pos, tmp, &dsi_phy_list) {
  415. struct dsi_phy_list_item *n;
  416. n = list_entry(pos, struct dsi_phy_list_item, list);
  417. if (n->phy == phy) {
  418. list_del(&n->list);
  419. devm_kfree(&pdev->dev, n);
  420. break;
  421. }
  422. }
  423. mutex_unlock(&dsi_phy_list_lock);
  424. mutex_lock(&phy->phy_lock);
  425. rc = dsi_phy_settings_deinit(phy);
  426. if (rc)
  427. DSI_PHY_ERR(phy, "failed to deinitialize phy settings, rc=%d\n",
  428. rc);
  429. rc = dsi_phy_supplies_deinit(phy);
  430. if (rc)
  431. DSI_PHY_ERR(phy, "failed to deinitialize voltage supplies, rc=%d\n",
  432. rc);
  433. rc = dsi_phy_regmap_deinit(phy);
  434. if (rc)
  435. DSI_PHY_ERR(phy, "failed to deinitialize regmap, rc=%d\n", rc);
  436. mutex_unlock(&phy->phy_lock);
  437. mutex_destroy(&phy->phy_lock);
  438. devm_kfree(&pdev->dev, phy);
  439. platform_set_drvdata(pdev, NULL);
  440. return 0;
  441. }
  442. static struct platform_driver dsi_phy_platform_driver = {
  443. .probe = dsi_phy_driver_probe,
  444. .remove = dsi_phy_driver_remove,
  445. .driver = {
  446. .name = "dsi_phy",
  447. .of_match_table = msm_dsi_phy_of_match,
  448. },
  449. };
  450. static void dsi_phy_enable_hw(struct msm_dsi_phy *phy)
  451. {
  452. if (phy->hw.ops.regulator_enable)
  453. phy->hw.ops.regulator_enable(&phy->hw, &phy->cfg.regulators);
  454. if (phy->hw.ops.enable)
  455. phy->hw.ops.enable(&phy->hw, &phy->cfg);
  456. }
  457. static void dsi_phy_disable_hw(struct msm_dsi_phy *phy)
  458. {
  459. if (phy->hw.ops.disable)
  460. phy->hw.ops.disable(&phy->hw, &phy->cfg);
  461. if (phy->hw.ops.regulator_disable)
  462. phy->hw.ops.regulator_disable(&phy->hw);
  463. }
  464. /**
  465. * dsi_phy_check_resource() - check if DSI PHY is probed
  466. * @of_node: of_node of the DSI PHY.
  467. *
  468. * Checks if the DSI PHY has been probed and is available.
  469. *
  470. * Return: status of DSI PHY
  471. */
  472. bool dsi_phy_check_resource(struct device_node *of_node)
  473. {
  474. struct list_head *pos, *tmp;
  475. struct msm_dsi_phy *phy = NULL;
  476. mutex_lock(&dsi_phy_list_lock);
  477. list_for_each_safe(pos, tmp, &dsi_phy_list) {
  478. struct dsi_phy_list_item *n;
  479. n = list_entry(pos, struct dsi_phy_list_item, list);
  480. if (!n->phy || !n->phy->pdev)
  481. break;
  482. if (n->phy->pdev->dev.of_node == of_node) {
  483. phy = n->phy;
  484. break;
  485. }
  486. }
  487. mutex_unlock(&dsi_phy_list_lock);
  488. return phy ? true : false;
  489. }
  490. /**
  491. * dsi_phy_get() - get a dsi phy handle from device node
  492. * @of_node: device node for dsi phy controller
  493. *
  494. * Gets the DSI PHY handle for the corresponding of_node. The ref count is
  495. * incremented to one all subsequents get will fail until the original client
  496. * calls a put.
  497. *
  498. * Return: DSI PHY handle or an error code.
  499. */
  500. struct msm_dsi_phy *dsi_phy_get(struct device_node *of_node)
  501. {
  502. struct list_head *pos, *tmp;
  503. struct msm_dsi_phy *phy = NULL;
  504. mutex_lock(&dsi_phy_list_lock);
  505. list_for_each_safe(pos, tmp, &dsi_phy_list) {
  506. struct dsi_phy_list_item *n;
  507. n = list_entry(pos, struct dsi_phy_list_item, list);
  508. if (n->phy->pdev->dev.of_node == of_node) {
  509. phy = n->phy;
  510. break;
  511. }
  512. }
  513. mutex_unlock(&dsi_phy_list_lock);
  514. if (!phy) {
  515. DSI_PHY_ERR(phy, "Device with of node not found rc=%d\n",
  516. -EPROBE_DEFER);
  517. phy = ERR_PTR(-EPROBE_DEFER);
  518. return phy;
  519. }
  520. mutex_lock(&phy->phy_lock);
  521. if (phy->refcount > 0) {
  522. DSI_PHY_ERR(phy, "Device under use\n");
  523. phy = ERR_PTR(-EINVAL);
  524. } else {
  525. phy->refcount++;
  526. }
  527. mutex_unlock(&phy->phy_lock);
  528. return phy;
  529. }
  530. /**
  531. * dsi_phy_put() - release dsi phy handle
  532. * @dsi_phy: DSI PHY handle.
  533. *
  534. * Release the DSI PHY hardware. Driver will clean up all resources and puts
  535. * back the DSI PHY into reset state.
  536. */
  537. void dsi_phy_put(struct msm_dsi_phy *dsi_phy)
  538. {
  539. mutex_lock(&dsi_phy->phy_lock);
  540. if (dsi_phy->refcount == 0)
  541. DSI_PHY_ERR(dsi_phy, "Unbalanced %s call\n", __func__);
  542. else
  543. dsi_phy->refcount--;
  544. mutex_unlock(&dsi_phy->phy_lock);
  545. }
  546. /**
  547. * dsi_phy_drv_init() - initialize dsi phy driver
  548. * @dsi_phy: DSI PHY handle.
  549. *
  550. * Initializes DSI PHY driver. Should be called after dsi_phy_get().
  551. *
  552. * Return: error code.
  553. */
  554. int dsi_phy_drv_init(struct msm_dsi_phy *dsi_phy)
  555. {
  556. char dbg_name[DSI_DEBUG_NAME_LEN];
  557. snprintf(dbg_name, DSI_DEBUG_NAME_LEN, "dsi%d_phy", dsi_phy->index);
  558. sde_dbg_reg_register_base(dbg_name, dsi_phy->hw.base,
  559. msm_iomap_size(dsi_phy->pdev, "dsi_phy"),
  560. msm_get_phys_addr(dsi_phy->pdev, "dsi_phy"), SDE_DBG_DSI);
  561. return 0;
  562. }
  563. /**
  564. * dsi_phy_drv_deinit() - de-initialize dsi phy driver
  565. * @dsi_phy: DSI PHY handle.
  566. *
  567. * Release all resources acquired by dsi_phy_drv_init().
  568. *
  569. * Return: error code.
  570. */
  571. int dsi_phy_drv_deinit(struct msm_dsi_phy *dsi_phy)
  572. {
  573. return 0;
  574. }
  575. int dsi_phy_clk_cb_register(struct msm_dsi_phy *dsi_phy,
  576. struct clk_ctrl_cb *clk_cb)
  577. {
  578. if (!dsi_phy || !clk_cb) {
  579. DSI_PHY_ERR(dsi_phy, "Invalid params\n");
  580. return -EINVAL;
  581. }
  582. dsi_phy->clk_cb.priv = clk_cb->priv;
  583. dsi_phy->clk_cb.dsi_clk_cb = clk_cb->dsi_clk_cb;
  584. return 0;
  585. }
  586. /**
  587. * dsi_phy_validate_mode() - validate a display mode
  588. * @dsi_phy: DSI PHY handle.
  589. * @mode: Mode information.
  590. *
  591. * Validation will fail if the mode cannot be supported by the PHY driver or
  592. * hardware.
  593. *
  594. * Return: error code.
  595. */
  596. int dsi_phy_validate_mode(struct msm_dsi_phy *dsi_phy,
  597. struct dsi_mode_info *mode)
  598. {
  599. int rc = 0;
  600. if (!dsi_phy || !mode) {
  601. DSI_PHY_ERR(dsi_phy, "Invalid params\n");
  602. return -EINVAL;
  603. }
  604. DSI_PHY_DBG(dsi_phy, "Skipping validation\n");
  605. return rc;
  606. }
  607. /**
  608. * dsi_phy_set_power_state() - enable/disable dsi phy power supplies
  609. * @dsi_phy: DSI PHY handle.
  610. * @enable: Boolean flag to enable/disable.
  611. *
  612. * Return: error code.
  613. */
  614. int dsi_phy_set_power_state(struct msm_dsi_phy *dsi_phy, bool enable)
  615. {
  616. int rc = 0;
  617. if (!dsi_phy) {
  618. DSI_PHY_ERR(dsi_phy, "Invalid params\n");
  619. return -EINVAL;
  620. }
  621. mutex_lock(&dsi_phy->phy_lock);
  622. if (enable == dsi_phy->power_state) {
  623. DSI_PHY_ERR(dsi_phy, "No state change\n");
  624. goto error;
  625. }
  626. if (enable) {
  627. rc = dsi_pwr_enable_regulator(&dsi_phy->pwr_info.digital, true);
  628. if (rc) {
  629. DSI_PHY_ERR(dsi_phy, "failed to enable digital regulator\n");
  630. goto error;
  631. }
  632. if (dsi_phy->dsi_phy_state == DSI_PHY_ENGINE_OFF &&
  633. dsi_phy->regulator_required) {
  634. rc = dsi_pwr_enable_regulator(
  635. &dsi_phy->pwr_info.phy_pwr, true);
  636. if (rc) {
  637. DSI_PHY_ERR(dsi_phy, "failed to enable phy power\n");
  638. (void)dsi_pwr_enable_regulator(
  639. &dsi_phy->pwr_info.digital, false);
  640. goto error;
  641. }
  642. }
  643. } else {
  644. if (dsi_phy->dsi_phy_state == DSI_PHY_ENGINE_OFF &&
  645. dsi_phy->regulator_required) {
  646. rc = dsi_pwr_enable_regulator(
  647. &dsi_phy->pwr_info.phy_pwr, false);
  648. if (rc) {
  649. DSI_PHY_ERR(dsi_phy, "failed to enable digital regulator\n");
  650. goto error;
  651. }
  652. }
  653. rc = dsi_pwr_enable_regulator(&dsi_phy->pwr_info.digital,
  654. false);
  655. if (rc) {
  656. DSI_PHY_ERR(dsi_phy, "failed to enable phy power\n");
  657. goto error;
  658. }
  659. }
  660. dsi_phy->power_state = enable;
  661. error:
  662. mutex_unlock(&dsi_phy->phy_lock);
  663. return rc;
  664. }
  665. /**
  666. * dsi_phy_get_data_lanes_count() - Count the data lines need to be configured
  667. * @dsi_phy: DSI PHY handle.
  668. *
  669. * Return: Count of data lanes being used
  670. */
  671. static inline int dsi_phy_get_data_lanes_count(struct msm_dsi_phy *phy)
  672. {
  673. int num_of_lanes = 0;
  674. enum dsi_data_lanes dlanes;
  675. dlanes = phy->data_lanes;
  676. /**
  677. * For split link use case effective data lines need to be used
  678. * rather than total lanes on PHY for clock calculation and hence we
  679. * fall back pll->lanes to lanes_per_sublink rather than total
  680. * lanes.
  681. */
  682. if (phy->cfg.split_link.enabled)
  683. return phy->cfg.split_link.lanes_per_sublink;
  684. if (dlanes & DSI_DATA_LANE_0)
  685. num_of_lanes++;
  686. if (dlanes & DSI_DATA_LANE_1)
  687. num_of_lanes++;
  688. if (dlanes & DSI_DATA_LANE_2)
  689. num_of_lanes++;
  690. if (dlanes & DSI_DATA_LANE_3)
  691. num_of_lanes++;
  692. return num_of_lanes;
  693. }
  694. /**
  695. * dsi_phy_configure() - Configure DSI PHY PLL
  696. * @dsi_phy: DSI PHY handle.
  697. * @commit: boolean to specify if calculated PHY configuration
  698. * needs to be committed. Set to false in case of
  699. * dynamic clock switch.
  700. *
  701. * Return: error code.
  702. */
  703. int dsi_phy_configure(struct msm_dsi_phy *phy, bool commit)
  704. {
  705. int rc = 0;
  706. phy->pll->type = phy->cfg.phy_type;
  707. phy->pll->bpp = dsi_pixel_format_to_bpp(phy->dst_format);
  708. phy->pll->lanes = dsi_phy_get_data_lanes_count(phy);
  709. if (phy->hw.ops.configure)
  710. rc = phy->hw.ops.configure(phy->pll, commit);
  711. return rc;
  712. }
  713. /**
  714. * dsi_phy_pll_toggle() - Toggle DSI PHY PLL
  715. * @dsi_phy: DSI PHY handle.
  716. * @prepare: specifies if PLL needs to be turned on or not.
  717. *
  718. * Return: error code.
  719. */
  720. int dsi_phy_pll_toggle(struct msm_dsi_phy *phy, bool prepare)
  721. {
  722. int rc = 0;
  723. if (phy->hw.ops.pll_toggle)
  724. rc = phy->hw.ops.pll_toggle(phy->pll, prepare);
  725. return rc;
  726. }
  727. static int dsi_phy_enable_ulps(struct msm_dsi_phy *phy,
  728. struct dsi_host_config *config, bool clamp_enabled)
  729. {
  730. int rc = 0;
  731. u32 lanes = 0;
  732. u32 ulps_lanes;
  733. lanes = config->common_config.data_lanes;
  734. if (!dsi_is_type_cphy(&config->common_config))
  735. lanes |= DSI_CLOCK_LANE;
  736. /*
  737. * If DSI clamps are enabled, it means that the DSI lanes are
  738. * already in idle state. Checking for lanes to be in idle state
  739. * should be skipped during ULPS entry programming while coming
  740. * out of idle screen.
  741. */
  742. if (!clamp_enabled) {
  743. rc = phy->hw.ops.ulps_ops.wait_for_lane_idle(&phy->hw, lanes);
  744. if (rc) {
  745. DSI_PHY_ERR(phy, "lanes not entering idle, skip ULPS\n");
  746. return rc;
  747. }
  748. }
  749. phy->hw.ops.ulps_ops.ulps_request(&phy->hw, &phy->cfg, lanes);
  750. ulps_lanes = phy->hw.ops.ulps_ops.get_lanes_in_ulps(&phy->hw);
  751. if (!phy->hw.ops.ulps_ops.is_lanes_in_ulps(lanes, ulps_lanes)) {
  752. DSI_PHY_ERR(phy, "Failed to enter ULPS, request=0x%x, actual=0x%x\n",
  753. lanes, ulps_lanes);
  754. rc = -EIO;
  755. }
  756. return rc;
  757. }
  758. static int dsi_phy_disable_ulps(struct msm_dsi_phy *phy,
  759. struct dsi_host_config *config)
  760. {
  761. u32 ulps_lanes, lanes = 0;
  762. lanes = config->common_config.data_lanes;
  763. if (!dsi_is_type_cphy(&config->common_config))
  764. lanes |= DSI_CLOCK_LANE;
  765. ulps_lanes = phy->hw.ops.ulps_ops.get_lanes_in_ulps(&phy->hw);
  766. if (!phy->hw.ops.ulps_ops.is_lanes_in_ulps(lanes, ulps_lanes)) {
  767. DSI_PHY_ERR(phy, "Mismatch in ULPS: lanes:%d, ulps_lanes:%d\n",
  768. lanes, ulps_lanes);
  769. return -EIO;
  770. }
  771. phy->hw.ops.ulps_ops.ulps_exit(&phy->hw, &phy->cfg, lanes);
  772. ulps_lanes = phy->hw.ops.ulps_ops.get_lanes_in_ulps(&phy->hw);
  773. if (phy->hw.ops.ulps_ops.is_lanes_in_ulps(lanes, ulps_lanes)) {
  774. DSI_PHY_ERR(phy, "Lanes (0x%x) stuck in ULPS\n", ulps_lanes);
  775. return -EIO;
  776. }
  777. return 0;
  778. }
  779. void dsi_phy_toggle_resync_fifo(struct msm_dsi_phy *phy)
  780. {
  781. if (!phy)
  782. return;
  783. if (!phy->hw.ops.toggle_resync_fifo)
  784. return;
  785. phy->hw.ops.toggle_resync_fifo(&phy->hw);
  786. }
  787. void dsi_phy_reset_clk_en_sel(struct msm_dsi_phy *phy)
  788. {
  789. if (!phy)
  790. return;
  791. if (!phy->hw.ops.reset_clk_en_sel)
  792. return;
  793. phy->hw.ops.reset_clk_en_sel(&phy->hw);
  794. }
  795. int dsi_phy_set_ulps(struct msm_dsi_phy *phy, struct dsi_host_config *config,
  796. bool enable, bool clamp_enabled)
  797. {
  798. int rc = 0;
  799. if (!phy) {
  800. DSI_PHY_ERR(phy, "Invalid params\n");
  801. return DSI_PHY_ULPS_ERROR;
  802. }
  803. if (!phy->hw.ops.ulps_ops.ulps_request ||
  804. !phy->hw.ops.ulps_ops.ulps_exit ||
  805. !phy->hw.ops.ulps_ops.get_lanes_in_ulps ||
  806. !phy->hw.ops.ulps_ops.is_lanes_in_ulps ||
  807. !phy->hw.ops.ulps_ops.wait_for_lane_idle) {
  808. DSI_PHY_DBG(phy, "DSI PHY ULPS ops not present\n");
  809. return DSI_PHY_ULPS_NOT_HANDLED;
  810. }
  811. mutex_lock(&phy->phy_lock);
  812. if (enable)
  813. rc = dsi_phy_enable_ulps(phy, config, clamp_enabled);
  814. else
  815. rc = dsi_phy_disable_ulps(phy, config);
  816. if (rc) {
  817. DSI_PHY_ERR(phy, "Ulps state change(%d) failed, rc=%d\n",
  818. enable, rc);
  819. rc = DSI_PHY_ULPS_ERROR;
  820. goto error;
  821. }
  822. DSI_PHY_DBG(phy, "ULPS state = %d\n", enable);
  823. error:
  824. mutex_unlock(&phy->phy_lock);
  825. return rc;
  826. }
  827. /**
  828. * dsi_phy_enable() - enable DSI PHY hardware
  829. * @dsi_phy: DSI PHY handle.
  830. * @config: DSI host configuration.
  831. * @pll_source: Source PLL for PHY clock.
  832. * @skip_validation: Validation will not be performed on parameters.
  833. * @skip_op: Skip re-enabling dsi phy hw during usecases like
  834. * cont-splash/trusted-vm if set to true.
  835. *
  836. * Validates and enables DSI PHY.
  837. *
  838. * Return: error code.
  839. */
  840. int dsi_phy_enable(struct msm_dsi_phy *phy,
  841. struct dsi_host_config *config,
  842. enum dsi_phy_pll_source pll_source,
  843. bool skip_validation,
  844. bool skip_op)
  845. {
  846. int rc = 0;
  847. if (!phy || !config) {
  848. DSI_PHY_ERR(phy, "Invalid params\n");
  849. return -EINVAL;
  850. }
  851. mutex_lock(&phy->phy_lock);
  852. if (!skip_validation)
  853. DSI_PHY_DBG(phy, "TODO: perform validation\n");
  854. memcpy(&phy->mode, &config->video_timing, sizeof(phy->mode));
  855. memcpy(&phy->cfg.lane_map, &config->lane_map, sizeof(config->lane_map));
  856. phy->data_lanes = config->common_config.data_lanes;
  857. phy->dst_format = config->common_config.dst_format;
  858. phy->cfg.pll_source = pll_source;
  859. phy->cfg.bit_clk_rate_hz = config->bit_clk_rate_hz;
  860. /**
  861. * If PHY timing parameters are not present in panel dtsi file,
  862. * then calculate them in the driver
  863. */
  864. if (!phy->cfg.is_phy_timing_present)
  865. rc = phy->hw.ops.calculate_timing_params(&phy->hw,
  866. &phy->mode,
  867. &config->common_config,
  868. &phy->cfg.timing, false);
  869. if (rc) {
  870. DSI_PHY_ERR(phy, "failed to set timing, rc=%d\n", rc);
  871. goto error;
  872. }
  873. if (!skip_op) {
  874. dsi_phy_enable_hw(phy);
  875. DSI_PHY_DBG(phy, "cont splash not enabled, phy enable required\n");
  876. }
  877. phy->dsi_phy_state = DSI_PHY_ENGINE_ON;
  878. error:
  879. mutex_unlock(&phy->phy_lock);
  880. return rc;
  881. }
  882. /* update dsi phy timings for dynamic clk switch use case */
  883. int dsi_phy_update_phy_timings(struct msm_dsi_phy *phy,
  884. struct dsi_host_config *config)
  885. {
  886. int rc = 0;
  887. if (!phy || !config) {
  888. DSI_PHY_ERR(phy, "invalid argument\n");
  889. return -EINVAL;
  890. }
  891. memcpy(&phy->mode, &config->video_timing, sizeof(phy->mode));
  892. rc = phy->hw.ops.calculate_timing_params(&phy->hw, &phy->mode,
  893. &config->common_config,
  894. &phy->cfg.timing, true);
  895. if (rc)
  896. DSI_PHY_ERR(phy, "failed to calculate phy timings %d\n", rc);
  897. return rc;
  898. }
  899. int dsi_phy_lane_reset(struct msm_dsi_phy *phy)
  900. {
  901. int ret = 0;
  902. if (!phy)
  903. return ret;
  904. mutex_lock(&phy->phy_lock);
  905. if (phy->hw.ops.phy_lane_reset)
  906. ret = phy->hw.ops.phy_lane_reset(&phy->hw);
  907. mutex_unlock(&phy->phy_lock);
  908. return ret;
  909. }
  910. /**
  911. * dsi_phy_disable() - disable DSI PHY hardware.
  912. * @phy: DSI PHY handle.
  913. * @skip_op: Skip disabling dsi phy hw during usecases like
  914. * trusted-vm if set to true.
  915. *
  916. * Return: error code.
  917. */
  918. int dsi_phy_disable(struct msm_dsi_phy *phy, bool skip_op)
  919. {
  920. int rc = 0;
  921. if (!phy) {
  922. DSI_PHY_ERR(phy, "Invalid params\n");
  923. return -EINVAL;
  924. }
  925. mutex_lock(&phy->phy_lock);
  926. if (!skip_op)
  927. dsi_phy_disable_hw(phy);
  928. phy->dsi_phy_state = DSI_PHY_ENGINE_OFF;
  929. mutex_unlock(&phy->phy_lock);
  930. return rc;
  931. }
  932. /**
  933. * dsi_phy_set_clamp_state() - configure clamps for DSI lanes
  934. * @phy: DSI PHY handle.
  935. * @enable: boolean to specify clamp enable/disable.
  936. *
  937. * Return: error code.
  938. */
  939. int dsi_phy_set_clamp_state(struct msm_dsi_phy *phy, bool enable)
  940. {
  941. if (!phy)
  942. return -EINVAL;
  943. DSI_PHY_DBG(phy, "enable=%d\n", enable);
  944. if (phy->hw.ops.clamp_ctrl)
  945. phy->hw.ops.clamp_ctrl(&phy->hw, enable);
  946. return 0;
  947. }
  948. /**
  949. * dsi_phy_idle_ctrl() - enable/disable DSI PHY during idle screen
  950. * @phy: DSI PHY handle
  951. * @enable: boolean to specify PHY enable/disable.
  952. *
  953. * Return: error code.
  954. */
  955. int dsi_phy_idle_ctrl(struct msm_dsi_phy *phy, bool enable)
  956. {
  957. if (!phy) {
  958. DSI_PHY_ERR(phy, "Invalid params\n");
  959. return -EINVAL;
  960. }
  961. DSI_PHY_DBG(phy, "enable=%d\n", enable);
  962. mutex_lock(&phy->phy_lock);
  963. if (enable) {
  964. if (phy->hw.ops.phy_idle_on)
  965. phy->hw.ops.phy_idle_on(&phy->hw, &phy->cfg);
  966. if (phy->hw.ops.regulator_enable)
  967. phy->hw.ops.regulator_enable(&phy->hw,
  968. &phy->cfg.regulators);
  969. if (phy->hw.ops.enable)
  970. phy->hw.ops.enable(&phy->hw, &phy->cfg);
  971. phy->dsi_phy_state = DSI_PHY_ENGINE_ON;
  972. } else {
  973. phy->dsi_phy_state = DSI_PHY_ENGINE_OFF;
  974. if (phy->hw.ops.phy_idle_off)
  975. phy->hw.ops.phy_idle_off(&phy->hw, &phy->cfg);
  976. }
  977. mutex_unlock(&phy->phy_lock);
  978. return 0;
  979. }
  980. /**
  981. * dsi_phy_set_clk_freq() - set DSI PHY clock frequency setting
  982. * @phy: DSI PHY handle
  983. * @clk_freq: link clock frequency
  984. *
  985. * Return: error code.
  986. */
  987. int dsi_phy_set_clk_freq(struct msm_dsi_phy *phy,
  988. struct link_clk_freq *clk_freq)
  989. {
  990. if (!phy || !clk_freq) {
  991. DSI_PHY_ERR(phy, "Invalid params\n");
  992. return -EINVAL;
  993. }
  994. phy->regulator_required = clk_freq->byte_clk_rate >
  995. (phy->regulator_min_datarate_bps / BITS_PER_BYTE);
  996. /*
  997. * DSI PLL needs 0p9 LDO1A for Powering DSI PLL block.
  998. * PLL driver can vote for this regulator in PLL driver file, but for
  999. * the usecase where we come out of idle(static screen), if PLL and
  1000. * PHY vote for regulator ,there will be performance delays as both
  1001. * votes go through RPM to enable regulators.
  1002. */
  1003. phy->regulator_required = true;
  1004. DSI_PHY_DBG(phy, "lane_datarate=%u min_datarate=%u required=%d\n",
  1005. clk_freq->byte_clk_rate * BITS_PER_BYTE,
  1006. phy->regulator_min_datarate_bps,
  1007. phy->regulator_required);
  1008. return 0;
  1009. }
  1010. /**
  1011. * dsi_phy_set_timing_params() - timing parameters for the panel
  1012. * @phy: DSI PHY handle
  1013. * @timing: array holding timing params.
  1014. * @size: size of the array.
  1015. * @commit: boolean to indicate if programming PHY HW registers is
  1016. * required
  1017. *
  1018. * When PHY timing calculator is not implemented, this array will be used to
  1019. * pass PHY timing information.
  1020. *
  1021. * Return: error code.
  1022. */
  1023. int dsi_phy_set_timing_params(struct msm_dsi_phy *phy,
  1024. u32 *timing, u32 size, bool commit)
  1025. {
  1026. int rc = 0;
  1027. if (!phy || !timing || !size) {
  1028. DSI_PHY_ERR(phy, "Invalid params\n");
  1029. return -EINVAL;
  1030. }
  1031. mutex_lock(&phy->phy_lock);
  1032. if (phy->hw.ops.phy_timing_val)
  1033. rc = phy->hw.ops.phy_timing_val(&phy->cfg.timing, timing, size);
  1034. if (!rc)
  1035. phy->cfg.is_phy_timing_present = true;
  1036. if (phy->hw.ops.commit_phy_timing && commit)
  1037. phy->hw.ops.commit_phy_timing(&phy->hw, &phy->cfg.timing);
  1038. mutex_unlock(&phy->phy_lock);
  1039. return rc;
  1040. }
  1041. /**
  1042. * dsi_phy_conv_phy_to_logical_lane() - Convert physical to logical lane
  1043. * @lane_map: logical lane
  1044. * @phy_lane: physical lane
  1045. *
  1046. * Return: Error code on failure. Lane number on success.
  1047. */
  1048. int dsi_phy_conv_phy_to_logical_lane(
  1049. struct dsi_lane_map *lane_map, enum dsi_phy_data_lanes phy_lane)
  1050. {
  1051. int i = 0;
  1052. if (phy_lane > DSI_PHYSICAL_LANE_3)
  1053. return -EINVAL;
  1054. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++) {
  1055. if (lane_map->lane_map_v2[i] == phy_lane)
  1056. break;
  1057. }
  1058. return i;
  1059. }
  1060. /**
  1061. * dsi_phy_conv_logical_to_phy_lane() - Convert logical to physical lane
  1062. * @lane_map: physical lane
  1063. * @lane: logical lane
  1064. *
  1065. * Return: Error code on failure. Lane number on success.
  1066. */
  1067. int dsi_phy_conv_logical_to_phy_lane(
  1068. struct dsi_lane_map *lane_map, enum dsi_logical_lane lane)
  1069. {
  1070. int i = 0;
  1071. if (lane > (DSI_LANE_MAX - 1))
  1072. return -EINVAL;
  1073. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++) {
  1074. if (BIT(i) == lane_map->lane_map_v2[lane])
  1075. break;
  1076. }
  1077. return i;
  1078. }
  1079. /**
  1080. * dsi_phy_config_dynamic_refresh() - Configure dynamic refresh registers
  1081. * @phy: DSI PHY handle
  1082. * @delay: pipe delays for dynamic refresh
  1083. * @is_master: Boolean to indicate if for master or slave.
  1084. */
  1085. void dsi_phy_config_dynamic_refresh(struct msm_dsi_phy *phy,
  1086. struct dsi_dyn_clk_delay *delay,
  1087. bool is_master)
  1088. {
  1089. struct dsi_phy_cfg *cfg;
  1090. if (!phy)
  1091. return;
  1092. mutex_lock(&phy->phy_lock);
  1093. cfg = &phy->cfg;
  1094. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_config)
  1095. phy->hw.ops.dyn_refresh_ops.dyn_refresh_config(&phy->hw, cfg,
  1096. is_master);
  1097. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_pipe_delay)
  1098. phy->hw.ops.dyn_refresh_ops.dyn_refresh_pipe_delay(
  1099. &phy->hw, delay);
  1100. mutex_unlock(&phy->phy_lock);
  1101. }
  1102. /**
  1103. * dsi_phy_dynamic_refresh_trigger_sel() - trigger dynamic refresh and
  1104. * update the video timings at next frame flush call.
  1105. * @phy: DSI PHY handle
  1106. * @is_master: Boolean to indicate if for master or slave.
  1107. */
  1108. void dsi_phy_dynamic_refresh_trigger_sel(struct msm_dsi_phy *phy,
  1109. bool is_master)
  1110. {
  1111. if (!phy)
  1112. return;
  1113. mutex_lock(&phy->phy_lock);
  1114. /*
  1115. * program DYNAMIC_REFRESH_CTRL.TRIGGER_SEL for master.
  1116. */
  1117. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_trigger_sel)
  1118. phy->hw.ops.dyn_refresh_ops.dyn_refresh_trigger_sel
  1119. (&phy->hw, is_master);
  1120. phy->dfps_trigger_mdpintf_flush = true;
  1121. SDE_EVT32(is_master, phy->index);
  1122. mutex_unlock(&phy->phy_lock);
  1123. }
  1124. /**
  1125. * dsi_phy_dynamic_refresh_trigger() - trigger dynamic refresh
  1126. * @phy: DSI PHY handle
  1127. * @is_master: Boolean to indicate if for master or slave.
  1128. */
  1129. void dsi_phy_dynamic_refresh_trigger(struct msm_dsi_phy *phy, bool is_master)
  1130. {
  1131. u32 off;
  1132. if (!phy)
  1133. return;
  1134. mutex_lock(&phy->phy_lock);
  1135. /*
  1136. * program PLL_SWI_INTF_SEL and SW_TRIGGER bit only for
  1137. * master and program SYNC_MODE bit only for slave.
  1138. */
  1139. if (is_master)
  1140. off = BIT(DYN_REFRESH_INTF_SEL) | BIT(DYN_REFRESH_SWI_CTRL) |
  1141. BIT(DYN_REFRESH_SW_TRIGGER);
  1142. else
  1143. off = BIT(DYN_REFRESH_SYNC_MODE) | BIT(DYN_REFRESH_SWI_CTRL);
  1144. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper)
  1145. phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper(&phy->hw, off);
  1146. mutex_unlock(&phy->phy_lock);
  1147. }
  1148. /**
  1149. * dsi_phy_cache_phy_timings - cache the phy timings calculated as part of
  1150. * dynamic refresh.
  1151. * @phy: DSI PHY Handle.
  1152. * @dst: Pointer to cache location.
  1153. * @size: Number of phy lane settings.
  1154. */
  1155. int dsi_phy_dyn_refresh_cache_phy_timings(struct msm_dsi_phy *phy, u32 *dst,
  1156. u32 size)
  1157. {
  1158. int rc = 0;
  1159. if (!phy || !dst || !size)
  1160. return -EINVAL;
  1161. if (phy->hw.ops.dyn_refresh_ops.cache_phy_timings)
  1162. rc = phy->hw.ops.dyn_refresh_ops.cache_phy_timings(
  1163. &phy->cfg.timing, dst, size);
  1164. if (rc)
  1165. DSI_PHY_ERR(phy, "failed to cache phy timings %d\n", rc);
  1166. return rc;
  1167. }
  1168. /**
  1169. * dsi_phy_dynamic_refresh_clear() - clear dynamic refresh config
  1170. * @phy: DSI PHY handle
  1171. */
  1172. void dsi_phy_dynamic_refresh_clear(struct msm_dsi_phy *phy)
  1173. {
  1174. if (!phy)
  1175. return;
  1176. mutex_lock(&phy->phy_lock);
  1177. if (phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper)
  1178. phy->hw.ops.dyn_refresh_ops.dyn_refresh_helper(&phy->hw, 0);
  1179. mutex_unlock(&phy->phy_lock);
  1180. }
  1181. /**
  1182. * dsi_phy_set_continuous_clk() - set/unset force clock lane HS request
  1183. * @phy: DSI PHY handle
  1184. * @enable: variable to control continuous clock
  1185. */
  1186. void dsi_phy_set_continuous_clk(struct msm_dsi_phy *phy, bool enable)
  1187. {
  1188. if (!phy)
  1189. return;
  1190. mutex_lock(&phy->phy_lock);
  1191. if (phy->hw.ops.set_continuous_clk)
  1192. phy->hw.ops.set_continuous_clk(&phy->hw, enable);
  1193. else
  1194. DSI_PHY_WARN(phy, "set_continuous_clk ops not present\n");
  1195. mutex_unlock(&phy->phy_lock);
  1196. }
  1197. /**
  1198. * dsi_phy_pll_parse_dfps_data() - parse dfps data for PLL
  1199. * @phy: DSI PHY handle
  1200. */
  1201. void dsi_phy_pll_parse_dfps_data(struct msm_dsi_phy *phy)
  1202. {
  1203. dsi_pll_parse_dfps_data(phy->pdev, phy->pll);
  1204. }
  1205. void dsi_phy_drv_register(void)
  1206. {
  1207. platform_driver_register(&dsi_phy_platform_driver);
  1208. }
  1209. void dsi_phy_drv_unregister(void)
  1210. {
  1211. platform_driver_unregister(&dsi_phy_platform_driver);
  1212. }