blob: 002a7d67e39d469b421f3f5f2d6413ea2400340b [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
MyungJoo Hama3c98b82011-10-02 00:19:15 +02002/*
3 * governor.h - internal header for devfreq governors.
4 *
5 * Copyright (C) 2011 Samsung Electronics
6 * MyungJoo Ham <myungjoo.ham@samsung.com>
7 *
MyungJoo Hama3c98b82011-10-02 00:19:15 +02008 * This header is for devfreq governors in drivers/devfreq/
9 */
10
11#ifndef _GOVERNOR_H
12#define _GOVERNOR_H
13
14#include <linux/devfreq.h>
15
Chanwoo Choi96ffcdf2020-10-20 15:12:12 +090016#define DEVFREQ_NAME_LEN 16
17
MyungJoo Hama3c98b82011-10-02 00:19:15 +020018#define to_devfreq(DEV) container_of((DEV), struct devfreq, dev)
19
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +020020/* Devfreq events */
21#define DEVFREQ_GOV_START 0x1
22#define DEVFREQ_GOV_STOP 0x2
Chanwoo Choi3a1ec2e2020-01-29 13:24:18 +090023#define DEVFREQ_GOV_UPDATE_INTERVAL 0x3
Rajagopal Venkat206c30c2012-10-26 01:50:18 +020024#define DEVFREQ_GOV_SUSPEND 0x4
25#define DEVFREQ_GOV_RESUME 0x5
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +020026
Matthias Kaehlcke6ff66e22018-08-03 13:05:10 -070027#define DEVFREQ_MIN_FREQ 0
28#define DEVFREQ_MAX_FREQ ULONG_MAX
29
Chanwoo Choi0dd25a02020-10-05 14:48:01 +090030/*
31 * Definition of the governor feature flags
32 * - DEVFREQ_GOV_FLAG_IMMUTABLE
33 * : This governor is never changeable to other governors.
34 * - DEVFREQ_GOV_FLAG_IRQ_DRIVEN
35 * : The devfreq won't schedule the work for this governor.
36 */
37#define DEVFREQ_GOV_FLAG_IMMUTABLE BIT(0)
38#define DEVFREQ_GOV_FLAG_IRQ_DRIVEN BIT(1)
39
Chanwoo Choi5f1a9062020-07-03 17:20:27 +090040/*
41 * Definition of governor attribute flags except for common sysfs attributes
42 * - DEVFREQ_GOV_ATTR_POLLING_INTERVAL
Lukasz Lubaf40d8122021-01-04 13:59:12 +000043 * : Indicate polling_interval sysfs attribute
Chanwoo Choi5f1a9062020-07-03 17:20:27 +090044 * - DEVFREQ_GOV_ATTR_TIMER
45 * : Indicate timer sysfs attribute
46 */
47#define DEVFREQ_GOV_ATTR_POLLING_INTERVAL BIT(0)
48#define DEVFREQ_GOV_ATTR_TIMER BIT(1)
49
Chanwoo Choi3ea6b702017-04-06 13:19:35 +090050/**
51 * struct devfreq_governor - Devfreq policy governor
52 * @node: list node - contains registered devfreq governors
53 * @name: Governor's name
Chanwoo Choi5f1a9062020-07-03 17:20:27 +090054 * @attrs: Governor's sysfs attribute flags
Chanwoo Choi0dd25a02020-10-05 14:48:01 +090055 * @flags: Governor's feature flags
Chanwoo Choi3ea6b702017-04-06 13:19:35 +090056 * @get_target_freq: Returns desired operating frequency for the device.
57 * Basically, get_target_freq will run
58 * devfreq_dev_profile.get_dev_status() to get the
59 * status of the device (load = busy_time / total_time).
Chanwoo Choi3ea6b702017-04-06 13:19:35 +090060 * @event_handler: Callback for devfreq core framework to notify events
61 * to governors. Events include per device governor
62 * init and exit, opp changes out of devfreq, suspend
63 * and resume of per device devfreq during device idle.
64 *
65 * Note that the callbacks are called with devfreq->lock locked by devfreq.
66 */
67struct devfreq_governor {
68 struct list_head node;
69
70 const char name[DEVFREQ_NAME_LEN];
Chanwoo Choi5f1a9062020-07-03 17:20:27 +090071 const u64 attrs;
Chanwoo Choi0dd25a02020-10-05 14:48:01 +090072 const u64 flags;
Chanwoo Choi3ea6b702017-04-06 13:19:35 +090073 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
74 int (*event_handler)(struct devfreq *devfreq,
75 unsigned int event, void *data);
76};
77
Chanwoo Choi6d743492020-01-08 19:35:49 +090078void devfreq_monitor_start(struct devfreq *devfreq);
79void devfreq_monitor_stop(struct devfreq *devfreq);
80void devfreq_monitor_suspend(struct devfreq *devfreq);
81void devfreq_monitor_resume(struct devfreq *devfreq);
Chanwoo Choi3a1ec2e2020-01-29 13:24:18 +090082void devfreq_update_interval(struct devfreq *devfreq, unsigned int *delay);
Nishanth Menon3aa173b2012-10-29 15:01:43 -050083
Chanwoo Choi6d743492020-01-08 19:35:49 +090084int devfreq_add_governor(struct devfreq_governor *governor);
85int devfreq_remove_governor(struct devfreq_governor *governor);
Nishanth Menon3aa173b2012-10-29 15:01:43 -050086
Dmitry Osipenko1cc55202021-09-20 20:22:47 +030087int devm_devfreq_add_governor(struct device *dev,
88 struct devfreq_governor *governor);
89
Chanwoo Choi6d743492020-01-08 19:35:49 +090090int devfreq_update_status(struct devfreq *devfreq, unsigned long freq);
Chanwoo Choib4365422020-10-07 22:02:39 +090091int devfreq_update_target(struct devfreq *devfreq, unsigned long freq);
Chanwoo Choi30582c22017-01-31 15:38:17 +090092
Chanwoo Choif75b0af2017-08-24 10:42:50 +090093static inline int devfreq_update_stats(struct devfreq *df)
94{
Dong Aishengb19e1342021-03-09 20:58:38 +080095 if (!df->profile->get_dev_status)
96 return -EINVAL;
97
Chanwoo Choif75b0af2017-08-24 10:42:50 +090098 return df->profile->get_dev_status(df->dev.parent, &df->last_status);
99}
MyungJoo Hama3c98b82011-10-02 00:19:15 +0200100#endif /* _GOVERNOR_H */