Lines Matching +full:hdmi +full:- +full:connector
1 // SPDX-License-Identifier: GPL-2.0
4 * Zheng Yang <zhengyang@rock-chips.com>
49 struct drm_connector connector; member
67 static struct rk3066_hdmi *connector_to_rk3066_hdmi(struct drm_connector *connector) in connector_to_rk3066_hdmi() argument
69 return container_of(connector, struct rk3066_hdmi, connector); in connector_to_rk3066_hdmi()
72 static inline u8 hdmi_readb(struct rk3066_hdmi *hdmi, u16 offset) in hdmi_readb() argument
74 return readl_relaxed(hdmi->regs + offset); in hdmi_readb()
77 static inline void hdmi_writeb(struct rk3066_hdmi *hdmi, u16 offset, u32 val) in hdmi_writeb() argument
79 writel_relaxed(val, hdmi->regs + offset); in hdmi_writeb()
82 static inline void hdmi_modb(struct rk3066_hdmi *hdmi, u16 offset, in hdmi_modb() argument
85 u8 temp = hdmi_readb(hdmi, offset) & ~msk; in hdmi_modb()
88 hdmi_writeb(hdmi, offset, temp); in hdmi_modb()
91 static void rk3066_hdmi_i2c_init(struct rk3066_hdmi *hdmi) in rk3066_hdmi_i2c_init() argument
95 ddc_bus_freq = (hdmi->tmdsclk >> 2) / HDMI_SCL_RATE; in rk3066_hdmi_i2c_init()
97 hdmi_writeb(hdmi, HDMI_DDC_BUS_FREQ_L, ddc_bus_freq & 0xFF); in rk3066_hdmi_i2c_init()
98 hdmi_writeb(hdmi, HDMI_DDC_BUS_FREQ_H, (ddc_bus_freq >> 8) & 0xFF); in rk3066_hdmi_i2c_init()
101 hdmi_modb(hdmi, HDMI_INTR_MASK1, HDMI_INTR_EDID_MASK, 0); in rk3066_hdmi_i2c_init()
102 hdmi_writeb(hdmi, HDMI_INTR_STATUS1, HDMI_INTR_EDID_MASK); in rk3066_hdmi_i2c_init()
105 static inline u8 rk3066_hdmi_get_power_mode(struct rk3066_hdmi *hdmi) in rk3066_hdmi_get_power_mode() argument
107 return hdmi_readb(hdmi, HDMI_SYS_CTRL) & HDMI_SYS_POWER_MODE_MASK; in rk3066_hdmi_get_power_mode()
110 static void rk3066_hdmi_set_power_mode(struct rk3066_hdmi *hdmi, int mode) in rk3066_hdmi_set_power_mode() argument
115 current_mode = rk3066_hdmi_get_power_mode(hdmi); in rk3066_hdmi_set_power_mode()
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()
136 hdmi_modb(hdmi, HDMI_SYS_CTRL, in rk3066_hdmi_set_power_mode()
139 hdmi_writeb(hdmi, HDMI_SYS_CTRL, in rk3066_hdmi_set_power_mode()
143 hdmi_writeb(hdmi, HDMI_SYS_CTRL, in rk3066_hdmi_set_power_mode()
147 hdmi_writeb(hdmi, HDMI_SYS_CTRL, in rk3066_hdmi_set_power_mode()
161 hdmi->tmdsclk = DEFAULT_PLLA_RATE; in rk3066_hdmi_set_power_mode()
165 rk3066_hdmi_upload_frame(struct rk3066_hdmi *hdmi, int setup_rc, in rk3066_hdmi_upload_frame() argument
170 hdmi_modb(hdmi, HDMI_CP_AUTO_SEND_CTRL, mask, disable); in rk3066_hdmi_upload_frame()
172 hdmi_writeb(hdmi, HDMI_CP_BUF_INDEX, frame_index); in rk3066_hdmi_upload_frame()
184 hdmi_writeb(hdmi, HDMI_CP_BUF_ACC_HB0 + i * 4, in rk3066_hdmi_upload_frame()
188 hdmi_modb(hdmi, HDMI_CP_AUTO_SEND_CTRL, mask, enable); in rk3066_hdmi_upload_frame()
194 static int rk3066_hdmi_config_avi(struct rk3066_hdmi *hdmi, in rk3066_hdmi_config_avi() argument
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()
213 return rk3066_hdmi_upload_frame(hdmi, rc, &frame, in rk3066_hdmi_config_avi()
217 static int rk3066_hdmi_config_video_timing(struct rk3066_hdmi *hdmi, in rk3066_hdmi_config_video_timing() argument
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()
237 hdmi_writeb(hdmi, HDMI_EXT_VIDEO_PARA, value); in rk3066_hdmi_config_video_timing()
240 value = mode->htotal; in rk3066_hdmi_config_video_timing()
241 hdmi_writeb(hdmi, HDMI_EXT_HTOTAL_L, value & 0xFF); in rk3066_hdmi_config_video_timing()
242 hdmi_writeb(hdmi, HDMI_EXT_HTOTAL_H, (value >> 8) & 0xFF); in rk3066_hdmi_config_video_timing()
244 value = mode->htotal - mode->hdisplay; in rk3066_hdmi_config_video_timing()
245 hdmi_writeb(hdmi, HDMI_EXT_HBLANK_L, value & 0xFF); in rk3066_hdmi_config_video_timing()
246 hdmi_writeb(hdmi, HDMI_EXT_HBLANK_H, (value >> 8) & 0xFF); in rk3066_hdmi_config_video_timing()
248 value = mode->htotal - mode->hsync_start; in rk3066_hdmi_config_video_timing()
249 hdmi_writeb(hdmi, HDMI_EXT_HDELAY_L, value & 0xFF); in rk3066_hdmi_config_video_timing()
250 hdmi_writeb(hdmi, HDMI_EXT_HDELAY_H, (value >> 8) & 0xFF); in rk3066_hdmi_config_video_timing()
252 value = mode->hsync_end - mode->hsync_start; in rk3066_hdmi_config_video_timing()
253 hdmi_writeb(hdmi, HDMI_EXT_HDURATION_L, value & 0xFF); in rk3066_hdmi_config_video_timing()
254 hdmi_writeb(hdmi, HDMI_EXT_HDURATION_H, (value >> 8) & 0xFF); in rk3066_hdmi_config_video_timing()
256 value = mode->vtotal; in rk3066_hdmi_config_video_timing()
257 hdmi_writeb(hdmi, HDMI_EXT_VTOTAL_L, value & 0xFF); in rk3066_hdmi_config_video_timing()
258 hdmi_writeb(hdmi, HDMI_EXT_VTOTAL_H, (value >> 8) & 0xFF); in rk3066_hdmi_config_video_timing()
260 value = mode->vtotal - mode->vdisplay; in rk3066_hdmi_config_video_timing()
261 hdmi_writeb(hdmi, HDMI_EXT_VBLANK_L, value & 0xFF); in rk3066_hdmi_config_video_timing()
263 value = mode->vtotal - mode->vsync_start + vsync_offset; in rk3066_hdmi_config_video_timing()
264 hdmi_writeb(hdmi, HDMI_EXT_VDELAY, value & 0xFF); in rk3066_hdmi_config_video_timing()
266 value = mode->vsync_end - mode->vsync_start; in rk3066_hdmi_config_video_timing()
267 hdmi_writeb(hdmi, HDMI_EXT_VDURATION, value & 0xFF); in rk3066_hdmi_config_video_timing()
273 rk3066_hdmi_phy_write(struct rk3066_hdmi *hdmi, u16 offset, u8 value) in rk3066_hdmi_phy_write() argument
275 hdmi_writeb(hdmi, offset, value); in rk3066_hdmi_phy_write()
276 hdmi_modb(hdmi, HDMI_SYS_CTRL, in rk3066_hdmi_phy_write()
279 hdmi_modb(hdmi, HDMI_SYS_CTRL, HDMI_SYS_PLL_RESET_MASK, 0); in rk3066_hdmi_phy_write()
283 static void rk3066_hdmi_config_phy(struct rk3066_hdmi *hdmi) in rk3066_hdmi_config_phy() argument
286 hdmi_writeb(hdmi, HDMI_DEEP_COLOR_MODE, 0x22); in rk3066_hdmi_config_phy()
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()
294 rk3066_hdmi_phy_write(hdmi, 0x158, 0x0E); in rk3066_hdmi_config_phy()
295 rk3066_hdmi_phy_write(hdmi, 0x15c, 0x00); in rk3066_hdmi_config_phy()
296 rk3066_hdmi_phy_write(hdmi, 0x160, 0x60); in rk3066_hdmi_config_phy()
297 rk3066_hdmi_phy_write(hdmi, 0x164, 0x00); in rk3066_hdmi_config_phy()
298 rk3066_hdmi_phy_write(hdmi, 0x168, 0xDA); in rk3066_hdmi_config_phy()
299 rk3066_hdmi_phy_write(hdmi, 0x16c, 0xA1); in rk3066_hdmi_config_phy()
300 rk3066_hdmi_phy_write(hdmi, 0x170, 0x0e); in rk3066_hdmi_config_phy()
301 rk3066_hdmi_phy_write(hdmi, 0x174, 0x22); in rk3066_hdmi_config_phy()
302 rk3066_hdmi_phy_write(hdmi, 0x178, 0x00); in rk3066_hdmi_config_phy()
303 } else if (hdmi->tmdsclk > 50000000) { in rk3066_hdmi_config_phy()
304 rk3066_hdmi_phy_write(hdmi, 0x158, 0x06); in rk3066_hdmi_config_phy()
305 rk3066_hdmi_phy_write(hdmi, 0x15c, 0x00); in rk3066_hdmi_config_phy()
306 rk3066_hdmi_phy_write(hdmi, 0x160, 0x60); in rk3066_hdmi_config_phy()
307 rk3066_hdmi_phy_write(hdmi, 0x164, 0x00); in rk3066_hdmi_config_phy()
308 rk3066_hdmi_phy_write(hdmi, 0x168, 0xCA); in rk3066_hdmi_config_phy()
309 rk3066_hdmi_phy_write(hdmi, 0x16c, 0xA3); in rk3066_hdmi_config_phy()
310 rk3066_hdmi_phy_write(hdmi, 0x170, 0x0e); in rk3066_hdmi_config_phy()
311 rk3066_hdmi_phy_write(hdmi, 0x174, 0x20); in rk3066_hdmi_config_phy()
312 rk3066_hdmi_phy_write(hdmi, 0x178, 0x00); in rk3066_hdmi_config_phy()
314 rk3066_hdmi_phy_write(hdmi, 0x158, 0x02); in rk3066_hdmi_config_phy()
315 rk3066_hdmi_phy_write(hdmi, 0x15c, 0x00); in rk3066_hdmi_config_phy()
316 rk3066_hdmi_phy_write(hdmi, 0x160, 0x60); in rk3066_hdmi_config_phy()
317 rk3066_hdmi_phy_write(hdmi, 0x164, 0x00); in rk3066_hdmi_config_phy()
318 rk3066_hdmi_phy_write(hdmi, 0x168, 0xC2); in rk3066_hdmi_config_phy()
319 rk3066_hdmi_phy_write(hdmi, 0x16c, 0xA2); in rk3066_hdmi_config_phy()
320 rk3066_hdmi_phy_write(hdmi, 0x170, 0x0e); in rk3066_hdmi_config_phy()
321 rk3066_hdmi_phy_write(hdmi, 0x174, 0x20); in rk3066_hdmi_config_phy()
322 rk3066_hdmi_phy_write(hdmi, 0x178, 0x00); in rk3066_hdmi_config_phy()
326 static int rk3066_hdmi_setup(struct rk3066_hdmi *hdmi, in rk3066_hdmi_setup() argument
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()
345 hdmi_modb(hdmi, HDMI_VIDEO_CTRL2, HDMI_VIDEO_AUDIO_DISABLE_MASK, in rk3066_hdmi_setup()
349 if (rk3066_hdmi_get_power_mode(hdmi) != HDMI_SYS_POWER_MODE_B) in rk3066_hdmi_setup()
350 rk3066_hdmi_set_power_mode(hdmi, HDMI_SYS_POWER_MODE_B); in rk3066_hdmi_setup()
353 hdmi_modb(hdmi, HDMI_AV_CTRL1, in rk3066_hdmi_setup()
355 hdmi_writeb(hdmi, HDMI_VIDEO_CTRL1, in rk3066_hdmi_setup()
359 hdmi_writeb(hdmi, HDMI_DEEP_COLOR_MODE, 0x20); in rk3066_hdmi_setup()
361 rk3066_hdmi_config_video_timing(hdmi, mode); in rk3066_hdmi_setup()
363 if (display->is_hdmi) { in rk3066_hdmi_setup()
364 hdmi_modb(hdmi, HDMI_HDCP_CTRL, HDMI_VIDEO_MODE_MASK, in rk3066_hdmi_setup()
366 rk3066_hdmi_config_avi(hdmi, mode); in rk3066_hdmi_setup()
368 hdmi_modb(hdmi, HDMI_HDCP_CTRL, HDMI_VIDEO_MODE_MASK, 0); in rk3066_hdmi_setup()
371 rk3066_hdmi_config_phy(hdmi); in rk3066_hdmi_setup()
373 rk3066_hdmi_set_power_mode(hdmi, HDMI_SYS_POWER_MODE_E); in rk3066_hdmi_setup()
381 rk3066_hdmi_i2c_init(hdmi); in rk3066_hdmi_setup()
384 hdmi_modb(hdmi, HDMI_VIDEO_CTRL2, in rk3066_hdmi_setup()
392 struct rk3066_hdmi *hdmi = encoder_to_rk3066_hdmi(encoder); in rk3066_hdmi_encoder_enable() local
397 conn_state = drm_atomic_get_new_connector_state(state, &hdmi->connector); in rk3066_hdmi_encoder_enable()
401 crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc); in rk3066_hdmi_encoder_enable()
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, &crtc_state->adjusted_mode); in rk3066_hdmi_encoder_enable()
422 struct rk3066_hdmi *hdmi = encoder_to_rk3066_hdmi(encoder); in rk3066_hdmi_encoder_disable() local
424 DRM_DEV_DEBUG(hdmi->dev, "hdmi encoder disable\n"); in rk3066_hdmi_encoder_disable()
426 if (rk3066_hdmi_get_power_mode(hdmi) == HDMI_SYS_POWER_MODE_E) { in rk3066_hdmi_encoder_disable()
427 hdmi_writeb(hdmi, HDMI_VIDEO_CTRL2, in rk3066_hdmi_encoder_disable()
429 hdmi_modb(hdmi, HDMI_VIDEO_CTRL2, in rk3066_hdmi_encoder_disable()
434 rk3066_hdmi_set_power_mode(hdmi, HDMI_SYS_POWER_MODE_A); in rk3066_hdmi_encoder_disable()
444 s->output_mode = ROCKCHIP_OUT_MODE_P888; in rk3066_hdmi_encoder_atomic_check()
445 s->output_type = DRM_MODE_CONNECTOR_HDMIA; in rk3066_hdmi_encoder_atomic_check()
458 rk3066_hdmi_connector_detect(struct drm_connector *connector, bool force) in rk3066_hdmi_connector_detect() argument
460 struct rk3066_hdmi *hdmi = connector_to_rk3066_hdmi(connector); in rk3066_hdmi_connector_detect() local
462 return (hdmi_readb(hdmi, HDMI_HPG_MENS_STA) & HDMI_HPG_IN_STATUS_HIGH) ? in rk3066_hdmi_connector_detect()
466 static int rk3066_hdmi_connector_get_modes(struct drm_connector *connector) in rk3066_hdmi_connector_get_modes() argument
468 struct rk3066_hdmi *hdmi = connector_to_rk3066_hdmi(connector); in rk3066_hdmi_connector_get_modes() local
472 if (!hdmi->ddc) in rk3066_hdmi_connector_get_modes()
475 drm_edid = drm_edid_read_ddc(connector, hdmi->ddc); in rk3066_hdmi_connector_get_modes()
476 drm_edid_connector_update(connector, drm_edid); in rk3066_hdmi_connector_get_modes()
477 ret = drm_edid_connector_add_modes(connector); in rk3066_hdmi_connector_get_modes()
484 rk3066_hdmi_connector_mode_valid(struct drm_connector *connector, in rk3066_hdmi_connector_mode_valid() argument
496 rk3066_hdmi_connector_best_encoder(struct drm_connector *connector) in rk3066_hdmi_connector_best_encoder() argument
498 struct rk3066_hdmi *hdmi = connector_to_rk3066_hdmi(connector); in rk3066_hdmi_connector_best_encoder() local
500 return &hdmi->encoder.encoder; in rk3066_hdmi_connector_best_encoder()
504 rk3066_hdmi_probe_single_connector_modes(struct drm_connector *connector, in rk3066_hdmi_probe_single_connector_modes() argument
512 return drm_helper_probe_single_connector_modes(connector, maxX, maxY); in rk3066_hdmi_probe_single_connector_modes()
515 static void rk3066_hdmi_connector_destroy(struct drm_connector *connector) in rk3066_hdmi_connector_destroy() argument
517 drm_connector_unregister(connector); in rk3066_hdmi_connector_destroy()
518 drm_connector_cleanup(connector); in rk3066_hdmi_connector_destroy()
538 rk3066_hdmi_register(struct drm_device *drm, struct rk3066_hdmi *hdmi) in rk3066_hdmi_register() argument
540 struct drm_encoder *encoder = &hdmi->encoder.encoder; in rk3066_hdmi_register()
541 struct device *dev = hdmi->dev; in rk3066_hdmi_register()
543 encoder->possible_crtcs = in rk3066_hdmi_register()
544 drm_of_find_possible_crtcs(drm, dev->of_node); in rk3066_hdmi_register()
552 if (encoder->possible_crtcs == 0) in rk3066_hdmi_register()
553 return -EPROBE_DEFER; in rk3066_hdmi_register()
558 hdmi->connector.polled = DRM_CONNECTOR_POLL_HPD; in rk3066_hdmi_register()
560 drm_connector_helper_add(&hdmi->connector, in rk3066_hdmi_register()
562 drm_connector_init_with_ddc(drm, &hdmi->connector, in rk3066_hdmi_register()
565 hdmi->ddc); in rk3066_hdmi_register()
567 drm_connector_attach_encoder(&hdmi->connector, encoder); in rk3066_hdmi_register()
574 struct rk3066_hdmi *hdmi = dev_id; in rk3066_hdmi_hardirq() local
578 if (rk3066_hdmi_get_power_mode(hdmi) == HDMI_SYS_POWER_MODE_A) in rk3066_hdmi_hardirq()
579 hdmi_writeb(hdmi, HDMI_SYS_CTRL, HDMI_SYS_POWER_MODE_B); in rk3066_hdmi_hardirq()
581 interrupt = hdmi_readb(hdmi, HDMI_INTR_STATUS1); in rk3066_hdmi_hardirq()
583 hdmi_writeb(hdmi, HDMI_INTR_STATUS1, interrupt); in rk3066_hdmi_hardirq()
586 hdmi->i2c->stat = interrupt; in rk3066_hdmi_hardirq()
587 complete(&hdmi->i2c->cmpltn); in rk3066_hdmi_hardirq()
598 struct rk3066_hdmi *hdmi = dev_id; in rk3066_hdmi_irq() local
600 drm_helper_hpd_irq_event(hdmi->connector.dev); in rk3066_hdmi_irq()
605 static int rk3066_hdmi_i2c_read(struct rk3066_hdmi *hdmi, struct i2c_msg *msgs) in rk3066_hdmi_i2c_read() argument
607 int length = msgs->len; in rk3066_hdmi_i2c_read()
608 u8 *buf = msgs->buf; in rk3066_hdmi_i2c_read()
611 ret = wait_for_completion_timeout(&hdmi->i2c->cmpltn, HZ / 10); in rk3066_hdmi_i2c_read()
612 if (!ret || hdmi->i2c->stat & HDMI_INTR_EDID_ERR) in rk3066_hdmi_i2c_read()
613 return -EAGAIN; in rk3066_hdmi_i2c_read()
615 while (length--) in rk3066_hdmi_i2c_read()
616 *buf++ = hdmi_readb(hdmi, HDMI_DDC_READ_FIFO_ADDR); in rk3066_hdmi_i2c_read()
621 static int rk3066_hdmi_i2c_write(struct rk3066_hdmi *hdmi, struct i2c_msg *msgs) in rk3066_hdmi_i2c_write() argument
628 if (msgs->len != 1 || in rk3066_hdmi_i2c_write()
629 (msgs->addr != DDC_ADDR && msgs->addr != DDC_SEGMENT_ADDR)) in rk3066_hdmi_i2c_write()
630 return -EINVAL; in rk3066_hdmi_i2c_write()
632 reinit_completion(&hdmi->i2c->cmpltn); in rk3066_hdmi_i2c_write()
634 if (msgs->addr == DDC_SEGMENT_ADDR) in rk3066_hdmi_i2c_write()
635 hdmi->i2c->segment_addr = msgs->buf[0]; in rk3066_hdmi_i2c_write()
636 if (msgs->addr == DDC_ADDR) in rk3066_hdmi_i2c_write()
637 hdmi->i2c->ddc_addr = msgs->buf[0]; in rk3066_hdmi_i2c_write()
640 hdmi_writeb(hdmi, HDMI_EDID_FIFO_ADDR, 0x00); in rk3066_hdmi_i2c_write()
643 hdmi_writeb(hdmi, HDMI_EDID_WORD_ADDR, hdmi->i2c->ddc_addr); in rk3066_hdmi_i2c_write()
646 hdmi_writeb(hdmi, HDMI_EDID_SEGMENT_POINTER, hdmi->i2c->segment_addr); in rk3066_hdmi_i2c_write()
654 struct rk3066_hdmi *hdmi = i2c_get_adapdata(adap); in rk3066_hdmi_i2c_xfer() local
655 struct rk3066_hdmi_i2c *i2c = hdmi->i2c; in rk3066_hdmi_i2c_xfer()
658 mutex_lock(&i2c->i2c_lock); in rk3066_hdmi_i2c_xfer()
660 rk3066_hdmi_i2c_init(hdmi); in rk3066_hdmi_i2c_xfer()
662 /* Unmute HDMI EDID interrupt. */ in rk3066_hdmi_i2c_xfer()
663 hdmi_modb(hdmi, HDMI_INTR_MASK1, in rk3066_hdmi_i2c_xfer()
665 i2c->stat = 0; in rk3066_hdmi_i2c_xfer()
668 DRM_DEV_DEBUG(hdmi->dev, in rk3066_hdmi_i2c_xfer()
673 ret = rk3066_hdmi_i2c_read(hdmi, &msgs[i]); in rk3066_hdmi_i2c_xfer()
675 ret = rk3066_hdmi_i2c_write(hdmi, &msgs[i]); in rk3066_hdmi_i2c_xfer()
684 /* Mute HDMI EDID interrupt. */ in rk3066_hdmi_i2c_xfer()
685 hdmi_modb(hdmi, HDMI_INTR_MASK1, HDMI_INTR_EDID_MASK, 0); in rk3066_hdmi_i2c_xfer()
687 mutex_unlock(&i2c->i2c_lock); in rk3066_hdmi_i2c_xfer()
702 static struct i2c_adapter *rk3066_hdmi_i2c_adapter(struct rk3066_hdmi *hdmi) in rk3066_hdmi_i2c_adapter() argument
708 i2c = devm_kzalloc(hdmi->dev, sizeof(*i2c), GFP_KERNEL); in rk3066_hdmi_i2c_adapter()
710 return ERR_PTR(-ENOMEM); in rk3066_hdmi_i2c_adapter()
712 mutex_init(&i2c->i2c_lock); in rk3066_hdmi_i2c_adapter()
713 init_completion(&i2c->cmpltn); in rk3066_hdmi_i2c_adapter()
715 adap = &i2c->adap; in rk3066_hdmi_i2c_adapter()
716 adap->owner = THIS_MODULE; in rk3066_hdmi_i2c_adapter()
717 adap->dev.parent = hdmi->dev; in rk3066_hdmi_i2c_adapter()
718 adap->dev.of_node = hdmi->dev->of_node; in rk3066_hdmi_i2c_adapter()
719 adap->algo = &rk3066_hdmi_algorithm; in rk3066_hdmi_i2c_adapter()
720 strscpy(adap->name, "RK3066 HDMI", sizeof(adap->name)); in rk3066_hdmi_i2c_adapter()
721 i2c_set_adapdata(adap, hdmi); in rk3066_hdmi_i2c_adapter()
725 DRM_DEV_ERROR(hdmi->dev, "cannot add %s I2C adapter\n", in rk3066_hdmi_i2c_adapter()
726 adap->name); in rk3066_hdmi_i2c_adapter()
727 devm_kfree(hdmi->dev, i2c); in rk3066_hdmi_i2c_adapter()
731 hdmi->i2c = i2c; in rk3066_hdmi_i2c_adapter()
733 DRM_DEV_DEBUG(hdmi->dev, "registered %s I2C bus driver\n", adap->name); in rk3066_hdmi_i2c_adapter()
743 struct rk3066_hdmi *hdmi; in rk3066_hdmi_bind() local
747 hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); in rk3066_hdmi_bind()
748 if (!hdmi) in rk3066_hdmi_bind()
749 return -ENOMEM; in rk3066_hdmi_bind()
751 hdmi->dev = dev; in rk3066_hdmi_bind()
752 hdmi->drm_dev = drm; in rk3066_hdmi_bind()
753 hdmi->regs = devm_platform_ioremap_resource(pdev, 0); in rk3066_hdmi_bind()
754 if (IS_ERR(hdmi->regs)) in rk3066_hdmi_bind()
755 return PTR_ERR(hdmi->regs); in rk3066_hdmi_bind()
761 hdmi->hclk = devm_clk_get(dev, "hclk"); in rk3066_hdmi_bind()
762 if (IS_ERR(hdmi->hclk)) { in rk3066_hdmi_bind()
763 DRM_DEV_ERROR(dev, "unable to get HDMI hclk clock\n"); in rk3066_hdmi_bind()
764 return PTR_ERR(hdmi->hclk); in rk3066_hdmi_bind()
767 ret = clk_prepare_enable(hdmi->hclk); in rk3066_hdmi_bind()
769 DRM_DEV_ERROR(dev, "cannot enable HDMI hclk clock: %d\n", ret); in rk3066_hdmi_bind()
773 hdmi->grf_regmap = syscon_regmap_lookup_by_phandle(dev->of_node, in rk3066_hdmi_bind()
775 if (IS_ERR(hdmi->grf_regmap)) { in rk3066_hdmi_bind()
777 ret = PTR_ERR(hdmi->grf_regmap); in rk3066_hdmi_bind()
782 hdmi_writeb(hdmi, HDMI_INTERNAL_CLK_DIVIDER, 25); in rk3066_hdmi_bind()
784 hdmi->ddc = rk3066_hdmi_i2c_adapter(hdmi); in rk3066_hdmi_bind()
785 if (IS_ERR(hdmi->ddc)) { in rk3066_hdmi_bind()
786 ret = PTR_ERR(hdmi->ddc); in rk3066_hdmi_bind()
787 hdmi->ddc = NULL; in rk3066_hdmi_bind()
791 rk3066_hdmi_set_power_mode(hdmi, HDMI_SYS_POWER_MODE_B); in rk3066_hdmi_bind()
793 hdmi_writeb(hdmi, HDMI_INTR_MASK1, HDMI_INTR_HOTPLUG); in rk3066_hdmi_bind()
794 hdmi_writeb(hdmi, HDMI_INTR_MASK2, 0); in rk3066_hdmi_bind()
795 hdmi_writeb(hdmi, HDMI_INTR_MASK3, 0); in rk3066_hdmi_bind()
796 hdmi_writeb(hdmi, HDMI_INTR_MASK4, 0); in rk3066_hdmi_bind()
797 rk3066_hdmi_set_power_mode(hdmi, HDMI_SYS_POWER_MODE_A); in rk3066_hdmi_bind()
799 ret = rk3066_hdmi_register(drm, hdmi); in rk3066_hdmi_bind()
803 dev_set_drvdata(dev, hdmi); in rk3066_hdmi_bind()
807 dev_name(dev), hdmi); in rk3066_hdmi_bind()
809 DRM_DEV_ERROR(dev, "failed to request hdmi irq: %d\n", ret); in rk3066_hdmi_bind()
816 hdmi->connector.funcs->destroy(&hdmi->connector); in rk3066_hdmi_bind()
817 hdmi->encoder.encoder.funcs->destroy(&hdmi->encoder.encoder); in rk3066_hdmi_bind()
819 i2c_put_adapter(hdmi->ddc); in rk3066_hdmi_bind()
821 clk_disable_unprepare(hdmi->hclk); in rk3066_hdmi_bind()
829 struct rk3066_hdmi *hdmi = dev_get_drvdata(dev); in rk3066_hdmi_unbind() local
831 hdmi->connector.funcs->destroy(&hdmi->connector); in rk3066_hdmi_unbind()
832 hdmi->encoder.encoder.funcs->destroy(&hdmi->encoder.encoder); in rk3066_hdmi_unbind()
834 i2c_put_adapter(hdmi->ddc); in rk3066_hdmi_unbind()
835 clk_disable_unprepare(hdmi->hclk); in rk3066_hdmi_unbind()
845 return component_add(&pdev->dev, &rk3066_hdmi_ops); in rk3066_hdmi_probe()
850 component_del(&pdev->dev, &rk3066_hdmi_ops); in rk3066_hdmi_remove()
854 { .compatible = "rockchip,rk3066-hdmi" },
863 .name = "rockchip-rk3066-hdmi",