Lines Matching refs:dpi

130 static void mtk_dpi_mask(struct mtk_dpi *dpi, u32 offset, u32 val, u32 mask)  in mtk_dpi_mask()  argument
132 u32 tmp = readl(dpi->regs + offset) & ~mask; in mtk_dpi_mask()
135 writel(tmp, dpi->regs + offset); in mtk_dpi_mask()
138 static void mtk_dpi_sw_reset(struct mtk_dpi *dpi, bool reset) in mtk_dpi_sw_reset() argument
140 mtk_dpi_mask(dpi, DPI_RET, reset ? RST : 0, RST); in mtk_dpi_sw_reset()
143 static void mtk_dpi_enable(struct mtk_dpi *dpi) in mtk_dpi_enable() argument
145 mtk_dpi_mask(dpi, DPI_EN, EN, EN); in mtk_dpi_enable()
148 static void mtk_dpi_disable(struct mtk_dpi *dpi) in mtk_dpi_disable() argument
150 mtk_dpi_mask(dpi, DPI_EN, 0, EN); in mtk_dpi_disable()
153 static void mtk_dpi_config_hsync(struct mtk_dpi *dpi, in mtk_dpi_config_hsync() argument
156 mtk_dpi_mask(dpi, DPI_TGEN_HWIDTH, in mtk_dpi_config_hsync()
158 mtk_dpi_mask(dpi, DPI_TGEN_HPORCH, in mtk_dpi_config_hsync()
160 mtk_dpi_mask(dpi, DPI_TGEN_HPORCH, sync->front_porch << HFP, in mtk_dpi_config_hsync()
164 static void mtk_dpi_config_vsync(struct mtk_dpi *dpi, in mtk_dpi_config_vsync() argument
168 mtk_dpi_mask(dpi, width_addr, in mtk_dpi_config_vsync()
171 mtk_dpi_mask(dpi, width_addr, in mtk_dpi_config_vsync()
174 mtk_dpi_mask(dpi, porch_addr, in mtk_dpi_config_vsync()
177 mtk_dpi_mask(dpi, porch_addr, in mtk_dpi_config_vsync()
182 static void mtk_dpi_config_vsync_lodd(struct mtk_dpi *dpi, in mtk_dpi_config_vsync_lodd() argument
185 mtk_dpi_config_vsync(dpi, sync, DPI_TGEN_VWIDTH, DPI_TGEN_VPORCH); in mtk_dpi_config_vsync_lodd()
188 static void mtk_dpi_config_vsync_leven(struct mtk_dpi *dpi, in mtk_dpi_config_vsync_leven() argument
191 mtk_dpi_config_vsync(dpi, sync, DPI_TGEN_VWIDTH_LEVEN, in mtk_dpi_config_vsync_leven()
195 static void mtk_dpi_config_vsync_rodd(struct mtk_dpi *dpi, in mtk_dpi_config_vsync_rodd() argument
198 mtk_dpi_config_vsync(dpi, sync, DPI_TGEN_VWIDTH_RODD, in mtk_dpi_config_vsync_rodd()
202 static void mtk_dpi_config_vsync_reven(struct mtk_dpi *dpi, in mtk_dpi_config_vsync_reven() argument
205 mtk_dpi_config_vsync(dpi, sync, DPI_TGEN_VWIDTH_REVEN, in mtk_dpi_config_vsync_reven()
209 static void mtk_dpi_config_pol(struct mtk_dpi *dpi, in mtk_dpi_config_pol() argument
218 mtk_dpi_mask(dpi, DPI_OUTPUT_SETTING, pol, in mtk_dpi_config_pol()
222 static void mtk_dpi_config_3d(struct mtk_dpi *dpi, bool en_3d) in mtk_dpi_config_3d() argument
224 mtk_dpi_mask(dpi, DPI_CON, en_3d ? TDFP_EN : 0, TDFP_EN); in mtk_dpi_config_3d()
227 static void mtk_dpi_config_interface(struct mtk_dpi *dpi, bool inter) in mtk_dpi_config_interface() argument
229 mtk_dpi_mask(dpi, DPI_CON, inter ? INTL_EN : 0, INTL_EN); in mtk_dpi_config_interface()
232 static void mtk_dpi_config_fb_size(struct mtk_dpi *dpi, u32 width, u32 height) in mtk_dpi_config_fb_size() argument
234 mtk_dpi_mask(dpi, DPI_SIZE, width << HSIZE, HSIZE_MASK); in mtk_dpi_config_fb_size()
235 mtk_dpi_mask(dpi, DPI_SIZE, height << VSIZE, VSIZE_MASK); in mtk_dpi_config_fb_size()
238 static void mtk_dpi_config_channel_limit(struct mtk_dpi *dpi, in mtk_dpi_config_channel_limit() argument
241 mtk_dpi_mask(dpi, DPI_Y_LIMIT, limit->y_bottom << Y_LIMINT_BOT, in mtk_dpi_config_channel_limit()
243 mtk_dpi_mask(dpi, DPI_Y_LIMIT, limit->y_top << Y_LIMINT_TOP, in mtk_dpi_config_channel_limit()
245 mtk_dpi_mask(dpi, DPI_C_LIMIT, limit->c_bottom << C_LIMIT_BOT, in mtk_dpi_config_channel_limit()
247 mtk_dpi_mask(dpi, DPI_C_LIMIT, limit->c_top << C_LIMIT_TOP, in mtk_dpi_config_channel_limit()
251 static void mtk_dpi_config_bit_num(struct mtk_dpi *dpi, in mtk_dpi_config_bit_num() argument
273 mtk_dpi_mask(dpi, DPI_OUTPUT_SETTING, val << OUT_BIT, in mtk_dpi_config_bit_num()
277 static void mtk_dpi_config_yc_map(struct mtk_dpi *dpi, in mtk_dpi_config_yc_map() argument
303 mtk_dpi_mask(dpi, DPI_OUTPUT_SETTING, val << YC_MAP, YC_MAP_MASK); in mtk_dpi_config_yc_map()
306 static void mtk_dpi_config_channel_swap(struct mtk_dpi *dpi, in mtk_dpi_config_channel_swap() argument
335 mtk_dpi_mask(dpi, DPI_OUTPUT_SETTING, val << CH_SWAP, CH_SWAP_MASK); in mtk_dpi_config_channel_swap()
338 static void mtk_dpi_config_yuv422_enable(struct mtk_dpi *dpi, bool enable) in mtk_dpi_config_yuv422_enable() argument
340 mtk_dpi_mask(dpi, DPI_CON, enable ? YUV422_EN : 0, YUV422_EN); in mtk_dpi_config_yuv422_enable()
343 static void mtk_dpi_config_csc_enable(struct mtk_dpi *dpi, bool enable) in mtk_dpi_config_csc_enable() argument
345 mtk_dpi_mask(dpi, DPI_CON, enable ? CSC_ENABLE : 0, CSC_ENABLE); in mtk_dpi_config_csc_enable()
348 static void mtk_dpi_config_swap_input(struct mtk_dpi *dpi, bool enable) in mtk_dpi_config_swap_input() argument
350 mtk_dpi_mask(dpi, DPI_CON, enable ? IN_RB_SWAP : 0, IN_RB_SWAP); in mtk_dpi_config_swap_input()
353 static void mtk_dpi_config_2n_h_fre(struct mtk_dpi *dpi) in mtk_dpi_config_2n_h_fre() argument
355 mtk_dpi_mask(dpi, dpi->conf->reg_h_fre_con, H_FRE_2N, H_FRE_2N); in mtk_dpi_config_2n_h_fre()
358 static void mtk_dpi_config_disable_edge(struct mtk_dpi *dpi) in mtk_dpi_config_disable_edge() argument
360 if (dpi->conf->edge_sel_en) in mtk_dpi_config_disable_edge()
361 mtk_dpi_mask(dpi, dpi->conf->reg_h_fre_con, 0, EDGE_SEL_EN); in mtk_dpi_config_disable_edge()
364 static void mtk_dpi_config_color_format(struct mtk_dpi *dpi, in mtk_dpi_config_color_format() argument
369 mtk_dpi_config_yuv422_enable(dpi, false); in mtk_dpi_config_color_format()
370 mtk_dpi_config_csc_enable(dpi, true); in mtk_dpi_config_color_format()
371 mtk_dpi_config_swap_input(dpi, false); in mtk_dpi_config_color_format()
372 mtk_dpi_config_channel_swap(dpi, MTK_DPI_OUT_CHANNEL_SWAP_BGR); in mtk_dpi_config_color_format()
375 mtk_dpi_config_yuv422_enable(dpi, true); in mtk_dpi_config_color_format()
376 mtk_dpi_config_csc_enable(dpi, true); in mtk_dpi_config_color_format()
377 mtk_dpi_config_swap_input(dpi, true); in mtk_dpi_config_color_format()
378 mtk_dpi_config_channel_swap(dpi, MTK_DPI_OUT_CHANNEL_SWAP_RGB); in mtk_dpi_config_color_format()
380 mtk_dpi_config_yuv422_enable(dpi, false); in mtk_dpi_config_color_format()
381 mtk_dpi_config_csc_enable(dpi, false); in mtk_dpi_config_color_format()
382 mtk_dpi_config_swap_input(dpi, false); in mtk_dpi_config_color_format()
383 mtk_dpi_config_channel_swap(dpi, MTK_DPI_OUT_CHANNEL_SWAP_RGB); in mtk_dpi_config_color_format()
387 static void mtk_dpi_dual_edge(struct mtk_dpi *dpi) in mtk_dpi_dual_edge() argument
389 if ((dpi->output_fmt == MEDIA_BUS_FMT_RGB888_2X12_LE) || in mtk_dpi_dual_edge()
390 (dpi->output_fmt == MEDIA_BUS_FMT_RGB888_2X12_BE)) { in mtk_dpi_dual_edge()
391 mtk_dpi_mask(dpi, DPI_DDR_SETTING, DDR_EN | DDR_4PHASE, in mtk_dpi_dual_edge()
393 mtk_dpi_mask(dpi, DPI_OUTPUT_SETTING, in mtk_dpi_dual_edge()
394 dpi->output_fmt == MEDIA_BUS_FMT_RGB888_2X12_LE ? in mtk_dpi_dual_edge()
397 mtk_dpi_mask(dpi, DPI_DDR_SETTING, DDR_EN | DDR_4PHASE, 0); in mtk_dpi_dual_edge()
401 static void mtk_dpi_power_off(struct mtk_dpi *dpi) in mtk_dpi_power_off() argument
403 if (WARN_ON(dpi->refcount == 0)) in mtk_dpi_power_off()
406 if (--dpi->refcount != 0) in mtk_dpi_power_off()
409 if (dpi->pinctrl && dpi->pins_gpio) in mtk_dpi_power_off()
410 pinctrl_select_state(dpi->pinctrl, dpi->pins_gpio); in mtk_dpi_power_off()
412 mtk_dpi_disable(dpi); in mtk_dpi_power_off()
413 clk_disable_unprepare(dpi->pixel_clk); in mtk_dpi_power_off()
414 clk_disable_unprepare(dpi->engine_clk); in mtk_dpi_power_off()
417 static int mtk_dpi_power_on(struct mtk_dpi *dpi) in mtk_dpi_power_on() argument
421 if (++dpi->refcount != 1) in mtk_dpi_power_on()
424 ret = clk_prepare_enable(dpi->engine_clk); in mtk_dpi_power_on()
426 dev_err(dpi->dev, "Failed to enable engine clock: %d\n", ret); in mtk_dpi_power_on()
430 ret = clk_prepare_enable(dpi->pixel_clk); in mtk_dpi_power_on()
432 dev_err(dpi->dev, "Failed to enable pixel clock: %d\n", ret); in mtk_dpi_power_on()
436 if (dpi->pinctrl && dpi->pins_dpi) in mtk_dpi_power_on()
437 pinctrl_select_state(dpi->pinctrl, dpi->pins_dpi); in mtk_dpi_power_on()
439 mtk_dpi_enable(dpi); in mtk_dpi_power_on()
443 clk_disable_unprepare(dpi->engine_clk); in mtk_dpi_power_on()
445 dpi->refcount--; in mtk_dpi_power_on()
449 static int mtk_dpi_set_display_mode(struct mtk_dpi *dpi, in mtk_dpi_set_display_mode() argument
464 factor = dpi->conf->cal_factor(mode->clock); in mtk_dpi_set_display_mode()
468 dev_dbg(dpi->dev, "Want PLL %lu Hz, pixel clock %lu Hz\n", in mtk_dpi_set_display_mode()
471 clk_set_rate(dpi->tvd_clk, pll_rate); in mtk_dpi_set_display_mode()
472 pll_rate = clk_get_rate(dpi->tvd_clk); in mtk_dpi_set_display_mode()
475 if ((dpi->output_fmt == MEDIA_BUS_FMT_RGB888_2X12_LE) || in mtk_dpi_set_display_mode()
476 (dpi->output_fmt == MEDIA_BUS_FMT_RGB888_2X12_BE)) in mtk_dpi_set_display_mode()
477 clk_set_rate(dpi->pixel_clk, vm.pixelclock * 2); in mtk_dpi_set_display_mode()
479 clk_set_rate(dpi->pixel_clk, vm.pixelclock); in mtk_dpi_set_display_mode()
482 vm.pixelclock = clk_get_rate(dpi->pixel_clk); in mtk_dpi_set_display_mode()
484 dev_dbg(dpi->dev, "Got PLL %lu Hz, pixel clock %lu Hz\n", in mtk_dpi_set_display_mode()
522 mtk_dpi_sw_reset(dpi, true); in mtk_dpi_set_display_mode()
523 mtk_dpi_config_pol(dpi, &dpi_pol); in mtk_dpi_set_display_mode()
525 mtk_dpi_config_hsync(dpi, &hsync); in mtk_dpi_set_display_mode()
526 mtk_dpi_config_vsync_lodd(dpi, &vsync_lodd); in mtk_dpi_set_display_mode()
527 mtk_dpi_config_vsync_rodd(dpi, &vsync_rodd); in mtk_dpi_set_display_mode()
528 mtk_dpi_config_vsync_leven(dpi, &vsync_leven); in mtk_dpi_set_display_mode()
529 mtk_dpi_config_vsync_reven(dpi, &vsync_reven); in mtk_dpi_set_display_mode()
531 mtk_dpi_config_3d(dpi, !!(mode->flags & DRM_MODE_FLAG_3D_MASK)); in mtk_dpi_set_display_mode()
532 mtk_dpi_config_interface(dpi, !!(vm.flags & in mtk_dpi_set_display_mode()
535 mtk_dpi_config_fb_size(dpi, vm.hactive, vm.vactive >> 1); in mtk_dpi_set_display_mode()
537 mtk_dpi_config_fb_size(dpi, vm.hactive, vm.vactive); in mtk_dpi_set_display_mode()
539 mtk_dpi_config_channel_limit(dpi, &limit); in mtk_dpi_set_display_mode()
540 mtk_dpi_config_bit_num(dpi, dpi->bit_num); in mtk_dpi_set_display_mode()
541 mtk_dpi_config_channel_swap(dpi, dpi->channel_swap); in mtk_dpi_set_display_mode()
542 mtk_dpi_config_yc_map(dpi, dpi->yc_map); in mtk_dpi_set_display_mode()
543 mtk_dpi_config_color_format(dpi, dpi->color_format); in mtk_dpi_set_display_mode()
544 mtk_dpi_config_2n_h_fre(dpi); in mtk_dpi_set_display_mode()
545 mtk_dpi_dual_edge(dpi); in mtk_dpi_set_display_mode()
546 mtk_dpi_config_disable_edge(dpi); in mtk_dpi_set_display_mode()
547 mtk_dpi_sw_reset(dpi, false); in mtk_dpi_set_display_mode()
558 struct mtk_dpi *dpi = bridge_to_dpi(bridge); in mtk_dpi_bridge_atomic_get_output_bus_fmts() local
563 if (!dpi->conf->output_fmts) { in mtk_dpi_bridge_atomic_get_output_bus_fmts()
564 dev_err(dpi->dev, "output_fmts should not be null\n"); in mtk_dpi_bridge_atomic_get_output_bus_fmts()
568 output_fmts = kcalloc(dpi->conf->num_output_fmts, sizeof(*output_fmts), in mtk_dpi_bridge_atomic_get_output_bus_fmts()
573 *num_output_fmts = dpi->conf->num_output_fmts; in mtk_dpi_bridge_atomic_get_output_bus_fmts()
575 memcpy(output_fmts, dpi->conf->output_fmts, in mtk_dpi_bridge_atomic_get_output_bus_fmts()
576 sizeof(*output_fmts) * dpi->conf->num_output_fmts); in mtk_dpi_bridge_atomic_get_output_bus_fmts()
608 struct mtk_dpi *dpi = bridge_to_dpi(bridge); in mtk_dpi_bridge_atomic_check() local
614 if (dpi->conf->num_output_fmts) in mtk_dpi_bridge_atomic_check()
615 out_bus_format = dpi->conf->output_fmts[0]; in mtk_dpi_bridge_atomic_check()
617 dev_dbg(dpi->dev, "input format 0x%04x, output format 0x%04x\n", in mtk_dpi_bridge_atomic_check()
621 dpi->output_fmt = out_bus_format; in mtk_dpi_bridge_atomic_check()
622 dpi->bit_num = MTK_DPI_OUT_BIT_NUM_8BITS; in mtk_dpi_bridge_atomic_check()
623 dpi->channel_swap = MTK_DPI_OUT_CHANNEL_SWAP_RGB; in mtk_dpi_bridge_atomic_check()
624 dpi->yc_map = MTK_DPI_OUT_YC_MAP_RGB; in mtk_dpi_bridge_atomic_check()
625 dpi->color_format = MTK_DPI_COLOR_FORMAT_RGB; in mtk_dpi_bridge_atomic_check()
633 struct mtk_dpi *dpi = bridge_to_dpi(bridge); in mtk_dpi_bridge_attach() local
635 return drm_bridge_attach(bridge->encoder, dpi->next_bridge, in mtk_dpi_bridge_attach()
636 &dpi->bridge, flags); in mtk_dpi_bridge_attach()
643 struct mtk_dpi *dpi = bridge_to_dpi(bridge); in mtk_dpi_bridge_mode_set() local
645 drm_mode_copy(&dpi->mode, adjusted_mode); in mtk_dpi_bridge_mode_set()
650 struct mtk_dpi *dpi = bridge_to_dpi(bridge); in mtk_dpi_bridge_disable() local
652 mtk_dpi_power_off(dpi); in mtk_dpi_bridge_disable()
657 struct mtk_dpi *dpi = bridge_to_dpi(bridge); in mtk_dpi_bridge_enable() local
659 mtk_dpi_power_on(dpi); in mtk_dpi_bridge_enable()
660 mtk_dpi_set_display_mode(dpi, &dpi->mode); in mtk_dpi_bridge_enable()
668 struct mtk_dpi *dpi = bridge_to_dpi(bridge); in mtk_dpi_bridge_mode_valid() local
670 if (mode->clock > dpi->conf->max_clock_khz) in mtk_dpi_bridge_mode_valid()
692 struct mtk_dpi *dpi = dev_get_drvdata(dev); in mtk_dpi_start() local
694 mtk_dpi_power_on(dpi); in mtk_dpi_start()
699 struct mtk_dpi *dpi = dev_get_drvdata(dev); in mtk_dpi_stop() local
701 mtk_dpi_power_off(dpi); in mtk_dpi_stop()
706 struct mtk_dpi *dpi = dev_get_drvdata(dev); in mtk_dpi_bind() local
710 ret = drm_simple_encoder_init(drm_dev, &dpi->encoder, in mtk_dpi_bind()
717 dpi->encoder.possible_crtcs = mtk_drm_find_possible_crtc_by_comp(drm_dev, dpi->dev); in mtk_dpi_bind()
719 ret = drm_bridge_attach(&dpi->encoder, &dpi->bridge, NULL, in mtk_dpi_bind()
724 dpi->connector = drm_bridge_connector_init(drm_dev, &dpi->encoder); in mtk_dpi_bind()
725 if (IS_ERR(dpi->connector)) { in mtk_dpi_bind()
727 ret = PTR_ERR(dpi->connector); in mtk_dpi_bind()
730 drm_connector_attach_encoder(dpi->connector, &dpi->encoder); in mtk_dpi_bind()
735 drm_encoder_cleanup(&dpi->encoder); in mtk_dpi_bind()
742 struct mtk_dpi *dpi = dev_get_drvdata(dev); in mtk_dpi_unbind() local
744 drm_encoder_cleanup(&dpi->encoder); in mtk_dpi_unbind()
829 struct mtk_dpi *dpi; in mtk_dpi_probe() local
833 dpi = devm_kzalloc(dev, sizeof(*dpi), GFP_KERNEL); in mtk_dpi_probe()
834 if (!dpi) in mtk_dpi_probe()
837 dpi->dev = dev; in mtk_dpi_probe()
838 dpi->conf = (struct mtk_dpi_conf *)of_device_get_match_data(dev); in mtk_dpi_probe()
839 dpi->output_fmt = MEDIA_BUS_FMT_RGB888_1X24; in mtk_dpi_probe()
841 dpi->pinctrl = devm_pinctrl_get(&pdev->dev); in mtk_dpi_probe()
842 if (IS_ERR(dpi->pinctrl)) { in mtk_dpi_probe()
843 dpi->pinctrl = NULL; in mtk_dpi_probe()
846 if (dpi->pinctrl) { in mtk_dpi_probe()
847 dpi->pins_gpio = pinctrl_lookup_state(dpi->pinctrl, "sleep"); in mtk_dpi_probe()
848 if (IS_ERR(dpi->pins_gpio)) { in mtk_dpi_probe()
849 dpi->pins_gpio = NULL; in mtk_dpi_probe()
852 if (dpi->pins_gpio) in mtk_dpi_probe()
853 pinctrl_select_state(dpi->pinctrl, dpi->pins_gpio); in mtk_dpi_probe()
855 dpi->pins_dpi = pinctrl_lookup_state(dpi->pinctrl, "default"); in mtk_dpi_probe()
856 if (IS_ERR(dpi->pins_dpi)) { in mtk_dpi_probe()
857 dpi->pins_dpi = NULL; in mtk_dpi_probe()
862 dpi->regs = devm_ioremap_resource(dev, mem); in mtk_dpi_probe()
863 if (IS_ERR(dpi->regs)) { in mtk_dpi_probe()
864 ret = PTR_ERR(dpi->regs); in mtk_dpi_probe()
869 dpi->engine_clk = devm_clk_get(dev, "engine"); in mtk_dpi_probe()
870 if (IS_ERR(dpi->engine_clk)) { in mtk_dpi_probe()
871 ret = PTR_ERR(dpi->engine_clk); in mtk_dpi_probe()
878 dpi->pixel_clk = devm_clk_get(dev, "pixel"); in mtk_dpi_probe()
879 if (IS_ERR(dpi->pixel_clk)) { in mtk_dpi_probe()
880 ret = PTR_ERR(dpi->pixel_clk); in mtk_dpi_probe()
887 dpi->tvd_clk = devm_clk_get(dev, "pll"); in mtk_dpi_probe()
888 if (IS_ERR(dpi->tvd_clk)) { in mtk_dpi_probe()
889 ret = PTR_ERR(dpi->tvd_clk); in mtk_dpi_probe()
896 dpi->irq = platform_get_irq(pdev, 0); in mtk_dpi_probe()
897 if (dpi->irq <= 0) in mtk_dpi_probe()
901 NULL, &dpi->next_bridge); in mtk_dpi_probe()
905 dev_info(dev, "Found bridge node: %pOF\n", dpi->next_bridge->of_node); in mtk_dpi_probe()
907 platform_set_drvdata(pdev, dpi); in mtk_dpi_probe()
909 dpi->bridge.funcs = &mtk_dpi_bridge_funcs; in mtk_dpi_probe()
910 dpi->bridge.of_node = dev->of_node; in mtk_dpi_probe()
911 dpi->bridge.type = DRM_MODE_CONNECTOR_DPI; in mtk_dpi_probe()
913 drm_bridge_add(&dpi->bridge); in mtk_dpi_probe()
917 drm_bridge_remove(&dpi->bridge); in mtk_dpi_probe()
927 struct mtk_dpi *dpi = platform_get_drvdata(pdev); in mtk_dpi_remove() local
930 drm_bridge_remove(&dpi->bridge); in mtk_dpi_remove()