Lines Matching full:lvds
3 * rcar_lvds.c -- R-Car LVDS Encoder
47 #define RCAR_LVDS_QUIRK_LANES BIT(0) /* LVDS lanes 1 and 3 inverted */
56 void (*pll_setup)(struct rcar_lvds *lvds, unsigned int freq);
86 static void rcar_lvds_write(struct rcar_lvds *lvds, u32 reg, u32 data) in rcar_lvds_write() argument
88 iowrite32(data, lvds->mmio + reg); in rcar_lvds_write()
97 struct rcar_lvds *lvds = connector_to_rcar_lvds(connector); in rcar_lvds_connector_get_modes() local
99 return drm_panel_get_modes(lvds->panel, connector); in rcar_lvds_connector_get_modes()
105 struct rcar_lvds *lvds = connector_to_rcar_lvds(connector); in rcar_lvds_connector_atomic_check() local
115 dev_dbg(lvds->dev, "connector: empty modes list\n"); in rcar_lvds_connector_atomic_check()
154 static void rcar_lvds_pll_setup_gen2(struct rcar_lvds *lvds, unsigned int freq) in rcar_lvds_pll_setup_gen2() argument
167 rcar_lvds_write(lvds, LVDPLLCR, val); in rcar_lvds_pll_setup_gen2()
170 static void rcar_lvds_pll_setup_gen3(struct rcar_lvds *lvds, unsigned int freq) in rcar_lvds_pll_setup_gen3() argument
183 rcar_lvds_write(lvds, LVDPLLCR, val); in rcar_lvds_pll_setup_gen3()
195 static void rcar_lvds_d3_e3_pll_calc(struct rcar_lvds *lvds, struct clk *clk, in rcar_lvds_d3_e3_pll_calc() argument
211 * The LVDS PLL is made of a pre-divider and a multiplier (strangely in rcar_lvds_d3_e3_pll_calc()
225 * clock (as LVDS transmits 7 bits per lane per clock sample). in rcar_lvds_d3_e3_pll_calc()
233 * The /7 divider is optional, it is enabled when the LVDS PLL is used in rcar_lvds_d3_e3_pll_calc()
234 * to drive the LVDS encoder, and disabled when used to generate a dot in rcar_lvds_d3_e3_pll_calc()
235 * clock for the DU RGB output, without using the LVDS encoder. in rcar_lvds_d3_e3_pll_calc()
319 dev_dbg(lvds->dev, in rcar_lvds_d3_e3_pll_calc()
326 static void __rcar_lvds_pll_setup_d3_e3(struct rcar_lvds *lvds, in __rcar_lvds_pll_setup_d3_e3() argument
332 rcar_lvds_d3_e3_pll_calc(lvds, lvds->clocks.dotclkin[0], freq, &pll, in __rcar_lvds_pll_setup_d3_e3()
334 rcar_lvds_d3_e3_pll_calc(lvds, lvds->clocks.dotclkin[1], freq, &pll, in __rcar_lvds_pll_setup_d3_e3()
336 rcar_lvds_d3_e3_pll_calc(lvds, lvds->clocks.extal, freq, &pll, in __rcar_lvds_pll_setup_d3_e3()
349 rcar_lvds_write(lvds, LVDPLLCR, lvdpllcr); in __rcar_lvds_pll_setup_d3_e3()
356 rcar_lvds_write(lvds, LVDDIV, LVDDIV_DIVSEL | in __rcar_lvds_pll_setup_d3_e3()
359 rcar_lvds_write(lvds, LVDDIV, 0); in __rcar_lvds_pll_setup_d3_e3()
362 static void rcar_lvds_pll_setup_d3_e3(struct rcar_lvds *lvds, unsigned int freq) in rcar_lvds_pll_setup_d3_e3() argument
364 __rcar_lvds_pll_setup_d3_e3(lvds, freq, false); in rcar_lvds_pll_setup_d3_e3()
373 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in rcar_lvds_clk_enable() local
376 if (WARN_ON(!(lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL))) in rcar_lvds_clk_enable()
379 dev_dbg(lvds->dev, "enabling LVDS PLL, freq=%luHz\n", freq); in rcar_lvds_clk_enable()
381 ret = clk_prepare_enable(lvds->clocks.mod); in rcar_lvds_clk_enable()
385 __rcar_lvds_pll_setup_d3_e3(lvds, freq, true); in rcar_lvds_clk_enable()
393 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in rcar_lvds_clk_disable() local
395 if (WARN_ON(!(lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL))) in rcar_lvds_clk_disable()
398 dev_dbg(lvds->dev, "disabling LVDS PLL\n"); in rcar_lvds_clk_disable()
400 rcar_lvds_write(lvds, LVDPLLCR, 0); in rcar_lvds_clk_disable()
402 clk_disable_unprepare(lvds->clocks.mod); in rcar_lvds_clk_disable()
410 static enum rcar_lvds_mode rcar_lvds_get_lvds_mode(struct rcar_lvds *lvds, in rcar_lvds_get_lvds_mode() argument
417 * There is no API yet to retrieve LVDS mode from a bridge, only panels in rcar_lvds_get_lvds_mode()
420 if (!lvds->panel) in rcar_lvds_get_lvds_mode()
425 dev_warn(lvds->dev, in rcar_lvds_get_lvds_mode()
426 "no LVDS bus format reported, using JEIDA\n"); in rcar_lvds_get_lvds_mode()
439 dev_warn(lvds->dev, in rcar_lvds_get_lvds_mode()
440 "unsupported LVDS bus format 0x%04x, using JEIDA\n", in rcar_lvds_get_lvds_mode()
456 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in __rcar_lvds_atomic_enable() local
461 ret = clk_prepare_enable(lvds->clocks.mod); in __rcar_lvds_atomic_enable()
465 /* Enable the companion LVDS encoder in dual-link mode. */ in __rcar_lvds_atomic_enable()
466 if (lvds->link_type != RCAR_LVDS_SINGLE_LINK && lvds->companion) in __rcar_lvds_atomic_enable()
467 __rcar_lvds_atomic_enable(lvds->companion, state, crtc, in __rcar_lvds_atomic_enable()
478 rcar_lvds_write(lvds, LVDCTRCR, LVDCTRCR_CTR3SEL_ZERO | in __rcar_lvds_atomic_enable()
482 if (lvds->info->quirks & RCAR_LVDS_QUIRK_LANES) in __rcar_lvds_atomic_enable()
489 rcar_lvds_write(lvds, LVDCHCR, lvdhcr); in __rcar_lvds_atomic_enable()
491 if (lvds->info->quirks & RCAR_LVDS_QUIRK_DUAL_LINK) { in __rcar_lvds_atomic_enable()
494 if (lvds->link_type != RCAR_LVDS_SINGLE_LINK) { in __rcar_lvds_atomic_enable()
502 bool swap_pixels = lvds->link_type == in __rcar_lvds_atomic_enable()
507 * an LVDS dual-link connection. in __rcar_lvds_atomic_enable()
513 | (lvds->companion && swap_pixels ? in __rcar_lvds_atomic_enable()
516 rcar_lvds_write(lvds, LVDSTRIPE, lvdstripe); in __rcar_lvds_atomic_enable()
523 if (lvds->link_type == RCAR_LVDS_SINGLE_LINK || lvds->companion) { in __rcar_lvds_atomic_enable()
529 lvds->info->pll_setup(lvds, mode->clock * 1000); in __rcar_lvds_atomic_enable()
532 /* Set the LVDS mode and select the input. */ in __rcar_lvds_atomic_enable()
533 lvdcr0 = rcar_lvds_get_lvds_mode(lvds, connector) << LVDCR0_LVMD_SHIFT; in __rcar_lvds_atomic_enable()
535 if (lvds->bridge.encoder) { in __rcar_lvds_atomic_enable()
540 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in __rcar_lvds_atomic_enable()
543 rcar_lvds_write(lvds, LVDCR1, in __rcar_lvds_atomic_enable()
547 if (lvds->info->gen < 3) { in __rcar_lvds_atomic_enable()
548 /* Enable LVDS operation and turn the bias circuitry on. */ in __rcar_lvds_atomic_enable()
550 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in __rcar_lvds_atomic_enable()
553 if (!(lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL)) { in __rcar_lvds_atomic_enable()
559 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in __rcar_lvds_atomic_enable()
562 if (lvds->info->quirks & RCAR_LVDS_QUIRK_PWD) { in __rcar_lvds_atomic_enable()
563 /* Set LVDS normal mode. */ in __rcar_lvds_atomic_enable()
565 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in __rcar_lvds_atomic_enable()
568 if (lvds->info->quirks & RCAR_LVDS_QUIRK_GEN3_LVEN) { in __rcar_lvds_atomic_enable()
570 * Turn on the LVDS PHY. On D3, the LVEN and LVRES bit must be in __rcar_lvds_atomic_enable()
574 if (!(lvds->info->quirks & RCAR_LVDS_QUIRK_PWD)) in __rcar_lvds_atomic_enable()
575 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in __rcar_lvds_atomic_enable()
578 if (!(lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL)) { in __rcar_lvds_atomic_enable()
585 rcar_lvds_write(lvds, LVDCR0, lvdcr0); in __rcar_lvds_atomic_enable()
587 if (lvds->panel) { in __rcar_lvds_atomic_enable()
588 drm_panel_prepare(lvds->panel); in __rcar_lvds_atomic_enable()
589 drm_panel_enable(lvds->panel); in __rcar_lvds_atomic_enable()
610 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in rcar_lvds_atomic_disable() local
612 if (lvds->panel) { in rcar_lvds_atomic_disable()
613 drm_panel_disable(lvds->panel); in rcar_lvds_atomic_disable()
614 drm_panel_unprepare(lvds->panel); in rcar_lvds_atomic_disable()
617 rcar_lvds_write(lvds, LVDCR0, 0); in rcar_lvds_atomic_disable()
618 rcar_lvds_write(lvds, LVDCR1, 0); in rcar_lvds_atomic_disable()
619 rcar_lvds_write(lvds, LVDPLLCR, 0); in rcar_lvds_atomic_disable()
621 /* Disable the companion LVDS encoder in dual-link mode. */ in rcar_lvds_atomic_disable()
622 if (lvds->link_type != RCAR_LVDS_SINGLE_LINK && lvds->companion) in rcar_lvds_atomic_disable()
623 lvds->companion->funcs->atomic_disable(lvds->companion, in rcar_lvds_atomic_disable()
626 clk_disable_unprepare(lvds->clocks.mod); in rcar_lvds_atomic_disable()
633 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in rcar_lvds_mode_fixup() local
637 * The internal LVDS encoder has a restricted clock frequency operating in rcar_lvds_mode_fixup()
641 min_freq = lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL ? 5000 : 31000; in rcar_lvds_mode_fixup()
650 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in rcar_lvds_attach() local
651 struct drm_connector *connector = &lvds->connector; in rcar_lvds_attach()
656 if (lvds->next_bridge) in rcar_lvds_attach()
657 return drm_bridge_attach(bridge->encoder, lvds->next_bridge, in rcar_lvds_attach()
666 if (!lvds->panel) in rcar_lvds_attach()
700 struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge); in rcar_lvds_dual_link() local
702 return lvds->link_type != RCAR_LVDS_SINGLE_LINK; in rcar_lvds_dual_link()
710 static int rcar_lvds_parse_dt_companion(struct rcar_lvds *lvds) in rcar_lvds_parse_dt_companion() argument
716 struct device *dev = lvds->dev; in rcar_lvds_parse_dt_companion()
720 /* Locate the companion LVDS encoder for dual-link operation, if any. */ in rcar_lvds_parse_dt_companion()
731 dev_err(dev, "Companion LVDS encoder is invalid\n"); in rcar_lvds_parse_dt_companion()
750 lvds->link_type = RCAR_LVDS_DUAL_LINK_ODD_EVEN_PIXELS; in rcar_lvds_parse_dt_companion()
753 lvds->link_type = RCAR_LVDS_DUAL_LINK_EVEN_ODD_PIXELS; in rcar_lvds_parse_dt_companion()
762 if (lvds->next_bridge && lvds->next_bridge->timings && in rcar_lvds_parse_dt_companion()
763 lvds->next_bridge->timings->dual_link) in rcar_lvds_parse_dt_companion()
764 lvds->link_type = RCAR_LVDS_DUAL_LINK_EVEN_ODD_PIXELS; in rcar_lvds_parse_dt_companion()
766 lvds->link_type = RCAR_LVDS_SINGLE_LINK; in rcar_lvds_parse_dt_companion()
769 if (lvds->link_type == RCAR_LVDS_SINGLE_LINK) { in rcar_lvds_parse_dt_companion()
774 lvds->companion = of_drm_find_bridge(companion); in rcar_lvds_parse_dt_companion()
775 if (!lvds->companion) { in rcar_lvds_parse_dt_companion()
784 if (lvds->link_type == RCAR_LVDS_DUAL_LINK_ODD_EVEN_PIXELS) in rcar_lvds_parse_dt_companion()
796 companion_lvds = bridge_to_rcar_lvds(lvds->companion); in rcar_lvds_parse_dt_companion()
797 companion_lvds->link_type = lvds->link_type; in rcar_lvds_parse_dt_companion()
805 static int rcar_lvds_parse_dt(struct rcar_lvds *lvds) in rcar_lvds_parse_dt() argument
809 ret = drm_of_find_panel_or_bridge(lvds->dev->of_node, 1, 0, in rcar_lvds_parse_dt()
810 &lvds->panel, &lvds->next_bridge); in rcar_lvds_parse_dt()
814 if (lvds->info->quirks & RCAR_LVDS_QUIRK_DUAL_LINK) in rcar_lvds_parse_dt()
815 ret = rcar_lvds_parse_dt_companion(lvds); in rcar_lvds_parse_dt()
819 * On D3/E3 the LVDS encoder provides a clock to the DU, which can be in rcar_lvds_parse_dt()
820 * used for the DPAD output even when the LVDS output is not connected. in rcar_lvds_parse_dt()
824 if (lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL) in rcar_lvds_parse_dt()
830 static struct clk *rcar_lvds_get_clock(struct rcar_lvds *lvds, const char *name, in rcar_lvds_get_clock() argument
835 clk = devm_clk_get(lvds->dev, name); in rcar_lvds_get_clock()
843 dev_err(lvds->dev, "failed to get %s clock\n", in rcar_lvds_get_clock()
849 static int rcar_lvds_get_clocks(struct rcar_lvds *lvds) in rcar_lvds_get_clocks() argument
851 lvds->clocks.mod = rcar_lvds_get_clock(lvds, NULL, false); in rcar_lvds_get_clocks()
852 if (IS_ERR(lvds->clocks.mod)) in rcar_lvds_get_clocks()
853 return PTR_ERR(lvds->clocks.mod); in rcar_lvds_get_clocks()
856 * LVDS encoders without an extended PLL have no external clock inputs. in rcar_lvds_get_clocks()
858 if (!(lvds->info->quirks & RCAR_LVDS_QUIRK_EXT_PLL)) in rcar_lvds_get_clocks()
861 lvds->clocks.extal = rcar_lvds_get_clock(lvds, "extal", true); in rcar_lvds_get_clocks()
862 if (IS_ERR(lvds->clocks.extal)) in rcar_lvds_get_clocks()
863 return PTR_ERR(lvds->clocks.extal); in rcar_lvds_get_clocks()
865 lvds->clocks.dotclkin[0] = rcar_lvds_get_clock(lvds, "dclkin.0", true); in rcar_lvds_get_clocks()
866 if (IS_ERR(lvds->clocks.dotclkin[0])) in rcar_lvds_get_clocks()
867 return PTR_ERR(lvds->clocks.dotclkin[0]); in rcar_lvds_get_clocks()
869 lvds->clocks.dotclkin[1] = rcar_lvds_get_clock(lvds, "dclkin.1", true); in rcar_lvds_get_clocks()
870 if (IS_ERR(lvds->clocks.dotclkin[1])) in rcar_lvds_get_clocks()
871 return PTR_ERR(lvds->clocks.dotclkin[1]); in rcar_lvds_get_clocks()
874 if (!lvds->clocks.extal && !lvds->clocks.dotclkin[0] && in rcar_lvds_get_clocks()
875 !lvds->clocks.dotclkin[1]) { in rcar_lvds_get_clocks()
876 dev_err(lvds->dev, in rcar_lvds_get_clocks()
901 struct rcar_lvds *lvds; in rcar_lvds_probe() local
905 lvds = devm_kzalloc(&pdev->dev, sizeof(*lvds), GFP_KERNEL); in rcar_lvds_probe()
906 if (lvds == NULL) in rcar_lvds_probe()
909 platform_set_drvdata(pdev, lvds); in rcar_lvds_probe()
911 lvds->dev = &pdev->dev; in rcar_lvds_probe()
912 lvds->info = of_device_get_match_data(&pdev->dev); in rcar_lvds_probe()
916 lvds->info = attr->data; in rcar_lvds_probe()
918 ret = rcar_lvds_parse_dt(lvds); in rcar_lvds_probe()
922 lvds->bridge.driver_private = lvds; in rcar_lvds_probe()
923 lvds->bridge.funcs = &rcar_lvds_bridge_ops; in rcar_lvds_probe()
924 lvds->bridge.of_node = pdev->dev.of_node; in rcar_lvds_probe()
927 lvds->mmio = devm_ioremap_resource(&pdev->dev, mem); in rcar_lvds_probe()
928 if (IS_ERR(lvds->mmio)) in rcar_lvds_probe()
929 return PTR_ERR(lvds->mmio); in rcar_lvds_probe()
931 ret = rcar_lvds_get_clocks(lvds); in rcar_lvds_probe()
935 drm_bridge_add(&lvds->bridge); in rcar_lvds_probe()
942 struct rcar_lvds *lvds = platform_get_drvdata(pdev); in rcar_lvds_remove() local
944 drm_bridge_remove(&lvds->bridge); in rcar_lvds_remove()
981 { .compatible = "renesas,r8a7742-lvds", .data = &rcar_lvds_gen2_info },
982 { .compatible = "renesas,r8a7743-lvds", .data = &rcar_lvds_gen2_info },
983 { .compatible = "renesas,r8a7744-lvds", .data = &rcar_lvds_gen2_info },
984 { .compatible = "renesas,r8a774a1-lvds", .data = &rcar_lvds_gen3_info },
985 { .compatible = "renesas,r8a774b1-lvds", .data = &rcar_lvds_gen3_info },
986 { .compatible = "renesas,r8a774c0-lvds", .data = &rcar_lvds_r8a77990_info },
987 { .compatible = "renesas,r8a774e1-lvds", .data = &rcar_lvds_gen3_info },
988 { .compatible = "renesas,r8a7790-lvds", .data = &rcar_lvds_gen2_info },
989 { .compatible = "renesas,r8a7791-lvds", .data = &rcar_lvds_gen2_info },
990 { .compatible = "renesas,r8a7793-lvds", .data = &rcar_lvds_gen2_info },
991 { .compatible = "renesas,r8a7795-lvds", .data = &rcar_lvds_gen3_info },
992 { .compatible = "renesas,r8a7796-lvds", .data = &rcar_lvds_gen3_info },
993 { .compatible = "renesas,r8a77965-lvds", .data = &rcar_lvds_gen3_info },
994 { .compatible = "renesas,r8a77970-lvds", .data = &rcar_lvds_r8a77970_info },
995 { .compatible = "renesas,r8a77980-lvds", .data = &rcar_lvds_gen3_info },
996 { .compatible = "renesas,r8a77990-lvds", .data = &rcar_lvds_r8a77990_info },
997 { .compatible = "renesas,r8a77995-lvds", .data = &rcar_lvds_r8a77995_info },
1007 .name = "rcar-lvds",
1015 MODULE_DESCRIPTION("Renesas R-Car LVDS Encoder Driver");