1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2018 MediaTek Inc.
7 #include "phy-mtk-hdmi.h"
9 static int mtk_hdmi_phy_power_on(struct phy *phy);
10 static int mtk_hdmi_phy_power_off(struct phy *phy);
12 static const struct phy_ops mtk_hdmi_phy_dev_ops = {
13 .power_on = mtk_hdmi_phy_power_on,
14 .power_off = mtk_hdmi_phy_power_off,
18 void mtk_hdmi_phy_clear_bits(struct mtk_hdmi_phy *hdmi_phy, u32 offset,
21 void __iomem *reg = hdmi_phy->regs + offset;
29 void mtk_hdmi_phy_set_bits(struct mtk_hdmi_phy *hdmi_phy, u32 offset,
32 void __iomem *reg = hdmi_phy->regs + offset;
40 void mtk_hdmi_phy_mask(struct mtk_hdmi_phy *hdmi_phy, u32 offset,
43 void __iomem *reg = hdmi_phy->regs + offset;
47 tmp = (tmp & ~mask) | (val & mask);
51 inline struct mtk_hdmi_phy *to_mtk_hdmi_phy(struct clk_hw *hw)
53 return container_of(hw, struct mtk_hdmi_phy, pll_hw);
56 static int mtk_hdmi_phy_power_on(struct phy *phy)
58 struct mtk_hdmi_phy *hdmi_phy = phy_get_drvdata(phy);
61 ret = clk_prepare_enable(hdmi_phy->pll);
65 hdmi_phy->conf->hdmi_phy_enable_tmds(hdmi_phy);
69 static int mtk_hdmi_phy_power_off(struct phy *phy)
71 struct mtk_hdmi_phy *hdmi_phy = phy_get_drvdata(phy);
73 hdmi_phy->conf->hdmi_phy_disable_tmds(hdmi_phy);
74 clk_disable_unprepare(hdmi_phy->pll);
79 static const struct phy_ops *
80 mtk_hdmi_phy_dev_get_ops(const struct mtk_hdmi_phy *hdmi_phy)
82 if (hdmi_phy && hdmi_phy->conf &&
83 hdmi_phy->conf->hdmi_phy_enable_tmds &&
84 hdmi_phy->conf->hdmi_phy_disable_tmds)
85 return &mtk_hdmi_phy_dev_ops;
88 dev_err(hdmi_phy->dev, "Failed to get dev ops of phy\n");
92 static void mtk_hdmi_phy_clk_get_data(struct mtk_hdmi_phy *hdmi_phy,
93 struct clk_init_data *clk_init)
95 clk_init->flags = hdmi_phy->conf->flags;
96 clk_init->ops = hdmi_phy->conf->hdmi_phy_clk_ops;
99 static int mtk_hdmi_phy_probe(struct platform_device *pdev)
101 struct device *dev = &pdev->dev;
102 struct mtk_hdmi_phy *hdmi_phy;
104 const char *ref_clk_name;
105 struct clk_init_data clk_init = {
107 .parent_names = (const char * const *)&ref_clk_name,
111 struct phy_provider *phy_provider;
114 hdmi_phy = devm_kzalloc(dev, sizeof(*hdmi_phy), GFP_KERNEL);
118 hdmi_phy->regs = devm_platform_ioremap_resource(pdev, 0);
119 if (IS_ERR(hdmi_phy->regs))
120 return PTR_ERR(hdmi_phy->regs);
122 ref_clk = devm_clk_get(dev, "pll_ref");
124 return dev_err_probe(dev, PTR_ERR(ref_clk),
125 "Failed to get PLL reference clock\n");
127 ref_clk_name = __clk_get_name(ref_clk);
129 ret = of_property_read_string(dev->of_node, "clock-output-names",
132 return dev_err_probe(dev, ret, "Failed to read clock-output-names\n");
136 (struct mtk_hdmi_phy_conf *)of_device_get_match_data(dev);
137 mtk_hdmi_phy_clk_get_data(hdmi_phy, &clk_init);
138 hdmi_phy->pll_hw.init = &clk_init;
139 hdmi_phy->pll = devm_clk_register(dev, &hdmi_phy->pll_hw);
140 if (IS_ERR(hdmi_phy->pll))
141 return dev_err_probe(dev, PTR_ERR(hdmi_phy->pll),
142 "Failed to register PLL\n");
144 ret = of_property_read_u32(dev->of_node, "mediatek,ibias",
147 return dev_err_probe(dev, ret, "Failed to get ibias\n");
149 ret = of_property_read_u32(dev->of_node, "mediatek,ibias_up",
150 &hdmi_phy->ibias_up);
152 return dev_err_probe(dev, ret, "Failed to get ibias_up\n");
154 dev_info(dev, "Using default TX DRV impedance: 4.2k/36\n");
155 hdmi_phy->drv_imp_clk = 0x30;
156 hdmi_phy->drv_imp_d2 = 0x30;
157 hdmi_phy->drv_imp_d1 = 0x30;
158 hdmi_phy->drv_imp_d0 = 0x30;
160 phy = devm_phy_create(dev, NULL, mtk_hdmi_phy_dev_get_ops(hdmi_phy));
162 return dev_err_probe(dev, PTR_ERR(phy), "Cannot create HDMI PHY\n");
164 phy_set_drvdata(phy, hdmi_phy);
166 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
167 if (IS_ERR(phy_provider))
168 return dev_err_probe(dev, PTR_ERR(phy_provider),
169 "Failed to register HDMI PHY\n");
171 if (hdmi_phy->conf->pll_default_off)
172 hdmi_phy->conf->hdmi_phy_disable_tmds(hdmi_phy);
174 return of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
178 static const struct of_device_id mtk_hdmi_phy_match[] = {
179 { .compatible = "mediatek,mt2701-hdmi-phy",
180 .data = &mtk_hdmi_phy_2701_conf,
182 { .compatible = "mediatek,mt8173-hdmi-phy",
183 .data = &mtk_hdmi_phy_8173_conf,
187 MODULE_DEVICE_TABLE(of, mtk_hdmi_phy_match);
189 static struct platform_driver mtk_hdmi_phy_driver = {
190 .probe = mtk_hdmi_phy_probe,
192 .name = "mediatek-hdmi-phy",
193 .of_match_table = mtk_hdmi_phy_match,
196 module_platform_driver(mtk_hdmi_phy_driver);
198 MODULE_DESCRIPTION("MediaTek HDMI PHY Driver");
199 MODULE_LICENSE("GPL v2");