dsi_phy.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /*
  2. * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/platform_device.h>
  14. #include <linux/regulator/consumer.h>
  15. #include "dsi.h"
  16. #include "dsi.xml.h"
  17. #define dsi_phy_read(offset) msm_readl((offset))
  18. #define dsi_phy_write(offset, data) msm_writel((data), (offset))
  19. struct dsi_phy_ops {
  20. int (*enable)(struct msm_dsi_phy *phy, bool is_dual_panel,
  21. const unsigned long bit_rate, const unsigned long esc_rate);
  22. int (*disable)(struct msm_dsi_phy *phy);
  23. };
  24. struct dsi_phy_cfg {
  25. enum msm_dsi_phy_type type;
  26. struct dsi_reg_config reg_cfg;
  27. struct dsi_phy_ops ops;
  28. };
  29. struct dsi_dphy_timing {
  30. u32 clk_pre;
  31. u32 clk_post;
  32. u32 clk_zero;
  33. u32 clk_trail;
  34. u32 clk_prepare;
  35. u32 hs_exit;
  36. u32 hs_zero;
  37. u32 hs_prepare;
  38. u32 hs_trail;
  39. u32 hs_rqst;
  40. u32 ta_go;
  41. u32 ta_sure;
  42. u32 ta_get;
  43. };
  44. struct msm_dsi_phy {
  45. struct platform_device *pdev;
  46. void __iomem *base;
  47. void __iomem *reg_base;
  48. int id;
  49. struct clk *ahb_clk;
  50. struct regulator_bulk_data supplies[DSI_DEV_REGULATOR_MAX];
  51. struct dsi_dphy_timing timing;
  52. const struct dsi_phy_cfg *cfg;
  53. struct msm_dsi_pll *pll;
  54. };
  55. static int dsi_phy_regulator_init(struct msm_dsi_phy *phy)
  56. {
  57. struct regulator_bulk_data *s = phy->supplies;
  58. const struct dsi_reg_entry *regs = phy->cfg->reg_cfg.regs;
  59. struct device *dev = &phy->pdev->dev;
  60. int num = phy->cfg->reg_cfg.num;
  61. int i, ret;
  62. for (i = 0; i < num; i++)
  63. s[i].supply = regs[i].name;
  64. ret = devm_regulator_bulk_get(&phy->pdev->dev, num, s);
  65. if (ret < 0) {
  66. dev_err(dev, "%s: failed to init regulator, ret=%d\n",
  67. __func__, ret);
  68. return ret;
  69. }
  70. for (i = 0; i < num; i++) {
  71. if ((regs[i].min_voltage >= 0) && (regs[i].max_voltage >= 0)) {
  72. ret = regulator_set_voltage(s[i].consumer,
  73. regs[i].min_voltage, regs[i].max_voltage);
  74. if (ret < 0) {
  75. dev_err(dev,
  76. "regulator %d set voltage failed, %d\n",
  77. i, ret);
  78. return ret;
  79. }
  80. }
  81. }
  82. return 0;
  83. }
  84. static void dsi_phy_regulator_disable(struct msm_dsi_phy *phy)
  85. {
  86. struct regulator_bulk_data *s = phy->supplies;
  87. const struct dsi_reg_entry *regs = phy->cfg->reg_cfg.regs;
  88. int num = phy->cfg->reg_cfg.num;
  89. int i;
  90. DBG("");
  91. for (i = num - 1; i >= 0; i--)
  92. if (regs[i].disable_load >= 0)
  93. regulator_set_load(s[i].consumer,
  94. regs[i].disable_load);
  95. regulator_bulk_disable(num, s);
  96. }
  97. static int dsi_phy_regulator_enable(struct msm_dsi_phy *phy)
  98. {
  99. struct regulator_bulk_data *s = phy->supplies;
  100. const struct dsi_reg_entry *regs = phy->cfg->reg_cfg.regs;
  101. struct device *dev = &phy->pdev->dev;
  102. int num = phy->cfg->reg_cfg.num;
  103. int ret, i;
  104. DBG("");
  105. for (i = 0; i < num; i++) {
  106. if (regs[i].enable_load >= 0) {
  107. ret = regulator_set_load(s[i].consumer,
  108. regs[i].enable_load);
  109. if (ret < 0) {
  110. dev_err(dev,
  111. "regulator %d set op mode failed, %d\n",
  112. i, ret);
  113. goto fail;
  114. }
  115. }
  116. }
  117. ret = regulator_bulk_enable(num, s);
  118. if (ret < 0) {
  119. dev_err(dev, "regulator enable failed, %d\n", ret);
  120. goto fail;
  121. }
  122. return 0;
  123. fail:
  124. for (i--; i >= 0; i--)
  125. regulator_set_load(s[i].consumer, regs[i].disable_load);
  126. return ret;
  127. }
  128. #define S_DIV_ROUND_UP(n, d) \
  129. (((n) >= 0) ? (((n) + (d) - 1) / (d)) : (((n) - (d) + 1) / (d)))
  130. static inline s32 linear_inter(s32 tmax, s32 tmin, s32 percent,
  131. s32 min_result, bool even)
  132. {
  133. s32 v;
  134. v = (tmax - tmin) * percent;
  135. v = S_DIV_ROUND_UP(v, 100) + tmin;
  136. if (even && (v & 0x1))
  137. return max_t(s32, min_result, v - 1);
  138. else
  139. return max_t(s32, min_result, v);
  140. }
  141. static void dsi_dphy_timing_calc_clk_zero(struct dsi_dphy_timing *timing,
  142. s32 ui, s32 coeff, s32 pcnt)
  143. {
  144. s32 tmax, tmin, clk_z;
  145. s32 temp;
  146. /* reset */
  147. temp = 300 * coeff - ((timing->clk_prepare >> 1) + 1) * 2 * ui;
  148. tmin = S_DIV_ROUND_UP(temp, ui) - 2;
  149. if (tmin > 255) {
  150. tmax = 511;
  151. clk_z = linear_inter(2 * tmin, tmin, pcnt, 0, true);
  152. } else {
  153. tmax = 255;
  154. clk_z = linear_inter(tmax, tmin, pcnt, 0, true);
  155. }
  156. /* adjust */
  157. temp = (timing->hs_rqst + timing->clk_prepare + clk_z) & 0x7;
  158. timing->clk_zero = clk_z + 8 - temp;
  159. }
  160. static int dsi_dphy_timing_calc(struct dsi_dphy_timing *timing,
  161. const unsigned long bit_rate, const unsigned long esc_rate)
  162. {
  163. s32 ui, lpx;
  164. s32 tmax, tmin;
  165. s32 pcnt0 = 10;
  166. s32 pcnt1 = (bit_rate > 1200000000) ? 15 : 10;
  167. s32 pcnt2 = 10;
  168. s32 pcnt3 = (bit_rate > 180000000) ? 10 : 40;
  169. s32 coeff = 1000; /* Precision, should avoid overflow */
  170. s32 temp;
  171. if (!bit_rate || !esc_rate)
  172. return -EINVAL;
  173. ui = mult_frac(NSEC_PER_MSEC, coeff, bit_rate / 1000);
  174. lpx = mult_frac(NSEC_PER_MSEC, coeff, esc_rate / 1000);
  175. tmax = S_DIV_ROUND_UP(95 * coeff, ui) - 2;
  176. tmin = S_DIV_ROUND_UP(38 * coeff, ui) - 2;
  177. timing->clk_prepare = linear_inter(tmax, tmin, pcnt0, 0, true);
  178. temp = lpx / ui;
  179. if (temp & 0x1)
  180. timing->hs_rqst = temp;
  181. else
  182. timing->hs_rqst = max_t(s32, 0, temp - 2);
  183. /* Calculate clk_zero after clk_prepare and hs_rqst */
  184. dsi_dphy_timing_calc_clk_zero(timing, ui, coeff, pcnt2);
  185. temp = 105 * coeff + 12 * ui - 20 * coeff;
  186. tmax = S_DIV_ROUND_UP(temp, ui) - 2;
  187. tmin = S_DIV_ROUND_UP(60 * coeff, ui) - 2;
  188. timing->clk_trail = linear_inter(tmax, tmin, pcnt3, 0, true);
  189. temp = 85 * coeff + 6 * ui;
  190. tmax = S_DIV_ROUND_UP(temp, ui) - 2;
  191. temp = 40 * coeff + 4 * ui;
  192. tmin = S_DIV_ROUND_UP(temp, ui) - 2;
  193. timing->hs_prepare = linear_inter(tmax, tmin, pcnt1, 0, true);
  194. tmax = 255;
  195. temp = ((timing->hs_prepare >> 1) + 1) * 2 * ui + 2 * ui;
  196. temp = 145 * coeff + 10 * ui - temp;
  197. tmin = S_DIV_ROUND_UP(temp, ui) - 2;
  198. timing->hs_zero = linear_inter(tmax, tmin, pcnt2, 24, true);
  199. temp = 105 * coeff + 12 * ui - 20 * coeff;
  200. tmax = S_DIV_ROUND_UP(temp, ui) - 2;
  201. temp = 60 * coeff + 4 * ui;
  202. tmin = DIV_ROUND_UP(temp, ui) - 2;
  203. timing->hs_trail = linear_inter(tmax, tmin, pcnt3, 0, true);
  204. tmax = 255;
  205. tmin = S_DIV_ROUND_UP(100 * coeff, ui) - 2;
  206. timing->hs_exit = linear_inter(tmax, tmin, pcnt2, 0, true);
  207. tmax = 63;
  208. temp = ((timing->hs_exit >> 1) + 1) * 2 * ui;
  209. temp = 60 * coeff + 52 * ui - 24 * ui - temp;
  210. tmin = S_DIV_ROUND_UP(temp, 8 * ui) - 1;
  211. timing->clk_post = linear_inter(tmax, tmin, pcnt2, 0, false);
  212. tmax = 63;
  213. temp = ((timing->clk_prepare >> 1) + 1) * 2 * ui;
  214. temp += ((timing->clk_zero >> 1) + 1) * 2 * ui;
  215. temp += 8 * ui + lpx;
  216. tmin = S_DIV_ROUND_UP(temp, 8 * ui) - 1;
  217. if (tmin > tmax) {
  218. temp = linear_inter(2 * tmax, tmin, pcnt2, 0, false) >> 1;
  219. timing->clk_pre = temp >> 1;
  220. temp = (2 * tmax - tmin) * pcnt2;
  221. } else {
  222. timing->clk_pre = linear_inter(tmax, tmin, pcnt2, 0, false);
  223. }
  224. timing->ta_go = 3;
  225. timing->ta_sure = 0;
  226. timing->ta_get = 4;
  227. DBG("PHY timings: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d",
  228. timing->clk_pre, timing->clk_post, timing->clk_zero,
  229. timing->clk_trail, timing->clk_prepare, timing->hs_exit,
  230. timing->hs_zero, timing->hs_prepare, timing->hs_trail,
  231. timing->hs_rqst);
  232. return 0;
  233. }
  234. static void dsi_28nm_phy_regulator_ctrl(struct msm_dsi_phy *phy, bool enable)
  235. {
  236. void __iomem *base = phy->reg_base;
  237. if (!enable) {
  238. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CAL_PWR_CFG, 0);
  239. return;
  240. }
  241. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CTRL_0, 0x0);
  242. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CAL_PWR_CFG, 1);
  243. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CTRL_5, 0);
  244. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CTRL_3, 0);
  245. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CTRL_2, 0x3);
  246. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CTRL_1, 0x9);
  247. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CTRL_0, 0x7);
  248. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CTRL_4, 0x20);
  249. }
  250. static int dsi_28nm_phy_enable(struct msm_dsi_phy *phy, bool is_dual_panel,
  251. const unsigned long bit_rate, const unsigned long esc_rate)
  252. {
  253. struct dsi_dphy_timing *timing = &phy->timing;
  254. int i;
  255. void __iomem *base = phy->base;
  256. DBG("");
  257. if (dsi_dphy_timing_calc(timing, bit_rate, esc_rate)) {
  258. pr_err("%s: D-PHY timing calculation failed\n", __func__);
  259. return -EINVAL;
  260. }
  261. dsi_phy_write(base + REG_DSI_28nm_PHY_STRENGTH_0, 0xff);
  262. dsi_28nm_phy_regulator_ctrl(phy, true);
  263. dsi_phy_write(base + REG_DSI_28nm_PHY_LDO_CNTRL, 0x00);
  264. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_0,
  265. DSI_28nm_PHY_TIMING_CTRL_0_CLK_ZERO(timing->clk_zero));
  266. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_1,
  267. DSI_28nm_PHY_TIMING_CTRL_1_CLK_TRAIL(timing->clk_trail));
  268. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_2,
  269. DSI_28nm_PHY_TIMING_CTRL_2_CLK_PREPARE(timing->clk_prepare));
  270. if (timing->clk_zero & BIT(8))
  271. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_3,
  272. DSI_28nm_PHY_TIMING_CTRL_3_CLK_ZERO_8);
  273. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_4,
  274. DSI_28nm_PHY_TIMING_CTRL_4_HS_EXIT(timing->hs_exit));
  275. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_5,
  276. DSI_28nm_PHY_TIMING_CTRL_5_HS_ZERO(timing->hs_zero));
  277. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_6,
  278. DSI_28nm_PHY_TIMING_CTRL_6_HS_PREPARE(timing->hs_prepare));
  279. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_7,
  280. DSI_28nm_PHY_TIMING_CTRL_7_HS_TRAIL(timing->hs_trail));
  281. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_8,
  282. DSI_28nm_PHY_TIMING_CTRL_8_HS_RQST(timing->hs_rqst));
  283. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_9,
  284. DSI_28nm_PHY_TIMING_CTRL_9_TA_GO(timing->ta_go) |
  285. DSI_28nm_PHY_TIMING_CTRL_9_TA_SURE(timing->ta_sure));
  286. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_10,
  287. DSI_28nm_PHY_TIMING_CTRL_10_TA_GET(timing->ta_get));
  288. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_11,
  289. DSI_28nm_PHY_TIMING_CTRL_11_TRIG3_CMD(0));
  290. dsi_phy_write(base + REG_DSI_28nm_PHY_CTRL_1, 0x00);
  291. dsi_phy_write(base + REG_DSI_28nm_PHY_CTRL_0, 0x5f);
  292. dsi_phy_write(base + REG_DSI_28nm_PHY_STRENGTH_1, 0x6);
  293. for (i = 0; i < 4; i++) {
  294. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_CFG_0(i), 0);
  295. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_CFG_1(i), 0);
  296. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_CFG_2(i), 0);
  297. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_CFG_3(i), 0);
  298. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_TEST_DATAPATH(i), 0);
  299. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_DEBUG_SEL(i), 0);
  300. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_TEST_STR_0(i), 0x1);
  301. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_TEST_STR_1(i), 0x97);
  302. }
  303. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_CFG_4(0), 0);
  304. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_CFG_4(1), 0x5);
  305. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_CFG_4(2), 0xa);
  306. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_CFG_4(3), 0xf);
  307. dsi_phy_write(base + REG_DSI_28nm_PHY_LNCK_CFG_1, 0xc0);
  308. dsi_phy_write(base + REG_DSI_28nm_PHY_LNCK_TEST_STR0, 0x1);
  309. dsi_phy_write(base + REG_DSI_28nm_PHY_LNCK_TEST_STR1, 0xbb);
  310. dsi_phy_write(base + REG_DSI_28nm_PHY_CTRL_0, 0x5f);
  311. if (is_dual_panel && (phy->id != DSI_CLOCK_MASTER))
  312. dsi_phy_write(base + REG_DSI_28nm_PHY_GLBL_TEST_CTRL, 0x00);
  313. else
  314. dsi_phy_write(base + REG_DSI_28nm_PHY_GLBL_TEST_CTRL, 0x01);
  315. return 0;
  316. }
  317. static int dsi_28nm_phy_disable(struct msm_dsi_phy *phy)
  318. {
  319. dsi_phy_write(phy->base + REG_DSI_28nm_PHY_CTRL_0, 0);
  320. dsi_28nm_phy_regulator_ctrl(phy, false);
  321. /*
  322. * Wait for the registers writes to complete in order to
  323. * ensure that the phy is completely disabled
  324. */
  325. wmb();
  326. return 0;
  327. }
  328. static int dsi_phy_enable_resource(struct msm_dsi_phy *phy)
  329. {
  330. int ret;
  331. pm_runtime_get_sync(&phy->pdev->dev);
  332. ret = clk_prepare_enable(phy->ahb_clk);
  333. if (ret) {
  334. pr_err("%s: can't enable ahb clk, %d\n", __func__, ret);
  335. pm_runtime_put_sync(&phy->pdev->dev);
  336. }
  337. return ret;
  338. }
  339. static void dsi_phy_disable_resource(struct msm_dsi_phy *phy)
  340. {
  341. clk_disable_unprepare(phy->ahb_clk);
  342. pm_runtime_put_sync(&phy->pdev->dev);
  343. }
  344. static const struct dsi_phy_cfg dsi_phy_cfgs[MSM_DSI_PHY_MAX] = {
  345. [MSM_DSI_PHY_28NM_HPM] = {
  346. .type = MSM_DSI_PHY_28NM_HPM,
  347. .reg_cfg = {
  348. .num = 1,
  349. .regs = {
  350. {"vddio", 1800000, 1800000, 100000, 100},
  351. },
  352. },
  353. .ops = {
  354. .enable = dsi_28nm_phy_enable,
  355. .disable = dsi_28nm_phy_disable,
  356. }
  357. },
  358. [MSM_DSI_PHY_28NM_LP] = {
  359. .type = MSM_DSI_PHY_28NM_LP,
  360. .reg_cfg = {
  361. .num = 1,
  362. .regs = {
  363. {"vddio", 1800000, 1800000, 100000, 100},
  364. },
  365. },
  366. .ops = {
  367. .enable = dsi_28nm_phy_enable,
  368. .disable = dsi_28nm_phy_disable,
  369. }
  370. },
  371. };
  372. static const struct of_device_id dsi_phy_dt_match[] = {
  373. { .compatible = "qcom,dsi-phy-28nm-hpm",
  374. .data = &dsi_phy_cfgs[MSM_DSI_PHY_28NM_HPM],},
  375. { .compatible = "qcom,dsi-phy-28nm-lp",
  376. .data = &dsi_phy_cfgs[MSM_DSI_PHY_28NM_LP],},
  377. {}
  378. };
  379. static int dsi_phy_driver_probe(struct platform_device *pdev)
  380. {
  381. struct msm_dsi_phy *phy;
  382. const struct of_device_id *match;
  383. int ret;
  384. phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
  385. if (!phy)
  386. return -ENOMEM;
  387. match = of_match_node(dsi_phy_dt_match, pdev->dev.of_node);
  388. if (!match)
  389. return -ENODEV;
  390. phy->cfg = match->data;
  391. phy->pdev = pdev;
  392. ret = of_property_read_u32(pdev->dev.of_node,
  393. "qcom,dsi-phy-index", &phy->id);
  394. if (ret) {
  395. dev_err(&pdev->dev,
  396. "%s: PHY index not specified, ret=%d\n",
  397. __func__, ret);
  398. goto fail;
  399. }
  400. phy->base = msm_ioremap(pdev, "dsi_phy", "DSI_PHY");
  401. if (IS_ERR(phy->base)) {
  402. dev_err(&pdev->dev, "%s: failed to map phy base\n", __func__);
  403. ret = -ENOMEM;
  404. goto fail;
  405. }
  406. phy->reg_base = msm_ioremap(pdev, "dsi_phy_regulator", "DSI_PHY_REG");
  407. if (IS_ERR(phy->reg_base)) {
  408. dev_err(&pdev->dev,
  409. "%s: failed to map phy regulator base\n", __func__);
  410. ret = -ENOMEM;
  411. goto fail;
  412. }
  413. ret = dsi_phy_regulator_init(phy);
  414. if (ret) {
  415. dev_err(&pdev->dev, "%s: failed to init regulator\n", __func__);
  416. goto fail;
  417. }
  418. phy->ahb_clk = devm_clk_get(&pdev->dev, "iface_clk");
  419. if (IS_ERR(phy->ahb_clk)) {
  420. pr_err("%s: Unable to get ahb clk\n", __func__);
  421. ret = PTR_ERR(phy->ahb_clk);
  422. goto fail;
  423. }
  424. /* PLL init will call into clk_register which requires
  425. * register access, so we need to enable power and ahb clock.
  426. */
  427. ret = dsi_phy_enable_resource(phy);
  428. if (ret)
  429. goto fail;
  430. phy->pll = msm_dsi_pll_init(pdev, phy->cfg->type, phy->id);
  431. if (!phy->pll)
  432. dev_info(&pdev->dev,
  433. "%s: pll init failed, need separate pll clk driver\n",
  434. __func__);
  435. dsi_phy_disable_resource(phy);
  436. platform_set_drvdata(pdev, phy);
  437. return 0;
  438. fail:
  439. return ret;
  440. }
  441. static int dsi_phy_driver_remove(struct platform_device *pdev)
  442. {
  443. struct msm_dsi_phy *phy = platform_get_drvdata(pdev);
  444. if (phy && phy->pll) {
  445. msm_dsi_pll_destroy(phy->pll);
  446. phy->pll = NULL;
  447. }
  448. platform_set_drvdata(pdev, NULL);
  449. return 0;
  450. }
  451. static struct platform_driver dsi_phy_platform_driver = {
  452. .probe = dsi_phy_driver_probe,
  453. .remove = dsi_phy_driver_remove,
  454. .driver = {
  455. .name = "msm_dsi_phy",
  456. .of_match_table = dsi_phy_dt_match,
  457. },
  458. };
  459. void __init msm_dsi_phy_driver_register(void)
  460. {
  461. platform_driver_register(&dsi_phy_platform_driver);
  462. }
  463. void __exit msm_dsi_phy_driver_unregister(void)
  464. {
  465. platform_driver_unregister(&dsi_phy_platform_driver);
  466. }
  467. int msm_dsi_phy_enable(struct msm_dsi_phy *phy, bool is_dual_panel,
  468. const unsigned long bit_rate, const unsigned long esc_rate)
  469. {
  470. int ret;
  471. if (!phy || !phy->cfg->ops.enable)
  472. return -EINVAL;
  473. ret = dsi_phy_regulator_enable(phy);
  474. if (ret) {
  475. dev_err(&phy->pdev->dev, "%s: regulator enable failed, %d\n",
  476. __func__, ret);
  477. return ret;
  478. }
  479. return phy->cfg->ops.enable(phy, is_dual_panel, bit_rate, esc_rate);
  480. }
  481. int msm_dsi_phy_disable(struct msm_dsi_phy *phy)
  482. {
  483. if (!phy || !phy->cfg->ops.disable)
  484. return -EINVAL;
  485. phy->cfg->ops.disable(phy);
  486. dsi_phy_regulator_disable(phy);
  487. return 0;
  488. }
  489. void msm_dsi_phy_get_clk_pre_post(struct msm_dsi_phy *phy,
  490. u32 *clk_pre, u32 *clk_post)
  491. {
  492. if (!phy)
  493. return;
  494. if (clk_pre)
  495. *clk_pre = phy->timing.clk_pre;
  496. if (clk_post)
  497. *clk_post = phy->timing.clk_post;
  498. }
  499. struct msm_dsi_pll *msm_dsi_phy_get_pll(struct msm_dsi_phy *phy)
  500. {
  501. if (!phy)
  502. return NULL;
  503. return phy->pll;
  504. }