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