2022-06-06 06:24:07

by Hsin-Yi Wang

[permalink] [raw]
Subject: [PATCH v3 0/8] Add a panel API to return panel orientation

Panels usually call drm_connector_set_panel_orientation(), which is
later than drm/kms driver calling drm_dev_register(). This leads to a
WARN()[1].

The orientation property is known earlier. For example, some panels
parse the property through device tree during probe.

The series add a panel API drm_panel_get_orientation() for drm/kms
drivers. The drivers can use the API to get panel's orientation, so they
can call drm_connector_set_panel_orientation() before drm_dev_register().

Panel needs to implement .get_orientation callback to return the property.

[1] https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

Hsin-Yi Wang (8):
drm/panel: Add an API drm_panel_get_orientation() to return panel
orientation
drm/panel: boe-tv101wum-nl6: Implement .get_orientation callback
drm/panel: panel-edp: Implement .get_orientation callback
drm/panel: lvds: Implement .get_orientation callback
drm/panel: panel-simple: Implement .get_orientation callback
drm/panel: ili9881c: Implement .get_orientation callback
drm/panel: elida-kd35t133: Implement .get_orientation callback
drm/mediatek: Config orientation property if panel provides it

drivers/gpu/drm/drm_panel.c | 8 ++++++++
drivers/gpu/drm/mediatek/mtk_dsi.c | 10 ++++++++++
drivers/gpu/drm/panel/panel-boe-tv101wum-nl6.c | 14 ++++++++++++++
drivers/gpu/drm/panel/panel-edp.c | 15 ++++++++++++++-
drivers/gpu/drm/panel/panel-elida-kd35t133.c | 14 ++++++++++++++
drivers/gpu/drm/panel/panel-ilitek-ili9881c.c | 14 ++++++++++++++
drivers/gpu/drm/panel/panel-lvds.c | 14 ++++++++++++++
drivers/gpu/drm/panel/panel-simple.c | 16 +++++++++++++++-
include/drm/drm_panel.h | 10 ++++++++++
9 files changed, 113 insertions(+), 2 deletions(-)

--
2.36.1.255.ge46751e96f-goog


2022-06-06 06:24:11

by Hsin-Yi Wang

[permalink] [raw]
Subject: [PATCH v3 8/8] drm/mediatek: Config orientation property if panel provides it

Panel orientation property should be set before drm_dev_register().
Mediatek drm driver calls drm_dev_register() in .bind(). However, most
panels sets orientation property relatively late, mostly in .get_modes()
callback, since this is when they are able to get the connector and
binds the orientation property to it, though the value should be known
when the panel is probed.

Let the drm driver check if the remote end point is a panel and if it
contains the orientation property. If it does, set it before
drm_dev_register() is called.

Signed-off-by: Hsin-Yi Wang <[email protected]>
Reviewed-by: Hans de Goede <[email protected]>
---
v2->v3: no change.
---
drivers/gpu/drm/mediatek/mtk_dsi.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c
index bd3f5b485085..86613360d2d9 100644
--- a/drivers/gpu/drm/mediatek/mtk_dsi.c
+++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
@@ -185,6 +185,7 @@ struct mtk_dsi {
struct drm_encoder encoder;
struct drm_bridge bridge;
struct drm_bridge *next_bridge;
+ struct drm_panel *panel;
struct drm_connector *connector;
struct phy *phy;

@@ -822,6 +823,12 @@ static int mtk_dsi_encoder_init(struct drm_device *drm, struct mtk_dsi *dsi)
ret = PTR_ERR(dsi->connector);
goto err_cleanup_encoder;
}
+
+ /* Read panel orientation */
+ if (dsi->panel)
+ drm_connector_set_panel_orientation(dsi->connector,
+ drm_panel_get_orientation(dsi->panel));
+
drm_connector_attach_encoder(dsi->connector, &dsi->encoder);

return 0;
@@ -837,6 +844,9 @@ static int mtk_dsi_bind(struct device *dev, struct device *master, void *data)
struct drm_device *drm = data;
struct mtk_dsi *dsi = dev_get_drvdata(dev);

+ /* Get panel if existed */
+ drm_of_find_panel_or_bridge(dev->of_node, 0, 0, &dsi->panel, NULL);
+
ret = mtk_dsi_encoder_init(drm, dsi);
if (ret)
return ret;
--
2.36.1.255.ge46751e96f-goog

2022-06-06 06:24:17

by Hsin-Yi Wang

