From patchwork Fri Feb 23 10:23:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10237359 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 89232602DC for ; Fri, 23 Feb 2018 10:35:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 706912913A for ; Fri, 23 Feb 2018 10:35:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64DF9294E5; Fri, 23 Feb 2018 10:35:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BE5EE2947F for ; Fri, 23 Feb 2018 10:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=COc654lVf4E0W/LNUQPQTJtqY/SbF8FeeG6l2OcHMk4=; b=DD3iKBLF9/k8q46XlBdFZJ6CUT pTSfrd3noWXy0OoZi7UfJPOBu/4qvlBWmkedyKEIl0QT4lao4texT8+/HVUxScIdQ696jaLEQCvQR Bsccw9k8OKZr+DMJcHUcMpfN20dUENJQ71dqgH97/VYTIPc5pY8os3Agc/EtktMt1a2o2qfTmPVRy ztDKjtz8GCOc6+lzEMZGKLgohPaCUfcCI9DoY3QkV/uAocyt/bpFLmHFThnPX4OmTcpfewIZaiT+K J1yZWzlRzk3Dp4L2+agRm3Sh8H82izGYrTcHTF6hUUPM6JtADCQT54ApB1sJk0rVARmOZLaSqyVZt IdQUP4mw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1epAh1-0005jX-AD; Fri, 23 Feb 2018 10:35:07 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1epAd8-0003Ib-Oz for linux-arm-kernel@bombadil.infradead.org; Fri, 23 Feb 2018 10:31:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=NEHZacP+KL+rUypqnXnVYM/ZBgBS8SyS2IS4QXMto1Q=; b=nbivv3jcFq2BopRR2J+nqPlB7 sTCVt1S49Hl8hFQPnkcIQzIKRthwyp0o02QQ8ENyvK9npcDgrhEyMzyomnWBQ5o2ei98r5Z8udaWJ O3pU9/Z39TT2fIx9xuS7AVo9K9BAWJ44ueTIjXNTq//zcAmq/REPJOWOqtfZpLxpFLY1rzRYRdfUs ap/c1T3QF5IW+RMNIcWfq2IxNO31uERBkJCagkvVnj/U+H0Htd4dmSXHOuoWQEukcZGHGDVtmq4f0 H4w+8frDMED1IlNvoVlKAceKE690B79cWc5UEfcV4LWOBCPg4cnlzgFM4mGrZjwUkGtJnynzk6/OE t7vHnSDng==; Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1epAWi-00060A-5J for linux-arm-kernel@lists.infradead.org; Fri, 23 Feb 2018 10:24:30 +0000 Received: by mail-pg0-x243.google.com with SMTP id m19so3205679pgn.1 for ; Fri, 23 Feb 2018 02:24:17 -0800 (PST) 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=NEHZacP+KL+rUypqnXnVYM/ZBgBS8SyS2IS4QXMto1Q=; b=evdnR6He4LMJvgvRD6Vzy9TrtqNC03fb5h97koPNf+m461YiQHjN0tyLD6Bsvmm9dt jagX5MYz71ALr8OgbS68i+n6zNaSLfgwxy0gGcm2SebcpIP1vTh6EmYzF0LErbBpBCVG kSgpih1alB8VRKQaOzLfDXlcL2ge0HtMzv01I= 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=NEHZacP+KL+rUypqnXnVYM/ZBgBS8SyS2IS4QXMto1Q=; b=a5xpVgamb1hmRZ3kMi0HYakVJJ4NxTuH0rUQfMJSxdGsbmFxVuVruW6FFxQgSzAZeE VA2yR61wm2hdVU9RvoWas3tF7wzNHNTNLsvcK7cpkxfY8zsP+w67qTC8bdo4mvyHJ8Ud lZVCbtvUOCopFOm1VZbO0J02w3TwPDDThaC2CKL9bLP+ecgQhV7bqqfW2KMuaUNGGXa0 ybfLlQSvXoDHq1cJoh2gISIoZ/tMdpnlXuG4QAIBU8NCLWJsBY/oU0pm6w06e280zgEL SzGjNByeHVm4sAcNdzd05SLkaBYWrENkDcPhbF6X6I0iuVyP4SDk+NYLyURNy6gyOd6t i1lg== X-Gm-Message-State: APf1xPAUDZX0YKBWah2ZxcE7JOC7QE4WpatNy/EuJiEy+Ha5e2ptTDJS HMkvIQ1s143hSG5fz0CM9mo3vw== X-Google-Smtp-Source: AH8x224MfuNNd9hrGE7GKK/AdBRHB1vjfILD+9Lm6D7S72FogwvBJ3mGBKqWN+YWbQCjGUvjOTuoNw== X-Received: by 10.98.198.1 with SMTP id m1mr1266712pfg.90.1519381455839; Fri, 23 Feb 2018 02:24:15 -0800 (PST) Received: from localhost ([122.167.232.138]) by smtp.gmail.com with ESMTPSA id p3sm4024590pfh.7.2018.02.23.02.24.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Feb 2018 02:24:15 -0800 (PST) From: Viresh Kumar To: Greg Kroah-Hartman Subject: [PATCH V7 04/13] boot_constraint: Add support for supply constraints Date: Fri, 23 Feb 2018 15:53:43 +0530 Message-Id: <4425c187bddde1baf7a17cb52e36aae746626add.1519380923.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180223_102428_190387_A84EDC45 X-CRM114-Status: GOOD ( 26.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nm@ti.com, Rajendra Nayak , Stephen Boyd , Viresh Kumar , s.hauer@pengutronix.de, linux-kernel@vger.kernel.org, xuwei5@hisilicon.com, olof@lixom.net, robdclark@gmail.com, robh+dt@kernel.org, fabio.estevam@nxp.com, Vincent Guittot , shawnguo@kernel.org, linux-arm-kernel@lists.infradead.org, l.stach@pengutronix.de MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Viresh Kumar --- drivers/bootconstraint/Makefile | 2 +- drivers/bootconstraint/core.c | 4 ++ drivers/bootconstraint/core.h | 5 +++ drivers/bootconstraint/supply.c | 95 +++++++++++++++++++++++++++++++++++++++++ include/linux/boot_constraint.h | 17 +++++++- 5 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 drivers/bootconstraint/supply.c diff --git a/drivers/bootconstraint/Makefile b/drivers/bootconstraint/Makefile index 0f2680177974..a45616f0c3b0 100644 --- a/drivers/bootconstraint/Makefile +++ b/drivers/bootconstraint/Makefile @@ -1,3 +1,3 @@ # Makefile for device boot constraints -obj-y := core.o +obj-y := core.o supply.o diff --git a/drivers/bootconstraint/core.c b/drivers/bootconstraint/core.c index a9f38a0febb3..2973f8dd9094 100644 --- a/drivers/bootconstraint/core.c +++ b/drivers/bootconstraint/core.c @@ -91,6 +91,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/bootconstraint/core.h b/drivers/bootconstraint/core.h index d04bd484b2a7..44c219716be5 100644 --- a/drivers/bootconstraint/core.h +++ b/drivers/bootconstraint/core.h @@ -27,4 +27,9 @@ struct constraint { void (*remove)(struct constraint *constraint); void *private; }; + +/* 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/bootconstraint/supply.c b/drivers/bootconstraint/supply.c new file mode 100644 index 000000000000..352ded92d057 --- /dev/null +++ b/drivers/bootconstraint/supply.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 Linaro. + * Viresh Kumar + */ + +#include +#include +#include + +#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 d56e33f3f921..736fe09a8589 100644 --- a/include/linux/boot_constraint.h +++ b/include/linux/boot_constraint.h @@ -16,9 +16,24 @@ struct device; /** * enum dev_boot_constraint_type - This defines different boot constraint types. * + * @DEV_BOOT_CONSTRAINT_SUPPLY: This represents a power supply boot constraint. */ enum dev_boot_constraint_type { - DEV_BOOT_CONSTRAINT_NONE, + DEV_BOOT_CONSTRAINT_SUPPLY, +}; + +/** + * struct dev_boot_constraint_supply_info - Power supply boot constraint + * information. + * + * @name: This must match the power supply name for the device. + * @u_volt_min: This is the minimum microvolts value supported by the device. + * @u_volt_max: This is the maximum microvolts value supported by the device. + */ +struct dev_boot_constraint_supply_info { + const char *name; + unsigned int u_volt_min; + unsigned int u_volt_max; }; /**