Path: blob/master/drivers/gpu/drm/bridge/th1520-dw-hdmi.c
170953 views
// SPDX-License-Identifier: GPL-2.0+1/*2* Copyright (C) 2025 Icenowy Zheng <[email protected]>3*4* Based on rcar_dw_hdmi.c, which is:5* Copyright (C) 2016 Renesas Electronics Corporation6* Based on imx8mp-hdmi-tx.c, which is:7* Copyright (C) 2022 Pengutronix, Lucas Stach <[email protected]>8*/910#include <linux/clk.h>11#include <linux/mod_devicetable.h>12#include <linux/module.h>13#include <linux/platform_device.h>14#include <linux/reset.h>1516#include <drm/bridge/dw_hdmi.h>17#include <drm/drm_modes.h>1819#define TH1520_HDMI_PHY_OPMODE_PLLCFG 0x06 /* Mode of operation and PLL dividers */20#define TH1520_HDMI_PHY_CKSYMTXCTRL 0x09 /* Clock Symbol and Transmitter Control Register */21#define TH1520_HDMI_PHY_VLEVCTRL 0x0e /* Voltage Level Control Register */22#define TH1520_HDMI_PHY_PLLCURRGMPCTRL 0x10 /* PLL current and Gmp (conductance) */23#define TH1520_HDMI_PHY_PLLDIVCTRL 0x11 /* PLL dividers */24#define TH1520_HDMI_PHY_TXTERM 0x19 /* Transmission Termination Register */2526struct th1520_hdmi_phy_params {27unsigned long mpixelclock;28u16 opmode_pllcfg;29u16 pllcurrgmpctrl;30u16 plldivctrl;31u16 cksymtxctrl;32u16 vlevctrl;33u16 txterm;34};3536static const struct th1520_hdmi_phy_params th1520_hdmi_phy_params[] = {37{ 35500000, 0x0003, 0x0283, 0x0628, 0x8088, 0x01a0, 0x0007 },38{ 44900000, 0x0003, 0x0285, 0x0228, 0x8088, 0x01a0, 0x0007 },39{ 71000000, 0x0002, 0x1183, 0x0614, 0x8088, 0x01a0, 0x0007 },40{ 90000000, 0x0002, 0x1142, 0x0214, 0x8088, 0x01a0, 0x0007 },41{ 121750000, 0x0001, 0x20c0, 0x060a, 0x8088, 0x01a0, 0x0007 },42{ 165000000, 0x0001, 0x2080, 0x020a, 0x8088, 0x01a0, 0x0007 },43{ 198000000, 0x0000, 0x3040, 0x0605, 0x83c8, 0x0120, 0x0004 },44{ 297000000, 0x0000, 0x3041, 0x0205, 0x81dc, 0x0200, 0x0005 },45{ 371250000, 0x0640, 0x3041, 0x0205, 0x80f6, 0x0140, 0x0000 },46{ 495000000, 0x0640, 0x3080, 0x0005, 0x80f6, 0x0140, 0x0000 },47{ 594000000, 0x0640, 0x3080, 0x0005, 0x80fa, 0x01e0, 0x0004 },48};4950struct th1520_hdmi {51struct dw_hdmi_plat_data plat_data;52struct dw_hdmi *dw_hdmi;53struct clk *pixclk;54struct reset_control *mainrst, *prst;55};5657static enum drm_mode_status58th1520_hdmi_mode_valid(struct dw_hdmi *hdmi, void *data,59const struct drm_display_info *info,60const struct drm_display_mode *mode)61{62/*63* The maximum supported clock frequency is 594 MHz, as shown in the PHY64* parameters table.65*/66if (mode->clock > 594000)67return MODE_CLOCK_HIGH;6869return MODE_OK;70}7172static void th1520_hdmi_phy_set_params(struct dw_hdmi *hdmi,73const struct th1520_hdmi_phy_params *params)74{75dw_hdmi_phy_i2c_write(hdmi, params->opmode_pllcfg,76TH1520_HDMI_PHY_OPMODE_PLLCFG);77dw_hdmi_phy_i2c_write(hdmi, params->pllcurrgmpctrl,78TH1520_HDMI_PHY_PLLCURRGMPCTRL);79dw_hdmi_phy_i2c_write(hdmi, params->plldivctrl,80TH1520_HDMI_PHY_PLLDIVCTRL);81dw_hdmi_phy_i2c_write(hdmi, params->vlevctrl,82TH1520_HDMI_PHY_VLEVCTRL);83dw_hdmi_phy_i2c_write(hdmi, params->cksymtxctrl,84TH1520_HDMI_PHY_CKSYMTXCTRL);85dw_hdmi_phy_i2c_write(hdmi, params->txterm,86TH1520_HDMI_PHY_TXTERM);87}8889static int th1520_hdmi_phy_configure(struct dw_hdmi *hdmi, void *data,90unsigned long mpixelclock)91{92unsigned int i;9394for (i = 0; i < ARRAY_SIZE(th1520_hdmi_phy_params); i++) {95if (mpixelclock <= th1520_hdmi_phy_params[i].mpixelclock) {96th1520_hdmi_phy_set_params(hdmi,97&th1520_hdmi_phy_params[i]);98return 0;99}100}101102return -EINVAL;103}104105static int th1520_dw_hdmi_probe(struct platform_device *pdev)106{107struct th1520_hdmi *hdmi;108struct dw_hdmi_plat_data *plat_data;109struct device *dev = &pdev->dev;110111hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL);112if (!hdmi)113return -ENOMEM;114115plat_data = &hdmi->plat_data;116117hdmi->pixclk = devm_clk_get_enabled(dev, "pix");118if (IS_ERR(hdmi->pixclk))119return dev_err_probe(dev, PTR_ERR(hdmi->pixclk),120"Unable to get pixel clock\n");121122hdmi->mainrst = devm_reset_control_get_exclusive_deasserted(dev, "main");123if (IS_ERR(hdmi->mainrst))124return dev_err_probe(dev, PTR_ERR(hdmi->mainrst),125"Unable to get main reset\n");126127hdmi->prst = devm_reset_control_get_exclusive_deasserted(dev, "apb");128if (IS_ERR(hdmi->prst))129return dev_err_probe(dev, PTR_ERR(hdmi->prst),130"Unable to get apb reset\n");131132plat_data->output_port = 1;133plat_data->mode_valid = th1520_hdmi_mode_valid;134plat_data->configure_phy = th1520_hdmi_phy_configure;135plat_data->priv_data = hdmi;136137hdmi->dw_hdmi = dw_hdmi_probe(pdev, plat_data);138if (IS_ERR(hdmi))139return PTR_ERR(hdmi);140141platform_set_drvdata(pdev, hdmi);142143return 0;144}145146static void th1520_dw_hdmi_remove(struct platform_device *pdev)147{148struct dw_hdmi *hdmi = platform_get_drvdata(pdev);149150dw_hdmi_remove(hdmi);151}152153static const struct of_device_id th1520_dw_hdmi_of_table[] = {154{ .compatible = "thead,th1520-dw-hdmi" },155{ /* Sentinel */ },156};157MODULE_DEVICE_TABLE(of, th1520_dw_hdmi_of_table);158159static struct platform_driver th1520_dw_hdmi_platform_driver = {160.probe = th1520_dw_hdmi_probe,161.remove = th1520_dw_hdmi_remove,162.driver = {163.name = "th1520-dw-hdmi",164.of_match_table = th1520_dw_hdmi_of_table,165},166};167168module_platform_driver(th1520_dw_hdmi_platform_driver);169170MODULE_AUTHOR("Icenowy Zheng <[email protected]>");171MODULE_DESCRIPTION("T-Head TH1520 HDMI Encoder Driver");172MODULE_LICENSE("GPL");173174175