windfarm_pid.h 2.7 KB

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