All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V3 0/8] drivers: Boot Constraints core
@ 2017-08-01  9:23 ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Viresh Kumar, Vincent Guittot, Mark Brown, Stephen Boyd,
	Rajendra Nayak, Shiraz Hashim, linux-kernel, linux-arm-kernel,
	robdclark, Jonathan Corbet, linux-doc

Hi Greg,

Here is V3 of the boot constraints core based on the feedbacks I have
received during V2. This tested on real hardware (Qcom dragonboard 410c)
with a display controller configured from bootloader to display a flash
screen. Obviously it doesn't work seamlessly without this series and
works just fine with it. Rajendra Nayak helped getting this tested on
Qcom hardware.

Problem statement:

Some devices are powered ON by the bootloader before the bootloader
handovers control to Linux. It maybe important for those devices to keep
working until the time a Linux device driver probes the device and
reconfigure its resources.

A typical example of that can be the LCD controller, which is used by
the bootloaders to show image(s) while the platform is booting into
Linux.  The LCD controller can be using some resources, like clk,
regulators, etc, that are shared between several devices. These shared
resources should be configured to satisfy need of all the users.  If
another device's (X) driver gets probed before the LCD controller driver
in this case, then it may end up reconfiguring these resources to ranges
satisfying the current users (only device X) and that can make the LCD
screen unstable.

Of course we can have more complex cases where the same resource is
getting used by two devices while the kernel boots and the order in
which devices get probed wouldn't matter as the other device will surely
break then.

There are also cases where the resources may not be shared, but the
kernel will disable them forcefully as no users may have appeared until
a certain point in kernel boot. This makes sure that the resources stay
enabled. A wide variety of constraints can be satisfied using the new
framework.

Proposed solution:

This patchset introduces the concept of boot-constraints, which are set
by platform specific drivers (for now at least) at early init (like
subsys_initcall) and the kernel will satisfy them until the time driver
for such a device is probed (successfully or unsuccessfully). Once the
driver is probed, the driver core removes the constraints set for the
device. This series implements clk, regulator and PM domain constraints
for now.

The last patch isn't up for merge yet, and is used to test the boot
constraint framework on Qcom 410c along with some of the display
controller patches from Rob's series [1] to make sure the controller's
registers are configured properly.

Rebased over: drivers/driver-core-next (some debugfs dependencies)
Pushed here: git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/linux.git device/boot-constraints

V2->V3:
- Removed DT support as we aren't sure about how to define the bindings
  yet.
- Added CLK and PM domain constraint types.
- A new directory is added for boot constraints, which will also contain
  platform specific drivers in future.
- Deferred devices are still supported, just that it wouldn't be called
  from generic code anymore but platform specific code.
- Tested on Qcom 410c dragonboard with display flash screen (Rajendra).
- Usual renaming/commit-log-updates/etc changes done.

V1->V2:
- Add support for setting constraints for devices created from DT.
- Allow handling deferred devices earlier then late_init.
- Remove 'default y' line from kconfig.
- Drop '=" after boot_constraints_disable kernel param.
- Dropped the dummy testing patch now.

--
viresh

[1] https://marc.info/?l=dri-devel&m=149979722606563&w=2

Rajendra Nayak (1):
  drivers: boot_constraint: Add Qualcomm display controller constraints

Viresh Kumar (7):
  drivers: Add boot constraints core
  drivers: boot_constraint: Add boot_constraints_disable kernel
    parameter
  drivers: boot_constraint: Add support for supply constraints
  drivers: boot_constraint: Add support for clk constraints
  drivers: boot_constraint: Add support for PM constraints
  drivers: boot_constraint: Add debugfs support
  drivers: boot_constraint: Manage deferrable constraints

 Documentation/admin-guide/kernel-parameters.txt |   3 +
 drivers/base/Kconfig                            |  10 +
 drivers/base/Makefile                           |   1 +
 drivers/base/base.h                             |   1 +
 drivers/base/boot_constraints/Makefile          |   3 +
 drivers/base/boot_constraints/clk.c             |  74 ++++++
 drivers/base/boot_constraints/core.c            | 300 ++++++++++++++++++++++++
 drivers/base/boot_constraints/core.h            |  50 ++++
 drivers/base/boot_constraints/deferrable_dev.c  | 192 +++++++++++++++
 drivers/base/boot_constraints/pm.c              |  32 +++
 drivers/base/boot_constraints/qcom-display.c    | 107 +++++++++
 drivers/base/boot_constraints/supply.c          | 108 +++++++++
 drivers/base/dd.c                               |  32 ++-
 include/linux/boot_constraint.h                 |  68 ++++++
 14 files changed, 974 insertions(+), 7 deletions(-)
 create mode 100644 drivers/base/boot_constraints/Makefile
 create mode 100644 drivers/base/boot_constraints/clk.c
 create mode 100644 drivers/base/boot_constraints/core.c
 create mode 100644 drivers/base/boot_constraints/core.h
 create mode 100644 drivers/base/boot_constraints/deferrable_dev.c
 create mode 100644 drivers/base/boot_constraints/pm.c
 create mode 100644 drivers/base/boot_constraints/qcom-display.c
 create mode 100644 drivers/base/boot_constraints/supply.c
 create mode 100644 include/linux/boot_constraint.h

-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 0/8] drivers: Boot Constraints core
@ 2017-08-01  9:23 ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Greg,

Here is V3 of the boot constraints core based on the feedbacks I have
received during V2. This tested on real hardware (Qcom dragonboard 410c)
with a display controller configured from bootloader to display a flash
screen. Obviously it doesn't work seamlessly without this series and
works just fine with it. Rajendra Nayak helped getting this tested on
Qcom hardware.

Problem statement:

Some devices are powered ON by the bootloader before the bootloader
handovers control to Linux. It maybe important for those devices to keep
working until the time a Linux device driver probes the device and
reconfigure its resources.

A typical example of that can be the LCD controller, which is used by
the bootloaders to show image(s) while the platform is booting into
Linux.  The LCD controller can be using some resources, like clk,
regulators, etc, that are shared between several devices. These shared
resources should be configured to satisfy need of all the users.  If
another device's (X) driver gets probed before the LCD controller driver
in this case, then it may end up reconfiguring these resources to ranges
satisfying the current users (only device X) and that can make the LCD
screen unstable.

Of course we can have more complex cases where the same resource is
getting used by two devices while the kernel boots and the order in
which devices get probed wouldn't matter as the other device will surely
break then.

There are also cases where the resources may not be shared, but the
kernel will disable them forcefully as no users may have appeared until
a certain point in kernel boot. This makes sure that the resources stay
enabled. A wide variety of constraints can be satisfied using the new
framework.

Proposed solution:

This patchset introduces the concept of boot-constraints, which are set
by platform specific drivers (for now at least) at early init (like
subsys_initcall) and the kernel will satisfy them until the time driver
for such a device is probed (successfully or unsuccessfully). Once the
driver is probed, the driver core removes the constraints set for the
device. This series implements clk, regulator and PM domain constraints
for now.

The last patch isn't up for merge yet, and is used to test the boot
constraint framework on Qcom 410c along with some of the display
controller patches from Rob's series [1] to make sure the controller's
registers are configured properly.

Rebased over: drivers/driver-core-next (some debugfs dependencies)
Pushed here: git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/linux.git device/boot-constraints

V2->V3:
- Removed DT support as we aren't sure about how to define the bindings
  yet.
- Added CLK and PM domain constraint types.
- A new directory is added for boot constraints, which will also contain
  platform specific drivers in future.
- Deferred devices are still supported, just that it wouldn't be called
  from generic code anymore but platform specific code.
- Tested on Qcom 410c dragonboard with display flash screen (Rajendra).
- Usual renaming/commit-log-updates/etc changes done.

V1->V2:
- Add support for setting constraints for devices created from DT.
- Allow handling deferred devices earlier then late_init.
- Remove 'default y' line from kconfig.
- Drop '=" after boot_constraints_disable kernel param.
- Dropped the dummy testing patch now.

--
viresh

[1] https://marc.info/?l=dri-devel&m=149979722606563&w=2

Rajendra Nayak (1):
  drivers: boot_constraint: Add Qualcomm display controller constraints

Viresh Kumar (7):
  drivers: Add boot constraints core
  drivers: boot_constraint: Add boot_constraints_disable kernel
    parameter
  drivers: boot_constraint: Add support for supply constraints
  drivers: boot_constraint: Add support for clk constraints
  drivers: boot_constraint: Add support for PM constraints
  drivers: boot_constraint: Add debugfs support
  drivers: boot_constraint: Manage deferrable constraints

 Documentation/admin-guide/kernel-parameters.txt |   3 +
 drivers/base/Kconfig                            |  10 +
 drivers/base/Makefile                           |   1 +
 drivers/base/base.h                             |   1 +
 drivers/base/boot_constraints/Makefile          |   3 +
 drivers/base/boot_constraints/clk.c             |  74 ++++++
 drivers/base/boot_constraints/core.c            | 300 ++++++++++++++++++++++++
 drivers/base/boot_constraints/core.h            |  50 ++++
 drivers/base/boot_constraints/deferrable_dev.c  | 192 +++++++++++++++
 drivers/base/boot_constraints/pm.c              |  32 +++
 drivers/base/boot_constraints/qcom-display.c    | 107 +++++++++
 drivers/base/boot_constraints/supply.c          | 108 +++++++++
 drivers/base/dd.c                               |  32 ++-
 include/linux/boot_constraint.h                 |  68 ++++++
 14 files changed, 974 insertions(+), 7 deletions(-)
 create mode 100644 drivers/base/boot_constraints/Makefile
 create mode 100644 drivers/base/boot_constraints/clk.c
 create mode 100644 drivers/base/boot_constraints/core.c
 create mode 100644 drivers/base/boot_constraints/core.h
 create mode 100644 drivers/base/boot_constraints/deferrable_dev.c
 create mode 100644 drivers/base/boot_constraints/pm.c
 create mode 100644 drivers/base/boot_constraints/qcom-display.c
 create mode 100644 drivers/base/boot_constraints/supply.c
 create mode 100644 include/linux/boot_constraint.h

-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 1/8] drivers: Add boot constraints core
  2017-08-01  9:23 ` Viresh Kumar
@ 2017-08-01  9:23   ` Viresh Kumar
  -1 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Viresh Kumar, Vincent Guittot, Mark Brown, Stephen Boyd,
	Rajendra Nayak, Shiraz Hashim, linux-kernel, linux-arm-kernel,
	robdclark

Some devices are powered ON by the bootloader before the bootloader
handovers control to Linux. It maybe important for those devices to keep
working until the time a Linux device driver probes the device and
reconfigure its resources.

A typical example of that can be the LCD controller, which is used by
the bootloaders to show image(s) while the platform is booting into
Linux. The LCD controller can be using some resources, like clk,
regulators, PM domain, etc, that are shared between several devices.
These shared resources should be configured to satisfy need of all the
users. If another device's (X) driver gets probed before the LCD
controller driver in this case, then it may end up reconfiguring these
resources to ranges satisfying the current users (only device X) and
that can make the LCD screen unstable.

This patch introduces the concept of boot-constraints, which will be set
by the bootloaders and the kernel will satisfy them until the time
driver for such a device is probed (successfully or unsuccessfully).

The list of boot constraint types is empty for now, and will be
incrementally updated by later patches.

Only two routines are exposed by the boot constraints core for now:

- dev_boot_constraint_add(): This shall be called by parts of the kernel
  (before the device is probed) to set the constraints.

- dev_boot_constraints_remove(): This is called only by the driver core
  after a device is probed successfully or unsuccessfully. Special
  handling is done here for deffered probing.

Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/Kconfig                   |  10 ++
 drivers/base/Makefile                  |   1 +
 drivers/base/boot_constraints/Makefile |   3 +
 drivers/base/boot_constraints/core.c   | 199 +++++++++++++++++++++++++++++++++
 drivers/base/boot_constraints/core.h   |  33 ++++++
 drivers/base/dd.c                      |  20 ++--
 include/linux/boot_constraint.h        |  46 ++++++++
 7 files changed, 305 insertions(+), 7 deletions(-)
 create mode 100644 drivers/base/boot_constraints/Makefile
 create mode 100644 drivers/base/boot_constraints/core.c
 create mode 100644 drivers/base/boot_constraints/core.h
 create mode 100644 include/linux/boot_constraint.h

diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index f046d21de57d..2333db2a33b7 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -347,4 +347,14 @@ config GENERIC_ARCH_TOPOLOGY
 	  appropriate scaling, sysfs interface for changing capacity values at
 	  runtime.
 
+config DEV_BOOT_CONSTRAINTS
+	bool "Boot constraints for devices"
+	help
+	  This enables boot constraints detection for devices. These constraints
+	  are (normally) set by the Bootloader and must be satisfied by the
+	  kernel until the relevant device driver is probed. Once the driver is
+	  probed, the constraint is dropped.
+
+	  If unsure, say N.
+
 endmenu
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 397e5c344e6a..8c37ca07114b 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -5,6 +5,7 @@ obj-y			:= component.o core.o bus.o dd.o syscore.o \
 			   cpu.o firmware.o init.o map.o devres.o \
 			   attribute_container.o transport_class.o \
 			   topology.o container.o property.o cacheinfo.o
+obj-$(CONFIG_DEV_BOOT_CONSTRAINTS) += boot_constraints/
 obj-$(CONFIG_DEVTMPFS)	+= devtmpfs.o
 obj-$(CONFIG_DMA_CMA) += dma-contiguous.o
 obj-y			+= power/
diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile
new file mode 100644
index 000000000000..0f2680177974
--- /dev/null
+++ b/drivers/base/boot_constraints/Makefile
@@ -0,0 +1,3 @@
+# Makefile for device boot constraints
+
+obj-y := core.o
diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
new file mode 100644
index 000000000000..366a05d6d9ba
--- /dev/null
+++ b/drivers/base/boot_constraints/core.c
@@ -0,0 +1,199 @@
+/*
+ * This takes care of boot time device constraints, normally set by the
+ * Bootloader.
+ *
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * This file is released under the GPLv2.
+ */
+
+#define pr_fmt(fmt) "Boot Constraints: " fmt
+
+#include <linux/err.h>
+#include <linux/export.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+
+#include "core.h"
+
+#define for_each_constraint(_constraint, _temp, _cdev)		\
+	list_for_each_entry_safe(_constraint, _temp, &_cdev->constraints, node)
+
+/* Global list of all constraint devices currently registered */
+static LIST_HEAD(constraint_devices);
+static DEFINE_MUTEX(constraint_devices_mutex);
+
+/* Boot constraints core */
+
+static struct constraint_dev *constraint_device_find(struct device *dev)
+{
+	struct constraint_dev *cdev;
+
+	list_for_each_entry(cdev, &constraint_devices, node) {
+		if (cdev->dev == dev)
+			return cdev;
+	}
+
+	return NULL;
+}
+
+static struct constraint_dev *constraint_device_allocate(struct device *dev)
+{
+	struct constraint_dev *cdev;
+
+	cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
+	if (!cdev)
+		return ERR_PTR(-ENOMEM);
+
+	cdev->dev = dev;
+	INIT_LIST_HEAD(&cdev->node);
+	INIT_LIST_HEAD(&cdev->constraints);
+
+	list_add(&cdev->node, &constraint_devices);
+
+	return cdev;
+}
+
+static void constraint_device_free(struct constraint_dev *cdev)
+{
+	list_del(&cdev->node);
+	kfree(cdev);
+}
+
+static struct constraint_dev *constraint_device_get(struct device *dev)
+{
+	struct constraint_dev *cdev;
+
+	cdev = constraint_device_find(dev);
+	if (cdev)
+		return cdev;
+
+	cdev = constraint_device_allocate(dev);
+	if (IS_ERR(cdev)) {
+		dev_err(dev, "Failed to add constraint dev (%ld)\n",
+			PTR_ERR(cdev));
+	}
+
+	return cdev;
+}
+
+static void constraint_device_put(struct constraint_dev *cdev)
+{
+	if (!list_empty(&cdev->constraints))
+		return;
+
+	constraint_device_free(cdev);
+}
+
+static struct constraint *constraint_allocate(struct constraint_dev *cdev,
+					enum dev_boot_constraint_type type)
+{
+	struct constraint *constraint;
+	int (*add)(struct constraint *constraint, void *data);
+	void (*remove)(struct constraint *constraint);
+
+	switch (type) {
+	default:
+		return ERR_PTR(-EINVAL);
+	}
+
+	constraint = kzalloc(sizeof(*constraint), GFP_KERNEL);
+	if (!constraint)
+		return ERR_PTR(-ENOMEM);
+
+	constraint->cdev = cdev;
+	constraint->type = type;
+	constraint->add = add;
+	constraint->remove = remove;
+	INIT_LIST_HEAD(&constraint->node);
+
+	list_add(&constraint->node, &cdev->constraints);
+
+	return constraint;
+}
+
+static void constraint_free(struct constraint *constraint)
+{
+	list_del(&constraint->node);
+	kfree(constraint);
+}
+
+int dev_boot_constraint_add(struct device *dev,
+			    struct dev_boot_constraint_info *info)
+{
+	struct constraint_dev *cdev;
+	struct constraint *constraint;
+	int ret;
+
+	mutex_lock(&constraint_devices_mutex);
+
+	/* Find or add the cdev type first */
+	cdev = constraint_device_get(dev);
+	if (IS_ERR(cdev)) {
+		ret = PTR_ERR(cdev);
+		goto unlock;
+	}
+
+	constraint = constraint_allocate(cdev, info->constraint.type);
+	if (IS_ERR(constraint)) {
+		dev_err(dev, "Failed to add constraint type: %d (%ld)\n",
+			info->constraint.type, PTR_ERR(constraint));
+		ret = PTR_ERR(constraint);
+		goto put_cdev;
+	}
+
+	constraint->free_resources = info->free_resources;
+	constraint->free_resources_data = info->free_resources_data;
+
+	/* Set constraint */
+	ret = constraint->add(constraint, info->constraint.data);
+	if (ret)
+		goto free_constraint;
+
+	dev_dbg(dev, "Added boot constraint-type (%d)\n",
+		info->constraint.type);
+
+	mutex_unlock(&constraint_devices_mutex);
+
+	return 0;
+
+free_constraint:
+	constraint_free(constraint);
+put_cdev:
+	constraint_device_put(cdev);
+unlock:
+	mutex_unlock(&constraint_devices_mutex);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(dev_boot_constraint_add);
+
+static void constraint_remove(struct constraint *constraint)
+{
+	constraint->remove(constraint);
+
+	if (constraint->free_resources)
+		constraint->free_resources(constraint->free_resources_data);
+
+	constraint_free(constraint);
+}
+
+void dev_boot_constraints_remove(struct device *dev)
+{
+	struct constraint_dev *cdev;
+	struct constraint *constraint, *temp;
+
+	mutex_lock(&constraint_devices_mutex);
+
+	cdev = constraint_device_find(dev);
+	if (!cdev)
+		goto unlock;
+
+	for_each_constraint(constraint, temp, cdev)
+		constraint_remove(constraint);
+
+	constraint_device_put(cdev);
+unlock:
+	mutex_unlock(&constraint_devices_mutex);
+}
diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h
new file mode 100644
index 000000000000..7ba4ac172c09
--- /dev/null
+++ b/drivers/base/boot_constraints/core.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * This file is released under the GPLv2.
+ */
+#ifndef _CORE_H
+#define _CORE_H
+
+#include <linux/boot_constraint.h>
+#include <linux/device.h>
+#include <linux/list.h>
+
+struct constraint_dev {
+	struct device *dev;
+	struct list_head node;
+	struct list_head constraints;
+};
+
+struct constraint {
+	struct constraint_dev *cdev;
+	struct list_head node;
+	enum dev_boot_constraint_type type;
+	void (*free_resources)(void *data);
+	void *free_resources_data;
+
+	int (*add)(struct constraint *constraint, void *data);
+	void (*remove)(struct constraint *constraint);
+	void *private;
+};
+
+/* Forward declarations of constraint specific callbacks */
+#endif /* _CORE_H */
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index c17fefc77345..2262a4a4c0e4 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -17,6 +17,7 @@
  * This file is released under the GPLv2
  */
 
+#include <linux/boot_constraint.h>
 #include <linux/device.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
@@ -383,15 +384,20 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 	 */
 	devices_kset_move_last(dev);
 
-	if (dev->bus->probe) {
+	if (dev->bus->probe)
 		ret = dev->bus->probe(dev);
-		if (ret)
-			goto probe_failed;
-	} else if (drv->probe) {
+	else if (drv->probe)
 		ret = drv->probe(dev);
-		if (ret)
-			goto probe_failed;
-	}
+
+	/*
+	 * Remove boot constraints for both successful and unsuccessful probe(),
+	 * except for the case where EPROBE_DEFER is returned by probe().
+	 */
+	if (ret != -EPROBE_DEFER)
+		dev_boot_constraints_remove(dev);
+
+	if (ret)
+		goto probe_failed;
 
 	if (test_remove) {
 		test_remove = false;
diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h
new file mode 100644
index 000000000000..ae34fee547c5
--- /dev/null
+++ b/include/linux/boot_constraint.h
@@ -0,0 +1,46 @@
+/*
+ * Boot constraints header.
+ *
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * This file is released under the GPLv2
+ */
+#ifndef _LINUX_BOOT_CONSTRAINT_H
+#define _LINUX_BOOT_CONSTRAINT_H
+
+#include <linux/err.h>
+#include <linux/types.h>
+
+struct device;
+
+enum dev_boot_constraint_type {
+	DEV_BOOT_CONSTRAINT_NONE,
+};
+
+struct dev_boot_constraint {
+	enum dev_boot_constraint_type type;
+	void *data;
+};
+
+struct dev_boot_constraint_info {
+	struct dev_boot_constraint constraint;
+
+	/* This will be called just before the constraint is removed */
+	void (*free_resources)(void *data);
+	void *free_resources_data;
+};
+
+#ifdef CONFIG_DEV_BOOT_CONSTRAINTS
+int dev_boot_constraint_add(struct device *dev,
+			    struct dev_boot_constraint_info *info);
+void dev_boot_constraints_remove(struct device *dev);
+#else
+static inline
+int dev_boot_constraint_add(struct device *dev,
+			    struct dev_boot_constraint_info *info);
+{ return -EINVAL; }
+static inline void dev_boot_constraints_remove(struct device *dev) {}
+#endif /* CONFIG_DEV_BOOT_CONSTRAINTS */
+
+#endif /* _LINUX_BOOT_CONSTRAINT_H */
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH V3 1/8] drivers: Add boot constraints core
@ 2017-08-01  9:23   ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: linux-arm-kernel

Some devices are powered ON by the bootloader before the bootloader
handovers control to Linux. It maybe important for those devices to keep
working until the time a Linux device driver probes the device and
reconfigure its resources.

A typical example of that can be the LCD controller, which is used by
the bootloaders to show image(s) while the platform is booting into
Linux. The LCD controller can be using some resources, like clk,
regulators, PM domain, etc, that are shared between several devices.
These shared resources should be configured to satisfy need of all the
users. If another device's (X) driver gets probed before the LCD
controller driver in this case, then it may end up reconfiguring these
resources to ranges satisfying the current users (only device X) and
that can make the LCD screen unstable.

This patch introduces the concept of boot-constraints, which will be set
by the bootloaders and the kernel will satisfy them until the time
driver for such a device is probed (successfully or unsuccessfully).

The list of boot constraint types is empty for now, and will be
incrementally updated by later patches.

Only two routines are exposed by the boot constraints core for now:

- dev_boot_constraint_add(): This shall be called by parts of the kernel
  (before the device is probed) to set the constraints.

- dev_boot_constraints_remove(): This is called only by the driver core
  after a device is probed successfully or unsuccessfully. Special
  handling is done here for deffered probing.

Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/Kconfig                   |  10 ++
 drivers/base/Makefile                  |   1 +
 drivers/base/boot_constraints/Makefile |   3 +
 drivers/base/boot_constraints/core.c   | 199 +++++++++++++++++++++++++++++++++
 drivers/base/boot_constraints/core.h   |  33 ++++++
 drivers/base/dd.c                      |  20 ++--
 include/linux/boot_constraint.h        |  46 ++++++++
 7 files changed, 305 insertions(+), 7 deletions(-)
 create mode 100644 drivers/base/boot_constraints/Makefile
 create mode 100644 drivers/base/boot_constraints/core.c
 create mode 100644 drivers/base/boot_constraints/core.h
 create mode 100644 include/linux/boot_constraint.h

diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index f046d21de57d..2333db2a33b7 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -347,4 +347,14 @@ config GENERIC_ARCH_TOPOLOGY
 	  appropriate scaling, sysfs interface for changing capacity values at
 	  runtime.
 
+config DEV_BOOT_CONSTRAINTS
+	bool "Boot constraints for devices"
+	help
+	  This enables boot constraints detection for devices. These constraints
+	  are (normally) set by the Bootloader and must be satisfied by the
+	  kernel until the relevant device driver is probed. Once the driver is
+	  probed, the constraint is dropped.
+
+	  If unsure, say N.
+
 endmenu
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 397e5c344e6a..8c37ca07114b 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -5,6 +5,7 @@ obj-y			:= component.o core.o bus.o dd.o syscore.o \
 			   cpu.o firmware.o init.o map.o devres.o \
 			   attribute_container.o transport_class.o \
 			   topology.o container.o property.o cacheinfo.o
+obj-$(CONFIG_DEV_BOOT_CONSTRAINTS) += boot_constraints/
 obj-$(CONFIG_DEVTMPFS)	+= devtmpfs.o
 obj-$(CONFIG_DMA_CMA) += dma-contiguous.o
 obj-y			+= power/
diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile
new file mode 100644
index 000000000000..0f2680177974
--- /dev/null
+++ b/drivers/base/boot_constraints/Makefile
@@ -0,0 +1,3 @@
+# Makefile for device boot constraints
+
+obj-y := core.o
diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
new file mode 100644
index 000000000000..366a05d6d9ba
--- /dev/null
+++ b/drivers/base/boot_constraints/core.c
@@ -0,0 +1,199 @@
+/*
+ * This takes care of boot time device constraints, normally set by the
+ * Bootloader.
+ *
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * This file is released under the GPLv2.
+ */
+
+#define pr_fmt(fmt) "Boot Constraints: " fmt
+
+#include <linux/err.h>
+#include <linux/export.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+
+#include "core.h"
+
+#define for_each_constraint(_constraint, _temp, _cdev)		\
+	list_for_each_entry_safe(_constraint, _temp, &_cdev->constraints, node)
+
+/* Global list of all constraint devices currently registered */
+static LIST_HEAD(constraint_devices);
+static DEFINE_MUTEX(constraint_devices_mutex);
+
+/* Boot constraints core */
+
+static struct constraint_dev *constraint_device_find(struct device *dev)
+{
+	struct constraint_dev *cdev;
+
+	list_for_each_entry(cdev, &constraint_devices, node) {
+		if (cdev->dev == dev)
+			return cdev;
+	}
+
+	return NULL;
+}
+
+static struct constraint_dev *constraint_device_allocate(struct device *dev)
+{
+	struct constraint_dev *cdev;
+
+	cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
+	if (!cdev)
+		return ERR_PTR(-ENOMEM);
+
+	cdev->dev = dev;
+	INIT_LIST_HEAD(&cdev->node);
+	INIT_LIST_HEAD(&cdev->constraints);
+
+	list_add(&cdev->node, &constraint_devices);
+
+	return cdev;
+}
+
+static void constraint_device_free(struct constraint_dev *cdev)
+{
+	list_del(&cdev->node);
+	kfree(cdev);
+}
+
+static struct constraint_dev *constraint_device_get(struct device *dev)
+{
+	struct constraint_dev *cdev;
+
+	cdev = constraint_device_find(dev);
+	if (cdev)
+		return cdev;
+
+	cdev = constraint_device_allocate(dev);
+	if (IS_ERR(cdev)) {
+		dev_err(dev, "Failed to add constraint dev (%ld)\n",
+			PTR_ERR(cdev));
+	}
+
+	return cdev;
+}
+
+static void constraint_device_put(struct constraint_dev *cdev)
+{
+	if (!list_empty(&cdev->constraints))
+		return;
+
+	constraint_device_free(cdev);
+}
+
+static struct constraint *constraint_allocate(struct constraint_dev *cdev,
+					enum dev_boot_constraint_type type)
+{
+	struct constraint *constraint;
+	int (*add)(struct constraint *constraint, void *data);
+	void (*remove)(struct constraint *constraint);
+
+	switch (type) {
+	default:
+		return ERR_PTR(-EINVAL);
+	}
+
+	constraint = kzalloc(sizeof(*constraint), GFP_KERNEL);
+	if (!constraint)
+		return ERR_PTR(-ENOMEM);
+
+	constraint->cdev = cdev;
+	constraint->type = type;
+	constraint->add = add;
+	constraint->remove = remove;
+	INIT_LIST_HEAD(&constraint->node);
+
+	list_add(&constraint->node, &cdev->constraints);
+
+	return constraint;
+}
+
+static void constraint_free(struct constraint *constraint)
+{
+	list_del(&constraint->node);
+	kfree(constraint);
+}
+
+int dev_boot_constraint_add(struct device *dev,
+			    struct dev_boot_constraint_info *info)
+{
+	struct constraint_dev *cdev;
+	struct constraint *constraint;
+	int ret;
+
+	mutex_lock(&constraint_devices_mutex);
+
+	/* Find or add the cdev type first */
+	cdev = constraint_device_get(dev);
+	if (IS_ERR(cdev)) {
+		ret = PTR_ERR(cdev);
+		goto unlock;
+	}
+
+	constraint = constraint_allocate(cdev, info->constraint.type);
+	if (IS_ERR(constraint)) {
+		dev_err(dev, "Failed to add constraint type: %d (%ld)\n",
+			info->constraint.type, PTR_ERR(constraint));
+		ret = PTR_ERR(constraint);
+		goto put_cdev;
+	}
+
+	constraint->free_resources = info->free_resources;
+	constraint->free_resources_data = info->free_resources_data;
+
+	/* Set constraint */
+	ret = constraint->add(constraint, info->constraint.data);
+	if (ret)
+		goto free_constraint;
+
+	dev_dbg(dev, "Added boot constraint-type (%d)\n",
+		info->constraint.type);
+
+	mutex_unlock(&constraint_devices_mutex);
+
+	return 0;
+
+free_constraint:
+	constraint_free(constraint);
+put_cdev:
+	constraint_device_put(cdev);
+unlock:
+	mutex_unlock(&constraint_devices_mutex);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(dev_boot_constraint_add);
+
+static void constraint_remove(struct constraint *constraint)
+{
+	constraint->remove(constraint);
+
+	if (constraint->free_resources)
+		constraint->free_resources(constraint->free_resources_data);
+
+	constraint_free(constraint);
+}
+
+void dev_boot_constraints_remove(struct device *dev)
+{
+	struct constraint_dev *cdev;
+	struct constraint *constraint, *temp;
+
+	mutex_lock(&constraint_devices_mutex);
+
+	cdev = constraint_device_find(dev);
+	if (!cdev)
+		goto unlock;
+
+	for_each_constraint(constraint, temp, cdev)
+		constraint_remove(constraint);
+
+	constraint_device_put(cdev);
+unlock:
+	mutex_unlock(&constraint_devices_mutex);
+}
diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h
new file mode 100644
index 000000000000..7ba4ac172c09
--- /dev/null
+++ b/drivers/base/boot_constraints/core.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * This file is released under the GPLv2.
+ */
+#ifndef _CORE_H
+#define _CORE_H
+
+#include <linux/boot_constraint.h>
+#include <linux/device.h>
+#include <linux/list.h>
+
+struct constraint_dev {
+	struct device *dev;
+	struct list_head node;
+	struct list_head constraints;
+};
+
+struct constraint {
+	struct constraint_dev *cdev;
+	struct list_head node;
+	enum dev_boot_constraint_type type;
+	void (*free_resources)(void *data);
+	void *free_resources_data;
+
+	int (*add)(struct constraint *constraint, void *data);
+	void (*remove)(struct constraint *constraint);
+	void *private;
+};
+
+/* Forward declarations of constraint specific callbacks */
+#endif /* _CORE_H */
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index c17fefc77345..2262a4a4c0e4 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -17,6 +17,7 @@
  * This file is released under the GPLv2
  */
 
+#include <linux/boot_constraint.h>
 #include <linux/device.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
@@ -383,15 +384,20 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 	 */
 	devices_kset_move_last(dev);
 
-	if (dev->bus->probe) {
+	if (dev->bus->probe)
 		ret = dev->bus->probe(dev);
-		if (ret)
-			goto probe_failed;
-	} else if (drv->probe) {
+	else if (drv->probe)
 		ret = drv->probe(dev);
-		if (ret)
-			goto probe_failed;
-	}
+
+	/*
+	 * Remove boot constraints for both successful and unsuccessful probe(),
+	 * except for the case where EPROBE_DEFER is returned by probe().
+	 */
+	if (ret != -EPROBE_DEFER)
+		dev_boot_constraints_remove(dev);
+
+	if (ret)
+		goto probe_failed;
 
 	if (test_remove) {
 		test_remove = false;
diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h
new file mode 100644
index 000000000000..ae34fee547c5
--- /dev/null
+++ b/include/linux/boot_constraint.h
@@ -0,0 +1,46 @@
+/*
+ * Boot constraints header.
+ *
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * This file is released under the GPLv2
+ */
+#ifndef _LINUX_BOOT_CONSTRAINT_H
+#define _LINUX_BOOT_CONSTRAINT_H
+
+#include <linux/err.h>
+#include <linux/types.h>
+
+struct device;
+
+enum dev_boot_constraint_type {
+	DEV_BOOT_CONSTRAINT_NONE,
+};
+
+struct dev_boot_constraint {
+	enum dev_boot_constraint_type type;
+	void *data;
+};
+
+struct dev_boot_constraint_info {
+	struct dev_boot_constraint constraint;
+
+	/* This will be called just before the constraint is removed */
+	void (*free_resources)(void *data);
+	void *free_resources_data;
+};
+
+#ifdef CONFIG_DEV_BOOT_CONSTRAINTS
+int dev_boot_constraint_add(struct device *dev,
+			    struct dev_boot_constraint_info *info);
+void dev_boot_constraints_remove(struct device *dev);
+#else
+static inline
+int dev_boot_constraint_add(struct device *dev,
+			    struct dev_boot_constraint_info *info);
+{ return -EINVAL; }
+static inline void dev_boot_constraints_remove(struct device *dev) {}
+#endif /* CONFIG_DEV_BOOT_CONSTRAINTS */
+
+#endif /* _LINUX_BOOT_CONSTRAINT_H */
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter
  2017-08-01  9:23 ` Viresh Kumar
@ 2017-08-01  9:23   ` Viresh Kumar
  -1 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jonathan Corbet
  Cc: Viresh Kumar, Vincent Guittot, Mark Brown, Stephen Boyd,
	Rajendra Nayak, Shiraz Hashim, linux-kernel, linux-arm-kernel,
	robdclark, linux-doc

Users must be given an option to discard any constraints set by
bootloaders. For example, consider that a constraint is set for the LCD
controller's supply and the LCD driver isn't loaded by the kernel. If
the user doesn't need to use the LCD device, then he shouldn't be forced
to honour the constraint.

We can also think about finer control of such constraints with help of
some sysfs files, but a kernel parameter is fine to begin with.

Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 Documentation/admin-guide/kernel-parameters.txt |  3 +++
 drivers/base/boot_constraints/core.c            | 17 +++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index d9c171ce4190..0706d1b6004d 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -426,6 +426,9 @@
 			embedded devices based on command line input.
 			See Documentation/block/cmdline-partition.txt
 
+	boot_constraints_disable
+			Do not set any boot constraints for devices.
+
 	boot_delay=	Milliseconds to delay each printk during boot.
 			Values larger than 10 seconds (10000) are changed to
 			no delay (0).
diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
index 366a05d6d9ba..e0c33b2b216f 100644
--- a/drivers/base/boot_constraints/core.c
+++ b/drivers/base/boot_constraints/core.c
@@ -24,6 +24,17 @@
 static LIST_HEAD(constraint_devices);
 static DEFINE_MUTEX(constraint_devices_mutex);
 
+static bool boot_constraints_disabled;
+
+static int __init constraints_disable(char *str)
+{
+	boot_constraints_disabled = true;
+	pr_debug("disabled\n");
+
+	return 0;
+}
+early_param("boot_constraints_disable", constraints_disable);
+
 /* Boot constraints core */
 
 static struct constraint_dev *constraint_device_find(struct device *dev)
@@ -126,6 +137,9 @@ int dev_boot_constraint_add(struct device *dev,
 	struct constraint *constraint;
 	int ret;
 
+	if (boot_constraints_disabled)
+		return -ENODEV;
+
 	mutex_lock(&constraint_devices_mutex);
 
 	/* Find or add the cdev type first */
@@ -184,6 +198,9 @@ void dev_boot_constraints_remove(struct device *dev)
 	struct constraint_dev *cdev;
 	struct constraint *constraint, *temp;
 
+	if (boot_constraints_disabled)
+		return;
+
 	mutex_lock(&constraint_devices_mutex);
 
 	cdev = constraint_device_find(dev);
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter
@ 2017-08-01  9:23   ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: linux-arm-kernel

Users must be given an option to discard any constraints set by
bootloaders. For example, consider that a constraint is set for the LCD
controller's supply and the LCD driver isn't loaded by the kernel. If
the user doesn't need to use the LCD device, then he shouldn't be forced
to honour the constraint.

We can also think about finer control of such constraints with help of
some sysfs files, but a kernel parameter is fine to begin with.

Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 Documentation/admin-guide/kernel-parameters.txt |  3 +++
 drivers/base/boot_constraints/core.c            | 17 +++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index d9c171ce4190..0706d1b6004d 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -426,6 +426,9 @@
 			embedded devices based on command line input.
 			See Documentation/block/cmdline-partition.txt
 
+	boot_constraints_disable
+			Do not set any boot constraints for devices.
+
 	boot_delay=	Milliseconds to delay each printk during boot.
 			Values larger than 10 seconds (10000) are changed to
 			no delay (0).
diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
index 366a05d6d9ba..e0c33b2b216f 100644
--- a/drivers/base/boot_constraints/core.c
+++ b/drivers/base/boot_constraints/core.c
@@ -24,6 +24,17 @@
 static LIST_HEAD(constraint_devices);
 static DEFINE_MUTEX(constraint_devices_mutex);
 
+static bool boot_constraints_disabled;
+
+static int __init constraints_disable(char *str)
+{
+	boot_constraints_disabled = true;
+	pr_debug("disabled\n");
+
+	return 0;
+}
+early_param("boot_constraints_disable", constraints_disable);
+
 /* Boot constraints core */
 
 static struct constraint_dev *constraint_device_find(struct device *dev)
@@ -126,6 +137,9 @@ int dev_boot_constraint_add(struct device *dev,
 	struct constraint *constraint;
 	int ret;
 
+	if (boot_constraints_disabled)
+		return -ENODEV;
+
 	mutex_lock(&constraint_devices_mutex);
 
 	/* Find or add the cdev type first */
@@ -184,6 +198,9 @@ void dev_boot_constraints_remove(struct device *dev)
 	struct constraint_dev *cdev;
 	struct constraint *constraint, *temp;
 
+	if (boot_constraints_disabled)
+		return;
+
 	mutex_lock(&constraint_devices_mutex);
 
 	cdev = constraint_device_find(dev);
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH V3 3/8] drivers: boot_constraint: Add support for supply constraints
  2017-08-01  9:23 ` Viresh Kumar
@ 2017-08-01  9:23   ` Viresh Kumar
  -1 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Viresh Kumar, Vincent Guittot, Mark Brown, Stephen Boyd,
	Rajendra Nayak, Shiraz Hashim, linux-kernel, linux-arm-kernel,
	robdclark

This patch adds the first constraint type: power-supply.

The constraint is set by enabling the regulator and setting a voltage
range (if required) for the respective regulator device, which will be
honored by the regulator core even if more users turn up. Once the
device is probed, the regulator is released and the constraint is
removed.

Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/boot_constraints/Makefile |  2 +-
 drivers/base/boot_constraints/core.c   |  4 ++
 drivers/base/boot_constraints/core.h   |  3 ++
 drivers/base/boot_constraints/supply.c | 98 ++++++++++++++++++++++++++++++++++
 include/linux/boot_constraint.h        |  8 ++-
 5 files changed, 113 insertions(+), 2 deletions(-)
 create mode 100644 drivers/base/boot_constraints/supply.c

diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile
index 0f2680177974..a45616f0c3b0 100644
--- a/drivers/base/boot_constraints/Makefile
+++ b/drivers/base/boot_constraints/Makefile
@@ -1,3 +1,3 @@
 # Makefile for device boot constraints
 
-obj-y := core.o
+obj-y := core.o supply.o
diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
index e0c33b2b216f..06b618a85c0a 100644
--- a/drivers/base/boot_constraints/core.c
+++ b/drivers/base/boot_constraints/core.c
@@ -105,6 +105,10 @@ static struct constraint *constraint_allocate(struct constraint_dev *cdev,
 	void (*remove)(struct constraint *constraint);
 
 	switch (type) {
+	case DEV_BOOT_CONSTRAINT_SUPPLY:
+		add = constraint_supply_add;
+		remove = constraint_supply_remove;
+		break;
 	default:
 		return ERR_PTR(-EINVAL);
 	}
diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h
index 7ba4ac172c09..73b9d2d22a12 100644
--- a/drivers/base/boot_constraints/core.h
+++ b/drivers/base/boot_constraints/core.h
@@ -30,4 +30,7 @@ struct constraint {
 };
 
 /* Forward declarations of constraint specific callbacks */
+int constraint_supply_add(struct constraint *constraint, void *data);
+void constraint_supply_remove(struct constraint *constraint);
+
 #endif /* _CORE_H */
diff --git a/drivers/base/boot_constraints/supply.c b/drivers/base/boot_constraints/supply.c
new file mode 100644
index 000000000000..30f816dbf12c
--- /dev/null
+++ b/drivers/base/boot_constraints/supply.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * This file is released under the GPLv2.
+ */
+
+#define pr_fmt(fmt) "Supply Boot Constraints: " fmt
+
+#include <linux/err.h>
+#include <linux/regulator/consumer.h>
+#include <linux/slab.h>
+
+#include "core.h"
+
+struct constraint_supply {
+	struct dev_boot_constraint_supply_info supply;
+	struct regulator *reg;
+};
+
+int constraint_supply_add(struct constraint *constraint, void *data)
+{
+	struct dev_boot_constraint_supply_info *supply = data;
+	struct constraint_supply *csupply;
+	struct device *dev = constraint->cdev->dev;
+	int ret;
+
+	csupply = kzalloc(sizeof(*csupply), GFP_KERNEL);
+	if (!csupply)
+		return -ENOMEM;
+
+	csupply->reg = regulator_get(dev, supply->name);
+	if (IS_ERR(csupply->reg)) {
+		ret = PTR_ERR(csupply->reg);
+		if (ret != -EPROBE_DEFER) {
+			dev_err(dev, "regulator_get() failed for %s (%d)\n",
+				supply->name, ret);
+		}
+		goto free;
+	}
+
+	if (supply->u_volt_min != 0 && supply->u_volt_max != 0) {
+		ret = regulator_set_voltage(csupply->reg, supply->u_volt_min,
+					    supply->u_volt_max);
+		if (ret) {
+			dev_err(dev, "regulator_set_voltage %s failed (%d)\n",
+				supply->name, ret);
+			goto free_regulator;
+		}
+	}
+
+	ret = regulator_enable(csupply->reg);
+	if (ret) {
+		dev_err(dev, "regulator_enable %s failed (%d)\n",
+			supply->name, ret);
+		goto remove_voltage;
+	}
+
+	memcpy(&csupply->supply, supply, sizeof(*supply));
+	csupply->supply.name = kstrdup_const(supply->name, GFP_KERNEL);
+	constraint->private = csupply;
+
+	return 0;
+
+remove_voltage:
+	if (supply->u_volt_min != 0 && supply->u_volt_max != 0)
+		regulator_set_voltage(csupply->reg, 0, INT_MAX);
+free_regulator:
+	regulator_put(csupply->reg);
+free:
+	kfree(csupply);
+
+	return ret;
+}
+
+void constraint_supply_remove(struct constraint *constraint)
+{
+	struct constraint_supply *csupply = constraint->private;
+	struct dev_boot_constraint_supply_info *supply = &csupply->supply;
+	struct device *dev = constraint->cdev->dev;
+	int ret;
+
+	kfree_const(supply->name);
+
+	ret = regulator_disable(csupply->reg);
+	if (ret)
+		dev_err(dev, "regulator_disable failed (%d)\n", ret);
+
+	if (supply->u_volt_min != 0 && supply->u_volt_max != 0) {
+		ret = regulator_set_voltage(csupply->reg, 0, INT_MAX);
+		if (ret)
+			dev_err(dev, "regulator_set_voltage failed (%d)\n",
+				ret);
+	}
+
+	regulator_put(csupply->reg);
+	kfree(csupply);
+}
diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h
index ae34fee547c5..d19b8ec2f10d 100644
--- a/include/linux/boot_constraint.h
+++ b/include/linux/boot_constraint.h
@@ -15,7 +15,13 @@
 struct device;
 
 enum dev_boot_constraint_type {
-	DEV_BOOT_CONSTRAINT_NONE,
+	DEV_BOOT_CONSTRAINT_SUPPLY,
+};
+
+struct dev_boot_constraint_supply_info {
+	const char *name;
+	unsigned int u_volt_min;
+	unsigned int u_volt_max;
 };
 
 struct dev_boot_constraint {
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH V3 3/8] drivers: boot_constraint: Add support for supply constraints
@ 2017-08-01  9:23   ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: linux-arm-kernel

This patch adds the first constraint type: power-supply.

The constraint is set by enabling the regulator and setting a voltage
range (if required) for the respective regulator device, which will be
honored by the regulator core even if more users turn up. Once the
device is probed, the regulator is released and the constraint is
removed.

Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/boot_constraints/Makefile |  2 +-
 drivers/base/boot_constraints/core.c   |  4 ++
 drivers/base/boot_constraints/core.h   |  3 ++
 drivers/base/boot_constraints/supply.c | 98 ++++++++++++++++++++++++++++++++++
 include/linux/boot_constraint.h        |  8 ++-
 5 files changed, 113 insertions(+), 2 deletions(-)
 create mode 100644 drivers/base/boot_constraints/supply.c

diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile
index 0f2680177974..a45616f0c3b0 100644
--- a/drivers/base/boot_constraints/Makefile
+++ b/drivers/base/boot_constraints/Makefile
@@ -1,3 +1,3 @@
 # Makefile for device boot constraints
 
-obj-y := core.o
+obj-y := core.o supply.o
diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
index e0c33b2b216f..06b618a85c0a 100644
--- a/drivers/base/boot_constraints/core.c
+++ b/drivers/base/boot_constraints/core.c
@@ -105,6 +105,10 @@ static struct constraint *constraint_allocate(struct constraint_dev *cdev,
 	void (*remove)(struct constraint *constraint);
 
 	switch (type) {
+	case DEV_BOOT_CONSTRAINT_SUPPLY:
+		add = constraint_supply_add;
+		remove = constraint_supply_remove;
+		break;
 	default:
 		return ERR_PTR(-EINVAL);
 	}
diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h
index 7ba4ac172c09..73b9d2d22a12 100644
--- a/drivers/base/boot_constraints/core.h
+++ b/drivers/base/boot_constraints/core.h
@@ -30,4 +30,7 @@ struct constraint {
 };
 
 /* Forward declarations of constraint specific callbacks */
+int constraint_supply_add(struct constraint *constraint, void *data);
+void constraint_supply_remove(struct constraint *constraint);
+
 #endif /* _CORE_H */
diff --git a/drivers/base/boot_constraints/supply.c b/drivers/base/boot_constraints/supply.c
new file mode 100644
index 000000000000..30f816dbf12c
--- /dev/null
+++ b/drivers/base/boot_constraints/supply.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * This file is released under the GPLv2.
+ */
+
+#define pr_fmt(fmt) "Supply Boot Constraints: " fmt
+
+#include <linux/err.h>
+#include <linux/regulator/consumer.h>
+#include <linux/slab.h>
+
+#include "core.h"
+
+struct constraint_supply {
+	struct dev_boot_constraint_supply_info supply;
+	struct regulator *reg;
+};
+
+int constraint_supply_add(struct constraint *constraint, void *data)
+{
+	struct dev_boot_constraint_supply_info *supply = data;
+	struct constraint_supply *csupply;
+	struct device *dev = constraint->cdev->dev;
+	int ret;
+
+	csupply = kzalloc(sizeof(*csupply), GFP_KERNEL);
+	if (!csupply)
+		return -ENOMEM;
+
+	csupply->reg = regulator_get(dev, supply->name);
+	if (IS_ERR(csupply->reg)) {
+		ret = PTR_ERR(csupply->reg);
+		if (ret != -EPROBE_DEFER) {
+			dev_err(dev, "regulator_get() failed for %s (%d)\n",
+				supply->name, ret);
+		}
+		goto free;
+	}
+
+	if (supply->u_volt_min != 0 && supply->u_volt_max != 0) {
+		ret = regulator_set_voltage(csupply->reg, supply->u_volt_min,
+					    supply->u_volt_max);
+		if (ret) {
+			dev_err(dev, "regulator_set_voltage %s failed (%d)\n",
+				supply->name, ret);
+			goto free_regulator;
+		}
+	}
+
+	ret = regulator_enable(csupply->reg);
+	if (ret) {
+		dev_err(dev, "regulator_enable %s failed (%d)\n",
+			supply->name, ret);
+		goto remove_voltage;
+	}
+
+	memcpy(&csupply->supply, supply, sizeof(*supply));
+	csupply->supply.name = kstrdup_const(supply->name, GFP_KERNEL);
+	constraint->private = csupply;
+
+	return 0;
+
+remove_voltage:
+	if (supply->u_volt_min != 0 && supply->u_volt_max != 0)
+		regulator_set_voltage(csupply->reg, 0, INT_MAX);
+free_regulator:
+	regulator_put(csupply->reg);
+free:
+	kfree(csupply);
+
+	return ret;
+}
+
+void constraint_supply_remove(struct constraint *constraint)
+{
+	struct constraint_supply *csupply = constraint->private;
+	struct dev_boot_constraint_supply_info *supply = &csupply->supply;
+	struct device *dev = constraint->cdev->dev;
+	int ret;
+
+	kfree_const(supply->name);
+
+	ret = regulator_disable(csupply->reg);
+	if (ret)
+		dev_err(dev, "regulator_disable failed (%d)\n", ret);
+
+	if (supply->u_volt_min != 0 && supply->u_volt_max != 0) {
+		ret = regulator_set_voltage(csupply->reg, 0, INT_MAX);
+		if (ret)
+			dev_err(dev, "regulator_set_voltage failed (%d)\n",
+				ret);
+	}
+
+	regulator_put(csupply->reg);
+	kfree(csupply);
+}
diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h
index ae34fee547c5..d19b8ec2f10d 100644
--- a/include/linux/boot_constraint.h
+++ b/include/linux/boot_constraint.h
@@ -15,7 +15,13 @@
 struct device;
 
 enum dev_boot_constraint_type {
-	DEV_BOOT_CONSTRAINT_NONE,
+	DEV_BOOT_CONSTRAINT_SUPPLY,
+};
+
+struct dev_boot_constraint_supply_info {
+	const char *name;
+	unsigned int u_volt_min;
+	unsigned int u_volt_max;
 };
 
 struct dev_boot_constraint {
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH V3 4/8] drivers: boot_constraint: Add support for clk constraints
  2017-08-01  9:23 ` Viresh Kumar
@ 2017-08-01  9:23   ` Viresh Kumar
  -1 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Viresh Kumar, Vincent Guittot, Mark Brown, Stephen Boyd,
	Rajendra Nayak, Shiraz Hashim, linux-kernel, linux-arm-kernel,
	robdclark

This patch adds the clk constraint type.

The constraint is set by enabling the clk for the device. Once the
device is probed, the clk is disabled and the constraint is removed.

We may want to do clk_set_rate() from here, but lets wait for some real
users that really want it.

Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/boot_constraints/Makefile |  2 +-
 drivers/base/boot_constraints/clk.c    | 70 ++++++++++++++++++++++++++++++++++
 drivers/base/boot_constraints/core.c   |  4 ++
 drivers/base/boot_constraints/core.h   |  3 ++
 include/linux/boot_constraint.h        |  5 +++
 5 files changed, 83 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/boot_constraints/clk.c

diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile
index a45616f0c3b0..3424379fd1e4 100644
--- a/drivers/base/boot_constraints/Makefile
+++ b/drivers/base/boot_constraints/Makefile
@@ -1,3 +1,3 @@
 # Makefile for device boot constraints
 
-obj-y := core.o supply.o
+obj-y := clk.o core.o supply.o
diff --git a/drivers/base/boot_constraints/clk.c b/drivers/base/boot_constraints/clk.c
new file mode 100644
index 000000000000..b5b1d63c3e76
--- /dev/null
+++ b/drivers/base/boot_constraints/clk.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * This file is released under the GPLv2.
+ */
+
+#define pr_fmt(fmt) "Clock Boot Constraints: " fmt
+
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/slab.h>
+
+#include "core.h"
+
+struct constraint_clk {
+	struct dev_boot_constraint_clk_info clk_info;
+	struct clk *clk;
+};
+
+int constraint_clk_add(struct constraint *constraint, void *data)
+{
+	struct dev_boot_constraint_clk_info *clk_info = data;
+	struct constraint_clk *cclk;
+	struct device *dev = constraint->cdev->dev;
+	int ret;
+
+	cclk = kzalloc(sizeof(*cclk), GFP_KERNEL);
+	if (!cclk)
+		return -ENOMEM;
+
+	cclk->clk = clk_get(dev, clk_info->name);
+	if (IS_ERR(cclk->clk)) {
+		ret = PTR_ERR(cclk->clk);
+		if (ret != -EPROBE_DEFER) {
+			dev_err(dev, "clk_get() failed for %s (%d)\n",
+				clk_info->name, ret);
+		}
+		goto free;
+	}
+
+	ret = clk_prepare_enable(cclk->clk);
+	if (ret) {
+		dev_err(dev, "clk_prepare_enable() %s failed (%d)\n",
+			clk_info->name, ret);
+		goto put_clk;
+	}
+
+	cclk->clk_info.name = kstrdup_const(clk_info->name, GFP_KERNEL);
+	constraint->private = cclk;
+
+	return 0;
+
+put_clk:
+	clk_put(cclk->clk);
+free:
+	kfree(cclk);
+
+	return ret;
+}
+
+void constraint_clk_remove(struct constraint *constraint)
+{
+	struct constraint_clk *cclk = constraint->private;
+
+	kfree_const(cclk->clk_info.name);
+	clk_disable_unprepare(cclk->clk);
+	clk_put(cclk->clk);
+	kfree(cclk);
+}
diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
index 06b618a85c0a..88568ed1bfad 100644
--- a/drivers/base/boot_constraints/core.c
+++ b/drivers/base/boot_constraints/core.c
@@ -105,6 +105,10 @@ static struct constraint *constraint_allocate(struct constraint_dev *cdev,
 	void (*remove)(struct constraint *constraint);
 
 	switch (type) {
+	case DEV_BOOT_CONSTRAINT_CLK:
+		add = constraint_clk_add;
+		remove = constraint_clk_remove;
+		break;
 	case DEV_BOOT_CONSTRAINT_SUPPLY:
 		add = constraint_supply_add;
 		remove = constraint_supply_remove;
diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h
index 73b9d2d22a12..4f28ac2ef691 100644
--- a/drivers/base/boot_constraints/core.h
+++ b/drivers/base/boot_constraints/core.h
@@ -30,6 +30,9 @@ struct constraint {
 };
 
 /* Forward declarations of constraint specific callbacks */
+int constraint_clk_add(struct constraint *constraint, void *data);
+void constraint_clk_remove(struct constraint *constraint);
+
 int constraint_supply_add(struct constraint *constraint, void *data);
 void constraint_supply_remove(struct constraint *constraint);
 
diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h
index d19b8ec2f10d..a2696002e6e1 100644
--- a/include/linux/boot_constraint.h
+++ b/include/linux/boot_constraint.h
@@ -15,9 +15,14 @@
 struct device;
 
 enum dev_boot_constraint_type {
+	DEV_BOOT_CONSTRAINT_CLK,
 	DEV_BOOT_CONSTRAINT_SUPPLY,
 };
 
+struct dev_boot_constraint_clk_info {
+	const char *name;
+};
+
 struct dev_boot_constraint_supply_info {
 	const char *name;
 	unsigned int u_volt_min;
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH V3 4/8] drivers: boot_constraint: Add support for clk constraints
@ 2017-08-01  9:23   ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: linux-arm-kernel

This patch adds the clk constraint type.

The constraint is set by enabling the clk for the device. Once the
device is probed, the clk is disabled and the constraint is removed.

We may want to do clk_set_rate() from here, but lets wait for some real
users that really want it.

Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/boot_constraints/Makefile |  2 +-
 drivers/base/boot_constraints/clk.c    | 70 ++++++++++++++++++++++++++++++++++
 drivers/base/boot_constraints/core.c   |  4 ++
 drivers/base/boot_constraints/core.h   |  3 ++
 include/linux/boot_constraint.h        |  5 +++
 5 files changed, 83 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/boot_constraints/clk.c

diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile
index a45616f0c3b0..3424379fd1e4 100644
--- a/drivers/base/boot_constraints/Makefile
+++ b/drivers/base/boot_constraints/Makefile
@@ -1,3 +1,3 @@
 # Makefile for device boot constraints
 
-obj-y := core.o supply.o
+obj-y := clk.o core.o supply.o
diff --git a/drivers/base/boot_constraints/clk.c b/drivers/base/boot_constraints/clk.c
new file mode 100644
index 000000000000..b5b1d63c3e76
--- /dev/null
+++ b/drivers/base/boot_constraints/clk.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * This file is released under the GPLv2.
+ */
+
+#define pr_fmt(fmt) "Clock Boot Constraints: " fmt
+
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/slab.h>
+
+#include "core.h"
+
+struct constraint_clk {
+	struct dev_boot_constraint_clk_info clk_info;
+	struct clk *clk;
+};
+
+int constraint_clk_add(struct constraint *constraint, void *data)
+{
+	struct dev_boot_constraint_clk_info *clk_info = data;
+	struct constraint_clk *cclk;
+	struct device *dev = constraint->cdev->dev;
+	int ret;
+
+	cclk = kzalloc(sizeof(*cclk), GFP_KERNEL);
+	if (!cclk)
+		return -ENOMEM;
+
+	cclk->clk = clk_get(dev, clk_info->name);
+	if (IS_ERR(cclk->clk)) {
+		ret = PTR_ERR(cclk->clk);
+		if (ret != -EPROBE_DEFER) {
+			dev_err(dev, "clk_get() failed for %s (%d)\n",
+				clk_info->name, ret);
+		}
+		goto free;
+	}
+
+	ret = clk_prepare_enable(cclk->clk);
+	if (ret) {
+		dev_err(dev, "clk_prepare_enable() %s failed (%d)\n",
+			clk_info->name, ret);
+		goto put_clk;
+	}
+
+	cclk->clk_info.name = kstrdup_const(clk_info->name, GFP_KERNEL);
+	constraint->private = cclk;
+
+	return 0;
+
+put_clk:
+	clk_put(cclk->clk);
+free:
+	kfree(cclk);
+
+	return ret;
+}
+
+void constraint_clk_remove(struct constraint *constraint)
+{
+	struct constraint_clk *cclk = constraint->private;
+
+	kfree_const(cclk->clk_info.name);
+	clk_disable_unprepare(cclk->clk);
+	clk_put(cclk->clk);
+	kfree(cclk);
+}
diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
index 06b618a85c0a..88568ed1bfad 100644
--- a/drivers/base/boot_constraints/core.c
+++ b/drivers/base/boot_constraints/core.c
@@ -105,6 +105,10 @@ static struct constraint *constraint_allocate(struct constraint_dev *cdev,
 	void (*remove)(struct constraint *constraint);
 
 	switch (type) {
+	case DEV_BOOT_CONSTRAINT_CLK:
+		add = constraint_clk_add;
+		remove = constraint_clk_remove;
+		break;
 	case DEV_BOOT_CONSTRAINT_SUPPLY:
 		add = constraint_supply_add;
 		remove = constraint_supply_remove;
diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h
index 73b9d2d22a12..4f28ac2ef691 100644
--- a/drivers/base/boot_constraints/core.h
+++ b/drivers/base/boot_constraints/core.h
@@ -30,6 +30,9 @@ struct constraint {
 };
 
 /* Forward declarations of constraint specific callbacks */
+int constraint_clk_add(struct constraint *constraint, void *data);
+void constraint_clk_remove(struct constraint *constraint);
+
 int constraint_supply_add(struct constraint *constraint, void *data);
 void constraint_supply_remove(struct constraint *constraint);
 
diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h
index d19b8ec2f10d..a2696002e6e1 100644
--- a/include/linux/boot_constraint.h
+++ b/include/linux/boot_constraint.h
@@ -15,9 +15,14 @@
 struct device;
 
 enum dev_boot_constraint_type {
+	DEV_BOOT_CONSTRAINT_CLK,
 	DEV_BOOT_CONSTRAINT_SUPPLY,
 };
 
+struct dev_boot_constraint_clk_info {
+	const char *name;
+};
+
 struct dev_boot_constraint_supply_info {
 	const char *name;
 	unsigned int u_volt_min;
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH V3 5/8] drivers: boot_constraint: Add support for PM constraints
  2017-08-01  9:23 ` Viresh Kumar
@ 2017-08-01  9:23   ` Viresh Kumar
  -1 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Viresh Kumar, Vincent Guittot, Mark Brown, Stephen Boyd,
	Rajendra Nayak, Shiraz Hashim, linux-kernel, linux-arm-kernel,
	robdclark

This patch adds the PM constraint type.

The constraint is set by attaching the power domain for the device,
which will also enable the power domain. This guarantees that the power
domain doesn't get shut down while being used.

We don't need to detach the power domain to remove the constraint as the
domain is attached only once, from here or before driver probe.

Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/boot_constraints/Makefile |  2 +-
 drivers/base/boot_constraints/core.c   |  4 ++++
 drivers/base/boot_constraints/core.h   |  3 +++
 drivers/base/boot_constraints/pm.c     | 24 ++++++++++++++++++++++++
 include/linux/boot_constraint.h        |  1 +
 5 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/boot_constraints/pm.c

diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile
index 3424379fd1e4..b7ade1a7afb5 100644
--- a/drivers/base/boot_constraints/Makefile
+++ b/drivers/base/boot_constraints/Makefile
@@ -1,3 +1,3 @@
 # Makefile for device boot constraints
 
-obj-y := clk.o core.o supply.o
+obj-y := clk.o core.o pm.o supply.o
diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
index 88568ed1bfad..06267f0c88d4 100644
--- a/drivers/base/boot_constraints/core.c
+++ b/drivers/base/boot_constraints/core.c
@@ -109,6 +109,10 @@ static struct constraint *constraint_allocate(struct constraint_dev *cdev,
 		add = constraint_clk_add;
 		remove = constraint_clk_remove;
 		break;
+	case DEV_BOOT_CONSTRAINT_PM:
+		add = constraint_pm_add;
+		remove = constraint_pm_remove;
+		break;
 	case DEV_BOOT_CONSTRAINT_SUPPLY:
 		add = constraint_supply_add;
 		remove = constraint_supply_remove;
diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h
index 4f28ac2ef691..a051c3d7c8ab 100644
--- a/drivers/base/boot_constraints/core.h
+++ b/drivers/base/boot_constraints/core.h
@@ -33,6 +33,9 @@ struct constraint {
 int constraint_clk_add(struct constraint *constraint, void *data);
 void constraint_clk_remove(struct constraint *constraint);
 
+int constraint_pm_add(struct constraint *constraint, void *data);
+void constraint_pm_remove(struct constraint *constraint);
+
 int constraint_supply_add(struct constraint *constraint, void *data);
 void constraint_supply_remove(struct constraint *constraint);
 
diff --git a/drivers/base/boot_constraints/pm.c b/drivers/base/boot_constraints/pm.c
new file mode 100644
index 000000000000..edba5eca5093
--- /dev/null
+++ b/drivers/base/boot_constraints/pm.c
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * This file is released under the GPLv2.
+ */
+
+#define pr_fmt(fmt) "PM Boot Constraints: " fmt
+
+#include <linux/pm_domain.h>
+
+#include "core.h"
+
+int constraint_pm_add(struct constraint *constraint, void *data)
+{
+	struct device *dev = constraint->cdev->dev;
+
+	return dev_pm_domain_attach(dev, true);
+}
+
+void constraint_pm_remove(struct constraint *constraint)
+{
+	/* Nothing to do for now */
+}
diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h
index a2696002e6e1..edc9abe7913a 100644
--- a/include/linux/boot_constraint.h
+++ b/include/linux/boot_constraint.h
@@ -16,6 +16,7 @@ struct device;
 
 enum dev_boot_constraint_type {
 	DEV_BOOT_CONSTRAINT_CLK,
+	DEV_BOOT_CONSTRAINT_PM,
 	DEV_BOOT_CONSTRAINT_SUPPLY,
 };
 
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH V3 5/8] drivers: boot_constraint: Add support for PM constraints
@ 2017-08-01  9:23   ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: linux-arm-kernel

This patch adds the PM constraint type.

The constraint is set by attaching the power domain for the device,
which will also enable the power domain. This guarantees that the power
domain doesn't get shut down while being used.

We don't need to detach the power domain to remove the constraint as the
domain is attached only once, from here or before driver probe.

Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/boot_constraints/Makefile |  2 +-
 drivers/base/boot_constraints/core.c   |  4 ++++
 drivers/base/boot_constraints/core.h   |  3 +++
 drivers/base/boot_constraints/pm.c     | 24 ++++++++++++++++++++++++
 include/linux/boot_constraint.h        |  1 +
 5 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/boot_constraints/pm.c

diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile
index 3424379fd1e4..b7ade1a7afb5 100644
--- a/drivers/base/boot_constraints/Makefile
+++ b/drivers/base/boot_constraints/Makefile
@@ -1,3 +1,3 @@
 # Makefile for device boot constraints
 
-obj-y := clk.o core.o supply.o
+obj-y := clk.o core.o pm.o supply.o
diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
index 88568ed1bfad..06267f0c88d4 100644
--- a/drivers/base/boot_constraints/core.c
+++ b/drivers/base/boot_constraints/core.c
@@ -109,6 +109,10 @@ static struct constraint *constraint_allocate(struct constraint_dev *cdev,
 		add = constraint_clk_add;
 		remove = constraint_clk_remove;
 		break;
+	case DEV_BOOT_CONSTRAINT_PM:
+		add = constraint_pm_add;
+		remove = constraint_pm_remove;
+		break;
 	case DEV_BOOT_CONSTRAINT_SUPPLY:
 		add = constraint_supply_add;
 		remove = constraint_supply_remove;
diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h
index 4f28ac2ef691..a051c3d7c8ab 100644
--- a/drivers/base/boot_constraints/core.h
+++ b/drivers/base/boot_constraints/core.h
@@ -33,6 +33,9 @@ struct constraint {
 int constraint_clk_add(struct constraint *constraint, void *data);
 void constraint_clk_remove(struct constraint *constraint);
 
+int constraint_pm_add(struct constraint *constraint, void *data);
+void constraint_pm_remove(struct constraint *constraint);
+
 int constraint_supply_add(struct constraint *constraint, void *data);
 void constraint_supply_remove(struct constraint *constraint);
 
diff --git a/drivers/base/boot_constraints/pm.c b/drivers/base/boot_constraints/pm.c
new file mode 100644
index 000000000000..edba5eca5093
--- /dev/null
+++ b/drivers/base/boot_constraints/pm.c
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * This file is released under the GPLv2.
+ */
+
+#define pr_fmt(fmt) "PM Boot Constraints: " fmt
+
+#include <linux/pm_domain.h>
+
+#include "core.h"
+
+int constraint_pm_add(struct constraint *constraint, void *data)
+{
+	struct device *dev = constraint->cdev->dev;
+
+	return dev_pm_domain_attach(dev, true);
+}
+
+void constraint_pm_remove(struct constraint *constraint)
+{
+	/* Nothing to do for now */
+}
diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h
index a2696002e6e1..edc9abe7913a 100644
--- a/include/linux/boot_constraint.h
+++ b/include/linux/boot_constraint.h
@@ -16,6 +16,7 @@ struct device;
 
 enum dev_boot_constraint_type {
 	DEV_BOOT_CONSTRAINT_CLK,
+	DEV_BOOT_CONSTRAINT_PM,
 	DEV_BOOT_CONSTRAINT_SUPPLY,
 };
 
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH V3 6/8] drivers: boot_constraint: Add debugfs support
  2017-08-01  9:23 ` Viresh Kumar
@ 2017-08-01  9:23   ` Viresh Kumar
  -1 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Viresh Kumar, Vincent Guittot, Mark Brown, Stephen Boyd,
	Rajendra Nayak, Shiraz Hashim, linux-kernel, linux-arm-kernel,
	robdclark

This patch adds debugfs support for boot constraints. This is how it
looks for a "vmmc-supply" constraint for the MMC device.

$ ls -R /sys/kernel/debug/boot_constraints/
/sys/kernel/debug/boot_constraints/:
f723d000.dwmmc0

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0:
clk-ciu  pm-domain  supply-vmmc  supply-vmmcaux

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/clk-ciu:

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/pm-domain:

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmc:
u_volt_max  u_volt_min

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmcaux:
u_volt_max  u_volt_min

Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/boot_constraints/clk.c    |  4 ++
 drivers/base/boot_constraints/core.c   | 72 ++++++++++++++++++++++++++++++++++
 drivers/base/boot_constraints/core.h   |  6 +++
 drivers/base/boot_constraints/pm.c     | 12 +++++-
 drivers/base/boot_constraints/supply.c | 10 +++++
 5 files changed, 102 insertions(+), 2 deletions(-)

diff --git a/drivers/base/boot_constraints/clk.c b/drivers/base/boot_constraints/clk.c
index b5b1d63c3e76..bdbfcbc2944d 100644
--- a/drivers/base/boot_constraints/clk.c
+++ b/drivers/base/boot_constraints/clk.c
@@ -49,6 +49,9 @@ int constraint_clk_add(struct constraint *constraint, void *data)
 	cclk->clk_info.name = kstrdup_const(clk_info->name, GFP_KERNEL);
 	constraint->private = cclk;
 
+	/* Debugfs */
+	constraint_add_debugfs(constraint, clk_info->name);
+
 	return 0;
 
 put_clk:
@@ -63,6 +66,7 @@ void constraint_clk_remove(struct constraint *constraint)
 {
 	struct constraint_clk *cclk = constraint->private;
 
+	constraint_remove_debugfs(constraint);
 	kfree_const(cclk->clk_info.name);
 	clk_disable_unprepare(cclk->clk);
 	clk_put(cclk->clk);
diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
index 06267f0c88d4..c0e3a85ff85a 100644
--- a/drivers/base/boot_constraints/core.c
+++ b/drivers/base/boot_constraints/core.c
@@ -35,6 +35,76 @@ static int __init constraints_disable(char *str)
 }
 early_param("boot_constraints_disable", constraints_disable);
 
+/* Debugfs */
+
+static struct dentry *rootdir;
+
+static void constraint_device_add_debugfs(struct constraint_dev *cdev)
+{
+	struct device *dev = cdev->dev;
+
+	cdev->dentry = debugfs_create_dir(dev_name(dev), rootdir);
+	if (!cdev->dentry)
+		dev_err(dev, "Failed to create constraint dev debugfs dir\n");
+}
+
+static void constraint_device_remove_debugfs(struct constraint_dev *cdev)
+{
+	debugfs_remove_recursive(cdev->dentry);
+}
+
+void constraint_add_debugfs(struct constraint *constraint, const char *suffix)
+{
+	struct device *dev = constraint->cdev->dev;
+	const char *prefix;
+	char name[NAME_MAX];
+
+	switch (constraint->type) {
+	case DEV_BOOT_CONSTRAINT_CLK:
+		prefix = "clk";
+		break;
+	case DEV_BOOT_CONSTRAINT_PM:
+		prefix = "pm";
+		break;
+	case DEV_BOOT_CONSTRAINT_SUPPLY:
+		prefix = "supply";
+		break;
+	default:
+		dev_err(dev, "%s: Constraint type (%d) not supported\n",
+			__func__, constraint->type);
+		return;
+	}
+
+	snprintf(name, NAME_MAX, "%s-%s", prefix, suffix);
+
+	constraint->dentry = debugfs_create_dir(name, constraint->cdev->dentry);
+	if (!constraint->dentry)
+		dev_err(dev, "Failed to create constraint (%s) debugfs dir\n",
+			name);
+}
+
+void constraint_remove_debugfs(struct constraint *constraint)
+{
+	debugfs_remove_recursive(constraint->dentry);
+}
+
+static int __init constraint_debugfs_init(void)
+{
+	if (boot_constraints_disabled)
+		return -ENODEV;
+
+	/* Create /sys/kernel/debug/opp directory */
+	rootdir = debugfs_create_dir("boot_constraints", NULL);
+	if (!rootdir) {
+		pr_err("Failed to create root directory\n");
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+core_initcall(constraint_debugfs_init);
+
+
 /* Boot constraints core */
 
 static struct constraint_dev *constraint_device_find(struct device *dev)
@@ -62,12 +132,14 @@ static struct constraint_dev *constraint_device_allocate(struct device *dev)
 	INIT_LIST_HEAD(&cdev->constraints);
 
 	list_add(&cdev->node, &constraint_devices);
+	constraint_device_add_debugfs(cdev);
 
 	return cdev;
 }
 
 static void constraint_device_free(struct constraint_dev *cdev)
 {
+	constraint_device_remove_debugfs(cdev);
 	list_del(&cdev->node);
 	kfree(cdev);
 }
diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h
index a051c3d7c8ab..ee84e237c66a 100644
--- a/drivers/base/boot_constraints/core.h
+++ b/drivers/base/boot_constraints/core.h
@@ -8,6 +8,7 @@
 #define _CORE_H
 
 #include <linux/boot_constraint.h>
+#include <linux/debugfs.h>
 #include <linux/device.h>
 #include <linux/list.h>
 
@@ -15,6 +16,7 @@ struct constraint_dev {
 	struct device *dev;
 	struct list_head node;
 	struct list_head constraints;
+	struct dentry *dentry;
 };
 
 struct constraint {
@@ -23,12 +25,16 @@ struct constraint {
 	enum dev_boot_constraint_type type;
 	void (*free_resources)(void *data);
 	void *free_resources_data;
+	struct dentry *dentry;
 
 	int (*add)(struct constraint *constraint, void *data);
 	void (*remove)(struct constraint *constraint);
 	void *private;
 };
 
+void constraint_add_debugfs(struct constraint *constraint, const char *suffix);
+void constraint_remove_debugfs(struct constraint *constraint);
+
 /* Forward declarations of constraint specific callbacks */
 int constraint_clk_add(struct constraint *constraint, void *data);
 void constraint_clk_remove(struct constraint *constraint);
diff --git a/drivers/base/boot_constraints/pm.c b/drivers/base/boot_constraints/pm.c
index edba5eca5093..95910d0dc457 100644
--- a/drivers/base/boot_constraints/pm.c
+++ b/drivers/base/boot_constraints/pm.c
@@ -14,11 +14,19 @@
 int constraint_pm_add(struct constraint *constraint, void *data)
 {
 	struct device *dev = constraint->cdev->dev;
+	int ret;
 
-	return dev_pm_domain_attach(dev, true);
+	ret = dev_pm_domain_attach(dev, true);
+	if (ret)
+		return ret;
+
+	/* Debugfs */
+	constraint_add_debugfs(constraint, "domain");
+
+	return 0;
 }
 
 void constraint_pm_remove(struct constraint *constraint)
 {
-	/* Nothing to do for now */
+	constraint_remove_debugfs(constraint);
 }
diff --git a/drivers/base/boot_constraints/supply.c b/drivers/base/boot_constraints/supply.c
index 30f816dbf12c..b206f500b2bc 100644
--- a/drivers/base/boot_constraints/supply.c
+++ b/drivers/base/boot_constraints/supply.c
@@ -60,6 +60,15 @@ int constraint_supply_add(struct constraint *constraint, void *data)
 	csupply->supply.name = kstrdup_const(supply->name, GFP_KERNEL);
 	constraint->private = csupply;
 
+	/* Debugfs */
+	constraint_add_debugfs(constraint, supply->name);
+
+	debugfs_create_u32("u_volt_min", 0444, constraint->dentry,
+			   &csupply->supply.u_volt_min);
+
+	debugfs_create_u32("u_volt_max", 0444, constraint->dentry,
+			   &csupply->supply.u_volt_max);
+
 	return 0;
 
 remove_voltage:
@@ -80,6 +89,7 @@ void constraint_supply_remove(struct constraint *constraint)
 	struct device *dev = constraint->cdev->dev;
 	int ret;
 
+	constraint_remove_debugfs(constraint);
 	kfree_const(supply->name);
 
 	ret = regulator_disable(csupply->reg);
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH V3 6/8] drivers: boot_constraint: Add debugfs support
@ 2017-08-01  9:23   ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: linux-arm-kernel

This patch adds debugfs support for boot constraints. This is how it
looks for a "vmmc-supply" constraint for the MMC device.

$ ls -R /sys/kernel/debug/boot_constraints/
/sys/kernel/debug/boot_constraints/:
f723d000.dwmmc0

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0:
clk-ciu  pm-domain  supply-vmmc  supply-vmmcaux

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/clk-ciu:

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/pm-domain:

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmc:
u_volt_max  u_volt_min

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmcaux:
u_volt_max  u_volt_min

Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/boot_constraints/clk.c    |  4 ++
 drivers/base/boot_constraints/core.c   | 72 ++++++++++++++++++++++++++++++++++
 drivers/base/boot_constraints/core.h   |  6 +++
 drivers/base/boot_constraints/pm.c     | 12 +++++-
 drivers/base/boot_constraints/supply.c | 10 +++++
 5 files changed, 102 insertions(+), 2 deletions(-)

diff --git a/drivers/base/boot_constraints/clk.c b/drivers/base/boot_constraints/clk.c
index b5b1d63c3e76..bdbfcbc2944d 100644
--- a/drivers/base/boot_constraints/clk.c
+++ b/drivers/base/boot_constraints/clk.c
@@ -49,6 +49,9 @@ int constraint_clk_add(struct constraint *constraint, void *data)
 	cclk->clk_info.name = kstrdup_const(clk_info->name, GFP_KERNEL);
 	constraint->private = cclk;
 
+	/* Debugfs */
+	constraint_add_debugfs(constraint, clk_info->name);
+
 	return 0;
 
 put_clk:
@@ -63,6 +66,7 @@ void constraint_clk_remove(struct constraint *constraint)
 {
 	struct constraint_clk *cclk = constraint->private;
 
+	constraint_remove_debugfs(constraint);
 	kfree_const(cclk->clk_info.name);
 	clk_disable_unprepare(cclk->clk);
 	clk_put(cclk->clk);
diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
index 06267f0c88d4..c0e3a85ff85a 100644
--- a/drivers/base/boot_constraints/core.c
+++ b/drivers/base/boot_constraints/core.c
@@ -35,6 +35,76 @@ static int __init constraints_disable(char *str)
 }
 early_param("boot_constraints_disable", constraints_disable);
 
+/* Debugfs */
+
+static struct dentry *rootdir;
+
+static void constraint_device_add_debugfs(struct constraint_dev *cdev)
+{
+	struct device *dev = cdev->dev;
+
+	cdev->dentry = debugfs_create_dir(dev_name(dev), rootdir);
+	if (!cdev->dentry)
+		dev_err(dev, "Failed to create constraint dev debugfs dir\n");
+}
+
+static void constraint_device_remove_debugfs(struct constraint_dev *cdev)
+{
+	debugfs_remove_recursive(cdev->dentry);
+}
+
+void constraint_add_debugfs(struct constraint *constraint, const char *suffix)
+{
+	struct device *dev = constraint->cdev->dev;
+	const char *prefix;
+	char name[NAME_MAX];
+
+	switch (constraint->type) {
+	case DEV_BOOT_CONSTRAINT_CLK:
+		prefix = "clk";
+		break;
+	case DEV_BOOT_CONSTRAINT_PM:
+		prefix = "pm";
+		break;
+	case DEV_BOOT_CONSTRAINT_SUPPLY:
+		prefix = "supply";
+		break;
+	default:
+		dev_err(dev, "%s: Constraint type (%d) not supported\n",
+			__func__, constraint->type);
+		return;
+	}
+
+	snprintf(name, NAME_MAX, "%s-%s", prefix, suffix);
+
+	constraint->dentry = debugfs_create_dir(name, constraint->cdev->dentry);
+	if (!constraint->dentry)
+		dev_err(dev, "Failed to create constraint (%s) debugfs dir\n",
+			name);
+}
+
+void constraint_remove_debugfs(struct constraint *constraint)
+{
+	debugfs_remove_recursive(constraint->dentry);
+}
+
+static int __init constraint_debugfs_init(void)
+{
+	if (boot_constraints_disabled)
+		return -ENODEV;
+
+	/* Create /sys/kernel/debug/opp directory */
+	rootdir = debugfs_create_dir("boot_constraints", NULL);
+	if (!rootdir) {
+		pr_err("Failed to create root directory\n");
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+core_initcall(constraint_debugfs_init);
+
+
 /* Boot constraints core */
 
 static struct constraint_dev *constraint_device_find(struct device *dev)
@@ -62,12 +132,14 @@ static struct constraint_dev *constraint_device_allocate(struct device *dev)
 	INIT_LIST_HEAD(&cdev->constraints);
 
 	list_add(&cdev->node, &constraint_devices);
+	constraint_device_add_debugfs(cdev);
 
 	return cdev;
 }
 
 static void constraint_device_free(struct constraint_dev *cdev)
 {
+	constraint_device_remove_debugfs(cdev);
 	list_del(&cdev->node);
 	kfree(cdev);
 }
diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h
index a051c3d7c8ab..ee84e237c66a 100644
--- a/drivers/base/boot_constraints/core.h
+++ b/drivers/base/boot_constraints/core.h
@@ -8,6 +8,7 @@
 #define _CORE_H
 
 #include <linux/boot_constraint.h>
+#include <linux/debugfs.h>
 #include <linux/device.h>
 #include <linux/list.h>
 
@@ -15,6 +16,7 @@ struct constraint_dev {
 	struct device *dev;
 	struct list_head node;
 	struct list_head constraints;
+	struct dentry *dentry;
 };
 
 struct constraint {
@@ -23,12 +25,16 @@ struct constraint {
 	enum dev_boot_constraint_type type;
 	void (*free_resources)(void *data);
 	void *free_resources_data;
+	struct dentry *dentry;
 
 	int (*add)(struct constraint *constraint, void *data);
 	void (*remove)(struct constraint *constraint);
 	void *private;
 };
 
+void constraint_add_debugfs(struct constraint *constraint, const char *suffix);
+void constraint_remove_debugfs(struct constraint *constraint);
+
 /* Forward declarations of constraint specific callbacks */
 int constraint_clk_add(struct constraint *constraint, void *data);
 void constraint_clk_remove(struct constraint *constraint);
diff --git a/drivers/base/boot_constraints/pm.c b/drivers/base/boot_constraints/pm.c
index edba5eca5093..95910d0dc457 100644
--- a/drivers/base/boot_constraints/pm.c
+++ b/drivers/base/boot_constraints/pm.c
@@ -14,11 +14,19 @@
 int constraint_pm_add(struct constraint *constraint, void *data)
 {
 	struct device *dev = constraint->cdev->dev;
+	int ret;
 
-	return dev_pm_domain_attach(dev, true);
+	ret = dev_pm_domain_attach(dev, true);
+	if (ret)
+		return ret;
+
+	/* Debugfs */
+	constraint_add_debugfs(constraint, "domain");
+
+	return 0;
 }
 
 void constraint_pm_remove(struct constraint *constraint)
 {
-	/* Nothing to do for now */
+	constraint_remove_debugfs(constraint);
 }
diff --git a/drivers/base/boot_constraints/supply.c b/drivers/base/boot_constraints/supply.c
index 30f816dbf12c..b206f500b2bc 100644
--- a/drivers/base/boot_constraints/supply.c
+++ b/drivers/base/boot_constraints/supply.c
@@ -60,6 +60,15 @@ int constraint_supply_add(struct constraint *constraint, void *data)
 	csupply->supply.name = kstrdup_const(supply->name, GFP_KERNEL);
 	constraint->private = csupply;
 
+	/* Debugfs */
+	constraint_add_debugfs(constraint, supply->name);
+
+	debugfs_create_u32("u_volt_min", 0444, constraint->dentry,
+			   &csupply->supply.u_volt_min);
+
+	debugfs_create_u32("u_volt_max", 0444, constraint->dentry,
+			   &csupply->supply.u_volt_max);
+
 	return 0;
 
 remove_voltage:
@@ -80,6 +89,7 @@ void constraint_supply_remove(struct constraint *constraint)
 	struct device *dev = constraint->cdev->dev;
 	int ret;
 
+	constraint_remove_debugfs(constraint);
 	kfree_const(supply->name);
 
 	ret = regulator_disable(csupply->reg);
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH V3 7/8] drivers: boot_constraint: Manage deferrable constraints
  2017-08-01  9:23 ` Viresh Kumar
@ 2017-08-01  9:23   ` Viresh Kumar
  -1 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Viresh Kumar, Vincent Guittot, Mark Brown, Stephen Boyd,
	Rajendra Nayak, Shiraz Hashim, linux-kernel, linux-arm-kernel,
	robdclark

It is possible that some of the resources aren't available at the time
constraints are getting set and the boot constraints core will return
-EPROBE_DEFER for them. In order to retry adding the constraints at a
later point of time (after the resource is added and before any of its
users come up), this patch proposes two things:

- Each constraint is represented by a virtual platform device, so that
  it is re-probed again until the time all the dependencies aren't met.
  The platform device is removed along with the constraint, with help of
  the free_resources() callback.

- Enable early defer probing support by calling
  driver_enable_deferred_probe(), so that the core retries probing
  deferred devices every time any device is bound to a driver. This
  makes sure that the constraint is set before any of the users of the
  resources come up.

This is tested on ARM64 Hikey board where probe was deferred for a
device.

Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/base.h                            |   1 +
 drivers/base/boot_constraints/Makefile         |   2 +-
 drivers/base/boot_constraints/core.c           |   2 +-
 drivers/base/boot_constraints/core.h           |   2 +
 drivers/base/boot_constraints/deferrable_dev.c | 192 +++++++++++++++++++++++++
 drivers/base/dd.c                              |  12 ++
 include/linux/boot_constraint.h                |  10 ++
 7 files changed, 219 insertions(+), 2 deletions(-)
 create mode 100644 drivers/base/boot_constraints/deferrable_dev.c

diff --git a/drivers/base/base.h b/drivers/base/base.h
index 539432a14b5c..9c117f0dc44c 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -131,6 +131,7 @@ extern char *make_class_name(const char *name, struct kobject *kobj);
 extern int devres_release_all(struct device *dev);
 extern void device_block_probing(void);
 extern void device_unblock_probing(void);
+extern void driver_enable_deferred_probe(void);
 
 /* /sys/devices directory */
 extern struct kset *devices_kset;
diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile
index b7ade1a7afb5..a765094623a3 100644
--- a/drivers/base/boot_constraints/Makefile
+++ b/drivers/base/boot_constraints/Makefile
@@ -1,3 +1,3 @@
 # Makefile for device boot constraints
 
-obj-y := clk.o core.o pm.o supply.o
+obj-y := clk.o deferrable_dev.o core.o pm.o supply.o
diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
index c0e3a85ff85a..8e2f9b8fe80f 100644
--- a/drivers/base/boot_constraints/core.c
+++ b/drivers/base/boot_constraints/core.c
@@ -24,7 +24,7 @@
 static LIST_HEAD(constraint_devices);
 static DEFINE_MUTEX(constraint_devices_mutex);
 
-static bool boot_constraints_disabled;
+bool boot_constraints_disabled;
 
 static int __init constraints_disable(char *str)
 {
diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h
index ee84e237c66a..41354f7206bf 100644
--- a/drivers/base/boot_constraints/core.h
+++ b/drivers/base/boot_constraints/core.h
@@ -32,6 +32,8 @@ struct constraint {
 	void *private;
 };
 
+extern bool boot_constraints_disabled;
+
 void constraint_add_debugfs(struct constraint *constraint, const char *suffix);
 void constraint_remove_debugfs(struct constraint *constraint);
 
diff --git a/drivers/base/boot_constraints/deferrable_dev.c b/drivers/base/boot_constraints/deferrable_dev.c
new file mode 100644
index 000000000000..5169882f2af1
--- /dev/null
+++ b/drivers/base/boot_constraints/deferrable_dev.c
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * This file is released under the GPLv2.
+ */
+
+#define pr_fmt(fmt) "Boot Constraints: " fmt
+
+#include <linux/err.h>
+#include <linux/idr.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#include "../base.h"
+#include "core.h"
+
+static DEFINE_IDA(pdev_index);
+
+struct boot_constraint_pdata {
+	struct device *dev;
+	struct dev_boot_constraint constraint;
+	int probe_failed;
+	int index;
+};
+
+static void boot_constraint_remove(void *data)
+{
+	struct platform_device *pdev = data;
+	struct boot_constraint_pdata *pdata = dev_get_platdata(&pdev->dev);
+
+	ida_simple_remove(&pdev_index, pdata->index);
+	kfree(pdata->constraint.data);
+	platform_device_unregister(pdev);
+}
+
+/*
+ * A platform device is added for each and every constraint, to handle
+ * -EPROBE_DEFER properly.
+ */
+static int boot_constraint_probe(struct platform_device *pdev)
+{
+	struct boot_constraint_pdata *pdata = dev_get_platdata(&pdev->dev);
+	struct dev_boot_constraint_info info;
+	int ret;
+
+	if (WARN_ON(!pdata))
+		return -EINVAL;
+
+	info.constraint = pdata->constraint;
+	info.free_resources = boot_constraint_remove;
+	info.free_resources_data = pdev;
+
+	ret = dev_boot_constraint_add(pdata->dev, &info);
+	if (ret) {
+		if (ret == -EPROBE_DEFER)
+			driver_enable_deferred_probe();
+		else
+			pdata->probe_failed = ret;
+	}
+
+	return ret;
+}
+
+static struct platform_driver boot_constraint_driver = {
+	.driver = {
+		.name = "boot-constraints-dev",
+	},
+	.probe = boot_constraint_probe,
+};
+
+static int __init boot_constraint_init(void)
+{
+	return platform_driver_register(&boot_constraint_driver);
+}
+core_initcall(boot_constraint_init);
+
+static int _boot_constraint_add_dev(struct device *dev,
+				    struct dev_boot_constraint *constraint)
+{
+	struct boot_constraint_pdata pdata = {
+		.dev = dev,
+		.constraint.type = constraint->type,
+	};
+	struct platform_device *pdev;
+	struct boot_constraint_pdata *pdev_pdata;
+	int size, ret;
+
+	switch (constraint->type) {
+	case DEV_BOOT_CONSTRAINT_CLK:
+		size = sizeof(struct dev_boot_constraint_clk_info);
+		break;
+	case DEV_BOOT_CONSTRAINT_PM:
+		size = 0;
+		break;
+	case DEV_BOOT_CONSTRAINT_SUPPLY:
+		size = sizeof(struct dev_boot_constraint_supply_info);
+		break;
+	default:
+		dev_err(dev, "%s: Constraint type (%d) not supported\n",
+			__func__, constraint->type);
+		return -EINVAL;
+	}
+
+	/* Will be freed from boot_constraint_remove() */
+	pdata.constraint.data = kmemdup(constraint->data, size, GFP_KERNEL);
+	if (!pdata.constraint.data)
+		return -ENOMEM;
+
+	ret = ida_simple_get(&pdev_index, 0, 256, GFP_KERNEL);
+	if (ret < 0) {
+		dev_err(dev, "failed to allocate index (%d)\n", ret);
+		goto free;
+	}
+
+	pdata.index = ret;
+
+	pdev = platform_device_register_data(NULL, "boot-constraints-dev", ret,
+					     &pdata, sizeof(pdata));
+	if (IS_ERR(pdev)) {
+		dev_err(dev, "%s: Failed to create pdev (%ld)\n", __func__,
+			PTR_ERR(pdev));
+		ret = PTR_ERR(pdev);
+		goto ida_remove;
+	}
+
+	/* Release resources if probe has failed */
+	pdev_pdata = dev_get_platdata(&pdev->dev);
+	if (pdev_pdata->probe_failed) {
+		ret = pdev_pdata->probe_failed;
+		goto remove_pdev;
+	}
+
+	return 0;
+
+remove_pdev:
+	platform_device_unregister(pdev);
+ida_remove:
+	ida_simple_remove(&pdev_index, pdata.index);
+free:
+	kfree(pdata.constraint.data);
+
+	return ret;
+}
+
+int dev_boot_constraint_add_deferrable(struct device *dev,
+			struct dev_boot_constraint *constraints, int count)
+{
+	int ret, i;
+
+	if (boot_constraints_disabled)
+		return -ENODEV;
+
+	for (i = 0; i < count; i++) {
+		ret = _boot_constraint_add_dev(dev, &constraints[i]);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(dev_boot_constraint_add_deferrable);
+
+/* This only creates platform devices for now */
+int dev_boot_constraint_add_of_deferrable(const char *compatible,
+			struct dev_boot_constraint *constraints, int count)
+{
+	struct platform_device *pdev;
+	struct device_node *np;
+
+	if (boot_constraints_disabled)
+		return -ENODEV;
+
+	np = of_find_compatible_node(NULL, NULL, compatible);
+	if (!np)
+		return -ENODEV;
+
+	pdev = of_find_device_by_node(np);
+	if (!pdev)
+		pdev = of_platform_device_create(np, NULL, NULL);
+
+	of_node_put(np);
+
+	if (!pdev)
+		return -ENODEV;
+
+	return dev_boot_constraint_add_deferrable(&pdev->dev, constraints,
+						  count);
+}
+EXPORT_SYMBOL_GPL(dev_boot_constraint_add_of_deferrable);
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 2262a4a4c0e4..62a8a22f8b04 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -204,6 +204,18 @@ void device_unblock_probing(void)
 }
 
 /**
+ * driver_enable_deferred_probe() - Enable probing of deferred devices
+ *
+ * We don't want to get in the way when the bulk of drivers are getting probed
+ * and so deferred probe is disabled in the beginning. Enable it now because we
+ * need it.
+ */
+void driver_enable_deferred_probe(void)
+{
+	driver_deferred_probe_enable = true;
+}
+
+/**
  * deferred_probe_initcall() - Enable probing of deferred devices
  *
  * We don't want to get in the way when the bulk of drivers are getting probed.
diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h
index edc9abe7913a..f66c2f6d14dc 100644
--- a/include/linux/boot_constraint.h
+++ b/include/linux/boot_constraint.h
@@ -47,12 +47,22 @@ struct dev_boot_constraint_info {
 int dev_boot_constraint_add(struct device *dev,
 			    struct dev_boot_constraint_info *info);
 void dev_boot_constraints_remove(struct device *dev);
+int dev_boot_constraint_add_deferrable(struct device *dev,
+			struct dev_boot_constraint *constraints, int count);
+int dev_boot_constraint_add_of_deferrable(const char *compatible,
+			struct dev_boot_constraint *constraints, int count);
 #else
 static inline
 int dev_boot_constraint_add(struct device *dev,
 			    struct dev_boot_constraint_info *info);
 { return -EINVAL; }
 static inline void dev_boot_constraints_remove(struct device *dev) {}
+static inline int dev_boot_constraint_add_deferrable(struct device *dev,
+			struct dev_boot_constraint *constraints, int count)
+{ return -EINVAL; }
+static inline int dev_boot_constraint_add_of_deferrable(const char *compatible,
+			struct dev_boot_constraint *constraints, int count)
+{ return -EINVAL; }
 #endif /* CONFIG_DEV_BOOT_CONSTRAINTS */
 
 #endif /* _LINUX_BOOT_CONSTRAINT_H */
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH V3 7/8] drivers: boot_constraint: Manage deferrable constraints
@ 2017-08-01  9:23   ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: linux-arm-kernel

It is possible that some of the resources aren't available at the time
constraints are getting set and the boot constraints core will return
-EPROBE_DEFER for them. In order to retry adding the constraints at a
later point of time (after the resource is added and before any of its
users come up), this patch proposes two things:

- Each constraint is represented by a virtual platform device, so that
  it is re-probed again until the time all the dependencies aren't met.
  The platform device is removed along with the constraint, with help of
  the free_resources() callback.

- Enable early defer probing support by calling
  driver_enable_deferred_probe(), so that the core retries probing
  deferred devices every time any device is bound to a driver. This
  makes sure that the constraint is set before any of the users of the
  resources come up.

This is tested on ARM64 Hikey board where probe was deferred for a
device.

Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/base.h                            |   1 +
 drivers/base/boot_constraints/Makefile         |   2 +-
 drivers/base/boot_constraints/core.c           |   2 +-
 drivers/base/boot_constraints/core.h           |   2 +
 drivers/base/boot_constraints/deferrable_dev.c | 192 +++++++++++++++++++++++++
 drivers/base/dd.c                              |  12 ++
 include/linux/boot_constraint.h                |  10 ++
 7 files changed, 219 insertions(+), 2 deletions(-)
 create mode 100644 drivers/base/boot_constraints/deferrable_dev.c

diff --git a/drivers/base/base.h b/drivers/base/base.h
index 539432a14b5c..9c117f0dc44c 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -131,6 +131,7 @@ extern char *make_class_name(const char *name, struct kobject *kobj);
 extern int devres_release_all(struct device *dev);
 extern void device_block_probing(void);
 extern void device_unblock_probing(void);
+extern void driver_enable_deferred_probe(void);
 
 /* /sys/devices directory */
 extern struct kset *devices_kset;
diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile
index b7ade1a7afb5..a765094623a3 100644
--- a/drivers/base/boot_constraints/Makefile
+++ b/drivers/base/boot_constraints/Makefile
@@ -1,3 +1,3 @@
 # Makefile for device boot constraints
 
-obj-y := clk.o core.o pm.o supply.o
+obj-y := clk.o deferrable_dev.o core.o pm.o supply.o
diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
index c0e3a85ff85a..8e2f9b8fe80f 100644
--- a/drivers/base/boot_constraints/core.c
+++ b/drivers/base/boot_constraints/core.c
@@ -24,7 +24,7 @@
 static LIST_HEAD(constraint_devices);
 static DEFINE_MUTEX(constraint_devices_mutex);
 
-static bool boot_constraints_disabled;
+bool boot_constraints_disabled;
 
 static int __init constraints_disable(char *str)
 {
diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h
index ee84e237c66a..41354f7206bf 100644
--- a/drivers/base/boot_constraints/core.h
+++ b/drivers/base/boot_constraints/core.h
@@ -32,6 +32,8 @@ struct constraint {
 	void *private;
 };
 
+extern bool boot_constraints_disabled;
+
 void constraint_add_debugfs(struct constraint *constraint, const char *suffix);
 void constraint_remove_debugfs(struct constraint *constraint);
 
diff --git a/drivers/base/boot_constraints/deferrable_dev.c b/drivers/base/boot_constraints/deferrable_dev.c
new file mode 100644
index 000000000000..5169882f2af1
--- /dev/null
+++ b/drivers/base/boot_constraints/deferrable_dev.c
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * This file is released under the GPLv2.
+ */
+
+#define pr_fmt(fmt) "Boot Constraints: " fmt
+
+#include <linux/err.h>
+#include <linux/idr.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#include "../base.h"
+#include "core.h"
+
+static DEFINE_IDA(pdev_index);
+
+struct boot_constraint_pdata {
+	struct device *dev;
+	struct dev_boot_constraint constraint;
+	int probe_failed;
+	int index;
+};
+
+static void boot_constraint_remove(void *data)
+{
+	struct platform_device *pdev = data;
+	struct boot_constraint_pdata *pdata = dev_get_platdata(&pdev->dev);
+
+	ida_simple_remove(&pdev_index, pdata->index);
+	kfree(pdata->constraint.data);
+	platform_device_unregister(pdev);
+}
+
+/*
+ * A platform device is added for each and every constraint, to handle
+ * -EPROBE_DEFER properly.
+ */
+static int boot_constraint_probe(struct platform_device *pdev)
+{
+	struct boot_constraint_pdata *pdata = dev_get_platdata(&pdev->dev);
+	struct dev_boot_constraint_info info;
+	int ret;
+
+	if (WARN_ON(!pdata))
+		return -EINVAL;
+
+	info.constraint = pdata->constraint;
+	info.free_resources = boot_constraint_remove;
+	info.free_resources_data = pdev;
+
+	ret = dev_boot_constraint_add(pdata->dev, &info);
+	if (ret) {
+		if (ret == -EPROBE_DEFER)
+			driver_enable_deferred_probe();
+		else
+			pdata->probe_failed = ret;
+	}
+
+	return ret;
+}
+
+static struct platform_driver boot_constraint_driver = {
+	.driver = {
+		.name = "boot-constraints-dev",
+	},
+	.probe = boot_constraint_probe,
+};
+
+static int __init boot_constraint_init(void)
+{
+	return platform_driver_register(&boot_constraint_driver);
+}
+core_initcall(boot_constraint_init);
+
+static int _boot_constraint_add_dev(struct device *dev,
+				    struct dev_boot_constraint *constraint)
+{
+	struct boot_constraint_pdata pdata = {
+		.dev = dev,
+		.constraint.type = constraint->type,
+	};
+	struct platform_device *pdev;
+	struct boot_constraint_pdata *pdev_pdata;
+	int size, ret;
+
+	switch (constraint->type) {
+	case DEV_BOOT_CONSTRAINT_CLK:
+		size = sizeof(struct dev_boot_constraint_clk_info);
+		break;
+	case DEV_BOOT_CONSTRAINT_PM:
+		size = 0;
+		break;
+	case DEV_BOOT_CONSTRAINT_SUPPLY:
+		size = sizeof(struct dev_boot_constraint_supply_info);
+		break;
+	default:
+		dev_err(dev, "%s: Constraint type (%d) not supported\n",
+			__func__, constraint->type);
+		return -EINVAL;
+	}
+
+	/* Will be freed from boot_constraint_remove() */
+	pdata.constraint.data = kmemdup(constraint->data, size, GFP_KERNEL);
+	if (!pdata.constraint.data)
+		return -ENOMEM;
+
+	ret = ida_simple_get(&pdev_index, 0, 256, GFP_KERNEL);
+	if (ret < 0) {
+		dev_err(dev, "failed to allocate index (%d)\n", ret);
+		goto free;
+	}
+
+	pdata.index = ret;
+
+	pdev = platform_device_register_data(NULL, "boot-constraints-dev", ret,
+					     &pdata, sizeof(pdata));
+	if (IS_ERR(pdev)) {
+		dev_err(dev, "%s: Failed to create pdev (%ld)\n", __func__,
+			PTR_ERR(pdev));
+		ret = PTR_ERR(pdev);
+		goto ida_remove;
+	}
+
+	/* Release resources if probe has failed */
+	pdev_pdata = dev_get_platdata(&pdev->dev);
+	if (pdev_pdata->probe_failed) {
+		ret = pdev_pdata->probe_failed;
+		goto remove_pdev;
+	}
+
+	return 0;
+
+remove_pdev:
+	platform_device_unregister(pdev);
+ida_remove:
+	ida_simple_remove(&pdev_index, pdata.index);
+free:
+	kfree(pdata.constraint.data);
+
+	return ret;
+}
+
+int dev_boot_constraint_add_deferrable(struct device *dev,
+			struct dev_boot_constraint *constraints, int count)
+{
+	int ret, i;
+
+	if (boot_constraints_disabled)
+		return -ENODEV;
+
+	for (i = 0; i < count; i++) {
+		ret = _boot_constraint_add_dev(dev, &constraints[i]);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(dev_boot_constraint_add_deferrable);
+
+/* This only creates platform devices for now */
+int dev_boot_constraint_add_of_deferrable(const char *compatible,
+			struct dev_boot_constraint *constraints, int count)
+{
+	struct platform_device *pdev;
+	struct device_node *np;
+
+	if (boot_constraints_disabled)
+		return -ENODEV;
+
+	np = of_find_compatible_node(NULL, NULL, compatible);
+	if (!np)
+		return -ENODEV;
+
+	pdev = of_find_device_by_node(np);
+	if (!pdev)
+		pdev = of_platform_device_create(np, NULL, NULL);
+
+	of_node_put(np);
+
+	if (!pdev)
+		return -ENODEV;
+
+	return dev_boot_constraint_add_deferrable(&pdev->dev, constraints,
+						  count);
+}
+EXPORT_SYMBOL_GPL(dev_boot_constraint_add_of_deferrable);
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 2262a4a4c0e4..62a8a22f8b04 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -204,6 +204,18 @@ void device_unblock_probing(void)
 }
 
 /**
+ * driver_enable_deferred_probe() - Enable probing of deferred devices
+ *
+ * We don't want to get in the way when the bulk of drivers are getting probed
+ * and so deferred probe is disabled in the beginning. Enable it now because we
+ * need it.
+ */
+void driver_enable_deferred_probe(void)
+{
+	driver_deferred_probe_enable = true;
+}
+
+/**
  * deferred_probe_initcall() - Enable probing of deferred devices
  *
  * We don't want to get in the way when the bulk of drivers are getting probed.
diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h
index edc9abe7913a..f66c2f6d14dc 100644
--- a/include/linux/boot_constraint.h
+++ b/include/linux/boot_constraint.h
@@ -47,12 +47,22 @@ struct dev_boot_constraint_info {
 int dev_boot_constraint_add(struct device *dev,
 			    struct dev_boot_constraint_info *info);
 void dev_boot_constraints_remove(struct device *dev);
+int dev_boot_constraint_add_deferrable(struct device *dev,
+			struct dev_boot_constraint *constraints, int count);
+int dev_boot_constraint_add_of_deferrable(const char *compatible,
+			struct dev_boot_constraint *constraints, int count);
 #else
 static inline
 int dev_boot_constraint_add(struct device *dev,
 			    struct dev_boot_constraint_info *info);
 { return -EINVAL; }
 static inline void dev_boot_constraints_remove(struct device *dev) {}
+static inline int dev_boot_constraint_add_deferrable(struct device *dev,
+			struct dev_boot_constraint *constraints, int count)
+{ return -EINVAL; }
+static inline int dev_boot_constraint_add_of_deferrable(const char *compatible,
+			struct dev_boot_constraint *constraints, int count)
+{ return -EINVAL; }
 #endif /* CONFIG_DEV_BOOT_CONSTRAINTS */
 
 #endif /* _LINUX_BOOT_CONSTRAINT_H */
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH V3 8/8] drivers: boot_constraint: Add Qualcomm display controller constraints
  2017-08-01  9:23 ` Viresh Kumar
@ 2017-08-01  9:23   ` Viresh Kumar
  -1 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Viresh Kumar, Vincent Guittot, Mark Brown, Stephen Boyd,
	Rajendra Nayak, Shiraz Hashim, linux-kernel, linux-arm-kernel,
	robdclark

From: Rajendra Nayak <rnayak@codeaurora.org>

NOT TO BE MERGED

This sets boot constraints for the display controller used on Qualcomm
dragonboard 410c.

Not-signed-off-by: Rajendra Nayak <rnayak@codeaurora.org>
Not-signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/boot_constraints/Makefile       |   2 +-
 drivers/base/boot_constraints/qcom-display.c | 107 +++++++++++++++++++++++++++
 2 files changed, 108 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/boot_constraints/qcom-display.c

diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile
index a765094623a3..b0bdf67ebbbf 100644
--- a/drivers/base/boot_constraints/Makefile
+++ b/drivers/base/boot_constraints/Makefile
@@ -1,3 +1,3 @@
 # Makefile for device boot constraints
 
-obj-y := clk.o deferrable_dev.o core.o pm.o supply.o
+obj-y := clk.o deferrable_dev.o core.o pm.o supply.o qcom-display.o
diff --git a/drivers/base/boot_constraints/qcom-display.c b/drivers/base/boot_constraints/qcom-display.c
new file mode 100644
index 000000000000..29f930ac692b
--- /dev/null
+++ b/drivers/base/boot_constraints/qcom-display.c
@@ -0,0 +1,107 @@
+/*
+ * Sets up constraints on behalf of the bootloader, which uses display
+ * controller to display a flash screen during system boot.
+ */
+
+#include <linux/boot_constraint.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+
+struct dev_boot_constraint_clk_info iface_clk_info = {
+	.name = "iface_clk",
+};
+
+struct dev_boot_constraint_clk_info bus_clk_info = {
+	.name = "bus_clk",
+};
+
+struct dev_boot_constraint_clk_info core_clk_info = {
+	.name = "core_clk",
+};
+
+struct dev_boot_constraint_clk_info vsync_clk_info = {
+	.name = "vsync_clk",
+};
+
+struct dev_boot_constraint_clk_info esc0_clk_info = {
+	.name = "core_clk",
+};
+
+struct dev_boot_constraint_clk_info byte_clk_info = {
+	.name = "byte_clk",
+};
+
+struct dev_boot_constraint_clk_info pixel_clk_info = {
+	.name = "pixel_clk",
+};
+
+struct dev_boot_constraint_supply_info vdda_info = {
+	.name = "vdda"
+};
+
+struct dev_boot_constraint_supply_info vddio_info = {
+	.name = "vddio"
+};
+
+struct dev_boot_constraint constraints_mdss[] = {
+	{
+		.type = DEV_BOOT_CONSTRAINT_PM,
+		.data = NULL,
+	},
+};
+
+struct dev_boot_constraint constraints_mdp[] = {
+	{
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &iface_clk_info,
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &bus_clk_info,
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &core_clk_info,
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &vsync_clk_info,
+	},
+};
+
+struct dev_boot_constraint constraints_dsi[] = {
+	{
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &esc0_clk_info,
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &byte_clk_info,
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &pixel_clk_info,
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_SUPPLY,
+		.data = &vdda_info,
+
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_SUPPLY,
+		.data = &vddio_info,
+	},
+};
+
+static int __init qcom_constraints_init(void)
+{
+	int ret;
+
+	ret = dev_boot_constraint_add_of_deferrable("qcom,mdss",
+				constraints_mdss, ARRAY_SIZE(constraints_mdss));
+	if (ret)
+		return ret;
+
+	ret = dev_boot_constraint_add_of_deferrable("qcom,mdp5",
+				constraints_mdp, ARRAY_SIZE(constraints_mdp));
+	if (ret)
+		return ret;
+
+	ret = dev_boot_constraint_add_of_deferrable("qcom,mdss-dsi-ctrl",
+				constraints_dsi, ARRAY_SIZE(constraints_dsi));
+	return ret;
+}
+subsys_initcall(qcom_constraints_init);
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH V3 8/8] drivers: boot_constraint: Add Qualcomm display controller constraints
@ 2017-08-01  9:23   ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-01  9:23 UTC (permalink / raw)
  To: linux-arm-kernel

From: Rajendra Nayak <rnayak@codeaurora.org>

NOT TO BE MERGED

This sets boot constraints for the display controller used on Qualcomm
dragonboard 410c.

Not-signed-off-by: Rajendra Nayak <rnayak@codeaurora.org>
Not-signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/boot_constraints/Makefile       |   2 +-
 drivers/base/boot_constraints/qcom-display.c | 107 +++++++++++++++++++++++++++
 2 files changed, 108 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/boot_constraints/qcom-display.c

diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile
index a765094623a3..b0bdf67ebbbf 100644
--- a/drivers/base/boot_constraints/Makefile
+++ b/drivers/base/boot_constraints/Makefile
@@ -1,3 +1,3 @@
 # Makefile for device boot constraints
 
-obj-y := clk.o deferrable_dev.o core.o pm.o supply.o
+obj-y := clk.o deferrable_dev.o core.o pm.o supply.o qcom-display.o
diff --git a/drivers/base/boot_constraints/qcom-display.c b/drivers/base/boot_constraints/qcom-display.c
new file mode 100644
index 000000000000..29f930ac692b
--- /dev/null
+++ b/drivers/base/boot_constraints/qcom-display.c
@@ -0,0 +1,107 @@
+/*
+ * Sets up constraints on behalf of the bootloader, which uses display
+ * controller to display a flash screen during system boot.
+ */
+
+#include <linux/boot_constraint.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+
+struct dev_boot_constraint_clk_info iface_clk_info = {
+	.name = "iface_clk",
+};
+
+struct dev_boot_constraint_clk_info bus_clk_info = {
+	.name = "bus_clk",
+};
+
+struct dev_boot_constraint_clk_info core_clk_info = {
+	.name = "core_clk",
+};
+
+struct dev_boot_constraint_clk_info vsync_clk_info = {
+	.name = "vsync_clk",
+};
+
+struct dev_boot_constraint_clk_info esc0_clk_info = {
+	.name = "core_clk",
+};
+
+struct dev_boot_constraint_clk_info byte_clk_info = {
+	.name = "byte_clk",
+};
+
+struct dev_boot_constraint_clk_info pixel_clk_info = {
+	.name = "pixel_clk",
+};
+
+struct dev_boot_constraint_supply_info vdda_info = {
+	.name = "vdda"
+};
+
+struct dev_boot_constraint_supply_info vddio_info = {
+	.name = "vddio"
+};
+
+struct dev_boot_constraint constraints_mdss[] = {
+	{
+		.type = DEV_BOOT_CONSTRAINT_PM,
+		.data = NULL,
+	},
+};
+
+struct dev_boot_constraint constraints_mdp[] = {
+	{
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &iface_clk_info,
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &bus_clk_info,
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &core_clk_info,
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &vsync_clk_info,
+	},
+};
+
+struct dev_boot_constraint constraints_dsi[] = {
+	{
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &esc0_clk_info,
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &byte_clk_info,
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &pixel_clk_info,
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_SUPPLY,
+		.data = &vdda_info,
+
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_SUPPLY,
+		.data = &vddio_info,
+	},
+};
+
+static int __init qcom_constraints_init(void)
+{
+	int ret;
+
+	ret = dev_boot_constraint_add_of_deferrable("qcom,mdss",
+				constraints_mdss, ARRAY_SIZE(constraints_mdss));
+	if (ret)
+		return ret;
+
+	ret = dev_boot_constraint_add_of_deferrable("qcom,mdp5",
+				constraints_mdp, ARRAY_SIZE(constraints_mdp));
+	if (ret)
+		return ret;
+
+	ret = dev_boot_constraint_add_of_deferrable("qcom,mdss-dsi-ctrl",
+				constraints_dsi, ARRAY_SIZE(constraints_dsi));
+	return ret;
+}
+subsys_initcall(qcom_constraints_init);
-- 
2.13.0.71.gd7076ec9c9cb

^ permalink raw reply related	[flat|nested] 46+ messages in thread

* Re: [PATCH V3 6/8] drivers: boot_constraint: Add debugfs support
  2017-08-01  9:23   ` Viresh Kumar
@ 2017-08-29  6:36     ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 46+ messages in thread
From: Greg Kroah-Hartman @ 2017-08-29  6:36 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Vincent Guittot, Mark Brown, Stephen Boyd, Rajendra Nayak,
	Shiraz Hashim, linux-kernel, linux-arm-kernel, robdclark

On Tue, Aug 01, 2017 at 02:53:47PM +0530, Viresh Kumar wrote:
> This patch adds debugfs support for boot constraints. This is how it
> looks for a "vmmc-supply" constraint for the MMC device.
> 
> $ ls -R /sys/kernel/debug/boot_constraints/
> /sys/kernel/debug/boot_constraints/:
> f723d000.dwmmc0
> 
> /sys/kernel/debug/boot_constraints/f723d000.dwmmc0:
> clk-ciu  pm-domain  supply-vmmc  supply-vmmcaux
> 
> /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/clk-ciu:
> 
> /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/pm-domain:
> 
> /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmc:
> u_volt_max  u_volt_min
> 
> /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmcaux:
> u_volt_max  u_volt_min
> 
> Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

Minor debugfs api interaction nits below:


> ---
>  drivers/base/boot_constraints/clk.c    |  4 ++
>  drivers/base/boot_constraints/core.c   | 72 ++++++++++++++++++++++++++++++++++
>  drivers/base/boot_constraints/core.h   |  6 +++
>  drivers/base/boot_constraints/pm.c     | 12 +++++-
>  drivers/base/boot_constraints/supply.c | 10 +++++
>  5 files changed, 102 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/base/boot_constraints/clk.c b/drivers/base/boot_constraints/clk.c
> index b5b1d63c3e76..bdbfcbc2944d 100644
> --- a/drivers/base/boot_constraints/clk.c
> +++ b/drivers/base/boot_constraints/clk.c
> @@ -49,6 +49,9 @@ int constraint_clk_add(struct constraint *constraint, void *data)
>  	cclk->clk_info.name = kstrdup_const(clk_info->name, GFP_KERNEL);
>  	constraint->private = cclk;
>  
> +	/* Debugfs */

That's obvious no need for the comment...

> +	constraint_add_debugfs(constraint, clk_info->name);
> +
>  	return 0;
>  
>  put_clk:
> @@ -63,6 +66,7 @@ void constraint_clk_remove(struct constraint *constraint)
>  {
>  	struct constraint_clk *cclk = constraint->private;
>  
> +	constraint_remove_debugfs(constraint);
>  	kfree_const(cclk->clk_info.name);
>  	clk_disable_unprepare(cclk->clk);
>  	clk_put(cclk->clk);
> diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
> index 06267f0c88d4..c0e3a85ff85a 100644
> --- a/drivers/base/boot_constraints/core.c
> +++ b/drivers/base/boot_constraints/core.c
> @@ -35,6 +35,76 @@ static int __init constraints_disable(char *str)
>  }
>  early_param("boot_constraints_disable", constraints_disable);
>  
> +/* Debugfs */
> +
> +static struct dentry *rootdir;
> +
> +static void constraint_device_add_debugfs(struct constraint_dev *cdev)
> +{
> +	struct device *dev = cdev->dev;
> +
> +	cdev->dentry = debugfs_create_dir(dev_name(dev), rootdir);
> +	if (!cdev->dentry)
> +		dev_err(dev, "Failed to create constraint dev debugfs dir\n");

No, you never need to check the return value of a debugfs call.  You
shouldn't care what happens here, it's just debugfs, a user can't do
anything with this info, and neither should you change your actions
(which you aren't here, which is good, but not true later on...)

So just call the function, save the value, and move on, it's always
going to return a value that you can use in any future debugfs calls, no
need to care.

> +}
> +
> +static void constraint_device_remove_debugfs(struct constraint_dev *cdev)
> +{
> +	debugfs_remove_recursive(cdev->dentry);
> +}
> +
> +void constraint_add_debugfs(struct constraint *constraint, const char *suffix)
> +{
> +	struct device *dev = constraint->cdev->dev;
> +	const char *prefix;
> +	char name[NAME_MAX];
> +
> +	switch (constraint->type) {
> +	case DEV_BOOT_CONSTRAINT_CLK:
> +		prefix = "clk";
> +		break;
> +	case DEV_BOOT_CONSTRAINT_PM:
> +		prefix = "pm";
> +		break;
> +	case DEV_BOOT_CONSTRAINT_SUPPLY:
> +		prefix = "supply";
> +		break;
> +	default:
> +		dev_err(dev, "%s: Constraint type (%d) not supported\n",
> +			__func__, constraint->type);
> +		return;
> +	}
> +
> +	snprintf(name, NAME_MAX, "%s-%s", prefix, suffix);
> +
> +	constraint->dentry = debugfs_create_dir(name, constraint->cdev->dentry);
> +	if (!constraint->dentry)
> +		dev_err(dev, "Failed to create constraint (%s) debugfs dir\n",
> +			name);

Again, you don't care, just call it and move on.

> +}
> +
> +void constraint_remove_debugfs(struct constraint *constraint)
> +{
> +	debugfs_remove_recursive(constraint->dentry);
> +}
> +
> +static int __init constraint_debugfs_init(void)
> +{
> +	if (boot_constraints_disabled)
> +		return -ENODEV;
> +
> +	/* Create /sys/kernel/debug/opp directory */
> +	rootdir = debugfs_create_dir("boot_constraints", NULL);
> +	if (!rootdir) {
> +		pr_err("Failed to create root directory\n");
> +		return -ENOMEM;

And again, you don't care, call it and move on, don't return an
incorrect value like this :)



> +	}
> +
> +	return 0;
> +}
> +core_initcall(constraint_debugfs_init);
> +
> +
>  /* Boot constraints core */
>  
>  static struct constraint_dev *constraint_device_find(struct device *dev)
> @@ -62,12 +132,14 @@ static struct constraint_dev *constraint_device_allocate(struct device *dev)
>  	INIT_LIST_HEAD(&cdev->constraints);
>  
>  	list_add(&cdev->node, &constraint_devices);
> +	constraint_device_add_debugfs(cdev);
>  
>  	return cdev;
>  }
>  
>  static void constraint_device_free(struct constraint_dev *cdev)
>  {
> +	constraint_device_remove_debugfs(cdev);
>  	list_del(&cdev->node);
>  	kfree(cdev);
>  }
> diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h
> index a051c3d7c8ab..ee84e237c66a 100644
> --- a/drivers/base/boot_constraints/core.h
> +++ b/drivers/base/boot_constraints/core.h
> @@ -8,6 +8,7 @@
>  #define _CORE_H
>  
>  #include <linux/boot_constraint.h>
> +#include <linux/debugfs.h>
>  #include <linux/device.h>
>  #include <linux/list.h>
>  
> @@ -15,6 +16,7 @@ struct constraint_dev {
>  	struct device *dev;
>  	struct list_head node;
>  	struct list_head constraints;
> +	struct dentry *dentry;
>  };
>  
>  struct constraint {
> @@ -23,12 +25,16 @@ struct constraint {
>  	enum dev_boot_constraint_type type;
>  	void (*free_resources)(void *data);
>  	void *free_resources_data;
> +	struct dentry *dentry;
>  
>  	int (*add)(struct constraint *constraint, void *data);
>  	void (*remove)(struct constraint *constraint);
>  	void *private;
>  };
>  
> +void constraint_add_debugfs(struct constraint *constraint, const char *suffix);
> +void constraint_remove_debugfs(struct constraint *constraint);
> +
>  /* Forward declarations of constraint specific callbacks */
>  int constraint_clk_add(struct constraint *constraint, void *data);
>  void constraint_clk_remove(struct constraint *constraint);
> diff --git a/drivers/base/boot_constraints/pm.c b/drivers/base/boot_constraints/pm.c
> index edba5eca5093..95910d0dc457 100644
> --- a/drivers/base/boot_constraints/pm.c
> +++ b/drivers/base/boot_constraints/pm.c
> @@ -14,11 +14,19 @@
>  int constraint_pm_add(struct constraint *constraint, void *data)
>  {
>  	struct device *dev = constraint->cdev->dev;
> +	int ret;
>  
> -	return dev_pm_domain_attach(dev, true);
> +	ret = dev_pm_domain_attach(dev, true);
> +	if (ret)
> +		return ret;
> +
> +	/* Debugfs */

Again, obvious comment, no need to have it.


> +	constraint_add_debugfs(constraint, "domain");
> +
> +	return 0;
>  }
>  
>  void constraint_pm_remove(struct constraint *constraint)
>  {
> -	/* Nothing to do for now */
> +	constraint_remove_debugfs(constraint);
>  }
> diff --git a/drivers/base/boot_constraints/supply.c b/drivers/base/boot_constraints/supply.c
> index 30f816dbf12c..b206f500b2bc 100644
> --- a/drivers/base/boot_constraints/supply.c
> +++ b/drivers/base/boot_constraints/supply.c
> @@ -60,6 +60,15 @@ int constraint_supply_add(struct constraint *constraint, void *data)
>  	csupply->supply.name = kstrdup_const(supply->name, GFP_KERNEL);
>  	constraint->private = csupply;
>  
> +	/* Debugfs */
> +	constraint_add_debugfs(constraint, supply->name);
> +
> +	debugfs_create_u32("u_volt_min", 0444, constraint->dentry,
> +			   &csupply->supply.u_volt_min);
> +
> +	debugfs_create_u32("u_volt_max", 0444, constraint->dentry,
> +			   &csupply->supply.u_volt_max);

See, that's how you do it!

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 6/8] drivers: boot_constraint: Add debugfs support
@ 2017-08-29  6:36     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 46+ messages in thread
From: Greg Kroah-Hartman @ 2017-08-29  6:36 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Aug 01, 2017 at 02:53:47PM +0530, Viresh Kumar wrote:
> This patch adds debugfs support for boot constraints. This is how it
> looks for a "vmmc-supply" constraint for the MMC device.
> 
> $ ls -R /sys/kernel/debug/boot_constraints/
> /sys/kernel/debug/boot_constraints/:
> f723d000.dwmmc0
> 
> /sys/kernel/debug/boot_constraints/f723d000.dwmmc0:
> clk-ciu  pm-domain  supply-vmmc  supply-vmmcaux
> 
> /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/clk-ciu:
> 
> /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/pm-domain:
> 
> /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmc:
> u_volt_max  u_volt_min
> 
> /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmcaux:
> u_volt_max  u_volt_min
> 
> Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

Minor debugfs api interaction nits below:


> ---
>  drivers/base/boot_constraints/clk.c    |  4 ++
>  drivers/base/boot_constraints/core.c   | 72 ++++++++++++++++++++++++++++++++++
>  drivers/base/boot_constraints/core.h   |  6 +++
>  drivers/base/boot_constraints/pm.c     | 12 +++++-
>  drivers/base/boot_constraints/supply.c | 10 +++++
>  5 files changed, 102 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/base/boot_constraints/clk.c b/drivers/base/boot_constraints/clk.c
> index b5b1d63c3e76..bdbfcbc2944d 100644
> --- a/drivers/base/boot_constraints/clk.c
> +++ b/drivers/base/boot_constraints/clk.c
> @@ -49,6 +49,9 @@ int constraint_clk_add(struct constraint *constraint, void *data)
>  	cclk->clk_info.name = kstrdup_const(clk_info->name, GFP_KERNEL);
>  	constraint->private = cclk;
>  
> +	/* Debugfs */

That's obvious no need for the comment...

> +	constraint_add_debugfs(constraint, clk_info->name);
> +
>  	return 0;
>  
>  put_clk:
> @@ -63,6 +66,7 @@ void constraint_clk_remove(struct constraint *constraint)
>  {
>  	struct constraint_clk *cclk = constraint->private;
>  
> +	constraint_remove_debugfs(constraint);
>  	kfree_const(cclk->clk_info.name);
>  	clk_disable_unprepare(cclk->clk);
>  	clk_put(cclk->clk);
> diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
> index 06267f0c88d4..c0e3a85ff85a 100644
> --- a/drivers/base/boot_constraints/core.c
> +++ b/drivers/base/boot_constraints/core.c
> @@ -35,6 +35,76 @@ static int __init constraints_disable(char *str)
>  }
>  early_param("boot_constraints_disable", constraints_disable);
>  
> +/* Debugfs */
> +
> +static struct dentry *rootdir;
> +
> +static void constraint_device_add_debugfs(struct constraint_dev *cdev)
> +{
> +	struct device *dev = cdev->dev;
> +
> +	cdev->dentry = debugfs_create_dir(dev_name(dev), rootdir);
> +	if (!cdev->dentry)
> +		dev_err(dev, "Failed to create constraint dev debugfs dir\n");

No, you never need to check the return value of a debugfs call.  You
shouldn't care what happens here, it's just debugfs, a user can't do
anything with this info, and neither should you change your actions
(which you aren't here, which is good, but not true later on...)

So just call the function, save the value, and move on, it's always
going to return a value that you can use in any future debugfs calls, no
need to care.

> +}
> +
> +static void constraint_device_remove_debugfs(struct constraint_dev *cdev)
> +{
> +	debugfs_remove_recursive(cdev->dentry);
> +}
> +
> +void constraint_add_debugfs(struct constraint *constraint, const char *suffix)
> +{
> +	struct device *dev = constraint->cdev->dev;
> +	const char *prefix;
> +	char name[NAME_MAX];
> +
> +	switch (constraint->type) {
> +	case DEV_BOOT_CONSTRAINT_CLK:
> +		prefix = "clk";
> +		break;
> +	case DEV_BOOT_CONSTRAINT_PM:
> +		prefix = "pm";
> +		break;
> +	case DEV_BOOT_CONSTRAINT_SUPPLY:
> +		prefix = "supply";
> +		break;
> +	default:
> +		dev_err(dev, "%s: Constraint type (%d) not supported\n",
> +			__func__, constraint->type);
> +		return;
> +	}
> +
> +	snprintf(name, NAME_MAX, "%s-%s", prefix, suffix);
> +
> +	constraint->dentry = debugfs_create_dir(name, constraint->cdev->dentry);
> +	if (!constraint->dentry)
> +		dev_err(dev, "Failed to create constraint (%s) debugfs dir\n",
> +			name);

Again, you don't care, just call it and move on.

> +}
> +
> +void constraint_remove_debugfs(struct constraint *constraint)
> +{
> +	debugfs_remove_recursive(constraint->dentry);
> +}
> +
> +static int __init constraint_debugfs_init(void)
> +{
> +	if (boot_constraints_disabled)
> +		return -ENODEV;
> +
> +	/* Create /sys/kernel/debug/opp directory */
> +	rootdir = debugfs_create_dir("boot_constraints", NULL);
> +	if (!rootdir) {
> +		pr_err("Failed to create root directory\n");
> +		return -ENOMEM;

And again, you don't care, call it and move on, don't return an
incorrect value like this :)



> +	}
> +
> +	return 0;
> +}
> +core_initcall(constraint_debugfs_init);
> +
> +
>  /* Boot constraints core */
>  
>  static struct constraint_dev *constraint_device_find(struct device *dev)
> @@ -62,12 +132,14 @@ static struct constraint_dev *constraint_device_allocate(struct device *dev)
>  	INIT_LIST_HEAD(&cdev->constraints);
>  
>  	list_add(&cdev->node, &constraint_devices);
> +	constraint_device_add_debugfs(cdev);
>  
>  	return cdev;
>  }
>  
>  static void constraint_device_free(struct constraint_dev *cdev)
>  {
> +	constraint_device_remove_debugfs(cdev);
>  	list_del(&cdev->node);
>  	kfree(cdev);
>  }
> diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h
> index a051c3d7c8ab..ee84e237c66a 100644
> --- a/drivers/base/boot_constraints/core.h
> +++ b/drivers/base/boot_constraints/core.h
> @@ -8,6 +8,7 @@
>  #define _CORE_H
>  
>  #include <linux/boot_constraint.h>
> +#include <linux/debugfs.h>
>  #include <linux/device.h>
>  #include <linux/list.h>
>  
> @@ -15,6 +16,7 @@ struct constraint_dev {
>  	struct device *dev;
>  	struct list_head node;
>  	struct list_head constraints;
> +	struct dentry *dentry;
>  };
>  
>  struct constraint {
> @@ -23,12 +25,16 @@ struct constraint {
>  	enum dev_boot_constraint_type type;
>  	void (*free_resources)(void *data);
>  	void *free_resources_data;
> +	struct dentry *dentry;
>  
>  	int (*add)(struct constraint *constraint, void *data);
>  	void (*remove)(struct constraint *constraint);
>  	void *private;
>  };
>  
> +void constraint_add_debugfs(struct constraint *constraint, const char *suffix);
> +void constraint_remove_debugfs(struct constraint *constraint);
> +
>  /* Forward declarations of constraint specific callbacks */
>  int constraint_clk_add(struct constraint *constraint, void *data);
>  void constraint_clk_remove(struct constraint *constraint);
> diff --git a/drivers/base/boot_constraints/pm.c b/drivers/base/boot_constraints/pm.c
> index edba5eca5093..95910d0dc457 100644
> --- a/drivers/base/boot_constraints/pm.c
> +++ b/drivers/base/boot_constraints/pm.c
> @@ -14,11 +14,19 @@
>  int constraint_pm_add(struct constraint *constraint, void *data)
>  {
>  	struct device *dev = constraint->cdev->dev;
> +	int ret;
>  
> -	return dev_pm_domain_attach(dev, true);
> +	ret = dev_pm_domain_attach(dev, true);
> +	if (ret)
> +		return ret;
> +
> +	/* Debugfs */

Again, obvious comment, no need to have it.


> +	constraint_add_debugfs(constraint, "domain");
> +
> +	return 0;
>  }
>  
>  void constraint_pm_remove(struct constraint *constraint)
>  {
> -	/* Nothing to do for now */
> +	constraint_remove_debugfs(constraint);
>  }
> diff --git a/drivers/base/boot_constraints/supply.c b/drivers/base/boot_constraints/supply.c
> index 30f816dbf12c..b206f500b2bc 100644
> --- a/drivers/base/boot_constraints/supply.c
> +++ b/drivers/base/boot_constraints/supply.c
> @@ -60,6 +60,15 @@ int constraint_supply_add(struct constraint *constraint, void *data)
>  	csupply->supply.name = kstrdup_const(supply->name, GFP_KERNEL);
>  	constraint->private = csupply;
>  
> +	/* Debugfs */
> +	constraint_add_debugfs(constraint, supply->name);
> +
> +	debugfs_create_u32("u_volt_min", 0444, constraint->dentry,
> +			   &csupply->supply.u_volt_min);
> +
> +	debugfs_create_u32("u_volt_max", 0444, constraint->dentry,
> +			   &csupply->supply.u_volt_max);

See, that's how you do it!

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter
  2017-08-01  9:23   ` Viresh Kumar
@ 2017-08-29  6:37     ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 46+ messages in thread
From: Greg Kroah-Hartman @ 2017-08-29  6:37 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Jonathan Corbet, Vincent Guittot, Mark Brown, Stephen Boyd,
	Rajendra Nayak, Shiraz Hashim, linux-kernel, linux-arm-kernel,
	robdclark, linux-doc

On Tue, Aug 01, 2017 at 02:53:43PM +0530, Viresh Kumar wrote:
> Users must be given an option to discard any constraints set by
> bootloaders. For example, consider that a constraint is set for the LCD
> controller's supply and the LCD driver isn't loaded by the kernel. If
> the user doesn't need to use the LCD device, then he shouldn't be forced
> to honour the constraint.
> 
> We can also think about finer control of such constraints with help of
> some sysfs files, but a kernel parameter is fine to begin with.
> 
> Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
>  Documentation/admin-guide/kernel-parameters.txt |  3 +++
>  drivers/base/boot_constraints/core.c            | 17 +++++++++++++++++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index d9c171ce4190..0706d1b6004d 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -426,6 +426,9 @@
>  			embedded devices based on command line input.
>  			See Documentation/block/cmdline-partition.txt
>  
> +	boot_constraints_disable
> +			Do not set any boot constraints for devices.

Shouldn't that be the default?  As really, that is what the situation is
today, why force everyone to always enable the disable value?  And
enabling a value to disable something is usually a sign of bad naming...

> +
>  	boot_delay=	Milliseconds to delay each printk during boot.
>  			Values larger than 10 seconds (10000) are changed to
>  			no delay (0).
> diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
> index 366a05d6d9ba..e0c33b2b216f 100644
> --- a/drivers/base/boot_constraints/core.c
> +++ b/drivers/base/boot_constraints/core.c
> @@ -24,6 +24,17 @@
>  static LIST_HEAD(constraint_devices);
>  static DEFINE_MUTEX(constraint_devices_mutex);
>  
> +static bool boot_constraints_disabled;

Again, this should only be an "enable" type of option, that kicks in if
you are using this type of bootloader/kernel interaction.  Don't force
someone to disable it.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter
@ 2017-08-29  6:37     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 46+ messages in thread
From: Greg Kroah-Hartman @ 2017-08-29  6:37 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Aug 01, 2017 at 02:53:43PM +0530, Viresh Kumar wrote:
> Users must be given an option to discard any constraints set by
> bootloaders. For example, consider that a constraint is set for the LCD
> controller's supply and the LCD driver isn't loaded by the kernel. If
> the user doesn't need to use the LCD device, then he shouldn't be forced
> to honour the constraint.
> 
> We can also think about finer control of such constraints with help of
> some sysfs files, but a kernel parameter is fine to begin with.
> 
> Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
>  Documentation/admin-guide/kernel-parameters.txt |  3 +++
>  drivers/base/boot_constraints/core.c            | 17 +++++++++++++++++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index d9c171ce4190..0706d1b6004d 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -426,6 +426,9 @@
>  			embedded devices based on command line input.
>  			See Documentation/block/cmdline-partition.txt
>  
> +	boot_constraints_disable
> +			Do not set any boot constraints for devices.

Shouldn't that be the default?  As really, that is what the situation is
today, why force everyone to always enable the disable value?  And
enabling a value to disable something is usually a sign of bad naming...

> +
>  	boot_delay=	Milliseconds to delay each printk during boot.
>  			Values larger than 10 seconds (10000) are changed to
>  			no delay (0).
> diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
> index 366a05d6d9ba..e0c33b2b216f 100644
> --- a/drivers/base/boot_constraints/core.c
> +++ b/drivers/base/boot_constraints/core.c
> @@ -24,6 +24,17 @@
>  static LIST_HEAD(constraint_devices);
>  static DEFINE_MUTEX(constraint_devices_mutex);
>  
> +static bool boot_constraints_disabled;

Again, this should only be an "enable" type of option, that kicks in if
you are using this type of bootloader/kernel interaction.  Don't force
someone to disable it.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH V3 1/8] drivers: Add boot constraints core
  2017-08-01  9:23   ` Viresh Kumar
@ 2017-08-29  6:39     ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 46+ messages in thread
From: Greg Kroah-Hartman @ 2017-08-29  6:39 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Vincent Guittot, Mark Brown, Stephen Boyd, Rajendra Nayak,
	Shiraz Hashim, linux-kernel, linux-arm-kernel, robdclark

On Tue, Aug 01, 2017 at 02:53:42PM +0530, Viresh Kumar wrote:
> Some devices are powered ON by the bootloader before the bootloader
> handovers control to Linux. It maybe important for those devices to keep
> working until the time a Linux device driver probes the device and
> reconfigure its resources.
> 
> A typical example of that can be the LCD controller, which is used by
> the bootloaders to show image(s) while the platform is booting into
> Linux. The LCD controller can be using some resources, like clk,
> regulators, PM domain, etc, that are shared between several devices.
> These shared resources should be configured to satisfy need of all the
> users. If another device's (X) driver gets probed before the LCD
> controller driver in this case, then it may end up reconfiguring these
> resources to ranges satisfying the current users (only device X) and
> that can make the LCD screen unstable.
> 
> This patch introduces the concept of boot-constraints, which will be set
> by the bootloaders and the kernel will satisfy them until the time
> driver for such a device is probed (successfully or unsuccessfully).
> 
> The list of boot constraint types is empty for now, and will be
> incrementally updated by later patches.
> 
> Only two routines are exposed by the boot constraints core for now:
> 
> - dev_boot_constraint_add(): This shall be called by parts of the kernel
>   (before the device is probed) to set the constraints.
> 
> - dev_boot_constraints_remove(): This is called only by the driver core
>   after a device is probed successfully or unsuccessfully. Special
>   handling is done here for deffered probing.

How is this information getting to the kernel from the bootloader?  I
didn't see where that happened, just a single example driver that
somehow "knew" what had to happen, which seems odd...

This is a lot of new code for no users, I would like to see at least 3
real drivers that are using it before we merge it, as then you have a
chance of getting the user/kernel api correct.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 1/8] drivers: Add boot constraints core
@ 2017-08-29  6:39     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 46+ messages in thread
From: Greg Kroah-Hartman @ 2017-08-29  6:39 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Aug 01, 2017 at 02:53:42PM +0530, Viresh Kumar wrote:
> Some devices are powered ON by the bootloader before the bootloader
> handovers control to Linux. It maybe important for those devices to keep
> working until the time a Linux device driver probes the device and
> reconfigure its resources.
> 
> A typical example of that can be the LCD controller, which is used by
> the bootloaders to show image(s) while the platform is booting into
> Linux. The LCD controller can be using some resources, like clk,
> regulators, PM domain, etc, that are shared between several devices.
> These shared resources should be configured to satisfy need of all the
> users. If another device's (X) driver gets probed before the LCD
> controller driver in this case, then it may end up reconfiguring these
> resources to ranges satisfying the current users (only device X) and
> that can make the LCD screen unstable.
> 
> This patch introduces the concept of boot-constraints, which will be set
> by the bootloaders and the kernel will satisfy them until the time
> driver for such a device is probed (successfully or unsuccessfully).
> 
> The list of boot constraint types is empty for now, and will be
> incrementally updated by later patches.
> 
> Only two routines are exposed by the boot constraints core for now:
> 
> - dev_boot_constraint_add(): This shall be called by parts of the kernel
>   (before the device is probed) to set the constraints.
> 
> - dev_boot_constraints_remove(): This is called only by the driver core
>   after a device is probed successfully or unsuccessfully. Special
>   handling is done here for deffered probing.

How is this information getting to the kernel from the bootloader?  I
didn't see where that happened, just a single example driver that
somehow "knew" what had to happen, which seems odd...

This is a lot of new code for no users, I would like to see at least 3
real drivers that are using it before we merge it, as then you have a
chance of getting the user/kernel api correct.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter
  2017-08-29  6:37     ` Greg Kroah-Hartman
@ 2017-08-29  6:48       ` Jani Nikula
  -1 siblings, 0 replies; 46+ messages in thread
From: Jani Nikula @ 2017-08-29  6:48 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Viresh Kumar
  Cc: Jonathan Corbet, Vincent Guittot, Mark Brown, Stephen Boyd,
	Rajendra Nayak, Shiraz Hashim, linux-kernel, linux-arm-kernel,
	robdclark, linux-doc

On Tue, 29 Aug 2017, Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:
> On Tue, Aug 01, 2017 at 02:53:43PM +0530, Viresh Kumar wrote:
>> Users must be given an option to discard any constraints set by
>> bootloaders. For example, consider that a constraint is set for the LCD
>> controller's supply and the LCD driver isn't loaded by the kernel. If
>> the user doesn't need to use the LCD device, then he shouldn't be forced
>> to honour the constraint.
>> 
>> We can also think about finer control of such constraints with help of
>> some sysfs files, but a kernel parameter is fine to begin with.
>> 
>> Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
>> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
>> ---
>>  Documentation/admin-guide/kernel-parameters.txt |  3 +++
>>  drivers/base/boot_constraints/core.c            | 17 +++++++++++++++++
>>  2 files changed, 20 insertions(+)
>> 
>> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
>> index d9c171ce4190..0706d1b6004d 100644
>> --- a/Documentation/admin-guide/kernel-parameters.txt
>> +++ b/Documentation/admin-guide/kernel-parameters.txt
>> @@ -426,6 +426,9 @@
>>  			embedded devices based on command line input.
>>  			See Documentation/block/cmdline-partition.txt
>>  
>> +	boot_constraints_disable
>> +			Do not set any boot constraints for devices.
>
> Shouldn't that be the default?  As really, that is what the situation is
> today, why force everyone to always enable the disable value?  And
> enabling a value to disable something is usually a sign of bad naming...
>
>> +
>>  	boot_delay=	Milliseconds to delay each printk during boot.
>>  			Values larger than 10 seconds (10000) are changed to
>>  			no delay (0).
>> diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
>> index 366a05d6d9ba..e0c33b2b216f 100644
>> --- a/drivers/base/boot_constraints/core.c
>> +++ b/drivers/base/boot_constraints/core.c
>> @@ -24,6 +24,17 @@
>>  static LIST_HEAD(constraint_devices);
>>  static DEFINE_MUTEX(constraint_devices_mutex);
>>  
>> +static bool boot_constraints_disabled;
>
> Again, this should only be an "enable" type of option, that kicks in if
> you are using this type of bootloader/kernel interaction.  Don't force
> someone to disable it.

I might add that "disable" type options lead to annoying double
negatives. Regardless of the default, I'd generally prefer "enable" type
options that you enable/disable as needed.

BR,
Jani.


-- 
Jani Nikula, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter
@ 2017-08-29  6:48       ` Jani Nikula
  0 siblings, 0 replies; 46+ messages in thread
From: Jani Nikula @ 2017-08-29  6:48 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 29 Aug 2017, Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:
> On Tue, Aug 01, 2017 at 02:53:43PM +0530, Viresh Kumar wrote:
>> Users must be given an option to discard any constraints set by
>> bootloaders. For example, consider that a constraint is set for the LCD
>> controller's supply and the LCD driver isn't loaded by the kernel. If
>> the user doesn't need to use the LCD device, then he shouldn't be forced
>> to honour the constraint.
>> 
>> We can also think about finer control of such constraints with help of
>> some sysfs files, but a kernel parameter is fine to begin with.
>> 
>> Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
>> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
>> ---
>>  Documentation/admin-guide/kernel-parameters.txt |  3 +++
>>  drivers/base/boot_constraints/core.c            | 17 +++++++++++++++++
>>  2 files changed, 20 insertions(+)
>> 
>> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
>> index d9c171ce4190..0706d1b6004d 100644
>> --- a/Documentation/admin-guide/kernel-parameters.txt
>> +++ b/Documentation/admin-guide/kernel-parameters.txt
>> @@ -426,6 +426,9 @@
>>  			embedded devices based on command line input.
>>  			See Documentation/block/cmdline-partition.txt
>>  
>> +	boot_constraints_disable
>> +			Do not set any boot constraints for devices.
>
> Shouldn't that be the default?  As really, that is what the situation is
> today, why force everyone to always enable the disable value?  And
> enabling a value to disable something is usually a sign of bad naming...
>
>> +
>>  	boot_delay=	Milliseconds to delay each printk during boot.
>>  			Values larger than 10 seconds (10000) are changed to
>>  			no delay (0).
>> diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c
>> index 366a05d6d9ba..e0c33b2b216f 100644
>> --- a/drivers/base/boot_constraints/core.c
>> +++ b/drivers/base/boot_constraints/core.c
>> @@ -24,6 +24,17 @@
>>  static LIST_HEAD(constraint_devices);
>>  static DEFINE_MUTEX(constraint_devices_mutex);
>>  
>> +static bool boot_constraints_disabled;
>
> Again, this should only be an "enable" type of option, that kicks in if
> you are using this type of bootloader/kernel interaction.  Don't force
> someone to disable it.

I might add that "disable" type options lead to annoying double
negatives. Regardless of the default, I'd generally prefer "enable" type
options that you enable/disable as needed.

BR,
Jani.


-- 
Jani Nikula, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH V3 1/8] drivers: Add boot constraints core
  2017-08-29  6:39     ` Greg Kroah-Hartman
@ 2017-08-29  9:52       ` Viresh Kumar
  -1 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-29  9:52 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Vincent Guittot, Mark Brown, Stephen Boyd, Rajendra Nayak,
	Shiraz Hashim, linux-kernel, linux-arm-kernel, robdclark

On 29-08-17, 08:39, Greg Kroah-Hartman wrote:
> How is this information getting to the kernel from the bootloader?  I
> didn't see where that happened, just a single example driver that
> somehow "knew" what had to happen, which seems odd...

I tried to do it with DT earlier, but we couldn't reach to an agreement on what
bindings to add and so this series started doing things the old way. The kernel
would have platform specific drivers, which would exactly know what constraints
to set and we wouldn't need the bootloaders to pass anything for now.

> This is a lot of new code for no users,

I agree and so added the patch 8/8 to show a real user. I will convert that to a
patch going forward, which can be merged along with this series.

> I would like to see at least 3
> real drivers that are using it before we merge it, as then you have a
> chance of getting the user/kernel api correct.

Hmm, so I am quite sure that this is a fairly generic problem to solve,
specifically for all the handheld devices. I can get code for few of the Qcom
SoCs but they may end up using the same platform driver. Not sure if I can get
code for multiple SoC families in the beginning.

-- 
viresh

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 1/8] drivers: Add boot constraints core
@ 2017-08-29  9:52       ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-29  9:52 UTC (permalink / raw)
  To: linux-arm-kernel

On 29-08-17, 08:39, Greg Kroah-Hartman wrote:
> How is this information getting to the kernel from the bootloader?  I
> didn't see where that happened, just a single example driver that
> somehow "knew" what had to happen, which seems odd...

I tried to do it with DT earlier, but we couldn't reach to an agreement on what
bindings to add and so this series started doing things the old way. The kernel
would have platform specific drivers, which would exactly know what constraints
to set and we wouldn't need the bootloaders to pass anything for now.

> This is a lot of new code for no users,

I agree and so added the patch 8/8 to show a real user. I will convert that to a
patch going forward, which can be merged along with this series.

> I would like to see at least 3
> real drivers that are using it before we merge it, as then you have a
> chance of getting the user/kernel api correct.

Hmm, so I am quite sure that this is a fairly generic problem to solve,
specifically for all the handheld devices. I can get code for few of the Qcom
SoCs but they may end up using the same platform driver. Not sure if I can get
code for multiple SoC families in the beginning.

-- 
viresh

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter
  2017-08-29  6:37     ` Greg Kroah-Hartman
@ 2017-08-29 10:02       ` Viresh Kumar
  -1 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-29 10:02 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Jonathan Corbet, Vincent Guittot, Mark Brown, Stephen Boyd,
	Rajendra Nayak, Shiraz Hashim, linux-kernel, linux-arm-kernel,
	robdclark, linux-doc

On 29-08-17, 08:37, Greg Kroah-Hartman wrote:
> On Tue, Aug 01, 2017 at 02:53:43PM +0530, Viresh Kumar wrote:
> > +	boot_constraints_disable
> > +			Do not set any boot constraints for devices.
> 
> Shouldn't that be the default?  As really, that is what the situation is
> today, why force everyone to always enable the disable value?  And
> enabling a value to disable something is usually a sign of bad naming...

I will explain once again how it is getting used and then will do whatever you
suggest.

- Platforms that don't need boot constraints should not enable the CONFIG in the
  first place. Though we use the same kernel image on multiple hardware types
  many times.
- If a platform doesn't have a platform-specific driver that adds constraints at
  boot, then the boot constraint core wouldn't get into picture at all and it is
  as good as being disabled.
- And the above boot-argument (boot_constraints_disable) is used ONLY in the
  case where the platform driver is adding boot constraints at runtime.

So, the boot-constraints are disabled by default for everyone even if the
configuration is enabled. And that's why I named it the way it is right now.

Do you still feel that it needs to be renamed? 

-- 
viresh

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter
@ 2017-08-29 10:02       ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-29 10:02 UTC (permalink / raw)
  To: linux-arm-kernel

On 29-08-17, 08:37, Greg Kroah-Hartman wrote:
> On Tue, Aug 01, 2017 at 02:53:43PM +0530, Viresh Kumar wrote:
> > +	boot_constraints_disable
> > +			Do not set any boot constraints for devices.
> 
> Shouldn't that be the default?  As really, that is what the situation is
> today, why force everyone to always enable the disable value?  And
> enabling a value to disable something is usually a sign of bad naming...

I will explain once again how it is getting used and then will do whatever you
suggest.

- Platforms that don't need boot constraints should not enable the CONFIG in the
  first place. Though we use the same kernel image on multiple hardware types
  many times.
- If a platform doesn't have a platform-specific driver that adds constraints at
  boot, then the boot constraint core wouldn't get into picture at all and it is
  as good as being disabled.
- And the above boot-argument (boot_constraints_disable) is used ONLY in the
  case where the platform driver is adding boot constraints at runtime.

So, the boot-constraints are disabled by default for everyone even if the
configuration is enabled. And that's why I named it the way it is right now.

Do you still feel that it needs to be renamed? 

-- 
viresh

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH V3 6/8] drivers: boot_constraint: Add debugfs support
  2017-08-29  6:36     ` Greg Kroah-Hartman
@ 2017-08-29 10:04       ` Viresh Kumar
  -1 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-29 10:04 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Vincent Guittot, Mark Brown, Stephen Boyd, Rajendra Nayak,
	Shiraz Hashim, linux-kernel, linux-arm-kernel, robdclark

On 29-08-17, 08:36, Greg Kroah-Hartman wrote:
> On Tue, Aug 01, 2017 at 02:53:47PM +0530, Viresh Kumar wrote:
> > This patch adds debugfs support for boot constraints. This is how it
> > looks for a "vmmc-supply" constraint for the MMC device.
> > 
> > $ ls -R /sys/kernel/debug/boot_constraints/
> > /sys/kernel/debug/boot_constraints/:
> > f723d000.dwmmc0
> > 
> > /sys/kernel/debug/boot_constraints/f723d000.dwmmc0:
> > clk-ciu  pm-domain  supply-vmmc  supply-vmmcaux
> > 
> > /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/clk-ciu:
> > 
> > /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/pm-domain:
> > 
> > /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmc:
> > u_volt_max  u_volt_min
> > 
> > /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmcaux:
> > u_volt_max  u_volt_min
> > 
> > Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
> > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> 
> Minor debugfs api interaction nits below:

All accepted :)

-- 
viresh

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 6/8] drivers: boot_constraint: Add debugfs support
@ 2017-08-29 10:04       ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-08-29 10:04 UTC (permalink / raw)
  To: linux-arm-kernel

On 29-08-17, 08:36, Greg Kroah-Hartman wrote:
> On Tue, Aug 01, 2017 at 02:53:47PM +0530, Viresh Kumar wrote:
> > This patch adds debugfs support for boot constraints. This is how it
> > looks for a "vmmc-supply" constraint for the MMC device.
> > 
> > $ ls -R /sys/kernel/debug/boot_constraints/
> > /sys/kernel/debug/boot_constraints/:
> > f723d000.dwmmc0
> > 
> > /sys/kernel/debug/boot_constraints/f723d000.dwmmc0:
> > clk-ciu  pm-domain  supply-vmmc  supply-vmmcaux
> > 
> > /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/clk-ciu:
> > 
> > /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/pm-domain:
> > 
> > /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmc:
> > u_volt_max  u_volt_min
> > 
> > /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmcaux:
> > u_volt_max  u_volt_min
> > 
> > Tested-by: Rajendra Nayak <rnayak@codeaurora.org>
> > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> 
> Minor debugfs api interaction nits below:

All accepted :)

-- 
viresh

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter
  2017-08-29 10:02       ` Viresh Kumar
@ 2017-08-29 11:56         ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 46+ messages in thread
From: Greg Kroah-Hartman @ 2017-08-29 11:56 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Jonathan Corbet, Vincent Guittot, Mark Brown, Stephen Boyd,
	Rajendra Nayak, Shiraz Hashim, linux-kernel, linux-arm-kernel,
	robdclark, linux-doc

On Tue, Aug 29, 2017 at 12:02:41PM +0200, Viresh Kumar wrote:
> On 29-08-17, 08:37, Greg Kroah-Hartman wrote:
> > On Tue, Aug 01, 2017 at 02:53:43PM +0530, Viresh Kumar wrote:
> > > +	boot_constraints_disable
> > > +			Do not set any boot constraints for devices.
> > 
> > Shouldn't that be the default?  As really, that is what the situation is
> > today, why force everyone to always enable the disable value?  And
> > enabling a value to disable something is usually a sign of bad naming...
> 
> I will explain once again how it is getting used and then will do whatever you
> suggest.
> 
> - Platforms that don't need boot constraints should not enable the CONFIG in the
>   first place. Though we use the same kernel image on multiple hardware types
>   many times.

Right, which means this is useless as an option, don't ever rely on it
:)

> - If a platform doesn't have a platform-specific driver that adds constraints at
>   boot, then the boot constraint core wouldn't get into picture at all and it is
>   as good as being disabled.

Possibly, but see above for the goal of one kernel image, many different
devices.

> - And the above boot-argument (boot_constraints_disable) is used ONLY in the
>   case where the platform driver is adding boot constraints at runtime.
> 
> So, the boot-constraints are disabled by default for everyone even if the
> configuration is enabled. And that's why I named it the way it is right now.
> 
> Do you still feel that it needs to be renamed? 

Well, negative options are ackward (although usb_disable is an
option...)  It still feels wrong, and I worry about the above
single-image goal...

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter
@ 2017-08-29 11:56         ` Greg Kroah-Hartman
  0 siblings, 0 replies; 46+ messages in thread
From: Greg Kroah-Hartman @ 2017-08-29 11:56 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Aug 29, 2017 at 12:02:41PM +0200, Viresh Kumar wrote:
> On 29-08-17, 08:37, Greg Kroah-Hartman wrote:
> > On Tue, Aug 01, 2017 at 02:53:43PM +0530, Viresh Kumar wrote:
> > > +	boot_constraints_disable
> > > +			Do not set any boot constraints for devices.
> > 
> > Shouldn't that be the default?  As really, that is what the situation is
> > today, why force everyone to always enable the disable value?  And
> > enabling a value to disable something is usually a sign of bad naming...
> 
> I will explain once again how it is getting used and then will do whatever you
> suggest.
> 
> - Platforms that don't need boot constraints should not enable the CONFIG in the
>   first place. Though we use the same kernel image on multiple hardware types
>   many times.

Right, which means this is useless as an option, don't ever rely on it
:)

> - If a platform doesn't have a platform-specific driver that adds constraints at
>   boot, then the boot constraint core wouldn't get into picture at all and it is
>   as good as being disabled.

Possibly, but see above for the goal of one kernel image, many different
devices.

> - And the above boot-argument (boot_constraints_disable) is used ONLY in the
>   case where the platform driver is adding boot constraints at runtime.
> 
> So, the boot-constraints are disabled by default for everyone even if the
> configuration is enabled. And that's why I named it the way it is right now.
> 
> Do you still feel that it needs to be renamed? 

Well, negative options are ackward (although usb_disable is an
option...)  It still feels wrong, and I worry about the above
single-image goal...

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH V3 1/8] drivers: Add boot constraints core
  2017-08-29  9:52       ` Viresh Kumar
@ 2017-08-29 12:03         ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 46+ messages in thread
From: Greg Kroah-Hartman @ 2017-08-29 12:03 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Vincent Guittot, Mark Brown, Stephen Boyd, Rajendra Nayak,
	Shiraz Hashim, linux-kernel, linux-arm-kernel, robdclark

On Tue, Aug 29, 2017 at 11:52:17AM +0200, Viresh Kumar wrote:
> On 29-08-17, 08:39, Greg Kroah-Hartman wrote:
> > How is this information getting to the kernel from the bootloader?  I
> > didn't see where that happened, just a single example driver that
> > somehow "knew" what had to happen, which seems odd...
> 
> I tried to do it with DT earlier, but we couldn't reach to an agreement on what
> bindings to add and so this series started doing things the old way. The kernel
> would have platform specific drivers, which would exactly know what constraints
> to set and we wouldn't need the bootloaders to pass anything for now.

Who couldn't reach an agreement?  So you gave up and decided to make a
whole bunch of kernel code instead of just using new DT entries?  That's
crazy...

> > This is a lot of new code for no users,
> 
> I agree and so added the patch 8/8 to show a real user. I will convert that to a
> patch going forward, which can be merged along with this series.
> 
> > I would like to see at least 3
> > real drivers that are using it before we merge it, as then you have a
> > chance of getting the user/kernel api correct.
> 
> Hmm, so I am quite sure that this is a fairly generic problem to solve,
> specifically for all the handheld devices. I can get code for few of the Qcom
> SoCs but they may end up using the same platform driver. Not sure if I can get
> code for multiple SoC families in the beginning.

Let's see a working system or two first here please.

But you are implying that existing handheld devices need this problem
solved, how do they do it today without this code as obviously they are
shipping working solutions.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 1/8] drivers: Add boot constraints core
@ 2017-08-29 12:03         ` Greg Kroah-Hartman
  0 siblings, 0 replies; 46+ messages in thread
From: Greg Kroah-Hartman @ 2017-08-29 12:03 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Aug 29, 2017 at 11:52:17AM +0200, Viresh Kumar wrote:
> On 29-08-17, 08:39, Greg Kroah-Hartman wrote:
> > How is this information getting to the kernel from the bootloader?  I
> > didn't see where that happened, just a single example driver that
> > somehow "knew" what had to happen, which seems odd...
> 
> I tried to do it with DT earlier, but we couldn't reach to an agreement on what
> bindings to add and so this series started doing things the old way. The kernel
> would have platform specific drivers, which would exactly know what constraints
> to set and we wouldn't need the bootloaders to pass anything for now.

Who couldn't reach an agreement?  So you gave up and decided to make a
whole bunch of kernel code instead of just using new DT entries?  That's
crazy...

> > This is a lot of new code for no users,
> 
> I agree and so added the patch 8/8 to show a real user. I will convert that to a
> patch going forward, which can be merged along with this series.
> 
> > I would like to see at least 3
> > real drivers that are using it before we merge it, as then you have a
> > chance of getting the user/kernel api correct.
> 
> Hmm, so I am quite sure that this is a fairly generic problem to solve,
> specifically for all the handheld devices. I can get code for few of the Qcom
> SoCs but they may end up using the same platform driver. Not sure if I can get
> code for multiple SoC families in the beginning.

Let's see a working system or two first here please.

But you are implying that existing handheld devices need this problem
solved, how do they do it today without this code as obviously they are
shipping working solutions.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH V3 1/8] drivers: Add boot constraints core
  2017-08-29 12:03         ` Greg Kroah-Hartman
@ 2017-09-04  9:15           ` Viresh Kumar
  -1 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-09-04  9:15 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Vincent Guittot, Mark Brown, Stephen Boyd, Rajendra Nayak,
	Shiraz Hashim, linux-kernel, linux-arm-kernel, robdclark

On 29-08-17, 14:03, Greg Kroah-Hartman wrote:
> Who couldn't reach an agreement?

Rob Herring (DT Maintainer) didn't like the first set of bindings and wasn't
convinced that we need any new bindings for this purpose to begin with.

> So you gave up and decided to make a
> whole bunch of kernel code instead of just using new DT entries?  That's
> crazy...

Its not a lot really. Most of the code is anyways required, the only extra part
is the platform specific drivers, which are replacing what the DT would have
done. So, it shouldn't be that big of a deal I suppose.

> Let's see a working system or two first here please.

Sure, I will get as many converted as possible.

> But you are implying that existing handheld devices need this problem
> solved, how do they do it today without this code as obviously they are
> shipping working solutions.

So yeah, LCD is a common usecase but the configurations aren't always shared. It
may not be an issue with private clock/regulator resources, but with shared
ones.

Though even with the private resources, we may want the clock/domains/regulators
to stay powered on and I assume that the platforms would be doing hacky stuff to
get that all working right now.

-- 
viresh

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 1/8] drivers: Add boot constraints core
@ 2017-09-04  9:15           ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-09-04  9:15 UTC (permalink / raw)
  To: linux-arm-kernel

On 29-08-17, 14:03, Greg Kroah-Hartman wrote:
> Who couldn't reach an agreement?

Rob Herring (DT Maintainer) didn't like the first set of bindings and wasn't
convinced that we need any new bindings for this purpose to begin with.

> So you gave up and decided to make a
> whole bunch of kernel code instead of just using new DT entries?  That's
> crazy...

Its not a lot really. Most of the code is anyways required, the only extra part
is the platform specific drivers, which are replacing what the DT would have
done. So, it shouldn't be that big of a deal I suppose.

> Let's see a working system or two first here please.

Sure, I will get as many converted as possible.

> But you are implying that existing handheld devices need this problem
> solved, how do they do it today without this code as obviously they are
> shipping working solutions.

So yeah, LCD is a common usecase but the configurations aren't always shared. It
may not be an issue with private clock/regulator resources, but with shared
ones.

Though even with the private resources, we may want the clock/domains/regulators
to stay powered on and I assume that the platforms would be doing hacky stuff to
get that all working right now.

-- 
viresh

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH V3 1/8] drivers: Add boot constraints core
  2017-09-04  9:15           ` Viresh Kumar
@ 2017-09-04  9:38             ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 46+ messages in thread
From: Greg Kroah-Hartman @ 2017-09-04  9:38 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Vincent Guittot, Mark Brown, Stephen Boyd, Rajendra Nayak,
	Shiraz Hashim, linux-kernel, linux-arm-kernel, robdclark

On Mon, Sep 04, 2017 at 11:15:47AM +0200, Viresh Kumar wrote:
> On 29-08-17, 14:03, Greg Kroah-Hartman wrote:
> > Who couldn't reach an agreement?
> 
> Rob Herring (DT Maintainer) didn't like the first set of bindings and wasn't
> convinced that we need any new bindings for this purpose to begin with.

So Rob wanted more kernel code and less bindings?
Ok, I'll ask for Rob to sign off on these patches then :)

> > But you are implying that existing handheld devices need this problem
> > solved, how do they do it today without this code as obviously they are
> > shipping working solutions.
> 
> So yeah, LCD is a common usecase but the configurations aren't always shared. It
> may not be an issue with private clock/regulator resources, but with shared
> ones.
> 
> Though even with the private resources, we may want the clock/domains/regulators
> to stay powered on and I assume that the platforms would be doing hacky stuff to
> get that all working right now.

As you have the source for a number of such systems, you might want to
verify this please.  Also, what is going to cause any new systems to use
this new api?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 1/8] drivers: Add boot constraints core
@ 2017-09-04  9:38             ` Greg Kroah-Hartman
  0 siblings, 0 replies; 46+ messages in thread
From: Greg Kroah-Hartman @ 2017-09-04  9:38 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Sep 04, 2017 at 11:15:47AM +0200, Viresh Kumar wrote:
> On 29-08-17, 14:03, Greg Kroah-Hartman wrote:
> > Who couldn't reach an agreement?
> 
> Rob Herring (DT Maintainer) didn't like the first set of bindings and wasn't
> convinced that we need any new bindings for this purpose to begin with.

So Rob wanted more kernel code and less bindings?
Ok, I'll ask for Rob to sign off on these patches then :)

> > But you are implying that existing handheld devices need this problem
> > solved, how do they do it today without this code as obviously they are
> > shipping working solutions.
> 
> So yeah, LCD is a common usecase but the configurations aren't always shared. It
> may not be an issue with private clock/regulator resources, but with shared
> ones.
> 
> Though even with the private resources, we may want the clock/domains/regulators
> to stay powered on and I assume that the platforms would be doing hacky stuff to
> get that all working right now.

As you have the source for a number of such systems, you might want to
verify this please.  Also, what is going to cause any new systems to use
this new api?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH V3 8/8] drivers: boot_constraint: Add Qualcomm display controller constraints
  2017-08-01  9:23   ` Viresh Kumar
@ 2017-09-04 16:25     ` Pavel Machek
  -1 siblings, 0 replies; 46+ messages in thread
From: Pavel Machek @ 2017-09-04 16:25 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Greg Kroah-Hartman, Vincent Guittot, Mark Brown, Stephen Boyd,
	Rajendra Nayak, Shiraz Hashim, linux-kernel, linux-arm-kernel,
	robdclark

[-- Attachment #1: Type: text/plain, Size: 2004 bytes --]

Hi!

> From: Rajendra Nayak <rnayak@codeaurora.org>
> 
> NOT TO BE MERGED
> 
> This sets boot constraints for the display controller used on Qualcomm
> dragonboard 410c.
> 
> Not-signed-off-by: Rajendra Nayak <rnayak@codeaurora.org>
> Not-signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

> +#include <linux/boot_constraint.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +
> +struct dev_boot_constraint_clk_info iface_clk_info = {
> +	.name = "iface_clk",
> +};
> +
> +struct dev_boot_constraint_clk_info bus_clk_info = {
> +	.name = "bus_clk",
> +};
> +
> +struct dev_boot_constraint_clk_info core_clk_info = {
> +	.name = "core_clk",
> +};
> +
> +struct dev_boot_constraint_clk_info vsync_clk_info = {
> +	.name = "vsync_clk",
> +};
> +
> +struct dev_boot_constraint_clk_info esc0_clk_info = {
> +	.name = "core_clk",
> +};
> +
> +struct dev_boot_constraint_clk_info byte_clk_info = {
> +	.name = "byte_clk",
> +};
> +
> +struct dev_boot_constraint_clk_info pixel_clk_info = {
> +	.name = "pixel_clk",
> +};
> +
> +struct dev_boot_constraint_supply_info vdda_info = {
> +	.name = "vdda"
> +};
> +
> +struct dev_boot_constraint_supply_info vddio_info = {
> +	.name = "vddio"
> +};
> +
> +struct dev_boot_constraint constraints_mdss[] = {
> +	{
> +		.type = DEV_BOOT_CONSTRAINT_PM,
> +		.data = NULL,
> +	},
> +};
> +
> +struct dev_boot_constraint constraints_mdp[] = {
> +	{
> +		.type = DEV_BOOT_CONSTRAINT_CLK,
> +		.data = &iface_clk_info,
> +	}, {
> +		.type = DEV_BOOT_CONSTRAINT_CLK,
> +		.data = &bus_clk_info,
> +	}, {
> +		.type = DEV_BOOT_CONSTRAINT_CLK,
> +		.data = &core_clk_info,
> +	}, {
> +		.type = DEV_BOOT_CONSTRAINT_CLK,
> +		.data = &vsync_clk_info,
> +	},
> +};

Hmm. I know this is not for merge, but should this go to device tree somewhere?


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 8/8] drivers: boot_constraint: Add Qualcomm display controller constraints
@ 2017-09-04 16:25     ` Pavel Machek
  0 siblings, 0 replies; 46+ messages in thread
From: Pavel Machek @ 2017-09-04 16:25 UTC (permalink / raw)
  To: linux-arm-kernel

Hi!

> From: Rajendra Nayak <rnayak@codeaurora.org>
> 
> NOT TO BE MERGED
> 
> This sets boot constraints for the display controller used on Qualcomm
> dragonboard 410c.
> 
> Not-signed-off-by: Rajendra Nayak <rnayak@codeaurora.org>
> Not-signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

> +#include <linux/boot_constraint.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +
> +struct dev_boot_constraint_clk_info iface_clk_info = {
> +	.name = "iface_clk",
> +};
> +
> +struct dev_boot_constraint_clk_info bus_clk_info = {
> +	.name = "bus_clk",
> +};
> +
> +struct dev_boot_constraint_clk_info core_clk_info = {
> +	.name = "core_clk",
> +};
> +
> +struct dev_boot_constraint_clk_info vsync_clk_info = {
> +	.name = "vsync_clk",
> +};
> +
> +struct dev_boot_constraint_clk_info esc0_clk_info = {
> +	.name = "core_clk",
> +};
> +
> +struct dev_boot_constraint_clk_info byte_clk_info = {
> +	.name = "byte_clk",
> +};
> +
> +struct dev_boot_constraint_clk_info pixel_clk_info = {
> +	.name = "pixel_clk",
> +};
> +
> +struct dev_boot_constraint_supply_info vdda_info = {
> +	.name = "vdda"
> +};
> +
> +struct dev_boot_constraint_supply_info vddio_info = {
> +	.name = "vddio"
> +};
> +
> +struct dev_boot_constraint constraints_mdss[] = {
> +	{
> +		.type = DEV_BOOT_CONSTRAINT_PM,
> +		.data = NULL,
> +	},
> +};
> +
> +struct dev_boot_constraint constraints_mdp[] = {
> +	{
> +		.type = DEV_BOOT_CONSTRAINT_CLK,
> +		.data = &iface_clk_info,
> +	}, {
> +		.type = DEV_BOOT_CONSTRAINT_CLK,
> +		.data = &bus_clk_info,
> +	}, {
> +		.type = DEV_BOOT_CONSTRAINT_CLK,
> +		.data = &core_clk_info,
> +	}, {
> +		.type = DEV_BOOT_CONSTRAINT_CLK,
> +		.data = &vsync_clk_info,
> +	},
> +};

Hmm. I know this is not for merge, but should this go to device tree somewhere?


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170904/61d21e65/attachment.sig>

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH V3 8/8] drivers: boot_constraint: Add Qualcomm display controller constraints
  2017-09-04 16:25     ` Pavel Machek
@ 2017-09-19 22:40       ` Viresh Kumar
  -1 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-09-19 22:40 UTC (permalink / raw)
  To: Pavel Machek
  Cc: Greg Kroah-Hartman, Vincent Guittot, Mark Brown, Stephen Boyd,
	Rajendra Nayak, Shiraz Hashim, linux-kernel, linux-arm-kernel,
	robdclark

On 04-09-17, 18:25, Pavel Machek wrote:
> Hmm. I know this is not for merge, but should this go to device tree somewhere?

Eventually yes. It should come from the boot loader in some way, which
includes DT, ACPI, etc.

This is just trying to get the core in first and once we have it
merged, we can propose DT bindings to start with.

-- 
viresh

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 8/8] drivers: boot_constraint: Add Qualcomm display controller constraints
@ 2017-09-19 22:40       ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-09-19 22:40 UTC (permalink / raw)
  To: linux-arm-kernel

On 04-09-17, 18:25, Pavel Machek wrote:
> Hmm. I know this is not for merge, but should this go to device tree somewhere?

Eventually yes. It should come from the boot loader in some way, which
includes DT, ACPI, etc.

This is just trying to get the core in first and once we have it
merged, we can propose DT bindings to start with.

-- 
viresh

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH V3 1/8] drivers: Add boot constraints core
  2017-09-04  9:38             ` Greg Kroah-Hartman
@ 2017-09-19 22:46               ` Viresh Kumar
  -1 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-09-19 22:46 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Vincent Guittot, Mark Brown, Stephen Boyd, Rajendra Nayak,
	Shiraz Hashim, linux-kernel, linux-arm-kernel, robdclark

On 04-09-17, 11:38, Greg Kroah-Hartman wrote:
> On Mon, Sep 04, 2017 at 11:15:47AM +0200, Viresh Kumar wrote:
> > On 29-08-17, 14:03, Greg Kroah-Hartman wrote:
> > > Who couldn't reach an agreement?
> > 
> > Rob Herring (DT Maintainer) didn't like the first set of bindings and wasn't
> > convinced that we need any new bindings for this purpose to begin with.
> 
> So Rob wanted more kernel code and less bindings?

We had a similar thread sometime back (Performance states for power
domains), where we couldn't get to the bindings in the first go. Rob
suggested that we can actually get the code in first and then we can
look at how to get stuff from DT once we understand it more.

He wasn't happy with the bindings I proposed and so I took the same
approach here. Its not a lot of code we are going to have to remove
once we move to DT, so it ain't that bad.

> Ok, I'll ask for Rob to sign off on these patches then :)

I can't give any guarantee of that ;)

> As you have the source for a number of such systems, you might want to
> verify this please.

I will try to talk to few guys during Linaro connect next week and
also look into source for such stuff.

> Also, what is going to cause any new systems to use
> this new api?

As far as my part go, I can do my best to advertise it with articles
and presentations. But eventually people have to get motivated to use
it themselves :)

What else can I do as an author here? I will do whatever it takes to
get people to use it.

-- 
viresh

^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH V3 1/8] drivers: Add boot constraints core
@ 2017-09-19 22:46               ` Viresh Kumar
  0 siblings, 0 replies; 46+ messages in thread
From: Viresh Kumar @ 2017-09-19 22:46 UTC (permalink / raw)
  To: linux-arm-kernel

On 04-09-17, 11:38, Greg Kroah-Hartman wrote:
> On Mon, Sep 04, 2017 at 11:15:47AM +0200, Viresh Kumar wrote:
> > On 29-08-17, 14:03, Greg Kroah-Hartman wrote:
> > > Who couldn't reach an agreement?
> > 
> > Rob Herring (DT Maintainer) didn't like the first set of bindings and wasn't
> > convinced that we need any new bindings for this purpose to begin with.
> 
> So Rob wanted more kernel code and less bindings?

We had a similar thread sometime back (Performance states for power
domains), where we couldn't get to the bindings in the first go. Rob
suggested that we can actually get the code in first and then we can
look at how to get stuff from DT once we understand it more.

He wasn't happy with the bindings I proposed and so I took the same
approach here. Its not a lot of code we are going to have to remove
once we move to DT, so it ain't that bad.

> Ok, I'll ask for Rob to sign off on these patches then :)

I can't give any guarantee of that ;)

> As you have the source for a number of such systems, you might want to
> verify this please.

I will try to talk to few guys during Linaro connect next week and
also look into source for such stuff.

> Also, what is going to cause any new systems to use
> this new api?

As far as my part go, I can do my best to advertise it with articles
and presentations. But eventually people have to get motivated to use
it themselves :)

What else can I do as an author here? I will do whatever it takes to
get people to use it.

-- 
viresh

^ permalink raw reply	[flat|nested] 46+ messages in thread

end of thread, other threads:[~2017-09-19 22:46 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-01  9:23 [PATCH V3 0/8] drivers: Boot Constraints core Viresh Kumar
2017-08-01  9:23 ` Viresh Kumar
2017-08-01  9:23 ` [PATCH V3 1/8] drivers: Add boot constraints core Viresh Kumar
2017-08-01  9:23   ` Viresh Kumar
2017-08-29  6:39   ` Greg Kroah-Hartman
2017-08-29  6:39     ` Greg Kroah-Hartman
2017-08-29  9:52     ` Viresh Kumar
2017-08-29  9:52       ` Viresh Kumar
2017-08-29 12:03       ` Greg Kroah-Hartman
2017-08-29 12:03         ` Greg Kroah-Hartman
2017-09-04  9:15         ` Viresh Kumar
2017-09-04  9:15           ` Viresh Kumar
2017-09-04  9:38           ` Greg Kroah-Hartman
2017-09-04  9:38             ` Greg Kroah-Hartman
2017-09-19 22:46             ` Viresh Kumar
2017-09-19 22:46               ` Viresh Kumar
2017-08-01  9:23 ` [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter Viresh Kumar
2017-08-01  9:23   ` Viresh Kumar
2017-08-29  6:37   ` Greg Kroah-Hartman
2017-08-29  6:37     ` Greg Kroah-Hartman
2017-08-29  6:48     ` Jani Nikula
2017-08-29  6:48       ` Jani Nikula
2017-08-29 10:02     ` Viresh Kumar
2017-08-29 10:02       ` Viresh Kumar
2017-08-29 11:56       ` Greg Kroah-Hartman
2017-08-29 11:56         ` Greg Kroah-Hartman
2017-08-01  9:23 ` [PATCH V3 3/8] drivers: boot_constraint: Add support for supply constraints Viresh Kumar
2017-08-01  9:23   ` Viresh Kumar
2017-08-01  9:23 ` [PATCH V3 4/8] drivers: boot_constraint: Add support for clk constraints Viresh Kumar
2017-08-01  9:23   ` Viresh Kumar
2017-08-01  9:23 ` [PATCH V3 5/8] drivers: boot_constraint: Add support for PM constraints Viresh Kumar
2017-08-01  9:23   ` Viresh Kumar
2017-08-01  9:23 ` [PATCH V3 6/8] drivers: boot_constraint: Add debugfs support Viresh Kumar
2017-08-01  9:23   ` Viresh Kumar
2017-08-29  6:36   ` Greg Kroah-Hartman
2017-08-29  6:36     ` Greg Kroah-Hartman
2017-08-29 10:04     ` Viresh Kumar
2017-08-29 10:04       ` Viresh Kumar
2017-08-01  9:23 ` [PATCH V3 7/8] drivers: boot_constraint: Manage deferrable constraints Viresh Kumar
2017-08-01  9:23   ` Viresh Kumar
2017-08-01  9:23 ` [PATCH V3 8/8] drivers: boot_constraint: Add Qualcomm display controller constraints Viresh Kumar
2017-08-01  9:23   ` Viresh Kumar
2017-09-04 16:25   ` Pavel Machek
2017-09-04 16:25     ` Pavel Machek
2017-09-19 22:40     ` Viresh Kumar
2017-09-19 22:40       ` Viresh Kumar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.