2023-07-28 14:38:45

by Johannes Zink

[permalink] [raw]
Subject: [PATCH v4 3/3] drm/panel-simple: allow LVDS format override

Some panels support multiple LVDS data mapping formats, which can be
used e.g. run displays on jeida-18 format when only 3 LVDS lanes are
available.

Add parsing of an optional data-mapping devicetree property, which also
touches up the bits per color to match the bus format.

Signed-off-by: Johannes Zink <[email protected]>

---

Changes:

v3 -> v4: - worked in Dan's feedback (thanks for reviewing my work):
- return with a proper error in case the call to
panel_simple_override_nondefault_lvds_datamapping()
fails
- drop the unneeded and ambiguous ret variable

v2 -> v3: - worked in Laurent's review findings (thanks for reviewing
my work):
- extract fixing up the bus format to separate
function
- only call function on LVDS panels
- fix typos found by Laurent
- simplified error handling

v1 -> v2: - fix missing unwind goto found by test robot
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Link: https://lore.kernel.org/r/[email protected]/
---
drivers/gpu/drm/panel/panel-simple.c | 53 ++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)

diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c
index 4badda6570d5..3a164931093e 100644
--- a/drivers/gpu/drm/panel/panel-simple.c
+++ b/drivers/gpu/drm/panel/panel-simple.c
@@ -40,6 +40,7 @@
#include <drm/drm_edid.h>
#include <drm/drm_mipi_dsi.h>
#include <drm/drm_panel.h>
+#include <drm/drm_of.h>

/**
* struct panel_desc - Describes a simple panel.
@@ -549,6 +550,51 @@ static void panel_simple_parse_panel_timing_node(struct device *dev,
dev_err(dev, "Reject override mode: No display_timing found\n");
}

+static int panel_simple_override_nondefault_lvds_datamapping(struct device *dev,
+ struct panel_simple *panel)
+{
+ int ret, bpc;
+
+ ret = drm_of_lvds_get_data_mapping(dev->of_node);
+ if (ret < 0) {
+ if (ret == -EINVAL)
+ dev_warn(dev, "Ignore invalid data-mapping property\n");
+
+ /*
+ * Ignore non-existing or malformatted property, fallback to
+ * default data-mapping, and return 0.
+ */
+ return 0;
+ }
+
+ switch (ret) {
+ default:
+ WARN_ON(1);
+ fallthrough;
+ case MEDIA_BUS_FMT_RGB888_1X7X4_SPWG:
+ fallthrough;
+ case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA:
+ bpc = 8;
+ break;
+ case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG:
+ bpc = 6;
+ }
+
+ if (panel->desc->bpc != bpc || panel->desc->bus_format != ret) {
+ struct panel_desc *override_desc;
+
+ override_desc = devm_kmemdup(dev, panel->desc, sizeof(*panel->desc), GFP_KERNEL);
+ if (!override_desc)
+ return -ENOMEM;
+
+ override_desc->bus_format = ret;
+ override_desc->bpc = bpc;
+ panel->desc = override_desc;
+ }
+
+ return 0;
+}
+
static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
{
struct panel_simple *panel;
@@ -601,6 +647,13 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
panel_simple_parse_panel_timing_node(dev, panel, &dt);
}

