1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2016, The Linux Foundation. All rights reserved.
6 #include <linux/of_device.h>
10 static int msm_hdmi_phy_resource_init(struct hdmi_phy *phy)
12 struct hdmi_phy_cfg *cfg = phy->cfg;
13 struct device *dev = &phy->pdev->dev;
16 phy->regs = devm_kcalloc(dev, cfg->num_regs, sizeof(phy->regs[0]),
21 phy->clks = devm_kcalloc(dev, cfg->num_clks, sizeof(phy->clks[0]),
26 for (i = 0; i < cfg->num_regs; i++) {
27 struct regulator *reg;
29 reg = devm_regulator_get(dev, cfg->reg_names[i]);
32 DRM_DEV_ERROR(dev, "failed to get phy regulator: %s (%d)\n",
33 cfg->reg_names[i], ret);
40 for (i = 0; i < cfg->num_clks; i++) {
43 clk = msm_clk_get(phy->pdev, cfg->clk_names[i]);
46 DRM_DEV_ERROR(dev, "failed to get phy clock: %s (%d)\n",
47 cfg->clk_names[i], ret);
57 int msm_hdmi_phy_resource_enable(struct hdmi_phy *phy)
59 struct hdmi_phy_cfg *cfg = phy->cfg;
60 struct device *dev = &phy->pdev->dev;
63 pm_runtime_get_sync(dev);
65 for (i = 0; i < cfg->num_regs; i++) {
66 ret = regulator_enable(phy->regs[i]);
68 DRM_DEV_ERROR(dev, "failed to enable regulator: %s (%d)\n",
69 cfg->reg_names[i], ret);
72 for (i = 0; i < cfg->num_clks; i++) {
73 ret = clk_prepare_enable(phy->clks[i]);
75 DRM_DEV_ERROR(dev, "failed to enable clock: %s (%d)\n",
76 cfg->clk_names[i], ret);
82 void msm_hdmi_phy_resource_disable(struct hdmi_phy *phy)
84 struct hdmi_phy_cfg *cfg = phy->cfg;
85 struct device *dev = &phy->pdev->dev;
88 for (i = cfg->num_clks - 1; i >= 0; i--)
89 clk_disable_unprepare(phy->clks[i]);
91 for (i = cfg->num_regs - 1; i >= 0; i--)
92 regulator_disable(phy->regs[i]);
94 pm_runtime_put_sync(dev);
97 void msm_hdmi_phy_powerup(struct hdmi_phy *phy, unsigned long int pixclock)
99 if (!phy || !phy->cfg->powerup)
102 phy->cfg->powerup(phy, pixclock);
105 void msm_hdmi_phy_powerdown(struct hdmi_phy *phy)
107 if (!phy || !phy->cfg->powerdown)
110 phy->cfg->powerdown(phy);
113 static int msm_hdmi_phy_pll_init(struct platform_device *pdev,
114 enum hdmi_phy_type type)
119 case MSM_HDMI_PHY_8960:
120 ret = msm_hdmi_pll_8960_init(pdev);
122 case MSM_HDMI_PHY_8996:
123 ret = msm_hdmi_pll_8996_init(pdev);
126 * we don't have PLL support for these, don't report an error for now
128 case MSM_HDMI_PHY_8x60:
129 case MSM_HDMI_PHY_8x74:
138 static int msm_hdmi_phy_probe(struct platform_device *pdev)
140 struct device *dev = &pdev->dev;
141 struct hdmi_phy *phy;
144 phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
148 phy->cfg = (struct hdmi_phy_cfg *)of_device_get_match_data(dev);
152 phy->mmio = msm_ioremap(pdev, "hdmi_phy", "HDMI_PHY");
153 if (IS_ERR(phy->mmio)) {
154 DRM_DEV_ERROR(dev, "%s: failed to map phy base\n", __func__);
160 ret = msm_hdmi_phy_resource_init(phy);
164 pm_runtime_enable(&pdev->dev);
166 ret = msm_hdmi_phy_resource_enable(phy);
170 ret = msm_hdmi_phy_pll_init(pdev, phy->cfg->type);
172 DRM_DEV_ERROR(dev, "couldn't init PLL\n");
173 msm_hdmi_phy_resource_disable(phy);
177 msm_hdmi_phy_resource_disable(phy);
179 platform_set_drvdata(pdev, phy);
184 static int msm_hdmi_phy_remove(struct platform_device *pdev)
186 pm_runtime_disable(&pdev->dev);
191 static const struct of_device_id msm_hdmi_phy_dt_match[] = {
192 { .compatible = "qcom,hdmi-phy-8660",
193 .data = &msm_hdmi_phy_8x60_cfg },
194 { .compatible = "qcom,hdmi-phy-8960",
195 .data = &msm_hdmi_phy_8960_cfg },
196 { .compatible = "qcom,hdmi-phy-8974",
197 .data = &msm_hdmi_phy_8x74_cfg },
198 { .compatible = "qcom,hdmi-phy-8084",
199 .data = &msm_hdmi_phy_8x74_cfg },
200 { .compatible = "qcom,hdmi-phy-8996",
201 .data = &msm_hdmi_phy_8996_cfg },
205 static struct platform_driver msm_hdmi_phy_platform_driver = {
206 .probe = msm_hdmi_phy_probe,
207 .remove = msm_hdmi_phy_remove,
209 .name = "msm_hdmi_phy",
210 .of_match_table = msm_hdmi_phy_dt_match,
214 void __init msm_hdmi_phy_driver_register(void)
216 platform_driver_register(&msm_hdmi_phy_platform_driver);
219 void __exit msm_hdmi_phy_driver_unregister(void)
221 platform_driver_unregister(&msm_hdmi_phy_platform_driver);