Skip to content

Commit 47c0826

Browse files
committed
drm/panel: panel-simple: Add function to look panel data up
Commit de04bb0 ("drm/panel/panel-simple: Use the new allocation in place of devm_kzalloc()") moved the call to drm_panel_init into the devm_drm_panel_alloc(), which needs a connector type to initialize properly. In the panel-dpi compatible case, the passed panel_desc structure is an empty one used as a discriminant, and the connector type it contains isn't actually initialized. It is initialized through a call to panel_dpi_probe() later in the function, which used to be before the call to drm_panel_init() that got merged into devm_drm_panel_alloc(). So, we do need a proper panel_desc pointer before the call to devm_drm_panel_alloc() now. All cases associate their panel_desc with the panel compatible and use of_device_get_match_data, except for the panel-dpi compatible. In that case, we're expected to call panel_dpi_probe, which will allocate and initialize the panel_desc for us. Let's create such a helper function that would be called first in the driver and will lookup the desc by compatible, or allocate one if relevant. Reported-by: Francesco Dolcini <[email protected]> Closes: https://lore.kernel.org/all/20250612081834.GA248237@francesco-nb/ Fixes: de04bb0 ("drm/panel/panel-simple: Use the new allocation in place of devm_kzalloc()") Reviewed-by: Javier Martinez Canillas <[email protected]> Tested-by: Francesco Dolcini <[email protected]> # Toradex Colibri iMX6 Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Maxime Ripard <[email protected]>
1 parent 921c41e commit 47c0826

File tree

1 file changed

+49
-33
lines changed

1 file changed

+49
-33
lines changed

drivers/gpu/drm/panel/panel-simple.c

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/i2c.h>
2727
#include <linux/media-bus-format.h>
2828
#include <linux/module.h>
29+
#include <linux/of_device.h>
2930
#include <linux/of_platform.h>
3031
#include <linux/platform_device.h>
3132
#include <linux/pm_runtime.h>
@@ -136,6 +137,14 @@ struct panel_desc {
136137
int connector_type;
137138
};
138139

140+
struct panel_desc_dsi {
141+
struct panel_desc desc;
142+
143+
unsigned long flags;
144+
enum mipi_dsi_pixel_format format;
145+
unsigned int lanes;
146+
};
147+
139148
struct panel_simple {
140149
struct drm_panel base;
141150

@@ -567,15 +576,49 @@ static int panel_simple_override_nondefault_lvds_datamapping(struct device *dev,
567576
return 0;
568577
}
569578

570-
static struct panel_simple *panel_simple_probe(struct device *dev, const struct panel_desc *desc)
579+
static const struct panel_desc *panel_simple_get_desc(struct device *dev)
580+
{
581+
if (IS_ENABLED(CONFIG_DRM_MIPI_DSI) &&
582+
dev_is_mipi_dsi(dev)) {
583+
const struct panel_desc_dsi *dsi_desc;
584+
585+
dsi_desc = of_device_get_match_data(dev);
586+
if (!dsi_desc)
587+
return ERR_PTR(-ENODEV);
588+
589+
return &dsi_desc->desc;
590+
}
591+
592+
if (dev_is_platform(dev)) {
593+
const struct panel_desc *desc;
594+
595+
desc = of_device_get_match_data(dev);
596+
if (!desc)
597+
return ERR_PTR(-ENODEV);
598+
599+
if (desc == &panel_dpi)
600+
return panel_dpi_probe(dev);
601+
602+
return desc;
603+
}
604+
605+
return ERR_PTR(-ENODEV);
606+
}
607+
608+
static struct panel_simple *panel_simple_probe(struct device *dev)
571609
{
610+
const struct panel_desc *desc;
572611
struct panel_simple *panel;
573612
struct display_timing dt;
574613
struct device_node *ddc;
575614
int connector_type;
576615
u32 bus_flags;
577616
int err;
578617

618+
desc = panel_simple_get_desc(dev);
619+
if (IS_ERR(desc))
620+
return ERR_CAST(desc);
621+
579622
panel = devm_drm_panel_alloc(dev, struct panel_simple, base,
580623
&panel_simple_funcs, desc->connector_type);
581624
if (IS_ERR(panel))
@@ -608,19 +651,9 @@ static struct panel_simple *panel_simple_probe(struct device *dev, const struct
608651
return ERR_PTR(-EPROBE_DEFER);
609652
}
610653

611-
if (desc == &panel_dpi) {
612-
/* Handle the generic panel-dpi binding */
613-
desc = panel_dpi_probe(dev);
614-
if (IS_ERR(desc)) {
615-
err = PTR_ERR(desc);
616-
goto free_ddc;
617-
}
618-
619-
panel->desc = desc;
620-
} else {
621-
if (!of_get_display_timing(dev->of_node, "panel-timing", &dt))
622-
panel_simple_parse_panel_timing_node(dev, panel, &dt);
623-
}
654+
if ((desc != &panel_dpi) &&
655+
!of_get_display_timing(dev->of_node, "panel-timing", &dt))
656+
panel_simple_parse_panel_timing_node(dev, panel, &dt);
624657

625658
if (desc->connector_type == DRM_MODE_CONNECTOR_LVDS) {
626659
/* Optional data-mapping property for overriding bus format */
@@ -5376,14 +5409,9 @@ MODULE_DEVICE_TABLE(of, platform_of_match);
53765409

53775410
static int panel_simple_platform_probe(struct platform_device *pdev)
53785411
{
5379-
const struct panel_desc *desc;
53805412
struct panel_simple *panel;
53815413

5382-
desc = of_device_get_match_data(&pdev->dev);
5383-
if (!desc)
5384-
return -ENODEV;
5385-
5386-
panel = panel_simple_probe(&pdev->dev, desc);
5414+
panel = panel_simple_probe(&pdev->dev);
53875415
if (IS_ERR(panel))
53885416
return PTR_ERR(panel);
53895417

@@ -5417,14 +5445,6 @@ static struct platform_driver panel_simple_platform_driver = {
54175445
.shutdown = panel_simple_platform_shutdown,
54185446
};
54195447

5420-
struct panel_desc_dsi {
5421-
struct panel_desc desc;
5422-
5423-
unsigned long flags;
5424-
enum mipi_dsi_pixel_format format;
5425-
unsigned int lanes;
5426-
};
5427-
54285448
static const struct drm_display_mode auo_b080uan01_mode = {
54295449
.clock = 154500,
54305450
.hdisplay = 1200,
@@ -5661,11 +5681,7 @@ static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
56615681
struct panel_simple *panel;
56625682
int err;
56635683

5664-
desc = of_device_get_match_data(&dsi->dev);
5665-
if (!desc)
5666-
return -ENODEV;
5667-
5668-
panel = panel_simple_probe(&dsi->dev, &desc->desc);
5684+
panel = panel_simple_probe(&dsi->dev);
56695685
if (IS_ERR(panel))
56705686
return PTR_ERR(panel);
56715687

0 commit comments

Comments
 (0)