From patchwork Wed Aug 24 08:22:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: MyungJoo Ham X-Patchwork-Id: 1091532 Received: from smtp1.linux-foundation.org (smtp1.linux-foundation.org [140.211.169.13]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7O8ZHDn006464 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Wed, 24 Aug 2011 08:35:38 GMT Received: from daredevil.linux-foundation.org (localhost [127.0.0.1]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p7O8X97S011253; Wed, 24 Aug 2011 01:33:10 -0700 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p7O8MF11009791 for ; Wed, 24 Aug 2011 01:23:35 -0700 Received: from epcpsbgm2.samsung.com (mailout3.samsung.com [203.254.224.33]) by mailout3.samsung.com (Oracle Communications Messaging Exchange Server 7u4-19.01 64bit (built Sep 7 2010)) with ESMTP id <0LQF00JLCB92BK70@mailout3.samsung.com> for linux-pm@lists.linux-foundation.org; Wed, 24 Aug 2011 17:22:14 +0900 (KST) X-AuditID: cbfee61b-b7b7fae000005864-c2-4e54b4b6789d Received: from epmmp1 ( [203.254.227.16]) by epcpsbgm2.samsung.com (MMPCPMTA) with SMTP id BA.E2.22628.6B4B45E4; Wed, 24 Aug 2011 17:22:14 +0900 (KST) Received: from TNRNDGASPAPP1.tn.corp.samsungelectronics.net ([165.213.149.150]) by mmp1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0LQF00G5BB927D@mmp1.samsung.com> for linux-pm@lists.linux-foundation.org; Wed, 24 Aug 2011 17:22:14 +0900 (KST) Received: from localhost.localdomain ([165.213.219.116]) by TNRNDGASPAPP1.tn.corp.samsungelectronics.net with Microsoft SMTPSVC(6.0.3790.4675); Wed, 24 Aug 2011 17:22:53 +0900 Date: Wed, 24 Aug 2011 17:22:10 +0900 From: MyungJoo Ham In-reply-to: <1314174131-14194-1-git-send-email-myungjoo.ham@samsung.com> To: linux-pm@lists.linux-foundation.org Message-id: <1314174131-14194-5-git-send-email-myungjoo.ham@samsung.com> X-Mailer: git-send-email 1.7.4.1 References: <1314086044-24659-1-git-send-email-myungjoo.ham@samsung.com> <1314174131-14194-1-git-send-email-myungjoo.ham@samsung.com> X-OriginalArrivalTime: 24 Aug 2011 08:22:53.0283 (UTC) FILETIME=[04F59B30:01CC6237] X-Brightmail-Tracker: AAAAAA== Received-SPF: pass (localhost is always allowed.) X-Spam-Status: No, hits=-12.028 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SUBJECT_BRACKETED, SAMSUNG_WEBMAIL_OSDL X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.21 Cc: Len Brown , Greg Kroah-Hartman , Kyungmin Park , Thomas Gleixner Subject: [linux-pm] [PATCH v8 4/5] PM / DEVFREQ: add internal interfaces for governors X-BeenThere: linux-pm@lists.linux-foundation.org X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux power management List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-pm-bounces@lists.linux-foundation.org Errors-To: linux-pm-bounces@lists.linux-foundation.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 24 Aug 2011 08:35:38 +0000 (UTC) - get_devfreq(): governors may convert struct dev -> struct devfreq - update_devfreq(): governors may notify DEVFREQ core to reevaluate frequencies. - Governors may have .init and .exit callbacks In order to use the internal interface, get_devfreq() and update_devfreq(), governor should include "governor.h" Signed-off-by: MyungJoo Ham Signed-off-by: Kyungmin Park --- drivers/devfreq/devfreq.c | 32 ++++++++++++++++++++++++-------- drivers/devfreq/governor.h | 20 ++++++++++++++++++++ include/linux/devfreq.h | 2 ++ 3 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 drivers/devfreq/governor.h diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 5bbece6..8de3b21 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -65,10 +65,10 @@ static struct devfreq *find_device_devfreq(struct device *dev) /** * get_devfreq() - find devfreq struct. a wrapped find_device_devfreq() - * with mutex protection. + * with mutex protection. exported for governors * @dev: device pointer used to lookup device devfreq. */ -static struct devfreq *get_devfreq(struct device *dev) +struct devfreq *get_devfreq(struct device *dev) { struct devfreq *ret; @@ -113,17 +113,15 @@ static int devfreq_do(struct devfreq *devfreq) } /** - * devfreq_update() - Notify that the device OPP has been changed. - * @dev: the device whose OPP has been changed. + * update_devfreq() - Notify that the device OPP or frequency requirement + * has been changed. This function is exported for governors. + * @devfreq: the devfreq instance. */ -static int devfreq_update(struct notifier_block *nb, unsigned long type, - void *devp) +int update_devfreq(struct devfreq *devfreq) { - struct devfreq *devfreq; int err = 0; mutex_lock(&devfreq_list_lock); - devfreq = container_of(nb, struct devfreq, nb); /* Reevaluate the proper frequency */ err = devfreq_do(devfreq); mutex_unlock(&devfreq_list_lock); @@ -131,6 +129,18 @@ static int devfreq_update(struct notifier_block *nb, unsigned long type, } /** + * devfreq_update() - Notify that the device OPP has been changed. + * @dev: the device whose OPP has been changed. + */ +static int devfreq_update(struct notifier_block *nb, unsigned long type, + void *devp) +{ + struct devfreq *devfreq = container_of(nb, struct devfreq, nb); + + return update_devfreq(devfreq); +} + +/** * devfreq_monitor() - Periodically run devfreq_do() * @work: the work struct used to run devfreq_monitor periodically. * @@ -254,6 +264,9 @@ int devfreq_add_device(struct device *dev, struct devfreq_dev_profile *profile, list_add(&devfreq->node, &devfreq_list); + if (governor->init) + governor->init(devfreq); + if (devfreq_wq && devfreq->next_polling && !polling) { polling = true; queue_delayed_work(devfreq_wq, &devfreq_work, @@ -295,6 +308,9 @@ int devfreq_remove_device(struct device *dev) sysfs_unmerge_group(&dev->kobj, &dev_attr_group); + if (devfreq->governor->exit) + devfreq->governor->exit(devfreq); + list_del(&devfreq->node); srcu_notifier_chain_unregister(nh, &devfreq->nb); kfree(devfreq); diff --git a/drivers/devfreq/governor.h b/drivers/devfreq/governor.h new file mode 100644 index 0000000..bb5d964 --- /dev/null +++ b/drivers/devfreq/governor.h @@ -0,0 +1,20 @@ +/* + * governor.h - internal header for governors. + * + * Copyright (C) 2011 Samsung Electronics + * MyungJoo Ham + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This header is for devfreq governors in drivers/devfreq/ + */ + +#ifndef _GOVERNOR_H +#define _GOVERNOR_H + +extern struct devfreq *get_devfreq(struct device *dev); +extern int update_devfreq(struct devfreq *devfreq); + +#endif /* _GOVERNOR_H */ diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index 8252238..fdc6916 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -46,6 +46,8 @@ struct devfreq_dev_profile { struct devfreq_governor { char name[DEVFREQ_NAME_LEN]; int (*get_target_freq)(struct devfreq *this, unsigned long *freq); + int (*init)(struct devfreq *this); + void (*exit)(struct devfreq *this); }; /**