Path: blob/master/drivers/macintosh/windfarm_pid.h
15111 views
/*1* Windfarm PowerMac thermal control. Generic PID helpers2*3* (c) Copyright 2005 Benjamin Herrenschmidt, IBM Corp.4* <[email protected]>5*6* Released under the term of the GNU GPL v2.7*8* This is a pair of generic PID helpers that can be used by9* control loops. One is the basic PID implementation, the10* other one is more specifically tailored to the loops used11* for CPU control with 2 input sample types (temp and power)12*/1314/*15* *** Simple PID ***16*/1718#define WF_PID_MAX_HISTORY 321920/* This parameter array is passed to the PID algorithm. Currently,21* we don't support changing parameters on the fly as it's not needed22* but could be implemented (with necessary adjustment of the history23* buffer24*/25struct wf_pid_param {26int interval; /* Interval between samples in seconds */27int history_len; /* Size of history buffer */28int additive; /* 1: target relative to previous value */29s32 gd, gp, gr; /* PID gains */30s32 itarget; /* PID input target */31s32 min,max; /* min and max target values */32};3334struct wf_pid_state {35int first; /* first run of the loop */36int index; /* index of current sample */37s32 target; /* current target value */38s32 samples[WF_PID_MAX_HISTORY]; /* samples history buffer */39s32 errors[WF_PID_MAX_HISTORY]; /* error history buffer */4041struct wf_pid_param param;42};4344extern void wf_pid_init(struct wf_pid_state *st, struct wf_pid_param *param);45extern s32 wf_pid_run(struct wf_pid_state *st, s32 sample);464748/*49* *** CPU PID ***50*/5152#define WF_CPU_PID_MAX_HISTORY 325354/* This parameter array is passed to the CPU PID algorithm. Currently,55* we don't support changing parameters on the fly as it's not needed56* but could be implemented (with necessary adjustment of the history57* buffer58*/59struct wf_cpu_pid_param {60int interval; /* Interval between samples in seconds */61int history_len; /* Size of history buffer */62s32 gd, gp, gr; /* PID gains */63s32 pmaxadj; /* PID max power adjust */64s32 ttarget; /* PID input target */65s32 tmax; /* PID input max */66s32 min,max; /* min and max target values */67};6869struct wf_cpu_pid_state {70int first; /* first run of the loop */71int index; /* index of current power */72int tindex; /* index of current temp */73s32 target; /* current target value */74s32 last_delta; /* last Tactual - Ttarget */75s32 powers[WF_PID_MAX_HISTORY]; /* power history buffer */76s32 errors[WF_PID_MAX_HISTORY]; /* error history buffer */77s32 temps[2]; /* temp. history buffer */7879struct wf_cpu_pid_param param;80};8182extern void wf_cpu_pid_init(struct wf_cpu_pid_state *st,83struct wf_cpu_pid_param *param);84extern s32 wf_cpu_pid_run(struct wf_cpu_pid_state *st, s32 power, s32 temp);858687