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>
20 #include <linux/of_gpio.h>
24 void hdmi_set_mode(struct hdmi
*hdmi
, bool power_on
)
29 spin_lock_irqsave(&hdmi
->reg_lock
, flags
);
31 ctrl
|= HDMI_CTRL_ENABLE
;
32 if (!hdmi
->hdmi_mode
) {
33 ctrl
|= HDMI_CTRL_HDMI
;
34 hdmi_write(hdmi
, REG_HDMI_CTRL
, ctrl
);
35 ctrl
&= ~HDMI_CTRL_HDMI
;
37 ctrl
|= HDMI_CTRL_HDMI
;
40 ctrl
= HDMI_CTRL_HDMI
;
43 hdmi_write(hdmi
, REG_HDMI_CTRL
, ctrl
);
44 spin_unlock_irqrestore(&hdmi
->reg_lock
, flags
);
45 DBG("HDMI Core: %s, HDMI_CTRL=0x%08x",
46 power_on
? "Enable" : "Disable", ctrl
);
49 static irqreturn_t
hdmi_irq(int irq
, void *dev_id
)
51 struct hdmi
*hdmi
= dev_id
;
54 hdmi_connector_irq(hdmi
->connector
);
57 hdmi_i2c_irq(hdmi
->i2c
);
61 hdmi_hdcp_irq(hdmi
->hdcp_ctrl
);
68 static void hdmi_destroy(struct hdmi
*hdmi
)
70 struct hdmi_phy
*phy
= hdmi
->phy
;
73 * at this point, hpd has been disabled,
74 * after flush workq, it's safe to deinit hdcp
77 flush_workqueue(hdmi
->workq
);
78 destroy_workqueue(hdmi
->workq
);
80 hdmi_hdcp_destroy(hdmi
);
82 phy
->funcs
->destroy(phy
);
85 hdmi_i2c_destroy(hdmi
->i2c
);
87 platform_set_drvdata(hdmi
->pdev
, NULL
);
90 /* construct hdmi at bind/probe time, grab all the resources. If
91 * we are to EPROBE_DEFER we want to do it here, rather than later
92 * at modeset_init() time
94 static struct hdmi
*hdmi_init(struct platform_device
*pdev
)
96 struct hdmi_platform_config
*config
= pdev
->dev
.platform_data
;
97 struct hdmi
*hdmi
= NULL
;
101 hdmi
= devm_kzalloc(&pdev
->dev
, sizeof(*hdmi
), GFP_KERNEL
);
108 hdmi
->config
= config
;
109 spin_lock_init(&hdmi
->reg_lock
);
111 /* not sure about which phy maps to which msm.. probably I miss some */
112 if (config
->phy_init
) {
113 hdmi
->phy
= config
->phy_init(hdmi
);
115 if (IS_ERR(hdmi
->phy
)) {
116 ret
= PTR_ERR(hdmi
->phy
);
117 dev_err(&pdev
->dev
, "failed to load phy: %d\n", ret
);
123 hdmi
->mmio
= msm_ioremap(pdev
, config
->mmio_name
, "HDMI");
124 if (IS_ERR(hdmi
->mmio
)) {
125 ret
= PTR_ERR(hdmi
->mmio
);
129 /* HDCP needs physical address of hdmi register */
130 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
132 hdmi
->mmio_phy_addr
= res
->start
;
134 hdmi
->qfprom_mmio
= msm_ioremap(pdev
,
135 config
->qfprom_mmio_name
, "HDMI_QFPROM");
136 if (IS_ERR(hdmi
->qfprom_mmio
)) {
137 dev_info(&pdev
->dev
, "can't find qfprom resource\n");
138 hdmi
->qfprom_mmio
= NULL
;
141 hdmi
->hpd_regs
= devm_kzalloc(&pdev
->dev
, sizeof(hdmi
->hpd_regs
[0]) *
142 config
->hpd_reg_cnt
, GFP_KERNEL
);
143 if (!hdmi
->hpd_regs
) {
147 for (i
= 0; i
< config
->hpd_reg_cnt
; i
++) {
148 struct regulator
*reg
;
150 reg
= devm_regulator_get(&pdev
->dev
,
151 config
->hpd_reg_names
[i
]);
154 dev_err(&pdev
->dev
, "failed to get hpd regulator: %s (%d)\n",
155 config
->hpd_reg_names
[i
], ret
);
159 hdmi
->hpd_regs
[i
] = reg
;
162 hdmi
->pwr_regs
= devm_kzalloc(&pdev
->dev
, sizeof(hdmi
->pwr_regs
[0]) *
163 config
->pwr_reg_cnt
, GFP_KERNEL
);
164 if (!hdmi
->pwr_regs
) {
168 for (i
= 0; i
< config
->pwr_reg_cnt
; i
++) {
169 struct regulator
*reg
;
171 reg
= devm_regulator_get(&pdev
->dev
,
172 config
->pwr_reg_names
[i
]);
175 dev_err(&pdev
->dev
, "failed to get pwr regulator: %s (%d)\n",
176 config
->pwr_reg_names
[i
], ret
);
180 hdmi
->pwr_regs
[i
] = reg
;
183 hdmi
->hpd_clks
= devm_kzalloc(&pdev
->dev
, sizeof(hdmi
->hpd_clks
[0]) *
184 config
->hpd_clk_cnt
, GFP_KERNEL
);
185 if (!hdmi
->hpd_clks
) {
189 for (i
= 0; i
< config
->hpd_clk_cnt
; i
++) {
192 clk
= devm_clk_get(&pdev
->dev
, config
->hpd_clk_names
[i
]);
195 dev_err(&pdev
->dev
, "failed to get hpd clk: %s (%d)\n",
196 config
->hpd_clk_names
[i
], ret
);
200 hdmi
->hpd_clks
[i
] = clk
;
203 hdmi
->pwr_clks
= devm_kzalloc(&pdev
->dev
, sizeof(hdmi
->pwr_clks
[0]) *
204 config
->pwr_clk_cnt
, GFP_KERNEL
);
205 if (!hdmi
->pwr_clks
) {
209 for (i
= 0; i
< config
->pwr_clk_cnt
; i
++) {
212 clk
= devm_clk_get(&pdev
->dev
, config
->pwr_clk_names
[i
]);
215 dev_err(&pdev
->dev
, "failed to get pwr clk: %s (%d)\n",
216 config
->pwr_clk_names
[i
], ret
);
220 hdmi
->pwr_clks
[i
] = clk
;
223 hdmi
->workq
= alloc_ordered_workqueue("msm_hdmi", 0);
225 hdmi
->i2c
= hdmi_i2c_init(hdmi
);
226 if (IS_ERR(hdmi
->i2c
)) {
227 ret
= PTR_ERR(hdmi
->i2c
);
228 dev_err(&pdev
->dev
, "failed to get i2c: %d\n", ret
);
233 hdmi
->hdcp_ctrl
= hdmi_hdcp_init(hdmi
);
234 if (IS_ERR(hdmi
->hdcp_ctrl
)) {
235 dev_warn(&pdev
->dev
, "failed to init hdcp: disabled\n");
236 hdmi
->hdcp_ctrl
= NULL
;
248 /* Second part of initialization, the drm/kms level modeset_init,
249 * constructs/initializes mode objects, etc, is called from master
250 * driver (not hdmi sub-device's probe/bind!)
252 * Any resource (regulator/clk/etc) which could be missing at boot
253 * should be handled in hdmi_init() so that failure happens from
254 * hdmi sub-device's probe.
256 int hdmi_modeset_init(struct hdmi
*hdmi
,
257 struct drm_device
*dev
, struct drm_encoder
*encoder
)
259 struct msm_drm_private
*priv
= dev
->dev_private
;
260 struct platform_device
*pdev
= hdmi
->pdev
;
264 hdmi
->encoder
= encoder
;
266 hdmi_audio_infoframe_init(&hdmi
->audio
.infoframe
);
268 hdmi
->bridge
= hdmi_bridge_init(hdmi
);
269 if (IS_ERR(hdmi
->bridge
)) {
270 ret
= PTR_ERR(hdmi
->bridge
);
271 dev_err(dev
->dev
, "failed to create HDMI bridge: %d\n", ret
);
276 hdmi
->connector
= hdmi_connector_init(hdmi
);
277 if (IS_ERR(hdmi
->connector
)) {
278 ret
= PTR_ERR(hdmi
->connector
);
279 dev_err(dev
->dev
, "failed to create HDMI connector: %d\n", ret
);
280 hdmi
->connector
= NULL
;
284 hdmi
->irq
= irq_of_parse_and_map(pdev
->dev
.of_node
, 0);
287 dev_err(dev
->dev
, "failed to get irq: %d\n", ret
);
291 ret
= devm_request_irq(&pdev
->dev
, hdmi
->irq
,
292 hdmi_irq
, IRQF_TRIGGER_HIGH
| IRQF_ONESHOT
,
295 dev_err(dev
->dev
, "failed to request IRQ%u: %d\n",
300 encoder
->bridge
= hdmi
->bridge
;
302 priv
->bridges
[priv
->num_bridges
++] = hdmi
->bridge
;
303 priv
->connectors
[priv
->num_connectors
++] = hdmi
->connector
;
305 platform_set_drvdata(pdev
, hdmi
);
310 /* bridge is normally destroyed by drm: */
312 hdmi_bridge_destroy(hdmi
->bridge
);
315 if (hdmi
->connector
) {
316 hdmi
->connector
->funcs
->destroy(hdmi
->connector
);
317 hdmi
->connector
= NULL
;
327 #define HDMI_CFG(item, entry) \
328 .item ## _names = item ##_names_ ## entry, \
329 .item ## _cnt = ARRAY_SIZE(item ## _names_ ## entry)
331 static const char *pwr_reg_names_none
[] = {};
332 static const char *hpd_reg_names_none
[] = {};
334 static struct hdmi_platform_config hdmi_tx_8660_config
= {
335 .phy_init
= hdmi_phy_8x60_init
,
338 static const char *hpd_reg_names_8960
[] = {"core-vdda", "hdmi-mux"};
339 static const char *hpd_clk_names_8960
[] = {"core_clk", "master_iface_clk", "slave_iface_clk"};
341 static struct hdmi_platform_config hdmi_tx_8960_config
= {
342 .phy_init
= hdmi_phy_8960_init
,
343 HDMI_CFG(hpd_reg
, 8960),
344 HDMI_CFG(hpd_clk
, 8960),
347 static const char *pwr_reg_names_8x74
[] = {"core-vdda", "core-vcc"};
348 static const char *hpd_reg_names_8x74
[] = {"hpd-gdsc", "hpd-5v"};
349 static const char *pwr_clk_names_8x74
[] = {"extp_clk", "alt_iface_clk"};
350 static const char *hpd_clk_names_8x74
[] = {"iface_clk", "core_clk", "mdp_core_clk"};
351 static unsigned long hpd_clk_freq_8x74
[] = {0, 19200000, 0};
353 static struct hdmi_platform_config hdmi_tx_8974_config
= {
354 .phy_init
= hdmi_phy_8x74_init
,
355 HDMI_CFG(pwr_reg
, 8x74
),
356 HDMI_CFG(hpd_reg
, 8x74
),
357 HDMI_CFG(pwr_clk
, 8x74
),
358 HDMI_CFG(hpd_clk
, 8x74
),
359 .hpd_freq
= hpd_clk_freq_8x74
,
362 static const char *hpd_reg_names_8084
[] = {"hpd-gdsc", "hpd-5v", "hpd-5v-en"};
364 static struct hdmi_platform_config hdmi_tx_8084_config
= {
365 .phy_init
= hdmi_phy_8x74_init
,
366 HDMI_CFG(pwr_reg
, 8x74
),
367 HDMI_CFG(hpd_reg
, 8084),
368 HDMI_CFG(pwr_clk
, 8x74
),
369 HDMI_CFG(hpd_clk
, 8x74
),
370 .hpd_freq
= hpd_clk_freq_8x74
,
373 static struct hdmi_platform_config hdmi_tx_8994_config
= {
374 .phy_init
= NULL
, /* nothing to do for this HDMI PHY 20nm */
375 HDMI_CFG(pwr_reg
, 8x74
),
376 HDMI_CFG(hpd_reg
, none
),
377 HDMI_CFG(pwr_clk
, 8x74
),
378 HDMI_CFG(hpd_clk
, 8x74
),
379 .hpd_freq
= hpd_clk_freq_8x74
,
382 static struct hdmi_platform_config hdmi_tx_8996_config
= {
384 HDMI_CFG(pwr_reg
, none
),
385 HDMI_CFG(hpd_reg
, none
),
386 HDMI_CFG(pwr_clk
, 8x74
),
387 HDMI_CFG(hpd_clk
, 8x74
),
388 .hpd_freq
= hpd_clk_freq_8x74
,
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
);
406 static int hdmi_bind(struct device
*dev
, struct device
*master
, void *data
)
408 struct drm_device
*drm
= dev_get_drvdata(master
);
409 struct msm_drm_private
*priv
= drm
->dev_private
;
410 static struct hdmi_platform_config
*hdmi_cfg
;
412 struct device_node
*of_node
= dev
->of_node
;
414 hdmi_cfg
= (struct hdmi_platform_config
*)
415 of_device_get_match_data(dev
);
417 dev_err(dev
, "unknown hdmi_cfg: %s\n", of_node
->name
);
421 hdmi_cfg
->mmio_name
= "core_physical";
422 hdmi_cfg
->qfprom_mmio_name
= "qfprom_physical";
423 hdmi_cfg
->ddc_clk_gpio
= get_gpio(dev
, of_node
, "qcom,hdmi-tx-ddc-clk");
424 hdmi_cfg
->ddc_data_gpio
= get_gpio(dev
, of_node
, "qcom,hdmi-tx-ddc-data");
425 hdmi_cfg
->hpd_gpio
= get_gpio(dev
, of_node
, "qcom,hdmi-tx-hpd");
426 hdmi_cfg
->mux_en_gpio
= get_gpio(dev
, of_node
, "qcom,hdmi-tx-mux-en");
427 hdmi_cfg
->mux_sel_gpio
= get_gpio(dev
, of_node
, "qcom,hdmi-tx-mux-sel");
428 hdmi_cfg
->mux_lpm_gpio
= get_gpio(dev
, of_node
, "qcom,hdmi-tx-mux-lpm");
430 dev
->platform_data
= hdmi_cfg
;
432 hdmi
= hdmi_init(to_platform_device(dev
));
434 return PTR_ERR(hdmi
);
440 static void hdmi_unbind(struct device
*dev
, struct device
*master
,
443 struct drm_device
*drm
= dev_get_drvdata(master
);
444 struct msm_drm_private
*priv
= drm
->dev_private
;
446 hdmi_destroy(priv
->hdmi
);
451 static const struct component_ops hdmi_ops
= {
453 .unbind
= hdmi_unbind
,
456 static int hdmi_dev_probe(struct platform_device
*pdev
)
458 return component_add(&pdev
->dev
, &hdmi_ops
);
461 static int hdmi_dev_remove(struct platform_device
*pdev
)
463 component_del(&pdev
->dev
, &hdmi_ops
);
467 static const struct of_device_id dt_match
[] = {
468 { .compatible
= "qcom,hdmi-tx-8996", .data
= &hdmi_tx_8996_config
},
469 { .compatible
= "qcom,hdmi-tx-8994", .data
= &hdmi_tx_8994_config
},
470 { .compatible
= "qcom,hdmi-tx-8084", .data
= &hdmi_tx_8084_config
},
471 { .compatible
= "qcom,hdmi-tx-8974", .data
= &hdmi_tx_8974_config
},
472 { .compatible
= "qcom,hdmi-tx-8960", .data
= &hdmi_tx_8960_config
},
473 { .compatible
= "qcom,hdmi-tx-8660", .data
= &hdmi_tx_8660_config
},
477 static struct platform_driver hdmi_driver
= {
478 .probe
= hdmi_dev_probe
,
479 .remove
= hdmi_dev_remove
,
482 .of_match_table
= dt_match
,
486 void __init
hdmi_register(void)
488 platform_driver_register(&hdmi_driver
);
491 void __exit
hdmi_unregister(void)
493 platform_driver_unregister(&hdmi_driver
);