+ if (desc->connector_type == DRM_MODE_CONNECTOR_LVDS) {
+ /* Optional data-mapping property for overriding bus format */
+ err = panel_simple_override_nondefault_lvds_datamapping(dev, panel);
+ if (err)
+ goto free_ddc;
+ }
+
connector_type = desc->connector_type;
/* Catch common mistakes for panels. */
switch (connector_type) {

--
2.39.2



2023-08-18 21:22:08

by Johannes Zink

[permalink] [raw]
Subject: Re: [PATCH v4 3/3] drm/panel-simple: allow LVDS format override

Hi Dan,

do you have any input on this for me?

Best regards
Johannes

On 7/28/23 16:16, Johannes Zink wrote:
> Some panels support multiple LVDS data mapping formats, which can be
> used e.g. run displays on jeida-18 format when only 3 LVDS lanes are
> available.
>
> Add parsing of an optional data-mapping devicetree property, which also
> touches up the bits per color to match the bus format.
>
> Signed-off-by: Johannes Zink <[email protected]>
>
> ---
>
> Changes:
>
> v3 -> v4: - worked in Dan's feedback (thanks for reviewing my work):
> - return with a proper error in case the call to
> panel_simple_override_nondefault_lvds_datamapping()
> fails
> - drop the unneeded and ambiguous ret variable
>
> v2 -> v3: - worked in Laurent's review findings (thanks for reviewing
> my work):
> - extract fixing up the bus format to separate
> function
> - only call function on LVDS panels
> - fix typos found by Laurent
> - simplified error handling
>
> v1 -> v2: - fix missing unwind goto found by test robot
> Reported-by: kernel test robot <[email protected]>
> Reported-by: Dan Carpenter <[email protected]>
> Link: https://lore.kernel.org/r/[email protected]/
> ---
> drivers/gpu/drm/panel/panel-simple.c | 53 ++++++++++++++++++++++++++++++++++++
> 1 file changed, 53 insertions(+)
>
> diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c
> index 4badda6570d5..3a164931093e 100644
> --- a/drivers/gpu/drm/panel/panel-simple.c
> +++ b/drivers/gpu/drm/panel/panel-simple.c
> @@ -40,6 +40,7 @@
> #include <drm/drm_edid.h>
> #include <drm/drm_mipi_dsi.h>
> #include <drm/drm_panel.h>
> +#include <drm/drm_of.h>
>
> /**
> * struct panel_desc - Describes a simple panel.
> @@ -549,6 +550,51 @@ static void panel_simple_parse_panel_timing_node(struct device *dev,
> dev_err(dev, "Reject override mode: No display_timing found\n");
> }
>
> +static int panel_simple_override_nondefault_lvds_datamapping(struct device *dev,
> + struct panel_simple *panel)
> +{
> + int ret, bpc;
> +
> + ret = drm_of_lvds_get_data_mapping(dev->of_node);
> + if (ret < 0) {
> + if (ret == -EINVAL)
> + dev_warn(dev, "Ignore invalid data-mapping property\n");
> +
> + /*
> + * Ignore non-existing or malformatted property, fallback to
> + * default data-mapping, and return 0.
> + */
> + return 0;
> + }
> +
> + switch (ret) {
> + default:
> + WARN_ON(1);
> + fallthrough;
> + case MEDIA_BUS_FMT_RGB888_1X7X4_SPWG:
> + fallthrough;
> + case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA:
> + bpc = 8;
> + break;
> + case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG:
> + bpc = 6;
> + }
> +
> + if (panel->desc->bpc != bpc || panel->desc->bus_format != ret) {
> + struct panel_desc *override_desc;
> +
> + override_desc = devm_kmemdup(dev, panel->desc, sizeof(*panel->desc), GFP_KERNEL);
> + if (!override_desc)
> + return -ENOMEM;
> +
> + override_desc->bus_format = ret;
> + override_desc->bpc = bpc;
> + panel->desc = override_desc;
> + }
> +
> + return 0;
> +}
> +
> static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
> {
> struct panel_simple *panel;
> @@ -601,6 +647,13 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
> panel_simple_parse_panel_timing_node(dev, panel, &dt);
> }
>
> + if (desc->connector_type == DRM_MODE_CONNECTOR_LVDS) {
> + /* Optional data-mapping property for overriding bus format */
> + err = panel_simple_override_nondefault_lvds_datamapping(dev, panel);
> + if (err)
> + goto free_ddc;
> + }
> +
> connector_type = desc->connector_type;
> /* Catch common mistakes for panels. */
> switch (connector_type) {
>

--
Pengutronix e.K. | Johannes Zink |
Steuerwalder Str. 21 | https://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686| Fax: +49-5121-206917-5555 |


2023-09-13 12:15:23

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH v4 3/3] drm/panel-simple: allow LVDS format override

On Fri, Aug 18, 2023 at 09:04:34AM +0200, Johannes Zink wrote:
> Hi Dan,
>
> do you have any input on this for me?
>

Sorry, I was out of office and the truth is that I'm never going to
catch up on all the email I missed. :/

Looks okay to me. I can't remember what I said about this code in v3
but it looks good now. I'm not a DRM dev so I'm not sure my review
counts for much. You should always just assume that if I'm quiet
then I'm happy. :)

regards,
dan carpenter

2023-09-13 14:38:10

by Johannes Zink

[permalink] [raw]
Subject: Re: [PATCH v4 3/3] drm/panel-simple: allow LVDS format override

Hi Dan,

On 9/13/23 13:14, Dan Carpenter wrote:
> On Fri, Aug 18, 2023 at 09:04:34AM +0200, Johannes Zink wrote:
>> Hi Dan,
>>
>> do you have any input on this for me?
>>
>
> Sorry, I was out of office and the truth is that I'm never going to
> catch up on all the email I missed. :/
>

nevermind, that's why I sent ping...

> Looks okay to me. I can't remember what I said about this code in v3
> but it looks good now. I'm not a DRM dev so I'm not sure my review
> counts for much.

IIRC it was a mistake I made with a return value that I have fixed in v4.

You should always just assume that if I'm quiet
> then I'm happy. :)

That's good to know ;-) Thanks for your review!

Johannes

>
> regards,
> dan carpenter
>
>

--
Pengutronix e.K. | Johannes Zink |
Steuerwalder Str. 21 | https://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686| Fax: +49-5121-206917-5555 |