windfarm_pid.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #ifndef _WINDFARM_PID_H
  3. #define _WINDFARM_PID_H
  4. /*
  5. * Windfarm PowerMac thermal control. Generic PID helpers
  6. *
  7. * (c) Copyright 2005 Benjamin Herrenschmidt, IBM Corp.
  8. * <benh@kernel.crashing.org>
  9. *
  10. * This is a pair of generic PID helpers that can be used by
  11. * control loops. One is the basic PID implementation, the
  12. * other one is more specifically tailored to the loops used
  13. * for CPU control with 2 input sample types (temp and power)
  14. */
  15. /*
  16. * *** Simple PID ***
  17. */
  18. #define WF_PID_MAX_HISTORY 32
  19. /* This parameter array is passed to the PID algorithm. Currently,
  20. * we don't support changing parameters on the fly as it's not needed
  21. * but could be implemented (with necessary adjustment of the history
  22. * buffer
  23. */
  24. struct wf_pid_param {
  25. int interval; /* Interval between samples in seconds */
  26. int history_len; /* Size of history buffer */
  27. int additive; /* 1: target relative to previous value */
  28. s32 gd, gp, gr; /* PID gains */
  29. s32 itarget; /* PID input target */
  30. s32 min,max; /* min and max target values */
  31. };
  32. struct wf_pid_state {
  33. int first; /* first run of the loop */
  34. int index; /* index of current sample */
  35. s32 target; /* current target value */
  36. s32 samples[WF_PID_MAX_HISTORY]; /* samples history buffer */
  37. s32 errors[WF_PID_MAX_HISTORY]; /* error history buffer */
  38. struct wf_pid_param param;
  39. };
  40. extern void wf_pid_init(struct wf_pid_state *st, struct wf_pid_param *param);
  41. extern s32 wf_pid_run(struct wf_pid_state *st, s32 sample);
  42. /*
  43. * *** CPU PID ***
  44. */
  45. #define WF_CPU_PID_MAX_HISTORY 32
  46. /* This parameter array is passed to the CPU PID algorithm. Currently,
  47. * we don't support changing parameters on the fly as it's not needed
  48. * but could be implemented (with necessary adjustment of the history
  49. * buffer
  50. */
  51. struct wf_cpu_pid_param {
  52. int interval; /* Interval between samples in seconds */
  53. int history_len; /* Size of history buffer */
  54. s32 gd, gp, gr; /* PID gains */
  55. s32 pmaxadj; /* PID max power adjust */
  56. s32 ttarget; /* PID input target */
  57. s32 tmax; /* PID input max */
  58. s32 min,max; /* min and max target values */
  59. };
  60. struct wf_cpu_pid_state {
  61. int first; /* first run of the loop */
  62. int index; /* index of current power */
  63. int tindex; /* index of current temp */
  64. s32 target; /* current target value */
  65. s32 last_delta; /* last Tactual - Ttarget */
  66. s32 powers[WF_PID_MAX_HISTORY]; /* power history buffer */
  67. s32 errors[WF_PID_MAX_HISTORY]; /* error history buffer */
  68. s32 temps[2]; /* temp. history buffer */
  69. struct wf_cpu_pid_param param;
  70. };
  71. extern void wf_cpu_pid_init(struct wf_cpu_pid_state *st,
  72. struct wf_cpu_pid_param *param);
  73. extern s32 wf_cpu_pid_run(struct wf_cpu_pid_state *st, s32 power, s32 temp);
  74. #endif /* _WINDFARM_PID_H */