2019-05-15 13:14:00

by Benjamin GAIGNARD

[permalink] [raw]
Subject: [PATCH v2 0/5] Add of_device_link_add() functions

It may happen that we need to ensure the order of suspend/resume
calls between two devices without obvious link.
It is for example the case on some boards where both panel and touchscreen
are sharing the same reset line. In this case we need to control which
device is going in resume first to do only one reset.
An other example is make sure that GPU is suspend before composition
hardware block to avoid pending drawing requests.

To not let everybody creating relationship between devices for free
of_device_links_add() has to be called by each driver and not in the core.

version 2:
- only keep of_device_links_add() and use
DL_FLAG_PM_RUNTIME and DL_FLAG_AUTOREMOVE_CONSUMER flags to follow Rafael
advices
- reword function description
- try to use a more explicit property name
- rebase on v5.1

Benjamin Gaignard (5):
of/device: Add of_device_link_add function
Input: edt-ft5x06: Document suspend-dependencies property
input: edt-ft5x06 - Call of_device_links_add() to create links
Input: goodix: Document suspend-dependencies property
input: goodix - Call of_device_links_add() to create links

.../bindings/input/touchscreen/edt-ft5x06.txt | 2 ++
.../bindings/input/touchscreen/goodix.txt | 2 ++
drivers/input/touchscreen/edt-ft5x06.c | 2 ++
drivers/input/touchscreen/goodix.c | 3 ++
drivers/of/device.c | 37 ++++++++++++++++++++++
include/linux/of_device.h | 7 ++++
6 files changed, 53 insertions(+)

--
2.15.0


2019-05-15 13:14:08

by Benjamin GAIGNARD

[permalink] [raw]
Subject: [PATCH v2 3/5] input: edt-ft5x06 - Call of_device_links_add() to create links

Add a call to of_device_links_add() to create links with suspend
dependencies at probe time.

Signed-off-by: Benjamin Gaignard <[email protected]>
---
drivers/input/touchscreen/edt-ft5x06.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
index 702bfda7ee77..65053be10d4e 100644
--- a/drivers/input/touchscreen/edt-ft5x06.c
+++ b/drivers/input/touchscreen/edt-ft5x06.c
@@ -1167,6 +1167,8 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,

i2c_set_clientdata(client, tsdata);

+ of_device_links_add(&client->dev);
+
irq_flags = irq_get_trigger_type(client->irq);
if (irq_flags == IRQF_TRIGGER_NONE)
irq_flags = IRQF_TRIGGER_FALLING;
--
2.15.0

2019-05-15 13:14:43

by Benjamin GAIGNARD

[permalink] [raw]
Subject: [PATCH v2 1/5] of/device: Add of_device_link_add function

Use 'suspend-dependencies' property from device node to ensure that
the listed devices will suspended after it and resumed before it.

Signed-off-by: Benjamin Gaignard <[email protected]>
---
CC: Rafael J. Wysocki <[email protected]>
version 2:
- only keep of_device_links_add() and use
DL_FLAG_PM_RUNTIME and DL_FLAG_AUTOREMOVE_CONSUMER flags to follow Rafael
advices
- reword function description
- try to use a more explicit property name

drivers/of/device.c | 37 +++++++++++++++++++++++++++++++++++++
include/linux/of_device.h | 7 +++++++
2 files changed, 44 insertions(+)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index 3717f2a20d0d..44ec84eee310 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -336,3 +336,40 @@ int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
return 0;
}
EXPORT_SYMBOL_GPL(of_device_uevent_modalias);
+
+/**
+ * of_device_links_add - Create links between a consumer device
+ * and it listed dependencies from device tree data
+ *
+ * @consumer: consumer device
+ *
+ * Ensure that consumer's dependencies will be suspended after it
+ * and resumed before it.
+ *
+ * Returns 0 on success, < 0 on failure.
+ */
+int of_device_links_add(struct device *consumer)
+{
+ struct device_node *np;
+ struct platform_device *pdev;
+ int i = 0;
+
+ np = of_parse_phandle(consumer->of_node, "suspend-dependencies", i++);
+ while (np) {
+ pdev = of_find_device_by_node(np);
+ of_node_put(np);
+ if (!pdev)
+ return -EINVAL;
+
+ device_link_add(consumer, &pdev->dev,
+ DL_FLAG_PM_RUNTIME |
+ DL_FLAG_AUTOREMOVE_CONSUMER);
+ platform_device_put(pdev);
+
+ np = of_parse_phandle(consumer->of_node, "suspend-dependencies",
+ i++);
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_device_links_add);
diff --git a/include/linux/of_device.h b/include/linux/of_device.h
index 8d31e39dd564..83f24c386d51 100644
--- a/include/linux/of_device.h
+++ b/include/linux/of_device.h
@@ -41,6 +41,8 @@ extern int of_device_request_module(struct device *dev);
extern void of_device_uevent(struct device *dev, struct kobj_uevent_env *env);
extern int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env);

+extern int of_device_links_add(struct device *consumer);
+
static inline void of_device_node_put(struct device *dev)
{
of_node_put(dev->of_node);
@@ -91,6 +93,11 @@ static inline int of_device_uevent_modalias(struct device *dev,
return -ENODEV;
}

+static int of_device_links_add(struct device *consumer)
+{
+ return 0;
+}
+
static inline void of_device_node_put(struct device *dev) { }

static inline const struct of_device_id *__of_match_device(
--
2.15.0

2019-05-15 13:14:52

by Benjamin GAIGNARD

[permalink] [raw]
Subject: [PATCH v2 5/5] input: goodix - Call of_device_links_add() to create links

Add a call to of_device_links_add() to create links with
suspend dependencies at probe time.

Signed-off-by: Benjamin Gaignard <[email protected]>
---
drivers/input/touchscreen/goodix.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c
index f57d82220a88..49fd4763f17b 100644
--- a/drivers/input/touchscreen/goodix.c
+++ b/drivers/input/touchscreen/goodix.c
@@ -30,6 +30,7 @@
#include <linux/slab.h>
#include <linux/acpi.h>
#include <linux/of.h>
+#include <linux/of_device.h>
#include <asm/unaligned.h>

struct goodix_ts_data;
@@ -812,6 +813,8 @@ static int goodix_ts_probe(struct i2c_client *client,

ts->chip = goodix_get_chip_data(ts->id);

+ of_device_links_add(&client->dev);
+
if (ts->gpiod_int && ts->gpiod_rst) {
/* update device config */
ts->cfg_name = devm_kasprintf(&client->dev, GFP_KERNEL,
--
2.15.0

2019-05-15 13:15:29

by Benjamin GAIGNARD

[permalink] [raw]
Subject: [PATCH v2 4/5] Input: goodix: Document suspend-dependencies property

Explain the purpose of suspend-dependencies property.

Signed-off-by: Benjamin Gaignard <[email protected]>
---
Documentation/devicetree/bindings/input/touchscreen/goodix.txt | 2 ++
1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/goodix.txt b/Documentation/devicetree/bindings/input/touchscreen/goodix.txt
index 8cf0b4d38a7e..5527952054d2 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/goodix.txt
+++ b/Documentation/devicetree/bindings/input/touchscreen/goodix.txt
@@ -24,6 +24,8 @@ Optional properties:
- touchscreen-size-x
- touchscreen-size-y
- touchscreen-swapped-x-y
+ - suspend-dependencies : Phandle list of devices which have to be suspended
+ after goodix device and resumed before it.

The touchscreen-* properties are documented in touchscreen.txt in this
directory.
--
2.15.0