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