Lines Matching +full:sharkl3 +full:- +full:dpu
1 // SPDX-License-Identifier: GPL-2.0
139 return (readl(ctx->base + offset) & mask) >> shift; in dsi_reg_rd()
148 ret = readl(ctx->base + offset); in dsi_reg_wr()
151 writel(ret, ctx->base + offset); in dsi_reg_wr()
158 u32 ret = readl(ctx->base + offset); in dsi_reg_up()
160 writel((ret & ~mask) | (val & mask), ctx->base + offset); in dsi_reg_up()
166 struct dsi_context *ctx = &dsi->ctx; in regmap_tst_io_write()
169 return -EINVAL; in regmap_tst_io_write()
171 drm_dbg(dsi->drm, "reg = 0x%02x, val = 0x%02x\n", reg, val); in regmap_tst_io_write()
188 struct dsi_context *ctx = &dsi->ctx; in regmap_tst_io_read()
192 return -EINVAL; in regmap_tst_io_read()
208 drm_dbg(dsi->drm, "reg = 0x%02x, val = 0x%02x\n", reg, *val); in regmap_tst_io_read()
233 drm_err(dsi->drm, "dphy pll can not be locked\n"); in dphy_wait_pll_locked()
234 return -ETIMEDOUT; in dphy_wait_pll_locked()
247 return -ETIMEDOUT; in dsi_wait_tx_payload_fifo_empty()
260 return -ETIMEDOUT; in dsi_wait_tx_cmd_fifo_empty()
273 return -ETIMEDOUT; in dsi_wait_rd_resp_completed()
392 u32 byte_clk = dsi->slave->hs_rate / 8; in sprd_dsi_init()
397 writel(0, ctx->base + SOFT_RESET); in sprd_dsi_init()
398 writel(0xffffffff, ctx->base + MASK_PROTOCOL_INT); in sprd_dsi_init()
399 writel(0xffffffff, ctx->base + MASK_INTERNAL_INT); in sprd_dsi_init()
400 writel(1, ctx->base + DSI_MODE_CFG); in sprd_dsi_init()
405 writel(1, ctx->base + TA_EN); in sprd_dsi_init()
409 div = DIV_ROUND_UP(byte_clk, dsi->slave->lp_rate); in sprd_dsi_init()
410 writel(div, ctx->base + TX_ESC_CLK_CONFIG); in sprd_dsi_init()
412 max_rd_time = ns_to_cycle(ctx->max_rd_time, byte_clk); in sprd_dsi_init()
413 writel(max_rd_time, ctx->base + MAX_READ_TIME); in sprd_dsi_init()
415 data_hs2lp = ns_to_cycle(ctx->data_hs2lp, byte_clk); in sprd_dsi_init()
416 data_lp2hs = ns_to_cycle(ctx->data_lp2hs, byte_clk); in sprd_dsi_init()
417 clk_hs2lp = ns_to_cycle(ctx->clk_hs2lp, byte_clk); in sprd_dsi_init()
418 clk_lp2hs = ns_to_cycle(ctx->clk_lp2hs, byte_clk); in sprd_dsi_init()
428 writel(1, ctx->base + SOFT_RESET); in sprd_dsi_init()
436 writel(0xffffffff, ctx->base + MASK_PROTOCOL_INT); in sprd_dsi_fini()
437 writel(0xffffffff, ctx->base + MASK_INTERNAL_INT); in sprd_dsi_fini()
438 writel(0, ctx->base + SOFT_RESET); in sprd_dsi_fini()
450 struct videomode *vm = &ctx->vm; in sprd_dsi_dpi_video()
451 u32 byte_clk = dsi->slave->hs_rate / 8; in sprd_dsi_dpi_video()
469 coding = fmt_to_coding(dsi->slave->format); in sprd_dsi_dpi_video()
470 video_size = round_video_size(coding, vm->hactive); in sprd_dsi_dpi_video()
473 ratio_x1000 = byte_clk * 1000 / (vm->pixelclock / 1000); in sprd_dsi_dpi_video()
474 hline = vm->hactive + vm->hsync_len + vm->hfront_porch + in sprd_dsi_dpi_video()
475 vm->hback_porch; in sprd_dsi_dpi_video()
477 writel(0, ctx->base + SOFT_RESET); in sprd_dsi_dpi_video()
478 dsi_reg_wr(ctx, VID_MODE_CFG, FRAME_BTA_ACK_EN, 15, ctx->frame_ack_en); in sprd_dsi_dpi_video()
480 dsi_reg_wr(ctx, VID_MODE_CFG, VID_MODE_TYPE, 0, ctx->burst_mode); in sprd_dsi_dpi_video()
484 writel(byte_cycle, ctx->base + VIDEO_LINE_TIME); in sprd_dsi_dpi_video()
485 byte_cycle = vm->hsync_len * ratio_x1000 / 1000; in sprd_dsi_dpi_video()
487 byte_cycle = vm->hback_porch * ratio_x1000 / 1000; in sprd_dsi_dpi_video()
489 writel(vm->vactive, ctx->base + VIDEO_VACTIVE_LINES); in sprd_dsi_dpi_video()
490 dsi_reg_wr(ctx, VIDEO_VBLK_LINES, VFP_LINES, 0, vm->vfront_porch); in sprd_dsi_dpi_video()
491 dsi_reg_wr(ctx, VIDEO_VBLK_LINES, VBP_LINES, 10, vm->vback_porch); in sprd_dsi_dpi_video()
492 dsi_reg_wr(ctx, VIDEO_VBLK_LINES, VSA_LINES, 20, vm->vsync_len); in sprd_dsi_dpi_video()
497 hs_to = (hline * vm->vactive) + (2 * bpp_x100) / 100; in sprd_dsi_dpi_video()
498 for (div = 0x80; (div < hs_to) && (div > 2); div--) { in sprd_dsi_dpi_video()
500 writel(div, ctx->base + TIMEOUT_CNT_CLK_CONFIG); in sprd_dsi_dpi_video()
501 writel(hs_to / div, ctx->base + LRX_H_TO_CONFIG); in sprd_dsi_dpi_video()
502 writel(hs_to / div, ctx->base + HTX_TO_CONFIG); in sprd_dsi_dpi_video()
507 if (ctx->burst_mode == VIDEO_BURST_WITH_SYNC_PULSES) { in sprd_dsi_dpi_video()
509 writel(0, ctx->base + VIDEO_NULLPKT_SIZE); in sprd_dsi_dpi_video()
515 /* bytes to be sent - first as one chunk */ in sprd_dsi_dpi_video()
516 bytes_per_chunk = vm->hactive * bpp_x100 / 100 + pkt_header; in sprd_dsi_dpi_video()
519 total_bytes = (vm->hactive + vm->hfront_porch) * in sprd_dsi_dpi_video()
520 ratio_x1000 / dsi->slave->lanes / 1000; in sprd_dsi_dpi_video()
524 drm_err(dsi->drm, "current resolution can not be set\n"); in sprd_dsi_dpi_video()
525 return -EINVAL; in sprd_dsi_dpi_video()
528 chunk_overhead = total_bytes - bytes_per_chunk; in sprd_dsi_dpi_video()
530 /* overhead higher than 1 -> enable multi packets */ in sprd_dsi_dpi_video()
534 video_size < vm->hactive; in sprd_dsi_dpi_video()
536 if (vm->hactive * 1000 / video_size % 1000) in sprd_dsi_dpi_video()
539 chunks = vm->hactive / video_size; in sprd_dsi_dpi_video()
543 bytes_left = total_bytes - in sprd_dsi_dpi_video()
549 /* prevent overflow (unsigned - unsigned) */ in sprd_dsi_dpi_video()
551 null_pkt_size = (bytes_left - in sprd_dsi_dpi_video()
563 for (video_size = vm->hactive; in sprd_dsi_dpi_video()
570 writel(null_pkt_size, ctx->base + VIDEO_NULLPKT_SIZE); in sprd_dsi_dpi_video()
574 writel(ctx->int0_mask, ctx->base + MASK_PROTOCOL_INT); in sprd_dsi_dpi_video()
575 writel(ctx->int1_mask, ctx->base + MASK_INTERNAL_INT); in sprd_dsi_dpi_video()
576 writel(1, ctx->base + SOFT_RESET); in sprd_dsi_dpi_video()
586 u32 hactive = ctx->vm.hactive; in sprd_dsi_edpi_video()
591 coding = fmt_to_coding(dsi->slave->format); in sprd_dsi_edpi_video()
595 writel(0, ctx->base + SOFT_RESET); in sprd_dsi_edpi_video()
597 dsi_reg_wr(ctx, CMD_MODE_CFG, TEAR_FX_EN, 0, ctx->te_ack_en); in sprd_dsi_edpi_video()
600 writel(hactive, ctx->base + DCS_WM_PKT_SIZE); in sprd_dsi_edpi_video()
602 writel(max_fifo_len, ctx->base + DCS_WM_PKT_SIZE); in sprd_dsi_edpi_video()
604 writel(ctx->int0_mask, ctx->base + MASK_PROTOCOL_INT); in sprd_dsi_edpi_video()
605 writel(ctx->int1_mask, ctx->base + MASK_INTERNAL_INT); in sprd_dsi_edpi_video()
606 writel(1, ctx->base + SOFT_RESET); in sprd_dsi_edpi_video()
628 return -EINVAL; in sprd_dsi_wr_pkt()
633 drm_err(dsi->drm, "tx payload fifo is not empty\n"); in sprd_dsi_wr_pkt()
643 writel(payload, ctx->base + GEN_PLD_DATA); in sprd_dsi_wr_pkt()
655 drm_err(dsi->drm, "tx cmd fifo is not empty\n"); in sprd_dsi_wr_pkt()
660 ctx->base + GEN_HDR); in sprd_dsi_wr_pkt()
684 return -EINVAL; in sprd_dsi_rd_pkt()
689 return -EIO; in sprd_dsi_rd_pkt()
692 ctx->base + GEN_HDR); in sprd_dsi_rd_pkt()
697 drm_err(dsi->drm, "wait read response time out\n"); in sprd_dsi_rd_pkt()
704 drm_err(dsi->drm, "rx payload fifo empty\n"); in sprd_dsi_rd_pkt()
705 return -EIO; in sprd_dsi_rd_pkt()
709 temp = readl(ctx->base + GEN_PLD_DATA); in sprd_dsi_rd_pkt()
731 writel(1, ctx->base + DSI_MODE_CFG); in sprd_dsi_set_work_mode()
733 writel(0, ctx->base + DSI_MODE_CFG); in sprd_dsi_set_work_mode()
738 writel(0, ctx->base + SOFT_RESET); in sprd_dsi_state_reset()
740 writel(1, ctx->base + SOFT_RESET); in sprd_dsi_state_reset()
761 writel(0x1C, ctx->base + PHY_MIN_STOP_TIME); in sprd_dphy_init()
763 writel(dsi->slave->lanes - 1, ctx->base + PHY_LANE_NUM_CONFIG); in sprd_dphy_init()
767 drm_err(dsi->drm, "dphy initial failed\n"); in sprd_dphy_init()
787 drm_display_mode_to_videomode(adj_mode, &dsi->ctx.vm); in sprd_dsi_encoder_mode_set()
793 struct sprd_dpu *dpu = to_sprd_crtc(encoder->crtc); in sprd_dsi_encoder_enable() local
794 struct dsi_context *ctx = &dsi->ctx; in sprd_dsi_encoder_enable()
796 if (ctx->enabled) { in sprd_dsi_encoder_enable()
797 drm_warn(dsi->drm, "dsi is initialized\n"); in sprd_dsi_encoder_enable()
802 if (ctx->work_mode == DSI_MODE_VIDEO) in sprd_dsi_encoder_enable()
809 sprd_dsi_set_work_mode(ctx, ctx->work_mode); in sprd_dsi_encoder_enable()
812 if (dsi->slave->mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) { in sprd_dsi_encoder_enable()
822 sprd_dpu_run(dpu); in sprd_dsi_encoder_enable()
824 ctx->enabled = true; in sprd_dsi_encoder_enable()
830 struct sprd_dpu *dpu = to_sprd_crtc(encoder->crtc); in sprd_dsi_encoder_disable() local
831 struct dsi_context *ctx = &dsi->ctx; in sprd_dsi_encoder_disable()
833 if (!ctx->enabled) { in sprd_dsi_encoder_disable()
834 drm_warn(dsi->drm, "dsi isn't initialized\n"); in sprd_dsi_encoder_disable()
838 sprd_dpu_stop(dpu); in sprd_dsi_encoder_disable()
842 ctx->enabled = false; in sprd_dsi_encoder_disable()
858 struct drm_encoder *encoder = &dsi->encoder; in sprd_dsi_encoder_init()
862 crtc_mask = drm_of_find_possible_crtcs(dsi->drm, dev->of_node); in sprd_dsi_encoder_init()
864 drm_err(dsi->drm, "failed to find crtc mask\n"); in sprd_dsi_encoder_init()
865 return -EINVAL; in sprd_dsi_encoder_init()
868 drm_dbg(dsi->drm, "find possible crtcs: 0x%08x\n", crtc_mask); in sprd_dsi_encoder_init()
870 encoder->possible_crtcs = crtc_mask; in sprd_dsi_encoder_init()
871 ret = drm_encoder_init(dsi->drm, encoder, &sprd_encoder_funcs, in sprd_dsi_encoder_init()
874 drm_err(dsi->drm, "failed to init dsi encoder\n"); in sprd_dsi_encoder_init()
888 dsi->panel_bridge = devm_drm_of_get_bridge(dev, dev->of_node, 1, 0); in sprd_dsi_bridge_init()
889 if (IS_ERR(dsi->panel_bridge)) in sprd_dsi_bridge_init()
890 return PTR_ERR(dsi->panel_bridge); in sprd_dsi_bridge_init()
892 ret = drm_bridge_attach(&dsi->encoder, dsi->panel_bridge, NULL, 0); in sprd_dsi_bridge_init()
903 struct dsi_context *ctx = &dsi->ctx; in sprd_dsi_context_init()
909 return -EINVAL; in sprd_dsi_context_init()
912 ctx->base = devm_ioremap(dev, res->start, resource_size(res)); in sprd_dsi_context_init()
913 if (!ctx->base) { in sprd_dsi_context_init()
914 drm_err(dsi->drm, "failed to map dsi host registers\n"); in sprd_dsi_context_init()
915 return -ENXIO; in sprd_dsi_context_init()
918 ctx->regmap = devm_regmap_init(dev, ®map_tst_io, dsi, &byte_config); in sprd_dsi_context_init()
919 if (IS_ERR(ctx->regmap)) { in sprd_dsi_context_init()
920 drm_err(dsi->drm, "dphy regmap init failed\n"); in sprd_dsi_context_init()
921 return PTR_ERR(ctx->regmap); in sprd_dsi_context_init()
924 ctx->data_hs2lp = 120; in sprd_dsi_context_init()
925 ctx->data_lp2hs = 500; in sprd_dsi_context_init()
926 ctx->clk_hs2lp = 4; in sprd_dsi_context_init()
927 ctx->clk_lp2hs = 15; in sprd_dsi_context_init()
928 ctx->max_rd_time = 6000; in sprd_dsi_context_init()
929 ctx->int0_mask = 0xffffffff; in sprd_dsi_context_init()
930 ctx->int1_mask = 0xffffffff; in sprd_dsi_context_init()
931 ctx->enabled = true; in sprd_dsi_context_init()
942 dsi->drm = drm; in sprd_dsi_bind()
964 drm_of_panel_bridge_remove(dev->of_node, 1, 0); in sprd_dsi_unbind()
966 drm_encoder_cleanup(&dsi->encoder); in sprd_dsi_unbind()
978 struct dsi_context *ctx = &dsi->ctx; in sprd_dsi_host_attach()
980 dsi->slave = slave; in sprd_dsi_host_attach()
982 if (slave->mode_flags & MIPI_DSI_MODE_VIDEO) in sprd_dsi_host_attach()
983 ctx->work_mode = DSI_MODE_VIDEO; in sprd_dsi_host_attach()
985 ctx->work_mode = DSI_MODE_CMD; in sprd_dsi_host_attach()
987 if (slave->mode_flags & MIPI_DSI_MODE_VIDEO_BURST) in sprd_dsi_host_attach()
988 ctx->burst_mode = VIDEO_BURST_WITH_SYNC_PULSES; in sprd_dsi_host_attach()
989 else if (slave->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) in sprd_dsi_host_attach()
990 ctx->burst_mode = VIDEO_NON_BURST_WITH_SYNC_PULSES; in sprd_dsi_host_attach()
992 ctx->burst_mode = VIDEO_NON_BURST_WITH_SYNC_EVENTS; in sprd_dsi_host_attach()
994 return component_add(host->dev, &dsi_component_ops); in sprd_dsi_host_attach()
1000 component_del(host->dev, &dsi_component_ops); in sprd_dsi_host_detach()
1009 const u8 *tx_buf = msg->tx_buf; in sprd_dsi_host_transfer()
1011 if (msg->rx_buf && msg->rx_len) { in sprd_dsi_host_transfer()
1012 u8 lsb = (msg->tx_len > 0) ? tx_buf[0] : 0; in sprd_dsi_host_transfer()
1013 u8 msb = (msg->tx_len > 1) ? tx_buf[1] : 0; in sprd_dsi_host_transfer()
1015 return sprd_dsi_rd_pkt(&dsi->ctx, msg->channel, msg->type, in sprd_dsi_host_transfer()
1016 msb, lsb, msg->rx_buf, msg->rx_len); in sprd_dsi_host_transfer()
1019 if (msg->tx_buf && msg->tx_len) in sprd_dsi_host_transfer()
1020 return sprd_dsi_wr_pkt(&dsi->ctx, msg->channel, msg->type, in sprd_dsi_host_transfer()
1021 tx_buf, msg->tx_len); in sprd_dsi_host_transfer()
1033 { .compatible = "sprd,sharkl3-dsi-host" },
1039 struct device *dev = &pdev->dev; in sprd_dsi_probe()
1044 return -ENOMEM; in sprd_dsi_probe()
1048 dsi->host.ops = &sprd_dsi_host_ops; in sprd_dsi_probe()
1049 dsi->host.dev = dev; in sprd_dsi_probe()
1051 return mipi_dsi_host_register(&dsi->host); in sprd_dsi_probe()
1056 struct sprd_dsi *dsi = dev_get_drvdata(&pdev->dev); in sprd_dsi_remove()
1058 mipi_dsi_host_unregister(&dsi->host); in sprd_dsi_remove()
1065 .name = "sprd-dsi-drv",