1 // SPDX-License-Identifier: GPL-2.0+
4 * Copyright 2022 Pengutronix, Lucas Stach <kernel@pengutronix.de>
7 #include <linux/bitfield.h>
8 #include <linux/bits.h>
10 #include <linux/clk-provider.h>
11 #include <linux/delay.h>
12 #include <linux/iopoll.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/pm_runtime.h>
17 #define PHY_REG(reg) (reg * 4)
19 #define REG01_PMS_P_MASK GENMASK(3, 0)
20 #define REG03_PMS_S_MASK GENMASK(7, 4)
21 #define REG12_CK_DIV_MASK GENMASK(5, 4)
23 #define REG13_TG_CODE_LOW_MASK GENMASK(7, 0)
25 #define REG14_TOL_MASK GENMASK(7, 4)
26 #define REG14_RP_CODE_MASK GENMASK(3, 1)
27 #define REG14_TG_CODE_HIGH_MASK GENMASK(0, 0)
29 #define REG21_SEL_TX_CK_INV BIT(7)
30 #define REG21_PMS_S_MASK GENMASK(3, 0)
32 * REG33 does not match the ref manual. According to Sandor Yu from NXP,
33 * "There is a doc issue on the i.MX8MP latest RM"
34 * REG33 is being used per guidance from Sandor
36 #define REG33_MODE_SET_DONE BIT(7)
37 #define REG33_FIX_DA BIT(1)
39 #define REG34_PHY_READY BIT(7)
40 #define REG34_PLL_LOCK BIT(6)
41 #define REG34_PHY_CLK_READY BIT(5)
44 #define MHZ (1000UL * 1000UL)
47 #define PHY_PLL_DIV_REGS_NUM 7
51 u8 pll_div_regs
[PHY_PLL_DIV_REGS_NUM
];
55 * The calculated_phy_pll_cfg only handles integer divider for PMS,
56 * meaning the last four entries will be fixed, but the first three will
57 * be calculated by the PMS calculator.
59 static struct phy_config calculated_phy_pll_cfg
= {
61 .pll_div_regs
= { 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00 },
64 /* The lookup table contains values for which the fractional divder is used */
65 static const struct phy_config phy_pll_cfg
[] = {
68 .pll_div_regs
= { 0xd1, 0x4b, 0xf1, 0x89, 0x88, 0x80, 0x40 },
71 .pll_div_regs
= { 0xd1, 0x50, 0xf1, 0x86, 0x85, 0x80, 0x40 },
74 .pll_div_regs
= { 0xd1, 0x50, 0xf1, 0x99, 0x02, 0x80, 0x40 },
77 .pll_div_regs
= { 0xd1, 0x54, 0xfc, 0xcc, 0x91, 0x80, 0x40 },
80 .pll_div_regs
= { 0xd1, 0x5a, 0xf2, 0x89, 0x88, 0x80, 0x40 },
83 .pll_div_regs
= { 0xd1, 0x5a, 0xf2, 0xfd, 0x0c, 0x80, 0x40 },
86 .pll_div_regs
= { 0xd1, 0x62, 0xf4, 0x95, 0x08, 0x80, 0x40 },
89 .pll_div_regs
= { 0xd1, 0x66, 0xf4, 0x82, 0x01, 0x88, 0x45 },
92 .pll_div_regs
= { 0xd1, 0x66, 0xf4, 0x99, 0x18, 0x88, 0x45 },
95 .pll_div_regs
= { 0xd1, 0x70, 0xf4, 0x82, 0x01, 0x80, 0x40 },
98 .pll_div_regs
= { 0xd1, 0x58, 0xb8, 0x8b, 0x88, 0x80, 0x40 },
101 .pll_div_regs
= { 0xd1, 0x5a, 0xb2, 0xfd, 0x0c, 0x80, 0x40 },
104 .pll_div_regs
= { 0xd1, 0x5a, 0x92, 0xfd, 0x0c, 0x80, 0x40 },
107 .pll_div_regs
= { 0xd1, 0x5c, 0x92, 0x98, 0x11, 0x84, 0x41 },
110 .pll_div_regs
= { 0xd1, 0x62, 0x94, 0x95, 0x82, 0x80, 0x40 },
113 .pll_div_regs
= { 0xd1, 0x63, 0x96, 0xa1, 0x82, 0x80, 0x40 },
116 .pll_div_regs
= { 0xd1, 0x54, 0x7c, 0xc3, 0x8f, 0x80, 0x40 },
119 .pll_div_regs
= { 0xd1, 0x58, 0x72, 0x84, 0x03, 0x82, 0x41 },
122 .pll_div_regs
= { 0xd1, 0x5a, 0x72, 0x89, 0x88, 0x80, 0x40 },
125 .pll_div_regs
= { 0xd1, 0x5a, 0x72, 0xfd, 0x0c, 0x80, 0x40 },
128 .pll_div_regs
= { 0xd1, 0x62, 0x74, 0x95, 0x08, 0x80, 0x40 },
131 .pll_div_regs
= { 0xd1, 0x62, 0x74, 0xdb, 0x52, 0x88, 0x47 },
134 .pll_div_regs
= { 0xd1, 0x66, 0x74, 0x82, 0x01, 0x88, 0x45 },
137 .pll_div_regs
= { 0xd1, 0x69, 0x74, 0x89, 0x08, 0x80, 0x40 },
140 .pll_div_regs
= { 0xd1, 0x54, 0x52, 0x87, 0x03, 0x80, 0x40 },
143 .pll_div_regs
= { 0xd1, 0x58, 0x58, 0x8b, 0x88, 0x80, 0x40 },
146 .pll_div_regs
= { 0xd1, 0x5a, 0x52, 0xfd, 0x0c, 0x80, 0x40 },
149 .pll_div_regs
= { 0xd1, 0x5d, 0x58, 0xdb, 0xA2, 0x88, 0x41 },
152 .pll_div_regs
= { 0xd1, 0x5c, 0x52, 0x90, 0x0d, 0x84, 0x41 },
155 .pll_div_regs
= { 0xd1, 0x62, 0x54, 0x87, 0x01, 0x80, 0x40 },
158 .pll_div_regs
= { 0xd1, 0x66, 0x54, 0x82, 0x01, 0x88, 0x45 },
161 .pll_div_regs
= { 0xd1, 0x67, 0x54, 0x88, 0x01, 0x90, 0x49 },
164 .pll_div_regs
= { 0xd1, 0x70, 0x54, 0x84, 0x83, 0x80, 0x40 },
167 .pll_div_regs
= { 0xd1, 0x70, 0x54, 0x82, 0x01, 0x80, 0x40 },
170 .pll_div_regs
= { 0xd1, 0x4e, 0x32, 0xa7, 0x10, 0x80, 0x40 },
173 .pll_div_regs
= { 0xd1, 0x50, 0x31, 0x86, 0x85, 0x80, 0x40 },
176 .pll_div_regs
= { 0xd1, 0x52, 0x3a, 0xdb, 0x4c, 0x88, 0x47 },
179 .pll_div_regs
= { 0xd1, 0x52, 0x32, 0x82, 0x01, 0x88, 0x47 },
182 .pll_div_regs
= { 0xd1, 0x54, 0x3c, 0xc3, 0x8f, 0x80, 0x40 },
185 .pll_div_regs
= { 0xd1, 0x55, 0x32, 0x8c, 0x05, 0x90, 0x4b },
188 .pll_div_regs
= { 0xd1, 0x57, 0x32, 0x98, 0x07, 0x90, 0x49 },
191 .pll_div_regs
= { 0xd1, 0x58, 0x32, 0x84, 0x03, 0x82, 0x41 },
194 .pll_div_regs
= { 0xd1, 0x5a, 0x32, 0x89, 0x88, 0x80, 0x40 },
197 .pll_div_regs
= { 0xd1, 0x5a, 0x32, 0xfd, 0x0c, 0x80, 0x40 },
200 .pll_div_regs
= { 0xd1, 0x62, 0x34, 0x95, 0x08, 0x80, 0x40 },
203 .pll_div_regs
= { 0xd1, 0x66, 0x34, 0x82, 0x01, 0x88, 0x45 },
206 .pll_div_regs
= { 0xd1, 0x69, 0x34, 0x89, 0x08, 0x80, 0x40 },
209 .pll_div_regs
= { 0xd1, 0x70, 0x34, 0x82, 0x01, 0x80, 0x40 },
212 .pll_div_regs
= { 0xd1, 0x71, 0x39, 0xe9, 0x82, 0x9c, 0x5b },
215 .pll_div_regs
= { 0xd1, 0x72, 0x38, 0x99, 0x10, 0x85, 0x41 },
218 .pll_div_regs
= { 0xd1, 0x73, 0x35, 0x88, 0x05, 0x90, 0x4d },
221 .pll_div_regs
= { 0xd1, 0x75, 0x36, 0xa7, 0x90, 0x80, 0x40 },
224 .pll_div_regs
= { 0xd1, 0x7b, 0x35, 0xdb, 0x39, 0x90, 0x45 },
227 .pll_div_regs
= { 0xd1, 0x7b, 0x35, 0x84, 0x03, 0x90, 0x45 },
230 .pll_div_regs
= { 0xd1, 0x40, 0x18, 0x83, 0x01, 0x00, 0x40 },
233 .pll_div_regs
= { 0xd1, 0x41, 0x11, 0xa7, 0x14, 0x80, 0x40 },
236 .pll_div_regs
= { 0xd1, 0x42, 0x12, 0xa1, 0x20, 0x80, 0x40 },
239 .pll_div_regs
= { 0xd1, 0x43, 0x18, 0x8b, 0x08, 0x96, 0x55 },
242 .pll_div_regs
= { 0xd1, 0x45, 0x11, 0x83, 0x82, 0x90, 0x4b },
245 .pll_div_regs
= { 0xd1, 0x45, 0x11, 0x84, 0x81, 0x90, 0x4b },
248 .pll_div_regs
= { 0xd1, 0x4e, 0x12, 0x9a, 0x95, 0x80, 0x40 },
251 .pll_div_regs
= { 0xd1, 0x4e, 0x12, 0xa7, 0x10, 0x80, 0x40 },
254 .pll_div_regs
= { 0xd1, 0x52, 0x12, 0x82, 0x01, 0x88, 0x47 },
257 .pll_div_regs
= { 0xd1, 0x55, 0x12, 0x8c, 0x05, 0x90, 0x4b },
260 .pll_div_regs
= { 0xd1, 0x57, 0x12, 0x98, 0x07, 0x90, 0x49 },
263 .pll_div_regs
= { 0xd1, 0x58, 0x12, 0x84, 0x03, 0x82, 0x41 },
266 .pll_div_regs
= { 0xd1, 0x5a, 0x12, 0xfd, 0x0c, 0x80, 0x40 },
269 .pll_div_regs
= { 0xd1, 0x69, 0x14, 0x89, 0x08, 0x80, 0x40 },
272 .pll_div_regs
= { 0xd1, 0x73, 0x15, 0x88, 0x05, 0x90, 0x4d },
275 .pll_div_regs
= { 0xd1, 0x7b, 0x15, 0x84, 0x03, 0x90, 0x45 },
279 struct reg_settings
{
284 static const struct reg_settings common_phy_cfg
[] = {
285 { PHY_REG(0), 0x00 },
286 /* PHY_REG(1-7) pix clk specific */
287 { PHY_REG(8), 0x4f }, { PHY_REG(9), 0x30 },
288 { PHY_REG(10), 0x33 }, { PHY_REG(11), 0x65 },
289 /* REG12 pixclk specific */
290 /* REG13 pixclk specific */
291 /* REG14 pixclk specific */
292 { PHY_REG(15), 0x80 }, { PHY_REG(16), 0x6c },
293 { PHY_REG(17), 0xf2 }, { PHY_REG(18), 0x67 },
294 { PHY_REG(19), 0x00 }, { PHY_REG(20), 0x10 },
295 /* REG21 pixclk specific */
296 { PHY_REG(22), 0x30 }, { PHY_REG(23), 0x32 },
297 { PHY_REG(24), 0x60 }, { PHY_REG(25), 0x8f },
298 { PHY_REG(26), 0x00 }, { PHY_REG(27), 0x00 },
299 { PHY_REG(28), 0x08 }, { PHY_REG(29), 0x00 },
300 { PHY_REG(30), 0x00 }, { PHY_REG(31), 0x00 },
301 { PHY_REG(32), 0x00 }, { PHY_REG(33), 0x80 },
302 { PHY_REG(34), 0x00 }, { PHY_REG(35), 0x00 },
303 { PHY_REG(36), 0x00 }, { PHY_REG(37), 0x00 },
304 { PHY_REG(38), 0x00 }, { PHY_REG(39), 0x00 },
305 { PHY_REG(40), 0x00 }, { PHY_REG(41), 0xe0 },
306 { PHY_REG(42), 0x83 }, { PHY_REG(43), 0x0f },
307 { PHY_REG(44), 0x3E }, { PHY_REG(45), 0xf8 },
308 { PHY_REG(46), 0x00 }, { PHY_REG(47), 0x00 }
311 struct fsl_samsung_hdmi_phy
{
319 const struct phy_config
*cur_cfg
;
322 static inline struct fsl_samsung_hdmi_phy
*
323 to_fsl_samsung_hdmi_phy(struct clk_hw
*hw
)
325 return container_of(hw
, struct fsl_samsung_hdmi_phy
, hw
);
329 fsl_samsung_hdmi_phy_configure_pll_lock_det(struct fsl_samsung_hdmi_phy
*phy
,
330 const struct phy_config
*cfg
)
332 u32 pclk
= cfg
->pixclk
;
337 switch (cfg
->pixclk
) {
338 case 22250000 ... 47500000:
341 case 50349650 ... 99000000:
344 case 100699300 ... 198000000:
347 case 205000000 ... 297000000:
352 writeb(FIELD_PREP(REG12_CK_DIV_MASK
, ilog2(div
)), phy
->regs
+ PHY_REG(12));
355 * Calculation for the frequency lock detector target code (fld_tg_code)
356 * is based on reference manual register description of PHY_REG13
358 * 1st) Calculate int_pllclk which is determinded by FLD_CK_DIV
359 * 2nd) Increase resolution to avoid rounding issues
360 * 3th) Do the div (256 / Freq. of int_pllclk) * 24
361 * 4th) Reduce the resolution and always round up since the NXP
362 * settings rounding up always too. TODO: Check if that is
366 pclk_khz
= pclk
/ 1000;
367 fld_tg_code
= 256 * 1000 * 1000 / pclk_khz
* 24;
368 fld_tg_code
= DIV_ROUND_UP(fld_tg_code
, 1000);
370 /* FLD_TOL and FLD_RP_CODE taken from downstream driver */
371 writeb(FIELD_PREP(REG13_TG_CODE_LOW_MASK
, fld_tg_code
),
372 phy
->regs
+ PHY_REG(13));
373 writeb(FIELD_PREP(REG14_TOL_MASK
, 2) |
374 FIELD_PREP(REG14_RP_CODE_MASK
, 2) |
375 FIELD_PREP(REG14_TG_CODE_HIGH_MASK
, fld_tg_code
>> 8),
376 phy
->regs
+ PHY_REG(14));
379 static unsigned long fsl_samsung_hdmi_phy_find_pms(unsigned long fout
, u8
*p
, u16
*m
, u8
*s
)
381 unsigned long best_freq
= 0;
382 u32 min_delta
= 0xffffffff;
388 * Figure 13-78 of the reference manual states the PLL should be TMDS x 5
389 * while the TMDS_CLKO should be the PLL / 5. So to calculate the PLL,
390 * take the pix clock x 5, then return the value of the PLL / 5.
394 /* The ref manual states the values of 'P' range from 1 to 11 */
395 for (_p
= 1; _p
<= 11; ++_p
) {
396 for (_s
= 1; _s
<= 16; ++_s
) {
400 /* s must be one or even */
401 if (_s
> 1 && (_s
& 0x01) == 1)
404 /* _s cannot be 14 per the TRM */
409 * TODO: Ref Manual doesn't state the range of _m
410 * so this should be further refined if possible.
411 * This range was set based on the original values
412 * in the lookup table
414 tmp
= (u64
)fout
* (_p
* _s
);
415 do_div(tmp
, 24 * MHZ
);
417 if (_m
< 0x30 || _m
> 0x7b)
421 * Rev 2 of the Ref Manual states the
422 * VCO can range between 750MHz and
423 * 3GHz. The VCO is assumed to be
424 * Fvco = (M * f_ref) / P,
425 * where f_ref is 24MHz.
427 tmp
= (u64
)_m
* 24 * MHZ
;
429 if (tmp
< 750 * MHZ
||
433 /* Final frequency after post-divider */
436 delta
= abs(fout
- tmp
);
437 if (delta
< min_delta
) {
453 return best_freq
/ 5;
456 static int fsl_samsung_hdmi_phy_configure(struct fsl_samsung_hdmi_phy
*phy
,
457 const struct phy_config
*cfg
)
463 writeb(REG33_FIX_DA
, phy
->regs
+ PHY_REG(33));
465 /* common PHY registers */
466 for (i
= 0; i
< ARRAY_SIZE(common_phy_cfg
); i
++)
467 writeb(common_phy_cfg
[i
].val
, phy
->regs
+ common_phy_cfg
[i
].reg
);
469 /* set individual PLL registers PHY_REG1 ... PHY_REG7 */
470 for (i
= 0; i
< PHY_PLL_DIV_REGS_NUM
; i
++)
471 writeb(cfg
->pll_div_regs
[i
], phy
->regs
+ PHY_REG(1) + i
* 4);
473 /* High nibble of PHY_REG3 and low nibble of PHY_REG21 both contain 'S' */
474 writeb(REG21_SEL_TX_CK_INV
| FIELD_PREP(REG21_PMS_S_MASK
,
475 cfg
->pll_div_regs
[2] >> 4), phy
->regs
+ PHY_REG(21));
477 fsl_samsung_hdmi_phy_configure_pll_lock_det(phy
, cfg
);
479 writeb(REG33_FIX_DA
| REG33_MODE_SET_DONE
, phy
->regs
+ PHY_REG(33));
481 ret
= readb_poll_timeout(phy
->regs
+ PHY_REG(34), val
,
482 val
& REG34_PLL_LOCK
, 50, 20000);
484 dev_err(phy
->dev
, "PLL failed to lock\n");
489 static unsigned long phy_clk_recalc_rate(struct clk_hw
*hw
,
490 unsigned long parent_rate
)
492 struct fsl_samsung_hdmi_phy
*phy
= to_fsl_samsung_hdmi_phy(hw
);
497 return phy
->cur_cfg
->pixclk
;
500 /* Helper function to lookup the available fractional-divider rate */
501 static const struct phy_config
*fsl_samsung_hdmi_phy_lookup_rate(unsigned long rate
)
505 /* Search the lookup table */
506 for (i
= ARRAY_SIZE(phy_pll_cfg
) - 1; i
>= 0; i
--)
507 if (phy_pll_cfg
[i
].pixclk
<= rate
)
510 return &phy_pll_cfg
[i
];
513 static void fsl_samsung_hdmi_calculate_phy(struct phy_config
*cal_phy
, unsigned long rate
,
516 cal_phy
->pixclk
= rate
;
517 cal_phy
->pll_div_regs
[0] = FIELD_PREP(REG01_PMS_P_MASK
, p
);
518 cal_phy
->pll_div_regs
[1] = m
;
519 cal_phy
->pll_div_regs
[2] = FIELD_PREP(REG03_PMS_S_MASK
, s
-1);
520 /* pll_div_regs 3-6 are fixed and pre-defined already */
523 static u32
fsl_samsung_hdmi_phy_get_closest_rate(unsigned long rate
,
524 u32 int_div_clk
, u32 frac_div_clk
)
526 /* Calculate the absolute value of the differences and return whichever is closest */
527 if (abs((long)rate
- (long)int_div_clk
) < abs((long)(rate
- (long)frac_div_clk
)))
533 static long phy_clk_round_rate(struct clk_hw
*hw
,
534 unsigned long rate
, unsigned long *parent_rate
)
536 const struct phy_config
*fract_div_phy
;
541 /* If the clock is out of range return error instead of searching */
542 if (rate
> 297000000 || rate
< 22250000)
545 /* Search the fractional divider lookup table */
546 fract_div_phy
= fsl_samsung_hdmi_phy_lookup_rate(rate
);
548 /* If the rate is an exact match, return that value */
549 if (rate
== fract_div_phy
->pixclk
)
550 return fract_div_phy
->pixclk
;
552 /* If the exact match isn't found, calculate the integer divider */
553 int_div_clk
= fsl_samsung_hdmi_phy_find_pms(rate
, &p
, &m
, &s
);
555 /* If the int_div_clk rate is an exact match, return that value */
556 if (int_div_clk
== rate
)
559 /* If neither rate is an exact match, use the value from the LUT */
560 return fract_div_phy
->pixclk
;
563 static int phy_use_fract_div(struct fsl_samsung_hdmi_phy
*phy
, const struct phy_config
*fract_div_phy
)
565 phy
->cur_cfg
= fract_div_phy
;
566 dev_dbg(phy
->dev
, "fsl_samsung_hdmi_phy: using fractional divider rate = %u\n",
567 phy
->cur_cfg
->pixclk
);
568 return fsl_samsung_hdmi_phy_configure(phy
, phy
->cur_cfg
);
571 static int phy_use_integer_div(struct fsl_samsung_hdmi_phy
*phy
,
572 const struct phy_config
*int_div_clk
)
574 phy
->cur_cfg
= &calculated_phy_pll_cfg
;
575 dev_dbg(phy
->dev
, "fsl_samsung_hdmi_phy: integer divider rate = %u\n",
576 phy
->cur_cfg
->pixclk
);
577 return fsl_samsung_hdmi_phy_configure(phy
, phy
->cur_cfg
);
580 static int phy_clk_set_rate(struct clk_hw
*hw
,
581 unsigned long rate
, unsigned long parent_rate
)
583 struct fsl_samsung_hdmi_phy
*phy
= to_fsl_samsung_hdmi_phy(hw
);
584 const struct phy_config
*fract_div_phy
;
589 /* Search the fractional divider lookup table */
590 fract_div_phy
= fsl_samsung_hdmi_phy_lookup_rate(rate
);
592 /* If the rate is an exact match, use that value */
593 if (fract_div_phy
->pixclk
== rate
)
594 return phy_use_fract_div(phy
, fract_div_phy
);
597 * If the rate from the fractional divider is not exact, check the integer divider,
598 * and use it if that value is an exact match.
600 int_div_clk
= fsl_samsung_hdmi_phy_find_pms(rate
, &p
, &m
, &s
);
601 fsl_samsung_hdmi_calculate_phy(&calculated_phy_pll_cfg
, int_div_clk
, p
, m
, s
);
602 if (int_div_clk
== rate
)
603 return phy_use_integer_div(phy
, &calculated_phy_pll_cfg
);
606 * Compare the difference between the integer clock and the fractional clock against
607 * the desired clock and which whichever is closest.
609 if (fsl_samsung_hdmi_phy_get_closest_rate(rate
, int_div_clk
,
610 fract_div_phy
->pixclk
) == fract_div_phy
->pixclk
)
611 return phy_use_fract_div(phy
, fract_div_phy
);
613 return phy_use_integer_div(phy
, &calculated_phy_pll_cfg
);
616 static const struct clk_ops phy_clk_ops
= {
617 .recalc_rate
= phy_clk_recalc_rate
,
618 .round_rate
= phy_clk_round_rate
,
619 .set_rate
= phy_clk_set_rate
,
622 static int phy_clk_register(struct fsl_samsung_hdmi_phy
*phy
)
624 struct device
*dev
= phy
->dev
;
625 struct device_node
*np
= dev
->of_node
;
626 struct clk_init_data init
;
627 const char *parent_name
;
631 parent_name
= __clk_get_name(phy
->refclk
);
633 init
.parent_names
= &parent_name
;
634 init
.num_parents
= 1;
636 init
.name
= "hdmi_pclk";
637 init
.ops
= &phy_clk_ops
;
639 phy
->hw
.init
= &init
;
641 phyclk
= devm_clk_register(dev
, &phy
->hw
);
643 return dev_err_probe(dev
, PTR_ERR(phyclk
),
644 "failed to register clock\n");
646 ret
= of_clk_add_hw_provider(np
, of_clk_hw_simple_get
, phyclk
);
648 return dev_err_probe(dev
, ret
,
649 "failed to register clock provider\n");
654 static int fsl_samsung_hdmi_phy_probe(struct platform_device
*pdev
)
656 struct fsl_samsung_hdmi_phy
*phy
;
659 phy
= devm_kzalloc(&pdev
->dev
, sizeof(*phy
), GFP_KERNEL
);
663 platform_set_drvdata(pdev
, phy
);
664 phy
->dev
= &pdev
->dev
;
666 phy
->regs
= devm_platform_ioremap_resource(pdev
, 0);
667 if (IS_ERR(phy
->regs
))
668 return PTR_ERR(phy
->regs
);
670 phy
->apbclk
= devm_clk_get(phy
->dev
, "apb");
671 if (IS_ERR(phy
->apbclk
))
672 return dev_err_probe(phy
->dev
, PTR_ERR(phy
->apbclk
),
673 "failed to get apb clk\n");
675 phy
->refclk
= devm_clk_get(phy
->dev
, "ref");
676 if (IS_ERR(phy
->refclk
))
677 return dev_err_probe(phy
->dev
, PTR_ERR(phy
->refclk
),
678 "failed to get ref clk\n");
680 ret
= clk_prepare_enable(phy
->apbclk
);
682 dev_err(phy
->dev
, "failed to enable apbclk\n");
686 pm_runtime_get_noresume(phy
->dev
);
687 pm_runtime_set_active(phy
->dev
);
688 pm_runtime_enable(phy
->dev
);
690 ret
= phy_clk_register(phy
);
692 dev_err(&pdev
->dev
, "register clk failed\n");
693 goto register_clk_failed
;
696 pm_runtime_put(phy
->dev
);
701 clk_disable_unprepare(phy
->apbclk
);
706 static void fsl_samsung_hdmi_phy_remove(struct platform_device
*pdev
)
708 of_clk_del_provider(pdev
->dev
.of_node
);
711 static int __maybe_unused
fsl_samsung_hdmi_phy_suspend(struct device
*dev
)
713 struct fsl_samsung_hdmi_phy
*phy
= dev_get_drvdata(dev
);
715 clk_disable_unprepare(phy
->apbclk
);
720 static int __maybe_unused
fsl_samsung_hdmi_phy_resume(struct device
*dev
)
722 struct fsl_samsung_hdmi_phy
*phy
= dev_get_drvdata(dev
);
725 ret
= clk_prepare_enable(phy
->apbclk
);
727 dev_err(phy
->dev
, "failed to enable apbclk\n");
732 ret
= fsl_samsung_hdmi_phy_configure(phy
, phy
->cur_cfg
);
738 static DEFINE_RUNTIME_DEV_PM_OPS(fsl_samsung_hdmi_phy_pm_ops
,
739 fsl_samsung_hdmi_phy_suspend
,
740 fsl_samsung_hdmi_phy_resume
, NULL
);
742 static const struct of_device_id fsl_samsung_hdmi_phy_of_match
[] = {
744 .compatible
= "fsl,imx8mp-hdmi-phy",
749 MODULE_DEVICE_TABLE(of
, fsl_samsung_hdmi_phy_of_match
);
751 static struct platform_driver fsl_samsung_hdmi_phy_driver
= {
752 .probe
= fsl_samsung_hdmi_phy_probe
,
753 .remove
= fsl_samsung_hdmi_phy_remove
,
755 .name
= "fsl-samsung-hdmi-phy",
756 .of_match_table
= fsl_samsung_hdmi_phy_of_match
,
757 .pm
= pm_ptr(&fsl_samsung_hdmi_phy_pm_ops
),
760 module_platform_driver(fsl_samsung_hdmi_phy_driver
);
762 MODULE_AUTHOR("Sandor Yu <Sandor.yu@nxp.com>");
763 MODULE_DESCRIPTION("SAMSUNG HDMI 2.0 Transmitter PHY Driver");
764 MODULE_LICENSE("GPL");