Lines Matching +full:tcon +full:- +full:top +full:- +full:dsi
1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Maxime Ripard <maxime.ripard@free-electrons.com>
11 #include <linux/media-bus-format.h>
48 drm_connector_list_iter_begin(encoder->dev, &iter); in sun4i_tcon_get_connector()
50 if (connector->encoder == encoder) { in sun4i_tcon_get_connector()
66 return -EINVAL; in sun4i_tcon_get_pixel_depth()
68 info = &connector->display_info; in sun4i_tcon_get_pixel_depth()
69 if (info->num_bus_formats != 1) in sun4i_tcon_get_pixel_depth()
70 return -EINVAL; in sun4i_tcon_get_pixel_depth()
72 switch (info->bus_formats[0]) { in sun4i_tcon_get_pixel_depth()
81 return -EINVAL; in sun4i_tcon_get_pixel_depth()
84 static void sun4i_tcon_channel_set_status(struct sun4i_tcon *tcon, int channel, in sun4i_tcon_channel_set_status() argument
91 WARN_ON(!tcon->quirks->has_channel_0); in sun4i_tcon_channel_set_status()
92 regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG, in sun4i_tcon_channel_set_status()
95 clk = tcon->dclk; in sun4i_tcon_channel_set_status()
98 WARN_ON(!tcon->quirks->has_channel_1); in sun4i_tcon_channel_set_status()
99 regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG, in sun4i_tcon_channel_set_status()
102 clk = tcon->sclk1; in sun4i_tcon_channel_set_status()
118 static void sun4i_tcon_setup_lvds_phy(struct sun4i_tcon *tcon, in sun4i_tcon_setup_lvds_phy() argument
121 regmap_write(tcon->regs, SUN4I_TCON0_LVDS_ANA0_REG, in sun4i_tcon_setup_lvds_phy()
130 regmap_update_bits(tcon->regs, SUN4I_TCON0_LVDS_ANA1_REG, in sun4i_tcon_setup_lvds_phy()
134 regmap_update_bits(tcon->regs, SUN4I_TCON0_LVDS_ANA1_REG, in sun4i_tcon_setup_lvds_phy()
137 regmap_update_bits(tcon->regs, SUN4I_TCON0_LVDS_ANA0_REG, in sun4i_tcon_setup_lvds_phy()
142 static void sun6i_tcon_setup_lvds_phy(struct sun4i_tcon *tcon, in sun6i_tcon_setup_lvds_phy() argument
147 regmap_write(tcon->regs, SUN4I_TCON0_LVDS_ANA0_REG, in sun6i_tcon_setup_lvds_phy()
154 regmap_update_bits(tcon->regs, SUN4I_TCON0_LVDS_ANA0_REG, in sun6i_tcon_setup_lvds_phy()
159 regmap_update_bits(tcon->regs, SUN4I_TCON0_LVDS_ANA0_REG, in sun6i_tcon_setup_lvds_phy()
168 regmap_write_bits(tcon->regs, SUN4I_TCON0_LVDS_ANA0_REG, in sun6i_tcon_setup_lvds_phy()
173 static void sun4i_tcon_lvds_set_status(struct sun4i_tcon *tcon, in sun4i_tcon_lvds_set_status() argument
178 regmap_update_bits(tcon->regs, SUN4I_TCON0_LVDS_IF_REG, in sun4i_tcon_lvds_set_status()
181 if (tcon->quirks->setup_lvds_phy) in sun4i_tcon_lvds_set_status()
182 tcon->quirks->setup_lvds_phy(tcon, encoder); in sun4i_tcon_lvds_set_status()
184 regmap_update_bits(tcon->regs, SUN4I_TCON0_LVDS_IF_REG, in sun4i_tcon_lvds_set_status()
189 void sun4i_tcon_set_status(struct sun4i_tcon *tcon, in sun4i_tcon_set_status() argument
196 switch (encoder->encoder_type) { in sun4i_tcon_set_status()
214 sun4i_tcon_lvds_set_status(tcon, encoder, false); in sun4i_tcon_set_status()
216 regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG, in sun4i_tcon_set_status()
221 sun4i_tcon_lvds_set_status(tcon, encoder, true); in sun4i_tcon_set_status()
223 sun4i_tcon_channel_set_status(tcon, channel, enabled); in sun4i_tcon_set_status()
226 void sun4i_tcon_enable_vblank(struct sun4i_tcon *tcon, bool enable) in sun4i_tcon_enable_vblank() argument
239 regmap_update_bits(tcon->regs, SUN4I_TCON_GINT0_REG, mask, val); in sun4i_tcon_enable_vblank()
244 * This function is a helper for TCON output muxing. The TCON output
245 * muxing control register in earlier SoCs (without the TCON TOP block)
251 struct sun4i_drv *drv = drm->dev_private; in sun4i_get_tcon0()
252 struct sun4i_tcon *tcon; in sun4i_get_tcon0() local
254 list_for_each_entry(tcon, &drv->tcon_list, list) in sun4i_get_tcon0()
255 if (tcon->id == 0) in sun4i_get_tcon0()
256 return tcon; in sun4i_get_tcon0()
258 dev_warn(drm->dev, in sun4i_get_tcon0()
264 static void sun4i_tcon_set_mux(struct sun4i_tcon *tcon, int channel, in sun4i_tcon_set_mux() argument
267 int ret = -ENOTSUPP; in sun4i_tcon_set_mux()
269 if (tcon->quirks->set_mux) in sun4i_tcon_set_mux()
270 ret = tcon->quirks->set_mux(tcon, encoder); in sun4i_tcon_set_mux()
273 encoder->name, encoder->crtc->name, ret); in sun4i_tcon_set_mux()
279 int delay = mode->vtotal - mode->vdisplay; in sun4i_tcon_get_clk_delay()
281 if (mode->flags & DRM_MODE_FLAG_INTERLACE) in sun4i_tcon_get_clk_delay()
285 delay -= 2; in sun4i_tcon_get_clk_delay()
289 DRM_DEBUG_DRIVER("TCON %d clock delay %u\n", channel, delay); in sun4i_tcon_get_clk_delay()
294 static void sun4i_tcon0_mode_set_dithering(struct sun4i_tcon *tcon, in sun4i_tcon0_mode_set_dithering() argument
310 regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_PR_REG, 0x11111111); in sun4i_tcon0_mode_set_dithering()
311 regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_PG_REG, 0x11111111); in sun4i_tcon0_mode_set_dithering()
312 regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_PB_REG, 0x11111111); in sun4i_tcon0_mode_set_dithering()
313 regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_LR_REG, 0x11111111); in sun4i_tcon0_mode_set_dithering()
314 regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_LG_REG, 0x11111111); in sun4i_tcon0_mode_set_dithering()
315 regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_LB_REG, 0x11111111); in sun4i_tcon0_mode_set_dithering()
316 regmap_write(tcon->regs, SUN4I_TCON0_FRM_TBL0_REG, 0x01010000); in sun4i_tcon0_mode_set_dithering()
317 regmap_write(tcon->regs, SUN4I_TCON0_FRM_TBL1_REG, 0x15151111); in sun4i_tcon0_mode_set_dithering()
318 regmap_write(tcon->regs, SUN4I_TCON0_FRM_TBL2_REG, 0x57575555); in sun4i_tcon0_mode_set_dithering()
319 regmap_write(tcon->regs, SUN4I_TCON0_FRM_TBL3_REG, 0x7f7f7777); in sun4i_tcon0_mode_set_dithering()
322 if (connector->display_info.bpc == 6) in sun4i_tcon0_mode_set_dithering()
325 if (connector->display_info.num_bus_formats == 1) in sun4i_tcon0_mode_set_dithering()
326 bus_format = connector->display_info.bus_formats[0]; in sun4i_tcon0_mode_set_dithering()
343 regmap_write(tcon->regs, SUN4I_TCON_FRM_CTL_REG, val); in sun4i_tcon0_mode_set_dithering()
346 static void sun4i_tcon0_mode_set_cpu(struct sun4i_tcon *tcon, in sun4i_tcon0_mode_set_cpu() argument
351 struct sun6i_dsi *dsi = encoder_to_sun6i_dsi(encoder); in sun4i_tcon0_mode_set_cpu() local
352 struct mipi_dsi_device *device = dsi->device; in sun4i_tcon0_mode_set_cpu()
353 u8 bpp = mipi_dsi_pixel_format_to_bpp(device->format); in sun4i_tcon0_mode_set_cpu()
354 u8 lanes = device->lanes; in sun4i_tcon0_mode_set_cpu()
359 * dclk is required to run at 1/4 the DSI per-lane bit rate. in sun4i_tcon0_mode_set_cpu()
361 tcon->dclk_min_div = SUN6I_DSI_TCON_DIV; in sun4i_tcon0_mode_set_cpu()
362 tcon->dclk_max_div = SUN6I_DSI_TCON_DIV; in sun4i_tcon0_mode_set_cpu()
363 clk_set_rate(tcon->dclk, mode->crtc_clock * 1000 * (bpp / lanes) in sun4i_tcon0_mode_set_cpu()
367 regmap_write(tcon->regs, SUN4I_TCON0_BASIC0_REG, in sun4i_tcon0_mode_set_cpu()
368 SUN4I_TCON0_BASIC0_X(mode->crtc_hdisplay) | in sun4i_tcon0_mode_set_cpu()
369 SUN4I_TCON0_BASIC0_Y(mode->crtc_vdisplay)); in sun4i_tcon0_mode_set_cpu()
372 sun4i_tcon0_mode_set_dithering(tcon, sun4i_tcon_get_connector(encoder)); in sun4i_tcon0_mode_set_cpu()
374 regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG, in sun4i_tcon0_mode_set_cpu()
378 regmap_write(tcon->regs, SUN4I_TCON_ECC_FIFO_REG, in sun4i_tcon0_mode_set_cpu()
381 regmap_write(tcon->regs, SUN4I_TCON0_CPU_IF_REG, in sun4i_tcon0_mode_set_cpu()
393 regmap_read(tcon->regs, SUN4I_TCON0_DCLK_REG, &tcon_div); in sun4i_tcon0_mode_set_cpu()
395 block_space = mode->htotal * bpp / (tcon_div * lanes); in sun4i_tcon0_mode_set_cpu()
396 block_space -= mode->hdisplay + 40; in sun4i_tcon0_mode_set_cpu()
398 regmap_write(tcon->regs, SUN4I_TCON0_CPU_TRI0_REG, in sun4i_tcon0_mode_set_cpu()
400 SUN4I_TCON0_CPU_TRI0_BLOCK_SIZE(mode->hdisplay)); in sun4i_tcon0_mode_set_cpu()
402 regmap_write(tcon->regs, SUN4I_TCON0_CPU_TRI1_REG, in sun4i_tcon0_mode_set_cpu()
403 SUN4I_TCON0_CPU_TRI1_BLOCK_NUM(mode->vdisplay)); in sun4i_tcon0_mode_set_cpu()
405 start_delay = (mode->crtc_vtotal - mode->crtc_vdisplay - 10 - 1); in sun4i_tcon0_mode_set_cpu()
406 start_delay = start_delay * mode->crtc_htotal * 149; in sun4i_tcon0_mode_set_cpu()
407 start_delay = start_delay / (mode->crtc_clock / 1000) / 8; in sun4i_tcon0_mode_set_cpu()
408 regmap_write(tcon->regs, SUN4I_TCON0_CPU_TRI2_REG, in sun4i_tcon0_mode_set_cpu()
416 regmap_write(tcon->regs, SUN4I_TCON_SAFE_PERIOD_REG, in sun4i_tcon0_mode_set_cpu()
421 regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, in sun4i_tcon0_mode_set_cpu()
425 static void sun4i_tcon0_mode_set_lvds(struct sun4i_tcon *tcon, in sun4i_tcon0_mode_set_lvds() argument
433 WARN_ON(!tcon->quirks->has_channel_0); in sun4i_tcon0_mode_set_lvds()
435 tcon->dclk_min_div = 7; in sun4i_tcon0_mode_set_lvds()
436 tcon->dclk_max_div = 7; in sun4i_tcon0_mode_set_lvds()
437 clk_set_rate(tcon->dclk, mode->crtc_clock * 1000); in sun4i_tcon0_mode_set_lvds()
440 regmap_write(tcon->regs, SUN4I_TCON0_BASIC0_REG, in sun4i_tcon0_mode_set_lvds()
441 SUN4I_TCON0_BASIC0_X(mode->crtc_hdisplay) | in sun4i_tcon0_mode_set_lvds()
442 SUN4I_TCON0_BASIC0_Y(mode->crtc_vdisplay)); in sun4i_tcon0_mode_set_lvds()
445 sun4i_tcon0_mode_set_dithering(tcon, sun4i_tcon_get_connector(encoder)); in sun4i_tcon0_mode_set_lvds()
449 regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG, in sun4i_tcon0_mode_set_lvds()
457 bp = mode->crtc_htotal - mode->crtc_hsync_start; in sun4i_tcon0_mode_set_lvds()
459 mode->crtc_htotal, bp); in sun4i_tcon0_mode_set_lvds()
462 regmap_write(tcon->regs, SUN4I_TCON0_BASIC1_REG, in sun4i_tcon0_mode_set_lvds()
463 SUN4I_TCON0_BASIC1_H_TOTAL(mode->htotal) | in sun4i_tcon0_mode_set_lvds()
470 bp = mode->crtc_vtotal - mode->crtc_vsync_start; in sun4i_tcon0_mode_set_lvds()
472 mode->crtc_vtotal, bp); in sun4i_tcon0_mode_set_lvds()
475 regmap_write(tcon->regs, SUN4I_TCON0_BASIC2_REG, in sun4i_tcon0_mode_set_lvds()
476 SUN4I_TCON0_BASIC2_V_TOTAL(mode->crtc_vtotal * 2) | in sun4i_tcon0_mode_set_lvds()
485 regmap_write(tcon->regs, SUN4I_TCON0_LVDS_IF_REG, reg); in sun4i_tcon0_mode_set_lvds()
488 if (!(mode->flags & DRM_MODE_FLAG_PHSYNC)) in sun4i_tcon0_mode_set_lvds()
491 if (!(mode->flags & DRM_MODE_FLAG_PVSYNC)) in sun4i_tcon0_mode_set_lvds()
494 regmap_write(tcon->regs, SUN4I_TCON0_IO_POL_REG, val); in sun4i_tcon0_mode_set_lvds()
497 regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG, in sun4i_tcon0_mode_set_lvds()
502 regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, 0xe0000000); in sun4i_tcon0_mode_set_lvds()
505 static void sun4i_tcon0_mode_set_rgb(struct sun4i_tcon *tcon, in sun4i_tcon0_mode_set_rgb() argument
510 const struct drm_display_info *info = &connector->display_info; in sun4i_tcon0_mode_set_rgb()
515 WARN_ON(!tcon->quirks->has_channel_0); in sun4i_tcon0_mode_set_rgb()
517 tcon->dclk_min_div = tcon->quirks->dclk_min_div; in sun4i_tcon0_mode_set_rgb()
518 tcon->dclk_max_div = 127; in sun4i_tcon0_mode_set_rgb()
519 clk_set_rate(tcon->dclk, mode->crtc_clock * 1000); in sun4i_tcon0_mode_set_rgb()
522 regmap_write(tcon->regs, SUN4I_TCON0_BASIC0_REG, in sun4i_tcon0_mode_set_rgb()
523 SUN4I_TCON0_BASIC0_X(mode->crtc_hdisplay) | in sun4i_tcon0_mode_set_rgb()
524 SUN4I_TCON0_BASIC0_Y(mode->crtc_vdisplay)); in sun4i_tcon0_mode_set_rgb()
527 sun4i_tcon0_mode_set_dithering(tcon, connector); in sun4i_tcon0_mode_set_rgb()
531 regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG, in sun4i_tcon0_mode_set_rgb()
539 bp = mode->crtc_htotal - mode->crtc_hsync_start; in sun4i_tcon0_mode_set_rgb()
541 mode->crtc_htotal, bp); in sun4i_tcon0_mode_set_rgb()
544 regmap_write(tcon->regs, SUN4I_TCON0_BASIC1_REG, in sun4i_tcon0_mode_set_rgb()
545 SUN4I_TCON0_BASIC1_H_TOTAL(mode->crtc_htotal) | in sun4i_tcon0_mode_set_rgb()
552 bp = mode->crtc_vtotal - mode->crtc_vsync_start; in sun4i_tcon0_mode_set_rgb()
554 mode->crtc_vtotal, bp); in sun4i_tcon0_mode_set_rgb()
557 regmap_write(tcon->regs, SUN4I_TCON0_BASIC2_REG, in sun4i_tcon0_mode_set_rgb()
558 SUN4I_TCON0_BASIC2_V_TOTAL(mode->crtc_vtotal * 2) | in sun4i_tcon0_mode_set_rgb()
562 hsync = mode->crtc_hsync_end - mode->crtc_hsync_start; in sun4i_tcon0_mode_set_rgb()
563 vsync = mode->crtc_vsync_end - mode->crtc_vsync_start; in sun4i_tcon0_mode_set_rgb()
565 regmap_write(tcon->regs, SUN4I_TCON0_BASIC3_REG, in sun4i_tcon0_mode_set_rgb()
570 if (mode->flags & DRM_MODE_FLAG_PHSYNC) in sun4i_tcon0_mode_set_rgb()
573 if (mode->flags & DRM_MODE_FLAG_PVSYNC) in sun4i_tcon0_mode_set_rgb()
576 if (info->bus_flags & DRM_BUS_FLAG_DE_LOW) in sun4i_tcon0_mode_set_rgb()
579 if (info->bus_flags & DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE) in sun4i_tcon0_mode_set_rgb()
582 regmap_update_bits(tcon->regs, SUN4I_TCON0_IO_POL_REG, in sun4i_tcon0_mode_set_rgb()
590 regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG, in sun4i_tcon0_mode_set_rgb()
595 regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, 0); in sun4i_tcon0_mode_set_rgb()
598 static void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon, in sun4i_tcon1_mode_set() argument
605 WARN_ON(!tcon->quirks->has_channel_1); in sun4i_tcon1_mode_set()
608 clk_set_rate(tcon->sclk1, mode->crtc_clock * 1000); in sun4i_tcon1_mode_set()
612 regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG, in sun4i_tcon1_mode_set()
617 if (mode->flags & DRM_MODE_FLAG_INTERLACE) in sun4i_tcon1_mode_set()
621 regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG, in sun4i_tcon1_mode_set()
626 regmap_write(tcon->regs, SUN4I_TCON1_BASIC0_REG, in sun4i_tcon1_mode_set()
627 SUN4I_TCON1_BASIC0_X(mode->crtc_hdisplay) | in sun4i_tcon1_mode_set()
628 SUN4I_TCON1_BASIC0_Y(mode->crtc_vdisplay)); in sun4i_tcon1_mode_set()
631 regmap_write(tcon->regs, SUN4I_TCON1_BASIC1_REG, in sun4i_tcon1_mode_set()
632 SUN4I_TCON1_BASIC1_X(mode->crtc_hdisplay) | in sun4i_tcon1_mode_set()
633 SUN4I_TCON1_BASIC1_Y(mode->crtc_vdisplay)); in sun4i_tcon1_mode_set()
636 regmap_write(tcon->regs, SUN4I_TCON1_BASIC2_REG, in sun4i_tcon1_mode_set()
637 SUN4I_TCON1_BASIC2_X(mode->crtc_hdisplay) | in sun4i_tcon1_mode_set()
638 SUN4I_TCON1_BASIC2_Y(mode->crtc_vdisplay)); in sun4i_tcon1_mode_set()
641 bp = mode->crtc_htotal - mode->crtc_hsync_start; in sun4i_tcon1_mode_set()
643 mode->htotal, bp); in sun4i_tcon1_mode_set()
644 regmap_write(tcon->regs, SUN4I_TCON1_BASIC3_REG, in sun4i_tcon1_mode_set()
645 SUN4I_TCON1_BASIC3_H_TOTAL(mode->crtc_htotal) | in sun4i_tcon1_mode_set()
648 bp = mode->crtc_vtotal - mode->crtc_vsync_start; in sun4i_tcon1_mode_set()
650 mode->crtc_vtotal, bp); in sun4i_tcon1_mode_set()
665 vtotal = mode->vtotal; in sun4i_tcon1_mode_set()
666 if (!(mode->flags & DRM_MODE_FLAG_INTERLACE)) in sun4i_tcon1_mode_set()
670 regmap_write(tcon->regs, SUN4I_TCON1_BASIC4_REG, in sun4i_tcon1_mode_set()
675 hsync = mode->crtc_hsync_end - mode->crtc_hsync_start; in sun4i_tcon1_mode_set()
676 vsync = mode->crtc_vsync_end - mode->crtc_vsync_start; in sun4i_tcon1_mode_set()
678 regmap_write(tcon->regs, SUN4I_TCON1_BASIC5_REG, in sun4i_tcon1_mode_set()
683 if (tcon->quirks->polarity_in_ch0) { in sun4i_tcon1_mode_set()
686 if (mode->flags & DRM_MODE_FLAG_PHSYNC) in sun4i_tcon1_mode_set()
689 if (mode->flags & DRM_MODE_FLAG_PVSYNC) in sun4i_tcon1_mode_set()
692 regmap_write(tcon->regs, SUN4I_TCON0_IO_POL_REG, val); in sun4i_tcon1_mode_set()
697 if (mode->flags & DRM_MODE_FLAG_PHSYNC) in sun4i_tcon1_mode_set()
700 if (mode->flags & DRM_MODE_FLAG_PVSYNC) in sun4i_tcon1_mode_set()
703 regmap_write(tcon->regs, SUN4I_TCON1_IO_POL_REG, val); in sun4i_tcon1_mode_set()
707 regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG, in sun4i_tcon1_mode_set()
712 void sun4i_tcon_mode_set(struct sun4i_tcon *tcon, in sun4i_tcon_mode_set() argument
716 switch (encoder->encoder_type) { in sun4i_tcon_mode_set()
718 /* DSI is tied to special case of CPU interface */ in sun4i_tcon_mode_set()
719 sun4i_tcon0_mode_set_cpu(tcon, encoder, mode); in sun4i_tcon_mode_set()
722 sun4i_tcon0_mode_set_lvds(tcon, encoder, mode); in sun4i_tcon_mode_set()
725 sun4i_tcon0_mode_set_rgb(tcon, encoder, mode); in sun4i_tcon_mode_set()
726 sun4i_tcon_set_mux(tcon, 0, encoder); in sun4i_tcon_mode_set()
730 sun4i_tcon1_mode_set(tcon, mode); in sun4i_tcon_mode_set()
731 sun4i_tcon_set_mux(tcon, 1, encoder); in sun4i_tcon_mode_set()
744 spin_lock_irqsave(&dev->event_lock, flags); in sun4i_tcon_finish_page_flip()
745 if (scrtc->event) { in sun4i_tcon_finish_page_flip()
746 drm_crtc_send_vblank_event(&scrtc->crtc, scrtc->event); in sun4i_tcon_finish_page_flip()
747 drm_crtc_vblank_put(&scrtc->crtc); in sun4i_tcon_finish_page_flip()
748 scrtc->event = NULL; in sun4i_tcon_finish_page_flip()
750 spin_unlock_irqrestore(&dev->event_lock, flags); in sun4i_tcon_finish_page_flip()
755 struct sun4i_tcon *tcon = private; in sun4i_tcon_handler() local
756 struct drm_device *drm = tcon->drm; in sun4i_tcon_handler()
757 struct sun4i_crtc *scrtc = tcon->crtc; in sun4i_tcon_handler()
758 struct sunxi_engine *engine = scrtc->engine; in sun4i_tcon_handler()
761 regmap_read(tcon->regs, SUN4I_TCON_GINT0_REG, &status); in sun4i_tcon_handler()
768 drm_crtc_handle_vblank(&scrtc->crtc); in sun4i_tcon_handler()
772 regmap_update_bits(tcon->regs, SUN4I_TCON_GINT0_REG, in sun4i_tcon_handler()
778 if (engine->ops->vblank_quirk) in sun4i_tcon_handler()
779 engine->ops->vblank_quirk(engine); in sun4i_tcon_handler()
785 struct sun4i_tcon *tcon) in sun4i_tcon_init_clocks() argument
787 tcon->clk = devm_clk_get_enabled(dev, "ahb"); in sun4i_tcon_init_clocks()
788 if (IS_ERR(tcon->clk)) { in sun4i_tcon_init_clocks()
789 dev_err(dev, "Couldn't get the TCON bus clock\n"); in sun4i_tcon_init_clocks()
790 return PTR_ERR(tcon->clk); in sun4i_tcon_init_clocks()
793 if (tcon->quirks->has_channel_0) { in sun4i_tcon_init_clocks()
794 tcon->sclk0 = devm_clk_get_enabled(dev, "tcon-ch0"); in sun4i_tcon_init_clocks()
795 if (IS_ERR(tcon->sclk0)) { in sun4i_tcon_init_clocks()
796 dev_err(dev, "Couldn't get the TCON channel 0 clock\n"); in sun4i_tcon_init_clocks()
797 return PTR_ERR(tcon->sclk0); in sun4i_tcon_init_clocks()
801 if (tcon->quirks->has_channel_1) { in sun4i_tcon_init_clocks()
802 tcon->sclk1 = devm_clk_get(dev, "tcon-ch1"); in sun4i_tcon_init_clocks()
803 if (IS_ERR(tcon->sclk1)) { in sun4i_tcon_init_clocks()
804 dev_err(dev, "Couldn't get the TCON channel 1 clock\n"); in sun4i_tcon_init_clocks()
805 return PTR_ERR(tcon->sclk1); in sun4i_tcon_init_clocks()
813 struct sun4i_tcon *tcon) in sun4i_tcon_init_irq() argument
823 dev_name(dev), tcon); in sun4i_tcon_init_irq()
840 struct sun4i_tcon *tcon) in sun4i_tcon_init_regmap() argument
849 tcon->regs = devm_regmap_init_mmio(dev, regs, in sun4i_tcon_init_regmap()
851 if (IS_ERR(tcon->regs)) { in sun4i_tcon_init_regmap()
852 dev_err(dev, "Couldn't create the TCON regmap\n"); in sun4i_tcon_init_regmap()
853 return PTR_ERR(tcon->regs); in sun4i_tcon_init_regmap()
856 /* Make sure the TCON is disabled and all IRQs are off */ in sun4i_tcon_init_regmap()
857 regmap_write(tcon->regs, SUN4I_TCON_GCTL_REG, 0); in sun4i_tcon_init_regmap()
858 regmap_write(tcon->regs, SUN4I_TCON_GINT0_REG, 0); in sun4i_tcon_init_regmap()
859 regmap_write(tcon->regs, SUN4I_TCON_GINT1_REG, 0); in sun4i_tcon_init_regmap()
862 regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, ~0); in sun4i_tcon_init_regmap()
863 regmap_write(tcon->regs, SUN4I_TCON1_IO_TRI_REG, ~0); in sun4i_tcon_init_regmap()
870 * the TCON is always tied to just one backend. Hence we can traverse
871 * the of_graph upwards to find the backend our tcon is connected to,
876 * registered and binded before the TCON, we can just go through the
889 struct sunxi_engine *engine = ERR_PTR(-EINVAL); in sun4i_tcon_find_engine_traverse()
894 return ERR_PTR(-EINVAL); in sun4i_tcon_find_engine_traverse()
897 * This only works if there is only one path from the TCON in sun4i_tcon_find_engine_traverse()
918 list_for_each_entry(engine, &drv->engine_list, list) in sun4i_tcon_find_engine_traverse()
919 if (remote == engine->node) in sun4i_tcon_find_engine_traverse()
925 * more than one input and one output (TCON TOP) exits, correct in sun4i_tcon_find_engine_traverse()
933 reg -= 1; in sun4i_tcon_find_engine_traverse()
950 * connection between components, up to and including the TCON, of
961 int ret = -EINVAL; in sun4i_tcon_of_get_id_from_port()
983 * Once we know the TCON's id, we can look through the list of
992 list_for_each_entry(engine, &drv->engine_list, list) in sun4i_tcon_get_engine_by_id()
993 if (engine->id == id) in sun4i_tcon_get_engine_by_id()
996 return ERR_PTR(-EINVAL); in sun4i_tcon_get_engine_by_id()
1004 remote = of_graph_get_remote_node(node, 0, -1); in sun4i_tcon_connected_to_tcon_top()
1020 * Because TCON is added to the list at the end of the probe in sun4i_tcon_get_index()
1021 * (after this function is called), index of the current TCON in sun4i_tcon_get_index()
1022 * will be same as current TCON list size. in sun4i_tcon_get_index()
1024 list_for_each(pos, &drv->tcon_list) in sun4i_tcon_get_index()
1032 * we assumed the TCON was always tied to just one backend. However
1033 * this proved not to be the case. On the A31, the TCON can select
1035 * the backend can choose which TCON to output to.
1038 * connection between components, up to and including the TCON, of
1044 * However the connections between the backend and TCON were assumed
1047 * up the remote endpoint ID of a TCON input endpoint. TCON1 would be
1050 * This function first checks if the TCON node has 2 input endpoints.
1055 * have endpoint connections between the backend and TCON across
1071 return ERR_PTR(-EINVAL); in sun4i_tcon_find_engine()
1075 * connections between the backend and TCON? in sun4i_tcon_find_engine()
1084 * contains TCON TOP, chances are that there are either more in sun4i_tcon_find_engine()
1085 * TCONs than engines (R40) or TCONs with non-consecutive ids. in sun4i_tcon_find_engine()
1086 * (H6). In that case it's easier just use TCON index in list in sun4i_tcon_find_engine()
1089 * TCON TOP, remaining 2 TCONs can't be connected to anything in sun4i_tcon_find_engine()
1113 struct sun4i_drv *drv = drm->dev_private; in sun4i_tcon_bind()
1116 struct sun4i_tcon *tcon; in sun4i_tcon_bind() local
1121 engine = sun4i_tcon_find_engine(drv, dev->of_node); in sun4i_tcon_bind()
1124 return -EPROBE_DEFER; in sun4i_tcon_bind()
1127 tcon = devm_kzalloc(dev, sizeof(*tcon), GFP_KERNEL); in sun4i_tcon_bind()
1128 if (!tcon) in sun4i_tcon_bind()
1129 return -ENOMEM; in sun4i_tcon_bind()
1130 dev_set_drvdata(dev, tcon); in sun4i_tcon_bind()
1131 tcon->drm = drm; in sun4i_tcon_bind()
1132 tcon->dev = dev; in sun4i_tcon_bind()
1133 tcon->id = engine->id; in sun4i_tcon_bind()
1134 tcon->quirks = of_device_get_match_data(dev); in sun4i_tcon_bind()
1136 tcon->lcd_rst = devm_reset_control_get(dev, "lcd"); in sun4i_tcon_bind()
1137 if (IS_ERR(tcon->lcd_rst)) { in sun4i_tcon_bind()
1139 return PTR_ERR(tcon->lcd_rst); in sun4i_tcon_bind()
1142 if (tcon->quirks->needs_edp_reset) { in sun4i_tcon_bind()
1156 /* Make sure our TCON is reset */ in sun4i_tcon_bind()
1157 ret = reset_control_reset(tcon->lcd_rst); in sun4i_tcon_bind()
1163 if (tcon->quirks->supports_lvds) { in sun4i_tcon_bind()
1171 tcon->lvds_rst = devm_reset_control_get_optional(dev, "lvds"); in sun4i_tcon_bind()
1172 if (IS_ERR(tcon->lvds_rst)) { in sun4i_tcon_bind()
1174 return PTR_ERR(tcon->lvds_rst); in sun4i_tcon_bind()
1175 } else if (tcon->lvds_rst) { in sun4i_tcon_bind()
1177 reset_control_reset(tcon->lvds_rst); in sun4i_tcon_bind()
1189 if (tcon->quirks->has_lvds_alt) { in sun4i_tcon_bind()
1190 tcon->lvds_pll = devm_clk_get(dev, "lvds-alt"); in sun4i_tcon_bind()
1191 if (IS_ERR(tcon->lvds_pll)) { in sun4i_tcon_bind()
1192 if (PTR_ERR(tcon->lvds_pll) == -ENOENT) { in sun4i_tcon_bind()
1196 return PTR_ERR(tcon->lvds_pll); in sun4i_tcon_bind()
1204 (tcon->quirks->has_lvds_alt && !has_lvds_alt)) { in sun4i_tcon_bind()
1215 ret = sun4i_tcon_init_clocks(dev, tcon); in sun4i_tcon_bind()
1217 dev_err(dev, "Couldn't init our TCON clocks\n"); in sun4i_tcon_bind()
1221 ret = sun4i_tcon_init_regmap(dev, tcon); in sun4i_tcon_bind()
1223 dev_err(dev, "Couldn't init our TCON regmap\n"); in sun4i_tcon_bind()
1227 if (tcon->quirks->has_channel_0) { in sun4i_tcon_bind()
1228 ret = sun4i_dclk_create(dev, tcon); in sun4i_tcon_bind()
1230 dev_err(dev, "Couldn't create our TCON dot clock\n"); in sun4i_tcon_bind()
1235 ret = sun4i_tcon_init_irq(dev, tcon); in sun4i_tcon_bind()
1237 dev_err(dev, "Couldn't init our TCON interrupts\n"); in sun4i_tcon_bind()
1241 tcon->crtc = sun4i_crtc_init(drm, engine, tcon); in sun4i_tcon_bind()
1242 if (IS_ERR(tcon->crtc)) { in sun4i_tcon_bind()
1244 ret = PTR_ERR(tcon->crtc); in sun4i_tcon_bind()
1248 if (tcon->quirks->has_channel_0) { in sun4i_tcon_bind()
1250 * If we have an LVDS panel connected to the TCON, we should in sun4i_tcon_bind()
1254 remote = of_graph_get_remote_node(dev->of_node, 1, 0); in sun4i_tcon_bind()
1255 if (of_device_is_compatible(remote, "panel-lvds")) in sun4i_tcon_bind()
1257 ret = sun4i_lvds_init(drm, tcon); in sun4i_tcon_bind()
1259 ret = -EINVAL; in sun4i_tcon_bind()
1261 ret = sun4i_rgb_init(drm, tcon); in sun4i_tcon_bind()
1268 if (tcon->quirks->needs_de_be_mux) { in sun4i_tcon_bind()
1274 * the CRTC is tied to the TCON, while the layers are in sun4i_tcon_bind()
1279 regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG, in sun4i_tcon_bind()
1281 tcon->id); in sun4i_tcon_bind()
1282 regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG, in sun4i_tcon_bind()
1284 tcon->id); in sun4i_tcon_bind()
1287 list_add_tail(&tcon->list, &drv->tcon_list); in sun4i_tcon_bind()
1292 if (tcon->quirks->has_channel_0) in sun4i_tcon_bind()
1293 sun4i_dclk_free(tcon); in sun4i_tcon_bind()
1295 reset_control_assert(tcon->lcd_rst); in sun4i_tcon_bind()
1302 struct sun4i_tcon *tcon = dev_get_drvdata(dev); in sun4i_tcon_unbind() local
1304 list_del(&tcon->list); in sun4i_tcon_unbind()
1305 if (tcon->quirks->has_channel_0) in sun4i_tcon_unbind()
1306 sun4i_dclk_free(tcon); in sun4i_tcon_unbind()
1316 struct device_node *node = pdev->dev.of_node; in sun4i_tcon_probe()
1322 quirks = of_device_get_match_data(&pdev->dev); in sun4i_tcon_probe()
1325 if (quirks->has_channel_0) { in sun4i_tcon_probe()
1327 if (ret == -EPROBE_DEFER) in sun4i_tcon_probe()
1331 return component_add(&pdev->dev, &sun4i_tcon_ops); in sun4i_tcon_probe()
1336 component_del(&pdev->dev, &sun4i_tcon_ops); in sun4i_tcon_remove()
1339 /* platform specific TCON muxing callbacks */
1340 static int sun4i_a10_tcon_set_mux(struct sun4i_tcon *tcon, in sun4i_a10_tcon_set_mux() argument
1343 struct sun4i_tcon *tcon0 = sun4i_get_tcon0(encoder->dev); in sun4i_a10_tcon_set_mux()
1347 return -EINVAL; in sun4i_a10_tcon_set_mux()
1349 switch (encoder->encoder_type) { in sun4i_a10_tcon_set_mux()
1355 return -EINVAL; in sun4i_a10_tcon_set_mux()
1358 regmap_update_bits(tcon0->regs, SUN4I_TCON_MUX_CTRL_REG, in sun4i_a10_tcon_set_mux()
1359 0x3 << shift, tcon->id << shift); in sun4i_a10_tcon_set_mux()
1364 static int sun5i_a13_tcon_set_mux(struct sun4i_tcon *tcon, in sun5i_a13_tcon_set_mux() argument
1369 if (encoder->encoder_type == DRM_MODE_ENCODER_TVDAC) in sun5i_a13_tcon_set_mux()
1377 return regmap_write(tcon->regs, SUN4I_TCON_MUX_CTRL_REG, val); in sun5i_a13_tcon_set_mux()
1380 static int sun6i_tcon_set_mux(struct sun4i_tcon *tcon, in sun6i_tcon_set_mux() argument
1383 struct sun4i_tcon *tcon0 = sun4i_get_tcon0(encoder->dev); in sun6i_tcon_set_mux()
1387 return -EINVAL; in sun6i_tcon_set_mux()
1389 switch (encoder->encoder_type) { in sun6i_tcon_set_mux()
1395 /* TODO A31 has MIPI DSI but A31s does not */ in sun6i_tcon_set_mux()
1396 return -EINVAL; in sun6i_tcon_set_mux()
1399 regmap_update_bits(tcon0->regs, SUN4I_TCON_MUX_CTRL_REG, in sun6i_tcon_set_mux()
1400 0x3 << shift, tcon->id << shift); in sun6i_tcon_set_mux()
1405 static int sun8i_r40_tcon_tv_set_mux(struct sun4i_tcon *tcon, in sun8i_r40_tcon_tv_set_mux() argument
1412 /* find TCON TOP platform device and TCON id */ in sun8i_r40_tcon_tv_set_mux()
1414 port = of_graph_get_port_by_id(tcon->dev->of_node, 0); in sun8i_r40_tcon_tv_set_mux()
1416 return -EINVAL; in sun8i_r40_tcon_tv_set_mux()
1421 remote = of_graph_get_remote_node(tcon->dev->of_node, 0, -1); in sun8i_r40_tcon_tv_set_mux()
1423 return -EINVAL; in sun8i_r40_tcon_tv_set_mux()
1428 return -EINVAL; in sun8i_r40_tcon_tv_set_mux()
1431 encoder->encoder_type == DRM_MODE_ENCODER_TMDS) { in sun8i_r40_tcon_tv_set_mux()
1432 ret = sun8i_tcon_top_set_hdmi_src(&pdev->dev, id); in sun8i_r40_tcon_tv_set_mux()
1434 put_device(&pdev->dev); in sun8i_r40_tcon_tv_set_mux()
1440 ret = sun8i_tcon_top_de_config(&pdev->dev, tcon->id, id); in sun8i_r40_tcon_tv_set_mux()
1442 put_device(&pdev->dev); in sun8i_r40_tcon_tv_set_mux()
1545 /* sun4i_drv uses this list to check if a device node is a TCON */
1547 { .compatible = "allwinner,sun4i-a10-tcon", .data = &sun4i_a10_quirks },
1548 { .compatible = "allwinner,sun5i-a13-tcon", .data = &sun5i_a13_quirks },
1549 { .compatible = "allwinner,sun6i-a31-tcon", .data = &sun6i_a31_quirks },
1550 { .compatible = "allwinner,sun6i-a31s-tcon", .data = &sun6i_a31s_quirks },
1551 { .compatible = "allwinner,sun7i-a20-tcon", .data = &sun7i_a20_quirks },
1552 { .compatible = "allwinner,sun7i-a20-tcon0", .data = &sun7i_a20_tcon0_quirks },
1553 { .compatible = "allwinner,sun7i-a20-tcon1", .data = &sun7i_a20_quirks },
1554 { .compatible = "allwinner,sun8i-a23-tcon", .data = &sun8i_a33_quirks },
1555 { .compatible = "allwinner,sun8i-a33-tcon", .data = &sun8i_a33_quirks },
1556 { .compatible = "allwinner,sun8i-a83t-tcon-lcd", .data = &sun8i_a83t_lcd_quirks },
1557 { .compatible = "allwinner,sun8i-a83t-tcon-tv", .data = &sun8i_a83t_tv_quirks },
1558 { .compatible = "allwinner,sun8i-r40-tcon-tv", .data = &sun8i_r40_tv_quirks },
1559 { .compatible = "allwinner,sun8i-v3s-tcon", .data = &sun8i_v3s_quirks },
1560 { .compatible = "allwinner,sun9i-a80-tcon-lcd", .data = &sun9i_a80_tcon_lcd_quirks },
1561 { .compatible = "allwinner,sun9i-a80-tcon-tv", .data = &sun9i_a80_tcon_tv_quirks },
1562 { .compatible = "allwinner,sun20i-d1-tcon-lcd", .data = &sun20i_d1_lcd_quirks },
1563 { .compatible = "allwinner,sun20i-d1-tcon-tv", .data = &sun8i_r40_tv_quirks },
1573 .name = "sun4i-tcon",
1579 MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");