Lines Matching full:dsi

236 static void mtk_dsi_mask(struct mtk_dsi *dsi, u32 offset, u32 mask, u32 data)  in mtk_dsi_mask()  argument
238 u32 temp = readl(dsi->regs + offset); in mtk_dsi_mask()
240 writel((temp & ~mask) | (data & mask), dsi->regs + offset); in mtk_dsi_mask()
243 static void mtk_dsi_phy_timconfig(struct mtk_dsi *dsi) in mtk_dsi_phy_timconfig() argument
246 u32 data_rate_mhz = DIV_ROUND_UP(dsi->data_rate, HZ_PER_MHZ); in mtk_dsi_phy_timconfig()
247 struct mtk_phy_timing *timing = &dsi->phy_timing; in mtk_dsi_phy_timconfig()
285 writel(timcon0, dsi->regs + DSI_PHY_TIMECON0); in mtk_dsi_phy_timconfig()
286 writel(timcon1, dsi->regs + DSI_PHY_TIMECON1); in mtk_dsi_phy_timconfig()
287 writel(timcon2, dsi->regs + DSI_PHY_TIMECON2); in mtk_dsi_phy_timconfig()
288 writel(timcon3, dsi->regs + DSI_PHY_TIMECON3); in mtk_dsi_phy_timconfig()
291 static void mtk_dsi_enable(struct mtk_dsi *dsi) in mtk_dsi_enable() argument
293 mtk_dsi_mask(dsi, DSI_CON_CTRL, DSI_EN, DSI_EN); in mtk_dsi_enable()
296 static void mtk_dsi_disable(struct mtk_dsi *dsi) in mtk_dsi_disable() argument
298 mtk_dsi_mask(dsi, DSI_CON_CTRL, DSI_EN, 0); in mtk_dsi_disable()
301 static void mtk_dsi_reset_engine(struct mtk_dsi *dsi) in mtk_dsi_reset_engine() argument
303 mtk_dsi_mask(dsi, DSI_CON_CTRL, DSI_RESET, DSI_RESET); in mtk_dsi_reset_engine()
304 mtk_dsi_mask(dsi, DSI_CON_CTRL, DSI_RESET, 0); in mtk_dsi_reset_engine()
307 static void mtk_dsi_reset_dphy(struct mtk_dsi *dsi) in mtk_dsi_reset_dphy() argument
309 mtk_dsi_mask(dsi, DSI_CON_CTRL, DPHY_RESET, DPHY_RESET); in mtk_dsi_reset_dphy()
310 mtk_dsi_mask(dsi, DSI_CON_CTRL, DPHY_RESET, 0); in mtk_dsi_reset_dphy()
313 static void mtk_dsi_clk_ulp_mode_enter(struct mtk_dsi *dsi) in mtk_dsi_clk_ulp_mode_enter() argument
315 mtk_dsi_mask(dsi, DSI_PHY_LCCON, LC_HS_TX_EN, 0); in mtk_dsi_clk_ulp_mode_enter()
316 mtk_dsi_mask(dsi, DSI_PHY_LCCON, LC_ULPM_EN, 0); in mtk_dsi_clk_ulp_mode_enter()
319 static void mtk_dsi_clk_ulp_mode_leave(struct mtk_dsi *dsi) in mtk_dsi_clk_ulp_mode_leave() argument
321 mtk_dsi_mask(dsi, DSI_PHY_LCCON, LC_ULPM_EN, 0); in mtk_dsi_clk_ulp_mode_leave()
322 mtk_dsi_mask(dsi, DSI_PHY_LCCON, LC_WAKEUP_EN, LC_WAKEUP_EN); in mtk_dsi_clk_ulp_mode_leave()
323 mtk_dsi_mask(dsi, DSI_PHY_LCCON, LC_WAKEUP_EN, 0); in mtk_dsi_clk_ulp_mode_leave()
326 static void mtk_dsi_lane0_ulp_mode_enter(struct mtk_dsi *dsi) in mtk_dsi_lane0_ulp_mode_enter() argument
328 mtk_dsi_mask(dsi, DSI_PHY_LD0CON, LD0_HS_TX_EN, 0); in mtk_dsi_lane0_ulp_mode_enter()
329 mtk_dsi_mask(dsi, DSI_PHY_LD0CON, LD0_ULPM_EN, 0); in mtk_dsi_lane0_ulp_mode_enter()
332 static void mtk_dsi_lane0_ulp_mode_leave(struct mtk_dsi *dsi) in mtk_dsi_lane0_ulp_mode_leave() argument
334 mtk_dsi_mask(dsi, DSI_PHY_LD0CON, LD0_ULPM_EN, 0); in mtk_dsi_lane0_ulp_mode_leave()
335 mtk_dsi_mask(dsi, DSI_PHY_LD0CON, LD0_WAKEUP_EN, LD0_WAKEUP_EN); in mtk_dsi_lane0_ulp_mode_leave()
336 mtk_dsi_mask(dsi, DSI_PHY_LD0CON, LD0_WAKEUP_EN, 0); in mtk_dsi_lane0_ulp_mode_leave()
339 static bool mtk_dsi_clk_hs_state(struct mtk_dsi *dsi) in mtk_dsi_clk_hs_state() argument
341 return readl(dsi->regs + DSI_PHY_LCCON) & LC_HS_TX_EN; in mtk_dsi_clk_hs_state()
344 static void mtk_dsi_clk_hs_mode(struct mtk_dsi *dsi, bool enter) in mtk_dsi_clk_hs_mode() argument
346 if (enter && !mtk_dsi_clk_hs_state(dsi)) in mtk_dsi_clk_hs_mode()
347 mtk_dsi_mask(dsi, DSI_PHY_LCCON, LC_HS_TX_EN, LC_HS_TX_EN); in mtk_dsi_clk_hs_mode()
348 else if (!enter && mtk_dsi_clk_hs_state(dsi)) in mtk_dsi_clk_hs_mode()
349 mtk_dsi_mask(dsi, DSI_PHY_LCCON, LC_HS_TX_EN, 0); in mtk_dsi_clk_hs_mode()
352 static void mtk_dsi_set_mode(struct mtk_dsi *dsi) in mtk_dsi_set_mode() argument
356 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO) { in mtk_dsi_set_mode()
357 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST) in mtk_dsi_set_mode()
359 else if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) in mtk_dsi_set_mode()
365 writel(vid_mode, dsi->regs + DSI_MODE_CTRL); in mtk_dsi_set_mode()
368 static void mtk_dsi_set_vm_cmd(struct mtk_dsi *dsi) in mtk_dsi_set_vm_cmd() argument
370 mtk_dsi_mask(dsi, DSI_VM_CMD_CON, VM_CMD_EN, VM_CMD_EN); in mtk_dsi_set_vm_cmd()
371 mtk_dsi_mask(dsi, DSI_VM_CMD_CON, TS_VFP_EN, TS_VFP_EN); in mtk_dsi_set_vm_cmd()
374 static void mtk_dsi_rxtx_control(struct mtk_dsi *dsi) in mtk_dsi_rxtx_control() argument
379 /* Number of DSI lanes (max 4 lanes), each bit enables one DSI lane. */ in mtk_dsi_rxtx_control()
380 for (i = 0; i < dsi->lanes; i++) in mtk_dsi_rxtx_control()
385 if (dsi->mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) in mtk_dsi_rxtx_control()
388 if (dsi->mode_flags & MIPI_DSI_MODE_NO_EOT_PACKET) in mtk_dsi_rxtx_control()
391 writel(regval, dsi->regs + DSI_TXRX_CTRL); in mtk_dsi_rxtx_control()
394 static void mtk_dsi_ps_control(struct mtk_dsi *dsi, bool config_vact) in mtk_dsi_ps_control() argument
398 if (dsi->format == MIPI_DSI_FMT_RGB565) in mtk_dsi_ps_control()
404 ps_wc = FIELD_PREP(DSI_PS_WC, dsi->vm.hactive * dsi_buf_bpp); in mtk_dsi_ps_control()
408 switch (dsi->format) { in mtk_dsi_ps_control()
426 vact_nl = FIELD_PREP(VACT_NL, dsi->vm.vactive); in mtk_dsi_ps_control()
427 writel(vact_nl, dsi->regs + DSI_VACT_NL); in mtk_dsi_ps_control()
428 writel(ps_wc, dsi->regs + DSI_HSTX_CKL_WC); in mtk_dsi_ps_control()
430 writel(ps_val, dsi->regs + DSI_PSCTRL); in mtk_dsi_ps_control()
433 static void mtk_dsi_config_vdo_timing_per_frame_lp(struct mtk_dsi *dsi) in mtk_dsi_config_vdo_timing_per_frame_lp() argument
445 struct videomode *vm = &dsi->vm; in mtk_dsi_config_vdo_timing_per_frame_lp()
447 if (dsi->format == MIPI_DSI_FMT_RGB565) in mtk_dsi_config_vdo_timing_per_frame_lp()
452 da_hs_trail = dsi->phy_timing.da_hs_trail; in mtk_dsi_config_vdo_timing_per_frame_lp()
455 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) { in mtk_dsi_config_vdo_timing_per_frame_lp()
470 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST) { in mtk_dsi_config_vdo_timing_per_frame_lp()
480 horizontal_frontporch_byte) % dsi->lanes; in mtk_dsi_config_vdo_timing_per_frame_lp()
482 horizontal_backporch_byte += dsi->lanes - v_active_roundup; in mtk_dsi_config_vdo_timing_per_frame_lp()
483 hstx_cklp_wc_min = (DIV_ROUND_UP(cklp_wc_min_adjust, dsi->lanes) + da_hs_trail + 1) in mtk_dsi_config_vdo_timing_per_frame_lp()
484 * dsi->lanes / 6 - 1; in mtk_dsi_config_vdo_timing_per_frame_lp()
486 ps_wc), dsi->lanes) + da_hs_trail + 1) * dsi->lanes / 6 - 1; in mtk_dsi_config_vdo_timing_per_frame_lp()
489 writel(hstx_cklp_wc, dsi->regs + DSI_HSTX_CKL_WC); in mtk_dsi_config_vdo_timing_per_frame_lp()
491 hs_vb_ps_wc = ps_wc - (dsi->phy_timing.lpx + dsi->phy_timing.da_hs_exit + in mtk_dsi_config_vdo_timing_per_frame_lp()
492 dsi->phy_timing.da_hs_prepare + dsi->phy_timing.da_hs_zero + 2) * dsi->lanes; in mtk_dsi_config_vdo_timing_per_frame_lp()
496 writel(horizontal_sync_active_byte, dsi->regs + DSI_HSA_WC); in mtk_dsi_config_vdo_timing_per_frame_lp()
497 writel(horizontal_backporch_byte, dsi->regs + DSI_HBP_WC); in mtk_dsi_config_vdo_timing_per_frame_lp()
498 writel(horizontal_frontporch_byte, dsi->regs + DSI_HFP_WC); in mtk_dsi_config_vdo_timing_per_frame_lp()
501 static void mtk_dsi_config_vdo_timing_per_line_lp(struct mtk_dsi *dsi) in mtk_dsi_config_vdo_timing_per_line_lp() argument
510 struct mtk_phy_timing *timing = &dsi->phy_timing; in mtk_dsi_config_vdo_timing_per_line_lp()
511 struct videomode *vm = &dsi->vm; in mtk_dsi_config_vdo_timing_per_line_lp()
513 if (dsi->format == MIPI_DSI_FMT_RGB565) in mtk_dsi_config_vdo_timing_per_line_lp()
520 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) in mtk_dsi_config_vdo_timing_per_line_lp()
529 delta = dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST ? 18 : 12; in mtk_dsi_config_vdo_timing_per_line_lp()
530 delta += dsi->mode_flags & MIPI_DSI_MODE_NO_EOT_PACKET ? 0 : 2; in mtk_dsi_config_vdo_timing_per_line_lp()
534 data_phy_cycles_byte = data_phy_cycles * dsi->lanes + delta; in mtk_dsi_config_vdo_timing_per_line_lp()
548 if ((dsi->mode_flags & MIPI_DSI_HS_PKT_END_ALIGNED) && in mtk_dsi_config_vdo_timing_per_line_lp()
549 (dsi->lanes == 4)) { in mtk_dsi_config_vdo_timing_per_line_lp()
551 roundup(horizontal_sync_active_byte, dsi->lanes) - 2; in mtk_dsi_config_vdo_timing_per_line_lp()
553 roundup(horizontal_frontporch_byte, dsi->lanes) - 2; in mtk_dsi_config_vdo_timing_per_line_lp()
555 roundup(horizontal_backporch_byte, dsi->lanes) - 2; in mtk_dsi_config_vdo_timing_per_line_lp()
557 (vm->hactive * dsi_tmp_buf_bpp + 2) % dsi->lanes; in mtk_dsi_config_vdo_timing_per_line_lp()
560 writel(horizontal_sync_active_byte, dsi->regs + DSI_HSA_WC); in mtk_dsi_config_vdo_timing_per_line_lp()
561 writel(horizontal_backporch_byte, dsi->regs + DSI_HBP_WC); in mtk_dsi_config_vdo_timing_per_line_lp()
562 writel(horizontal_frontporch_byte, dsi->regs + DSI_HFP_WC); in mtk_dsi_config_vdo_timing_per_line_lp()
565 static void mtk_dsi_config_vdo_timing(struct mtk_dsi *dsi) in mtk_dsi_config_vdo_timing() argument
567 struct videomode *vm = &dsi->vm; in mtk_dsi_config_vdo_timing()
569 writel(vm->vsync_len, dsi->regs + DSI_VSA_NL); in mtk_dsi_config_vdo_timing()
570 writel(vm->vback_porch, dsi->regs + DSI_VBP_NL); in mtk_dsi_config_vdo_timing()
571 writel(vm->vfront_porch, dsi->regs + DSI_VFP_NL); in mtk_dsi_config_vdo_timing()
572 writel(vm->vactive, dsi->regs + DSI_VACT_NL); in mtk_dsi_config_vdo_timing()
574 if (dsi->driver_data->has_size_ctl) in mtk_dsi_config_vdo_timing()
577 dsi->regs + DSI_SIZE_CON); in mtk_dsi_config_vdo_timing()
579 if (dsi->driver_data->support_per_frame_lp) in mtk_dsi_config_vdo_timing()
580 mtk_dsi_config_vdo_timing_per_frame_lp(dsi); in mtk_dsi_config_vdo_timing()
582 mtk_dsi_config_vdo_timing_per_line_lp(dsi); in mtk_dsi_config_vdo_timing()
584 mtk_dsi_ps_control(dsi, false); in mtk_dsi_config_vdo_timing()
587 static void mtk_dsi_start(struct mtk_dsi *dsi) in mtk_dsi_start() argument
589 writel(0, dsi->regs + DSI_START); in mtk_dsi_start()
590 writel(1, dsi->regs + DSI_START); in mtk_dsi_start()
593 static void mtk_dsi_stop(struct mtk_dsi *dsi) in mtk_dsi_stop() argument
595 writel(0, dsi->regs + DSI_START); in mtk_dsi_stop()
598 static void mtk_dsi_set_cmd_mode(struct mtk_dsi *dsi) in mtk_dsi_set_cmd_mode() argument
600 writel(CMD_MODE, dsi->regs + DSI_MODE_CTRL); in mtk_dsi_set_cmd_mode()
603 static void mtk_dsi_set_interrupt_enable(struct mtk_dsi *dsi) in mtk_dsi_set_interrupt_enable() argument
607 writel(inten, dsi->regs + DSI_INTEN); in mtk_dsi_set_interrupt_enable()
610 static void mtk_dsi_irq_data_set(struct mtk_dsi *dsi, u32 irq_bit) in mtk_dsi_irq_data_set() argument
612 dsi->irq_data |= irq_bit; in mtk_dsi_irq_data_set()
615 static void mtk_dsi_irq_data_clear(struct mtk_dsi *dsi, u32 irq_bit) in mtk_dsi_irq_data_clear() argument
617 dsi->irq_data &= ~irq_bit; in mtk_dsi_irq_data_clear()
620 static s32 mtk_dsi_wait_for_irq_done(struct mtk_dsi *dsi, u32 irq_flag, in mtk_dsi_wait_for_irq_done() argument
626 ret = wait_event_interruptible_timeout(dsi->irq_wait_queue, in mtk_dsi_wait_for_irq_done()
627 dsi->irq_data & irq_flag, in mtk_dsi_wait_for_irq_done()
630 DRM_WARN("Wait DSI IRQ(0x%08x) Timeout\n", irq_flag); in mtk_dsi_wait_for_irq_done()
632 mtk_dsi_enable(dsi); in mtk_dsi_wait_for_irq_done()
633 mtk_dsi_reset_engine(dsi); in mtk_dsi_wait_for_irq_done()
641 struct mtk_dsi *dsi = dev_id; in mtk_dsi_irq() local
645 status = readl(dsi->regs + DSI_INTSTA) & flag; in mtk_dsi_irq()
649 mtk_dsi_mask(dsi, DSI_RACK, RACK, RACK); in mtk_dsi_irq()
650 tmp = readl(dsi->regs + DSI_INTSTA); in mtk_dsi_irq()
653 mtk_dsi_mask(dsi, DSI_INTSTA, status, 0); in mtk_dsi_irq()
654 mtk_dsi_irq_data_set(dsi, status); in mtk_dsi_irq()
655 wake_up_interruptible(&dsi->irq_wait_queue); in mtk_dsi_irq()
661 static s32 mtk_dsi_switch_to_cmd_mode(struct mtk_dsi *dsi, u8 irq_flag, u32 t) in mtk_dsi_switch_to_cmd_mode() argument
663 mtk_dsi_irq_data_clear(dsi, irq_flag); in mtk_dsi_switch_to_cmd_mode()
664 mtk_dsi_set_cmd_mode(dsi); in mtk_dsi_switch_to_cmd_mode()
666 if (!mtk_dsi_wait_for_irq_done(dsi, irq_flag, t)) { in mtk_dsi_switch_to_cmd_mode()
674 static int mtk_dsi_poweron(struct mtk_dsi *dsi) in mtk_dsi_poweron() argument
676 struct device *dev = dsi->host.dev; in mtk_dsi_poweron()
680 if (++dsi->refcount != 1) in mtk_dsi_poweron()
683 ret = mipi_dsi_pixel_format_to_bpp(dsi->format); in mtk_dsi_poweron()
685 dev_err(dev, "Unknown MIPI DSI format %d\n", dsi->format); in mtk_dsi_poweron()
690 dsi->data_rate = DIV_ROUND_UP_ULL(dsi->vm.pixelclock * bit_per_pixel, in mtk_dsi_poweron()
691 dsi->lanes); in mtk_dsi_poweron()
693 ret = clk_set_rate(dsi->hs_clk, dsi->data_rate); in mtk_dsi_poweron()
699 phy_power_on(dsi->phy); in mtk_dsi_poweron()
701 ret = clk_prepare_enable(dsi->engine_clk); in mtk_dsi_poweron()
707 ret = clk_prepare_enable(dsi->digital_clk); in mtk_dsi_poweron()
713 mtk_dsi_enable(dsi); in mtk_dsi_poweron()
715 if (dsi->driver_data->has_shadow_ctl) in mtk_dsi_poweron()
717 dsi->regs + DSI_SHADOW_DEBUG); in mtk_dsi_poweron()
719 mtk_dsi_reset_engine(dsi); in mtk_dsi_poweron()
720 mtk_dsi_phy_timconfig(dsi); in mtk_dsi_poweron()
722 mtk_dsi_ps_control(dsi, true); in mtk_dsi_poweron()
723 mtk_dsi_set_vm_cmd(dsi); in mtk_dsi_poweron()
724 mtk_dsi_config_vdo_timing(dsi); in mtk_dsi_poweron()
725 mtk_dsi_set_interrupt_enable(dsi); in mtk_dsi_poweron()
729 clk_disable_unprepare(dsi->engine_clk); in mtk_dsi_poweron()
731 phy_power_off(dsi->phy); in mtk_dsi_poweron()
733 dsi->refcount--; in mtk_dsi_poweron()
737 static void mtk_dsi_poweroff(struct mtk_dsi *dsi) in mtk_dsi_poweroff() argument
739 if (WARN_ON(dsi->refcount == 0)) in mtk_dsi_poweroff()
742 if (--dsi->refcount != 0) in mtk_dsi_poweroff()
750 * after dsi is fully set. in mtk_dsi_poweroff()
752 mtk_dsi_stop(dsi); in mtk_dsi_poweroff()
754 mtk_dsi_switch_to_cmd_mode(dsi, VM_DONE_INT_FLAG, 500); in mtk_dsi_poweroff()
755 mtk_dsi_reset_engine(dsi); in mtk_dsi_poweroff()
756 mtk_dsi_lane0_ulp_mode_enter(dsi); in mtk_dsi_poweroff()
757 mtk_dsi_clk_ulp_mode_enter(dsi); in mtk_dsi_poweroff()
759 writel(0, dsi->regs + DSI_TXRX_CTRL); in mtk_dsi_poweroff()
761 mtk_dsi_disable(dsi); in mtk_dsi_poweroff()
763 clk_disable_unprepare(dsi->engine_clk); in mtk_dsi_poweroff()
764 clk_disable_unprepare(dsi->digital_clk); in mtk_dsi_poweroff()
766 phy_power_off(dsi->phy); in mtk_dsi_poweroff()
768 dsi->lanes_ready = false; in mtk_dsi_poweroff()
771 static void mtk_dsi_lane_ready(struct mtk_dsi *dsi) in mtk_dsi_lane_ready() argument
773 if (!dsi->lanes_ready) { in mtk_dsi_lane_ready()
774 dsi->lanes_ready = true; in mtk_dsi_lane_ready()
775 mtk_dsi_rxtx_control(dsi); in mtk_dsi_lane_ready()
777 mtk_dsi_reset_dphy(dsi); in mtk_dsi_lane_ready()
778 mtk_dsi_clk_ulp_mode_leave(dsi); in mtk_dsi_lane_ready()
779 mtk_dsi_lane0_ulp_mode_leave(dsi); in mtk_dsi_lane_ready()
780 mtk_dsi_clk_hs_mode(dsi, 0); in mtk_dsi_lane_ready()
786 static void mtk_output_dsi_enable(struct mtk_dsi *dsi) in mtk_output_dsi_enable() argument
788 if (dsi->enabled) in mtk_output_dsi_enable()
791 mtk_dsi_lane_ready(dsi); in mtk_output_dsi_enable()
792 mtk_dsi_set_mode(dsi); in mtk_output_dsi_enable()
793 mtk_dsi_clk_hs_mode(dsi, 1); in mtk_output_dsi_enable()
795 mtk_dsi_start(dsi); in mtk_output_dsi_enable()
797 dsi->enabled = true; in mtk_output_dsi_enable()
800 static void mtk_output_dsi_disable(struct mtk_dsi *dsi) in mtk_output_dsi_disable() argument
802 if (!dsi->enabled) in mtk_output_dsi_disable()
805 dsi->enabled = false; in mtk_output_dsi_disable()
811 struct mtk_dsi *dsi = bridge_to_dsi(bridge); in mtk_dsi_bridge_attach() local
813 /* Attach the panel or bridge to the dsi bridge */ in mtk_dsi_bridge_attach()
814 return drm_bridge_attach(bridge->encoder, dsi->next_bridge, in mtk_dsi_bridge_attach()
815 &dsi->bridge, flags); in mtk_dsi_bridge_attach()
822 struct mtk_dsi *dsi = bridge_to_dsi(bridge); in mtk_dsi_bridge_mode_set() local
824 drm_display_mode_to_videomode(adjusted, &dsi->vm); in mtk_dsi_bridge_mode_set()
830 struct mtk_dsi *dsi = bridge_to_dsi(bridge); in mtk_dsi_bridge_atomic_disable() local
832 mtk_output_dsi_disable(dsi); in mtk_dsi_bridge_atomic_disable()
838 struct mtk_dsi *dsi = bridge_to_dsi(bridge); in mtk_dsi_bridge_atomic_enable() local
840 if (dsi->refcount == 0) in mtk_dsi_bridge_atomic_enable()
843 mtk_output_dsi_enable(dsi); in mtk_dsi_bridge_atomic_enable()
849 struct mtk_dsi *dsi = bridge_to_dsi(bridge); in mtk_dsi_bridge_atomic_pre_enable() local
852 ret = mtk_dsi_poweron(dsi); in mtk_dsi_bridge_atomic_pre_enable()
854 DRM_ERROR("failed to power on dsi\n"); in mtk_dsi_bridge_atomic_pre_enable()
860 struct mtk_dsi *dsi = bridge_to_dsi(bridge); in mtk_dsi_bridge_atomic_post_disable() local
862 mtk_dsi_poweroff(dsi); in mtk_dsi_bridge_atomic_post_disable()
870 struct mtk_dsi *dsi = bridge_to_dsi(bridge); in mtk_dsi_bridge_mode_valid() local
873 bpp = mipi_dsi_pixel_format_to_bpp(dsi->format); in mtk_dsi_bridge_mode_valid()
877 if (mode->clock * bpp / dsi->lanes > 1500000) in mtk_dsi_bridge_mode_valid()
898 struct mtk_dsi *dsi = dev_get_drvdata(dev); in mtk_dsi_ddp_start() local
900 mtk_dsi_poweron(dsi); in mtk_dsi_ddp_start()
905 struct mtk_dsi *dsi = dev_get_drvdata(dev); in mtk_dsi_ddp_stop() local
907 mtk_dsi_poweroff(dsi); in mtk_dsi_ddp_stop()
910 static int mtk_dsi_encoder_init(struct drm_device *drm, struct mtk_dsi *dsi) in mtk_dsi_encoder_init() argument
914 ret = drm_simple_encoder_init(drm, &dsi->encoder, in mtk_dsi_encoder_init()
921 ret = mtk_find_possible_crtcs(drm, dsi->host.dev); in mtk_dsi_encoder_init()
924 dsi->encoder.possible_crtcs = ret; in mtk_dsi_encoder_init()
926 ret = drm_bridge_attach(&dsi->encoder, &dsi->bridge, NULL, in mtk_dsi_encoder_init()
931 dsi->connector = drm_bridge_connector_init(drm, &dsi->encoder); in mtk_dsi_encoder_init()
932 if (IS_ERR(dsi->connector)) { in mtk_dsi_encoder_init()
934 ret = PTR_ERR(dsi->connector); in mtk_dsi_encoder_init()
937 drm_connector_attach_encoder(dsi->connector, &dsi->encoder); in mtk_dsi_encoder_init()
942 drm_encoder_cleanup(&dsi->encoder); in mtk_dsi_encoder_init()
948 struct mtk_dsi *dsi = dev_get_drvdata(dev); in mtk_dsi_encoder_index() local
949 unsigned int encoder_index = drm_encoder_index(&dsi->encoder); in mtk_dsi_encoder_index()
959 struct mtk_dsi *dsi = dev_get_drvdata(dev); in mtk_dsi_bind() local
961 ret = mtk_dsi_encoder_init(drm, dsi); in mtk_dsi_bind()
971 struct mtk_dsi *dsi = dev_get_drvdata(dev); in mtk_dsi_unbind() local
973 drm_encoder_cleanup(&dsi->encoder); in mtk_dsi_unbind()
984 struct mtk_dsi *dsi = host_to_dsi(host); in mtk_dsi_host_attach() local
988 dsi->lanes = device->lanes; in mtk_dsi_host_attach()
989 dsi->format = device->format; in mtk_dsi_host_attach()
990 dsi->mode_flags = device->mode_flags; in mtk_dsi_host_attach()
991 dsi->next_bridge = devm_drm_of_get_bridge(dev, dev->of_node, 0, 0); in mtk_dsi_host_attach()
992 if (IS_ERR(dsi->next_bridge)) in mtk_dsi_host_attach()
993 return PTR_ERR(dsi->next_bridge); in mtk_dsi_host_attach()
995 drm_bridge_add(&dsi->bridge); in mtk_dsi_host_attach()
1000 drm_bridge_remove(&dsi->bridge); in mtk_dsi_host_attach()
1010 struct mtk_dsi *dsi = host_to_dsi(host); in mtk_dsi_host_detach() local
1013 drm_bridge_remove(&dsi->bridge); in mtk_dsi_host_detach()
1017 static void mtk_dsi_wait_for_idle(struct mtk_dsi *dsi) in mtk_dsi_wait_for_idle() argument
1022 ret = readl_poll_timeout(dsi->regs + DSI_INTSTA, val, !(val & DSI_BUSY), in mtk_dsi_wait_for_idle()
1025 DRM_WARN("polling dsi wait not busy timeout!\n"); in mtk_dsi_wait_for_idle()
1027 mtk_dsi_enable(dsi); in mtk_dsi_wait_for_idle()
1028 mtk_dsi_reset_engine(dsi); in mtk_dsi_wait_for_idle()
1055 static void mtk_dsi_cmdq(struct mtk_dsi *dsi, const struct mipi_dsi_msg *msg) in mtk_dsi_cmdq() argument
1060 u32 reg_cmdq_off = dsi->driver_data->reg_cmdq_off; in mtk_dsi_cmdq()
1080 mtk_dsi_mask(dsi, (reg_cmdq_off + cmdq_off + i) & (~0x3U), in mtk_dsi_cmdq()
1084 mtk_dsi_mask(dsi, reg_cmdq_off, cmdq_mask, reg_val); in mtk_dsi_cmdq()
1085 mtk_dsi_mask(dsi, DSI_CMDQ_SIZE, CMDQ_SIZE, cmdq_size); in mtk_dsi_cmdq()
1086 if (dsi->driver_data->cmdq_long_packet_ctl) { in mtk_dsi_cmdq()
1088 mtk_dsi_mask(dsi, DSI_CMDQ_SIZE, CMDQ_SIZE_SEL, CMDQ_SIZE_SEL); in mtk_dsi_cmdq()
1092 static ssize_t mtk_dsi_host_send_cmd(struct mtk_dsi *dsi, in mtk_dsi_host_send_cmd() argument
1095 mtk_dsi_wait_for_idle(dsi); in mtk_dsi_host_send_cmd()
1096 mtk_dsi_irq_data_clear(dsi, flag); in mtk_dsi_host_send_cmd()
1097 mtk_dsi_cmdq(dsi, msg); in mtk_dsi_host_send_cmd()
1098 mtk_dsi_start(dsi); in mtk_dsi_host_send_cmd()
1100 if (!mtk_dsi_wait_for_irq_done(dsi, flag, 2000)) in mtk_dsi_host_send_cmd()
1109 struct mtk_dsi *dsi = host_to_dsi(host); in mtk_dsi_host_transfer() local
1117 dsi_mode = readl(dsi->regs + DSI_MODE_CTRL); in mtk_dsi_host_transfer()
1119 mtk_dsi_stop(dsi); in mtk_dsi_host_transfer()
1120 ret = mtk_dsi_switch_to_cmd_mode(dsi, VM_DONE_INT_FLAG, 500); in mtk_dsi_host_transfer()
1128 mtk_dsi_lane_ready(dsi); in mtk_dsi_host_transfer()
1130 ret = mtk_dsi_host_send_cmd(dsi, msg, irq_flag); in mtk_dsi_host_transfer()
1140 DRM_ERROR("dsi receive buffer size may be NULL\n"); in mtk_dsi_host_transfer()
1146 *(read_data + i) = readb(dsi->regs + DSI_RX_DATA0 + i); in mtk_dsi_host_transfer()
1164 DRM_INFO("dsi get %d byte data from the panel address(0x%x)\n", in mtk_dsi_host_transfer()
1169 mtk_dsi_set_mode(dsi); in mtk_dsi_host_transfer()
1170 mtk_dsi_start(dsi); in mtk_dsi_host_transfer()
1184 struct mtk_dsi *dsi; in mtk_dsi_probe() local
1190 dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL); in mtk_dsi_probe()
1191 if (!dsi) in mtk_dsi_probe()
1194 dsi->driver_data = of_device_get_match_data(dev); in mtk_dsi_probe()
1196 dsi->engine_clk = devm_clk_get(dev, "engine"); in mtk_dsi_probe()
1197 if (IS_ERR(dsi->engine_clk)) in mtk_dsi_probe()
1198 return dev_err_probe(dev, PTR_ERR(dsi->engine_clk), in mtk_dsi_probe()
1202 dsi->digital_clk = devm_clk_get(dev, "digital"); in mtk_dsi_probe()
1203 if (IS_ERR(dsi->digital_clk)) in mtk_dsi_probe()
1204 return dev_err_probe(dev, PTR_ERR(dsi->digital_clk), in mtk_dsi_probe()
1207 dsi->hs_clk = devm_clk_get(dev, "hs"); in mtk_dsi_probe()
1208 if (IS_ERR(dsi->hs_clk)) in mtk_dsi_probe()
1209 return dev_err_probe(dev, PTR_ERR(dsi->hs_clk), "Failed to get hs clock\n"); in mtk_dsi_probe()
1212 dsi->regs = devm_ioremap_resource(dev, regs); in mtk_dsi_probe()
1213 if (IS_ERR(dsi->regs)) in mtk_dsi_probe()
1214 return dev_err_probe(dev, PTR_ERR(dsi->regs), "Failed to ioremap memory\n"); in mtk_dsi_probe()
1216 dsi->phy = devm_phy_get(dev, "dphy"); in mtk_dsi_probe()
1217 if (IS_ERR(dsi->phy)) in mtk_dsi_probe()
1218 return dev_err_probe(dev, PTR_ERR(dsi->phy), "Failed to get MIPI-DPHY\n"); in mtk_dsi_probe()
1224 dsi->host.ops = &mtk_dsi_ops; in mtk_dsi_probe()
1225 dsi->host.dev = dev; in mtk_dsi_probe()
1226 ret = mipi_dsi_host_register(&dsi->host); in mtk_dsi_probe()
1228 return dev_err_probe(dev, ret, "Failed to register DSI host\n"); in mtk_dsi_probe()
1231 IRQF_TRIGGER_NONE, dev_name(&pdev->dev), dsi); in mtk_dsi_probe()
1233 mipi_dsi_host_unregister(&dsi->host); in mtk_dsi_probe()
1234 return dev_err_probe(&pdev->dev, ret, "Failed to request DSI irq\n"); in mtk_dsi_probe()
1237 init_waitqueue_head(&dsi->irq_wait_queue); in mtk_dsi_probe()
1239 platform_set_drvdata(pdev, dsi); in mtk_dsi_probe()
1241 dsi->bridge.funcs = &mtk_dsi_bridge_funcs; in mtk_dsi_probe()
1242 dsi->bridge.of_node = dev->of_node; in mtk_dsi_probe()
1243 dsi->bridge.type = DRM_MODE_CONNECTOR_DSI; in mtk_dsi_probe()
1250 struct mtk_dsi *dsi = platform_get_drvdata(pdev); in mtk_dsi_remove() local
1252 mtk_output_dsi_disable(dsi); in mtk_dsi_remove()
1253 mipi_dsi_host_unregister(&dsi->host); in mtk_dsi_remove()
1285 { .compatible = "mediatek,mt2701-dsi", .data = &mt2701_dsi_driver_data },
1286 { .compatible = "mediatek,mt8173-dsi", .data = &mt8173_dsi_driver_data },
1287 { .compatible = "mediatek,mt8183-dsi", .data = &mt8183_dsi_driver_data },
1288 { .compatible = "mediatek,mt8186-dsi", .data = &mt8186_dsi_driver_data },
1289 { .compatible = "mediatek,mt8188-dsi", .data = &mt8188_dsi_driver_data },
1298 .name = "mtk-dsi",