[PATCH v2 6/6] drm/panel: rpi-touchscreen: Set status to "fail" when ->probe() fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <boris.brezillon@xxxxxxxxxxx>
---
 .../gpu/drm/panel/panel-raspberrypi-touchscreen.c  | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
index 2c9c9722734f..b8fcb1acef75 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)
 {
@@ -382,6 +415,7 @@ static int rpi_touchscreen_probe(struct i2c_client *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;
 	}
@@ -391,6 +425,7 @@ 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;
 	}
-- 
2.14.1

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




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux