Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * R-Car Gen3 HDMI PHY
0004  *
0005  * Copyright (C) 2016 Renesas Electronics Corporation
0006  *
0007  * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
0008  */
0009 
0010 #include <linux/mod_devicetable.h>
0011 #include <linux/module.h>
0012 #include <linux/platform_device.h>
0013 
0014 #include <drm/bridge/dw_hdmi.h>
0015 #include <drm/drm_modes.h>
0016 
0017 #define RCAR_HDMI_PHY_OPMODE_PLLCFG 0x06    /* Mode of operation and PLL dividers */
0018 #define RCAR_HDMI_PHY_PLLCURRGMPCTRL    0x10    /* PLL current and Gmp (conductance) */
0019 #define RCAR_HDMI_PHY_PLLDIVCTRL    0x11    /* PLL dividers */
0020 
0021 struct rcar_hdmi_phy_params {
0022     unsigned long mpixelclock;
0023     u16 opmode_div; /* Mode of operation and PLL dividers */
0024     u16 curr_gmp;   /* PLL current and Gmp (conductance) */
0025     u16 div;    /* PLL dividers */
0026 };
0027 
0028 static const struct rcar_hdmi_phy_params rcar_hdmi_phy_params[] = {
0029     { 35500000,  0x0003, 0x0344, 0x0328 },
0030     { 44900000,  0x0003, 0x0285, 0x0128 },
0031     { 71000000,  0x0002, 0x1184, 0x0314 },
0032     { 90000000,  0x0002, 0x1144, 0x0114 },
0033     { 140250000, 0x0001, 0x20c4, 0x030a },
0034     { 182750000, 0x0001, 0x2084, 0x010a },
0035     { 281250000, 0x0000, 0x0084, 0x0305 },
0036     { 297000000, 0x0000, 0x0084, 0x0105 },
0037     { ~0UL,      0x0000, 0x0000, 0x0000 },
0038 };
0039 
0040 static enum drm_mode_status
0041 rcar_hdmi_mode_valid(struct dw_hdmi *hdmi, void *data,
0042              const struct drm_display_info *info,
0043              const struct drm_display_mode *mode)
0044 {
0045     /*
0046      * The maximum supported clock frequency is 297 MHz, as shown in the PHY
0047      * parameters table.
0048      */
0049     if (mode->clock > 297000)
0050         return MODE_CLOCK_HIGH;
0051 
0052     return MODE_OK;
0053 }
0054 
0055 static int rcar_hdmi_phy_configure(struct dw_hdmi *hdmi, void *data,
0056                    unsigned long mpixelclock)
0057 {
0058     const struct rcar_hdmi_phy_params *params = rcar_hdmi_phy_params;
0059 
0060     for (; params->mpixelclock != ~0UL; ++params) {
0061         if (mpixelclock <= params->mpixelclock)
0062             break;
0063     }
0064 
0065     if (params->mpixelclock == ~0UL)
0066         return -EINVAL;
0067 
0068     dw_hdmi_phy_i2c_write(hdmi, params->opmode_div,
0069                   RCAR_HDMI_PHY_OPMODE_PLLCFG);
0070     dw_hdmi_phy_i2c_write(hdmi, params->curr_gmp,
0071                   RCAR_HDMI_PHY_PLLCURRGMPCTRL);
0072     dw_hdmi_phy_i2c_write(hdmi, params->div, RCAR_HDMI_PHY_PLLDIVCTRL);
0073 
0074     return 0;
0075 }
0076 
0077 static const struct dw_hdmi_plat_data rcar_dw_hdmi_plat_data = {
0078     .output_port = 1,
0079     .mode_valid = rcar_hdmi_mode_valid,
0080     .configure_phy  = rcar_hdmi_phy_configure,
0081 };
0082 
0083 static int rcar_dw_hdmi_probe(struct platform_device *pdev)
0084 {
0085     struct dw_hdmi *hdmi;
0086 
0087     hdmi = dw_hdmi_probe(pdev, &rcar_dw_hdmi_plat_data);
0088     if (IS_ERR(hdmi))
0089         return PTR_ERR(hdmi);
0090 
0091     platform_set_drvdata(pdev, hdmi);
0092 
0093     return 0;
0094 }
0095 
0096 static int rcar_dw_hdmi_remove(struct platform_device *pdev)
0097 {
0098     struct dw_hdmi *hdmi = platform_get_drvdata(pdev);
0099 
0100     dw_hdmi_remove(hdmi);
0101 
0102     return 0;
0103 }
0104 
0105 static const struct of_device_id rcar_dw_hdmi_of_table[] = {
0106     { .compatible = "renesas,rcar-gen3-hdmi" },
0107     { /* Sentinel */ },
0108 };
0109 MODULE_DEVICE_TABLE(of, rcar_dw_hdmi_of_table);
0110 
0111 static struct platform_driver rcar_dw_hdmi_platform_driver = {
0112     .probe      = rcar_dw_hdmi_probe,
0113     .remove     = rcar_dw_hdmi_remove,
0114     .driver     = {
0115         .name   = "rcar-dw-hdmi",
0116         .of_match_table = rcar_dw_hdmi_of_table,
0117     },
0118 };
0119 
0120 module_platform_driver(rcar_dw_hdmi_platform_driver);
0121 
0122 MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
0123 MODULE_DESCRIPTION("Renesas R-Car Gen3 HDMI Encoder Driver");
0124 MODULE_LICENSE("GPL");