[permalink] [raw]
Subject: [PATCH v3 1/8] drm/panel: Add an API drm_panel_get_orientation() to return panel orientation

Panels usually call drm_connector_set_panel_orientation(), which is
later than drm/kms driver calling drm_dev_register(). This leads to a
WARN().

The orientation property is known earlier. For example, some panels
parse the property through device tree during probe.

Add an API to return the property from panel to drm/kms driver, so the
drivers are able to call drm_connector_set_panel_orientation() before
drm_dev_register().

Suggested-by: Hans de Goede <[email protected]>
Signed-off-by: Hsin-Yi Wang <[email protected]>
Reviewed-by: Hans de Goede <[email protected]>
---
v2->v3: no change
---
drivers/gpu/drm/drm_panel.c | 8 ++++++++
include/drm/drm_panel.h | 10 ++++++++++
2 files changed, 18 insertions(+)

diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
index f634371c717a..4a512ca80673 100644
--- a/drivers/gpu/drm/drm_panel.c
+++ b/drivers/gpu/drm/drm_panel.c
@@ -223,6 +223,14 @@ int drm_panel_get_modes(struct drm_panel *panel,
}
EXPORT_SYMBOL(drm_panel_get_modes);

+enum drm_panel_orientation drm_panel_get_orientation(struct drm_panel *panel)
+{
+ if (panel && panel->funcs && panel->funcs->get_orientation)
+ return panel->funcs->get_orientation(panel);
+
+ return DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
+}
+EXPORT_SYMBOL(drm_panel_get_orientation);
#ifdef CONFIG_OF
/**
* of_drm_find_panel - look up a panel using a device tree node
diff --git a/include/drm/drm_panel.h b/include/drm/drm_panel.h
index 1ba2d424a53f..d1bd3be4bbdf 100644
--- a/include/drm/drm_panel.h
+++ b/include/drm/drm_panel.h
@@ -133,6 +133,15 @@ struct drm_panel_funcs {
* Allows panels to create panels-specific debugfs files.
*/
void (*debugfs_init)(struct drm_panel *panel, struct dentry *root);
+
+ /**
+ * @get_orientation:
+ *
+ * Return the panel orientation set by device tree or EDID.
+ *
+ * This function is optional.
+ */
+ enum drm_panel_orientation (*get_orientation)(struct drm_panel *panel);
};

/**
@@ -195,6 +204,7 @@ int drm_panel_enable(struct drm_panel *panel);
int drm_panel_disable(struct drm_panel *panel);

int drm_panel_get_modes(struct drm_panel *panel, struct drm_connector *connector);
+enum drm_panel_orientation drm_panel_get_orientation(struct drm_panel *panel);

#if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL)
struct drm_panel *of_drm_find_panel(const struct device_node *np);
--
2.36.1.255.ge46751e96f-goog

2022-06-06 06:24:17

by Hsin-Yi Wang

[permalink] [raw]
Subject: [PATCH v3 5/8] drm/panel: panel-simple: Implement .get_orientation callback

To return the orientation property to drm/kms driver.

Signed-off-by: Hsin-Yi Wang <[email protected]>
Reviewed-by: Hans de Goede <[email protected]>
---
v2->v3: add comments for notice.
---
drivers/gpu/drm/panel/panel-simple.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c
index a34f4198a534..82041cdb5478 100644
--- a/drivers/gpu/drm/panel/panel-simple.c
+++ b/drivers/gpu/drm/panel/panel-simple.c
@@ -411,7 +411,12 @@ static int panel_simple_get_modes(struct drm_panel *panel,
/* add hard-coded panel modes */
num += panel_simple_get_non_edid_modes(p, connector);

- /* set up connector's "panel orientation" property */
+ /*
+ * drm drivers are expected to call drm_panel_get_orientation() to get
+ * panel's orientation then drm_connector_set_panel_orientation() to
+ * set the property before drm_dev_register(). Otherwise there will be
+ * a WARN_ON if orientation is set after drm is registered.
+ */
drm_connector_set_panel_orientation(connector, p->orientation);

return num;
@@ -434,6 +439,14 @@ static int panel_simple_get_timings(struct drm_panel *panel,
return p->desc->num_timings;
}

