dsi_phy.c 34 KB

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