From patchwork Thu Oct 15 16:12:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 7407861 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C9584BEEA4 for ; Thu, 15 Oct 2015 16:14:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9BF2A207DD for ; Thu, 15 Oct 2015 16:14:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 47C16207D5 for ; Thu, 15 Oct 2015 16:14:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752502AbbJOQN6 (ORCPT ); Thu, 15 Oct 2015 12:13:58 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:33249 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753867AbbJOQNm (ORCPT ); Thu, 15 Oct 2015 12:13:42 -0400 Received: by pabrc13 with SMTP id rc13so91900764pab.0 for ; Thu, 15 Oct 2015 09:13:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=vE74Zj4QFeatfjBM2nxINqDb1Km6DTGo1CCoDl2JXgM=; b=fWxyeihYDByPKOWpgd4NDK8V3+HXTFbfZQIBvrBPSlXUuK1VJbWdN5a/+4Ew9p/GBj xEAOis8ykyDD/UMWWJiN2I3YpDWGS2HlMkRLX/r/QF8C5KnhWZwwjGGV1n+dOn9b/bCi RPRbJLywsfcCpqCk77Af0jEpfDrXqXAcsMaYVNc6OjElBSVQrp0LOeQ9oP61q2ohYHhL PRJtZ6ogDC5crcJs1FOsahEJvIhUWZw7B9OOylRWxQw5ZjNnKx/e3iZr1tHnzT3wxl8l gRyodEKNmaPtnCbtC7nVOGhbW0xif8x0//tLXBTkgSIvFgWUNevuOL+yY5OROLkBWodv oKtg== X-Gm-Message-State: ALoCoQkMeyItdJ3CuJXe2d0QoFnxuBAGEEwf4VxFtSs7dYY68CX04RZci87WH+FBlpqd4u5Bw6TW X-Received: by 10.68.98.99 with SMTP id eh3mr10922487pbb.126.1444925621809; Thu, 15 Oct 2015 09:13:41 -0700 (PDT) Received: from localhost ([223.227.130.246]) by smtp.gmail.com with ESMTPSA id xm9sm16245619pbc.32.2015.10.15.09.13.39 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 15 Oct 2015 09:13:41 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, sboyd@codeaurora.org, nm@ti.com, Viresh Kumar , Bartlomiej Zolnierkiewicz , Dmitry Torokhov , Greg Kroah-Hartman , Len Brown , linux-kernel@vger.kernel.org (open list), Pavel Machek Subject: [PATCH V2 4/4] PM / OPP: Create separate structure for regulator/supplies Date: Thu, 15 Oct 2015 21:42:46 +0530 Message-Id: X-Mailer: git-send-email 2.4.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Support for multiple regulators will be added later, until then move all power-supply related information in a separate structure. To make allocating/freeing memory for these supply structures easy, allocate memory for them along with opp. Signed-off-by: Viresh Kumar --- drivers/base/power/opp/core.c | 57 ++++++++++++++++++++++++++++--------------- drivers/base/power/opp/opp.h | 29 ++++++++++++++++------ 2 files changed, 58 insertions(+), 28 deletions(-) diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index 8fa522f41226..4c00ba719ae4 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -127,7 +127,7 @@ unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp) if (IS_ERR_OR_NULL(tmp_opp) || !tmp_opp->available) pr_err("%s: Invalid parameters\n", __func__); else - v = tmp_opp->u_volt; + v = tmp_opp->supplies[0].u_volt; return v; } @@ -483,13 +483,14 @@ struct device_list_opp *_add_list_dev(const struct device *dev, /** * _add_device_opp() - Find device OPP table or allocate a new one * @dev: device for which we do this operation + * @supply_count: Number of supplies available for each OPP. * * It tries to find an existing table first, if it couldn't find one, it * allocates a new OPP table and returns that. * * Return: valid device_opp pointer if success, else NULL. */ -static struct device_opp *_add_device_opp(struct device *dev) +static struct device_opp *_add_device_opp(struct device *dev, int supply_count) { struct device_opp *dev_opp; struct device_list_opp *list_dev; @@ -507,6 +508,7 @@ static struct device_opp *_add_device_opp(struct device *dev) if (!dev_opp) return NULL; + dev_opp->supply_count = supply_count; INIT_LIST_HEAD(&dev_opp->dev_list); list_dev = _add_list_dev(dev, dev_opp); @@ -643,24 +645,31 @@ void dev_pm_opp_remove(struct device *dev, unsigned long freq) } EXPORT_SYMBOL_GPL(dev_pm_opp_remove); -static struct dev_pm_opp *_allocate_opp(struct device *dev, - struct device_opp **dev_opp) +static struct dev_pm_opp * +_allocate_opp(struct device *dev, struct device_opp **dev_opp, int supply_count) { struct dev_pm_opp *opp; + size_t size = sizeof(*opp); + + /* Memory for the OPP and its supplies is allocated together */ + size += supply_count * sizeof(*opp->supplies); /* allocate new OPP node */ - opp = kzalloc(sizeof(*opp), GFP_KERNEL); + opp = kzalloc(size, GFP_KERNEL); if (!opp) return NULL; INIT_LIST_HEAD(&opp->node); - *dev_opp = _add_device_opp(dev); + *dev_opp = _add_device_opp(dev, supply_count); if (!*dev_opp) { kfree(opp); return NULL; } + /* Supplies points to the memory right after the opp */ + opp->supplies = (struct opp_supply *)(opp + 1); + return opp; } @@ -689,10 +698,12 @@ static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, /* Duplicate OPPs */ dev_warn(dev, "%s: duplicate OPPs detected. Existing: freq: %lu, volt: %lu, enabled: %d. New: freq: %lu, volt: %lu, enabled: %d\n", - __func__, opp->rate, opp->u_volt, opp->available, - new_opp->rate, new_opp->u_volt, new_opp->available); + __func__, opp->rate, opp->supplies[0].u_volt, + opp->available, new_opp->rate, + new_opp->supplies[0].u_volt, new_opp->available); - return opp->available && new_opp->u_volt == opp->u_volt ? + return opp->available && + opp->supplies[0].u_volt == new_opp->supplies[0].u_volt ? 0 : -EEXIST; } @@ -739,7 +750,7 @@ static int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt, /* Hold our list modification lock here */ mutex_lock(&dev_opp_list_lock); - new_opp = _allocate_opp(dev, &dev_opp); + new_opp = _allocate_opp(dev, &dev_opp, 1); if (!new_opp) { ret = -ENOMEM; goto unlock; @@ -747,7 +758,7 @@ static int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt, /* populate the opp table */ new_opp->rate = freq; - new_opp->u_volt = u_volt; + new_opp->supplies[0].u_volt = u_volt; new_opp->available = true; new_opp->dynamic = dynamic; @@ -774,6 +785,7 @@ static int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt, /* TODO: Support multiple regulators */ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev) { + struct opp_supply *supply = &opp->supplies[0]; u32 microvolt[3] = {0}; u32 val; int count, ret; @@ -804,12 +816,12 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev) return -EINVAL; } - opp->u_volt = microvolt[0]; - opp->u_volt_min = microvolt[1]; - opp->u_volt_max = microvolt[2]; + supply->u_volt = microvolt[0]; + supply->u_volt_min = microvolt[1]; + supply->u_volt_max = microvolt[2]; if (!of_property_read_u32(opp->np, "opp-microamp", &val)) - opp->u_amp = val; + supply->u_amp = val; return 0; } @@ -818,6 +830,7 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev) * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings) * @dev: device for which we do this operation * @np: device node + * @supply_count: Number of supplies available for each OPP * * This function adds an opp definition to the opp list and returns status. The * opp can be controlled using dev_pm_opp_enable/disable functions and may be @@ -837,10 +850,12 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev) * -ENOMEM Memory allocation failure * -EINVAL Failed parsing the OPP node */ -static int _opp_add_static_v2(struct device *dev, struct device_node *np) +static int _opp_add_static_v2(struct device *dev, struct device_node *np, + int supply_count) { struct device_opp *dev_opp; struct dev_pm_opp *new_opp; + struct opp_supply *supply; u64 rate; u32 val; int ret; @@ -848,7 +863,7 @@ static int _opp_add_static_v2(struct device *dev, struct device_node *np) /* Hold our list modification lock here */ mutex_lock(&dev_opp_list_lock); - new_opp = _allocate_opp(dev, &dev_opp); + new_opp = _allocate_opp(dev, &dev_opp, supply_count); if (!new_opp) { ret = -ENOMEM; goto unlock; @@ -898,9 +913,10 @@ static int _opp_add_static_v2(struct device *dev, struct device_node *np) mutex_unlock(&dev_opp_list_lock); + supply = &new_opp->supplies[0]; pr_debug("%s: turbo:%d rate:%lu uv:%lu uvmin:%lu uvmax:%lu latency:%lu\n", - __func__, new_opp->turbo, new_opp->rate, new_opp->u_volt, - new_opp->u_volt_min, new_opp->u_volt_max, + __func__, new_opp->turbo, new_opp->rate, supply->u_volt, + supply->u_volt_min, supply->u_volt_max, new_opp->clock_latency_ns); /* @@ -1187,7 +1203,8 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) for_each_available_child_of_node(opp_np, np) { count++; - ret = _opp_add_static_v2(dev, np); + /* Todo: Add support for multiple supplies */ + ret = _opp_add_static_v2(dev, np, 1); if (ret) { dev_err(dev, "%s: Failed to add OPP, %d\n", __func__, ret); diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h index dcb38f78dae4..bdc2bbab1444 100644 --- a/drivers/base/power/opp/opp.h +++ b/drivers/base/power/opp/opp.h @@ -38,6 +38,22 @@ */ /** + * struct opp_supply - Per power-supply structure + * @u_volt: Target voltage in microvolts corresponding to this OPP + * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP + * @u_volt_max: Maximum voltage in microvolts corresponding to this OPP + * @u_amp: Maximum current drawn by the device in microamperes + * + * This structure stores the OPP power-supply information for a given device. + */ +struct opp_supply { + unsigned long u_volt; + unsigned long u_volt_min; + unsigned long u_volt_max; + unsigned long u_amp; +}; + +/** * struct dev_pm_opp - Generic OPP description structure * @node: opp list node. The nodes are maintained throughout the lifetime * of boot. It is expected only an optimal set of OPPs are @@ -51,10 +67,7 @@ * @available: true/false - marks if this OPP as available or not * @turbo: true if turbo (boost) OPP * @rate: Frequency in hertz - * @u_volt: Target voltage in microvolts corresponding to this OPP - * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP - * @u_volt_max: Maximum voltage in microvolts corresponding to this OPP - * @u_amp: Maximum current drawn by the device in microamperes + * @supplies: Array of power-supplies for the device. * @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's * frequency from any other OPP's frequency. * @dev_opp: points back to the device_opp struct this opp belongs to @@ -71,10 +84,8 @@ struct dev_pm_opp { bool turbo; unsigned long rate; - unsigned long u_volt; - unsigned long u_volt_min; - unsigned long u_volt_max; - unsigned long u_amp; + struct opp_supply *supplies; + unsigned long clock_latency_ns; struct device_opp *dev_opp; @@ -110,6 +121,7 @@ struct device_list_opp { * @dev_list: list of devices that share these OPPs * @opp_list: list of opps * @np: struct device_node pointer for opp's DT node. + * @supply_count: Number of power-supplies * @shared_opp: OPP is shared between multiple devices. * * This is an internal data structure maintaining the link to opps attached to @@ -130,6 +142,7 @@ struct device_opp { struct device_node *np; unsigned long clock_latency_ns_max; + unsigned int supply_count; bool shared_opp; struct dev_pm_opp *suspend_opp; };