+static enum drm_panel_orientation panel_simple_get_orientation(struct drm_panel *panel)
+{
+ struct panel_simple *p = to_panel_simple(panel);
+
+ return p->orientation;
+}
+
+
static const struct drm_panel_funcs panel_simple_funcs = {
.disable = panel_simple_disable,
.unprepare = panel_simple_unprepare,
@@ -441,6 +454,7 @@ static const struct drm_panel_funcs panel_simple_funcs = {
.enable = panel_simple_enable,
.get_modes = panel_simple_get_modes,
.get_timings = panel_simple_get_timings,
+ .get_orientation = panel_simple_get_orientation,
};

static struct panel_desc panel_dpi;
--
2.36.1.255.ge46751e96f-goog

2022-06-06 06:24:18

by Hsin-Yi Wang

[permalink] [raw]
Subject: [PATCH v3 7/8] drm/panel: elida-kd35t133: Implement .get_orientation callback

To return the orientation property to drm/kms driver.

Signed-off-by: Hsin-Yi Wang <[email protected]>
Reviewed-by: Hans de Goede <[email protected]>
---
v2->v3: add comments for notice.
---
drivers/gpu/drm/panel/panel-elida-kd35t133.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/panel/panel-elida-kd35t133.c b/drivers/gpu/drm/panel/panel-elida-kd35t133.c
index 80227617a4d6..fa85a288afdc 100644
--- a/drivers/gpu/drm/panel/panel-elida-kd35t133.c
+++ b/drivers/gpu/drm/panel/panel-elida-kd35t133.c
@@ -217,15 +217,29 @@ static int kd35t133_get_modes(struct drm_panel *panel,
connector->display_info.width_mm = mode->width_mm;
connector->display_info.height_mm = mode->height_mm;
drm_mode_probed_add(connector, mode);
+ /*
+ * drm drivers are expected to call drm_panel_get_orientation() to get
+ * panel's orientation then drm_connector_set_panel_orientation() to
+ * set the property before drm_dev_register(). Otherwise there will be
+ * a WARN_ON if orientation is set after drm is registered.
+ */
drm_connector_set_panel_orientation(connector, ctx->orientation);

return 1;
}

+static enum drm_panel_orientation kd35t133_get_orientation(struct drm_panel *panel)
+{
+ struct kd35t133 *ctx = panel_to_kd35t133(panel);
+
+ return ctx->orientation;
+}
+
static const struct drm_panel_funcs kd35t133_funcs = {
.unprepare = kd35t133_unprepare,
.prepare = kd35t133_prepare,
.get_modes = kd35t133_get_modes,
+ .get_orientation = kd35t133_get_orientation,
};

static int kd35t133_probe(struct mipi_dsi_device *dsi)
--
2.36.1.255.ge46751e96f-goog

Subject: Re: [PATCH v3 8/8] drm/mediatek: Config orientation property if panel provides it

Il 06/06/22 06:47, Hsin-Yi Wang ha scritto:
> Panel orientation property should be set before drm_dev_register().
> Mediatek drm driver calls drm_dev_register() in .bind(). However, most
> panels sets orientation property relatively late, mostly in .get_modes()
> callback, since this is when they are able to get the connector and
> binds the orientation property to it, though the value should be known
> when the panel is probed.
>
> Let the drm driver check if the remote end point is a panel and if it
> contains the orientation property. If it does, set it before
> drm_dev_register() is called.
>
> Signed-off-by: Hsin-Yi Wang <[email protected]>
> Reviewed-by: Hans de Goede <[email protected]>

Reviewed-by: AngeloGioacchino Del Regno <[email protected]>

2022-06-06 14:31:38

by Doug Anderson

[permalink] [raw]
Subject: Re: [PATCH v3 1/8] drm/panel: Add an API drm_panel_get_orientation() to return panel orientation

Hi,

On Sun, Jun 5, 2022 at 9:47 PM Hsin-Yi Wang <[email protected]> wrote:
>
> Panels usually call drm_connector_set_panel_orientation(), which is
> later than drm/kms driver calling drm_dev_register(). This leads to a
> WARN().
>
> The orientation property is known earlier. For example, some panels
> parse the property through device tree during probe.
>
> Add an API to return the property from panel to drm/kms driver, so the
> drivers are able to call drm_connector_set_panel_orientation() before
> drm_dev_register().
>
> Suggested-by: Hans de Goede <[email protected]>
> Signed-off-by: Hsin-Yi Wang <[email protected]>
> Reviewed-by: Hans de Goede <[email protected]>
> ---
> v2->v3: no change
> ---
> drivers/gpu/drm/drm_panel.c | 8 ++++++++
> include/drm/drm_panel.h | 10 ++++++++++
> 2 files changed, 18 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
> index f634371c717a..4a512ca80673 100644
> --- a/drivers/gpu/drm/drm_panel.c
> +++ b/drivers/gpu/drm/drm_panel.c
> @@ -223,6 +223,14 @@ int drm_panel_get_modes(struct drm_panel *panel,
> }
> EXPORT_SYMBOL(drm_panel_get_modes);
>
> +enum drm_panel_orientation drm_panel_get_orientation(struct drm_panel *panel)
> +{
> + if (panel && panel->funcs && panel->funcs->get_orientation)
> + return panel->funcs->get_orientation(panel);
> +
> + return DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
> +}
> +EXPORT_SYMBOL(drm_panel_get_orientation);
> #ifdef CONFIG_OF

nit: there used to be a blank line before the #ifdef but there no
longer is after your patch.

Other than that...

Reviewed-by: Douglas Anderson <[email protected]>

2022-06-06 14:35:16

by Doug Anderson

[permalink] [raw]
Subject: Re: [PATCH v3 5/8] drm/panel: panel-simple: Implement .get_orientation callback

Hi,

On Sun, Jun 5, 2022 at 9:47 PM Hsin-Yi Wang <[email protected]> wrote:
>
> To return the orientation property to drm/kms driver.
>
> Signed-off-by: Hsin-Yi Wang <[email protected]>
> Reviewed-by: Hans de Goede <[email protected]>
> ---
> v2->v3: add comments for notice.
> ---
> drivers/gpu/drm/panel/panel-simple.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)

