Lines Matching full:hdmi
47 static int sun4i_hdmi_setup_avi_infoframes(struct sun4i_hdmi *hdmi, in sun4i_hdmi_setup_avi_infoframes() argument
55 &hdmi->connector, mode); in sun4i_hdmi_setup_avi_infoframes()
68 writeb(buffer[i], hdmi->base + SUN4I_HDMI_AVI_INFOFRAME_REG(i)); in sun4i_hdmi_setup_avi_infoframes()
88 struct sun4i_hdmi *hdmi = drm_encoder_to_sun4i_hdmi(encoder); in sun4i_hdmi_disable() local
91 DRM_DEBUG_DRIVER("Disabling the HDMI Output\n"); in sun4i_hdmi_disable()
93 val = readl(hdmi->base + SUN4I_HDMI_VID_CTRL_REG); in sun4i_hdmi_disable()
95 writel(val, hdmi->base + SUN4I_HDMI_VID_CTRL_REG); in sun4i_hdmi_disable()
97 clk_disable_unprepare(hdmi->tmds_clk); in sun4i_hdmi_disable()
104 struct sun4i_hdmi *hdmi = drm_encoder_to_sun4i_hdmi(encoder); in sun4i_hdmi_enable() local
105 struct drm_display_info *display = &hdmi->connector.display_info; in sun4i_hdmi_enable()
109 DRM_DEBUG_DRIVER("Enabling the HDMI Output\n"); in sun4i_hdmi_enable()
111 clk_set_rate(hdmi->mod_clk, mode->crtc_clock * 1000); in sun4i_hdmi_enable()
112 clk_set_rate(hdmi->tmds_clk, mode->crtc_clock * 1000); in sun4i_hdmi_enable()
116 hdmi->base + SUN4I_HDMI_UNKNOWN_REG); in sun4i_hdmi_enable()
128 val = readl(hdmi->base + SUN4I_HDMI_PAD_CTRL1_REG); in sun4i_hdmi_enable()
130 val |= hdmi->variant->pad_ctrl1_init_val; in sun4i_hdmi_enable()
131 writel(val, hdmi->base + SUN4I_HDMI_PAD_CTRL1_REG); in sun4i_hdmi_enable()
132 val = readl(hdmi->base + SUN4I_HDMI_PAD_CTRL1_REG); in sun4i_hdmi_enable()
137 hdmi->base + SUN4I_HDMI_VID_TIMING_ACT_REG); in sun4i_hdmi_enable()
142 hdmi->base + SUN4I_HDMI_VID_TIMING_BP_REG); in sun4i_hdmi_enable()
147 hdmi->base + SUN4I_HDMI_VID_TIMING_FP_REG); in sun4i_hdmi_enable()
152 hdmi->base + SUN4I_HDMI_VID_TIMING_SPW_REG); in sun4i_hdmi_enable()
161 writel(val, hdmi->base + SUN4I_HDMI_VID_TIMING_POL_REG); in sun4i_hdmi_enable()
163 clk_prepare_enable(hdmi->tmds_clk); in sun4i_hdmi_enable()
165 sun4i_hdmi_setup_avi_infoframes(hdmi, mode); in sun4i_hdmi_enable()
168 writel(val, hdmi->base + SUN4I_HDMI_PKT_CTRL_REG(0)); in sun4i_hdmi_enable()
174 writel(val, hdmi->base + SUN4I_HDMI_VID_CTRL_REG); in sun4i_hdmi_enable()
180 struct sun4i_hdmi *hdmi = drm_encoder_to_sun4i_hdmi(encoder); in sun4i_hdmi_mode_valid() local
182 unsigned long diff = rate / 200; /* +-0.5% allowed by HDMI spec */ in sun4i_hdmi_mode_valid()
185 /* 165 MHz is the typical max pixelclock frequency for HDMI <= 1.2 */ in sun4i_hdmi_mode_valid()
188 rounded_rate = clk_round_rate(hdmi->tmds_clk, rate); in sun4i_hdmi_mode_valid()
205 struct sun4i_hdmi *hdmi = drm_connector_to_sun4i_hdmi(connector); in sun4i_hdmi_get_modes() local
209 edid = drm_get_edid(connector, hdmi->ddc_i2c ?: hdmi->i2c); in sun4i_hdmi_get_modes()
214 connector->display_info.is_hdmi ? "an HDMI" : "a DVI"); in sun4i_hdmi_get_modes()
217 cec_s_phys_addr_from_edid(hdmi->cec_adap, edid); in sun4i_hdmi_get_modes()
253 struct sun4i_hdmi *hdmi = drm_connector_to_sun4i_hdmi(connector); in sun4i_hdmi_connector_detect() local
256 reg = readl(hdmi->base + SUN4I_HDMI_HPD_REG); in sun4i_hdmi_connector_detect()
258 cec_phys_addr_invalidate(hdmi->cec_adap); in sun4i_hdmi_connector_detect()
277 struct sun4i_hdmi *hdmi = cec_get_drvdata(adap); in sun4i_hdmi_cec_pin_read() local
279 return readl(hdmi->base + SUN4I_HDMI_CEC) & SUN4I_HDMI_CEC_RX; in sun4i_hdmi_cec_pin_read()
284 struct sun4i_hdmi *hdmi = cec_get_drvdata(adap); in sun4i_hdmi_cec_pin_low() local
287 writel(SUN4I_HDMI_CEC_ENABLE, hdmi->base + SUN4I_HDMI_CEC); in sun4i_hdmi_cec_pin_low()
292 struct sun4i_hdmi *hdmi = cec_get_drvdata(adap); in sun4i_hdmi_cec_pin_high() local
298 writel(0, hdmi->base + SUN4I_HDMI_CEC); in sun4i_hdmi_cec_pin_high()
485 struct sun4i_hdmi *hdmi; in sun4i_hdmi_bind() local
489 hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); in sun4i_hdmi_bind()
490 if (!hdmi) in sun4i_hdmi_bind()
492 dev_set_drvdata(dev, hdmi); in sun4i_hdmi_bind()
493 hdmi->dev = dev; in sun4i_hdmi_bind()
494 hdmi->drv = drv; in sun4i_hdmi_bind()
496 hdmi->variant = of_device_get_match_data(dev); in sun4i_hdmi_bind()
497 if (!hdmi->variant) in sun4i_hdmi_bind()
500 hdmi->base = devm_platform_ioremap_resource(pdev, 0); in sun4i_hdmi_bind()
501 if (IS_ERR(hdmi->base)) { in sun4i_hdmi_bind()
502 dev_err(dev, "Couldn't map the HDMI encoder registers\n"); in sun4i_hdmi_bind()
503 return PTR_ERR(hdmi->base); in sun4i_hdmi_bind()
506 if (hdmi->variant->has_reset_control) { in sun4i_hdmi_bind()
507 hdmi->reset = devm_reset_control_get(dev, NULL); in sun4i_hdmi_bind()
508 if (IS_ERR(hdmi->reset)) { in sun4i_hdmi_bind()
509 dev_err(dev, "Couldn't get the HDMI reset control\n"); in sun4i_hdmi_bind()
510 return PTR_ERR(hdmi->reset); in sun4i_hdmi_bind()
513 ret = reset_control_deassert(hdmi->reset); in sun4i_hdmi_bind()
515 dev_err(dev, "Couldn't deassert HDMI reset\n"); in sun4i_hdmi_bind()
520 hdmi->bus_clk = devm_clk_get(dev, "ahb"); in sun4i_hdmi_bind()
521 if (IS_ERR(hdmi->bus_clk)) { in sun4i_hdmi_bind()
522 dev_err(dev, "Couldn't get the HDMI bus clock\n"); in sun4i_hdmi_bind()
523 ret = PTR_ERR(hdmi->bus_clk); in sun4i_hdmi_bind()
526 clk_prepare_enable(hdmi->bus_clk); in sun4i_hdmi_bind()
528 hdmi->mod_clk = devm_clk_get(dev, "mod"); in sun4i_hdmi_bind()
529 if (IS_ERR(hdmi->mod_clk)) { in sun4i_hdmi_bind()
530 dev_err(dev, "Couldn't get the HDMI mod clock\n"); in sun4i_hdmi_bind()
531 ret = PTR_ERR(hdmi->mod_clk); in sun4i_hdmi_bind()
534 clk_prepare_enable(hdmi->mod_clk); in sun4i_hdmi_bind()
536 hdmi->pll0_clk = devm_clk_get(dev, "pll-0"); in sun4i_hdmi_bind()
537 if (IS_ERR(hdmi->pll0_clk)) { in sun4i_hdmi_bind()
538 dev_err(dev, "Couldn't get the HDMI PLL 0 clock\n"); in sun4i_hdmi_bind()
539 ret = PTR_ERR(hdmi->pll0_clk); in sun4i_hdmi_bind()
543 hdmi->pll1_clk = devm_clk_get(dev, "pll-1"); in sun4i_hdmi_bind()
544 if (IS_ERR(hdmi->pll1_clk)) { in sun4i_hdmi_bind()
545 dev_err(dev, "Couldn't get the HDMI PLL 1 clock\n"); in sun4i_hdmi_bind()
546 ret = PTR_ERR(hdmi->pll1_clk); in sun4i_hdmi_bind()
550 hdmi->regmap = devm_regmap_init_mmio(dev, hdmi->base, in sun4i_hdmi_bind()
552 if (IS_ERR(hdmi->regmap)) { in sun4i_hdmi_bind()
553 dev_err(dev, "Couldn't create HDMI encoder regmap\n"); in sun4i_hdmi_bind()
554 ret = PTR_ERR(hdmi->regmap); in sun4i_hdmi_bind()
558 ret = sun4i_tmds_create(hdmi); in sun4i_hdmi_bind()
564 if (hdmi->variant->has_ddc_parent_clk) { in sun4i_hdmi_bind()
565 hdmi->ddc_parent_clk = devm_clk_get(dev, "ddc"); in sun4i_hdmi_bind()
566 if (IS_ERR(hdmi->ddc_parent_clk)) { in sun4i_hdmi_bind()
567 dev_err(dev, "Couldn't get the HDMI DDC clock\n"); in sun4i_hdmi_bind()
568 ret = PTR_ERR(hdmi->ddc_parent_clk); in sun4i_hdmi_bind()
572 hdmi->ddc_parent_clk = hdmi->tmds_clk; in sun4i_hdmi_bind()
575 writel(SUN4I_HDMI_CTRL_ENABLE, hdmi->base + SUN4I_HDMI_CTRL_REG); in sun4i_hdmi_bind()
577 writel(hdmi->variant->pad_ctrl0_init_val, in sun4i_hdmi_bind()
578 hdmi->base + SUN4I_HDMI_PAD_CTRL0_REG); in sun4i_hdmi_bind()
580 reg = readl(hdmi->base + SUN4I_HDMI_PLL_CTRL_REG); in sun4i_hdmi_bind()
582 reg |= hdmi->variant->pll_ctrl_init_val; in sun4i_hdmi_bind()
583 writel(reg, hdmi->base + SUN4I_HDMI_PLL_CTRL_REG); in sun4i_hdmi_bind()
585 ret = sun4i_hdmi_i2c_create(dev, hdmi); in sun4i_hdmi_bind()
587 dev_err(dev, "Couldn't create the HDMI I2C adapter\n"); in sun4i_hdmi_bind()
591 hdmi->ddc_i2c = sun4i_hdmi_get_ddc(dev); in sun4i_hdmi_bind()
592 if (IS_ERR(hdmi->ddc_i2c)) { in sun4i_hdmi_bind()
593 ret = PTR_ERR(hdmi->ddc_i2c); in sun4i_hdmi_bind()
595 hdmi->ddc_i2c = NULL; in sun4i_hdmi_bind()
600 drm_encoder_helper_add(&hdmi->encoder, in sun4i_hdmi_bind()
602 ret = drm_simple_encoder_init(drm, &hdmi->encoder, in sun4i_hdmi_bind()
605 dev_err(dev, "Couldn't initialise the HDMI encoder\n"); in sun4i_hdmi_bind()
609 hdmi->encoder.possible_crtcs = drm_of_find_possible_crtcs(drm, in sun4i_hdmi_bind()
611 if (!hdmi->encoder.possible_crtcs) { in sun4i_hdmi_bind()
617 hdmi->cec_adap = cec_pin_allocate_adapter(&sun4i_hdmi_cec_pin_ops, in sun4i_hdmi_bind()
618 hdmi, "sun4i", CEC_CAP_DEFAULTS | CEC_CAP_CONNECTOR_INFO); in sun4i_hdmi_bind()
619 ret = PTR_ERR_OR_ZERO(hdmi->cec_adap); in sun4i_hdmi_bind()
622 writel(readl(hdmi->base + SUN4I_HDMI_CEC) & ~SUN4I_HDMI_CEC_TX, in sun4i_hdmi_bind()
623 hdmi->base + SUN4I_HDMI_CEC); in sun4i_hdmi_bind()
626 drm_connector_helper_add(&hdmi->connector, in sun4i_hdmi_bind()
628 ret = drm_connector_init_with_ddc(drm, &hdmi->connector, in sun4i_hdmi_bind()
631 hdmi->ddc_i2c); in sun4i_hdmi_bind()
634 "Couldn't initialise the HDMI connector\n"); in sun4i_hdmi_bind()
637 cec_fill_conn_info_from_drm(&conn_info, &hdmi->connector); in sun4i_hdmi_bind()
638 cec_s_conn_info(hdmi->cec_adap, &conn_info); in sun4i_hdmi_bind()
641 hdmi->connector.polled = DRM_CONNECTOR_POLL_CONNECT | in sun4i_hdmi_bind()
644 ret = cec_register_adapter(hdmi->cec_adap, dev); in sun4i_hdmi_bind()
647 drm_connector_attach_encoder(&hdmi->connector, &hdmi->encoder); in sun4i_hdmi_bind()
652 cec_delete_adapter(hdmi->cec_adap); in sun4i_hdmi_bind()
653 drm_encoder_cleanup(&hdmi->encoder); in sun4i_hdmi_bind()
655 i2c_put_adapter(hdmi->ddc_i2c); in sun4i_hdmi_bind()
657 i2c_del_adapter(hdmi->i2c); in sun4i_hdmi_bind()
659 clk_disable_unprepare(hdmi->mod_clk); in sun4i_hdmi_bind()
661 clk_disable_unprepare(hdmi->bus_clk); in sun4i_hdmi_bind()
663 reset_control_assert(hdmi->reset); in sun4i_hdmi_bind()
670 struct sun4i_hdmi *hdmi = dev_get_drvdata(dev); in sun4i_hdmi_unbind() local
672 cec_unregister_adapter(hdmi->cec_adap); in sun4i_hdmi_unbind()
673 i2c_del_adapter(hdmi->i2c); in sun4i_hdmi_unbind()
674 i2c_put_adapter(hdmi->ddc_i2c); in sun4i_hdmi_unbind()
675 clk_disable_unprepare(hdmi->mod_clk); in sun4i_hdmi_unbind()
676 clk_disable_unprepare(hdmi->bus_clk); in sun4i_hdmi_unbind()
695 { .compatible = "allwinner,sun4i-a10-hdmi", .data = &sun4i_variant, },
696 { .compatible = "allwinner,sun5i-a10s-hdmi", .data = &sun5i_variant, },
697 { .compatible = "allwinner,sun6i-a31-hdmi", .data = &sun6i_variant, },
706 .name = "sun4i-hdmi",
713 MODULE_DESCRIPTION("Allwinner A10 HDMI Driver");