2 * Copyright (c) 2014 The Linux Foundation. All rights reserved.
3 * Copyright (C) 2013 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <linux/of_irq.h>
22 void hdmi_set_mode(struct hdmi
*hdmi
, bool power_on
)
27 spin_lock_irqsave(&hdmi
->reg_lock
, flags
);
29 ctrl
|= HDMI_CTRL_ENABLE
;
30 if (!hdmi
->hdmi_mode
) {
31 ctrl
|= HDMI_CTRL_HDMI
;
32 hdmi_write(hdmi
, REG_HDMI_CTRL
, ctrl
);
33 ctrl
&= ~HDMI_CTRL_HDMI
;
35 ctrl
|= HDMI_CTRL_HDMI
;
38 ctrl
= HDMI_CTRL_HDMI
;
41 hdmi_write(hdmi
, REG_HDMI_CTRL
, ctrl
);
42 spin_unlock_irqrestore(&hdmi
->reg_lock
, flags
);
43 DBG("HDMI Core: %s, HDMI_CTRL=0x%08x",
44 power_on
? "Enable" : "Disable", ctrl
);
47 static irqreturn_t
hdmi_irq(int irq
, void *dev_id
)
49 struct hdmi
*hdmi
= dev_id
;
52 hdmi_connector_irq(hdmi
->connector
);
55 hdmi_i2c_irq(hdmi
->i2c
);
59 hdmi_hdcp_irq(hdmi
->hdcp_ctrl
);
66 static void hdmi_destroy(struct hdmi
*hdmi
)
68 struct hdmi_phy
*phy
= hdmi
->phy
;
71 * at this point, hpd has been disabled,
72 * after flush workq, it's safe to deinit hdcp
75 flush_workqueue(hdmi
->workq
);
76 destroy_workqueue(hdmi
->workq
);
78 hdmi_hdcp_destroy(hdmi
);
80 phy
->funcs
->destroy(phy
);
83 hdmi_i2c_destroy(hdmi
->i2c
);
85 platform_set_drvdata(hdmi
->pdev
, NULL
);
88 /* construct hdmi at bind/probe time, grab all the resources. If
89 * we are to EPROBE_DEFER we want to do it here, rather than later
90 * at modeset_init() time
92 static struct hdmi
*hdmi_init(struct platform_device
*pdev
)
94 struct hdmi_platform_config
*config
= pdev
->dev
.platform_data
;
95 struct hdmi
*hdmi
= NULL
;
99 hdmi
= devm_kzalloc(&pdev
->dev
, sizeof(*hdmi
), GFP_KERNEL
);
106 hdmi
->config
= config
;
107 spin_lock_init(&hdmi
->reg_lock
);
109 /* not sure about which phy maps to which msm.. probably I miss some */
110 if (config
->phy_init
) {
111 hdmi
->phy
= config
->phy_init(hdmi
);
113 if (IS_ERR(hdmi
->phy
)) {
114 ret
= PTR_ERR(hdmi
->phy
);
115 dev_err(&pdev
->dev
, "failed to load phy: %d\n", ret
);
121 hdmi
->mmio
= msm_ioremap(pdev
, config
->mmio_name
, "HDMI");
122 if (IS_ERR(hdmi
->mmio
)) {
123 ret
= PTR_ERR(hdmi
->mmio
);
127 /* HDCP needs physical address of hdmi register */
128 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
130 hdmi
->mmio_phy_addr
= res
->start
;
132 hdmi
->qfprom_mmio
= msm_ioremap(pdev
,
133 config
->qfprom_mmio_name
, "HDMI_QFPROM");
134 if (IS_ERR(hdmi
->qfprom_mmio
)) {
135 dev_info(&pdev
->dev
, "can't find qfprom resource\n");
136 hdmi
->qfprom_mmio
= NULL
;
139 hdmi
->hpd_regs
= devm_kzalloc(&pdev
->dev
, sizeof(hdmi
->hpd_regs
[0]) *
140 config
->hpd_reg_cnt
, GFP_KERNEL
);
141 if (!hdmi
->hpd_regs
) {
145 for (i
= 0; i
< config
->hpd_reg_cnt
; i
++) {
146 struct regulator
*reg
;
148 reg
= devm_regulator_get(&pdev
->dev
,
149 config
->hpd_reg_names
[i
]);
152 dev_err(&pdev
->dev
, "failed to get hpd regulator: %s (%d)\n",
153 config
->hpd_reg_names
[i
], ret
);
157 hdmi
->hpd_regs
[i
] = reg
;
160 hdmi
->pwr_regs
= devm_kzalloc(&pdev
->dev
, sizeof(hdmi
->pwr_regs
[0]) *
161 config
->pwr_reg_cnt
, GFP_KERNEL
);
162 if (!hdmi
->pwr_regs
) {
166 for (i
= 0; i
< config
->pwr_reg_cnt
; i
++) {
167 struct regulator
*reg
;
169 reg
= devm_regulator_get(&pdev
->dev
,
170 config
->pwr_reg_names
[i
]);
173 dev_err(&pdev
->dev
, "failed to get pwr regulator: %s (%d)\n",
174 config
->pwr_reg_names
[i
], ret
);
178 hdmi
->pwr_regs
[i
] = reg
;
181 hdmi
->hpd_clks
= devm_kzalloc(&pdev
->dev
, sizeof(hdmi
->hpd_clks
[0]) *
182 config
->hpd_clk_cnt
, GFP_KERNEL
);
183 if (!hdmi
->hpd_clks
) {
187 for (i
= 0; i
< config
->hpd_clk_cnt
; i
++) {
190 clk
= devm_clk_get(&pdev
->dev
, config
->hpd_clk_names
[i
]);
193 dev_err(&pdev
->dev
, "failed to get hpd clk: %s (%d)\n",
194 config
->hpd_clk_names
[i
], ret
);
198 hdmi
->hpd_clks
[i
] = clk
;
201 hdmi
->pwr_clks
= devm_kzalloc(&pdev
->dev
, sizeof(hdmi
->pwr_clks
[0]) *
202 config
->pwr_clk_cnt
, GFP_KERNEL
);
203 if (!hdmi
->pwr_clks
) {
207 for (i
= 0; i
< config
->pwr_clk_cnt
; i
++) {
210 clk
= devm_clk_get(&pdev
->dev
, config
->pwr_clk_names
[i
]);
213 dev_err(&pdev
->dev
, "failed to get pwr clk: %s (%d)\n",
214 config
->pwr_clk_names
[i
], ret
);
218 hdmi
->pwr_clks
[i
] = clk
;
221 hdmi
->workq
= alloc_ordered_workqueue("msm_hdmi", 0);
223 hdmi
->i2c
= hdmi_i2c_init(hdmi
);
224 if (IS_ERR(hdmi
->i2c
)) {
225 ret
= PTR_ERR(hdmi
->i2c
);
226 dev_err(&pdev
->dev
, "failed to get i2c: %d\n", ret
);
231 hdmi
->hdcp_ctrl
= hdmi_hdcp_init(hdmi
);
232 if (IS_ERR(hdmi
->hdcp_ctrl
)) {
233 dev_warn(&pdev
->dev
, "failed to init hdcp: disabled\n");
234 hdmi
->hdcp_ctrl
= NULL
;
246 /* Second part of initialization, the drm/kms level modeset_init,
247 * constructs/initializes mode objects, etc, is called from master
248 * driver (not hdmi sub-device's probe/bind!)
250 * Any resource (regulator/clk/etc) which could be missing at boot
251 * should be handled in hdmi_init() so that failure happens from
252 * hdmi sub-device's probe.
254 int hdmi_modeset_init(struct hdmi
*hdmi
,
255 struct drm_device
*dev
, struct drm_encoder
*encoder
)
257 struct msm_drm_private
*priv
= dev
->dev_private
;
258 struct platform_device
*pdev
= hdmi
->pdev
;
262 hdmi
->encoder
= encoder
;
264 hdmi_audio_infoframe_init(&hdmi
->audio
.infoframe
);
266 hdmi
->bridge
= hdmi_bridge_init(hdmi
);
267 if (IS_ERR(hdmi
->bridge
)) {
268 ret
= PTR_ERR(hdmi
->bridge
);
269 dev_err(dev
->dev
, "failed to create HDMI bridge: %d\n", ret
);
274 hdmi
->connector
= hdmi_connector_init(hdmi
);
275 if (IS_ERR(hdmi
->connector
)) {
276 ret
= PTR_ERR(hdmi
->connector
);
277 dev_err(dev
->dev
, "failed to create HDMI connector: %d\n", ret
);
278 hdmi
->connector
= NULL
;
282 hdmi
->irq
= irq_of_parse_and_map(pdev
->dev
.of_node
, 0);
285 dev_err(dev
->dev
, "failed to get irq: %d\n", ret
);
289 ret
= devm_request_irq(&pdev
->dev
, hdmi
->irq
,
290 hdmi_irq
, IRQF_TRIGGER_HIGH
| IRQF_ONESHOT
,
293 dev_err(dev
->dev
, "failed to request IRQ%u: %d\n",
298 encoder
->bridge
= hdmi
->bridge
;
300 priv
->bridges
[priv
->num_bridges
++] = hdmi
->bridge
;
301 priv
->connectors
[priv
->num_connectors
++] = hdmi
->connector
;
303 platform_set_drvdata(pdev
, hdmi
);
308 /* bridge is normally destroyed by drm: */
310 hdmi_bridge_destroy(hdmi
->bridge
);
313 if (hdmi
->connector
) {
314 hdmi
->connector
->funcs
->destroy(hdmi
->connector
);
315 hdmi
->connector
= NULL
;
325 #include <linux/of_gpio.h>
327 #define HDMI_CFG(item, entry) \
328 .item ## _names = item ##_names_ ## entry, \
329 .item ## _cnt = ARRAY_SIZE(item ## _names_ ## entry)
331 static struct hdmi_platform_config hdmi_tx_8660_config
= {
332 .phy_init
= hdmi_phy_8x60_init
,
335 static const char *hpd_reg_names_8960
[] = {"core-vdda", "hdmi-mux"};
336 static const char *hpd_clk_names_8960
[] = {"core_clk", "master_iface_clk", "slave_iface_clk"};
338 static struct hdmi_platform_config hdmi_tx_8960_config
= {
339 .phy_init
= hdmi_phy_8960_init
,
340 HDMI_CFG(hpd_reg
, 8960),
341 HDMI_CFG(hpd_clk
, 8960),
344 static const char *pwr_reg_names_8x74
[] = {"core-vdda", "core-vcc"};
345 static const char *hpd_reg_names_8x74
[] = {"hpd-gdsc", "hpd-5v"};
346 static const char *pwr_clk_names_8x74
[] = {"extp_clk", "alt_iface_clk"};
347 static const char *hpd_clk_names_8x74
[] = {"iface_clk", "core_clk", "mdp_core_clk"};
348 static unsigned long hpd_clk_freq_8x74
[] = {0, 19200000, 0};
350 static struct hdmi_platform_config hdmi_tx_8974_config
= {
351 .phy_init
= hdmi_phy_8x74_init
,
352 HDMI_CFG(pwr_reg
, 8x74
),
353 HDMI_CFG(hpd_reg
, 8x74
),
354 HDMI_CFG(pwr_clk
, 8x74
),
355 HDMI_CFG(hpd_clk
, 8x74
),
356 .hpd_freq
= hpd_clk_freq_8x74
,
359 static const char *hpd_reg_names_8084
[] = {"hpd-gdsc", "hpd-5v", "hpd-5v-en"};
361 static struct hdmi_platform_config hdmi_tx_8084_config
= {
362 .phy_init
= hdmi_phy_8x74_init
,
363 HDMI_CFG(pwr_reg
, 8x74
),
364 HDMI_CFG(hpd_reg
, 8084),
365 HDMI_CFG(pwr_clk
, 8x74
),
366 HDMI_CFG(hpd_clk
, 8x74
),
367 .hpd_freq
= hpd_clk_freq_8x74
,
370 static const char *hpd_reg_names_8x94
[] = {};
372 static struct hdmi_platform_config hdmi_tx_8994_config
= {
373 .phy_init
= NULL
, /* nothing to do for this HDMI PHY 20nm */
374 HDMI_CFG(pwr_reg
, 8x74
),
375 HDMI_CFG(hpd_reg
, 8x94
),
376 HDMI_CFG(pwr_clk
, 8x74
),
377 HDMI_CFG(hpd_clk
, 8x74
),
378 .hpd_freq
= hpd_clk_freq_8x74
,
381 static const struct of_device_id dt_match
[] = {
382 { .compatible
= "qcom,hdmi-tx-8994", .data
= &hdmi_tx_8994_config
},
383 { .compatible
= "qcom,hdmi-tx-8084", .data
= &hdmi_tx_8084_config
},
384 { .compatible
= "qcom,hdmi-tx-8974", .data
= &hdmi_tx_8974_config
},
385 { .compatible
= "qcom,hdmi-tx-8960", .data
= &hdmi_tx_8960_config
},
386 { .compatible
= "qcom,hdmi-tx-8660", .data
= &hdmi_tx_8660_config
},
391 static int get_gpio(struct device
*dev
, struct device_node
*of_node
, const char *name
)
393 int gpio
= of_get_named_gpio(of_node
, name
, 0);
396 snprintf(name2
, sizeof(name2
), "%s-gpio", name
);
397 gpio
= of_get_named_gpio(of_node
, name2
, 0);
399 DBG("failed to get gpio: %s (%d)", name
, gpio
);
407 static int hdmi_bind(struct device
*dev
, struct device
*master
, void *data
)
409 struct drm_device
*drm
= dev_get_drvdata(master
);
410 struct msm_drm_private
*priv
= drm
->dev_private
;
411 static struct hdmi_platform_config
*hdmi_cfg
;
414 struct device_node
*of_node
= dev
->of_node
;
415 const struct of_device_id
*match
;
417 match
= of_match_node(dt_match
, of_node
);
418 if (match
&& match
->data
) {
419 hdmi_cfg
= (struct hdmi_platform_config
*)match
->data
;
420 DBG("hdmi phy: %s", match
->compatible
);
422 dev_err(dev
, "unknown phy: %s\n", of_node
->name
);
426 hdmi_cfg
->mmio_name
= "core_physical";
427 hdmi_cfg
->qfprom_mmio_name
= "qfprom_physical";
428 hdmi_cfg
->ddc_clk_gpio
= get_gpio(dev
, of_node
, "qcom,hdmi-tx-ddc-clk");
429 hdmi_cfg
->ddc_data_gpio
= get_gpio(dev
, of_node
, "qcom,hdmi-tx-ddc-data");
430 hdmi_cfg
->hpd_gpio
= get_gpio(dev
, of_node
, "qcom,hdmi-tx-hpd");
431 hdmi_cfg
->mux_en_gpio
= get_gpio(dev
, of_node
, "qcom,hdmi-tx-mux-en");
432 hdmi_cfg
->mux_sel_gpio
= get_gpio(dev
, of_node
, "qcom,hdmi-tx-mux-sel");
433 hdmi_cfg
->mux_lpm_gpio
= get_gpio(dev
, of_node
, "qcom,hdmi-tx-mux-lpm");
436 static struct hdmi_platform_config config
= {};
437 static const char *hpd_clk_names
[] = {
438 "core_clk", "master_iface_clk", "slave_iface_clk",
440 if (cpu_is_apq8064()) {
441 static const char *hpd_reg_names
[] = {"8921_hdmi_mvs"};
442 config
.phy_init
= hdmi_phy_8960_init
;
443 config
.hpd_reg_names
= hpd_reg_names
;
444 config
.hpd_reg_cnt
= ARRAY_SIZE(hpd_reg_names
);
445 config
.hpd_clk_names
= hpd_clk_names
;
446 config
.hpd_clk_cnt
= ARRAY_SIZE(hpd_clk_names
);
447 config
.ddc_clk_gpio
= 70;
448 config
.ddc_data_gpio
= 71;
449 config
.hpd_gpio
= 72;
450 config
.mux_en_gpio
= -1;
451 config
.mux_sel_gpio
= -1;
452 } else if (cpu_is_msm8960() || cpu_is_msm8960ab()) {
453 static const char *hpd_reg_names
[] = {"8921_hdmi_mvs"};
454 config
.phy_init
= hdmi_phy_8960_init
;
455 config
.hpd_reg_names
= hpd_reg_names
;
456 config
.hpd_reg_cnt
= ARRAY_SIZE(hpd_reg_names
);
457 config
.hpd_clk_names
= hpd_clk_names
;
458 config
.hpd_clk_cnt
= ARRAY_SIZE(hpd_clk_names
);
459 config
.ddc_clk_gpio
= 100;
460 config
.ddc_data_gpio
= 101;
461 config
.hpd_gpio
= 102;
462 config
.mux_en_gpio
= -1;
463 config
.mux_sel_gpio
= -1;
464 } else if (cpu_is_msm8x60()) {
465 static const char *hpd_reg_names
[] = {
466 "8901_hdmi_mvs", "8901_mpp0"
468 config
.phy_init
= hdmi_phy_8x60_init
;
469 config
.hpd_reg_names
= hpd_reg_names
;
470 config
.hpd_reg_cnt
= ARRAY_SIZE(hpd_reg_names
);
471 config
.hpd_clk_names
= hpd_clk_names
;
472 config
.hpd_clk_cnt
= ARRAY_SIZE(hpd_clk_names
);
473 config
.ddc_clk_gpio
= 170;
474 config
.ddc_data_gpio
= 171;
475 config
.hpd_gpio
= 172;
476 config
.mux_en_gpio
= -1;
477 config
.mux_sel_gpio
= -1;
479 config
.mmio_name
= "hdmi_msm_hdmi_addr";
480 config
.qfprom_mmio_name
= "hdmi_msm_qfprom_addr";
484 dev
->platform_data
= hdmi_cfg
;
486 hdmi
= hdmi_init(to_platform_device(dev
));
488 return PTR_ERR(hdmi
);
494 static void hdmi_unbind(struct device
*dev
, struct device
*master
,
497 struct drm_device
*drm
= dev_get_drvdata(master
);
498 struct msm_drm_private
*priv
= drm
->dev_private
;
500 hdmi_destroy(priv
->hdmi
);
505 static const struct component_ops hdmi_ops
= {
507 .unbind
= hdmi_unbind
,
510 static int hdmi_dev_probe(struct platform_device
*pdev
)
512 return component_add(&pdev
->dev
, &hdmi_ops
);
515 static int hdmi_dev_remove(struct platform_device
*pdev
)
517 component_del(&pdev
->dev
, &hdmi_ops
);
521 static struct platform_driver hdmi_driver
= {
522 .probe
= hdmi_dev_probe
,
523 .remove
= hdmi_dev_remove
,
526 .of_match_table
= dt_match
,
530 void __init
hdmi_register(void)
532 platform_driver_register(&hdmi_driver
);
535 void __exit
hdmi_unregister(void)
537 platform_driver_unregister(&hdmi_driver
);