From patchwork Wed Jun 28 10:26:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 106509 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp838502qge; Wed, 28 Jun 2017 03:27:42 -0700 (PDT) X-Received: by 10.84.241.135 with SMTP id b7mr2056331pll.107.1498645662638; Wed, 28 Jun 2017 03:27:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498645662; cv=none; d=google.com; s=arc-20160816; b=LoEakmUHSNX0LjauTOZLTh0TzGy4bmicC2o7yB87pmqoXcYIJXf1IXtqmcosr53ue/ 5oCUtaMxN8i2dcT2pHh+g+XOVLzz02b7dEUeIDBsIesWcV7WZEyKWfXwdt5a1ELb6tD2 a+w8evoetaDH7R0VUo7ir9MbTXOKKNU8dRigO4vAqBO8ChViOkA28Qftxj0E3m8vOMpD iN6tozxwbDqauuzRWSsBDZhEhSe6h+e7Yv76wiIr2bOAqNIwq80cWW50Yw1dAVoHkrBC Uaw630aEhKRXW+xjPzug9zcr/6nj6UVGtlBs4J+/CQtO6xu0ROz2bpgdWm7W+TPrnzwb QPJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=yHGVxR0ImpHL1ASJ1ASxaYPSqi7SLzyamyC+9vaqDfs=; b=M/TBhHJi/372PHhwmlm7Knm7eC34UPrUj+3bKFwgxFxceC2/NyMUT62mdeby9jWabS /wXW9ic1JyfpW7lDClWe9juctRqRNcK3YhlaRXkvknMfga2IhhHbPz86cut3D6vJLZmu KL8sCWH/HG93Eu2DRBa8urPAa4JZwJDqf51m0uqjBrBrguloRwzFsxDDc9zcyVmDG2OA Rhl4H3hEfqYofrfgO+QU0RpbbWYtG/JHp+HxpsvWm4bvyR63IGBUPeuRhxyiESWhqUNI zCn7NiZF5YmXBYrQnybuAUDn3i9VSLBwEsrzhUJNxMSUeo1/Jyj8PiFDAmsXB0PlGUgg 1KdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=MK439bkQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m63si1320730pfk.76.2017.06.28.03.27.42; Wed, 28 Jun 2017 03:27:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=MK439bkQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751875AbdF1K12 (ORCPT + 25 others); Wed, 28 Jun 2017 06:27:28 -0400 Received: from mail-pf0-f173.google.com ([209.85.192.173]:33773 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751742AbdF1K1N (ORCPT ); Wed, 28 Jun 2017 06:27:13 -0400 Received: by mail-pf0-f173.google.com with SMTP id e7so31376712pfk.0 for ; Wed, 28 Jun 2017 03:27:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=yHGVxR0ImpHL1ASJ1ASxaYPSqi7SLzyamyC+9vaqDfs=; b=MK439bkQOshqvnh4UelE8RrWO08Xgwc9qttIH/diig2fchgzNnNclYxVI4NlvuOpWF i2KMO/hhM968olk+MhcEZ2UtJG1vGxRWiebESdKLOBhrnQQM7VND83KZFsRi/ZO3j6Pn GBZZFgLA7WwvA+OdT1Mk1P2Jyv1nAFZdcvPwM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=yHGVxR0ImpHL1ASJ1ASxaYPSqi7SLzyamyC+9vaqDfs=; b=rOieSr3ssJJ7Jcr1kJR41gKfMAOW6gaX+L34bOnj/3GqGrYUNhOCZwHT6P3I6woPSy jQLpxbOwLmqB3am6LXP8Ys26PcQaCAovj9c5M2WEKRBaWnZxr7U3hpDcmqejurrekc1r BWOSwm7W8r1oYOaFTFDUo3rxQVJ+jr81uuvzF4fwKY3hnxB6vDQH8vxCROLExCaNqT1X OfRvB/QP4aoB57eHzxn0gg60DYzKdoCP8tNQOqKegkHqFe+EIOubngw/cxDQhoyHvOzf HLmoETw7hoc5YuysgpgOKkAMKaDoewiFY5jSgQaAoI8ej62Uhe2GQ29nT158iYrD0uKl tYCg== X-Gm-Message-State: AKS2vOxlvT4OTouiGLbEKHp5YsbLoG8tJkn0HlXvWcKTCZRxsS457lCS BFqExwSf9Fya17mn X-Received: by 10.98.41.130 with SMTP id p124mr9935169pfp.220.1498645632219; Wed, 28 Jun 2017 03:27:12 -0700 (PDT) Received: from localhost ([122.171.238.149]) by smtp.gmail.com with ESMTPSA id 66sm4054975pfm.82.2017.06.28.03.27.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Jun 2017 03:27:11 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Rafael Wysocki , Vincent Guittot , Stephen Boyd , Mark Brown , Shiraz Hashim , Rob Herring , rnayak@codeaurora.org Subject: [RFC 1/5] drivers: Add boot constraints core Date: Wed, 28 Jun 2017 15:56:34 +0530 Message-Id: <24921f2a6a86cb9b2b3a1cae86649180bc116a62.1498642745.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.13.0.71.gd7076ec9c9cb In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some devices are powered ON by the bootloaders 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 device 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 programmed so that all the users of them are satisfied. If some user (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 user 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 added by a later patch. Only two routines are exposed by the boot constraints core for now: - boot_constraint_add(): This will be called by parts of the kernel (before the device is probed) to set the constraints. - 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. Signed-off-by: Viresh Kumar --- drivers/base/Kconfig | 11 +++ drivers/base/Makefile | 1 + drivers/base/boot_constraint.c | 210 ++++++++++++++++++++++++++++++++++++++++ drivers/base/dd.c | 20 ++-- include/linux/boot_constraint.h | 28 ++++++ 5 files changed, 263 insertions(+), 7 deletions(-) create mode 100644 drivers/base/boot_constraint.c create mode 100644 include/linux/boot_constraint.h -- 2.13.0.71.gd7076ec9c9cb diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig index d718ae4b907a..d71217a91793 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig @@ -339,4 +339,15 @@ config CMA_ALIGNMENT endif +config BOOT_CONSTRAINTS + bool "Boot constraints for devices" + default y + 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 Y. + endmenu diff --git a/drivers/base/Makefile b/drivers/base/Makefile index f2816f6ff76a..6094b3b75184 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_BOOT_CONSTRAINTS) += boot_constraint.o obj-$(CONFIG_DEVTMPFS) += devtmpfs.o obj-$(CONFIG_DMA_CMA) += dma-contiguous.o obj-y += power/ diff --git a/drivers/base/boot_constraint.c b/drivers/base/boot_constraint.c new file mode 100644 index 000000000000..38740b8499ba --- /dev/null +++ b/drivers/base/boot_constraint.c @@ -0,0 +1,210 @@ +/* + * This takes care of boot time constraints, normally set by the Bootloader. + * + * Copyright (C) 2017 Linaro. + * Viresh Kumar + * + * This file is released under the GPLv2. + */ + +#define pr_fmt(fmt) "Boot Constraints: " fmt + +#include +#include +#include +#include +#include +#include +#include + +struct constraint { + struct constraint_dev *cdev; + struct list_head node; + enum boot_constraint_type type; + + int (*add)(struct constraint *constraint, void *data); + void (*remove)(struct constraint *constraint); + void *private; +}; + +struct constraint_dev { + struct device *dev; + struct list_head node; + struct list_head constraints; +}; + +#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); + +/* Forward declarations of constraints */ + + +/* 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 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 boot_constraint_add(struct device *dev, enum boot_constraint_type type, + void *data) +{ + 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, type); + if (IS_ERR(constraint)) { + dev_err(dev, "Failed to add constraint type: %d (%ld)\n", type, + PTR_ERR(constraint)); + ret = PTR_ERR(constraint); + goto put_cdev; + } + + /* Set constraint */ + ret = constraint->add(constraint, data); + if (ret) + goto free_constraint; + + dev_dbg(dev, "Added boot constraint-type (%d)\n", 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(boot_constraint_add); + +static void constraint_remove(struct constraint *constraint) +{ + constraint->remove(constraint); + constraint_free(constraint); +} + +void 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/dd.c b/drivers/base/dd.c index 4882f06d12df..4eb9d183d647 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -17,6 +17,7 @@ * This file is released under the GPLv2 */ +#include #include #include #include @@ -381,15 +382,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) + 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..41b5a62d2dbb --- /dev/null +++ b/include/linux/boot_constraint.h @@ -0,0 +1,28 @@ +/* + * Boot constraints header. + * + * Copyright (C) 2017 Linaro. + * Viresh Kumar + * + * This file is released under the GPLv2 + */ + +#include +#include + +struct device; + +enum boot_constraint_type { + BOOT_CONSTRAINT_NONE, +}; + +#ifdef CONFIG_BOOT_CONSTRAINTS +int boot_constraint_add(struct device *dev, enum boot_constraint_type type, + void *data); +void boot_constraints_remove(struct device *dev); +#else +static inline int boot_constraint_add(struct device *dev, + enum boot_constraint_type type, void *data) +{ return -EINVAL; } +static inline void boot_constraints_remove(struct device *dev) {} +#endif From patchwork Wed Jun 28 10:26:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 106510 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp838738qge; Wed, 28 Jun 2017 03:27:58 -0700 (PDT) X-Received: by 10.84.167.74 with SMTP id j10mr10829763plg.144.1498645678740; Wed, 28 Jun 2017 03:27:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498645678; cv=none; d=google.com; s=arc-20160816; b=uZ86oVD33j2I1Dg0kU5ZHH1TmN2ELLCQifZFV1/p4XX4Rwinbj+jSWjJRb0q699vbu hqbuLEGE/liILPNCLwJTdZRhBFxZoO6G7CBO51T7sJDdi7Li3Sp3R1huvWqPNE8bh+s1 1XTT6QuB3Xhg6Yyjnf1ALDWqNjHDtFdEzQ5rgujyQNzc+g2Qr6gde1+TUbuBkE8/DesW LglQcdWF9P5AvP/+zAy8fZFZtqclkyetuuL5lncuXUTJE6EV/jzslJlDesOsnFfbirYp nrmW9aCKhb6YUVznKehWR3GZqXLFf2ieOnw8Y5w7HqglfpWJ/jlZ9X3dl4y70kTg++qH jhHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Vt35BfYTZOaTj23j3TWipkaXWMH6ZoYCK0UJDjVKIHM=; b=Yqhbug9RKxU6XXTPOLuV+V200Tje2nVv5p9OxmaeB70zBHSs+dtzgkN/E06vlSdume ZnYIEahoidSZwDBIS089+NlAnIvWcoEx0tLooXpShtDrp/bheLNc5uwodFzjcYmhg0VL y10G6gR8DPOC91uXH8NQKNFe2FOuLj03qMYhdNbZLBk8WytWXMaWcFBhJkB3wbHP+ZfT l2dlFKXfzyCsxCOXXAFTEOEAamrz5JVYw7mngbbhB8jMBcu3kzIKK8q0gL5Lq4DHYDYc hsvtY6qUwg074hDhy4GqjpqUXGOYgn3qTK1S1jbkLRcAKgvxV/jsHzZ3Nw53ZvDRA1xz KkEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=KGxuUrv7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si1185325pge.232.2017.06.28.03.27.58; Wed, 28 Jun 2017 03:27:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=KGxuUrv7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751943AbdF1K1j (ORCPT + 25 others); Wed, 28 Jun 2017 06:27:39 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:33785 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751787AbdF1K1Q (ORCPT ); Wed, 28 Jun 2017 06:27:16 -0400 Received: by mail-pf0-f169.google.com with SMTP id e7so31377255pfk.0 for ; Wed, 28 Jun 2017 03:27:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=Vt35BfYTZOaTj23j3TWipkaXWMH6ZoYCK0UJDjVKIHM=; b=KGxuUrv7NlhgfFQ3VnSxn4lek5pbB3IP3T7Vi84CBiwRCfAZxGwPBPDgpzSGLRs8Ww 7SvMNE2mNQH45Xi2c1JLylyEu9Xm+PrK/To3i3ccEn84l2dVg9Qx/M+fIbAsGSqA8IEb kqAG48BNGSRE2RH4Sy+iHLD2xTr/1cDlPc0ns= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=Vt35BfYTZOaTj23j3TWipkaXWMH6ZoYCK0UJDjVKIHM=; b=L6SsILcGe6GVNTL0qSZo4gvEo3zYiTRNy1Kgkd6NERIvkdnMoPIAYmUsP+v+j+iLiX g5YC05soF62Hl1j8eBvKEAfRiJsalrNirPqxVIZYP3gzi0jJnWdhPIj4RSE/v+ufT+Dr /aVYWxFWaKxiv4K+rJyfJmNufrsULktwH1PAPc3Ib+dC6uDGdioet06bcUo7aVR8ux1f PQ8wppTt/K8C5qes92PwRiQSTbyUoX4Ufqi41b8s9D6Ie8vVQrKT5kO1O3Yl2j70IskD q1vtXQqqqf3ebW+17txtnkcMqsr8hlPUQ2mrxYJ/6UnK0HRQkcWhTcrg7f3f92jt9sJ3 KGJg== X-Gm-Message-State: AKS2vOyQSA8J7VXbDY8g/dbdMf+HnzNxELh983PnStvVqtUWAvIKV3+o X6sxDlk0mZ6Yx9+wXrcKlw== X-Received: by 10.98.153.135 with SMTP id t7mr10223732pfk.160.1498645635216; Wed, 28 Jun 2017 03:27:15 -0700 (PDT) Received: from localhost ([122.171.238.149]) by smtp.gmail.com with ESMTPSA id l3sm3949463pfk.34.2017.06.28.03.27.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Jun 2017 03:27:14 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Rafael Wysocki , Vincent Guittot , Stephen Boyd , Mark Brown , Shiraz Hashim , Rob Herring , rnayak@codeaurora.org Subject: [RFC 2/5] drivers: boot_constraint: Add support for supply constraints Date: Wed, 28 Jun 2017 15:56:35 +0530 Message-Id: X-Mailer: git-send-email 2.13.0.71.gd7076ec9c9cb In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds the first constraint type: power-supply. The constraint is set by setting a voltage range 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. Signed-off-by: Viresh Kumar --- drivers/base/boot_constraint.c | 92 +++++++++++++++++++++++++++++++++++++++++ include/linux/boot_constraint.h | 9 +++- 2 files changed, 100 insertions(+), 1 deletion(-) -- 2.13.0.71.gd7076ec9c9cb diff --git a/drivers/base/boot_constraint.c b/drivers/base/boot_constraint.c index 38740b8499ba..495344e6405b 100644 --- a/drivers/base/boot_constraint.c +++ b/drivers/base/boot_constraint.c @@ -15,6 +15,7 @@ #include #include #include +#include #include struct constraint { @@ -41,6 +42,8 @@ static LIST_HEAD(constraint_devices); static DEFINE_MUTEX(constraint_devices_mutex); /* Forward declarations of constraints */ +static int constraint_supply_add(struct constraint *constraint, void *data); +static void constraint_supply_remove(struct constraint *constraint); /* Boot constraints core */ @@ -113,6 +116,10 @@ static struct constraint *constraint_allocate(struct constraint_dev *cdev, void (*remove)(struct constraint *constraint); switch (type) { + case BOOT_CONSTRAINT_SUPPLY: + add = constraint_supply_add; + remove = constraint_supply_remove; + break; default: return ERR_PTR(-EINVAL); } @@ -208,3 +215,88 @@ void boot_constraints_remove(struct device *dev) unlock: mutex_unlock(&constraint_devices_mutex); } + + +/* Boot constraints */ + +/* Boot constraint - Supply */ + +struct constraint_supply { + struct boot_constraint_supply_info supply; + struct regulator *reg; +}; + +static int constraint_supply_add(struct constraint *constraint, void *data) +{ + struct 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; + } + + 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; + } + + if (supply->enable) { + 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: + regulator_set_voltage(csupply->reg, 0, INT_MAX); +free_regulator: + regulator_put(csupply->reg); +free: + kfree(csupply); + + return ret; +} + +static void constraint_supply_remove(struct constraint *constraint) +{ + struct constraint_supply *csupply = constraint->private; + struct device *dev = constraint->cdev->dev; + int ret; + + if (csupply->supply.enable) { + ret = regulator_disable(csupply->reg); + if (ret) + dev_err(dev, "regulator_disable failed (%d)\n", ret); + } + + 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_const(csupply->supply.name); + kfree(csupply); +} diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h index 41b5a62d2dbb..a98fdb403e8d 100644 --- a/include/linux/boot_constraint.h +++ b/include/linux/boot_constraint.h @@ -13,7 +13,14 @@ struct device; enum boot_constraint_type { - BOOT_CONSTRAINT_NONE, + BOOT_CONSTRAINT_SUPPLY, +}; + +struct boot_constraint_supply_info { + bool enable; + const char *name; + unsigned long u_volt_min; + unsigned long u_volt_max; }; #ifdef CONFIG_BOOT_CONSTRAINTS From patchwork Wed Jun 28 10:26:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 106513 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp839056qge; Wed, 28 Jun 2017 03:28:20 -0700 (PDT) X-Received: by 10.99.8.1 with SMTP id 1mr9680431pgi.15.1498645700120; Wed, 28 Jun 2017 03:28:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498645700; cv=none; d=google.com; s=arc-20160816; b=KOczN0pu2UrnJ11ubL+FvfG6I0EjCqqMsSeFMTboEzBSGnIbjvJmxLv2naOaKXxtnl ntzpURToz/ORJ2YSv+HBiT6qrnjBOjUAd3z9HF+lOqb7f57r9jyBqBlGSh2tiNYiZBye ruxz8/gSl6UkFc39bYk99D2JrZxwdiUYM8/nbjosE2BZPmc6j/ETXixzo7xIZNmgjm9c AcN3KZLiP+RtHbLoTdtEB2CEykCu0j7ZRoFqRics4rBJiKufLixahzBtX2uToXY84wnL 8snMja4iIm1r/8tk3oeLVmHApoSZQklDLhkPEygXyy9FQhyFuOYDVsInphzZaux3DEQN rRRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=qyB32UkiHvfw4RrsV6muACp7JOg89CFII9LwZnma0os=; b=0vfqeP30x3ZAsyoJlJGXJ0QfoNzPaWPEffhldtlG15OAnkNkGduEBlq2blOSAbRzNC aAJX2fbocfLocDWwSZsSPiZc8enYM5HS8XbOt1X8F6a3GBxOyo3KwO4OS2OB54nxangY vWEcAo9fLbzdjMk4QU4awnFpC3T7f8fAuahatxxRVhP0ELWC8UcRZt+Ok1WNsQSdoE1H RHsagOuIcKUi0CN5TS+23JNK+rAr6QBFSUj2cb5cK3cy+39QzxRc6KnROv7eIljDafx+ MgiOLtRBQtJnAzDvlIzUkYojxh4JysEQPdVVcR1/WPXYVnhs8HqdNV1KZQ2SDQJZZKHc Eizg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=AhIqkcQp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u91si1401529plb.586.2017.06.28.03.28.19; Wed, 28 Jun 2017 03:28:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=AhIqkcQp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752060AbdF1K2G (ORCPT + 25 others); Wed, 28 Jun 2017 06:28:06 -0400 Received: from mail-pg0-f49.google.com ([74.125.83.49]:33923 "EHLO mail-pg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751704AbdF1K1T (ORCPT ); Wed, 28 Jun 2017 06:27:19 -0400 Received: by mail-pg0-f49.google.com with SMTP id t186so29977956pgb.1 for ; Wed, 28 Jun 2017 03:27:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=qyB32UkiHvfw4RrsV6muACp7JOg89CFII9LwZnma0os=; b=AhIqkcQpuDm+Zq8oNR/83VVivuEJkDDxHlX4Ct2tWF1LK3plt0XdIluUidflvZ2Y0q LcbLNrMBqjq8xpQve/CulAdOcfxjDPDCAa714BVsiulQY6eOi7zz1SWtZ//klzRNycJB O0MUWfVSdYACx12SjckkVDh3vTsAzWwAAcsD0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=qyB32UkiHvfw4RrsV6muACp7JOg89CFII9LwZnma0os=; b=d0B2hupI+zpSu7OcL/q5OD9y1rO0WwrgOvhqLxSb14kqShN0lydHyrradI6KqUxQVy nUd5HXwORg8yCyL+L3OMeHFU490T08RYKqlw3fpjUNcD5uXgqep6eTCgrdp6B/9SgtEF Gg9+6h1VO/LLz7zpBh+kjJUKXK0ptjwPDIKGLSaYmaXvsMzAuwC1Slh+WGqfw0hUJWPw G4urZRWAwWVM5hOzsXcofTXPykOU/i8hFUB8KWKTJh9K8IyPOfiItvvuZcV8j9n3f/tz 3IY2OyZ2jsmzxlurkNZFUjFhybbOw0ACUFdOZh6BBRjqiMyYnQojpF5RmQ3B1UCBuSa6 DmpQ== X-Gm-Message-State: AKS2vOwrTXltQUGZJFnoXdIk6Xlf8h5Uo8QNXMlgoBQrhHIOJQjMTzUp SrLgXadhRupuN7io X-Received: by 10.99.103.7 with SMTP id b7mr9844035pgc.2.1498645638103; Wed, 28 Jun 2017 03:27:18 -0700 (PDT) Received: from localhost ([122.171.238.149]) by smtp.gmail.com with ESMTPSA id y15sm4265243pgs.33.2017.06.28.03.27.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Jun 2017 03:27:17 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Rafael Wysocki , Vincent Guittot , Stephen Boyd , Mark Brown , Shiraz Hashim , Rob Herring , rnayak@codeaurora.org, linux-doc@vger.kernel.org Subject: [RFC 3/5] drivers: boot_constraint: Add boot_constraints_disable kernel parameter Date: Wed, 28 Jun 2017 15:56:36 +0530 Message-Id: X-Mailer: git-send-email 2.13.0.71.gd7076ec9c9cb In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Viresh Kumar --- Documentation/admin-guide/kernel-parameters.txt | 2 ++ drivers/base/boot_constraint.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) -- 2.13.0.71.gd7076ec9c9cb diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 7737ab5d04b2..35e8a298bfc1 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -426,6 +426,8 @@ 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_constraint.c b/drivers/base/boot_constraint.c index 495344e6405b..ab766d60191a 100644 --- a/drivers/base/boot_constraint.c +++ b/drivers/base/boot_constraint.c @@ -45,6 +45,17 @@ static DEFINE_MUTEX(constraint_devices_mutex); static int constraint_supply_add(struct constraint *constraint, void *data); static void constraint_supply_remove(struct constraint *constraint); +static bool constraints_disabled; + +static int __init constraints_disable(char *str) +{ + constraints_disabled = true; + pr_debug("disabled\n"); + + return 0; +} +early_param("boot_constraints_disable", constraints_disable); + /* Boot constraints core */ @@ -152,6 +163,9 @@ int boot_constraint_add(struct device *dev, enum boot_constraint_type type, struct constraint *constraint; int ret; + if (constraints_disabled) + return -ENODEV; + mutex_lock(&constraint_devices_mutex); /* Find or add the cdev type first */ @@ -202,6 +216,9 @@ void boot_constraints_remove(struct device *dev) struct constraint_dev *cdev; struct constraint *constraint, *temp; + if (constraints_disabled) + return; + mutex_lock(&constraint_devices_mutex); cdev = constraint_device_find(dev); From patchwork Wed Jun 28 10:26:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 106511 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp838748qge; Wed, 28 Jun 2017 03:27:59 -0700 (PDT) X-Received: by 10.99.49.20 with SMTP id x20mr9677498pgx.181.1498645679147; Wed, 28 Jun 2017 03:27:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498645679; cv=none; d=google.com; s=arc-20160816; b=Z2cLhyBpkM6B6k2cQrjBo6hrY3O9xw596hlvVRQnb3Erz3cuZCAaMsFTueX13fhKMU p1ywyLZGYowej3DMavqqkbnxeLzqWYDNKJxaqSB1vwBuBVsjvdKfAKio5yHxuZDpUiS3 Y5q8Op8FuusxImhK/G+vLxppClRG/VSTDQmRBO2z2kpDXLFBzeEESpDYQFnPHj7nfA/w yZN2EtEM7mj320/3MTtXXDQjuojmmDdruSBivwFy+jXJJFh+IFjAOL+ZnjN+RXFL4aN7 nuzyCc9uemApvYSdBXQ9DAqVJLEYY7qtvhbDSJhP2XTUeYWWk9osnFwj62kD7e4KZL2u y11A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=yjcbfsMFbC4geogg52o+6IZ35JP03uzSX+gBJl1Lzv8=; b=UrQ4AYwJG7Klg2IOBaQSbBO6Zk59r0uslg73g40IYAUuedsvih4xftr1wmM/dmhMO2 bLaRjSsU3u5cpIZ9jZJHAHMsCCZk0LR+ExD09rZZrgRDfxzr5SKYIND0CTaRXyZsgmeT NXU63PeFUVe0R+qBIoLQRJpt+jk4kzlLUInx2SYLL/lXh+Gq3qJrVsvb1Nsf/V1sh6x7 04Pwgc8ex7IpjkGsVYOrcjYiA6zDJOka/G2yIjdOc9eq5nUtswjd8UvQ/hTUu6wFM0IZ lowEvPtOH2JeGcKZaEbs8B/k3C+Ll1wR+J+R3JxXvacaPBQ7RlErnB9SlJgYnYYoS18p k+sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=QcpuXOtx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si1185325pge.232.2017.06.28.03.27.58; Wed, 28 Jun 2017 03:27:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=QcpuXOtx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751989AbdF1K1t (ORCPT + 25 others); Wed, 28 Jun 2017 06:27:49 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:33081 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751817AbdF1K1W (ORCPT ); Wed, 28 Jun 2017 06:27:22 -0400 Received: by mail-pg0-f43.google.com with SMTP id f127so29836053pgc.0 for ; Wed, 28 Jun 2017 03:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=yjcbfsMFbC4geogg52o+6IZ35JP03uzSX+gBJl1Lzv8=; b=QcpuXOtxQur9DhbFnJQ+Y6o5AReNFl/jXAXq+bFH4d5FH3jOvZJsibJ4C25E6s0+Ce nbFle6gr6Oi5anofZCgxEtxPwNyNvA1fzjEMXT5cWl4Ir+7eOv89iskoPNQC6UpBtqQN cPHa4meCXq+P8ZzDF1bxfy7t6Gt3XEuBk3vrU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=yjcbfsMFbC4geogg52o+6IZ35JP03uzSX+gBJl1Lzv8=; b=CowBs590ikVCjUgMXjx21VHA+qjUh8l3jFblWhub99zKYiZaKmImPpIutSNT/SOKIL MsyQPEpl/q+dO9RpmZxLm6erLKSr+Uoe7W4Tu6GnMjwA11jWb4cCIsqXt2t6L/3Oj29f 7k/cZ7w1+zV6huI0I7l4n3I1FqzHwD8Jg8vKwvSPcNxECQmTnfgjCR/Rk3XY/0HPf+UL rX0dHe24zXlK72ZZeBoO/oC8eZIXFgpvK3VO/LR3186W/f8UhW7764yyP9xhc1jEdL3S nagZuxXu6XUv/3aNzQXh0/iSf0O+vSyCxbseMJKcOTImpoOvhZ/qsNx4AAyEOgBWtV32 AjIA== X-Gm-Message-State: AKS2vOwYQfgSf3aP6WrVh9nc5Nq7CWnlkQYqFTWDNe5YcX0tDJidcWXT KwI32S2jX0PkiMWH X-Received: by 10.99.131.193 with SMTP id h184mr9960929pge.80.1498645641015; Wed, 28 Jun 2017 03:27:21 -0700 (PDT) Received: from localhost ([122.171.238.149]) by smtp.gmail.com with ESMTPSA id d1sm4081951pfj.51.2017.06.28.03.27.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Jun 2017 03:27:20 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Rafael Wysocki , Vincent Guittot , Stephen Boyd , Mark Brown , Shiraz Hashim , Rob Herring , rnayak@codeaurora.org Subject: [RFC 4/5] drivers: boot_constraint: Add debugfs support Date: Wed, 28 Jun 2017 15:56:37 +0530 Message-Id: <58dbcc2e397fc679af814a9752efa1829885d7f3.1498642745.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.13.0.71.gd7076ec9c9cb In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: supply-vmmc /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmc: enable u_volt_max u_volt_min Signed-off-by: Viresh Kumar --- drivers/base/boot_constraint.c | 83 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) -- 2.13.0.71.gd7076ec9c9cb diff --git a/drivers/base/boot_constraint.c b/drivers/base/boot_constraint.c index ab766d60191a..ff1c63b34458 100644 --- a/drivers/base/boot_constraint.c +++ b/drivers/base/boot_constraint.c @@ -10,6 +10,7 @@ #define pr_fmt(fmt) "Boot Constraints: " fmt #include +#include #include #include #include @@ -22,6 +23,7 @@ struct constraint { struct constraint_dev *cdev; struct list_head node; enum boot_constraint_type type; + struct dentry *dentry; int (*add)(struct constraint *constraint, void *data); void (*remove)(struct constraint *constraint); @@ -32,6 +34,7 @@ struct constraint_dev { struct device *dev; struct list_head node; struct list_head constraints; + struct dentry *dentry; }; #define for_each_constraint(_constraint, _temp, _cdev) \ @@ -57,6 +60,71 @@ 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); +} + +static 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 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); +} + +static void constraint_remove_debugfs(struct constraint *constraint) +{ + debugfs_remove_recursive(constraint->dentry); +} + +static int __init constraint_debugfs_init(void) +{ + if (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) @@ -84,12 +152,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); } @@ -285,6 +355,18 @@ static 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_ulong("u_volt_min", 0444, constraint->dentry, + &csupply->supply.u_volt_min); + + debugfs_create_ulong("u_volt_max", 0444, constraint->dentry, + &csupply->supply.u_volt_max); + + debugfs_create_bool("enable", 0444, constraint->dentry, + &csupply->supply.enable); + return 0; remove_voltage: @@ -314,6 +396,7 @@ static void constraint_supply_remove(struct constraint *constraint) dev_err(dev, "regulator_set_voltage failed (%d)\n", ret); regulator_put(csupply->reg); + constraint_remove_debugfs(constraint); kfree_const(csupply->supply.name); kfree(csupply); } From patchwork Wed Jun 28 10:26:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 106512 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp838869qge; Wed, 28 Jun 2017 03:28:07 -0700 (PDT) X-Received: by 10.84.157.74 with SMTP id u10mr4228440plu.137.1498645687203; Wed, 28 Jun 2017 03:28:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498645687; cv=none; d=google.com; s=arc-20160816; b=lEgDaUafuQbNFGroXx3tUyjWsh5E4t7z21BPFZQKYGWj8n646pbGzri8tpLmux362E mPm4sagD5MjVYIfnji0ijMBIAS4ENvaau79ZpvkBhq8h1WUs/Huh20/LNeF2cK1k7mWa nt/F1ZerV+PzC3Za16si5c17VgrGl2x/2Wimx/kMjkL0zN6POLGLXjTFuOZ2HXKEGOyb Gnp562svaxLZHRV9FiA6CpnrT386C7zFzPgvucjZmc6Ou58h8FXZIgvo5VyFvI/cUWXn OcdfmSa0mjHhO3ombf2fz5LuE46Wc7K+BPpP9Cvtf9yJRqghBg2/CygFZlEmNgUnmMaf ZJVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=FsSsjDkYlAFRQaSqDtvrxTsBejF9/Czol2y7ykIXzjY=; b=unxwugAi/r0N+vawRHsZuVy2XnxESwFCigJsCAYIjFbU3x4bjF6EZOisG4ivtFa2Cv qCqIzijVru0u1j8HBsGOOfpAv1mPvsQDstgo2ff4gl5H19MhgKSvxMKi91tgGxBKtTE2 MnJfnuKL448MvYtnvAX8m73wI0pyRUGZFqBiWWW7bje2gqQ4Fha3Y3pIZPQXBkqlI2wr ij4oJl22w9immCsYMEWx0AbQZhsz6kubfxNk5onf0LY4pg/pOq7iGDwtYkoMc/aSTNJL bz6CKH0RceIf8BblRfL8jNY1/Y9t2Z8AqOHpwAvGKHKwKhRdZNY7kufjm0EuHVVh8aJ6 tLpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=F9ALZCZK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n189si1252021pga.550.2017.06.28.03.28.06; Wed, 28 Jun 2017 03:28:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=F9ALZCZK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751528AbdF1K16 (ORCPT + 25 others); Wed, 28 Jun 2017 06:27:58 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:32799 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751838AbdF1K1Y (ORCPT ); Wed, 28 Jun 2017 06:27:24 -0400 Received: by mail-pf0-f181.google.com with SMTP id e7so31379084pfk.0 for ; Wed, 28 Jun 2017 03:27:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=FsSsjDkYlAFRQaSqDtvrxTsBejF9/Czol2y7ykIXzjY=; b=F9ALZCZKUfSvN3l5N82dr3bDCxLNHUB6wgfZTo9UUbH0MCALkkbZ+L1wBEWe5SmOqt fVBkGxPuOzdVzLsZTzybyJKwgmKUgZWO7aSR92545u4viMLfwZ5l1AUM3ebN1269zpCl OEyy+SxJMb+nynDqKkat2yq4Xks4pV7+pbbmo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=FsSsjDkYlAFRQaSqDtvrxTsBejF9/Czol2y7ykIXzjY=; b=SFNlSh+dmjcGT7Z/kgXVxLZYanY9Q9iH0vpFjfTOguA6oTNvxxz9TM0UyjS71bNg3n 51aMttKTQOvQNItY1LMQoZ0ayKKZqvIvb0FlyykuU2o/RKI6fPnkRzEDNd5LVJPcE5qj TY//TCObq9MMCFoSUihYgxCw7aybh+3CBqiSMTDp7ZlpClHGe3Zrkn8TGg+wSeHmi1GB mSchIOQa4uCUHA327lT+uGukUE4FT6kc+IpqQUx59UhznWlhobiR8iwB6Mw2e4drRFEl PRX6ua3IfnIl6afsLuC+kDolibedC+kARDBYp+RwPnvdA50A1wpSPj1j2QQMdYz6UI0j 2SIg== X-Gm-Message-State: AKS2vOztF7HV1LR6Cma+1KJBhenlLc/fdV1ahcOkD7i6MuCD1fyUTal3 i6c02V8Q4WtZx7W9 X-Received: by 10.84.169.67 with SMTP id g61mr10847927plb.250.1498645644055; Wed, 28 Jun 2017 03:27:24 -0700 (PDT) Received: from localhost ([122.171.238.149]) by smtp.gmail.com with ESMTPSA id k129sm4041229pfc.87.2017.06.28.03.27.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Jun 2017 03:27:23 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Rafael Wysocki , Vincent Guittot , Stephen Boyd , Mark Brown , Shiraz Hashim , Rob Herring , rnayak@codeaurora.org Subject: [RFC 5/5] drivers: Code to test boot constraints Date: Wed, 28 Jun 2017 15:56:38 +0530 Message-Id: X-Mailer: git-send-email 2.13.0.71.gd7076ec9c9cb In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.13.0.71.gd7076ec9c9cb 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 000000000000..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 = 1800000, + .u_volt_max = 3000000, + }; + 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(&pdev->dev, BOOT_CONSTRAINT_SUPPLY, &info); + 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(&test_constraints_driver); +} +subsys_initcall(test_constraints_init);