Lines Matching full:lvds
3 * R-Car LVDS Encoder
50 #define RCAR_LVDS_QUIRK_LANES BIT(0) /* LVDS lanes 1 and 3 inverted */
59 void (*pll_setup)(struct rcar_lvds *lvds, unsigned int freq);
86 static u32 rcar_lvds_read(struct rcar_lvds *lvds, u32 reg) in rcar_lvds_read() argument
88 return ioread32(lvds->mmio + reg); in rcar_lvds_read()
91 static void rcar_lvds_write(struct rcar_lvds *lvds, u32 reg, u32 data) in rcar_lvds_write() argument
93 iowrite32(data, lvds->mmio + reg); in rcar_lvds_write()
100 static void rcar_lvds_pll_setup_gen2(struct rcar_lvds *lvds, unsigned int freq) in rcar_lvds_pll_setup_gen2() argument
113 rcar_lvds_write(lvds, LVDPLLCR, val); in rcar_lvds_pll_setup_gen2()
116 static void rcar_lvds_pll_setup_gen3(struct rcar_lvds *lvds, unsigned int freq) in rcar_lvds_pll_setup_gen3() argument
129 rcar_lvds_write(lvds, LVDPLLCR, val); in rcar_lvds_pll_setup_gen3()
141 static void rcar_lvds_d3_e3_pll_calc(struct rcar_lvds *lvds, struct clk *clk, in rcar_lvds_d3_e3_pll_calc() argument
157 * The LVDS PLL is made of a pre-divider and a multiplier (strangely in rcar_lvds_d3_e3_pll_calc()
171 * clock (as LVDS transmits 7 bits per lane per clock sample). in rcar_lvds_d3_e3_pll_calc()
179 * The /7 divider is optional, it is enabled when the LVDS PLL is used in rcar_lvds_d3_e3_pll_calc()
180 * to drive the LVDS encoder, and disabled when used to generate a dot in rcar_lvds_d3_e3_pll_calc()
181 * clock for the DU RGB output, without using the LVDS encoder. in rcar_lvds_d3_e3_pll_calc()
265 dev_dbg(lvds->dev, in rcar_lvds_d3_e3_pll_calc()
272 static void rcar_lvds_pll_setup_d3_e3(struct rcar_lvds *lvds, in rcar_lvds_pll_setup_d3_e3() argument
278 rcar_lvds_d3_e3_pll_calc(lvds, lvds->clocks.dotclkin[0], freq, &pll, in rcar_lvds_pll_setup_d3_e3()
280 rcar_lvds_d3_e3_pll_calc(lvds, lvds->clocks.dotclkin[1], freq, &pll, in rcar_lvds_pll_setup_d3_e3()
282 rcar_lvds_d3_e3_pll_calc(lvds, lvds->clocks.extal, freq, &pll, in rcar_lvds_pll_setup_d3_e3()
295 rcar_lvds_write(lvds, LVDPLLCR, lvdpllcr); in rcar_lvds_pll_setup_d3_e3()
302 rcar_lvds_write(lvds, LVDDIV, LVDDIV_DIVSEL | in rcar_lvds_pll_setup_d3_e3()
305 rcar_lvds_write(lvds, LVDDIV, 0); in rcar_lvds_pll_setup_d3_e3()
312 static enum rcar_lvds_mode rcar_lvds_get_lvds_mode(struct rcar_lvds *lvds, in rcar_lvds_get_lvds_mode() argument
319 * There is no API yet to retrieve LVDS mode from a bridge, only panels in rcar_lvds_get_lvds_mode()
322 if (!lvds->panel) in rcar_lvds_get_lvds_mode()
327 dev_warn(lvds->dev, in rcar_lvds_get_lvds_mode()
328 "no LVDS bus format reported, using JEIDA\n"); in rcar_lvds_get_lvds_mode()
341 dev_warn(lvds->dev, in rcar_lvds_get_lvds_mode()
342 "unsupported LVDS bus format 0x%04x, using JEIDA\n", in rcar_lvds_get_lvds_mode()
358 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in rcar_lvds_enable() local
363 ret = pm_runtime_resume_and_get(lvds->dev); in rcar_lvds_enable()
367 /* Enable the companion LVDS encoder in dual-link mode. */ in rcar_lvds_enable()
368 if (lvds->link_type != RCAR_LVDS_SINGLE_LINK && lvds->companion) in rcar_lvds_enable()
369 rcar_lvds_enable(lvds->companion, state, crtc, connector); in rcar_lvds_enable()
379 rcar_lvds_write(lvds, LVDCTRCR, LVDCTRCR_CTR3SEL_ZERO | in rcar_lvds_enable()
383 if (lvds->info->quirks & RCAR_LVDS_QUIRK_LANES) in rcar_lvds_enable()
390 rcar_lvds_write(lvds, LVDCHCR, lvdhcr); in rcar_lvds_enable()
392 if (lvds->info->quirks & RCAR_LVDS_QUIRK_DUAL_LINK) { in rcar_lvds_enable()
395 if (lvds->link_type != RCAR_LVDS_SINGLE_LINK) { in rcar_lvds_enable()
403 bool swap_pixels = lvds->link_type == in rcar_lvds_enable()
408 * an LVDS dual-link connection. in rcar_lvds_enable()
414 | (lvds->companion && swap_pixels ? in rcar_lvds_enable()
417 rcar_lvds_write(lvds, LVDSTRIPE, lvdstripe); in rcar_lvds_enable()
427 if ((lvds->link_type == RCAR_LVDS_SINGLE_LINK || lvds->companion) && in rcar_lvds_enable()
428 !(lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL)) { in rcar_lvds_enable()
434 lvds->info->pll_setup(lvds, mode->clock * 1000); in rcar_lvds_enable()
437 /* Set the LVDS mode and select the input. */ in rcar_lvds_enable()
438 lvdcr0 = rcar_lvds_get_lvds_mode(lvds, connector) << LVDCR0_LVMD_SHIFT; in rcar_lvds_enable()
440 if (lvds->bridge.encoder) { in rcar_lvds_enable()
445 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in rcar_lvds_enable()
448 rcar_lvds_write(lvds, LVDCR1, in rcar_lvds_enable()
452 if (lvds->info->gen < 3) { in rcar_lvds_enable()
453 /* Enable LVDS operation and turn the bias circuitry on. */ in rcar_lvds_enable()
455 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in rcar_lvds_enable()
458 if (!(lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL)) { in rcar_lvds_enable()
464 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in rcar_lvds_enable()
467 if (lvds->info->quirks & RCAR_LVDS_QUIRK_PWD) { in rcar_lvds_enable()
468 /* Set LVDS normal mode. */ in rcar_lvds_enable()
470 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in rcar_lvds_enable()
473 if (lvds->info->quirks & RCAR_LVDS_QUIRK_GEN3_LVEN) { in rcar_lvds_enable()
475 * Turn on the LVDS PHY. On D3, the LVEN and LVRES bit must be in rcar_lvds_enable()
479 if (!(lvds->info->quirks & RCAR_LVDS_QUIRK_PWD)) in rcar_lvds_enable()
480 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in rcar_lvds_enable()
483 if (!(lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL)) { in rcar_lvds_enable()
490 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in rcar_lvds_enable()
495 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in rcar_lvds_disable() local
503 lvdcr0 = rcar_lvds_read(lvds, LVDCR0); in rcar_lvds_disable()
506 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in rcar_lvds_disable()
508 if (lvds->info->quirks & RCAR_LVDS_QUIRK_GEN3_LVEN) { in rcar_lvds_disable()
510 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in rcar_lvds_disable()
513 if (lvds->info->quirks & RCAR_LVDS_QUIRK_PWD) { in rcar_lvds_disable()
515 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in rcar_lvds_disable()
518 if (!(lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL)) { in rcar_lvds_disable()
520 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in rcar_lvds_disable()
523 rcar_lvds_write(lvds, LVDCR0, 0); in rcar_lvds_disable()
524 rcar_lvds_write(lvds, LVDCR1, 0); in rcar_lvds_disable()
527 if (!(lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL)) in rcar_lvds_disable()
528 rcar_lvds_write(lvds, LVDPLLCR, 0); in rcar_lvds_disable()
530 /* Disable the companion LVDS encoder in dual-link mode. */ in rcar_lvds_disable()
531 if (lvds->link_type != RCAR_LVDS_SINGLE_LINK && lvds->companion) in rcar_lvds_disable()
532 rcar_lvds_disable(lvds->companion); in rcar_lvds_disable()
534 pm_runtime_put_sync(lvds->dev); in rcar_lvds_disable()
544 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in rcar_lvds_pclk_enable() local
547 if (WARN_ON(!(lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL))) in rcar_lvds_pclk_enable()
550 dev_dbg(lvds->dev, "enabling LVDS PLL, freq=%luHz\n", freq); in rcar_lvds_pclk_enable()
552 ret = pm_runtime_resume_and_get(lvds->dev); in rcar_lvds_pclk_enable()
556 rcar_lvds_pll_setup_d3_e3(lvds, freq, dot_clk_only); in rcar_lvds_pclk_enable()
564 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in rcar_lvds_pclk_disable() local
566 if (WARN_ON(!(lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL))) in rcar_lvds_pclk_disable()
569 dev_dbg(lvds->dev, "disabling LVDS PLL\n"); in rcar_lvds_pclk_disable()
574 rcar_lvds_write(lvds, LVDPLLCR, 0); in rcar_lvds_pclk_disable()
576 pm_runtime_put_sync(lvds->dev); in rcar_lvds_pclk_disable()
601 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in rcar_lvds_atomic_disable() local
604 * For D3 and E3, disabling the LVDS encoder before the DU would stall in rcar_lvds_atomic_disable()
610 * We could clear the LVRES bit already to disable the LVDS output, but in rcar_lvds_atomic_disable()
613 if (lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL) in rcar_lvds_atomic_disable()
623 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in rcar_lvds_mode_fixup() local
627 * The internal LVDS encoder has a restricted clock frequency operating in rcar_lvds_mode_fixup()
631 min_freq = lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL ? 5000 : 31000; in rcar_lvds_mode_fixup()
640 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in rcar_lvds_attach() local
642 if (!lvds->next_bridge) in rcar_lvds_attach()
645 return drm_bridge_attach(bridge->encoder, lvds->next_bridge, bridge, in rcar_lvds_attach()
661 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in rcar_lvds_dual_link() local
663 return lvds->link_type != RCAR_LVDS_SINGLE_LINK; in rcar_lvds_dual_link()
669 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in rcar_lvds_is_connected() local
671 return lvds->next_bridge != NULL; in rcar_lvds_is_connected()
679 static int rcar_lvds_parse_dt_companion(struct rcar_lvds *lvds) in rcar_lvds_parse_dt_companion() argument
685 struct device *dev = lvds->dev; in rcar_lvds_parse_dt_companion()
689 /* Locate the companion LVDS encoder for dual-link operation, if any. */ in rcar_lvds_parse_dt_companion()
700 dev_err(dev, "Companion LVDS encoder is invalid\n"); in rcar_lvds_parse_dt_companion()
719 lvds->link_type = RCAR_LVDS_DUAL_LINK_ODD_EVEN_PIXELS; in rcar_lvds_parse_dt_companion()
722 lvds->link_type = RCAR_LVDS_DUAL_LINK_EVEN_ODD_PIXELS; in rcar_lvds_parse_dt_companion()
731 if (lvds->next_bridge->timings && in rcar_lvds_parse_dt_companion()
732 lvds->next_bridge->timings->dual_link) in rcar_lvds_parse_dt_companion()
733 lvds->link_type = RCAR_LVDS_DUAL_LINK_EVEN_ODD_PIXELS; in rcar_lvds_parse_dt_companion()
735 lvds->link_type = RCAR_LVDS_SINGLE_LINK; in rcar_lvds_parse_dt_companion()
738 if (lvds->link_type == RCAR_LVDS_SINGLE_LINK) { in rcar_lvds_parse_dt_companion()
743 lvds->companion = of_drm_find_bridge(companion); in rcar_lvds_parse_dt_companion()
744 if (!lvds->companion) { in rcar_lvds_parse_dt_companion()
753 if (lvds->link_type == RCAR_LVDS_DUAL_LINK_ODD_EVEN_PIXELS) in rcar_lvds_parse_dt_companion()
765 companion_lvds = bridge_to_rcar_lvds(lvds->companion); in rcar_lvds_parse_dt_companion()
766 companion_lvds->link_type = lvds->link_type; in rcar_lvds_parse_dt_companion()
774 static int rcar_lvds_parse_dt(struct rcar_lvds *lvds) in rcar_lvds_parse_dt() argument
778 ret = drm_of_find_panel_or_bridge(lvds->dev->of_node, 1, 0, in rcar_lvds_parse_dt()
779 &lvds->panel, &lvds->next_bridge); in rcar_lvds_parse_dt()
783 if (lvds->panel) { in rcar_lvds_parse_dt()
784 lvds->next_bridge = devm_drm_panel_bridge_add(lvds->dev, in rcar_lvds_parse_dt()
785 lvds->panel); in rcar_lvds_parse_dt()
786 if (IS_ERR_OR_NULL(lvds->next_bridge)) { in rcar_lvds_parse_dt()
792 if (lvds->info->quirks & RCAR_LVDS_QUIRK_DUAL_LINK) in rcar_lvds_parse_dt()
793 ret = rcar_lvds_parse_dt_companion(lvds); in rcar_lvds_parse_dt()
797 * On D3/E3 the LVDS encoder provides a clock to the DU, which can be in rcar_lvds_parse_dt()
798 * used for the DPAD output even when the LVDS output is not connected. in rcar_lvds_parse_dt()
802 if (lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL) in rcar_lvds_parse_dt()
808 static struct clk *rcar_lvds_get_clock(struct rcar_lvds *lvds, const char *name, in rcar_lvds_get_clock() argument
813 clk = devm_clk_get(lvds->dev, name); in rcar_lvds_get_clock()
820 dev_err_probe(lvds->dev, PTR_ERR(clk), "failed to get %s clock\n", in rcar_lvds_get_clock()
826 static int rcar_lvds_get_clocks(struct rcar_lvds *lvds) in rcar_lvds_get_clocks() argument
828 lvds->clocks.mod = rcar_lvds_get_clock(lvds, NULL, false); in rcar_lvds_get_clocks()
829 if (IS_ERR(lvds->clocks.mod)) in rcar_lvds_get_clocks()
830 return PTR_ERR(lvds->clocks.mod); in rcar_lvds_get_clocks()
833 * LVDS encoders without an extended PLL have no external clock inputs. in rcar_lvds_get_clocks()
835 if (!(lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL)) in rcar_lvds_get_clocks()
838 lvds->clocks.extal = rcar_lvds_get_clock(lvds, "extal", true); in rcar_lvds_get_clocks()
839 if (IS_ERR(lvds->clocks.extal)) in rcar_lvds_get_clocks()
840 return PTR_ERR(lvds->clocks.extal); in rcar_lvds_get_clocks()
842 lvds->clocks.dotclkin[0] = rcar_lvds_get_clock(lvds, "dclkin.0", true); in rcar_lvds_get_clocks()
843 if (IS_ERR(lvds->clocks.dotclkin[0])) in rcar_lvds_get_clocks()
844 return PTR_ERR(lvds->clocks.dotclkin[0]); in rcar_lvds_get_clocks()
846 lvds->clocks.dotclkin[1] = rcar_lvds_get_clock(lvds, "dclkin.1", true); in rcar_lvds_get_clocks()
847 if (IS_ERR(lvds->clocks.dotclkin[1])) in rcar_lvds_get_clocks()
848 return PTR_ERR(lvds->clocks.dotclkin[1]); in rcar_lvds_get_clocks()
851 if (!lvds->clocks.extal && !lvds->clocks.dotclkin[0] && in rcar_lvds_get_clocks()
852 !lvds->clocks.dotclkin[1]) { in rcar_lvds_get_clocks()
853 dev_err(lvds->dev, in rcar_lvds_get_clocks()
878 struct rcar_lvds *lvds; in rcar_lvds_probe() local
881 lvds = devm_kzalloc(&pdev->dev, sizeof(*lvds), GFP_KERNEL); in rcar_lvds_probe()
882 if (lvds == NULL) in rcar_lvds_probe()
885 platform_set_drvdata(pdev, lvds); in rcar_lvds_probe()
887 lvds->dev = &pdev->dev; in rcar_lvds_probe()
888 lvds->info = of_device_get_match_data(&pdev->dev); in rcar_lvds_probe()
892 lvds->info = attr->data; in rcar_lvds_probe()
894 ret = rcar_lvds_parse_dt(lvds); in rcar_lvds_probe()
898 lvds->bridge.funcs = &rcar_lvds_bridge_ops; in rcar_lvds_probe()
899 lvds->bridge.of_node = pdev->dev.of_node; in rcar_lvds_probe()
901 lvds->mmio = devm_platform_ioremap_resource(pdev, 0); in rcar_lvds_probe()
902 if (IS_ERR(lvds->mmio)) in rcar_lvds_probe()
903 return PTR_ERR(lvds->mmio); in rcar_lvds_probe()
905 ret = rcar_lvds_get_clocks(lvds); in rcar_lvds_probe()
909 lvds->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); in rcar_lvds_probe()
910 if (IS_ERR(lvds->rstc)) in rcar_lvds_probe()
911 return dev_err_probe(&pdev->dev, PTR_ERR(lvds->rstc), in rcar_lvds_probe()
916 drm_bridge_add(&lvds->bridge); in rcar_lvds_probe()
923 struct rcar_lvds *lvds = platform_get_drvdata(pdev); in rcar_lvds_remove() local
925 drm_bridge_remove(&lvds->bridge); in rcar_lvds_remove()
960 { .compatible = "renesas,r8a7742-lvds", .data = &rcar_lvds_gen2_info },
961 { .compatible = "renesas,r8a7743-lvds", .data = &rcar_lvds_gen2_info },
962 { .compatible = "renesas,r8a7744-lvds", .data = &rcar_lvds_gen2_info },
963 { .compatible = "renesas,r8a774a1-lvds", .data = &rcar_lvds_gen3_info },
964 { .compatible = "renesas,r8a774b1-lvds", .data = &rcar_lvds_gen3_info },
965 { .compatible = "renesas,r8a774c0-lvds", .data = &rcar_lvds_r8a77990_info },
966 { .compatible = "renesas,r8a774e1-lvds", .data = &rcar_lvds_gen3_info },
967 { .compatible = "renesas,r8a7790-lvds", .data = &rcar_lvds_gen2_info },
968 { .compatible = "renesas,r8a7791-lvds", .data = &rcar_lvds_gen2_info },
969 { .compatible = "renesas,r8a7793-lvds", .data = &rcar_lvds_gen2_info },
970 { .compatible = "renesas,r8a7795-lvds", .data = &rcar_lvds_gen3_info },
971 { .compatible = "renesas,r8a7796-lvds", .data = &rcar_lvds_gen3_info },
972 { .compatible = "renesas,r8a77961-lvds", .data = &rcar_lvds_gen3_info },
973 { .compatible = "renesas,r8a77965-lvds", .data = &rcar_lvds_gen3_info },
974 { .compatible = "renesas,r8a77970-lvds", .data = &rcar_lvds_r8a77970_info },
975 { .compatible = "renesas,r8a77980-lvds", .data = &rcar_lvds_gen3_info },
976 { .compatible = "renesas,r8a77990-lvds", .data = &rcar_lvds_r8a77990_info },
977 { .compatible = "renesas,r8a77995-lvds", .data = &rcar_lvds_r8a77995_info },
985 struct rcar_lvds *lvds = dev_get_drvdata(dev); in rcar_lvds_runtime_suspend() local
987 clk_disable_unprepare(lvds->clocks.mod); in rcar_lvds_runtime_suspend()
989 reset_control_assert(lvds->rstc); in rcar_lvds_runtime_suspend()
996 struct rcar_lvds *lvds = dev_get_drvdata(dev); in rcar_lvds_runtime_resume() local
999 ret = reset_control_deassert(lvds->rstc); in rcar_lvds_runtime_resume()
1003 ret = clk_prepare_enable(lvds->clocks.mod); in rcar_lvds_runtime_resume()
1010 reset_control_assert(lvds->rstc); in rcar_lvds_runtime_resume()
1023 .name = "rcar-lvds",
1032 MODULE_DESCRIPTION("Renesas R-Car LVDS Encoder Driver");