Lines Matching +full:mt8188 +full:- +full:pinctrl

1 // SPDX-License-Identifier: GPL-2.0-only
11 #include <linux/media-bus-format.h>
14 #include <linux/pinctrl/consumer.h>
16 #include <linux/soc/mediatek/mtk-mmsys.h>
81 struct pinctrl *pinctrl; member
120 * struct mtk_dpi_conf - Configuration of mediatek dpi.
163 u32 tmp = readl(dpi->regs + offset) & ~mask; in mtk_dpi_mask()
166 writel(tmp, dpi->regs + offset); in mtk_dpi_mask()
187 mtk_dpi_mask(dpi, DPI_TGEN_HWIDTH, sync->sync_width << HPW, in mtk_dpi_config_hsync()
188 dpi->conf->dimension_mask << HPW); in mtk_dpi_config_hsync()
189 mtk_dpi_mask(dpi, DPI_TGEN_HPORCH, sync->back_porch << HBP, in mtk_dpi_config_hsync()
190 dpi->conf->dimension_mask << HBP); in mtk_dpi_config_hsync()
191 mtk_dpi_mask(dpi, DPI_TGEN_HPORCH, sync->front_porch << HFP, in mtk_dpi_config_hsync()
192 dpi->conf->dimension_mask << HFP); in mtk_dpi_config_hsync()
200 sync->shift_half_line << VSYNC_HALF_LINE_SHIFT, in mtk_dpi_config_vsync()
203 sync->sync_width << VSYNC_WIDTH_SHIFT, in mtk_dpi_config_vsync()
204 dpi->conf->dimension_mask << VSYNC_WIDTH_SHIFT); in mtk_dpi_config_vsync()
206 sync->back_porch << VSYNC_BACK_PORCH_SHIFT, in mtk_dpi_config_vsync()
207 dpi->conf->dimension_mask << VSYNC_BACK_PORCH_SHIFT); in mtk_dpi_config_vsync()
209 sync->front_porch << VSYNC_FRONT_PORCH_SHIFT, in mtk_dpi_config_vsync()
210 dpi->conf->dimension_mask << VSYNC_FRONT_PORCH_SHIFT); in mtk_dpi_config_vsync()
247 pol = (dpi_pol->hsync_pol == MTK_DPI_POLARITY_RISING ? 0 : HSYNC_POL) | in mtk_dpi_config_pol()
248 (dpi_pol->vsync_pol == MTK_DPI_POLARITY_RISING ? 0 : VSYNC_POL); in mtk_dpi_config_pol()
249 if (dpi->conf->is_ck_de_pol) { in mtk_dpi_config_pol()
251 pol |= (dpi_pol->ck_pol == MTK_DPI_POLARITY_RISING ? in mtk_dpi_config_pol()
253 (dpi_pol->de_pol == MTK_DPI_POLARITY_RISING ? in mtk_dpi_config_pol()
273 dpi->conf->hvsize_mask << HSIZE); in mtk_dpi_config_fb_size()
275 dpi->conf->hvsize_mask << VSIZE); in mtk_dpi_config_fb_size()
282 if (drm_default_rgb_quant_range(&dpi->mode) == in mtk_dpi_config_channel_limit()
390 val << dpi->conf->channel_swap_shift, in mtk_dpi_config_channel_swap()
391 CH_SWAP_MASK << dpi->conf->channel_swap_shift); in mtk_dpi_config_channel_swap()
396 mtk_dpi_mask(dpi, DPI_CON, enable ? dpi->conf->yuv422_en_bit : 0, in mtk_dpi_config_yuv422_enable()
397 dpi->conf->yuv422_en_bit); in mtk_dpi_config_yuv422_enable()
402 mtk_dpi_mask(dpi, DPI_CON, enable ? dpi->conf->csc_enable_bit : 0, in mtk_dpi_config_csc_enable()
403 dpi->conf->csc_enable_bit); in mtk_dpi_config_csc_enable()
413 mtk_dpi_mask(dpi, dpi->conf->reg_h_fre_con, H_FRE_2N, H_FRE_2N); in mtk_dpi_config_2n_h_fre()
418 if (dpi->conf->edge_sel_en) in mtk_dpi_config_disable_edge()
419 mtk_dpi_mask(dpi, dpi->conf->reg_h_fre_con, 0, EDGE_SEL_EN); in mtk_dpi_config_disable_edge()
435 mtk_dpi_mask(dpi, DPI_MATRIX_SET, dpi->mode.hdisplay <= 720 ? in mtk_dpi_config_color_format()
441 if (dpi->conf->swap_input_support) in mtk_dpi_config_color_format()
448 if ((dpi->output_fmt == MEDIA_BUS_FMT_RGB888_2X12_LE) || in mtk_dpi_dual_edge()
449 (dpi->output_fmt == MEDIA_BUS_FMT_RGB888_2X12_BE)) { in mtk_dpi_dual_edge()
453 dpi->output_fmt == MEDIA_BUS_FMT_RGB888_2X12_LE ? in mtk_dpi_dual_edge()
455 if (dpi->conf->edge_cfg_in_mmsys) in mtk_dpi_dual_edge()
456 mtk_mmsys_ddp_dpi_fmt_config(dpi->mmsys_dev, MTK_DPI_RGB888_DDR_CON); in mtk_dpi_dual_edge()
459 if (dpi->conf->edge_cfg_in_mmsys) in mtk_dpi_dual_edge()
460 mtk_mmsys_ddp_dpi_fmt_config(dpi->mmsys_dev, MTK_DPI_RGB888_SDR_CON); in mtk_dpi_dual_edge()
466 if (WARN_ON(dpi->refcount == 0)) in mtk_dpi_power_off()
469 if (--dpi->refcount != 0) in mtk_dpi_power_off()
473 clk_disable_unprepare(dpi->pixel_clk); in mtk_dpi_power_off()
474 clk_disable_unprepare(dpi->engine_clk); in mtk_dpi_power_off()
481 if (++dpi->refcount != 1) in mtk_dpi_power_on()
484 ret = clk_prepare_enable(dpi->engine_clk); in mtk_dpi_power_on()
486 dev_err(dpi->dev, "Failed to enable engine clock: %d\n", ret); in mtk_dpi_power_on()
490 ret = clk_prepare_enable(dpi->pixel_clk); in mtk_dpi_power_on()
492 dev_err(dpi->dev, "Failed to enable pixel clock: %d\n", ret); in mtk_dpi_power_on()
499 clk_disable_unprepare(dpi->engine_clk); in mtk_dpi_power_on()
501 dpi->refcount--; in mtk_dpi_power_on()
519 factor = dpi->conf->cal_factor(mode->clock); in mtk_dpi_set_display_mode()
523 dev_dbg(dpi->dev, "Want PLL %lu Hz, pixel clock %lu Hz\n", in mtk_dpi_set_display_mode()
526 clk_set_rate(dpi->tvd_clk, pll_rate); in mtk_dpi_set_display_mode()
527 pll_rate = clk_get_rate(dpi->tvd_clk); in mtk_dpi_set_display_mode()
535 vm.pixelclock /= dpi->conf->pixels_per_iter; in mtk_dpi_set_display_mode()
537 if ((dpi->output_fmt == MEDIA_BUS_FMT_RGB888_2X12_LE) || in mtk_dpi_set_display_mode()
538 (dpi->output_fmt == MEDIA_BUS_FMT_RGB888_2X12_BE)) in mtk_dpi_set_display_mode()
539 clk_set_rate(dpi->pixel_clk, vm.pixelclock * 2); in mtk_dpi_set_display_mode()
541 clk_set_rate(dpi->pixel_clk, vm.pixelclock); in mtk_dpi_set_display_mode()
544 vm.pixelclock = clk_get_rate(dpi->pixel_clk); in mtk_dpi_set_display_mode()
546 dev_dbg(dpi->dev, "Got PLL %lu Hz, pixel clock %lu Hz\n", in mtk_dpi_set_display_mode()
561 hsync.sync_width = vm.hsync_len / dpi->conf->pixels_per_iter; in mtk_dpi_set_display_mode()
562 hsync.back_porch = vm.hback_porch / dpi->conf->pixels_per_iter; in mtk_dpi_set_display_mode()
563 hsync.front_porch = vm.hfront_porch / dpi->conf->pixels_per_iter; in mtk_dpi_set_display_mode()
572 mode->flags & DRM_MODE_FLAG_3D_MASK) { in mtk_dpi_set_display_mode()
579 !(mode->flags & DRM_MODE_FLAG_3D_MASK)) { in mtk_dpi_set_display_mode()
583 mode->flags & DRM_MODE_FLAG_3D_MASK) { in mtk_dpi_set_display_mode()
595 mtk_dpi_config_3d(dpi, !!(mode->flags & DRM_MODE_FLAG_3D_MASK)); in mtk_dpi_set_display_mode()
604 mtk_dpi_config_bit_num(dpi, dpi->bit_num); in mtk_dpi_set_display_mode()
605 mtk_dpi_config_channel_swap(dpi, dpi->channel_swap); in mtk_dpi_set_display_mode()
606 mtk_dpi_config_color_format(dpi, dpi->color_format); in mtk_dpi_set_display_mode()
607 if (dpi->conf->support_direct_pin) { in mtk_dpi_set_display_mode()
608 mtk_dpi_config_yc_map(dpi, dpi->yc_map); in mtk_dpi_set_display_mode()
613 if (dpi->conf->input_2pixel) { in mtk_dpi_set_display_mode()
633 if (!dpi->conf->output_fmts) { in mtk_dpi_bridge_atomic_get_output_bus_fmts()
634 dev_err(dpi->dev, "output_fmts should not be null\n"); in mtk_dpi_bridge_atomic_get_output_bus_fmts()
638 output_fmts = kcalloc(dpi->conf->num_output_fmts, sizeof(*output_fmts), in mtk_dpi_bridge_atomic_get_output_bus_fmts()
643 *num_output_fmts = dpi->conf->num_output_fmts; in mtk_dpi_bridge_atomic_get_output_bus_fmts()
645 memcpy(output_fmts, dpi->conf->output_fmts, in mtk_dpi_bridge_atomic_get_output_bus_fmts()
646 sizeof(*output_fmts) * dpi->conf->num_output_fmts); in mtk_dpi_bridge_atomic_get_output_bus_fmts()
681 out_bus_format = bridge_state->output_bus_cfg.format; in mtk_dpi_bridge_atomic_check()
684 if (dpi->conf->num_output_fmts) in mtk_dpi_bridge_atomic_check()
685 out_bus_format = dpi->conf->output_fmts[0]; in mtk_dpi_bridge_atomic_check()
687 dev_dbg(dpi->dev, "input format 0x%04x, output format 0x%04x\n", in mtk_dpi_bridge_atomic_check()
688 bridge_state->input_bus_cfg.format, in mtk_dpi_bridge_atomic_check()
689 bridge_state->output_bus_cfg.format); in mtk_dpi_bridge_atomic_check()
691 dpi->output_fmt = out_bus_format; in mtk_dpi_bridge_atomic_check()
692 dpi->bit_num = MTK_DPI_OUT_BIT_NUM_8BITS; in mtk_dpi_bridge_atomic_check()
693 dpi->channel_swap = MTK_DPI_OUT_CHANNEL_SWAP_RGB; in mtk_dpi_bridge_atomic_check()
694 dpi->yc_map = MTK_DPI_OUT_YC_MAP_RGB; in mtk_dpi_bridge_atomic_check()
696 dpi->color_format = MTK_DPI_COLOR_FORMAT_YCBCR_422; in mtk_dpi_bridge_atomic_check()
698 dpi->color_format = MTK_DPI_COLOR_FORMAT_RGB; in mtk_dpi_bridge_atomic_check()
709 dpi->next_bridge = devm_drm_of_get_bridge(dpi->dev, dpi->dev->of_node, 1, -1); in mtk_dpi_bridge_attach()
710 if (IS_ERR(dpi->next_bridge)) { in mtk_dpi_bridge_attach()
711 ret = PTR_ERR(dpi->next_bridge); in mtk_dpi_bridge_attach()
712 if (ret == -EPROBE_DEFER) in mtk_dpi_bridge_attach()
716 dpi->next_bridge = devm_drm_of_get_bridge(dpi->dev, dpi->dev->of_node, 0, 0); in mtk_dpi_bridge_attach()
717 if (IS_ERR(dpi->next_bridge)) in mtk_dpi_bridge_attach()
718 return dev_err_probe(dpi->dev, PTR_ERR(dpi->next_bridge), in mtk_dpi_bridge_attach()
722 return drm_bridge_attach(bridge->encoder, dpi->next_bridge, in mtk_dpi_bridge_attach()
723 &dpi->bridge, flags); in mtk_dpi_bridge_attach()
732 drm_mode_copy(&dpi->mode, adjusted_mode); in mtk_dpi_bridge_mode_set()
741 if (dpi->pinctrl && dpi->pins_gpio) in mtk_dpi_bridge_disable()
742 pinctrl_select_state(dpi->pinctrl, dpi->pins_gpio); in mtk_dpi_bridge_disable()
749 if (dpi->pinctrl && dpi->pins_dpi) in mtk_dpi_bridge_enable()
750 pinctrl_select_state(dpi->pinctrl, dpi->pins_dpi); in mtk_dpi_bridge_enable()
753 mtk_dpi_set_display_mode(dpi, &dpi->mode); in mtk_dpi_bridge_enable()
764 if (mode->clock > dpi->conf->max_clock_khz) in mtk_dpi_bridge_mode_valid()
801 unsigned int encoder_index = drm_encoder_index(&dpi->encoder); in mtk_dpi_encoder_index()
811 struct mtk_drm_private *priv = drm_dev->dev_private; in mtk_dpi_bind()
814 dpi->mmsys_dev = priv->mmsys_dev; in mtk_dpi_bind()
815 ret = drm_simple_encoder_init(drm_dev, &dpi->encoder, in mtk_dpi_bind()
822 ret = mtk_find_possible_crtcs(drm_dev, dpi->dev); in mtk_dpi_bind()
825 dpi->encoder.possible_crtcs = ret; in mtk_dpi_bind()
827 ret = drm_bridge_attach(&dpi->encoder, &dpi->bridge, NULL, in mtk_dpi_bind()
832 dpi->connector = drm_bridge_connector_init(drm_dev, &dpi->encoder); in mtk_dpi_bind()
833 if (IS_ERR(dpi->connector)) { in mtk_dpi_bind()
835 ret = PTR_ERR(dpi->connector); in mtk_dpi_bind()
838 drm_connector_attach_encoder(dpi->connector, &dpi->encoder); in mtk_dpi_bind()
843 drm_encoder_cleanup(&dpi->encoder); in mtk_dpi_bind()
852 drm_encoder_cleanup(&dpi->encoder); in mtk_dpi_unbind()
1019 struct device *dev = &pdev->dev; in mtk_dpi_probe()
1025 return -ENOMEM; in mtk_dpi_probe()
1027 dpi->dev = dev; in mtk_dpi_probe()
1028 dpi->conf = (struct mtk_dpi_conf *)of_device_get_match_data(dev); in mtk_dpi_probe()
1029 dpi->output_fmt = MEDIA_BUS_FMT_RGB888_1X24; in mtk_dpi_probe()
1031 dpi->pinctrl = devm_pinctrl_get(&pdev->dev); in mtk_dpi_probe()
1032 if (IS_ERR(dpi->pinctrl)) { in mtk_dpi_probe()
1033 dpi->pinctrl = NULL; in mtk_dpi_probe()
1034 dev_dbg(&pdev->dev, "Cannot find pinctrl!\n"); in mtk_dpi_probe()
1036 if (dpi->pinctrl) { in mtk_dpi_probe()
1037 dpi->pins_gpio = pinctrl_lookup_state(dpi->pinctrl, "sleep"); in mtk_dpi_probe()
1038 if (IS_ERR(dpi->pins_gpio)) { in mtk_dpi_probe()
1039 dpi->pins_gpio = NULL; in mtk_dpi_probe()
1040 dev_dbg(&pdev->dev, "Cannot find pinctrl idle!\n"); in mtk_dpi_probe()
1042 if (dpi->pins_gpio) in mtk_dpi_probe()
1043 pinctrl_select_state(dpi->pinctrl, dpi->pins_gpio); in mtk_dpi_probe()
1045 dpi->pins_dpi = pinctrl_lookup_state(dpi->pinctrl, "default"); in mtk_dpi_probe()
1046 if (IS_ERR(dpi->pins_dpi)) { in mtk_dpi_probe()
1047 dpi->pins_dpi = NULL; in mtk_dpi_probe()
1048 dev_dbg(&pdev->dev, "Cannot find pinctrl active!\n"); in mtk_dpi_probe()
1051 dpi->regs = devm_platform_ioremap_resource(pdev, 0); in mtk_dpi_probe()
1052 if (IS_ERR(dpi->regs)) in mtk_dpi_probe()
1053 return dev_err_probe(dev, PTR_ERR(dpi->regs), in mtk_dpi_probe()
1056 dpi->engine_clk = devm_clk_get(dev, "engine"); in mtk_dpi_probe()
1057 if (IS_ERR(dpi->engine_clk)) in mtk_dpi_probe()
1058 return dev_err_probe(dev, PTR_ERR(dpi->engine_clk), in mtk_dpi_probe()
1061 dpi->pixel_clk = devm_clk_get(dev, "pixel"); in mtk_dpi_probe()
1062 if (IS_ERR(dpi->pixel_clk)) in mtk_dpi_probe()
1063 return dev_err_probe(dev, PTR_ERR(dpi->pixel_clk), in mtk_dpi_probe()
1066 dpi->tvd_clk = devm_clk_get(dev, "pll"); in mtk_dpi_probe()
1067 if (IS_ERR(dpi->tvd_clk)) in mtk_dpi_probe()
1068 return dev_err_probe(dev, PTR_ERR(dpi->tvd_clk), in mtk_dpi_probe()
1071 dpi->irq = platform_get_irq(pdev, 0); in mtk_dpi_probe()
1072 if (dpi->irq < 0) in mtk_dpi_probe()
1073 return dpi->irq; in mtk_dpi_probe()
1077 dpi->bridge.funcs = &mtk_dpi_bridge_funcs; in mtk_dpi_probe()
1078 dpi->bridge.of_node = dev->of_node; in mtk_dpi_probe()
1079 dpi->bridge.type = DRM_MODE_CONNECTOR_DPI; in mtk_dpi_probe()
1081 ret = devm_drm_bridge_add(dev, &dpi->bridge); in mtk_dpi_probe()
1094 component_del(&pdev->dev, &mtk_dpi_component_ops); in mtk_dpi_remove()
1098 { .compatible = "mediatek,mt2701-dpi", .data = &mt2701_conf },
1099 { .compatible = "mediatek,mt8173-dpi", .data = &mt8173_conf },
1100 { .compatible = "mediatek,mt8183-dpi", .data = &mt8183_conf },
1101 { .compatible = "mediatek,mt8186-dpi", .data = &mt8186_conf },
1102 { .compatible = "mediatek,mt8188-dp-intf", .data = &mt8195_dpintf_conf },
1103 { .compatible = "mediatek,mt8192-dpi", .data = &mt8192_conf },
1104 { .compatible = "mediatek,mt8195-dp-intf", .data = &mt8195_dpintf_conf },
1113 .name = "mediatek-dpi",