Lines Matching +full:ddc +full:- +full:i2c

1 // SPDX-License-Identifier: GPL-2.0
4 * Zheng Yang <zhengyang@rock-chips.com>
36 struct mutex i2c_lock; /* For i2c operation. */
51 struct rk3066_hdmi_i2c *i2c; member
52 struct i2c_adapter *ddc; member
74 return readl_relaxed(hdmi->regs + offset); in hdmi_readb()
79 writel_relaxed(val, hdmi->regs + offset); in hdmi_writeb()
95 ddc_bus_freq = (hdmi->tmdsclk >> 2) / HDMI_SCL_RATE; in rk3066_hdmi_i2c_init()
117 DRM_DEV_DEBUG(hdmi->dev, "mode :%d\n", mode); in rk3066_hdmi_set_power_mode()
118 DRM_DEV_DEBUG(hdmi->dev, "current_mode :%d\n", current_mode); in rk3066_hdmi_set_power_mode()
133 DRM_DEV_DEBUG(hdmi->dev, "%d: next_mode :%d\n", i, next_mode); in rk3066_hdmi_set_power_mode()
158 * the DDC clock. in rk3066_hdmi_set_power_mode()
161 hdmi->tmdsclk = DEFAULT_PLLA_RATE; in rk3066_hdmi_set_power_mode()
201 &hdmi->connector, mode); in rk3066_hdmi_config_avi()
203 if (hdmi->hdmi_data.enc_out_format == HDMI_COLORSPACE_YUV444) in rk3066_hdmi_config_avi()
205 else if (hdmi->hdmi_data.enc_out_format == HDMI_COLORSPACE_YUV422) in rk3066_hdmi_config_avi()
210 frame.avi.colorimetry = hdmi->hdmi_data.colorimetry; in rk3066_hdmi_config_avi()
224 value |= mode->flags & DRM_MODE_FLAG_PHSYNC ? in rk3066_hdmi_config_video_timing()
226 value |= mode->flags & DRM_MODE_FLAG_PVSYNC ? in rk3066_hdmi_config_video_timing()
228 value |= mode->flags & DRM_MODE_FLAG_INTERLACE ? in rk3066_hdmi_config_video_timing()
231 if (hdmi->hdmi_data.vic == 2 || hdmi->hdmi_data.vic == 3) in rk3066_hdmi_config_video_timing()
240 value = mode->htotal; in rk3066_hdmi_config_video_timing()
244 value = mode->htotal - mode->hdisplay; in rk3066_hdmi_config_video_timing()
248 value = mode->htotal - mode->hsync_start; in rk3066_hdmi_config_video_timing()
252 value = mode->hsync_end - mode->hsync_start; in rk3066_hdmi_config_video_timing()
256 value = mode->vtotal; in rk3066_hdmi_config_video_timing()
260 value = mode->vtotal - mode->vdisplay; in rk3066_hdmi_config_video_timing()
263 value = mode->vtotal - mode->vsync_start + vsync_offset; in rk3066_hdmi_config_video_timing()
266 value = mode->vsync_end - mode->vsync_start; in rk3066_hdmi_config_video_timing()
289 * The semi-public documentation does not describe the hdmi registers in rk3066_hdmi_config_phy()
293 if (hdmi->tmdsclk > 100000000) { in rk3066_hdmi_config_phy()
303 } else if (hdmi->tmdsclk > 50000000) { in rk3066_hdmi_config_phy()
329 struct drm_display_info *display = &hdmi->connector.display_info; in rk3066_hdmi_setup()
331 hdmi->hdmi_data.vic = drm_match_cea_mode(mode); in rk3066_hdmi_setup()
332 hdmi->hdmi_data.enc_out_format = HDMI_COLORSPACE_RGB; in rk3066_hdmi_setup()
334 if (hdmi->hdmi_data.vic == 6 || hdmi->hdmi_data.vic == 7 || in rk3066_hdmi_setup()
335 hdmi->hdmi_data.vic == 21 || hdmi->hdmi_data.vic == 22 || in rk3066_hdmi_setup()
336 hdmi->hdmi_data.vic == 2 || hdmi->hdmi_data.vic == 3 || in rk3066_hdmi_setup()
337 hdmi->hdmi_data.vic == 17 || hdmi->hdmi_data.vic == 18) in rk3066_hdmi_setup()
338 hdmi->hdmi_data.colorimetry = HDMI_COLORIMETRY_ITU_601; in rk3066_hdmi_setup()
340 hdmi->hdmi_data.colorimetry = HDMI_COLORIMETRY_ITU_709; in rk3066_hdmi_setup()
342 hdmi->tmdsclk = mode->clock * 1000; in rk3066_hdmi_setup()
363 if (display->is_hdmi) { in rk3066_hdmi_setup()
379 * clock rate and reconfigure the DDC clock. in rk3066_hdmi_setup()
397 drm_mode_copy(&hdmi->previous_mode, adj_mode); in rk3066_hdmi_encoder_mode_set()
405 mux = drm_of_encoder_active_endpoint_id(hdmi->dev->of_node, encoder); in rk3066_hdmi_encoder_enable()
411 regmap_write(hdmi->grf_regmap, GRF_SOC_CON0, val); in rk3066_hdmi_encoder_enable()
413 DRM_DEV_DEBUG(hdmi->dev, "hdmi encoder enable select: vop%s\n", in rk3066_hdmi_encoder_enable()
416 rk3066_hdmi_setup(hdmi, &hdmi->previous_mode); in rk3066_hdmi_encoder_enable()
423 DRM_DEV_DEBUG(hdmi->dev, "hdmi encoder disable\n"); in rk3066_hdmi_encoder_disable()
451 s->output_mode = ROCKCHIP_OUT_MODE_P888; in rk3066_hdmi_encoder_atomic_check()
452 s->output_type = DRM_MODE_CONNECTOR_HDMIA; in rk3066_hdmi_encoder_atomic_check()
481 if (!hdmi->ddc) in rk3066_hdmi_connector_get_modes()
484 edid = drm_get_edid(connector, hdmi->ddc); in rk3066_hdmi_connector_get_modes()
511 return &hdmi->encoder.encoder; in rk3066_hdmi_connector_best_encoder()
551 struct drm_encoder *encoder = &hdmi->encoder.encoder; in rk3066_hdmi_register()
552 struct device *dev = hdmi->dev; in rk3066_hdmi_register()
554 encoder->possible_crtcs = in rk3066_hdmi_register()
555 drm_of_find_possible_crtcs(drm, dev->of_node); in rk3066_hdmi_register()
563 if (encoder->possible_crtcs == 0) in rk3066_hdmi_register()
564 return -EPROBE_DEFER; in rk3066_hdmi_register()
569 hdmi->connector.polled = DRM_CONNECTOR_POLL_HPD; in rk3066_hdmi_register()
571 drm_connector_helper_add(&hdmi->connector, in rk3066_hdmi_register()
573 drm_connector_init_with_ddc(drm, &hdmi->connector, in rk3066_hdmi_register()
576 hdmi->ddc); in rk3066_hdmi_register()
578 drm_connector_attach_encoder(&hdmi->connector, encoder); in rk3066_hdmi_register()
597 hdmi->i2c->stat = interrupt; in rk3066_hdmi_hardirq()
598 complete(&hdmi->i2c->cmpltn); in rk3066_hdmi_hardirq()
611 drm_helper_hpd_irq_event(hdmi->connector.dev); in rk3066_hdmi_irq()
618 int length = msgs->len; in rk3066_hdmi_i2c_read()
619 u8 *buf = msgs->buf; in rk3066_hdmi_i2c_read()
622 ret = wait_for_completion_timeout(&hdmi->i2c->cmpltn, HZ / 10); in rk3066_hdmi_i2c_read()
623 if (!ret || hdmi->i2c->stat & HDMI_INTR_EDID_ERR) in rk3066_hdmi_i2c_read()
624 return -EAGAIN; in rk3066_hdmi_i2c_read()
626 while (length--) in rk3066_hdmi_i2c_read()
635 * The DDC module only supports read EDID message, so in rk3066_hdmi_i2c_write()
636 * we assume that each word write to this i2c adapter in rk3066_hdmi_i2c_write()
639 if (msgs->len != 1 || in rk3066_hdmi_i2c_write()
640 (msgs->addr != DDC_ADDR && msgs->addr != DDC_SEGMENT_ADDR)) in rk3066_hdmi_i2c_write()
641 return -EINVAL; in rk3066_hdmi_i2c_write()
643 reinit_completion(&hdmi->i2c->cmpltn); in rk3066_hdmi_i2c_write()
645 if (msgs->addr == DDC_SEGMENT_ADDR) in rk3066_hdmi_i2c_write()
646 hdmi->i2c->segment_addr = msgs->buf[0]; in rk3066_hdmi_i2c_write()
647 if (msgs->addr == DDC_ADDR) in rk3066_hdmi_i2c_write()
648 hdmi->i2c->ddc_addr = msgs->buf[0]; in rk3066_hdmi_i2c_write()
654 hdmi_writeb(hdmi, HDMI_EDID_WORD_ADDR, hdmi->i2c->ddc_addr); in rk3066_hdmi_i2c_write()
657 hdmi_writeb(hdmi, HDMI_EDID_SEGMENT_POINTER, hdmi->i2c->segment_addr); in rk3066_hdmi_i2c_write()
666 struct rk3066_hdmi_i2c *i2c = hdmi->i2c; in rk3066_hdmi_i2c_xfer() local
669 mutex_lock(&i2c->i2c_lock); in rk3066_hdmi_i2c_xfer()
676 i2c->stat = 0; in rk3066_hdmi_i2c_xfer()
679 DRM_DEV_DEBUG(hdmi->dev, in rk3066_hdmi_i2c_xfer()
698 mutex_unlock(&i2c->i2c_lock); in rk3066_hdmi_i2c_xfer()
716 struct rk3066_hdmi_i2c *i2c; in rk3066_hdmi_i2c_adapter() local
719 i2c = devm_kzalloc(hdmi->dev, sizeof(*i2c), GFP_KERNEL); in rk3066_hdmi_i2c_adapter()
720 if (!i2c) in rk3066_hdmi_i2c_adapter()
721 return ERR_PTR(-ENOMEM); in rk3066_hdmi_i2c_adapter()
723 mutex_init(&i2c->i2c_lock); in rk3066_hdmi_i2c_adapter()
724 init_completion(&i2c->cmpltn); in rk3066_hdmi_i2c_adapter()
726 adap = &i2c->adap; in rk3066_hdmi_i2c_adapter()
727 adap->class = I2C_CLASS_DDC; in rk3066_hdmi_i2c_adapter()
728 adap->owner = THIS_MODULE; in rk3066_hdmi_i2c_adapter()
729 adap->dev.parent = hdmi->dev; in rk3066_hdmi_i2c_adapter()
730 adap->dev.of_node = hdmi->dev->of_node; in rk3066_hdmi_i2c_adapter()
731 adap->algo = &rk3066_hdmi_algorithm; in rk3066_hdmi_i2c_adapter()
732 strscpy(adap->name, "RK3066 HDMI", sizeof(adap->name)); in rk3066_hdmi_i2c_adapter()
737 DRM_DEV_ERROR(hdmi->dev, "cannot add %s I2C adapter\n", in rk3066_hdmi_i2c_adapter()
738 adap->name); in rk3066_hdmi_i2c_adapter()
739 devm_kfree(hdmi->dev, i2c); in rk3066_hdmi_i2c_adapter()
743 hdmi->i2c = i2c; in rk3066_hdmi_i2c_adapter()
745 DRM_DEV_DEBUG(hdmi->dev, "registered %s I2C bus driver\n", adap->name); in rk3066_hdmi_i2c_adapter()
761 return -ENOMEM; in rk3066_hdmi_bind()
763 hdmi->dev = dev; in rk3066_hdmi_bind()
764 hdmi->drm_dev = drm; in rk3066_hdmi_bind()
765 hdmi->regs = devm_platform_ioremap_resource(pdev, 0); in rk3066_hdmi_bind()
766 if (IS_ERR(hdmi->regs)) in rk3066_hdmi_bind()
767 return PTR_ERR(hdmi->regs); in rk3066_hdmi_bind()
773 hdmi->hclk = devm_clk_get(dev, "hclk"); in rk3066_hdmi_bind()
774 if (IS_ERR(hdmi->hclk)) { in rk3066_hdmi_bind()
776 return PTR_ERR(hdmi->hclk); in rk3066_hdmi_bind()
779 ret = clk_prepare_enable(hdmi->hclk); in rk3066_hdmi_bind()
785 hdmi->grf_regmap = syscon_regmap_lookup_by_phandle(dev->of_node, in rk3066_hdmi_bind()
787 if (IS_ERR(hdmi->grf_regmap)) { in rk3066_hdmi_bind()
789 ret = PTR_ERR(hdmi->grf_regmap); in rk3066_hdmi_bind()
796 hdmi->ddc = rk3066_hdmi_i2c_adapter(hdmi); in rk3066_hdmi_bind()
797 if (IS_ERR(hdmi->ddc)) { in rk3066_hdmi_bind()
798 ret = PTR_ERR(hdmi->ddc); in rk3066_hdmi_bind()
799 hdmi->ddc = NULL; in rk3066_hdmi_bind()
828 hdmi->connector.funcs->destroy(&hdmi->connector); in rk3066_hdmi_bind()
829 hdmi->encoder.encoder.funcs->destroy(&hdmi->encoder.encoder); in rk3066_hdmi_bind()
831 i2c_put_adapter(hdmi->ddc); in rk3066_hdmi_bind()
833 clk_disable_unprepare(hdmi->hclk); in rk3066_hdmi_bind()
843 hdmi->connector.funcs->destroy(&hdmi->connector); in rk3066_hdmi_unbind()
844 hdmi->encoder.encoder.funcs->destroy(&hdmi->encoder.encoder); in rk3066_hdmi_unbind()
846 i2c_put_adapter(hdmi->ddc); in rk3066_hdmi_unbind()
847 clk_disable_unprepare(hdmi->hclk); in rk3066_hdmi_unbind()
857 return component_add(&pdev->dev, &rk3066_hdmi_ops); in rk3066_hdmi_probe()
862 component_del(&pdev->dev, &rk3066_hdmi_ops); in rk3066_hdmi_remove()
866 { .compatible = "rockchip,rk3066-hdmi" },
875 .name = "rockchip-rk3066-hdmi",