From patchwork Mon May 30 21:27:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9142559 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 DDFFF60757 for ; Mon, 30 May 2016 21:37:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFF4527F17 for ; Mon, 30 May 2016 21:37:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4EBF2819C; Mon, 30 May 2016 21:37:46 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 175ED27F17 for ; Mon, 30 May 2016 21:37:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162353AbcE3Vh1 (ORCPT ); Mon, 30 May 2016 17:37:27 -0400 Received: from mail-pa0-f68.google.com ([209.85.220.68]:33850 "EHLO mail-pa0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423271AbcE3V2g (ORCPT ); Mon, 30 May 2016 17:28:36 -0400 Received: by mail-pa0-f68.google.com with SMTP id x1so6059460pav.1; Mon, 30 May 2016 14:28:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yZapKsqJyGvCSVwZsaoLqfLtfw4bQhmjrDX9ybN9SEI=; b=R/zrACnPg36Ek2vh/8ZIowkCzpOVzCIRZpeYD6s+msCw3nWz3OkR8UptpW6/VYDXUd HdQ9DJcpr2Ji2m3Yv7WBR81D/k4KVkJadq3IkWatJdZrqq6wjA/7Rh8EYBO+dM56Hvgn Px92Xmqve/A2Rv+1jFsecSzNO06KAeBeAvm9FaTHUIQ5iONiRJ5Rvsd7fLWDcZ8QtqVq MQEpGUyMlVYppSQWwM7Fn8DbD5DizI7e+m0He4l8hCA/fSe/Z6zWP+hbv6Q4h+SllBCf lBtoEXEwO2Wn6bEMJu7TpvznnnHQxEeaLefHuC42oGC2sMwPj+M1rhYCwjJ/vkRv/TIU +Rog== 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; bh=yZapKsqJyGvCSVwZsaoLqfLtfw4bQhmjrDX9ybN9SEI=; b=CCvqqujeKUlXLecU8NWFJid+ecBbDc67xmcugPdQgsyhYOnY+tEl4Q8shkCKS6SJ/w o1w1sLQUX6Z2Supde2Vp2/Z0yQ0HFuweig29ptUwwv1QhVDux2CCrdr0rP83RGV+7d6T kNO07mmyUJtcZj+w2/CTwY3vxRekvb+5N61Oa1Z97MgoN/Wwx2UHvIqR1jVUg45In9dm 0UIQRajpDKTp9Pe5I1fYsVyqAgkYZ7/KsgT2xxqwBGqabgKuwrsZkOD5LlVK2Wm60n5R 38o1uaxxzPDlCN6susWWy4vFBm6sDIoqjiqGQxKN9Wul8LsNGegYqvWGY+dlhYeAO0Vr k/4g== X-Gm-Message-State: ALyK8tI8daaefBfNUv1f+3iajeYT04aW+aHJ2CroXoP8LciSQReSHpLnnoutBmplk4fL+Q== X-Received: by 10.66.138.16 with SMTP id qm16mr49909044pab.28.1464643710820; Mon, 30 May 2016 14:28:30 -0700 (PDT) Received: from localhost ([2601:b00:c501:3660:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id p187sm35092822pfb.3.2016.05.30.14.28.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 14:28:30 -0700 (PDT) From: Eduardo Valentin To: Rui Zhang Cc: Linux PM , LKML , Eduardo Valentin Subject: [PATCHv2 09/40] thermal: core: move power actor code out of sysfs I/F section Date: Mon, 30 May 2016 14:27:28 -0700 Message-Id: <1464643679-2733-10-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464643679-2733-1-git-send-email-edubezval@gmail.com> References: <1464643679-2733-1-git-send-email-edubezval@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Simply reorganize code to keep only functions of sysfs interface of thermal zone device together. Therefore, move the power actor code out of the sysfs I/F section. Cc: Zhang Rui Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_core.c | 162 ++++++++++++++++++++--------------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 12427cc..d6595b1 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -582,6 +582,87 @@ static void thermal_zone_device_check(struct work_struct *work) thermal_zone_device_update(tz); } +/** + * power_actor_get_max_power() - get the maximum power that a cdev can consume + * @cdev: pointer to &thermal_cooling_device + * @tz: a valid thermal zone device pointer + * @max_power: pointer in which to store the maximum power + * + * Calculate the maximum power consumption in milliwats that the + * cooling device can currently consume and store it in @max_power. + * + * Return: 0 on success, -EINVAL if @cdev doesn't support the + * power_actor API or -E* on other error. + */ +int power_actor_get_max_power(struct thermal_cooling_device *cdev, + struct thermal_zone_device *tz, u32 *max_power) +{ + if (!cdev_is_power_actor(cdev)) + return -EINVAL; + + return cdev->ops->state2power(cdev, tz, 0, max_power); +} + +/** + * power_actor_get_min_power() - get the mainimum power that a cdev can consume + * @cdev: pointer to &thermal_cooling_device + * @tz: a valid thermal zone device pointer + * @min_power: pointer in which to store the minimum power + * + * Calculate the minimum power consumption in milliwatts that the + * cooling device can currently consume and store it in @min_power. + * + * Return: 0 on success, -EINVAL if @cdev doesn't support the + * power_actor API or -E* on other error. + */ +int power_actor_get_min_power(struct thermal_cooling_device *cdev, + struct thermal_zone_device *tz, u32 *min_power) +{ + unsigned long max_state; + int ret; + + if (!cdev_is_power_actor(cdev)) + return -EINVAL; + + ret = cdev->ops->get_max_state(cdev, &max_state); + if (ret) + return ret; + + return cdev->ops->state2power(cdev, tz, max_state, min_power); +} + +/** + * power_actor_set_power() - limit the maximum power a cooling device consumes + * @cdev: pointer to &thermal_cooling_device + * @instance: thermal instance to update + * @power: the power in milliwatts + * + * Set the cooling device to consume at most @power milliwatts. The limit is + * expected to be a cap at the maximum power consumption. + * + * Return: 0 on success, -EINVAL if the cooling device does not + * implement the power actor API or -E* for other failures. + */ +int power_actor_set_power(struct thermal_cooling_device *cdev, + struct thermal_instance *instance, u32 power) +{ + unsigned long state; + int ret; + + if (!cdev_is_power_actor(cdev)) + return -EINVAL; + + ret = cdev->ops->power2state(cdev, instance->tz, power, &state); + if (ret) + return ret; + + instance->target = state; + cdev->updated = false; + thermal_cdev_update(cdev); + + return 0; +} + /* sys I/F for thermal zone */ #define to_thermal_zone(_dev) \ @@ -1092,87 +1173,6 @@ static const struct attribute_group *thermal_zone_attribute_groups[] = { NULL }; -/** - * power_actor_get_max_power() - get the maximum power that a cdev can consume - * @cdev: pointer to &thermal_cooling_device - * @tz: a valid thermal zone device pointer - * @max_power: pointer in which to store the maximum power - * - * Calculate the maximum power consumption in milliwats that the - * cooling device can currently consume and store it in @max_power. - * - * Return: 0 on success, -EINVAL if @cdev doesn't support the - * power_actor API or -E* on other error. - */ -int power_actor_get_max_power(struct thermal_cooling_device *cdev, - struct thermal_zone_device *tz, u32 *max_power) -{ - if (!cdev_is_power_actor(cdev)) - return -EINVAL; - - return cdev->ops->state2power(cdev, tz, 0, max_power); -} - -/** - * power_actor_get_min_power() - get the mainimum power that a cdev can consume - * @cdev: pointer to &thermal_cooling_device - * @tz: a valid thermal zone device pointer - * @min_power: pointer in which to store the minimum power - * - * Calculate the minimum power consumption in milliwatts that the - * cooling device can currently consume and store it in @min_power. - * - * Return: 0 on success, -EINVAL if @cdev doesn't support the - * power_actor API or -E* on other error. - */ -int power_actor_get_min_power(struct thermal_cooling_device *cdev, - struct thermal_zone_device *tz, u32 *min_power) -{ - unsigned long max_state; - int ret; - - if (!cdev_is_power_actor(cdev)) - return -EINVAL; - - ret = cdev->ops->get_max_state(cdev, &max_state); - if (ret) - return ret; - - return cdev->ops->state2power(cdev, tz, max_state, min_power); -} - -/** - * power_actor_set_power() - limit the maximum power a cooling device consumes - * @cdev: pointer to &thermal_cooling_device - * @instance: thermal instance to update - * @power: the power in milliwatts - * - * Set the cooling device to consume at most @power milliwatts. The limit is - * expected to be a cap at the maximum power consumption. - * - * Return: 0 on success, -EINVAL if the cooling device does not - * implement the power actor API or -E* for other failures. - */ -int power_actor_set_power(struct thermal_cooling_device *cdev, - struct thermal_instance *instance, u32 power) -{ - unsigned long state; - int ret; - - if (!cdev_is_power_actor(cdev)) - return -EINVAL; - - ret = cdev->ops->power2state(cdev, instance->tz, power, &state); - if (ret) - return ret; - - instance->target = state; - cdev->updated = false; - thermal_cdev_update(cdev); - - return 0; -} - /* sys I/F for cooling device */ #define to_cooling_device(_dev) \ container_of(_dev, struct thermal_cooling_device, device)