From patchwork Wed Jul 12 06:34:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 107442 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp432462qge; Tue, 11 Jul 2017 23:34:59 -0700 (PDT) X-Received: by 10.98.113.71 with SMTP id m68mr37157768pfc.220.1499841299663; Tue, 11 Jul 2017 23:34:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499841299; cv=none; d=google.com; s=arc-20160816; b=MZWkUzcil/A4w+IQWnzMZvXIcQRQwOCTKhB/K+QT7mqdWd6SiMncr3/Ml7dtf4KNVd uQuacbcp9vvmk3k4IilR8CH7v6JO9JU7r3U2bV6fG9EReDM9IyG0ckXPWWdU18Pa2bTe BO1rEkh7GIAnglRNccuojfBCXQSIq3ZNBTsfUzJTa6r60HB13m/n+ITkCiHDQb1YdfRW XkPMY0xRRtb7S/ZOdfr5p7mUnPZ8L3IvJTCzrqBS5hKgHC6CytH0vkrb6LhTFiaL2B8l XDnah8C1lg15ttVVlzWGO8bsDNiz2YDtUKvCHezxJ748jgqqIIowEezG/MV7F6pHVL5L e0vQ== 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=m16X9ipbd33AgAsVfnjWbNFaVVu9Q6bCDEEDZHi1Pf8=; b=PtY5xueLh6SsZV3OLE4jlrJpSt/W3CPZ8K0T4ubJu0ovI+WCthr2W9vwmNU8/R7xD6 P/LGnEVsZCuLu3taLIpG+83Yo7tcZfnzX+XsE/AgS378PpiJGsBpjwGchnyowvqCIbm4 adeEd4gJ0T5TKp/Gg8pXprwqih2kDVIUW6uSRQ19EM5OtCyw8wu9rEQTgYzkg9Zdep0v Q6NgYBW/n0/aC5voYDX4Qk41y3e1YGHoT+lrQg7CpdLJh5blra9TEXuSfJDxOEPwFzeD XYIBbHPq1nNm/CGqJHXQvHrPzbifvwryW5Vzq4vX1DyjZfjjetdSJX/C/fDhtkMXFSQM fx3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=O56eTPWl; 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 x13si1265814pgq.222.2017.07.11.23.34.58; Tue, 11 Jul 2017 23:34: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=O56eTPWl; 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 S1756432AbdGLGew (ORCPT + 25 others); Wed, 12 Jul 2017 02:34:52 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:32854 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755899AbdGLGeu (ORCPT ); Wed, 12 Jul 2017 02:34:50 -0400 Received: by mail-pg0-f43.google.com with SMTP id k14so8071592pgr.0 for ; Tue, 11 Jul 2017 23:34:50 -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=m16X9ipbd33AgAsVfnjWbNFaVVu9Q6bCDEEDZHi1Pf8=; b=O56eTPWlh7A3pvRRLoBepnkHJEc4hz6YJ9R+DQkRzob4NeAdz6rdz6V/h8+1tnlzZQ 0SXMs54AEGaozP809k52aLO2NWf+qOhQwfsLpBFETcAf1nOtzKtX/WRwM9bNT04djX0j /sKkrG86SKvkuQ7iPrc6N8PbBCl/A8f0X6dV4= 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=m16X9ipbd33AgAsVfnjWbNFaVVu9Q6bCDEEDZHi1Pf8=; b=YWGrNSmH2zxqePYO0jPfv2wsA1e1KIuJpN1+B0wycjkrqiwZ+MzYyzoJLTbtL/CQMU sH8eFAdlgW2y8ubEBALvz3Fzb+oKxc1pbszF4d152hhSNLo904lfvHFyWK+coCI98afZ 7ox2W6IlH+DFmctNygb8hZd7IK6lJDOrQpQyCltulWsgS1C9E3ABZxrbZ4XdwCxkHK9Z iQfi0g8CIWmWkqsuahS3jXVRsyHQJcNeh5yPx+8ygkyIvaVo6t4tR/3LbdG/Rfhl9hDC X3AAz9ZuJmyO0Onjh3w114wu1vaqd4mtZXaA03klTGa1xUVaLGM4raDqEwxi8afKK+YR 5qPQ== X-Gm-Message-State: AIVw110ZYl/3Cts4s2ghatbAGS/TRq88O8dvG5v0XklUswcZfJyWrZNM T4xtZ7rlctsUFHU+ X-Received: by 10.98.36.19 with SMTP id r19mr52462660pfj.95.1499841290187; Tue, 11 Jul 2017 23:34:50 -0700 (PDT) Received: from localhost ([122.167.138.108]) by smtp.gmail.com with ESMTPSA id 71sm2668797pge.45.2017.07.11.23.34.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Jul 2017 23:34:49 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , Vincent Guittot , Rob Herring , Mark Brown , Stephen Boyd , Rajendra Nayak , Shiraz Hashim , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RFC v2 2/6] drivers: boot_constraint: Add support for supply constraints Date: Wed, 12 Jul 2017 12:04:32 +0530 Message-Id: <9a0ae6f5bf543373f6a3e51fd6e83706c3cb9683.1499770771.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 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 | 88 +++++++++++++++++++++++++++++++++++++++++ include/linux/boot_constraint.h | 8 +++- 2 files changed, 95 insertions(+), 1 deletion(-) -- 2.13.0.71.gd7076ec9c9cb diff --git a/drivers/base/boot_constraint.c b/drivers/base/boot_constraint.c index 7dc7b6132765..4e4332751c5f 100644 --- a/drivers/base/boot_constraint.c +++ b/drivers/base/boot_constraint.c @@ -15,6 +15,7 @@ #include #include #include +#include #include struct constraint { @@ -43,6 +44,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 */ @@ -115,6 +118,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); } @@ -217,3 +224,84 @@ 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; + } + + 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; + + 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 99f268447f72..110e5eca36c6 100644 --- a/include/linux/boot_constraint.h +++ b/include/linux/boot_constraint.h @@ -13,7 +13,13 @@ struct device; enum boot_constraint_type { - BOOT_CONSTRAINT_NONE, + BOOT_CONSTRAINT_SUPPLY, +}; + +struct boot_constraint_supply_info { + const char *name; + unsigned int u_volt_min; + unsigned int u_volt_max; }; struct boot_constraint_info {