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 phy->regs[i].supply = cfg->reg_names[i];
29 ret = devm_regulator_bulk_get(dev, cfg->num_regs, phy->regs);
31 if (ret != -EPROBE_DEFER)
32 DRM_DEV_ERROR(dev, "failed to get phy regulators: %d\n", ret);
37 for (i = 0; i < cfg->num_clks; i++) {
40 clk = msm_clk_get(phy->pdev, cfg->clk_names[i]);
43 DRM_DEV_ERROR(dev, "failed to get phy clock: %s (%d)\n",
44 cfg->clk_names[i], ret);
54 int msm_hdmi_phy_resource_enable(struct hdmi_phy *phy)
56 struct hdmi_phy_cfg *cfg = phy->cfg;
57 struct device *dev = &phy->pdev->dev;
60 pm_runtime_get_sync(dev);
62 ret = regulator_bulk_enable(cfg->num_regs, phy->regs);
64 DRM_DEV_ERROR(dev, "failed to enable regulators: (%d)\n", ret);
68 for (i = 0; i < cfg->num_clks; i++) {
69 ret = clk_prepare_enable(phy->clks[i]);
71 DRM_DEV_ERROR(dev, "failed to enable clock: %s (%d)\n",
72 cfg->clk_names[i], ret);
78 void msm_hdmi_phy_resource_disable(struct hdmi_phy *phy)
80 struct hdmi_phy_cfg *cfg = phy->cfg;
81 struct device *dev = &phy->pdev->dev;
84 for (i = cfg->num_clks - 1; i >= 0; i--)
85 clk_disable_unprepare(phy->clks[i]);
87 regulator_bulk_disable(cfg->num_regs, phy->regs);
89 pm_runtime_put_sync(dev);
92 void msm_hdmi_phy_powerup(struct hdmi_phy *phy, unsigned long int pixclock)
94 if (!phy || !phy->cfg->powerup)
97 phy->cfg->powerup(phy, pixclock);
100 void msm_hdmi_phy_powerdown(struct hdmi_phy *phy)
102 if (!phy || !phy->cfg->powerdown)
105 phy->cfg->powerdown(phy);
108 static int msm_hdmi_phy_pll_init(struct platform_device *pdev,
109 enum hdmi_phy_type type)
114 case MSM_HDMI_PHY_8960:
115 ret = msm_hdmi_pll_8960_init(pdev);
117 case MSM_HDMI_PHY_8996:
118 ret = msm_hdmi_pll_8996_init(pdev);
121 * we don't have PLL support for these, don't report an error for now
123 case MSM_HDMI_PHY_8x60:
124 case MSM_HDMI_PHY_8x74:
133 static int msm_hdmi_phy_probe(struct platform_device *pdev)
135 struct device *dev = &pdev->dev;
136 struct hdmi_phy *phy;
139 phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
143 phy->cfg = (struct hdmi_phy_cfg *)of_device_get_match_data(dev);
147 phy->mmio = msm_ioremap(pdev, "hdmi_phy");
148 if (IS_ERR(phy->mmio)) {
149 DRM_DEV_ERROR(dev, "%s: failed to map phy base\n", __func__);
155 ret = msm_hdmi_phy_resource_init(phy);
159 pm_runtime_enable(&pdev->dev);
161 ret = msm_hdmi_phy_resource_enable(phy);
165 ret = msm_hdmi_phy_pll_init(pdev, phy->cfg->type);
167 DRM_DEV_ERROR(dev, "couldn't init PLL\n");
168 msm_hdmi_phy_resource_disable(phy);
172 msm_hdmi_phy_resource_disable(phy);
174 platform_set_drvdata(pdev, phy);
179 static int msm_hdmi_phy_remove(struct platform_device *pdev)
181 pm_runtime_disable(&pdev->dev);
186 static const struct of_device_id msm_hdmi_phy_dt_match[] = {
187 { .compatible = "qcom,hdmi-phy-8660",
188 .data = &msm_hdmi_phy_8x60_cfg },
189 { .compatible = "qcom,hdmi-phy-8960",
190 .data = &msm_hdmi_phy_8960_cfg },
191 { .compatible = "qcom,hdmi-phy-8974",
192 .data = &msm_hdmi_phy_8x74_cfg },
193 { .compatible = "qcom,hdmi-phy-8084",
194 .data = &msm_hdmi_phy_8x74_cfg },
195 { .compatible = "qcom,hdmi-phy-8996",
196 .data = &msm_hdmi_phy_8996_cfg },
200 static struct platform_driver msm_hdmi_phy_platform_driver = {
201 .probe = msm_hdmi_phy_probe,
202 .remove = msm_hdmi_phy_remove,
204 .name = "msm_hdmi_phy",
205 .of_match_table = msm_hdmi_phy_dt_match,
209 void __init msm_hdmi_phy_driver_register(void)
211 platform_driver_register(&msm_hdmi_phy_platform_driver);
214 void __exit msm_hdmi_phy_driver_unregister(void)
216 platform_driver_unregister(&msm_hdmi_phy_platform_driver);