Path: blob/master/drivers/gpu/drm/bridge/imx/imx8mp-hdmi-tx.c
52487 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/component.h>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>13#include <drm/drm_of.h>1415struct imx8mp_hdmi {16struct dw_hdmi_plat_data plat_data;17struct dw_hdmi *dw_hdmi;18struct clk *pixclk;19};2021static enum drm_mode_status22imx8mp_hdmi_mode_valid(struct dw_hdmi *dw_hdmi, void *data,23const struct drm_display_info *info,24const struct drm_display_mode *mode)25{26struct imx8mp_hdmi *hdmi = (struct imx8mp_hdmi *)data;27long round_rate;2829if (mode->clock < 13500)30return MODE_CLOCK_LOW;3132if (mode->clock > 297000)33return MODE_CLOCK_HIGH;3435round_rate = clk_round_rate(hdmi->pixclk, mode->clock * 1000);36/* imx8mp's pixel clock generator (fsl-samsung-hdmi) cannot generate37* all possible frequencies, so allow some tolerance to support more38* modes.39* Allow 0.5% difference allowed in various standards (VESA, CEA861)40* 0.5% = 5/1000 tolerance (mode->clock is 1/1000)41*/42if (abs(round_rate - mode->clock * 1000) > mode->clock * 5)43return MODE_CLOCK_RANGE;4445/* We don't support double-clocked and Interlaced modes */46if ((mode->flags & DRM_MODE_FLAG_DBLCLK) ||47(mode->flags & DRM_MODE_FLAG_INTERLACE))48return MODE_BAD;4950return MODE_OK;51}5253static int imx8mp_hdmi_phy_init(struct dw_hdmi *dw_hdmi, void *data,54const struct drm_display_info *display,55const struct drm_display_mode *mode)56{57return 0;58}5960static void imx8mp_hdmi_phy_disable(struct dw_hdmi *dw_hdmi, void *data)61{62}6364static void im8mp_hdmi_phy_setup_hpd(struct dw_hdmi *hdmi, void *data)65{66/*67* Just release PHY core from reset, all other power management is done68* by the PHY driver.69*/70dw_hdmi_phy_gen1_reset(hdmi);7172dw_hdmi_phy_setup_hpd(hdmi, data);73}7475static const struct dw_hdmi_phy_ops imx8mp_hdmi_phy_ops = {76.init = imx8mp_hdmi_phy_init,77.disable = imx8mp_hdmi_phy_disable,78.setup_hpd = im8mp_hdmi_phy_setup_hpd,79.read_hpd = dw_hdmi_phy_read_hpd,80.update_hpd = dw_hdmi_phy_update_hpd,81};8283static int imx8mp_dw_hdmi_bind(struct device *dev)84{85struct platform_device *pdev = to_platform_device(dev);86struct imx8mp_hdmi *hdmi = dev_get_drvdata(dev);87int ret;8889ret = component_bind_all(dev, &hdmi->plat_data);90if (ret)91return dev_err_probe(dev, ret, "component_bind_all failed!\n");9293hdmi->dw_hdmi = dw_hdmi_probe(pdev, &hdmi->plat_data);94if (IS_ERR(hdmi->dw_hdmi)) {95component_unbind_all(dev, &hdmi->plat_data);96return PTR_ERR(hdmi->dw_hdmi);97}9899return 0;100}101102static void imx8mp_dw_hdmi_unbind(struct device *dev)103{104struct imx8mp_hdmi *hdmi = dev_get_drvdata(dev);105106dw_hdmi_remove(hdmi->dw_hdmi);107108component_unbind_all(dev, &hdmi->plat_data);109}110111static const struct component_master_ops imx8mp_dw_hdmi_ops = {112.bind = imx8mp_dw_hdmi_bind,113.unbind = imx8mp_dw_hdmi_unbind,114};115116static int imx8mp_dw_hdmi_probe(struct platform_device *pdev)117{118struct device *dev = &pdev->dev;119struct dw_hdmi_plat_data *plat_data;120struct component_match *match = NULL;121struct device_node *remote;122struct imx8mp_hdmi *hdmi;123124hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL);125if (!hdmi)126return -ENOMEM;127128plat_data = &hdmi->plat_data;129130hdmi->pixclk = devm_clk_get(dev, "pix");131if (IS_ERR(hdmi->pixclk))132return dev_err_probe(dev, PTR_ERR(hdmi->pixclk),133"Unable to get pixel clock\n");134135plat_data->mode_valid = imx8mp_hdmi_mode_valid;136plat_data->phy_ops = &imx8mp_hdmi_phy_ops;137plat_data->phy_name = "SAMSUNG HDMI TX PHY";138plat_data->priv_data = hdmi;139plat_data->phy_force_vendor = true;140141platform_set_drvdata(pdev, hdmi);142143/* port@2 is for hdmi_pai device */144remote = of_graph_get_remote_node(pdev->dev.of_node, 2, 0);145if (!remote) {146hdmi->dw_hdmi = dw_hdmi_probe(pdev, plat_data);147if (IS_ERR(hdmi->dw_hdmi))148return PTR_ERR(hdmi->dw_hdmi);149} else {150drm_of_component_match_add(dev, &match, component_compare_of, remote);151152of_node_put(remote);153154return component_master_add_with_match(dev, &imx8mp_dw_hdmi_ops, match);155}156157return 0;158}159160static void imx8mp_dw_hdmi_remove(struct platform_device *pdev)161{162struct imx8mp_hdmi *hdmi = platform_get_drvdata(pdev);163struct device_node *remote;164165remote = of_graph_get_remote_node(pdev->dev.of_node, 2, 0);166if (remote) {167of_node_put(remote);168169component_master_del(&pdev->dev, &imx8mp_dw_hdmi_ops);170} else {171dw_hdmi_remove(hdmi->dw_hdmi);172}173}174175static int imx8mp_dw_hdmi_pm_suspend(struct device *dev)176{177return 0;178}179180static int imx8mp_dw_hdmi_pm_resume(struct device *dev)181{182struct imx8mp_hdmi *hdmi = dev_get_drvdata(dev);183184dw_hdmi_resume(hdmi->dw_hdmi);185186return 0;187}188189static const struct dev_pm_ops imx8mp_dw_hdmi_pm_ops = {190SYSTEM_SLEEP_PM_OPS(imx8mp_dw_hdmi_pm_suspend, imx8mp_dw_hdmi_pm_resume)191};192193static const struct of_device_id imx8mp_dw_hdmi_of_table[] = {194{ .compatible = "fsl,imx8mp-hdmi-tx" },195{ /* Sentinel */ }196};197MODULE_DEVICE_TABLE(of, imx8mp_dw_hdmi_of_table);198199static struct platform_driver imx8mp_dw_hdmi_platform_driver = {200.probe = imx8mp_dw_hdmi_probe,201.remove = imx8mp_dw_hdmi_remove,202.driver = {203.name = "imx8mp-dw-hdmi-tx",204.of_match_table = imx8mp_dw_hdmi_of_table,205.pm = pm_ptr(&imx8mp_dw_hdmi_pm_ops),206},207};208209module_platform_driver(imx8mp_dw_hdmi_platform_driver);210211MODULE_DESCRIPTION("i.MX8MP HDMI encoder driver");212MODULE_LICENSE("GPL");213214215