1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2017, 2020, The Linux Foundation. All rights reserved.
4 * Copyright (c) 2021, Linaro Ltd.
8 #include <linux/clk-provider.h>
9 #include <linux/delay.h>
10 #include <linux/err.h>
12 #include <linux/iopoll.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
16 #include <linux/of_device.h>
17 #include <linux/of_address.h>
18 #include <linux/phy/phy.h>
19 #include <linux/platform_device.h>
20 #include <linux/regulator/consumer.h>
21 #include <linux/reset.h>
22 #include <linux/slab.h>
24 #include <dt-bindings/phy/phy.h>
26 #include "phy-qcom-qmp.h"
28 /* EDP_PHY registers */
29 #define DP_PHY_CFG 0x0010
30 #define DP_PHY_CFG_1 0x0014
31 #define DP_PHY_PD_CTL 0x001c
32 #define DP_PHY_MODE 0x0020
34 #define DP_PHY_AUX_CFG0 0x0024
35 #define DP_PHY_AUX_CFG1 0x0028
36 #define DP_PHY_AUX_CFG2 0x002C
37 #define DP_PHY_AUX_CFG3 0x0030
38 #define DP_PHY_AUX_CFG4 0x0034
39 #define DP_PHY_AUX_CFG5 0x0038
40 #define DP_PHY_AUX_CFG6 0x003C
41 #define DP_PHY_AUX_CFG7 0x0040
42 #define DP_PHY_AUX_CFG8 0x0044
43 #define DP_PHY_AUX_CFG9 0x0048
45 #define DP_PHY_AUX_INTERRUPT_MASK 0x0058
47 #define DP_PHY_VCO_DIV 0x0074
48 #define DP_PHY_TX0_TX1_LANE_CTL 0x007c
49 #define DP_PHY_TX2_TX3_LANE_CTL 0x00a0
51 #define DP_PHY_STATUS 0x00e0
53 /* LANE_TXn registers */
54 #define TXn_CLKBUF_ENABLE 0x0000
55 #define TXn_TX_EMP_POST1_LVL 0x0004
57 #define TXn_TX_DRV_LVL 0x0014
58 #define TXn_TX_DRV_LVL_OFFSET 0x0018
59 #define TXn_RESET_TSYNC_EN 0x001c
60 #define TXn_LDO_CONFIG 0x0084
61 #define TXn_TX_BAND 0x0028
63 #define TXn_RES_CODE_LANE_OFFSET_TX0 0x0044
64 #define TXn_RES_CODE_LANE_OFFSET_TX1 0x0048
66 #define TXn_TRANSCEIVER_BIAS_EN 0x0054
67 #define TXn_HIGHZ_DRVR_EN 0x0058
68 #define TXn_TX_POL_INV 0x005c
69 #define TXn_LANE_MODE_1 0x0064
71 #define TXn_TRAN_DRVR_EMP_EN 0x0078
76 /* DP PHY swing and pre_emphasis tables */
77 const u8 (*swing_hbr_rbr)[4][4];
78 const u8 (*swing_hbr3_hbr2)[4][4];
79 const u8 (*pre_emphasis_hbr_rbr)[4][4];
80 const u8 (*pre_emphasis_hbr3_hbr2)[4][4];
85 const struct qcom_edp_cfg *cfg;
94 struct clk_hw dp_link_hw;
95 struct clk_hw dp_pixel_hw;
97 struct phy_configure_opts_dp dp_opts;
99 struct clk_bulk_data clks[2];
100 struct regulator_bulk_data supplies[2];
103 static const u8 dp_swing_hbr_rbr[4][4] = {
104 { 0x08, 0x0f, 0x16, 0x1f },
105 { 0x11, 0x1e, 0x1f, 0xff },
106 { 0x16, 0x1f, 0xff, 0xff },
107 { 0x1f, 0xff, 0xff, 0xff }
110 static const u8 dp_pre_emp_hbr_rbr[4][4] = {
111 { 0x00, 0x0d, 0x14, 0x1a },
112 { 0x00, 0x0e, 0x15, 0xff },
113 { 0x00, 0x0e, 0xff, 0xff },
114 { 0x03, 0xff, 0xff, 0xff }
117 static const u8 dp_swing_hbr2_hbr3[4][4] = {
118 { 0x02, 0x12, 0x16, 0x1a },
119 { 0x09, 0x19, 0x1f, 0xff },
120 { 0x10, 0x1f, 0xff, 0xff },
121 { 0x1f, 0xff, 0xff, 0xff }
124 static const u8 dp_pre_emp_hbr2_hbr3[4][4] = {
125 { 0x00, 0x0c, 0x15, 0x1b },
126 { 0x02, 0x0e, 0x16, 0xff },
127 { 0x02, 0x11, 0xff, 0xff },
128 { 0x04, 0xff, 0xff, 0xff }
131 static const struct qcom_edp_cfg dp_phy_cfg = {
133 .swing_hbr_rbr = &dp_swing_hbr_rbr,
134 .swing_hbr3_hbr2 = &dp_swing_hbr2_hbr3,
135 .pre_emphasis_hbr_rbr = &dp_pre_emp_hbr_rbr,
136 .pre_emphasis_hbr3_hbr2 = &dp_pre_emp_hbr2_hbr3,
139 static const u8 edp_swing_hbr_rbr[4][4] = {
140 { 0x07, 0x0f, 0x16, 0x1f },
141 { 0x0d, 0x16, 0x1e, 0xff },
142 { 0x11, 0x1b, 0xff, 0xff },
143 { 0x16, 0xff, 0xff, 0xff }
146 static const u8 edp_pre_emp_hbr_rbr[4][4] = {
147 { 0x05, 0x12, 0x17, 0x1d },
148 { 0x05, 0x11, 0x18, 0xff },
149 { 0x06, 0x11, 0xff, 0xff },
150 { 0x00, 0xff, 0xff, 0xff }
153 static const u8 edp_swing_hbr2_hbr3[4][4] = {
154 { 0x0b, 0x11, 0x17, 0x1c },
155 { 0x10, 0x19, 0x1f, 0xff },
156 { 0x19, 0x1f, 0xff, 0xff },
157 { 0x1f, 0xff, 0xff, 0xff }
160 static const u8 edp_pre_emp_hbr2_hbr3[4][4] = {
161 { 0x08, 0x11, 0x17, 0x1b },
162 { 0x00, 0x0c, 0x13, 0xff },
163 { 0x05, 0x10, 0xff, 0xff },
164 { 0x00, 0xff, 0xff, 0xff }
167 static const struct qcom_edp_cfg edp_phy_cfg = {
169 .swing_hbr_rbr = &edp_swing_hbr_rbr,
170 .swing_hbr3_hbr2 = &edp_swing_hbr2_hbr3,
171 .pre_emphasis_hbr_rbr = &edp_pre_emp_hbr_rbr,
172 .pre_emphasis_hbr3_hbr2 = &edp_pre_emp_hbr2_hbr3,
175 static int qcom_edp_phy_init(struct phy *phy)
177 struct qcom_edp *edp = phy_get_drvdata(phy);
178 const struct qcom_edp_cfg *cfg = edp->cfg;
182 ret = regulator_bulk_enable(ARRAY_SIZE(edp->supplies), edp->supplies);
186 ret = clk_bulk_prepare_enable(ARRAY_SIZE(edp->clks), edp->clks);
188 goto out_disable_supplies;
190 writel(DP_PHY_PD_CTL_PWRDN | DP_PHY_PD_CTL_AUX_PWRDN |
191 DP_PHY_PD_CTL_PLL_PWRDN | DP_PHY_PD_CTL_DP_CLAMP_EN,
192 edp->edp + DP_PHY_PD_CTL);
194 /* Turn on BIAS current for PHY/PLL */
195 writel(0x17, edp->pll + QSERDES_V4_COM_BIAS_EN_CLKBUFLR_EN);
197 writel(DP_PHY_PD_CTL_PSR_PWRDN, edp->edp + DP_PHY_PD_CTL);
200 writel(DP_PHY_PD_CTL_PWRDN | DP_PHY_PD_CTL_AUX_PWRDN |
201 DP_PHY_PD_CTL_LANE_0_1_PWRDN | DP_PHY_PD_CTL_LANE_2_3_PWRDN |
202 DP_PHY_PD_CTL_PLL_PWRDN | DP_PHY_PD_CTL_DP_CLAMP_EN,
203 edp->edp + DP_PHY_PD_CTL);
205 if (cfg && cfg->is_dp)
210 writel(0xfc, edp->edp + DP_PHY_MODE);
212 writel(0x00, edp->edp + DP_PHY_AUX_CFG0);
213 writel(0x13, edp->edp + DP_PHY_AUX_CFG1);
214 writel(0x24, edp->edp + DP_PHY_AUX_CFG2);
215 writel(0x00, edp->edp + DP_PHY_AUX_CFG3);
216 writel(0x0a, edp->edp + DP_PHY_AUX_CFG4);
217 writel(0x26, edp->edp + DP_PHY_AUX_CFG5);
218 writel(0x0a, edp->edp + DP_PHY_AUX_CFG6);
219 writel(0x03, edp->edp + DP_PHY_AUX_CFG7);
220 writel(cfg8, edp->edp + DP_PHY_AUX_CFG8);
221 writel(0x03, edp->edp + DP_PHY_AUX_CFG9);
223 writel(PHY_AUX_STOP_ERR_MASK | PHY_AUX_DEC_ERR_MASK |
224 PHY_AUX_SYNC_ERR_MASK | PHY_AUX_ALIGN_ERR_MASK |
225 PHY_AUX_REQ_ERR_MASK, edp->edp + DP_PHY_AUX_INTERRUPT_MASK);
231 out_disable_supplies:
232 regulator_bulk_disable(ARRAY_SIZE(edp->supplies), edp->supplies);
237 static int qcom_edp_set_voltages(struct qcom_edp *edp, const struct phy_configure_opts_dp *dp_opts)
239 const struct qcom_edp_cfg *cfg = edp->cfg;
240 unsigned int v_level = 0;
241 unsigned int p_level = 0;
250 for (i = 0; i < dp_opts->lanes; i++) {
251 v_level = max(v_level, dp_opts->voltage[i]);
252 p_level = max(p_level, dp_opts->pre[i]);
255 if (dp_opts->link_rate <= 2700) {
256 swing = (*cfg->swing_hbr_rbr)[v_level][p_level];
257 emph = (*cfg->pre_emphasis_hbr_rbr)[v_level][p_level];
259 swing = (*cfg->swing_hbr3_hbr2)[v_level][p_level];
260 emph = (*cfg->pre_emphasis_hbr3_hbr2)[v_level][p_level];
263 if (swing == 0xff || emph == 0xff)
266 ldo_config = (cfg && cfg->is_dp) ? 0x1 : 0x0;
268 writel(ldo_config, edp->tx0 + TXn_LDO_CONFIG);
269 writel(swing, edp->tx0 + TXn_TX_DRV_LVL);
270 writel(emph, edp->tx0 + TXn_TX_EMP_POST1_LVL);
272 writel(ldo_config, edp->tx1 + TXn_LDO_CONFIG);
273 writel(swing, edp->tx1 + TXn_TX_DRV_LVL);
274 writel(emph, edp->tx1 + TXn_TX_EMP_POST1_LVL);
279 static int qcom_edp_phy_configure(struct phy *phy, union phy_configure_opts *opts)
281 const struct phy_configure_opts_dp *dp_opts = &opts->dp;
282 struct qcom_edp *edp = phy_get_drvdata(phy);
285 memcpy(&edp->dp_opts, dp_opts, sizeof(*dp_opts));
287 if (dp_opts->set_voltages)
288 ret = qcom_edp_set_voltages(edp, dp_opts);
293 static int qcom_edp_configure_ssc(const struct qcom_edp *edp)
295 const struct phy_configure_opts_dp *dp_opts = &edp->dp_opts;
299 switch (dp_opts->link_rate) {
313 /* Other link rates aren't supported */
317 writel(0x01, edp->pll + QSERDES_V4_COM_SSC_EN_CENTER);
318 writel(0x00, edp->pll + QSERDES_V4_COM_SSC_ADJ_PER1);
319 writel(0x36, edp->pll + QSERDES_V4_COM_SSC_PER1);
320 writel(0x01, edp->pll + QSERDES_V4_COM_SSC_PER2);
321 writel(step1, edp->pll + QSERDES_V4_COM_SSC_STEP_SIZE1_MODE0);
322 writel(step2, edp->pll + QSERDES_V4_COM_SSC_STEP_SIZE2_MODE0);
327 static int qcom_edp_configure_pll(const struct qcom_edp *edp)
329 const struct phy_configure_opts_dp *dp_opts = &edp->dp_opts;
330 u32 div_frac_start2_mode0;
331 u32 div_frac_start3_mode0;
337 switch (dp_opts->link_rate) {
340 dec_start_mode0 = 0x69;
341 div_frac_start2_mode0 = 0x80;
342 div_frac_start3_mode0 = 0x07;
343 lock_cmp1_mode0 = 0x6f;
344 lock_cmp2_mode0 = 0x08;
349 dec_start_mode0 = 0x69;
350 div_frac_start2_mode0 = 0x80;
351 div_frac_start3_mode0 = 0x07;
352 lock_cmp1_mode0 = 0x0f;
353 lock_cmp2_mode0 = 0x0e;
358 dec_start_mode0 = 0x8c;
359 div_frac_start2_mode0 = 0x00;
360 div_frac_start3_mode0 = 0x0a;
361 lock_cmp1_mode0 = 0x1f;
362 lock_cmp2_mode0 = 0x1c;
367 dec_start_mode0 = 0x69;
368 div_frac_start2_mode0 = 0x80;
369 div_frac_start3_mode0 = 0x07;
370 lock_cmp1_mode0 = 0x2f;
371 lock_cmp2_mode0 = 0x2a;
375 /* Other link rates aren't supported */
379 writel(0x01, edp->pll + QSERDES_V4_COM_SVS_MODE_CLK_SEL);
380 writel(0x0b, edp->pll + QSERDES_V4_COM_SYSCLK_EN_SEL);
381 writel(0x02, edp->pll + QSERDES_V4_COM_SYS_CLK_CTRL);
382 writel(0x0c, edp->pll + QSERDES_V4_COM_CLK_ENABLE1);
383 writel(0x06, edp->pll + QSERDES_V4_COM_SYSCLK_BUF_ENABLE);
384 writel(0x30, edp->pll + QSERDES_V4_COM_CLK_SELECT);
385 writel(hsclk_sel, edp->pll + QSERDES_V4_COM_HSCLK_SEL);
386 writel(0x0f, edp->pll + QSERDES_V4_COM_PLL_IVCO);
387 writel(0x08, edp->pll + QSERDES_V4_COM_LOCK_CMP_EN);
388 writel(0x36, edp->pll + QSERDES_V4_COM_PLL_CCTRL_MODE0);
389 writel(0x16, edp->pll + QSERDES_V4_COM_PLL_RCTRL_MODE0);
390 writel(0x06, edp->pll + QSERDES_V4_COM_CP_CTRL_MODE0);
391 writel(dec_start_mode0, edp->pll + QSERDES_V4_COM_DEC_START_MODE0);
392 writel(0x00, edp->pll + QSERDES_V4_COM_DIV_FRAC_START1_MODE0);
393 writel(div_frac_start2_mode0, edp->pll + QSERDES_V4_COM_DIV_FRAC_START2_MODE0);
394 writel(div_frac_start3_mode0, edp->pll + QSERDES_V4_COM_DIV_FRAC_START3_MODE0);
395 writel(0x02, edp->pll + QSERDES_V4_COM_CMN_CONFIG);
396 writel(0x3f, edp->pll + QSERDES_V4_COM_INTEGLOOP_GAIN0_MODE0);
397 writel(0x00, edp->pll + QSERDES_V4_COM_INTEGLOOP_GAIN1_MODE0);
398 writel(0x00, edp->pll + QSERDES_V4_COM_VCO_TUNE_MAP);
399 writel(lock_cmp1_mode0, edp->pll + QSERDES_V4_COM_LOCK_CMP1_MODE0);
400 writel(lock_cmp2_mode0, edp->pll + QSERDES_V4_COM_LOCK_CMP2_MODE0);
402 writel(0x0a, edp->pll + QSERDES_V4_COM_BG_TIMER);
403 writel(0x14, edp->pll + QSERDES_V4_COM_CORECLK_DIV_MODE0);
404 writel(0x00, edp->pll + QSERDES_V4_COM_VCO_TUNE_CTRL);
405 writel(0x17, edp->pll + QSERDES_V4_COM_BIAS_EN_CLKBUFLR_EN);
406 writel(0x0f, edp->pll + QSERDES_V4_COM_CORE_CLK_EN);
407 writel(0xa0, edp->pll + QSERDES_V4_COM_VCO_TUNE1_MODE0);
408 writel(0x03, edp->pll + QSERDES_V4_COM_VCO_TUNE2_MODE0);
413 static int qcom_edp_set_vco_div(const struct qcom_edp *edp, unsigned long *pixel_freq)
415 const struct phy_configure_opts_dp *dp_opts = &edp->dp_opts;
418 switch (dp_opts->link_rate) {
421 *pixel_freq = 1620000000UL / 2;
426 *pixel_freq = 2700000000UL / 2;
431 *pixel_freq = 5400000000UL / 4;
436 *pixel_freq = 8100000000UL / 6;
440 /* Other link rates aren't supported */
444 writel(vco_div, edp->edp + DP_PHY_VCO_DIV);
449 static int qcom_edp_phy_power_on(struct phy *phy)
451 const struct qcom_edp *edp = phy_get_drvdata(phy);
452 const struct qcom_edp_cfg *cfg = edp->cfg;
453 u32 bias0_en, drvr0_en, bias1_en, drvr1_en;
454 unsigned long pixel_freq;
461 writel(DP_PHY_PD_CTL_PWRDN | DP_PHY_PD_CTL_AUX_PWRDN |
462 DP_PHY_PD_CTL_LANE_0_1_PWRDN | DP_PHY_PD_CTL_LANE_2_3_PWRDN |
463 DP_PHY_PD_CTL_PLL_PWRDN | DP_PHY_PD_CTL_DP_CLAMP_EN,
464 edp->edp + DP_PHY_PD_CTL);
465 writel(0xfc, edp->edp + DP_PHY_MODE);
467 timeout = readl_poll_timeout(edp->pll + QSERDES_V4_COM_CMN_STATUS,
468 val, val & BIT(7), 5, 200);
473 ldo_config = (cfg && cfg->is_dp) ? 0x1 : 0x0;
475 writel(ldo_config, edp->tx0 + TXn_LDO_CONFIG);
476 writel(ldo_config, edp->tx1 + TXn_LDO_CONFIG);
477 writel(0x00, edp->tx0 + TXn_LANE_MODE_1);
478 writel(0x00, edp->tx1 + TXn_LANE_MODE_1);
480 if (edp->dp_opts.ssc) {
481 ret = qcom_edp_configure_ssc(edp);
486 ret = qcom_edp_configure_pll(edp);
490 /* TX Lane configuration */
491 writel(0x05, edp->edp + DP_PHY_TX0_TX1_LANE_CTL);
492 writel(0x05, edp->edp + DP_PHY_TX2_TX3_LANE_CTL);
494 /* TX-0 register configuration */
495 writel(0x03, edp->tx0 + TXn_TRANSCEIVER_BIAS_EN);
496 writel(0x0f, edp->tx0 + TXn_CLKBUF_ENABLE);
497 writel(0x03, edp->tx0 + TXn_RESET_TSYNC_EN);
498 writel(0x01, edp->tx0 + TXn_TRAN_DRVR_EMP_EN);
499 writel(0x04, edp->tx0 + TXn_TX_BAND);
501 /* TX-1 register configuration */
502 writel(0x03, edp->tx1 + TXn_TRANSCEIVER_BIAS_EN);
503 writel(0x0f, edp->tx1 + TXn_CLKBUF_ENABLE);
504 writel(0x03, edp->tx1 + TXn_RESET_TSYNC_EN);
505 writel(0x01, edp->tx1 + TXn_TRAN_DRVR_EMP_EN);
506 writel(0x04, edp->tx1 + TXn_TX_BAND);
508 ret = qcom_edp_set_vco_div(edp, &pixel_freq);
512 writel(0x01, edp->edp + DP_PHY_CFG);
513 writel(0x05, edp->edp + DP_PHY_CFG);
514 writel(0x01, edp->edp + DP_PHY_CFG);
515 writel(0x09, edp->edp + DP_PHY_CFG);
517 writel(0x20, edp->pll + QSERDES_V4_COM_RESETSM_CNTRL);
519 timeout = readl_poll_timeout(edp->pll + QSERDES_V4_COM_C_READY_STATUS,
520 val, val & BIT(0), 500, 10000);
524 writel(0x19, edp->edp + DP_PHY_CFG);
525 writel(0x1f, edp->tx0 + TXn_HIGHZ_DRVR_EN);
526 writel(0x04, edp->tx0 + TXn_HIGHZ_DRVR_EN);
527 writel(0x00, edp->tx0 + TXn_TX_POL_INV);
528 writel(0x1f, edp->tx1 + TXn_HIGHZ_DRVR_EN);
529 writel(0x04, edp->tx1 + TXn_HIGHZ_DRVR_EN);
530 writel(0x00, edp->tx1 + TXn_TX_POL_INV);
531 writel(0x10, edp->tx0 + TXn_TX_DRV_LVL_OFFSET);
532 writel(0x10, edp->tx1 + TXn_TX_DRV_LVL_OFFSET);
533 writel(0x11, edp->tx0 + TXn_RES_CODE_LANE_OFFSET_TX0);
534 writel(0x11, edp->tx0 + TXn_RES_CODE_LANE_OFFSET_TX1);
535 writel(0x11, edp->tx1 + TXn_RES_CODE_LANE_OFFSET_TX0);
536 writel(0x11, edp->tx1 + TXn_RES_CODE_LANE_OFFSET_TX1);
538 writel(0x10, edp->tx0 + TXn_TX_EMP_POST1_LVL);
539 writel(0x10, edp->tx1 + TXn_TX_EMP_POST1_LVL);
540 writel(0x1f, edp->tx0 + TXn_TX_DRV_LVL);
541 writel(0x1f, edp->tx1 + TXn_TX_DRV_LVL);
543 if (edp->dp_opts.lanes == 1) {
549 } else if (edp->dp_opts.lanes == 2) {
563 writel(drvr0_en, edp->tx0 + TXn_HIGHZ_DRVR_EN);
564 writel(bias0_en, edp->tx0 + TXn_TRANSCEIVER_BIAS_EN);
565 writel(drvr1_en, edp->tx1 + TXn_HIGHZ_DRVR_EN);
566 writel(bias1_en, edp->tx1 + TXn_TRANSCEIVER_BIAS_EN);
567 writel(cfg1, edp->edp + DP_PHY_CFG_1);
569 writel(0x18, edp->edp + DP_PHY_CFG);
570 usleep_range(100, 1000);
572 writel(0x19, edp->edp + DP_PHY_CFG);
574 ret = readl_poll_timeout(edp->edp + DP_PHY_STATUS,
575 val, val & BIT(1), 500, 10000);
579 clk_set_rate(edp->dp_link_hw.clk, edp->dp_opts.link_rate * 100000);
580 clk_set_rate(edp->dp_pixel_hw.clk, pixel_freq);
585 static int qcom_edp_phy_power_off(struct phy *phy)
587 const struct qcom_edp *edp = phy_get_drvdata(phy);
589 writel(DP_PHY_PD_CTL_PSR_PWRDN, edp->edp + DP_PHY_PD_CTL);
594 static int qcom_edp_phy_exit(struct phy *phy)
596 struct qcom_edp *edp = phy_get_drvdata(phy);
598 clk_bulk_disable_unprepare(ARRAY_SIZE(edp->clks), edp->clks);
599 regulator_bulk_disable(ARRAY_SIZE(edp->supplies), edp->supplies);
604 static const struct phy_ops qcom_edp_ops = {
605 .init = qcom_edp_phy_init,
606 .configure = qcom_edp_phy_configure,
607 .power_on = qcom_edp_phy_power_on,
608 .power_off = qcom_edp_phy_power_off,
609 .exit = qcom_edp_phy_exit,
610 .owner = THIS_MODULE,
614 * Embedded Display Port PLL driver block diagram for branch clocks
616 * +------------------------------+
619 * | +-------------------+ |
620 * | | (EDP PLL/VCO) | |
621 * | +---------+---------+ |
623 * | +----------+-----------+ |
624 * | | hsclk_divsel_clk_src | |
625 * | +----------+-----------+ |
626 * +------------------------------+
628 * +---------<---------v------------>----------+
630 * +--------v----------------+ |
631 * | edp_phy_pll_link_clk | |
633 * +--------+----------------+ |
637 * Input to DISPCC block |
638 * for link clk, crypto clk |
639 * and interface clock |
642 * +--------<------------+-----------------+---<---+
644 * +----v---------+ +--------v-----+ +--------v------+
645 * | vco_divided | | vco_divided | | vco_divided |
646 * | _clk_src | | _clk_src | | _clk_src |
648 * |divsel_six | | divsel_two | | divsel_four |
649 * +-------+------+ +-----+--------+ +--------+------+
651 * v---->----------v-------------<------v
653 * +----------+-----------------+
654 * | edp_phy_pll_vco_div_clk |
655 * +---------+------------------+
658 * Input to DISPCC block
659 * for EDP pixel clock
662 static int qcom_edp_dp_pixel_clk_determine_rate(struct clk_hw *hw,
663 struct clk_rate_request *req)
666 case 1620000000UL / 2:
667 case 2700000000UL / 2:
668 /* 5.4 and 8.1 GHz are same link rate as 2.7GHz, i.e. div 4 and div 6 */
677 qcom_edp_dp_pixel_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
679 const struct qcom_edp *edp = container_of(hw, struct qcom_edp, dp_pixel_hw);
680 const struct phy_configure_opts_dp *dp_opts = &edp->dp_opts;
682 switch (dp_opts->link_rate) {
684 return 1620000000UL / 2;
686 return 2700000000UL / 2;
688 return 5400000000UL / 4;
690 return 8100000000UL / 6;
696 static const struct clk_ops qcom_edp_dp_pixel_clk_ops = {
697 .determine_rate = qcom_edp_dp_pixel_clk_determine_rate,
698 .recalc_rate = qcom_edp_dp_pixel_clk_recalc_rate,
701 static int qcom_edp_dp_link_clk_determine_rate(struct clk_hw *hw,
702 struct clk_rate_request *req)
717 qcom_edp_dp_link_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
719 const struct qcom_edp *edp = container_of(hw, struct qcom_edp, dp_link_hw);
720 const struct phy_configure_opts_dp *dp_opts = &edp->dp_opts;
722 switch (dp_opts->link_rate) {
727 return dp_opts->link_rate * 100000;
734 static const struct clk_ops qcom_edp_dp_link_clk_ops = {
735 .determine_rate = qcom_edp_dp_link_clk_determine_rate,
736 .recalc_rate = qcom_edp_dp_link_clk_recalc_rate,
739 static int qcom_edp_clks_register(struct qcom_edp *edp, struct device_node *np)
741 struct clk_hw_onecell_data *data;
742 struct clk_init_data init = { };
746 data = devm_kzalloc(edp->dev, struct_size(data, hws, 2), GFP_KERNEL);
750 snprintf(name, sizeof(name), "%s::link_clk", dev_name(edp->dev));
751 init.ops = &qcom_edp_dp_link_clk_ops;
753 edp->dp_link_hw.init = &init;
754 ret = devm_clk_hw_register(edp->dev, &edp->dp_link_hw);
758 snprintf(name, sizeof(name), "%s::vco_div_clk", dev_name(edp->dev));
759 init.ops = &qcom_edp_dp_pixel_clk_ops;
761 edp->dp_pixel_hw.init = &init;
762 ret = devm_clk_hw_register(edp->dev, &edp->dp_pixel_hw);
766 data->hws[0] = &edp->dp_link_hw;
767 data->hws[1] = &edp->dp_pixel_hw;
770 return devm_of_clk_add_hw_provider(edp->dev, of_clk_hw_onecell_get, data);
773 static int qcom_edp_phy_probe(struct platform_device *pdev)
775 struct phy_provider *phy_provider;
776 struct device *dev = &pdev->dev;
777 struct qcom_edp *edp;
780 edp = devm_kzalloc(dev, sizeof(*edp), GFP_KERNEL);
785 edp->cfg = of_device_get_match_data(&pdev->dev);
787 edp->edp = devm_platform_ioremap_resource(pdev, 0);
788 if (IS_ERR(edp->edp))
789 return PTR_ERR(edp->edp);
791 edp->tx0 = devm_platform_ioremap_resource(pdev, 1);
792 if (IS_ERR(edp->tx0))
793 return PTR_ERR(edp->tx0);
795 edp->tx1 = devm_platform_ioremap_resource(pdev, 2);
796 if (IS_ERR(edp->tx1))
797 return PTR_ERR(edp->tx1);
799 edp->pll = devm_platform_ioremap_resource(pdev, 3);
800 if (IS_ERR(edp->pll))
801 return PTR_ERR(edp->pll);
803 edp->clks[0].id = "aux";
804 edp->clks[1].id = "cfg_ahb";
805 ret = devm_clk_bulk_get(dev, ARRAY_SIZE(edp->clks), edp->clks);
809 edp->supplies[0].supply = "vdda-phy";
810 edp->supplies[1].supply = "vdda-pll";
811 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(edp->supplies), edp->supplies);
815 ret = regulator_set_load(edp->supplies[0].consumer, 21800); /* 1.2 V vdda-phy */
817 dev_err(dev, "failed to set load at %s\n", edp->supplies[0].supply);
821 ret = regulator_set_load(edp->supplies[1].consumer, 36000); /* 0.9 V vdda-pll */
823 dev_err(dev, "failed to set load at %s\n", edp->supplies[1].supply);
827 ret = qcom_edp_clks_register(edp, pdev->dev.of_node);
831 edp->phy = devm_phy_create(dev, pdev->dev.of_node, &qcom_edp_ops);
832 if (IS_ERR(edp->phy)) {
833 dev_err(dev, "failed to register phy\n");
834 return PTR_ERR(edp->phy);
837 phy_set_drvdata(edp->phy, edp);
839 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
840 return PTR_ERR_OR_ZERO(phy_provider);
843 static const struct of_device_id qcom_edp_phy_match_table[] = {
844 { .compatible = "qcom,sc7280-edp-phy" },
845 { .compatible = "qcom,sc8180x-edp-phy" },
846 { .compatible = "qcom,sc8280xp-dp-phy", .data = &dp_phy_cfg },
847 { .compatible = "qcom,sc8280xp-edp-phy", .data = &edp_phy_cfg },
850 MODULE_DEVICE_TABLE(of, qcom_edp_phy_match_table);
852 static struct platform_driver qcom_edp_phy_driver = {
853 .probe = qcom_edp_phy_probe,
855 .name = "qcom-edp-phy",
856 .of_match_table = qcom_edp_phy_match_table,
860 module_platform_driver(qcom_edp_phy_driver);
863 MODULE_DESCRIPTION("Qualcomm eDP QMP PHY driver");
864 MODULE_LICENSE("GPL v2");