[RFC 5/5] drivers: Code to test boot constraints

2017-06-28 Thread Viresh Kumar
NOT FOR MERGE

This is test code to show how this is tested for now on the hikey
platform with the MMC device.

Not-signed-off-by: Viresh Kumar 
---
 drivers/base/Makefile|  2 +-
 drivers/base/test_plat_boot_constraint.c | 51 
 2 files changed, 52 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/test_plat_boot_constraint.c

diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 6094b3b75184..a1ffa9f1a0b6 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -5,7 +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_BOOT_CONSTRAINTS) += boot_constraint.o
+obj-$(CONFIG_BOOT_CONSTRAINTS) += boot_constraint.o test_plat_boot_constraint.o
 obj-$(CONFIG_DEVTMPFS) += devtmpfs.o
 obj-$(CONFIG_DMA_CMA) += dma-contiguous.o
 obj-y  += power/
diff --git a/drivers/base/test_plat_boot_constraint.c 
b/drivers/base/test_plat_boot_constraint.c
new file mode 100644
index ..498f87056409
--- /dev/null
+++ b/drivers/base/test_plat_boot_constraint.c
@@ -0,0 +1,51 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int test_constraints_probe(struct platform_device *platform_dev)
+{
+   struct device_node *np;
+   struct boot_constraint_supply_info info = {
+   .enable = true,
+   .name = "vmmc",
+   .u_volt_min = 180,
+   .u_volt_max = 300,
+   };
+   struct platform_device *pdev;
+   int ret;
+
+   np = of_find_compatible_node(NULL, NULL, "hisilicon,hi6220-dw-mshc");
+   if (!np)
+   return -ENODEV;
+
+   pdev = of_find_device_by_node(np);
+   of_node_put(np);
+
+   if (!pdev) {
+   pr_err("%s: device not found\n", __func__);
+   return -ENODEV;
+   }
+
+   ret = boot_constraint_add(>dev, BOOT_CONSTRAINT_SUPPLY, );
+   if (ret)
+   return ret;
+
+   return ret;
+}
+
+static struct platform_driver test_constraints_driver = {
+   .driver = {
+   .name   = "test-constraints",
+   },
+   .probe  = test_constraints_probe,
+};
+
+static int __init test_constraints_init(void)
+{
+   platform_device_register_data(NULL, "test-constraints", -1, NULL, 0);
+
+   return platform_driver_register(_constraints_driver);
+}
+subsys_initcall(test_constraints_init);
-- 
2.13.0.71.gd7076ec9c9cb



[RFC 5/5] drivers: Code to test boot constraints

2017-06-28 Thread Viresh Kumar
NOT FOR MERGE

This is test code to show how this is tested for now on the hikey
platform with the MMC device.

Not-signed-off-by: Viresh Kumar 
---
 drivers/base/Makefile|  2 +-
 drivers/base/test_plat_boot_constraint.c | 51 
 2 files changed, 52 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/test_plat_boot_constraint.c

diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 6094b3b75184..a1ffa9f1a0b6 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -5,7 +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_BOOT_CONSTRAINTS) += boot_constraint.o
+obj-$(CONFIG_BOOT_CONSTRAINTS) += boot_constraint.o test_plat_boot_constraint.o
 obj-$(CONFIG_DEVTMPFS) += devtmpfs.o
 obj-$(CONFIG_DMA_CMA) += dma-contiguous.o
 obj-y  += power/
diff --git a/drivers/base/test_plat_boot_constraint.c 
b/drivers/base/test_plat_boot_constraint.c
new file mode 100644
index ..498f87056409
--- /dev/null
+++ b/drivers/base/test_plat_boot_constraint.c
@@ -0,0 +1,51 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int test_constraints_probe(struct platform_device *platform_dev)
+{
+   struct device_node *np;
+   struct boot_constraint_supply_info info = {
+   .enable = true,
+   .name = "vmmc",
+   .u_volt_min = 180,
+   .u_volt_max = 300,
+   };
+   struct platform_device *pdev;
+   int ret;
+
+   np = of_find_compatible_node(NULL, NULL, "hisilicon,hi6220-dw-mshc");
+   if (!np)
+   return -ENODEV;
+
+   pdev = of_find_device_by_node(np);
+   of_node_put(np);
+
+   if (!pdev) {
+   pr_err("%s: device not found\n", __func__);
+   return -ENODEV;
+   }
+
+   ret = boot_constraint_add(>dev, BOOT_CONSTRAINT_SUPPLY, );
+   if (ret)
+   return ret;
+
+   return ret;
+}
+
+static struct platform_driver test_constraints_driver = {
+   .driver = {
+   .name   = "test-constraints",
+   },
+   .probe  = test_constraints_probe,
+};
+
+static int __init test_constraints_init(void)
+{
+   platform_device_register_data(NULL, "test-constraints", -1, NULL, 0);
+
+   return platform_driver_register(_constraints_driver);
+}
+subsys_initcall(test_constraints_init);
-- 
2.13.0.71.gd7076ec9c9cb