1 // SPDX-License-Identifier: GPL-2.0+
4 * Copyright (C) 2022 Pengutronix, Lucas Stach <kernel@pengutronix.de>
8 #include <linux/mod_devicetable.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <drm/bridge/dw_hdmi.h>
12 #include <drm/drm_modes.h>
15 struct dw_hdmi_plat_data plat_data
;
16 struct dw_hdmi
*dw_hdmi
;
20 static enum drm_mode_status
21 imx8mp_hdmi_mode_valid(struct dw_hdmi
*dw_hdmi
, void *data
,
22 const struct drm_display_info
*info
,
23 const struct drm_display_mode
*mode
)
25 struct imx8mp_hdmi
*hdmi
= (struct imx8mp_hdmi
*)data
;
28 if (mode
->clock
< 13500)
29 return MODE_CLOCK_LOW
;
31 if (mode
->clock
> 297000)
32 return MODE_CLOCK_HIGH
;
34 round_rate
= clk_round_rate(hdmi
->pixclk
, mode
->clock
* 1000);
35 /* imx8mp's pixel clock generator (fsl-samsung-hdmi) cannot generate
36 * all possible frequencies, so allow some tolerance to support more
38 * Allow 0.5% difference allowed in various standards (VESA, CEA861)
39 * 0.5% = 5/1000 tolerance (mode->clock is 1/1000)
41 if (abs(round_rate
- mode
->clock
* 1000) > mode
->clock
* 5)
42 return MODE_CLOCK_RANGE
;
44 /* We don't support double-clocked and Interlaced modes */
45 if ((mode
->flags
& DRM_MODE_FLAG_DBLCLK
) ||
46 (mode
->flags
& DRM_MODE_FLAG_INTERLACE
))
52 static int imx8mp_hdmi_phy_init(struct dw_hdmi
*dw_hdmi
, void *data
,
53 const struct drm_display_info
*display
,
54 const struct drm_display_mode
*mode
)
59 static void imx8mp_hdmi_phy_disable(struct dw_hdmi
*dw_hdmi
, void *data
)
63 static void im8mp_hdmi_phy_setup_hpd(struct dw_hdmi
*hdmi
, void *data
)
66 * Just release PHY core from reset, all other power management is done
69 dw_hdmi_phy_gen1_reset(hdmi
);
71 dw_hdmi_phy_setup_hpd(hdmi
, data
);
74 static const struct dw_hdmi_phy_ops imx8mp_hdmi_phy_ops
= {
75 .init
= imx8mp_hdmi_phy_init
,
76 .disable
= imx8mp_hdmi_phy_disable
,
77 .setup_hpd
= im8mp_hdmi_phy_setup_hpd
,
78 .read_hpd
= dw_hdmi_phy_read_hpd
,
79 .update_hpd
= dw_hdmi_phy_update_hpd
,
82 static int imx8mp_dw_hdmi_probe(struct platform_device
*pdev
)
84 struct device
*dev
= &pdev
->dev
;
85 struct dw_hdmi_plat_data
*plat_data
;
86 struct imx8mp_hdmi
*hdmi
;
88 hdmi
= devm_kzalloc(dev
, sizeof(*hdmi
), GFP_KERNEL
);
92 plat_data
= &hdmi
->plat_data
;
94 hdmi
->pixclk
= devm_clk_get(dev
, "pix");
95 if (IS_ERR(hdmi
->pixclk
))
96 return dev_err_probe(dev
, PTR_ERR(hdmi
->pixclk
),
97 "Unable to get pixel clock\n");
99 plat_data
->mode_valid
= imx8mp_hdmi_mode_valid
;
100 plat_data
->phy_ops
= &imx8mp_hdmi_phy_ops
;
101 plat_data
->phy_name
= "SAMSUNG HDMI TX PHY";
102 plat_data
->priv_data
= hdmi
;
103 plat_data
->phy_force_vendor
= true;
105 hdmi
->dw_hdmi
= dw_hdmi_probe(pdev
, plat_data
);
106 if (IS_ERR(hdmi
->dw_hdmi
))
107 return PTR_ERR(hdmi
->dw_hdmi
);
109 platform_set_drvdata(pdev
, hdmi
);
114 static void imx8mp_dw_hdmi_remove(struct platform_device
*pdev
)
116 struct imx8mp_hdmi
*hdmi
= platform_get_drvdata(pdev
);
118 dw_hdmi_remove(hdmi
->dw_hdmi
);
121 static int imx8mp_dw_hdmi_pm_suspend(struct device
*dev
)
126 static int imx8mp_dw_hdmi_pm_resume(struct device
*dev
)
128 struct imx8mp_hdmi
*hdmi
= dev_get_drvdata(dev
);
130 dw_hdmi_resume(hdmi
->dw_hdmi
);
135 static const struct dev_pm_ops imx8mp_dw_hdmi_pm_ops
= {
136 SYSTEM_SLEEP_PM_OPS(imx8mp_dw_hdmi_pm_suspend
, imx8mp_dw_hdmi_pm_resume
)
139 static const struct of_device_id imx8mp_dw_hdmi_of_table
[] = {
140 { .compatible
= "fsl,imx8mp-hdmi-tx" },
143 MODULE_DEVICE_TABLE(of
, imx8mp_dw_hdmi_of_table
);
145 static struct platform_driver imx8mp_dw_hdmi_platform_driver
= {
146 .probe
= imx8mp_dw_hdmi_probe
,
147 .remove
= imx8mp_dw_hdmi_remove
,
149 .name
= "imx8mp-dw-hdmi-tx",
150 .of_match_table
= imx8mp_dw_hdmi_of_table
,
151 .pm
= pm_ptr(&imx8mp_dw_hdmi_pm_ops
),
155 module_platform_driver(imx8mp_dw_hdmi_platform_driver
);
157 MODULE_DESCRIPTION("i.MX8MP HDMI encoder driver");
158 MODULE_LICENSE("GPL");