Path: blob/master/drivers/gpu/drm/bridge/imx/imx8mp-hdmi-tx.c
26517 views
// SPDX-License-Identifier: GPL-2.0+12/*3* Copyright (C) 2022 Pengutronix, Lucas Stach <[email protected]>4*/56#include <linux/clk.h>7#include <linux/mod_devicetable.h>8#include <linux/module.h>9#include <linux/platform_device.h>10#include <drm/bridge/dw_hdmi.h>11#include <drm/drm_modes.h>1213struct imx8mp_hdmi {14struct dw_hdmi_plat_data plat_data;15struct dw_hdmi *dw_hdmi;16struct clk *pixclk;17};1819static enum drm_mode_status20imx8mp_hdmi_mode_valid(struct dw_hdmi *dw_hdmi, void *data,21const struct drm_display_info *info,22const struct drm_display_mode *mode)23{24struct imx8mp_hdmi *hdmi = (struct imx8mp_hdmi *)data;25long round_rate;2627if (mode->clock < 13500)28return MODE_CLOCK_LOW;2930if (mode->clock > 297000)31return MODE_CLOCK_HIGH;3233round_rate = clk_round_rate(hdmi->pixclk, mode->clock * 1000);34/* imx8mp's pixel clock generator (fsl-samsung-hdmi) cannot generate35* all possible frequencies, so allow some tolerance to support more36* modes.37* Allow 0.5% difference allowed in various standards (VESA, CEA861)38* 0.5% = 5/1000 tolerance (mode->clock is 1/1000)39*/40if (abs(round_rate - mode->clock * 1000) > mode->clock * 5)41return MODE_CLOCK_RANGE;4243/* We don't support double-clocked and Interlaced modes */44if ((mode->flags & DRM_MODE_FLAG_DBLCLK) ||45(mode->flags & DRM_MODE_FLAG_INTERLACE))46return MODE_BAD;4748return MODE_OK;49}5051static int imx8mp_hdmi_phy_init(struct dw_hdmi *dw_hdmi, void *data,52const struct drm_display_info *display,53const struct drm_display_mode *mode)54{55return 0;56}5758static void imx8mp_hdmi_phy_disable(struct dw_hdmi *dw_hdmi, void *data)59{60}6162static void im8mp_hdmi_phy_setup_hpd(struct dw_hdmi *hdmi, void *data)63{64/*65* Just release PHY core from reset, all other power management is done66* by the PHY driver.67*/68dw_hdmi_phy_gen1_reset(hdmi);6970dw_hdmi_phy_setup_hpd(hdmi, data);71}7273static const struct dw_hdmi_phy_ops imx8mp_hdmi_phy_ops = {74.init = imx8mp_hdmi_phy_init,75.disable = imx8mp_hdmi_phy_disable,76.setup_hpd = im8mp_hdmi_phy_setup_hpd,77.read_hpd = dw_hdmi_phy_read_hpd,78.update_hpd = dw_hdmi_phy_update_hpd,79};8081static int imx8mp_dw_hdmi_probe(struct platform_device *pdev)82{83struct device *dev = &pdev->dev;84struct dw_hdmi_plat_data *plat_data;85struct imx8mp_hdmi *hdmi;8687hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL);88if (!hdmi)89return -ENOMEM;9091plat_data = &hdmi->plat_data;9293hdmi->pixclk = devm_clk_get(dev, "pix");94if (IS_ERR(hdmi->pixclk))95return dev_err_probe(dev, PTR_ERR(hdmi->pixclk),96"Unable to get pixel clock\n");9798plat_data->mode_valid = imx8mp_hdmi_mode_valid;99plat_data->phy_ops = &imx8mp_hdmi_phy_ops;100plat_data->phy_name = "SAMSUNG HDMI TX PHY";101plat_data->priv_data = hdmi;102plat_data->phy_force_vendor = true;103104hdmi->dw_hdmi = dw_hdmi_probe(pdev, plat_data);105if (IS_ERR(hdmi->dw_hdmi))106return PTR_ERR(hdmi->dw_hdmi);107108platform_set_drvdata(pdev, hdmi);109110return 0;111}112113static void imx8mp_dw_hdmi_remove(struct platform_device *pdev)114{115struct imx8mp_hdmi *hdmi = platform_get_drvdata(pdev);116117dw_hdmi_remove(hdmi->dw_hdmi);118}119120static int imx8mp_dw_hdmi_pm_suspend(struct device *dev)121{122return 0;123}124125static int imx8mp_dw_hdmi_pm_resume(struct device *dev)126{127struct imx8mp_hdmi *hdmi = dev_get_drvdata(dev);128129dw_hdmi_resume(hdmi->dw_hdmi);130131return 0;132}133134static const struct dev_pm_ops imx8mp_dw_hdmi_pm_ops = {135SYSTEM_SLEEP_PM_OPS(imx8mp_dw_hdmi_pm_suspend, imx8mp_dw_hdmi_pm_resume)136};137138static const struct of_device_id imx8mp_dw_hdmi_of_table[] = {139{ .compatible = "fsl,imx8mp-hdmi-tx" },140{ /* Sentinel */ }141};142MODULE_DEVICE_TABLE(of, imx8mp_dw_hdmi_of_table);143144static struct platform_driver imx8mp_dw_hdmi_platform_driver = {145.probe = imx8mp_dw_hdmi_probe,146.remove = imx8mp_dw_hdmi_remove,147.driver = {148.name = "imx8mp-dw-hdmi-tx",149.of_match_table = imx8mp_dw_hdmi_of_table,150.pm = pm_ptr(&imx8mp_dw_hdmi_pm_ops),151},152};153154module_platform_driver(imx8mp_dw_hdmi_platform_driver);155156MODULE_DESCRIPTION("i.MX8MP HDMI encoder driver");157MODULE_LICENSE("GPL");158159160