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/phy/phy.h>
17 #include <linux/platform_device.h>
18 #include <linux/regulator/consumer.h>
19 #include <linux/reset.h>
20 #include <linux/slab.h>
22 #include <dt-bindings/phy/phy.h>
24 #include "phy-qcom-qmp.h"
26 /* EDP_PHY registers */
27 #define DP_PHY_CFG 0x0010
28 #define DP_PHY_CFG_1 0x0014
29 #define DP_PHY_PD_CTL 0x001c
30 #define DP_PHY_MODE 0x0020
32 #define DP_PHY_AUX_CFG0 0x0024
33 #define DP_PHY_AUX_CFG1 0x0028
34 #define DP_PHY_AUX_CFG2 0x002C
35 #define DP_PHY_AUX_CFG3 0x0030
36 #define DP_PHY_AUX_CFG4 0x0034
37 #define DP_PHY_AUX_CFG5 0x0038
38 #define DP_PHY_AUX_CFG6 0x003C
39 #define DP_PHY_AUX_CFG7 0x0040
40 #define DP_PHY_AUX_CFG8 0x0044
41 #define DP_PHY_AUX_CFG9 0x0048
43 #define DP_PHY_AUX_INTERRUPT_MASK 0x0058
45 #define DP_PHY_VCO_DIV 0x0074
46 #define DP_PHY_TX0_TX1_LANE_CTL 0x007c
47 #define DP_PHY_TX2_TX3_LANE_CTL 0x00a0
49 #define DP_PHY_STATUS 0x00e0
51 /* LANE_TXn registers */
52 #define TXn_CLKBUF_ENABLE 0x0000
53 #define TXn_TX_EMP_POST1_LVL 0x0004
55 #define TXn_TX_DRV_LVL 0x0014
56 #define TXn_TX_DRV_LVL_OFFSET 0x0018
57 #define TXn_RESET_TSYNC_EN 0x001c
58 #define TXn_LDO_CONFIG 0x0084
59 #define TXn_TX_BAND 0x0028
61 #define TXn_RES_CODE_LANE_OFFSET_TX0 0x0044
62 #define TXn_RES_CODE_LANE_OFFSET_TX1 0x0048
64 #define TXn_TRANSCEIVER_BIAS_EN 0x0054
65 #define TXn_HIGHZ_DRVR_EN 0x0058
66 #define TXn_TX_POL_INV 0x005c
67 #define TXn_LANE_MODE_1 0x0064
69 #define TXn_TRAN_DRVR_EMP_EN 0x0078
74 /* DP PHY swing and pre_emphasis tables */
75 const u8 (*swing_hbr_rbr)[4][4];
76 const u8 (*swing_hbr3_hbr2)[4][4];
77 const u8 (*pre_emphasis_hbr_rbr)[4][4];
78 const u8 (*pre_emphasis_hbr3_hbr2)[4][4];
83 const struct qcom_edp_cfg *cfg;
92 struct clk_hw dp_link_hw;
93 struct clk_hw dp_pixel_hw;
95 struct phy_configure_opts_dp dp_opts;
97 struct clk_bulk_data clks[2];
98 struct regulator_bulk_data supplies[2];
101 static const u8 dp_swing_hbr_rbr[4][4] = {
102 { 0x08, 0x0f, 0x16, 0x1f },
103 { 0x11, 0x1e, 0x1f, 0xff },
104 { 0x16, 0x1f, 0xff, 0xff },
105 { 0x1f, 0xff, 0xff, 0xff }
108 static const u8 dp_pre_emp_hbr_rbr[4][4] = {
109 { 0x00, 0x0d, 0x14, 0x1a },
110 { 0x00, 0x0e, 0x15, 0xff },
111 { 0x00, 0x0e, 0xff, 0xff },
112 { 0x03, 0xff, 0xff, 0xff }
115 static const u8 dp_swing_hbr2_hbr3[4][4] = {
116 { 0x02, 0x12, 0x16, 0x1a },
117 { 0x09, 0x19, 0x1f, 0xff },
118 { 0x10, 0x1f, 0xff, 0xff },
119 { 0x1f, 0xff, 0xff, 0xff }
122 static const u8 dp_pre_emp_hbr2_hbr3[4][4] = {
123 { 0x00, 0x0c, 0x15, 0x1b },
124 { 0x02, 0x0e, 0x16, 0xff },
125 { 0x02, 0x11, 0xff, 0xff },
126 { 0x04, 0xff, 0xff, 0xff }
129 static const struct qcom_edp_cfg dp_phy_cfg = {
131 .swing_hbr_rbr = &dp_swing_hbr_rbr,
132 .swing_hbr3_hbr2 = &dp_swing_hbr2_hbr3,
133 .pre_emphasis_hbr_rbr = &dp_pre_emp_hbr_rbr,
134 .pre_emphasis_hbr3_hbr2 = &dp_pre_emp_hbr2_hbr3,
137 static const u8 edp_swing_hbr_rbr[4][4] = {
138 { 0x07, 0x0f, 0x16, 0x1f },
139 { 0x0d, 0x16, 0x1e, 0xff },
140 { 0x11, 0x1b, 0xff, 0xff },
141 { 0x16, 0xff, 0xff, 0xff }
144 static const u8 edp_pre_emp_hbr_rbr[4][4] = {
145 { 0x05, 0x12, 0x17, 0x1d },
146 { 0x05, 0x11, 0x18, 0xff },
147 { 0x06, 0x11, 0xff, 0xff },
148 { 0x00, 0xff, 0xff, 0xff }
151 static const u8 edp_swing_hbr2_hbr3[4][4] = {
152 { 0x0b, 0x11, 0x17, 0x1c },
153 { 0x10, 0x19, 0x1f, 0xff },
154 { 0x19, 0x1f, 0xff, 0xff },
155 { 0x1f, 0xff, 0xff, 0xff }
158 static const u8 edp_pre_emp_hbr2_hbr3[4][4] = {
159 { 0x08, 0x11, 0x17, 0x1b },
160 { 0x00, 0x0c, 0x13, 0xff },
161 { 0x05, 0x10, 0xff, 0xff },
162 { 0x00, 0xff, 0xff, 0xff }
165 static const struct qcom_edp_cfg edp_phy_cfg = {
167 .swing_hbr_rbr = &edp_swing_hbr_rbr,
168 .swing_hbr3_hbr2 = &edp_swing_hbr2_hbr3,
169 .pre_emphasis_hbr_rbr = &edp_pre_emp_hbr_rbr,
170 .pre_emphasis_hbr3_hbr2 = &edp_pre_emp_hbr2_hbr3,
173 static int qcom_edp_phy_init(struct phy *phy)
175 struct qcom_edp *edp = phy_get_drvdata(phy);
176 const struct qcom_edp_cfg *cfg = edp->cfg;
180 ret = regulator_bulk_enable(ARRAY_SIZE(edp->supplies), edp->supplies);
184 ret = clk_bulk_prepare_enable(ARRAY_SIZE(edp->clks), edp->clks);
186 goto out_disable_supplies;
188 writel(DP_PHY_PD_CTL_PWRDN | DP_PHY_PD_CTL_AUX_PWRDN |
189 DP_PHY_PD_CTL_PLL_PWRDN | DP_PHY_PD_CTL_DP_CLAMP_EN,
190 edp->edp + DP_PHY_PD_CTL);
192 /* Turn on BIAS current for PHY/PLL */
193 writel(0x17, edp->pll + QSERDES_V4_COM_BIAS_EN_CLKBUFLR_EN);
195 writel(DP_PHY_PD_CTL_PSR_PWRDN, edp->edp + DP_PHY_PD_CTL);
198 writel(DP_PHY_PD_CTL_PWRDN | DP_PHY_PD_CTL_AUX_PWRDN |
199 DP_PHY_PD_CTL_LANE_0_1_PWRDN | DP_PHY_PD_CTL_LANE_2_3_PWRDN |
200 DP_PHY_PD_CTL_PLL_PWRDN | DP_PHY_PD_CTL_DP_CLAMP_EN,
201 edp->edp + DP_PHY_PD_CTL);
203 if (cfg && cfg->is_dp)
208 writel(0xfc, edp->edp + DP_PHY_MODE);
210 writel(0x00, edp->edp + DP_PHY_AUX_CFG0);
211 writel(0x13, edp->edp + DP_PHY_AUX_CFG1);
212 writel(0x24, edp->edp + DP_PHY_AUX_CFG2);
213 writel(0x00, edp->edp + DP_PHY_AUX_CFG3);
214 writel(0x0a, edp->edp + DP_PHY_AUX_CFG4);
215 writel(0x26, edp->edp + DP_PHY_AUX_CFG5);
216 writel(0x0a, edp->edp + DP_PHY_AUX_CFG6);
217 writel(0x03, edp->edp + DP_PHY_AUX_CFG7);
218 writel(cfg8, edp->edp + DP_PHY_AUX_CFG8);
219 writel(0x03, edp->edp + DP_PHY_AUX_CFG9);
221 writel(PHY_AUX_STOP_ERR_MASK | PHY_AUX_DEC_ERR_MASK |
222 PHY_AUX_SYNC_ERR_MASK | PHY_AUX_ALIGN_ERR_MASK |
223 PHY_AUX_REQ_ERR_MASK, edp->edp + DP_PHY_AUX_INTERRUPT_MASK);
229 out_disable_supplies:
230 regulator_bulk_disable(ARRAY_SIZE(edp->supplies), edp->supplies);
235 static int qcom_edp_set_voltages(struct qcom_edp *edp, const struct phy_configure_opts_dp *dp_opts)
237 const struct qcom_edp_cfg *cfg = edp->cfg;
238 unsigned int v_level = 0;
239 unsigned int p_level = 0;
248 for (i = 0; i < dp_opts->lanes; i++) {
249 v_level = max(v_level, dp_opts->voltage[i]);
250 p_level = max(p_level, dp_opts->pre[i]);
253 if (dp_opts->link_rate <= 2700) {
254 swing = (*cfg->swing_hbr_rbr)[v_level][p_level];
255 emph = (*cfg->pre_emphasis_hbr_rbr)[v_level][p_level];
257 swing = (*cfg->swing_hbr3_hbr2)[v_level][p_level];
258 emph = (*cfg->pre_emphasis_hbr3_hbr2)[v_level][p_level];
261 if (swing == 0xff || emph == 0xff)
264 ldo_config = (cfg && cfg->is_dp) ? 0x1 : 0x0;
266 writel(ldo_config, edp->tx0 + TXn_LDO_CONFIG);
267 writel(swing, edp->tx0 + TXn_TX_DRV_LVL);
268 writel(emph, edp->tx0 + TXn_TX_EMP_POST1_LVL);
270 writel(ldo_config, edp->tx1 + TXn_LDO_CONFIG);
271 writel(swing, edp->tx1 + TXn_TX_DRV_LVL);
272 writel(emph, edp->tx1 + TXn_TX_EMP_POST1_LVL);
277 static int qcom_edp_phy_configure(struct phy *phy, union phy_configure_opts *opts)
279 const struct phy_configure_opts_dp *dp_opts = &opts->dp;
280 struct qcom_edp *edp = phy_get_drvdata(phy);
283 memcpy(&edp->dp_opts, dp_opts, sizeof(*dp_opts));
285 if (dp_opts->set_voltages)
286 ret = qcom_edp_set_voltages(edp, dp_opts);
291 static int qcom_edp_configure_ssc(const struct qcom_edp *edp)
293 const struct phy_configure_opts_dp *dp_opts = &edp->dp_opts;
297 switch (dp_opts->link_rate) {
311 /* Other link rates aren't supported */
315 writel(0x01, edp->pll + QSERDES_V4_COM_SSC_EN_CENTER);
316 writel(0x00, edp->pll + QSERDES_V4_COM_SSC_ADJ_PER1);
317 writel(0x36, edp->pll + QSERDES_V4_COM_SSC_PER1);
318 writel(0x01, edp->pll + QSERDES_V4_COM_SSC_PER2);
319 writel(step1, edp->pll + QSERDES_V4_COM_SSC_STEP_SIZE1_MODE0);
320 writel(step2, edp->pll + QSERDES_V4_COM_SSC_STEP_SIZE2_MODE0);
325 static int qcom_edp_configure_pll(const struct qcom_edp *edp)
327 const struct phy_configure_opts_dp *dp_opts = &edp->dp_opts;
328 u32 div_frac_start2_mode0;
329 u32 div_frac_start3_mode0;
335 switch (dp_opts->link_rate) {
338 dec_start_mode0 = 0x69;
339 div_frac_start2_mode0 = 0x80;
340 div_frac_start3_mode0 = 0x07;
341 lock_cmp1_mode0 = 0x6f;
342 lock_cmp2_mode0 = 0x08;
347 dec_start_mode0 = 0x69;
348 div_frac_start2_mode0 = 0x80;
349 div_frac_start3_mode0 = 0x07;
350 lock_cmp1_mode0 = 0x0f;
351 lock_cmp2_mode0 = 0x0e;
356 dec_start_mode0 = 0x8c;
357 div_frac_start2_mode0 = 0x00;
358 div_frac_start3_mode0 = 0x0a;
359 lock_cmp1_mode0 = 0x1f;
360 lock_cmp2_mode0 = 0x1c;
365 dec_start_mode0 = 0x69;
366 div_frac_start2_mode0 = 0x80;
367 div_frac_start3_mode0 = 0x07;
368 lock_cmp1_mode0 = 0x2f;
369 lock_cmp2_mode0 = 0x2a;
373 /* Other link rates aren't supported */
377 writel(0x01, edp->pll + QSERDES_V4_COM_SVS_MODE_CLK_SEL);
378 writel(0x0b, edp->pll + QSERDES_V4_COM_SYSCLK_EN_SEL);
379 writel(0x02, edp->pll + QSERDES_V4_COM_SYS_CLK_CTRL);
380 writel(0x0c, edp->pll + QSERDES_V4_COM_CLK_ENABLE1);
381 writel(0x06, edp->pll + QSERDES_V4_COM_SYSCLK_BUF_ENABLE);
382 writel(0x30, edp->pll + QSERDES_V4_COM_CLK_SELECT);
383 writel(hsclk_sel, edp->pll + QSERDES_V4_COM_HSCLK_SEL);
384 writel(0x0f, edp->pll + QSERDES_V4_COM_PLL_IVCO);
385 writel(0x08, edp->pll + QSERDES_V4_COM_LOCK_CMP_EN);
386 writel(0x36, edp->pll + QSERDES_V4_COM_PLL_CCTRL_MODE0);
387 writel(0x16, edp->pll + QSERDES_V4_COM_PLL_RCTRL_MODE0);
388 writel(0x06, edp->pll + QSERDES_V4_COM_CP_CTRL_MODE0);
389 writel(dec_start_mode0, edp->pll + QSERDES_V4_COM_DEC_START_MODE0);
390 writel(0x00, edp->pll + QSERDES_V4_COM_DIV_FRAC_START1_MODE0);
391 writel(div_frac_start2_mode0, edp->pll + QSERDES_V4_COM_DIV_FRAC_START2_MODE0);
392 writel(div_frac_start3_mode0, edp->pll + QSERDES_V4_COM_DIV_FRAC_START3_MODE0);
393 writel(0x02, edp->pll + QSERDES_V4_COM_CMN_CONFIG);
394 writel(0x3f, edp->pll + QSERDES_V4_COM_INTEGLOOP_GAIN0_MODE0);
395 writel(0x00, edp->pll + QSERDES_V4_COM_INTEGLOOP_GAIN1_MODE0);
396 writel(0x00, edp->pll + QSERDES_V4_COM_VCO_TUNE_MAP);
397 writel(lock_cmp1_mode0, edp->pll + QSERDES_V4_COM_LOCK_CMP1_MODE0);
398 writel(lock_cmp2_mode0, edp->pll + QSERDES_V4_COM_LOCK_CMP2_MODE0);
400 writel(0x0a, edp->pll + QSERDES_V4_COM_BG_TIMER);
401 writel(0x14, edp->pll + QSERDES_V4_COM_CORECLK_DIV_MODE0);
402 writel(0x00, edp->pll + QSERDES_V4_COM_VCO_TUNE_CTRL);
403 writel(0x17, edp->pll + QSERDES_V4_COM_BIAS_EN_CLKBUFLR_EN);
404 writel(0x0f, edp->pll + QSERDES_V4_COM_CORE_CLK_EN);
405 writel(0xa0, edp->pll + QSERDES_V4_COM_VCO_TUNE1_MODE0);
406 writel(0x03, edp->pll + QSERDES_V4_COM_VCO_TUNE2_MODE0);
411 static int qcom_edp_set_vco_div(const struct qcom_edp *edp, unsigned long *pixel_freq)
413 const struct phy_configure_opts_dp *dp_opts = &edp->dp_opts;
416 switch (dp_opts->link_rate) {
419 *pixel_freq = 1620000000UL / 2;
424 *pixel_freq = 2700000000UL / 2;
429 *pixel_freq = 5400000000UL / 4;
434 *pixel_freq = 8100000000UL / 6;
438 /* Other link rates aren't supported */
442 writel(vco_div, edp->edp + DP_PHY_VCO_DIV);
447 static int qcom_edp_phy_power_on(struct phy *phy)
449 const struct qcom_edp *edp = phy_get_drvdata(phy);
450 const struct qcom_edp_cfg *cfg = edp->cfg;
451 u32 bias0_en, drvr0_en, bias1_en, drvr1_en;
452 unsigned long pixel_freq;
459 writel(DP_PHY_PD_CTL_PWRDN | DP_PHY_PD_CTL_AUX_PWRDN |
460 DP_PHY_PD_CTL_LANE_0_1_PWRDN | DP_PHY_PD_CTL_LANE_2_3_PWRDN |
461 DP_PHY_PD_CTL_PLL_PWRDN | DP_PHY_PD_CTL_DP_CLAMP_EN,
462 edp->edp + DP_PHY_PD_CTL);
463 writel(0xfc, edp->edp + DP_PHY_MODE);
465 timeout = readl_poll_timeout(edp->pll + QSERDES_V4_COM_CMN_STATUS,
466 val, val & BIT(7), 5, 200);
471 ldo_config = (cfg && cfg->is_dp) ? 0x1 : 0x0;
473 writel(ldo_config, edp->tx0 + TXn_LDO_CONFIG);
474 writel(ldo_config, edp->tx1 + TXn_LDO_CONFIG);
475 writel(0x00, edp->tx0 + TXn_LANE_MODE_1);
476 writel(0x00, edp->tx1 + TXn_LANE_MODE_1);
478 if (edp->dp_opts.ssc) {
479 ret = qcom_edp_configure_ssc(edp);
484 ret = qcom_edp_configure_pll(edp);
488 /* TX Lane configuration */
489 writel(0x05, edp->edp + DP_PHY_TX0_TX1_LANE_CTL);
490 writel(0x05, edp->edp + DP_PHY_TX2_TX3_LANE_CTL);
492 /* TX-0 register configuration */
493 writel(0x03, edp->tx0 + TXn_TRANSCEIVER_BIAS_EN);
494 writel(0x0f, edp->tx0 + TXn_CLKBUF_ENABLE);
495 writel(0x03, edp->tx0 + TXn_RESET_TSYNC_EN);
496 writel(0x01, edp->tx0 + TXn_TRAN_DRVR_EMP_EN);
497 writel(0x04, edp->tx0 + TXn_TX_BAND);
499 /* TX-1 register configuration */
500 writel(0x03, edp->tx1 + TXn_TRANSCEIVER_BIAS_EN);
501 writel(0x0f, edp->tx1 + TXn_CLKBUF_ENABLE);
502 writel(0x03, edp->tx1 + TXn_RESET_TSYNC_EN);
503 writel(0x01, edp->tx1 + TXn_TRAN_DRVR_EMP_EN);
504 writel(0x04, edp->tx1 + TXn_TX_BAND);
506 ret = qcom_edp_set_vco_div(edp, &pixel_freq);
510 writel(0x01, edp->edp + DP_PHY_CFG);
511 writel(0x05, edp->edp + DP_PHY_CFG);
512 writel(0x01, edp->edp + DP_PHY_CFG);
513 writel(0x09, edp->edp + DP_PHY_CFG);
515 writel(0x20, edp->pll + QSERDES_V4_COM_RESETSM_CNTRL);
517 timeout = readl_poll_timeout(edp->pll + QSERDES_V4_COM_C_READY_STATUS,
518 val, val & BIT(0), 500, 10000);
522 writel(0x19, edp->edp + DP_PHY_CFG);
523 writel(0x1f, edp->tx0 + TXn_HIGHZ_DRVR_EN);
524 writel(0x04, edp->tx0 + TXn_HIGHZ_DRVR_EN);
525 writel(0x00, edp->tx0 + TXn_TX_POL_INV);
526 writel(0x1f, edp->tx1 + TXn_HIGHZ_DRVR_EN);
527 writel(0x04, edp->tx1 + TXn_HIGHZ_DRVR_EN);
528 writel(0x00, edp->tx1 + TXn_TX_POL_INV);
529 writel(0x10, edp->tx0 + TXn_TX_DRV_LVL_OFFSET);
530 writel(0x10, edp->tx1 + TXn_TX_DRV_LVL_OFFSET);
531 writel(0x11, edp->tx0 + TXn_RES_CODE_LANE_OFFSET_TX0);
532 writel(0x11, edp->tx0 + TXn_RES_CODE_LANE_OFFSET_TX1);
533 writel(0x11, edp->tx1 + TXn_RES_CODE_LANE_OFFSET_TX0);
534 writel(0x11, edp->tx1 + TXn_RES_CODE_LANE_OFFSET_TX1);
536 writel(0x10, edp->tx0 + TXn_TX_EMP_POST1_LVL);
537 writel(0x10, edp->tx1 + TXn_TX_EMP_POST1_LVL);
538 writel(0x1f, edp->tx0 + TXn_TX_DRV_LVL);
539 writel(0x1f, edp->tx1 + TXn_TX_DRV_LVL);
541 if (edp->dp_opts.lanes == 1) {
547 } else if (edp->dp_opts.lanes == 2) {
561 writel(drvr0_en, edp->tx0 + TXn_HIGHZ_DRVR_EN);
562 writel(bias0_en, edp->tx0 + TXn_TRANSCEIVER_BIAS_EN);
563 writel(drvr1_en, edp->tx1 + TXn_HIGHZ_DRVR_EN);
564 writel(bias1_en, edp->tx1 + TXn_TRANSCEIVER_BIAS_EN);
565 writel(cfg1, edp->edp + DP_PHY_CFG_1);
567 writel(0x18, edp->edp + DP_PHY_CFG);
568 usleep_range(100, 1000);
570 writel(0x19, edp->edp + DP_PHY_CFG);
572 ret = readl_poll_timeout(edp->edp + DP_PHY_STATUS,
573 val, val & BIT(1), 500, 10000);
577 clk_set_rate(edp->dp_link_hw.clk, edp->dp_opts.link_rate * 100000);
578 clk_set_rate(edp->dp_pixel_hw.clk, pixel_freq);
583 static int qcom_edp_phy_power_off(struct phy *phy)
585 const struct qcom_edp *edp = phy_get_drvdata(phy);
587 writel(DP_PHY_PD_CTL_PSR_PWRDN, edp->edp + DP_PHY_PD_CTL);
592 static int qcom_edp_phy_exit(struct phy *phy)
594 struct qcom_edp *edp = phy_get_drvdata(phy);
596 clk_bulk_disable_unprepare(ARRAY_SIZE(edp->clks), edp->clks);
597 regulator_bulk_disable(ARRAY_SIZE(edp->supplies), edp->supplies);
602 static const struct phy_ops qcom_edp_ops = {
603 .init = qcom_edp_phy_init,
604 .configure = qcom_edp_phy_configure,
605 .power_on = qcom_edp_phy_power_on,
606 .power_off = qcom_edp_phy_power_off,
607 .exit = qcom_edp_phy_exit,
608 .owner = THIS_MODULE,
612 * Embedded Display Port PLL driver block diagram for branch clocks
614 * +------------------------------+
617 * | +-------------------+ |
618 * | | (EDP PLL/VCO) | |
619 * | +---------+---------+ |
621 * | +----------+-----------+ |
622 * | | hsclk_divsel_clk_src | |
623 * | +----------+-----------+ |
624 * +------------------------------+
626 * +---------<---------v------------>----------+
628 * +--------v----------------+ |
629 * | edp_phy_pll_link_clk | |
631 * +--------+----------------+ |
635 * Input to DISPCC block |
636 * for link clk, crypto clk |
637 * and interface clock |
640 * +--------<------------+-----------------+---<---+
642 * +----v---------+ +--------v-----+ +--------v------+
643 * | vco_divided | | vco_divided | | vco_divided |
644 * | _clk_src | | _clk_src | | _clk_src |
646 * |divsel_six | | divsel_two | | divsel_four |
647 * +-------+------+ +-----+--------+ +--------+------+
649 * v---->----------v-------------<------v
651 * +----------+-----------------+
652 * | edp_phy_pll_vco_div_clk |
653 * +---------+------------------+
656 * Input to DISPCC block
657 * for EDP pixel clock
660 static int qcom_edp_dp_pixel_clk_determine_rate(struct clk_hw *hw,
661 struct clk_rate_request *req)
664 case 1620000000UL / 2:
665 case 2700000000UL / 2:
666 /* 5.4 and 8.1 GHz are same link rate as 2.7GHz, i.e. div 4 and div 6 */
675 qcom_edp_dp_pixel_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
677 const struct qcom_edp *edp = container_of(hw, struct qcom_edp, dp_pixel_hw);
678 const struct phy_configure_opts_dp *dp_opts = &edp->dp_opts;
680 switch (dp_opts->link_rate) {
682 return 1620000000UL / 2;
684 return 2700000000UL / 2;
686 return 5400000000UL / 4;
688 return 8100000000UL / 6;
694 static const struct clk_ops qcom_edp_dp_pixel_clk_ops = {
695 .determine_rate = qcom_edp_dp_pixel_clk_determine_rate,
696 .recalc_rate = qcom_edp_dp_pixel_clk_recalc_rate,
699 static int qcom_edp_dp_link_clk_determine_rate(struct clk_hw *hw,
700 struct clk_rate_request *req)
715 qcom_edp_dp_link_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
717 const struct qcom_edp *edp = container_of(hw, struct qcom_edp, dp_link_hw);
718 const struct phy_configure_opts_dp *dp_opts = &edp->dp_opts;
720 switch (dp_opts->link_rate) {
725 return dp_opts->link_rate * 100000;
732 static const struct clk_ops qcom_edp_dp_link_clk_ops = {
733 .determine_rate = qcom_edp_dp_link_clk_determine_rate,
734 .recalc_rate = qcom_edp_dp_link_clk_recalc_rate,
737 static int qcom_edp_clks_register(struct qcom_edp *edp, struct device_node *np)
739 struct clk_hw_onecell_data *data;
740 struct clk_init_data init = { };
744 data = devm_kzalloc(edp->dev, struct_size(data, hws, 2), GFP_KERNEL);
749 snprintf(name, sizeof(name), "%s::link_clk", dev_name(edp->dev));
750 init.ops = &qcom_edp_dp_link_clk_ops;
752 edp->dp_link_hw.init = &init;
753 ret = devm_clk_hw_register(edp->dev, &edp->dp_link_hw);
757 snprintf(name, sizeof(name), "%s::vco_div_clk", dev_name(edp->dev));
758 init.ops = &qcom_edp_dp_pixel_clk_ops;
760 edp->dp_pixel_hw.init = &init;
761 ret = devm_clk_hw_register(edp->dev, &edp->dp_pixel_hw);
765 data->hws[0] = &edp->dp_link_hw;
766 data->hws[1] = &edp->dp_pixel_hw;
768 return devm_of_clk_add_hw_provider(edp->dev, of_clk_hw_onecell_get, data);
771 static int qcom_edp_phy_probe(struct platform_device *pdev)
773 struct phy_provider *phy_provider;
774 struct device *dev = &pdev->dev;
775 struct qcom_edp *edp;
778 edp = devm_kzalloc(dev, sizeof(*edp), GFP_KERNEL);
783 edp->cfg = of_device_get_match_data(&pdev->dev);
785 edp->edp = devm_platform_ioremap_resource(pdev, 0);
786 if (IS_ERR(edp->edp))
787 return PTR_ERR(edp->edp);
789 edp->tx0 = devm_platform_ioremap_resource(pdev, 1);
790 if (IS_ERR(edp->tx0))
791 return PTR_ERR(edp->tx0);
793 edp->tx1 = devm_platform_ioremap_resource(pdev, 2);
794 if (IS_ERR(edp->tx1))
795 return PTR_ERR(edp->tx1);
797 edp->pll = devm_platform_ioremap_resource(pdev, 3);
798 if (IS_ERR(edp->pll))
799 return PTR_ERR(edp->pll);
801 edp->clks[0].id = "aux";
802 edp->clks[1].id = "cfg_ahb";
803 ret = devm_clk_bulk_get(dev, ARRAY_SIZE(edp->clks), edp->clks);
807 edp->supplies[0].supply = "vdda-phy";
808 edp->supplies[1].supply = "vdda-pll";
809 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(edp->supplies), edp->supplies);
813 ret = regulator_set_load(edp->supplies[0].consumer, 21800); /* 1.2 V vdda-phy */
815 dev_err(dev, "failed to set load at %s\n", edp->supplies[0].supply);
819 ret = regulator_set_load(edp->supplies[1].consumer, 36000); /* 0.9 V vdda-pll */
821 dev_err(dev, "failed to set load at %s\n", edp->supplies[1].supply);
825 ret = qcom_edp_clks_register(edp, pdev->dev.of_node);
829 edp->phy = devm_phy_create(dev, pdev->dev.of_node, &qcom_edp_ops);
830 if (IS_ERR(edp->phy)) {
831 dev_err(dev, "failed to register phy\n");
832 return PTR_ERR(edp->phy);
835 phy_set_drvdata(edp->phy, edp);
837 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
838 return PTR_ERR_OR_ZERO(phy_provider);
841 static const struct of_device_id qcom_edp_phy_match_table[] = {
842 { .compatible = "qcom,sc7280-edp-phy" },
843 { .compatible = "qcom,sc8180x-edp-phy" },
844 { .compatible = "qcom,sc8280xp-dp-phy", .data = &dp_phy_cfg },
845 { .compatible = "qcom,sc8280xp-edp-phy", .data = &edp_phy_cfg },
848 MODULE_DEVICE_TABLE(of, qcom_edp_phy_match_table);
850 static struct platform_driver qcom_edp_phy_driver = {
851 .probe = qcom_edp_phy_probe,
853 .name = "qcom-edp-phy",
854 .of_match_table = qcom_edp_phy_match_table,
858 module_platform_driver(qcom_edp_phy_driver);
861 MODULE_DESCRIPTION("Qualcomm eDP QMP PHY driver");
862 MODULE_LICENSE("GPL v2");