From patchwork Wed Nov 24 09:45:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Petazzoni X-Patchwork-Id: 352271 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAO9jutr020324 for ; Wed, 24 Nov 2010 09:45:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752735Ab0KXJpz (ORCPT ); Wed, 24 Nov 2010 04:45:55 -0500 Received: from mail.free-electrons.com ([88.190.12.23]:43319 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752582Ab0KXJpy convert rfc822-to-8bit (ORCPT ); Wed, 24 Nov 2010 04:45:54 -0500 Received: by mail.free-electrons.com (Postfix, from userid 106) id B2FAD182; Wed, 24 Nov 2010 10:45:52 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.3.1 Received: from surf (humanoidz.org [82.247.183.72]) by mail.free-electrons.com (Postfix) with ESMTPA id D04F1E7; Wed, 24 Nov 2010 10:45:44 +0100 (CET) Date: Wed, 24 Nov 2010 10:45:44 +0100 From: Thomas Petazzoni To: Mark Brown Cc: Kevin Hilman , "Gopinath, Thara" , "linux-omap@vger.kernel.org" , "paul@pwsan.com" , "Sripathy, Vishwanath" , "Sawant, Anand" , "Cousson, Benoit" , Liam Girdwood Subject: Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver. Message-ID: <20101124104544.13da3cd2@surf> In-Reply-To: <20100903182052.GB32226@rakim.wolfsonmicro.main> References: <1282130412-12027-1-git-send-email-thara@ti.com> <1282130412-12027-2-git-send-email-thara@ti.com> <87eiddgjr7.fsf@deeprootsystems.com> <5A47E75E594F054BAF48C5E4FC4B92AB03291AD889@dbde02.ent.ti.com> <87r5ha3hlk.fsf@deeprootsystems.com> <20100903173046.GA32226@rakim.wolfsonmicro.main> <87pqwu1zcw.fsf@deeprootsystems.com> <20100903182052.GB32226@rakim.wolfsonmicro.main> X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 24 Nov 2010 09:45:56 +0000 (UTC) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index f1d10c9..12a1cae 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -132,6 +132,28 @@ static int regulator_check_voltage(struct regulator_dev *rdev, return 0; } +/* Make sure we select a voltage that suits the needs of all + * regulator consumers + */ +static int regulator_check_consumers(struct regulator_dev *rdev, + int *min_uV, int *max_uV) +{ + struct regulator *regulator; + + list_for_each_entry(regulator, &rdev->consumer_list, list) + { + if (*max_uV > regulator->max_uV) + *max_uV = regulator->max_uV; + if (*min_uV < regulator->min_uV) + *min_uV = regulator->min_uV; + } + + if (*min_uV > *max_uV) + return -EINVAL; + + return 0; +} + /* current constraint check */ static int regulator_check_current_limit(struct regulator_dev *rdev, int *min_uA, int *max_uA) @@ -1636,6 +1658,11 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) goto out; regulator->min_uV = min_uV; regulator->max_uV = max_uV; + + ret = regulator_check_consumers(rdev, &min_uV, &max_uV); + if (ret < 0) + goto out; + ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV); out: