<br><br><br>Sent from ProtonMail mobile<br><br><br><br>-------- Original Message --------<br>On Mar 10, 2021, 12:10, < dri-devel-request@lists.freedesktop.org> wrote:<blockquote class="protonmail_quote"><br><p dir="ltr">Send dri-devel mailing list submissions to<br>
dri-devel@lists.freedesktop.org</p>
<p dir="ltr">To subscribe or unsubscribe via the World Wide Web, visit<br>
<a href="https://lists.freedesktop.org/mailman/listinfo/dri-devel">https://lists.freedesktop.org/mailman/listinfo/dri-devel</a><br>
or, via email, send a message with subject or body 'help' to<br>
dri-devel-request@lists.freedesktop.org</p>
<p dir="ltr">You can reach the person managing the list at<br>
dri-devel-owner@lists.freedesktop.org</p>
<p dir="ltr">When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of dri-devel digest..."<br></p>
<p dir="ltr">Today's Topics:</p>
<p dir="ltr">1. [PATCH v5 12/14] drm/bridge: imx: Add LDB support for<br>
i.MX8qxp (Liu Ying)<br></p>
<p dir="ltr">----------------------------------------------------------------------</p>
<p dir="ltr">Message: 1<br>
Date: Wed, 10 Mar 2021 17:55:36 +0800<br>
From: Liu Ying <victor.liu@nxp.com><br>
To: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,<br>
linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org,<br>
linux-media@vger.kernel.org<br>
Cc: airlied@linux.ie, daniel@ffwll.ch, robh+dt@kernel.org,<br>
shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de,<br>
festevam@gmail.com, linux-imx@nxp.com, mchehab@kernel.org,<br>
a.hajda@samsung.com, narmstrong@baylibre.com,<br>
Laurent.pinchart@ideasonboard.com, jonas@kwiboo.se,<br>
jernej.skrabec@siol.net, kishon@ti.com, vkoul@kernel.org,<br>
robert.foss@linaro.org, lee.jones@linaro.org<br>
Subject: [PATCH v5 12/14] drm/bridge: imx: Add LDB support for<br>
i.MX8qxp<br>
Message-ID: <1615370138-5673-13-git-send-email-victor.liu@nxp.com><br>
Content-Type: text/plain</p>
<p dir="ltr">This patch adds a drm bridge driver for i.MX8qxp LVDS display bridge(LDB)<br>
which is officially named as pixel mapper. The LDB has two channels.<br>
Each of them supports up to 24bpp parallel input color format and can map<br>
the input to VESA or JEIDA standards. The two channels cannot be used<br>
simultaneously, that is to say, the user should pick one of them to use.<br>
Two LDB channels from two LDB instances can work together in LDB split<br>
mode to support a dual link LVDS display. The channel indexes have to be<br>
different. Channel0 outputs odd pixels and channel1 outputs even pixels.<br>
This patch supports the LDB single mode and split mode.</p>
<p dir="ltr">Signed-off-by: Liu Ying <victor.liu@nxp.com><br>
---<br>
Note that this patch depends on the patch 'phy: Add LVDS configuration options',<br>
which has already been sent with the following series to add Mixel combo PHY<br>
found in i.MX8qxp:<br>
<a href="https://www.spinics.net/lists/arm-kernel/msg879957.html">https://www.spinics.net/lists/arm-kernel/msg879957.html</a></p>
<p dir="ltr">v4->v5:<br>
* Link with the imx-ldb-helper object. (Robert)<br>
* Correspondingly, rename 'imx8qxp-ldb.c' to 'imx8qxp-ldb-drv.c'.</p>
<p dir="ltr">v3->v4:<br>
* No change.</p>
<p dir="ltr">v2->v3:<br>
* No change.</p>
<p dir="ltr">v1->v2:<br>
* Drop unnecessary DT validation.<br>
* Use of_graph_get_endpoint_by_regs() and of_graph_get_remote_endpoint() to<br>
get the input remote endpoint in imx8qxp_ldb_set_di_id().<br>
* Avoid using companion_port OF node after putting it in<br>
imx8qxp_ldb_parse_dt_companion().<br>
* Mention i.MX8qxp LDB official name 'pixel mapper' in the bridge driver<br>
and Kconfig help message.</p>
<p dir="ltr">drivers/gpu/drm/bridge/imx/Kconfig | 9 +<br>
drivers/gpu/drm/bridge/imx/Makefile | 3 +<br>
drivers/gpu/drm/bridge/imx/imx8qxp-ldb-drv.c | 720 +++++++++++++++++++++++++++<br>
3 files changed, 732 insertions(+)<br>
create mode 100644 drivers/gpu/drm/bridge/imx/imx8qxp-ldb-drv.c</p>
<p dir="ltr">diff --git a/drivers/gpu/drm/bridge/imx/Kconfig b/drivers/gpu/drm/bridge/imx/Kconfig<br>
index 1ea1ce7..94f8db4d 100644<br>
--- a/drivers/gpu/drm/bridge/imx/Kconfig<br>
+++ b/drivers/gpu/drm/bridge/imx/Kconfig<br>
@@ -1,3 +1,12 @@<br>
+config DRM_IMX8QXP_LDB<br>
+ tristate "Freescale i.MX8QXP LVDS display bridge"<br>
+ depends on OF<br>
+ depends on COMMON_CLK<br>
+ select DRM_KMS_HELPER<br>
+ help<br>
+ Choose this to enable the internal LVDS Display Bridge(LDB) found in<br>
+ Freescale i.MX8qxp processor. Official name of LDB is pixel mapper.<br>
+<br>
config DRM_IMX8QXP_PIXEL_COMBINER<br>
tristate "Freescale i.MX8QM/QXP pixel combiner"<br>
depends on OF<br>
diff --git a/drivers/gpu/drm/bridge/imx/Makefile b/drivers/gpu/drm/bridge/imx/Makefile<br>
index e74dd64..96d5d1e 100644<br>
--- a/drivers/gpu/drm/bridge/imx/Makefile<br>
+++ b/drivers/gpu/drm/bridge/imx/Makefile<br>
@@ -1,3 +1,6 @@<br>
+imx8qxp-ldb-objs := imx-ldb-helper.o imx8qxp-ldb-drv.o<br>
+obj-$(CONFIG_DRM_IMX8QXP_LDB) += imx8qxp-ldb.o<br>
+<br>
obj-$(CONFIG_DRM_IMX8QXP_PIXEL_COMBINER) += imx8qxp-pixel-combiner.o<br>
obj-$(CONFIG_DRM_IMX8QXP_PIXEL_LINK) += imx8qxp-pixel-link.o<br>
obj-$(CONFIG_DRM_IMX8QXP_PIXEL_LINK_TO_DPI) += imx8qxp-pxl2dpi.o<br>
diff --git a/drivers/gpu/drm/bridge/imx/imx8qxp-ldb-drv.c b/drivers/gpu/drm/bridge/imx/imx8qxp-ldb-drv.c<br>
new file mode 100644<br>
index 00000000..d7f59c1<br>
--- /dev/null<br>
+++ b/drivers/gpu/drm/bridge/imx/imx8qxp-ldb-drv.c<br>
@@ -0,0 +1,720 @@<br>
+// SPDX-License-Identifier: GPL-2.0+<br>
+<br>
+/*<br>
+ * Copyright 2020 NXP<br>
+ */<br>
+<br>
+#include <linux/clk.h><br>
+#include <linux/mfd/syscon.h><br>
+#include <linux/module.h><br>
+#include <linux/of.h><br>
+#include <linux/of_device.h><br>
+#include <linux/of_graph.h><br>
+#include <linux/phy/phy.h><br>
+#include <linux/pm_runtime.h><br>
+#include <linux/regmap.h><br>
+<br>
+#include <drm/drm_atomic_state_helper.h><br>
+#include <drm/drm_bridge.h><br>
+#include <drm/drm_connector.h><br>
+#include <drm/drm_fourcc.h><br>
+#include <drm/drm_of.h><br>
+#include <drm/drm_print.h><br>
+<br>
+#include "imx-ldb-helper.h"<br>
+<br>
+#define LDB_CH_SEL (1 << 28)<br>
+<br>
+#define SS_CTRL 0x20<br>
+#define CH_HSYNC_M(id) BIT(0 + ((id) * 2))<br>
+#define CH_VSYNC_M(id) BIT(1 + ((id) * 2))<br>
+#define CH_PHSYNC(id) BIT(0 + ((id) * 2))<br>
+#define CH_PVSYNC(id) BIT(1 + ((id) * 2))<br>
+<br>
+#define DRIVER_NAME "imx8qxp-ldb"<br>
+<br>
+struct imx8qxp_ldb_channel {<br>
+ struct ldb_channel base;<br>
+ struct phy *phy;<br>
+ unsigned int di_id;<br>
+};<br>
+<br>
+struct imx8qxp_ldb {<br>
+ struct ldb base;<br>
+ struct device *dev;<br>
+ struct imx8qxp_ldb_channel channel[MAX_LDB_CHAN_NUM];<br>
+ struct clk *clk_pixel;<br>
+ struct clk *clk_bypass;<br>
+ struct drm_bridge *companion;<br>
+ int active_chno;<br>
+};<br>
+<br>
+static inline struct imx8qxp_ldb_channel *<br>
+base_to_imx8qxp_ldb_channel(struct ldb_channel *base)<br>
+{<br>
+ return container_of(base, struct imx8qxp_ldb_channel, base);<br>
+}<br>
+<br>
+static inline struct imx8qxp_ldb *base_to_imx8qxp_ldb(struct ldb *base)<br>
+{<br>
+ return container_of(base, struct imx8qxp_ldb, base);<br>
+}<br>
+<br>
+static void imx8qxp_ldb_set_phy_cfg(struct imx8qxp_ldb *imx8qxp_ldb,<br>
+ unsigned long di_clk, bool is_split,<br>
+ struct phy_configure_opts_lvds *phy_cfg)<br>
+{<br>
+ phy_cfg->bits_per_lane_and_dclk_cycle = 7;<br>
+ phy_cfg->lanes = 4;<br>
+<br>
+ if (is_split) {<br>
+ phy_cfg->differential_clk_rate = di_clk / 2;<br>
+ phy_cfg->is_slave = !imx8qxp_ldb->companion;<br>
+ } else {<br>
+ phy_cfg->differential_clk_rate = di_clk;<br>
+ phy_cfg->is_slave = false;<br>
+ }<br>
+}<br>
+<br>
+static int imx8qxp_ldb_bridge_atomic_check(struct drm_bridge *bridge,<br>
+ struct drm_bridge_state *bridge_state,<br>
+ struct drm_crtc_state *crtc_state,<br>
+ struct drm_connector_state *conn_state)<br>
+{<br>
+ struct ldb_channel *ldb_ch = bridge->driver_private;<br>
+ struct ldb *ldb = ldb_ch->ldb;<br>
+ struct imx8qxp_ldb_channel *imx8qxp_ldb_ch =<br>
+ base_to_imx8qxp_ldb_channel(ldb_ch);<br>
+ struct imx8qxp_ldb *imx8qxp_ldb = base_to_imx8qxp_ldb(ldb);<br>
+ struct drm_bridge *companion = imx8qxp_ldb->companion;<br>
+ struct drm_display_mode *adj = &crtc_state->adjusted_mode;<br>
+ unsigned long di_clk = adj->clock * 1000;<br>
+ bool is_split = ldb_channel_is_split_link(ldb_ch);<br>
+ union phy_configure_opts opts = { };<br>
+ struct phy_configure_opts_lvds *phy_cfg = &opts.lvds;<br>
+ int ret;<br>
+<br>
+ ret = ldb_bridge_atomic_check_helper(bridge, bridge_state,<br>
+ crtc_state, conn_state);<br>
+ if (ret)<br>
+ return ret;<br>
+<br>
+ imx8qxp_ldb_set_phy_cfg(imx8qxp_ldb, di_clk, is_split, phy_cfg);<br>
+ ret = phy_validate(imx8qxp_ldb_ch->phy, PHY_MODE_LVDS, 0, &opts);<br>
+ if (ret < 0) {<br>
+ DRM_DEV_DEBUG_DRIVER(imx8qxp_ldb->dev,<br>
+ "failed to validate PHY: %d\n", ret);<br>
+ return ret;<br>
+ }<br>
+<br>
+ if (is_split && companion) {<br>
+ ret = companion->funcs->atomic_check(companion,<br>
+ bridge_state, crtc_state, conn_state);<br>
+ if (ret)<br>
+ return ret;<br>
+ }<br>
+<br>
+ return ret;<br>
+}<br>
+<br>
+static void<br>
+imx8qxp_ldb_bridge_mode_set(struct drm_bridge *bridge,<br>
+ const struct drm_display_mode *mode,<br>
+ const struct drm_display_mode *adjusted_mode)<br>
+{<br>
+ struct ldb_channel *ldb_ch = bridge->driver_private;<br>
+ struct ldb_channel *companion_ldb_ch;<br>
+ struct ldb *ldb = ldb_ch->ldb;<br>
+ struct imx8qxp_ldb_channel *imx8qxp_ldb_ch =<br>
+ base_to_imx8qxp_ldb_channel(ldb_ch);<br>
+ struct imx8qxp_ldb *imx8qxp_ldb = base_to_imx8qxp_ldb(ldb);<br>
+ struct drm_bridge *companion = imx8qxp_ldb->companion;<br>
+ struct device *dev = imx8qxp_ldb->dev;<br>
+ unsigned long di_clk = adjusted_mode->clock * 1000;<br>
+ bool is_split = ldb_channel_is_split_link(ldb_ch);<br>
+ union phy_configure_opts opts = { };<br>
+ struct phy_configure_opts_lvds *phy_cfg = &opts.lvds;<br>
+ u32 chno = ldb_ch->chno;<br>
+ int ret;<br>
+<br>
+ ret = pm_runtime_get_sync(dev);<br>
+ if (ret < 0)<br>
+ DRM_DEV_ERROR(dev, "failed to get runtime PM sync: %d\n", ret);<br>
+<br>
+ ret = phy_init(imx8qxp_ldb_ch->phy);<br>
+ if (ret < 0)<br>
+ DRM_DEV_ERROR(dev, "failed to initialize PHY: %d\n", ret);<br>
+<br>
+ ret = phy_set_mode(imx8qxp_ldb_ch->phy, PHY_MODE_LVDS);<br>
+ if (ret < 0)<br>
+ DRM_DEV_ERROR(dev, "failed to set PHY mode: %d\n", ret);<br>
+<br>
+ if (is_split && companion) {<br>
+ companion_ldb_ch = bridge_to_ldb_ch(companion);<br>
+<br>
+ companion_ldb_ch->in_bus_format = ldb_ch->in_bus_format;<br>
+ companion_ldb_ch->out_bus_format = ldb_ch->out_bus_format;<br>
+ }<br>
+<br>
+ clk_set_rate(imx8qxp_ldb->clk_bypass, di_clk);<br>
+ clk_set_rate(imx8qxp_ldb->clk_pixel, di_clk);<br>
+<br>
+ imx8qxp_ldb_set_phy_cfg(imx8qxp_ldb, di_clk, is_split, phy_cfg);<br>
+ ret = phy_configure(imx8qxp_ldb_ch->phy, &opts);<br>
+ if (ret < 0)<br>
+ DRM_DEV_ERROR(dev, "failed to configure PHY: %d\n", ret);<br>
+<br>
+ if (chno == 0)<br>
+ ldb->ldb_ctrl &= ~LDB_CH_SEL;<br>
+ else<br>
+ ldb->ldb_ctrl |= LDB_CH_SEL;<br>
+<br>
+ /* input VSYNC signal from pixel link is active low */<br>
+ if (imx8qxp_ldb_ch->di_id == 0)<br>
+ ldb->ldb_ctrl |= LDB_DI0_VS_POL_ACT_LOW;<br>
+ else<br>
+ ldb->ldb_ctrl |= LDB_DI1_VS_POL_ACT_LOW;<br>
+<br>
+ /*<br>
+ * For split mode, settle input VSYNC signal polarity and<br>
+ * channel selection down early.<br>
+ */<br>
+ if (is_split)<br>
+ regmap_write(ldb->regmap, ldb->ctrl_reg, ldb->ldb_ctrl);<br>
+<br>
+ ldb_bridge_mode_set_helper(bridge, mode, adjusted_mode);<br>
+<br>
+ if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)<br>
+ regmap_update_bits(ldb->regmap, SS_CTRL, CH_VSYNC_M(chno), 0);<br>
+ else if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)<br>
+ regmap_update_bits(ldb->regmap, SS_CTRL,<br>
+ CH_VSYNC_M(chno), CH_PVSYNC(chno));<br>
+<br>
+ if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)<br>
+ regmap_update_bits(ldb->regmap, SS_CTRL, CH_HSYNC_M(chno), 0);<br>
+ else if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)<br>
+ regmap_update_bits(ldb->regmap, SS_CTRL,<br>
+ CH_HSYNC_M(chno), CH_PHSYNC(chno));<br>
+<br>
+ if (is_split && companion)<br>
+ companion->funcs->mode_set(companion, mode, adjusted_mode);<br>
+}<br>
+<br>
+static void<br>
+imx8qxp_ldb_bridge_atomic_pre_enable(struct drm_bridge *bridge,<br>
+ struct drm_bridge_state *old_bridge_state)<br>
+{<br>
+ struct ldb_channel *ldb_ch = bridge->driver_private;<br>
+ struct ldb *ldb = ldb_ch->ldb;<br>
+ struct imx8qxp_ldb *imx8qxp_ldb = base_to_imx8qxp_ldb(ldb);<br>
+ struct drm_bridge *companion = imx8qxp_ldb->companion;<br>
+ bool is_split = ldb_channel_is_split_link(ldb_ch);<br>
+<br>
+ clk_prepare_enable(imx8qxp_ldb->clk_pixel);<br>
+ clk_prepare_enable(imx8qxp_ldb->clk_bypass);<br>
+<br>
+ if (is_split && companion)<br>
+ companion->funcs->atomic_pre_enable(companion, old_bridge_state);<br>
+}<br>
+<br>
+static void<br>
+imx8qxp_ldb_bridge_atomic_enable(struct drm_bridge *bridge,<br>
+ struct drm_bridge_state *old_bridge_state)<br>
+{<br>
+ struct ldb_channel *ldb_ch = bridge->driver_private;<br>
+ struct ldb *ldb = ldb_ch->ldb;<br>
+ struct imx8qxp_ldb_channel *imx8qxp_ldb_ch =<br>
+ base_to_imx8qxp_ldb_channel(ldb_ch);<br>
+ struct imx8qxp_ldb *imx8qxp_ldb = base_to_imx8qxp_ldb(ldb);<br>
+ struct drm_bridge *companion = imx8qxp_ldb->companion;<br>
+ struct device *dev = imx8qxp_ldb->dev;<br>
+ bool is_split = ldb_channel_is_split_link(ldb_ch);<br>
+ int ret;<br>
+<br>
+ if (ldb_ch->chno == 0 || is_split) {<br>
+ ldb->ldb_ctrl &= ~LDB_CH0_MODE_EN_MASK;<br>
+ ldb->ldb_ctrl |= imx8qxp_ldb_ch->di_id == 0 ?<br>
+ LDB_CH0_MODE_EN_TO_DI0 : LDB_CH0_MODE_EN_TO_DI1;<br>
+ }<br>
+ if (ldb_ch->chno == 1 || is_split) {<br>
+ ldb->ldb_ctrl &= ~LDB_CH1_MODE_EN_MASK;<br>
+ ldb->ldb_ctrl |= imx8qxp_ldb_ch->di_id == 0 ?<br>
+ LDB_CH1_MODE_EN_TO_DI0 : LDB_CH1_MODE_EN_TO_DI1;<br>
+ }<br>
+<br>
+ ldb_bridge_enable_helper(bridge);<br>
+<br>
+ ret = phy_power_on(imx8qxp_ldb_ch->phy);<br>
+ if (ret)<br>
+ DRM_DEV_ERROR(dev, "failed to power on PHY: %d\n", ret);<br>
+<br>
+ if (is_split && companion)<br>
+ companion->funcs->atomic_enable(companion, old_bridge_state);<br>
+}<br>
+<br>
+static void<br>
+imx8qxp_ldb_bridge_atomic_disable(struct drm_bridge *bridge,<br>
+ struct drm_bridge_state *old_bridge_state)<br>
+{<br>
+ struct ldb_channel *ldb_ch = bridge->driver_private;<br>
+ struct ldb *ldb = ldb_ch->ldb;<br>
+ struct imx8qxp_ldb_channel *imx8qxp_ldb_ch =<br>
+ base_to_imx8qxp_ldb_channel(ldb_ch);<br>
+ struct imx8qxp_ldb *imx8qxp_ldb = base_to_imx8qxp_ldb(ldb);<br>
+ struct drm_bridge *companion = imx8qxp_ldb->companion;<br>
+ struct device *dev = imx8qxp_ldb->dev;<br>
+ bool is_split = ldb_channel_is_split_link(ldb_ch);<br>
+ int ret;<br>
+<br>
+ ret = phy_power_off(imx8qxp_ldb_ch->phy);<br>
+ if (ret)<br>
+ DRM_DEV_ERROR(dev, "failed to power off PHY: %d\n", ret);<br>
+<br>
+ ret = phy_exit(imx8qxp_ldb_ch->phy);<br>
+ if (ret < 0)<br>
+ DRM_DEV_ERROR(dev, "failed to teardown PHY: %d\n", ret);<br>
+<br>
+ ldb_bridge_disable_helper(bridge);<br>
+<br>
+ clk_disable_unprepare(imx8qxp_ldb->clk_bypass);<br>
+ clk_disable_unprepare(imx8qxp_ldb->clk_pixel);<br>
+<br>
+ if (is_split && companion)<br>
+ companion->funcs->atomic_disable(companion, old_bridge_state);<br>
+<br>
+ ret = pm_runtime_put(dev);<br>
+ if (ret < 0)<br>
+ DRM_DEV_ERROR(dev, "failed to put runtime PM: %d\n", ret);<br>
+}<br>
+<br>
+static const u32 imx8qxp_ldb_bus_output_fmts[] = {<br>
+ MEDIA_BUS_FMT_RGB666_1X7X3_SPWG,<br>
+ MEDIA_BUS_FMT_RGB888_1X7X4_SPWG,<br>
+ MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA,<br>
+ MEDIA_BUS_FMT_FIXED,<br>
+};<br>
+<br>
+static bool imx8qxp_ldb_bus_output_fmt_supported(u32 fmt)<br>
+{<br>
+ int i;<br>
+<br>
+ for (i = 0; i < ARRAY_SIZE(imx8qxp_ldb_bus_output_fmts); i++) {<br>
+ if (imx8qxp_ldb_bus_output_fmts[i] == fmt)<br>
+ return true;<br>
+ }<br>
+<br>
+ return false;<br>
+}<br>
+<br>
+static u32 *<br>
+imx8qxp_ldb_bridge_atomic_get_input_bus_fmts(struct drm_bridge *bridge,<br>
+ struct drm_bridge_state *bridge_state,<br>
+ struct drm_crtc_state *crtc_state,<br>
+ struct drm_connector_state *conn_state,<br>
+ u32 output_fmt,<br>
+ unsigned int *num_input_fmts)<br>
+{<br>
+ struct drm_display_info *di;<br>
+ const struct drm_format_info *finfo;<br>
+ u32 *input_fmts;<br>
+<br>
+ if (!imx8qxp_ldb_bus_output_fmt_supported(output_fmt))<br>
+ return NULL;<br>
+<br>
+ *num_input_fmts = 1;<br>
+<br>
+ input_fmts = kmalloc(sizeof(*input_fmts), GFP_KERNEL);<br>
+ if (!input_fmts)<br>
+ return NULL;<br>
+<br>
+ switch (output_fmt) {<br>
+ case MEDIA_BUS_FMT_FIXED:<br>
+ di = &conn_state->connector->display_info;<br>
+<br>
+ /*<br>
+ * Look at the first bus format to determine input format.<br>
+ * Default to MEDIA_BUS_FMT_RGB888_1X24, if no match.<br>
+ */<br>
+ if (di->num_bus_formats) {<br>
+ finfo = drm_format_info(di->bus_formats[0]);<br>
+<br>
+ input_fmts[0] = finfo->depth == 18 ?<br>
+ MEDIA_BUS_FMT_RGB666_1X24_CPADHI :<br>
+ MEDIA_BUS_FMT_RGB888_1X24;<br>
+ } else {<br>
+ input_fmts[0] = MEDIA_BUS_FMT_RGB888_1X24;<br>
+ }<br>
+ break;<br>
+ case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG:<br>
+ input_fmts[0] = MEDIA_BUS_FMT_RGB666_1X24_CPADHI;<br>
+ break;<br>
+ case MEDIA_BUS_FMT_RGB888_1X7X4_SPWG:<br>
+ case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA:<br>
+ input_fmts[0] = MEDIA_BUS_FMT_RGB888_1X24;<br>
+ break;<br>
+ default:<br>
+ kfree(input_fmts);<br>
+ input_fmts = NULL;<br>
+ break;<br>
+ }<br>
+<br>
+ return input_fmts;<br>
+}<br>
+<br>
+static u32 *<br>
+imx8qxp_ldb_bridge_atomic_get_output_bus_fmts(struct drm_bridge *bridge,<br>
+ struct drm_bridge_state *bridge_state,<br>
+ struct drm_crtc_state *crtc_state,<br>
+ struct drm_connector_state *conn_state,<br>
+ unsigned int *num_output_fmts)<br>
+{<br>
+ *num_output_fmts = ARRAY_SIZE(imx8qxp_ldb_bus_output_fmts);<br>
+ return kmemdup(imx8qxp_ldb_bus_output_fmts,<br>
+ sizeof(imx8qxp_ldb_bus_output_fmts), GFP_KERNEL);<br>
+}<br>
+<br>
+static enum drm_mode_status<br>
+imx8qxp_ldb_bridge_mode_valid(struct drm_bridge *bridge,<br>
+ const struct drm_display_info *info,<br>
+ const struct drm_display_mode *mode)<br>
+{<br>
+ struct ldb_channel *ldb_ch = bridge->driver_private;<br>
+ bool is_single = ldb_channel_is_single_link(ldb_ch);<br>
+<br>
+ if (mode->clock > 170000)<br>
+ return MODE_CLOCK_HIGH;<br>
+<br>
+ if (mode->clock > 150000 && is_single)<br>
+ return MODE_CLOCK_HIGH;<br>
+<br>
+ return MODE_OK;<br>
+}<br>
+<br>
+static const struct drm_bridge_funcs imx8qxp_ldb_bridge_funcs = {<br>
+ .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,<br>
+ .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,<br>
+ .atomic_reset = drm_atomic_helper_bridge_reset,<br>
+ .mode_valid = imx8qxp_ldb_bridge_mode_valid,<br>
+ .attach = ldb_bridge_attach_helper,<br>
+ .atomic_check = imx8qxp_ldb_bridge_atomic_check,<br>
+ .mode_set = imx8qxp_ldb_bridge_mode_set,<br>
+ .atomic_pre_enable = imx8qxp_ldb_bridge_atomic_pre_enable,<br>
+ .atomic_enable = imx8qxp_ldb_bridge_atomic_enable,<br>
+ .atomic_disable = imx8qxp_ldb_bridge_atomic_disable,<br>
+ .atomic_get_input_bus_fmts =<br>
+ imx8qxp_ldb_bridge_atomic_get_input_bus_fmts,<br>
+ .atomic_get_output_bus_fmts =<br>
+ imx8qxp_ldb_bridge_atomic_get_output_bus_fmts,<br>
+};<br>
+<br>
+static int imx8qxp_ldb_set_di_id(struct imx8qxp_ldb *imx8qxp_ldb)<br>
+{<br>
+ struct imx8qxp_ldb_channel *imx8qxp_ldb_ch =<br>
+ &imx8qxp_ldb->channel[imx8qxp_ldb->active_chno];<br>
+ struct ldb_channel *ldb_ch = &imx8qxp_ldb_ch->base;<br>
+ struct device_node *ep, *remote;<br>
+ struct device *dev = imx8qxp_ldb->dev;<br>
+ struct of_endpoint endpoint;<br>
+ int ret;<br>
+<br>
+ ep = of_graph_get_endpoint_by_regs(ldb_ch->np, 0, -1);<br>
+ if (!ep) {<br>
+ DRM_DEV_ERROR(dev, "failed to get port0 endpoint\n");<br>
+ return -EINVAL;<br>
+ }<br>
+<br>
+ remote = of_graph_get_remote_endpoint(ep);<br>
+ of_node_put(ep);<br>
+ if (!remote) {<br>
+ DRM_DEV_ERROR(dev, "failed to get port0 remote endpoint\n");<br>
+ return -EINVAL;<br>
+ }<br>
+<br>
+ ret = of_graph_parse_endpoint(remote, &endpoint);<br>
+ of_node_put(remote);<br>
+ if (ret) {<br>
+ DRM_DEV_ERROR(dev, "failed to parse port0 remote endpoint: %d\n",<br>
+ ret);<br>
+ return ret;<br>
+ }<br>
+<br>
+ imx8qxp_ldb_ch->di_id = <a href="http://endpoint.id">endpoint.id</a>;<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
+static int<br>
+imx8qxp_ldb_check_chno_and_dual_link(struct ldb_channel *ldb_ch, int link)<br>
+{<br>
+ if ((link == DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS && ldb_ch->chno != 0) ||<br>
+ (link == DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS && ldb_ch->chno != 1))<br>
+ return -EINVAL;<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
+static int imx8qxp_ldb_parse_dt_companion(struct imx8qxp_ldb *imx8qxp_ldb)<br>
+{<br>
+ struct imx8qxp_ldb_channel *imx8qxp_ldb_ch =<br>
+ &imx8qxp_ldb->channel[imx8qxp_ldb->active_chno];<br>
+ struct ldb_channel *ldb_ch = &imx8qxp_ldb_ch->base;<br>
+ struct ldb_channel *companion_ldb_ch;<br>
+ struct device_node *companion;<br>
+ struct device_node *child;<br>
+ struct device_node *companion_port = NULL;<br>
+ struct device_node *port1, *port2;<br>
+ struct device *dev = imx8qxp_ldb->dev;<br>
+ const struct of_device_id *match;<br>
+ u32 i;<br>
+ int dual_link;<br>
+ int ret;<br>
+<br>
+ /* Locate the companion LDB for dual-link operation, if any. */<br>
+ companion = of_parse_phandle(dev->of_node, "fsl,companion-ldb", 0);<br>
+ if (!companion)<br>
+ return 0;<br>
+<br>
+ if (!of_device_is_available(companion)) {<br>
+ DRM_DEV_ERROR(dev, "companion LDB is not available\n");<br>
+ ret = -ENODEV;<br>
+ goto out;<br>
+ }<br>
+<br>
+ /*<br>
+ * Sanity check: the companion bridge must have the same compatible<br>
+ * string.<br>
+ */<br>
+ match = of_match_device(dev->driver->of_match_table, dev);<br>
+ if (!of_device_is_compatible(companion, match->compatible)) {<br>
+ DRM_DEV_ERROR(dev, "companion LDB is incompatible\n");<br>
+ ret = -ENXIO;<br>
+ goto out;<br>
+ }<br>
+<br>
+ for_each_available_child_of_node(companion, child) {<br>
+ ret = of_property_read_u32(child, "reg", &i);<br>
+ if (ret || i > MAX_LDB_CHAN_NUM - 1) {<br>
+ DRM_DEV_ERROR(dev,<br>
+ "invalid channel node address: %u\n", i);<br>
+ ret = -EINVAL;<br>
+ of_node_put(child);<br>
+ goto out;<br>
+ }<br>
+<br>
+ /*<br>
+ * Channel numbers have to be different, because channel0<br>
+ * transmits odd pixels and channel1 transmits even pixels.<br>
+ */<br>
+ if (i == (ldb_ch->chno ^ 0x1)) {<br>
+ companion_port = child;<br>
+ break;<br>
+ }<br>
+ }<br>
+<br>
+ if (companion_port == NULL) {<br>
+ DRM_DEV_ERROR(dev,<br>
+ "failed to find companion LDB channel port\n");<br>
+ ret = -EINVAL;<br>
+ goto out;<br>
+ }<br>
+<br>
+ /*<br>
+ * We need to work out if the sink is expecting us to function in<br>
+ * dual-link mode. We do this by looking at the DT port nodes we are<br>
+ * connected to. If they are marked as expecting odd pixels and<br>
+ * even pixels than we need to enable LDB split mode.<br>
+ */<br>
+ port1 = of_graph_get_port_by_id(ldb_ch->np, 1);<br>
+ port2 = of_graph_get_port_by_id(companion_port, 1);<br>
+ dual_link = drm_of_lvds_get_dual_link_pixel_order(port1, port2);<br>
+ of_node_put(port1);<br>
+ of_node_put(port2);<br>
+<br>
+ switch (dual_link) {<br>
+ case DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS:<br>
+ ldb_ch->link_type = LDB_CH_DUAL_LINK_ODD_EVEN_PIXELS;<br>
+ break;<br>
+ case DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS:<br>
+ ldb_ch->link_type = LDB_CH_DUAL_LINK_EVEN_ODD_PIXELS;<br>
+ break;<br>
+ default:<br>
+ ret = dual_link;<br>
+ DRM_DEV_ERROR(dev,<br>
+ "failed to get dual link pixel order: %d\n", ret);<br>
+ goto out;<br>
+ }<br>
+<br>
+ ret = imx8qxp_ldb_check_chno_and_dual_link(ldb_ch, dual_link);<br>
+ if (ret < 0) {<br>
+ DRM_DEV_ERROR(dev,<br>
+ "unmatched channel number(%u) vs dual link(%d)\n",<br>
+ ldb_ch->chno, dual_link);<br>
+ goto out;<br>
+ }<br>
+<br>
+ imx8qxp_ldb->companion = of_drm_find_bridge(companion_port);<br>
+ if (!imx8qxp_ldb->companion) {<br>
+ ret = -EPROBE_DEFER;<br>
+ DRM_DEV_DEBUG_DRIVER(dev,<br>
+ "failed to find bridge for companion bridge: %d\n", ret);<br>
+ goto out;<br>
+ }<br>
+<br>
+ DRM_DEV_DEBUG_DRIVER(dev,<br>
+ "dual-link configuration detected (companion bridge %pOF)\n",<br>
+ companion);<br>
+<br>
+ companion_ldb_ch = bridge_to_ldb_ch(imx8qxp_ldb->companion);<br>
+ companion_ldb_ch->link_type = ldb_ch->link_type;<br>
+out:<br>
+ of_node_put(companion_port);<br>
+ of_node_put(companion);<br>
+ return ret;<br>
+}<br>
+<br>
+static int imx8qxp_ldb_probe(struct platform_device *pdev)<br>
+{<br>
+ struct device *dev = &pdev->dev;<br>
+ struct imx8qxp_ldb *imx8qxp_ldb;<br>
+ struct imx8qxp_ldb_channel *imx8qxp_ldb_ch;<br>
+ struct ldb *ldb;<br>
+ struct ldb_channel *ldb_ch;<br>
+ int ret, i;<br>
+<br>
+ imx8qxp_ldb = devm_kzalloc(dev, sizeof(*imx8qxp_ldb), GFP_KERNEL);<br>
+ if (!imx8qxp_ldb)<br>
+ return -ENOMEM;<br>
+<br>
+ imx8qxp_ldb->clk_pixel = devm_clk_get(dev, "pixel");<br>
+ if (IS_ERR(imx8qxp_ldb->clk_pixel)) {<br>
+ ret = PTR_ERR(imx8qxp_ldb->clk_pixel);<br>
+ if (ret != -EPROBE_DEFER)<br>
+ DRM_DEV_ERROR(dev,<br>
+ "failed to get pixel clock: %d\n", ret);<br>
+ return ret;<br>
+ }<br>
+<br>
+ imx8qxp_ldb->clk_bypass = devm_clk_get(dev, "bypass");<br>
+ if (IS_ERR(imx8qxp_ldb->clk_bypass)) {<br>
+ ret = PTR_ERR(imx8qxp_ldb->clk_bypass);<br>
+ if (ret != -EPROBE_DEFER)<br>
+ DRM_DEV_ERROR(dev,<br>
+ "failed to get bypass clock: %d\n", ret);<br>
+ return ret;<br>
+ }<br>
+<br>
+ imx8qxp_ldb->dev = dev;<br>
+<br>
+ ldb = &imx8qxp_ldb->base;<br>
+ ldb->dev = dev;<br>
+ ldb->ctrl_reg = 0xe0;<br>
+<br>
+ for (i = 0; i < MAX_LDB_CHAN_NUM; i++)<br>
+ ldb->channel[i] = &imx8qxp_ldb->channel[i].base;<br>
+<br>
+ ret = ldb_init_helper(ldb);<br>
+ if (ret)<br>
+ return ret;<br>
+<br>
+ if (ldb->available_ch_cnt == 0) {<br>
+ DRM_DEV_DEBUG_DRIVER(dev, "no available channel\n");<br>
+ return 0;<br>
+ } else if (ldb->available_ch_cnt > 1) {<br>
+ DRM_DEV_ERROR(dev, "invalid available channel number(%u)\n",<br>
+ ldb->available_ch_cnt);<br>
+ return -ENOTSUPP;<br>
+ }<br>
+<br>
+ for (i = 0; i < MAX_LDB_CHAN_NUM; i++) {<br>
+ imx8qxp_ldb_ch = &imx8qxp_ldb->channel[i];<br>
+ ldb_ch = &imx8qxp_ldb_ch->base;<br>
+<br>
+ if (ldb_ch->is_available) {<br>
+ imx8qxp_ldb->active_chno = ldb_ch->chno;<br>
+ break;<br>
+ }<br>
+ }<br>
+<br>
+ imx8qxp_ldb_ch->phy = devm_of_phy_get(dev, ldb_ch->np, "lvds_phy");<br>
+ if (IS_ERR(imx8qxp_ldb_ch->phy)) {<br>
+ ret = PTR_ERR(imx8qxp_ldb_ch->phy);<br>
+ if (ret != -EPROBE_DEFER)<br>
+ DRM_DEV_ERROR(dev, "failed to get channel%d PHY: %d\n",<br>
+ imx8qxp_ldb->active_chno, ret);<br>
+ return ret;<br>
+ }<br>
+<br>
+ ret = ldb_find_next_bridge_helper(ldb);<br>
+ if (ret)<br>
+ return ret;<br>
+<br>
+ ret = imx8qxp_ldb_set_di_id(imx8qxp_ldb);<br>
+ if (ret)<br>
+ return ret;<br>
+<br>
+ ret = imx8qxp_ldb_parse_dt_companion(imx8qxp_ldb);<br>
+ if (ret)<br>
+ return ret;<br>
+<br>
+ platform_set_drvdata(pdev, imx8qxp_ldb);<br>
+ pm_runtime_enable(dev);<br>
+<br>
+ ldb_add_bridge_helper(ldb, &imx8qxp_ldb_bridge_funcs);<br>
+<br>
+ return ret;<br>
+}<br>
+<br>
+static int imx8qxp_ldb_remove(struct platform_device *pdev)<br>
+{<br>
+ struct imx8qxp_ldb *imx8qxp_ldb = platform_get_drvdata(pdev);<br>
+ struct ldb *ldb = &imx8qxp_ldb->base;<br>
+<br>
+ ldb_remove_bridge_helper(ldb);<br>
+<br>
+ pm_runtime_disable(&pdev->dev);<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
+static int __maybe_unused imx8qxp_ldb_runtime_suspend(struct device *dev)<br>
+{<br>
+ return 0;<br>
+}<br>
+<br>
+static int __maybe_unused imx8qxp_ldb_runtime_resume(struct device *dev)<br>
+{<br>
+ struct imx8qxp_ldb *imx8qxp_ldb = dev_get_drvdata(dev);<br>
+ struct ldb *ldb = &imx8qxp_ldb->base;<br>
+<br>
+ /* disable LDB by resetting the control register to POR default */<br>
+ regmap_write(ldb->regmap, ldb->ctrl_reg, 0);<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
+static const struct dev_pm_ops imx8qxp_ldb_pm_ops = {<br>
+ SET_RUNTIME_PM_OPS(imx8qxp_ldb_runtime_suspend,<br>
+ imx8qxp_ldb_runtime_resume, NULL)<br>
+};<br>
+<br>
+static const struct of_device_id imx8qxp_ldb_dt_ids[] = {<br>
+ { .compatible = "fsl,imx8qxp-ldb" },<br>
+ { /* sentinel */ }<br>
+};<br>
+MODULE_DEVICE_TABLE(of, imx8qxp_ldb_dt_ids);<br>
+<br>
+static struct platform_driver imx8qxp_ldb_driver = {<br>
+ .probe = imx8qxp_ldb_probe,<br>
+ .remove = imx8qxp_ldb_remove,<br>
+ .driver = {<br>
+ .pm = &imx8qxp_ldb_pm_ops,<br>
+ .name = DRIVER_NAME,<br>
+ .of_match_table = imx8qxp_ldb_dt_ids,<br>
+ },<br>
+};<br>
+module_platform_driver(imx8qxp_ldb_driver);<br>
+<br>
+MODULE_DESCRIPTION("i.MX8QXP LVDS Display Bridge(LDB)/Pixel Mapper bridge driver");<br>
+MODULE_AUTHOR("Liu Ying <victor.liu@nxp.com>");<br>
+MODULE_LICENSE("GPL v2");<br>
+MODULE_ALIAS("platform:" DRIVER_NAME);<br>
--<br>
2.7.4<br><br></p>
<p dir="ltr">------------------------------</p>
<p dir="ltr">Subject: Digest Footer</p>
<p dir="ltr">_______________________________________________<br>
dri-devel mailing list<br>
dri-devel@lists.freedesktop.org<br>
<a href="https://lists.freedesktop.org/mailman/listinfo/dri-devel">https://lists.freedesktop.org/mailman/listinfo/dri-devel</a><br></p>
<p dir="ltr">------------------------------</p>
<p dir="ltr">End of dri-devel Digest, Vol 132, Issue 197<br>
*******************************************<br>
</p>
</div>