From patchwork Wed Nov 7 14:55:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Brezillon X-Patchwork-Id: 10672481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0024514E2 for ; Wed, 7 Nov 2018 14:56:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E34DB2BE02 for ; Wed, 7 Nov 2018 14:56:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D66C82BE0E; Wed, 7 Nov 2018 14:56:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 784562BE02 for ; Wed, 7 Nov 2018 14:56:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 294B989308; Wed, 7 Nov 2018 14:56:03 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail.bootlin.com (mail.bootlin.com [62.4.15.54]) by gabe.freedesktop.org (Postfix) with ESMTP id D3D0E89312 for ; Wed, 7 Nov 2018 14:56:01 +0000 (UTC) Received: by mail.bootlin.com (Postfix, from userid 110) id 0C8FE224E2; Wed, 7 Nov 2018 15:56:00 +0100 (CET) Received: from localhost.localdomain (aaubervilliers-681-1-93-44.w90-88.abo.wanadoo.fr [90.88.34.44]) by mail.bootlin.com (Postfix) with ESMTPSA id 9DB79224F5; Wed, 7 Nov 2018 15:55:27 +0100 (CET) From: Boris Brezillon To: Eric Anholt Subject: [PATCH v3] drm/panel: rpi-touchscreen: Set status to "fail" when detection fails Date: Wed, 7 Nov 2018 15:55:26 +0100 Message-Id: <20181107145526.4656-1-boris.brezillon@bootlin.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Boris Brezillon , Rob Herring , Thierry Reding , dri-devel@lists.freedesktop.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The device might be described in the device tree but not connected to the I2C bus. Update the status property so that the DRM panel logic returns -ENODEV when someone tries to get the panel attached to this DT node. Signed-off-by: Boris Brezillon Cc: Rob Herring Cc: Thierry Reding Cc: Daniel Vetter Cc: Eric Anholt --- Rob, Thierry, I know this v3 is not following your recommendations (propagate the error to the upper layer and let the code in drivers/{base,i2c}/ handle the reprobing of devices that previously returned EPROBE_DEFER and the deregistration of the device that has been marked disabled), but it addresses the problem Eric was trying to solve in a simple and non-invasive way. I'm all for a clean solution, but I also know this sort of rework is likely to take time, so I'd appreciate having this patch accepted first. Regards, Boris Changes in v3: - Do not return -ENODEV when the touchscree detection fails, so that the DRM driver can be probed again and detect that the panel status is "failed" Changes in v2: - New commit --- .../drm/panel/panel-raspberrypi-touchscreen.c | 46 +++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c index 2c9c9722734f..26b5576c07f9 100644 --- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c +++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c @@ -358,6 +358,39 @@ static const struct drm_panel_funcs rpi_touchscreen_funcs = { .get_modes = rpi_touchscreen_get_modes, }; +static void rpi_touchscreen_set_status_fail(struct i2c_client *i2c) +{ + struct property *newprop; + + newprop = kzalloc(sizeof(*newprop), GFP_KERNEL); + if (!newprop) + return; + + newprop->name = kstrdup("status", GFP_KERNEL); + if (!newprop->name) + goto err; + + newprop->value = kstrdup("fail", GFP_KERNEL); + if (!newprop->value) + goto err; + + newprop->length = sizeof("fail"); + + if (of_update_property(i2c->dev.of_node, newprop)) + goto err; + + /* We intentionally leak the memory we allocate here, because the new + * OF property might live longer than the underlying dev, so no way + * we can use devm_kzalloc() here. + */ + return; + +err: + kfree(newprop->value); + kfree(newprop->name); + kfree(newprop); +} + static int rpi_touchscreen_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { @@ -376,14 +409,13 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c, if (!ts) return -ENOMEM; - i2c_set_clientdata(i2c, ts); - ts->i2c = i2c; ver = rpi_touchscreen_i2c_read(ts, REG_ID); if (ver < 0) { + rpi_touchscreen_set_status_fail(i2c); dev_err(dev, "Atmel I2C read failed: %d\n", ver); - return -ENODEV; + return 0; } switch (ver) { @@ -391,10 +423,13 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c, case 0xc3: /* ver 2 */ break; default: + rpi_touchscreen_set_status_fail(i2c); dev_err(dev, "Unknown Atmel firmware revision: 0x%02x\n", ver); - return -ENODEV; + return 0; } + i2c_set_clientdata(i2c, ts); + /* Turn off at boot, so we can cleanly sequence powering on. */ rpi_touchscreen_i2c_write(ts, REG_POWERON, 0); @@ -435,6 +470,9 @@ static int rpi_touchscreen_remove(struct i2c_client *i2c) { struct rpi_touchscreen *ts = i2c_get_clientdata(i2c); + if (!ts) + return 0; + mipi_dsi_detach(ts->dsi); drm_panel_remove(&ts->base);