1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2016, The Linux Foundation. All rights reserved.
7 #include <linux/platform_device.h>
11 static int msm_hdmi_phy_resource_init(struct hdmi_phy *phy)
13 struct hdmi_phy_cfg *cfg = phy->cfg;
14 struct device *dev = &phy->pdev->dev;
17 phy->regs = devm_kcalloc(dev, cfg->num_regs, sizeof(phy->regs[0]),
22 phy->clks = devm_kcalloc(dev, cfg->num_clks, sizeof(phy->clks[0]),
27 for (i = 0; i < cfg->num_regs; i++)
28 phy->regs[i].supply = cfg->reg_names[i];
30 ret = devm_regulator_bulk_get(dev, cfg->num_regs, phy->regs);
32 if (ret != -EPROBE_DEFER)
33 DRM_DEV_ERROR(dev, "failed to get phy regulators: %d\n", ret);
38 for (i = 0; i < cfg->num_clks; i++) {
41 clk = msm_clk_get(phy->pdev, cfg->clk_names[i]);
44 DRM_DEV_ERROR(dev, "failed to get phy clock: %s (%d)\n",
45 cfg->clk_names[i], ret);
55 int msm_hdmi_phy_resource_enable(struct hdmi_phy *phy)
57 struct hdmi_phy_cfg *cfg = phy->cfg;
58 struct device *dev = &phy->pdev->dev;
61 pm_runtime_get_sync(dev);
63 ret = regulator_bulk_enable(cfg->num_regs, phy->regs);
65 DRM_DEV_ERROR(dev, "failed to enable regulators: (%d)\n", ret);
69 for (i = 0; i < cfg->num_clks; i++) {
70 ret = clk_prepare_enable(phy->clks[i]);
72 DRM_DEV_ERROR(dev, "failed to enable clock: %s (%d)\n",
73 cfg->clk_names[i], ret);
79 void msm_hdmi_phy_resource_disable(struct hdmi_phy *phy)
81 struct hdmi_phy_cfg *cfg = phy->cfg;
82 struct device *dev = &phy->pdev->dev;
85 for (i = cfg->num_clks - 1; i >= 0; i--)
86 clk_disable_unprepare(phy->clks[i]);
88 regulator_bulk_disable(cfg->num_regs, phy->regs);
90 pm_runtime_put_sync(dev);
93 void msm_hdmi_phy_powerup(struct hdmi_phy *phy, unsigned long int pixclock)
95 if (!phy || !phy->cfg->powerup)
98 phy->cfg->powerup(phy, pixclock);
101 void msm_hdmi_phy_powerdown(struct hdmi_phy *phy)
103 if (!phy || !phy->cfg->powerdown)
106 phy->cfg->powerdown(phy);
109 static int msm_hdmi_phy_pll_init(struct platform_device *pdev,
110 enum hdmi_phy_type type)
115 case MSM_HDMI_PHY_8960:
116 ret = msm_hdmi_pll_8960_init(pdev);
118 case MSM_HDMI_PHY_8996:
119 ret = msm_hdmi_pll_8996_init(pdev);
122 * we don't have PLL support for these, don't report an error for now
124 case MSM_HDMI_PHY_8x60:
125 case MSM_HDMI_PHY_8x74:
134 static int msm_hdmi_phy_probe(struct platform_device *pdev)
136 struct device *dev = &pdev->dev;
137 struct hdmi_phy *phy;
140 phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
144 phy->cfg = (struct hdmi_phy_cfg *)of_device_get_match_data(dev);
148 phy->mmio = msm_ioremap(pdev, "hdmi_phy");
149 if (IS_ERR(phy->mmio)) {
150 DRM_DEV_ERROR(dev, "%s: failed to map phy base\n", __func__);
156 ret = msm_hdmi_phy_resource_init(phy);
160 pm_runtime_enable(&pdev->dev);
162 ret = msm_hdmi_phy_resource_enable(phy);
166 ret = msm_hdmi_phy_pll_init(pdev, phy->cfg->type);
168 DRM_DEV_ERROR(dev, "couldn't init PLL\n");
169 msm_hdmi_phy_resource_disable(phy);
173 msm_hdmi_phy_resource_disable(phy);
175 platform_set_drvdata(pdev, phy);
180 static void msm_hdmi_phy_remove(struct platform_device *pdev)
182 pm_runtime_disable(&pdev->dev);
185 static const struct of_device_id msm_hdmi_phy_dt_match[] = {
186 { .compatible = "qcom,hdmi-phy-8660",
187 .data = &msm_hdmi_phy_8x60_cfg },
188 { .compatible = "qcom,hdmi-phy-8960",
189 .data = &msm_hdmi_phy_8960_cfg },
190 { .compatible = "qcom,hdmi-phy-8974",
191 .data = &msm_hdmi_phy_8x74_cfg },
192 { .compatible = "qcom,hdmi-phy-8084",
193 .data = &msm_hdmi_phy_8x74_cfg },
194 { .compatible = "qcom,hdmi-phy-8996",
195 .data = &msm_hdmi_phy_8996_cfg },
199 static struct platform_driver msm_hdmi_phy_platform_driver = {
200 .probe = msm_hdmi_phy_probe,
201 .remove_new = msm_hdmi_phy_remove,
203 .name = "msm_hdmi_phy",
204 .of_match_table = msm_hdmi_phy_dt_match,
208 void __init msm_hdmi_phy_driver_register(void)
210 platform_driver_register(&msm_hdmi_phy_platform_driver);
213 void __exit msm_hdmi_phy_driver_unregister(void)
215 platform_driver_unregister(&msm_hdmi_phy_platform_driver);