Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Windfarm PowerMac thermal control.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Control loops for machines with SMU and PPC970MP processors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2005 Paul Mackerras, IBM Corp. <paulus@samba.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/smu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "windfarm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "windfarm_pid.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define VERSION "0.2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #undef LOTSA_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define DBG(args...)	printk(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define DBG(args...)	do { } while(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #ifdef LOTSA_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define DBG_LOTS(args...)	printk(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define DBG_LOTS(args...)	do { } while(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) /* define this to force CPU overtemp to 60 degree, useful for testing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * the overtemp code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #undef HACKED_OVERTEMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) /* We currently only handle 2 chips, 4 cores... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define NR_CHIPS	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define NR_CORES	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define NR_CPU_FANS	3 * NR_CHIPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /* Controls and sensors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static struct wf_sensor *sens_cpu_temp[NR_CORES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static struct wf_sensor *sens_cpu_power[NR_CORES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static struct wf_sensor *hd_temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static struct wf_sensor *slots_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static struct wf_sensor *u4_temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static struct wf_control *cpu_fans[NR_CPU_FANS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static char *cpu_fan_names[NR_CPU_FANS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	"cpu-rear-fan-0",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	"cpu-rear-fan-1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	"cpu-front-fan-0",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	"cpu-front-fan-1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	"cpu-pump-0",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	"cpu-pump-1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static struct wf_control *cpufreq_clamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) /* Second pump isn't required (and isn't actually present) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #define CPU_FANS_REQD		(NR_CPU_FANS - 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define FIRST_PUMP		4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #define LAST_PUMP		5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) /* We keep a temperature history for average calculation of 180s */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #define CPU_TEMP_HIST_SIZE	180
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) /* Scale factor for fan speed, *100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static int cpu_fan_scale[NR_CPU_FANS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	97,		/* inlet fans run at 97% of exhaust fan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	97,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	100,		/* updated later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	100,		/* updated later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static struct wf_control *backside_fan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static struct wf_control *slots_fan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static struct wf_control *drive_bay_fan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) /* PID loop state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static struct wf_cpu_pid_state cpu_pid[NR_CORES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static u32 cpu_thist[CPU_TEMP_HIST_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static int cpu_thist_pt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static s64 cpu_thist_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static s32 cpu_all_tmax = 100 << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static int cpu_last_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static struct wf_pid_state backside_pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) static int backside_tick;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static struct wf_pid_state slots_pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static bool slots_started;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static struct wf_pid_state drive_bay_pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int drive_bay_tick;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int nr_cores;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int have_all_controls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int have_all_sensors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static bool started;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int failure_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define FAILURE_SENSOR		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define FAILURE_FAN		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define FAILURE_PERM		4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define FAILURE_LOW_OVERTEMP	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define FAILURE_HIGH_OVERTEMP	16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* Overtemp values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define LOW_OVER_AVERAGE	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define LOW_OVER_IMMEDIATE	(10 << 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define LOW_OVER_CLEAR		((-10) << 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define HIGH_OVER_IMMEDIATE	(14 << 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #define HIGH_OVER_AVERAGE	(10 << 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define HIGH_OVER_IMMEDIATE	(14 << 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* Implementation... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static int create_cpu_loop(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	int chip = cpu / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	int core = cpu & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	struct smu_sdbp_header *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct smu_sdbp_cpupiddata *piddata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct wf_cpu_pid_param pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct wf_control *main_fan = cpu_fans[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	s32 tmax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	int fmin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	/* Get FVT params to get Tmax; if not found, assume default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	hdr = smu_sat_get_sdb_partition(chip, 0xC4 + core, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (hdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		struct smu_sdbp_fvt *fvt = (struct smu_sdbp_fvt *)&hdr[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		tmax = fvt->maxtemp << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		tmax = 95 << 16;	/* default to 95 degrees C */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	/* We keep a global tmax for overtemp calculations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (tmax < cpu_all_tmax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		cpu_all_tmax = tmax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	kfree(hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	/* Get PID params from the appropriate SAT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	hdr = smu_sat_get_sdb_partition(chip, 0xC8 + core, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (hdr == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		printk(KERN_WARNING"windfarm: can't get CPU PID fan config\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	piddata = (struct smu_sdbp_cpupiddata *)&hdr[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	 * Darwin has a minimum fan speed of 1000 rpm for the 4-way and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 * 515 for the 2-way.  That appears to be overkill, so for now,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	 * impose a minimum of 750 or 515.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	fmin = (nr_cores > 2) ? 750 : 515;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	/* Initialize PID loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	pid.interval = 1;	/* seconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	pid.history_len = piddata->history_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	pid.gd = piddata->gd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	pid.gp = piddata->gp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	pid.gr = piddata->gr / piddata->history_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	pid.pmaxadj = (piddata->max_power << 16) - (piddata->power_adj << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	pid.ttarget = tmax - (piddata->target_temp_delta << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	pid.tmax = tmax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	pid.min = main_fan->ops->get_min(main_fan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	pid.max = main_fan->ops->get_max(main_fan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (pid.min < fmin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		pid.min = fmin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	wf_cpu_pid_init(&cpu_pid[cpu], &pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	kfree(hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static void cpu_max_all_fans(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	/* We max all CPU fans in case of a sensor error. We also do the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	 * cpufreq clamping now, even if it's supposedly done later by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	 * generic code anyway, we do it earlier here to react faster
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (cpufreq_clamp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		wf_control_set_max(cpufreq_clamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	for (i = 0; i < NR_CPU_FANS; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		if (cpu_fans[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			wf_control_set_max(cpu_fans[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int cpu_check_overtemp(s32 temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	int new_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	s32 t_avg, t_old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	/* First check for immediate overtemps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	if (temp >= (cpu_all_tmax + LOW_OVER_IMMEDIATE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		new_state |= FAILURE_LOW_OVERTEMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		if ((failure_state & FAILURE_LOW_OVERTEMP) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			printk(KERN_ERR "windfarm: Overtemp due to immediate CPU"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			       " temperature !\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (temp >= (cpu_all_tmax + HIGH_OVER_IMMEDIATE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		new_state |= FAILURE_HIGH_OVERTEMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		if ((failure_state & FAILURE_HIGH_OVERTEMP) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			printk(KERN_ERR "windfarm: Critical overtemp due to"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			       " immediate CPU temperature !\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	/* We calculate a history of max temperatures and use that for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	 * overtemp management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	t_old = cpu_thist[cpu_thist_pt];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	cpu_thist[cpu_thist_pt] = temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	cpu_thist_pt = (cpu_thist_pt + 1) % CPU_TEMP_HIST_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	cpu_thist_total -= t_old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	cpu_thist_total += temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	t_avg = cpu_thist_total / CPU_TEMP_HIST_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	DBG_LOTS("t_avg = %d.%03d (out: %d.%03d, in: %d.%03d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		 FIX32TOPRINT(t_avg), FIX32TOPRINT(t_old), FIX32TOPRINT(temp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	/* Now check for average overtemps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (t_avg >= (cpu_all_tmax + LOW_OVER_AVERAGE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		new_state |= FAILURE_LOW_OVERTEMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		if ((failure_state & FAILURE_LOW_OVERTEMP) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			printk(KERN_ERR "windfarm: Overtemp due to average CPU"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			       " temperature !\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	if (t_avg >= (cpu_all_tmax + HIGH_OVER_AVERAGE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		new_state |= FAILURE_HIGH_OVERTEMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		if ((failure_state & FAILURE_HIGH_OVERTEMP) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			printk(KERN_ERR "windfarm: Critical overtemp due to"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			       " average CPU temperature !\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	/* Now handle overtemp conditions. We don't currently use the windfarm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	 * overtemp handling core as it's not fully suited to the needs of those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	 * new machine. This will be fixed later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	if (new_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		/* High overtemp -> immediate shutdown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		if (new_state & FAILURE_HIGH_OVERTEMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			machine_power_off();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		if ((failure_state & new_state) != new_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 			cpu_max_all_fans();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		failure_state |= new_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	} else if ((failure_state & FAILURE_LOW_OVERTEMP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		   (temp < (cpu_all_tmax + LOW_OVER_CLEAR))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		printk(KERN_ERR "windfarm: Overtemp condition cleared !\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		failure_state &= ~FAILURE_LOW_OVERTEMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	return failure_state & (FAILURE_LOW_OVERTEMP | FAILURE_HIGH_OVERTEMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static void cpu_fans_tick(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	int err, cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	s32 greatest_delta = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	s32 temp, power, t_max = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	int i, t, target = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	struct wf_sensor *sr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	struct wf_control *ct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	struct wf_cpu_pid_state *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	DBG_LOTS(KERN_DEBUG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	for (cpu = 0; cpu < nr_cores; ++cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		/* Get CPU core temperature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		sr = sens_cpu_temp[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		err = sr->ops->get_value(sr, &temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			DBG("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			printk(KERN_WARNING "windfarm: CPU %d temperature "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			       "sensor error %d\n", cpu, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			failure_state |= FAILURE_SENSOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			cpu_max_all_fans();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		/* Keep track of highest temp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		t_max = max(t_max, temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		/* Get CPU power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		sr = sens_cpu_power[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		err = sr->ops->get_value(sr, &power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			DBG("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			printk(KERN_WARNING "windfarm: CPU %d power "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			       "sensor error %d\n", cpu, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			failure_state |= FAILURE_SENSOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			cpu_max_all_fans();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		/* Run PID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		sp = &cpu_pid[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		t = wf_cpu_pid_run(sp, power, temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		if (cpu == 0 || sp->last_delta > greatest_delta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			greatest_delta = sp->last_delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			target = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		DBG_LOTS("[%d] P=%d.%.3d T=%d.%.3d ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		    cpu, FIX32TOPRINT(power), FIX32TOPRINT(temp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	DBG_LOTS("fans = %d, t_max = %d.%03d\n", target, FIX32TOPRINT(t_max));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	/* Darwin limits decrease to 20 per iteration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	if (target < (cpu_last_target - 20))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		target = cpu_last_target - 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	cpu_last_target = target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	for (cpu = 0; cpu < nr_cores; ++cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		cpu_pid[cpu].target = target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	/* Handle possible overtemps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	if (cpu_check_overtemp(t_max))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	/* Set fans */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	for (i = 0; i < NR_CPU_FANS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		ct = cpu_fans[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		if (ct == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		err = ct->ops->set_value(ct, target * cpu_fan_scale[i] / 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			printk(KERN_WARNING "windfarm: fan %s reports "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			       "error %d\n", ct->name, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			failure_state |= FAILURE_FAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) /* Backside/U4 fan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static struct wf_pid_param backside_param = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	.interval	= 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	.history_len	= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	.gd		= 48 << 20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	.gp		= 5 << 20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	.gr		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	.itarget	= 64 << 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	.additive	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static void backside_fan_tick(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	s32 temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	int speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	if (!backside_fan || !u4_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (!backside_tick) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		/* first time; initialize things */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		printk(KERN_INFO "windfarm: Backside control loop started.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		backside_param.min = backside_fan->ops->get_min(backside_fan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		backside_param.max = backside_fan->ops->get_max(backside_fan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		wf_pid_init(&backside_pid, &backside_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		backside_tick = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	if (--backside_tick > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	backside_tick = backside_pid.param.interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	err = u4_temp->ops->get_value(u4_temp, &temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		printk(KERN_WARNING "windfarm: U4 temp sensor error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		       err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		failure_state |= FAILURE_SENSOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		wf_control_set_max(backside_fan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	speed = wf_pid_run(&backside_pid, temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	DBG_LOTS("backside PID temp=%d.%.3d speed=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		 FIX32TOPRINT(temp), speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	err = backside_fan->ops->set_value(backside_fan, speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		printk(KERN_WARNING "windfarm: backside fan error %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		failure_state |= FAILURE_FAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /* Drive bay fan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) static struct wf_pid_param drive_bay_prm = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	.interval	= 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	.history_len	= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	.gd		= 30 << 20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	.gp		= 5 << 20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	.gr		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	.itarget	= 40 << 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	.additive	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static void drive_bay_fan_tick(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	s32 temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	int speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	if (!drive_bay_fan || !hd_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	if (!drive_bay_tick) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		/* first time; initialize things */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		printk(KERN_INFO "windfarm: Drive bay control loop started.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		drive_bay_prm.min = drive_bay_fan->ops->get_min(drive_bay_fan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		drive_bay_prm.max = drive_bay_fan->ops->get_max(drive_bay_fan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		wf_pid_init(&drive_bay_pid, &drive_bay_prm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		drive_bay_tick = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	if (--drive_bay_tick > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	drive_bay_tick = drive_bay_pid.param.interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	err = hd_temp->ops->get_value(hd_temp, &temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		printk(KERN_WARNING "windfarm: drive bay temp sensor "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		       "error %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		failure_state |= FAILURE_SENSOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		wf_control_set_max(drive_bay_fan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	speed = wf_pid_run(&drive_bay_pid, temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	DBG_LOTS("drive_bay PID temp=%d.%.3d speed=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		 FIX32TOPRINT(temp), speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	err = drive_bay_fan->ops->set_value(drive_bay_fan, speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		printk(KERN_WARNING "windfarm: drive bay fan error %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		failure_state |= FAILURE_FAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) /* PCI slots area fan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) /* This makes the fan speed proportional to the power consumed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) static struct wf_pid_param slots_param = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	.interval	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	.history_len	= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	.gd		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	.gp		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	.gr		= 0x1277952,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	.itarget	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	.min		= 1560,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	.max		= 3510,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) static void slots_fan_tick(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	s32 power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	int speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	if (!slots_fan || !slots_power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	if (!slots_started) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		/* first time; initialize things */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		printk(KERN_INFO "windfarm: Slots control loop started.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		wf_pid_init(&slots_pid, &slots_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		slots_started = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	err = slots_power->ops->get_value(slots_power, &power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		printk(KERN_WARNING "windfarm: slots power sensor error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		       err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		failure_state |= FAILURE_SENSOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		wf_control_set_max(slots_fan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	speed = wf_pid_run(&slots_pid, power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	DBG_LOTS("slots PID power=%d.%.3d speed=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		 FIX32TOPRINT(power), speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	err = slots_fan->ops->set_value(slots_fan, speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		printk(KERN_WARNING "windfarm: slots fan error %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		failure_state |= FAILURE_FAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static void set_fail_state(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	if (cpufreq_clamp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		wf_control_set_max(cpufreq_clamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	for (i = 0; i < NR_CPU_FANS; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		if (cpu_fans[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			wf_control_set_max(cpu_fans[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	if (backside_fan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		wf_control_set_max(backside_fan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	if (slots_fan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		wf_control_set_max(slots_fan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	if (drive_bay_fan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		wf_control_set_max(drive_bay_fan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static void pm112_tick(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	int i, last_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	if (!started) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		started = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		printk(KERN_INFO "windfarm: CPUs control loops started.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 		for (i = 0; i < nr_cores; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 			if (create_cpu_loop(i) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 				failure_state = FAILURE_PERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 				set_fail_state();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		DBG_LOTS("cpu_all_tmax=%d.%03d\n", FIX32TOPRINT(cpu_all_tmax));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) #ifdef HACKED_OVERTEMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		cpu_all_tmax = 60 << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	/* Permanent failure, bail out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	if (failure_state & FAILURE_PERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	/* Clear all failure bits except low overtemp which will be eventually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	 * cleared by the control loop itself
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	last_failure = failure_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	failure_state &= FAILURE_LOW_OVERTEMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	cpu_fans_tick();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	backside_fan_tick();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	slots_fan_tick();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	drive_bay_fan_tick();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	DBG_LOTS("last_failure: 0x%x, failure_state: %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		 last_failure, failure_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	/* Check for failures. Any failure causes cpufreq clamping */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	if (failure_state && last_failure == 0 && cpufreq_clamp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		wf_control_set_max(cpufreq_clamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	if (failure_state == 0 && last_failure && cpufreq_clamp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 		wf_control_set_min(cpufreq_clamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	/* That's it for now, we might want to deal with other failures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	 * differently in the future though
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) static void pm112_new_control(struct wf_control *ct)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	int i, max_exhaust;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	if (cpufreq_clamp == NULL && !strcmp(ct->name, "cpufreq-clamp")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		if (wf_get_control(ct) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 			cpufreq_clamp = ct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	for (i = 0; i < NR_CPU_FANS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		if (!strcmp(ct->name, cpu_fan_names[i])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 			if (cpu_fans[i] == NULL && wf_get_control(ct) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 				cpu_fans[i] = ct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	if (i >= NR_CPU_FANS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		/* not a CPU fan, try the others */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 		if (!strcmp(ct->name, "backside-fan")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 			if (backside_fan == NULL && wf_get_control(ct) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 				backside_fan = ct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 		} else if (!strcmp(ct->name, "slots-fan")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 			if (slots_fan == NULL && wf_get_control(ct) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 				slots_fan = ct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		} else if (!strcmp(ct->name, "drive-bay-fan")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 			if (drive_bay_fan == NULL && wf_get_control(ct) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 				drive_bay_fan = ct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	for (i = 0; i < CPU_FANS_REQD; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 		if (cpu_fans[i] == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	/* work out pump scaling factors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	max_exhaust = cpu_fans[0]->ops->get_max(cpu_fans[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	for (i = FIRST_PUMP; i <= LAST_PUMP; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 		if ((ct = cpu_fans[i]) != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 			cpu_fan_scale[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 				ct->ops->get_max(ct) * 100 / max_exhaust;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	have_all_controls = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) static void pm112_new_sensor(struct wf_sensor *sr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	if (!strncmp(sr->name, "cpu-temp-", 9)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 		i = sr->name[9] - '0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 		if (sr->name[10] == 0 && i < NR_CORES &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 		    sens_cpu_temp[i] == NULL && wf_get_sensor(sr) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 			sens_cpu_temp[i] = sr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	} else if (!strncmp(sr->name, "cpu-power-", 10)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 		i = sr->name[10] - '0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		if (sr->name[11] == 0 && i < NR_CORES &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		    sens_cpu_power[i] == NULL && wf_get_sensor(sr) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 			sens_cpu_power[i] = sr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	} else if (!strcmp(sr->name, "hd-temp")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 		if (hd_temp == NULL && wf_get_sensor(sr) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 			hd_temp = sr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	} else if (!strcmp(sr->name, "slots-power")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 		if (slots_power == NULL && wf_get_sensor(sr) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 			slots_power = sr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	} else if (!strcmp(sr->name, "backside-temp")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 		if (u4_temp == NULL && wf_get_sensor(sr) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 			u4_temp = sr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	/* check if we have all the sensors we need */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	for (i = 0; i < nr_cores; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 		if (sens_cpu_temp[i] == NULL || sens_cpu_power[i] == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	have_all_sensors = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) static int pm112_wf_notify(struct notifier_block *self,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 			   unsigned long event, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	case WF_EVENT_NEW_SENSOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 		pm112_new_sensor(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	case WF_EVENT_NEW_CONTROL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 		pm112_new_control(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	case WF_EVENT_TICK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 		if (have_all_controls && have_all_sensors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 			pm112_tick();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) static struct notifier_block pm112_events = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	.notifier_call = pm112_wf_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) static int wf_pm112_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	wf_register_client(&pm112_events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) static int wf_pm112_remove(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	wf_unregister_client(&pm112_events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	/* should release all sensors and controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) static struct platform_driver wf_pm112_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	.probe = wf_pm112_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	.remove = wf_pm112_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 		.name = "windfarm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) static int __init wf_pm112_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	struct device_node *cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	if (!of_machine_is_compatible("PowerMac11,2"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	/* Count the number of CPU cores */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	nr_cores = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	for_each_node_by_type(cpu, "cpu")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 		++nr_cores;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	printk(KERN_INFO "windfarm: initializing for dual-core desktop G5\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) #ifdef MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	request_module("windfarm_smu_controls");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	request_module("windfarm_smu_sensors");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	request_module("windfarm_smu_sat");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	request_module("windfarm_lm75_sensor");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	request_module("windfarm_max6690_sensor");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	request_module("windfarm_cpufreq_clamp");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) #endif /* MODULE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	platform_driver_register(&wf_pm112_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) static void __exit wf_pm112_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	platform_driver_unregister(&wf_pm112_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) module_init(wf_pm112_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) module_exit(wf_pm112_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) MODULE_DESCRIPTION("Thermal control for PowerMac11,2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) MODULE_ALIAS("platform:windfarm");