xref: /linux/drivers/macintosh/windfarm_mpu.h (revision 44f57d78)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Windfarm PowerMac thermal control
4  *
5  * Copyright 2012 Benjamin Herrenschmidt, IBM Corp.
6  */
7 
8 #ifndef __WINDFARM_MPU_H
9 #define __WINDFARM_MPU_H
10 
11 typedef unsigned short fu16;
12 typedef int fs32;
13 typedef short fs16;
14 
15 /* Definition of the MPU data structure which contains per CPU
16  * calibration information (among others) for the G5 machines
17  */
18 struct mpu_data
19 {
20 	u8	signature;		/* 0x00 - EEPROM sig. */
21 	u8	bytes_used;		/* 0x01 - Bytes used in eeprom (160 ?) */
22 	u8	size;			/* 0x02 - EEPROM size (256 ?) */
23 	u8	version;		/* 0x03 - EEPROM version */
24 	u32	data_revision;		/* 0x04 - Dataset revision */
25 	u8	processor_bin_code[3];	/* 0x08 - Processor BIN code */
26 	u8	bin_code_expansion;	/* 0x0b - ??? (padding ?) */
27 	u8	processor_num;		/* 0x0c - Number of CPUs on this MPU */
28 	u8	input_mul_bus_div;	/* 0x0d - Clock input multiplier/bus divider */
29 	u8	reserved1[2];		/* 0x0e - */
30 	u32	input_clk_freq_high;	/* 0x10 - Input clock frequency high */
31 	u8	cpu_nb_target_cycles;	/* 0x14 - ??? */
32 	u8	cpu_statlat;		/* 0x15 - ??? */
33 	u8	cpu_snooplat;		/* 0x16 - ??? */
34 	u8	cpu_snoopacc;		/* 0x17 - ??? */
35 	u8	nb_paamwin;		/* 0x18 - ??? */
36 	u8	nb_statlat;		/* 0x19 - ??? */
37 	u8	nb_snooplat;		/* 0x1a - ??? */
38 	u8	nb_snoopwin;		/* 0x1b - ??? */
39 	u8	api_bus_mode;		/* 0x1c - ??? */
40 	u8	reserved2[3];		/* 0x1d - */
41 	u32	input_clk_freq_low;	/* 0x20 - Input clock frequency low */
42 	u8	processor_card_slot;	/* 0x24 - Processor card slot number */
43 	u8	reserved3[2];		/* 0x25 - */
44 	u8	padjmax;       		/* 0x27 - Max power adjustment (Not in OF!) */
45 	u8	ttarget;		/* 0x28 - Target temperature */
46 	u8	tmax;			/* 0x29 - Max temperature */
47 	u8	pmaxh;			/* 0x2a - Max power */
48 	u8	tguardband;		/* 0x2b - Guardband temp ??? Hist. len in OSX */
49 	fs32	pid_gp;			/* 0x2c - PID proportional gain */
50 	fs32	pid_gr;			/* 0x30 - PID reset gain */
51 	fs32	pid_gd;			/* 0x34 - PID derivative gain */
52 	fu16	voph;			/* 0x38 - Vop High */
53 	fu16	vopl;			/* 0x3a - Vop Low */
54 	fs16	nactual_die;		/* 0x3c - nActual Die */
55 	fs16	nactual_heatsink;	/* 0x3e - nActual Heatsink */
56 	fs16	nactual_system;		/* 0x40 - nActual System */
57 	u16	calibration_flags;	/* 0x42 - Calibration flags */
58 	fu16	mdiode;			/* 0x44 - Diode M value (scaling factor) */
59 	fs16	bdiode;			/* 0x46 - Diode B value (offset) */
60 	fs32	theta_heat_sink;	/* 0x48 - Theta heat sink */
61 	u16	rminn_intake_fan;	/* 0x4c - Intake fan min RPM */
62 	u16	rmaxn_intake_fan;	/* 0x4e - Intake fan max RPM */
63 	u16	rminn_exhaust_fan;	/* 0x50 - Exhaust fan min RPM */
64 	u16	rmaxn_exhaust_fan;	/* 0x52 - Exhaust fan max RPM */
65 	u8	processor_part_num[8];	/* 0x54 - Processor part number XX pumps min/max */
66 	u32	processor_lot_num;	/* 0x5c - Processor lot number */
67 	u8	orig_card_sernum[0x10];	/* 0x60 - Card original serial number */
68 	u8	curr_card_sernum[0x10];	/* 0x70 - Card current serial number */
69 	u8	mlb_sernum[0x18];	/* 0x80 - MLB serial number */
70 	u32	checksum1;		/* 0x98 - */
71 	u32	checksum2;		/* 0x9c - */
72 }; /* Total size = 0xa0 */
73 
74 static inline const struct mpu_data *wf_get_mpu(int cpu)
75 {
76 	struct device_node *np;
77 	char nodename[64];
78 	const void *data;
79 	int len;
80 
81 	/*
82 	 * prom.c routine for finding a node by path is a bit brain dead
83 	 * and requires exact @xxx unit numbers. This is a bit ugly but
84 	 * will work for these machines
85 	 */
86 	sprintf(nodename, "/u3@0,f8000000/i2c@f8001000/cpuid@a%d", cpu ? 2 : 0);
87 	np = of_find_node_by_path(nodename);
88 	if (!np)
89 		return NULL;
90 	data = of_get_property(np, "cpuid", &len);
91 	of_node_put(np);
92 	if (!data)
93 		return NULL;
94 
95 	/*
96 	 * We are naughty, we have dropped the reference to the device
97 	 * node and still return a pointer to the content. We know we
98 	 * can do that though as this is only ever called on PowerMac
99 	 * which cannot remove those nodes
100 	 */
101 	return data;
102 }
103 
104 #endif /*  __WINDFARM_MPU_H */
105