dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@bootlin.com>
To: Thierry Reding <thierry.reding@gmail.com>,
	dri-devel@lists.freedesktop.org
Cc: David Airlie <airlied@linux.ie>,
	Boris Brezillon <boris.brezillon@bootlin.com>
Subject: [RFC PATCH 3/3] drm/panel: rpi-touchscreen: Implement ->detect()
Date: Mon, 30 Apr 2018 16:43:23 +0200	[thread overview]
Message-ID: <20180430144323.9233-4-boris.brezillon@bootlin.com> (raw)
In-Reply-To: <20180430144323.9233-1-boris.brezillon@bootlin.com>

Implement a way to determine when the panel is connected. This is done
by reading REG_ID through I2C. We consider the panel as disconnect
until we retrieve a valid ID.

Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
---
 .../gpu/drm/panel/panel-raspberrypi-touchscreen.c  | 62 ++++++++++++++++++----
 1 file changed, 53 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
index d964d454e4ae..e65caec590d4 100644
--- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
+++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
@@ -196,6 +196,7 @@ struct rpi_touchscreen {
 	struct drm_panel base;
 	struct mipi_dsi_device *dsi;
 	struct i2c_client *i2c;
+	bool connected;
 };
 
 static const struct drm_display_mode rpi_touchscreen_modes[] = {
@@ -255,6 +256,9 @@ static int rpi_touchscreen_write(struct rpi_touchscreen *ts, u16 reg, u32 val)
 
 	mipi_dsi_dcs_write_buffer(ts->dsi, msg, sizeof(msg));
 #else
+	if (!ts->connected)
+		return 0;
+
 	rpi_touchscreen_i2c_write(ts, REG_WR_ADDRH, reg >> 8);
 	rpi_touchscreen_i2c_write(ts, REG_WR_ADDRL, reg);
 	rpi_touchscreen_i2c_write(ts, REG_WRITEH, val >> 8);
@@ -268,6 +272,9 @@ static int rpi_touchscreen_disable(struct drm_panel *panel)
 {
 	struct rpi_touchscreen *ts = panel_to_ts(panel);
 
+	if (!ts->connected)
+		return 0;
+
 	rpi_touchscreen_i2c_write(ts, REG_PWM, 0);
 
 	rpi_touchscreen_i2c_write(ts, REG_POWERON, 0);
@@ -286,6 +293,9 @@ static int rpi_touchscreen_enable(struct drm_panel *panel)
 	struct rpi_touchscreen *ts = panel_to_ts(panel);
 	int i;
 
+	if (!ts->connected)
+		return 0;
+
 	rpi_touchscreen_i2c_write(ts, REG_POWERON, 1);
 	/* Wait for nPWRDWN to go low to indicate poweron is done. */
 	for (i = 0; i < 100; i++) {
@@ -330,6 +340,10 @@ static int rpi_touchscreen_get_modes(struct drm_panel *panel)
 	struct drm_device *drm = panel->drm;
 	unsigned int i, num = 0;
 	static const u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24;
+	struct rpi_touchscreen *ts = panel_to_ts(panel);
+
+	if (!ts->connected)
+		return 0;
 
 	for (i = 0; i < ARRAY_SIZE(rpi_touchscreen_modes); i++) {
 		const struct drm_display_mode *m = &rpi_touchscreen_modes[i];
@@ -362,7 +376,34 @@ static int rpi_touchscreen_get_modes(struct drm_panel *panel)
 	return num;
 }
 
+static int rpi_touchscreen_detect(struct drm_panel *panel)
+{
+	struct rpi_touchscreen *ts = panel_to_ts(panel);
+	int ver;
+
+	if (ts->connected)
+		return connector_status_connected;
+
+	ver = rpi_touchscreen_i2c_read(ts, REG_ID);
+	switch (ver) {
+	case 0xde: /* ver 1 */
+	case 0xc3: /* ver 2 */
+		ts->connected = true;
+
+		/* Turn off at boot, so we can cleanly sequence powering on. */
+		rpi_touchscreen_i2c_write(ts, REG_POWERON, 0);
+
+		return connector_status_connected;
+
+	default:
+		break;
+	}
+
+	return connector_status_disconnected;
+}
+
 static const struct drm_panel_funcs rpi_touchscreen_funcs = {
+	.detect = rpi_touchscreen_detect,
 	.disable = rpi_touchscreen_disable,
 	.unprepare = rpi_touchscreen_noop,
 	.prepare = rpi_touchscreen_noop,
@@ -393,22 +434,24 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c,
 	ts->i2c = i2c;
 
 	ver = rpi_touchscreen_i2c_read(ts, REG_ID);
-	if (ver < 0) {
-		dev_err(dev, "Atmel I2C read failed: %d\n", ver);
-		return -ENODEV;
-	}
-
 	switch (ver) {
 	case 0xde: /* ver 1 */
 	case 0xc3: /* ver 2 */
+		ts->connected = true;
+
+		/* Turn off at boot, so we can cleanly sequence powering on. */
+		rpi_touchscreen_i2c_write(ts, REG_POWERON, 0);
 		break;
 	default:
-		dev_err(dev, "Unknown Atmel firmware revision: 0x%02x\n", ver);
-		return -ENODEV;
+		if (ver < 0)
+			dev_err(dev, "Atmel I2C read failed: %d\n", ver);
+		else
+			dev_err(dev,
+				"Unknown Atmel firmware revision: 0x%02x\n",
+				ver);
+		break;
 	}
 
-	/* Turn off at boot, so we can cleanly sequence powering on. */
-	rpi_touchscreen_i2c_write(ts, REG_POWERON, 0);
 
 	/* Look up the DSI host.  It needs to probe before we do. */
 	endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
@@ -432,6 +475,7 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c,
 
 	ts->base.dev = dev;
 	ts->base.funcs = &rpi_touchscreen_funcs;
+	ts->base.polled = DRM_CONNECTOR_POLL_CONNECT;
 
 	/* This appears last, as it's what will unblock the DSI host
 	 * driver's component bind function.
-- 
2.14.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2018-04-30 14:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-30 14:43 [RFC PATCH 0/3] drm/panel: Support panel detection Boris Brezillon
2018-04-30 14:43 ` [RFC PATCH 1/3] " Boris Brezillon
2018-04-30 16:08   ` Daniel Vetter
2018-04-30 16:34     ` Boris Brezillon
2018-04-30 14:43 ` [RFC PATCH 2/3] drm/bridge: panel: Make use of the panel detection infrastructure Boris Brezillon
2018-04-30 14:43 ` Boris Brezillon [this message]
2018-04-30 17:22 ` [RFC PATCH 0/3] drm/panel: Support panel detection Eric Anholt
2018-04-30 17:43   ` Boris Brezillon
2018-04-30 19:48     ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180430144323.9233-4-boris.brezillon@bootlin.com \
    --to=boris.brezillon@bootlin.com \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox