/* SPDX-License-Identifier: GPL-2.0-only */1/*2* governor.h - internal header for devfreq governors.3*4* Copyright (C) 2011 Samsung Electronics5* MyungJoo Ham <[email protected]>6*7* This header is for devfreq governors in drivers/devfreq/8*/910#ifndef _GOVERNOR_H11#define _GOVERNOR_H1213#include <linux/devfreq.h>1415#define DEVFREQ_NAME_LEN 161617#define to_devfreq(DEV) container_of((DEV), struct devfreq, dev)1819/* Devfreq events */20#define DEVFREQ_GOV_START 0x121#define DEVFREQ_GOV_STOP 0x222#define DEVFREQ_GOV_UPDATE_INTERVAL 0x323#define DEVFREQ_GOV_SUSPEND 0x424#define DEVFREQ_GOV_RESUME 0x52526#define DEVFREQ_MIN_FREQ 027#define DEVFREQ_MAX_FREQ ULONG_MAX2829/*30* Definition of the governor feature flags31* - DEVFREQ_GOV_FLAG_IMMUTABLE32* : This governor is never changeable to other governors.33* - DEVFREQ_GOV_FLAG_IRQ_DRIVEN34* : The devfreq won't schedule the work for this governor.35*/36#define DEVFREQ_GOV_FLAG_IMMUTABLE BIT(0)37#define DEVFREQ_GOV_FLAG_IRQ_DRIVEN BIT(1)3839/*40* Definition of governor attribute flags except for common sysfs attributes41* - DEVFREQ_GOV_ATTR_POLLING_INTERVAL42* : Indicate polling_interval sysfs attribute43* - DEVFREQ_GOV_ATTR_TIMER44* : Indicate timer sysfs attribute45*/46#define DEVFREQ_GOV_ATTR_POLLING_INTERVAL BIT(0)47#define DEVFREQ_GOV_ATTR_TIMER BIT(1)4849/**50* struct devfreq_cpu_data - Hold the per-cpu data51* @node: list node52* @dev: reference to cpu device.53* @first_cpu: the cpumask of the first cpu of a policy.54* @opp_table: reference to cpu opp table.55* @cur_freq: the current frequency of the cpu.56* @min_freq: the min frequency of the cpu.57* @max_freq: the max frequency of the cpu.58*59* This structure stores the required cpu_data of a cpu.60* This is auto-populated by the governor.61*/62struct devfreq_cpu_data {63struct list_head node;6465struct device *dev;66unsigned int first_cpu;6768struct opp_table *opp_table;69unsigned int cur_freq;70unsigned int min_freq;71unsigned int max_freq;72};7374/**75* struct devfreq_governor - Devfreq policy governor76* @node: list node - contains registered devfreq governors77* @name: Governor's name78* @attrs: Governor's sysfs attribute flags79* @flags: Governor's feature flags80* @get_target_freq: Returns desired operating frequency for the device.81* Basically, get_target_freq will run82* devfreq_dev_profile.get_dev_status() to get the83* status of the device (load = busy_time / total_time).84* @event_handler: Callback for devfreq core framework to notify events85* to governors. Events include per device governor86* init and exit, opp changes out of devfreq, suspend87* and resume of per device devfreq during device idle.88*89* Note that the callbacks are called with devfreq->lock locked by devfreq.90*/91struct devfreq_governor {92struct list_head node;9394const char name[DEVFREQ_NAME_LEN];95const u64 attrs;96const u64 flags;97int (*get_target_freq)(struct devfreq *this, unsigned long *freq);98int (*event_handler)(struct devfreq *devfreq,99unsigned int event, void *data);100};101102void devfreq_monitor_start(struct devfreq *devfreq);103void devfreq_monitor_stop(struct devfreq *devfreq);104void devfreq_monitor_suspend(struct devfreq *devfreq);105void devfreq_monitor_resume(struct devfreq *devfreq);106void devfreq_update_interval(struct devfreq *devfreq, unsigned int *delay);107108int devfreq_add_governor(struct devfreq_governor *governor);109int devfreq_remove_governor(struct devfreq_governor *governor);110111int devm_devfreq_add_governor(struct device *dev,112struct devfreq_governor *governor);113114int devfreq_update_status(struct devfreq *devfreq, unsigned long freq);115int devfreq_update_target(struct devfreq *devfreq, unsigned long freq);116void devfreq_get_freq_range(struct devfreq *devfreq, unsigned long *min_freq,117unsigned long *max_freq);118119static inline int devfreq_update_stats(struct devfreq *df)120{121if (!df->profile->get_dev_status)122return -EINVAL;123124return df->profile->get_dev_status(df->dev.parent, &df->last_status);125}126#endif /* _GOVERNOR_H */127128129