Lines Matching +full:rk3288 +full:- +full:dw +full:- +full:hdmi

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * DesignWare High-Definition Multimedia Interface (HDMI) driver
5 * Copyright (C) 2013-2015 Mentor Graphics Inc.
6 * Copyright (C) 2011-2013 Freescale Semiconductor, Inc.
12 #include <linux/hdmi.h>
20 #include <linux/dma-mapping.h>
23 #include <media/cec-notifier.h>
25 #include <uapi/linux/media-bus-format.h>
38 #include "dw-hdmi-audio.h"
39 #include "dw-hdmi-cec.h"
40 #include "dw-hdmi.h"
47 /* DW-HDMI Controller >= 0x200a are at least compliant with SCDC version 1 */
125 int (*configure)(struct dw_hdmi *hdmi,
171 enum drm_connector_force force; /* mutex-protected force state */
191 void (*enable_audio)(struct dw_hdmi *hdmi);
192 void (*disable_audio)(struct dw_hdmi *hdmi);
210 static inline void hdmi_writeb(struct dw_hdmi *hdmi, u8 val, int offset) in hdmi_writeb() argument
212 regmap_write(hdmi->regm, offset << hdmi->reg_shift, val); in hdmi_writeb()
215 static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset) in hdmi_readb() argument
219 regmap_read(hdmi->regm, offset << hdmi->reg_shift, &val); in hdmi_readb()
224 static void handle_plugged_change(struct dw_hdmi *hdmi, bool plugged) in handle_plugged_change() argument
226 if (hdmi->plugged_cb && hdmi->codec_dev) in handle_plugged_change()
227 hdmi->plugged_cb(hdmi->codec_dev, plugged); in handle_plugged_change()
230 int dw_hdmi_set_plugged_cb(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn, in dw_hdmi_set_plugged_cb() argument
235 mutex_lock(&hdmi->mutex); in dw_hdmi_set_plugged_cb()
236 hdmi->plugged_cb = fn; in dw_hdmi_set_plugged_cb()
237 hdmi->codec_dev = codec_dev; in dw_hdmi_set_plugged_cb()
238 plugged = hdmi->last_connector_result == connector_status_connected; in dw_hdmi_set_plugged_cb()
239 handle_plugged_change(hdmi, plugged); in dw_hdmi_set_plugged_cb()
240 mutex_unlock(&hdmi->mutex); in dw_hdmi_set_plugged_cb()
246 static void hdmi_modb(struct dw_hdmi *hdmi, u8 data, u8 mask, unsigned reg) in hdmi_modb() argument
248 regmap_update_bits(hdmi->regm, reg << hdmi->reg_shift, mask, data); in hdmi_modb()
251 static void hdmi_mask_writeb(struct dw_hdmi *hdmi, u8 data, unsigned int reg, in hdmi_mask_writeb() argument
254 hdmi_modb(hdmi, data << shift, mask, reg); in hdmi_mask_writeb()
257 static void dw_hdmi_i2c_init(struct dw_hdmi *hdmi) in dw_hdmi_i2c_init() argument
259 hdmi_writeb(hdmi, HDMI_PHY_I2CM_INT_ADDR_DONE_POL, in dw_hdmi_i2c_init()
262 hdmi_writeb(hdmi, HDMI_PHY_I2CM_CTLINT_ADDR_NAC_POL | in dw_hdmi_i2c_init()
267 hdmi_writeb(hdmi, 0x00, HDMI_I2CM_SOFTRSTZ); in dw_hdmi_i2c_init()
270 hdmi_writeb(hdmi, 0x00, HDMI_I2CM_DIV); in dw_hdmi_i2c_init()
273 hdmi_writeb(hdmi, HDMI_I2CM_INT_DONE_POL, HDMI_I2CM_INT); in dw_hdmi_i2c_init()
274 hdmi_writeb(hdmi, HDMI_I2CM_CTLINT_NAC_POL | HDMI_I2CM_CTLINT_ARB_POL, in dw_hdmi_i2c_init()
278 hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE, in dw_hdmi_i2c_init()
282 hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE, in dw_hdmi_i2c_init()
286 static bool dw_hdmi_i2c_unwedge(struct dw_hdmi *hdmi) in dw_hdmi_i2c_unwedge() argument
289 if (!hdmi->unwedge_state) in dw_hdmi_i2c_unwedge()
292 dev_info(hdmi->dev, "Attempting to unwedge stuck i2c bus\n"); in dw_hdmi_i2c_unwedge()
312 * its HDMI ports. It happened when the TV was powered on while the in dw_hdmi_i2c_unwedge()
326 pinctrl_select_state(hdmi->pinctrl, hdmi->unwedge_state); in dw_hdmi_i2c_unwedge()
328 pinctrl_select_state(hdmi->pinctrl, hdmi->default_state); in dw_hdmi_i2c_unwedge()
333 static int dw_hdmi_i2c_wait(struct dw_hdmi *hdmi) in dw_hdmi_i2c_wait() argument
335 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_wait()
338 stat = wait_for_completion_timeout(&i2c->cmp, HZ / 10); in dw_hdmi_i2c_wait()
341 if (!dw_hdmi_i2c_unwedge(hdmi)) in dw_hdmi_i2c_wait()
342 return -EAGAIN; in dw_hdmi_i2c_wait()
345 stat = wait_for_completion_timeout(&i2c->cmp, HZ / 10); in dw_hdmi_i2c_wait()
347 return -EAGAIN; in dw_hdmi_i2c_wait()
351 if (i2c->stat & HDMI_IH_I2CM_STAT0_ERROR) in dw_hdmi_i2c_wait()
352 return -EIO; in dw_hdmi_i2c_wait()
357 static int dw_hdmi_i2c_read(struct dw_hdmi *hdmi, in dw_hdmi_i2c_read() argument
360 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_read()
363 if (!i2c->is_regaddr) { in dw_hdmi_i2c_read()
364 dev_dbg(hdmi->dev, "set read register address to 0\n"); in dw_hdmi_i2c_read()
365 i2c->slave_reg = 0x00; in dw_hdmi_i2c_read()
366 i2c->is_regaddr = true; in dw_hdmi_i2c_read()
369 while (length--) { in dw_hdmi_i2c_read()
370 reinit_completion(&i2c->cmp); in dw_hdmi_i2c_read()
372 hdmi_writeb(hdmi, i2c->slave_reg++, HDMI_I2CM_ADDRESS); in dw_hdmi_i2c_read()
373 if (i2c->is_segment) in dw_hdmi_i2c_read()
374 hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_READ_EXT, in dw_hdmi_i2c_read()
377 hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_READ, in dw_hdmi_i2c_read()
380 ret = dw_hdmi_i2c_wait(hdmi); in dw_hdmi_i2c_read()
384 *buf++ = hdmi_readb(hdmi, HDMI_I2CM_DATAI); in dw_hdmi_i2c_read()
386 i2c->is_segment = false; in dw_hdmi_i2c_read()
391 static int dw_hdmi_i2c_write(struct dw_hdmi *hdmi, in dw_hdmi_i2c_write() argument
394 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_write()
397 if (!i2c->is_regaddr) { in dw_hdmi_i2c_write()
399 i2c->slave_reg = buf[0]; in dw_hdmi_i2c_write()
400 length--; in dw_hdmi_i2c_write()
402 i2c->is_regaddr = true; in dw_hdmi_i2c_write()
405 while (length--) { in dw_hdmi_i2c_write()
406 reinit_completion(&i2c->cmp); in dw_hdmi_i2c_write()
408 hdmi_writeb(hdmi, *buf++, HDMI_I2CM_DATAO); in dw_hdmi_i2c_write()
409 hdmi_writeb(hdmi, i2c->slave_reg++, HDMI_I2CM_ADDRESS); in dw_hdmi_i2c_write()
410 hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_WRITE, in dw_hdmi_i2c_write()
413 ret = dw_hdmi_i2c_wait(hdmi); in dw_hdmi_i2c_write()
424 struct dw_hdmi *hdmi = i2c_get_adapdata(adap); in dw_hdmi_i2c_xfer() local
425 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_xfer()
431 * The internal I2C controller does not support the multi-byte in dw_hdmi_i2c_xfer()
436 return -EOPNOTSUPP; in dw_hdmi_i2c_xfer()
438 dev_dbg(hdmi->dev, "xfer: num: %d, addr: %#x\n", num, addr); in dw_hdmi_i2c_xfer()
442 dev_dbg(hdmi->dev, in dw_hdmi_i2c_xfer()
445 return -EOPNOTSUPP; in dw_hdmi_i2c_xfer()
449 mutex_lock(&i2c->lock); in dw_hdmi_i2c_xfer()
452 hdmi_writeb(hdmi, 0x00, HDMI_IH_MUTE_I2CM_STAT0); in dw_hdmi_i2c_xfer()
455 hdmi_writeb(hdmi, addr, HDMI_I2CM_SLAVE); in dw_hdmi_i2c_xfer()
458 i2c->is_regaddr = false; in dw_hdmi_i2c_xfer()
461 i2c->is_segment = false; in dw_hdmi_i2c_xfer()
464 dev_dbg(hdmi->dev, "xfer: num: %d/%d, len: %d, flags: %#x\n", in dw_hdmi_i2c_xfer()
467 i2c->is_segment = true; in dw_hdmi_i2c_xfer()
468 hdmi_writeb(hdmi, DDC_SEGMENT_ADDR, HDMI_I2CM_SEGADDR); in dw_hdmi_i2c_xfer()
469 hdmi_writeb(hdmi, *msgs[i].buf, HDMI_I2CM_SEGPTR); in dw_hdmi_i2c_xfer()
472 ret = dw_hdmi_i2c_read(hdmi, msgs[i].buf, in dw_hdmi_i2c_xfer()
475 ret = dw_hdmi_i2c_write(hdmi, msgs[i].buf, in dw_hdmi_i2c_xfer()
486 hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE, in dw_hdmi_i2c_xfer()
489 mutex_unlock(&i2c->lock); in dw_hdmi_i2c_xfer()
504 static struct i2c_adapter *dw_hdmi_i2c_adapter(struct dw_hdmi *hdmi) in dw_hdmi_i2c_adapter() argument
510 i2c = devm_kzalloc(hdmi->dev, sizeof(*i2c), GFP_KERNEL); in dw_hdmi_i2c_adapter()
512 return ERR_PTR(-ENOMEM); in dw_hdmi_i2c_adapter()
514 mutex_init(&i2c->lock); in dw_hdmi_i2c_adapter()
515 init_completion(&i2c->cmp); in dw_hdmi_i2c_adapter()
517 adap = &i2c->adap; in dw_hdmi_i2c_adapter()
518 adap->class = I2C_CLASS_DDC; in dw_hdmi_i2c_adapter()
519 adap->owner = THIS_MODULE; in dw_hdmi_i2c_adapter()
520 adap->dev.parent = hdmi->dev; in dw_hdmi_i2c_adapter()
521 adap->algo = &dw_hdmi_algorithm; in dw_hdmi_i2c_adapter()
522 strscpy(adap->name, "DesignWare HDMI", sizeof(adap->name)); in dw_hdmi_i2c_adapter()
523 i2c_set_adapdata(adap, hdmi); in dw_hdmi_i2c_adapter()
527 dev_warn(hdmi->dev, "cannot add %s I2C adapter\n", adap->name); in dw_hdmi_i2c_adapter()
528 devm_kfree(hdmi->dev, i2c); in dw_hdmi_i2c_adapter()
532 hdmi->i2c = i2c; in dw_hdmi_i2c_adapter()
534 dev_info(hdmi->dev, "registered %s I2C bus driver\n", adap->name); in dw_hdmi_i2c_adapter()
539 static void hdmi_set_cts_n(struct dw_hdmi *hdmi, unsigned int cts, in hdmi_set_cts_n() argument
543 hdmi_modb(hdmi, 0, HDMI_AUD_CTS3_CTS_MANUAL, HDMI_AUD_CTS3); in hdmi_set_cts_n()
546 hdmi_modb(hdmi, 0, HDMI_AUD_CTS3_N_SHIFT_MASK, HDMI_AUD_CTS3); in hdmi_set_cts_n()
550 hdmi_writeb(hdmi, ((cts >> 16) & in hdmi_set_cts_n()
555 hdmi_writeb(hdmi, 0, HDMI_AUD_CTS3); in hdmi_set_cts_n()
556 hdmi_writeb(hdmi, (cts >> 8) & 0xff, HDMI_AUD_CTS2); in hdmi_set_cts_n()
557 hdmi_writeb(hdmi, cts & 0xff, HDMI_AUD_CTS1); in hdmi_set_cts_n()
559 hdmi_writeb(hdmi, (n >> 16) & 0x0f, HDMI_AUD_N3); in hdmi_set_cts_n()
560 hdmi_writeb(hdmi, (n >> 8) & 0xff, HDMI_AUD_N2); in hdmi_set_cts_n()
561 hdmi_writeb(hdmi, n & 0xff, HDMI_AUD_N1); in hdmi_set_cts_n()
634 void dw_hdmi_set_channel_status(struct dw_hdmi *hdmi, in dw_hdmi_set_channel_status() argument
641 hdmi_writeb(hdmi, channel_status[3], HDMI_FC_AUDSCHNLS7); in dw_hdmi_set_channel_status()
642 hdmi_writeb(hdmi, channel_status[4], HDMI_FC_AUDSCHNLS8); in dw_hdmi_set_channel_status()
646 static void hdmi_set_clk_regenerator(struct dw_hdmi *hdmi, in hdmi_set_clk_regenerator() argument
656 config3 = hdmi_readb(hdmi, HDMI_CONFIG3_ID); in hdmi_set_clk_regenerator()
662 * can be up to 20 bits in total, so we need 64-bit math. Also in hdmi_set_clk_regenerator()
671 dev_dbg(hdmi->dev, "%s: fs=%uHz ftdms=%lu.%03luMHz N=%d cts=%d\n", in hdmi_set_clk_regenerator()
679 spin_lock_irq(&hdmi->audio_lock); in hdmi_set_clk_regenerator()
680 hdmi->audio_n = n; in hdmi_set_clk_regenerator()
681 hdmi->audio_cts = cts; in hdmi_set_clk_regenerator()
682 hdmi_set_cts_n(hdmi, cts, hdmi->audio_enable ? n : 0); in hdmi_set_clk_regenerator()
683 spin_unlock_irq(&hdmi->audio_lock); in hdmi_set_clk_regenerator()
686 static void hdmi_init_clk_regenerator(struct dw_hdmi *hdmi) in hdmi_init_clk_regenerator() argument
688 mutex_lock(&hdmi->audio_mutex); in hdmi_init_clk_regenerator()
689 hdmi_set_clk_regenerator(hdmi, 74250000, hdmi->sample_rate); in hdmi_init_clk_regenerator()
690 mutex_unlock(&hdmi->audio_mutex); in hdmi_init_clk_regenerator()
693 static void hdmi_clk_regenerator_update_pixel_clock(struct dw_hdmi *hdmi) in hdmi_clk_regenerator_update_pixel_clock() argument
695 mutex_lock(&hdmi->audio_mutex); in hdmi_clk_regenerator_update_pixel_clock()
696 hdmi_set_clk_regenerator(hdmi, hdmi->hdmi_data.video_mode.mtmdsclock, in hdmi_clk_regenerator_update_pixel_clock()
697 hdmi->sample_rate); in hdmi_clk_regenerator_update_pixel_clock()
698 mutex_unlock(&hdmi->audio_mutex); in hdmi_clk_regenerator_update_pixel_clock()
701 void dw_hdmi_set_sample_width(struct dw_hdmi *hdmi, unsigned int width) in dw_hdmi_set_sample_width() argument
703 mutex_lock(&hdmi->audio_mutex); in dw_hdmi_set_sample_width()
704 hdmi->sample_width = width; in dw_hdmi_set_sample_width()
705 mutex_unlock(&hdmi->audio_mutex); in dw_hdmi_set_sample_width()
709 void dw_hdmi_set_sample_non_pcm(struct dw_hdmi *hdmi, unsigned int non_pcm) in dw_hdmi_set_sample_non_pcm() argument
711 mutex_lock(&hdmi->audio_mutex); in dw_hdmi_set_sample_non_pcm()
712 hdmi->sample_non_pcm = non_pcm; in dw_hdmi_set_sample_non_pcm()
713 mutex_unlock(&hdmi->audio_mutex); in dw_hdmi_set_sample_non_pcm()
717 void dw_hdmi_set_sample_rate(struct dw_hdmi *hdmi, unsigned int rate) in dw_hdmi_set_sample_rate() argument
719 mutex_lock(&hdmi->audio_mutex); in dw_hdmi_set_sample_rate()
720 hdmi->sample_rate = rate; in dw_hdmi_set_sample_rate()
721 hdmi_set_clk_regenerator(hdmi, hdmi->hdmi_data.video_mode.mtmdsclock, in dw_hdmi_set_sample_rate()
722 hdmi->sample_rate); in dw_hdmi_set_sample_rate()
723 mutex_unlock(&hdmi->audio_mutex); in dw_hdmi_set_sample_rate()
727 void dw_hdmi_set_channel_count(struct dw_hdmi *hdmi, unsigned int cnt) in dw_hdmi_set_channel_count() argument
731 mutex_lock(&hdmi->audio_mutex); in dw_hdmi_set_channel_count()
732 hdmi->channels = cnt; in dw_hdmi_set_channel_count()
743 hdmi_modb(hdmi, layout, HDMI_FC_AUDSCONF_AUD_PACKET_LAYOUT_MASK, in dw_hdmi_set_channel_count()
747 hdmi_modb(hdmi, (cnt - 1) << HDMI_FC_AUDICONF0_CC_OFFSET, in dw_hdmi_set_channel_count()
750 mutex_unlock(&hdmi->audio_mutex); in dw_hdmi_set_channel_count()
754 void dw_hdmi_set_channel_allocation(struct dw_hdmi *hdmi, unsigned int ca) in dw_hdmi_set_channel_allocation() argument
756 mutex_lock(&hdmi->audio_mutex); in dw_hdmi_set_channel_allocation()
758 hdmi_writeb(hdmi, ca, HDMI_FC_AUDICONF2); in dw_hdmi_set_channel_allocation()
760 mutex_unlock(&hdmi->audio_mutex); in dw_hdmi_set_channel_allocation()
764 static void hdmi_enable_audio_clk(struct dw_hdmi *hdmi, bool enable) in hdmi_enable_audio_clk() argument
767 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_AUDCLK_DISABLE; in hdmi_enable_audio_clk()
769 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_AUDCLK_DISABLE; in hdmi_enable_audio_clk()
770 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in hdmi_enable_audio_clk()
773 static u8 *hdmi_audio_get_eld(struct dw_hdmi *hdmi) in hdmi_audio_get_eld() argument
775 if (!hdmi->curr_conn) in hdmi_audio_get_eld()
778 return hdmi->curr_conn->eld; in hdmi_audio_get_eld()
781 static void dw_hdmi_gp_audio_enable(struct dw_hdmi *hdmi) in dw_hdmi_gp_audio_enable() argument
783 const struct dw_hdmi_plat_data *pdata = hdmi->plat_data; in dw_hdmi_gp_audio_enable()
785 int ch_mask = BIT(hdmi->channels) - 1; in dw_hdmi_gp_audio_enable()
787 switch (hdmi->sample_rate) { in dw_hdmi_gp_audio_enable()
820 hdmi_set_cts_n(hdmi, hdmi->audio_cts, hdmi->audio_n); in dw_hdmi_gp_audio_enable()
821 hdmi_enable_audio_clk(hdmi, true); in dw_hdmi_gp_audio_enable()
823 hdmi_writeb(hdmi, 0x1, HDMI_FC_AUDSCHNLS0); in dw_hdmi_gp_audio_enable()
824 hdmi_writeb(hdmi, hdmi->channels, HDMI_FC_AUDSCHNLS2); in dw_hdmi_gp_audio_enable()
825 hdmi_writeb(hdmi, 0x22, HDMI_FC_AUDSCHNLS3); in dw_hdmi_gp_audio_enable()
826 hdmi_writeb(hdmi, 0x22, HDMI_FC_AUDSCHNLS4); in dw_hdmi_gp_audio_enable()
827 hdmi_writeb(hdmi, 0x11, HDMI_FC_AUDSCHNLS5); in dw_hdmi_gp_audio_enable()
828 hdmi_writeb(hdmi, 0x11, HDMI_FC_AUDSCHNLS6); in dw_hdmi_gp_audio_enable()
829 hdmi_writeb(hdmi, (0x3 << 4) | sample_freq, HDMI_FC_AUDSCHNLS7); in dw_hdmi_gp_audio_enable()
830 hdmi_writeb(hdmi, (org_sample_freq << 4) | 0xb, HDMI_FC_AUDSCHNLS8); in dw_hdmi_gp_audio_enable()
832 hdmi_writeb(hdmi, ch_mask, HDMI_GP_CONF1); in dw_hdmi_gp_audio_enable()
833 hdmi_writeb(hdmi, 0x02, HDMI_GP_CONF2); in dw_hdmi_gp_audio_enable()
834 hdmi_writeb(hdmi, 0x01, HDMI_GP_CONF0); in dw_hdmi_gp_audio_enable()
836 hdmi_modb(hdmi, 0x3, 0x3, HDMI_FC_DATAUTO3); in dw_hdmi_gp_audio_enable()
839 if (hdmi->sample_rate == 192000 && hdmi->channels == 8 && in dw_hdmi_gp_audio_enable()
840 hdmi->sample_width == 32 && hdmi->sample_non_pcm) in dw_hdmi_gp_audio_enable()
841 hdmi_modb(hdmi, 0x01, 0x01, HDMI_GP_CONF2); in dw_hdmi_gp_audio_enable()
843 if (pdata->enable_audio) in dw_hdmi_gp_audio_enable()
844 pdata->enable_audio(hdmi, in dw_hdmi_gp_audio_enable()
845 hdmi->channels, in dw_hdmi_gp_audio_enable()
846 hdmi->sample_width, in dw_hdmi_gp_audio_enable()
847 hdmi->sample_rate, in dw_hdmi_gp_audio_enable()
848 hdmi->sample_non_pcm); in dw_hdmi_gp_audio_enable()
851 static void dw_hdmi_gp_audio_disable(struct dw_hdmi *hdmi) in dw_hdmi_gp_audio_disable() argument
853 const struct dw_hdmi_plat_data *pdata = hdmi->plat_data; in dw_hdmi_gp_audio_disable()
855 hdmi_set_cts_n(hdmi, hdmi->audio_cts, 0); in dw_hdmi_gp_audio_disable()
857 hdmi_modb(hdmi, 0, 0x3, HDMI_FC_DATAUTO3); in dw_hdmi_gp_audio_disable()
858 if (pdata->disable_audio) in dw_hdmi_gp_audio_disable()
859 pdata->disable_audio(hdmi); in dw_hdmi_gp_audio_disable()
861 hdmi_enable_audio_clk(hdmi, false); in dw_hdmi_gp_audio_disable()
864 static void dw_hdmi_ahb_audio_enable(struct dw_hdmi *hdmi) in dw_hdmi_ahb_audio_enable() argument
866 hdmi_set_cts_n(hdmi, hdmi->audio_cts, hdmi->audio_n); in dw_hdmi_ahb_audio_enable()
869 static void dw_hdmi_ahb_audio_disable(struct dw_hdmi *hdmi) in dw_hdmi_ahb_audio_disable() argument
871 hdmi_set_cts_n(hdmi, hdmi->audio_cts, 0); in dw_hdmi_ahb_audio_disable()
874 static void dw_hdmi_i2s_audio_enable(struct dw_hdmi *hdmi) in dw_hdmi_i2s_audio_enable() argument
876 hdmi_set_cts_n(hdmi, hdmi->audio_cts, hdmi->audio_n); in dw_hdmi_i2s_audio_enable()
877 hdmi_enable_audio_clk(hdmi, true); in dw_hdmi_i2s_audio_enable()
880 static void dw_hdmi_i2s_audio_disable(struct dw_hdmi *hdmi) in dw_hdmi_i2s_audio_disable() argument
882 hdmi_enable_audio_clk(hdmi, false); in dw_hdmi_i2s_audio_disable()
885 void dw_hdmi_audio_enable(struct dw_hdmi *hdmi) in dw_hdmi_audio_enable() argument
889 spin_lock_irqsave(&hdmi->audio_lock, flags); in dw_hdmi_audio_enable()
890 hdmi->audio_enable = true; in dw_hdmi_audio_enable()
891 if (hdmi->enable_audio) in dw_hdmi_audio_enable()
892 hdmi->enable_audio(hdmi); in dw_hdmi_audio_enable()
893 spin_unlock_irqrestore(&hdmi->audio_lock, flags); in dw_hdmi_audio_enable()
897 void dw_hdmi_audio_disable(struct dw_hdmi *hdmi) in dw_hdmi_audio_disable() argument
901 spin_lock_irqsave(&hdmi->audio_lock, flags); in dw_hdmi_audio_disable()
902 hdmi->audio_enable = false; in dw_hdmi_audio_disable()
903 if (hdmi->disable_audio) in dw_hdmi_audio_disable()
904 hdmi->disable_audio(hdmi); in dw_hdmi_audio_disable()
905 spin_unlock_irqrestore(&hdmi->audio_lock, flags); in dw_hdmi_audio_disable()
1002 static void hdmi_video_sample(struct dw_hdmi *hdmi) in hdmi_video_sample() argument
1007 switch (hdmi->hdmi_data.enc_in_bus_format) { in hdmi_video_sample()
1055 hdmi_writeb(hdmi, val, HDMI_TX_INVID0); in hdmi_video_sample()
1061 hdmi_writeb(hdmi, val, HDMI_TX_INSTUFFING); in hdmi_video_sample()
1062 hdmi_writeb(hdmi, 0x0, HDMI_TX_GYDATA0); in hdmi_video_sample()
1063 hdmi_writeb(hdmi, 0x0, HDMI_TX_GYDATA1); in hdmi_video_sample()
1064 hdmi_writeb(hdmi, 0x0, HDMI_TX_RCRDATA0); in hdmi_video_sample()
1065 hdmi_writeb(hdmi, 0x0, HDMI_TX_RCRDATA1); in hdmi_video_sample()
1066 hdmi_writeb(hdmi, 0x0, HDMI_TX_BCBDATA0); in hdmi_video_sample()
1067 hdmi_writeb(hdmi, 0x0, HDMI_TX_BCBDATA1); in hdmi_video_sample()
1070 static int is_color_space_conversion(struct dw_hdmi *hdmi) in is_color_space_conversion() argument
1072 struct hdmi_data_info *hdmi_data = &hdmi->hdmi_data; in is_color_space_conversion()
1075 is_input_rgb = hdmi_bus_fmt_is_rgb(hdmi_data->enc_in_bus_format); in is_color_space_conversion()
1076 is_output_rgb = hdmi_bus_fmt_is_rgb(hdmi_data->enc_out_bus_format); in is_color_space_conversion()
1079 (is_input_rgb && is_output_rgb && hdmi_data->rgb_limited_range); in is_color_space_conversion()
1082 static int is_color_space_decimation(struct dw_hdmi *hdmi) in is_color_space_decimation() argument
1084 if (!hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) in is_color_space_decimation()
1087 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_in_bus_format) || in is_color_space_decimation()
1088 hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_in_bus_format)) in is_color_space_decimation()
1094 static int is_color_space_interpolation(struct dw_hdmi *hdmi) in is_color_space_interpolation() argument
1096 if (!hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_in_bus_format)) in is_color_space_interpolation()
1099 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format) || in is_color_space_interpolation()
1100 hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format)) in is_color_space_interpolation()
1106 static bool is_csc_needed(struct dw_hdmi *hdmi) in is_csc_needed() argument
1108 return is_color_space_conversion(hdmi) || in is_csc_needed()
1109 is_color_space_decimation(hdmi) || in is_csc_needed()
1110 is_color_space_interpolation(hdmi); in is_csc_needed()
1113 static void dw_hdmi_update_csc_coeffs(struct dw_hdmi *hdmi) in dw_hdmi_update_csc_coeffs() argument
1120 is_input_rgb = hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_in_bus_format); in dw_hdmi_update_csc_coeffs()
1121 is_output_rgb = hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format); in dw_hdmi_update_csc_coeffs()
1124 if (hdmi->hdmi_data.enc_out_encoding == V4L2_YCBCR_ENC_601) in dw_hdmi_update_csc_coeffs()
1129 if (hdmi->hdmi_data.enc_out_encoding == V4L2_YCBCR_ENC_601) in dw_hdmi_update_csc_coeffs()
1135 hdmi->hdmi_data.rgb_limited_range) { in dw_hdmi_update_csc_coeffs()
1145 hdmi_writeb(hdmi, coeff_a & 0xff, HDMI_CSC_COEF_A1_LSB + i * 2); in dw_hdmi_update_csc_coeffs()
1146 hdmi_writeb(hdmi, coeff_a >> 8, HDMI_CSC_COEF_A1_MSB + i * 2); in dw_hdmi_update_csc_coeffs()
1147 hdmi_writeb(hdmi, coeff_b & 0xff, HDMI_CSC_COEF_B1_LSB + i * 2); in dw_hdmi_update_csc_coeffs()
1148 hdmi_writeb(hdmi, coeff_b >> 8, HDMI_CSC_COEF_B1_MSB + i * 2); in dw_hdmi_update_csc_coeffs()
1149 hdmi_writeb(hdmi, coeff_c & 0xff, HDMI_CSC_COEF_C1_LSB + i * 2); in dw_hdmi_update_csc_coeffs()
1150 hdmi_writeb(hdmi, coeff_c >> 8, HDMI_CSC_COEF_C1_MSB + i * 2); in dw_hdmi_update_csc_coeffs()
1153 hdmi_modb(hdmi, csc_scale, HDMI_CSC_SCALE_CSCSCALE_MASK, in dw_hdmi_update_csc_coeffs()
1157 static void hdmi_video_csc(struct dw_hdmi *hdmi) in hdmi_video_csc() argument
1164 if (is_color_space_interpolation(hdmi)) in hdmi_video_csc()
1166 else if (is_color_space_decimation(hdmi)) in hdmi_video_csc()
1169 switch (hdmi_bus_fmt_color_depth(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_csc()
1188 hdmi_writeb(hdmi, interpolation | decimation, HDMI_CSC_CFG); in hdmi_video_csc()
1189 hdmi_modb(hdmi, color_depth, HDMI_CSC_SCALE_CSC_COLORDE_PTH_MASK, in hdmi_video_csc()
1192 dw_hdmi_update_csc_coeffs(hdmi); in hdmi_video_csc()
1196 * HDMI video packetizer is used to packetize the data.
1200 static void hdmi_video_packetize(struct dw_hdmi *hdmi) in hdmi_video_packetize() argument
1205 struct hdmi_data_info *hdmi_data = &hdmi->hdmi_data; in hdmi_video_packetize()
1210 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format) || in hdmi_video_packetize()
1211 hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format) || in hdmi_video_packetize()
1212 hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1214 hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1232 } else if (hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1234 hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1258 ((hdmi_data->pix_repet_factor << in hdmi_video_packetize()
1261 hdmi_writeb(hdmi, val, HDMI_VP_PR_CD); in hdmi_video_packetize()
1264 * Source shall only send GCPs with non-zero CD to sinks in hdmi_video_packetize()
1267 * Disable Auto GCP when 24-bit color for sinks that not support Deep Color. in hdmi_video_packetize()
1269 val = hdmi_readb(hdmi, HDMI_FC_DATAUTO3); in hdmi_video_packetize()
1274 hdmi_writeb(hdmi, val, HDMI_FC_DATAUTO3); in hdmi_video_packetize()
1276 hdmi_modb(hdmi, HDMI_VP_STUFF_PR_STUFFING_STUFFING_MODE, in hdmi_video_packetize()
1280 if (hdmi_data->pix_repet_factor > 1) { in hdmi_video_packetize()
1288 hdmi_modb(hdmi, vp_conf, in hdmi_video_packetize()
1292 hdmi_modb(hdmi, 1 << HDMI_VP_STUFF_IDEFAULT_PHASE_OFFSET, in hdmi_video_packetize()
1295 hdmi_writeb(hdmi, remap_size, HDMI_VP_REMAP); in hdmi_video_packetize()
1313 hdmi_modb(hdmi, vp_conf, in hdmi_video_packetize()
1317 hdmi_modb(hdmi, HDMI_VP_STUFF_PP_STUFFING_STUFFING_MODE | in hdmi_video_packetize()
1322 hdmi_modb(hdmi, output_select, HDMI_VP_CONF_OUTPUT_SELECTOR_MASK, in hdmi_video_packetize()
1326 /* -----------------------------------------------------------------------------
1330 static inline void hdmi_phy_test_clear(struct dw_hdmi *hdmi, in hdmi_phy_test_clear() argument
1333 hdmi_modb(hdmi, bit << HDMI_PHY_TST0_TSTCLR_OFFSET, in hdmi_phy_test_clear()
1337 static bool hdmi_phy_wait_i2c_done(struct dw_hdmi *hdmi, int msec) in hdmi_phy_wait_i2c_done() argument
1341 while ((val = hdmi_readb(hdmi, HDMI_IH_I2CMPHY_STAT0) & 0x3) == 0) { in hdmi_phy_wait_i2c_done()
1342 if (msec-- == 0) in hdmi_phy_wait_i2c_done()
1346 hdmi_writeb(hdmi, val, HDMI_IH_I2CMPHY_STAT0); in hdmi_phy_wait_i2c_done()
1351 void dw_hdmi_phy_i2c_write(struct dw_hdmi *hdmi, unsigned short data, in dw_hdmi_phy_i2c_write() argument
1354 hdmi_writeb(hdmi, 0xFF, HDMI_IH_I2CMPHY_STAT0); in dw_hdmi_phy_i2c_write()
1355 hdmi_writeb(hdmi, addr, HDMI_PHY_I2CM_ADDRESS_ADDR); in dw_hdmi_phy_i2c_write()
1356 hdmi_writeb(hdmi, (unsigned char)(data >> 8), in dw_hdmi_phy_i2c_write()
1358 hdmi_writeb(hdmi, (unsigned char)(data >> 0), in dw_hdmi_phy_i2c_write()
1360 hdmi_writeb(hdmi, HDMI_PHY_I2CM_OPERATION_ADDR_WRITE, in dw_hdmi_phy_i2c_write()
1362 hdmi_phy_wait_i2c_done(hdmi, 1000); in dw_hdmi_phy_i2c_write()
1367 static bool dw_hdmi_support_scdc(struct dw_hdmi *hdmi, in dw_hdmi_support_scdc() argument
1371 if (hdmi->version < 0x200a) in dw_hdmi_support_scdc()
1375 if (!hdmi->ddc) in dw_hdmi_support_scdc()
1378 /* Disable if SCDC is not supported, or if an HF-VSDB block is absent */ in dw_hdmi_support_scdc()
1379 if (!display->hdmi.scdc.supported || in dw_hdmi_support_scdc()
1380 !display->hdmi.scdc.scrambling.supported) in dw_hdmi_support_scdc()
1387 if (!display->hdmi.scdc.scrambling.low_rates && in dw_hdmi_support_scdc()
1388 display->max_tmds_clock <= 340000) in dw_hdmi_support_scdc()
1396 * - The Source shall suspend transmission of the TMDS clock and data
1397 * - The Source shall write to the TMDS_Bit_Clock_Ratio bit to change it
1399 * - The Source shall allow a minimum of 1 ms and a maximum of 100 ms from
1407 void dw_hdmi_set_high_tmds_clock_ratio(struct dw_hdmi *hdmi, in dw_hdmi_set_high_tmds_clock_ratio() argument
1410 unsigned long mtmdsclock = hdmi->hdmi_data.video_mode.mtmdsclock; in dw_hdmi_set_high_tmds_clock_ratio()
1412 /* Control for TMDS Bit Period/TMDS Clock-Period Ratio */ in dw_hdmi_set_high_tmds_clock_ratio()
1413 if (dw_hdmi_support_scdc(hdmi, display)) { in dw_hdmi_set_high_tmds_clock_ratio()
1415 drm_scdc_set_high_tmds_clock_ratio(hdmi->curr_conn, 1); in dw_hdmi_set_high_tmds_clock_ratio()
1417 drm_scdc_set_high_tmds_clock_ratio(hdmi->curr_conn, 0); in dw_hdmi_set_high_tmds_clock_ratio()
1422 static void dw_hdmi_phy_enable_powerdown(struct dw_hdmi *hdmi, bool enable) in dw_hdmi_phy_enable_powerdown() argument
1424 hdmi_mask_writeb(hdmi, !enable, HDMI_PHY_CONF0, in dw_hdmi_phy_enable_powerdown()
1429 static void dw_hdmi_phy_enable_tmds(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_enable_tmds() argument
1431 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_enable_tmds()
1436 static void dw_hdmi_phy_enable_svsret(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_enable_svsret() argument
1438 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_enable_svsret()
1443 void dw_hdmi_phy_gen2_pddq(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_gen2_pddq() argument
1445 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_gen2_pddq()
1451 void dw_hdmi_phy_gen2_txpwron(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_gen2_txpwron() argument
1453 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_gen2_txpwron()
1459 static void dw_hdmi_phy_sel_data_en_pol(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_sel_data_en_pol() argument
1461 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_sel_data_en_pol()
1466 static void dw_hdmi_phy_sel_interface_control(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_sel_interface_control() argument
1468 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_sel_interface_control()
1473 void dw_hdmi_phy_gen1_reset(struct dw_hdmi *hdmi) in dw_hdmi_phy_gen1_reset() argument
1476 hdmi_writeb(hdmi, 0, HDMI_MC_PHYRSTZ); in dw_hdmi_phy_gen1_reset()
1477 hdmi_writeb(hdmi, HDMI_MC_PHYRSTZ_PHYRSTZ, HDMI_MC_PHYRSTZ); in dw_hdmi_phy_gen1_reset()
1481 void dw_hdmi_phy_gen2_reset(struct dw_hdmi *hdmi) in dw_hdmi_phy_gen2_reset() argument
1484 hdmi_writeb(hdmi, HDMI_MC_PHYRSTZ_PHYRSTZ, HDMI_MC_PHYRSTZ); in dw_hdmi_phy_gen2_reset()
1485 hdmi_writeb(hdmi, 0, HDMI_MC_PHYRSTZ); in dw_hdmi_phy_gen2_reset()
1489 void dw_hdmi_phy_i2c_set_addr(struct dw_hdmi *hdmi, u8 address) in dw_hdmi_phy_i2c_set_addr() argument
1491 hdmi_phy_test_clear(hdmi, 1); in dw_hdmi_phy_i2c_set_addr()
1492 hdmi_writeb(hdmi, address, HDMI_PHY_I2CM_SLAVE_ADDR); in dw_hdmi_phy_i2c_set_addr()
1493 hdmi_phy_test_clear(hdmi, 0); in dw_hdmi_phy_i2c_set_addr()
1497 static void dw_hdmi_phy_power_off(struct dw_hdmi *hdmi) in dw_hdmi_phy_power_off() argument
1499 const struct dw_hdmi_phy_data *phy = hdmi->phy.data; in dw_hdmi_phy_power_off()
1503 if (phy->gen == 1) { in dw_hdmi_phy_power_off()
1504 dw_hdmi_phy_enable_tmds(hdmi, 0); in dw_hdmi_phy_power_off()
1505 dw_hdmi_phy_enable_powerdown(hdmi, true); in dw_hdmi_phy_power_off()
1509 dw_hdmi_phy_gen2_txpwron(hdmi, 0); in dw_hdmi_phy_power_off()
1516 val = hdmi_readb(hdmi, HDMI_PHY_STAT0); in dw_hdmi_phy_power_off()
1524 dev_warn(hdmi->dev, "PHY failed to power down\n"); in dw_hdmi_phy_power_off()
1526 dev_dbg(hdmi->dev, "PHY powered down in %u iterations\n", i); in dw_hdmi_phy_power_off()
1528 dw_hdmi_phy_gen2_pddq(hdmi, 1); in dw_hdmi_phy_power_off()
1531 static int dw_hdmi_phy_power_on(struct dw_hdmi *hdmi) in dw_hdmi_phy_power_on() argument
1533 const struct dw_hdmi_phy_data *phy = hdmi->phy.data; in dw_hdmi_phy_power_on()
1537 if (phy->gen == 1) { in dw_hdmi_phy_power_on()
1538 dw_hdmi_phy_enable_powerdown(hdmi, false); in dw_hdmi_phy_power_on()
1541 dw_hdmi_phy_enable_tmds(hdmi, 0); in dw_hdmi_phy_power_on()
1542 dw_hdmi_phy_enable_tmds(hdmi, 1); in dw_hdmi_phy_power_on()
1546 dw_hdmi_phy_gen2_txpwron(hdmi, 1); in dw_hdmi_phy_power_on()
1547 dw_hdmi_phy_gen2_pddq(hdmi, 0); in dw_hdmi_phy_power_on()
1551 val = hdmi_readb(hdmi, HDMI_PHY_STAT0) & HDMI_PHY_TX_PHY_LOCK; in dw_hdmi_phy_power_on()
1559 dev_err(hdmi->dev, "PHY PLL failed to lock\n"); in dw_hdmi_phy_power_on()
1560 return -ETIMEDOUT; in dw_hdmi_phy_power_on()
1563 dev_dbg(hdmi->dev, "PHY PLL locked %u iterations\n", i); in dw_hdmi_phy_power_on()
1568 * PHY configuration function for the DWC HDMI 3D TX PHY. Based on the available
1572 static int hdmi_phy_configure_dwc_hdmi_3d_tx(struct dw_hdmi *hdmi, in hdmi_phy_configure_dwc_hdmi_3d_tx() argument
1576 const struct dw_hdmi_mpll_config *mpll_config = pdata->mpll_cfg; in hdmi_phy_configure_dwc_hdmi_3d_tx()
1577 const struct dw_hdmi_curr_ctrl *curr_ctrl = pdata->cur_ctr; in hdmi_phy_configure_dwc_hdmi_3d_tx()
1578 const struct dw_hdmi_phy_config *phy_config = pdata->phy_config; in hdmi_phy_configure_dwc_hdmi_3d_tx()
1582 /* PLL/MPLL Cfg - always match on final entry */ in hdmi_phy_configure_dwc_hdmi_3d_tx()
1583 for (; mpll_config->mpixelclock != ~0UL; mpll_config++) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1584 if (mpixelclock <= mpll_config->mpixelclock) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1587 for (; curr_ctrl->mpixelclock != ~0UL; curr_ctrl++) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1588 if (mpixelclock <= curr_ctrl->mpixelclock) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1591 for (; phy_config->mpixelclock != ~0UL; phy_config++) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1592 if (mpixelclock <= phy_config->mpixelclock) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1595 if (mpll_config->mpixelclock == ~0UL || in hdmi_phy_configure_dwc_hdmi_3d_tx()
1596 curr_ctrl->mpixelclock == ~0UL || in hdmi_phy_configure_dwc_hdmi_3d_tx()
1597 phy_config->mpixelclock == ~0UL) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1598 return -EINVAL; in hdmi_phy_configure_dwc_hdmi_3d_tx()
1600 dw_hdmi_phy_i2c_write(hdmi, mpll_config->res[0].cpce, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1602 dw_hdmi_phy_i2c_write(hdmi, mpll_config->res[0].gmp, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1604 dw_hdmi_phy_i2c_write(hdmi, curr_ctrl->curr[0], in hdmi_phy_configure_dwc_hdmi_3d_tx()
1607 dw_hdmi_phy_i2c_write(hdmi, 0, HDMI_3D_TX_PHY_PLLPHBYCTRL); in hdmi_phy_configure_dwc_hdmi_3d_tx()
1608 dw_hdmi_phy_i2c_write(hdmi, HDMI_3D_TX_PHY_MSM_CTRL_CKO_SEL_FB_CLK, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1611 dw_hdmi_phy_i2c_write(hdmi, phy_config->term, HDMI_3D_TX_PHY_TXTERM); in hdmi_phy_configure_dwc_hdmi_3d_tx()
1612 dw_hdmi_phy_i2c_write(hdmi, phy_config->sym_ctr, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1614 dw_hdmi_phy_i2c_write(hdmi, phy_config->vlev_ctr, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1618 dw_hdmi_phy_i2c_write(hdmi, HDMI_3D_TX_PHY_CKCALCTRL_OVERRIDE, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1624 static int hdmi_phy_configure(struct dw_hdmi *hdmi, in hdmi_phy_configure() argument
1627 const struct dw_hdmi_phy_data *phy = hdmi->phy.data; in hdmi_phy_configure()
1628 const struct dw_hdmi_plat_data *pdata = hdmi->plat_data; in hdmi_phy_configure()
1629 unsigned long mpixelclock = hdmi->hdmi_data.video_mode.mpixelclock; in hdmi_phy_configure()
1630 unsigned long mtmdsclock = hdmi->hdmi_data.video_mode.mtmdsclock; in hdmi_phy_configure()
1633 dw_hdmi_phy_power_off(hdmi); in hdmi_phy_configure()
1635 dw_hdmi_set_high_tmds_clock_ratio(hdmi, display); in hdmi_phy_configure()
1638 if (phy->has_svsret) in hdmi_phy_configure()
1639 dw_hdmi_phy_enable_svsret(hdmi, 1); in hdmi_phy_configure()
1641 dw_hdmi_phy_gen2_reset(hdmi); in hdmi_phy_configure()
1643 hdmi_writeb(hdmi, HDMI_MC_HEACPHY_RST_ASSERT, HDMI_MC_HEACPHY_RST); in hdmi_phy_configure()
1645 dw_hdmi_phy_i2c_set_addr(hdmi, HDMI_PHY_I2CM_SLAVE_ADDR_PHY_GEN2); in hdmi_phy_configure()
1648 if (pdata->configure_phy) in hdmi_phy_configure()
1649 ret = pdata->configure_phy(hdmi, pdata->priv_data, mpixelclock); in hdmi_phy_configure()
1651 ret = phy->configure(hdmi, pdata, mpixelclock); in hdmi_phy_configure()
1653 dev_err(hdmi->dev, "PHY configuration failed (clock %lu)\n", in hdmi_phy_configure()
1662 return dw_hdmi_phy_power_on(hdmi); in hdmi_phy_configure()
1665 static int dw_hdmi_phy_init(struct dw_hdmi *hdmi, void *data, in dw_hdmi_phy_init() argument
1671 /* HDMI Phy spec says to do the phy initialization sequence twice */ in dw_hdmi_phy_init()
1673 dw_hdmi_phy_sel_data_en_pol(hdmi, 1); in dw_hdmi_phy_init()
1674 dw_hdmi_phy_sel_interface_control(hdmi, 0); in dw_hdmi_phy_init()
1676 ret = hdmi_phy_configure(hdmi, display); in dw_hdmi_phy_init()
1684 static void dw_hdmi_phy_disable(struct dw_hdmi *hdmi, void *data) in dw_hdmi_phy_disable() argument
1686 dw_hdmi_phy_power_off(hdmi); in dw_hdmi_phy_disable()
1689 enum drm_connector_status dw_hdmi_phy_read_hpd(struct dw_hdmi *hdmi, in dw_hdmi_phy_read_hpd() argument
1692 return hdmi_readb(hdmi, HDMI_PHY_STAT0) & HDMI_PHY_HPD ? in dw_hdmi_phy_read_hpd()
1697 void dw_hdmi_phy_update_hpd(struct dw_hdmi *hdmi, void *data, in dw_hdmi_phy_update_hpd() argument
1700 u8 old_mask = hdmi->phy_mask; in dw_hdmi_phy_update_hpd()
1703 hdmi->phy_mask |= HDMI_PHY_RX_SENSE; in dw_hdmi_phy_update_hpd()
1705 hdmi->phy_mask &= ~HDMI_PHY_RX_SENSE; in dw_hdmi_phy_update_hpd()
1707 if (old_mask != hdmi->phy_mask) in dw_hdmi_phy_update_hpd()
1708 hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0); in dw_hdmi_phy_update_hpd()
1712 void dw_hdmi_phy_setup_hpd(struct dw_hdmi *hdmi, void *data) in dw_hdmi_phy_setup_hpd() argument
1718 hdmi_writeb(hdmi, HDMI_PHY_HPD | HDMI_PHY_RX_SENSE, HDMI_PHY_POL0); in dw_hdmi_phy_setup_hpd()
1719 hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE, in dw_hdmi_phy_setup_hpd()
1723 hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0); in dw_hdmi_phy_setup_hpd()
1726 hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE, in dw_hdmi_phy_setup_hpd()
1728 hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE), in dw_hdmi_phy_setup_hpd()
1741 /* -----------------------------------------------------------------------------
1742 * HDMI TX Setup
1745 static void hdmi_tx_hdcp_config(struct dw_hdmi *hdmi) in hdmi_tx_hdcp_config() argument
1749 if (hdmi->hdmi_data.video_mode.mdataenablepolarity) in hdmi_tx_hdcp_config()
1755 hdmi_modb(hdmi, HDMI_A_HDCPCFG0_RXDETECT_DISABLE, in hdmi_tx_hdcp_config()
1758 hdmi_modb(hdmi, de, HDMI_A_VIDPOLCFG_DATAENPOL_MASK, HDMI_A_VIDPOLCFG); in hdmi_tx_hdcp_config()
1760 hdmi_modb(hdmi, HDMI_A_HDCPCFG1_ENCRYPTIONDISABLE_DISABLE, in hdmi_tx_hdcp_config()
1764 static void hdmi_config_AVI(struct dw_hdmi *hdmi, in hdmi_config_AVI() argument
1774 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_config_AVI()
1776 hdmi->hdmi_data.rgb_limited_range ? in hdmi_config_AVI()
1785 if (hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_config_AVI()
1787 else if (hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_config_AVI()
1789 else if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_config_AVI()
1795 if (!hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_config_AVI()
1796 switch (hdmi->hdmi_data.enc_out_encoding) { in hdmi_config_AVI()
1798 if (hdmi->hdmi_data.enc_in_encoding == V4L2_YCBCR_ENC_XV601) in hdmi_config_AVI()
1806 if (hdmi->hdmi_data.enc_in_encoding == V4L2_YCBCR_ENC_XV709) in hdmi_config_AVI()
1843 hdmi_writeb(hdmi, val, HDMI_FC_AVICONF0); in hdmi_config_AVI()
1849 hdmi_writeb(hdmi, val, HDMI_FC_AVICONF1); in hdmi_config_AVI()
1857 hdmi_writeb(hdmi, val, HDMI_FC_AVICONF2); in hdmi_config_AVI()
1861 hdmi_writeb(hdmi, val, HDMI_FC_AVIVID); in hdmi_config_AVI()
1863 /* AVI Data Byte 5- set up input and output pixel repetition */ in hdmi_config_AVI()
1864 val = (((hdmi->hdmi_data.video_mode.mpixelrepetitioninput + 1) << in hdmi_config_AVI()
1867 ((hdmi->hdmi_data.video_mode.mpixelrepetitionoutput << in hdmi_config_AVI()
1870 hdmi_writeb(hdmi, val, HDMI_FC_PRCONF); in hdmi_config_AVI()
1878 hdmi_writeb(hdmi, val, HDMI_FC_AVICONF3); in hdmi_config_AVI()
1880 /* AVI Data Bytes 6-13 */ in hdmi_config_AVI()
1881 hdmi_writeb(hdmi, frame.top_bar & 0xff, HDMI_FC_AVIETB0); in hdmi_config_AVI()
1882 hdmi_writeb(hdmi, (frame.top_bar >> 8) & 0xff, HDMI_FC_AVIETB1); in hdmi_config_AVI()
1883 hdmi_writeb(hdmi, frame.bottom_bar & 0xff, HDMI_FC_AVISBB0); in hdmi_config_AVI()
1884 hdmi_writeb(hdmi, (frame.bottom_bar >> 8) & 0xff, HDMI_FC_AVISBB1); in hdmi_config_AVI()
1885 hdmi_writeb(hdmi, frame.left_bar & 0xff, HDMI_FC_AVIELB0); in hdmi_config_AVI()
1886 hdmi_writeb(hdmi, (frame.left_bar >> 8) & 0xff, HDMI_FC_AVIELB1); in hdmi_config_AVI()
1887 hdmi_writeb(hdmi, frame.right_bar & 0xff, HDMI_FC_AVISRB0); in hdmi_config_AVI()
1888 hdmi_writeb(hdmi, (frame.right_bar >> 8) & 0xff, HDMI_FC_AVISRB1); in hdmi_config_AVI()
1891 static void hdmi_config_vendor_specific_infoframe(struct dw_hdmi *hdmi, in hdmi_config_vendor_specific_infoframe() argument
1912 dev_err(hdmi->dev, "Failed to pack vendor infoframe: %zd\n", in hdmi_config_vendor_specific_infoframe()
1916 hdmi_mask_writeb(hdmi, 0, HDMI_FC_DATAUTO0, HDMI_FC_DATAUTO0_VSD_OFFSET, in hdmi_config_vendor_specific_infoframe()
1919 /* Set the length of HDMI vendor specific InfoFrame payload */ in hdmi_config_vendor_specific_infoframe()
1920 hdmi_writeb(hdmi, buffer[2], HDMI_FC_VSDSIZE); in hdmi_config_vendor_specific_infoframe()
1923 hdmi_writeb(hdmi, buffer[4], HDMI_FC_VSDIEEEID0); in hdmi_config_vendor_specific_infoframe()
1924 hdmi_writeb(hdmi, buffer[5], HDMI_FC_VSDIEEEID1); in hdmi_config_vendor_specific_infoframe()
1925 hdmi_writeb(hdmi, buffer[6], HDMI_FC_VSDIEEEID2); in hdmi_config_vendor_specific_infoframe()
1928 hdmi_writeb(hdmi, buffer[7], HDMI_FC_VSDPAYLOAD0); in hdmi_config_vendor_specific_infoframe()
1929 hdmi_writeb(hdmi, buffer[8], HDMI_FC_VSDPAYLOAD1); in hdmi_config_vendor_specific_infoframe()
1932 hdmi_writeb(hdmi, buffer[9], HDMI_FC_VSDPAYLOAD2); in hdmi_config_vendor_specific_infoframe()
1935 hdmi_writeb(hdmi, 1, HDMI_FC_DATAUTO1); in hdmi_config_vendor_specific_infoframe()
1938 hdmi_writeb(hdmi, 0x11, HDMI_FC_DATAUTO2); in hdmi_config_vendor_specific_infoframe()
1941 hdmi_mask_writeb(hdmi, 1, HDMI_FC_DATAUTO0, HDMI_FC_DATAUTO0_VSD_OFFSET, in hdmi_config_vendor_specific_infoframe()
1945 static void hdmi_config_drm_infoframe(struct dw_hdmi *hdmi, in hdmi_config_drm_infoframe() argument
1948 const struct drm_connector_state *conn_state = connector->state; in hdmi_config_drm_infoframe()
1954 if (!hdmi->plat_data->use_drm_infoframe) in hdmi_config_drm_infoframe()
1957 hdmi_modb(hdmi, HDMI_FC_PACKET_TX_EN_DRM_DISABLE, in hdmi_config_drm_infoframe()
1966 dev_err(hdmi->dev, "Failed to pack drm infoframe: %zd\n", err); in hdmi_config_drm_infoframe()
1970 hdmi_writeb(hdmi, frame.version, HDMI_FC_DRM_HB0); in hdmi_config_drm_infoframe()
1971 hdmi_writeb(hdmi, frame.length, HDMI_FC_DRM_HB1); in hdmi_config_drm_infoframe()
1974 hdmi_writeb(hdmi, buffer[4 + i], HDMI_FC_DRM_PB0 + i); in hdmi_config_drm_infoframe()
1976 hdmi_writeb(hdmi, 1, HDMI_FC_DRM_UP); in hdmi_config_drm_infoframe()
1977 hdmi_modb(hdmi, HDMI_FC_PACKET_TX_EN_DRM_ENABLE, in hdmi_config_drm_infoframe()
1981 static void hdmi_av_composer(struct dw_hdmi *hdmi, in hdmi_av_composer() argument
1986 const struct drm_hdmi_info *hdmi_info = &display->hdmi; in hdmi_av_composer()
1987 struct hdmi_vmode *vmode = &hdmi->hdmi_data.video_mode; in hdmi_av_composer()
1991 vmode->mpixelclock = mode->clock * 1000; in hdmi_av_composer()
1993 dev_dbg(hdmi->dev, "final pixclk = %d\n", vmode->mpixelclock); in hdmi_av_composer()
1995 vmode->mtmdsclock = vmode->mpixelclock; in hdmi_av_composer()
1997 if (!hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_av_composer()
1999 hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_av_composer()
2001 vmode->mtmdsclock = vmode->mpixelclock * 2; in hdmi_av_composer()
2004 vmode->mtmdsclock = vmode->mpixelclock * 3 / 2; in hdmi_av_composer()
2007 vmode->mtmdsclock = vmode->mpixelclock * 5 / 4; in hdmi_av_composer()
2012 if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_av_composer()
2013 vmode->mtmdsclock /= 2; in hdmi_av_composer()
2015 dev_dbg(hdmi->dev, "final tmdsclock = %d\n", vmode->mtmdsclock); in hdmi_av_composer()
2018 inv_val = (hdmi->hdmi_data.hdcp_enable || in hdmi_av_composer()
2019 (dw_hdmi_support_scdc(hdmi, display) && in hdmi_av_composer()
2020 (vmode->mtmdsclock > HDMI14_MAX_TMDSCLK || in hdmi_av_composer()
2021 hdmi_info->scdc.scrambling.low_rates)) ? in hdmi_av_composer()
2025 inv_val |= mode->flags & DRM_MODE_FLAG_PVSYNC ? in hdmi_av_composer()
2029 inv_val |= mode->flags & DRM_MODE_FLAG_PHSYNC ? in hdmi_av_composer()
2033 inv_val |= (vmode->mdataenablepolarity ? in hdmi_av_composer()
2037 if (hdmi->vic == 39) in hdmi_av_composer()
2040 inv_val |= mode->flags & DRM_MODE_FLAG_INTERLACE ? in hdmi_av_composer()
2044 inv_val |= mode->flags & DRM_MODE_FLAG_INTERLACE ? in hdmi_av_composer()
2048 inv_val |= hdmi->sink_is_hdmi ? in hdmi_av_composer()
2052 hdmi_writeb(hdmi, inv_val, HDMI_FC_INVIDCONF); in hdmi_av_composer()
2054 hdisplay = mode->hdisplay; in hdmi_av_composer()
2055 hblank = mode->htotal - mode->hdisplay; in hdmi_av_composer()
2056 h_de_hs = mode->hsync_start - mode->hdisplay; in hdmi_av_composer()
2057 hsync_len = mode->hsync_end - mode->hsync_start; in hdmi_av_composer()
2063 if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_av_composer()
2070 vdisplay = mode->vdisplay; in hdmi_av_composer()
2071 vblank = mode->vtotal - mode->vdisplay; in hdmi_av_composer()
2072 v_de_vs = mode->vsync_start - mode->vdisplay; in hdmi_av_composer()
2073 vsync_len = mode->vsync_end - mode->vsync_start; in hdmi_av_composer()
2079 if (mode->flags & DRM_MODE_FLAG_INTERLACE) { in hdmi_av_composer()
2087 if (dw_hdmi_support_scdc(hdmi, display)) { in hdmi_av_composer()
2088 if (vmode->mtmdsclock > HDMI14_MAX_TMDSCLK || in hdmi_av_composer()
2089 hdmi_info->scdc.scrambling.low_rates) { in hdmi_av_composer()
2099 drm_scdc_readb(hdmi->ddc, SCDC_SINK_VERSION, in hdmi_av_composer()
2101 drm_scdc_writeb(hdmi->ddc, SCDC_SOURCE_VERSION, in hdmi_av_composer()
2105 drm_scdc_set_scrambling(hdmi->curr_conn, 1); in hdmi_av_composer()
2109 * that the quasi-static configuration bit in hdmi_av_composer()
2114 hdmi_writeb(hdmi, (u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, in hdmi_av_composer()
2116 hdmi_writeb(hdmi, 1, HDMI_FC_SCRAMBLER_CTRL); in hdmi_av_composer()
2118 hdmi_writeb(hdmi, 0, HDMI_FC_SCRAMBLER_CTRL); in hdmi_av_composer()
2119 hdmi_writeb(hdmi, (u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, in hdmi_av_composer()
2121 drm_scdc_set_scrambling(hdmi->curr_conn, 0); in hdmi_av_composer()
2126 hdmi_writeb(hdmi, hdisplay >> 8, HDMI_FC_INHACTV1); in hdmi_av_composer()
2127 hdmi_writeb(hdmi, hdisplay, HDMI_FC_INHACTV0); in hdmi_av_composer()
2130 hdmi_writeb(hdmi, vdisplay >> 8, HDMI_FC_INVACTV1); in hdmi_av_composer()
2131 hdmi_writeb(hdmi, vdisplay, HDMI_FC_INVACTV0); in hdmi_av_composer()
2134 hdmi_writeb(hdmi, hblank >> 8, HDMI_FC_INHBLANK1); in hdmi_av_composer()
2135 hdmi_writeb(hdmi, hblank, HDMI_FC_INHBLANK0); in hdmi_av_composer()
2138 hdmi_writeb(hdmi, vblank, HDMI_FC_INVBLANK); in hdmi_av_composer()
2141 hdmi_writeb(hdmi, h_de_hs >> 8, HDMI_FC_HSYNCINDELAY1); in hdmi_av_composer()
2142 hdmi_writeb(hdmi, h_de_hs, HDMI_FC_HSYNCINDELAY0); in hdmi_av_composer()
2145 hdmi_writeb(hdmi, v_de_vs, HDMI_FC_VSYNCINDELAY); in hdmi_av_composer()
2148 hdmi_writeb(hdmi, hsync_len >> 8, HDMI_FC_HSYNCINWIDTH1); in hdmi_av_composer()
2149 hdmi_writeb(hdmi, hsync_len, HDMI_FC_HSYNCINWIDTH0); in hdmi_av_composer()
2152 hdmi_writeb(hdmi, vsync_len, HDMI_FC_VSYNCINWIDTH); in hdmi_av_composer()
2155 /* HDMI Initialization Step B.4 */
2156 static void dw_hdmi_enable_video_path(struct dw_hdmi *hdmi) in dw_hdmi_enable_video_path() argument
2159 hdmi_writeb(hdmi, 12, HDMI_FC_CTRLDUR); in dw_hdmi_enable_video_path()
2160 hdmi_writeb(hdmi, 32, HDMI_FC_EXCTRLDUR); in dw_hdmi_enable_video_path()
2161 hdmi_writeb(hdmi, 1, HDMI_FC_EXCTRLSPAC); in dw_hdmi_enable_video_path()
2164 hdmi_writeb(hdmi, 0x0B, HDMI_FC_CH0PREAM); in dw_hdmi_enable_video_path()
2165 hdmi_writeb(hdmi, 0x16, HDMI_FC_CH1PREAM); in dw_hdmi_enable_video_path()
2166 hdmi_writeb(hdmi, 0x21, HDMI_FC_CH2PREAM); in dw_hdmi_enable_video_path()
2169 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_HDCPCLK_DISABLE | in dw_hdmi_enable_video_path()
2174 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_PIXELCLK_DISABLE; in dw_hdmi_enable_video_path()
2175 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2177 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_TMDSCLK_DISABLE; in dw_hdmi_enable_video_path()
2178 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2181 if (is_csc_needed(hdmi)) { in dw_hdmi_enable_video_path()
2182 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_CSCCLK_DISABLE; in dw_hdmi_enable_video_path()
2183 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2185 hdmi_writeb(hdmi, HDMI_MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_IN_PATH, in dw_hdmi_enable_video_path()
2188 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_CSCCLK_DISABLE; in dw_hdmi_enable_video_path()
2189 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2191 hdmi_writeb(hdmi, HDMI_MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_BYPASS, in dw_hdmi_enable_video_path()
2197 static void dw_hdmi_clear_overflow(struct dw_hdmi *hdmi) in dw_hdmi_clear_overflow() argument
2209 * The number of iterations matters and depends on the HDMI TX revision in dw_hdmi_clear_overflow()
2212 * i.MX6DL (v1.31a), Allwinner SoCs (v1.32a), Rockchip RK3288 SoC (v2.00a), in dw_hdmi_clear_overflow()
2218 switch (hdmi->version) { in dw_hdmi_clear_overflow()
2228 hdmi_writeb(hdmi, (u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, HDMI_MC_SWRSTZ); in dw_hdmi_clear_overflow()
2230 val = hdmi_readb(hdmi, HDMI_FC_INVIDCONF); in dw_hdmi_clear_overflow()
2232 hdmi_writeb(hdmi, val, HDMI_FC_INVIDCONF); in dw_hdmi_clear_overflow()
2235 static void hdmi_disable_overflow_interrupts(struct dw_hdmi *hdmi) in hdmi_disable_overflow_interrupts() argument
2237 hdmi_writeb(hdmi, HDMI_IH_MUTE_FC_STAT2_OVERFLOW_MASK, in hdmi_disable_overflow_interrupts()
2241 static int dw_hdmi_setup(struct dw_hdmi *hdmi, in dw_hdmi_setup() argument
2247 hdmi_disable_overflow_interrupts(hdmi); in dw_hdmi_setup()
2249 hdmi->vic = drm_match_cea_mode(mode); in dw_hdmi_setup()
2251 if (!hdmi->vic) { in dw_hdmi_setup()
2252 dev_dbg(hdmi->dev, "Non-CEA mode used in HDMI\n"); in dw_hdmi_setup()
2254 dev_dbg(hdmi->dev, "CEA mode used vic=%d\n", hdmi->vic); in dw_hdmi_setup()
2257 if ((hdmi->vic == 6) || (hdmi->vic == 7) || in dw_hdmi_setup()
2258 (hdmi->vic == 21) || (hdmi->vic == 22) || in dw_hdmi_setup()
2259 (hdmi->vic == 2) || (hdmi->vic == 3) || in dw_hdmi_setup()
2260 (hdmi->vic == 17) || (hdmi->vic == 18)) in dw_hdmi_setup()
2261 hdmi->hdmi_data.enc_out_encoding = V4L2_YCBCR_ENC_601; in dw_hdmi_setup()
2263 hdmi->hdmi_data.enc_out_encoding = V4L2_YCBCR_ENC_709; in dw_hdmi_setup()
2265 hdmi->hdmi_data.video_mode.mpixelrepetitionoutput = 0; in dw_hdmi_setup()
2266 hdmi->hdmi_data.video_mode.mpixelrepetitioninput = 0; in dw_hdmi_setup()
2268 if (hdmi->hdmi_data.enc_in_bus_format == MEDIA_BUS_FMT_FIXED) in dw_hdmi_setup()
2269 hdmi->hdmi_data.enc_in_bus_format = MEDIA_BUS_FMT_RGB888_1X24; in dw_hdmi_setup()
2272 if (hdmi->plat_data->input_bus_encoding) in dw_hdmi_setup()
2273 hdmi->hdmi_data.enc_in_encoding = in dw_hdmi_setup()
2274 hdmi->plat_data->input_bus_encoding; in dw_hdmi_setup()
2276 hdmi->hdmi_data.enc_in_encoding = V4L2_YCBCR_ENC_DEFAULT; in dw_hdmi_setup()
2278 if (hdmi->hdmi_data.enc_out_bus_format == MEDIA_BUS_FMT_FIXED) in dw_hdmi_setup()
2279 hdmi->hdmi_data.enc_out_bus_format = MEDIA_BUS_FMT_RGB888_1X24; in dw_hdmi_setup()
2281 hdmi->hdmi_data.rgb_limited_range = hdmi->sink_is_hdmi && in dw_hdmi_setup()
2285 hdmi->hdmi_data.pix_repet_factor = 0; in dw_hdmi_setup()
2286 hdmi->hdmi_data.hdcp_enable = 0; in dw_hdmi_setup()
2287 hdmi->hdmi_data.video_mode.mdataenablepolarity = true; in dw_hdmi_setup()
2289 /* HDMI Initialization Step B.1 */ in dw_hdmi_setup()
2290 hdmi_av_composer(hdmi, &connector->display_info, mode); in dw_hdmi_setup()
2292 /* HDMI Initializateion Step B.2 */ in dw_hdmi_setup()
2293 ret = hdmi->phy.ops->init(hdmi, hdmi->phy.data, in dw_hdmi_setup()
2294 &connector->display_info, in dw_hdmi_setup()
2295 &hdmi->previous_mode); in dw_hdmi_setup()
2298 hdmi->phy.enabled = true; in dw_hdmi_setup()
2300 /* HDMI Initialization Step B.3 */ in dw_hdmi_setup()
2301 dw_hdmi_enable_video_path(hdmi); in dw_hdmi_setup()
2303 if (hdmi->sink_has_audio) { in dw_hdmi_setup()
2304 dev_dbg(hdmi->dev, "sink has audio support\n"); in dw_hdmi_setup()
2306 /* HDMI Initialization Step E - Configure audio */ in dw_hdmi_setup()
2307 hdmi_clk_regenerator_update_pixel_clock(hdmi); in dw_hdmi_setup()
2308 hdmi_enable_audio_clk(hdmi, hdmi->audio_enable); in dw_hdmi_setup()
2312 if (hdmi->sink_is_hdmi) { in dw_hdmi_setup()
2313 dev_dbg(hdmi->dev, "%s HDMI mode\n", __func__); in dw_hdmi_setup()
2315 /* HDMI Initialization Step F - Configure AVI InfoFrame */ in dw_hdmi_setup()
2316 hdmi_config_AVI(hdmi, connector, mode); in dw_hdmi_setup()
2317 hdmi_config_vendor_specific_infoframe(hdmi, connector, mode); in dw_hdmi_setup()
2318 hdmi_config_drm_infoframe(hdmi, connector); in dw_hdmi_setup()
2320 dev_dbg(hdmi->dev, "%s DVI mode\n", __func__); in dw_hdmi_setup()
2323 hdmi_video_packetize(hdmi); in dw_hdmi_setup()
2324 hdmi_video_csc(hdmi); in dw_hdmi_setup()
2325 hdmi_video_sample(hdmi); in dw_hdmi_setup()
2326 hdmi_tx_hdcp_config(hdmi); in dw_hdmi_setup()
2328 dw_hdmi_clear_overflow(hdmi); in dw_hdmi_setup()
2333 static void initialize_hdmi_ih_mutes(struct dw_hdmi *hdmi) in initialize_hdmi_ih_mutes() argument
2342 * Disable top level interrupt bits in HDMI block in initialize_hdmi_ih_mutes()
2344 ih_mute = hdmi_readb(hdmi, HDMI_IH_MUTE) | in initialize_hdmi_ih_mutes()
2348 hdmi_writeb(hdmi, ih_mute, HDMI_IH_MUTE); in initialize_hdmi_ih_mutes()
2351 hdmi_writeb(hdmi, 0xff, HDMI_VP_MASK); in initialize_hdmi_ih_mutes()
2352 hdmi_writeb(hdmi, 0xff, HDMI_FC_MASK0); in initialize_hdmi_ih_mutes()
2353 hdmi_writeb(hdmi, 0xff, HDMI_FC_MASK1); in initialize_hdmi_ih_mutes()
2354 hdmi_writeb(hdmi, 0xff, HDMI_FC_MASK2); in initialize_hdmi_ih_mutes()
2355 hdmi_writeb(hdmi, 0xff, HDMI_PHY_MASK0); in initialize_hdmi_ih_mutes()
2356 hdmi_writeb(hdmi, 0xff, HDMI_PHY_I2CM_INT_ADDR); in initialize_hdmi_ih_mutes()
2357 hdmi_writeb(hdmi, 0xff, HDMI_PHY_I2CM_CTLINT_ADDR); in initialize_hdmi_ih_mutes()
2358 hdmi_writeb(hdmi, 0xff, HDMI_AUD_INT); in initialize_hdmi_ih_mutes()
2359 hdmi_writeb(hdmi, 0xff, HDMI_AUD_SPDIFINT); in initialize_hdmi_ih_mutes()
2360 hdmi_writeb(hdmi, 0xff, HDMI_AUD_HBR_MASK); in initialize_hdmi_ih_mutes()
2361 hdmi_writeb(hdmi, 0xff, HDMI_GP_MASK); in initialize_hdmi_ih_mutes()
2362 hdmi_writeb(hdmi, 0xff, HDMI_A_APIINTMSK); in initialize_hdmi_ih_mutes()
2363 hdmi_writeb(hdmi, 0xff, HDMI_I2CM_INT); in initialize_hdmi_ih_mutes()
2364 hdmi_writeb(hdmi, 0xff, HDMI_I2CM_CTLINT); in initialize_hdmi_ih_mutes()
2367 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_FC_STAT0); in initialize_hdmi_ih_mutes()
2368 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_FC_STAT1); in initialize_hdmi_ih_mutes()
2369 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_FC_STAT2); in initialize_hdmi_ih_mutes()
2370 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_AS_STAT0); in initialize_hdmi_ih_mutes()
2371 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_PHY_STAT0); in initialize_hdmi_ih_mutes()
2372 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_I2CM_STAT0); in initialize_hdmi_ih_mutes()
2373 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_CEC_STAT0); in initialize_hdmi_ih_mutes()
2374 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_VP_STAT0); in initialize_hdmi_ih_mutes()
2375 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_I2CMPHY_STAT0); in initialize_hdmi_ih_mutes()
2376 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_AHBDMAAUD_STAT0); in initialize_hdmi_ih_mutes()
2378 /* Enable top level interrupt bits in HDMI block */ in initialize_hdmi_ih_mutes()
2381 hdmi_writeb(hdmi, ih_mute, HDMI_IH_MUTE); in initialize_hdmi_ih_mutes()
2384 static void dw_hdmi_poweron(struct dw_hdmi *hdmi) in dw_hdmi_poweron() argument
2386 hdmi->bridge_is_on = true; in dw_hdmi_poweron()
2390 * is only be called when !hdmi->disabled. in dw_hdmi_poweron()
2392 dw_hdmi_setup(hdmi, hdmi->curr_conn, &hdmi->previous_mode); in dw_hdmi_poweron()
2395 static void dw_hdmi_poweroff(struct dw_hdmi *hdmi) in dw_hdmi_poweroff() argument
2397 if (hdmi->phy.enabled) { in dw_hdmi_poweroff()
2398 hdmi->phy.ops->disable(hdmi, hdmi->phy.data); in dw_hdmi_poweroff()
2399 hdmi->phy.enabled = false; in dw_hdmi_poweroff()
2402 hdmi->bridge_is_on = false; in dw_hdmi_poweroff()
2405 static void dw_hdmi_update_power(struct dw_hdmi *hdmi) in dw_hdmi_update_power() argument
2407 int force = hdmi->force; in dw_hdmi_update_power()
2409 if (hdmi->disabled) { in dw_hdmi_update_power()
2412 if (hdmi->rxsense) in dw_hdmi_update_power()
2419 if (hdmi->bridge_is_on) in dw_hdmi_update_power()
2420 dw_hdmi_poweroff(hdmi); in dw_hdmi_update_power()
2422 if (!hdmi->bridge_is_on) in dw_hdmi_update_power()
2423 dw_hdmi_poweron(hdmi); in dw_hdmi_update_power()
2439 static void dw_hdmi_update_phy_mask(struct dw_hdmi *hdmi) in dw_hdmi_update_phy_mask() argument
2441 if (hdmi->phy.ops->update_hpd) in dw_hdmi_update_phy_mask()
2442 hdmi->phy.ops->update_hpd(hdmi, hdmi->phy.data, in dw_hdmi_update_phy_mask()
2443 hdmi->force, hdmi->disabled, in dw_hdmi_update_phy_mask()
2444 hdmi->rxsense); in dw_hdmi_update_phy_mask()
2447 static enum drm_connector_status dw_hdmi_detect(struct dw_hdmi *hdmi) in dw_hdmi_detect() argument
2451 result = hdmi->phy.ops->read_hpd(hdmi, hdmi->phy.data); in dw_hdmi_detect()
2452 hdmi->last_connector_result = result; in dw_hdmi_detect()
2457 static struct edid *dw_hdmi_get_edid(struct dw_hdmi *hdmi, in dw_hdmi_get_edid() argument
2462 if (!hdmi->ddc) in dw_hdmi_get_edid()
2465 edid = drm_get_edid(connector, hdmi->ddc); in dw_hdmi_get_edid()
2467 dev_dbg(hdmi->dev, "failed to get edid\n"); in dw_hdmi_get_edid()
2471 dev_dbg(hdmi->dev, "got edid: width[%d] x height[%d]\n", in dw_hdmi_get_edid()
2472 edid->width_cm, edid->height_cm); in dw_hdmi_get_edid()
2474 hdmi->sink_is_hdmi = drm_detect_hdmi_monitor(edid); in dw_hdmi_get_edid()
2475 hdmi->sink_has_audio = drm_detect_monitor_audio(edid); in dw_hdmi_get_edid()
2480 /* -----------------------------------------------------------------------------
2487 struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, in dw_hdmi_connector_detect() local
2489 return dw_hdmi_detect(hdmi); in dw_hdmi_connector_detect()
2494 struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, in dw_hdmi_connector_get_modes() local
2499 edid = dw_hdmi_get_edid(hdmi, connector); in dw_hdmi_connector_get_modes()
2504 cec_notifier_set_phys_addr_from_edid(hdmi->cec_notifier, edid); in dw_hdmi_connector_get_modes()
2518 struct drm_crtc *crtc = new_state->crtc; in dw_hdmi_connector_atomic_check()
2529 crtc_state->mode_changed = true; in dw_hdmi_connector_atomic_check()
2537 struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, in dw_hdmi_connector_force() local
2540 mutex_lock(&hdmi->mutex); in dw_hdmi_connector_force()
2541 hdmi->force = connector->force; in dw_hdmi_connector_force()
2542 dw_hdmi_update_power(hdmi); in dw_hdmi_connector_force()
2543 dw_hdmi_update_phy_mask(hdmi); in dw_hdmi_connector_force()
2544 mutex_unlock(&hdmi->mutex); in dw_hdmi_connector_force()
2562 static int dw_hdmi_connector_create(struct dw_hdmi *hdmi) in dw_hdmi_connector_create() argument
2564 struct drm_connector *connector = &hdmi->connector; in dw_hdmi_connector_create()
2568 if (hdmi->version >= 0x200a) in dw_hdmi_connector_create()
2569 connector->ycbcr_420_allowed = in dw_hdmi_connector_create()
2570 hdmi->plat_data->ycbcr_420_allowed; in dw_hdmi_connector_create()
2572 connector->ycbcr_420_allowed = false; in dw_hdmi_connector_create()
2574 connector->interlace_allowed = 1; in dw_hdmi_connector_create()
2575 connector->polled = DRM_CONNECTOR_POLL_HPD; in dw_hdmi_connector_create()
2579 drm_connector_init_with_ddc(hdmi->bridge.dev, connector, in dw_hdmi_connector_create()
2582 hdmi->ddc); in dw_hdmi_connector_create()
2592 if (hdmi->version >= 0x200a && hdmi->plat_data->use_drm_infoframe) in dw_hdmi_connector_create()
2595 drm_connector_attach_encoder(connector, hdmi->bridge.encoder); in dw_hdmi_connector_create()
2599 notifier = cec_notifier_conn_register(hdmi->dev, NULL, &conn_info); in dw_hdmi_connector_create()
2601 return -ENOMEM; in dw_hdmi_connector_create()
2603 mutex_lock(&hdmi->cec_notifier_mutex); in dw_hdmi_connector_create()
2604 hdmi->cec_notifier = notifier; in dw_hdmi_connector_create()
2605 mutex_unlock(&hdmi->cec_notifier_mutex); in dw_hdmi_connector_create()
2610 /* -----------------------------------------------------------------------------
2616 * - MEDIA_BUS_FMT_UYYVYY16_0_5X48,
2617 * - MEDIA_BUS_FMT_UYYVYY12_0_5X36,
2618 * - MEDIA_BUS_FMT_UYYVYY10_0_5X30,
2619 * - MEDIA_BUS_FMT_UYYVYY8_0_5X24,
2620 * - MEDIA_BUS_FMT_YUV16_1X48,
2621 * - MEDIA_BUS_FMT_RGB161616_1X48,
2622 * - MEDIA_BUS_FMT_UYVY12_1X24,
2623 * - MEDIA_BUS_FMT_YUV12_1X36,
2624 * - MEDIA_BUS_FMT_RGB121212_1X36,
2625 * - MEDIA_BUS_FMT_UYVY10_1X20,
2626 * - MEDIA_BUS_FMT_YUV10_1X30,
2627 * - MEDIA_BUS_FMT_RGB101010_1X30,
2628 * - MEDIA_BUS_FMT_UYVY8_1X16,
2629 * - MEDIA_BUS_FMT_YUV8_1X24,
2630 * - MEDIA_BUS_FMT_RGB888_1X24,
2642 struct drm_connector *conn = conn_state->connector; in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2643 struct drm_display_info *info = &conn->display_info; in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2644 struct drm_display_mode *mode = &crtc_state->mode; in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2645 u8 max_bpc = conn_state->max_requested_bpc; in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2646 bool is_hdmi2_sink = info->hdmi.scdc.supported || in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2647 (info->color_formats & DRM_COLOR_FORMAT_YCBCR420); in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2658 /* If dw-hdmi is the first or only bridge, avoid negociating with ourselves */ in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2659 if (list_is_singular(&bridge->encoder->bridge_chain) || in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2660 list_is_first(&bridge->chain_node, &bridge->encoder->bridge_chain)) { in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2671 if (conn->ycbcr_420_allowed && in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2676 if (max_bpc >= 16 && info->bpc == 16 && in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2677 (info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_48)) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2680 if (max_bpc >= 12 && info->bpc >= 12 && in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2681 (info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_36)) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2684 if (max_bpc >= 10 && info->bpc >= 10 && in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2685 (info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_30)) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2705 if (max_bpc >= 16 && info->bpc == 16) { in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2706 if (info->color_formats & DRM_COLOR_FORMAT_YCBCR444) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2712 if (max_bpc >= 12 && info->bpc >= 12) { in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2713 if (info->color_formats & DRM_COLOR_FORMAT_YCBCR422) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2716 if (info->color_formats & DRM_COLOR_FORMAT_YCBCR444) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2722 if (max_bpc >= 10 && info->bpc >= 10) { in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2723 if (info->color_formats & DRM_COLOR_FORMAT_YCBCR422) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2726 if (info->color_formats & DRM_COLOR_FORMAT_YCBCR444) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2732 if (info->color_formats & DRM_COLOR_FORMAT_YCBCR422) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2735 if (info->color_formats & DRM_COLOR_FORMAT_YCBCR444) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2745 * - MEDIA_BUS_FMT_RGB888_1X24
2746 * - MEDIA_BUS_FMT_YUV8_1X24
2747 * - MEDIA_BUS_FMT_UYVY8_1X16
2748 * - MEDIA_BUS_FMT_UYYVYY8_0_5X24
2749 * - MEDIA_BUS_FMT_RGB101010_1X30
2750 * - MEDIA_BUS_FMT_YUV10_1X30
2751 * - MEDIA_BUS_FMT_UYVY10_1X20
2752 * - MEDIA_BUS_FMT_UYYVYY10_0_5X30
2753 * - MEDIA_BUS_FMT_RGB121212_1X36
2754 * - MEDIA_BUS_FMT_YUV12_1X36
2755 * - MEDIA_BUS_FMT_UYVY12_1X24
2756 * - MEDIA_BUS_FMT_UYYVYY12_0_5X36
2757 * - MEDIA_BUS_FMT_RGB161616_1X48
2758 * - MEDIA_BUS_FMT_YUV16_1X48
2759 * - MEDIA_BUS_FMT_UYYVYY16_0_5X48
2872 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_atomic_check() local
2874 hdmi->hdmi_data.enc_out_bus_format = in dw_hdmi_bridge_atomic_check()
2875 bridge_state->output_bus_cfg.format; in dw_hdmi_bridge_atomic_check()
2877 hdmi->hdmi_data.enc_in_bus_format = in dw_hdmi_bridge_atomic_check()
2878 bridge_state->input_bus_cfg.format; in dw_hdmi_bridge_atomic_check()
2880 dev_dbg(hdmi->dev, "input format 0x%04x, output format 0x%04x\n", in dw_hdmi_bridge_atomic_check()
2881 bridge_state->input_bus_cfg.format, in dw_hdmi_bridge_atomic_check()
2882 bridge_state->output_bus_cfg.format); in dw_hdmi_bridge_atomic_check()
2890 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_attach() local
2893 return drm_bridge_attach(bridge->encoder, hdmi->next_bridge, in dw_hdmi_bridge_attach()
2896 return dw_hdmi_connector_create(hdmi); in dw_hdmi_bridge_attach()
2901 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_detach() local
2903 mutex_lock(&hdmi->cec_notifier_mutex); in dw_hdmi_bridge_detach()
2904 cec_notifier_conn_unregister(hdmi->cec_notifier); in dw_hdmi_bridge_detach()
2905 hdmi->cec_notifier = NULL; in dw_hdmi_bridge_detach()
2906 mutex_unlock(&hdmi->cec_notifier_mutex); in dw_hdmi_bridge_detach()
2914 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_mode_valid() local
2915 const struct dw_hdmi_plat_data *pdata = hdmi->plat_data; in dw_hdmi_bridge_mode_valid()
2918 /* We don't support double-clocked modes */ in dw_hdmi_bridge_mode_valid()
2919 if (mode->flags & DRM_MODE_FLAG_DBLCLK) in dw_hdmi_bridge_mode_valid()
2922 if (pdata->mode_valid) in dw_hdmi_bridge_mode_valid()
2923 mode_status = pdata->mode_valid(hdmi, pdata->priv_data, info, in dw_hdmi_bridge_mode_valid()
2933 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_mode_set() local
2935 mutex_lock(&hdmi->mutex); in dw_hdmi_bridge_mode_set()
2938 drm_mode_copy(&hdmi->previous_mode, mode); in dw_hdmi_bridge_mode_set()
2940 mutex_unlock(&hdmi->mutex); in dw_hdmi_bridge_mode_set()
2946 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_atomic_disable() local
2948 mutex_lock(&hdmi->mutex); in dw_hdmi_bridge_atomic_disable()
2949 hdmi->disabled = true; in dw_hdmi_bridge_atomic_disable()
2950 hdmi->curr_conn = NULL; in dw_hdmi_bridge_atomic_disable()
2951 dw_hdmi_update_power(hdmi); in dw_hdmi_bridge_atomic_disable()
2952 dw_hdmi_update_phy_mask(hdmi); in dw_hdmi_bridge_atomic_disable()
2953 handle_plugged_change(hdmi, false); in dw_hdmi_bridge_atomic_disable()
2954 mutex_unlock(&hdmi->mutex); in dw_hdmi_bridge_atomic_disable()
2960 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_atomic_enable() local
2961 struct drm_atomic_state *state = old_state->base.state; in dw_hdmi_bridge_atomic_enable()
2965 bridge->encoder); in dw_hdmi_bridge_atomic_enable()
2967 mutex_lock(&hdmi->mutex); in dw_hdmi_bridge_atomic_enable()
2968 hdmi->disabled = false; in dw_hdmi_bridge_atomic_enable()
2969 hdmi->curr_conn = connector; in dw_hdmi_bridge_atomic_enable()
2970 dw_hdmi_update_power(hdmi); in dw_hdmi_bridge_atomic_enable()
2971 dw_hdmi_update_phy_mask(hdmi); in dw_hdmi_bridge_atomic_enable()
2972 handle_plugged_change(hdmi, true); in dw_hdmi_bridge_atomic_enable()
2973 mutex_unlock(&hdmi->mutex); in dw_hdmi_bridge_atomic_enable()
2978 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_detect() local
2980 return dw_hdmi_detect(hdmi); in dw_hdmi_bridge_detect()
2986 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_get_edid() local
2988 return dw_hdmi_get_edid(hdmi, connector); in dw_hdmi_bridge_get_edid()
3008 /* -----------------------------------------------------------------------------
3012 static irqreturn_t dw_hdmi_i2c_irq(struct dw_hdmi *hdmi) in dw_hdmi_i2c_irq() argument
3014 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_irq()
3017 stat = hdmi_readb(hdmi, HDMI_IH_I2CM_STAT0); in dw_hdmi_i2c_irq()
3021 hdmi_writeb(hdmi, stat, HDMI_IH_I2CM_STAT0); in dw_hdmi_i2c_irq()
3023 i2c->stat = stat; in dw_hdmi_i2c_irq()
3025 complete(&i2c->cmp); in dw_hdmi_i2c_irq()
3032 struct dw_hdmi *hdmi = dev_id; in dw_hdmi_hardirq() local
3036 if (hdmi->i2c) in dw_hdmi_hardirq()
3037 ret = dw_hdmi_i2c_irq(hdmi); in dw_hdmi_hardirq()
3039 intr_stat = hdmi_readb(hdmi, HDMI_IH_PHY_STAT0); in dw_hdmi_hardirq()
3041 hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0); in dw_hdmi_hardirq()
3048 void dw_hdmi_setup_rx_sense(struct dw_hdmi *hdmi, bool hpd, bool rx_sense) in dw_hdmi_setup_rx_sense() argument
3050 mutex_lock(&hdmi->mutex); in dw_hdmi_setup_rx_sense()
3052 if (!hdmi->force) { in dw_hdmi_setup_rx_sense()
3058 hdmi->rxsense = false; in dw_hdmi_setup_rx_sense()
3067 hdmi->rxsense = true; in dw_hdmi_setup_rx_sense()
3069 dw_hdmi_update_power(hdmi); in dw_hdmi_setup_rx_sense()
3070 dw_hdmi_update_phy_mask(hdmi); in dw_hdmi_setup_rx_sense()
3072 mutex_unlock(&hdmi->mutex); in dw_hdmi_setup_rx_sense()
3078 struct dw_hdmi *hdmi = dev_id; in dw_hdmi_irq() local
3082 intr_stat = hdmi_readb(hdmi, HDMI_IH_PHY_STAT0); in dw_hdmi_irq()
3083 phy_int_pol = hdmi_readb(hdmi, HDMI_PHY_POL0); in dw_hdmi_irq()
3084 phy_stat = hdmi_readb(hdmi, HDMI_PHY_STAT0); in dw_hdmi_irq()
3099 hdmi_modb(hdmi, ~phy_int_pol, phy_pol_mask, HDMI_PHY_POL0); in dw_hdmi_irq()
3103 * load - in other words, there's something listening on the in dw_hdmi_irq()
3106 * ask the source to re-read the EDID. in dw_hdmi_irq()
3110 dw_hdmi_setup_rx_sense(hdmi, in dw_hdmi_irq()
3115 mutex_lock(&hdmi->cec_notifier_mutex); in dw_hdmi_irq()
3116 cec_notifier_phys_addr_invalidate(hdmi->cec_notifier); in dw_hdmi_irq()
3117 mutex_unlock(&hdmi->cec_notifier_mutex); in dw_hdmi_irq()
3128 dev_dbg(hdmi->dev, "EVENT=%s\n", in dw_hdmi_irq()
3132 if (hdmi->bridge.dev) { in dw_hdmi_irq()
3133 drm_helper_hpd_irq_event(hdmi->bridge.dev); in dw_hdmi_irq()
3134 drm_bridge_hpd_notify(&hdmi->bridge, status); in dw_hdmi_irq()
3138 hdmi_writeb(hdmi, intr_stat, HDMI_IH_PHY_STAT0); in dw_hdmi_irq()
3139 hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE), in dw_hdmi_irq()
3148 .name = "DWC HDMI TX PHY",
3164 .name = "DWC HDMI 3D TX PHY + HEAC PHY",
3169 .name = "DWC HDMI 3D TX PHY",
3174 .name = "DWC HDMI 2.0 TX PHY",
3184 static int dw_hdmi_detect_phy(struct dw_hdmi *hdmi) in dw_hdmi_detect_phy() argument
3189 phy_type = hdmi->plat_data->phy_force_vendor ? in dw_hdmi_detect_phy()
3191 hdmi_readb(hdmi, HDMI_CONFIG2_ID); in dw_hdmi_detect_phy()
3195 if (!hdmi->plat_data->phy_ops || !hdmi->plat_data->phy_name) { in dw_hdmi_detect_phy()
3196 dev_err(hdmi->dev, in dw_hdmi_detect_phy()
3197 "Vendor HDMI PHY not supported by glue layer\n"); in dw_hdmi_detect_phy()
3198 return -ENODEV; in dw_hdmi_detect_phy()
3201 hdmi->phy.ops = hdmi->plat_data->phy_ops; in dw_hdmi_detect_phy()
3202 hdmi->phy.data = hdmi->plat_data->phy_data; in dw_hdmi_detect_phy()
3203 hdmi->phy.name = hdmi->plat_data->phy_name; in dw_hdmi_detect_phy()
3210 hdmi->phy.ops = &dw_hdmi_synopsys_phy_ops; in dw_hdmi_detect_phy()
3211 hdmi->phy.name = dw_hdmi_phys[i].name; in dw_hdmi_detect_phy()
3212 hdmi->phy.data = (void *)&dw_hdmi_phys[i]; in dw_hdmi_detect_phy()
3215 !hdmi->plat_data->configure_phy) { in dw_hdmi_detect_phy()
3216 dev_err(hdmi->dev, "%s requires platform support\n", in dw_hdmi_detect_phy()
3217 hdmi->phy.name); in dw_hdmi_detect_phy()
3218 return -ENODEV; in dw_hdmi_detect_phy()
3225 dev_err(hdmi->dev, "Unsupported HDMI PHY type (%02x)\n", phy_type); in dw_hdmi_detect_phy()
3226 return -ENODEV; in dw_hdmi_detect_phy()
3229 static void dw_hdmi_cec_enable(struct dw_hdmi *hdmi) in dw_hdmi_cec_enable() argument
3231 mutex_lock(&hdmi->mutex); in dw_hdmi_cec_enable()
3232 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_CECCLK_DISABLE; in dw_hdmi_cec_enable()
3233 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_cec_enable()
3234 mutex_unlock(&hdmi->mutex); in dw_hdmi_cec_enable()
3237 static void dw_hdmi_cec_disable(struct dw_hdmi *hdmi) in dw_hdmi_cec_disable() argument
3239 mutex_lock(&hdmi->mutex); in dw_hdmi_cec_disable()
3240 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_CECCLK_DISABLE; in dw_hdmi_cec_disable()
3241 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_cec_disable()
3242 mutex_unlock(&hdmi->mutex); in dw_hdmi_cec_disable()
3266 static void dw_hdmi_init_hw(struct dw_hdmi *hdmi) in dw_hdmi_init_hw() argument
3268 initialize_hdmi_ih_mutes(hdmi); in dw_hdmi_init_hw()
3271 * Reset HDMI DDC I2C master controller and mute I2CM interrupts. in dw_hdmi_init_hw()
3275 dw_hdmi_i2c_init(hdmi); in dw_hdmi_init_hw()
3277 if (hdmi->phy.ops->setup_hpd) in dw_hdmi_init_hw()
3278 hdmi->phy.ops->setup_hpd(hdmi, hdmi->phy.data); in dw_hdmi_init_hw()
3281 /* -----------------------------------------------------------------------------
3285 static int dw_hdmi_parse_dt(struct dw_hdmi *hdmi) in dw_hdmi_parse_dt() argument
3290 if (!hdmi->plat_data->output_port) in dw_hdmi_parse_dt()
3293 endpoint = of_graph_get_endpoint_by_regs(hdmi->dev->of_node, in dw_hdmi_parse_dt()
3294 hdmi->plat_data->output_port, in dw_hdmi_parse_dt()
3295 -1); in dw_hdmi_parse_dt()
3299 * mandatory (such as Rockchip) the plat_data->output_port in dw_hdmi_parse_dt()
3302 dev_err(hdmi->dev, "Missing endpoint in port@%u\n", in dw_hdmi_parse_dt()
3303 hdmi->plat_data->output_port); in dw_hdmi_parse_dt()
3304 return -ENODEV; in dw_hdmi_parse_dt()
3310 dev_err(hdmi->dev, "Endpoint in port@%u unconnected\n", in dw_hdmi_parse_dt()
3311 hdmi->plat_data->output_port); in dw_hdmi_parse_dt()
3312 return -ENODEV; in dw_hdmi_parse_dt()
3316 dev_err(hdmi->dev, "port@%u remote device is disabled\n", in dw_hdmi_parse_dt()
3317 hdmi->plat_data->output_port); in dw_hdmi_parse_dt()
3319 return -ENODEV; in dw_hdmi_parse_dt()
3322 hdmi->next_bridge = of_drm_find_bridge(remote); in dw_hdmi_parse_dt()
3324 if (!hdmi->next_bridge) in dw_hdmi_parse_dt()
3325 return -EPROBE_DEFER; in dw_hdmi_parse_dt()
3330 bool dw_hdmi_bus_fmt_is_420(struct dw_hdmi *hdmi) in dw_hdmi_bus_fmt_is_420() argument
3332 return hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format); in dw_hdmi_bus_fmt_is_420()
3339 struct device *dev = &pdev->dev; in dw_hdmi_probe()
3340 struct device_node *np = dev->of_node; in dw_hdmi_probe()
3344 struct dw_hdmi *hdmi; in dw_hdmi_probe() local
3354 hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); in dw_hdmi_probe()
3355 if (!hdmi) in dw_hdmi_probe()
3356 return ERR_PTR(-ENOMEM); in dw_hdmi_probe()
3358 hdmi->plat_data = plat_data; in dw_hdmi_probe()
3359 hdmi->dev = dev; in dw_hdmi_probe()
3360 hdmi->sample_rate = 48000; in dw_hdmi_probe()
3361 hdmi->channels = 2; in dw_hdmi_probe()
3362 hdmi->disabled = true; in dw_hdmi_probe()
3363 hdmi->rxsense = true; in dw_hdmi_probe()
3364 hdmi->phy_mask = (u8)~(HDMI_PHY_HPD | HDMI_PHY_RX_SENSE); in dw_hdmi_probe()
3365 hdmi->mc_clkdis = 0x7f; in dw_hdmi_probe()
3366 hdmi->last_connector_result = connector_status_disconnected; in dw_hdmi_probe()
3368 mutex_init(&hdmi->mutex); in dw_hdmi_probe()
3369 mutex_init(&hdmi->audio_mutex); in dw_hdmi_probe()
3370 mutex_init(&hdmi->cec_notifier_mutex); in dw_hdmi_probe()
3371 spin_lock_init(&hdmi->audio_lock); in dw_hdmi_probe()
3373 ret = dw_hdmi_parse_dt(hdmi); in dw_hdmi_probe()
3377 ddc_node = of_parse_phandle(np, "ddc-i2c-bus", 0); in dw_hdmi_probe()
3379 hdmi->ddc = of_get_i2c_adapter_by_node(ddc_node); in dw_hdmi_probe()
3381 if (!hdmi->ddc) { in dw_hdmi_probe()
3382 dev_dbg(hdmi->dev, "failed to read ddc node\n"); in dw_hdmi_probe()
3383 return ERR_PTR(-EPROBE_DEFER); in dw_hdmi_probe()
3387 dev_dbg(hdmi->dev, "no ddc property found\n"); in dw_hdmi_probe()
3390 if (!plat_data->regm) { in dw_hdmi_probe()
3393 of_property_read_u32(np, "reg-io-width", &val); in dw_hdmi_probe()
3397 hdmi->reg_shift = 2; in dw_hdmi_probe()
3403 dev_err(dev, "reg-io-width must be 1 or 4\n"); in dw_hdmi_probe()
3404 return ERR_PTR(-EINVAL); in dw_hdmi_probe()
3408 hdmi->regs = devm_ioremap_resource(dev, iores); in dw_hdmi_probe()
3409 if (IS_ERR(hdmi->regs)) { in dw_hdmi_probe()
3410 ret = PTR_ERR(hdmi->regs); in dw_hdmi_probe()
3414 hdmi->regm = devm_regmap_init_mmio(dev, hdmi->regs, reg_config); in dw_hdmi_probe()
3415 if (IS_ERR(hdmi->regm)) { in dw_hdmi_probe()
3417 ret = PTR_ERR(hdmi->regm); in dw_hdmi_probe()
3421 hdmi->regm = plat_data->regm; in dw_hdmi_probe()
3424 hdmi->isfr_clk = devm_clk_get(hdmi->dev, "isfr"); in dw_hdmi_probe()
3425 if (IS_ERR(hdmi->isfr_clk)) { in dw_hdmi_probe()
3426 ret = PTR_ERR(hdmi->isfr_clk); in dw_hdmi_probe()
3427 dev_err(hdmi->dev, "Unable to get HDMI isfr clk: %d\n", ret); in dw_hdmi_probe()
3431 ret = clk_prepare_enable(hdmi->isfr_clk); in dw_hdmi_probe()
3433 dev_err(hdmi->dev, "Cannot enable HDMI isfr clock: %d\n", ret); in dw_hdmi_probe()
3437 hdmi->iahb_clk = devm_clk_get(hdmi->dev, "iahb"); in dw_hdmi_probe()
3438 if (IS_ERR(hdmi->iahb_clk)) { in dw_hdmi_probe()
3439 ret = PTR_ERR(hdmi->iahb_clk); in dw_hdmi_probe()
3440 dev_err(hdmi->dev, "Unable to get HDMI iahb clk: %d\n", ret); in dw_hdmi_probe()
3444 ret = clk_prepare_enable(hdmi->iahb_clk); in dw_hdmi_probe()
3446 dev_err(hdmi->dev, "Cannot enable HDMI iahb clock: %d\n", ret); in dw_hdmi_probe()
3450 hdmi->cec_clk = devm_clk_get(hdmi->dev, "cec"); in dw_hdmi_probe()
3451 if (PTR_ERR(hdmi->cec_clk) == -ENOENT) { in dw_hdmi_probe()
3452 hdmi->cec_clk = NULL; in dw_hdmi_probe()
3453 } else if (IS_ERR(hdmi->cec_clk)) { in dw_hdmi_probe()
3454 ret = PTR_ERR(hdmi->cec_clk); in dw_hdmi_probe()
3455 if (ret != -EPROBE_DEFER) in dw_hdmi_probe()
3456 dev_err(hdmi->dev, "Cannot get HDMI cec clock: %d\n", in dw_hdmi_probe()
3459 hdmi->cec_clk = NULL; in dw_hdmi_probe()
3462 ret = clk_prepare_enable(hdmi->cec_clk); in dw_hdmi_probe()
3464 dev_err(hdmi->dev, "Cannot enable HDMI cec clock: %d\n", in dw_hdmi_probe()
3471 hdmi->version = (hdmi_readb(hdmi, HDMI_DESIGN_ID) << 8) in dw_hdmi_probe()
3472 | (hdmi_readb(hdmi, HDMI_REVISION_ID) << 0); in dw_hdmi_probe()
3473 prod_id0 = hdmi_readb(hdmi, HDMI_PRODUCT_ID0); in dw_hdmi_probe()
3474 prod_id1 = hdmi_readb(hdmi, HDMI_PRODUCT_ID1); in dw_hdmi_probe()
3478 dev_err(dev, "Unsupported HDMI controller (%04x:%02x:%02x)\n", in dw_hdmi_probe()
3479 hdmi->version, prod_id0, prod_id1); in dw_hdmi_probe()
3480 ret = -ENODEV; in dw_hdmi_probe()
3484 ret = dw_hdmi_detect_phy(hdmi); in dw_hdmi_probe()
3488 dev_info(dev, "Detected HDMI TX controller v%x.%03x %s HDCP (%s)\n", in dw_hdmi_probe()
3489 hdmi->version >> 12, hdmi->version & 0xfff, in dw_hdmi_probe()
3491 hdmi->phy.name); in dw_hdmi_probe()
3493 dw_hdmi_init_hw(hdmi); in dw_hdmi_probe()
3503 dev_name(dev), hdmi); in dw_hdmi_probe()
3511 hdmi_init_clk_regenerator(hdmi); in dw_hdmi_probe()
3513 /* If DDC bus is not specified, try to register HDMI I2C bus */ in dw_hdmi_probe()
3514 if (!hdmi->ddc) { in dw_hdmi_probe()
3516 hdmi->pinctrl = devm_pinctrl_get(dev); in dw_hdmi_probe()
3517 if (!IS_ERR(hdmi->pinctrl)) { in dw_hdmi_probe()
3518 hdmi->unwedge_state = in dw_hdmi_probe()
3519 pinctrl_lookup_state(hdmi->pinctrl, "unwedge"); in dw_hdmi_probe()
3520 hdmi->default_state = in dw_hdmi_probe()
3521 pinctrl_lookup_state(hdmi->pinctrl, "default"); in dw_hdmi_probe()
3523 if (IS_ERR(hdmi->default_state) || in dw_hdmi_probe()
3524 IS_ERR(hdmi->unwedge_state)) { in dw_hdmi_probe()
3525 if (!IS_ERR(hdmi->unwedge_state)) in dw_hdmi_probe()
3528 hdmi->default_state = NULL; in dw_hdmi_probe()
3529 hdmi->unwedge_state = NULL; in dw_hdmi_probe()
3533 hdmi->ddc = dw_hdmi_i2c_adapter(hdmi); in dw_hdmi_probe()
3534 if (IS_ERR(hdmi->ddc)) in dw_hdmi_probe()
3535 hdmi->ddc = NULL; in dw_hdmi_probe()
3538 hdmi->bridge.driver_private = hdmi; in dw_hdmi_probe()
3539 hdmi->bridge.funcs = &dw_hdmi_bridge_funcs; in dw_hdmi_probe()
3540 hdmi->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID in dw_hdmi_probe()
3542 hdmi->bridge.interlace_allowed = true; in dw_hdmi_probe()
3543 hdmi->bridge.ddc = hdmi->ddc; in dw_hdmi_probe()
3545 hdmi->bridge.of_node = pdev->dev.of_node; in dw_hdmi_probe()
3552 config0 = hdmi_readb(hdmi, HDMI_CONFIG0_ID); in dw_hdmi_probe()
3553 config3 = hdmi_readb(hdmi, HDMI_CONFIG3_ID); in dw_hdmi_probe()
3558 audio.phys = iores->start; in dw_hdmi_probe()
3559 audio.base = hdmi->regs; in dw_hdmi_probe()
3561 audio.hdmi = hdmi; in dw_hdmi_probe()
3563 hdmi->enable_audio = dw_hdmi_ahb_audio_enable; in dw_hdmi_probe()
3564 hdmi->disable_audio = dw_hdmi_ahb_audio_disable; in dw_hdmi_probe()
3566 pdevinfo.name = "dw-hdmi-ahb-audio"; in dw_hdmi_probe()
3570 hdmi->audio = platform_device_register_full(&pdevinfo); in dw_hdmi_probe()
3574 audio.hdmi = hdmi; in dw_hdmi_probe()
3578 hdmi->enable_audio = dw_hdmi_i2s_audio_enable; in dw_hdmi_probe()
3579 hdmi->disable_audio = dw_hdmi_i2s_audio_disable; in dw_hdmi_probe()
3581 pdevinfo.name = "dw-hdmi-i2s-audio"; in dw_hdmi_probe()
3585 hdmi->audio = platform_device_register_full(&pdevinfo); in dw_hdmi_probe()
3589 audio.phys = iores->start; in dw_hdmi_probe()
3590 audio.base = hdmi->regs; in dw_hdmi_probe()
3592 audio.hdmi = hdmi; in dw_hdmi_probe()
3595 hdmi->enable_audio = dw_hdmi_gp_audio_enable; in dw_hdmi_probe()
3596 hdmi->disable_audio = dw_hdmi_gp_audio_disable; in dw_hdmi_probe()
3598 pdevinfo.name = "dw-hdmi-gp-audio"; in dw_hdmi_probe()
3603 hdmi->audio = platform_device_register_full(&pdevinfo); in dw_hdmi_probe()
3606 if (!plat_data->disable_cec && (config0 & HDMI_CONFIG0_CEC)) { in dw_hdmi_probe()
3607 cec.hdmi = hdmi; in dw_hdmi_probe()
3611 pdevinfo.name = "dw-hdmi-cec"; in dw_hdmi_probe()
3616 hdmi->cec = platform_device_register_full(&pdevinfo); in dw_hdmi_probe()
3619 drm_bridge_add(&hdmi->bridge); in dw_hdmi_probe()
3621 return hdmi; in dw_hdmi_probe()
3624 clk_disable_unprepare(hdmi->iahb_clk); in dw_hdmi_probe()
3625 clk_disable_unprepare(hdmi->cec_clk); in dw_hdmi_probe()
3627 clk_disable_unprepare(hdmi->isfr_clk); in dw_hdmi_probe()
3629 i2c_put_adapter(hdmi->ddc); in dw_hdmi_probe()
3635 void dw_hdmi_remove(struct dw_hdmi *hdmi) in dw_hdmi_remove() argument
3637 drm_bridge_remove(&hdmi->bridge); in dw_hdmi_remove()
3639 if (hdmi->audio && !IS_ERR(hdmi->audio)) in dw_hdmi_remove()
3640 platform_device_unregister(hdmi->audio); in dw_hdmi_remove()
3641 if (!IS_ERR(hdmi->cec)) in dw_hdmi_remove()
3642 platform_device_unregister(hdmi->cec); in dw_hdmi_remove()
3645 hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0); in dw_hdmi_remove()
3647 clk_disable_unprepare(hdmi->iahb_clk); in dw_hdmi_remove()
3648 clk_disable_unprepare(hdmi->isfr_clk); in dw_hdmi_remove()
3649 clk_disable_unprepare(hdmi->cec_clk); in dw_hdmi_remove()
3651 if (hdmi->i2c) in dw_hdmi_remove()
3652 i2c_del_adapter(&hdmi->i2c->adap); in dw_hdmi_remove()
3654 i2c_put_adapter(hdmi->ddc); in dw_hdmi_remove()
3658 /* -----------------------------------------------------------------------------
3665 struct dw_hdmi *hdmi; in dw_hdmi_bind() local
3668 hdmi = dw_hdmi_probe(pdev, plat_data); in dw_hdmi_bind()
3669 if (IS_ERR(hdmi)) in dw_hdmi_bind()
3670 return hdmi; in dw_hdmi_bind()
3672 ret = drm_bridge_attach(encoder, &hdmi->bridge, NULL, 0); in dw_hdmi_bind()
3674 dw_hdmi_remove(hdmi); in dw_hdmi_bind()
3678 return hdmi; in dw_hdmi_bind()
3682 void dw_hdmi_unbind(struct dw_hdmi *hdmi) in dw_hdmi_unbind() argument
3684 dw_hdmi_remove(hdmi); in dw_hdmi_unbind()
3688 void dw_hdmi_resume(struct dw_hdmi *hdmi) in dw_hdmi_resume() argument
3690 dw_hdmi_init_hw(hdmi); in dw_hdmi_resume()
3695 MODULE_AUTHOR("Andy Yan <andy.yan@rock-chips.com>");
3696 MODULE_AUTHOR("Yakir Yang <ykk@rock-chips.com>");
3698 MODULE_DESCRIPTION("DW HDMI transmitter driver");
3700 MODULE_ALIAS("platform:dw-hdmi");