Lines Matching +full:mt8192 +full:- +full:pinctrl

1 // SPDX-License-Identifier: GPL-2.0-only
11 #include <linux/media-bus-format.h>
15 #include <linux/pinctrl/consumer.h>
79 struct pinctrl *pinctrl; member
118 * struct mtk_dpi_conf - Configuration of mediatek dpi.
159 u32 tmp = readl(dpi->regs + offset) & ~mask; in mtk_dpi_mask()
162 writel(tmp, dpi->regs + offset); in mtk_dpi_mask()
183 mtk_dpi_mask(dpi, DPI_TGEN_HWIDTH, sync->sync_width << HPW, in mtk_dpi_config_hsync()
184 dpi->conf->dimension_mask << HPW); in mtk_dpi_config_hsync()
185 mtk_dpi_mask(dpi, DPI_TGEN_HPORCH, sync->back_porch << HBP, in mtk_dpi_config_hsync()
186 dpi->conf->dimension_mask << HBP); in mtk_dpi_config_hsync()
187 mtk_dpi_mask(dpi, DPI_TGEN_HPORCH, sync->front_porch << HFP, in mtk_dpi_config_hsync()
188 dpi->conf->dimension_mask << HFP); in mtk_dpi_config_hsync()
196 sync->shift_half_line << VSYNC_HALF_LINE_SHIFT, in mtk_dpi_config_vsync()
199 sync->sync_width << VSYNC_WIDTH_SHIFT, in mtk_dpi_config_vsync()
200 dpi->conf->dimension_mask << VSYNC_WIDTH_SHIFT); in mtk_dpi_config_vsync()
202 sync->back_porch << VSYNC_BACK_PORCH_SHIFT, in mtk_dpi_config_vsync()
203 dpi->conf->dimension_mask << VSYNC_BACK_PORCH_SHIFT); in mtk_dpi_config_vsync()
205 sync->front_porch << VSYNC_FRONT_PORCH_SHIFT, in mtk_dpi_config_vsync()
206 dpi->conf->dimension_mask << VSYNC_FRONT_PORCH_SHIFT); in mtk_dpi_config_vsync()
243 pol = (dpi_pol->hsync_pol == MTK_DPI_POLARITY_RISING ? 0 : HSYNC_POL) | in mtk_dpi_config_pol()
244 (dpi_pol->vsync_pol == MTK_DPI_POLARITY_RISING ? 0 : VSYNC_POL); in mtk_dpi_config_pol()
245 if (dpi->conf->is_ck_de_pol) { in mtk_dpi_config_pol()
247 pol |= (dpi_pol->ck_pol == MTK_DPI_POLARITY_RISING ? in mtk_dpi_config_pol()
249 (dpi_pol->de_pol == MTK_DPI_POLARITY_RISING ? in mtk_dpi_config_pol()
269 dpi->conf->hvsize_mask << HSIZE); in mtk_dpi_config_fb_size()
271 dpi->conf->hvsize_mask << VSIZE); in mtk_dpi_config_fb_size()
278 if (drm_default_rgb_quant_range(&dpi->mode) == in mtk_dpi_config_channel_limit()
386 val << dpi->conf->channel_swap_shift, in mtk_dpi_config_channel_swap()
387 CH_SWAP_MASK << dpi->conf->channel_swap_shift); in mtk_dpi_config_channel_swap()
392 mtk_dpi_mask(dpi, DPI_CON, enable ? dpi->conf->yuv422_en_bit : 0, in mtk_dpi_config_yuv422_enable()
393 dpi->conf->yuv422_en_bit); in mtk_dpi_config_yuv422_enable()
398 mtk_dpi_mask(dpi, DPI_CON, enable ? dpi->conf->csc_enable_bit : 0, in mtk_dpi_config_csc_enable()
399 dpi->conf->csc_enable_bit); in mtk_dpi_config_csc_enable()
409 mtk_dpi_mask(dpi, dpi->conf->reg_h_fre_con, H_FRE_2N, H_FRE_2N); in mtk_dpi_config_2n_h_fre()
414 if (dpi->conf->edge_sel_en) in mtk_dpi_config_disable_edge()
415 mtk_dpi_mask(dpi, dpi->conf->reg_h_fre_con, 0, EDGE_SEL_EN); in mtk_dpi_config_disable_edge()
431 mtk_dpi_mask(dpi, DPI_MATRIX_SET, dpi->mode.hdisplay <= 720 ? in mtk_dpi_config_color_format()
437 if (dpi->conf->swap_input_support) in mtk_dpi_config_color_format()
444 if ((dpi->output_fmt == MEDIA_BUS_FMT_RGB888_2X12_LE) || in mtk_dpi_dual_edge()
445 (dpi->output_fmt == MEDIA_BUS_FMT_RGB888_2X12_BE)) { in mtk_dpi_dual_edge()
449 dpi->output_fmt == MEDIA_BUS_FMT_RGB888_2X12_LE ? in mtk_dpi_dual_edge()
458 if (WARN_ON(dpi->refcount == 0)) in mtk_dpi_power_off()
461 if (--dpi->refcount != 0) in mtk_dpi_power_off()
464 if (dpi->pinctrl && dpi->pins_gpio) in mtk_dpi_power_off()
465 pinctrl_select_state(dpi->pinctrl, dpi->pins_gpio); in mtk_dpi_power_off()
468 clk_disable_unprepare(dpi->pixel_clk); in mtk_dpi_power_off()
469 clk_disable_unprepare(dpi->engine_clk); in mtk_dpi_power_off()
476 if (++dpi->refcount != 1) in mtk_dpi_power_on()
479 ret = clk_prepare_enable(dpi->engine_clk); in mtk_dpi_power_on()
481 dev_err(dpi->dev, "Failed to enable engine clock: %d\n", ret); in mtk_dpi_power_on()
485 ret = clk_prepare_enable(dpi->pixel_clk); in mtk_dpi_power_on()
487 dev_err(dpi->dev, "Failed to enable pixel clock: %d\n", ret); in mtk_dpi_power_on()
491 if (dpi->pinctrl && dpi->pins_dpi) in mtk_dpi_power_on()
492 pinctrl_select_state(dpi->pinctrl, dpi->pins_dpi); in mtk_dpi_power_on()
497 clk_disable_unprepare(dpi->engine_clk); in mtk_dpi_power_on()
499 dpi->refcount--; in mtk_dpi_power_on()
517 factor = dpi->conf->cal_factor(mode->clock); in mtk_dpi_set_display_mode()
521 dev_dbg(dpi->dev, "Want PLL %lu Hz, pixel clock %lu Hz\n", in mtk_dpi_set_display_mode()
524 clk_set_rate(dpi->tvd_clk, pll_rate); in mtk_dpi_set_display_mode()
525 pll_rate = clk_get_rate(dpi->tvd_clk); in mtk_dpi_set_display_mode()
533 vm.pixelclock /= dpi->conf->pixels_per_iter; in mtk_dpi_set_display_mode()
535 if ((dpi->output_fmt == MEDIA_BUS_FMT_RGB888_2X12_LE) || in mtk_dpi_set_display_mode()
536 (dpi->output_fmt == MEDIA_BUS_FMT_RGB888_2X12_BE)) in mtk_dpi_set_display_mode()
537 clk_set_rate(dpi->pixel_clk, vm.pixelclock * 2); in mtk_dpi_set_display_mode()
539 clk_set_rate(dpi->pixel_clk, vm.pixelclock); in mtk_dpi_set_display_mode()
542 vm.pixelclock = clk_get_rate(dpi->pixel_clk); in mtk_dpi_set_display_mode()
544 dev_dbg(dpi->dev, "Got PLL %lu Hz, pixel clock %lu Hz\n", in mtk_dpi_set_display_mode()
559 hsync.sync_width = vm.hsync_len / dpi->conf->pixels_per_iter; in mtk_dpi_set_display_mode()
560 hsync.back_porch = vm.hback_porch / dpi->conf->pixels_per_iter; in mtk_dpi_set_display_mode()
561 hsync.front_porch = vm.hfront_porch / dpi->conf->pixels_per_iter; in mtk_dpi_set_display_mode()
570 mode->flags & DRM_MODE_FLAG_3D_MASK) { in mtk_dpi_set_display_mode()
577 !(mode->flags & DRM_MODE_FLAG_3D_MASK)) { in mtk_dpi_set_display_mode()
581 mode->flags & DRM_MODE_FLAG_3D_MASK) { in mtk_dpi_set_display_mode()
593 mtk_dpi_config_3d(dpi, !!(mode->flags & DRM_MODE_FLAG_3D_MASK)); in mtk_dpi_set_display_mode()
602 mtk_dpi_config_bit_num(dpi, dpi->bit_num); in mtk_dpi_set_display_mode()
603 mtk_dpi_config_channel_swap(dpi, dpi->channel_swap); in mtk_dpi_set_display_mode()
604 mtk_dpi_config_color_format(dpi, dpi->color_format); in mtk_dpi_set_display_mode()
605 if (dpi->conf->support_direct_pin) { in mtk_dpi_set_display_mode()
606 mtk_dpi_config_yc_map(dpi, dpi->yc_map); in mtk_dpi_set_display_mode()
611 if (dpi->conf->input_2pixel) { in mtk_dpi_set_display_mode()
631 if (!dpi->conf->output_fmts) { in mtk_dpi_bridge_atomic_get_output_bus_fmts()
632 dev_err(dpi->dev, "output_fmts should not be null\n"); in mtk_dpi_bridge_atomic_get_output_bus_fmts()
636 output_fmts = kcalloc(dpi->conf->num_output_fmts, sizeof(*output_fmts), in mtk_dpi_bridge_atomic_get_output_bus_fmts()
641 *num_output_fmts = dpi->conf->num_output_fmts; in mtk_dpi_bridge_atomic_get_output_bus_fmts()
643 memcpy(output_fmts, dpi->conf->output_fmts, in mtk_dpi_bridge_atomic_get_output_bus_fmts()
644 sizeof(*output_fmts) * dpi->conf->num_output_fmts); in mtk_dpi_bridge_atomic_get_output_bus_fmts()
679 out_bus_format = bridge_state->output_bus_cfg.format; in mtk_dpi_bridge_atomic_check()
682 if (dpi->conf->num_output_fmts) in mtk_dpi_bridge_atomic_check()
683 out_bus_format = dpi->conf->output_fmts[0]; in mtk_dpi_bridge_atomic_check()
685 dev_dbg(dpi->dev, "input format 0x%04x, output format 0x%04x\n", in mtk_dpi_bridge_atomic_check()
686 bridge_state->input_bus_cfg.format, in mtk_dpi_bridge_atomic_check()
687 bridge_state->output_bus_cfg.format); in mtk_dpi_bridge_atomic_check()
689 dpi->output_fmt = out_bus_format; in mtk_dpi_bridge_atomic_check()
690 dpi->bit_num = MTK_DPI_OUT_BIT_NUM_8BITS; in mtk_dpi_bridge_atomic_check()
691 dpi->channel_swap = MTK_DPI_OUT_CHANNEL_SWAP_RGB; in mtk_dpi_bridge_atomic_check()
692 dpi->yc_map = MTK_DPI_OUT_YC_MAP_RGB; in mtk_dpi_bridge_atomic_check()
694 dpi->color_format = MTK_DPI_COLOR_FORMAT_YCBCR_422; in mtk_dpi_bridge_atomic_check()
696 dpi->color_format = MTK_DPI_COLOR_FORMAT_RGB; in mtk_dpi_bridge_atomic_check()
706 return drm_bridge_attach(bridge->encoder, dpi->next_bridge, in mtk_dpi_bridge_attach()
707 &dpi->bridge, flags); in mtk_dpi_bridge_attach()
716 drm_mode_copy(&dpi->mode, adjusted_mode); in mtk_dpi_bridge_mode_set()
731 mtk_dpi_set_display_mode(dpi, &dpi->mode); in mtk_dpi_bridge_enable()
742 if (mode->clock > dpi->conf->max_clock_khz) in mtk_dpi_bridge_mode_valid()
782 ret = drm_simple_encoder_init(drm_dev, &dpi->encoder, in mtk_dpi_bind()
789 dpi->encoder.possible_crtcs = mtk_drm_find_possible_crtc_by_comp(drm_dev, dpi->dev); in mtk_dpi_bind()
791 ret = drm_bridge_attach(&dpi->encoder, &dpi->bridge, NULL, in mtk_dpi_bind()
796 dpi->connector = drm_bridge_connector_init(drm_dev, &dpi->encoder); in mtk_dpi_bind()
797 if (IS_ERR(dpi->connector)) { in mtk_dpi_bind()
799 ret = PTR_ERR(dpi->connector); in mtk_dpi_bind()
802 drm_connector_attach_encoder(dpi->connector, &dpi->encoder); in mtk_dpi_bind()
807 drm_encoder_cleanup(&dpi->encoder); in mtk_dpi_bind()
816 drm_encoder_cleanup(&dpi->encoder); in mtk_dpi_unbind()
965 struct device *dev = &pdev->dev; in mtk_dpi_probe()
972 return -ENOMEM; in mtk_dpi_probe()
974 dpi->dev = dev; in mtk_dpi_probe()
975 dpi->conf = (struct mtk_dpi_conf *)of_device_get_match_data(dev); in mtk_dpi_probe()
976 dpi->output_fmt = MEDIA_BUS_FMT_RGB888_1X24; in mtk_dpi_probe()
978 dpi->pinctrl = devm_pinctrl_get(&pdev->dev); in mtk_dpi_probe()
979 if (IS_ERR(dpi->pinctrl)) { in mtk_dpi_probe()
980 dpi->pinctrl = NULL; in mtk_dpi_probe()
981 dev_dbg(&pdev->dev, "Cannot find pinctrl!\n"); in mtk_dpi_probe()
983 if (dpi->pinctrl) { in mtk_dpi_probe()
984 dpi->pins_gpio = pinctrl_lookup_state(dpi->pinctrl, "sleep"); in mtk_dpi_probe()
985 if (IS_ERR(dpi->pins_gpio)) { in mtk_dpi_probe()
986 dpi->pins_gpio = NULL; in mtk_dpi_probe()
987 dev_dbg(&pdev->dev, "Cannot find pinctrl idle!\n"); in mtk_dpi_probe()
989 if (dpi->pins_gpio) in mtk_dpi_probe()
990 pinctrl_select_state(dpi->pinctrl, dpi->pins_gpio); in mtk_dpi_probe()
992 dpi->pins_dpi = pinctrl_lookup_state(dpi->pinctrl, "default"); in mtk_dpi_probe()
993 if (IS_ERR(dpi->pins_dpi)) { in mtk_dpi_probe()
994 dpi->pins_dpi = NULL; in mtk_dpi_probe()
995 dev_dbg(&pdev->dev, "Cannot find pinctrl active!\n"); in mtk_dpi_probe()
999 dpi->regs = devm_ioremap_resource(dev, mem); in mtk_dpi_probe()
1000 if (IS_ERR(dpi->regs)) { in mtk_dpi_probe()
1001 ret = PTR_ERR(dpi->regs); in mtk_dpi_probe()
1006 dpi->engine_clk = devm_clk_get(dev, "engine"); in mtk_dpi_probe()
1007 if (IS_ERR(dpi->engine_clk)) { in mtk_dpi_probe()
1008 ret = PTR_ERR(dpi->engine_clk); in mtk_dpi_probe()
1009 if (ret != -EPROBE_DEFER) in mtk_dpi_probe()
1015 dpi->pixel_clk = devm_clk_get(dev, "pixel"); in mtk_dpi_probe()
1016 if (IS_ERR(dpi->pixel_clk)) { in mtk_dpi_probe()
1017 ret = PTR_ERR(dpi->pixel_clk); in mtk_dpi_probe()
1018 if (ret != -EPROBE_DEFER) in mtk_dpi_probe()
1024 dpi->tvd_clk = devm_clk_get(dev, "pll"); in mtk_dpi_probe()
1025 if (IS_ERR(dpi->tvd_clk)) { in mtk_dpi_probe()
1026 ret = PTR_ERR(dpi->tvd_clk); in mtk_dpi_probe()
1027 if (ret != -EPROBE_DEFER) in mtk_dpi_probe()
1033 dpi->irq = platform_get_irq(pdev, 0); in mtk_dpi_probe()
1034 if (dpi->irq <= 0) in mtk_dpi_probe()
1035 return -EINVAL; in mtk_dpi_probe()
1037 ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0, in mtk_dpi_probe()
1038 NULL, &dpi->next_bridge); in mtk_dpi_probe()
1042 dev_info(dev, "Found bridge node: %pOF\n", dpi->next_bridge->of_node); in mtk_dpi_probe()
1046 dpi->bridge.funcs = &mtk_dpi_bridge_funcs; in mtk_dpi_probe()
1047 dpi->bridge.of_node = dev->of_node; in mtk_dpi_probe()
1048 dpi->bridge.type = DRM_MODE_CONNECTOR_DPI; in mtk_dpi_probe()
1050 drm_bridge_add(&dpi->bridge); in mtk_dpi_probe()
1054 drm_bridge_remove(&dpi->bridge); in mtk_dpi_probe()
1066 component_del(&pdev->dev, &mtk_dpi_component_ops); in mtk_dpi_remove()
1067 drm_bridge_remove(&dpi->bridge); in mtk_dpi_remove()
1073 { .compatible = "mediatek,mt2701-dpi",
1076 { .compatible = "mediatek,mt8173-dpi",
1079 { .compatible = "mediatek,mt8183-dpi",
1082 { .compatible = "mediatek,mt8192-dpi",
1085 { .compatible = "mediatek,mt8195-dp-intf",
1096 .name = "mediatek-dpi",