Lines Matching full:dsi

291 static void sun6i_dsi_inst_abort(struct sun6i_dsi *dsi)  in sun6i_dsi_inst_abort()  argument
293 regmap_update_bits(dsi->regs, SUN6I_DSI_BASIC_CTL0_REG, in sun6i_dsi_inst_abort()
297 static void sun6i_dsi_inst_commit(struct sun6i_dsi *dsi) in sun6i_dsi_inst_commit() argument
299 regmap_update_bits(dsi->regs, SUN6I_DSI_BASIC_CTL0_REG, in sun6i_dsi_inst_commit()
304 static int sun6i_dsi_inst_wait_for_completion(struct sun6i_dsi *dsi) in sun6i_dsi_inst_wait_for_completion() argument
308 return regmap_read_poll_timeout(dsi->regs, SUN6I_DSI_BASIC_CTL0_REG, in sun6i_dsi_inst_wait_for_completion()
314 static void sun6i_dsi_inst_setup(struct sun6i_dsi *dsi, in sun6i_dsi_inst_setup() argument
321 regmap_write(dsi->regs, SUN6I_DSI_INST_FUNC_REG(id), in sun6i_dsi_inst_setup()
329 static void sun6i_dsi_inst_init(struct sun6i_dsi *dsi, in sun6i_dsi_inst_init() argument
334 sun6i_dsi_inst_setup(dsi, DSI_INST_ID_LP11, DSI_INST_MODE_STOP, in sun6i_dsi_inst_init()
337 sun6i_dsi_inst_setup(dsi, DSI_INST_ID_TBA, DSI_INST_MODE_TBA, in sun6i_dsi_inst_init()
340 sun6i_dsi_inst_setup(dsi, DSI_INST_ID_HSC, DSI_INST_MODE_HS, in sun6i_dsi_inst_init()
343 sun6i_dsi_inst_setup(dsi, DSI_INST_ID_HSD, DSI_INST_MODE_HS, in sun6i_dsi_inst_init()
346 sun6i_dsi_inst_setup(dsi, DSI_INST_ID_LPDT, DSI_INST_MODE_ESCAPE, in sun6i_dsi_inst_init()
350 sun6i_dsi_inst_setup(dsi, DSI_INST_ID_HSCEXIT, DSI_INST_MODE_HSCEXIT, in sun6i_dsi_inst_init()
353 sun6i_dsi_inst_setup(dsi, DSI_INST_ID_NOP, DSI_INST_MODE_STOP, in sun6i_dsi_inst_init()
356 sun6i_dsi_inst_setup(dsi, DSI_INST_ID_DLY, DSI_INST_MODE_NOP, in sun6i_dsi_inst_init()
359 regmap_write(dsi->regs, SUN6I_DSI_INST_JUMP_CFG_REG(0), in sun6i_dsi_inst_init()
365 static u16 sun6i_dsi_get_video_start_delay(struct sun6i_dsi *dsi, in sun6i_dsi_get_video_start_delay() argument
376 static u16 sun6i_dsi_get_line_num(struct sun6i_dsi *dsi, in sun6i_dsi_get_line_num() argument
379 struct mipi_dsi_device *device = dsi->device; in sun6i_dsi_get_line_num()
385 static u16 sun6i_dsi_get_drq_edge0(struct sun6i_dsi *dsi, in sun6i_dsi_get_drq_edge0() argument
399 static u16 sun6i_dsi_get_drq_edge1(struct sun6i_dsi *dsi, in sun6i_dsi_get_drq_edge1() argument
403 struct mipi_dsi_device *device = dsi->device; in sun6i_dsi_get_drq_edge1()
417 static void sun6i_dsi_setup_burst(struct sun6i_dsi *dsi, in sun6i_dsi_setup_burst() argument
420 struct mipi_dsi_device *device = dsi->device; in sun6i_dsi_setup_burst()
424 u16 line_num = sun6i_dsi_get_line_num(dsi, mode); in sun6i_dsi_setup_burst()
427 edge1 = sun6i_dsi_get_drq_edge1(dsi, mode, line_num); in sun6i_dsi_setup_burst()
428 edge0 = sun6i_dsi_get_drq_edge0(dsi, mode, line_num, edge1); in sun6i_dsi_setup_burst()
430 regmap_write(dsi->regs, SUN6I_DSI_BURST_DRQ_REG, in sun6i_dsi_setup_burst()
434 regmap_write(dsi->regs, SUN6I_DSI_BURST_LINE_REG, in sun6i_dsi_setup_burst()
450 regmap_write(dsi->regs, SUN6I_DSI_TCON_DRQ_REG, val); in sun6i_dsi_setup_burst()
453 static void sun6i_dsi_setup_inst_loop(struct sun6i_dsi *dsi, in sun6i_dsi_setup_inst_loop() argument
456 struct mipi_dsi_device *device = dsi->device; in sun6i_dsi_setup_inst_loop()
466 regmap_write(dsi->regs, SUN6I_DSI_INST_LOOP_SEL_REG, in sun6i_dsi_setup_inst_loop()
470 regmap_write(dsi->regs, SUN6I_DSI_INST_LOOP_NUM_REG(0), in sun6i_dsi_setup_inst_loop()
473 regmap_write(dsi->regs, SUN6I_DSI_INST_LOOP_NUM_REG(1), in sun6i_dsi_setup_inst_loop()
478 static void sun6i_dsi_setup_format(struct sun6i_dsi *dsi, in sun6i_dsi_setup_format() argument
481 struct mipi_dsi_device *device = dsi->device; in sun6i_dsi_setup_format()
516 regmap_write(dsi->regs, SUN6I_DSI_PIXEL_PH_REG, val); in sun6i_dsi_setup_format()
518 regmap_write(dsi->regs, SUN6I_DSI_PIXEL_PF0_REG, in sun6i_dsi_setup_format()
521 regmap_write(dsi->regs, SUN6I_DSI_PIXEL_PF1_REG, in sun6i_dsi_setup_format()
525 regmap_write(dsi->regs, SUN6I_DSI_PIXEL_CTL0_REG, in sun6i_dsi_setup_format()
530 static void sun6i_dsi_setup_timings(struct sun6i_dsi *dsi, in sun6i_dsi_setup_timings() argument
533 struct mipi_dsi_device *device = dsi->device; in sun6i_dsi_setup_timings()
605 regmap_write(dsi->regs, SUN6I_DSI_BASIC_CTL_REG, basic_ctl); in sun6i_dsi_setup_timings()
607 regmap_write(dsi->regs, SUN6I_DSI_SYNC_HSS_REG, in sun6i_dsi_setup_timings()
612 regmap_write(dsi->regs, SUN6I_DSI_SYNC_HSE_REG, in sun6i_dsi_setup_timings()
617 regmap_write(dsi->regs, SUN6I_DSI_SYNC_VSS_REG, in sun6i_dsi_setup_timings()
622 regmap_write(dsi->regs, SUN6I_DSI_SYNC_VSE_REG, in sun6i_dsi_setup_timings()
627 regmap_write(dsi->regs, SUN6I_DSI_BASIC_SIZE0_REG, in sun6i_dsi_setup_timings()
633 regmap_write(dsi->regs, SUN6I_DSI_BASIC_SIZE1_REG, in sun6i_dsi_setup_timings()
638 regmap_write(dsi->regs, SUN6I_DSI_BLK_HSA0_REG, in sun6i_dsi_setup_timings()
640 regmap_write(dsi->regs, SUN6I_DSI_BLK_HSA1_REG, in sun6i_dsi_setup_timings()
644 regmap_write(dsi->regs, SUN6I_DSI_BLK_HBP0_REG, in sun6i_dsi_setup_timings()
646 regmap_write(dsi->regs, SUN6I_DSI_BLK_HBP1_REG, in sun6i_dsi_setup_timings()
650 regmap_write(dsi->regs, SUN6I_DSI_BLK_HFP0_REG, in sun6i_dsi_setup_timings()
652 regmap_write(dsi->regs, SUN6I_DSI_BLK_HFP1_REG, in sun6i_dsi_setup_timings()
656 regmap_write(dsi->regs, SUN6I_DSI_BLK_HBLK0_REG, in sun6i_dsi_setup_timings()
658 regmap_write(dsi->regs, SUN6I_DSI_BLK_HBLK1_REG, in sun6i_dsi_setup_timings()
662 regmap_write(dsi->regs, SUN6I_DSI_BLK_VBLK0_REG, in sun6i_dsi_setup_timings()
664 regmap_write(dsi->regs, SUN6I_DSI_BLK_VBLK1_REG, in sun6i_dsi_setup_timings()
670 static int sun6i_dsi_start(struct sun6i_dsi *dsi, in sun6i_dsi_start() argument
675 regmap_write(dsi->regs, SUN6I_DSI_INST_JUMP_SEL_REG, in sun6i_dsi_start()
680 regmap_write(dsi->regs, SUN6I_DSI_INST_JUMP_SEL_REG, in sun6i_dsi_start()
687 regmap_write(dsi->regs, SUN6I_DSI_INST_JUMP_SEL_REG, in sun6i_dsi_start()
692 regmap_write(dsi->regs, SUN6I_DSI_INST_JUMP_SEL_REG, in sun6i_dsi_start()
700 regmap_write(dsi->regs, SUN6I_DSI_INST_JUMP_SEL_REG, in sun6i_dsi_start()
705 sun6i_dsi_inst_abort(dsi); in sun6i_dsi_start()
706 sun6i_dsi_inst_commit(dsi); in sun6i_dsi_start()
709 regmap_write_bits(dsi->regs, in sun6i_dsi_start()
719 struct sun6i_dsi *dsi = encoder_to_sun6i_dsi(encoder); in sun6i_dsi_encoder_enable() local
720 struct mipi_dsi_device *device = dsi->device; in sun6i_dsi_encoder_enable()
726 DRM_DEBUG_DRIVER("Enabling DSI output\n"); in sun6i_dsi_encoder_enable()
728 err = regulator_enable(dsi->regulator); in sun6i_dsi_encoder_enable()
730 dev_warn(dsi->dev, "failed to enable VCC-DSI supply: %d\n", err); in sun6i_dsi_encoder_enable()
732 reset_control_deassert(dsi->reset); in sun6i_dsi_encoder_enable()
733 clk_prepare_enable(dsi->mod_clk); in sun6i_dsi_encoder_enable()
736 * Enable the DSI block. in sun6i_dsi_encoder_enable()
738 regmap_write(dsi->regs, SUN6I_DSI_CTL_REG, SUN6I_DSI_CTL_EN); in sun6i_dsi_encoder_enable()
740 regmap_write(dsi->regs, SUN6I_DSI_BASIC_CTL0_REG, in sun6i_dsi_encoder_enable()
743 regmap_write(dsi->regs, SUN6I_DSI_TRANS_START_REG, 10); in sun6i_dsi_encoder_enable()
744 regmap_write(dsi->regs, SUN6I_DSI_TRANS_ZERO_REG, 0); in sun6i_dsi_encoder_enable()
746 sun6i_dsi_inst_init(dsi, dsi->device); in sun6i_dsi_encoder_enable()
748 regmap_write(dsi->regs, SUN6I_DSI_DEBUG_DATA_REG, 0xff); in sun6i_dsi_encoder_enable()
750 delay = sun6i_dsi_get_video_start_delay(dsi, mode); in sun6i_dsi_encoder_enable()
751 regmap_write(dsi->regs, SUN6I_DSI_BASIC_CTL1_REG, in sun6i_dsi_encoder_enable()
757 sun6i_dsi_setup_burst(dsi, mode); in sun6i_dsi_encoder_enable()
758 sun6i_dsi_setup_inst_loop(dsi, mode); in sun6i_dsi_encoder_enable()
759 sun6i_dsi_setup_format(dsi, mode); in sun6i_dsi_encoder_enable()
760 sun6i_dsi_setup_timings(dsi, mode); in sun6i_dsi_encoder_enable()
762 phy_init(dsi->dphy); in sun6i_dsi_encoder_enable()
768 phy_set_mode(dsi->dphy, PHY_MODE_MIPI_DPHY); in sun6i_dsi_encoder_enable()
769 phy_configure(dsi->dphy, &opts); in sun6i_dsi_encoder_enable()
770 phy_power_on(dsi->dphy); in sun6i_dsi_encoder_enable()
772 if (dsi->panel) in sun6i_dsi_encoder_enable()
773 drm_panel_prepare(dsi->panel); in sun6i_dsi_encoder_enable()
787 if (dsi->panel) in sun6i_dsi_encoder_enable()
788 drm_panel_enable(dsi->panel); in sun6i_dsi_encoder_enable()
790 sun6i_dsi_start(dsi, DSI_START_HSC); in sun6i_dsi_encoder_enable()
794 sun6i_dsi_start(dsi, DSI_START_HSD); in sun6i_dsi_encoder_enable()
799 struct sun6i_dsi *dsi = encoder_to_sun6i_dsi(encoder); in sun6i_dsi_encoder_disable() local
801 DRM_DEBUG_DRIVER("Disabling DSI output\n"); in sun6i_dsi_encoder_disable()
803 if (dsi->panel) { in sun6i_dsi_encoder_disable()
804 drm_panel_disable(dsi->panel); in sun6i_dsi_encoder_disable()
805 drm_panel_unprepare(dsi->panel); in sun6i_dsi_encoder_disable()
808 phy_power_off(dsi->dphy); in sun6i_dsi_encoder_disable()
809 phy_exit(dsi->dphy); in sun6i_dsi_encoder_disable()
811 clk_disable_unprepare(dsi->mod_clk); in sun6i_dsi_encoder_disable()
812 reset_control_assert(dsi->reset); in sun6i_dsi_encoder_disable()
813 regulator_disable(dsi->regulator); in sun6i_dsi_encoder_disable()
818 struct sun6i_dsi *dsi = connector_to_sun6i_dsi(connector); in sun6i_dsi_get_modes() local
820 return drm_panel_get_modes(dsi->panel, connector); in sun6i_dsi_get_modes()
830 struct sun6i_dsi *dsi = connector_to_sun6i_dsi(connector); in sun6i_dsi_connector_detect() local
832 return dsi->panel ? connector_status_connected : in sun6i_dsi_connector_detect()
850 static u32 sun6i_dsi_dcs_build_pkt_hdr(struct sun6i_dsi *dsi, in sun6i_dsi_dcs_build_pkt_hdr() argument
869 static int sun6i_dsi_dcs_write_short(struct sun6i_dsi *dsi, in sun6i_dsi_dcs_write_short() argument
872 regmap_write(dsi->regs, SUN6I_DSI_CMD_TX_REG(0), in sun6i_dsi_dcs_write_short()
873 sun6i_dsi_dcs_build_pkt_hdr(dsi, msg)); in sun6i_dsi_dcs_write_short()
874 regmap_write_bits(dsi->regs, SUN6I_DSI_CMD_CTL_REG, in sun6i_dsi_dcs_write_short()
877 sun6i_dsi_start(dsi, DSI_START_LPTX); in sun6i_dsi_dcs_write_short()
882 static int sun6i_dsi_dcs_write_long(struct sun6i_dsi *dsi, in sun6i_dsi_dcs_write_long() argument
889 regmap_write(dsi->regs, SUN6I_DSI_CMD_TX_REG(0), in sun6i_dsi_dcs_write_long()
890 sun6i_dsi_dcs_build_pkt_hdr(dsi, msg)); in sun6i_dsi_dcs_write_long()
903 regmap_bulk_write(dsi->regs, SUN6I_DSI_CMD_TX_REG(1), bounce, DIV_ROUND_UP(len, 4)); in sun6i_dsi_dcs_write_long()
904 regmap_write(dsi->regs, SUN6I_DSI_CMD_CTL_REG, len + 4 - 1); in sun6i_dsi_dcs_write_long()
907 sun6i_dsi_start(dsi, DSI_START_LPTX); in sun6i_dsi_dcs_write_long()
909 ret = sun6i_dsi_inst_wait_for_completion(dsi); in sun6i_dsi_dcs_write_long()
911 sun6i_dsi_inst_abort(dsi); in sun6i_dsi_dcs_write_long()
923 static int sun6i_dsi_dcs_read(struct sun6i_dsi *dsi, in sun6i_dsi_dcs_read() argument
930 regmap_write(dsi->regs, SUN6I_DSI_CMD_TX_REG(0), in sun6i_dsi_dcs_read()
931 sun6i_dsi_dcs_build_pkt_hdr(dsi, msg)); in sun6i_dsi_dcs_read()
932 regmap_write(dsi->regs, SUN6I_DSI_CMD_CTL_REG, in sun6i_dsi_dcs_read()
935 sun6i_dsi_start(dsi, DSI_START_LPRX); in sun6i_dsi_dcs_read()
937 ret = sun6i_dsi_inst_wait_for_completion(dsi); in sun6i_dsi_dcs_read()
939 sun6i_dsi_inst_abort(dsi); in sun6i_dsi_dcs_read()
948 regmap_read(dsi->regs, SUN6I_DSI_CMD_CTL_REG, &val); in sun6i_dsi_dcs_read()
952 regmap_read(dsi->regs, SUN6I_DSI_CMD_RX_REG(0), &val); in sun6i_dsi_dcs_read()
965 struct sun6i_dsi *dsi = host_to_sun6i_dsi(host); in sun6i_dsi_attach() local
970 if (!dsi->drm || !dsi->drm->registered) in sun6i_dsi_attach()
973 dsi->panel = panel; in sun6i_dsi_attach()
974 dsi->device = device; in sun6i_dsi_attach()
976 drm_kms_helper_hotplug_event(dsi->drm); in sun6i_dsi_attach()
986 struct sun6i_dsi *dsi = host_to_sun6i_dsi(host); in sun6i_dsi_detach() local
988 dsi->panel = NULL; in sun6i_dsi_detach()
989 dsi->device = NULL; in sun6i_dsi_detach()
991 drm_kms_helper_hotplug_event(dsi->drm); in sun6i_dsi_detach()
999 struct sun6i_dsi *dsi = host_to_sun6i_dsi(host); in sun6i_dsi_transfer() local
1002 ret = sun6i_dsi_inst_wait_for_completion(dsi); in sun6i_dsi_transfer()
1004 sun6i_dsi_inst_abort(dsi); in sun6i_dsi_transfer()
1006 regmap_write(dsi->regs, SUN6I_DSI_CMD_CTL_REG, in sun6i_dsi_transfer()
1015 ret = sun6i_dsi_dcs_write_short(dsi, msg); in sun6i_dsi_transfer()
1019 ret = sun6i_dsi_dcs_write_long(dsi, msg); in sun6i_dsi_transfer()
1024 ret = sun6i_dsi_dcs_read(dsi, msg); in sun6i_dsi_transfer()
1047 .name = "mipi-dsi",
1054 struct sun6i_dsi *dsi = dev_get_drvdata(dev); in sun6i_dsi_bind() local
1057 drm_encoder_helper_add(&dsi->encoder, in sun6i_dsi_bind()
1059 ret = drm_simple_encoder_init(drm, &dsi->encoder, in sun6i_dsi_bind()
1062 dev_err(dsi->dev, "Couldn't initialise the DSI encoder\n"); in sun6i_dsi_bind()
1065 dsi->encoder.possible_crtcs = BIT(0); in sun6i_dsi_bind()
1067 drm_connector_helper_add(&dsi->connector, in sun6i_dsi_bind()
1069 ret = drm_connector_init(drm, &dsi->connector, in sun6i_dsi_bind()
1073 dev_err(dsi->dev, in sun6i_dsi_bind()
1074 "Couldn't initialise the DSI connector\n"); in sun6i_dsi_bind()
1078 drm_connector_attach_encoder(&dsi->connector, &dsi->encoder); in sun6i_dsi_bind()
1080 dsi->drm = drm; in sun6i_dsi_bind()
1085 drm_encoder_cleanup(&dsi->encoder); in sun6i_dsi_bind()
1092 struct sun6i_dsi *dsi = dev_get_drvdata(dev); in sun6i_dsi_unbind() local
1094 dsi->drm = NULL; in sun6i_dsi_unbind()
1106 struct sun6i_dsi *dsi; in sun6i_dsi_probe() local
1114 dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL); in sun6i_dsi_probe()
1115 if (!dsi) in sun6i_dsi_probe()
1117 dev_set_drvdata(dev, dsi); in sun6i_dsi_probe()
1118 dsi->dev = dev; in sun6i_dsi_probe()
1119 dsi->host.ops = &sun6i_dsi_host_ops; in sun6i_dsi_probe()
1120 dsi->host.dev = dev; in sun6i_dsi_probe()
1121 dsi->variant = variant; in sun6i_dsi_probe()
1125 dev_err(dev, "Couldn't map the DSI encoder registers\n"); in sun6i_dsi_probe()
1129 dsi->regulator = devm_regulator_get(dev, "vcc-dsi"); in sun6i_dsi_probe()
1130 if (IS_ERR(dsi->regulator)) in sun6i_dsi_probe()
1131 return dev_err_probe(dev, PTR_ERR(dsi->regulator), in sun6i_dsi_probe()
1132 "Couldn't get VCC-DSI supply\n"); in sun6i_dsi_probe()
1134 dsi->reset = devm_reset_control_get_shared(dev, NULL); in sun6i_dsi_probe()
1135 if (IS_ERR(dsi->reset)) { in sun6i_dsi_probe()
1137 return PTR_ERR(dsi->reset); in sun6i_dsi_probe()
1140 dsi->regs = devm_regmap_init_mmio(dev, base, &sun6i_dsi_regmap_config); in sun6i_dsi_probe()
1141 if (IS_ERR(dsi->regs)) { in sun6i_dsi_probe()
1143 return PTR_ERR(dsi->regs); in sun6i_dsi_probe()
1146 dsi->bus_clk = devm_clk_get(dev, variant->has_mod_clk ? "bus" : NULL); in sun6i_dsi_probe()
1147 if (IS_ERR(dsi->bus_clk)) in sun6i_dsi_probe()
1148 return dev_err_probe(dev, PTR_ERR(dsi->bus_clk), in sun6i_dsi_probe()
1149 "Couldn't get the DSI bus clock\n"); in sun6i_dsi_probe()
1151 ret = regmap_mmio_attach_clk(dsi->regs, dsi->bus_clk); in sun6i_dsi_probe()
1156 dsi->mod_clk = devm_clk_get(dev, "mod"); in sun6i_dsi_probe()
1157 if (IS_ERR(dsi->mod_clk)) { in sun6i_dsi_probe()
1158 dev_err(dev, "Couldn't get the DSI mod clock\n"); in sun6i_dsi_probe()
1159 ret = PTR_ERR(dsi->mod_clk); in sun6i_dsi_probe()
1168 clk_set_rate_exclusive(dsi->mod_clk, 297000000); in sun6i_dsi_probe()
1171 dsi->dphy = devm_phy_get(dev, "dphy"); in sun6i_dsi_probe()
1172 if (IS_ERR(dsi->dphy)) { in sun6i_dsi_probe()
1174 ret = PTR_ERR(dsi->dphy); in sun6i_dsi_probe()
1178 ret = mipi_dsi_host_register(&dsi->host); in sun6i_dsi_probe()
1180 dev_err(dev, "Couldn't register MIPI-DSI host\n"); in sun6i_dsi_probe()
1193 mipi_dsi_host_unregister(&dsi->host); in sun6i_dsi_probe()
1195 if (dsi->variant->has_mod_clk && dsi->variant->set_mod_clk) in sun6i_dsi_probe()
1196 clk_rate_exclusive_put(dsi->mod_clk); in sun6i_dsi_probe()
1198 regmap_mmio_detach_clk(dsi->regs); in sun6i_dsi_probe()
1206 struct sun6i_dsi *dsi = dev_get_drvdata(dev); in sun6i_dsi_remove() local
1209 mipi_dsi_host_unregister(&dsi->host); in sun6i_dsi_remove()
1210 if (dsi->variant->has_mod_clk && dsi->variant->set_mod_clk) in sun6i_dsi_remove()
1211 clk_rate_exclusive_put(dsi->mod_clk); in sun6i_dsi_remove()
1213 regmap_mmio_detach_clk(dsi->regs); in sun6i_dsi_remove()
1230 .compatible = "allwinner,sun6i-a31-mipi-dsi",
1234 .compatible = "allwinner,sun50i-a64-mipi-dsi",
1238 .compatible = "allwinner,sun50i-a100-mipi-dsi",
1249 .name = "sun6i-mipi-dsi",
1256 MODULE_DESCRIPTION("Allwinner A31 DSI Driver");