Lines Matching +full:hdmi +full:- +full:connector
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>
19 #include <linux/dma-mapping.h>
22 #include <media/cec-notifier.h>
24 #include <uapi/linux/media-bus-format.h>
37 #include "dw-hdmi-audio.h"
38 #include "dw-hdmi-cec.h"
39 #include "dw-hdmi.h"
46 /* DW-HDMI Controller >= 0x200a are at least compliant with SCDC version 1 */
138 int (*configure)(struct dw_hdmi *hdmi,
144 struct drm_connector connector; member
184 enum drm_connector_force force; /* mutex-protected force state */
185 struct drm_connector *curr_conn;/* current connector (only valid when !disabled) */
201 void (*enable_audio)(struct dw_hdmi *hdmi);
202 void (*disable_audio)(struct dw_hdmi *hdmi);
220 static inline void hdmi_writeb(struct dw_hdmi *hdmi, u8 val, int offset) in hdmi_writeb() argument
222 regmap_write(hdmi->regm, offset << hdmi->reg_shift, val); in hdmi_writeb()
225 static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset) in hdmi_readb() argument
229 regmap_read(hdmi->regm, offset << hdmi->reg_shift, &val); in hdmi_readb()
234 static void handle_plugged_change(struct dw_hdmi *hdmi, bool plugged) in handle_plugged_change() argument
236 if (hdmi->plugged_cb && hdmi->codec_dev) in handle_plugged_change()
237 hdmi->plugged_cb(hdmi->codec_dev, plugged); in handle_plugged_change()
240 int dw_hdmi_set_plugged_cb(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn, in dw_hdmi_set_plugged_cb() argument
245 mutex_lock(&hdmi->mutex); in dw_hdmi_set_plugged_cb()
246 hdmi->plugged_cb = fn; in dw_hdmi_set_plugged_cb()
247 hdmi->codec_dev = codec_dev; in dw_hdmi_set_plugged_cb()
248 plugged = hdmi->last_connector_result == connector_status_connected; in dw_hdmi_set_plugged_cb()
249 handle_plugged_change(hdmi, plugged); in dw_hdmi_set_plugged_cb()
250 mutex_unlock(&hdmi->mutex); in dw_hdmi_set_plugged_cb()
256 static void hdmi_modb(struct dw_hdmi *hdmi, u8 data, u8 mask, unsigned reg) in hdmi_modb() argument
258 regmap_update_bits(hdmi->regm, reg << hdmi->reg_shift, mask, data); in hdmi_modb()
261 static void hdmi_mask_writeb(struct dw_hdmi *hdmi, u8 data, unsigned int reg, in hdmi_mask_writeb() argument
264 hdmi_modb(hdmi, data << shift, mask, reg); in hdmi_mask_writeb()
267 static void dw_hdmi_i2c_init(struct dw_hdmi *hdmi) in dw_hdmi_i2c_init() argument
269 hdmi_writeb(hdmi, HDMI_PHY_I2CM_INT_ADDR_DONE_POL, in dw_hdmi_i2c_init()
272 hdmi_writeb(hdmi, HDMI_PHY_I2CM_CTLINT_ADDR_NAC_POL | in dw_hdmi_i2c_init()
277 hdmi_writeb(hdmi, 0x00, HDMI_I2CM_SOFTRSTZ); in dw_hdmi_i2c_init()
280 hdmi_writeb(hdmi, 0x00, HDMI_I2CM_DIV); in dw_hdmi_i2c_init()
283 hdmi_writeb(hdmi, HDMI_I2CM_INT_DONE_POL, HDMI_I2CM_INT); in dw_hdmi_i2c_init()
284 hdmi_writeb(hdmi, HDMI_I2CM_CTLINT_NAC_POL | HDMI_I2CM_CTLINT_ARB_POL, in dw_hdmi_i2c_init()
288 hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE, in dw_hdmi_i2c_init()
292 hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE, in dw_hdmi_i2c_init()
296 static bool dw_hdmi_i2c_unwedge(struct dw_hdmi *hdmi) in dw_hdmi_i2c_unwedge() argument
299 if (!hdmi->unwedge_state) in dw_hdmi_i2c_unwedge()
302 dev_info(hdmi->dev, "Attempting to unwedge stuck i2c bus\n"); in dw_hdmi_i2c_unwedge()
322 * its HDMI ports. It happened when the TV was powered on while the in dw_hdmi_i2c_unwedge()
336 pinctrl_select_state(hdmi->pinctrl, hdmi->unwedge_state); in dw_hdmi_i2c_unwedge()
338 pinctrl_select_state(hdmi->pinctrl, hdmi->default_state); in dw_hdmi_i2c_unwedge()
343 static int dw_hdmi_i2c_wait(struct dw_hdmi *hdmi) in dw_hdmi_i2c_wait() argument
345 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_wait()
348 stat = wait_for_completion_timeout(&i2c->cmp, HZ / 10); in dw_hdmi_i2c_wait()
351 if (!dw_hdmi_i2c_unwedge(hdmi)) in dw_hdmi_i2c_wait()
352 return -EAGAIN; in dw_hdmi_i2c_wait()
355 stat = wait_for_completion_timeout(&i2c->cmp, HZ / 10); in dw_hdmi_i2c_wait()
357 return -EAGAIN; in dw_hdmi_i2c_wait()
361 if (i2c->stat & HDMI_IH_I2CM_STAT0_ERROR) in dw_hdmi_i2c_wait()
362 return -EIO; in dw_hdmi_i2c_wait()
367 static int dw_hdmi_i2c_read(struct dw_hdmi *hdmi, in dw_hdmi_i2c_read() argument
370 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_read()
373 if (!i2c->is_regaddr) { in dw_hdmi_i2c_read()
374 dev_dbg(hdmi->dev, "set read register address to 0\n"); in dw_hdmi_i2c_read()
375 i2c->slave_reg = 0x00; in dw_hdmi_i2c_read()
376 i2c->is_regaddr = true; in dw_hdmi_i2c_read()
379 while (length--) { in dw_hdmi_i2c_read()
380 reinit_completion(&i2c->cmp); in dw_hdmi_i2c_read()
382 hdmi_writeb(hdmi, i2c->slave_reg++, HDMI_I2CM_ADDRESS); in dw_hdmi_i2c_read()
383 if (i2c->is_segment) in dw_hdmi_i2c_read()
384 hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_READ_EXT, in dw_hdmi_i2c_read()
387 hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_READ, in dw_hdmi_i2c_read()
390 ret = dw_hdmi_i2c_wait(hdmi); in dw_hdmi_i2c_read()
394 *buf++ = hdmi_readb(hdmi, HDMI_I2CM_DATAI); in dw_hdmi_i2c_read()
396 i2c->is_segment = false; in dw_hdmi_i2c_read()
401 static int dw_hdmi_i2c_write(struct dw_hdmi *hdmi, in dw_hdmi_i2c_write() argument
404 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_write()
407 if (!i2c->is_regaddr) { in dw_hdmi_i2c_write()
409 i2c->slave_reg = buf[0]; in dw_hdmi_i2c_write()
410 length--; in dw_hdmi_i2c_write()
412 i2c->is_regaddr = true; in dw_hdmi_i2c_write()
415 while (length--) { in dw_hdmi_i2c_write()
416 reinit_completion(&i2c->cmp); in dw_hdmi_i2c_write()
418 hdmi_writeb(hdmi, *buf++, HDMI_I2CM_DATAO); in dw_hdmi_i2c_write()
419 hdmi_writeb(hdmi, i2c->slave_reg++, HDMI_I2CM_ADDRESS); in dw_hdmi_i2c_write()
420 hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_WRITE, in dw_hdmi_i2c_write()
423 ret = dw_hdmi_i2c_wait(hdmi); in dw_hdmi_i2c_write()
434 struct dw_hdmi *hdmi = i2c_get_adapdata(adap); in dw_hdmi_i2c_xfer() local
435 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_xfer()
441 * The internal I2C controller does not support the multi-byte in dw_hdmi_i2c_xfer()
446 return -EOPNOTSUPP; in dw_hdmi_i2c_xfer()
448 dev_dbg(hdmi->dev, "xfer: num: %d, addr: %#x\n", num, addr); in dw_hdmi_i2c_xfer()
452 dev_dbg(hdmi->dev, in dw_hdmi_i2c_xfer()
455 return -EOPNOTSUPP; in dw_hdmi_i2c_xfer()
459 mutex_lock(&i2c->lock); in dw_hdmi_i2c_xfer()
462 hdmi_writeb(hdmi, 0x00, HDMI_IH_MUTE_I2CM_STAT0); in dw_hdmi_i2c_xfer()
465 hdmi_writeb(hdmi, addr, HDMI_I2CM_SLAVE); in dw_hdmi_i2c_xfer()
468 i2c->is_regaddr = false; in dw_hdmi_i2c_xfer()
471 i2c->is_segment = false; in dw_hdmi_i2c_xfer()
474 dev_dbg(hdmi->dev, "xfer: num: %d/%d, len: %d, flags: %#x\n", in dw_hdmi_i2c_xfer()
477 i2c->is_segment = true; in dw_hdmi_i2c_xfer()
478 hdmi_writeb(hdmi, DDC_SEGMENT_ADDR, HDMI_I2CM_SEGADDR); in dw_hdmi_i2c_xfer()
479 hdmi_writeb(hdmi, *msgs[i].buf, HDMI_I2CM_SEGPTR); in dw_hdmi_i2c_xfer()
482 ret = dw_hdmi_i2c_read(hdmi, msgs[i].buf, in dw_hdmi_i2c_xfer()
485 ret = dw_hdmi_i2c_write(hdmi, msgs[i].buf, in dw_hdmi_i2c_xfer()
496 hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE, in dw_hdmi_i2c_xfer()
499 mutex_unlock(&i2c->lock); in dw_hdmi_i2c_xfer()
514 static struct i2c_adapter *dw_hdmi_i2c_adapter(struct dw_hdmi *hdmi) in dw_hdmi_i2c_adapter() argument
520 i2c = devm_kzalloc(hdmi->dev, sizeof(*i2c), GFP_KERNEL); in dw_hdmi_i2c_adapter()
522 return ERR_PTR(-ENOMEM); in dw_hdmi_i2c_adapter()
524 mutex_init(&i2c->lock); in dw_hdmi_i2c_adapter()
525 init_completion(&i2c->cmp); in dw_hdmi_i2c_adapter()
527 adap = &i2c->adap; in dw_hdmi_i2c_adapter()
528 adap->class = I2C_CLASS_DDC; in dw_hdmi_i2c_adapter()
529 adap->owner = THIS_MODULE; in dw_hdmi_i2c_adapter()
530 adap->dev.parent = hdmi->dev; in dw_hdmi_i2c_adapter()
531 adap->algo = &dw_hdmi_algorithm; in dw_hdmi_i2c_adapter()
532 strlcpy(adap->name, "DesignWare HDMI", sizeof(adap->name)); in dw_hdmi_i2c_adapter()
533 i2c_set_adapdata(adap, hdmi); in dw_hdmi_i2c_adapter()
537 dev_warn(hdmi->dev, "cannot add %s I2C adapter\n", adap->name); in dw_hdmi_i2c_adapter()
538 devm_kfree(hdmi->dev, i2c); in dw_hdmi_i2c_adapter()
542 hdmi->i2c = i2c; in dw_hdmi_i2c_adapter()
544 dev_info(hdmi->dev, "registered %s I2C bus driver\n", adap->name); in dw_hdmi_i2c_adapter()
549 static void hdmi_set_cts_n(struct dw_hdmi *hdmi, unsigned int cts, in hdmi_set_cts_n() argument
553 hdmi_modb(hdmi, 0, HDMI_AUD_CTS3_CTS_MANUAL, HDMI_AUD_CTS3); in hdmi_set_cts_n()
556 hdmi_modb(hdmi, 0, HDMI_AUD_CTS3_N_SHIFT_MASK, HDMI_AUD_CTS3); in hdmi_set_cts_n()
560 hdmi_writeb(hdmi, ((cts >> 16) & in hdmi_set_cts_n()
565 hdmi_writeb(hdmi, 0, HDMI_AUD_CTS3); in hdmi_set_cts_n()
566 hdmi_writeb(hdmi, (cts >> 8) & 0xff, HDMI_AUD_CTS2); in hdmi_set_cts_n()
567 hdmi_writeb(hdmi, cts & 0xff, HDMI_AUD_CTS1); in hdmi_set_cts_n()
569 hdmi_writeb(hdmi, (n >> 16) & 0x0f, HDMI_AUD_N3); in hdmi_set_cts_n()
570 hdmi_writeb(hdmi, (n >> 8) & 0xff, HDMI_AUD_N2); in hdmi_set_cts_n()
571 hdmi_writeb(hdmi, n & 0xff, HDMI_AUD_N1); in hdmi_set_cts_n()
638 void dw_hdmi_set_channel_status(struct dw_hdmi *hdmi, in dw_hdmi_set_channel_status() argument
645 hdmi_writeb(hdmi, channel_status[3], HDMI_FC_AUDSCHNLS7); in dw_hdmi_set_channel_status()
646 hdmi_writeb(hdmi, channel_status[4], HDMI_FC_AUDSCHNLS8); in dw_hdmi_set_channel_status()
650 static void hdmi_set_clk_regenerator(struct dw_hdmi *hdmi, in hdmi_set_clk_regenerator() argument
660 config3 = hdmi_readb(hdmi, HDMI_CONFIG3_ID); in hdmi_set_clk_regenerator()
666 * can be up to 20 bits in total, so we need 64-bit math. Also in hdmi_set_clk_regenerator()
675 dev_dbg(hdmi->dev, "%s: fs=%uHz ftdms=%lu.%03luMHz N=%d cts=%d\n", in hdmi_set_clk_regenerator()
683 spin_lock_irq(&hdmi->audio_lock); in hdmi_set_clk_regenerator()
684 hdmi->audio_n = n; in hdmi_set_clk_regenerator()
685 hdmi->audio_cts = cts; in hdmi_set_clk_regenerator()
686 hdmi_set_cts_n(hdmi, cts, hdmi->audio_enable ? n : 0); in hdmi_set_clk_regenerator()
687 spin_unlock_irq(&hdmi->audio_lock); in hdmi_set_clk_regenerator()
690 static void hdmi_init_clk_regenerator(struct dw_hdmi *hdmi) in hdmi_init_clk_regenerator() argument
692 mutex_lock(&hdmi->audio_mutex); in hdmi_init_clk_regenerator()
693 hdmi_set_clk_regenerator(hdmi, 74250000, hdmi->sample_rate); in hdmi_init_clk_regenerator()
694 mutex_unlock(&hdmi->audio_mutex); in hdmi_init_clk_regenerator()
697 static void hdmi_clk_regenerator_update_pixel_clock(struct dw_hdmi *hdmi) in hdmi_clk_regenerator_update_pixel_clock() argument
699 mutex_lock(&hdmi->audio_mutex); in hdmi_clk_regenerator_update_pixel_clock()
700 hdmi_set_clk_regenerator(hdmi, hdmi->hdmi_data.video_mode.mtmdsclock, in hdmi_clk_regenerator_update_pixel_clock()
701 hdmi->sample_rate); in hdmi_clk_regenerator_update_pixel_clock()
702 mutex_unlock(&hdmi->audio_mutex); in hdmi_clk_regenerator_update_pixel_clock()
705 void dw_hdmi_set_sample_rate(struct dw_hdmi *hdmi, unsigned int rate) in dw_hdmi_set_sample_rate() argument
707 mutex_lock(&hdmi->audio_mutex); in dw_hdmi_set_sample_rate()
708 hdmi->sample_rate = rate; in dw_hdmi_set_sample_rate()
709 hdmi_set_clk_regenerator(hdmi, hdmi->hdmi_data.video_mode.mtmdsclock, in dw_hdmi_set_sample_rate()
710 hdmi->sample_rate); in dw_hdmi_set_sample_rate()
711 mutex_unlock(&hdmi->audio_mutex); in dw_hdmi_set_sample_rate()
715 void dw_hdmi_set_channel_count(struct dw_hdmi *hdmi, unsigned int cnt) in dw_hdmi_set_channel_count() argument
719 mutex_lock(&hdmi->audio_mutex); in dw_hdmi_set_channel_count()
730 hdmi_modb(hdmi, layout, HDMI_FC_AUDSCONF_AUD_PACKET_LAYOUT_MASK, in dw_hdmi_set_channel_count()
734 hdmi_modb(hdmi, (cnt - 1) << HDMI_FC_AUDICONF0_CC_OFFSET, in dw_hdmi_set_channel_count()
737 mutex_unlock(&hdmi->audio_mutex); in dw_hdmi_set_channel_count()
741 void dw_hdmi_set_channel_allocation(struct dw_hdmi *hdmi, unsigned int ca) in dw_hdmi_set_channel_allocation() argument
743 mutex_lock(&hdmi->audio_mutex); in dw_hdmi_set_channel_allocation()
745 hdmi_writeb(hdmi, ca, HDMI_FC_AUDICONF2); in dw_hdmi_set_channel_allocation()
747 mutex_unlock(&hdmi->audio_mutex); in dw_hdmi_set_channel_allocation()
751 static void hdmi_enable_audio_clk(struct dw_hdmi *hdmi, bool enable) in hdmi_enable_audio_clk() argument
754 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_AUDCLK_DISABLE; in hdmi_enable_audio_clk()
756 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_AUDCLK_DISABLE; in hdmi_enable_audio_clk()
757 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in hdmi_enable_audio_clk()
760 static void dw_hdmi_ahb_audio_enable(struct dw_hdmi *hdmi) in dw_hdmi_ahb_audio_enable() argument
762 hdmi_set_cts_n(hdmi, hdmi->audio_cts, hdmi->audio_n); in dw_hdmi_ahb_audio_enable()
765 static void dw_hdmi_ahb_audio_disable(struct dw_hdmi *hdmi) in dw_hdmi_ahb_audio_disable() argument
767 hdmi_set_cts_n(hdmi, hdmi->audio_cts, 0); in dw_hdmi_ahb_audio_disable()
770 static void dw_hdmi_i2s_audio_enable(struct dw_hdmi *hdmi) in dw_hdmi_i2s_audio_enable() argument
772 hdmi_set_cts_n(hdmi, hdmi->audio_cts, hdmi->audio_n); in dw_hdmi_i2s_audio_enable()
773 hdmi_enable_audio_clk(hdmi, true); in dw_hdmi_i2s_audio_enable()
776 static void dw_hdmi_i2s_audio_disable(struct dw_hdmi *hdmi) in dw_hdmi_i2s_audio_disable() argument
778 hdmi_enable_audio_clk(hdmi, false); in dw_hdmi_i2s_audio_disable()
781 void dw_hdmi_audio_enable(struct dw_hdmi *hdmi) in dw_hdmi_audio_enable() argument
785 spin_lock_irqsave(&hdmi->audio_lock, flags); in dw_hdmi_audio_enable()
786 hdmi->audio_enable = true; in dw_hdmi_audio_enable()
787 if (hdmi->enable_audio) in dw_hdmi_audio_enable()
788 hdmi->enable_audio(hdmi); in dw_hdmi_audio_enable()
789 spin_unlock_irqrestore(&hdmi->audio_lock, flags); in dw_hdmi_audio_enable()
793 void dw_hdmi_audio_disable(struct dw_hdmi *hdmi) in dw_hdmi_audio_disable() argument
797 spin_lock_irqsave(&hdmi->audio_lock, flags); in dw_hdmi_audio_disable()
798 hdmi->audio_enable = false; in dw_hdmi_audio_disable()
799 if (hdmi->disable_audio) in dw_hdmi_audio_disable()
800 hdmi->disable_audio(hdmi); in dw_hdmi_audio_disable()
801 spin_unlock_irqrestore(&hdmi->audio_lock, flags); in dw_hdmi_audio_disable()
898 static void hdmi_video_sample(struct dw_hdmi *hdmi) in hdmi_video_sample() argument
903 switch (hdmi->hdmi_data.enc_in_bus_format) { in hdmi_video_sample()
951 hdmi_writeb(hdmi, val, HDMI_TX_INVID0); in hdmi_video_sample()
957 hdmi_writeb(hdmi, val, HDMI_TX_INSTUFFING); in hdmi_video_sample()
958 hdmi_writeb(hdmi, 0x0, HDMI_TX_GYDATA0); in hdmi_video_sample()
959 hdmi_writeb(hdmi, 0x0, HDMI_TX_GYDATA1); in hdmi_video_sample()
960 hdmi_writeb(hdmi, 0x0, HDMI_TX_RCRDATA0); in hdmi_video_sample()
961 hdmi_writeb(hdmi, 0x0, HDMI_TX_RCRDATA1); in hdmi_video_sample()
962 hdmi_writeb(hdmi, 0x0, HDMI_TX_BCBDATA0); in hdmi_video_sample()
963 hdmi_writeb(hdmi, 0x0, HDMI_TX_BCBDATA1); in hdmi_video_sample()
966 static int is_color_space_conversion(struct dw_hdmi *hdmi) in is_color_space_conversion() argument
968 struct hdmi_data_info *hdmi_data = &hdmi->hdmi_data; in is_color_space_conversion()
971 is_input_rgb = hdmi_bus_fmt_is_rgb(hdmi_data->enc_in_bus_format); in is_color_space_conversion()
972 is_output_rgb = hdmi_bus_fmt_is_rgb(hdmi_data->enc_out_bus_format); in is_color_space_conversion()
975 (is_input_rgb && is_output_rgb && hdmi_data->rgb_limited_range); in is_color_space_conversion()
978 static int is_color_space_decimation(struct dw_hdmi *hdmi) in is_color_space_decimation() argument
980 if (!hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) in is_color_space_decimation()
983 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_in_bus_format) || in is_color_space_decimation()
984 hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_in_bus_format)) in is_color_space_decimation()
990 static int is_color_space_interpolation(struct dw_hdmi *hdmi) in is_color_space_interpolation() argument
992 if (!hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_in_bus_format)) in is_color_space_interpolation()
995 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format) || in is_color_space_interpolation()
996 hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format)) in is_color_space_interpolation()
1002 static bool is_csc_needed(struct dw_hdmi *hdmi) in is_csc_needed() argument
1004 return is_color_space_conversion(hdmi) || in is_csc_needed()
1005 is_color_space_decimation(hdmi) || in is_csc_needed()
1006 is_color_space_interpolation(hdmi); in is_csc_needed()
1009 static void dw_hdmi_update_csc_coeffs(struct dw_hdmi *hdmi) in dw_hdmi_update_csc_coeffs() argument
1016 is_input_rgb = hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_in_bus_format); in dw_hdmi_update_csc_coeffs()
1017 is_output_rgb = hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format); in dw_hdmi_update_csc_coeffs()
1020 if (hdmi->hdmi_data.enc_out_encoding == V4L2_YCBCR_ENC_601) in dw_hdmi_update_csc_coeffs()
1025 if (hdmi->hdmi_data.enc_out_encoding == V4L2_YCBCR_ENC_601) in dw_hdmi_update_csc_coeffs()
1031 hdmi->hdmi_data.rgb_limited_range) { in dw_hdmi_update_csc_coeffs()
1041 hdmi_writeb(hdmi, coeff_a & 0xff, HDMI_CSC_COEF_A1_LSB + i * 2); in dw_hdmi_update_csc_coeffs()
1042 hdmi_writeb(hdmi, coeff_a >> 8, HDMI_CSC_COEF_A1_MSB + i * 2); in dw_hdmi_update_csc_coeffs()
1043 hdmi_writeb(hdmi, coeff_b & 0xff, HDMI_CSC_COEF_B1_LSB + i * 2); in dw_hdmi_update_csc_coeffs()
1044 hdmi_writeb(hdmi, coeff_b >> 8, HDMI_CSC_COEF_B1_MSB + i * 2); in dw_hdmi_update_csc_coeffs()
1045 hdmi_writeb(hdmi, coeff_c & 0xff, HDMI_CSC_COEF_C1_LSB + i * 2); in dw_hdmi_update_csc_coeffs()
1046 hdmi_writeb(hdmi, coeff_c >> 8, HDMI_CSC_COEF_C1_MSB + i * 2); in dw_hdmi_update_csc_coeffs()
1049 hdmi_modb(hdmi, csc_scale, HDMI_CSC_SCALE_CSCSCALE_MASK, in dw_hdmi_update_csc_coeffs()
1053 static void hdmi_video_csc(struct dw_hdmi *hdmi) in hdmi_video_csc() argument
1060 if (is_color_space_interpolation(hdmi)) in hdmi_video_csc()
1062 else if (is_color_space_decimation(hdmi)) in hdmi_video_csc()
1065 switch (hdmi_bus_fmt_color_depth(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_csc()
1084 hdmi_writeb(hdmi, interpolation | decimation, HDMI_CSC_CFG); in hdmi_video_csc()
1085 hdmi_modb(hdmi, color_depth, HDMI_CSC_SCALE_CSC_COLORDE_PTH_MASK, in hdmi_video_csc()
1088 dw_hdmi_update_csc_coeffs(hdmi); in hdmi_video_csc()
1092 * HDMI video packetizer is used to packetize the data.
1096 static void hdmi_video_packetize(struct dw_hdmi *hdmi) in hdmi_video_packetize() argument
1101 struct hdmi_data_info *hdmi_data = &hdmi->hdmi_data; in hdmi_video_packetize()
1104 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format) || in hdmi_video_packetize()
1105 hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format) || in hdmi_video_packetize()
1106 hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1108 hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1125 } else if (hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1127 hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1150 ((hdmi_data->pix_repet_factor << in hdmi_video_packetize()
1153 hdmi_writeb(hdmi, val, HDMI_VP_PR_CD); in hdmi_video_packetize()
1155 hdmi_modb(hdmi, HDMI_VP_STUFF_PR_STUFFING_STUFFING_MODE, in hdmi_video_packetize()
1159 if (hdmi_data->pix_repet_factor > 1) { in hdmi_video_packetize()
1167 hdmi_modb(hdmi, vp_conf, in hdmi_video_packetize()
1171 hdmi_modb(hdmi, 1 << HDMI_VP_STUFF_IDEFAULT_PHASE_OFFSET, in hdmi_video_packetize()
1174 hdmi_writeb(hdmi, remap_size, HDMI_VP_REMAP); in hdmi_video_packetize()
1192 hdmi_modb(hdmi, vp_conf, in hdmi_video_packetize()
1196 hdmi_modb(hdmi, HDMI_VP_STUFF_PP_STUFFING_STUFFING_MODE | in hdmi_video_packetize()
1201 hdmi_modb(hdmi, output_select, HDMI_VP_CONF_OUTPUT_SELECTOR_MASK, in hdmi_video_packetize()
1205 /* -----------------------------------------------------------------------------
1209 static inline void hdmi_phy_test_clear(struct dw_hdmi *hdmi, in hdmi_phy_test_clear() argument
1212 hdmi_modb(hdmi, bit << HDMI_PHY_TST0_TSTCLR_OFFSET, in hdmi_phy_test_clear()
1216 static bool hdmi_phy_wait_i2c_done(struct dw_hdmi *hdmi, int msec) in hdmi_phy_wait_i2c_done() argument
1220 while ((val = hdmi_readb(hdmi, HDMI_IH_I2CMPHY_STAT0) & 0x3) == 0) { in hdmi_phy_wait_i2c_done()
1221 if (msec-- == 0) in hdmi_phy_wait_i2c_done()
1225 hdmi_writeb(hdmi, val, HDMI_IH_I2CMPHY_STAT0); in hdmi_phy_wait_i2c_done()
1230 void dw_hdmi_phy_i2c_write(struct dw_hdmi *hdmi, unsigned short data, in dw_hdmi_phy_i2c_write() argument
1233 hdmi_writeb(hdmi, 0xFF, HDMI_IH_I2CMPHY_STAT0); in dw_hdmi_phy_i2c_write()
1234 hdmi_writeb(hdmi, addr, HDMI_PHY_I2CM_ADDRESS_ADDR); in dw_hdmi_phy_i2c_write()
1235 hdmi_writeb(hdmi, (unsigned char)(data >> 8), in dw_hdmi_phy_i2c_write()
1237 hdmi_writeb(hdmi, (unsigned char)(data >> 0), in dw_hdmi_phy_i2c_write()
1239 hdmi_writeb(hdmi, HDMI_PHY_I2CM_OPERATION_ADDR_WRITE, in dw_hdmi_phy_i2c_write()
1241 hdmi_phy_wait_i2c_done(hdmi, 1000); in dw_hdmi_phy_i2c_write()
1246 static bool dw_hdmi_support_scdc(struct dw_hdmi *hdmi, in dw_hdmi_support_scdc() argument
1250 if (hdmi->version < 0x200a) in dw_hdmi_support_scdc()
1254 if (!hdmi->ddc) in dw_hdmi_support_scdc()
1257 /* Disable if SCDC is not supported, or if an HF-VSDB block is absent */ in dw_hdmi_support_scdc()
1258 if (!display->hdmi.scdc.supported || in dw_hdmi_support_scdc()
1259 !display->hdmi.scdc.scrambling.supported) in dw_hdmi_support_scdc()
1266 if (!display->hdmi.scdc.scrambling.low_rates && in dw_hdmi_support_scdc()
1267 display->max_tmds_clock <= 340000) in dw_hdmi_support_scdc()
1275 * - The Source shall suspend transmission of the TMDS clock and data
1276 * - The Source shall write to the TMDS_Bit_Clock_Ratio bit to change it
1278 * - The Source shall allow a minimum of 1 ms and a maximum of 100 ms from
1286 void dw_hdmi_set_high_tmds_clock_ratio(struct dw_hdmi *hdmi, in dw_hdmi_set_high_tmds_clock_ratio() argument
1289 unsigned long mtmdsclock = hdmi->hdmi_data.video_mode.mtmdsclock; in dw_hdmi_set_high_tmds_clock_ratio()
1291 /* Control for TMDS Bit Period/TMDS Clock-Period Ratio */ in dw_hdmi_set_high_tmds_clock_ratio()
1292 if (dw_hdmi_support_scdc(hdmi, display)) { in dw_hdmi_set_high_tmds_clock_ratio()
1294 drm_scdc_set_high_tmds_clock_ratio(hdmi->ddc, 1); in dw_hdmi_set_high_tmds_clock_ratio()
1296 drm_scdc_set_high_tmds_clock_ratio(hdmi->ddc, 0); in dw_hdmi_set_high_tmds_clock_ratio()
1301 static void dw_hdmi_phy_enable_powerdown(struct dw_hdmi *hdmi, bool enable) in dw_hdmi_phy_enable_powerdown() argument
1303 hdmi_mask_writeb(hdmi, !enable, HDMI_PHY_CONF0, in dw_hdmi_phy_enable_powerdown()
1308 static void dw_hdmi_phy_enable_tmds(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_enable_tmds() argument
1310 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_enable_tmds()
1315 static void dw_hdmi_phy_enable_svsret(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_enable_svsret() argument
1317 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_enable_svsret()
1322 void dw_hdmi_phy_gen2_pddq(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_gen2_pddq() argument
1324 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_gen2_pddq()
1330 void dw_hdmi_phy_gen2_txpwron(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_gen2_txpwron() argument
1332 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_gen2_txpwron()
1338 static void dw_hdmi_phy_sel_data_en_pol(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_sel_data_en_pol() argument
1340 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_sel_data_en_pol()
1345 static void dw_hdmi_phy_sel_interface_control(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_sel_interface_control() argument
1347 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_sel_interface_control()
1352 void dw_hdmi_phy_reset(struct dw_hdmi *hdmi) in dw_hdmi_phy_reset() argument
1355 hdmi_writeb(hdmi, HDMI_MC_PHYRSTZ_PHYRSTZ, HDMI_MC_PHYRSTZ); in dw_hdmi_phy_reset()
1356 hdmi_writeb(hdmi, 0, HDMI_MC_PHYRSTZ); in dw_hdmi_phy_reset()
1360 void dw_hdmi_phy_i2c_set_addr(struct dw_hdmi *hdmi, u8 address) in dw_hdmi_phy_i2c_set_addr() argument
1362 hdmi_phy_test_clear(hdmi, 1); in dw_hdmi_phy_i2c_set_addr()
1363 hdmi_writeb(hdmi, address, HDMI_PHY_I2CM_SLAVE_ADDR); in dw_hdmi_phy_i2c_set_addr()
1364 hdmi_phy_test_clear(hdmi, 0); in dw_hdmi_phy_i2c_set_addr()
1368 static void dw_hdmi_phy_power_off(struct dw_hdmi *hdmi) in dw_hdmi_phy_power_off() argument
1370 const struct dw_hdmi_phy_data *phy = hdmi->phy.data; in dw_hdmi_phy_power_off()
1374 if (phy->gen == 1) { in dw_hdmi_phy_power_off()
1375 dw_hdmi_phy_enable_tmds(hdmi, 0); in dw_hdmi_phy_power_off()
1376 dw_hdmi_phy_enable_powerdown(hdmi, true); in dw_hdmi_phy_power_off()
1380 dw_hdmi_phy_gen2_txpwron(hdmi, 0); in dw_hdmi_phy_power_off()
1387 val = hdmi_readb(hdmi, HDMI_PHY_STAT0); in dw_hdmi_phy_power_off()
1395 dev_warn(hdmi->dev, "PHY failed to power down\n"); in dw_hdmi_phy_power_off()
1397 dev_dbg(hdmi->dev, "PHY powered down in %u iterations\n", i); in dw_hdmi_phy_power_off()
1399 dw_hdmi_phy_gen2_pddq(hdmi, 1); in dw_hdmi_phy_power_off()
1402 static int dw_hdmi_phy_power_on(struct dw_hdmi *hdmi) in dw_hdmi_phy_power_on() argument
1404 const struct dw_hdmi_phy_data *phy = hdmi->phy.data; in dw_hdmi_phy_power_on()
1408 if (phy->gen == 1) { in dw_hdmi_phy_power_on()
1409 dw_hdmi_phy_enable_powerdown(hdmi, false); in dw_hdmi_phy_power_on()
1412 dw_hdmi_phy_enable_tmds(hdmi, 0); in dw_hdmi_phy_power_on()
1413 dw_hdmi_phy_enable_tmds(hdmi, 1); in dw_hdmi_phy_power_on()
1417 dw_hdmi_phy_gen2_txpwron(hdmi, 1); in dw_hdmi_phy_power_on()
1418 dw_hdmi_phy_gen2_pddq(hdmi, 0); in dw_hdmi_phy_power_on()
1422 val = hdmi_readb(hdmi, HDMI_PHY_STAT0) & HDMI_PHY_TX_PHY_LOCK; in dw_hdmi_phy_power_on()
1430 dev_err(hdmi->dev, "PHY PLL failed to lock\n"); in dw_hdmi_phy_power_on()
1431 return -ETIMEDOUT; in dw_hdmi_phy_power_on()
1434 dev_dbg(hdmi->dev, "PHY PLL locked %u iterations\n", i); in dw_hdmi_phy_power_on()
1439 * PHY configuration function for the DWC HDMI 3D TX PHY. Based on the available
1443 static int hdmi_phy_configure_dwc_hdmi_3d_tx(struct dw_hdmi *hdmi, in hdmi_phy_configure_dwc_hdmi_3d_tx() argument
1447 const struct dw_hdmi_mpll_config *mpll_config = pdata->mpll_cfg; in hdmi_phy_configure_dwc_hdmi_3d_tx()
1448 const struct dw_hdmi_curr_ctrl *curr_ctrl = pdata->cur_ctr; in hdmi_phy_configure_dwc_hdmi_3d_tx()
1449 const struct dw_hdmi_phy_config *phy_config = pdata->phy_config; in hdmi_phy_configure_dwc_hdmi_3d_tx()
1453 /* PLL/MPLL Cfg - always match on final entry */ in hdmi_phy_configure_dwc_hdmi_3d_tx()
1454 for (; mpll_config->mpixelclock != ~0UL; mpll_config++) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1455 if (mpixelclock <= mpll_config->mpixelclock) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1458 for (; curr_ctrl->mpixelclock != ~0UL; curr_ctrl++) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1459 if (mpixelclock <= curr_ctrl->mpixelclock) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1462 for (; phy_config->mpixelclock != ~0UL; phy_config++) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1463 if (mpixelclock <= phy_config->mpixelclock) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1466 if (mpll_config->mpixelclock == ~0UL || in hdmi_phy_configure_dwc_hdmi_3d_tx()
1467 curr_ctrl->mpixelclock == ~0UL || in hdmi_phy_configure_dwc_hdmi_3d_tx()
1468 phy_config->mpixelclock == ~0UL) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1469 return -EINVAL; in hdmi_phy_configure_dwc_hdmi_3d_tx()
1471 dw_hdmi_phy_i2c_write(hdmi, mpll_config->res[0].cpce, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1473 dw_hdmi_phy_i2c_write(hdmi, mpll_config->res[0].gmp, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1475 dw_hdmi_phy_i2c_write(hdmi, curr_ctrl->curr[0], in hdmi_phy_configure_dwc_hdmi_3d_tx()
1478 dw_hdmi_phy_i2c_write(hdmi, 0, HDMI_3D_TX_PHY_PLLPHBYCTRL); in hdmi_phy_configure_dwc_hdmi_3d_tx()
1479 dw_hdmi_phy_i2c_write(hdmi, HDMI_3D_TX_PHY_MSM_CTRL_CKO_SEL_FB_CLK, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1482 dw_hdmi_phy_i2c_write(hdmi, phy_config->term, HDMI_3D_TX_PHY_TXTERM); in hdmi_phy_configure_dwc_hdmi_3d_tx()
1483 dw_hdmi_phy_i2c_write(hdmi, phy_config->sym_ctr, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1485 dw_hdmi_phy_i2c_write(hdmi, phy_config->vlev_ctr, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1489 dw_hdmi_phy_i2c_write(hdmi, HDMI_3D_TX_PHY_CKCALCTRL_OVERRIDE, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1495 static int hdmi_phy_configure(struct dw_hdmi *hdmi, in hdmi_phy_configure() argument
1498 const struct dw_hdmi_phy_data *phy = hdmi->phy.data; in hdmi_phy_configure()
1499 const struct dw_hdmi_plat_data *pdata = hdmi->plat_data; in hdmi_phy_configure()
1500 unsigned long mpixelclock = hdmi->hdmi_data.video_mode.mpixelclock; in hdmi_phy_configure()
1501 unsigned long mtmdsclock = hdmi->hdmi_data.video_mode.mtmdsclock; in hdmi_phy_configure()
1504 dw_hdmi_phy_power_off(hdmi); in hdmi_phy_configure()
1506 dw_hdmi_set_high_tmds_clock_ratio(hdmi, display); in hdmi_phy_configure()
1509 if (phy->has_svsret) in hdmi_phy_configure()
1510 dw_hdmi_phy_enable_svsret(hdmi, 1); in hdmi_phy_configure()
1512 dw_hdmi_phy_reset(hdmi); in hdmi_phy_configure()
1514 hdmi_writeb(hdmi, HDMI_MC_HEACPHY_RST_ASSERT, HDMI_MC_HEACPHY_RST); in hdmi_phy_configure()
1516 dw_hdmi_phy_i2c_set_addr(hdmi, HDMI_PHY_I2CM_SLAVE_ADDR_PHY_GEN2); in hdmi_phy_configure()
1519 if (pdata->configure_phy) in hdmi_phy_configure()
1520 ret = pdata->configure_phy(hdmi, pdata->priv_data, mpixelclock); in hdmi_phy_configure()
1522 ret = phy->configure(hdmi, pdata, mpixelclock); in hdmi_phy_configure()
1524 dev_err(hdmi->dev, "PHY configuration failed (clock %lu)\n", in hdmi_phy_configure()
1533 return dw_hdmi_phy_power_on(hdmi); in hdmi_phy_configure()
1536 static int dw_hdmi_phy_init(struct dw_hdmi *hdmi, void *data, in dw_hdmi_phy_init() argument
1542 /* HDMI Phy spec says to do the phy initialization sequence twice */ in dw_hdmi_phy_init()
1544 dw_hdmi_phy_sel_data_en_pol(hdmi, 1); in dw_hdmi_phy_init()
1545 dw_hdmi_phy_sel_interface_control(hdmi, 0); in dw_hdmi_phy_init()
1547 ret = hdmi_phy_configure(hdmi, display); in dw_hdmi_phy_init()
1555 static void dw_hdmi_phy_disable(struct dw_hdmi *hdmi, void *data) in dw_hdmi_phy_disable() argument
1557 dw_hdmi_phy_power_off(hdmi); in dw_hdmi_phy_disable()
1560 enum drm_connector_status dw_hdmi_phy_read_hpd(struct dw_hdmi *hdmi, in dw_hdmi_phy_read_hpd() argument
1563 return hdmi_readb(hdmi, HDMI_PHY_STAT0) & HDMI_PHY_HPD ? in dw_hdmi_phy_read_hpd()
1568 void dw_hdmi_phy_update_hpd(struct dw_hdmi *hdmi, void *data, in dw_hdmi_phy_update_hpd() argument
1571 u8 old_mask = hdmi->phy_mask; in dw_hdmi_phy_update_hpd()
1574 hdmi->phy_mask |= HDMI_PHY_RX_SENSE; in dw_hdmi_phy_update_hpd()
1576 hdmi->phy_mask &= ~HDMI_PHY_RX_SENSE; in dw_hdmi_phy_update_hpd()
1578 if (old_mask != hdmi->phy_mask) in dw_hdmi_phy_update_hpd()
1579 hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0); in dw_hdmi_phy_update_hpd()
1583 void dw_hdmi_phy_setup_hpd(struct dw_hdmi *hdmi, void *data) in dw_hdmi_phy_setup_hpd() argument
1589 hdmi_writeb(hdmi, HDMI_PHY_HPD | HDMI_PHY_RX_SENSE, HDMI_PHY_POL0); in dw_hdmi_phy_setup_hpd()
1590 hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE, in dw_hdmi_phy_setup_hpd()
1594 hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0); in dw_hdmi_phy_setup_hpd()
1597 hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE, in dw_hdmi_phy_setup_hpd()
1599 hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE), in dw_hdmi_phy_setup_hpd()
1612 /* -----------------------------------------------------------------------------
1613 * HDMI TX Setup
1616 static void hdmi_tx_hdcp_config(struct dw_hdmi *hdmi) in hdmi_tx_hdcp_config() argument
1620 if (hdmi->hdmi_data.video_mode.mdataenablepolarity) in hdmi_tx_hdcp_config()
1626 hdmi_modb(hdmi, HDMI_A_HDCPCFG0_RXDETECT_DISABLE, in hdmi_tx_hdcp_config()
1629 hdmi_modb(hdmi, de, HDMI_A_VIDPOLCFG_DATAENPOL_MASK, HDMI_A_VIDPOLCFG); in hdmi_tx_hdcp_config()
1631 hdmi_modb(hdmi, HDMI_A_HDCPCFG1_ENCRYPTIONDISABLE_DISABLE, in hdmi_tx_hdcp_config()
1635 static void hdmi_config_AVI(struct dw_hdmi *hdmi, in hdmi_config_AVI() argument
1636 const struct drm_connector *connector, in hdmi_config_AVI() argument
1643 drm_hdmi_avi_infoframe_from_display_mode(&frame, connector, mode); in hdmi_config_AVI()
1645 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_config_AVI()
1646 drm_hdmi_avi_infoframe_quant_range(&frame, connector, mode, in hdmi_config_AVI()
1647 hdmi->hdmi_data.rgb_limited_range ? in hdmi_config_AVI()
1656 if (hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_config_AVI()
1658 else if (hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_config_AVI()
1660 else if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_config_AVI()
1666 if (!hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_config_AVI()
1667 switch (hdmi->hdmi_data.enc_out_encoding) { in hdmi_config_AVI()
1669 if (hdmi->hdmi_data.enc_in_encoding == V4L2_YCBCR_ENC_XV601) in hdmi_config_AVI()
1677 if (hdmi->hdmi_data.enc_in_encoding == V4L2_YCBCR_ENC_XV709) in hdmi_config_AVI()
1714 hdmi_writeb(hdmi, val, HDMI_FC_AVICONF0); in hdmi_config_AVI()
1720 hdmi_writeb(hdmi, val, HDMI_FC_AVICONF1); in hdmi_config_AVI()
1728 hdmi_writeb(hdmi, val, HDMI_FC_AVICONF2); in hdmi_config_AVI()
1732 hdmi_writeb(hdmi, val, HDMI_FC_AVIVID); in hdmi_config_AVI()
1734 /* AVI Data Byte 5- set up input and output pixel repetition */ in hdmi_config_AVI()
1735 val = (((hdmi->hdmi_data.video_mode.mpixelrepetitioninput + 1) << in hdmi_config_AVI()
1738 ((hdmi->hdmi_data.video_mode.mpixelrepetitionoutput << in hdmi_config_AVI()
1741 hdmi_writeb(hdmi, val, HDMI_FC_PRCONF); in hdmi_config_AVI()
1749 hdmi_writeb(hdmi, val, HDMI_FC_AVICONF3); in hdmi_config_AVI()
1751 /* AVI Data Bytes 6-13 */ in hdmi_config_AVI()
1752 hdmi_writeb(hdmi, frame.top_bar & 0xff, HDMI_FC_AVIETB0); in hdmi_config_AVI()
1753 hdmi_writeb(hdmi, (frame.top_bar >> 8) & 0xff, HDMI_FC_AVIETB1); in hdmi_config_AVI()
1754 hdmi_writeb(hdmi, frame.bottom_bar & 0xff, HDMI_FC_AVISBB0); in hdmi_config_AVI()
1755 hdmi_writeb(hdmi, (frame.bottom_bar >> 8) & 0xff, HDMI_FC_AVISBB1); in hdmi_config_AVI()
1756 hdmi_writeb(hdmi, frame.left_bar & 0xff, HDMI_FC_AVIELB0); in hdmi_config_AVI()
1757 hdmi_writeb(hdmi, (frame.left_bar >> 8) & 0xff, HDMI_FC_AVIELB1); in hdmi_config_AVI()
1758 hdmi_writeb(hdmi, frame.right_bar & 0xff, HDMI_FC_AVISRB0); in hdmi_config_AVI()
1759 hdmi_writeb(hdmi, (frame.right_bar >> 8) & 0xff, HDMI_FC_AVISRB1); in hdmi_config_AVI()
1762 static void hdmi_config_vendor_specific_infoframe(struct dw_hdmi *hdmi, in hdmi_config_vendor_specific_infoframe() argument
1763 const struct drm_connector *connector, in hdmi_config_vendor_specific_infoframe() argument
1770 err = drm_hdmi_vendor_infoframe_from_display_mode(&frame, connector, in hdmi_config_vendor_specific_infoframe()
1783 dev_err(hdmi->dev, "Failed to pack vendor infoframe: %zd\n", in hdmi_config_vendor_specific_infoframe()
1787 hdmi_mask_writeb(hdmi, 0, HDMI_FC_DATAUTO0, HDMI_FC_DATAUTO0_VSD_OFFSET, in hdmi_config_vendor_specific_infoframe()
1790 /* Set the length of HDMI vendor specific InfoFrame payload */ in hdmi_config_vendor_specific_infoframe()
1791 hdmi_writeb(hdmi, buffer[2], HDMI_FC_VSDSIZE); in hdmi_config_vendor_specific_infoframe()
1794 hdmi_writeb(hdmi, buffer[4], HDMI_FC_VSDIEEEID0); in hdmi_config_vendor_specific_infoframe()
1795 hdmi_writeb(hdmi, buffer[5], HDMI_FC_VSDIEEEID1); in hdmi_config_vendor_specific_infoframe()
1796 hdmi_writeb(hdmi, buffer[6], HDMI_FC_VSDIEEEID2); in hdmi_config_vendor_specific_infoframe()
1799 hdmi_writeb(hdmi, buffer[7], HDMI_FC_VSDPAYLOAD0); in hdmi_config_vendor_specific_infoframe()
1800 hdmi_writeb(hdmi, buffer[8], HDMI_FC_VSDPAYLOAD1); in hdmi_config_vendor_specific_infoframe()
1803 hdmi_writeb(hdmi, buffer[9], HDMI_FC_VSDPAYLOAD2); in hdmi_config_vendor_specific_infoframe()
1806 hdmi_writeb(hdmi, 1, HDMI_FC_DATAUTO1); in hdmi_config_vendor_specific_infoframe()
1809 hdmi_writeb(hdmi, 0x11, HDMI_FC_DATAUTO2); in hdmi_config_vendor_specific_infoframe()
1812 hdmi_mask_writeb(hdmi, 1, HDMI_FC_DATAUTO0, HDMI_FC_DATAUTO0_VSD_OFFSET, in hdmi_config_vendor_specific_infoframe()
1816 static void hdmi_config_drm_infoframe(struct dw_hdmi *hdmi, in hdmi_config_drm_infoframe() argument
1817 const struct drm_connector *connector) in hdmi_config_drm_infoframe() argument
1819 const struct drm_connector_state *conn_state = connector->state; in hdmi_config_drm_infoframe()
1825 if (!hdmi->plat_data->use_drm_infoframe) in hdmi_config_drm_infoframe()
1828 hdmi_modb(hdmi, HDMI_FC_PACKET_TX_EN_DRM_DISABLE, in hdmi_config_drm_infoframe()
1837 dev_err(hdmi->dev, "Failed to pack drm infoframe: %zd\n", err); in hdmi_config_drm_infoframe()
1841 hdmi_writeb(hdmi, frame.version, HDMI_FC_DRM_HB0); in hdmi_config_drm_infoframe()
1842 hdmi_writeb(hdmi, frame.length, HDMI_FC_DRM_HB1); in hdmi_config_drm_infoframe()
1845 hdmi_writeb(hdmi, buffer[4 + i], HDMI_FC_DRM_PB0 + i); in hdmi_config_drm_infoframe()
1847 hdmi_writeb(hdmi, 1, HDMI_FC_DRM_UP); in hdmi_config_drm_infoframe()
1848 hdmi_modb(hdmi, HDMI_FC_PACKET_TX_EN_DRM_ENABLE, in hdmi_config_drm_infoframe()
1852 static void hdmi_av_composer(struct dw_hdmi *hdmi, in hdmi_av_composer() argument
1857 const struct drm_hdmi_info *hdmi_info = &display->hdmi; in hdmi_av_composer()
1858 struct hdmi_vmode *vmode = &hdmi->hdmi_data.video_mode; in hdmi_av_composer()
1862 vmode->mpixelclock = mode->clock * 1000; in hdmi_av_composer()
1864 dev_dbg(hdmi->dev, "final pixclk = %d\n", vmode->mpixelclock); in hdmi_av_composer()
1866 vmode->mtmdsclock = vmode->mpixelclock; in hdmi_av_composer()
1868 if (!hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_av_composer()
1870 hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_av_composer()
1872 vmode->mtmdsclock = vmode->mpixelclock * 2; in hdmi_av_composer()
1875 vmode->mtmdsclock = vmode->mpixelclock * 3 / 2; in hdmi_av_composer()
1878 vmode->mtmdsclock = vmode->mpixelclock * 5 / 4; in hdmi_av_composer()
1883 if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_av_composer()
1884 vmode->mtmdsclock /= 2; in hdmi_av_composer()
1886 dev_dbg(hdmi->dev, "final tmdsclock = %d\n", vmode->mtmdsclock); in hdmi_av_composer()
1889 inv_val = (hdmi->hdmi_data.hdcp_enable || in hdmi_av_composer()
1890 (dw_hdmi_support_scdc(hdmi, display) && in hdmi_av_composer()
1891 (vmode->mtmdsclock > HDMI14_MAX_TMDSCLK || in hdmi_av_composer()
1892 hdmi_info->scdc.scrambling.low_rates)) ? in hdmi_av_composer()
1896 inv_val |= mode->flags & DRM_MODE_FLAG_PVSYNC ? in hdmi_av_composer()
1900 inv_val |= mode->flags & DRM_MODE_FLAG_PHSYNC ? in hdmi_av_composer()
1904 inv_val |= (vmode->mdataenablepolarity ? in hdmi_av_composer()
1908 if (hdmi->vic == 39) in hdmi_av_composer()
1911 inv_val |= mode->flags & DRM_MODE_FLAG_INTERLACE ? in hdmi_av_composer()
1915 inv_val |= mode->flags & DRM_MODE_FLAG_INTERLACE ? in hdmi_av_composer()
1919 inv_val |= hdmi->sink_is_hdmi ? in hdmi_av_composer()
1923 hdmi_writeb(hdmi, inv_val, HDMI_FC_INVIDCONF); in hdmi_av_composer()
1925 hdisplay = mode->hdisplay; in hdmi_av_composer()
1926 hblank = mode->htotal - mode->hdisplay; in hdmi_av_composer()
1927 h_de_hs = mode->hsync_start - mode->hdisplay; in hdmi_av_composer()
1928 hsync_len = mode->hsync_end - mode->hsync_start; in hdmi_av_composer()
1934 if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_av_composer()
1941 vdisplay = mode->vdisplay; in hdmi_av_composer()
1942 vblank = mode->vtotal - mode->vdisplay; in hdmi_av_composer()
1943 v_de_vs = mode->vsync_start - mode->vdisplay; in hdmi_av_composer()
1944 vsync_len = mode->vsync_end - mode->vsync_start; in hdmi_av_composer()
1950 if (mode->flags & DRM_MODE_FLAG_INTERLACE) { in hdmi_av_composer()
1958 if (dw_hdmi_support_scdc(hdmi, display)) { in hdmi_av_composer()
1959 if (vmode->mtmdsclock > HDMI14_MAX_TMDSCLK || in hdmi_av_composer()
1960 hdmi_info->scdc.scrambling.low_rates) { in hdmi_av_composer()
1970 drm_scdc_readb(hdmi->ddc, SCDC_SINK_VERSION, in hdmi_av_composer()
1972 drm_scdc_writeb(hdmi->ddc, SCDC_SOURCE_VERSION, in hdmi_av_composer()
1976 drm_scdc_set_scrambling(hdmi->ddc, 1); in hdmi_av_composer()
1980 * that the quasi-static configuration bit in hdmi_av_composer()
1985 hdmi_writeb(hdmi, (u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, in hdmi_av_composer()
1987 hdmi_writeb(hdmi, 1, HDMI_FC_SCRAMBLER_CTRL); in hdmi_av_composer()
1989 hdmi_writeb(hdmi, 0, HDMI_FC_SCRAMBLER_CTRL); in hdmi_av_composer()
1990 hdmi_writeb(hdmi, (u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, in hdmi_av_composer()
1992 drm_scdc_set_scrambling(hdmi->ddc, 0); in hdmi_av_composer()
1997 hdmi_writeb(hdmi, hdisplay >> 8, HDMI_FC_INHACTV1); in hdmi_av_composer()
1998 hdmi_writeb(hdmi, hdisplay, HDMI_FC_INHACTV0); in hdmi_av_composer()
2001 hdmi_writeb(hdmi, vdisplay >> 8, HDMI_FC_INVACTV1); in hdmi_av_composer()
2002 hdmi_writeb(hdmi, vdisplay, HDMI_FC_INVACTV0); in hdmi_av_composer()
2005 hdmi_writeb(hdmi, hblank >> 8, HDMI_FC_INHBLANK1); in hdmi_av_composer()
2006 hdmi_writeb(hdmi, hblank, HDMI_FC_INHBLANK0); in hdmi_av_composer()
2009 hdmi_writeb(hdmi, vblank, HDMI_FC_INVBLANK); in hdmi_av_composer()
2012 hdmi_writeb(hdmi, h_de_hs >> 8, HDMI_FC_HSYNCINDELAY1); in hdmi_av_composer()
2013 hdmi_writeb(hdmi, h_de_hs, HDMI_FC_HSYNCINDELAY0); in hdmi_av_composer()
2016 hdmi_writeb(hdmi, v_de_vs, HDMI_FC_VSYNCINDELAY); in hdmi_av_composer()
2019 hdmi_writeb(hdmi, hsync_len >> 8, HDMI_FC_HSYNCINWIDTH1); in hdmi_av_composer()
2020 hdmi_writeb(hdmi, hsync_len, HDMI_FC_HSYNCINWIDTH0); in hdmi_av_composer()
2023 hdmi_writeb(hdmi, vsync_len, HDMI_FC_VSYNCINWIDTH); in hdmi_av_composer()
2026 /* HDMI Initialization Step B.4 */
2027 static void dw_hdmi_enable_video_path(struct dw_hdmi *hdmi) in dw_hdmi_enable_video_path() argument
2030 hdmi_writeb(hdmi, 12, HDMI_FC_CTRLDUR); in dw_hdmi_enable_video_path()
2031 hdmi_writeb(hdmi, 32, HDMI_FC_EXCTRLDUR); in dw_hdmi_enable_video_path()
2032 hdmi_writeb(hdmi, 1, HDMI_FC_EXCTRLSPAC); in dw_hdmi_enable_video_path()
2035 hdmi_writeb(hdmi, 0x0B, HDMI_FC_CH0PREAM); in dw_hdmi_enable_video_path()
2036 hdmi_writeb(hdmi, 0x16, HDMI_FC_CH1PREAM); in dw_hdmi_enable_video_path()
2037 hdmi_writeb(hdmi, 0x21, HDMI_FC_CH2PREAM); in dw_hdmi_enable_video_path()
2040 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_HDCPCLK_DISABLE | in dw_hdmi_enable_video_path()
2045 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_PIXELCLK_DISABLE; in dw_hdmi_enable_video_path()
2046 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2048 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_TMDSCLK_DISABLE; in dw_hdmi_enable_video_path()
2049 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2052 if (is_csc_needed(hdmi)) { in dw_hdmi_enable_video_path()
2053 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_CSCCLK_DISABLE; in dw_hdmi_enable_video_path()
2054 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2056 hdmi_writeb(hdmi, HDMI_MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_IN_PATH, in dw_hdmi_enable_video_path()
2059 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_CSCCLK_DISABLE; in dw_hdmi_enable_video_path()
2060 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2062 hdmi_writeb(hdmi, HDMI_MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_BYPASS, in dw_hdmi_enable_video_path()
2068 static void dw_hdmi_clear_overflow(struct dw_hdmi *hdmi) in dw_hdmi_clear_overflow() argument
2080 * The number of iterations matters and depends on the HDMI TX revision in dw_hdmi_clear_overflow()
2091 switch (hdmi->version) { in dw_hdmi_clear_overflow()
2108 hdmi_writeb(hdmi, (u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, HDMI_MC_SWRSTZ); in dw_hdmi_clear_overflow()
2110 val = hdmi_readb(hdmi, HDMI_FC_INVIDCONF); in dw_hdmi_clear_overflow()
2112 hdmi_writeb(hdmi, val, HDMI_FC_INVIDCONF); in dw_hdmi_clear_overflow()
2115 static void hdmi_disable_overflow_interrupts(struct dw_hdmi *hdmi) in hdmi_disable_overflow_interrupts() argument
2117 hdmi_writeb(hdmi, HDMI_IH_MUTE_FC_STAT2_OVERFLOW_MASK, in hdmi_disable_overflow_interrupts()
2121 static int dw_hdmi_setup(struct dw_hdmi *hdmi, in dw_hdmi_setup() argument
2122 const struct drm_connector *connector, in dw_hdmi_setup() argument
2127 hdmi_disable_overflow_interrupts(hdmi); in dw_hdmi_setup()
2129 hdmi->vic = drm_match_cea_mode(mode); in dw_hdmi_setup()
2131 if (!hdmi->vic) { in dw_hdmi_setup()
2132 dev_dbg(hdmi->dev, "Non-CEA mode used in HDMI\n"); in dw_hdmi_setup()
2134 dev_dbg(hdmi->dev, "CEA mode used vic=%d\n", hdmi->vic); in dw_hdmi_setup()
2137 if ((hdmi->vic == 6) || (hdmi->vic == 7) || in dw_hdmi_setup()
2138 (hdmi->vic == 21) || (hdmi->vic == 22) || in dw_hdmi_setup()
2139 (hdmi->vic == 2) || (hdmi->vic == 3) || in dw_hdmi_setup()
2140 (hdmi->vic == 17) || (hdmi->vic == 18)) in dw_hdmi_setup()
2141 hdmi->hdmi_data.enc_out_encoding = V4L2_YCBCR_ENC_601; in dw_hdmi_setup()
2143 hdmi->hdmi_data.enc_out_encoding = V4L2_YCBCR_ENC_709; in dw_hdmi_setup()
2145 hdmi->hdmi_data.video_mode.mpixelrepetitionoutput = 0; in dw_hdmi_setup()
2146 hdmi->hdmi_data.video_mode.mpixelrepetitioninput = 0; in dw_hdmi_setup()
2148 if (hdmi->hdmi_data.enc_in_bus_format == MEDIA_BUS_FMT_FIXED) in dw_hdmi_setup()
2149 hdmi->hdmi_data.enc_in_bus_format = MEDIA_BUS_FMT_RGB888_1X24; in dw_hdmi_setup()
2152 if (hdmi->plat_data->input_bus_encoding) in dw_hdmi_setup()
2153 hdmi->hdmi_data.enc_in_encoding = in dw_hdmi_setup()
2154 hdmi->plat_data->input_bus_encoding; in dw_hdmi_setup()
2156 hdmi->hdmi_data.enc_in_encoding = V4L2_YCBCR_ENC_DEFAULT; in dw_hdmi_setup()
2158 if (hdmi->hdmi_data.enc_out_bus_format == MEDIA_BUS_FMT_FIXED) in dw_hdmi_setup()
2159 hdmi->hdmi_data.enc_out_bus_format = MEDIA_BUS_FMT_RGB888_1X24; in dw_hdmi_setup()
2161 hdmi->hdmi_data.rgb_limited_range = hdmi->sink_is_hdmi && in dw_hdmi_setup()
2165 hdmi->hdmi_data.pix_repet_factor = 0; in dw_hdmi_setup()
2166 hdmi->hdmi_data.hdcp_enable = 0; in dw_hdmi_setup()
2167 hdmi->hdmi_data.video_mode.mdataenablepolarity = true; in dw_hdmi_setup()
2169 /* HDMI Initialization Step B.1 */ in dw_hdmi_setup()
2170 hdmi_av_composer(hdmi, &connector->display_info, mode); in dw_hdmi_setup()
2172 /* HDMI Initializateion Step B.2 */ in dw_hdmi_setup()
2173 ret = hdmi->phy.ops->init(hdmi, hdmi->phy.data, in dw_hdmi_setup()
2174 &connector->display_info, in dw_hdmi_setup()
2175 &hdmi->previous_mode); in dw_hdmi_setup()
2178 hdmi->phy.enabled = true; in dw_hdmi_setup()
2180 /* HDMI Initialization Step B.3 */ in dw_hdmi_setup()
2181 dw_hdmi_enable_video_path(hdmi); in dw_hdmi_setup()
2183 if (hdmi->sink_has_audio) { in dw_hdmi_setup()
2184 dev_dbg(hdmi->dev, "sink has audio support\n"); in dw_hdmi_setup()
2186 /* HDMI Initialization Step E - Configure audio */ in dw_hdmi_setup()
2187 hdmi_clk_regenerator_update_pixel_clock(hdmi); in dw_hdmi_setup()
2188 hdmi_enable_audio_clk(hdmi, hdmi->audio_enable); in dw_hdmi_setup()
2192 if (hdmi->sink_is_hdmi) { in dw_hdmi_setup()
2193 dev_dbg(hdmi->dev, "%s HDMI mode\n", __func__); in dw_hdmi_setup()
2195 /* HDMI Initialization Step F - Configure AVI InfoFrame */ in dw_hdmi_setup()
2196 hdmi_config_AVI(hdmi, connector, mode); in dw_hdmi_setup()
2197 hdmi_config_vendor_specific_infoframe(hdmi, connector, mode); in dw_hdmi_setup()
2198 hdmi_config_drm_infoframe(hdmi, connector); in dw_hdmi_setup()
2200 dev_dbg(hdmi->dev, "%s DVI mode\n", __func__); in dw_hdmi_setup()
2203 hdmi_video_packetize(hdmi); in dw_hdmi_setup()
2204 hdmi_video_csc(hdmi); in dw_hdmi_setup()
2205 hdmi_video_sample(hdmi); in dw_hdmi_setup()
2206 hdmi_tx_hdcp_config(hdmi); in dw_hdmi_setup()
2208 dw_hdmi_clear_overflow(hdmi); in dw_hdmi_setup()
2213 static void initialize_hdmi_ih_mutes(struct dw_hdmi *hdmi) in initialize_hdmi_ih_mutes() argument
2222 * Disable top level interrupt bits in HDMI block in initialize_hdmi_ih_mutes()
2224 ih_mute = hdmi_readb(hdmi, HDMI_IH_MUTE) | in initialize_hdmi_ih_mutes()
2228 hdmi_writeb(hdmi, ih_mute, HDMI_IH_MUTE); in initialize_hdmi_ih_mutes()
2231 hdmi_writeb(hdmi, 0xff, HDMI_VP_MASK); in initialize_hdmi_ih_mutes()
2232 hdmi_writeb(hdmi, 0xff, HDMI_FC_MASK0); in initialize_hdmi_ih_mutes()
2233 hdmi_writeb(hdmi, 0xff, HDMI_FC_MASK1); in initialize_hdmi_ih_mutes()
2234 hdmi_writeb(hdmi, 0xff, HDMI_FC_MASK2); in initialize_hdmi_ih_mutes()
2235 hdmi_writeb(hdmi, 0xff, HDMI_PHY_MASK0); in initialize_hdmi_ih_mutes()
2236 hdmi_writeb(hdmi, 0xff, HDMI_PHY_I2CM_INT_ADDR); in initialize_hdmi_ih_mutes()
2237 hdmi_writeb(hdmi, 0xff, HDMI_PHY_I2CM_CTLINT_ADDR); in initialize_hdmi_ih_mutes()
2238 hdmi_writeb(hdmi, 0xff, HDMI_AUD_INT); in initialize_hdmi_ih_mutes()
2239 hdmi_writeb(hdmi, 0xff, HDMI_AUD_SPDIFINT); in initialize_hdmi_ih_mutes()
2240 hdmi_writeb(hdmi, 0xff, HDMI_AUD_HBR_MASK); in initialize_hdmi_ih_mutes()
2241 hdmi_writeb(hdmi, 0xff, HDMI_GP_MASK); in initialize_hdmi_ih_mutes()
2242 hdmi_writeb(hdmi, 0xff, HDMI_A_APIINTMSK); in initialize_hdmi_ih_mutes()
2243 hdmi_writeb(hdmi, 0xff, HDMI_I2CM_INT); in initialize_hdmi_ih_mutes()
2244 hdmi_writeb(hdmi, 0xff, HDMI_I2CM_CTLINT); in initialize_hdmi_ih_mutes()
2247 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_FC_STAT0); in initialize_hdmi_ih_mutes()
2248 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_FC_STAT1); in initialize_hdmi_ih_mutes()
2249 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_FC_STAT2); in initialize_hdmi_ih_mutes()
2250 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_AS_STAT0); in initialize_hdmi_ih_mutes()
2251 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_PHY_STAT0); in initialize_hdmi_ih_mutes()
2252 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_I2CM_STAT0); in initialize_hdmi_ih_mutes()
2253 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_CEC_STAT0); in initialize_hdmi_ih_mutes()
2254 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_VP_STAT0); in initialize_hdmi_ih_mutes()
2255 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_I2CMPHY_STAT0); in initialize_hdmi_ih_mutes()
2256 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_AHBDMAAUD_STAT0); in initialize_hdmi_ih_mutes()
2258 /* Enable top level interrupt bits in HDMI block */ in initialize_hdmi_ih_mutes()
2261 hdmi_writeb(hdmi, ih_mute, HDMI_IH_MUTE); in initialize_hdmi_ih_mutes()
2264 static void dw_hdmi_poweron(struct dw_hdmi *hdmi) in dw_hdmi_poweron() argument
2266 hdmi->bridge_is_on = true; in dw_hdmi_poweron()
2270 * is only be called when !hdmi->disabled. in dw_hdmi_poweron()
2272 dw_hdmi_setup(hdmi, hdmi->curr_conn, &hdmi->previous_mode); in dw_hdmi_poweron()
2275 static void dw_hdmi_poweroff(struct dw_hdmi *hdmi) in dw_hdmi_poweroff() argument
2277 if (hdmi->phy.enabled) { in dw_hdmi_poweroff()
2278 hdmi->phy.ops->disable(hdmi, hdmi->phy.data); in dw_hdmi_poweroff()
2279 hdmi->phy.enabled = false; in dw_hdmi_poweroff()
2282 hdmi->bridge_is_on = false; in dw_hdmi_poweroff()
2285 static void dw_hdmi_update_power(struct dw_hdmi *hdmi) in dw_hdmi_update_power() argument
2287 int force = hdmi->force; in dw_hdmi_update_power()
2289 if (hdmi->disabled) { in dw_hdmi_update_power()
2292 if (hdmi->rxsense) in dw_hdmi_update_power()
2299 if (hdmi->bridge_is_on) in dw_hdmi_update_power()
2300 dw_hdmi_poweroff(hdmi); in dw_hdmi_update_power()
2302 if (!hdmi->bridge_is_on) in dw_hdmi_update_power()
2303 dw_hdmi_poweron(hdmi); in dw_hdmi_update_power()
2319 static void dw_hdmi_update_phy_mask(struct dw_hdmi *hdmi) in dw_hdmi_update_phy_mask() argument
2321 if (hdmi->phy.ops->update_hpd) in dw_hdmi_update_phy_mask()
2322 hdmi->phy.ops->update_hpd(hdmi, hdmi->phy.data, in dw_hdmi_update_phy_mask()
2323 hdmi->force, hdmi->disabled, in dw_hdmi_update_phy_mask()
2324 hdmi->rxsense); in dw_hdmi_update_phy_mask()
2327 static enum drm_connector_status dw_hdmi_detect(struct dw_hdmi *hdmi) in dw_hdmi_detect() argument
2331 result = hdmi->phy.ops->read_hpd(hdmi, hdmi->phy.data); in dw_hdmi_detect()
2333 mutex_lock(&hdmi->mutex); in dw_hdmi_detect()
2334 if (result != hdmi->last_connector_result) { in dw_hdmi_detect()
2335 dev_dbg(hdmi->dev, "read_hpd result: %d", result); in dw_hdmi_detect()
2336 handle_plugged_change(hdmi, in dw_hdmi_detect()
2338 hdmi->last_connector_result = result; in dw_hdmi_detect()
2340 mutex_unlock(&hdmi->mutex); in dw_hdmi_detect()
2345 static struct edid *dw_hdmi_get_edid(struct dw_hdmi *hdmi, in dw_hdmi_get_edid() argument
2346 struct drm_connector *connector) in dw_hdmi_get_edid() argument
2350 if (!hdmi->ddc) in dw_hdmi_get_edid()
2353 edid = drm_get_edid(connector, hdmi->ddc); in dw_hdmi_get_edid()
2355 dev_dbg(hdmi->dev, "failed to get edid\n"); in dw_hdmi_get_edid()
2359 dev_dbg(hdmi->dev, "got edid: width[%d] x height[%d]\n", in dw_hdmi_get_edid()
2360 edid->width_cm, edid->height_cm); in dw_hdmi_get_edid()
2362 hdmi->sink_is_hdmi = drm_detect_hdmi_monitor(edid); in dw_hdmi_get_edid()
2363 hdmi->sink_has_audio = drm_detect_monitor_audio(edid); in dw_hdmi_get_edid()
2368 /* -----------------------------------------------------------------------------
2369 * DRM Connector Operations
2373 dw_hdmi_connector_detect(struct drm_connector *connector, bool force) in dw_hdmi_connector_detect() argument
2375 struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, in dw_hdmi_connector_detect() local
2376 connector); in dw_hdmi_connector_detect()
2377 return dw_hdmi_detect(hdmi); in dw_hdmi_connector_detect()
2380 static int dw_hdmi_connector_get_modes(struct drm_connector *connector) in dw_hdmi_connector_get_modes() argument
2382 struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, in dw_hdmi_connector_get_modes() local
2383 connector); in dw_hdmi_connector_get_modes()
2387 edid = dw_hdmi_get_edid(hdmi, connector); in dw_hdmi_connector_get_modes()
2391 drm_connector_update_edid_property(connector, edid); in dw_hdmi_connector_get_modes()
2392 cec_notifier_set_phys_addr_from_edid(hdmi->cec_notifier, edid); in dw_hdmi_connector_get_modes()
2393 ret = drm_add_edid_modes(connector, edid); in dw_hdmi_connector_get_modes()
2399 static int dw_hdmi_connector_atomic_check(struct drm_connector *connector, in dw_hdmi_connector_atomic_check() argument
2403 drm_atomic_get_old_connector_state(state, connector); in dw_hdmi_connector_atomic_check()
2405 drm_atomic_get_new_connector_state(state, connector); in dw_hdmi_connector_atomic_check()
2406 struct drm_crtc *crtc = new_state->crtc; in dw_hdmi_connector_atomic_check()
2417 crtc_state->mode_changed = true; in dw_hdmi_connector_atomic_check()
2423 static void dw_hdmi_connector_force(struct drm_connector *connector) in dw_hdmi_connector_force() argument
2425 struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, in dw_hdmi_connector_force() local
2426 connector); in dw_hdmi_connector_force()
2428 mutex_lock(&hdmi->mutex); in dw_hdmi_connector_force()
2429 hdmi->force = connector->force; in dw_hdmi_connector_force()
2430 dw_hdmi_update_power(hdmi); in dw_hdmi_connector_force()
2431 dw_hdmi_update_phy_mask(hdmi); in dw_hdmi_connector_force()
2432 mutex_unlock(&hdmi->mutex); in dw_hdmi_connector_force()
2450 static int dw_hdmi_connector_create(struct dw_hdmi *hdmi) in dw_hdmi_connector_create() argument
2452 struct drm_connector *connector = &hdmi->connector; in dw_hdmi_connector_create() local
2456 if (hdmi->version >= 0x200a) in dw_hdmi_connector_create()
2457 connector->ycbcr_420_allowed = in dw_hdmi_connector_create()
2458 hdmi->plat_data->ycbcr_420_allowed; in dw_hdmi_connector_create()
2460 connector->ycbcr_420_allowed = false; in dw_hdmi_connector_create()
2462 connector->interlace_allowed = 1; in dw_hdmi_connector_create()
2463 connector->polled = DRM_CONNECTOR_POLL_HPD; in dw_hdmi_connector_create()
2465 drm_connector_helper_add(connector, &dw_hdmi_connector_helper_funcs); in dw_hdmi_connector_create()
2467 drm_connector_init_with_ddc(hdmi->bridge.dev, connector, in dw_hdmi_connector_create()
2470 hdmi->ddc); in dw_hdmi_connector_create()
2474 * connector to have a state. in dw_hdmi_connector_create()
2476 drm_atomic_helper_connector_reset(connector); in dw_hdmi_connector_create()
2478 drm_connector_attach_max_bpc_property(connector, 8, 16); in dw_hdmi_connector_create()
2480 if (hdmi->version >= 0x200a && hdmi->plat_data->use_drm_infoframe) in dw_hdmi_connector_create()
2481 drm_connector_attach_hdr_output_metadata_property(connector); in dw_hdmi_connector_create()
2483 drm_connector_attach_encoder(connector, hdmi->bridge.encoder); in dw_hdmi_connector_create()
2485 cec_fill_conn_info_from_drm(&conn_info, connector); in dw_hdmi_connector_create()
2487 notifier = cec_notifier_conn_register(hdmi->dev, NULL, &conn_info); in dw_hdmi_connector_create()
2489 return -ENOMEM; in dw_hdmi_connector_create()
2491 mutex_lock(&hdmi->cec_notifier_mutex); in dw_hdmi_connector_create()
2492 hdmi->cec_notifier = notifier; in dw_hdmi_connector_create()
2493 mutex_unlock(&hdmi->cec_notifier_mutex); in dw_hdmi_connector_create()
2498 /* -----------------------------------------------------------------------------
2504 * - MEDIA_BUS_FMT_UYYVYY16_0_5X48,
2505 * - MEDIA_BUS_FMT_UYYVYY12_0_5X36,
2506 * - MEDIA_BUS_FMT_UYYVYY10_0_5X30,
2507 * - MEDIA_BUS_FMT_UYYVYY8_0_5X24,
2508 * - MEDIA_BUS_FMT_YUV16_1X48,
2509 * - MEDIA_BUS_FMT_RGB161616_1X48,
2510 * - MEDIA_BUS_FMT_UYVY12_1X24,
2511 * - MEDIA_BUS_FMT_YUV12_1X36,
2512 * - MEDIA_BUS_FMT_RGB121212_1X36,
2513 * - MEDIA_BUS_FMT_UYVY10_1X20,
2514 * - MEDIA_BUS_FMT_YUV10_1X30,
2515 * - MEDIA_BUS_FMT_RGB101010_1X30,
2516 * - MEDIA_BUS_FMT_UYVY8_1X16,
2517 * - MEDIA_BUS_FMT_YUV8_1X24,
2518 * - MEDIA_BUS_FMT_RGB888_1X24,
2521 /* Can return a maximum of 11 possible output formats for a mode/connector */
2530 struct drm_connector *conn = conn_state->connector; in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2531 struct drm_display_info *info = &conn->display_info; in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2532 struct drm_display_mode *mode = &crtc_state->mode; in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2533 u8 max_bpc = conn_state->max_requested_bpc; in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2534 bool is_hdmi2_sink = info->hdmi.scdc.supported || in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2535 (info->color_formats & DRM_COLOR_FORMAT_YCRCB420); in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2546 /* If dw-hdmi is the only bridge, avoid negociating with ourselves */ in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2547 if (list_is_singular(&bridge->encoder->bridge_chain)) { in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2558 if (conn->ycbcr_420_allowed && in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2563 if (max_bpc >= 16 && info->bpc == 16 && in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2564 (info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_48)) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2567 if (max_bpc >= 12 && info->bpc >= 12 && in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2568 (info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_36)) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2571 if (max_bpc >= 10 && info->bpc >= 10 && in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2572 (info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_30)) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2588 if (max_bpc >= 16 && info->bpc == 16) { in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2589 if (info->color_formats & DRM_COLOR_FORMAT_YCRCB444) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2595 if (max_bpc >= 12 && info->bpc >= 12) { in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2596 if (info->color_formats & DRM_COLOR_FORMAT_YCRCB422) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2599 if (info->color_formats & DRM_COLOR_FORMAT_YCRCB444) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2605 if (max_bpc >= 10 && info->bpc >= 10) { in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2606 if (info->color_formats & DRM_COLOR_FORMAT_YCRCB422) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2609 if (info->color_formats & DRM_COLOR_FORMAT_YCRCB444) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2615 if (info->color_formats & DRM_COLOR_FORMAT_YCRCB422) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2618 if (info->color_formats & DRM_COLOR_FORMAT_YCRCB444) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2631 * - MEDIA_BUS_FMT_RGB888_1X24
2632 * - MEDIA_BUS_FMT_YUV8_1X24
2633 * - MEDIA_BUS_FMT_UYVY8_1X16
2634 * - MEDIA_BUS_FMT_UYYVYY8_0_5X24
2635 * - MEDIA_BUS_FMT_RGB101010_1X30
2636 * - MEDIA_BUS_FMT_YUV10_1X30
2637 * - MEDIA_BUS_FMT_UYVY10_1X20
2638 * - MEDIA_BUS_FMT_UYYVYY10_0_5X30
2639 * - MEDIA_BUS_FMT_RGB121212_1X36
2640 * - MEDIA_BUS_FMT_YUV12_1X36
2641 * - MEDIA_BUS_FMT_UYVY12_1X24
2642 * - MEDIA_BUS_FMT_UYYVYY12_0_5X36
2643 * - MEDIA_BUS_FMT_RGB161616_1X48
2644 * - MEDIA_BUS_FMT_YUV16_1X48
2645 * - MEDIA_BUS_FMT_UYYVYY16_0_5X48
2758 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_atomic_check() local
2760 hdmi->hdmi_data.enc_out_bus_format = in dw_hdmi_bridge_atomic_check()
2761 bridge_state->output_bus_cfg.format; in dw_hdmi_bridge_atomic_check()
2763 hdmi->hdmi_data.enc_in_bus_format = in dw_hdmi_bridge_atomic_check()
2764 bridge_state->input_bus_cfg.format; in dw_hdmi_bridge_atomic_check()
2766 dev_dbg(hdmi->dev, "input format 0x%04x, output format 0x%04x\n", in dw_hdmi_bridge_atomic_check()
2767 bridge_state->input_bus_cfg.format, in dw_hdmi_bridge_atomic_check()
2768 bridge_state->output_bus_cfg.format); in dw_hdmi_bridge_atomic_check()
2776 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_attach() local
2779 return drm_bridge_attach(bridge->encoder, hdmi->next_bridge, in dw_hdmi_bridge_attach()
2782 return dw_hdmi_connector_create(hdmi); in dw_hdmi_bridge_attach()
2787 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_detach() local
2789 mutex_lock(&hdmi->cec_notifier_mutex); in dw_hdmi_bridge_detach()
2790 cec_notifier_conn_unregister(hdmi->cec_notifier); in dw_hdmi_bridge_detach()
2791 hdmi->cec_notifier = NULL; in dw_hdmi_bridge_detach()
2792 mutex_unlock(&hdmi->cec_notifier_mutex); in dw_hdmi_bridge_detach()
2800 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_mode_valid() local
2801 const struct dw_hdmi_plat_data *pdata = hdmi->plat_data; in dw_hdmi_bridge_mode_valid()
2804 /* We don't support double-clocked modes */ in dw_hdmi_bridge_mode_valid()
2805 if (mode->flags & DRM_MODE_FLAG_DBLCLK) in dw_hdmi_bridge_mode_valid()
2808 if (pdata->mode_valid) in dw_hdmi_bridge_mode_valid()
2809 mode_status = pdata->mode_valid(hdmi, pdata->priv_data, info, in dw_hdmi_bridge_mode_valid()
2819 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_mode_set() local
2821 mutex_lock(&hdmi->mutex); in dw_hdmi_bridge_mode_set()
2824 memcpy(&hdmi->previous_mode, mode, sizeof(hdmi->previous_mode)); in dw_hdmi_bridge_mode_set()
2826 mutex_unlock(&hdmi->mutex); in dw_hdmi_bridge_mode_set()
2832 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_atomic_disable() local
2834 mutex_lock(&hdmi->mutex); in dw_hdmi_bridge_atomic_disable()
2835 hdmi->disabled = true; in dw_hdmi_bridge_atomic_disable()
2836 hdmi->curr_conn = NULL; in dw_hdmi_bridge_atomic_disable()
2837 dw_hdmi_update_power(hdmi); in dw_hdmi_bridge_atomic_disable()
2838 dw_hdmi_update_phy_mask(hdmi); in dw_hdmi_bridge_atomic_disable()
2839 mutex_unlock(&hdmi->mutex); in dw_hdmi_bridge_atomic_disable()
2845 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_atomic_enable() local
2846 struct drm_atomic_state *state = old_state->base.state; in dw_hdmi_bridge_atomic_enable()
2847 struct drm_connector *connector; in dw_hdmi_bridge_atomic_enable() local
2849 connector = drm_atomic_get_new_connector_for_encoder(state, in dw_hdmi_bridge_atomic_enable()
2850 bridge->encoder); in dw_hdmi_bridge_atomic_enable()
2852 mutex_lock(&hdmi->mutex); in dw_hdmi_bridge_atomic_enable()
2853 hdmi->disabled = false; in dw_hdmi_bridge_atomic_enable()
2854 hdmi->curr_conn = connector; in dw_hdmi_bridge_atomic_enable()
2855 dw_hdmi_update_power(hdmi); in dw_hdmi_bridge_atomic_enable()
2856 dw_hdmi_update_phy_mask(hdmi); in dw_hdmi_bridge_atomic_enable()
2857 mutex_unlock(&hdmi->mutex); in dw_hdmi_bridge_atomic_enable()
2862 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_detect() local
2864 return dw_hdmi_detect(hdmi); in dw_hdmi_bridge_detect()
2868 struct drm_connector *connector) in dw_hdmi_bridge_get_edid() argument
2870 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_get_edid() local
2872 return dw_hdmi_get_edid(hdmi, connector); in dw_hdmi_bridge_get_edid()
2892 /* -----------------------------------------------------------------------------
2896 static irqreturn_t dw_hdmi_i2c_irq(struct dw_hdmi *hdmi) in dw_hdmi_i2c_irq() argument
2898 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_irq()
2901 stat = hdmi_readb(hdmi, HDMI_IH_I2CM_STAT0); in dw_hdmi_i2c_irq()
2905 hdmi_writeb(hdmi, stat, HDMI_IH_I2CM_STAT0); in dw_hdmi_i2c_irq()
2907 i2c->stat = stat; in dw_hdmi_i2c_irq()
2909 complete(&i2c->cmp); in dw_hdmi_i2c_irq()
2916 struct dw_hdmi *hdmi = dev_id; in dw_hdmi_hardirq() local
2920 if (hdmi->i2c) in dw_hdmi_hardirq()
2921 ret = dw_hdmi_i2c_irq(hdmi); in dw_hdmi_hardirq()
2923 intr_stat = hdmi_readb(hdmi, HDMI_IH_PHY_STAT0); in dw_hdmi_hardirq()
2925 hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0); in dw_hdmi_hardirq()
2932 void dw_hdmi_setup_rx_sense(struct dw_hdmi *hdmi, bool hpd, bool rx_sense) in dw_hdmi_setup_rx_sense() argument
2934 mutex_lock(&hdmi->mutex); in dw_hdmi_setup_rx_sense()
2936 if (!hdmi->force) { in dw_hdmi_setup_rx_sense()
2942 hdmi->rxsense = false; in dw_hdmi_setup_rx_sense()
2951 hdmi->rxsense = true; in dw_hdmi_setup_rx_sense()
2953 dw_hdmi_update_power(hdmi); in dw_hdmi_setup_rx_sense()
2954 dw_hdmi_update_phy_mask(hdmi); in dw_hdmi_setup_rx_sense()
2956 mutex_unlock(&hdmi->mutex); in dw_hdmi_setup_rx_sense()
2962 struct dw_hdmi *hdmi = dev_id; in dw_hdmi_irq() local
2965 intr_stat = hdmi_readb(hdmi, HDMI_IH_PHY_STAT0); in dw_hdmi_irq()
2966 phy_int_pol = hdmi_readb(hdmi, HDMI_PHY_POL0); in dw_hdmi_irq()
2967 phy_stat = hdmi_readb(hdmi, HDMI_PHY_STAT0); in dw_hdmi_irq()
2982 hdmi_modb(hdmi, ~phy_int_pol, phy_pol_mask, HDMI_PHY_POL0); in dw_hdmi_irq()
2986 * load - in other words, there's something listening on the in dw_hdmi_irq()
2989 * ask the source to re-read the EDID. in dw_hdmi_irq()
2993 dw_hdmi_setup_rx_sense(hdmi, in dw_hdmi_irq()
2998 mutex_lock(&hdmi->cec_notifier_mutex); in dw_hdmi_irq()
2999 cec_notifier_phys_addr_invalidate(hdmi->cec_notifier); in dw_hdmi_irq()
3000 mutex_unlock(&hdmi->cec_notifier_mutex); in dw_hdmi_irq()
3009 dev_dbg(hdmi->dev, "EVENT=%s\n", in dw_hdmi_irq()
3013 if (hdmi->bridge.dev) { in dw_hdmi_irq()
3014 drm_helper_hpd_irq_event(hdmi->bridge.dev); in dw_hdmi_irq()
3015 drm_bridge_hpd_notify(&hdmi->bridge, status); in dw_hdmi_irq()
3019 hdmi_writeb(hdmi, intr_stat, HDMI_IH_PHY_STAT0); in dw_hdmi_irq()
3020 hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE), in dw_hdmi_irq()
3029 .name = "DWC HDMI TX PHY",
3045 .name = "DWC HDMI 3D TX PHY + HEAC PHY",
3050 .name = "DWC HDMI 3D TX PHY",
3055 .name = "DWC HDMI 2.0 TX PHY",
3065 static int dw_hdmi_detect_phy(struct dw_hdmi *hdmi) in dw_hdmi_detect_phy() argument
3070 phy_type = hdmi->plat_data->phy_force_vendor ? in dw_hdmi_detect_phy()
3072 hdmi_readb(hdmi, HDMI_CONFIG2_ID); in dw_hdmi_detect_phy()
3076 if (!hdmi->plat_data->phy_ops || !hdmi->plat_data->phy_name) { in dw_hdmi_detect_phy()
3077 dev_err(hdmi->dev, in dw_hdmi_detect_phy()
3078 "Vendor HDMI PHY not supported by glue layer\n"); in dw_hdmi_detect_phy()
3079 return -ENODEV; in dw_hdmi_detect_phy()
3082 hdmi->phy.ops = hdmi->plat_data->phy_ops; in dw_hdmi_detect_phy()
3083 hdmi->phy.data = hdmi->plat_data->phy_data; in dw_hdmi_detect_phy()
3084 hdmi->phy.name = hdmi->plat_data->phy_name; in dw_hdmi_detect_phy()
3091 hdmi->phy.ops = &dw_hdmi_synopsys_phy_ops; in dw_hdmi_detect_phy()
3092 hdmi->phy.name = dw_hdmi_phys[i].name; in dw_hdmi_detect_phy()
3093 hdmi->phy.data = (void *)&dw_hdmi_phys[i]; in dw_hdmi_detect_phy()
3096 !hdmi->plat_data->configure_phy) { in dw_hdmi_detect_phy()
3097 dev_err(hdmi->dev, "%s requires platform support\n", in dw_hdmi_detect_phy()
3098 hdmi->phy.name); in dw_hdmi_detect_phy()
3099 return -ENODEV; in dw_hdmi_detect_phy()
3106 dev_err(hdmi->dev, "Unsupported HDMI PHY type (%02x)\n", phy_type); in dw_hdmi_detect_phy()
3107 return -ENODEV; in dw_hdmi_detect_phy()
3110 static void dw_hdmi_cec_enable(struct dw_hdmi *hdmi) in dw_hdmi_cec_enable() argument
3112 mutex_lock(&hdmi->mutex); in dw_hdmi_cec_enable()
3113 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_CECCLK_DISABLE; in dw_hdmi_cec_enable()
3114 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_cec_enable()
3115 mutex_unlock(&hdmi->mutex); in dw_hdmi_cec_enable()
3118 static void dw_hdmi_cec_disable(struct dw_hdmi *hdmi) in dw_hdmi_cec_disable() argument
3120 mutex_lock(&hdmi->mutex); in dw_hdmi_cec_disable()
3121 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_CECCLK_DISABLE; in dw_hdmi_cec_disable()
3122 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_cec_disable()
3123 mutex_unlock(&hdmi->mutex); in dw_hdmi_cec_disable()
3147 static void dw_hdmi_init_hw(struct dw_hdmi *hdmi) in dw_hdmi_init_hw() argument
3149 initialize_hdmi_ih_mutes(hdmi); in dw_hdmi_init_hw()
3152 * Reset HDMI DDC I2C master controller and mute I2CM interrupts. in dw_hdmi_init_hw()
3156 dw_hdmi_i2c_init(hdmi); in dw_hdmi_init_hw()
3158 if (hdmi->phy.ops->setup_hpd) in dw_hdmi_init_hw()
3159 hdmi->phy.ops->setup_hpd(hdmi, hdmi->phy.data); in dw_hdmi_init_hw()
3162 /* -----------------------------------------------------------------------------
3166 static int dw_hdmi_parse_dt(struct dw_hdmi *hdmi) in dw_hdmi_parse_dt() argument
3171 if (!hdmi->plat_data->output_port) in dw_hdmi_parse_dt()
3174 endpoint = of_graph_get_endpoint_by_regs(hdmi->dev->of_node, in dw_hdmi_parse_dt()
3175 hdmi->plat_data->output_port, in dw_hdmi_parse_dt()
3176 -1); in dw_hdmi_parse_dt()
3180 * mandatory (such as Rockchip) the plat_data->output_port in dw_hdmi_parse_dt()
3183 dev_err(hdmi->dev, "Missing endpoint in port@%u\n", in dw_hdmi_parse_dt()
3184 hdmi->plat_data->output_port); in dw_hdmi_parse_dt()
3185 return -ENODEV; in dw_hdmi_parse_dt()
3191 dev_err(hdmi->dev, "Endpoint in port@%u unconnected\n", in dw_hdmi_parse_dt()
3192 hdmi->plat_data->output_port); in dw_hdmi_parse_dt()
3193 return -ENODEV; in dw_hdmi_parse_dt()
3197 dev_err(hdmi->dev, "port@%u remote device is disabled\n", in dw_hdmi_parse_dt()
3198 hdmi->plat_data->output_port); in dw_hdmi_parse_dt()
3200 return -ENODEV; in dw_hdmi_parse_dt()
3203 hdmi->next_bridge = of_drm_find_bridge(remote); in dw_hdmi_parse_dt()
3205 if (!hdmi->next_bridge) in dw_hdmi_parse_dt()
3206 return -EPROBE_DEFER; in dw_hdmi_parse_dt()
3214 struct device *dev = &pdev->dev; in dw_hdmi_probe()
3215 struct device_node *np = dev->of_node; in dw_hdmi_probe()
3219 struct dw_hdmi *hdmi; in dw_hdmi_probe() local
3229 hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); in dw_hdmi_probe()
3230 if (!hdmi) in dw_hdmi_probe()
3231 return ERR_PTR(-ENOMEM); in dw_hdmi_probe()
3233 hdmi->plat_data = plat_data; in dw_hdmi_probe()
3234 hdmi->dev = dev; in dw_hdmi_probe()
3235 hdmi->sample_rate = 48000; in dw_hdmi_probe()
3236 hdmi->disabled = true; in dw_hdmi_probe()
3237 hdmi->rxsense = true; in dw_hdmi_probe()
3238 hdmi->phy_mask = (u8)~(HDMI_PHY_HPD | HDMI_PHY_RX_SENSE); in dw_hdmi_probe()
3239 hdmi->mc_clkdis = 0x7f; in dw_hdmi_probe()
3240 hdmi->last_connector_result = connector_status_disconnected; in dw_hdmi_probe()
3242 mutex_init(&hdmi->mutex); in dw_hdmi_probe()
3243 mutex_init(&hdmi->audio_mutex); in dw_hdmi_probe()
3244 mutex_init(&hdmi->cec_notifier_mutex); in dw_hdmi_probe()
3245 spin_lock_init(&hdmi->audio_lock); in dw_hdmi_probe()
3247 ret = dw_hdmi_parse_dt(hdmi); in dw_hdmi_probe()
3251 ddc_node = of_parse_phandle(np, "ddc-i2c-bus", 0); in dw_hdmi_probe()
3253 hdmi->ddc = of_get_i2c_adapter_by_node(ddc_node); in dw_hdmi_probe()
3255 if (!hdmi->ddc) { in dw_hdmi_probe()
3256 dev_dbg(hdmi->dev, "failed to read ddc node\n"); in dw_hdmi_probe()
3257 return ERR_PTR(-EPROBE_DEFER); in dw_hdmi_probe()
3261 dev_dbg(hdmi->dev, "no ddc property found\n"); in dw_hdmi_probe()
3264 if (!plat_data->regm) { in dw_hdmi_probe()
3267 of_property_read_u32(np, "reg-io-width", &val); in dw_hdmi_probe()
3271 hdmi->reg_shift = 2; in dw_hdmi_probe()
3277 dev_err(dev, "reg-io-width must be 1 or 4\n"); in dw_hdmi_probe()
3278 return ERR_PTR(-EINVAL); in dw_hdmi_probe()
3282 hdmi->regs = devm_ioremap_resource(dev, iores); in dw_hdmi_probe()
3283 if (IS_ERR(hdmi->regs)) { in dw_hdmi_probe()
3284 ret = PTR_ERR(hdmi->regs); in dw_hdmi_probe()
3288 hdmi->regm = devm_regmap_init_mmio(dev, hdmi->regs, reg_config); in dw_hdmi_probe()
3289 if (IS_ERR(hdmi->regm)) { in dw_hdmi_probe()
3291 ret = PTR_ERR(hdmi->regm); in dw_hdmi_probe()
3295 hdmi->regm = plat_data->regm; in dw_hdmi_probe()
3298 hdmi->isfr_clk = devm_clk_get(hdmi->dev, "isfr"); in dw_hdmi_probe()
3299 if (IS_ERR(hdmi->isfr_clk)) { in dw_hdmi_probe()
3300 ret = PTR_ERR(hdmi->isfr_clk); in dw_hdmi_probe()
3301 dev_err(hdmi->dev, "Unable to get HDMI isfr clk: %d\n", ret); in dw_hdmi_probe()
3305 ret = clk_prepare_enable(hdmi->isfr_clk); in dw_hdmi_probe()
3307 dev_err(hdmi->dev, "Cannot enable HDMI isfr clock: %d\n", ret); in dw_hdmi_probe()
3311 hdmi->iahb_clk = devm_clk_get(hdmi->dev, "iahb"); in dw_hdmi_probe()
3312 if (IS_ERR(hdmi->iahb_clk)) { in dw_hdmi_probe()
3313 ret = PTR_ERR(hdmi->iahb_clk); in dw_hdmi_probe()
3314 dev_err(hdmi->dev, "Unable to get HDMI iahb clk: %d\n", ret); in dw_hdmi_probe()
3318 ret = clk_prepare_enable(hdmi->iahb_clk); in dw_hdmi_probe()
3320 dev_err(hdmi->dev, "Cannot enable HDMI iahb clock: %d\n", ret); in dw_hdmi_probe()
3324 hdmi->cec_clk = devm_clk_get(hdmi->dev, "cec"); in dw_hdmi_probe()
3325 if (PTR_ERR(hdmi->cec_clk) == -ENOENT) { in dw_hdmi_probe()
3326 hdmi->cec_clk = NULL; in dw_hdmi_probe()
3327 } else if (IS_ERR(hdmi->cec_clk)) { in dw_hdmi_probe()
3328 ret = PTR_ERR(hdmi->cec_clk); in dw_hdmi_probe()
3329 if (ret != -EPROBE_DEFER) in dw_hdmi_probe()
3330 dev_err(hdmi->dev, "Cannot get HDMI cec clock: %d\n", in dw_hdmi_probe()
3333 hdmi->cec_clk = NULL; in dw_hdmi_probe()
3336 ret = clk_prepare_enable(hdmi->cec_clk); in dw_hdmi_probe()
3338 dev_err(hdmi->dev, "Cannot enable HDMI cec clock: %d\n", in dw_hdmi_probe()
3345 hdmi->version = (hdmi_readb(hdmi, HDMI_DESIGN_ID) << 8) in dw_hdmi_probe()
3346 | (hdmi_readb(hdmi, HDMI_REVISION_ID) << 0); in dw_hdmi_probe()
3347 prod_id0 = hdmi_readb(hdmi, HDMI_PRODUCT_ID0); in dw_hdmi_probe()
3348 prod_id1 = hdmi_readb(hdmi, HDMI_PRODUCT_ID1); in dw_hdmi_probe()
3352 dev_err(dev, "Unsupported HDMI controller (%04x:%02x:%02x)\n", in dw_hdmi_probe()
3353 hdmi->version, prod_id0, prod_id1); in dw_hdmi_probe()
3354 ret = -ENODEV; in dw_hdmi_probe()
3358 ret = dw_hdmi_detect_phy(hdmi); in dw_hdmi_probe()
3362 dev_info(dev, "Detected HDMI TX controller v%x.%03x %s HDCP (%s)\n", in dw_hdmi_probe()
3363 hdmi->version >> 12, hdmi->version & 0xfff, in dw_hdmi_probe()
3365 hdmi->phy.name); in dw_hdmi_probe()
3367 dw_hdmi_init_hw(hdmi); in dw_hdmi_probe()
3377 dev_name(dev), hdmi); in dw_hdmi_probe()
3385 hdmi_init_clk_regenerator(hdmi); in dw_hdmi_probe()
3387 /* If DDC bus is not specified, try to register HDMI I2C bus */ in dw_hdmi_probe()
3388 if (!hdmi->ddc) { in dw_hdmi_probe()
3390 hdmi->pinctrl = devm_pinctrl_get(dev); in dw_hdmi_probe()
3391 if (!IS_ERR(hdmi->pinctrl)) { in dw_hdmi_probe()
3392 hdmi->unwedge_state = in dw_hdmi_probe()
3393 pinctrl_lookup_state(hdmi->pinctrl, "unwedge"); in dw_hdmi_probe()
3394 hdmi->default_state = in dw_hdmi_probe()
3395 pinctrl_lookup_state(hdmi->pinctrl, "default"); in dw_hdmi_probe()
3397 if (IS_ERR(hdmi->default_state) || in dw_hdmi_probe()
3398 IS_ERR(hdmi->unwedge_state)) { in dw_hdmi_probe()
3399 if (!IS_ERR(hdmi->unwedge_state)) in dw_hdmi_probe()
3402 hdmi->default_state = NULL; in dw_hdmi_probe()
3403 hdmi->unwedge_state = NULL; in dw_hdmi_probe()
3407 hdmi->ddc = dw_hdmi_i2c_adapter(hdmi); in dw_hdmi_probe()
3408 if (IS_ERR(hdmi->ddc)) in dw_hdmi_probe()
3409 hdmi->ddc = NULL; in dw_hdmi_probe()
3412 hdmi->bridge.driver_private = hdmi; in dw_hdmi_probe()
3413 hdmi->bridge.funcs = &dw_hdmi_bridge_funcs; in dw_hdmi_probe()
3414 hdmi->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID in dw_hdmi_probe()
3417 hdmi->bridge.of_node = pdev->dev.of_node; in dw_hdmi_probe()
3424 config0 = hdmi_readb(hdmi, HDMI_CONFIG0_ID); in dw_hdmi_probe()
3425 config3 = hdmi_readb(hdmi, HDMI_CONFIG3_ID); in dw_hdmi_probe()
3430 audio.phys = iores->start; in dw_hdmi_probe()
3431 audio.base = hdmi->regs; in dw_hdmi_probe()
3433 audio.hdmi = hdmi; in dw_hdmi_probe()
3434 audio.eld = hdmi->connector.eld; in dw_hdmi_probe()
3435 hdmi->enable_audio = dw_hdmi_ahb_audio_enable; in dw_hdmi_probe()
3436 hdmi->disable_audio = dw_hdmi_ahb_audio_disable; in dw_hdmi_probe()
3438 pdevinfo.name = "dw-hdmi-ahb-audio"; in dw_hdmi_probe()
3442 hdmi->audio = platform_device_register_full(&pdevinfo); in dw_hdmi_probe()
3446 audio.hdmi = hdmi; in dw_hdmi_probe()
3447 audio.eld = hdmi->connector.eld; in dw_hdmi_probe()
3450 hdmi->enable_audio = dw_hdmi_i2s_audio_enable; in dw_hdmi_probe()
3451 hdmi->disable_audio = dw_hdmi_i2s_audio_disable; in dw_hdmi_probe()
3453 pdevinfo.name = "dw-hdmi-i2s-audio"; in dw_hdmi_probe()
3457 hdmi->audio = platform_device_register_full(&pdevinfo); in dw_hdmi_probe()
3460 if (!plat_data->disable_cec && (config0 & HDMI_CONFIG0_CEC)) { in dw_hdmi_probe()
3461 cec.hdmi = hdmi; in dw_hdmi_probe()
3465 pdevinfo.name = "dw-hdmi-cec"; in dw_hdmi_probe()
3470 hdmi->cec = platform_device_register_full(&pdevinfo); in dw_hdmi_probe()
3473 drm_bridge_add(&hdmi->bridge); in dw_hdmi_probe()
3475 return hdmi; in dw_hdmi_probe()
3478 clk_disable_unprepare(hdmi->iahb_clk); in dw_hdmi_probe()
3479 clk_disable_unprepare(hdmi->cec_clk); in dw_hdmi_probe()
3481 clk_disable_unprepare(hdmi->isfr_clk); in dw_hdmi_probe()
3483 i2c_put_adapter(hdmi->ddc); in dw_hdmi_probe()
3489 void dw_hdmi_remove(struct dw_hdmi *hdmi) in dw_hdmi_remove() argument
3491 drm_bridge_remove(&hdmi->bridge); in dw_hdmi_remove()
3493 if (hdmi->audio && !IS_ERR(hdmi->audio)) in dw_hdmi_remove()
3494 platform_device_unregister(hdmi->audio); in dw_hdmi_remove()
3495 if (!IS_ERR(hdmi->cec)) in dw_hdmi_remove()
3496 platform_device_unregister(hdmi->cec); in dw_hdmi_remove()
3499 hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0); in dw_hdmi_remove()
3501 clk_disable_unprepare(hdmi->iahb_clk); in dw_hdmi_remove()
3502 clk_disable_unprepare(hdmi->isfr_clk); in dw_hdmi_remove()
3503 clk_disable_unprepare(hdmi->cec_clk); in dw_hdmi_remove()
3505 if (hdmi->i2c) in dw_hdmi_remove()
3506 i2c_del_adapter(&hdmi->i2c->adap); in dw_hdmi_remove()
3508 i2c_put_adapter(hdmi->ddc); in dw_hdmi_remove()
3512 /* -----------------------------------------------------------------------------
3519 struct dw_hdmi *hdmi; in dw_hdmi_bind() local
3522 hdmi = dw_hdmi_probe(pdev, plat_data); in dw_hdmi_bind()
3523 if (IS_ERR(hdmi)) in dw_hdmi_bind()
3524 return hdmi; in dw_hdmi_bind()
3526 ret = drm_bridge_attach(encoder, &hdmi->bridge, NULL, 0); in dw_hdmi_bind()
3528 dw_hdmi_remove(hdmi); in dw_hdmi_bind()
3532 return hdmi; in dw_hdmi_bind()
3536 void dw_hdmi_unbind(struct dw_hdmi *hdmi) in dw_hdmi_unbind() argument
3538 dw_hdmi_remove(hdmi); in dw_hdmi_unbind()
3542 void dw_hdmi_resume(struct dw_hdmi *hdmi) in dw_hdmi_resume() argument
3544 dw_hdmi_init_hw(hdmi); in dw_hdmi_resume()
3549 MODULE_AUTHOR("Andy Yan <andy.yan@rock-chips.com>");
3550 MODULE_AUTHOR("Yakir Yang <ykk@rock-chips.com>");
3552 MODULE_DESCRIPTION("DW HDMI transmitter driver");
3554 MODULE_ALIAS("platform:dw-hdmi");