Hi,
This patch set aims to add i.MX93 LCDIF display controller support
in the existing LCDIF DRM driver. The LCDIF embedded in i.MX93 SoC
is essentially the same to those embedded in i.MX8mp SoC. Through
internal bridges, i.MX93 LCDIF may drive a MIPI DSI display or a LVDS
display or a parallel display.
Patch 1/6 adds device tree binding support for i.MX93 LCDIF in the
existing fsl,lcdif.yaml.
Patch 2/6 drops lcdif->bridge NULL pointer check as a cleanup patch.
Patch 3/6~5/6 prepare for adding i.MX93 LCDIF support step by step.
Patch 6/6 adds i.MX93 LCDIF compatible string as the last step of
adding i.MX93 LCDIF support.
v2->v3:
* Fix a trivial typo in patch 6/6's commit message.
v1->v2:
* Add Krzysztof's A-b and Marek's R-b tags on patch 1/6.
* Split patch 2/2 in v1 into patch 2/6~6/6 in v2. (Marek, Alexander)
* Drop '!remote ||' from lcdif_attach_bridge(). (Lothar)
* Add comment on the 'base' member of lcdif_crtc_state structure to
note it should always be the first member. (Lothar)
* Drop unneeded 'bridges' member from lcdif_drm_private structure.
* Drop a comment about bridge input bus format from lcdif_crtc_atomic_check().
Liu Ying (6):
dt-bindings: lcdif: Add i.MX93 LCDIF support
drm: lcdif: Drop unnecessary NULL pointer check on lcdif->bridge
drm: lcdif: Determine bus format and flags in ->atomic_check()
drm: lcdif: Check consistent bus format and flags across first bridges
drm: lcdif: Add multiple encoders and first bridges support
drm: lcdif: Add i.MX93 LCDIF compatible string
.../bindings/display/fsl,lcdif.yaml | 7 +-
drivers/gpu/drm/mxsfb/lcdif_drv.c | 71 +++++-
drivers/gpu/drm/mxsfb/lcdif_drv.h | 5 +-
drivers/gpu/drm/mxsfb/lcdif_kms.c | 202 ++++++++++++------
4 files changed, 207 insertions(+), 78 deletions(-)
--
2.37.1
There is one LCDIF embedded in i.MX93 SoC to connect with
MIPI DSI controller through LCDIF cross line pattern(controlled
by mediamix blk-ctrl) or connect with LVDS display bridge(LDB)
directly or connect with a parallel display through parallel
display format(also controlled by mediamix blk-ctrl). i.MX93
LCDIF IP is essentially the same to i.MX8MP LCDIF IP. Add device
tree binding for i.MX93 LCDIF.
Acked-by: Krzysztof Kozlowski <[email protected]>
Reviewed-by: Marek Vasut <[email protected]>
Signed-off-by: Liu Ying <[email protected]>
---
v2->v3:
* No change.
v1->v2:
* Add Krzysztof's A-b and Marek's R-b tags on patch 1/6.
Documentation/devicetree/bindings/display/fsl,lcdif.yaml | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/display/fsl,lcdif.yaml b/Documentation/devicetree/bindings/display/fsl,lcdif.yaml
index 75b4efd70ba8..fc11ab5fc465 100644
--- a/Documentation/devicetree/bindings/display/fsl,lcdif.yaml
+++ b/Documentation/devicetree/bindings/display/fsl,lcdif.yaml
@@ -21,6 +21,7 @@ properties:
- fsl,imx28-lcdif
- fsl,imx6sx-lcdif
- fsl,imx8mp-lcdif
+ - fsl,imx93-lcdif
- items:
- enum:
- fsl,imx6sl-lcdif
@@ -88,7 +89,9 @@ allOf:
properties:
compatible:
contains:
- const: fsl,imx8mp-lcdif
+ enum:
+ - fsl,imx8mp-lcdif
+ - fsl,imx93-lcdif
then:
properties:
clocks:
@@ -107,6 +110,7 @@ allOf:
enum:
- fsl,imx6sx-lcdif
- fsl,imx8mp-lcdif
+ - fsl,imx93-lcdif
then:
properties:
clocks:
@@ -123,6 +127,7 @@ allOf:
- fsl,imx8mm-lcdif
- fsl,imx8mn-lcdif
- fsl,imx8mp-lcdif
+ - fsl,imx93-lcdif
then:
required:
- power-domains
--
2.37.1
A valid bridge is already found in lcdif_attach_bridge() and set
to lcdif->bridge, so lcdif->bridge cannot be a NULL pointer. Drop
the unnecessary NULL pointer check in KMS stage.
Signed-off-by: Liu Ying <[email protected]>
---
v2->v3:
* No change.
v1->v2:
* Split from patch 2/2 in v1. (Marek, Alexander)
drivers/gpu/drm/mxsfb/lcdif_kms.c | 33 +++++++++++--------------------
1 file changed, 12 insertions(+), 21 deletions(-)
diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c b/drivers/gpu/drm/mxsfb/lcdif_kms.c
index 262bc43b1079..e54200a9fcb9 100644
--- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
+++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
@@ -394,7 +394,7 @@ static void lcdif_crtc_mode_set_nofb(struct lcdif_drm_private *lcdif,
struct drm_display_mode *m = &lcdif->crtc.state->adjusted_mode;
u32 bus_flags = 0;
- if (lcdif->bridge && lcdif->bridge->timings)
+ if (lcdif->bridge->timings)
bus_flags = lcdif->bridge->timings->input_bus_flags;
else if (bridge_state)
bus_flags = bridge_state->input_bus_cfg.flags;
@@ -463,30 +463,21 @@ static void lcdif_crtc_atomic_enable(struct drm_crtc *crtc,
struct drm_display_mode *m = &lcdif->crtc.state->adjusted_mode;
struct drm_bridge_state *bridge_state = NULL;
struct drm_device *drm = lcdif->drm;
- u32 bus_format = 0;
+ u32 bus_format;
dma_addr_t paddr;
- /* If there is a bridge attached to the LCDIF, use its bus format */
- if (lcdif->bridge) {
- bridge_state =
- drm_atomic_get_new_bridge_state(state,
- lcdif->bridge);
- if (!bridge_state)
- bus_format = MEDIA_BUS_FMT_FIXED;
- else
- bus_format = bridge_state->input_bus_cfg.format;
-
- if (bus_format == MEDIA_BUS_FMT_FIXED) {
- dev_warn_once(drm->dev,
- "Bridge does not provide bus format, assuming MEDIA_BUS_FMT_RGB888_1X24.\n"
- "Please fix bridge driver by handling atomic_get_input_bus_fmts.\n");
- bus_format = MEDIA_BUS_FMT_RGB888_1X24;
- }
- }
+ bridge_state = drm_atomic_get_new_bridge_state(state, lcdif->bridge);
+ if (!bridge_state)
+ bus_format = MEDIA_BUS_FMT_FIXED;
+ else
+ bus_format = bridge_state->input_bus_cfg.format;
- /* If all else fails, default to RGB888_1X24 */
- if (!bus_format)
+ if (bus_format == MEDIA_BUS_FMT_FIXED) {
+ dev_warn_once(drm->dev,
+ "Bridge does not provide bus format, assuming MEDIA_BUS_FMT_RGB888_1X24.\n"
+ "Please fix bridge driver by handling atomic_get_input_bus_fmts.\n");
bus_format = MEDIA_BUS_FMT_RGB888_1X24;
+ }
clk_set_rate(lcdif->clk, m->crtc_clock * 1000);
--
2.37.1
Instead of determining LCDIF output bus format and bus flags in
->atomic_enable(), do that in ->atomic_check(). This is a
preparation for the upcoming patch to check consistent bus format
and bus flags across all first downstream bridges in ->atomic_check().
New lcdif_crtc_state structure is introduced to cache bus format
and bus flags states in ->atomic_check() so that they can be read
in ->atomic_enable().
Signed-off-by: Liu Ying <[email protected]>
---
v2->v3:
* No change.
v1->v2:
* Split from patch 2/2 in v1. (Marek, Alexander)
* Add comment on the 'base' member of lcdif_crtc_state structure to
note it should always be the first member. (Lothar)
drivers/gpu/drm/mxsfb/lcdif_kms.c | 138 ++++++++++++++++++++++--------
1 file changed, 100 insertions(+), 38 deletions(-)
diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c b/drivers/gpu/drm/mxsfb/lcdif_kms.c
index e54200a9fcb9..294cecdf5439 100644
--- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
+++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
@@ -30,6 +30,18 @@
#include "lcdif_drv.h"
#include "lcdif_regs.h"
+struct lcdif_crtc_state {
+ struct drm_crtc_state base; /* always be the first member */
+ u32 bus_format;
+ u32 bus_flags;
+};
+
+static inline struct lcdif_crtc_state *
+to_lcdif_crtc_state(struct drm_crtc_state *s)
+{
+ return container_of(s, struct lcdif_crtc_state, base);
+}
+
/* -----------------------------------------------------------------------------
* CRTC
*/
@@ -385,48 +397,72 @@ static void lcdif_reset_block(struct lcdif_drm_private *lcdif)
readl(lcdif->base + LCDC_V8_CTRL);
}
-static void lcdif_crtc_mode_set_nofb(struct lcdif_drm_private *lcdif,
- struct drm_plane_state *plane_state,
- struct drm_bridge_state *bridge_state,
- const u32 bus_format)
+static void lcdif_crtc_mode_set_nofb(struct drm_crtc_state *crtc_state,
+ struct drm_plane_state *plane_state)
{
- struct drm_device *drm = lcdif->crtc.dev;
- struct drm_display_mode *m = &lcdif->crtc.state->adjusted_mode;
- u32 bus_flags = 0;
-
- if (lcdif->bridge->timings)
- bus_flags = lcdif->bridge->timings->input_bus_flags;
- else if (bridge_state)
- bus_flags = bridge_state->input_bus_cfg.flags;
+ struct lcdif_crtc_state *lcdif_crtc_state = to_lcdif_crtc_state(crtc_state);
+ struct drm_device *drm = crtc_state->crtc->dev;
+ struct lcdif_drm_private *lcdif = to_lcdif_drm_private(drm);
+ struct drm_display_mode *m = &crtc_state->adjusted_mode;
DRM_DEV_DEBUG_DRIVER(drm->dev, "Pixel clock: %dkHz (actual: %dkHz)\n",
m->crtc_clock,
(int)(clk_get_rate(lcdif->clk) / 1000));
DRM_DEV_DEBUG_DRIVER(drm->dev, "Bridge bus_flags: 0x%08X\n",
- bus_flags);
+ lcdif_crtc_state->bus_flags);
DRM_DEV_DEBUG_DRIVER(drm->dev, "Mode flags: 0x%08X\n", m->flags);
/* Mandatory eLCDIF reset as per the Reference Manual */
lcdif_reset_block(lcdif);
- lcdif_set_formats(lcdif, plane_state, bus_format);
+ lcdif_set_formats(lcdif, plane_state, lcdif_crtc_state->bus_format);
- lcdif_set_mode(lcdif, bus_flags);
+ lcdif_set_mode(lcdif, lcdif_crtc_state->bus_flags);
}
static int lcdif_crtc_atomic_check(struct drm_crtc *crtc,
struct drm_atomic_state *state)
{
+ struct drm_device *drm = crtc->dev;
+ struct lcdif_drm_private *lcdif = to_lcdif_drm_private(drm);
struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state,
crtc);
+ struct lcdif_crtc_state *lcdif_crtc_state = to_lcdif_crtc_state(crtc_state);
bool has_primary = crtc_state->plane_mask &
drm_plane_mask(crtc->primary);
+ struct drm_bridge_state *bridge_state;
+ struct drm_bridge *bridge = lcdif->bridge;
+ int ret;
/* The primary plane has to be enabled when the CRTC is active. */
if (crtc_state->active && !has_primary)
return -EINVAL;
- return drm_atomic_add_affected_planes(state, crtc);
+ ret = drm_atomic_add_affected_planes(state, crtc);
+ if (ret)
+ return ret;
+
+ bridge_state = drm_atomic_get_new_bridge_state(state, bridge);
+ if (!bridge_state)
+ lcdif_crtc_state->bus_format = MEDIA_BUS_FMT_FIXED;
+ else
+ lcdif_crtc_state->bus_format = bridge_state->input_bus_cfg.format;
+
+ if (lcdif_crtc_state->bus_format == MEDIA_BUS_FMT_FIXED) {
+ dev_warn_once(drm->dev,
+ "Bridge does not provide bus format, assuming MEDIA_BUS_FMT_RGB888_1X24.\n"
+ "Please fix bridge driver by handling atomic_get_input_bus_fmts.\n");
+ lcdif_crtc_state->bus_format = MEDIA_BUS_FMT_RGB888_1X24;
+ }
+
+ if (bridge->timings)
+ lcdif_crtc_state->bus_flags = bridge->timings->input_bus_flags;
+ else if (bridge_state)
+ lcdif_crtc_state->bus_flags = bridge_state->input_bus_cfg.flags;
+ else
+ lcdif_crtc_state->bus_flags = 0;
+
+ return 0;
}
static void lcdif_crtc_atomic_flush(struct drm_crtc *crtc,
@@ -458,35 +494,21 @@ static void lcdif_crtc_atomic_enable(struct drm_crtc *crtc,
struct drm_atomic_state *state)
{
struct lcdif_drm_private *lcdif = to_lcdif_drm_private(crtc->dev);
- struct drm_plane_state *new_pstate = drm_atomic_get_new_plane_state(state,
- crtc->primary);
+ struct drm_crtc_state *new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
+ struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
+ crtc->primary);
struct drm_display_mode *m = &lcdif->crtc.state->adjusted_mode;
- struct drm_bridge_state *bridge_state = NULL;
struct drm_device *drm = lcdif->drm;
- u32 bus_format;
dma_addr_t paddr;
- bridge_state = drm_atomic_get_new_bridge_state(state, lcdif->bridge);
- if (!bridge_state)
- bus_format = MEDIA_BUS_FMT_FIXED;
- else
- bus_format = bridge_state->input_bus_cfg.format;
-
- if (bus_format == MEDIA_BUS_FMT_FIXED) {
- dev_warn_once(drm->dev,
- "Bridge does not provide bus format, assuming MEDIA_BUS_FMT_RGB888_1X24.\n"
- "Please fix bridge driver by handling atomic_get_input_bus_fmts.\n");
- bus_format = MEDIA_BUS_FMT_RGB888_1X24;
- }
-
clk_set_rate(lcdif->clk, m->crtc_clock * 1000);
pm_runtime_get_sync(drm->dev);
- lcdif_crtc_mode_set_nofb(lcdif, new_pstate, bridge_state, bus_format);
+ lcdif_crtc_mode_set_nofb(new_crtc_state, new_plane_state);
/* Write cur_buf as well to avoid an initial corrupt frame */
- paddr = drm_fb_dma_get_gem_addr(new_pstate->fb, new_pstate, 0);
+ paddr = drm_fb_dma_get_gem_addr(new_plane_state->fb, new_plane_state, 0);
if (paddr) {
writel(lower_32_bits(paddr),
lcdif->base + LCDC_V8_CTRLDESCL_LOW0_4);
@@ -520,6 +542,46 @@ static void lcdif_crtc_atomic_disable(struct drm_crtc *crtc,
pm_runtime_put_sync(drm->dev);
}
+static void lcdif_crtc_reset(struct drm_crtc *crtc)
+{
+ struct lcdif_crtc_state *state;
+
+ if (crtc->state)
+ __drm_atomic_helper_crtc_destroy_state(crtc->state);
+
+ kfree(to_lcdif_crtc_state(crtc->state));
+ crtc->state = NULL;
+
+ state = kzalloc(sizeof(*state), GFP_KERNEL);
+ if (state)
+ __drm_atomic_helper_crtc_reset(crtc, &state->base);
+}
+
+static struct drm_crtc_state *
+lcdif_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
+{
+ struct lcdif_crtc_state *old = to_lcdif_crtc_state(crtc->state);
+ struct lcdif_crtc_state *new;
+
+ new = kzalloc(sizeof(*new), GFP_KERNEL);
+ if (!new)
+ return NULL;
+
+ __drm_atomic_helper_crtc_duplicate_state(crtc, &new->base);
+
+ new->bus_format = old->bus_format;
+ new->bus_flags = old->bus_flags;
+
+ return &new->base;
+}
+
+static void lcdif_crtc_atomic_destroy_state(struct drm_crtc *crtc,
+ struct drm_crtc_state *state)
+{
+ __drm_atomic_helper_crtc_destroy_state(state);
+ kfree(to_lcdif_crtc_state(state));
+}
+
static int lcdif_crtc_enable_vblank(struct drm_crtc *crtc)
{
struct lcdif_drm_private *lcdif = to_lcdif_drm_private(crtc->dev);
@@ -548,12 +610,12 @@ static const struct drm_crtc_helper_funcs lcdif_crtc_helper_funcs = {
};
static const struct drm_crtc_funcs lcdif_crtc_funcs = {
- .reset = drm_atomic_helper_crtc_reset,
+ .reset = lcdif_crtc_reset,
.destroy = drm_crtc_cleanup,
.set_config = drm_atomic_helper_set_config,
.page_flip = drm_atomic_helper_page_flip,
- .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
- .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
+ .atomic_duplicate_state = lcdif_crtc_atomic_duplicate_state,
+ .atomic_destroy_state = lcdif_crtc_atomic_destroy_state,
.enable_vblank = lcdif_crtc_enable_vblank,
.disable_vblank = lcdif_crtc_disable_vblank,
};
--
2.37.1
The single LCDIF embedded in i.MX93 SoC may drive multiple displays
simultaneously. Check bus format and flags across first bridges in
->atomic_check() to ensure they are consistent. This is a preparation
for adding i.MX93 LCDIF support.
Signed-off-by: Liu Ying <[email protected]>
---
v2->v3:
* No change.
v1->v2:
* Split from patch 2/2 in v1. (Marek, Alexander)
* Drop a comment about bridge input bus format from lcdif_crtc_atomic_check().
drivers/gpu/drm/mxsfb/lcdif_drv.c | 2 -
drivers/gpu/drm/mxsfb/lcdif_drv.h | 1 -
drivers/gpu/drm/mxsfb/lcdif_kms.c | 76 ++++++++++++++++++++++---------
3 files changed, 55 insertions(+), 24 deletions(-)
diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c b/drivers/gpu/drm/mxsfb/lcdif_drv.c
index cc2ceb301b96..b5b9a8e273c6 100644
--- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
+++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
@@ -52,8 +52,6 @@ static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
if (ret)
return dev_err_probe(drm->dev, ret, "Failed to attach bridge\n");
- lcdif->bridge = bridge;
-
return 0;
}
diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.h b/drivers/gpu/drm/mxsfb/lcdif_drv.h
index 6cdba6e20c02..aa6d099a1897 100644
--- a/drivers/gpu/drm/mxsfb/lcdif_drv.h
+++ b/drivers/gpu/drm/mxsfb/lcdif_drv.h
@@ -31,7 +31,6 @@ struct lcdif_drm_private {
} planes;
struct drm_crtc crtc;
struct drm_encoder encoder;
- struct drm_bridge *bridge;
};
static inline struct lcdif_drm_private *
diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c b/drivers/gpu/drm/mxsfb/lcdif_kms.c
index 294cecdf5439..4ea3d2b2cf61 100644
--- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
+++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
@@ -17,6 +17,7 @@
#include <drm/drm_atomic_helper.h>
#include <drm/drm_bridge.h>
#include <drm/drm_color_mgmt.h>
+#include <drm/drm_connector.h>
#include <drm/drm_crtc.h>
#include <drm/drm_encoder.h>
#include <drm/drm_fb_dma_helper.h>
@@ -424,15 +425,19 @@ static int lcdif_crtc_atomic_check(struct drm_crtc *crtc,
struct drm_atomic_state *state)
{
struct drm_device *drm = crtc->dev;
- struct lcdif_drm_private *lcdif = to_lcdif_drm_private(drm);
struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state,
crtc);
struct lcdif_crtc_state *lcdif_crtc_state = to_lcdif_crtc_state(crtc_state);
bool has_primary = crtc_state->plane_mask &
drm_plane_mask(crtc->primary);
+ struct drm_connector_state *connector_state;
+ struct drm_connector *connector;
+ struct drm_encoder *encoder;
struct drm_bridge_state *bridge_state;
- struct drm_bridge *bridge = lcdif->bridge;
- int ret;
+ struct drm_bridge *bridge;
+ u32 bus_format, bus_flags;
+ bool format_set = false, flags_set = false;
+ int ret, i;
/* The primary plane has to be enabled when the CRTC is active. */
if (crtc_state->active && !has_primary)
@@ -442,26 +447,55 @@ static int lcdif_crtc_atomic_check(struct drm_crtc *crtc,
if (ret)
return ret;
- bridge_state = drm_atomic_get_new_bridge_state(state, bridge);
- if (!bridge_state)
- lcdif_crtc_state->bus_format = MEDIA_BUS_FMT_FIXED;
- else
- lcdif_crtc_state->bus_format = bridge_state->input_bus_cfg.format;
-
- if (lcdif_crtc_state->bus_format == MEDIA_BUS_FMT_FIXED) {
- dev_warn_once(drm->dev,
- "Bridge does not provide bus format, assuming MEDIA_BUS_FMT_RGB888_1X24.\n"
- "Please fix bridge driver by handling atomic_get_input_bus_fmts.\n");
- lcdif_crtc_state->bus_format = MEDIA_BUS_FMT_RGB888_1X24;
+ /* Try to find consistent bus format and flags across first bridges. */
+ for_each_new_connector_in_state(state, connector, connector_state, i) {
+ if (!connector_state->crtc)
+ continue;
+
+ encoder = connector_state->best_encoder;
+
+ bridge = drm_bridge_chain_get_first_bridge(encoder);
+ if (!bridge)
+ continue;
+
+ bridge_state = drm_atomic_get_new_bridge_state(state, bridge);
+ if (!bridge_state)
+ bus_format = MEDIA_BUS_FMT_FIXED;
+ else
+ bus_format = bridge_state->input_bus_cfg.format;
+
+ if (bus_format == MEDIA_BUS_FMT_FIXED) {
+ dev_warn(drm->dev,
+ "[ENCODER:%d:%s]'s bridge does not provide bus format, assuming MEDIA_BUS_FMT_RGB888_1X24.\n"
+ "Please fix bridge driver by handling atomic_get_input_bus_fmts.\n",
+ encoder->base.id, encoder->name);
+ bus_format = MEDIA_BUS_FMT_RGB888_1X24;
+ }
+
+ if (!format_set) {
+ lcdif_crtc_state->bus_format = bus_format;
+ format_set = true;
+ } else if (lcdif_crtc_state->bus_format != bus_format) {
+ DRM_DEV_DEBUG_DRIVER(drm->dev, "inconsistent bus format\n");
+ return -EINVAL;
+ }
+
+ if (bridge->timings)
+ bus_flags = bridge->timings->input_bus_flags;
+ else if (bridge_state)
+ bus_flags = bridge_state->input_bus_cfg.flags;
+ else
+ bus_flags = 0;
+
+ if (!flags_set) {
+ lcdif_crtc_state->bus_flags = bus_flags;
+ flags_set = true;
+ } else if (lcdif_crtc_state->bus_flags != bus_flags) {
+ DRM_DEV_DEBUG_DRIVER(drm->dev, "inconsistent bus flags\n");
+ return -EINVAL;
+ }
}
- if (bridge->timings)
- lcdif_crtc_state->bus_flags = bridge->timings->input_bus_flags;
- else if (bridge_state)
- lcdif_crtc_state->bus_flags = bridge_state->input_bus_cfg.flags;
- else
- lcdif_crtc_state->bus_flags = 0;
-
return 0;
}
--
2.37.1
The single LCDIF embedded in i.MX93 SoC may drive multiple displays
simultaneously. Look at LCDIF output port's remote port parents to
find all enabled first bridges. Add an encoder for each found bridge
and attach the bridge to the encoder. This is a preparation for
adding i.MX93 LCDIF support.
Signed-off-by: Liu Ying <[email protected]>
---
v2->v3:
* No change.
v1->v2:
* Split from patch 2/2 in v1. (Marek, Alexander)
* Drop '!remote ||' from lcdif_attach_bridge(). (Lothar)
* Drop unneeded 'bridges' member from lcdif_drm_private structure.
drivers/gpu/drm/mxsfb/lcdif_drv.c | 68 +++++++++++++++++++++++++++----
drivers/gpu/drm/mxsfb/lcdif_drv.h | 4 +-
drivers/gpu/drm/mxsfb/lcdif_kms.c | 21 ++--------
3 files changed, 66 insertions(+), 27 deletions(-)
diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c b/drivers/gpu/drm/mxsfb/lcdif_drv.c
index b5b9a8e273c6..eb6c265fa2fe 100644
--- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
+++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
@@ -9,13 +9,16 @@
#include <linux/dma-mapping.h>
#include <linux/io.h>
#include <linux/module.h>
+#include <linux/of.h>
#include <linux/of_device.h>
+#include <linux/of_graph.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_bridge.h>
#include <drm/drm_drv.h>
+#include <drm/drm_encoder.h>
#include <drm/drm_fbdev_generic.h>
#include <drm/drm_gem_dma_helper.h>
#include <drm/drm_gem_framebuffer_helper.h>
@@ -38,19 +41,68 @@ static const struct drm_mode_config_helper_funcs lcdif_mode_config_helpers = {
.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
};
+static const struct drm_encoder_funcs lcdif_encoder_funcs = {
+ .destroy = drm_encoder_cleanup,
+};
+
static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
{
- struct drm_device *drm = lcdif->drm;
+ struct device *dev = lcdif->drm->dev;
+ struct device_node *ep;
struct drm_bridge *bridge;
int ret;
- bridge = devm_drm_of_get_bridge(drm->dev, drm->dev->of_node, 0, 0);
- if (IS_ERR(bridge))
- return PTR_ERR(bridge);
-
- ret = drm_bridge_attach(&lcdif->encoder, bridge, NULL, 0);
- if (ret)
- return dev_err_probe(drm->dev, ret, "Failed to attach bridge\n");
+ for_each_endpoint_of_node(dev->of_node, ep) {
+ struct device_node *remote;
+ struct of_endpoint of_ep;
+ struct drm_encoder *encoder;
+
+ remote = of_graph_get_remote_port_parent(ep);
+ if (!of_device_is_available(remote)) {
+ of_node_put(remote);
+ continue;
+ }
+ of_node_put(remote);
+
+ ret = of_graph_parse_endpoint(ep, &of_ep);
+ if (ret < 0) {
+ dev_err(dev, "Failed to parse endpoint %pOF\n", ep);
+ of_node_put(ep);
+ return ret;
+ }
+
+ if (of_ep.id >= MAX_DISPLAYS) {
+ dev_warn(dev, "invalid endpoint id %u\n", of_ep.id);
+ continue;
+ }
+
+ bridge = devm_drm_of_get_bridge(dev, dev->of_node, 0, of_ep.id);
+ if (IS_ERR(bridge)) {
+ of_node_put(ep);
+ return dev_err_probe(dev, PTR_ERR(bridge),
+ "Failed to get bridge for endpoint%u\n",
+ of_ep.id);
+ }
+
+ encoder = &lcdif->encoders[of_ep.id];
+ encoder->possible_crtcs = drm_crtc_mask(&lcdif->crtc);
+ ret = drm_encoder_init(lcdif->drm, encoder, &lcdif_encoder_funcs,
+ DRM_MODE_ENCODER_NONE, NULL);
+ if (ret) {
+ dev_err(dev, "Failed to initialize encoder for endpoint%u: %d\n",
+ of_ep.id, ret);
+ of_node_put(ep);
+ return ret;
+ }
+
+ ret = drm_bridge_attach(encoder, bridge, NULL, 0);
+ if (ret) {
+ of_node_put(ep);
+ return dev_err_probe(dev, ret,
+ "Failed to attach bridge for endpoint%u\n",
+ of_ep.id);
+ }
+ }
return 0;
}
diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.h b/drivers/gpu/drm/mxsfb/lcdif_drv.h
index aa6d099a1897..c7400bd9bbd9 100644
--- a/drivers/gpu/drm/mxsfb/lcdif_drv.h
+++ b/drivers/gpu/drm/mxsfb/lcdif_drv.h
@@ -14,6 +14,8 @@
#include <drm/drm_encoder.h>
#include <drm/drm_plane.h>
+#define MAX_DISPLAYS 3
+
struct clk;
struct lcdif_drm_private {
@@ -30,7 +32,7 @@ struct lcdif_drm_private {
/* i.MXRT does support overlay planes, add them here. */
} planes;
struct drm_crtc crtc;
- struct drm_encoder encoder;
+ struct drm_encoder encoders[MAX_DISPLAYS];
};
static inline struct lcdif_drm_private *
diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c b/drivers/gpu/drm/mxsfb/lcdif_kms.c
index 4ea3d2b2cf61..5f34d01e133e 100644
--- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
+++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
@@ -654,14 +654,6 @@ static const struct drm_crtc_funcs lcdif_crtc_funcs = {
.disable_vblank = lcdif_crtc_disable_vblank,
};
-/* -----------------------------------------------------------------------------
- * Encoder
- */
-
-static const struct drm_encoder_funcs lcdif_encoder_funcs = {
- .destroy = drm_encoder_cleanup,
-};
-
/* -----------------------------------------------------------------------------
* Planes
*/
@@ -754,7 +746,6 @@ int lcdif_kms_init(struct lcdif_drm_private *lcdif)
BIT(DRM_COLOR_YCBCR_BT2020);
const u32 supported_ranges = BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
BIT(DRM_COLOR_YCBCR_FULL_RANGE);
- struct drm_encoder *encoder = &lcdif->encoder;
struct drm_crtc *crtc = &lcdif->crtc;
int ret;
@@ -778,13 +769,7 @@ int lcdif_kms_init(struct lcdif_drm_private *lcdif)
return ret;
drm_crtc_helper_add(crtc, &lcdif_crtc_helper_funcs);
- ret = drm_crtc_init_with_planes(lcdif->drm, crtc,
- &lcdif->planes.primary, NULL,
- &lcdif_crtc_funcs, NULL);
- if (ret)
- return ret;
-
- encoder->possible_crtcs = drm_crtc_mask(crtc);
- return drm_encoder_init(lcdif->drm, encoder, &lcdif_encoder_funcs,
- DRM_MODE_ENCODER_NONE, NULL);
+ return drm_crtc_init_with_planes(lcdif->drm, crtc,
+ &lcdif->planes.primary, NULL,
+ &lcdif_crtc_funcs, NULL);
}
--
2.37.1
With all previous preparations done to make it possible for the
single LCDIF embedded in i.MX93 SoC to drive multiple displays
simultaneously, add i.MX93 LCDIF compatible string as the last
step of adding i.MX93 LCDIF support.
Signed-off-by: Liu Ying <[email protected]>
---
v2->v3:
* Fix a trivial typo in commit message.
v1->v2:
* Split from patch 2/2 in v1. (Marek, Alexander)
drivers/gpu/drm/mxsfb/lcdif_drv.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c b/drivers/gpu/drm/mxsfb/lcdif_drv.c
index eb6c265fa2fe..48c43b273a4a 100644
--- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
+++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
@@ -249,6 +249,7 @@ static const struct drm_driver lcdif_driver = {
static const struct of_device_id lcdif_dt_ids[] = {
{ .compatible = "fsl,imx8mp-lcdif" },
+ { .compatible = "fsl,imx93-lcdif" },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, lcdif_dt_ids);
--
2.37.1
Hi Liu,
thanks for the update.
Am Montag, 13. Februar 2023, 09:56:08 CET schrieb Liu Ying:
> A valid bridge is already found in lcdif_attach_bridge() and set
> to lcdif->bridge, so lcdif->bridge cannot be a NULL pointer. Drop
> the unnecessary NULL pointer check in KMS stage.
>
> Signed-off-by: Liu Ying <[email protected]>
> ---
> v2->v3:
> * No change.
>
> v1->v2:
> * Split from patch 2/2 in v1. (Marek, Alexander)
>
> drivers/gpu/drm/mxsfb/lcdif_kms.c | 33 +++++++++++--------------------
> 1 file changed, 12 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> b/drivers/gpu/drm/mxsfb/lcdif_kms.c index 262bc43b1079..e54200a9fcb9 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> +++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
> @@ -394,7 +394,7 @@ static void lcdif_crtc_mode_set_nofb(struct
> lcdif_drm_private *lcdif, struct drm_display_mode *m =
> &lcdif->crtc.state->adjusted_mode;
> u32 bus_flags = 0;
>
> - if (lcdif->bridge && lcdif->bridge->timings)
> + if (lcdif->bridge->timings)
> bus_flags = lcdif->bridge->timings->input_bus_flags;
> else if (bridge_state)
> bus_flags = bridge_state->input_bus_cfg.flags;
> @@ -463,30 +463,21 @@ static void lcdif_crtc_atomic_enable(struct drm_crtc
> *crtc, struct drm_display_mode *m = &lcdif->crtc.state->adjusted_mode;
> struct drm_bridge_state *bridge_state = NULL;
> struct drm_device *drm = lcdif->drm;
> - u32 bus_format = 0;
> + u32 bus_format;
> dma_addr_t paddr;
>
> - /* If there is a bridge attached to the LCDIF, use its bus format */
> - if (lcdif->bridge) {
> - bridge_state =
> - drm_atomic_get_new_bridge_state(state,
> - lcdif-
>bridge);
> - if (!bridge_state)
> - bus_format = MEDIA_BUS_FMT_FIXED;
> - else
> - bus_format = bridge_state->input_bus_cfg.format;
> -
> - if (bus_format == MEDIA_BUS_FMT_FIXED) {
> - dev_warn_once(drm->dev,
> - "Bridge does not provide bus
format, assuming
> MEDIA_BUS_FMT_RGB888_1X24.\n" -
"Please fix bridge driver by
> handling atomic_get_input_bus_fmts.\n"); -
bus_format =
> MEDIA_BUS_FMT_RGB888_1X24;
> - }
> - }
> + bridge_state = drm_atomic_get_new_bridge_state(state, lcdif-
>bridge);
> + if (!bridge_state)
> + bus_format = MEDIA_BUS_FMT_FIXED;
> + else
> + bus_format = bridge_state->input_bus_cfg.format;
>
> - /* If all else fails, default to RGB888_1X24 */
> - if (!bus_format)
> + if (bus_format == MEDIA_BUS_FMT_FIXED) {
> + dev_warn_once(drm->dev,
> + "Bridge does not provide bus format,
assuming
> MEDIA_BUS_FMT_RGB888_1X24.\n" + "Please fix
bridge driver by
> handling atomic_get_input_bus_fmts.\n"); bus_format =
> MEDIA_BUS_FMT_RGB888_1X24;
> + }
>
> clk_set_rate(lcdif->clk, m->crtc_clock * 1000);
LGTM.
Reviewed-by: Alexander Stein <[email protected]>
--
TQ-Systems GmbH | M?hlstra?e 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht M?nchen, HRB 105018
Gesch?ftsf?hrer: Detlef Schneider, R?diger Stahl, Stefan Schneider
http://www.tq-group.com/
Hi Liu,
thanks for the update.
Am Montag, 13. Februar 2023, 09:56:09 CET schrieb Liu Ying:
> Instead of determining LCDIF output bus format and bus flags in
> ->atomic_enable(), do that in ->atomic_check(). This is a
> preparation for the upcoming patch to check consistent bus format
> and bus flags across all first downstream bridges in ->atomic_check().
> New lcdif_crtc_state structure is introduced to cache bus format
> and bus flags states in ->atomic_check() so that they can be read
> in ->atomic_enable().
>
> Signed-off-by: Liu Ying <[email protected]>
> ---
> v2->v3:
> * No change.
>
> v1->v2:
> * Split from patch 2/2 in v1. (Marek, Alexander)
> * Add comment on the 'base' member of lcdif_crtc_state structure to
> note it should always be the first member. (Lothar)
>
> drivers/gpu/drm/mxsfb/lcdif_kms.c | 138 ++++++++++++++++++++++--------
> 1 file changed, 100 insertions(+), 38 deletions(-)
>
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> b/drivers/gpu/drm/mxsfb/lcdif_kms.c index e54200a9fcb9..294cecdf5439 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> +++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
> @@ -30,6 +30,18 @@
> #include "lcdif_drv.h"
> #include "lcdif_regs.h"
>
> +struct lcdif_crtc_state {
> + struct drm_crtc_state base; /* always be the first
member */
Is it strictly necessary that base is the first member? to_lcdif_crtc_state()
should be able to handle any position within the struct. I mean it's sensible
to put it in first place. But the comment somehow bugs me.
> + u32 bus_format;
> + u32 bus_flags;
> +};
> +
> +static inline struct lcdif_crtc_state *
> +to_lcdif_crtc_state(struct drm_crtc_state *s)
> +{
> + return container_of(s, struct lcdif_crtc_state, base);
> +}
> +
> /*
> ---------------------------------------------------------------------------
> -- * CRTC
> */
> @@ -385,48 +397,72 @@ static void lcdif_reset_block(struct lcdif_drm_private
> *lcdif) readl(lcdif->base + LCDC_V8_CTRL);
> }
>
> -static void lcdif_crtc_mode_set_nofb(struct lcdif_drm_private *lcdif,
> - struct drm_plane_state
*plane_state,
> - struct drm_bridge_state
*bridge_state,
> - const u32 bus_format)
> +static void lcdif_crtc_mode_set_nofb(struct drm_crtc_state *crtc_state,
> + struct drm_plane_state
*plane_state)
> {
> - struct drm_device *drm = lcdif->crtc.dev;
> - struct drm_display_mode *m = &lcdif->crtc.state->adjusted_mode;
> - u32 bus_flags = 0;
> -
> - if (lcdif->bridge->timings)
> - bus_flags = lcdif->bridge->timings->input_bus_flags;
> - else if (bridge_state)
> - bus_flags = bridge_state->input_bus_cfg.flags;
> + struct lcdif_crtc_state *lcdif_crtc_state =
> to_lcdif_crtc_state(crtc_state); + struct drm_device *drm =
> crtc_state->crtc->dev;
> + struct lcdif_drm_private *lcdif = to_lcdif_drm_private(drm);
> + struct drm_display_mode *m = &crtc_state->adjusted_mode;
>
> DRM_DEV_DEBUG_DRIVER(drm->dev, "Pixel clock: %dkHz (actual: %dkHz)
\n",
> m->crtc_clock,
> (int)(clk_get_rate(lcdif->clk) / 1000));
> DRM_DEV_DEBUG_DRIVER(drm->dev, "Bridge bus_flags: 0x%08X\n",
> - bus_flags);
> + lcdif_crtc_state->bus_flags);
> DRM_DEV_DEBUG_DRIVER(drm->dev, "Mode flags: 0x%08X\n", m->flags);
>
> /* Mandatory eLCDIF reset as per the Reference Manual */
> lcdif_reset_block(lcdif);
>
> - lcdif_set_formats(lcdif, plane_state, bus_format);
> + lcdif_set_formats(lcdif, plane_state, lcdif_crtc_state->bus_format);
>
> - lcdif_set_mode(lcdif, bus_flags);
> + lcdif_set_mode(lcdif, lcdif_crtc_state->bus_flags);
> }
>
> static int lcdif_crtc_atomic_check(struct drm_crtc *crtc,
> struct drm_atomic_state *state)
> {
> + struct drm_device *drm = crtc->dev;
> + struct lcdif_drm_private *lcdif = to_lcdif_drm_private(drm);
> struct drm_crtc_state *crtc_state =
drm_atomic_get_new_crtc_state(state,
>
crtc);
> + struct lcdif_crtc_state *lcdif_crtc_state =
> to_lcdif_crtc_state(crtc_state); bool has_primary = crtc_state->plane_mask
> &
> drm_plane_mask(crtc->primary);
> + struct drm_bridge_state *bridge_state;
> + struct drm_bridge *bridge = lcdif->bridge;
> + int ret;
>
> /* The primary plane has to be enabled when the CRTC is active. */
> if (crtc_state->active && !has_primary)
> return -EINVAL;
>
> - return drm_atomic_add_affected_planes(state, crtc);
> + ret = drm_atomic_add_affected_planes(state, crtc);
> + if (ret)
> + return ret;
> +
> + bridge_state = drm_atomic_get_new_bridge_state(state, bridge);
> + if (!bridge_state)
> + lcdif_crtc_state->bus_format = MEDIA_BUS_FMT_FIXED;
> + else
> + lcdif_crtc_state->bus_format = bridge_state-
>input_bus_cfg.format;
> +
> + if (lcdif_crtc_state->bus_format == MEDIA_BUS_FMT_FIXED) {
> + dev_warn_once(drm->dev,
> + "Bridge does not provide bus format,
assuming
> MEDIA_BUS_FMT_RGB888_1X24.\n" + "Please fix
bridge driver by
> handling atomic_get_input_bus_fmts.\n"); + lcdif_crtc_state-
>bus_format =
> MEDIA_BUS_FMT_RGB888_1X24;
> + }
> +
> + if (bridge->timings)
> + lcdif_crtc_state->bus_flags = bridge->timings-
>input_bus_flags;
> + else if (bridge_state)
> + lcdif_crtc_state->bus_flags = bridge_state-
>input_bus_cfg.flags;
> + else
> + lcdif_crtc_state->bus_flags = 0;
> +
> + return 0;
> }
>
> static void lcdif_crtc_atomic_flush(struct drm_crtc *crtc,
> @@ -458,35 +494,21 @@ static void lcdif_crtc_atomic_enable(struct drm_crtc
> *crtc, struct drm_atomic_state *state)
> {
> struct lcdif_drm_private *lcdif = to_lcdif_drm_private(crtc->dev);
> - struct drm_plane_state *new_pstate =
drm_atomic_get_new_plane_state(state,
> -
crtc->primary);
> + struct drm_crtc_state *new_crtc_state =
> drm_atomic_get_new_crtc_state(state, crtc); + struct drm_plane_state
> *new_plane_state = drm_atomic_get_new_plane_state(state, +
> crtc->primary);
While the rename to 'new_plane_state' makes sense, this is an unrelated
change.
> struct drm_display_mode *m = &lcdif->crtc.state->adjusted_mode;
> - struct drm_bridge_state *bridge_state = NULL;
> struct drm_device *drm = lcdif->drm;
> - u32 bus_format;
> dma_addr_t paddr;
>
> - bridge_state = drm_atomic_get_new_bridge_state(state, lcdif-
>bridge);
> - if (!bridge_state)
> - bus_format = MEDIA_BUS_FMT_FIXED;
> - else
> - bus_format = bridge_state->input_bus_cfg.format;
> -
> - if (bus_format == MEDIA_BUS_FMT_FIXED) {
> - dev_warn_once(drm->dev,
> - "Bridge does not provide bus format,
assuming
> MEDIA_BUS_FMT_RGB888_1X24.\n" - "Please fix
bridge driver by
> handling atomic_get_input_bus_fmts.\n"); - bus_format =
> MEDIA_BUS_FMT_RGB888_1X24;
> - }
> -
> clk_set_rate(lcdif->clk, m->crtc_clock * 1000);
>
> pm_runtime_get_sync(drm->dev);
>
> - lcdif_crtc_mode_set_nofb(lcdif, new_pstate, bridge_state,
bus_format);
> + lcdif_crtc_mode_set_nofb(new_crtc_state, new_plane_state);
>
> /* Write cur_buf as well to avoid an initial corrupt frame */
> - paddr = drm_fb_dma_get_gem_addr(new_pstate->fb, new_pstate, 0);
> + paddr = drm_fb_dma_get_gem_addr(new_plane_state->fb,
new_plane_state, 0);
> if (paddr) {
> writel(lower_32_bits(paddr),
> lcdif->base + LCDC_V8_CTRLDESCL_LOW0_4);
> @@ -520,6 +542,46 @@ static void lcdif_crtc_atomic_disable(struct drm_crtc
> *crtc, pm_runtime_put_sync(drm->dev);
> }
>
> +static void lcdif_crtc_reset(struct drm_crtc *crtc)
> +{
> + struct lcdif_crtc_state *state;
> +
> + if (crtc->state)
> + __drm_atomic_helper_crtc_destroy_state(crtc->state);
> +
> + kfree(to_lcdif_crtc_state(crtc->state));
Shouldn't this be just
if (crtc->state)
crtc->funcs->atomic_destroy_state(crtc, crtc->state);
similar to what drm_atomic_helper_crtc_reset is doing? This will eventually
call lcdif_crtc_atomic_destroy_state().
> + crtc->state = NULL;
> +
> + state = kzalloc(sizeof(*state), GFP_KERNEL);
> + if (state)
> + __drm_atomic_helper_crtc_reset(crtc, &state->base);
Is there a specific reason to not call this helper when 'state==NULL'?
drm_atomic_helper_crtc_reset() does call this even when passing NULL for
crtc_state.
> +}
> +
> +static struct drm_crtc_state *
> +lcdif_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
> +{
> + struct lcdif_crtc_state *old = to_lcdif_crtc_state(crtc->state);
> + struct lcdif_crtc_state *new;
> +
drm_atomic_helper_crtc_duplicate_state() has a check for
if (WARN_ON(!crtc->state))
return NULL;
Maybe it should be added here as well. But then the call to
to_lcdif_crtc_state() has to be moved down.
Best regards,
Alexander
> + new = kzalloc(sizeof(*new), GFP_KERNEL);
> + if (!new)
> + return NULL;
> +
> + __drm_atomic_helper_crtc_duplicate_state(crtc, &new->base);
> +
> + new->bus_format = old->bus_format;
> + new->bus_flags = old->bus_flags;
> +
> + return &new->base;
> +}
> +
> +static void lcdif_crtc_atomic_destroy_state(struct drm_crtc *crtc,
> + struct drm_crtc_state
*state)
> +{
> + __drm_atomic_helper_crtc_destroy_state(state);
> + kfree(to_lcdif_crtc_state(state));
> +}
> +
> static int lcdif_crtc_enable_vblank(struct drm_crtc *crtc)
> {
> struct lcdif_drm_private *lcdif = to_lcdif_drm_private(crtc->dev);
> @@ -548,12 +610,12 @@ static const struct drm_crtc_helper_funcs
> lcdif_crtc_helper_funcs = { };
>
> static const struct drm_crtc_funcs lcdif_crtc_funcs = {
> - .reset = drm_atomic_helper_crtc_reset,
> + .reset = lcdif_crtc_reset,
> .destroy = drm_crtc_cleanup,
> .set_config = drm_atomic_helper_set_config,
> .page_flip = drm_atomic_helper_page_flip,
> - .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
> - .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
> + .atomic_duplicate_state = lcdif_crtc_atomic_duplicate_state,
> + .atomic_destroy_state = lcdif_crtc_atomic_destroy_state,
> .enable_vblank = lcdif_crtc_enable_vblank,
> .disable_vblank = lcdif_crtc_disable_vblank,
> };
--
TQ-Systems GmbH | M?hlstra?e 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht M?nchen, HRB 105018
Gesch?ftsf?hrer: Detlef Schneider, R?diger Stahl, Stefan Schneider
http://www.tq-group.com/
On Tue, Feb 14, 2023 at 03:12:55PM +0100, Alexander Stein wrote:
> Hi Liu,
>
> thanks for the update.
>
> Am Montag, 13. Februar 2023, 09:56:09 CET schrieb Liu Ying:
> > Instead of determining LCDIF output bus format and bus flags in
> > ->atomic_enable(), do that in ->atomic_check(). This is a
> > preparation for the upcoming patch to check consistent bus format
> > and bus flags across all first downstream bridges in ->atomic_check().
> > New lcdif_crtc_state structure is introduced to cache bus format
> > and bus flags states in ->atomic_check() so that they can be read
> > in ->atomic_enable().
> >
> > Signed-off-by: Liu Ying <[email protected]>
> > ---
> > v2->v3:
> > * No change.
> >
> > v1->v2:
> > * Split from patch 2/2 in v1. (Marek, Alexander)
> > * Add comment on the 'base' member of lcdif_crtc_state structure to
> > note it should always be the first member. (Lothar)
> >
> > drivers/gpu/drm/mxsfb/lcdif_kms.c | 138 ++++++++++++++++++++++--------
> > 1 file changed, 100 insertions(+), 38 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> > b/drivers/gpu/drm/mxsfb/lcdif_kms.c index e54200a9fcb9..294cecdf5439 100644
> > --- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> > +++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
> > @@ -30,6 +30,18 @@
> > #include "lcdif_drv.h"
> > #include "lcdif_regs.h"
> >
> > +struct lcdif_crtc_state {
> > + struct drm_crtc_state base; /* always be the first
> member */
>
> Is it strictly necessary that base is the first member? to_lcdif_crtc_state()
> should be able to handle any position within the struct. I mean it's sensible
> to put it in first place. But the comment somehow bugs me.
NULL pointers is where these things go bad if it't not at
offset 0. Unless you're willing to always handle those
explicitly.
--
Ville Syrj?l?
Intel
On Tue, 2023-02-14 at 15:12 +0100, Alexander Stein wrote:
> Hi Liu,
Hi Alexander,
>
> thanks for the update.
Thanks for your review.
>
> Am Montag, 13. Februar 2023, 09:56:09 CET schrieb Liu Ying:
> > Instead of determining LCDIF output bus format and bus flags in
> > ->atomic_enable(), do that in ->atomic_check(). This is a
> > preparation for the upcoming patch to check consistent bus format
> > and bus flags across all first downstream bridges in
> > ->atomic_check().
> > New lcdif_crtc_state structure is introduced to cache bus format
> > and bus flags states in ->atomic_check() so that they can be read
> > in ->atomic_enable().
> >
> > Signed-off-by: Liu Ying <[email protected]>
> > ---
> > v2->v3:
> > * No change.
> >
> > v1->v2:
> > * Split from patch 2/2 in v1. (Marek, Alexander)
> > * Add comment on the 'base' member of lcdif_crtc_state structure to
> > note it should always be the first member. (Lothar)
> >
> > drivers/gpu/drm/mxsfb/lcdif_kms.c | 138 ++++++++++++++++++++++--
> > ------
> > 1 file changed, 100 insertions(+), 38 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> > b/drivers/gpu/drm/mxsfb/lcdif_kms.c index
> > e54200a9fcb9..294cecdf5439 100644
> > --- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> > +++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
> > @@ -30,6 +30,18 @@
> > #include "lcdif_drv.h"
> > #include "lcdif_regs.h"
> >
> > +struct lcdif_crtc_state {
> > + struct drm_crtc_state base; /* always be the first
>
> member */
>
> Is it strictly necessary that base is the first member?
> to_lcdif_crtc_state()
> should be able to handle any position within the struct. I mean it's
> sensible
> to put it in first place. But the comment somehow bugs me.
The comment was added in v2 to make sure to_lcdif_crtc_state() work ok
when a NULL pointer is handed over to it. The NULL pointer worries
Lothar a bit as we can see Lothar's comment for v1.
>
> > + u32 bus_format;
> > + u32 bus_flags;
> > +};
> > +
> > +static inline struct lcdif_crtc_state *
> > +to_lcdif_crtc_state(struct drm_crtc_state *s)
> > +{
> > + return container_of(s, struct lcdif_crtc_state, base);
> > +}
> > +
> > /*
> > -----------------------------------------------------------------
> > ----------
> > -- * CRTC
> > */
> > @@ -385,48 +397,72 @@ static void lcdif_reset_block(struct
> > lcdif_drm_private
> > *lcdif) readl(lcdif->base + LCDC_V8_CTRL);
> > }
> >
> > -static void lcdif_crtc_mode_set_nofb(struct lcdif_drm_private
> > *lcdif,
> > - struct drm_plane_state
>
> *plane_state,
> > - struct drm_bridge_state
>
> *bridge_state,
> > - const u32 bus_format)
> > +static void lcdif_crtc_mode_set_nofb(struct drm_crtc_state
> > *crtc_state,
> > + struct drm_plane_state
>
> *plane_state)
> > {
> > - struct drm_device *drm = lcdif->crtc.dev;
> > - struct drm_display_mode *m = &lcdif->crtc.state->adjusted_mode;
> > - u32 bus_flags = 0;
> > -
> > - if (lcdif->bridge->timings)
> > - bus_flags = lcdif->bridge->timings->input_bus_flags;
> > - else if (bridge_state)
> > - bus_flags = bridge_state->input_bus_cfg.flags;
> > + struct lcdif_crtc_state *lcdif_crtc_state =
> > to_lcdif_crtc_state(crtc_state); + struct drm_device *drm =
> > crtc_state->crtc->dev;
> > + struct lcdif_drm_private *lcdif = to_lcdif_drm_private(drm);
> > + struct drm_display_mode *m = &crtc_state->adjusted_mode;
> >
> > DRM_DEV_DEBUG_DRIVER(drm->dev, "Pixel clock: %dkHz (actual:
> > %dkHz)
>
> \n",
> > m->crtc_clock,
> > (int)(clk_get_rate(lcdif->clk) / 1000));
> > DRM_DEV_DEBUG_DRIVER(drm->dev, "Bridge bus_flags: 0x%08X\n",
> > - bus_flags);
> > + lcdif_crtc_state->bus_flags);
> > DRM_DEV_DEBUG_DRIVER(drm->dev, "Mode flags: 0x%08X\n", m-
> > >flags);
> >
> > /* Mandatory eLCDIF reset as per the Reference Manual */
> > lcdif_reset_block(lcdif);
> >
> > - lcdif_set_formats(lcdif, plane_state, bus_format);
> > + lcdif_set_formats(lcdif, plane_state, lcdif_crtc_state-
> > >bus_format);
> >
> > - lcdif_set_mode(lcdif, bus_flags);
> > + lcdif_set_mode(lcdif, lcdif_crtc_state->bus_flags);
> > }
> >
> > static int lcdif_crtc_atomic_check(struct drm_crtc *crtc,
> > struct drm_atomic_state *state)
> > {
> > + struct drm_device *drm = crtc->dev;
> > + struct lcdif_drm_private *lcdif = to_lcdif_drm_private(drm);
> > struct drm_crtc_state *crtc_state =
>
> drm_atomic_get_new_crtc_state(state,
> >
>
> crtc);
> > + struct lcdif_crtc_state *lcdif_crtc_state =
> > to_lcdif_crtc_state(crtc_state); bool has_primary = crtc_state-
> > >plane_mask
> > &
> > drm_plane_mask(crtc->primary);
> > + struct drm_bridge_state *bridge_state;
> > + struct drm_bridge *bridge = lcdif->bridge;
> > + int ret;
> >
> > /* The primary plane has to be enabled when the CRTC is active.
> > */
> > if (crtc_state->active && !has_primary)
> > return -EINVAL;
> >
> > - return drm_atomic_add_affected_planes(state, crtc);
> > + ret = drm_atomic_add_affected_planes(state, crtc);
> > + if (ret)
> > + return ret;
> > +
> > + bridge_state = drm_atomic_get_new_bridge_state(state, bridge);
> > + if (!bridge_state)
> > + lcdif_crtc_state->bus_format = MEDIA_BUS_FMT_FIXED;
> > + else
> > + lcdif_crtc_state->bus_format = bridge_state-
> > input_bus_cfg.format;
> > +
> > + if (lcdif_crtc_state->bus_format == MEDIA_BUS_FMT_FIXED) {
> > + dev_warn_once(drm->dev,
> > + "Bridge does not provide bus format,
>
> assuming
> > MEDIA_BUS_FMT_RGB888_1X24.\n" + "Please
> > fix
>
> bridge driver by
> > handling atomic_get_input_bus_fmts.\n"); + lcdif_crtc_stat
> > e-
> > bus_format =
> > MEDIA_BUS_FMT_RGB888_1X24;
> > + }
> > +
> > + if (bridge->timings)
> > + lcdif_crtc_state->bus_flags = bridge->timings-
> > input_bus_flags;
> > + else if (bridge_state)
> > + lcdif_crtc_state->bus_flags = bridge_state-
> > input_bus_cfg.flags;
> > + else
> > + lcdif_crtc_state->bus_flags = 0;
> > +
> > + return 0;
> > }
> >
> > static void lcdif_crtc_atomic_flush(struct drm_crtc *crtc,
> > @@ -458,35 +494,21 @@ static void lcdif_crtc_atomic_enable(struct
> > drm_crtc
> > *crtc, struct drm_atomic_state *state)
> > {
> > struct lcdif_drm_private *lcdif = to_lcdif_drm_private(crtc-
> > >dev);
> > - struct drm_plane_state *new_pstate =
>
> drm_atomic_get_new_plane_state(state,
> > -
>
> crtc->primary);
> > + struct drm_crtc_state *new_crtc_state =
> > drm_atomic_get_new_crtc_state(state, crtc); + struct
> > drm_plane_state
> > *new_plane_state = drm_atomic_get_new_plane_state(state, +
> >
>
>
> > crtc->primary);
>
> While the rename to 'new_plane_state' makes sense, this is an
> unrelated
> change.
I'll use 'new_pstate' and 'new_cstate' in next version.
>
> > struct drm_display_mode *m = &lcdif->crtc.state->adjusted_mode;
> > - struct drm_bridge_state *bridge_state = NULL;
> > struct drm_device *drm = lcdif->drm;
> > - u32 bus_format;
> > dma_addr_t paddr;
> >
> > - bridge_state = drm_atomic_get_new_bridge_state(state, lcdif-
> > bridge);
> > - if (!bridge_state)
> > - bus_format = MEDIA_BUS_FMT_FIXED;
> > - else
> > - bus_format = bridge_state->input_bus_cfg.format;
> > -
> > - if (bus_format == MEDIA_BUS_FMT_FIXED) {
> > - dev_warn_once(drm->dev,
> > - "Bridge does not provide bus format,
>
> assuming
> > MEDIA_BUS_FMT_RGB888_1X24.\n" - "Please
> > fix
>
> bridge driver by
> > handling atomic_get_input_bus_fmts.\n"); - bus_format =
> > MEDIA_BUS_FMT_RGB888_1X24;
> > - }
> > -
> > clk_set_rate(lcdif->clk, m->crtc_clock * 1000);
> >
> > pm_runtime_get_sync(drm->dev);
> >
> > - lcdif_crtc_mode_set_nofb(lcdif, new_pstate, bridge_state,
>
> bus_format);
> > + lcdif_crtc_mode_set_nofb(new_crtc_state, new_plane_state);
> >
> > /* Write cur_buf as well to avoid an initial corrupt frame */
> > - paddr = drm_fb_dma_get_gem_addr(new_pstate->fb, new_pstate, 0);
> > + paddr = drm_fb_dma_get_gem_addr(new_plane_state->fb,
>
> new_plane_state, 0);
> > if (paddr) {
> > writel(lower_32_bits(paddr),
> > lcdif->base + LCDC_V8_CTRLDESCL_LOW0_4);
> > @@ -520,6 +542,46 @@ static void lcdif_crtc_atomic_disable(struct
> > drm_crtc
> > *crtc, pm_runtime_put_sync(drm->dev);
> > }
> >
> > +static void lcdif_crtc_reset(struct drm_crtc *crtc)
> > +{
> > + struct lcdif_crtc_state *state;
> > +
> > + if (crtc->state)
> > + __drm_atomic_helper_crtc_destroy_state(crtc->state);
> > +
> > + kfree(to_lcdif_crtc_state(crtc->state));
>
> Shouldn't this be just
> if (crtc->state)
> crtc->funcs->atomic_destroy_state(crtc, crtc->state);
>
> similar to what drm_atomic_helper_crtc_reset is doing? This will
> eventually
> call lcdif_crtc_atomic_destroy_state().
I think you are right. But, instead of calling crtc->funcs-
>atomic_destroy_state(), I would call lcdif_crtc_atomic_destroy_state()
directly, which looks simpler to me.
>
> > + crtc->state = NULL;
> > +
> > + state = kzalloc(sizeof(*state), GFP_KERNEL);
> > + if (state)
> > + __drm_atomic_helper_crtc_reset(crtc, &state->base);
>
> Is there a specific reason to not call this helper when
> 'state==NULL'?
Yes, when 'state==NULL', &state->base would de-reference a NULL
pointer.
> drm_atomic_helper_crtc_reset() does call this even when passing NULL
> for
> crtc_state.
>
> > +}
> > +
> > +static struct drm_crtc_state *
> > +lcdif_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
> > +{
> > + struct lcdif_crtc_state *old = to_lcdif_crtc_state(crtc-
> > >state);
> > + struct lcdif_crtc_state *new;
> > +
>
> drm_atomic_helper_crtc_duplicate_state() has a check for
> if (WARN_ON(!crtc->state))
> return NULL;
>
> Maybe it should be added here as well. But then the call to
> to_lcdif_crtc_state() has to be moved down.
I'll add the check in next version. But, to_lcdif_crtc_state() doesn't
have to be moved down even if crtc->state is NULL, because 'base' is
the first member of struct lcdif_crtc_state and it's safe.
Regards,
Liu Ying
Hi Liu,
thanks for the update.
Am Montag, 13. Februar 2023, 09:56:07 CET schrieb Liu Ying:
> There is one LCDIF embedded in i.MX93 SoC to connect with
> MIPI DSI controller through LCDIF cross line pattern(controlled
> by mediamix blk-ctrl) or connect with LVDS display bridge(LDB)
> directly or connect with a parallel display through parallel
> display format(also controlled by mediamix blk-ctrl). i.MX93
> LCDIF IP is essentially the same to i.MX8MP LCDIF IP. Add device
> tree binding for i.MX93 LCDIF.
>
> Acked-by: Krzysztof Kozlowski <[email protected]>
> Reviewed-by: Marek Vasut <[email protected]>
> Signed-off-by: Liu Ying <[email protected]>
> ---
> v2->v3:
> * No change.
>
> v1->v2:
> * Add Krzysztof's A-b and Marek's R-b tags on patch 1/6.
>
> Documentation/devicetree/bindings/display/fsl,lcdif.yaml | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/devicetree/bindings/display/fsl,lcdif.yaml
> b/Documentation/devicetree/bindings/display/fsl,lcdif.yaml index
> 75b4efd70ba8..fc11ab5fc465 100644
> --- a/Documentation/devicetree/bindings/display/fsl,lcdif.yaml
> +++ b/Documentation/devicetree/bindings/display/fsl,lcdif.yaml
> @@ -21,6 +21,7 @@ properties:
> - fsl,imx28-lcdif
> - fsl,imx6sx-lcdif
> - fsl,imx8mp-lcdif
> + - fsl,imx93-lcdif
> - items:
> - enum:
> - fsl,imx6sl-lcdif
> @@ -88,7 +89,9 @@ allOf:
> properties:
> compatible:
> contains:
> - const: fsl,imx8mp-lcdif
> + enum:
> + - fsl,imx8mp-lcdif
> + - fsl,imx93-lcdif
> then:
> properties:
> clocks:
> @@ -107,6 +110,7 @@ allOf:
> enum:
> - fsl,imx6sx-lcdif
> - fsl,imx8mp-lcdif
> + - fsl,imx93-lcdif
> then:
> properties:
> clocks:
> @@ -123,6 +127,7 @@ allOf:
> - fsl,imx8mm-lcdif
> - fsl,imx8mn-lcdif
> - fsl,imx8mp-lcdif
> + - fsl,imx93-lcdif
> then:
> required:
> - power-domains
I would have expected that fsl,imx93-lcdif supports up to 3 endpoints (MIPI
DSI, LVDS, and parallel) in a 'ports' subnode. But this binding only supports
a single 'port' sub-node. Also an example for this case might be very helpful.
Best regards,
Alexander
--
TQ-Systems GmbH | M?hlstra?e 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht M?nchen, HRB 105018
Gesch?ftsf?hrer: Detlef Schneider, R?diger Stahl, Stefan Schneider
http://www.tq-group.com/
On Wed, 2023-02-15 at 08:26 +0100, Alexander Stein wrote:
> Hi Liu,
Hi Alexander,
>
> thanks for the update.
Thanks for the review.
>
> Am Montag, 13. Februar 2023, 09:56:07 CET schrieb Liu Ying:
> > There is one LCDIF embedded in i.MX93 SoC to connect with
> > MIPI DSI controller through LCDIF cross line pattern(controlled
> > by mediamix blk-ctrl) or connect with LVDS display bridge(LDB)
> > directly or connect with a parallel display through parallel
> > display format(also controlled by mediamix blk-ctrl). i.MX93
> > LCDIF IP is essentially the same to i.MX8MP LCDIF IP. Add device
> > tree binding for i.MX93 LCDIF.
> >
> > Acked-by: Krzysztof Kozlowski <[email protected]>
> > Reviewed-by: Marek Vasut <[email protected]>
> > Signed-off-by: Liu Ying <[email protected]>
> > ---
> > v2->v3:
> > * No change.
> >
> > v1->v2:
> > * Add Krzysztof's A-b and Marek's R-b tags on patch 1/6.
> >
> > Documentation/devicetree/bindings/display/fsl,lcdif.yaml | 7
> > ++++++-
> > 1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git
> > a/Documentation/devicetree/bindings/display/fsl,lcdif.yaml
> > b/Documentation/devicetree/bindings/display/fsl,lcdif.yaml index
> > 75b4efd70ba8..fc11ab5fc465 100644
> > --- a/Documentation/devicetree/bindings/display/fsl,lcdif.yaml
> > +++ b/Documentation/devicetree/bindings/display/fsl,lcdif.yaml
> > @@ -21,6 +21,7 @@ properties:
> > - fsl,imx28-lcdif
> > - fsl,imx6sx-lcdif
> > - fsl,imx8mp-lcdif
> > + - fsl,imx93-lcdif
> > - items:
> > - enum:
> > - fsl,imx6sl-lcdif
> > @@ -88,7 +89,9 @@ allOf:
> > properties:
> > compatible:
> > contains:
> > - const: fsl,imx8mp-lcdif
> > + enum:
> > + - fsl,imx8mp-lcdif
> > + - fsl,imx93-lcdif
> > then:
> > properties:
> > clocks:
> > @@ -107,6 +110,7 @@ allOf:
> > enum:
> > - fsl,imx6sx-lcdif
> > - fsl,imx8mp-lcdif
> > + - fsl,imx93-lcdif
> > then:
> > properties:
> > clocks:
> > @@ -123,6 +127,7 @@ allOf:
> > - fsl,imx8mm-lcdif
> > - fsl,imx8mn-lcdif
> > - fsl,imx8mp-lcdif
> > + - fsl,imx93-lcdif
> > then:
> > required:
> > - power-domains
>
> I would have expected that fsl,imx93-lcdif supports up to 3 endpoints
> (MIPI
> DSI, LVDS, and parallel) in a 'ports' subnode. But this binding only
> supports
> a single 'port' sub-node. Also an example for this case might be very
> helpful.
The port node allows multiple endpoints(See graph.yaml[1]). It's
enough to use the existing port node instead of using ports node.
For i.MX93 LCDIF, the port node will be something like this:
--------------------8<--------------------------
port {
#address-cells = <1>;
#size-cells = <0>;
lcdif_to_pdfc: endpoint@0 {
reg = <0>;
};
lcdif_to_ldb: endpoint@1 {
reg = <1>;
};
lcdif_to_cross_line_pattern: endpoint@2 {
reg = <2>;
};
};
--------------------8<--------------------------
Looks like it's not necessary to add a specifc example for i.MX93
LCDIF.
[1]
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/graph.yaml#L48
Regards,
Liu Ying
Hi Liu,
thanks for the update.
Am Montag, 13. Februar 2023, 09:56:11 CET schrieb Liu Ying:
> The single LCDIF embedded in i.MX93 SoC may drive multiple displays
> simultaneously. Look at LCDIF output port's remote port parents to
> find all enabled first bridges. Add an encoder for each found bridge
> and attach the bridge to the encoder. This is a preparation for
> adding i.MX93 LCDIF support.
>
> Signed-off-by: Liu Ying <[email protected]>
> ---
> v2->v3:
> * No change.
>
> v1->v2:
> * Split from patch 2/2 in v1. (Marek, Alexander)
> * Drop '!remote ||' from lcdif_attach_bridge(). (Lothar)
> * Drop unneeded 'bridges' member from lcdif_drm_private structure.
>
> drivers/gpu/drm/mxsfb/lcdif_drv.c | 68 +++++++++++++++++++++++++++----
> drivers/gpu/drm/mxsfb/lcdif_drv.h | 4 +-
> drivers/gpu/drm/mxsfb/lcdif_kms.c | 21 ++--------
> 3 files changed, 66 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> b/drivers/gpu/drm/mxsfb/lcdif_drv.c index b5b9a8e273c6..eb6c265fa2fe 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
> @@ -9,13 +9,16 @@
> #include <linux/dma-mapping.h>
> #include <linux/io.h>
> #include <linux/module.h>
> +#include <linux/of.h>
> #include <linux/of_device.h>
> +#include <linux/of_graph.h>
> #include <linux/platform_device.h>
> #include <linux/pm_runtime.h>
>
> #include <drm/drm_atomic_helper.h>
> #include <drm/drm_bridge.h>
> #include <drm/drm_drv.h>
> +#include <drm/drm_encoder.h>
> #include <drm/drm_fbdev_generic.h>
> #include <drm/drm_gem_dma_helper.h>
> #include <drm/drm_gem_framebuffer_helper.h>
> @@ -38,19 +41,68 @@ static const struct drm_mode_config_helper_funcs
> lcdif_mode_config_helpers = { .atomic_commit_tail =
> drm_atomic_helper_commit_tail_rpm,
> };
>
> +static const struct drm_encoder_funcs lcdif_encoder_funcs = {
> + .destroy = drm_encoder_cleanup,
> +};
> +
> static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
> {
> - struct drm_device *drm = lcdif->drm;
> + struct device *dev = lcdif->drm->dev;
> + struct device_node *ep;
> struct drm_bridge *bridge;
> int ret;
>
> - bridge = devm_drm_of_get_bridge(drm->dev, drm->dev->of_node, 0, 0);
> - if (IS_ERR(bridge))
> - return PTR_ERR(bridge);
> -
> - ret = drm_bridge_attach(&lcdif->encoder, bridge, NULL, 0);
> - if (ret)
> - return dev_err_probe(drm->dev, ret, "Failed to attach
bridge\n");
> + for_each_endpoint_of_node(dev->of_node, ep) {
> + struct device_node *remote;
> + struct of_endpoint of_ep;
> + struct drm_encoder *encoder;
> +
> + remote = of_graph_get_remote_port_parent(ep);
Is it possible for remote to be NULL?
> + if (!of_device_is_available(remote)) {
> + of_node_put(remote);
> + continue;
> + }
> + of_node_put(remote);
> +
> + ret = of_graph_parse_endpoint(ep, &of_ep);
> + if (ret < 0) {
> + dev_err(dev, "Failed to parse endpoint %pOF\n",
ep);
> + of_node_put(ep);
> + return ret;
> + }
> +
> + if (of_ep.id >= MAX_DISPLAYS) {
> + dev_warn(dev, "invalid endpoint id %u\n",
of_ep.id);
I would write
dev_warn(dev, "ignoring invalid endpoint id %u\n", of_ep.id);
just because the parsing continues but this one is skipped.
> + continue;
> + }
> +
> + bridge = devm_drm_of_get_bridge(dev, dev->of_node, 0,
of_ep.id);
> + if (IS_ERR(bridge)) {
> + of_node_put(ep);
> + return dev_err_probe(dev, PTR_ERR(bridge),
> + "Failed to get bridge
for endpoint%u\n",
> + of_ep.id);
> + }
> +
> + encoder = &lcdif->encoders[of_ep.id];
> + encoder->possible_crtcs = drm_crtc_mask(&lcdif->crtc);
> + ret = drm_encoder_init(lcdif->drm, encoder,
&lcdif_encoder_funcs,
> + DRM_MODE_ENCODER_NONE, NULL);
> + if (ret) {
> + dev_err(dev, "Failed to initialize encoder for
endpoint%u: %d\n",
> + of_ep.id, ret);
> + of_node_put(ep);
> + return ret;
> + }
> +
> + ret = drm_bridge_attach(encoder, bridge, NULL, 0);
> + if (ret) {
> + of_node_put(ep);
> + return dev_err_probe(dev, ret,
> + "Failed to attach
bridge for endpoint%u\n",
> + of_ep.id);
> + }
Admittedly I'm not used to the drm API, but do we need to some manual cleanup/
revert if some endpoints is e.g. deferred, but previous endpoints already have
been successfully added? e.g. endpoint 0 is added, but adding endpoint 1
fails.
Best regards,
Alexander
> + }
>
> return 0;
> }
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.h
> b/drivers/gpu/drm/mxsfb/lcdif_drv.h index aa6d099a1897..c7400bd9bbd9 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_drv.h
> +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.h
> @@ -14,6 +14,8 @@
> #include <drm/drm_encoder.h>
> #include <drm/drm_plane.h>
>
> +#define MAX_DISPLAYS 3
> +
> struct clk;
>
> struct lcdif_drm_private {
> @@ -30,7 +32,7 @@ struct lcdif_drm_private {
> /* i.MXRT does support overlay planes, add them here. */
> } planes;
> struct drm_crtc crtc;
> - struct drm_encoder encoder;
> + struct drm_encoder encoders[MAX_DISPLAYS];
> };
>
> static inline struct lcdif_drm_private *
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> b/drivers/gpu/drm/mxsfb/lcdif_kms.c index 4ea3d2b2cf61..5f34d01e133e 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> +++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
> @@ -654,14 +654,6 @@ static const struct drm_crtc_funcs lcdif_crtc_funcs = {
> .disable_vblank = lcdif_crtc_disable_vblank,
> };
>
> -/*
> ---------------------------------------------------------------------------
> -- - * Encoder
> - */
> -
> -static const struct drm_encoder_funcs lcdif_encoder_funcs = {
> - .destroy = drm_encoder_cleanup,
> -};
> -
> /*
> ---------------------------------------------------------------------------
> -- * Planes
> */
> @@ -754,7 +746,6 @@ int lcdif_kms_init(struct lcdif_drm_private *lcdif)
> BIT(DRM_COLOR_YCBCR_BT2020);
> const u32 supported_ranges = BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
> BIT(DRM_COLOR_YCBCR_FULL_RANGE);
> - struct drm_encoder *encoder = &lcdif->encoder;
> struct drm_crtc *crtc = &lcdif->crtc;
> int ret;
>
> @@ -778,13 +769,7 @@ int lcdif_kms_init(struct lcdif_drm_private *lcdif)
> return ret;
>
> drm_crtc_helper_add(crtc, &lcdif_crtc_helper_funcs);
> - ret = drm_crtc_init_with_planes(lcdif->drm, crtc,
> - &lcdif->planes.primary,
NULL,
> - &lcdif_crtc_funcs, NULL);
> - if (ret)
> - return ret;
> -
> - encoder->possible_crtcs = drm_crtc_mask(crtc);
> - return drm_encoder_init(lcdif->drm, encoder, &lcdif_encoder_funcs,
> - DRM_MODE_ENCODER_NONE, NULL);
> + return drm_crtc_init_with_planes(lcdif->drm, crtc,
> + &lcdif->planes.primary,
NULL,
> + &lcdif_crtc_funcs, NULL);
> }
--
TQ-Systems GmbH | M?hlstra?e 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht M?nchen, HRB 105018
Gesch?ftsf?hrer: Detlef Schneider, R?diger Stahl, Stefan Schneider
http://www.tq-group.com/
Hi Liu,
thanks for the update.
Am Montag, 13. Februar 2023, 09:56:12 CET schrieb Liu Ying:
> With all previous preparations done to make it possible for the
> single LCDIF embedded in i.MX93 SoC to drive multiple displays
> simultaneously, add i.MX93 LCDIF compatible string as the last
> step of adding i.MX93 LCDIF support.
>
> Signed-off-by: Liu Ying <[email protected]>
> ---
> v2->v3:
> * Fix a trivial typo in commit message.
>
> v1->v2:
> * Split from patch 2/2 in v1. (Marek, Alexander)
>
> drivers/gpu/drm/mxsfb/lcdif_drv.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> b/drivers/gpu/drm/mxsfb/lcdif_drv.c index eb6c265fa2fe..48c43b273a4a 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
> @@ -249,6 +249,7 @@ static const struct drm_driver lcdif_driver = {
>
> static const struct of_device_id lcdif_dt_ids[] = {
> { .compatible = "fsl,imx8mp-lcdif" },
> + { .compatible = "fsl,imx93-lcdif" },
> { /* sentinel */ }
> };
> MODULE_DEVICE_TABLE(of, lcdif_dt_ids);
Reviewed-by: Alexander Stein <[email protected]>
--
TQ-Systems GmbH | M?hlstra?e 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht M?nchen, HRB 105018
Gesch?ftsf?hrer: Detlef Schneider, R?diger Stahl, Stefan Schneider
http://www.tq-group.com/
Hi Liu,
thanks for the update.
Am Montag, 13. Februar 2023, 09:56:10 CET schrieb Liu Ying:
> The single LCDIF embedded in i.MX93 SoC may drive multiple displays
> simultaneously. Check bus format and flags across first bridges in
> ->atomic_check() to ensure they are consistent. This is a preparation
> for adding i.MX93 LCDIF support.
>
> Signed-off-by: Liu Ying <[email protected]>
> ---
> v2->v3:
> * No change.
>
> v1->v2:
> * Split from patch 2/2 in v1. (Marek, Alexander)
> * Drop a comment about bridge input bus format from
> lcdif_crtc_atomic_check().
>
> drivers/gpu/drm/mxsfb/lcdif_drv.c | 2 -
> drivers/gpu/drm/mxsfb/lcdif_drv.h | 1 -
> drivers/gpu/drm/mxsfb/lcdif_kms.c | 76 ++++++++++++++++++++++---------
> 3 files changed, 55 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> b/drivers/gpu/drm/mxsfb/lcdif_drv.c index cc2ceb301b96..b5b9a8e273c6 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
> @@ -52,8 +52,6 @@ static int lcdif_attach_bridge(struct lcdif_drm_private
> *lcdif) if (ret)
> return dev_err_probe(drm->dev, ret, "Failed to attach
bridge\n");
>
> - lcdif->bridge = bridge;
> -
> return 0;
> }
>
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.h
> b/drivers/gpu/drm/mxsfb/lcdif_drv.h index 6cdba6e20c02..aa6d099a1897 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_drv.h
> +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.h
> @@ -31,7 +31,6 @@ struct lcdif_drm_private {
> } planes;
> struct drm_crtc crtc;
> struct drm_encoder encoder;
> - struct drm_bridge *bridge;
> };
>
> static inline struct lcdif_drm_private *
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> b/drivers/gpu/drm/mxsfb/lcdif_kms.c index 294cecdf5439..4ea3d2b2cf61 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> +++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
> @@ -17,6 +17,7 @@
> #include <drm/drm_atomic_helper.h>
> #include <drm/drm_bridge.h>
> #include <drm/drm_color_mgmt.h>
> +#include <drm/drm_connector.h>
> #include <drm/drm_crtc.h>
> #include <drm/drm_encoder.h>
> #include <drm/drm_fb_dma_helper.h>
> @@ -424,15 +425,19 @@ static int lcdif_crtc_atomic_check(struct drm_crtc
> *crtc, struct drm_atomic_state *state)
> {
> struct drm_device *drm = crtc->dev;
> - struct lcdif_drm_private *lcdif = to_lcdif_drm_private(drm);
> struct drm_crtc_state *crtc_state =
drm_atomic_get_new_crtc_state(state,
>
crtc);
> struct lcdif_crtc_state *lcdif_crtc_state =
> to_lcdif_crtc_state(crtc_state); bool has_primary = crtc_state->plane_mask
> &
> drm_plane_mask(crtc->primary);
> + struct drm_connector_state *connector_state;
> + struct drm_connector *connector;
> + struct drm_encoder *encoder;
> struct drm_bridge_state *bridge_state;
> - struct drm_bridge *bridge = lcdif->bridge;
> - int ret;
> + struct drm_bridge *bridge;
> + u32 bus_format, bus_flags;
> + bool format_set = false, flags_set = false;
> + int ret, i;
>
> /* The primary plane has to be enabled when the CRTC is active. */
> if (crtc_state->active && !has_primary)
> @@ -442,26 +447,55 @@ static int lcdif_crtc_atomic_check(struct drm_crtc
> *crtc, if (ret)
> return ret;
>
> - bridge_state = drm_atomic_get_new_bridge_state(state, bridge);
> - if (!bridge_state)
> - lcdif_crtc_state->bus_format = MEDIA_BUS_FMT_FIXED;
> - else
> - lcdif_crtc_state->bus_format = bridge_state-
>input_bus_cfg.format;
> -
> - if (lcdif_crtc_state->bus_format == MEDIA_BUS_FMT_FIXED) {
> - dev_warn_once(drm->dev,
> - "Bridge does not provide bus format,
assuming
> MEDIA_BUS_FMT_RGB888_1X24.\n" - "Please fix
bridge driver by
> handling atomic_get_input_bus_fmts.\n"); - lcdif_crtc_state-
>bus_format =
> MEDIA_BUS_FMT_RGB888_1X24;
> + /* Try to find consistent bus format and flags across first bridges.
*/
> + for_each_new_connector_in_state(state, connector, connector_state,
i) {
> + if (!connector_state->crtc)
> + continue;
> +
> + encoder = connector_state->best_encoder;
> +
> + bridge = drm_bridge_chain_get_first_bridge(encoder);
> + if (!bridge)
> + continue;
> +
> + bridge_state = drm_atomic_get_new_bridge_state(state,
bridge);
> + if (!bridge_state)
> + bus_format = MEDIA_BUS_FMT_FIXED;
> + else
> + bus_format = bridge_state->input_bus_cfg.format;
> +
> + if (bus_format == MEDIA_BUS_FMT_FIXED) {
> + dev_warn(drm->dev,
> + "[ENCODER:%d:%s]'s bridge does not
provide bus format, assuming
> MEDIA_BUS_FMT_RGB888_1X24.\n" +
"Please fix bridge driver by handling
> atomic_get_input_bus_fmts.\n", +
encoder->base.id, encoder->name);
> + bus_format = MEDIA_BUS_FMT_RGB888_1X24;
> + }
> +
> + if (!format_set) {
> + lcdif_crtc_state->bus_format = bus_format;
> + format_set = true;
> + } else if (lcdif_crtc_state->bus_format != bus_format) {
> + DRM_DEV_DEBUG_DRIVER(drm->dev, "inconsistent bus
format\n");
Is there another way to know the actual reason the atomic_check fails? Maybe
this is worthy to be an error message instead.
Best regards,
Alexander
> + return -EINVAL;
> + }
> +
> + if (bridge->timings)
> + bus_flags = bridge->timings->input_bus_flags;
> + else if (bridge_state)
> + bus_flags = bridge_state->input_bus_cfg.flags;
> + else
> + bus_flags = 0;
> +
> + if (!flags_set) {
> + lcdif_crtc_state->bus_flags = bus_flags;
> + flags_set = true;
> + } else if (lcdif_crtc_state->bus_flags != bus_flags) {
> + DRM_DEV_DEBUG_DRIVER(drm->dev, "inconsistent bus
flags\n");
> + return -EINVAL;
> + }
> }
>
> - if (bridge->timings)
> - lcdif_crtc_state->bus_flags = bridge->timings-
>input_bus_flags;
> - else if (bridge_state)
> - lcdif_crtc_state->bus_flags = bridge_state-
>input_bus_cfg.flags;
> - else
> - lcdif_crtc_state->bus_flags = 0;
> -
> return 0;
> }
--
TQ-Systems GmbH | M?hlstra?e 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht M?nchen, HRB 105018
Gesch?ftsf?hrer: Detlef Schneider, R?diger Stahl, Stefan Schneider
http://www.tq-group.com/
Hi Liu,
Am Mittwoch, 15. Februar 2023, 04:44:15 CET schrieb Liu Ying:
> On Tue, 2023-02-14 at 15:12 +0100, Alexander Stein wrote:
> > Hi Liu,
>
> Hi Alexander,
>
> > thanks for the update.
>
> Thanks for your review.
>
> > Am Montag, 13. Februar 2023, 09:56:09 CET schrieb Liu Ying:
> > > Instead of determining LCDIF output bus format and bus flags in
> > > ->atomic_enable(), do that in ->atomic_check(). This is a
> > > preparation for the upcoming patch to check consistent bus format
> > > and bus flags across all first downstream bridges in
> > > ->atomic_check().
> > > New lcdif_crtc_state structure is introduced to cache bus format
> > > and bus flags states in ->atomic_check() so that they can be read
> > > in ->atomic_enable().
> > >
> > > Signed-off-by: Liu Ying <[email protected]>
> > > ---
> > > v2->v3:
> > > * No change.
> > >
> > > v1->v2:
> > > * Split from patch 2/2 in v1. (Marek, Alexander)
> > > * Add comment on the 'base' member of lcdif_crtc_state structure to
> > >
> > > note it should always be the first member. (Lothar)
> > >
> > > drivers/gpu/drm/mxsfb/lcdif_kms.c | 138 ++++++++++++++++++++++--
> > >
> > > ------
> > >
> > > 1 file changed, 100 insertions(+), 38 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> > > b/drivers/gpu/drm/mxsfb/lcdif_kms.c index
> > > e54200a9fcb9..294cecdf5439 100644
> > > --- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> > > +++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
> > > @@ -30,6 +30,18 @@
> > >
> > > #include "lcdif_drv.h"
> > > #include "lcdif_regs.h"
> > >
> > > +struct lcdif_crtc_state {
> > > + struct drm_crtc_state base; /* always be the first
> >
> > member */
> >
> > Is it strictly necessary that base is the first member?
> > to_lcdif_crtc_state()
> > should be able to handle any position within the struct. I mean it's
> > sensible
> > to put it in first place. But the comment somehow bugs me.
>
> The comment was added in v2 to make sure to_lcdif_crtc_state() work ok
> when a NULL pointer is handed over to it. The NULL pointer worries
> Lothar a bit as we can see Lothar's comment for v1.
Nice, this makes totally sense. I was just curious about the reasoning.
>
> > > + u32 bus_format;
> > > + u32 bus_flags;
> > > +};
> > > +
> > > +static inline struct lcdif_crtc_state *
> > > +to_lcdif_crtc_state(struct drm_crtc_state *s)
> > > +{
> > > + return container_of(s, struct lcdif_crtc_state, base);
> > > +}
> > > +
> > >
> > > /*
> > >
> > > -----------------------------------------------------------------
> > > ----------
> > > -- * CRTC
> > >
> > > */
> > >
> > > @@ -385,48 +397,72 @@ static void lcdif_reset_block(struct
> > > lcdif_drm_private
> > > *lcdif) readl(lcdif->base + LCDC_V8_CTRL);
> > >
> > > }
> > >
> > > -static void lcdif_crtc_mode_set_nofb(struct lcdif_drm_private
> > > *lcdif,
> > > - struct drm_plane_state
> >
> > *plane_state,
> >
> > > - struct drm_bridge_state
> >
> > *bridge_state,
> >
> > > - const u32 bus_format)
> > > +static void lcdif_crtc_mode_set_nofb(struct drm_crtc_state
> > > *crtc_state,
> > > + struct drm_plane_state
> >
> > *plane_state)
> >
> > > {
> > >
> > > - struct drm_device *drm = lcdif->crtc.dev;
> > > - struct drm_display_mode *m = &lcdif->crtc.state->adjusted_mode;
> > > - u32 bus_flags = 0;
> > > -
> > > - if (lcdif->bridge->timings)
> > > - bus_flags = lcdif->bridge->timings->input_bus_flags;
> > > - else if (bridge_state)
> > > - bus_flags = bridge_state->input_bus_cfg.flags;
> > > + struct lcdif_crtc_state *lcdif_crtc_state =
> > > to_lcdif_crtc_state(crtc_state); + struct drm_device *drm =
> > > crtc_state->crtc->dev;
> > > + struct lcdif_drm_private *lcdif = to_lcdif_drm_private(drm);
> > > + struct drm_display_mode *m = &crtc_state->adjusted_mode;
> > >
> > > DRM_DEV_DEBUG_DRIVER(drm->dev, "Pixel clock: %dkHz (actual:
> > > %dkHz)
> >
> > \n",
> >
> > > m->crtc_clock,
> > > (int)(clk_get_rate(lcdif->clk) / 1000));
> > >
> > > DRM_DEV_DEBUG_DRIVER(drm->dev, "Bridge bus_flags: 0x%08X\n",
> > >
> > > - bus_flags);
> > > + lcdif_crtc_state->bus_flags);
> > >
> > > DRM_DEV_DEBUG_DRIVER(drm->dev, "Mode flags: 0x%08X\n", m-
> > > >
> > > >flags);
> > > >
> > > /* Mandatory eLCDIF reset as per the Reference Manual */
> > > lcdif_reset_block(lcdif);
> > >
> > > - lcdif_set_formats(lcdif, plane_state, bus_format);
> > > + lcdif_set_formats(lcdif, plane_state, lcdif_crtc_state-
> > >
> > > >bus_format);
> > >
> > > - lcdif_set_mode(lcdif, bus_flags);
> > > + lcdif_set_mode(lcdif, lcdif_crtc_state->bus_flags);
> > >
> > > }
> > >
> > > static int lcdif_crtc_atomic_check(struct drm_crtc *crtc,
> > >
> > > struct drm_atomic_state *state)
> > >
> > > {
> > >
> > > + struct drm_device *drm = crtc->dev;
> > > + struct lcdif_drm_private *lcdif = to_lcdif_drm_private(drm);
> > >
> > > struct drm_crtc_state *crtc_state =
> >
> > drm_atomic_get_new_crtc_state(state,
> >
> > crtc);
> > >
> > > + struct lcdif_crtc_state *lcdif_crtc_state =
> > > to_lcdif_crtc_state(crtc_state); bool has_primary = crtc_state-
> > >
> > > >plane_mask
> > >
> > > &
> > >
> > > drm_plane_mask(crtc->primary);
> > >
> > > + struct drm_bridge_state *bridge_state;
> > > + struct drm_bridge *bridge = lcdif->bridge;
> > > + int ret;
> > >
> > > /* The primary plane has to be enabled when the CRTC is active.
> > >
> > > */
> > >
> > > if (crtc_state->active && !has_primary)
> > >
> > > return -EINVAL;
> > >
> > > - return drm_atomic_add_affected_planes(state, crtc);
> > > + ret = drm_atomic_add_affected_planes(state, crtc);
> > > + if (ret)
> > > + return ret;
> > > +
> > > + bridge_state = drm_atomic_get_new_bridge_state(state, bridge);
> > > + if (!bridge_state)
> > > + lcdif_crtc_state->bus_format = MEDIA_BUS_FMT_FIXED;
> > > + else
> > > + lcdif_crtc_state->bus_format = bridge_state-
> > > input_bus_cfg.format;
> > > +
> > > + if (lcdif_crtc_state->bus_format == MEDIA_BUS_FMT_FIXED) {
> > > + dev_warn_once(drm->dev,
> > > + "Bridge does not provide bus format,
> >
> > assuming
> >
> > > MEDIA_BUS_FMT_RGB888_1X24.\n" + "Please
> > > fix
> >
> > bridge driver by
> >
> > > handling atomic_get_input_bus_fmts.\n"); + lcdif_crtc_stat
> > > e-
> > > bus_format =
> > > MEDIA_BUS_FMT_RGB888_1X24;
> > > + }
> > > +
> > > + if (bridge->timings)
> > > + lcdif_crtc_state->bus_flags = bridge->timings-
> > > input_bus_flags;
> > > + else if (bridge_state)
> > > + lcdif_crtc_state->bus_flags = bridge_state-
> > > input_bus_cfg.flags;
> > > + else
> > > + lcdif_crtc_state->bus_flags = 0;
> > > +
> > > + return 0;
> > >
> > > }
> > >
> > > static void lcdif_crtc_atomic_flush(struct drm_crtc *crtc,
> > >
> > > @@ -458,35 +494,21 @@ static void lcdif_crtc_atomic_enable(struct
> > > drm_crtc
> > > *crtc, struct drm_atomic_state *state)
> > >
> > > {
> > >
> > > struct lcdif_drm_private *lcdif = to_lcdif_drm_private(crtc-
> > > >
> > > >dev);
> > >
> > > - struct drm_plane_state *new_pstate =
> >
> > drm_atomic_get_new_plane_state(state,
> >
> > > -
> > >
> > crtc->primary);
> > >
> > > + struct drm_crtc_state *new_crtc_state =
> > > drm_atomic_get_new_crtc_state(state, crtc); + struct
> > > drm_plane_state
> > > *new_plane_state = drm_atomic_get_new_plane_state(state, +
> > >
> > >
> > >
> > > crtc->primary);
> >
> > While the rename to 'new_plane_state' makes sense, this is an
> > unrelated
> > change.
>
> I'll use 'new_pstate' and 'new_cstate' in next version.
You can do a rename, but I would rather put that into a dedicated commit. Up
to you.
> > > struct drm_display_mode *m = &lcdif->crtc.state->adjusted_mode;
> > >
> > > - struct drm_bridge_state *bridge_state = NULL;
> > >
> > > struct drm_device *drm = lcdif->drm;
> > >
> > > - u32 bus_format;
> > >
> > > dma_addr_t paddr;
> > >
> > > - bridge_state = drm_atomic_get_new_bridge_state(state, lcdif-
> > > bridge);
> > > - if (!bridge_state)
> > > - bus_format = MEDIA_BUS_FMT_FIXED;
> > > - else
> > > - bus_format = bridge_state->input_bus_cfg.format;
> > > -
> > > - if (bus_format == MEDIA_BUS_FMT_FIXED) {
> > > - dev_warn_once(drm->dev,
> > > - "Bridge does not provide bus format,
> >
> > assuming
> >
> > > MEDIA_BUS_FMT_RGB888_1X24.\n" - "Please
> > > fix
> >
> > bridge driver by
> >
> > > handling atomic_get_input_bus_fmts.\n"); - bus_format =
> > > MEDIA_BUS_FMT_RGB888_1X24;
> > > - }
> > > -
> > >
> > > clk_set_rate(lcdif->clk, m->crtc_clock * 1000);
> > >
> > > pm_runtime_get_sync(drm->dev);
> > >
> > > - lcdif_crtc_mode_set_nofb(lcdif, new_pstate, bridge_state,
> >
> > bus_format);
> >
> > > + lcdif_crtc_mode_set_nofb(new_crtc_state, new_plane_state);
> > >
> > > /* Write cur_buf as well to avoid an initial corrupt frame */
> > >
> > > - paddr = drm_fb_dma_get_gem_addr(new_pstate->fb, new_pstate, 0);
> > > + paddr = drm_fb_dma_get_gem_addr(new_plane_state->fb,
> >
> > new_plane_state, 0);
> >
> > > if (paddr) {
> > >
> > > writel(lower_32_bits(paddr),
> > >
> > > lcdif->base + LCDC_V8_CTRLDESCL_LOW0_4);
> > >
> > > @@ -520,6 +542,46 @@ static void lcdif_crtc_atomic_disable(struct
> > > drm_crtc
> > > *crtc, pm_runtime_put_sync(drm->dev);
> > >
> > > }
> > >
> > > +static void lcdif_crtc_reset(struct drm_crtc *crtc)
> > > +{
> > > + struct lcdif_crtc_state *state;
> > > +
> > > + if (crtc->state)
> > > + __drm_atomic_helper_crtc_destroy_state(crtc->state);
> > > +
> > > + kfree(to_lcdif_crtc_state(crtc->state));
> >
> > Shouldn't this be just
> > if (crtc->state)
> >
> > crtc->funcs->atomic_destroy_state(crtc, crtc->state);
> >
> > similar to what drm_atomic_helper_crtc_reset is doing? This will
> > eventually
> > call lcdif_crtc_atomic_destroy_state().
>
> I think you are right. But, instead of calling crtc->funcs-
>
> >atomic_destroy_state(), I would call lcdif_crtc_atomic_destroy_state()
>
> directly, which looks simpler to me.
Agreed, both ways have their advantages. I tried to match you changes to the
previously used helper functions.
>
> > > + crtc->state = NULL;
> > > +
> > > + state = kzalloc(sizeof(*state), GFP_KERNEL);
> > > + if (state)
> > > + __drm_atomic_helper_crtc_reset(crtc, &state->base);
> >
> > Is there a specific reason to not call this helper when
> > 'state==NULL'?
>
> Yes, when 'state==NULL', &state->base would de-reference a NULL
> pointer.
Oh, that's for sure. It was late :)
>
> > drm_atomic_helper_crtc_reset() does call this even when passing NULL
> > for
> > crtc_state.
> >
> > > +}
> > > +
> > > +static struct drm_crtc_state *
> > > +lcdif_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
> > > +{
> > > + struct lcdif_crtc_state *old = to_lcdif_crtc_state(crtc-
> > >
> > > >state);
> > >
> > > + struct lcdif_crtc_state *new;
> > > +
> >
> > drm_atomic_helper_crtc_duplicate_state() has a check for
> > if (WARN_ON(!crtc->state))
> >
> > return NULL;
> >
> > Maybe it should be added here as well. But then the call to
> > to_lcdif_crtc_state() has to be moved down.
>
> I'll add the check in next version. But, to_lcdif_crtc_state() doesn't
> have to be moved down even if crtc->state is NULL, because 'base' is
> the first member of struct lcdif_crtc_state and it's safe.
Sounds reasonable. Thanks
> Regards,
> Liu Ying
Best regards,
Alexander
--
TQ-Systems GmbH | M?hlstra?e 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht M?nchen, HRB 105018
Gesch?ftsf?hrer: Detlef Schneider, R?diger Stahl, Stefan Schneider
http://www.tq-group.com/
On Wed, 2023-02-15 at 08:55 +0100, Alexander Stein wrote:
> Hi Liu,
Hi Alexander,
>
> thanks for the update.
Thanks for the review.
>
> Am Montag, 13. Februar 2023, 09:56:10 CET schrieb Liu Ying:
> > The single LCDIF embedded in i.MX93 SoC may drive multiple displays
> > simultaneously. Check bus format and flags across first bridges in
> > ->atomic_check() to ensure they are consistent. This is a
> > preparation
> > for adding i.MX93 LCDIF support.
> >
> > Signed-off-by: Liu Ying <[email protected]>
> > ---
> > v2->v3:
> > * No change.
> >
> > v1->v2:
> > * Split from patch 2/2 in v1. (Marek, Alexander)
> > * Drop a comment about bridge input bus format from
> > lcdif_crtc_atomic_check().
> >
> > drivers/gpu/drm/mxsfb/lcdif_drv.c | 2 -
> > drivers/gpu/drm/mxsfb/lcdif_drv.h | 1 -
> > drivers/gpu/drm/mxsfb/lcdif_kms.c | 76 ++++++++++++++++++++++-----
> > ----
> > 3 files changed, 55 insertions(+), 24 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> > b/drivers/gpu/drm/mxsfb/lcdif_drv.c index
> > cc2ceb301b96..b5b9a8e273c6 100644
> > --- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> > +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
> > @@ -52,8 +52,6 @@ static int lcdif_attach_bridge(struct
> > lcdif_drm_private
> > *lcdif) if (ret)
> > return dev_err_probe(drm->dev, ret, "Failed to attach
>
> bridge\n");
> >
> > - lcdif->bridge = bridge;
> > -
> > return 0;
> > }
> >
> > diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.h
> > b/drivers/gpu/drm/mxsfb/lcdif_drv.h index
> > 6cdba6e20c02..aa6d099a1897 100644
> > --- a/drivers/gpu/drm/mxsfb/lcdif_drv.h
> > +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.h
> > @@ -31,7 +31,6 @@ struct lcdif_drm_private {
> > } planes;
> > struct drm_crtc crtc;
> > struct drm_encoder encoder;
> > - struct drm_bridge *bridge;
> > };
> >
> > static inline struct lcdif_drm_private *
> > diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> > b/drivers/gpu/drm/mxsfb/lcdif_kms.c index
> > 294cecdf5439..4ea3d2b2cf61 100644
> > --- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
> > +++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
> > @@ -17,6 +17,7 @@
> > #include <drm/drm_atomic_helper.h>
> > #include <drm/drm_bridge.h>
> > #include <drm/drm_color_mgmt.h>
> > +#include <drm/drm_connector.h>
> > #include <drm/drm_crtc.h>
> > #include <drm/drm_encoder.h>
> > #include <drm/drm_fb_dma_helper.h>
> > @@ -424,15 +425,19 @@ static int lcdif_crtc_atomic_check(struct
> > drm_crtc
> > *crtc, struct drm_atomic_state *state)
> > {
> > struct drm_device *drm = crtc->dev;
> > - struct lcdif_drm_private *lcdif = to_lcdif_drm_private(drm);
> > struct drm_crtc_state *crtc_state =
>
> drm_atomic_get_new_crtc_state(state,
> >
>
> crtc);
> > struct lcdif_crtc_state *lcdif_crtc_state =
> > to_lcdif_crtc_state(crtc_state); bool has_primary = crtc_state-
> > >plane_mask
> > &
> > drm_plane_mask(crtc->primary);
> > + struct drm_connector_state *connector_state;
> > + struct drm_connector *connector;
> > + struct drm_encoder *encoder;
> > struct drm_bridge_state *bridge_state;
> > - struct drm_bridge *bridge = lcdif->bridge;
> > - int ret;
> > + struct drm_bridge *bridge;
> > + u32 bus_format, bus_flags;
> > + bool format_set = false, flags_set = false;
> > + int ret, i;
> >
> > /* The primary plane has to be enabled when the CRTC is active.
> > */
> > if (crtc_state->active && !has_primary)
> > @@ -442,26 +447,55 @@ static int lcdif_crtc_atomic_check(struct
> > drm_crtc
> > *crtc, if (ret)
> > return ret;
> >
> > - bridge_state = drm_atomic_get_new_bridge_state(state, bridge);
> > - if (!bridge_state)
> > - lcdif_crtc_state->bus_format = MEDIA_BUS_FMT_FIXED;
> > - else
> > - lcdif_crtc_state->bus_format = bridge_state-
> > input_bus_cfg.format;
> > -
> > - if (lcdif_crtc_state->bus_format == MEDIA_BUS_FMT_FIXED) {
> > - dev_warn_once(drm->dev,
> > - "Bridge does not provide bus format,
>
> assuming
> > MEDIA_BUS_FMT_RGB888_1X24.\n" - "Please
> > fix
>
> bridge driver by
> > handling atomic_get_input_bus_fmts.\n"); - lcdif_crtc_stat
> > e-
> > bus_format =
> > MEDIA_BUS_FMT_RGB888_1X24;
> > + /* Try to find consistent bus format and flags across first
> > bridges.
>
> */
> > + for_each_new_connector_in_state(state, connector,
> > connector_state,
>
> i) {
> > + if (!connector_state->crtc)
> > + continue;
> > +
> > + encoder = connector_state->best_encoder;
> > +
> > + bridge = drm_bridge_chain_get_first_bridge(encoder);
> > + if (!bridge)
> > + continue;
> > +
> > + bridge_state = drm_atomic_get_new_bridge_state(state,
>
> bridge);
> > + if (!bridge_state)
> > + bus_format = MEDIA_BUS_FMT_FIXED;
> > + else
> > + bus_format = bridge_state-
> > >input_bus_cfg.format;
> > +
> > + if (bus_format == MEDIA_BUS_FMT_FIXED) {
> > + dev_warn(drm->dev,
> > + "[ENCODER:%d:%s]'s bridge does not
>
> provide bus format, assuming
> > MEDIA_BUS_FMT_RGB888_1X24.\n" +
>
> "Please fix bridge driver by handling
> > atomic_get_input_bus_fmts.\n", +
>
> encoder->base.id, encoder->name);
> > + bus_format = MEDIA_BUS_FMT_RGB888_1X24;
> > + }
> > +
> > + if (!format_set) {
> > + lcdif_crtc_state->bus_format = bus_format;
> > + format_set = true;
> > + } else if (lcdif_crtc_state->bus_format != bus_format)
> > {
> > + DRM_DEV_DEBUG_DRIVER(drm->dev, "inconsistent
> > bus
>
> format\n");
>
> Is there another way to know the actual reason the atomic_check
> fails? Maybe
> this is worthy to be an error message instead.
No, I don't think there is any other way. -EINVAL is what we can tell
userspace about the reason why the atomic check fails, plus the debug
message if userspace wants to look at it.
Error message is not appropriate here. Userspace supposes to try
another combination of output modes and hopes it passes atomic check.
We don't want to give too much error message to userspace.
Regards,
Liu Ying
Hi Liu,
Am Mittwoch, 15. Februar 2023, 08:49:56 CET schrieb Liu Ying:
> On Wed, 2023-02-15 at 08:26 +0100, Alexander Stein wrote:
> > Hi Liu,
>
> Hi Alexander,
>
> > thanks for the update.
>
> Thanks for the review.
>
> > Am Montag, 13. Februar 2023, 09:56:07 CET schrieb Liu Ying:
> > > There is one LCDIF embedded in i.MX93 SoC to connect with
> > > MIPI DSI controller through LCDIF cross line pattern(controlled
> > > by mediamix blk-ctrl) or connect with LVDS display bridge(LDB)
> > > directly or connect with a parallel display through parallel
> > > display format(also controlled by mediamix blk-ctrl). i.MX93
> > > LCDIF IP is essentially the same to i.MX8MP LCDIF IP. Add device
> > > tree binding for i.MX93 LCDIF.
> > >
> > > Acked-by: Krzysztof Kozlowski <[email protected]>
> > > Reviewed-by: Marek Vasut <[email protected]>
> > > Signed-off-by: Liu Ying <[email protected]>
> > > ---
> > > v2->v3:
> > > * No change.
> > >
> > > v1->v2:
> > > * Add Krzysztof's A-b and Marek's R-b tags on patch 1/6.
> > >
> > > Documentation/devicetree/bindings/display/fsl,lcdif.yaml | 7
> > >
> > > ++++++-
> > >
> > > 1 file changed, 6 insertions(+), 1 deletion(-)
> > >
> > > diff --git
> > > a/Documentation/devicetree/bindings/display/fsl,lcdif.yaml
> > > b/Documentation/devicetree/bindings/display/fsl,lcdif.yaml index
> > > 75b4efd70ba8..fc11ab5fc465 100644
> > > --- a/Documentation/devicetree/bindings/display/fsl,lcdif.yaml
> > > +++ b/Documentation/devicetree/bindings/display/fsl,lcdif.yaml
> > >
> > > @@ -21,6 +21,7 @@ properties:
> > > - fsl,imx28-lcdif
> > > - fsl,imx6sx-lcdif
> > > - fsl,imx8mp-lcdif
> > >
> > > + - fsl,imx93-lcdif
> > >
> > > - items:
> > > - enum:
> > > - fsl,imx6sl-lcdif
> > >
> > > @@ -88,7 +89,9 @@ allOf:
> > > properties:
> > > compatible:
> > > contains:
> > > - const: fsl,imx8mp-lcdif
> > > + enum:
> > > + - fsl,imx8mp-lcdif
> > > + - fsl,imx93-lcdif
> > >
> > > then:
> > > properties:
> > > clocks:
> > > @@ -107,6 +110,7 @@ allOf:
> > > enum:
> > > - fsl,imx6sx-lcdif
> > > - fsl,imx8mp-lcdif
> > >
> > > + - fsl,imx93-lcdif
> > >
> > > then:
> > > properties:
> > > clocks:
> > > @@ -123,6 +127,7 @@ allOf:
> > > - fsl,imx8mm-lcdif
> > > - fsl,imx8mn-lcdif
> > > - fsl,imx8mp-lcdif
> > >
> > > + - fsl,imx93-lcdif
> > >
> > > then:
> > > required:
> > > - power-domains
> >
> > I would have expected that fsl,imx93-lcdif supports up to 3 endpoints
> > (MIPI
> > DSI, LVDS, and parallel) in a 'ports' subnode. But this binding only
> > supports
> > a single 'port' sub-node. Also an example for this case might be very
> > helpful.
>
> The port node allows multiple endpoints(See graph.yaml[1]). It's
> enough to use the existing port node instead of using ports node.
Ah, I wasn't aware of that possibility for OF graph. Yep, agreed then it's
enough.
> For i.MX93 LCDIF, the port node will be something like this:
> --------------------8<--------------------------
> port {
> #address-cells = <1>;
> #size-cells = <0>;
>
> lcdif_to_pdfc: endpoint@0 {
> reg = <0>;
> };
>
> lcdif_to_ldb: endpoint@1 {
> reg = <1>;
> };
>
> lcdif_to_cross_line_pattern: endpoint@2 {
> reg = <2>;
> };
> };
> --------------------8<--------------------------
>
> Looks like it's not necessary to add a specifc example for i.MX93
> LCDIF.
Fine by me.
Reviewed-by: Alexander Stein <[email protected]>
> [1]
> https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/graph
> .yaml#L48
>
> Regards,
> Liu Ying
TQ-Systems GmbH | M?hlstra?e 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht M?nchen, HRB 105018
Gesch?ftsf?hrer: Detlef Schneider, R?diger Stahl, Stefan Schneider
On Wed, 2023-02-15 at 08:54 +0100, Alexander Stein wrote:
> Hi Liu,
Hi Alexander,
>
> thanks for the update.
Thanks for the review.
>
> Am Montag, 13. Februar 2023, 09:56:11 CET schrieb Liu Ying:
> > The single LCDIF embedded in i.MX93 SoC may drive multiple displays
> > simultaneously. Look at LCDIF output port's remote port parents to
> > find all enabled first bridges. Add an encoder for each found
> > bridge
> > and attach the bridge to the encoder. This is a preparation for
> > adding i.MX93 LCDIF support.
> >
> > Signed-off-by: Liu Ying <[email protected]>
> > ---
> > v2->v3:
> > * No change.
> >
> > v1->v2:
> > * Split from patch 2/2 in v1. (Marek, Alexander)
> > * Drop '!remote ||' from lcdif_attach_bridge(). (Lothar)
> > * Drop unneeded 'bridges' member from lcdif_drm_private structure.
> >
> > drivers/gpu/drm/mxsfb/lcdif_drv.c | 68
> > +++++++++++++++++++++++++++----
> > drivers/gpu/drm/mxsfb/lcdif_drv.h | 4 +-
> > drivers/gpu/drm/mxsfb/lcdif_kms.c | 21 ++--------
> > 3 files changed, 66 insertions(+), 27 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> > b/drivers/gpu/drm/mxsfb/lcdif_drv.c index
> > b5b9a8e273c6..eb6c265fa2fe 100644
> > --- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> > +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
> > @@ -9,13 +9,16 @@
> > #include <linux/dma-mapping.h>
> > #include <linux/io.h>
> > #include <linux/module.h>
> > +#include <linux/of.h>
> > #include <linux/of_device.h>
> > +#include <linux/of_graph.h>
> > #include <linux/platform_device.h>
> > #include <linux/pm_runtime.h>
> >
> > #include <drm/drm_atomic_helper.h>
> > #include <drm/drm_bridge.h>
> > #include <drm/drm_drv.h>
> > +#include <drm/drm_encoder.h>
> > #include <drm/drm_fbdev_generic.h>
> > #include <drm/drm_gem_dma_helper.h>
> > #include <drm/drm_gem_framebuffer_helper.h>
> > @@ -38,19 +41,68 @@ static const struct
> > drm_mode_config_helper_funcs
> > lcdif_mode_config_helpers = { .atomic_commit_tail =
> > drm_atomic_helper_commit_tail_rpm,
> > };
> >
> > +static const struct drm_encoder_funcs lcdif_encoder_funcs = {
> > + .destroy = drm_encoder_cleanup,
> > +};
> > +
> > static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
> > {
> > - struct drm_device *drm = lcdif->drm;
> > + struct device *dev = lcdif->drm->dev;
> > + struct device_node *ep;
> > struct drm_bridge *bridge;
> > int ret;
> >
> > - bridge = devm_drm_of_get_bridge(drm->dev, drm->dev->of_node, 0,
> > 0);
> > - if (IS_ERR(bridge))
> > - return PTR_ERR(bridge);
> > -
> > - ret = drm_bridge_attach(&lcdif->encoder, bridge, NULL, 0);
> > - if (ret)
> > - return dev_err_probe(drm->dev, ret, "Failed to attach
>
> bridge\n");
> > + for_each_endpoint_of_node(dev->of_node, ep) {
> > + struct device_node *remote;
> > + struct of_endpoint of_ep;
> > + struct drm_encoder *encoder;
> > +
> > + remote = of_graph_get_remote_port_parent(ep);
>
> Is it possible for remote to be NULL?
Yes. But, no worries. Lothar said the check for '!remote' is not
needed in v1 comment because of_device_is_available() checks that.
>
> > + if (!of_device_is_available(remote)) {
> > + of_node_put(remote);
> > + continue;
> > + }
> > + of_node_put(remote);
> > +
> > + ret = of_graph_parse_endpoint(ep, &of_ep);
> > + if (ret < 0) {
> > + dev_err(dev, "Failed to parse endpoint
> > %pOF\n",
>
> ep);
> > + of_node_put(ep);
> > + return ret;
> > + }
> > +
> > + if (of_ep.id >= MAX_DISPLAYS) {
> > + dev_warn(dev, "invalid endpoint id %u\n",
>
> of_ep.id);
>
> I would write
> dev_warn(dev, "ignoring invalid endpoint id %u\n", of_ep.id);
> just because the parsing continues but this one is skipped.
Ok, will do that in next version.
>
> > + continue;
> > + }
> > +
> > + bridge = devm_drm_of_get_bridge(dev, dev->of_node, 0,
>
> of_ep.id);
> > + if (IS_ERR(bridge)) {
> > + of_node_put(ep);
> > + return dev_err_probe(dev, PTR_ERR(bridge),
> > + "Failed to get bridge
>
> for endpoint%u\n",
> > + of_ep.id);
> > + }
> > +
> > + encoder = &lcdif->encoders[of_ep.id];
> > + encoder->possible_crtcs = drm_crtc_mask(&lcdif->crtc);
> > + ret = drm_encoder_init(lcdif->drm, encoder,
>
> &lcdif_encoder_funcs,
> > + DRM_MODE_ENCODER_NONE, NULL);
> > + if (ret) {
> > + dev_err(dev, "Failed to initialize encoder for
>
> endpoint%u: %d\n",
> > + of_ep.id, ret);
> > + of_node_put(ep);
> > + return ret;
> > + }
> > +
> > + ret = drm_bridge_attach(encoder, bridge, NULL, 0);
> > + if (ret) {
> > + of_node_put(ep);
> > + return dev_err_probe(dev, ret,
> > + "Failed to attach
>
> bridge for endpoint%u\n",
> > + of_ep.id);
> > + }
>
> Admittedly I'm not used to the drm API, but do we need to some manual
> cleanup/
> revert if some endpoints is e.g. deferred, but previous endpoints
> already have
> been successfully added? e.g. endpoint 0 is added, but adding
> endpoint 1
> fails.
I think the bailout path is safe, because
drm_mode_config_init_release() is called as the managed release action
added through drm_mode_config_init(). drm_mode_config_cleanup() would
clean things up.
Regards,
Liu Ying