Skip to content

Commit 48834e6

Browse files
dianderssravnborg
authored andcommitted
drm/panel-simple: Support hpd-gpios for delaying prepare()
People use panel-simple when they have panels that are builtin to their device. In these cases the HPD (Hot Plug Detect) signal isn't really used for hotplugging devices but instead is used for power sequencing. Panel timing diagrams (especially for eDP panels) usually have the HPD signal in them and it acts as an indicator that the panel is ready for us to talk to it. Sometimes the HPD signal is hooked up to a normal GPIO on a system. In this case we need to poll it in the correct place to know that the panel is ready for us. In some system designs the right place for this is panel-simple. When adding this support, we'll account for the case that there might be a circular dependency between panel-simple and the provider of the GPIO. The case this was designed for was for the "ti-sn65dsi86" bridge chip. If HPD is hooked up to one of the GPIOs provided by the bridge chip then in our probe function we'll always get back -EPROBE_DEFER. Let's handle this by allowing this GPIO to show up late if we saw -EPROBE_DEFER during probe. NOTE: since the gpio_get_optional() is used, if the "hpd-gpios" isn't there our variable will just be NULL and we won't do anything in prepare(). Signed-off-by: Douglas Anderson <[email protected]> Reviewed-by: Stephen Boyd <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Signed-off-by: Sam Ravnborg <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/20200507143354.v5.3.I53fed5b501a31e7a7fa13268ebcdd6b77bd0cadd@changeid
1 parent d252830 commit 48834e6

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <linux/delay.h>
2525
#include <linux/gpio/consumer.h>
26+
#include <linux/iopoll.h>
2627
#include <linux/module.h>
2728
#include <linux/of_platform.h>
2829
#include <linux/platform_device.h>
@@ -108,6 +109,7 @@ struct panel_simple {
108109
struct i2c_adapter *ddc;
109110

110111
struct gpio_desc *enable_gpio;
112+
struct gpio_desc *hpd_gpio;
111113

112114
struct drm_display_mode override_mode;
113115
};
@@ -259,11 +261,37 @@ static int panel_simple_unprepare(struct drm_panel *panel)
259261
return 0;
260262
}
261263

264+
static int panel_simple_get_hpd_gpio(struct device *dev,
265+
struct panel_simple *p, bool from_probe)
266+
{
267+
int err;
268+
269+
p->hpd_gpio = devm_gpiod_get_optional(dev, "hpd", GPIOD_IN);
270+
if (IS_ERR(p->hpd_gpio)) {
271+
err = PTR_ERR(p->hpd_gpio);
272+
273+
/*
274+
* If we're called from probe we won't consider '-EPROBE_DEFER'
275+
* to be an error--we'll leave the error code in "hpd_gpio".
276+
* When we try to use it we'll try again. This allows for
277+
* circular dependencies where the component providing the
278+
* hpd gpio needs the panel to init before probing.
279+
*/
280+
if (err != -EPROBE_DEFER || !from_probe) {
281+
dev_err(dev, "failed to get 'hpd' GPIO: %d\n", err);
282+
return err;
283+
}
284+
}
285+
286+
return 0;
287+
}
288+
262289
static int panel_simple_prepare(struct drm_panel *panel)
263290
{
264291
struct panel_simple *p = to_panel_simple(panel);
265292
unsigned int delay;
266293
int err;
294+
int hpd_asserted;
267295

268296
if (p->prepared)
269297
return 0;
@@ -282,6 +310,26 @@ static int panel_simple_prepare(struct drm_panel *panel)
282310
if (delay)
283311
msleep(delay);
284312

313+
if (p->hpd_gpio) {
314+
if (IS_ERR(p->hpd_gpio)) {
315+
err = panel_simple_get_hpd_gpio(panel->dev, p, false);
316+
if (err)
317+
return err;
318+
}
319+
320+
err = readx_poll_timeout(gpiod_get_value_cansleep, p->hpd_gpio,
321+
hpd_asserted, hpd_asserted,
322+
1000, 2000000);
323+
if (hpd_asserted < 0)
324+
err = hpd_asserted;
325+
326+
if (err) {
327+
dev_err(panel->dev,
328+
"error waiting for hpd GPIO: %d\n", err);
329+
return err;
330+
}
331+
}
332+
285333
p->prepared = true;
286334

287335
return 0;
@@ -462,6 +510,11 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
462510
panel->desc = desc;
463511

464512
panel->no_hpd = of_property_read_bool(dev->of_node, "no-hpd");
513+
if (!panel->no_hpd) {
514+
err = panel_simple_get_hpd_gpio(dev, panel, true);
515+
if (err)
516+
return err;
517+
}
465518

466519
panel->supply = devm_regulator_get(dev, "power");
467520
if (IS_ERR(panel->supply))

0 commit comments

Comments
 (0)