2 * Copyright (C) 2013 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <linux/of_irq.h>
21 void hdmi_set_mode(struct hdmi *hdmi, bool power_on)
26 ctrl |= HDMI_CTRL_ENABLE;
27 if (!hdmi->hdmi_mode) {
28 ctrl |= HDMI_CTRL_HDMI;
29 hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
30 ctrl &= ~HDMI_CTRL_HDMI;
32 ctrl |= HDMI_CTRL_HDMI;
35 ctrl = HDMI_CTRL_HDMI;
38 hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
39 DBG("HDMI Core: %s, HDMI_CTRL=0x%08x",
40 power_on ? "Enable" : "Disable", ctrl);
43 static irqreturn_t hdmi_irq(int irq, void *dev_id)
45 struct hdmi *hdmi = dev_id;
48 hdmi_connector_irq(hdmi->connector);
51 hdmi_i2c_irq(hdmi->i2c);
58 static void hdmi_destroy(struct hdmi *hdmi)
60 struct hdmi_phy *phy = hdmi->phy;
63 phy->funcs->destroy(phy);
66 hdmi_i2c_destroy(hdmi->i2c);
68 platform_set_drvdata(hdmi->pdev, NULL);
71 /* construct hdmi at bind/probe time, grab all the resources. If
72 * we are to EPROBE_DEFER we want to do it here, rather than later
73 * at modeset_init() time
75 static struct hdmi *hdmi_init(struct platform_device *pdev)
77 struct hdmi_platform_config *config = pdev->dev.platform_data;
78 struct hdmi *hdmi = NULL;
81 hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
88 hdmi->config = config;
90 /* not sure about which phy maps to which msm.. probably I miss some */
92 hdmi->phy = config->phy_init(hdmi);
94 hdmi->phy = ERR_PTR(-ENXIO);
96 if (IS_ERR(hdmi->phy)) {
97 ret = PTR_ERR(hdmi->phy);
98 dev_err(&pdev->dev, "failed to load phy: %d\n", ret);
103 hdmi->mmio = msm_ioremap(pdev, config->mmio_name, "HDMI");
104 if (IS_ERR(hdmi->mmio)) {
105 ret = PTR_ERR(hdmi->mmio);
109 BUG_ON(config->hpd_reg_cnt > ARRAY_SIZE(hdmi->hpd_regs));
110 for (i = 0; i < config->hpd_reg_cnt; i++) {
111 struct regulator *reg;
113 reg = devm_regulator_get(&pdev->dev,
114 config->hpd_reg_names[i]);
117 dev_err(&pdev->dev, "failed to get hpd regulator: %s (%d)\n",
118 config->hpd_reg_names[i], ret);
122 hdmi->hpd_regs[i] = reg;
125 BUG_ON(config->pwr_reg_cnt > ARRAY_SIZE(hdmi->pwr_regs));
126 for (i = 0; i < config->pwr_reg_cnt; i++) {
127 struct regulator *reg;
129 reg = devm_regulator_get(&pdev->dev,
130 config->pwr_reg_names[i]);
133 dev_err(&pdev->dev, "failed to get pwr regulator: %s (%d)\n",
134 config->pwr_reg_names[i], ret);
138 hdmi->pwr_regs[i] = reg;
141 BUG_ON(config->hpd_clk_cnt > ARRAY_SIZE(hdmi->hpd_clks));
142 for (i = 0; i < config->hpd_clk_cnt; i++) {
145 clk = devm_clk_get(&pdev->dev, config->hpd_clk_names[i]);
148 dev_err(&pdev->dev, "failed to get hpd clk: %s (%d)\n",
149 config->hpd_clk_names[i], ret);
153 hdmi->hpd_clks[i] = clk;
156 BUG_ON(config->pwr_clk_cnt > ARRAY_SIZE(hdmi->pwr_clks));
157 for (i = 0; i < config->pwr_clk_cnt; i++) {
160 clk = devm_clk_get(&pdev->dev, config->pwr_clk_names[i]);
163 dev_err(&pdev->dev, "failed to get pwr clk: %s (%d)\n",
164 config->pwr_clk_names[i], ret);
168 hdmi->pwr_clks[i] = clk;
171 hdmi->i2c = hdmi_i2c_init(hdmi);
172 if (IS_ERR(hdmi->i2c)) {
173 ret = PTR_ERR(hdmi->i2c);
174 dev_err(&pdev->dev, "failed to get i2c: %d\n", ret);
188 /* Second part of initialization, the drm/kms level modeset_init,
189 * constructs/initializes mode objects, etc, is called from master
190 * driver (not hdmi sub-device's probe/bind!)
192 * Any resource (regulator/clk/etc) which could be missing at boot
193 * should be handled in hdmi_init() so that failure happens from
194 * hdmi sub-device's probe.
196 int hdmi_modeset_init(struct hdmi *hdmi,
197 struct drm_device *dev, struct drm_encoder *encoder)
199 struct msm_drm_private *priv = dev->dev_private;
200 struct platform_device *pdev = hdmi->pdev;
204 hdmi->encoder = encoder;
206 hdmi_audio_infoframe_init(&hdmi->audio.infoframe);
208 hdmi->bridge = hdmi_bridge_init(hdmi);
209 if (IS_ERR(hdmi->bridge)) {
210 ret = PTR_ERR(hdmi->bridge);
211 dev_err(dev->dev, "failed to create HDMI bridge: %d\n", ret);
216 hdmi->connector = hdmi_connector_init(hdmi);
217 if (IS_ERR(hdmi->connector)) {
218 ret = PTR_ERR(hdmi->connector);
219 dev_err(dev->dev, "failed to create HDMI connector: %d\n", ret);
220 hdmi->connector = NULL;
224 hdmi->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
227 dev_err(dev->dev, "failed to get irq: %d\n", ret);
231 ret = devm_request_irq(&pdev->dev, hdmi->irq,
232 hdmi_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
235 dev_err(dev->dev, "failed to request IRQ%u: %d\n",
240 encoder->bridge = hdmi->bridge;
242 priv->bridges[priv->num_bridges++] = hdmi->bridge;
243 priv->connectors[priv->num_connectors++] = hdmi->connector;
245 platform_set_drvdata(pdev, hdmi);
250 /* bridge is normally destroyed by drm: */
252 hdmi_bridge_destroy(hdmi->bridge);
255 if (hdmi->connector) {
256 hdmi->connector->funcs->destroy(hdmi->connector);
257 hdmi->connector = NULL;
267 #include <linux/of_gpio.h>
270 static int get_gpio(struct device *dev, struct device_node *of_node, const char *name)
272 int gpio = of_get_named_gpio(of_node, name, 0);
275 snprintf(name2, sizeof(name2), "%s-gpio", name);
276 gpio = of_get_named_gpio(of_node, name2, 0);
278 dev_err(dev, "failed to get gpio: %s (%d)\n",
287 static int hdmi_bind(struct device *dev, struct device *master, void *data)
289 struct drm_device *drm = dev_get_drvdata(master);
290 struct msm_drm_private *priv = drm->dev_private;
291 static struct hdmi_platform_config config = {};
294 struct device_node *of_node = dev->of_node;
296 if (of_device_is_compatible(of_node, "qcom,hdmi-tx-8074")) {
297 static const char *hpd_reg_names[] = {"hpd-gdsc", "hpd-5v"};
298 static const char *pwr_reg_names[] = {"core-vdda", "core-vcc"};
299 static const char *hpd_clk_names[] = {"iface_clk", "core_clk", "mdp_core_clk"};
300 static unsigned long hpd_clk_freq[] = {0, 19200000, 0};
301 static const char *pwr_clk_names[] = {"extp_clk", "alt_iface_clk"};
302 config.phy_init = hdmi_phy_8x74_init;
303 config.hpd_reg_names = hpd_reg_names;
304 config.hpd_reg_cnt = ARRAY_SIZE(hpd_reg_names);
305 config.pwr_reg_names = pwr_reg_names;
306 config.pwr_reg_cnt = ARRAY_SIZE(pwr_reg_names);
307 config.hpd_clk_names = hpd_clk_names;
308 config.hpd_freq = hpd_clk_freq;
309 config.hpd_clk_cnt = ARRAY_SIZE(hpd_clk_names);
310 config.pwr_clk_names = pwr_clk_names;
311 config.pwr_clk_cnt = ARRAY_SIZE(pwr_clk_names);
312 } else if (of_device_is_compatible(of_node, "qcom,hdmi-tx-8960")) {
313 static const char *hpd_clk_names[] = {"core_clk", "master_iface_clk", "slave_iface_clk"};
314 static const char *hpd_reg_names[] = {"core-vdda", "hdmi-mux"};
315 config.phy_init = hdmi_phy_8960_init;
316 config.hpd_reg_names = hpd_reg_names;
317 config.hpd_reg_cnt = ARRAY_SIZE(hpd_reg_names);
318 config.hpd_clk_names = hpd_clk_names;
319 config.hpd_clk_cnt = ARRAY_SIZE(hpd_clk_names);
320 } else if (of_device_is_compatible(of_node, "qcom,hdmi-tx-8660")) {
321 config.phy_init = hdmi_phy_8x60_init;
323 dev_err(dev, "unknown phy: %s\n", of_node->name);
326 config.mmio_name = "core_physical";
327 config.ddc_clk_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-ddc-clk");
328 config.ddc_data_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-ddc-data");
329 config.hpd_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-hpd");
330 config.mux_en_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-mux-en");
331 config.mux_sel_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-mux-sel");
332 config.mux_lpm_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-mux-lpm");
335 static const char *hpd_clk_names[] = {
336 "core_clk", "master_iface_clk", "slave_iface_clk",
338 if (cpu_is_apq8064()) {
339 static const char *hpd_reg_names[] = {"8921_hdmi_mvs"};
340 config.phy_init = hdmi_phy_8960_init;
341 config.mmio_name = "hdmi_msm_hdmi_addr";
342 config.hpd_reg_names = hpd_reg_names;
343 config.hpd_reg_cnt = ARRAY_SIZE(hpd_reg_names);
344 config.hpd_clk_names = hpd_clk_names;
345 config.hpd_clk_cnt = ARRAY_SIZE(hpd_clk_names);
346 config.ddc_clk_gpio = 70;
347 config.ddc_data_gpio = 71;
348 config.hpd_gpio = 72;
349 config.mux_en_gpio = -1;
350 config.mux_sel_gpio = -1;
351 } else if (cpu_is_msm8960() || cpu_is_msm8960ab()) {
352 static const char *hpd_reg_names[] = {"8921_hdmi_mvs"};
353 config.phy_init = hdmi_phy_8960_init;
354 config.mmio_name = "hdmi_msm_hdmi_addr";
355 config.hpd_reg_names = hpd_reg_names;
356 config.hpd_reg_cnt = ARRAY_SIZE(hpd_reg_names);
357 config.hpd_clk_names = hpd_clk_names;
358 config.hpd_clk_cnt = ARRAY_SIZE(hpd_clk_names);
359 config.ddc_clk_gpio = 100;
360 config.ddc_data_gpio = 101;
361 config.hpd_gpio = 102;
362 config.mux_en_gpio = -1;
363 config.mux_sel_gpio = -1;
364 } else if (cpu_is_msm8x60()) {
365 static const char *hpd_reg_names[] = {
366 "8901_hdmi_mvs", "8901_mpp0"
368 config.phy_init = hdmi_phy_8x60_init;
369 config.mmio_name = "hdmi_msm_hdmi_addr";
370 config.hpd_reg_names = hpd_reg_names;
371 config.hpd_reg_cnt = ARRAY_SIZE(hpd_reg_names);
372 config.hpd_clk_names = hpd_clk_names;
373 config.hpd_clk_cnt = ARRAY_SIZE(hpd_clk_names);
374 config.ddc_clk_gpio = 170;
375 config.ddc_data_gpio = 171;
376 config.hpd_gpio = 172;
377 config.mux_en_gpio = -1;
378 config.mux_sel_gpio = -1;
381 dev->platform_data = &config;
382 hdmi = hdmi_init(to_platform_device(dev));
384 return PTR_ERR(hdmi);
389 static void hdmi_unbind(struct device *dev, struct device *master,
392 struct drm_device *drm = dev_get_drvdata(master);
393 struct msm_drm_private *priv = drm->dev_private;
395 hdmi_destroy(priv->hdmi);
400 static const struct component_ops hdmi_ops = {
402 .unbind = hdmi_unbind,
405 static int hdmi_dev_probe(struct platform_device *pdev)
407 return component_add(&pdev->dev, &hdmi_ops);
410 static int hdmi_dev_remove(struct platform_device *pdev)
412 component_del(&pdev->dev, &hdmi_ops);
416 static const struct of_device_id dt_match[] = {
417 { .compatible = "qcom,hdmi-tx-8074" },
418 { .compatible = "qcom,hdmi-tx-8960" },
419 { .compatible = "qcom,hdmi-tx-8660" },
423 static struct platform_driver hdmi_driver = {
424 .probe = hdmi_dev_probe,
425 .remove = hdmi_dev_remove,
428 .of_match_table = dt_match,
432 void __init hdmi_register(void)
434 platform_driver_register(&hdmi_driver);
437 void __exit hdmi_unregister(void)
439 platform_driver_unregister(&hdmi_driver);