Reviewed-by: Douglas Anderson <[email protected]>

2022-06-06 15:01:31

by Doug Anderson

[permalink] [raw]
Subject: Re: [PATCH v3 7/8] drm/panel: elida-kd35t133: Implement .get_orientation callback

Hi,

On Sun, Jun 5, 2022 at 9:47 PM Hsin-Yi Wang <[email protected]> wrote:
>
> To return the orientation property to drm/kms driver.
>
> Signed-off-by: Hsin-Yi Wang <[email protected]>
> Reviewed-by: Hans de Goede <[email protected]>
> ---
> v2->v3: add comments for notice.
> ---
> drivers/gpu/drm/panel/panel-elida-kd35t133.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)

Reviewed-by: Douglas Anderson <[email protected]>

2022-06-06 15:46:11

by Hsin-Yi Wang

[permalink] [raw]
Subject: Re: [PATCH v3 1/8] drm/panel: Add an API drm_panel_get_orientation() to return panel orientation

On Mon, Jun 6, 2022 at 10:21 PM Doug Anderson <[email protected]> wrote:
>
> Hi,
>
> On Sun, Jun 5, 2022 at 9:47 PM Hsin-Yi Wang <[email protected]> wrote:
> >
> > Panels usually call drm_connector_set_panel_orientation(), which is
> > later than drm/kms driver calling drm_dev_register(). This leads to a
> > WARN().
> >
> > The orientation property is known earlier. For example, some panels
> > parse the property through device tree during probe.
> >
> > Add an API to return the property from panel to drm/kms driver, so the
> > drivers are able to call drm_connector_set_panel_orientation() before
> > drm_dev_register().
> >
> > Suggested-by: Hans de Goede <[email protected]>
> > Signed-off-by: Hsin-Yi Wang <[email protected]>
> > Reviewed-by: Hans de Goede <[email protected]>
> > ---
> > v2->v3: no change
> > ---
> > drivers/gpu/drm/drm_panel.c | 8 ++++++++
> > include/drm/drm_panel.h | 10 ++++++++++
> > 2 files changed, 18 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
> > index f634371c717a..4a512ca80673 100644
> > --- a/drivers/gpu/drm/drm_panel.c
> > +++ b/drivers/gpu/drm/drm_panel.c
> > @@ -223,6 +223,14 @@ int drm_panel_get_modes(struct drm_panel *panel,
> > }
> > EXPORT_SYMBOL(drm_panel_get_modes);
> >
> > +enum drm_panel_orientation drm_panel_get_orientation(struct drm_panel *panel)
> > +{
> > + if (panel && panel->funcs && panel->funcs->get_orientation)
> > + return panel->funcs->get_orientation(panel);
> > +
> > + return DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
> > +}
> > +EXPORT_SYMBOL(drm_panel_get_orientation);
> > #ifdef CONFIG_OF
>
> nit: there used to be a blank line before the #ifdef but there no
> longer is after your patch.
>
Added in v4.
> Other than that...
>
> Reviewed-by: Douglas Anderson <[email protected]>